forked from MJ0706/HCM-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms_MRC2.py
713 lines (473 loc) · 16 KB
/
forms_MRC2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
from dolfin import *
import sys
class Forms(object):
def __init__(self, params):
self.parameters = self.default_parameters()
self.parameters.update(params)
Matmodel = self.parameters["material model"]["Name"]
assert (Matmodel == "Guccione" or Matmodel == "HolzapfelOgden"), "Material model not implemented"
self.parameters.update({"F": self.Fe()})
if(Matmodel == "Guccione"):
from GuccionePas import GuccionePas as Passive
if(Matmodel == "HolzapfelOgden"):
from holzapfelogden import HolzapfelOgden as Passive
self.passiveforms = Passive(self.parameters)
self.matparams = self.passiveforms.Getmatparam()
def default_parameters(self):
return {"material model": {"Name": "Guccione"},
"Kappa": 1e5,
"incompressible" : True,
};
def PassiveMatSEF(self):
Wp = self.passiveforms.PassiveMatSEF() + self.Wvolumetric()
return Wp
def PK1(self):
PK1 = self.PK1volumetric() + self.passiveforms.PK1()
return PK1
def PK2(self):
PK2 = inv(self.Fmat())*self.PK1()
return PK2
def sigma(self):
sigma = 1.0/self.J()*self.PK1()*transpose(self.Fmat())
return sigma
def Fmat(self):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = I + grad(u)
return F
def Fe(self):
Fg = self.parameters["growth_tensor"]
F = self.Fmat()
if (Fg is None):
Fe = F
else:
Fe = as_tensor(F[i,j]*inv(Fg)[j,k], (i,k))
return Fe
def Emat(self):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()
return 0.5*(as_tensor(F[k,i]*F[k,j] - I[i,j], (i,j)))
def J(self):
F = self.Fe()
return det(F)
def Wvolumetric(self):
isincomp = self.parameters["incompressible"]
u = self.parameters["displacement_variable"]
d = u.geometric_dimension()
I = Identity(d)
F = I + grad(u)
F = dolfin.variable(F)
J = det(F)
if(isincomp):
p = self.parameters["pressure_variable"]
Wvolumetric = -1.0*p*(J - 1.0)
else:
Kappa = self.parameters["Kappa"]
Wvolumetric = Kappa/2.0*(J - 1.0)**2.0
return Wvolumetric
def PK1volumetric(self):
isincomp = self.parameters["incompressible"]
u = self.parameters["displacement_variable"]
d = u.geometric_dimension()
I = Identity(d)
F = I + grad(u)
F = dolfin.variable(F)
J = det(F)
if(isincomp):
p = self.parameters["pressure_variable"]
Wvolumetric = -1.0*p*(J - 1.0)
PK1volumetric = dolfin.diff(Wvolumetric, F)
else:
Kappa = self.parameters["Kappa"]
Wvolumetric = Kappa/2.0*(J - 1.0)**2.0
PK1volumetric = dolfin.diff(Wvolumetric, F)
return PK1volumetric
def LVcavityvol(self):
u = self.parameters["displacement_variable"]
N = self.parameters["facet_normal"]
mesh = self.parameters["mesh"]
X = SpatialCoordinate(mesh)
ds = dolfin.ds(subdomain_data = self.parameters["facetboundaries"])
F = self.Fmat()
vol_form = -Constant(1.0/3.0) * inner(det(F)*dot(inv(F).T, N), X + u)*ds(self.parameters["LVendoid"])
return assemble(vol_form, form_compiler_parameters={"representation":"uflacs"})
def RVcavityvol(self):
u = self.parameters["displacement_variable"]
N = self.parameters["facet_normal"]
mesh = self.parameters["mesh"]
X = SpatialCoordinate(mesh)
ds = dolfin.ds(subdomain_data = self.parameters["facetboundaries"])
F = self.Fmat()
vol_form = -Constant(1.0/3.0) * inner(det(F)*dot(inv(F).T, N), X + u)*ds(self.parameters["RVendoid"])
return assemble(vol_form, form_compiler_parameters={"representation":"uflacs"})
def LVcavitypressure(self):
W = self.parameters["mixedfunctionspace"]
w = self.parameters["mixedfunction"]
mesh = self.parameters["mesh"]
comm = W.mesh().mpi_comm()
dofmap = W.sub(self.parameters["LVendo_comp"]).dofmap()
val_dof = dofmap.cell_dofs(0)[0]
# the owner of the dof broadcasts the value
own_range = dofmap.ownership_range()
try:
val_local = w.vector()[val_dof][0]
except IndexError:
val_local = 0.0
pressure = MPI.sum(comm, val_local)
return pressure
def RVcavitypressure(self):
W = self.parameters["mixedfunctionspace"]
w = self.parameters["mixedfunction"]
mesh = self.parameters["mesh"]
comm = W.mesh().mpi_comm()
dofmap = W.sub(self.parameters["RVendo_comp"]).dofmap()
val_dof = dofmap.cell_dofs(0)[0]
# the owner of the dof broadcasts the value
own_range = dofmap.ownership_range()
try:
val_local = w.vector()[val_dof][0]
except IndexError:
val_local = 0.0
pressure = MPI.sum(comm, val_local)
return pressure
def LVV0constrainedE(self):
mesh = self.parameters["mesh"]
u = self.parameters["displacement_variable"]
ds = dolfin.ds(subdomain_data = self.parameters["facetboundaries"])
dsendo = ds(self.parameters["LVendoid"], domain = self.parameters["mesh"], subdomain_data = self.parameters["facetboundaries"])
area = self.parameters["LVendo_area"]
pendo = self.parameters["lv_volconst_variable"]
V0= self.parameters["lv_constrained_vol"]
X = SpatialCoordinate(mesh)
x = u + X
F = self.Fmat()
N = self.parameters["facet_normal"]
n = cofac(F)*N
V_u = - Constant(1.0/3.0) * inner(x, n)
Wvol = (Constant(1.0)/area * pendo * V0 * dsendo) - (pendo * V_u *dsendo)
return Wvol
def RVV0constrainedE(self):
mesh = self.parameters["mesh"]
u = self.parameters["displacement_variable"]
ds = dolfin.ds(subdomain_data = self.parameters["facetboundaries"])
dsendo = ds(self.parameters["RVendoid"], domain = self.parameters["mesh"], subdomain_data = self.parameters["facetboundaries"])
pendo = self.parameters["rv_volconst_variable"]
V0= self.parameters["rv_constrained_vol"]
X = SpatialCoordinate(mesh)
x = u + X
F = self.Fmat()
N = self.parameters["facet_normal"]
n = cofac(F)*N
area = assemble(Constant(1.0) * dsendo, form_compiler_parameters={"representation":"uflacs"})
V_u = - Constant(1.0/3.0) * inner(x, n)
Wvol = (Constant(1.0/area) * pendo * V0 * dsendo) - (pendo * V_u *dsendo)
return Wvol
def fiberstress_wokappa(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
f0 = self.parameters["fiber"]
return f0[i]*Sca[i,j]*f0[j]
def sheetstress(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
s0 = self.parameters["sheet"]
return s0[i]*Sca[i,j]*s0[j]
def normalstress(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
n0 = self.parameters["sheet-normal"]
return n0[i]*Sca[i,j]*n0[j]
def fiberstress_1(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
H = self.passiveforms.structTensor()
fstress = tr(Sca*H)
return fstress
def fiberstress_2(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
f0 = self.parameters["fiber"]
Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
H = self.passiveforms.structTensor()
fstress = f0[i]*Sca[i,j]*f0[j]
return fstress
def fiberstress_3(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
f0 = self.parameters["fiber"]
Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
H = self.passiveforms.structTensor()
fstress = f0[i]*Sca[i,j]*f0[j]
kappa = self.passiveforms.parameters["material params"]["kappa"]
return (1-3*kappa)*fstress
def fiberstress_4(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
f0 = self.parameters["fiber"]
Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
H = self.passiveforms.structTensor()
fstress = f0[i]*Sca[i,j]*f0[j]
kappa = self.passiveforms.parameters["material params"]["kappa"]
return (1-2*kappa)*fstress
def fiberstrain_1(self, F_ref):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()*inv(F_ref)
f0 = self.parameters["fiber"]
Emat = 0.5*(as_tensor(F[k,i]*F[k,j] - I[i,j], (i,j)))
H = self.passiveforms.structTensor()
fstrain = tr(Emat*H)
return fstrain #f0[i]*Emat[i,j]*f0[j]
def fiberstrain_2(self, F_ref):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()*inv(F_ref)
f0 = self.parameters["fiber"]
Emat = 0.5*(as_tensor(F[k,i]*F[k,j] - I[i,j], (i,j)))
#H = self.passiveforms.structTensor()
#fstrain = tr(Emat*H)
return f0[i]*Emat[i,j]*f0[j]
def fiberstrain_3(self, F_ref):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()*inv(F_ref)
f0 = self.parameters["fiber"]
Emat = 0.5*(as_tensor(F[k,i]*F[k,j] - I[i,j], (i,j)))
#H = self.passiveforms.structTensor()
#fstrain = tr(Emat*H)
kappa = self.passiveforms.parameters["material params"]["kappa"]
fstrain = f0[i]*Emat[i,j]*f0[j]
return (1-3*kappa)*fstrain
def fiberstrain_4(self, F_ref):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()*inv(F_ref)
f0 = self.parameters["fiber"]
Emat = 0.5*(as_tensor(F[k,i]*F[k,j] - I[i,j], (i,j)))
#H = self.passiveforms.structTensor()
#fstrain = tr(Emat*H)
kappa = self.passiveforms.parameters["material params"]["kappa"]
fstrain = f0[i]*Emat[i,j]*f0[j]
return (1-2*kappa)*fstrain
def sheetstrain(self, F_ref):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()*inv(F_ref)
s0 = self.parameters["sheet"]
Emat = 0.5*(as_tensor(F[k,i]*F[k,j] - I[i,j], (i,j)))
return s0[i]*Emat[i,j]*s0[j]
def normalstrain(self, F_ref):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()*inv(F_ref)
n0 = self.parameters["sheet-normal"]
Emat = 0.5*(as_tensor(F[k,i]*F[k,j] - I[i,j], (i,j)))
return n0[i]*Emat[i,j]*n0[j]
def fiberstrainalmansi(self, F_ref):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()*inv(F_ref)
f0 = self.parameters["fiber"]
b = F*F.T
B = inv(b)
emat = 0.5*(I-B)
H = self.passiveforms.structTensor()
hi = H*F.T
h = F*hi
fstrain = tr(emat*H)
#fstrain = tr(emat*h.T)
return fstrain
def fiberstrain_wokappa(self, F_ref):
u = self.parameters["displacement_variable"]
d = u.ufl_domain().geometric_dimension()
I = Identity(d)
F = self.Fe()*inv(F_ref)
f0 = self.parameters["fiber"]
Emat = 0.5*(as_tensor(F[k,i]*F[k,j] - I[i,j], (i,j)))
return f0[i]*Emat[i,j]*f0[j]
def fiberwork(self, F_ref):
F = self.Fe()*inv(F_ref)
J = self.J()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
f0 = self.parameters["fiber"]
Emat = self.Emat()
H = self.passiveforms.structTensor()
strain = tr(H*Emat)
stress = tr(H*Sca)
#f = f0[i]*Sca[i,j]*f0[j]
#s = f0[i]*Emat[i,j]*f0[j]
return strain*stress #dot(f,s)
def IMP(self):
u = self.parameters["displacement_variable"]
J = self.J()
f0 = self.parameters["fiber"]
s0 = self.parameters["sheet"]
n0 = self.parameters["sheet-normal"]
#F = self.Fmat()
F = self.Fe()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
s = F*s0/sqrt(inner(F*s0, F*s0))
n = F*n0/sqrt(inner(F*n0, F*n0))
Ipressure = s[i]*Tca[i,j]*s[j]
return Ipressure
def IMP2(self):
u = self.parameters["displacement_variable"]
J = self.J()
f0 = self.parameters["fiber"]
s0 = self.parameters["sheet"]
n0 = self.parameters["sheet-normal"]
#F = self.Fmat()
F = self.Fe()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
s = F*s0/sqrt(inner(F*s0, F*s0))
n = F*n0/sqrt(inner(F*n0, F*n0))
Ipressure = 0.5*(s[i]*Tca[i,j]*s[j] + n[i]*Tca[i,j]*n[j])
return Ipressure
def IMPendo(self):
u = self.parameters["displacement_variable"]
N = self.parameters["facet_normal"]
F = self.Fe()
PK1 = self.PK1()
ds = dolfin.ds(subdomain_data = self.parameters["facetboundaries"])
n = F*N/sqrt(inner(F*N, F*N))
Ipressure = -n[i]*PK1[i,j]*N[j]*ds(self.parameters["LVendoid"])
return Ipressure
def IMPepi(self):
u = self.parameters["displacement_variable"]
N = self.parameters["facet_normal"]
F = self.Fe()
PK1 = self.PK1()
ds = dolfin.ds(subdomain_data = self.parameters["facetboundaries"])
n = F*N/sqrt(inner(F*N, F*N))
Ipressure = -n[i]*PK1[i,j]*N[j]*ds(self.parameters["epiid"])
return Ipressure
def areaendo(self):
u = self.parameters["displacement_variable"]
f0 = self.parameters["fiber"]
s0 = self.parameters["sheet"]
n0 = self.parameters["sheet-normal"]
d = u.geometric_dimension()
I = Identity(d)
F = I + grad(u)
J = det(F)
s = F*s0/sqrt(inner(F*s0, F*s0))
N = self.parameters["facet_normal"]
ds = dolfin.ds(subdomain_data = self.parameters["facetboundaries"])
n = F*N/sqrt(inner(F*N, F*N))
return (J*inv(F.T)*N)[i]*n[i]*ds(self.parameters["endoid"])
def areaepi(self):
u = self.parameters["displacement_variable"]
f0 = self.parameters["fiber"]
s0 = self.parameters["sheet"]
n0 = self.parameters["sheet-normal"]
d = u.geometric_dimension()
I = Identity(d)
F = I + grad(u)
J = det(F)
s = F*s0/sqrt(inner(F*s0, F*s0))
N = self.parameters["facet_normal"]
ds = dolfin.ds(subdomain_data = self.parameters["facetboundaries"])
n = F*N/sqrt(inner(F*N, F*N))
return (J*inv(F.T)*N)[i]*n[i]*ds(self.parameters["epiid"])
def globalfiberstress(self):
u = self.parameters["displacement_variable"]
f0 = self.parameters["fiber"]
F = self.Fmat()
J = self.J()
W = self.passiveforms.TotalPasMatSEF(diff=0) + self.Wvolumetric()
#F = dolfin.variable(F)
#PK1 = dolfin.diff(W,F)
PK1 = self.PK1()
mesh1 = self.parameters["mesh"]
dx = dolfin.dx(mesh1) #(subdomain_data = self.parameters["facetboundaries"])
#Tca = (1.0/J)*PK1*F.T
#Sca = inv(F)*PK1
kappa = self.passiveforms.parameters["material params"]["kappa"]
d = u.geometric_dimension()
I = Identity(d)
H = kappa*I + (1-3*kappa)*as_tensor(f0[i]*f0[j], (i,j))
fstress = tr(H*PK1)
volume = assemble(Constant(1.0)*dx, form_compiler_parameters={"representation":"uflacs"})
stress = assemble(fstress*dx, form_compiler_parameters={"representation":"uflacs"})/volume
return stress #f0[i]*Sca[i,j]*f0[j]
def globalfiberstretch(self):
I4 = self.passiveforms.globalpassivefstretch()
mesh1 = self.parameters["mesh"]
dx = dolfin.dx(mesh1)
volume = assemble(Constant(1.0)*dx, form_compiler_parameters={"representation":"uflacs"})
stretch = assemble(I4*dx, form_compiler_parameters={"representation":"uflacs"})/volume
return stretch #f0[i]*Sca[i,j]*f0[j]
def FiberCauchyStress(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
#Sca = inv(F)*PK1
H = self.passiveforms.structTensor()
hi = H*F.T
h = F*hi
fstress = tr(Tca*H)
return fstress
def FiberPk2Stress(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
#Tca = (1.0/J)*PK1*F.T
Sca = inv(F)*PK1
H = self.passiveforms.structTensor()
hi = H*F.T
h = F*hi
fstress = tr(Sca*H)
return fstress
def SheetCauchyStress(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
#Sca = inv(F)*PK1
ef0 = self.parameters["sheet"]
ef = (F*ef0)/sqrt(inner(F*ef0, F*ef0))
fstress = dot(Tca*ef, ef)
return fstress
def SheetnormalCauchyStress(self):
F = self.Fmat()
J = self.J()
PK1 = self.PK1()
Tca = (1.0/J)*PK1*F.T
#Sca = inv(F)*PK1
ef0 = self.parameters["sheet-normal"]
ef = (F*ef0)/sqrt(inner(F*ef0, F*ef0))
fstress = dot(Tca*ef, ef)
return fstress