Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F98639678
test_bridging.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
Wed, Jan 15, 04:09
Size
4 KB
Mime Type
text/x-python
Expires
Fri, Jan 17, 04:09 (2 d)
Engine
blob
Format
Raw Data
Handle
23611445
Attached To
rLIBMULTISCALE LibMultiScale
test_bridging.py
View Options
#!/usr/bin/python3
import
pylibmultiscale
as
lm
import
pytest
import
numpy
as
np
################################################################
# geometrical properties
################################################################
r0
=
1.23157195294235
nb_atoms
=
1000
LMD
=
nb_atoms
*
r0
el_size
=
8.1
*
r0
nb_el
=
300
LFE
=
el_size
*
nb_el
bridging_size
=
el_size
*
10
rcut
=
2.2
*
r0
################################################################
lm
.
loadModules
()
Dim
=
3
lm
.
print_trace
.
fset
(
True
)
comm
=
lm
.
Communicator
.
getCommunicator
()
nb_proc
=
comm
.
getNumberFreeProcs
()
comm
.
addGroup
(
'md'
,
nb_proc
)
md_group
=
lm
.
Communicator
.
getGroup
(
'md'
)
fe_group
=
md_group
md_geom
=
lm
.
Ball
(
Dim
,
'md_geom'
)
md_geom
.
params
.
center
=
[
0
]
md_geom
.
params
.
radii
=
[
0
,
LMD
+
bridging_size
]
md_geom
.
init
()
fe_geom
=
lm
.
Ball
(
Dim
,
'fe_geom'
)
fe_geom
.
params
.
center
=
[
0
]
fe_geom
.
params
.
radii
=
[
LMD
,
LMD
+
LFE
]
fe_geom
.
init
()
# coupling geom
bridge_geom
=
lm
.
Ball
(
Dim
,
'bridge_geom'
)
bridge_geom
.
params
.
center
=
[
0
]
bridge_geom
.
params
.
radii
=
[
LMD
,
LMD
+
bridging_size
-
el_size
]
bridge_geom
.
init
()
gManager
=
lm
.
GeometryManager
.
getManager
()
gManager
.
addGeometry
(
md_geom
)
gManager
.
addGeometry
(
fe_geom
)
gManager
.
addGeometry
(
bridge_geom
)
@pytest.fixture
def
managers
():
lm
.
FilterManager
.
getManager
(
Dim
)
lm
.
ActionManager
.
getManager
(
Dim
)
lm
.
DomainMultiScale
.
getManager
()
yield
lm
.
FilterManager
.
destroy
()
lm
.
ActionManager
.
destroy
()
lm
.
DomainMultiScale
.
destroy
()
def
test_create_domain
(
managers
):
domMD
=
lm
.
DomainMD1D
(
'md'
,
md_group
)
domMD
.
params
.
rcut
=
rcut
domMD
.
params
.
r0
=
r0
domMD
.
params
.
mass
=
39.95
domMD
.
params
.
timestep
=
10
domMD
.
params
.
epsilon
=
1.6567944e-21
/
6.94769e-21
domMD
.
params
.
sigma
=
1.1
domMD
.
params
.
domain_geometry
=
"md_geom"
domMD
.
init
()
lm
.
DomainMultiScale
.
getManager
()
.
addObject
(
domMD
)
domFE
=
lm
.
DomainMeca1D
(
'fe'
,
fe_group
)
domFE
.
params
.
elem_size
=
el_size
domFE
.
params
.
domain_geometry
=
"fe_geom"
domFE
.
params
.
mass
=
39.95
domFE
.
params
.
r0
=
r0
domFE
.
params
.
rcut
=
rcut
domFE
.
params
.
epsilon
=
1.6567944e-21
/
6.94769e-21
domFE
.
params
.
sigma
=
1.1
domFE
.
params
.
timestep
=
10
domFE
.
init
()
lm
.
DomainMultiScale
.
getManager
()
.
addObject
(
domFE
)
return
domMD
,
domFE
@pytest.fixture
def
domains
(
managers
):
return
test_create_domain
(
managers
)
def
test_bridge_init
(
domains
):
domMD
,
domFE
=
domains
assert
domMD
is
not
None
assert
domFE
is
not
None
bridge
=
lm
.
Bridging
(
"test"
)
bridge
.
params
.
geometry
=
"bridge_geom"
bridge
.
init
(
domMD
.
getContainer
(),
domFE
.
getContainer
())
return
domMD
,
domFE
,
bridge
@pytest.fixture
def
bridge_domain
(
domains
):
return
test_bridge_init
(
domains
)
def
test_bridge_constant_field_interpolation
(
bridge_domain
):
domMD
,
domFE
,
bridge
=
bridge_domain
extract
=
lm
.
ComputeExtract
(
'extractor'
)
extract
.
params
.
field
=
lm
.
position0
extract
.
compute
(
bridge
.
meshList
)
pos0
=
extract
.
evalArrayOutput
()
.
array
()
set_field
=
lm
.
StimulationField
(
'set'
)
set_field
.
params
.
field
=
lm
.
position
set_field
.
compute
(
dofs
=
bridge
.
meshList
,
field
=
np
.
ones_like
(
pos0
))
out
=
lm
.
ContainerArrayReal
(
bridge
.
pointList
.
castContainer
()
.
size
())
bridge
.
mesh2Point
(
lm
.
position
,
out
)
assert
(
out
.
array
()
==
np
.
ones_like
(
out
.
array
()))
.
all
()
def
test_bridge_linear_field_interpolation
(
bridge_domain
):
domMD
,
domFE
,
bridge
=
bridge_domain
extract
=
lm
.
ComputeExtract
(
'extractor'
)
extract
.
params
.
field
=
lm
.
position0
extract
.
compute
(
bridge
.
meshList
)
pos0
=
extract
.
evalArrayOutput
()
.
array
()
set_field
=
lm
.
StimulationField
(
'set'
)
set_field
.
params
.
field
=
lm
.
position
alpha
=
1.45
beta
=
4.546
linear_field
=
pos0
*
alpha
+
beta
set_field
.
compute
(
dofs
=
bridge
.
meshList
,
field
=
linear_field
)
out
=
lm
.
ContainerArrayReal
(
bridge
.
pointList
.
castContainer
()
.
size
())
bridge
.
mesh2Point
(
lm
.
position
,
out
)
extract
.
params
.
field
=
lm
.
position0
extract
.
compute
(
bridge
.
pointList
)
pos0
=
extract
.
evalArrayOutput
()
.
array
()
assert
out
.
array
()
.
shape
==
pos0
.
shape
assert
(
np
.
abs
(
out
.
array
()
-
(
pos0
*
alpha
+
beta
))
<
1e-12
)
.
all
()
Event Timeline
Log In to Comment