Statistiques
| Révision :

root / Parameters_fs / pulvinus-images.cpp @ 19

Historique | Voir | Annoter | Télécharger (10,32 ko)

1
include "getARGV.idp"
2
//include "bib_meca2d.cpp"
3

    
4
//usage :
5
//Freefem++ pulvinus.edp [-fE fEvalue] [-Nit Nit] [-geometry g]
6
//arguments:
7
//-fE fEvalue:
8
//-Nit Nit: number of iterations
9
//-geometry g: differnet geometries
10
//1: 
11
//2: 
12
//3: 
13

    
14

    
15

    
16
func real lineD(real xA, real xB, real yA, real yB)
17
{        return (yB-yA)/(xB-xA);
18
}
19

    
20
func real lineC(real xA, real xB, real yA, real yB)
21
{        return (yA*xB-yB*xA)/(xB-xA);
22
}
23

    
24
//real PI=3.14159265;
25

    
26
func real angleToVertical(real Mx, real My, real Nx, real Ny)
27
{ /*  Computes the sinus of angle between the MN vector and Oy   */
28
        return asin((Nx-Mx)/sqrt((Mx-Nx)^2+(My-Ny)^2))*180/pi;
29
}
30

    
31

    
32
/*************************************************************
33
 *                  PARAMETERS
34
 * **********************************************************/
35
 
36
// reading script arguments
37
for (int i=0;i<ARGV.n;++i)
38
{ cout << ARGV[i] << " ";}
39
cout<<endl;
40

    
41
verbosity = getARGV("-vv", 0);
42
int vdebug = getARGV("-d", 1);
43
//real fE = getARGV("-fE", 0.2);
44
real sm = -getARGV("-sm", 0.95);// measured value
45
real fs = getARGV("-fs", 0.02);
46
int Nit = getARGV("-Nit", 1);
47
string geom = getARGV("-geometry", "1");
48
string output = getARGV("-out", ".");
49

    
50

    
51
int hyp=getARGV("-hyp", 1);
52

    
53
cout<<"----------------------------------------------"<< endl;
54
cout<<"Hypothesis no. "<<hyp<< ":   sm="<<sm<< endl;
55

    
56
// ---------------- geometrical parameters
57

    
58
// (lengths are measured in micrometers)
59
real units=200;
60

    
61
// pulvinus dimensions
62
real lx=491.0/units;       //sd =34.4
63
real ly= 240.0/units;      //sd=36.0
64

    
65
// nectary height
66
real hnect = 38.8/units;   //sd=9.6
67
real R=363.0/units;    //sd=49.4
68

    
69
// side dimensions
70
real hside=91.4/units;     //12.6
71
real lside=47.6/units/2;     //6.6
72

    
73
// vasculature dimensions
74
real vthickness=34.3/units;//5.5
75
real cwidth=74.8/units;    //15.2
76
real cwidthdry=44.2/units; //8.4
77

    
78
// vasculature displacement (from vascular bundle distance)
79
real vd=(cwidth-cwidthdry)/2;
80
real vposition=lx/2-vthickness-hnect/ly*(lx/2-cwidth/2-vthickness); //cout<<"vposition="<<vposition<<endl;
81

    
82
// mesh parameters
83
int nvertex=50; cout << "nvertex="<<nvertex<<endl;
84
real pinned=lx/nvertex/2;
85

    
86

    
87
// ---------------- Material properties
88

    
89
real nu = 0.29;    // Poisson's ratio
90

    
91
// Young modulus
92
real Ev;   // vasculature Young modulus
93
real fEm; // mesophyl Em/Ev 
94
real fEn;  // nectary  En/Ev 
95
real fEs;  // side     Es/Ev 
96

    
97
// hydrophobicity as swelling ability
98
//   sm        // mesophyl swelling property
99
real fsn;   // nectary     sn/sm
100
real fss;   // side        ss/sm
101
real fsv;   // vasculature sv/sm
102

    
103

    
104
        
105
// measured values for the density
106
//Region,Mean_tissue_density,SD_tissue_density
107
real dm=0.668060839; //sd=0.04091249
108
real dn=1.01896008; //sd=0.015464575
109
real ds=0.918032482; //sd=0.075097509
110
real dv=0.882171532; //sd=0.066651037
111

    
112
real nEd=1.0;
113

    
114

    
115
// Young modulus
116
Ev=1;   // vasculature Young modulus
117
fEm=(dm/dv)^nEd; // mesophyl Em/Ev 
118
fEn=(dn/dv)^nEd;  // nectary  En/Ev 
119
fEs=(ds/dv)^nEd;  // side     Es/Ev 
120

    
121
// hydrophobicity as swelling ability
122
cout << "hyp="<<hyp<<"============================="<<endl;
123

    
124
if (hyp==1) 
125
{
126
fsn=fs;   // nectary     sn/sm
127
fss=fs;   // side        ss/sm
128
fsv=fs;   // vasculature sv/sm
129
}
130

    
131

    
132
if (hyp==2) 
133
{
134
fsn=fs;   // nectary     sn/sm
135
fss=1;   // side        ss/sm
136
fsv=fs;   // vasculature sv/sm
137
}
138

    
139
if (hyp==3) 
140
{
141
fsn=1;   // nectary     sn/sm
142
fss=1;   // side        ss/sm
143
fsv=fs;   // vasculature sv/sm
144
}
145

    
146
if (hyp==4) 
147
{
148
fsn=1;   // nectary     sn/sm
149
fss=fs;   // side        ss/sm
150
fsv=fs;   // vasculature sv/sm
151
}
152

    
153

    
154

    
155
/*************************************************************
156
 *                  GEOMETRY and MESH
157
 * **********************************************************/
158

    
159
string geomfilename="geometry"+geom+".cpp";
160
cout<<"including "<<geomfilename<<endl;
161
include "geometry1.cpp";
162

    
163
// -------------------- define the finite element space
164

    
165
fespace Vh(Th,[P2,P2]);  // vector on the mesh (displacement vector)
166
Vh [u1,u2], [v1,v2];
167

    
168
fespace Sh(Th, P2);   // scalar on the mesh, P2 elements
169
fespace Sh0(Th,P0);   // scalar on the mesh, P0 elements
170
fespace Sh1(Th,P1);   // scalar on the mesh, P1 elements
171

    
172
Sh0 strain, stress;
173

    
174
// bounding box for the plot (use the same for all images so that they can be superposed)
175
func bb=[[-lx/2*1.5,-ly*1],[lx/2*1.5,ly*.1]];
176
real coef=1;
177
cout << "Coefficent of amplification:"<<coef<<endl;
178
//plot(Th, fill=1, ps=output+"/original_geometry.png", bb=bb); -------------------------------
179

    
180
// macro to redefine variables on the displaced mesh 
181
macro redefineVariable(vvv)
182
{        real[int] temp(vvv[].n);
183
        temp=vvv[]; vvv=0; vvv[]=temp;
184
        vvv=vvv;
185
}//
186

    
187

    
188
real sqrt2=sqrt(2.);
189
macro epsilon(u1,u2)  [dx(u1),dy(u2),(dy(u1)+dx(u2))/sqrt2] // EOM
190
//the sqrt2 is because we want: epsilon(u1,u2)'* epsilon(v1,v2) $==  \epsilon(\bm{u}): \epsilon(\bm{v})$
191
macro div(u1,u2) ( dx(u1)+dy(u2) ) // EOM
192

    
193
/*************************************************************
194
 *                  MECHANICS
195
 * **********************************************************/
196

    
197
// definition of integer functions for the structural domains
198
func vasculature=int(vasculatureBool(x,y));
199
func nectary=int(nectaryBool(x,y));
200
func side=int(sideBool(x,y));
201
func mesophyl=int(mesophylBool(x,y));
202
func geometry = 1*vasculature + 3*nectary + 2*side + 4*mesophyl;
203

    
204
// definition of FE variables for the structural domains
205
Sh0 vasculatureh=vasculature;
206
//plot(vasculatureh,wait=1,value=true,fill=1, ps=output+"/vasculature-original.png", bb=bb);
207

    
208
Sh0 nectaryh=nectary;
209
//plot(nectaryh,wait=1,value=true,fill=1, ps=output+"/nectary-original.png", bb=bb);
210

    
211
Sh0 sideh=side;
212
//plot(sideh,wait=1,value=true,fill=1, ps=output+"/side-original.png", bb=bb);
213

    
214
Sh0 mesophylh=mesophyl;
215
//plot(mesophylh,wait=1,value=true,fill=1, ps=output+"/mesophyl-original.png", bb=bb);
216

    
217
Sh0 geometryh=geometry;
218
string fname=output+"/geometry-original.png";
219
plot(geometryh,fill=1, ps=fname, bb=bb);
220

    
221
// spatial dependence of Young modulus
222
func E=Ev*(vasculature + fEn*nectary + fEs*side + fEm*mesophyl);
223
Sh0 Eh=E;
224

    
225
// spatial dependence of the swelling property
226
func s=sm*(fsv*vasculature + fsn*nectary + fss*side + mesophyl);
227
Sh0 sh=s;
228

    
229
func mu=E/(2*(1+nu));
230
func lambda=E*nu/((1+nu)*(1-2*nu));
231
func K=lambda+2*mu/3;
232

    
233
// ------ iterations
234

    
235
{
236

    
237

    
238
/*************************************************************
239
 *                  SOLVING THE FEM
240
 * **********************************************************/
241

    
242
solve Lame([u1,u2],[v1,v2])=
243
  int2d(Th)(
244
            lambda*div(u1,u2)*div(v1,v2)         
245
            + 2.*mu*( epsilon(u1,u2)'*epsilon(v1,v2) ) 
246
              )
247
  - int2d(Th) ( K*sh*div(v1,v2))
248
  + on(32,u1=vd,u2=0)
249
  + on(33,u1=-vd,u2=0) 
250
  ;
251

    
252

    
253
stress=2*K*(strain-s);
254

    
255
Sh0 e11=dx(u1)+1.;
256
Sh0 e12=1/2.*(dx(u2) + dy(u1));
257
Sh0 e22=dy(u2)+1.;
258

    
259
strain=e11+e22 ;
260
Sh0 Det=e11*e22-e12*e12;
261

    
262
Sh0 l1=abs(strain+sqrt(strain*strain-4*Det))/2.;
263
Sh0 l2=abs(strain-sqrt(strain*strain-4*Det))/2.;
264

    
265
Sh0 lmax=(l1-l2+abs(l1-l2))/2.+l2;
266
Sh0 lmin=(l1-l2-abs(l1-l2))/2.+l2;
267

    
268
Sh0 strainanisotropy=lmin/lmax;
269

    
270

    
271
/*************************************************************
272
 *                  VISUALISATION
273
 * **********************************************************/
274
real voltotal0=int2d(Th)(1);
275
real volvasculature0=int2d(Th)(vasculatureh);
276
real volnectary0=int2d(Th)(nectaryh);
277
real volmesophyl0=int2d(Th)(mesophylh);
278
real volside0=int2d(Th)(sideh);
279

    
280
cout<<"Original volume="<<voltotal0<<endl;
281
cout<<"Original vasculature volume="<<volvasculature0<<endl;
282

    
283

    
284
// compute mean strain per region
285
real straintotal=int2d(Th)(strain)/voltotal0;
286
real strainvasculature=int2d(Th)(strain*vasculatureh)/volvasculature0;
287
real strainnectary=int2d(Th)(strain*nectaryh)/volnectary0;
288
real strainside=int2d(Th)(strain*sideh)/volside0;
289
real strainmesophyl=int2d(Th)(strain*mesophylh)/volmesophyl0;
290

    
291

    
292
// compute mean strain anisotropy per region
293
real satotal=int2d(Th)(strainanisotropy)/voltotal0;
294
real savasculature=int2d(Th)(strainanisotropy*vasculatureh)/volvasculature0;
295
real sanectary=int2d(Th)(strainanisotropy*nectaryh)/volnectary0;
296
real saside=int2d(Th)(strainanisotropy*sideh)/volside0;
297
real samesophyl=int2d(Th)(strainanisotropy*mesophylh)/volmesophyl0;
298

    
299

    
300
cout<<"Mean strain and strain anisotropy per region :"<<endl;
301
cout<<"Mesophyll:"<<strainmesophyl<<"   "<<samesophyl<<endl;
302
cout<<"Nectary:"<<strainnectary<<"   "<<sanectary<<endl;
303
cout<<"Side:"<<strainside<<"   "<<saside<<endl;
304
cout<<"Vasculature:"<<strainvasculature<<"   "<<savasculature<<endl;
305
cout<<"Total:"<<straintotal<<"   "<<satotal<<endl;
306

    
307
mesh Th0=Th;
308
Th=movemesh(Th,[x+u1*coef,y+u2*coef]);
309

    
310
plot(Th, Th0, ps=output+"/geometry-deformed-superposed_hyp"+string(hyp)+"_sm"+string(sm)+"_fs"+string(fs)+".png",bb=bb);
311

    
312

    
313
redefineVariable(strain);
314
redefineVariable(stress);
315
plot(strain, fill=1,wait=1,value=true, ps="strain.png",bb=bb);
316
plot(stress, fill=1,wait=1,value=true, ps="stress.png",bb=bb);
317

    
318

    
319
redefineVariable(geometryh);
320
plot(geometryh, fill=1, ps=output+"/geometry-deformed_hyp"+string(hyp)+"_sm"+string(sm)+".png",bb=bb);
321

    
322
redefineVariable(vasculatureh);
323
redefineVariable(nectaryh);
324
redefineVariable(sideh);
325
redefineVariable(mesophylh);
326

    
327
// compute structure volumes
328
real voltotal=int2d(Th)(1);
329
real volvasculature=int2d(Th)(vasculatureh);
330
real volnectary=int2d(Th)(nectaryh);
331
real volside=int2d(Th)(sideh);
332
real volmesophyl=int2d(Th)(mesophylh);
333

    
334
cout<<"Deformed total volume="<<voltotal<<endl;
335
cout<<"Deformed vasculature volume="<<volvasculature<<endl;
336

    
337

    
338
/*************************************************************
339
 *         LOOKING FOR ANGLE AND NECKHEIGHT
340
 * **********************************************************/
341

    
342
// displaced upper corner
343
real Nx=lx/2+u1(lx/2.,0), Ny=u2(lx/2.,0);
344

    
345

    
346
// compute tangentangle
347
real height=ly/nvertex/100;
348
real Mx=lx/2+u1(lx/2.,-height), My=-height+u2(lx/2.,-height);
349
real tangentangle=angleToVertical(Mx, My, Nx, Ny);
350
cout<<"Tangent angle="<<tangentangle<<endl;
351

    
352
// compute sideangle
353
height=hside;
354
Mx=lx/2+u1(lx/2.,-height); My=-height+u2(lx/2.,-height);
355
real sideangle=angleToVertical(Mx, My, Nx, Ny);
356

    
357

    
358
cout<<"Side angle="<<sideangle<<endl;
359

    
360

    
361
real am=volmesophyl0/volmesophyl;
362
real an=volnectary0/volnectary;
363
real as=volside0/volside;
364
real av=volvasculature0/volvasculature;
365

    
366

    
367

    
368
ofstream textfile(output+"/results.csv", append);
369
        
370
/*
371
hyp;fs;tangentangle;sideangle;am;an;as;av;sam;san;sas;sav
372
*/
373

    
374
textfile<<hyp<<";"<<fs<<";"<<tangentangle/38<<";"<<sideangle/38
375
<<";"<<am<<";"<<an<<";"<<as<<";"<<av
376
<<";"<<samesophyl<<";"<<sanectary<<";"<<saside<<";"<<savasculature
377
<<endl;
378

    
379

    
380

    
381

    
382
}//end for iteration loop
383

    
384

    
385

    
386
/*************************************************************
387
 *         Writing results
388
 * **********************************************************/
389
 
390
 
391