Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lbmpy
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
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
lbmpy
Commits
c4f23fbe
Commit
c4f23fbe
authored
7 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
PressureTensor approach for phase field
parent
b3201b16
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
phasefield/analytical.py
+70
-56
70 additions, 56 deletions
phasefield/analytical.py
with
70 additions
and
56 deletions
phasefield/analytical.py
+
70
−
56
View file @
c4f23fbe
...
...
@@ -8,62 +8,6 @@ surfaceTensionSymbolName = "tau"
interfaceWidthSymbol
=
sp
.
Symbol
(
"
alpha
"
)
def
functionalDerivative
(
functional
,
v
,
constants
=
None
):
"""
Computes functional derivative of functional with respect to v using Euler-Lagrange equation
.. math ::
\f
rac{\delta F}{\delta v} =
\f
rac{\partial F}{\partial v} -
\n
abla \cdot
\f
rac{\partial F}{\partial
\n
abla v}
- assumes that gradients are represented by Diff() node (from Chapman Enskog module)
- Diff(Diff(r)) represents the divergence of r
- the constants parameter is a list with symbols not affected by the derivative. This is used for simplification
of the derivative terms.
"""
functional
=
expandUsingLinearity
(
functional
,
constants
=
constants
)
diffs
=
functional
.
atoms
(
Diff
)
diffV
=
Diff
(
v
)
assert
diffV
in
diffs
# not necessary in general, but for this use case this should be true
nonDiffPart
=
functional
.
subs
({
d
:
0
for
d
in
diffs
})
partialF_partialV
=
sp
.
diff
(
nonDiffPart
,
v
)
dummy
=
sp
.
Dummy
()
partialF_partialGradV
=
functional
.
subs
(
diffV
,
dummy
).
diff
(
dummy
).
subs
(
dummy
,
diffV
)
result
=
partialF_partialV
-
Diff
(
partialF_partialGradV
)
return
expandUsingLinearity
(
result
,
constants
=
constants
)
def
coshIntegral
(
f
,
var
):
"""
Integrates a function f that has exactly one cosh term, from -oo to oo, by
substituting a new helper variable for the cosh argument
"""
coshTerm
=
list
(
f
.
atoms
(
sp
.
cosh
))
assert
len
(
coshTerm
)
==
1
integral
=
sp
.
Integral
(
f
,
var
)
transformedInt
=
integral
.
transform
(
coshTerm
[
0
].
args
[
0
],
sp
.
Symbol
(
"
u
"
,
real
=
True
))
return
sp
.
integrate
(
transformedInt
.
args
[
0
],
(
transformedInt
.
args
[
1
][
0
],
-
sp
.
oo
,
sp
.
oo
))
def
discreteLaplace
(
field
,
index
,
dx
):
"""
Returns second order Laplace stencil
"""
dim
=
field
.
spatialDimensions
count
=
0
result
=
0
for
d
in
range
(
dim
):
for
offset
in
(
-
1
,
1
):
count
+=
1
result
+=
field
.
neighbor
(
d
,
offset
)(
index
)
result
-=
count
*
field
.
center
(
index
)
result
/=
dx
**
2
return
result
def
symmetricSymbolicSurfaceTension
(
i
,
j
):
"""
Returns symbolic surface tension. The function is symmetric, i.e. interchanging i and j yields the same result.
If both phase indices i and j are chosen equal, zero is returned
"""
...
...
@@ -181,6 +125,20 @@ def freeEnergyFunctionalNPhases(numPhases=None, surfaceTensions=symmetricSymboli
return
result
def
separateIntoBulkAndInterface
(
freeEnergy
):
"""
Separates the bulk and interface parts of a free energy
>>>
F
=
freeEnergyFunctionalNPhases
(
3
)
>>>
bulk
,
inter
=
separateIntoBulkAndInterface
(
F
)
>>>
assert
sp
.
expand
(
bulk
-
freeEnergyFunctionalNPhases
(
3
,
includeInterface
=
False
))
==
0
>>>
assert
sp
.
expand
(
inter
-
freeEnergyFunctionalNPhases
(
3
,
includeBulk
=
False
))
==
0
"""
freeEnergy
=
freeEnergy
.
expand
()
bulkPart
=
freeEnergy
.
subs
({
a
:
0
for
a
in
freeEnergy
.
atoms
(
Diff
)})
interfacePart
=
freeEnergy
-
bulkPart
return
bulkPart
,
interfacePart
def
analyticInterfaceProfile
(
x
,
interfaceWidth
=
interfaceWidthSymbol
):
"""
Analytic expression for a 1D interface normal to x with given interface width
...
...
@@ -238,6 +196,62 @@ def createForceUpdateEquations(forceField, phiField, muField, dx=1):
return
forceSweepEqs
def
functionalDerivative
(
functional
,
v
,
constants
=
None
):
"""
Computes functional derivative of functional with respect to v using Euler-Lagrange equation
.. math ::
\f
rac{\delta F}{\delta v} =
\f
rac{\partial F}{\partial v} -
\n
abla \cdot
\f
rac{\partial F}{\partial
\n
abla v}
- assumes that gradients are represented by Diff() node (from Chapman Enskog module)
- Diff(Diff(r)) represents the divergence of r
- the constants parameter is a list with symbols not affected by the derivative. This is used for simplification
of the derivative terms.
"""
functional
=
expandUsingLinearity
(
functional
,
constants
=
constants
)
diffs
=
functional
.
atoms
(
Diff
)
diffV
=
Diff
(
v
)
#assert diffV in diffs # not necessary in general, but for this use case this should be true
nonDiffPart
=
functional
.
subs
({
d
:
0
for
d
in
diffs
})
partialF_partialV
=
sp
.
diff
(
nonDiffPart
,
v
)
dummy
=
sp
.
Dummy
()
partialF_partialGradV
=
functional
.
subs
(
diffV
,
dummy
).
diff
(
dummy
).
subs
(
dummy
,
diffV
)
result
=
partialF_partialV
-
Diff
(
partialF_partialGradV
)
return
expandUsingLinearity
(
result
,
constants
=
constants
)
def
coshIntegral
(
f
,
var
):
"""
Integrates a function f that has exactly one cosh term, from -oo to oo, by
substituting a new helper variable for the cosh argument
"""
coshTerm
=
list
(
f
.
atoms
(
sp
.
cosh
))
assert
len
(
coshTerm
)
==
1
integral
=
sp
.
Integral
(
f
,
var
)
transformedInt
=
integral
.
transform
(
coshTerm
[
0
].
args
[
0
],
sp
.
Symbol
(
"
u
"
,
real
=
True
))
return
sp
.
integrate
(
transformedInt
.
args
[
0
],
(
transformedInt
.
args
[
1
][
0
],
-
sp
.
oo
,
sp
.
oo
))
def
discreteLaplace
(
field
,
index
,
dx
):
"""
Returns second order Laplace stencil
"""
dim
=
field
.
spatialDimensions
count
=
0
result
=
0
for
d
in
range
(
dim
):
for
offset
in
(
-
1
,
1
):
count
+=
1
result
+=
field
.
neighbor
(
d
,
offset
)(
index
)
result
-=
count
*
field
.
center
(
index
)
result
/=
dx
**
2
return
result
def
cahnHilliardFdEq
(
phaseIdx
,
phi
,
mu
,
velocity
,
mobility
,
dx
,
dt
):
from
pystencils.finitedifferences
import
transient
,
advection
,
diffusion
,
Discretization2ndOrder
cahnHilliard
=
transient
(
phi
,
phaseIdx
)
+
advection
(
phi
,
velocity
,
phaseIdx
)
-
diffusion
(
mu
,
mobility
,
phaseIdx
)
...
...
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