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
e9ee584d
authored
Dec 12, 2023
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
project the IC, not interpolate. Computing errornorm
parent
f0ead902
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
68 additions
and
29 deletions
simple_extend_code/111223-235806_parameters.json
simple_extend_code/111223-235856_parameters.json
simple_extend_code/121223-065829_parameters.json
simple_extend_code/121223-065916_parameters.json
simple_extend_code/__pycache__/extend_for_diffusion.cpython-39.pyc
simple_extend_code/__pycache__/viz_extend_for_diffusion.cpython-39.pyc
simple_extend_code/compare.py
simple_extend_code/extend_for_diffusion.py
simple_extend_code/parameters.json
simple_extend_code/run_extend_for_diffusion.py
simple_extend_code/viz_extend_for_diffusion.py
simple_extend_code/111223-235806_parameters.json
0 → 100644
View file @
e9ee584d
{
"D"
:
0.1
,
"L"
:
1.0
,
"maxtime"
:
1.0
,
"resolution"
:
128
,
"timestamp"
:
"111223-235806"
,
"timestep"
:
0.1
}
\ No newline at end of file
simple_extend_code/111223-235856_parameters.json
0 → 100644
View file @
e9ee584d
{
"D"
:
0.1
,
"L"
:
1.0
,
"maxtime"
:
1
,
"resolution"
:
128
,
"timestamp"
:
"111223-235856"
,
"timestep"
:
0.1
}
\ No newline at end of file
simple_extend_code/121223-065829_parameters.json
0 → 100644
View file @
e9ee584d
{
"D"
:
0.1
,
"L"
:
1.0
,
"maxtime"
:
1.0
,
"resolution"
:
128
,
"timestamp"
:
"121223-065829"
,
"timestep"
:
0.1
}
\ No newline at end of file
simple_extend_code/121223-065916_parameters.json
0 → 100644
View file @
e9ee584d
{
"D"
:
0.1
,
"L"
:
1.0
,
"maxtime"
:
1
,
"resolution"
:
128
,
"timestamp"
:
"121223-065916"
,
"timestep"
:
0.1
}
\ No newline at end of file
simple_extend_code/__pycache__/extend_for_diffusion.cpython-39.pyc
0 → 100644
View file @
e9ee584d
File added
simple_extend_code/__pycache__/viz_extend_for_diffusion.cpython-39.pyc
0 → 100644
View file @
e9ee584d
File added
simple_extend_code/compare.py
0 → 100644
View file @
e9ee584d
import
dolfin
as
df
import
numpy
as
np
c1File
=
df
.
XDMFFile
(
'121223-065916_concentration.xdmf'
)
c2File
=
df
.
XDMFFile
(
'121223-065829_concentration.xdmf'
)
mesh
=
df
.
IntervalMesh
(
128
,
-
0.5
,
0.5
)
times
=
np
.
arange
(
0.0
,
1.1
,
0.1
)
SFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
for
steps
in
range
(
len
(
times
)):
c1
=
df
.
Function
(
SFS
)
c2
=
df
.
Function
(
SFS
)
c1File
.
read_checkpoint
(
c1
,
'concentration'
,
steps
)
c2File
.
read_checkpoint
(
c2
,
'concentration'
,
steps
)
print
(
df
.
assemble
((
c2
-
c1
)
**
2
*
df
.
dx
(
mesh
))
**
0.5
)
c1File
.
close
()
c2File
.
close
()
simple_extend_code/extend_for_diffusion.py
View file @
e9ee584d
import
numpy
as
np
import
numpy
as
np
import
dolfin
as
df
import
dolfin
as
df
import
progressbar
import
progressbar
import
os
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
...
@@ -25,21 +24,19 @@ class diffusion(object):
...
@@ -25,21 +24,19 @@ class diffusion(object):
if
initc
is
None
:
if
initc
is
None
:
self
.
c0
.
interpolate
(
df
.
Expression
(
'1 + 0.2 * cos(pi*x[0]/L)'
,
pi
=
np
.
pi
,
L
=
self
.
L
,
degree
=
1
))
self
.
c0
.
interpolate
(
df
.
Expression
(
'1 + 0.2 * cos(pi*x[0]/L)'
,
pi
=
np
.
pi
,
L
=
self
.
L
,
degree
=
1
))
else
:
else
:
self
.
c0
.
interpolate
(
initc
)
self
.
c0
=
df
.
project
(
initc
,
self
.
function_space
)
print
(
'c0[-1]='
,
self
.
c0
.
compute_vertex_values
(
self
.
mesh
)[
-
1
])
def
setup_weak_forms
(
self
):
def
setup_weak_forms
(
self
):
self
.
form
=
(
df
.
inner
((
self
.
c
-
self
.
c0
)
/
self
.
timestep
,
self
.
tc
)
self
.
form
=
(
df
.
inner
((
self
.
c
-
self
.
c0
)
/
self
.
timestep
,
self
.
tc
)
+
self
.
D
*
df
.
inner
(
df
.
nabla_grad
(
self
.
c
),
df
.
nabla_grad
(
self
.
tc
))
+
self
.
D
*
df
.
inner
(
df
.
nabla_grad
(
self
.
c
),
df
.
nabla_grad
(
self
.
tc
))
)
*
df
.
dx
)
*
df
.
dx
def
solve
(
self
,
initc
=
None
,
initTime
=
0.0
,
extend
=
False
):
def
solve
(
self
,
initc
=
None
,
initTime
=
0.0
,
extend
=
False
):
# create file if it doesn't exist, open if it exists
self
.
cFile
=
df
.
XDMFFile
(
'
%
s_concentration.xdmf'
%
self
.
timestamp
)
self
.
cFile
=
df
.
XDMFFile
(
'
%
s_concentration.xdmf'
%
self
.
timestamp
)
# time-variables
# time-variables
self
.
time
=
initTime
self
.
time
=
initTime
print
(
'time='
,
self
.
time
)
maxsteps
=
int
(
self
.
maxtime
/
self
.
timestep
)
maxsteps
=
int
(
self
.
maxtime
/
self
.
timestep
)
self
.
setup_initial_conditions
(
initc
)
self
.
setup_initial_conditions
(
initc
)
...
@@ -51,12 +48,9 @@ class diffusion(object):
...
@@ -51,12 +48,9 @@ class diffusion(object):
for
steps
in
progressbar
.
progressbar
(
range
(
1
,
maxsteps
+
1
)):
for
steps
in
progressbar
.
progressbar
(
range
(
1
,
maxsteps
+
1
)):
self
.
time
+=
self
.
timestep
self
.
time
+=
self
.
timestep
print
(
'time='
,
self
.
time
)
df
.
solve
(
self
.
form
==
0
,
self
.
c
)
df
.
solve
(
self
.
form
==
0
,
self
.
c
)
print
(
'c[-1]='
,
self
.
c
.
compute_vertex_values
(
self
.
mesh
)[
-
1
]
)
self
.
cFile
.
write_checkpoint
(
self
.
c
,
'concentration'
,
self
.
time
,
append
=
True
)
self
.
c0
.
assign
(
self
.
c
)
self
.
c0
.
assign
(
self
.
c
)
self
.
cFile
.
write_checkpoint
(
self
.
c
,
'concentration'
,
self
.
time
,
append
=
True
)
self
.
cFile
.
close
()
self
.
cFile
.
close
()
...
...
simple_extend_code/parameters.json
View file @
e9ee584d
{
{
"resolution"
:
1
000
,
"resolution"
:
1
28
,
"L"
:
1.0
,
"L"
:
1.0
,
"D"
:
0.1
,
"D"
:
0.1
,
"timestep"
:
0.1
,
"timestep"
:
0.1
,
"maxtime"
:
0.5
"maxtime"
:
1
}
}
\ No newline at end of file
simple_extend_code/run_extend_for_diffusion.py
View file @
e9ee584d
import
json
,
datetime
import
json
,
datetime
import
os
import
os
from
extend_for_diffusion
import
diffusion
from
extend_for_diffusion
import
diffusion
from
viz_extend_for_diffusion
import
visualize
import
argparse
import
argparse
import
dolfin
as
df
import
dolfin
as
df
import
h5py
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-j'
,
'--jsonfile'
,
help
=
'data file'
,
parser
.
add_argument
(
'-j'
,
'--jsonfile'
,
help
=
'data file'
,
default
=
'parameters.json'
)
default
=
'parameters.json'
)
parser
.
add_argument
(
'-t'
,
'--time'
,
help
=
'time to run'
,
type
=
float
)
parser
.
add_argument
(
'-t'
,
'--time'
,
help
=
'time to run'
,
type
=
float
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
assert
os
.
path
.
isfile
(
args
.
jsonfile
),
'
%
s file not found'
%
args
.
jsonfile
assert
os
.
path
.
isfile
(
args
.
jsonfile
),
'
%
s file not found'
%
args
.
jsonfile
...
@@ -18,7 +16,7 @@ assert os.path.isfile(args.jsonfile), '%s file not found' % args.jsonfile
...
@@ -18,7 +16,7 @@ assert os.path.isfile(args.jsonfile), '%s file not found' % args.jsonfile
with
open
(
args
.
jsonfile
)
as
jsonFile
:
with
open
(
args
.
jsonfile
)
as
jsonFile
:
parameters
=
json
.
load
(
jsonFile
)
parameters
=
json
.
load
(
jsonFile
)
if
args
.
jsonfile
==
'parameters.json'
:
if
args
.
jsonfile
==
'parameters.json'
:
extend
=
False
extend
=
False
print
(
'Fresh run...'
)
print
(
'Fresh run...'
)
timestamp
=
datetime
.
datetime
.
now
()
.
strftime
(
"
%
d
%
m
%
y-
%
H
%
M
%
S"
)
timestamp
=
datetime
.
datetime
.
now
()
.
strftime
(
"
%
d
%
m
%
y-
%
H
%
M
%
S"
)
...
@@ -29,7 +27,7 @@ if args.jsonfile=='parameters.json':
...
@@ -29,7 +27,7 @@ if args.jsonfile=='parameters.json':
else
:
else
:
extend
=
True
extend
=
True
print
(
'Extending run'
)
print
(
'Extending run
...
'
)
parametersFile
=
args
.
jsonfile
parametersFile
=
args
.
jsonfile
steps
=
int
(
parameters
[
'maxtime'
]
/
parameters
[
'timestep'
])
steps
=
int
(
parameters
[
'maxtime'
]
/
parameters
[
'timestep'
])
...
@@ -38,10 +36,6 @@ else:
...
@@ -38,10 +36,6 @@ else:
-
parameters
[
'L'
]
/
2
,
-
parameters
[
'L'
]
/
2
,
parameters
[
'L'
]
/
2
)
parameters
[
'L'
]
/
2
)
# read geometry from h5 file
var
=
'concentration'
h5
=
h5py
.
File
(
'
%
s_
%
s.h5'
%
(
parameters
[
'timestamp'
],
var
,),
'r+'
)
# Read data
# Read data
SFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
SFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
initc
=
df
.
Function
(
SFS
)
initc
=
df
.
Function
(
SFS
)
...
...
simple_extend_code/viz_extend_for_diffusion.py
View file @
e9ee584d
import
dolfin
as
df
import
dolfin
as
df
import
numpy
as
np
import
numpy
as
np
import
os
import
os
import
h5py
from
matplotlib.widgets
import
Slider
from
matplotlib.widgets
import
Slider
import
progressbar
import
progressbar
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
tempfile
import
TemporaryDirectory
def
visualize
(
params
,
DIR
=
''
):
def
visualize
(
params
,
DIR
=
''
):
savesteps
=
int
(
params
[
'maxtime'
]
/
params
[
'timestep'
])
savesteps
=
int
(
params
[
'maxtime'
]
/
params
[
'timestep'
])
...
@@ -16,16 +14,13 @@ def visualize(params, DIR=''):
...
@@ -16,16 +14,13 @@ def visualize(params, DIR=''):
params
[
'L'
]
/
2
)
params
[
'L'
]
/
2
)
# Read data
# Read data
c
=
np
.
zeros
((
len
(
times
),
mesh
.
num_vertices
()))
c
=
np
.
zeros
((
len
(
times
),
mesh
.
num_vertices
()))
cFile
=
df
.
XDMFFile
(
os
.
path
.
join
(
DIR
,
'
%
s_concentration.xdmf'
%
params
[
'timestamp'
]))
cFile
=
df
.
XDMFFile
(
os
.
path
.
join
(
DIR
,
'
%
s_concentration.xdmf'
%
params
[
'timestamp'
]))
# Reading data
# Reading data
print
(
'Reading data...'
)
print
(
'Reading data...'
)
for
steps
in
progressbar
.
progressbar
(
range
(
savesteps
+
1
)):
for
steps
in
progressbar
.
progressbar
(
range
(
savesteps
+
1
)):
SFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
SFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
ci
=
df
.
Function
(
SFS
)
ci
=
df
.
Function
(
SFS
)
cFile
.
read_checkpoint
(
ci
,
'concentration'
,
steps
)
cFile
.
read_checkpoint
(
ci
,
'concentration'
,
steps
)
c
[
steps
]
=
ci
.
compute_vertex_values
(
mesh
)
c
[
steps
]
=
ci
.
compute_vertex_values
(
mesh
)
...
@@ -57,7 +52,6 @@ if __name__ == '__main__':
...
@@ -57,7 +52,6 @@ if __name__ == '__main__':
import
argparse
,
json
import
argparse
,
json
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-j'
,
'--jsonfile'
,
help
=
'parameters file'
,
required
=
True
)
parser
.
add_argument
(
'-j'
,
'--jsonfile'
,
help
=
'parameters file'
,
required
=
True
)
parser
.
add_argument
(
'--onscreen'
,
action
=
argparse
.
BooleanOptionalAction
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
with
open
(
args
.
jsonfile
)
as
jsonFile
:
with
open
(
args
.
jsonfile
)
as
jsonFile
:
...
...
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