Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91143209
manual-python.tex
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, Nov 8, 08:26
Size
3 KB
Mime Type
text/x-tex
Expires
Sun, Nov 10, 08:26 (2 d)
Engine
blob
Format
Raw Data
Handle
13184129
Attached To
rAKA akantu
manual-python.tex
View Options
\chapter
{
Python interface
\index
{
Python
}
\label
{
sect:python
}}
Akantu as a python interface which allows to implement a finite
element case entirely in the Python language. The interface is
currently in
\textcolor
{
red
}{
beta
}
version and bugs (including memory
leaks) can be expected.
The philosophy of the python wrappers is that it should follow, as
much as possible, the C++ interface. This is made possible thanks to
the
\href
{
SWIG
}{}
software which can port C++ interfaces to Python.
However, the possibilities of the Python language have some
restrictions which do not allow the concept of template. For this
reason the templated classes and methods are currently hardly
supported in the Akantu Python interface (some are, but without any
warranty that the interface shall not change in a near future).
In order to use the python interface you want to import the
\code
{
akantu
}
module which is possibly located in directory where you
built or where you installed
\akantu
. The easiest way is to source
the file
\code
{
akantu
\_
environement.sh
}
in your terminal environment:
\begin
{
command
}
source AKANTU
_
BUILD
_
DIR/akantu
_
environement.sh
\end
{
command
}
or for an installed akantu version:
\begin
{
command
}
source AKANTU
_
INSTALL
_
DIR/share/akantuVERSION/akantu
_
environement.sh
\end
{
command
}
Then, you can create a Python script, like
\code
{
script.py
}
which
starts with:
\begin
{
python
}
import akantu
\end
{
python
}
Then, you can write the initialization sequence just like for the C++
case:
\begin
{
python
}
akantu.initialize('materials.dat') spatial
_
dimension = 2
mesh = akantu.Mesh(spatial
_
dimension) mesh.read('mesh.msh')
model = akantu.SolidMechanicsModel(mesh)
model.initFull(
_
analysis
_
method = akantu.
_
static)
\end
{
python
}
Then for the dumpers declaration:
\begin
{
python
}
model.setBaseName("example") model.addDumpFieldVector("displacement")
model.addDumpFieldVector("force") model.addDumpField("boundary")
model.addDumpField("strain") model.addDumpField("stress")
model.addDumpField("blocked
_
dofs")
\end
{
python
}
The
\akantu
arrays can be retrieved at all time. For convenience there
is an automatic trans-typing operator which allows to use
\akantu
Array, Vectors and Matrix as mere
\textbf
{
Numpy
}
s.
\begin
{
python
}
displacement = model.getDisplacement()
\end
{
python
}
There is no copy made and the
\textbf
{
Numpy
}
vectors are wrapped
around
\akantu
's memory pool.
\begin
{
python
}
displacement[:,:] = 1.
displacement[0,1] = 10.
\end
{
python
}
Also to assign an entire vector to another the '[]' operator must be
used:
\begin
{
python
}
result = numpy.linspace(0.,1.,100)
# This works
displacement[:] = result[:]
# This does not
displacement = result
\end
{
python
}
Then you can solve the problem for instance with:
\begin
{
python
}
model.solveStaticDisplacement(1e-10,2);
\end
{
python
}
And dump to Paraview:
\begin
{
python
}
model.dump()
\end
{
python
}
Do not forget to finalize at the end of the script:
\begin
{
python
}
akantu.finalize()
\end
{
python
}
Finally the python script can be launched with:
\begin
{
command
}
python ./script.py
\end
{
command
}
\vspace
{
1cm
}
\textcolor
{
red
}{
Warning!
}
: We recall once more that the Python
interface is in
\textbf
{
beta
}
state and is provided only for its nice
services: it avoids recompilation of akantu when coding the main function.
Several preliminary examples are provided
in the
\code
{
examples
}
directory where it is described how to specify
boundary conditions and also constitutive behavior.
Event Timeline
Log In to Comment