Timothy  0.9
Tissue Modelling Framework
 All Data Structures Files Functions Variables Typedefs Macros
potential.c File Reference

contains functions that compute the potential More...

#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#include "global.h"
#include "inline.h"
Include dependency graph for potential.c:

Go to the source code of this file.

Functions

double computeCCPotential (int p1, int p2, int mode)
 
void potentialTraverseSubtree (int p, struct bht_node *no)
 
void computeRemoteCellsPotential (int rp, struct bht_node *no)
 
void computePotentialField ()
 
void computePotential ()
 

Detailed Description

contains functions that compute the potential

Definition in file potential.c.

Function Documentation

double computeCCPotential ( int  p1,
int  p2,
int  mode 
)

This function computes potential for two neighbour cells. mode=0 - computations for local cells mode=1 - computations for remote cells

Definition at line 40 of file potential.c.

References cells, csize, cellData::density, h, h2, h3, statisticsData::mindist, recvData, sdim, cellData::size, partData::size, statistics, x, cellData::x, partData::x, cellData::y, partData::y, cellData::young, partData::young, cellData::z, and partData::z.

41 {
42  double pot;
43  double dist;
44  double size;
45  double g;
46  double x, y, z;
47  double xc;
48  double D;
49  double poisson = 0.33;
50  double young;
51 
52  if (mode == 0 && p1 == p2)
53  return 0.0;
54 
55  if (mode == 0) {
56  x = cells[p1].x;
57  y = cells[p1].y;
58  z = cells[p1].z;
59  size = cells[p1].size;
60  young = cells[p1].young;
61  }
62  if (mode == 1) {
63  x = recvData[p1].x;
64  y = recvData[p1].y;
65  z = recvData[p1].z;
66  size = recvData[p1].size;
67  young = recvData[p1].young;
68  }
69 
70  /* compute the distance between two cells */
71  if (sdim == 2)
72  dist =
73  sqrt((x - cells[p2].x) * (x - cells[p2].x) +
74  (y - cells[p2].y) * (y - cells[p2].y));
75  if (sdim == 3)
76  dist =
77  sqrt((x - cells[p2].x) * (x - cells[p2].x) +
78  (y - cells[p2].y) * (y - cells[p2].y) + (z -
79  cells[p2].z) * (z -
80  cells
81  [p2].
82  z));
83 
84  if (statistics.mindist > dist)
85  statistics.mindist = dist;
86 
87  if (dist <= h) {
88 
89  double r01, r02;
90  double area;
91  double sc;
92 
93  if (sdim == 2)
94  sc = h2;
95  if (sdim == 3)
96  sc = h3;
97 
98  if (mode == 0) {
99  cells[p1].density +=
100  sc * (cells[p2].size / csize) * sph_kernel(dist);
101  }
102  if (mode == 1) {
103  cells[p2].density += sc * (size / csize) * sph_kernel(dist);
104  }
105 
106  xc = size + cells[p2].size - dist;
107 
108  if (xc <= 0.0)
109  return 0.0;
110 
111  D = 0.75 * ((1.0 - poisson * poisson) / young +
112  (1.0 - poisson * poisson / cells[p2].young));
113 
114  /* adhesion */
115  r01 =
116  (size * size - cells[p2].size * cells[p2].size +
117  dist * dist) / (2 * dist);
118  r02 = dist - r01;
119 
120  area =
121  M_PI *
122  ((size * size * (size - r01) -
123  (size * size * size - r01 * r01 * r01) / 3) +
124  (cells[p2].size * cells[p2].size * (cells[p2].size - r02) -
125  (cells[p2].size * cells[p2].size * cells[p2].size -
126  r02 * r02 * r02) / 3));
127 
128  /* compute potential */
129  pot =
130  (2.0 * pow(xc, 5 / 2) / (5.0 * D)) * sqrt((size * cells[p2].size) /
131  (size +
132  cells[p2].size)) +
133  area * 0.1;
134 
135  return pot;
136 
137  } else
138  return 0.0;
139 
140 }
double density
Definition: global.h:75
HYPRE_SStructVector x
Definition: tempf.c:41
double z
Definition: global.h:119
float young
Definition: global.h:67
double mindist
Definition: global.h:259
double size
Definition: global.h:72
struct partData * recvData
Definition: global.h:149
double h3
Definition: global.h:202
int sdim
Definition: global.h:160
struct statisticsData statistics
Definition: global.h:268
double x
Definition: global.h:69
double csize
Definition: global.h:197
struct cellData * cells
Definition: global.h:82
double size
Definition: global.h:121
double z
Definition: global.h:71
double h2
Definition: global.h:201
double y
Definition: global.h:70
double young
Definition: global.h:122
double x
Definition: global.h:117
double y
Definition: global.h:118
double h
Definition: global.h:200

Here is the caller graph for this function:

void computePotential ( )

This is a driving routine for the potential computations.

Definition at line 287 of file potential.c.

References computePotentialField(), MPIrank, statOutStep, and step.

288 {
289 #ifdef DEBUG
290  if (MPIrank == 0 && !(step % statOutStep)) {
291  printf(" Potential computations...");
292  fflush(stdout);
293  }
294 #endif
295 
297 
298 #ifdef DEBUG
299  if (MPIrank == 0 && !(step % statOutStep)) {
300  printf("done\n");
301  fflush(stdout);
302  }
303 #endif
304 }
int statOutStep
Definition: global.h:214
int MPIrank
Definition: global.h:134
void computePotentialField()
Definition: potential.c:209
int step
Definition: global.h:173

Here is the call graph for this function:

Here is the caller graph for this function:

void computePotentialField ( )

This function computes potential for all local cells.

Definition at line 209 of file potential.c.

References bht_root, cells, cellsExchangeInit(), cellsExchangeWait(), bht_node::child, computeRemoteCellsPotential(), cellData::density, bht_node::father, h, leafs, lnc, statisticsData::maxsize, statisticsData::maxvel, statisticsData::mindist, statisticsData::minsize, statisticsData::minvel, nc, numImp, nx, bht_node::partnum, potentialTraverseSubtree(), s, statistics, tnc, cellData::v, and x.

210 {
211  int p, rp;
212  int s;
213  struct bht_node *no;
214 
215  if (nc > 1)
216  statistics.mindist = nx; /* minimal distance is set to the box size */
217  else
218  statistics.mindist = 0.0;
219  statistics.minvel = DBL_MAX; /* minimal velocity is set to DBL_MAX */
220  statistics.maxvel = 0; /* maximal velocity is set to zero */
221  statistics.minsize = DBL_MAX; /* minimal size is set to DBL_MAX */
222  statistics.maxsize = 0; /* maximal size is set to zero */
223 
224  if (lnc == 0)
225  return;
226 
227  /* initiate asynchronous data transfers between processors */
229 
230  /* loop over all local cells */
231  //#pragma omp parallel for private(p,s,no) schedule(dynamic)
232 #pragma omp parallel for private(p,s,no)
233  for (p = 0; p < lnc; p++) {
234 
235  cells[p].density = 0.0;
236  cells[p].v = 0.0;
237 
238  /* set the pointer to the node that owns the cell */
239  no = leafs[p];
240 
241  /* traverse the tree (bottom-up) */
242  while (1) {
243 
244  if (no->father == NULL)
245  break;
246 
247  /* loop over siblings */
248  for (s = 0; s < tnc; s++) {
249  /* "Son of my father but not my brother. It's me." Hairdresser */
250  if ((no->father->child[s] == NULL) || (no->father->child[s] == no)
251  || (no->father->child[s]->partnum == -1))
252  continue;
253  if (cellIntersectNode
254  (cells[p].x, cells[p].y, cells[p].z, cells[p].h,
255  no->father->child[s])) {
256  /* traverse subtree of the sibling (up-bottom) */
258  }
259  }
260 
261  no = no->father;
262  if (no->father == NULL)
263  break; /* this is the root node */
264  if (cellInsideNode(p, no))
265  break;
266 
267  }
268 
269  }
270 
271  /* wait for data transfers to finish */
273 
274  /* loop over remote cells */
275  for (rp = 0; rp < numImp; rp++) {
276  /* start with the root node */
277  no = bht_root;
278  /* traverse the tree and compute potential (starting from the root) */
280 
281  }
282 }
double density
Definition: global.h:75
#define lnc
Definition: global.h:102
float s
Definition: global.h:186
HYPRE_SStructVector x
Definition: tempf.c:41
void cellsExchangeInit()
Definition: comm.c:177
double mindist
Definition: global.h:259
double maxsize
Definition: global.h:258
double minsize
Definition: global.h:257
int tnc
Definition: global.h:295
void potentialTraverseSubtree(int p, struct bht_node *no)
Definition: potential.c:146
struct bht_node * child[8]
Definition: global.h:283
struct statisticsData statistics
Definition: global.h:268
int partnum
Definition: global.h:281
struct bht_node * bht_root
Definition: global.h:289
struct bht_node ** leafs
Definition: global.h:290
void computeRemoteCellsPotential(int rp, struct bht_node *no)
Definition: potential.c:176
int numImp
Definition: global.h:154
struct cellData * cells
Definition: global.h:82
struct bht_node * father
Definition: global.h:282
void cellsExchangeWait()
Definition: comm.c:223
double maxvel
Definition: global.h:260
#define nc
Definition: global.h:93
int nx
Definition: global.h:162
double v
Definition: global.h:74
double minvel
Definition: global.h:261
double h
Definition: global.h:200

Here is the call graph for this function:

Here is the caller graph for this function:

void computeRemoteCellsPotential ( int  rp,
struct bht_node no 
)

This function traverse the tree (up-bottom) and computes potential for remote cells.

Definition at line 176 of file potential.c.

References cells, bht_node::child, computeCCPotential(), h, bht_node::leaf, lnc, bht_node::partnum, recvData, s, tnc, cellData::v, and x.

177 {
178  int s;
179 
180  if (lnc == 0)
181  return;
182  if (no->partnum == -1)
183  return;
184 
185  /* compute potential if it is a leaf node */
186  if (no->leaf == 1) {
187  if (lnc > 0)
188  cells[no->partnum].v += computeCCPotential(rp, no->partnum, 1);
189  return;
190  }
191 
192  /* loop over all siblings */
193  for (s = 0; s < tnc; s++) {
194  /* continue if there is no child */
195  if (no->child[s] == NULL || no->child[s]->partnum == -1)
196  continue;
197  /* proceed if the child node and particle intersect */
198  if (!cellIntersectNode
199  (recvData[rp].x, recvData[rp].y, recvData[rp].z, recvData[rp].h,
200  no->child[s]))
201  continue;
203  }
204 }
#define lnc
Definition: global.h:102
float s
Definition: global.h:186
HYPRE_SStructVector x
Definition: tempf.c:41
unsigned char leaf
Definition: global.h:284
double computeCCPotential(int p1, int p2, int mode)
Definition: potential.c:40
struct partData * recvData
Definition: global.h:149
int tnc
Definition: global.h:295
struct bht_node * child[8]
Definition: global.h:283
int partnum
Definition: global.h:281
void computeRemoteCellsPotential(int rp, struct bht_node *no)
Definition: potential.c:176
struct cellData * cells
Definition: global.h:82
double v
Definition: global.h:74
double h
Definition: global.h:200

Here is the call graph for this function:

Here is the caller graph for this function:

void potentialTraverseSubtree ( int  p,
struct bht_node no 
)

This function traverses the subtree under given node looking for neighbour cells.

Definition at line 146 of file potential.c.

References cells, bht_node::child, computeCCPotential(), h, bht_node::leaf, lnc, bht_node::partnum, s, tnc, cellData::v, and x.

147 {
148  int s;
149 
150  if (no->partnum == -1)
151  return;
152 
153  /* if it is a leaf node we do not proceed to the siblings */
154  if (no->leaf == 1) {
155  if (lnc > 0)
156  cells[p].v += computeCCPotential(p, no->partnum, 0);
157  return;
158  }
159 
160  /* loop over siblings */
161  for (s = 0; s < tnc; s++) {
162  /* if it is an empty child proceed to the next one */
163  if ((no->child[s] == NULL) || (no->child[s]->partnum == -1))
164  continue;
165  /* if there is no intersection with this child proceed to next one */
166  if (!cellIntersectNode
167  (cells[p].x, cells[p].y, cells[p].z, cells[p].h, no->child[s]))
168  continue;
169  potentialTraverseSubtree(p, no->child[s]);
170  }
171 }
#define lnc
Definition: global.h:102
float s
Definition: global.h:186
HYPRE_SStructVector x
Definition: tempf.c:41
unsigned char leaf
Definition: global.h:284
double computeCCPotential(int p1, int p2, int mode)
Definition: potential.c:40
int tnc
Definition: global.h:295
void potentialTraverseSubtree(int p, struct bht_node *no)
Definition: potential.c:146
struct bht_node * child[8]
Definition: global.h:283
int partnum
Definition: global.h:281
struct cellData * cells
Definition: global.h:82
double v
Definition: global.h:74
double h
Definition: global.h:200

Here is the call graph for this function:

Here is the caller graph for this function: