Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61089069
fenics_norms.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 4, 11:28
Size
3 KB
Mime Type
text/x-python
Expires
Mon, May 6, 11:28 (2 d)
Engine
blob
Format
Raw Data
Handle
17463479
Attached To
R6746 RationalROMPy
fenics_norms.py
View Options
# 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
(
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
,
1.
,
solverType
,
solverArgs
)
return
Np2DLikeInvLowRank
(
L2Mat
,
1.
,
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
)
->
Np2D
:
H1Mat
=
H1NormMatrix
(
V
,
w
,
r_
,
a_
)
if
compressRank
is
None
:
return
Np2DLikeInv
(
H1Mat
,
1.
,
solverType
,
solverArgs
)
return
Np2DLikeInvLowRank
(
H1Mat
,
1.
,
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
)
->
Np2D
:
elMat
=
elasticNormMatrix
(
V
,
l_
,
m_
,
w
,
r_
)
if
compressRank
is
None
:
return
Np2DLikeInv
(
elMat
,
1.
,
solverType
,
solverArgs
)
return
Np2DLikeInvLowRank
(
elMat
,
1.
,
solverType
,
solverArgs
,
compressRank
,
compressOversampling
,
compressSeed
)
Event Timeline
Log In to Comment