Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Frap Theory
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hubatsch
Frap Theory
Commits
21570d0d
Commit
21570d0d
authored
4 years ago
by
Lars Hubatsch
Browse files
Options
Downloads
Patches
Plain Diff
Swapping Gamma and D works in principle for 1D.
parent
29995129
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
FloryHugg_DiffUnbleached.ipynb
+44
-12
44 additions, 12 deletions
FloryHugg_DiffUnbleached.ipynb
with
44 additions
and
12 deletions
FloryHugg_DiffUnbleached.ipynb
+
44
−
12
View file @
21570d0d
...
...
@@ -15,8 +15,8 @@
"\n",
"# domain = ms.Sphere(df.Point(0, 0, 0), 1.0)\n",
"# mesh = ms.generate_mesh(domain, 50)\n",
"mesh = df.UnitIntervalMesh(1000)\n",
"dt = 0.0
1
\n",
"mesh = df.UnitIntervalMesh(1000
0
)\n",
"dt = 0.0
000002
\n",
"\n",
"F = df.FunctionSpace(mesh, 'CG', 1)\n",
"\n",
...
...
@@ -24,18 +24,27 @@
"c_tot = df.Function(F)\n",
"c = df.Function(F)\n",
"tc = df.TestFunction(F)\n",
"\n",
"
Ga0 = df.Function(F)
\n",
"# Interpolate c_tot and initial conditions\n",
"# 3D:\n",
"# c_tot.interpolate(df.Expression('0.4*tanh(-350*(sqrt((x[0])*(x[0])+(x[1])*(x[1])+(x[2])*(x[2]))-0.2))+0.5', degree=1))\n",
"# c0.interpolate(df.Expression(('(x[0]<0.5) && sqrt((x[0])*(x[0])+(x[1])*(x[1])+(x[2])*(x[2]))<0.2 ? 0 :'\n",
"# '0.4*tanh(-350*(sqrt((x[0])*(x[0])+(x[1])*(x[1])+(x[2])*(x[2]))-0.2)) + 0.5'),\n",
"# degree=1))\n",
"# 1D:\n",
"c_tot.interpolate(df.Expression('0.4*tanh(-350*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.2))+0.5', degree=1))\n",
"c0.interpolate(df.Expression(('sqrt((x[0]-0.5)*(x[0]-0.5))<0.2 ? 0 :'\n",
" '0.4*tanh(-350*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.2)) +0.5'),\n",
"# 1D, high partitioning\n",
"# c_tot.interpolate(df.Expression('0.4*tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001))+0.5', degree=1))\n",
"# c0.interpolate(df.Expression(('sqrt((x[0]-0.5)*(x[0]-0.5))<0.001 ? 0 :'\n",
"# '0.4*tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001)) +0.5'),\n",
"# degree=1))\n",
"# Ga0.interpolate(df.Expression('0*(tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001))+1)+1', degree=1))\n",
"\n",
"# 1D, no partitioning\n",
"c_tot.interpolate(df.Expression('0*tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001))+0.9', degree=1))\n",
"c0.interpolate(df.Expression(('sqrt((x[0]-0.5)*(x[0]-0.5))<0.001 ? 0 :'\n",
" '0*tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001)) +0.9'),\n",
" degree=1))\n",
"Ga0.interpolate(df.Expression('4.*(tanh(35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001))+1)+1', degree=1))\n",
"\n",
"# tanh from left to right initial conditions\n",
"# c_tot.interpolate(df.Expression('0.4*tanh(5*(x[0]-0.5)) - 1', degree=1))\n",
"# Step function left to right initial condition\n",
...
...
@@ -43,8 +52,8 @@
"# Somewhat realistic half FRAP\n",
"\n",
"# Weak form\n",
"form = ((df.inner((c-c0)/dt, tc) + (1-c_tot)* df.inner(df.grad(c), df.grad(tc))) -\n",
" (1-c_tot)/c_tot* c*df.inner(df.grad(c_tot), df.grad(tc))) * df.dx\n",
"form = ((df.inner((c-c0)/dt, tc) +
1/Ga0*
(1-c_tot)* df.inner(df.grad(c), df.grad(tc))) -\n",
"
1/Ga0*
(1-c_tot)/c_tot* c*df.inner(df.grad(c_tot), df.grad(tc))) * df.dx\n",
"\n",
"# Open file for writing\n",
"cFile = df.XDMFFile('conc.xdmf')\n",
...
...
@@ -53,7 +62,7 @@
"\n",
"# Solve in time\n",
"ti = time.time()\n",
"for i in range(
8
):\n",
"for i in range(
10
):\n",
" print(time.time() - ti)\n",
" df.solve(form == 0, c)\n",
" df.assign(c0, c)\n",
...
...
@@ -70,7 +79,9 @@
"outputs": [],
"source": [
"# 1D:\n",
"plt.plot(np.linspace(0, 1, 1000), [c0([x]) for x in np.linspace(0, 1, 1000)])\n",
"plt.plot(np.linspace(0, 1, 10000), [c0([x]) for x in np.linspace(0, 1, 10000)])\n",
"plt.xlim(0.495, 0.505)\n",
"plt.ylim(0, 0.3)\n",
"# 3D:\n",
"# plt.plot(np.linspace(0, 0.5, 1000), [c0([x, 0, 0]) for x in np.linspace(0, 0.5, 1000)])"
]
...
...
@@ -81,7 +92,28 @@
"metadata": {},
"outputs": [],
"source": [
"c0([0, 0, 0])"
"# 1D:\n",
"plt.plot(np.linspace(0, 1, 10000), [c0([x]) for x in np.linspace(0, 1, 10000)])\n",
"plt.xlim(0.495, 0.505)\n",
"plt.ylim(0., 0.3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.plot(np.linspace(0, 1, 2000), [Ga0([x]) for x in np.linspace(0, 1, 2000)])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.plot(np.linspace(0, 1, 1000), [c_tot([x]) for x in np.linspace(0, 1, 1000)])"
]
},
{
...
...
%% Cell type:code id: tags:
```
python
import
dolfin
as
df
import
matplotlib.pyplot
as
plt
import
mshr
as
ms
import
numpy
as
np
import
time
df
.
set_log_level
(
40
)
# domain = ms.Sphere(df.Point(0, 0, 0), 1.0)
# mesh = ms.generate_mesh(domain, 50)
mesh
=
df
.
UnitIntervalMesh
(
1000
)
dt
=
0.0
1
mesh
=
df
.
UnitIntervalMesh
(
1000
0
)
dt
=
0.0
000002
F
=
df
.
FunctionSpace
(
mesh
,
'
CG
'
,
1
)
c0
=
df
.
Function
(
F
)
c_tot
=
df
.
Function
(
F
)
c
=
df
.
Function
(
F
)
tc
=
df
.
TestFunction
(
F
)
Ga0
=
df
.
Function
(
F
)
# Interpolate c_tot and initial conditions
# 3D:
# c_tot.interpolate(df.Expression('0.4*tanh(-350*(sqrt((x[0])*(x[0])+(x[1])*(x[1])+(x[2])*(x[2]))-0.2))+0.5', degree=1))
# c0.interpolate(df.Expression(('(x[0]<0.5) && sqrt((x[0])*(x[0])+(x[1])*(x[1])+(x[2])*(x[2]))<0.2 ? 0 :'
# '0.4*tanh(-350*(sqrt((x[0])*(x[0])+(x[1])*(x[1])+(x[2])*(x[2]))-0.2)) + 0.5'),
# degree=1))
# 1D:
c_tot
.
interpolate
(
df
.
Expression
(
'
0.4*tanh(-350*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.2))+0.5
'
,
degree
=
1
))
c0
.
interpolate
(
df
.
Expression
((
'
sqrt((x[0]-0.5)*(x[0]-0.5))<0.2 ? 0 :
'
'
0.4*tanh(-350*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.2)) +0.5
'
),
# 1D, high partitioning
# c_tot.interpolate(df.Expression('0.4*tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001))+0.5', degree=1))
# c0.interpolate(df.Expression(('sqrt((x[0]-0.5)*(x[0]-0.5))<0.001 ? 0 :'
# '0.4*tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001)) +0.5'),
# degree=1))
# Ga0.interpolate(df.Expression('0*(tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001))+1)+1', degree=1))
# 1D, no partitioning
c_tot
.
interpolate
(
df
.
Expression
(
'
0*tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001))+0.9
'
,
degree
=
1
))
c0
.
interpolate
(
df
.
Expression
((
'
sqrt((x[0]-0.5)*(x[0]-0.5))<0.001 ? 0 :
'
'
0*tanh(-35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001)) +0.9
'
),
degree
=
1
))
Ga0
.
interpolate
(
df
.
Expression
(
'
4.*(tanh(35000*(sqrt((x[0]-0.5)*(x[0]-0.5))-0.001))+1)+1
'
,
degree
=
1
))
# tanh from left to right initial conditions
# c_tot.interpolate(df.Expression('0.4*tanh(5*(x[0]-0.5)) - 1', degree=1))
# Step function left to right initial condition
# c0.interpolate(df.Expression('(x[0]<0.5) ? 0 : 1.0', degree=1))
# Somewhat realistic half FRAP
# Weak form
form
=
((
df
.
inner
((
c
-
c0
)
/
dt
,
tc
)
+
(
1
-
c_tot
)
*
df
.
inner
(
df
.
grad
(
c
),
df
.
grad
(
tc
)))
-
(
1
-
c_tot
)
/
c_tot
*
c
*
df
.
inner
(
df
.
grad
(
c_tot
),
df
.
grad
(
tc
)))
*
df
.
dx
form
=
((
df
.
inner
((
c
-
c0
)
/
dt
,
tc
)
+
1
/
Ga0
*
(
1
-
c_tot
)
*
df
.
inner
(
df
.
grad
(
c
),
df
.
grad
(
tc
)))
-
1
/
Ga0
*
(
1
-
c_tot
)
/
c_tot
*
c
*
df
.
inner
(
df
.
grad
(
c_tot
),
df
.
grad
(
tc
)))
*
df
.
dx
# Open file for writing
cFile
=
df
.
XDMFFile
(
'
conc.xdmf
'
)
t
=
0
cFile
.
write
(
c0
,
t
)
# Solve in time
ti
=
time
.
time
()
for
i
in
range
(
8
):
for
i
in
range
(
10
):
print
(
time
.
time
()
-
ti
)
df
.
solve
(
form
==
0
,
c
)
df
.
assign
(
c0
,
c
)
t
+=
dt
cFile
.
write
(
c0
,
t
)
cFile
.
close
()
print
(
time
.
time
()
-
ti
)
```
%% Cell type:code id: tags:
```
python
# 1D:
plt
.
plot
(
np
.
linspace
(
0
,
1
,
1000
),
[
c0
([
x
])
for
x
in
np
.
linspace
(
0
,
1
,
1000
)])
plt
.
plot
(
np
.
linspace
(
0
,
1
,
10000
),
[
c0
([
x
])
for
x
in
np
.
linspace
(
0
,
1
,
10000
)])
plt
.
xlim
(
0.495
,
0.505
)
plt
.
ylim
(
0
,
0.3
)
# 3D:
# plt.plot(np.linspace(0, 0.5, 1000), [c0([x, 0, 0]) for x in np.linspace(0, 0.5, 1000)])
```
%% Cell type:code id: tags:
```
python
c0
([
0
,
0
,
0
])
# 1D:
plt
.
plot
(
np
.
linspace
(
0
,
1
,
10000
),
[
c0
([
x
])
for
x
in
np
.
linspace
(
0
,
1
,
10000
)])
plt
.
xlim
(
0.495
,
0.505
)
plt
.
ylim
(
0.
,
0.3
)
```
%% Cell type:code id: tags:
```
python
plt
.
plot
(
np
.
linspace
(
0
,
1
,
2000
),
[
Ga0
([
x
])
for
x
in
np
.
linspace
(
0
,
1
,
2000
)])
```
%% Cell type:code id: tags:
```
python
plt
.
plot
(
np
.
linspace
(
0
,
1
,
1000
),
[
c_tot
([
x
])
for
x
in
np
.
linspace
(
0
,
1
,
1000
)])
```
%% Cell type:code id: tags:
```
python
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment