Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85136458
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
Fri, Sep 27, 00:52
Size
4 KB
Mime Type
text/x-python
Expires
Sun, Sep 29, 00:52 (2 d)
Engine
blob
Format
Raw Data
Handle
21133507
Attached To
R6746 RationalROMPy
boundary_conditions.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/>.
#
from
fenics
import
SubDomain
,
AutoSubDomain
from
rrompy.utilities.base.types
import
GenExpr
from
rrompy.utilities.fenics
import
bdrFalse
from
rrompy.utilities.exception_manager
import
RROMPyException
__all__
=
[
'BoundaryConditions'
]
class
BoundaryConditions
:
"""
Boundary conditions manager.
Attributes:
DirichletBoundary: Callable returning True when on Dirichlet boundary.
NeumannBoundary: Callable returning True when on Neumann boundary.
RobinBoundary: Callable returning True when on Robin boundary.
"""
allowedKinds
=
[
"Dirichlet"
,
"Neumann"
,
"Robin"
]
def
__init__
(
self
,
kind
:
str
=
None
):
if
kind
is
None
:
return
kind
=
kind
[
0
]
.
upper
()
+
kind
[
1
:]
.
lower
()
if
kind
in
self
.
allowedKinds
:
getattr
(
self
.
__class__
,
kind
+
"Boundary"
,
None
)
.
fset
(
self
,
"ALL"
)
else
:
raise
RROMPyException
(
"BC kind not recognized."
)
def
name
(
self
)
->
str
:
return
self
.
__class__
.
__name__
def
__str__
(
self
)
->
str
:
return
self
.
name
()
def
__repr__
(
self
)
->
str
:
return
self
.
__str__
()
+
" at "
+
hex
(
id
(
self
))
def
_generalManagement
(
self
,
kind
:
str
,
value
:
GenExpr
):
if
isinstance
(
value
,
(
str
,)):
value
=
value
.
upper
()
if
value
.
upper
()
==
"ALL"
:
self
.
_complementaryManagementAll
(
kind
)
elif
value
.
upper
()
==
"REST"
:
self
.
_complementaryManagementRest
(
kind
)
else
:
raise
RROMPyException
(
"Wildcard not recognized."
)
elif
callable
(
value
):
self
.
_standardManagementCallable
(
kind
,
value
)
elif
isinstance
(
value
,
(
SubDomain
,)):
self
.
_standardManagement
(
kind
,
value
)
else
:
raise
RROMPyException
(
kind
+
"Boundary type not recognized."
)
def
_complementaryManagementAll
(
self
,
kind
:
str
):
if
kind
not
in
self
.
allowedKinds
:
raise
RROMPyException
(
"BC kind not recognized."
)
for
k
in
self
.
allowedKinds
:
if
k
!=
kind
:
self
.
_standardManagementCallable
(
k
,
bdrFalse
)
self
.
_complementaryManagementRest
(
kind
)
def
_complementaryManagementRest
(
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
.
_standardManagement
(
k
,
bdrFalse
)
otherBCs
+=
[
getattr
(
self
,
k
+
"Boundary"
)]
def
restCall
(
x
,
on_boundary
):
return
(
on_boundary
and
not
any
([
bc
.
inside
(
x
,
on_boundary
)
for
bc
in
otherBCs
]))
self
.
_standardManagementCallable
(
kind
,
restCall
)
super
()
.
__setattr__
(
"_"
+
kind
+
"Rest"
,
1
)
def
_standardManagementCallable
(
self
,
kind
:
str
,
bc
:
callable
):
bcSD
=
AutoSubDomain
(
bc
)
self
.
_standardManagement
(
kind
,
bcSD
)
def
_standardManagement
(
self
,
kind
:
str
,
bc
:
SubDomain
):
super
()
.
__setattr__
(
"_"
+
kind
+
"Boundary"
,
bc
)
if
hasattr
(
self
,
"_"
+
kind
+
"Rest"
):
super
()
.
__delattr__
(
"_"
+
kind
+
"Rest"
)
@property
def
DirichletBoundary
(
self
):
"""Function handle to DirichletBoundary."""
return
self
.
_DirichletBoundary
@DirichletBoundary.setter
def
DirichletBoundary
(
self
,
DirichletBoundary
):
self
.
_generalManagement
(
"Dirichlet"
,
DirichletBoundary
)
@property
def
NeumannBoundary
(
self
):
"""Function handle to NeumannBoundary."""
return
self
.
_NeumannBoundary
@NeumannBoundary.setter
def
NeumannBoundary
(
self
,
NeumannBoundary
):
self
.
_generalManagement
(
"Neumann"
,
NeumannBoundary
)
@property
def
RobinBoundary
(
self
):
"""Function handle to RobinBoundary."""
return
self
.
_RobinBoundary
@RobinBoundary.setter
def
RobinBoundary
(
self
,
RobinBoundary
):
self
.
_generalManagement
(
"Robin"
,
RobinBoundary
)
Event Timeline
Log In to Comment