Skip to content

Python API: results and design

How to solve a model, read what comes back, design it, edit it afterwards, and use the variants and construction sequences, all without the interface. Building the model is on Python API: building a model, the loads and analysis cases on Python API: loads and analysis.

The signatures on this page are written from the engine, so they are complete: every parameter, with its type and default. Python API: reference lists every call.

Solving and reading the results

Structure2D(domain="plane")                 # or "plate"; fixed for the model's life
calculate() -> dict
    # assemble and solve every analysis case; returns the results
check_references()
    # raise on dangling or invalid references
domain_problems() -> list[str]
    # features the model's domain does not support
save(path: str)
    # write a .x2d or .json
Structure2D.load(path) -> Structure2D       # read a file

calculate() returns a dictionary. The ones you will use most are keyed by analysis-case id and then by node or element id:

Key Holds
displacements[case][node] [ux, uy, θz] (in a plate model [w, θx, θy])
reactions[case][node] [Rx, Ry, Mz] (plate: [Rz, Mx, My]) at a supported node
element_forces[case][element] {'i': [N, V, M], 'j': [N, V, M]}: the end forces of a bar (plate: T in place of N)
spring_forces, constraint_forces the reaction of springs and the force each constraint transmits
tri_stress[case][element] the field of the triangles and quads: stresses in a plane model, moments and shears in a plate model
combinations the results of the combinations, built from the analysis cases
analysis_cases per case: its type and whether it was solved
timing, system_size the size of the system and the time of each stage
r = s.calculate()
print(r['reactions']['LC1']['N1'])                 # [Rx, Ry, Mz]
print(r['element_forces']['LC1']['E1']['i'])       # [N, V, M] at the start of the bar

Running without a window: xdfem2d.workflows

The checks and the calculation that the application's Run and Design menu do, as functions that need no window:

validate_for_analysis(struc) -> list           # what stops the model from being analysed: [{'code', 'msg'}], empty when it can run
run_analysis(struc, scope="active" | "all", results=None) -> AnalysisOutcome
    # solves the model; "all" also solves the variants, the combinations across variants and the construction sequences.
    # given the previous results of a solved model, only the pending analysis cases are solved
run_design(struc, results, kind, prefs=None, combinations=None, sls_combinations=None) -> dict
    # designs the members of a kind and stores the outcome in `results`, where the design views read it.
    # kind: "concrete" | "bars" | "areas" | "crack" | "punching" | "steel" | "timber"
    # returns {'kind', 'designed', 'failing', 'combinations'}; raises ValueError for an unknown kind, no results, or no combination
available_combinations(struc, results) -> list  # the combination ids a design can use

The application's window calls the same functions, so the two cannot differ. Automatic EN 1990 combinations:

xdfem2d.combinations.auto_combinations(struc, types=("ULS",), replace=True) -> dict
    # types: any of "ULS", "SLS-K", "SLS-FR", "SLS-QP"; returns {'added', 'skipped', 'removed', 'errors', 'cases'}
    # replace=True first removes the combinations an earlier run generated (ids starting ULS:, ULS-E:, SLS-K:, SLS-FR:, SLS-QP:),
    # never one you named

Editing and removing

Nodes, elements, sections, materials, load cases, combinations, analysis cases and geometry objects have companion remove_* and rename_* methods, and so do loads (remove_point_loads, remove_distributed_loads, remove_area_load, the remove_*_temperature_load family) and springs (remove_node_spring, remove_element_spring, remove_area_spring, remove_line_element_spring). The load/temperature removes take a load_case_id="" that clears every case on the target, or one named case.

Forgiving removal: delete_* and free_edge

The intent-level inverses of the create_*, pin and support layer, and what to reach for when undoing an edit:

delete_support(nodes)
    # unassign the support on a node / list of nodes
free_edge(object_id: str, edge)
    # free an edge (inverse of support_edge/pin_edge)
delete_area(object_id: str)
    # delete a region/line object (= remove_geo_object)
delete_load(target: str, load_case_id: str = '')
    # node / bar / area loads on a target
delete_temperature(target: str, load_case_id: str = '')
    # bar / triangle / quad / object
delete_spring(target: str)
    # node / element / area / line spring

Each is a forgiving wrapper over the low-level remove_*: removing what is not there is a no-op, so one delete_load('N1') clears whatever loads N1 carries without the caller first classifying the target. The low-level remove_* are the by-id/by-name primitives (used by the application); the delete_* and free_edge calls are the ones to use in a script.

Variants, support sets and construction sequences

The variants and construction sequences of the application are plain objects of the engine, in xdfem2d.models: SupportSet, Variant, ConstructionSequence, ConstructionPhase, Operation, with OpAction (ADD, REMOVE) and OpTarget (ELEMENTS, SUPPORTS, LOADS).

add_support_set(support_set) -> object
add_variant(variant) -> object
add_construction_sequence(sequence) -> object
    # also keeps its analysis case of type 'Sequence'
derive_variant(variant, support_set=None, filter_tri: bool = False) -> Structure2D
    # a new model for the variant; the original is untouched
with_active(active_elements) -> Structure2D
    # a copy with only those elements active
xdfem2d.workflows.run_sequence(struc, seq_id) -> dict                        # solve one construction sequence
xdfem2d.workflows.run_variant_combination(struc, terms, op, ...) -> dict     # combine variant results: terms are (variant_id, case_id, factor)
xdfem2d.phasing.resolve_phase_state(...)                                     # the state of a phase, replayed from its operations
xdfem2d.workflows.assign_stage(struc, element_ids, stage) -> int             # the `stage` of the elements, for phases that add a stage

A phase is a list of Operations, replayed from the top on top of the previous phase; see Construction sequences for what each one means. The cached state of a phase (its active elements, applied cases and case factors) is recalculated from its operations, which is what the Python export relies on.

Section cuts

add_cut(id: str, x1: float, y1: float, x2: float, y2: float, name: str = '') -> Cut
remove_cut(cut_id: str)
rename_cut(old_id: str, new_id: str)

A Cut is a straight segment (x1,y1) -> (x2,y2) that reports the resultant of the internal forces crossing it — bars and areas, combined and separately — for one case (load case, analysis case, or LinearSum combination) at a time. Evaluation lives in the Qt-free xdfem2d.cuts module, not on Structure2D itself:

cut_result(struc, results, cut, case, ref_point=None) -> dict
    # {'domain', 'bars': [...], 'areas': [...],
    #  'resultant': {'bars', 'areas', 'total'}, 'reason'}
    # bars/areas per-crossing detail; resultant['total'] is what a Results
    # panel shows. ref_point defaults to the cut's own midpoint.
cut_distribution(cutres, n=101) -> dict
    # {'s', 'fields', 'markers'} — sampled per-length area fields (piecewise
    # constant per triangle) plus bar crossings as point markers, for
    # plotting the distribution along the cut.
cuts_report(struc, results, cases, ref_point=None) -> list[dict]
    # one row per (cut, case): cut_id, cut_name, case, total_<N|V|M or
    # V|Mb|Mt>, reason — every cut against every case id, for CSV export.
cut_bar_resultant(struc, results, cut, case, ref_point=None) -> dict
cut_area_resultant(struc, results, cut, case, ref_point=None) -> dict
    # the two halves cut_result sums; called directly only if you want one
    # side in isolation.
find_bar_crossings(struc, cut) -> list[dict]        # {elem_id, a, s, x, y}
find_triangle_crossings(struc, cut) -> list[dict]    # {tri_id, s0, s1, p0, p1}
    # pure geometry — every bar/triangle the cut crosses, no results needed.

Resultant keys are N, V, M for a plane cut (axial along the cut's normal, shear along its tangent, in-plane moment about ref_point) or V, Mb, Mt for a plate cut (transverse shear, bending and twisting moment — the same mn/mnt split slab results already use). struc must be the compiled model (geo_expand.expand_geometry's output) when the model has geometry objects, matching whatever handle the GUI already keeps for tri-field plotting — cuts are evaluated against the solved mesh, not the editable objects.

A cut has a tangent t = (P2 − P1)/L and a normal n, t rotated +90° (to the left of the drawing direction). The forces reported are those the positive side (the side n points to) exerts on the negative side, and moments are taken about the cut's midpoint unless ref_point is given. Bars crossing the cut contribute their internal forces at the crossing, rotated to the cut's axes (point contributions); areas contribute the line integral of the stress field along the part of the cut inside each triangle (per-length contributions). Bars and areas are always computed separately and then summed.

Member buckling (steel EC3 and timber EC5)

The steel and timber member checks work on physical members — chains of collinear bars grouped by xdfem2d.member_utils.identify_members(struc). Each BarElement carries the per-member buckling-length factors used by the design (buckling length = K × physical-member length); leave them None to inherit the global default from the design preferences:

BarElement.sd_ky   # K for flexural buckling about y (major / in-plane)
BarElement.sd_kz   # K for flexural buckling about z (minor / out-of-plane)
BarElement.sd_klt  # K for the lateral-torsional length
BarElement.sd_ltb  # bool: member susceptible to lateral-torsional buckling

Free-end (cantilever) detection helpers in xdfem2d.member_utils:

member_free_ends(struc, member)   -> (free_i, free_j)   # a truly-free end node
member_has_free_end(struc, member) -> bool
cantilever_k_for(struc, member, prefs) -> float | None  # auto K (Ky, Kz) or None

A node is a free end when nothing is attached to it (a single incident bar and no support, node spring, triangle or constraint). When enabled (cantilever_auto, default on), such members take cantilever_k (default 2.0) for sd_ky/sd_kz unless an explicit value is set.

Design reports (calculation trace)

Every design routine can, with with_reports=True, attach a full step-by-step calculation report for the governing case of each member / section / column / triangle. The report content — clause, symbolic expression, LaTeX and numeric substitution — is produced by eurocodepy through an optional trace (eurocodepy.calc_report.CalcReport): the check computes exactly as before and the trace only records what was computed, so the reported numbers are, by construction, the ones used. The app only gathers and renders; it never re-derives formulas.

The EC2 procedures are owned by eurocodepy composites, each taking an input dataclass and an optional trace:

eurocode2_shear_check(ShearInput, v_ed, trace=None)      # §6.2 shear
eurocode2_punching_check(PunchInput, n_ed, …, trace=None) # §6.4 / :2023 §8.4
eurocode2_membrane_check(MembraneInput, trace=None)       # §6.109 membrane (areas)
eurocode2_slab_check(SlabInput, trace=None)               # §6.1 slab flexure (areas)
calc_torsion(…, trace=None)                               # §6.3 grillage torsion
calc_asl_nm(…, trace=None)                                # §6.1 M-N flexure

Gathering and rendering live in xdfem2d.design_report (Qt-free):

build_reports(struc, results, material, prefs=None, combinations=None) -> {id: report}
    # material: "steel" | "timber" | "concrete" | "concrete_area" | "punching"
filter_reports(reports, material, struc,
               selected_bars=None, selected_nodes=None, selected_tris=None)
reports_from(design_output) -> {id: report}      # normalise a routine's output
report_base_id(report) -> str                    # member/element/column/triangle id
per_combination_key(base_id, combo) / merge_per_combination({combo: {id: report}})
render_html(reports, title)   / render_markdown(...) / render_pdf(...) / render_docx(...)
write_markdown_bundle(reports, md_path, title)   # .md + <stem>_assets/ figures
section_figure_png(geom)      # cross-section drawing (rect / I / RHS / SHS / CHS)
pandoc_available()            # gates the native editable-OMML Word route
EXPECTED_SCHEMA / schema_mismatches(reports)     # report-schema version guard

A report dict has the shape {schema_version, title, meta, sections:[{title, steps:[{symbol, value, unit, clause, expr, latex, subst, note, ok}]}]}. The GUI consumes these through the Design → Design report… side panel.