Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90012759
boundary_conditions.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
Mon, Oct 28, 10:53
Size
3 KB
Mime Type
text/x-python
Expires
Wed, Oct 30, 10:53 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21993697
Attached To
R6746 RationalROMPy
boundary_conditions.py
View Options
# Copyright (C) 2018-2020 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/>.
#
from
copy
import
copy
from
fenics
import
SubDomain
,
AutoSubDomain
from
rrompy.utilities.base.types
import
GenExpr
,
List
from
rrompy.solver.fenics
import
bdrFalse
from
rrompy.utilities.exception_manager
import
RROMPyException
__all__
=
[
'BoundaryConditions'
]
class
BoundaryConditions
:
"""Boundary conditions manager."""
def
__init__
(
self
,
kinds
:
List
[
str
]
=
[
"Dirichlet"
,
"Neumann"
,
"Robin"
]):
self
.
allowedKinds
=
kinds
kind
=
kinds
[
0
]
self
.
setAll
(
kind
)
def
name
(
self
)
->
str
:
return
self
.
__class__
.
__name__
def
__str__
(
self
)
->
str
:
return
self
.
name
()
def
__deepcopy__
(
self
,
memo
):
return
copy
(
self
)
def
__repr__
(
self
)
->
str
:
return
self
.
__str__
()
+
" at "
+
hex
(
id
(
self
))
def
get
(
self
,
kind
:
str
):
if
kind
not
in
self
.
allowedKinds
:
raise
RROMPyException
(
"BC kind not recognized."
)
return
getattr
(
self
,
"_"
+
kind
)
def
set
(
self
,
kind
:
str
,
value
:
GenExpr
):
if
isinstance
(
value
,
(
str
,)):
value
=
value
.
upper
()
if
value
.
upper
()
==
"ALL"
:
return
self
.
setAll
(
kind
)
if
value
.
upper
()
==
"REST"
:
return
self
.
setRest
(
kind
)
raise
RROMPyException
(
"Boundary wildcard not recognized."
)
if
callable
(
value
):
return
self
.
setCallable
(
kind
,
value
)
if
isinstance
(
value
,
(
SubDomain
,)):
return
self
.
setSubDomain
(
kind
,
value
)
else
:
raise
RROMPyException
(
"Boundary type not recognized."
)
def
setAll
(
self
,
kind
:
str
):
if
kind
not
in
self
.
allowedKinds
:
raise
RROMPyException
(
"BC kind not recognized."
)
for
k
in
self
.
allowedKinds
:
if
k
!=
kind
:
self
.
setCallable
(
k
,
bdrFalse
)
return
self
.
setRest
(
kind
)
def
setRest
(
self
,
kind
:
str
):
if
kind
not
in
self
.
allowedKinds
:
raise
RROMPyException
(
"BC kind not recognized."
)
otherBCs
=
[]
for
k
in
self
.
allowedKinds
:
if
k
!=
kind
:
if
hasattr
(
self
,
"_"
+
k
+
"Rest"
):
self
.
setCallable
(
k
,
bdrFalse
)
else
:
otherBCs
+=
[
getattr
(
self
,
"_"
+
k
)]
restCall
=
lambda
x
,
on_boundary
:
(
on_boundary
and
not
any
([
bc
.
inside
(
x
,
on_boundary
)
for
bc
in
otherBCs
]))
self
.
setCallable
(
kind
,
restCall
)
super
()
.
__setattr__
(
"_"
+
kind
+
"Rest"
,
1
)
def
setCallable
(
self
,
kind
:
str
,
bc
:
callable
):
return
self
.
setSubDomain
(
kind
,
AutoSubDomain
(
bc
))
def
setSubDomain
(
self
,
kind
:
str
,
bc
:
SubDomain
):
super
()
.
__setattr__
(
"_"
+
kind
,
bc
)
if
hasattr
(
self
,
"_"
+
kind
+
"Rest"
):
super
()
.
__delattr__
(
"_"
+
kind
+
"Rest"
)
Event Timeline
Log In to Comment