Skip to content
Snippets Groups Projects
Commit c060718c authored by Dominic Kempf's avatar Dominic Kempf
Browse files

dirichlet_expression -> interpolate_expression

There is way more reasons to interpolate a function into the
solution vector and we cover them with one code path:
* Dirichlet boundary conditions (strong ones)
* Initial conditions for instationary expressions
* Initial guesses for Newton solvers
parent 5081753a
No related branches found
No related tags found
No related merge requests found
Showing
with 25 additions and 29 deletions
...@@ -92,7 +92,7 @@ def read_ufl(uflfile): ...@@ -92,7 +92,7 @@ def read_ufl(uflfile):
if get_option("exact_solution_expression"): if get_option("exact_solution_expression"):
data.object_by_name[get_option("exact_solution_expression")] = namespace[get_option("exact_solution_expression")] data.object_by_name[get_option("exact_solution_expression")] = namespace[get_option("exact_solution_expression")]
magic_names = ("dirichlet_expression", magic_names = ("interpolate_expression",
"is_dirichlet", "is_dirichlet",
"exact_solution", "exact_solution",
) )
......
...@@ -192,8 +192,11 @@ def unroll_list_tensors(data): ...@@ -192,8 +192,11 @@ def unroll_list_tensors(data):
yield e yield e
def preprocess_leaf_data(element, data): def preprocess_leaf_data(element, data, applyZeroDefault=True):
data = get_object(data) data = get_object(data)
if data is None and not applyZeroDefault:
return None
from ufl import MixedElement from ufl import MixedElement
if isinstance(element, MixedElement): if isinstance(element, MixedElement):
# data is None -> use 0 default # data is None -> use 0 default
......
...@@ -67,7 +67,7 @@ def time_loop(): ...@@ -67,7 +67,7 @@ def time_loop():
osm = name_explicitonestepmethod() osm = name_explicitonestepmethod()
apply_call = "{}.apply(time, dt, {}, {}new);".format(osm, vector, vector) apply_call = "{}.apply(time, dt, {}, {}new);".format(osm, vector, vector)
else: else:
dirichlet = preprocess_leaf_data(element, "dirichlet_expression") dirichlet = preprocess_leaf_data(element, "interpolate_expression")
boundary = name_boundary_function(element, dirichlet) boundary = name_boundary_function(element, dirichlet)
osm = name_onestepmethod() osm = name_onestepmethod()
apply_call = "{}.apply(time, dt, {}, {}, {}new);".format(osm, vector, boundary, vector) apply_call = "{}.apply(time, dt, {}, {}, {}new);".format(osm, vector, boundary, vector)
......
...@@ -18,20 +18,13 @@ from dune.perftool.pdelab.driver.gridoperator import (name_parameters,) ...@@ -18,20 +18,13 @@ from dune.perftool.pdelab.driver.gridoperator import (name_parameters,)
from ufl import FiniteElement, MixedElement, TensorElement, VectorElement, TensorProductElement from ufl import FiniteElement, MixedElement, TensorElement, VectorElement, TensorProductElement
def _do_interpolate(dirichlet):
if isinstance(dirichlet, (list, tuple)):
return any(bool(d) for d in dirichlet)
else:
return bool(dirichlet)
def interpolate_dirichlet_data(name): def interpolate_dirichlet_data(name):
element = get_trial_element() element = get_trial_element()
is_dirichlet = preprocess_leaf_data(element, "is_dirichlet") func = preprocess_leaf_data(element, "interpolate_expression", applyZeroDefault=False)
if _do_interpolate(is_dirichlet) or not is_stationary(): if func is not None:
bf = name_boundary_function(element, func)
gfs = name_trial_gfs() gfs = name_trial_gfs()
dirichlet = preprocess_leaf_data(element, "dirichlet_expression")
bf = name_boundary_function(element, dirichlet)
interpolate_vector(bf, gfs, name) interpolate_vector(bf, gfs, name)
......
...@@ -10,6 +10,6 @@ u = TrialFunction(V) ...@@ -10,6 +10,6 @@ u = TrialFunction(V)
v = TestFunction(V) v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) + u*u*v - f*v)*dx] forms = [(inner(grad(u), grad(v)) + u*u*v - f*v)*dx]
dirichlet_expression = g interpolate_expression = g
exact_solution = g exact_solution = g
is_dirichlet = 1 is_dirichlet = 1
...@@ -11,6 +11,6 @@ v = TestFunction(V) ...@@ -11,6 +11,6 @@ v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx] forms = [(inner(grad(u), grad(v)) - f*v)*dx]
dirichlet_expression = g interpolate_expression = g
exact_solution = g exact_solution = g
is_dirichlet = 1 is_dirichlet = 1
...@@ -10,6 +10,6 @@ u = TrialFunction(V) ...@@ -10,6 +10,6 @@ u = TrialFunction(V)
v = TestFunction(V) v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx] forms = [(inner(grad(u), grad(v)) - f*v)*dx]
dirichlet_expression = g interpolate_expression = g
exact_solution = g exact_solution = g
is_dirichlet = 1 is_dirichlet = 1
...@@ -17,6 +17,6 @@ v = TestFunction(V) ...@@ -17,6 +17,6 @@ v = TestFunction(V)
ds = ds(subdomain_data=bctype) ds = ds(subdomain_data=bctype)
forms = [(inner(grad(u), grad(v)) - f*v)*dx - j*v*ds(0)] forms = [(inner(grad(u), grad(v)) - f*v)*dx - j*v*ds(0)]
dirichlet_expression = g interpolate_expression = g
exact_solution = g exact_solution = g
is_dirichlet = bctype is_dirichlet = bctype
...@@ -13,6 +13,6 @@ u = TrialFunction(V) ...@@ -13,6 +13,6 @@ u = TrialFunction(V)
v = TestFunction(V) v = TestFunction(V)
forms = [(inner(A*grad(u), grad(v)) + c*u*v -f*v)*dx] forms = [(inner(A*grad(u), grad(v)) + c*u*v -f*v)*dx]
dirichlet_expression = g interpolate_expression = g
exact_solution = g exact_solution = g
is_dirichlet = 1 is_dirichlet = 1
...@@ -15,5 +15,5 @@ r = (inner(grad(v), grad(u)) - div(v)*p - q*div(u))*dx ...@@ -15,5 +15,5 @@ r = (inner(grad(v), grad(u)) - div(v)*p - q*div(u))*dx
forms = [r] forms = [r]
is_dirichlet = v_bctype, v_bctype, 0 is_dirichlet = v_bctype, v_bctype, 0
dirichlet_expression = g_v, None interpolate_expression = g_v, None
exact_solution = g_v, 8.*(1.-x[0]) exact_solution = g_v, 8.*(1.-x[0])
...@@ -14,6 +14,6 @@ mass = (u*v)*dx ...@@ -14,6 +14,6 @@ mass = (u*v)*dx
poisson = (inner(grad(u), grad(v)) - f*v)*dx poisson = (inner(grad(u), grad(v)) - f*v)*dx
forms = [mass, poisson] forms = [mass, poisson]
dirichlet_expression = g interpolate_expression = g
is_dirichlet = 1 is_dirichlet = 1
exact_solution = g exact_solution = g
\ No newline at end of file
...@@ -33,6 +33,6 @@ poisson = inner(grad(u), grad(v))*dx \ ...@@ -33,6 +33,6 @@ poisson = inner(grad(u), grad(v))*dx \
mass = (u*v)*dx mass = (u*v)*dx
forms = [mass, poisson] forms = [mass, poisson]
dirichlet_expression = g interpolate_expression = g
is_dirichlet = 1 is_dirichlet = 1
exact_solution = g exact_solution = g
\ No newline at end of file
...@@ -17,6 +17,6 @@ mass = (u*v)*dx ...@@ -17,6 +17,6 @@ mass = (u*v)*dx
poisson = (inner(grad(u), grad(v)) - f*v)*dx poisson = (inner(grad(u), grad(v)) - f*v)*dx
forms = [mass, poisson] forms = [mass, poisson]
dirichlet_expression = g interpolate_expression = g
is_dirichlet = 1 is_dirichlet = 1
exact_solution = g exact_solution = g
...@@ -29,4 +29,4 @@ r = -1. * inner(flux, grad(v))*dx \ ...@@ -29,4 +29,4 @@ r = -1. * inner(flux, grad(v))*dx \
+ inner(u, v)*ds + inner(u, v)*ds
forms = [mass, r] forms = [mass, r]
dirichlet_expression = f, 0.0, 0.0 interpolate_expression = f, 0.0, 0.0
...@@ -27,5 +27,5 @@ r = -1.*u*inner(beta, grad(v))*dx \ ...@@ -27,5 +27,5 @@ r = -1.*u*inner(beta, grad(v))*dx \
forms = [mass, r] forms = [mass, r]
is_dirichlet = dirichlet is_dirichlet = dirichlet
dirichlet_expression = initial interpolate_expression = initial
exact_solution = 0 exact_solution = 0
\ No newline at end of file
...@@ -33,4 +33,4 @@ r = -1. * inner(flux, grad(v))*dx \ ...@@ -33,4 +33,4 @@ r = -1. * inner(flux, grad(v))*dx \
+ inner(boundary_flux, v)*ds + inner(boundary_flux, v)*ds
forms = [mass, r] forms = [mass, r]
dirichlet_expression = f, 0.0 interpolate_expression = f, 0.0
...@@ -32,4 +32,4 @@ poisson = inner(K*grad(u), grad(v))*dx \ ...@@ -32,4 +32,4 @@ poisson = inner(K*grad(u), grad(v))*dx \
mass = (u*v)*dx mass = (u*v)*dx
forms = [mass, poisson] forms = [mass, poisson]
dirichlet_expression = sin(pi*x[0]) interpolate_expression = sin(pi*x[0])
...@@ -12,5 +12,5 @@ r = (inner(grad(u), grad(v)) + u*u*v - f*v)*dx ...@@ -12,5 +12,5 @@ r = (inner(grad(u), grad(v)) + u*u*v - f*v)*dx
forms = [r] forms = [r]
exact_solution = g exact_solution = g
dirichlet_expression = g interpolate_expression = g
is_dirichlet = 1 is_dirichlet = 1
\ No newline at end of file
...@@ -12,4 +12,4 @@ v = TestFunction(V) ...@@ -12,4 +12,4 @@ v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx] forms = [(inner(grad(u), grad(v)) - f*v)*dx]
exact_solution = g exact_solution = g
is_dirichlet = 1 is_dirichlet = 1
dirichlet_expression = g interpolate_expression = g
...@@ -12,4 +12,4 @@ v = TestFunction(V) ...@@ -12,4 +12,4 @@ v = TestFunction(V)
forms = [(inner(grad(u), grad(v)) - f*v)*dx] forms = [(inner(grad(u), grad(v)) - f*v)*dx]
exact_solution = g exact_solution = g
is_dirichlet = 1 is_dirichlet = 1
dirichlet_expression = g interpolate_expression = g
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment