Page MenuHomec4science

membrane_fracture_nodomain_engine.py
No OneTemporary

File Metadata

Created
Mon, Nov 11, 08:58

membrane_fracture_nodomain_engine.py

# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import fenics as fen
import mshr, ufl
from rrompy.utilities.base.types import paramVal
from rrompy.solver.fenics import fenZERO, fenONE
from rrompy.hfengines.linear_problem.helmholtz_problem_engine import (
HelmholtzProblemEngine)
from rrompy.utilities.base import verbosityManager as vbMng
from rrompy.solver.fenics import fenics2Sparse
class MembraneFractureNoDomainEngine(HelmholtzProblemEngine):
def __init__(self, mu0 : paramVal = [20. ** .5, .6], H : float = 1.,
L : float = .75, delta : float = .05, n : int = 50,
*args, **kwargs):
super().__init__(mu0[0], *args, **kwargs)
self._affinePoly = True
self.npar = 1
self.lFrac = mu0[1]
self.H = H
self.rescalingExp = [2.]
domain = (mshr.Rectangle(fen.Point(0., - H / 2.),
fen.Point(2. * L + delta, H / 2.))
- mshr.Rectangle(fen.Point(L, 0.),
fen.Point(L + delta, H / 2.)))
mesh = mshr.generate_mesh(domain, n)
self.V = fen.FunctionSpace(mesh, "P", 1)
self.NeumannBoundary = lambda x, on_b: (on_b and x[1] >= - H / 4.
and x[0] >= L
and x[0] <= L + delta)
self.DirichletBoundary = "REST"
x, y = fen.SpatialCoordinate(mesh)[:]
self._belowIndicator = ufl.conditional(ufl.le(y, 0.), fenONE, fenZERO)
self._aboveIndicator = fenONE - self._belowIndicator
self.DirichletDatum = [fen.exp(- 10. * (H / 2. + y) / H
- .5 * ((x - .6 * L) / (.1 * L)) ** 2.
) * self._belowIndicator, fenZERO]
def buildA(self):
"""Build terms of operator of linear system."""
if self.thAs[0] is None: self.thAs = self.getMonomialWeights(self.nAs)
if self.As[0] is None:
self.autoSetDS()
vbMng(self, "INIT", "Assembling operator term A0.", 20)
DirichletBC0 = fen.DirichletBC(self.V, fenZERO,
self.DirichletBoundary)
a0Re = (fen.dot(self.u.dx(0), self.v.dx(0))
+ self.H ** 4 / 4. * (self.lFrac ** -2. * self._aboveIndicator
+ (self.H - self.lFrac) ** -2. * self._belowIndicator)
* fen.dot(self.u.dx(1), self.v.dx(1))
) * fen.dx
self.As[0] = fenics2Sparse(a0Re, {}, DirichletBC0, 1)
vbMng(self, "DEL", "Done assembling operator term.", 20)
if self.As[1] is None:
vbMng(self, "INIT", "Assembling operator term A1.", 20)
DirichletBC0 = fen.DirichletBC(self.V, fenZERO,
self.DirichletBoundary)
nRe, nIm = self.refractionIndex
n2Re, n2Im = nRe * nRe - nIm * nIm, 2 * nRe * nIm
parsRe = self.iterReduceQuadratureDegree(zip([n2Re],
["refractionIndexSquaredReal"]))
parsIm = self.iterReduceQuadratureDegree(zip([n2Im],
["refractionIndexSquaredImag"]))
a1Re = - n2Re * fen.dot(self.u, self.v) * fen.dx
a1Im = - n2Im * fen.dot(self.u, self.v) * fen.dx
self.As[1] = (fenics2Sparse(a1Re, parsRe, DirichletBC0, 0)
+ 1.j * fenics2Sparse(a1Im, parsIm, DirichletBC0, 0))
vbMng(self, "DEL", "Done assembling operator term.", 20)

Event Timeline