Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73322170
plate-mpi.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, Jul 20, 14:15
Size
3 KB
Mime Type
text/x-python
Expires
Mon, Jul 22, 14:15 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
19184676
Attached To
rAKA akantu
plate-mpi.py
View Options
#!/usr/bin/env python3
from
mpi4py
import
MPI
import
akantu
import
numpy
as
np
comm
=
MPI
.
COMM_WORLD
rank
=
comm
.
Get_rank
()
################################################################
# Dirichlet Boudary condition functor: fix the displacement
################################################################
class
FixedValue
(
akantu
.
DirichletFunctor
):
def
__init__
(
self
,
value
,
axis
):
super
()
.
__init__
(
axis
)
self
.
value
=
value
self
.
axis
=
int
(
axis
)
def
__call__
(
self
,
node
,
flags
,
disp
,
coord
):
# sets the displacement to the desired value in the desired axis
disp
[
self
.
axis
]
=
self
.
value
# sets the blocked dofs vector to true in the desired axis
flags
[
self
.
axis
]
=
True
################################################################
# Neumann Boudary condition functor: impose a traction
################################################################
class
FromTraction
(
akantu
.
NeumannFunctor
):
def
__init__
(
self
,
traction
):
super
()
.
__init__
()
self
.
traction
=
traction
def
__call__
(
self
,
quad_point
,
force
,
coord
,
normals
):
# sets the force to the desired value in the desired axis
force
[:]
=
self
.
traction
################################################################
def
solve
(
material_file
,
mesh_file
,
traction
):
akantu
.
parseInput
(
material_file
)
spatial_dimension
=
2
################################################################
# Initialization
################################################################
mesh
=
akantu
.
Mesh
(
spatial_dimension
)
if
rank
==
0
:
mesh
.
read
(
mesh_file
)
mesh
.
distribute
()
model
=
akantu
.
SolidMechanicsModel
(
mesh
)
model
.
initFull
(
akantu
.
SolidMechanicsModelOptions
(
akantu
.
_static
))
model
.
setBaseName
(
"plate"
)
model
.
addDumpFieldVector
(
"displacement"
)
model
.
addDumpFieldVector
(
"external_force"
)
model
.
addDumpField
(
"strain"
)
model
.
addDumpField
(
"stress"
)
model
.
addDumpField
(
"blocked_dofs"
)
################################################################
# Boundary conditions
################################################################
model
.
applyBC
(
FixedValue
(
0.0
,
akantu
.
_x
),
"XBlocked"
)
model
.
applyBC
(
FixedValue
(
0.0
,
akantu
.
_y
),
"YBlocked"
)
trac
=
np
.
zeros
(
spatial_dimension
)
trac
[
1
]
=
traction
if
rank
==
0
:
print
(
"Solve for traction "
,
traction
)
model
.
getExternalForce
()[:]
=
0
model
.
applyBC
(
FromTraction
(
trac
),
"Traction"
)
solver
=
model
.
getNonLinearSolver
()
solver
.
set
(
"max_iterations"
,
int
(
2
))
solver
.
set
(
"threshold"
,
1e-10
)
solver
.
set
(
"convergence_type"
,
akantu
.
_scc_residual
)
model
.
solveStep
()
model
.
dump
()
################################################################
# main
################################################################
def
main
():
import
os
mesh_file
=
'plate.msh'
# if mesh was not created the calls gmsh to generate it
if
rank
==
0
and
not
os
.
path
.
isfile
(
mesh_file
):
import
subprocess
ret
=
subprocess
.
call
(
'gmsh -format msh2 -2 plate.geo {0}'
.
format
(
mesh_file
),
shell
=
True
)
if
not
ret
==
0
:
raise
Exception
(
'execution of GMSH failed: do you have it installed ?'
)
comm
.
Barrier
()
material_file
=
'material.dat'
traction
=
1.
solve
(
material_file
,
mesh_file
,
traction
)
################################################################
if
__name__
==
"__main__"
:
main
()
Event Timeline
Log In to Comment