-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf_BD2B_mic.py
308 lines (280 loc) · 10.2 KB
/
perf_BD2B_mic.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
# This example implements 1st-level homogenization of Biot-Darcy-Brinkman model of flow in deformable
# double porous media.
# The mathematical model is described in:
#
#ROHAN E., TURJANICOVA J., LUKES V.
#Multiscale modelling and simulations of tissue perfusion using the Biot-Darcy-Brinkman model.
# Computers & Structures, 2020,
#
# Run calculation of homogenized coefficients:
#
# ./homogen.py example_perfusion_BD2B/perf_BD2B_mic.py
#
# The results are stored in `example_perfusion_BD2B/results/micro` directory.
#
import numpy as nm
from sfepy.mechanics.matcoefs import stiffness_from_youngpoisson
from sfepy.homogenization.utils import define_box_regions
from sfepy.discrete.fem.mesh import Mesh
import sfepy.discrete.fem.periodic as per
import sfepy.homogenization.coefs_base as cb
import os.path as osp
data_dir = 'example_perfusion_BD2B'
#Definition of periodic boundary conditions
def get_periodic_bc(var_tab, dim=3, dim_tab=None):
if dim_tab is None:
dim_tab = {'x': ['left', 'right'],
'z': ['bottom', 'top'],
'y': ['near', 'far']}
periodic = {}
epbcs = {}
for ivar, reg in var_tab:
periodic['per_%s' % ivar] = pers = []
for idim in 'xyz'[0:dim]:
key = 'per_%s_%s' % (ivar, idim)
regs = ['%s_%s' % (reg, ii) for ii in dim_tab[idim]]
epbcs[key] = (regs, {'%s.all' % ivar: '%s.all' % ivar},
'match_%s_plane' % idim)
pers.append(key)
return epbcs, periodic
# define homogenized coefficients and subproblems for correctors
def define(filename_mesh=None):
eps0 = 0.01 # given scale parameter
if filename_mesh is None:
filename_mesh = osp.join(data_dir, 'micro_perf_puc.vtk')
mesh = Mesh.from_file(filename_mesh)
dim = 3
sym = (dim + 1) * dim // 2
sym_eye = 'nm.array([1,1,0])' if dim == 2 else 'nm.array([1,1,1,0,0,0])'
bbox = mesh.get_bounding_box()
regions = define_box_regions(mesh.dim, bbox[0], bbox[1], eps=1e-3)
regions.update({
'Y': 'all',
'Gamma_Y': ('vertices of surface', 'facet'),
# solid matrix
'Ys': 'cells of group 1',
'Ys_left': ('r.Ys *v r.Left', 'vertex'),
'Ys_right': ('r.Ys *v r.Right', 'vertex'),
'Ys_bottom': ('r.Ys *v r.Bottom', 'vertex'),
'Ys_top': ('r.Ys *v r.Top', 'vertex'),
'Gamma_Ysf': ('r.Ys *v r.Yf', 'facet', 'Ys'),
# channel
'Yf': 'cells of group 2',
'Yf0': ('r.Yf -v r.Gamma_Yfs', 'vertex'),
'Yf_left': ('r.Yf0 *v r.Left', 'vertex'),
'Yf_right': ('r.Yf0 *v r.Right', 'vertex'),
'Yf_bottom': ('r.Yf0 *v r.Bottom', 'vertex'),
'Yf_top': ('r.Yf0 *v r.Top', 'vertex'),
'Gamma_Yfs': ('r.Ys *v r.Yf', 'facet', 'Yf'),
})
if dim == 3:
regions.update({
'Ys_far': ('r.Ys *v r.Far', 'vertex'),
'Ys_near': ('r.Ys *v r.Near', 'vertex'),
'Yf_far': ('r.Yf0 *v r.Far', 'vertex'),
'Yf_near': ('r.Yf0 *v r.Near', 'vertex'),
})
fields = {
'volume': ('real', 'scalar', 'Y', 1),
'displacement': ('real', 'vector', 'Ys', 1),
'pressure': ('real', 'scalar', 'Yf', 1),
'velocity': ('real', 'vector', 'Yf', 2),
}
variables = {
# displacement
'u': ('unknown field', 'displacement'),
'v': ('test field', 'displacement', 'u'),
'Pi_u': ('parameter field', 'displacement', 'u'),
'U1': ('parameter field', 'displacement', '(set-to-None)'),
'U2': ('parameter field', 'displacement', '(set-to-None)'),
# velocity
'w': ('unknown field', 'velocity'),
'z': ('test field', 'velocity', 'w'),
'Pi_w': ('parameter field', 'velocity', 'w'),
'W1': ('parameter field', 'velocity', '(set-to-None)'),
'W2': ('parameter field', 'velocity', '(set-to-None)'),
# pressure
'p': ('unknown field', 'pressure'),
'q': ('test field', 'pressure', 'p'),
# volume
'volume': ('parameter field', 'volume', '(set-to-None)'),
}
functions = {
'match_x_plane': (per.match_x_plane,),
'match_y_plane': (per.match_y_plane,),
'match_z_plane': (per.match_z_plane,),
}
materials = {
'matrix': ({'D': stiffness_from_youngpoisson(dim, 1e3, 0.49)},),#Soft tissue
'fluid': ({
'eta_p': 3.6e-3 / eps0**2,#Rescaled blood viscosity
'aux_compress': 1e-18},),#Auxillary compressibility
}
ebcs = {
'fixed_u': ('Corners', {'u.all': 0.0}),
'fixed_w': ('Gamma_Yfs', {'w.all': 0.0}),
}
epbcs, periodic = get_periodic_bc([('u', 'Ys'), ('p', 'Yf'), ('w', 'Yf')])
integrals = {
'i': 4,
}
options = {
'coefs': 'coefs',
'coefs_filename': 'coefs_micro',
'requirements': 'requirements',
'volume': {
'variables': ['u', 'p'],
'expression': 'd_volume.i.Ys(u) + d_volume.i.Yf(p)',
},
'output_dir': data_dir+'/results/micro',
'ls': 'ls',
'file_per_var': True,
'absolute_mesh_path': True,
'multiprocessing': True,
'output_prefix': 'micro:',
}
#Definition of used solvers
solvers = {
'ls': ('ls.mumps', {}),
'ns_em9': ('nls.newton', {
'i_max': 1,
'eps_a': 1e-9,
'eps_r': 1e-3,
'problem': 'nonlinear'}),
'ns_em12': ('nls.newton', {
'i_max': 1,
'eps_a': 1e-12,
'eps_r': 1e-3,
'problem': 'nonlinear'}),
}
#Definition of homogenized coefficients, see (22) and (23)
coefs = {
#Elasticity coefficient
'A': {
'requires': ['pis_u', 'corrs_omega_ij'],
'expression': 'dw_lin_elastic.i.Ys(matrix.D, U1, U2)',
'set_variables': [('U1', ('corrs_omega_ij', 'pis_u'), 'u'),
('U2', ('corrs_omega_ij', 'pis_u'), 'u')],
'class': cb.CoefSymSym,
},
#Biot coefficient
'hat_B': {
'status': 'auxiliary',
'requires': ['corrs_omega_ij'],
'expression': '- ev_div.i.Ys(U1)',
'set_variables': [('U1', 'corrs_omega_ij', 'u')],
'class': cb.CoefSym,
},
'B': {
'requires': ['c.phi_f', 'c.hat_B'],
'expression': 'c.hat_B + c.phi_f * %s' % sym_eye,
'class': cb.CoefEval,
},
'M': {
'requires': ['corrs_omega_p'],
'expression': 'dw_lin_elastic.i.Ys(matrix.D, U1, U2)',
'set_variables': [('U1', 'corrs_omega_p', 'u'),
('U2', 'corrs_omega_p', 'u')],
'class': cb.CoefOne,
},
#Permeability
'K': {
'requires': ['corrs_psi_i'],
'expression': 'dw_div_grad.i.Yf(W1, W2)', # !!!
'set_variables': [('W1', 'corrs_psi_i', 'w'),
('W2', 'corrs_psi_i', 'w')],
'class': cb.CoefDimDim,
},
#Volume fraction of fluid part
'phi_f': {
'requires': ['c.vol'],
'expression': 'c.vol["fraction_Yf"]',
'class': cb.CoefEval,
},
#Coefficient for storing viscosity
'eta_p': {
'expression': '%e' % materials['fluid'][0]['eta_p'],
'class': cb.CoefEval,
},
#Volume fractions
'vol': {
'regions': ['Ys', 'Yf'],
'expression': 'd_volume.i.%s(volume)',
'class': cb.VolumeFractions,
},
#Surface volume fractions
'surf_vol': {
'regions': ['Ys', 'Yf'],
'expression': 'd_surface.i.%s(volume)',
'class': cb.VolumeFractions,
},
'filenames': {},
}
#Definition of microscopic corrector problems
requirements = {
#Definition of \Pi^{ij}_k
'pis_u': {
'variables': ['u'],
'class': cb.ShapeDimDim,
},
#Correcotr like class returning ones
'pis_w': {
'variables': ['w'],
'class': cb.OnesDim,
},
#Corrector problem related to elasticity, see (17)
'corrs_omega_ij': {
'requires': ['pis_u'],
'ebcs': ['fixed_u'],
'epbcs': periodic['per_u'],
'is_linear': True,
'equations': {
'balance_of_forces':
"""dw_lin_elastic.i.Ys(matrix.D, v, u)
= - dw_lin_elastic.i.Ys(matrix.D, v, Pi_u)"""
},
'set_variables': [('Pi_u', 'pis_u', 'u')],
'class': cb.CorrDimDim,
'save_name': 'corrs_omega_ij',
'dump_variables': ['u'],
'solvers': {'ls': 'ls', 'nls': 'ns_em9'},
},
# Corrector problem related to elasticity, see (18)
'corrs_omega_p': {
'requires': [],
'ebcs': ['fixed_u'],
'epbcs': periodic['per_u'],
'equations': {
'balance_of_forces':
"""dw_lin_elastic.i.Ys(matrix.D, v, u)
= -dw_surface_ltr.i.Gamma_Ysf(v)"""
},
'class': cb.CorrOne,
'save_name': 'corrs_omega_p',
'dump_variables': ['u'],
'solvers': {'ls': 'ls', 'nls': 'ns_em3'},
},
#Corrector problem related to velocity, see (19)
'corrs_psi_i': {
'requires': ['pis_w'],
'ebcs': ['fixed_w'],
'epbcs': periodic['per_w'] + periodic['per_p'],
'is_linear': True,
'equations': {
'balance_of_forces': # !!!
"""dw_div_grad.i.Yf(fluid.eta_p,z, w)
- dw_stokes.i.Yf(z, p)
= dw_volume_dot.i.Yf(z, Pi_w)""",
'incompressibility':
"""dw_stokes.i.Yf(w, q)
+ dw_volume_dot.i.Yf(fluid.aux_compress, q, p)
= 0""",#
},
'set_variables': [('Pi_w', 'pis_w', 'w')],
'class': cb.CorrDim,
'save_name': 'corrs_psi_i',
'dump_variables': ['w', 'p'],
'solvers': {'ls': 'ls', 'nls': 'ns_em12'},
},
}
return locals()