Skip to main content

A Python API for the FEBio finite element solver.

Project description

PyPI - Version

Overview

This is a Python package for generating FEBio input files. We rely heavily on pydantic and pydantic-xml for type validation and XML serialization. Many of FEBio's features are covered, but not all.

Getting Started

Installation

From PyPi

With pip:

Create a virtual environment:

/path/to/compatible-python -m venv .venv

where /path/to/compatible-python is the path to a compatible python executable.

Activate the virtual environment:

On Linux or macOS:

source .venv/bin/activate

On Windows (cmd):

.\.venv\Scripts\activate.bat

On Windows (powershell):

.\.venv\Scripts\Activate.ps1

Install the package:

pip install pyfebio

From Source (with uv manager)

Clone with https:

git clone https://github.com/CompOrthoBiomech/pyfebio.git

Or,

Clone with ssh:

git clone git@github.com:CompOrthoBiomech/pyfebio.git

Install uv:

Install uv from here

Sync the uv environment

In top-level repository directory:

uv sync

This will create a virtual environment and install the package.

Testing

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
pytest

For 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]current

Example

import 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")

Short Example Simulation

Features

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
  • 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
  • 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
  • Step
    • ☑️ Multistep Analysis
  • Output
    • ☑️ Log File Configuration
    • ☑️ Plot File Configuration
    • ☑️ Node Variables
    • ☑️ Element Variables
    • ☑️ Rigid Body Variables
    • ☑️ Rigid Connector Variables

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfebio-0.1.0b0.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyfebio-0.1.0b0-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file pyfebio-0.1.0b0.tar.gz.

File metadata

  • Download URL: pyfebio-0.1.0b0.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyfebio-0.1.0b0.tar.gz
Algorithm Hash digest
SHA256 3a6f29b4dd0487a53212cf14d9c5e98958028b171e5dfe4b50882a4af07b192f
MD5 787362ab26307afb713be399ff738c29
BLAKE2b-256 0fc1c9e2d03a71e8290fe28a84d4b31f0b1ed2fe1588fca2dd6d3b0ba64879bb

See more details on using hashes here.

File details

Details for the file pyfebio-0.1.0b0-py3-none-any.whl.

File metadata

  • Download URL: pyfebio-0.1.0b0-py3-none-any.whl
  • Upload date:
  • Size: 32.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyfebio-0.1.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 c45105f4639ef781b73b2dffad1f19c03a09305259407c4ca0d0da48668e96d8
MD5 5f9c12a880e834dd50d0dcc0851d6a67
BLAKE2b-256 d2e96adc80035f5e4a586010fafaf0d75a2a03d2a2e669e0e138b173ec3171fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page