This is a Python package for generating FEBio input files and converting XPLT files to HDF5. We rely heavily on pydantic and pydantic-xml for type validation and XML serialization. Many of FEBio's features are covered, but not all.
Our design focuses on:
๐๐ฎ๐๐ ๐ถ๐ป๐๐๐ฎ๐น๐น๐ฎ๐๐ถ๐ผ๐ป
Python wheels are built and uploaded to PyPI for installation with pip or other tools. Installation from source is simplified with the powerful and user-friendly ๐ถ๐ท package manager.
๐ฅ๐๐ป๐๐ถ๐บ๐ฒ ๐ฉ๐ฎ๐น๐ถ๐ฑ๐ฎ๐๐ฒ๐ฑ ๐๐น๐ฎ๐๐๐ฒ๐ ๐ณ๐ผ๐ฟ ๐ ๐ผ๐ฑ๐ฒ๐น ๐๐ผ๐บ๐ฝ๐ผ๐ป๐ฒ๐ป๐๐
All the components necessary to construct an FEBio model are defined as classes inheriting from the ๐๐ข๐ด๐ฆ๐๐ฐ๐ฅ๐ฆ๐ญ provided by the popular ๐ฑ๐บ๐ฅ๐ข๐ฏ๐ต๐ช๐ค library, which allows for enforcement of type and value constraints at runtime. This enables the definition of โguard railsโ when defining these components to help ensure a valid FEBio model is created.
๐ง๐๐ฝ๐ฒ ๐๐ถ๐ป๐๐ ๐๐ผ ๐ฒ๐ป๐ต๐ฎ๐ป๐ฐ๐ฒ ๐๐๐ ๐ฒ๐ ๐ฝ๐ฒ๐ฟ๐ถ๐ฒ๐ป๐ฐ๐ฒ
Modern integrated development environments in combination with a linter, formatter, and/or a language server protocol can aid code development by providing auto-completion, highlighting syntax and type errors and style violations, and formatting code based on a style standard. This functionality is greatly enhanced when a Python library provides โtype hints.โ When present, in-line help provided by these tools can bypass the need to consult the documentation directly.
๐ ๐ถ๐ป๐ถ๐บ๐ฎ๐น ๐๐ฒ๐ฝ๐ฒ๐ป๐ฑ๐ฒ๐ป๐ฐ๐ถ๐ฒ๐
By utilizing a small dependency set, ๐ฑ๐บ๐ง๐ฆ๐ฃ๐ช๐ฐ should "play nice" with the wider Python ecosystem, allowing users to build solutions with the libraries of their choice.
๐๐ผ๐ฐ๐๐บ๐ฒ๐ป๐๐ฎ๐๐ถ๐ผ๐ป ๐๐ถ๐ฎ ๐ฆ๐ฝ๐ต๐ถ๐ป๐
Organized and searchable documentation is automatically generated with Sphinx.
๐ง๐ฒ๐๐๐ถ๐ป๐ด
The FEBio development team has helped us develop continuous integration tasks to test our library with the latest FEBio release. We are still working on full code test coverage but once complete this will help maintain compatibility and functionality with future releases.
With pip:
Create a virtual environment:
/path/to/compatible-python -m venv .venvwhere /path/to/compatible-python is the path to a compatible python executable.
Activate the virtual environment:
On Linux or macOS:
source .venv/bin/activateOn Windows (cmd):
.\.venv\Scripts\activate.batOn Windows (powershell):
.\.venv\Scripts\Activate.ps1Install the package:
pip install pyfebioClone with https:
git clone https://github.com/CompOrthoBiomech/pyfebio.gitOr,
Clone with ssh:
git clone git@github.com:CompOrthoBiomech/pyfebio.gitInstall uv:
Install uv from here
Sync the uv environment
In top-level repository directory:
uv syncThis will create a virtual environment and install the package.
We rely on FEBio to check our generated models are valid. Therefore, you will need to have FEBio installed and available in your PATH.
To run all the tests, execute the following command:
cd src
pytestFor tests that depend on running finite element simulations, you can find them in the pytest tmp_path directory, which varies by operating system.
For the latest run:
on Linux,
cd /tmp/pytest-of-[USER]/pytest-current/[TEST_FUNCTION_NAME]currentimport pyfebio
# Instantiate a model tree with default values
# This contains empty mesh, material, loads, boundary, etc. sections
my_model = pyfebio.model.Model()
# Let's create a single hex8 element explicitly
# Normally, you would use the meshio functions to import
nodes_list = [
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
[1.0, 0.0, 1.0],
[1.0, 1.0, 1.0],
[0.0, 1.0, 1.0],
]
elements_list = [[1, 2, 3, 4, 5, 6, 7, 8]]
# Add Nodes to an pyfebio.Nodes object
nodes = pyfebio.mesh.Nodes(name="nodes")
for i, node in enumerate(nodes_list):
nodes.add_node(pyfebio.mesh.Node(id=i + 1, text=",".join(map(str, node))))
# Add Elements to an pyfebio.Elements object
elements = pyfebio.mesh.Elements(name="box", type="hex8")
for i, element in enumerate(elements_list):
elements.add_element(pyfebio.mesh.Hex8Element(id=i + 1, text=",".join(map(str, element))))
# Append nodes and elements to the model's mesh section
my_model.mesh_.nodes.append(nodes)
my_model.mesh_.elements.append(elements)
# Let's make a node set for top and bottom
bottom_nodes = [1, 2, 3, 4]
top_nodes = [5, 6, 7, 8]
top_node_set = pyfebio.mesh.NodeSet(name="top", text=",".join(map(str, top_nodes)))
bottom_node_set = pyfebio.mesh.NodeSet(name="bottom", text=",".join(map(str, bottom_nodes)))
# Append the node sets to the model's mesh section
my_model.mesh_.node_sets.append(top_node_set)
my_model.mesh_.node_sets.append(bottom_node_set)
# We need a material
# the use of pyfebio.material.MaterialParameter is our solution
# to handle mapped, math, or directly specified values
my_material = pyfebio.material.CoupledMooneyRivlin(
id=1,
name="cartilage",
c1=pyfebio.material.MaterialParameter(text=10.0),
c2=pyfebio.material.MaterialParameter(text=1.0),
k=pyfebio.material.MaterialParameter(text=1000.0),
)
# Define a solid domain for the box to assign the material
solid_domain = pyfebio.meshdomains.SolidDomain(name="box", mat="cartilage")
# add the solid domain
my_model.meshdomains_.add_solid_domain(solid_domain)
# add the material
my_model.material_.add_material(my_material)
# Fix the bottom nodes (1 means BC DoF is active)
fixed_bottom = pyfebio.boundary.BCZeroDisplacement(node_set="bottom", x_dof=1, y_dof=1, z_dof=1)
# Displace the top nodes in z
# We need to create a boundary.Value object that references a load curve
displacement_value = pyfebio.boundary.Value(lc=1, text=-0.2)
move_top = pyfebio.boundary.BCPrescribedDisplacement(node_set="top", dof="z", value=displacement_value)
# Add boundary conditions
my_model.boundary_.add_bc(fixed_bottom)
my_model.boundary_.add_bc(move_top)
# Now, create the loadcurve 1 we referenced
curve_points = pyfebio.loaddata.CurvePoints(points=["0.0,0.0", "1.0,1.0"])
load_curve1 = pyfebio.loaddata.LoadCurve(id=1, points=curve_points)
# And, add it to model
my_model.loaddata_.add_load_curve(load_curve1)
# Save the model to disk
my_model.save("my_model.feb")
# And run it
pyfebio.model.run_model("my_model.feb")Brief overview, see module documentation for more details. Unchecked are not yet implemented.
โ Implemented and tested
โ๏ธ Implemented but untested
โ Not yet implemented
- Control
- โ All control settings
- Mesh Section
- โ Nodes
- โ
Solid Elements:
- tet4, tet10, hex8, hex20, hex27, penta6
- โ๏ธ Shell Elements:
- tri3, tri6, quad4, quad8, quad9, q4ans, q4eas
- โ๏ธ Beam Elements:
- line2, line3
- โ Node, Element, Surface Sets
- MeshDomain
- โ Solid Domain
- โ๏ธ Shell Domain
- โ๏ธ Beam Domain
- โ๏ธ Granular control for integration schemes, etc.
- MeshData Section
- โ๏ธ Node Data
- โ๏ธ Scalar
- โ๏ธ Vector3
- โ๏ธ Element Data
- โ๏ธ Scalar
- โ๏ธ Vector3
- โ Surface Data
- โ Scalar
- โ Vector3
- โ๏ธ Node Data
- MeshAdaptor
- โ๏ธ Erosion
- โ MMG3d Remeshing
- โ hex_refine
- โ hex_refine2d
- โ๏ธ Criteria
- โ๏ธ element selection
- โ๏ธ math
- โ๏ธ min-max filter
- โ relative error
- โ stress
- โ๏ธ contact gap
- โ๏ธ damage
- โ๏ธ max variable
- Material
- โ Most Unconstrained Formulation Materials
- โ Most Uncoupled Formulation Materials
- โ๏ธ Prestrain Material
- โ๏ธ Fiber models
- โ
Material Axis
- โ Vector Definition
- โ Fiber Vector
- โ๏ธ Continuous Fiber Distributions
- โ๏ธ Integration Schemes
- โ๏ธ Element-wise, mapped, or math parameter defintion
- โ Biphasic Materials
- โ Viscoelastic Materials
- โ Multiphasic Materials
- โ Biphasic-solute Materials
- โ Chemical Reactions
- โ Active Contraction Materials
- โ Damage Materials
- โ First-order Homogenization
- Rigid
- โ๏ธ Fixed Displacement and Rotation
- โ๏ธ Prescribed Displacement and Rotation
- โ๏ธ Precribed Rotation about Vector
- โ๏ธ Prescribed Euler Rotation
- โ๏ธ All Connectors
- โ๏ธ Follower Loads
- Initial
- โ๏ธ Initial Velocity
- โ๏ธ Initial Pre-strain
- Loads
- โ๏ธ Nodal Loads
- โ๏ธ Traction Loads (surface)
- โ๏ธ Pressure Loads (surface)
- โ๏ธ Fluid Flux (surface)
- โ๏ธ Fluid Pressure (surface)
- LoadData
- โ
Load Curves
- โ๏ธ All Options
- โ๏ธ PID Controllers
- โ๏ธ Math Controllers
- โ
Load Curves
- Boundary
- โ Fixed Displacement (solid)
- โ Prescribed Displacement (solid)
- โ๏ธ Fixed Displacement (shell)
- โ๏ธ Prescribed Displacement (shell)
- โ๏ธ Precribed Deformation Gradient
- โ๏ธ Displacement Along Normals
- โ๏ธ Fix to Rigid Body
- โ Rigid Node Set Deformation (rotation about axis)
- โ Zero Fluid Pressure
- โ๏ธ Prescribed Fluid Pressure
- Constraints
- โ๏ธ Symmetry Plane
- โ๏ธ Prestrain
- โ๏ธ In-Situ Stretch
- Contact
- โ
Sliding
- โ Elastic
- โ Facet-Facet
- โ Node-Facet
- โ Biphasic
- โ Sliding2
- โ๏ธ Contact Potential Formulation
- โ๏ธ Tie
- โ๏ธ Elastic
- โ๏ธ Facet-Facet
- โ๏ธ Node-Facet
- โ๏ธ Biphasic
- โ
Sliding
- Step
- โ๏ธ Multistep Analysis
- Output
- โ๏ธ Log File Configuration
- โ๏ธ Plot File Configuration
- โ๏ธ Node Variables
- โ๏ธ Element Variables
- โ๏ธ Rigid Body Variables
- โ๏ธ Rigid Connector Variables
- XPLT
- โ Convert XPLT to HDF5
