Python bindings¶
Warning
The python bindings are in beta. Expect API changes and possible bugs. Use at your own peril!
I am making efforts to provide a simple python interface to Polyfem.
For doing so I am maintaining a conda package which can be easily installed https://anaconda.org/conda-forge/polyfempy.
Note that the conda deployment is slow and this tutorial will follow the deployment version.
If you hare in a hurry for the juicy latest feature you can clone the repository Polyfem-python and use pip
to install:
python setup.py develop
python setup.py test
Note that the folders tests contain some tests which can be used as documentation.
The documentation can be found here.
Tutorial¶
Polyfem relies on 3 main objects:
Settings
that contains the main settings such discretization order (e.g., or ), material parameters, formulation, etc.Problem
that describe the problem you want to solve, that is the boundary conditions and right-hand side. There are some predefined problems, such asDrivenCavity
, or generic problems, such asGenericTensor
.Solver
that is the actual FEM solver.
The usage of specific problems is indented for benchmarking, in general you want to use the GenericTensor
for tensor-based PDEs (e.g., elasticity) or GenericScalar
for scalar PDEs (e.g., Poisson).
A typical use of Polyfem is:
settings = polyfempy.Settings()
# set necessary settings
# e.g. settings.discr_order = 2
problem = polyfempy.GenericTensor() # or any other problem
# set problem related data
# e.g. problem.set_displacement(1, [0, 0], [True, False])
settings.problem = problem
#now we can create a solver and solve
solver = polyfempy.Solver()
solver.settings(settings)
solver.load_mesh_from_path(mesh_path)
solver.solve()
Note 1: for legacy reasons Polyfem always normalizes the mesh (i.e., rescale it to lay in the normalize_mesh = False
while loading to disable this feature.
Note 2: the solution
For this reason Polyfem uses a visualization mesh where the solution is sampled at the vertices.
This mesh has two advantages:
1. it solves the problem of nodes reordering and additional nodes in the same way
2. it provides a “true” visualization for high order solution by densely sampling each element (a
To control the resolution of the visualization mesh use vismesh_rel_area
named-argument while loading.
Notebook¶
For more details and nice interactive example go to the notebook tutorial!
Or just play with the tutorial in