Skip to content

Parts, models, and problems

A model holds the parts (geometry, mesh, sections); a problem attached to it holds the steps (loads and requested outputs). Solving the problem writes its files into <path>/<problem name>/ and reads the results back, with no plugin-specific code in the script.

The model before it is solved: parts, supports and loads

The model before it is solved: its parts, supports (red) and loads (blue).

The result: the deformed shape coloured by displacement (magnitude [mm])

The deformed shape, coloured by displacement (magnitude [mm]), in xfea’s 3D viewer.

Open in 3D turn it, cut it, pick any field: in xfea's viewer, in your browser

examples/scripts/02_core_concepts/model/parts_and_problems.py. Run it from the repository with uv run python examples/scripts/02_core_concepts/model/parts_and_problems.py, or, with xfea-examples installed, xfea-examples run 02_core_concepts/model/parts_and_problems.py.

from xfea.problem import Problem
from xfea.problem import StaticStep
from xfea.results import DisplacementFieldResults
from xfea_examples import out_dir
from xfea_examples.models import cantilever_beam_model
tip_load = -1_000 # [N] downward tip force
model, part, tip_nodes, _, _, _ = cantilever_beam_model(name="parts_and_problems")
problem = model.add_problem(Problem(name="parts_problem"))
step = problem.add_step(StaticStep(name="service"))
step.add_uniform_forcefield(nodes=tip_nodes, z=tip_load, load_case="service")
disp = DisplacementFieldResults()
step.add_field_outputs([disp])
print(f"Model {model.name!r}: parts {[p.name for p in model.parts]}, problems {[p.name for p in model.problems]}")
print(f"Part {part.name!r}: {len(part.nodes)} nodes, {len(part.elements)} elements")
print(f"Problem {problem.name!r}: steps {[s.name for s in problem.steps]}")
problem.analyse_and_extract(path=out_dir(model.name), verbose=True)
print(f"Solver files in {problem.path}")
print(f"Tip deflection: {disp.get_min_result('z').z:.4f} mm")

© 2026 Francesco Ranaudo · Text and pictures CC BY 4.0 · Code Elastic License 2.0 · how to reuse them