Timothy  0.9
Tissue Modelling Framework
 All Data Structures Files Functions Variables Typedefs Macros
inline.h
Go to the documentation of this file.
1 /* **************************************************************************
2  * This file is part of Timothy
3  *
4  * Copyright (c) 2014/15 Maciej Cytowski
5  * Copyright (c) 2014/15 ICM, University of Warsaw, Poland
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  * *************************************************************************/
22 
30 static inline int cellIntersectNode(double x,double y,double z,double h,struct bht_node *node)
31 {
32  double xmin,xmax,ymin,ymax,zmin,zmax;
33  double cx,cy,cz;
34  double l;
35  double dist;
36  l=node->len*0.5;
37 
38  xmin=node->center[0]-l;
39  ymin=node->center[1]-l;
40  zmin=node->center[2]-l;
41  xmax=node->center[0]+l;
42  ymax=node->center[1]+l;
43  zmax=node->center[2]+l;
44 
45  if(x<xmin) cx=xmin;
46  else if(x>xmax) cx=xmax;
47  else cx=x;
48 
49  if(y<ymin) cy=ymin;
50  else if(y>ymax) cy=ymax;
51  else cy=y;
52 
53  if(z<zmin) cz=zmin;
54  else if(z>zmax) cz=zmax;
55  else cz=z;
56 
57  dist = sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy)+(z-cz)*(z-cz));
58 
59  if(dist<=h) return 1;
60 
61  return 0;
62 }
63 
68 static inline int cellInsideNode(int c, struct bht_node *node)
69 {
70  double xmin,xmax,ymin,ymax,zmin,zmax;
71  double l;
72  double x,y,z;
73  l=node->len*0.5;
74  x=cells[c].x;
75  y=cells[c].y;
76  z=cells[c].z;
77 
78  xmin=node->center[0]-l;
79  ymin=node->center[1]-l;
80  zmin=node->center[2]-l;
81  xmax=node->center[0]+l;
82  ymax=node->center[1]+l;
83  zmax=node->center[2]+l;
84 
85  if( x+cells[c].h<=xmax && x-cells[c].h>xmin && y+cells[c].h<=ymax && y-cells[c].h>ymin && z+cells[c].h<=zmax && z-cells[c].h>zmin ) return 1;
86 
87  return 0;
88 }
89 
96 static inline float sph_kernel(double r)
97 {
98 
99  double u,c;
100 
101  if(r<0.0) return 0.0;//r=0.0;
102 
103  u=r/h;
104  if(sdim==2) c=40/(7*M_PI*h2);
105  if(sdim==3) c=8/(M_PI*h3);
106  if(u<0.0) stopRun(666,NULL,__FILE__,__LINE__);
107 
108  if(u>=0.0 && u<=0.5) return c*(1-6*u*u+6*u*u*u);
109  if(u>0.5 && u<=1.0) return c*(2*(1-u)*(1-u)*(1-u));
110  if(u>1.0) return 0.0;
111 
112 }
113 
122 static inline int sph_kernel_gradient(int p1, int p2, double grad[3],int mode,double r)
123 {
124 
125  double u,c,w;
126  double x1,x2,y1,y2,z1,z2;
127  double v,d;
128 
129  if(mode==0) {
130  x1=cells[p1].x;
131  x2=cells[p2].x;
132  y1=cells[p1].y;
133  y2=cells[p2].y;
134  z1=cells[p1].z;
135  z2=cells[p2].z;
136  }
137  if(mode==1) {
138  x1=recvData[p1].x;
139  x2=cells[p2].x;
140  y1=recvData[p1].y;
141  y2=cells[p2].y;
142  z1=recvData[p1].z;
143  z2=cells[p2].z;
144  }
145 
146  if(r>=0.0 && r<=h) {
147 
148  u=r/h;
149  if(sdim==2) c=(40*8)/(7*M_PI*h3);
150  if(sdim==3) c=48/(M_PI*h4);
151 
152  if(u<0.0) stopRun(666,NULL,__FILE__,__LINE__);
153 
154  if(u>=0.0 && u<=0.5) w=-2.0*u+3.0*u*u;
155  if(u>0.5 && u<=1.0) w=-(1.0-u)*(1.0-u);
156  if(u>1.0) w=0.0;
157 
158  grad[0]=w*c*(x2-x1)/r;
159  grad[1]=w*c*(y2-y1)/r;
160  if(sdim==3) grad[2]=w*c*(z2-z1)/r;
161  if(sdim==2) grad[2]=0.0;
162 
163  } else {
164 
165  grad[0]=0.0;
166  grad[1]=0.0;
167  grad[2]=0.0;
168 
169  }
170  return 0;
171 }
172 
HYPRE_SStructVector x
Definition: tempf.c:41
double z
Definition: global.h:119
double h4
Definition: global.h:203
int64_t z
Definition: global.h:231
struct partData * recvData
Definition: global.h:149
double h3
Definition: global.h:202
int sdim
Definition: global.h:160
double x
Definition: global.h:69
double center[3]
Definition: global.h:280
struct cellData * cells
Definition: global.h:82
float v
Definition: global.h:189
double z
Definition: global.h:71
double h2
Definition: global.h:201
int64_t y
Definition: global.h:230
double y
Definition: global.h:70
void stopRun(int ierr, char *name, char *file, int line)
Definition: utils.c:72
double len
Definition: global.h:279
double x
Definition: global.h:117
double y
Definition: global.h:118
double h
Definition: global.h:200