Viewers
A viewer shows a model, and its results once it is solved. Viewers are plugins; two ship with xfea.
| Name | What it is |
|---|---|
browser |
The browser viewer: a page served from your machine and opened in your browser. Nothing else to install. |
paraview |
Writes the model and the results as VTU files and opens them in ParaView’s desktop app, which must be installed, with paraview on your PATH. |
xfea viewersShowing a model
Section titled “Showing a model”from pathlib import Path
from xfea.model import BeamElement, ElasticIsotropic, Model, Node, Part, RectangularSectionfrom xfea.viewers import Viewer
model = Model(name="cantilever")steel = ElasticIsotropic(E=210_000, v=0.3, density=7.85e-9) # N, mm, tsection = RectangularSection(w=50, h=100, material=steel)
part = model.add_part(Part(name="beam"))nodes = [part.add_node(Node(xyz=[i * 100.0, 0, 0])) for i in range(21)]for a, b in zip(nodes, nodes[1:]): part.add_element(BeamElement(nodes=[a, b], section=section, orientation=[0, 1, 0]))model.add_fix_bc(nodes=[nodes[0]])
viewer = Viewer(plugin="browser")viewer.add_model(model)viewer.run()run() prints the page’s address, opens it in your browser and waits: press Ctrl+C in the terminal to stop it. Keep
it out of a script that has to finish on its own.
Showing results
Section titled “Showing results”Give the viewer the fields to show, each with the component to colour by:
from xfea.problem import Problem, StaticStepfrom xfea.results import DisplacementFieldResults, ReactionFieldResults
problem = model.add_problem(Problem(name="tip_load"))step = problem.add_step(StaticStep(name="load"))step.add_uniform_forcefield(nodes=[nodes[-1]], z=-1000)
disp = DisplacementFieldResults()react = ReactionFieldResults()step.add_field_outputs([disp, react])problem.analyse_and_extract(path=Path(__file__).resolve().parent / "output")
viewer = Viewer(plugin="browser")viewer.add_model(model)viewer.add_results({disp: "z"})viewer.add_results({react: "z"}) # each call adds to the fields already thereviewer.run()The page has its own controls for the field shown, the colours and the deformed shape.
A default viewer
Section titled “A default viewer”Name the viewer once, for the session or for good, and Viewer() needs no argument:
from xfea import settingsfrom xfea.viewers import list_viewers, set_viewer
print(list_viewers()) # ['browser', 'paraview']set_viewer("browser") # for this sessionsettings.DEFAULT_VIEWER = "browser" # saved to ~/.xfea/config.jsonWith an AI assistant
Section titled “With an AI assistant”Through xfea-mcp the assistant does the looking first: it renders the model before solving, with its supports,
loads and interfaces, to check it against what you asked for, shows the results coloured by the field that answers
your question, and opens the 3D viewer at a local address when you want to explore.
Writing a viewer
Section titled “Writing a viewer”A viewer plugin receives a scene, plain meshes, lines, points and labels built from the model and its results, and draws it. See Viewer scenes for the pipeline and Plugins for the contract.
© 2026 Francesco Ranaudo · Text and pictures CC BY 4.0 · Code Elastic License 2.0 · how to reuse them