Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104717354
test_lammps.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
Tue, Mar 11, 19:12
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Mar 13, 19:12 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24830202
Attached To
rLIBMULTISCALE LibMultiScale
test_lammps.py
View Options
#!/usr/bin/python3
import
pylibmultiscale
as
lm
import
numpy
as
np
import
cv2
lm
.
loadModules
()
Dim
=
3
comm
=
lm
.
Communicator
.
getCommunicator
()
nb_proc
=
comm
.
getNumberFreeProcs
()
comm
.
addGroup
(
'md'
,
nb_proc
)
md_group
=
lm
.
Communicator
.
getGroup
(
'md'
)
A
=
4.047971240341177
L
=
200
class
ImageGeom
(
lm
.
Geometry
):
def
__init__
(
self
,
center
,
name
,
filename
):
super
()
.
__init__
(
3
,
name
)
self
.
center
=
np
.
array
(
center
)
self
.
img
=
np
.
array
(
cv2
.
imread
(
filename
))
# import matplotlib.pyplot as plt
# print(self.img.shape)
# print(self.img)
# plt.imshow(np.linalg.norm(self.img, axis=2))
# plt.show()
def
init
(
self
):
pass
def
contains
(
self
,
x
,
y
,
z
):
_x
=
int
((
x
-
self
.
center
[
0
]))
_y
=
int
((
y
-
self
.
center
[
1
]))
_x
+=
int
(
self
.
img
.
shape
[
0
]
/
2
)
_y
+=
int
(
self
.
img
.
shape
[
1
]
/
2
)
if
_x
>
self
.
img
.
shape
[
0
]
-
1
or
_x
<
0
:
return
False
if
_y
>
self
.
img
.
shape
[
1
]
-
1
or
_y
<
0
:
return
False
if
(
self
.
img
[
_x
,
_y
,
:]
==
[
255
,
255
,
255
])
.
all
():
return
False
return
True
gManager
=
lm
.
GeometryManager
.
getManager
()
gManager
.
reset
()
pineapple
=
ImageGeom
((
0
,
-
100
*
A
,
0
),
'pineapple'
,
'pineapple.png'
)
pizza
=
ImageGeom
((
0
,
100
*
A
,
0
),
'pizza'
,
'pizza.png'
)
gManager
.
addGeometry
(
pineapple
)
gManager
.
addGeometry
(
pizza
)
cube
=
lm
.
GeomUnion
(
3
,
'md_geom'
)
cube
.
params
.
ids
=
[
'pineapple'
,
'pizza'
]
cube
.
init
()
gManager
.
addGeometry
(
cube
)
lm
.
FilterManager
.
destroy
()
lm
.
ActionManager
.
destroy
()
lm
.
DomainMultiScale
.
destroy
()
dom
=
lm
.
DomainLammps3
(
'md'
,
md_group
)
open
(
"lammps.in"
,
'w'
)
.
write
(
"""
mass * 26.98153860
pair_style lj/cut 6.03863042319
pair_coeff * * 2.4621 2.596037
fix 2 all nve
"""
)
dom
.
params
.
lammps_file
=
"lammps.in"
dom
.
params
.
create_header
=
True
dom
.
params
.
boundary
=
[
's'
,
's'
,
'p'
]
dom
.
params
.
lattice
=
'fcc'
dom
.
params
.
lattice_size
=
A
dom
.
params
.
domain_geometry
=
"md_geom"
dom
.
params
.
replica
=
[
-
3
*
L
,
3
*
L
,
-
L
,
L
,
0
,
1
]
dom
.
params
.
lattice_origin
=
[
.
1
,
.
1
,
.
1
]
dom
.
params
.
timestep
=
1.
dom
.
init
()
lm
.
DomainMultiScale
.
getManager
()
.
addObject
(
dom
)
atoms_pineapple
=
lm
.
FilterGeometry
(
'atoms_pineapple'
)
atoms_pineapple
.
params
.
geometry
=
'pineapple'
atoms_pineapple
.
init
()
atoms_pineapple
.
compute
(
dom
.
getContainer
())
atoms_pizza
=
lm
.
FilterGeometry
(
'atoms_pizza'
)
atoms_pizza
.
params
.
geometry
=
'pizza'
atoms_pizza
.
init
()
atoms_pizza
.
compute
(
dom
.
getContainer
())
vel
=
lm
.
ComputeExtract
(
'vel_pineapple'
)
vel
.
params
.
field
=
lm
.
velocity
vel
.
init
()
vel
.
compute
(
atoms_pineapple
.
evalOutput
())
imposed_vel
=
vel
.
evalOutput
()
.
array
()
.
copy
()
imposed_vel
[:]
=
[
0.
,
10.
,
0.
]
impose
=
lm
.
StimulationField
(
'stim_vel'
)
impose
.
params
.
field
=
lm
.
velocity
impose
.
init
()
impose
.
compute
(
dofs
=
atoms_pineapple
.
evalOutput
(),
field
=
imposed_vel
)
dumper
=
lm
.
DumperParaview
(
'dumper'
)
dumper
.
params
.
input
=
'md'
dumper
.
params
.
force
=
True
dumper
.
params
.
disp
=
True
dumper
.
params
.
vel
=
True
dumper
.
init
()
dumper
.
dump
()
nb_step
=
10000
for
current_step
in
range
(
nb_step
):
lm
.
current_step
.
fset
(
current_step
)
current_time
+=
min_dt
if
shouldPrintState
:
printState
()
print
(
'current_stage: '
,
lm
.
current_stage
.
fget
())
lm
.
current_stage
.
fset
(
lm
.
PRE_DUMP
)
actions
.
action
()
lm
.
current_stage
.
fset
(
lm
.
PRE_STEP1
)
actions
.
action
()
dom
.
performStep1
()
dom
.
coupling
(
lm
.
COUPLING_STEP1
)
lm
.
current_stage
.
fset
(
lm
.
PRE_STEP2
)
actions
.
action
()
dom
.
performStep2
()
dom
.
coupling
(
lm
.
COUPLING_STEP2
)
lm
.
current_stage
.
fset
(
lm
.
PRE_STEP3
)
actions
.
action
()
dom
.
performStep3
()
dom
.
coupling
(
lm
.
COUPLING_STEP3
)
lm
.
current_stage
.
fset
(
lm
.
PRE_STEP4
)
actions
.
action
()
dom
.
coupling
(
lm
.
COUPLING_STEP4
)
comm
.
Barrier
()
Event Timeline
Log In to Comment