Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jigyasa Watwani
/
growth-pattern-control
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2c482e06
authored
Nov 10, 2022
by
Vijay Kumar Krishnamurthy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working 1D/2D/3D all growth models. Need to benchmark with exact solution
parent
581100ec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
65 deletions
growing_domain/diffusion_on_growing_domain.py
growing_domain/diffusion_on_growing_domain.py
View file @
2c482e06
import
dolfin
as
df
import
dolfin
as
df
import
mshr
as
ms
import
numpy
as
np
import
numpy
as
np
import
progressbar
import
progressbar
import
os
import
os
import
meshzoo
df
.
set_log_level
(
df
.
LogLevel
.
ERROR
)
df
.
set_log_level
(
df
.
LogLevel
.
ERROR
)
df
.
parameters
[
'form_compiler'
][
'optimize'
]
=
True
df
.
parameters
[
'form_compiler'
][
'optimize'
]
=
True
...
@@ -12,40 +12,27 @@ class GrowthDiffusion(object):
...
@@ -12,40 +12,27 @@ class GrowthDiffusion(object):
# read in parameters
# read in parameters
for
key
in
parameters
:
for
key
in
parameters
:
setattr
(
self
,
key
,
parameters
[
key
])
setattr
(
self
,
key
,
parameters
[
key
])
sigma
=
{
'none'
:
'0.0'
,
'linear'
:
'b/(L0+b*t)'
,
'exponential'
:
'b'
}
# define the growth velocity field
growth_direction
=
tuple
([
'x['
+
str
(
i
)
+
']'
for
i
in
range
(
self
.
dimension
)])
#growth_direction = ('x[0]', )
self
.
growth_direction
=
df
.
Expression
(
growth_direction
,
degree
=
1
)
self
.
sigma
=
df
.
Expression
(
sigma
[
self
.
growth
],
L0
=
self
.
system_size
,
b
=
self
.
growth_parameter
,
t
=
0
,
degree
=
1
)
# set up mesh
# set up mesh
# and define the growth velocity field
if
self
.
dimension
==
1
:
if
self
.
dimension
==
1
:
if
self
.
growth
==
'none'
:
self
.
velocity
=
df
.
Expression
((
's*x[0]'
,),
s
=
df
.
Constant
(
0
),
t
=
0
,
degree
=
0
)
if
self
.
growth
==
'linear'
:
self
.
velocity
=
df
.
Expression
((
'b*x[0]/(L0 + b*t)'
,),
b
=
self
.
growth_parameter
,
L0
=
self
.
system_size
,
t
=
0
,
degree
=
0
)
if
self
.
growth
==
'exponential'
:
self
.
velocity
=
df
.
Expression
((
's*x[0]'
),
s
=
df
.
Constant
(
self
.
growth_parameter
),
t
=
0
,
degree
=
0
)
self
.
mesh
=
df
.
IntervalMesh
(
self
.
resolution
,
0
,
self
.
system_size
)
self
.
mesh
=
df
.
IntervalMesh
(
self
.
resolution
,
0
,
self
.
system_size
)
elif
self
.
dimension
==
2
:
elif
self
.
dimension
==
2
:
geometry
=
ms
.
Circle
(
df
.
Point
(
0
,
0
),
self
.
system_size
)
if
self
.
growth
==
'none'
:
self
.
mesh
=
ms
.
generate_mesh
(
geometry
,
self
.
resolution
)
self
.
velocity
=
df
.
Expression
((
's*x[0]'
,
's*x[1]'
),
s
=
df
.
Constant
(
0
),
t
=
0
,
degree
=
0
)
elif
self
.
dimension
==
3
:
if
self
.
growth
==
'linear'
:
geometry
=
ms
.
Sphere
(
df
.
Point
(
0
,
0
,
0
),
self
.
system_size
)
self
.
velocity
=
df
.
Expression
((
'b*x[0]/(L0 + b*t)'
,
'b*x[1]/(L0 + b*t)'
),
b
=
self
.
growth_parameter
,
L0
=
self
.
system_size
,
t
=
0
,
degree
=
0
)
self
.
mesh
=
ms
.
generate_mesh
(
geometry
,
self
.
resolution
)
if
self
.
growth
==
'exponential'
:
self
.
velocity
=
df
.
Expression
((
's*x[0]'
,
's*x[1]'
),
s
=
df
.
Constant
(
self
.
growth_parameter
),
t
=
0
,
degree
=
0
)
points
,
cells
=
meshzoo
.
disk
(
self
.
resolution
,
2
*
self
.
resolution
)
points
*=
self
.
system_size
self
.
mesh
=
df
.
Mesh
()
e
=
df
.
MeshEditor
()
e
.
open
(
self
.
mesh
,
type
=
'triangle'
,
tdim
=
2
,
gdim
=
2
)
e
.
init_vertices
(
len
(
points
))
e
.
init_cells
(
len
(
cells
))
for
n
in
range
(
len
(
points
)):
e
.
add_vertex
(
n
,
[
points
[
n
,
0
],
points
[
n
,
1
]])
for
n
in
range
(
len
(
cells
)):
e
.
add_cell
(
n
,
cells
[
n
])
e
.
close
()
# create mesh, function space, define function, test function
# create mesh, function space, define function, test function
self
.
SFS
=
df
.
FunctionSpace
(
self
.
mesh
,
'P'
,
1
)
self
.
SFS
=
df
.
FunctionSpace
(
self
.
mesh
,
'P'
,
1
)
...
@@ -54,69 +41,59 @@ class GrowthDiffusion(object):
...
@@ -54,69 +41,59 @@ class GrowthDiffusion(object):
self
.
c0
=
df
.
Function
(
self
.
SFS
)
self
.
c0
=
df
.
Function
(
self
.
SFS
)
tc
=
df
.
TestFunction
(
self
.
SFS
)
tc
=
df
.
TestFunction
(
self
.
SFS
)
# self.velocity.t = 0
self
.
velocity
=
df
.
project
(
self
.
sigma
*
self
.
growth_direction
,
self
.
VFS
)
self
.
vel
=
df
.
project
(
self
.
velocity
,
self
.
VFS
)
self
.
form
=
(
df
.
inner
((
self
.
c
-
self
.
c0
)
/
self
.
timestep
,
tc
)
self
.
form
=
(
df
.
inner
((
self
.
c
-
self
.
c0
)
/
self
.
timestep
,
tc
)
+
df
.
inner
(
df
.
div
(
self
.
vel
*
self
.
c0
),
tc
)
+
df
.
inner
(
df
.
div
(
self
.
vel
ocity
*
self
.
c0
),
tc
)
+
self
.
Dc
*
df
.
inner
(
df
.
nabla_grad
(
self
.
c
),
df
.
nabla_grad
(
tc
))
+
self
.
Dc
*
df
.
inner
(
df
.
nabla_grad
(
self
.
c
),
df
.
nabla_grad
(
tc
))
-
df
.
inner
(
self
.
reaction_rate
*
self
.
c
,
tc
)
)
*
df
.
dx
-
df
.
inner
(
self
.
reaction_rate
*
self
.
c
,
tc
)
)
*
df
.
dx
def
solve
(
self
):
def
solve
(
self
):
times
=
np
.
arange
(
0
,
self
.
maxtime
+
self
.
timestep
,
self
.
timestep
)
times
=
np
.
arange
(
0
,
self
.
maxtime
+
self
.
timestep
,
self
.
timestep
)
if
self
.
growth
==
'linear'
:
fname
=
params
[
'timestamp'
]
+
'_concentration'
cFile
=
df
.
XDMFFile
(
'concentration_linear.xdmf'
)
cFile
=
df
.
XDMFFile
(
fname
+
'.xdmf'
)
elif
self
.
growth
==
'exponential'
:
cFile
=
df
.
XDMFFile
(
'concentration_exponential.xdmf'
)
elif
self
.
growth
==
'none'
:
cFile
=
df
.
XDMFFile
(
'concentration_no_growth.xdmf'
)
# initial condition
# initial condition
if
self
.
dimension
==
1
:
r2
=
"+"
.
join
([
'x['
+
str
(
i
)
+
']*x['
+
str
(
i
)
+
']'
for
i
in
range
(
self
.
dimension
)])
c0
=
df
.
Expression
(
'1 + 0.1*cos(pi*m*x[0]/L)'
,
c0
=
'1 + 0.1*cos(pi*m*(
%
s)/L)'
%
r2
pi
=
np
.
pi
,
m
=
1
,
L
=
self
.
system_size
,
degree
=
1
)
c0
=
df
.
Expression
(
c0
,
pi
=
np
.
pi
,
m
=
1
,
L
=
self
.
system_size
,
degree
=
1
)
elif
self
.
dimension
==
2
:
c0
=
df
.
Expression
(
'1 + 0.1*cos(pi*m*sqrt(x[0]*x[0]+x[1]*x[1])/L)'
,
pi
=
np
.
pi
,
m
=
2
,
L
=
self
.
system_size
,
degree
=
1
)
self
.
c0
.
assign
(
df
.
project
(
c0
,
self
.
SFS
))
self
.
c0
.
assign
(
df
.
project
(
c0
,
self
.
SFS
))
# save data
# save data
if
self
.
growth
==
'linear'
:
cFile
.
write_checkpoint
(
self
.
c0
,
fname
,
times
[
0
])
cFile
.
write_checkpoint
(
self
.
c0
,
'concentration_linear'
,
0.0
)
elif
self
.
growth
==
'exponential'
:
cFile
.
write_checkpoint
(
self
.
c0
,
'concentration_exponential'
,
0.0
)
elif
self
.
growth
==
'none'
:
cFile
.
write_checkpoint
(
self
.
c0
,
'concentration_no_growth'
,
0.0
)
# time stepping
# time stepping
for
i
in
progressbar
.
progressbar
(
range
(
1
,
len
(
times
))):
for
i
in
progressbar
.
progressbar
(
range
(
1
,
len
(
times
))):
# get velocity
# get velocity
self
.
velocity
.
t
=
times
[
i
-
1
]
self
.
sigma
.
t
=
times
[
i
-
1
]
self
.
vel
.
assign
(
df
.
project
(
self
.
velocity
,
self
.
VFS
))
self
.
vel
ocity
.
assign
(
df
.
project
(
self
.
sigma
*
self
.
growth_direction
,
self
.
VFS
))
# solve
# solve
df
.
solve
(
self
.
form
==
0
,
self
.
c
)
df
.
solve
(
self
.
form
==
0
,
self
.
c
)
# update
# update
self
.
c0
.
assign
(
self
.
c
)
self
.
c0
.
assign
(
self
.
c
)
# save data
# save data
if
self
.
growth
==
'linear'
:
cFile
.
write_checkpoint
(
self
.
c0
,
fname
,
times
[
i
],
append
=
True
)
cFile
.
write_checkpoint
(
self
.
c0
,
'concentration_linear'
,
times
[
i
],
append
=
True
)
elif
self
.
growth
==
'exponential'
:
cFile
.
write_checkpoint
(
self
.
c0
,
'concentration_exponential'
,
times
[
i
],
append
=
True
)
elif
self
.
growth
==
'none'
:
cFile
.
write_checkpoint
(
self
.
c0
,
'concentration_no_growth'
,
times
[
i
],
append
=
True
)
# move mesh
# move mesh
displacement
=
df
.
project
(
self
.
vel
*
self
.
timestep
,
self
.
VFS
)
displacement
=
df
.
project
(
self
.
vel
ocity
*
self
.
timestep
,
self
.
VFS
)
df
.
ALE
.
move
(
self
.
mesh
,
displacement
)
df
.
ALE
.
move
(
self
.
mesh
,
displacement
)
cFile
.
close
()
cFile
.
close
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
import
json
import
json
,
datetime
assert
os
.
path
.
isfile
(
'parameters.json'
),
'parameters.json file not found'
assert
os
.
path
.
isfile
(
'parameters.json'
),
'parameters.json file not found'
with
open
(
'parameters.json'
)
as
jsonFile
:
with
open
(
'parameters.json'
)
as
jsonFile
:
params
=
json
.
load
(
jsonFile
)
params
=
json
.
load
(
jsonFile
)
# parse parameters
# parse parameters
assert
params
[
'growth'
]
in
(
'none'
,
'linear'
,
'exponential'
),
'Unknown growth model'
assert
params
[
'dimension'
]
in
(
1
,
2
,
3
)
assert
params
[
'growth'
]
in
(
'none'
,
'linear'
,
'exponential'
),
'Unknown growth model'
timestamp
=
datetime
.
datetime
.
now
()
.
strftime
(
"
%
d
%
m
%
y-
%
H
%
M
%
S"
)
params
[
'timestamp'
]
=
timestamp
gd
=
GrowthDiffusion
(
params
)
gd
=
GrowthDiffusion
(
params
)
gd
.
solve
()
gd
.
solve
()
\ No newline at end of file
with
open
(
params
[
'timestamp'
]
+
'_parmeters.json'
,
"w"
)
as
fp
:
json
.
dump
(
params
,
fp
,
indent
=
4
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment