grid_util.lyx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. #LyX 1.3 created this file. For more info see http://www.lyx.org/
  2. \lyxformat 221
  3. \textclass article
  4. \language english
  5. \inputencoding auto
  6. \fontscheme default
  7. \graphics default
  8. \paperfontsize default
  9. \spacing single
  10. \papersize letterpaper
  11. \paperpackage a4
  12. \use_geometry 1
  13. \use_amsmath 0
  14. \use_natbib 0
  15. \use_numerical_citations 0
  16. \paperorientation portrait
  17. \leftmargin 1in
  18. \topmargin 1in
  19. \rightmargin 1in
  20. \bottommargin 0.75in
  21. \secnumdepth 3
  22. \tocdepth 3
  23. \paragraph_separation indent
  24. \defskip medskip
  25. \quotes_language english
  26. \quotes_times 2
  27. \papercolumns 1
  28. \papersides 1
  29. \paperpagestyle default
  30. \layout Title
  31. Documentation for MCell Grid Utilities
  32. \layout Author
  33. Rex Kerr
  34. \layout Standard
  35. The surface grid utilities can be found in the files
  36. \family typewriter
  37. grid_util.h
  38. \family default
  39. and
  40. \family typewriter
  41. grid_util.c
  42. \layout Section
  43. Theory
  44. \layout Standard
  45. Consider a triangle with vertices
  46. \begin_inset Formula $A,B,C$
  47. \end_inset
  48. .
  49. We will orient the
  50. \begin_inset Formula $\hat{u}$
  51. \end_inset
  52. axis along the line from
  53. \begin_inset Formula $A$
  54. \end_inset
  55. to
  56. \begin_inset Formula $B$
  57. \end_inset
  58. and the
  59. \begin_inset Formula $\hat{v}$
  60. \end_inset
  61. axis perpendicular according to the right-hand rule.
  62. Thus,
  63. \begin_inset Formula $A$
  64. \end_inset
  65. is at
  66. \begin_inset Formula $(0,0)$
  67. \end_inset
  68. ,
  69. \begin_inset Formula $B$
  70. \end_inset
  71. is at
  72. \begin_inset Formula $u_{B}\cdot\hat{u}$
  73. \end_inset
  74. and
  75. \begin_inset Formula $C$
  76. \end_inset
  77. is at
  78. \begin_inset Formula $u_{C}\cdot\hat{u}+v_{C}\cdot\hat{v}$
  79. \end_inset
  80. .
  81. Suppose that we subdivide this triangle into
  82. \begin_inset Formula $n$
  83. \end_inset
  84. equal pieces along each edge, creating
  85. \begin_inset Formula $n^{2}$
  86. \end_inset
  87. subtriangles (see Figure
  88. \begin_inset LatexCommand \ref{fig:bary}
  89. \end_inset
  90. ).
  91. \begin_inset Float figure
  92. placement H
  93. wide false
  94. collapsed false
  95. \layout Standard
  96. \line_top
  97. \begin_inset Graphics
  98. filename grid_util_bary.eps
  99. scale 50
  100. \end_inset
  101. \layout Caption
  102. \line_bottom
  103. \begin_inset LatexCommand \label{fig:bary}
  104. \end_inset
  105. A barycentrically subdivided triangle (top left) consists of
  106. \begin_inset Formula $n^{2}$
  107. \end_inset
  108. subtriangles (red) identical to the original save for flipping.
  109. These can be numbered in
  110. \begin_inset Formula $n$
  111. \end_inset
  112. strips as demonstrated.
  113. If you hit a spot on the original triangle (gold dot, top right), you can
  114. quickly find which row it is in, and then the portion of the way through
  115. the row (bottom left).
  116. Finally, the line can be segmented into original-orientation and inverted-orien
  117. tation segments and the position within that line noted (bottom right).
  118. \end_inset
  119. \layout Subsection
  120. \begin_inset Formula $u,v$
  121. \end_inset
  122. coordinates to barycentric index
  123. \begin_inset LatexCommand \label{uv_to_bary}
  124. \end_inset
  125. \layout Standard
  126. Any point
  127. \begin_inset Formula $P$
  128. \end_inset
  129. in the triangle
  130. \begin_inset Formula $ABC$
  131. \end_inset
  132. will have a
  133. \begin_inset Formula $\hat{v}$
  134. \end_inset
  135. coordinate between
  136. \begin_inset Formula $0$
  137. \end_inset
  138. and
  139. \begin_inset Formula $v_{C}$
  140. \end_inset
  141. .
  142. Barycentric subdivision will split this into
  143. \begin_inset Formula $n$
  144. \end_inset
  145. equal strips and thus
  146. \begin_inset Formula $P$
  147. \end_inset
  148. will be in the
  149. \begin_inset Formula $k=\left\lfloor \frac{n\cdot v_{P}}{v_{C}}\right\rfloor $
  150. \end_inset
  151. 'th strip (counting from
  152. \begin_inset Formula $0$
  153. \end_inset
  154. to
  155. \begin_inset Formula $n-1$
  156. \end_inset
  157. ).
  158. Furthermore, one can find that
  159. \begin_inset Formula $P$
  160. \end_inset
  161. is a fraction
  162. \begin_inset Formula $f=\frac{v_{P}-k\cdot v_{C}/n}{v_{C}/n}=\frac{n\cdot v_{P}}{v_{C}}-k$
  163. \end_inset
  164. of the way to the next strip (see Figure
  165. \begin_inset LatexCommand \ref{fig:bary}
  166. \end_inset
  167. ).
  168. At
  169. \begin_inset Formula $P$
  170. \end_inset
  171. , the triangle stretches from
  172. \begin_inset Formula $u_{0}=u_{C}\frac{v_{P}}{v_{C}}$
  173. \end_inset
  174. to
  175. \begin_inset Formula $u_{1}=u_{B}+\left(u_{C}-u_{B}\right)\frac{v_{P}}{v_{C}}$
  176. \end_inset
  177. along the
  178. \begin_inset Formula $u$
  179. \end_inset
  180. axis, which we can map to
  181. \begin_inset Formula $2k+1$
  182. \end_inset
  183. regions as shown in Figure
  184. \begin_inset LatexCommand \ref{fig:bary}
  185. \end_inset
  186. .
  187. We thus can find
  188. \begin_inset Formula $j$
  189. \end_inset
  190. between
  191. \begin_inset Formula $0$
  192. \end_inset
  193. and
  194. \begin_inset Formula $k$
  195. \end_inset
  196. using
  197. \begin_inset Formula $j=\left\lfloor \frac{u_{P}-u_{0}}{u_{1}-u_{0}}\right\rfloor $
  198. \end_inset
  199. and then find if the remainder
  200. \begin_inset Formula $\frac{u_{P}-u_{0}}{u_{1}-u_{0}}-j$
  201. \end_inset
  202. is less than
  203. \begin_inset Formula $1-f$
  204. \end_inset
  205. .
  206. If so, let
  207. \begin_inset Formula $i=0$
  208. \end_inset
  209. (upright triangle), otherwise set
  210. \begin_inset Formula $i=1$
  211. \end_inset
  212. (inverted triangle).
  213. Then we have the
  214. \begin_inset Formula $2j+i$
  215. \end_inset
  216. 'th triangle in the
  217. \begin_inset Formula $k$
  218. \end_inset
  219. 'th strip, and there are
  220. \begin_inset Formula $\left(n-k-1\right)^{2}$
  221. \end_inset
  222. triangles in higher-numbered strips so the barycentric index is
  223. \begin_inset Formula $b=\left(n-k-1\right)^{2}+2j+i$
  224. \end_inset
  225. .
  226. \layout Subsection
  227. Barycentric index to
  228. \begin_inset Formula $u,v$
  229. \end_inset
  230. coordinates
  231. \layout Standard
  232. We can write the barycentric index
  233. \begin_inset Formula $b$
  234. \end_inset
  235. as
  236. \begin_inset Formula $b=\left\lfloor \sqrt{b}\right\rfloor ^{2}+r$
  237. \end_inset
  238. and
  239. \begin_inset Formula $r=2\left\lfloor \frac{r}{2}\right\rfloor +\left(r-2\left\lfloor \frac{r}{2}\right\rfloor \right)$
  240. \end_inset
  241. .
  242. Using the results of section
  243. \begin_inset LatexCommand \ref{uv_to_bary}
  244. \end_inset
  245. , we thus have
  246. \begin_inset Formula $k=n-\left\lfloor \sqrt{b}\right\rfloor -1$
  247. \end_inset
  248. ,
  249. \begin_inset Formula $j=\left\lfloor \frac{r}{2}\right\rfloor =\left\lfloor \frac{b-\left\lfloor \sqrt{b}\right\rfloor ^{2}}{2}\right\rfloor $
  250. \end_inset
  251. , and
  252. \begin_inset Formula $i=r-2j$
  253. \end_inset
  254. .
  255. We then have two cases.
  256. If
  257. \begin_inset Formula $i=0$
  258. \end_inset
  259. , the triangle is upright.
  260. The
  261. \begin_inset Formula $A$
  262. \end_inset
  263. -corner starts at
  264. \begin_inset Formula $\left(\frac{j}{n}u_{B}+\frac{k}{n}u_{C}\right)\hat{u}+\frac{k}{n}v_{C}\cdot\hat{v}$
  265. \end_inset
  266. , and the center of the large triangle is at
  267. \begin_inset Formula $\left(\frac{u_{B}+u_{C}}{3}\right)\hat{u}+\frac{v_{C}}{3}\hat{v}$
  268. \end_inset
  269. .
  270. Since the small triangle is
  271. \begin_inset Formula $n$
  272. \end_inset
  273. times smaller along each axis, the centroid of the triangle is thus at
  274. \begin_inset Formula $\left(\frac{3j+1}{3n}u_{B}+\frac{3k+1}{3n}u_{C}\right)\hat{u}+\frac{3k+1}{3n}v_{C}\cdot\hat{v}$
  275. \end_inset
  276. .
  277. If
  278. \begin_inset Formula $i=1$
  279. \end_inset
  280. , the triangle is inverted and the
  281. \begin_inset Formula $A$
  282. \end_inset
  283. -corner is on the
  284. \begin_inset Formula $k+1$
  285. \end_inset
  286. 'st line, so our corner is at
  287. \begin_inset Formula $\left(\frac{j}{n}u_{B}+\frac{k+1}{n}u_{C}\right)\hat{u}+\frac{k+1}{n}v_{C}\cdot\hat{v}$
  288. \end_inset
  289. , and since the triangle is inverted, the centroid is flipped in the
  290. \begin_inset Formula $\hat{v}$
  291. \end_inset
  292. direction, and thus is offset by
  293. \begin_inset Formula $\left(\frac{u_{B}+u_{C}}{3n}\right)\hat{u}-\frac{v_{C}}{3n}\hat{v}$
  294. \end_inset
  295. from the corner.
  296. Thus the centroid is at
  297. \begin_inset Formula $\left(\frac{3j+1}{3n}u_{B}+\frac{3k+4}{3n}u_{C}\right)\hat{u}+\frac{3k+2}{3n}v_{C}\cdot\hat{v}$
  298. \end_inset
  299. .
  300. These two results for different
  301. \begin_inset Formula $i$
  302. \end_inset
  303. can be rewritten as follows:
  304. \begin_inset Formula $\left(\frac{3j+1}{3n}u_{B}+\frac{3k+1+3i}{3n}u_{C}\right)\hat{u}+\frac{3k+1+i}{3n}v_{C}\cdot\hat{v}$
  305. \end_inset
  306. .
  307. \layout Section
  308. Implementation
  309. \layout Standard
  310. There are three grid utility functions (so far).
  311. Please see the
  312. \family typewriter
  313. grid_util.c
  314. \family default
  315. file for explanations.
  316. \the_end