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
79b2d4bf
Commit
79b2d4bf
authored
5 years ago
by
Lars Hubatsch
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
93f115a6
53d9202c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Meshes/Meshes_Sphere.geo
+30
-0
30 additions, 0 deletions
Meshes/Meshes_Sphere.geo
Solve_Phi_u.ipynb
+47
-14
47 additions, 14 deletions
Solve_Phi_u.ipynb
with
77 additions
and
14 deletions
Meshes/Meshes_Sphere.geo
0 → 100644
+
30
−
0
View file @
79b2d4bf
//+
SetFactory("OpenCASCADE");
Sphere(1) = {0, 0, 0, 1, -Pi/2, Pi/2, 2*Pi};
//+
Point(3) = {0, 0, 0, 0.015};
lc = .15;
Physical Surface("surfacedomain") = {1};
//+
Physical Volume("vilumedomain") = {1};
//+
Field[1] = Distance;
//+
Field[1].NodesList = {3};
Field[1].NNodesByEdge = 20;
Field[2] = Threshold;
Field[2].IField = 1;
Field[2].LcMin = lc / 10;
Field[2].LcMax = lc;
Field[2].DistMin = 0.3;
Field[2].DistMax = 0.5;
Field[3] = Min;
Field[3].FieldsList = {2};
Background Field = 3;
This diff is collapsed.
Click to expand it.
Solve_Phi_u.ipynb
+
47
−
14
View file @
79b2d4bf
...
...
@@ -2,9 +2,36 @@
"cells": [
{
"cell_type": "code",
"execution_count":
null
,
"execution_count":
5
,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.384448766708374\n",
"2.8050124645233154\n",
"4.201659917831421\n",
"5.629311561584473\n",
"7.02629828453064\n",
"8.605925798416138\n",
"10.40172266960144\n",
"12.074671268463135\n",
"13.842711925506592\n",
"15.555825471878052\n"
]
},
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"from __future__ import print_function\n",
...
...
@@ -81,10 +108,12 @@
" dt = 0.15\n",
"\n",
"\n",
" mesh = generate_mesh(Sphere(Point(0,0,0),Radius_Sphere),30)\n",
" \n",
" # mesh = generate_mesh(Sphere(Point(0,0,0),Radius_Sphere),30)\n",
" mesh = Mesh('Meshes_Sphere.xml') \n",
" P1 = FiniteElement(\"Lagrange\", mesh.ufl_cell(), 1)\n",
" V = FunctionSpace(mesh, P1)\n",
"\n",
" V = FunctionSpace(mesh, 'CG', 1)\n",
"
#
V = FunctionSpace(mesh, 'CG', 1)\n",
" Phi_u = Function(V)\n",
" v = TestFunction(V)\n",
"\n",
...
...
@@ -108,7 +137,7 @@
"\n",
"\n",
"\n",
" bc
C
= DirichletBC(V, u_D, boundary)\n",
" bc = DirichletBC(V, u_D, boundary)\n",
"\n",
"\n",
" Form = (inner((Phi_u-Phi_u0)/dt, v) - inner(((1-Phi_tot)/Phi_tot)*Phi_u*grad(Phi_tot) - (1-Phi_tot)*grad(Phi_u), grad(v))) *dx\n",
...
...
@@ -120,8 +149,9 @@
" cFile.write(Phi_u0, t)\n",
"\n",
" ti = time.time()\n",
" for i in range(100):\n",
" solve(Form == 0, Phi_u, bcC)\n",
" for i in range(10):\n",
" #solve(Form == 0, Phi_u, bcC)\n",
" solve(Form == 0, Phi_u, bc,solver_parameters={'newton_solver': {'linear_solver': 'gmres'}})\n",
" assign(Phi_u0, Phi_u)\n",
" t += dt\n",
" cFile.write(Phi_u0, t)\n",
...
...
@@ -193,9 +223,10 @@
"def solver_half_frap_sphere(Radius_Drop, Radius_Sphere):\n",
"\n",
" dt = 0.01\n",
" mesh = generate_mesh(Sphere(Point(0,0,0),Radius_Sphere),50)\n",
"\n",
" V = FunctionSpace(mesh, 'CG', 1)\n",
" #mesh = generate_mesh(Sphere(Point(0,0,0),Radius_Sphere),50)\n",
" mesh = Mesh('Meshes_Sphere.xml') \n",
" P1 = FiniteElement(\"Lagrange\", mesh.ufl_cell(), 1)\n",
" V = FunctionSpace(mesh, P1)\n",
" Phi_u = Function(V)\n",
" v = TestFunction(V)\n",
"\n",
...
...
@@ -236,7 +267,9 @@
"\n",
" ti = time.time()\n",
" for i in range(50):\n",
" solve(Form == 0, Phi_u, bc)\n",
" #solve(Form == 0, Phi_u, bc)\n",
" solve(Form == 0, Phi_u, bc,solver_parameters={'newton_solver': {'linear_solver': 'gmres'}})\n",
"\n",
" assign(Phi_u0, Phi_u)\n",
" t += dt\n",
" cFile.write(Phi_u0, t)\n",
...
...
@@ -249,11 +282,11 @@
"\n",
"#solver_disk(3,10)\n",
"\n",
"#solver_sphere(2,1
0
)\n",
"#solver_sphere(
0.
2,1)\n",
"\n",
"#solver_half_frap_disk(2,10)\n",
"\n",
"
#
solver_half_frap_sphere(2,1
0
)\n",
"solver_half_frap_sphere(
0.
2,1)\n",
"\n",
"\n",
"\n",
...
...
%% Cell type:code id: tags:
```
python
from
__future__
import
print_function
from
fenics
import
*
from
mshr
import
*
from
dolfin
import
*
import
matplotlib.pyplot
as
plt
import
time
from
math
import
*
set_log_level
(
40
)
def
solver_disk
(
Radius_Drop
,
Radius_Disk
):
dt
=
0.5
mesh
=
generate_mesh
(
Circle
(
Point
(
0
,
0
),
Radius_Disk
),
120
)
V
=
FunctionSpace
(
mesh
,
'
CG
'
,
1
)
Phi_u
=
Function
(
V
)
v
=
TestFunction
(
V
)
Phi_u0
=
Function
(
V
)
Phi_tot
=
Function
(
V
)
Phi_tot
=
interpolate
(
Expression
(
'
0.5-0.4*tanh(sqrt(x[0]*x[0]+x[1]*x[1]) - 5)
'
,
degree
=
2
),
V
)
Phi_u0
=
interpolate
(
Expression
(
'
0.0505 - (0.0495)*tanh(-sqrt(x[0]*x[0]+x[1]*x[1]) + 5)
'
,
degree
=
2
),
V
)
def
boundary
(
x
,
on_boundary
):
tol
=
1E-14
return
on_boundary
u_D
=
Constant
(
0.1
)
bcC
=
DirichletBC
(
V
,
u_D
,
boundary
)
Form
=
(
inner
((
Phi_u
-
Phi_u0
)
/
dt
,
v
)
-
inner
(((
1
-
Phi_tot
)
/
Phi_tot
)
*
Phi_u
*
grad
(
Phi_tot
)
-
(
1
-
Phi_tot
)
*
grad
(
Phi_u
),
grad
(
v
)))
*
dx
t
=
0
cFile
=
XDMFFile
(
'
Phi_u_Disk.xmdf
'
)
cFile
.
write
(
Phi_u0
,
t
)
ti
=
time
.
time
()
for
i
in
range
(
100
):
solve
(
Form
==
0
,
Phi_u
,
bcC
)
assign
(
Phi_u0
,
Phi_u
)
t
+=
dt
cFile
.
write
(
Phi_u0
,
t
)
print
(
time
.
time
()
-
ti
)
cFile
.
close
()
return
0
def
solver_sphere
(
Radius_Drop
,
Radius_Sphere
):
dt
=
0.15
mesh
=
generate_mesh
(
Sphere
(
Point
(
0
,
0
,
0
),
Radius_Sphere
),
30
)
# mesh = generate_mesh(Sphere(Point(0,0,0),Radius_Sphere),30)
mesh
=
Mesh
(
'
Meshes_Sphere.xml
'
)
P1
=
FiniteElement
(
"
Lagrange
"
,
mesh
.
ufl_cell
(),
1
)
V
=
FunctionSpace
(
mesh
,
P1
)
V
=
FunctionSpace
(
mesh
,
'
CG
'
,
1
)
# V = FunctionSpace(mesh, 'CG', 1)
Phi_u
=
Function
(
V
)
v
=
TestFunction
(
V
)
Phi_u0
=
Function
(
V
)
Phi_tot
=
Function
(
V
)
tol
=
1E-14
Phi_tot
=
interpolate
(
Expression
(
'
0.5-0.4*tanh(sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]) - Radius_Drop)
'
,
Radius_Drop
=
Radius_Drop
,
degree
=
2
),
V
)
Phi_u0
=
interpolate
(
Expression
(
'
0.0505 - (0.0495)*tanh(-sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]) + Radius_Drop)
'
,
Radius_Drop
=
Radius_Drop
,
degree
=
2
),
V
)
u_D
=
Constant
(
0.01
)
def
boundary
(
x
,
on_boundary
):
tol
=
1E-14
return
on_boundary
bc
C
=
DirichletBC
(
V
,
u_D
,
boundary
)
bc
=
DirichletBC
(
V
,
u_D
,
boundary
)
Form
=
(
inner
((
Phi_u
-
Phi_u0
)
/
dt
,
v
)
-
inner
(((
1
-
Phi_tot
)
/
Phi_tot
)
*
Phi_u
*
grad
(
Phi_tot
)
-
(
1
-
Phi_tot
)
*
grad
(
Phi_u
),
grad
(
v
)))
*
dx
t
=
0
cFile
=
XDMFFile
(
'
Phi_u_Sphere.xmdf
'
)
cFile
.
write
(
Phi_u0
,
t
)
ti
=
time
.
time
()
for
i
in
range
(
100
):
solve
(
Form
==
0
,
Phi_u
,
bcC
)
for
i
in
range
(
10
):
#solve(Form == 0, Phi_u, bcC)
solve
(
Form
==
0
,
Phi_u
,
bc
,
solver_parameters
=
{
'
newton_solver
'
:
{
'
linear_solver
'
:
'
gmres
'
}})
assign
(
Phi_u0
,
Phi_u
)
t
+=
dt
cFile
.
write
(
Phi_u0
,
t
)
print
(
time
.
time
()
-
ti
)
cFile
.
close
()
return
0
def
solver_half_frap_disk
(
Radius_Drop
,
Radius_Disk
):
dt
=
0.01
mesh
=
generate_mesh
(
Circle
(
Point
(
0
,
0
),
Radius_Disk
),
100
)
V
=
FunctionSpace
(
mesh
,
'
CG
'
,
1
)
Phi_u
=
Function
(
V
)
v
=
TestFunction
(
V
)
Phi_u0
=
Function
(
V
)
Phi_tot
=
Function
(
V
)
tol
=
1E-14
Phi_u0_int
=
0.01
Phi_u0_ext
=
0.05
Phi_u0_int_notbleach
=
0.35
Phi_u0
=
interpolate
(
Expression
(
'
sqrt(x[1]*x[1]+x[0]*x[0]) <= Radius_Drop && atan2(x[1],x[0]) < 0 ? Phi_u0_int : sqrt(x[1]*x[1]+x[0]*x[0]) <= Radius_Drop && atan2(x[1],x[0]) >= 0 ? Phi_u0_int_notbleach : Phi_u0_ext
'
,
degree
=
2
,
tol
=
tol
,
Phi_u0_int
=
Phi_u0_int
,
Phi_u0_ext
=
Phi_u0_ext
,
Phi_u0_int_notbleach
=
Phi_u0_int_notbleach
,
Radius_Drop
=
Radius_Drop
),
V
)
Phi_tot_int
=
0.35
Phi_tot_ext
=
0.05
Phi_tot
=
interpolate
(
Expression
(
'
sqrt(x[1]*x[1]+x[0]*x[0]) <= Radius_Drop ? Phi_tot_int : Phi_tot_ext
'
,
degree
=
2
,
tol
=
tol
,
Phi_tot_int
=
Phi_tot_int
,
Phi_tot_ext
=
Phi_tot_ext
,
Radius_Drop
=
Radius_Drop
),
V
)
u_D
=
Constant
(
0.05
)
def
boundary
(
x
,
on_boundary
):
tol
=
1E-14
return
on_boundary
bc
=
DirichletBC
(
V
,
u_D
,
boundary
)
Form
=
(
inner
((
Phi_u
-
Phi_u0
)
/
dt
,
v
)
-
inner
(((
1
-
Phi_tot
)
/
Phi_tot
)
*
Phi_u
*
grad
(
Phi_tot
)
-
(
1
-
Phi_tot
)
*
grad
(
Phi_u
),
grad
(
v
)))
*
dx
t
=
0
cFile
=
XDMFFile
(
'
Phi_u_half_frap_disk.xmdf
'
)
cFile
.
write
(
Phi_u0
,
t
)
ti
=
time
.
time
()
for
i
in
range
(
50
):
solve
(
Form
==
0
,
Phi_u
,
bc
)
assign
(
Phi_u0
,
Phi_u
)
t
+=
dt
cFile
.
write
(
Phi_u0
,
t
)
print
(
time
.
time
()
-
ti
)
cFile
.
close
()
def
solver_half_frap_sphere
(
Radius_Drop
,
Radius_Sphere
):
dt
=
0.01
mesh
=
generate_mesh
(
Sphere
(
Point
(
0
,
0
,
0
),
Radius_Sphere
),
50
)
V
=
FunctionSpace
(
mesh
,
'
CG
'
,
1
)
#mesh = generate_mesh(Sphere(Point(0,0,0),Radius_Sphere),50)
mesh
=
Mesh
(
'
Meshes_Sphere.xml
'
)
P1
=
FiniteElement
(
"
Lagrange
"
,
mesh
.
ufl_cell
(),
1
)
V
=
FunctionSpace
(
mesh
,
P1
)
Phi_u
=
Function
(
V
)
v
=
TestFunction
(
V
)
Phi_u0
=
Function
(
V
)
Phi_tot
=
Function
(
V
)
tol
=
1E-14
Phi_u0_int
=
0.01
Phi_u0_ext
=
0.05
Phi_u0_int_notbleach
=
0.35
Phi_u0
=
interpolate
(
Expression
(
'
sqrt(x[1]*x[1]+x[0]*x[0]+x[2]*x[2]) <= Radius_Drop && atan2(x[1],x[0]) < 0 ? Phi_u0_int : sqrt(x[1]*x[1]+x[0]*x[0]+x[2]*x[2]) <= Radius_Drop && atan2(x[1],x[0]) >= 0 ? Phi_u0_int_notbleach : Phi_u0_ext
'
,
degree
=
2
,
tol
=
tol
,
Phi_u0_int
=
Phi_u0_int
,
Phi_u0_ext
=
Phi_u0_ext
,
Phi_u0_int_notbleach
=
Phi_u0_int_notbleach
,
Radius_Drop
=
Radius_Drop
),
V
)
Phi_tot_int
=
0.35
Phi_tot_ext
=
0.05
Phi_tot
=
interpolate
(
Expression
(
'
sqrt(x[1]*x[1]+x[0]*x[0]+x[2]*x[2]) <= Radius_Drop ? Phi_tot_int : Phi_tot_ext
'
,
degree
=
2
,
tol
=
tol
,
Phi_tot_int
=
Phi_tot_int
,
Phi_tot_ext
=
Phi_tot_ext
,
Radius_Drop
=
Radius_Drop
),
V
)
u_D
=
Constant
(
0.05
)
def
boundary
(
x
,
on_boundary
):
tol
=
1E-14
return
on_boundary
bc
=
DirichletBC
(
V
,
u_D
,
boundary
)
Form
=
(
inner
((
Phi_u
-
Phi_u0
)
/
dt
,
v
)
-
inner
(((
1
-
Phi_tot
)
/
Phi_tot
)
*
Phi_u
*
grad
(
Phi_tot
)
-
(
1
-
Phi_tot
)
*
grad
(
Phi_u
),
grad
(
v
)))
*
dx
t
=
0
cFile
=
XDMFFile
(
'
Phi_u_half_frap_sphere.xmdf
'
)
cFile
.
write
(
Phi_u0
,
t
)
ti
=
time
.
time
()
for
i
in
range
(
50
):
solve
(
Form
==
0
,
Phi_u
,
bc
)
#solve(Form == 0, Phi_u, bc)
solve
(
Form
==
0
,
Phi_u
,
bc
,
solver_parameters
=
{
'
newton_solver
'
:
{
'
linear_solver
'
:
'
gmres
'
}})
assign
(
Phi_u0
,
Phi_u
)
t
+=
dt
cFile
.
write
(
Phi_u0
,
t
)
print
(
time
.
time
()
-
ti
)
cFile
.
close
()
return
0
#solver_disk(3,10)
#solver_sphere(2,1
0
)
#solver_sphere(
0.
2,1)
#solver_half_frap_disk(2,10)
#
solver_half_frap_sphere(2,1
0
)
solver_half_frap_sphere
(
0.
2
,
1
)
```
%% Output
1.384448766708374
2.8050124645233154
4.201659917831421
5.629311561584473
7.02629828453064
8.605925798416138
10.40172266960144
12.074671268463135
13.842711925506592
15.555825471878052
0
%% Cell type:code id: tags:
```
python
``
`
%%
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