MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
edges.cc
Go to the documentation of this file.
1 
6 #include "globals.hh"
7 #include <iostream>
8 #include <cmath>
9 #include "geometry.hh"
10 using namespace std;
11 using namespace globals;
18  int ***amat , \
19  int sv , \
20  double **vert , \
21  int **vinc , \
22  bool report )
23 {
24  // Creates struts - solid material along cell edge. Created strut has
25  // a shape of triangular prism. Updates `amat`.
26  int i,j,k,l,m,n;
27  double da,db,dc,de; //distance
28  double xx,xxa,xxb,xxc;
29  double mini[3],maxi[3];
30  double xmin=0,xmax=nx;
31  double ymin=0,ymax=ny;
32  double zmin=0,zmax=nz;
33  double n0[3]; //primary edge unit vector
34  double a0[3],b0[3],c0[3]; //incident edges unit vectors
35  //(their projection to plane normal to primary edge vector)
36  double pa[3],pb[3],pc[3]; //vertices of triangle base of the prism
37  double pap[3],pbp[3],pcp[3]; //vertices of triangle in plane of point P
38  double pp[3]; //coordinates of point P
39  if (report) {
40  cout << "creating struts at cell edges..." << dedge << endl;
41  }
42  for (i=0; i<sv; i++) { // for all vertices
43  if (in_domain(vert[i][0],vert[i][1],vert[i][2])) {
44  for (j=0; j<4; j++) { // for every edge
45  de=sqrt(pow(vert[i][0]-vert[vinc[i][j]][0],2)+\
46  pow(vert[i][1]-vert[vinc[i][j]][1],2)+\
47  pow(vert[i][2]-vert[vinc[i][j]][2],2));
48  //length of the primary edge
49  for (k=0; k<3; k++) {
50  // define primary and incident edge vectors
51  n0[k]=vert[vinc[i][j]][k]-vert[i][k];
52  a0[k]=vert[vinc[i][(j+1)%4]][k];
53  b0[k]=vert[vinc[i][(j+2)%4]][k];
54  c0[k]=vert[vinc[i][(j+3)%4]][k];
55  }
56  xx=0; // normalize primary vector
57  for (k=0; k<3; k++) {
58  xx+=pow(n0[k],2);
59  }
60  for (k=0; k<3; k++) {
61  n0[k]/=sqrt(xx);
62  }
63  da=abs(n0[0]*a0[0]+n0[1]*a0[1]+n0[2]*a0[2]-\
64  n0[0]*vert[i][0]-n0[1]*vert[i][1]-n0[2]*vert[i][2]);
65  // calculate distance from plane normal to
66  // primary vector at cell vertex
67  for (k=0; k<3; k++) {
68  // redefine incident edge vectors to be in plane normal
69  // to primary edge vector (project them to the plane)
70  a0[k]+=da*n0[k];
71  }
72  if (abs(n0[0]*a0[0]+n0[1]*a0[1]+n0[2]*a0[2]-\
73  n0[0]*vert[i][0]-n0[1]*vert[i][1]-\
74  n0[2]*vert[i][2])>1e-2) {
75  for (k=0; k<3; k++) {
76  a0[k]-=2*da*n0[k];
77  }
78  }
79  db=abs(n0[0]*b0[0]+n0[1]*b0[1]+n0[2]*b0[2]-\
80  n0[0]*vert[i][0]-n0[1]*vert[i][1]-n0[2]*vert[i][2]);
81  for (k=0; k<3; k++) {
82  b0[k]+=db*n0[k];
83  }
84  if (abs(n0[0]*b0[0]+n0[1]*b0[1]+n0[2]*b0[2]-\
85  n0[0]*vert[i][0]-n0[1]*vert[i][1]-\
86  n0[2]*vert[i][2])>1e-2) {
87  for (k=0; k<3; k++) {
88  b0[k]-=2*db*n0[k];
89  }
90  }
91  dc=abs(n0[0]*c0[0]+n0[1]*c0[1]+n0[2]*c0[2]-\
92  n0[0]*vert[i][0]-n0[1]*vert[i][1]-n0[2]*vert[i][2]);
93  for (k=0; k<3; k++) {
94  c0[k]+=dc*n0[k];
95  }
96  if (abs(n0[0]*c0[0]+n0[1]*c0[1]+n0[2]*c0[2]-\
97  n0[0]*vert[i][0]-n0[1]*vert[i][1]-\
98  n0[2]*vert[i][2])>1e-2) {
99  for (k=0; k<3; k++) {
100  c0[k]-=2*dc*n0[k];
101  }
102  }
103  for (k=0; k<3; k++) {
104  // redefine incident edge vectors to be in plane normal
105  // to primary edge vector (project them to the plane)
106  a0[k]-=vert[i][k];
107  b0[k]-=vert[i][k];
108  c0[k]-=vert[i][k];
109  }
110  xxa=0; xxb=0; xxc=0; // normalize incident edge vectors
111  for (k=0; k<3; k++) {
112  xxa+=pow(a0[k],2);
113  xxb+=pow(b0[k],2);
114  xxc+=pow(c0[k],2);
115  }
116  for (k=0; k<3; k++) {
117  a0[k]/=sqrt(xxa);
118  b0[k]/=sqrt(xxb);
119  c0[k]/=sqrt(xxc);
120  }
121  for (k=0; k<3; k++) {
122  // calculate triangle points at the base of prism
123  pa[k]=vert[i][k]+a0[k]*dedge;
124  pb[k]=vert[i][k]+b0[k]*dedge;
125  pc[k]=vert[i][k]+c0[k]*dedge;
126  }
127  // set boundaries of suspicious region
128  mini[0]=2*xmax; maxi[0]=-2*xmax;
129  mini[1]=2*ymax; maxi[1]=-2*ymax;
130  mini[2]=2*zmax; maxi[2]=-2*zmax;
131  for (k=0; k<3; k++) {
132  if (vert[vinc[i][j]][k]<mini[k]) {
133  mini[k]=vert[vinc[i][j]][k];
134  }
135  if (vert[i][k]<mini[k]) mini[k]=vert[i][k];
136  if (vert[vinc[i][j]][k]>maxi[k]) {
137  maxi[k]=vert[vinc[i][j]][k];
138  }
139  if (vert[i][k]>maxi[k]) maxi[k]=vert[i][k];
140  }
141  for (k=0; k<3; k++) {
142  mini[k]-=dedge;
143  maxi[k]+=dedge;
144  }
145  for (k=(int) floor(mini[0]); k<=ceil(maxi[0]); k++)
146  for (l=(int) floor(mini[1]); l<=ceil(maxi[1]); l++)
147  for (m=(int) floor(mini[2]); m<=ceil(maxi[2]); m++){
148  // for all points P in suspicious region
149  if (amat[CONFINEX(k)][CONFINEY(l)]\
150  [CONFINEZ(m)]==0) {
151  da=sqrt(pow(vert[i][0]-k,2)+pow(vert[i][1]-\
152  l,2)+pow(vert[i][2]-m,2));
153  db=sqrt(pow(k-vert[vinc[i][j]][0],2)+\
154  pow(l-vert[vinc[i][j]][1],2)+\
155  pow(m-vert[vinc[i][j]][2],2));
156  if (da<de && db<de) {
157  // calculate distance of triangle from
158  // plane of point P (it is the same for
159  // any point of triangle)
160  da=abs(n0[0]*pa[0]+n0[1]*pa[1]+n0[2]*\
161  pa[2]-n0[0]*k-n0[1]*l-n0[2]*m);
162 
163  pp[0]=k; pp[1]=l; pp[2]=m;
164  for (n=0; n<3; n++) {
165  //calculate triangle vertices in
166  //plane of point P
167  pap[n]=pa[n]+da*n0[n];
168  pbp[n]=pb[n]+da*n0[n];
169  pcp[n]=pc[n]+da*n0[n];
170  }
171  if (abs(n0[0]*pap[0]+n0[1]*pap[1]+\
172  n0[2]*pap[2]-n0[0]*k-n0[1]*l-\
173  n0[2]*m) > 1e-2) {
174  for (n=0; n<3; n++) {
175  //calculate triangle vertices in
176  //plane of point P
177  pap[n]=pa[n]-da*n0[n];
178  pbp[n]=pb[n]-da*n0[n];
179  pcp[n]=pc[n]-da*n0[n];
180  }
181  }
182  if (abs(n0[0]*pap[0]+n0[1]*pap[1]+\
183  n0[2]*pap[2]-n0[0]*k-n0[1]*l-\
184  n0[2]*m) > 1e-2) {
185  cout << "not in plane" << endl;
186  exit(1);
187  }
188  if (PointInTriangle(pp,pap,pbp,pcp)) {
189  //make him solid
190  amat[CONFINEX(k)][CONFINEY(l)]\
191  [CONFINEZ(m)]=1;
192  }
193  }
194  }
195  }
196  }
197  }
198  }
199  return;
200 }
double dedge
parameter influencing size of struts in cell edges
Definition: globals.cc:13
real(dp), parameter c0
speed of light in vacuum
Definition: constants.f90:10
Defines global variables, macros, templates and namespace.
void makeEdgeStruts(int ***amat, int sv, double **vert, int **vinc, bool report)
Definition: edges.cc:17
bool in_domain(double x, double y, double z)
True if the point is in the domain, False otherwise.
Definition: geometry.cc:9
m
Bubble Growth Application Recipe.
Definition: bubbleGrowth.py:59
real(dp), dimension(4) pc
critical pressure
Definition: constants.f90:25
int nx
domain size in X
Definition: globals.cc:19
#define CONFINEZ(x)
Periodic boundary conditions in z.
Definition: globals.hh:17
bool PointInTriangle(double p[], double a[], double b[], double c[])
True if point lies in the triangle.
Definition: geometry.cc:56
#define CONFINEY(x)
Periodic boundary conditions in y.
Definition: globals.hh:15
integer nz
spatial discretization
Definition: constants.f90:32
namespace with global variables
Definition: globals.f90:8
#define CONFINEX(x)
Periodic boundary conditions in x.
Definition: globals.hh:13
int ny
domain size in Y
Definition: globals.cc:20