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
8c901e31
authored
Nov 22, 2022
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working 2D exact soolutions with visualization, 1D visualization to be done
parent
5942d213
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
26 deletions
growing_domain/diffusion_on_growing_domain_exact_solutions.py
growing_domain/diffusion_on_growing_domain_exact_solutions.py
View file @
8c901e31
...
...
@@ -22,9 +22,6 @@ offscreen=(not args.onscreen)
# parameters
Nt
=
int
(
params
[
'maxtime'
]
/
params
[
'timestep'
])
times
=
np
.
linspace
(
0
,
params
[
'maxtime'
],
Nt
+
1
)
mesh
=
df
.
Mesh
(
'disk.xml.gz'
)
Nv
=
mesh
.
num_vertices
()
d
=
params
[
'dimension'
]
L
=
params
[
'system_size'
]
alpha
=
params
[
'growth_parameter'
]
...
...
@@ -32,35 +29,44 @@ dt = params['timestep']
Dc
=
params
[
'Dc'
]
k
=
params
[
'reaction_rate'
]
growth
=
params
[
'growth'
]
m
=
2
# mth mode of cosine in the initial condition for d=1
p
=
1
# pth zero of bessel 1 in the initial condition for d=2
# topology and geometry arrays
topology_array
=
mesh
.
cells
()
# mesh
if
d
==
2
:
mesh
=
df
.
Mesh
(
'disk.xml.gz'
)
else
:
mesh
=
df
.
IntervalMesh
(
params
[
'resolution'
],
0
,
L
)
Nv
=
mesh
.
num_vertices
()
# why is the number of vertices in the 2D mesh less than the number of cells?
# initialize topology and geometry arrays
topology_array
=
mesh
.
cells
()
geometry_array
=
np
.
zeros
(((
Nt
+
1
,
Nv
,
d
)))
x
=
np
.
reshape
(
mesh
.
coordinates
()[:,
0
],
(
Nv
,
1
))
y
=
np
.
reshape
(
mesh
.
coordinates
()[:,
1
],
(
Nv
,
1
))
geometry_array
[
0
]
=
np
.
concatenate
((
x
,
y
),
axis
=
1
)
#
r and solution array
#
initialize r and sol arrays
r_array
=
np
.
zeros
((
Nt
+
1
,
Nv
))
r_array
[
0
]
=
np
.
sqrt
(
mesh
.
coordinates
()[:,
0
]
**
2
+
mesh
.
coordinates
()[:,
1
]
**
2
)
sol
=
np
.
zeros
((
len
(
times
),
len
(
r_array
[
0
])))
# velocity
# velocity
to move the mesh
VFS
=
df
.
VectorFunctionSpace
(
mesh
,
'P'
,
1
)
sigma
=
{
'none'
:
'0.0'
,
'linear'
:
'alpha/(L0 + alpha*t)'
,
'exponential'
:
'alpha'
}
sigma
=
df
.
Expression
(
sigma
[
growth
],
L0
=
L
,
alpha
=
alpha
,
t
=
0
,
degree
=
1
)
growth_direction
=
(
'x[0]'
,
'x[1]'
)
growth_direction
=
tuple
([
'x['
+
str
(
i
)
+
']'
for
i
in
range
(
0
,
d
)]
)
growth_direction
=
df
.
Expression
(
growth_direction
,
degree
=
1
)
velocity
=
df
.
project
(
sigma
*
growth_direction
,
VFS
)
velocity
=
df
.
project
(
sigma
*
growth_direction
,
VFS
)
# modes enetering the solution
if
d
==
1
:
mode
=
m
*
np
.
pi
else
:
mode
=
sc
.
special
.
jn_zeros
(
1
,
p
)
# time loop
t
=
0
first_zero_of_bessel_1
=
sc
.
special
.
jn_zeros
(
1
,
1
)
for
steps
in
range
(
0
,
Nt
+
1
):
# update sigma
sigma
.
t
=
t
...
...
@@ -68,19 +74,34 @@ for steps in range(0, Nt+1):
# update velocity
velocity
.
assign
(
df
.
project
(
sigma
*
growth_direction
,
VFS
))
# find r, geometry on solution on the mesh
x
=
np
.
reshape
(
mesh
.
coordinates
()[:,
0
],
(
mesh
.
num_vertices
(),
1
))
y
=
np
.
reshape
(
mesh
.
coordinates
()[:,
1
],
(
mesh
.
num_vertices
(),
1
))
r_array
[
steps
]
=
np
.
sqrt
(
mesh
.
coordinates
()[:,
0
]
**
2
+
mesh
.
coordinates
()[:,
1
]
**
2
)
# find r, geometry and sol arrays on the mesh
# geometry array
if
d
==
1
:
x
=
np
.
reshape
(
mesh
.
coordinates
()[:],
(
Nv
,
1
))
geometry_array
[
steps
]
=
x
else
:
x
=
np
.
reshape
(
mesh
.
coordinates
()[:,
0
],
(
Nv
,
1
))
y
=
np
.
reshape
(
mesh
.
coordinates
()[:,
1
],
(
Nv
,
1
))
geometry_array
[
steps
]
=
np
.
concatenate
((
x
,
y
),
axis
=
1
)
time_part
=
{
'none'
:
np
.
exp
(
-
first_zero_of_bessel_1
**
2
*
Dc
*
t
/
L
**
2
+
k
*
t
),
'exponential'
:
np
.
exp
(
-
first_zero_of_bessel_1
**
2
*
Dc
*
(
1
-
np
.
exp
(
-
2
*
alpha
*
t
))
/
(
2
*
alpha
*
L
**
2
)
+
(
k
-
2
*
alpha
)
*
t
),
'linear'
:
(
L
/
(
L
+
alpha
*
t
))
**
2
*
np
.
exp
(
-
first_zero_of_bessel_1
**
2
*
Dc
*
t
/
(
L
*
(
L
+
alpha
*
t
))
+
k
*
t
)}
sol
[
steps
]
=
(
sc
.
special
.
j0
(
first_zero_of_bessel_1
*
r_array
[
steps
]
/
L
)
*
time_part
[
growth
])
# r array
r_array
[
0
]
=
0
for
j
in
range
(
0
,
d
):
r_array
[
steps
]
+=
mesh
.
coordinates
()[:,
j
]
**
2
r_array
[
steps
]
=
np
.
sqrt
(
r_array
[
steps
])
# sol array
time_part
=
{
'none'
:
np
.
exp
(
-
mode
**
2
*
Dc
*
t
/
L
**
2
+
k
*
t
),
'exponential'
:
np
.
exp
(
-
mode
**
2
*
Dc
*
(
1
-
np
.
exp
(
-
2
*
alpha
*
t
))
/
(
2
*
alpha
*
L
**
2
)
+
(
k
-
d
*
alpha
)
*
t
),
'linear'
:
(
L
/
(
L
+
alpha
*
t
))
**
d
*
np
.
exp
(
-
mode
**
2
*
Dc
*
t
/
(
L
*
(
L
+
alpha
*
t
))
+
k
*
t
)}
domain_length
=
{
'none'
:
L
,
'exponential'
:
L
*
np
.
exp
(
alpha
*
t
),
'linear'
:
L
+
alpha
*
t
}
if
d
==
1
:
sol
[
steps
]
=
np
.
cos
(
mode
*
r_array
[
steps
]
/
domain_length
[
growth
])
*
time_part
[
growth
]
else
:
sol
[
steps
]
=
sc
.
special
.
j0
(
mode
*
r_array
[
steps
]
/
domain_length
[
growth
])
*
time_part
[
growth
]
# move the mesh
displacement
=
df
.
project
(
velocity
*
dt
,
VFS
)
...
...
@@ -92,7 +113,8 @@ for steps in range(0, Nt+1):
# visualise the solution
n_cmap_vals
=
16
scalar_cmap
=
'viridis'
geometry
=
np
.
dstack
((
geometry_array
,
np
.
zeros
(
geometry_array
.
shape
[
0
:
2
])))
geometry
=
np
.
dstack
((
geometry_array
,
np
.
zeros
(
geometry_array
.
shape
[
0
:
2
])))
# not workin without this, check why
# this is necessary
cmin
,
cmax
=
np
.
min
(
sol
),
np
.
max
(
sol
)
plotter
=
vd
.
plotter
.
Plotter
(
axes
=
0
)
poly
=
vd
.
utils
.
buildPolyData
(
geometry
[
0
],
topology_array
)
...
...
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