Page MenuHomec4science

fenics_norms.py
No OneTemporary

File Metadata

Created
Sun, Sep 1, 13:05

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, FenFuncSpace
from scipy.sparse import csr_matrix
__all__ = ['L2NormMatrix', 'H1NormMatrix', 'elasticNormMatrix']
def _fen2sp(expr):
matFen = fen.as_backend_type(fen.assemble(expr)).mat()
return csr_matrix(matFen.getValuesCSR()[::-1], shape = matFen.size)
def L2NormMatrix(V:FenFuncSpace) -> Np2D:
u = fen.TrialFunction(V)
v = fen.TestFunction(V)
return _fen2sp(fen.dot(u, v) * fen.dx)
def H1NormMatrix(V:FenFuncSpace, w : FenFunc = 0.) -> Np2D:
u = fen.TrialFunction(V)
v = fen.TestFunction(V)
return _fen2sp((w * fen.dot(u, v)
+ fen.dot(fen.grad(u), fen.grad(v))) * fen.dx)
def elasticNormMatrix(V:FenFuncSpace, l_:FenFunc, m_:FenFunc,
w : FenFunc = 0.) -> 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 _fen2sp((w * fen.dot(u, v) + fen.inner(sigma, epsilon(v))) * fen.dx)

Event Timeline