Skip to content

Commit

Permalink
Moving residual fix from datatype to problem class
Browse files Browse the repository at this point in the history
  • Loading branch information
pancetta committed Dec 26, 2023
1 parent d337dc9 commit 61145dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
5 changes: 0 additions & 5 deletions pySDC/implementations/datatype_classes/fenics_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ def __abs__(self):
# return maximum
return absval

def fix_bc(self, bc):
bc.apply(self.values.vector())

return None


class rhs_fenics_mesh(object):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ class fenics_heat(ptype):
The forcing term :math:`f` in the heat equation.
bc : DirichletBC
Denotes the Dirichlet boundary conditions.
bc_hom : DirichletBC
Denotes the homogeneous Dirichlet boundary conditions, potentially required for fixing the residual
fix_bc_for_residual: boolean
flag to indicate that the residual requires special treatment due to boundary conditions
References
----------
Expand Down Expand Up @@ -129,10 +125,9 @@ def Boundary(x, on_boundary):
self.M = df.assemble(a_M)
self.K = df.assemble(a_K)

# set boundary values, incl. homogeneous ones for the residual
# set boundary values
self.bc = df.DirichletBC(self.V, df.Constant(c), Boundary)
self.bc_hom = df.DirichletBC(self.V, df.Constant(0), Boundary)
self.fix_bc_for_residual = True

# set forcing term as expression
self.g = df.Expression(
Expand Down Expand Up @@ -360,7 +355,11 @@ class fenics_heat_mass(fenics_heat):
g : Expression
The forcing term :math:`f` in the heat equation.
bc : DirichletBC
Denotes the Dirichlet boundary conditions (currently not used here).
Denotes the Dirichlet boundary conditions.
bc_hom : DirichletBC
Denotes the homogeneous Dirichlet boundary conditions, potentially required for fixing the residual
fix_bc_for_residual: boolean
flag to indicate that the residual requires special treatment due to boundary conditions
References
----------
Expand All @@ -370,6 +369,13 @@ class fenics_heat_mass(fenics_heat):
Wells and others. Springer (2012).
"""

def __init__(self, c_nvars=128, t0=0.0, family='CG', order=4, refinements=1, nu=0.1, c=0.0):
"""Initialization routine"""

super().__init__(c_nvars, t0, family, order, refinements, nu, c)

self.fix_bc_for_residual = True

def solve_system(self, rhs, factor, u0, t):
r"""
Dolfin's linear solver for :math:`(M - factor A) \vec{u} = \vec{rhs}`.
Expand Down Expand Up @@ -428,3 +434,15 @@ def eval_f(self, u, t):
f.expl = self.apply_mass_matrix(f.expl)

return f

def fix_residual(self, res):
"""
Applies homogeneous Dirichlet boundary conditions to the residual
Parameters
----------
res : dtype_u
Residual
"""
self.bc_hom.apply(res.values.vector())
return None
3 changes: 2 additions & 1 deletion pySDC/implementations/sweeper_classes/imex_1st_order_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def compute_residual(self, stage=None):
# add tau if associated
if L.tau[m] is not None:
res[m] += L.tau[m]
# Due to different boundary conditions we might have to fix the residual
if L.prob.fix_bc_for_residual:
res[m].fix_bc(L.prob.bc_hom)
L.prob.fix_residual(res[m])
# use abs function from data type here
res_norm.append(abs(res[m]))

Expand Down

0 comments on commit 61145dc

Please sign in to comment.