Page MenuHomec4science

fenics_norms.py
No OneTemporary

File Metadata

Created
Sat, Apr 27, 08:50

fenics_norms.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
from rrompy.utilities.base.types import Np2D, FenFunc, DictAny, FenFuncSpace
from rrompy.solver.norm_utilities import (Np2DLikeEye, Np2DLikeInv,
Np2DLikeInvLowRank)
from .fenics_la import fenics2Sparse
__all__ = ['L2NormMatrix', 'L2InverseNormMatrix', 'H1NormMatrix',
'Hminus1NormMatrix', 'elasticNormMatrix', 'elasticDualNormMatrix']
def L2NormMatrix(V:FenFuncSpace, r_ : FenFunc = 1.) -> Np2D:
u = fen.TrialFunction(V)
v = fen.TestFunction(V)
return fenics2Sparse(r_ * fen.dot(u, v) * fen.dx)
def L2InverseNormMatrix(V:FenFuncSpace, r_ : FenFunc = 1.,
solverType : str = "SPSOLVE",
solverArgs : DictAny = {}, compressRank : int = None,
compressOversampling : int = 10,
compressSeed : int = 420) -> Np2D:
L2Mat = L2NormMatrix(V, r_)
if compressRank is None:
return Np2DLikeInv(L2Mat, Np2DLikeEye(L2Mat.shape[0]), solverType,
solverArgs)
return Np2DLikeInvLowRank(L2Mat, Np2DLikeEye(L2Mat.shape[0]), solverType,
solverArgs, compressRank, compressOversampling,
compressSeed)
def H1NormMatrix(V:FenFuncSpace, w : float = 0., r_ : FenFunc = 1.,
a_ : FenFunc = 1.) -> Np2D:
u = fen.TrialFunction(V)
v = fen.TestFunction(V)
return fenics2Sparse((w * r_ * fen.dot(u, v)
+ fen.dot(a_ * fen.grad(u), fen.grad(v))) * fen.dx)
def Hminus1NormMatrix(V:FenFuncSpace, w : float = 0., r_ : FenFunc = 1.,
a_ : FenFunc = 1., solverType : str = "SPSOLVE",
solverArgs : DictAny = {}, compressRank : int = None,
compressOversampling : int = 10,
compressSeed : int = 420, duality : bool = True) -> Np2D:
H1Mat = H1NormMatrix(V, w, r_, a_)
identity = L2NormMatrix(V, r_) if duality else Np2DLikeEye(H1Mat.shape[0])
if compressRank is None:
return Np2DLikeInv(H1Mat, identity, solverType, solverArgs)
return Np2DLikeInvLowRank(H1Mat, identity, solverType, solverArgs,
compressRank, compressOversampling, compressSeed)
def elasticNormMatrix(V:FenFuncSpace, l_:FenFunc, m_:FenFunc,
w : float = 0., r_ : FenFunc = 1.) -> Np2D:
u = fen.TrialFunction(V)
v = fen.TestFunction(V)
epsilon = lambda f: 0.5 * (fen.grad(f) + fen.nabla_grad(f))
sigma = (l_ * fen.div(u) * fen.Identity(u.geometric_dimension())
+ 2. * m_ * epsilon(u))
return fenics2Sparse((w * r_ * fen.dot(u, v)
+ fen.inner(sigma, epsilon(v))) * fen.dx)
def elasticDualNormMatrix(V:FenFuncSpace, l_:FenFunc, m_:FenFunc,
w : float = 0., solverType : str = "SPSOLVE",
solverArgs : DictAny = {}, r_ : FenFunc = 1.,
compressRank : int = None,
compressOversampling : int = 10,
compressSeed : int = 420,
duality : bool = True) -> Np2D:
elMat = elasticNormMatrix(V, l_, m_, w, r_)
identity = L2NormMatrix(V, r_) if duality else Np2DLikeEye(elMat.shape[0])
if compressRank is None:
return Np2DLikeInv(elMat, identity, solverType, solverArgs)
return Np2DLikeInvLowRank(elMat, identity, solverType, solverArgs,
compressRank, compressOversampling, compressSeed)

Event Timeline