MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
nodes.cc
Go to the documentation of this file.
1 
6 #include "globals.hh"
7 #include <iostream>
8 #include <cmath>
9 #include "determinant.hh"
10 #include "geometry.hh"
11 #include "allocation.hh"
12 using namespace std;
13 using namespace globals;
20  int ***amat ,\
21  int sv ,\
22  int incmax ,\
23  int vmax ,\
24  double **vert ,\
25  int **vinc ,\
26  bool report )
27 {
28  // Creates strut parts - solid material around cell vertices. Created
29  // strut has a shape of tetrahedron. Updates `amat`.
30  int i,j,k,l,m,n;
31  int svd; //final number of vertices in the domain
32  double xx;
33  double mini[3],maxi[3];
34  double xmin=0,xmax=nx;
35  double ymin=0,ymax=ny;
36  double zmin=0,zmax=nz;
37  double dist[4];
38  double ***tetra; //four points defining each tetrahedron
39  tetra=alloc_3Ddmatrix(vmax,4,3);
40  // calculate tetrahedra
41  if (report) {
42  cout << "creating struts at cell vertices..." << endl;
43  }
44  svd=0;
45  for (i=0; i<sv; i++) {
46  if (in_domain(vert[i][0],vert[i][1],vert[i][2])) {
47  k=0;
48  for (j=0; j<incmax; j++) {
49  if (vinc[i][j] != -1) {
50  k++;
51  } else {
52  break;
53  }
54  }
55  if (k>3) {
56  for (l=0; l<4; l++) {
57  xx=0;
58  for (m=0; m<3; m++) {
59  xx += pow(vert[vinc[i][l]][m]-vert[i][m],2);
60  }
61  dist[l]=sqrt(xx);
62  }
63  for (l=0; l<4; l++) {
64  for (m=0; m<3; m++) {
65  if (dstrut/dist[l]<1) {
66  tetra[svd][l][m]=vert[i][m] + \
67  dstrut/dist[l]*(vert[vinc[i][l]][m]-\
68  vert[i][m]); //strut parameter
69  } else {
70  tetra[svd][l][m]=vert[vinc[i][l]][m];
71  //for safety
72  //(we don't want sharp edges (just try and see))
73  }
74  }
75  }
76  svd++;
77  }
78  }
79  }
80  // determine if voxel is inside the tetrahedron
81  double **A0,**A1,**A2,**A3,**A4;
82  A0 = new double*[4]; //allocate
83  for (i=0; i<4; ++i)
84  A0[i] = new double[4];
85  A1 = new double*[4]; //allocate
86  for (i=0; i<4; ++i)
87  A1[i] = new double[4];
88  A2 = new double*[4]; //allocate
89  for (i=0; i<4; ++i)
90  A2[i] = new double[4];
91  A3 = new double*[4]; //allocate
92  for (i=0; i<4; ++i)
93  A3[i] = new double[4];
94  A4 = new double*[4]; //allocate
95  for (i=0; i<4; ++i)
96  A4[i] = new double[4];
97  for (i=0; i<svd; i++) {
98  mini[0]=2*xmax; maxi[0]=-2*xmax;
99  mini[1]=2*ymax; maxi[1]=-2*ymax;
100  mini[2]=2*zmax; maxi[2]=-2*zmax;
101  for (j=0; j<4; j++) {
102  for (k=0; k<3; k++) {
103  if (tetra[i][j][k]<mini[k]) mini[k]=tetra[i][j][k];
104  if (tetra[i][j][k]>maxi[k]) maxi[k]=tetra[i][j][k];
105  }
106  }
107  for (j=(int) floor(mini[0]); j<=ceil(maxi[0]); j++)
108  for (k=(int) floor(mini[1]); k<=ceil(maxi[1]); k++)
109  for (l=(int) floor(mini[2]); l<=ceil(maxi[2]); l++) {
110  for (m=0; m<4; m++) {
111  for (n=0; n<3; n++) {
112  A0[m][n]=tetra[i][m][n];
113  A1[m][n]=tetra[i][m][n];
114  A2[m][n]=tetra[i][m][n];
115  A3[m][n]=tetra[i][m][n];
116  A4[m][n]=tetra[i][m][n];
117  }
118  }
119  for (m=0; m<4; m++) {
120  A0[m][3]=1;
121  A1[m][3]=1;
122  A2[m][3]=1;
123  A3[m][3]=1;
124  A4[m][3]=1;
125  }
126  A1[0][0]=j; A1[0][1]=k; A1[0][2]=l;
127  A2[1][0]=j; A2[1][1]=k; A2[1][2]=l;
128  A3[2][0]=j; A3[2][1]=k; A3[2][2]=l;
129  A4[3][0]=j; A4[3][1]=k; A4[3][2]=l;
130  m=sgn(Determinant(A0,4));
131  if (m==sgn(Determinant(A1,4)) && \
132  m==sgn(Determinant(A2,4)) && \
133  m==sgn(Determinant(A3,4)) && \
134  m==sgn(Determinant(A4,4))) {
135  amat[CONFINEX(j)][CONFINEY(k)][CONFINEZ(l)]=1;
136  }
137  }
138  }
139  tetra=free_3Ddmatrix(tetra);
140  for (i=0; i<4; ++i) delete [] A0[i]; //deallocate
141  delete [] A0;
142  for (i=0; i<4; ++i) delete [] A1[i]; //deallocate
143  delete [] A1;
144  for (i=0; i<4; ++i) delete [] A2[i]; //deallocate
145  delete [] A2;
146  for (i=0; i<4; ++i) delete [] A3[i]; //deallocate
147  delete [] A3;
148  for (i=0; i<4; ++i) delete [] A4[i]; //deallocate
149  delete [] A4;
150  return;
151 }
double Determinant(double **a, int n)
Recursive function for calculation of determinant.
Definition: determinant.cc:54
void makeNodeStruts(int ***amat, int sv, int incmax, int vmax, double **vert, int **vinc, bool report)
Definition: nodes.cc:19
double *** alloc_3Ddmatrix(int nx, int ny, int nz)
allocate 3D double matrix
Definition: allocation.cc:9
Defines global variables, macros, templates and namespace.
real(dp) dstrut
strut diameter
Definition: constants.f90:42
int sgn(T val)
signum
Definition: globals.hh:23
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
int nx
domain size in X
Definition: globals.cc:19
#define CONFINEZ(x)
Periodic boundary conditions in z.
Definition: globals.hh:17
#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
double *** free_3Ddmatrix(double ***amat)
free 3D double matrix
Definition: allocation.cc:37
int ny
domain size in Y
Definition: globals.cc:20