Skip to content

Database

Module: xfea.results.parser

ParserBase(problem)

Parser class for parsing results from a file.

Methods
parse()

No docstring available.

Module: xfea.results.database

ColumnSpec(name: str, dtype: type, nullable: bool = True)

One column of a results table: its name and type, the same for every results database.

Parameters

Name Type Description
name str The column name ("key", "frame", "x"…).
dtype type The Python type of the values: int, float, str or bool; each database maps it to its own.
nullable bool, optional Whether a value may be missing (default True).
ResultsDatabase(problem, **kwargs)

Where a problem’s results are stored, and read back: the interface each database plugin implements.

A results reader writes the solver’s results into it as rows, table by table (record_table()); the fields read them back as result objects (get_rows(), to_results()). The plugins (SQLite today) are registered under a name (register_results_database()).

Schemas are expressed with ColumnSpec, the same for every database; each maps the types to its own storage.

Parameters

Name Type Description
problem Problem The problem whose results it holds.
**kwargs dict Passed to FEAObject.

Attributes

Name Type Description
problem Problem The problem whose results it holds.
model Model The problem’s model.
Properties
db_uriread-only

The database’s file path or URI.

keyAny | Noneread-only

The object’s key (its number) in what it is registered to; None until it is given one.

modelread-only

No docstring available.

namestr

The object’s name.

problemread-only

No docstring available.

registrationAny | None

The object this one is registered to (a part, a model, a step, …), or None.

uidUUID | Noneread-only

The object’s unique id, a UUID.

unit_systemread-only

The name of the unit system recorded with the results, or None (xfea does not track units).

Methods
add_results_to_output_class_table(output_cls, results)

Write rows into the table output_cls describes (a TableSchema); rows are tuples in its column order.

bulk_write()

A context for writing many rows at once; here it does nothing, a database may batch the writes.

get_rows(table_name, columns_names, filters, func=None)

Rows of a results table: the given columns, filtered, optionally only the first in an order.

Parameters

Name Type Description
table_name str The table to read ("u", "s"…).
columns_names list[str] The columns to return, in order; a column the table lacks comes back as None.
filters dict[str, list] {column: allowed values}: a row is kept if each column’s value is among them.
func tuple[str, str], optional ("ASC" | "DESC", column): only the first row in that order (the minimum or the maximum).

Returns

Name Type Description
list One sequence of values per row; empty when the table is missing.
record_model_index()

Store what links the rows to the model’s entities, where the database supports it (here, nothing).

record_table(schema, rows, step=None, step_name=None)

Write rows into a table, with the unit system and the model’s index.

Parameters

Name Type Description
schema TableSchema The table to write.
rows list The rows, as dicts by column or as tuples in column order.
step object, optional The step whose name fills the rows’ step column, if step_name is not given.
step_name str, optional The name to fill the rows’ step column with, where the table has one.
record_unit_system(unit_system=None)

Store the name of the unit system the results are written in, when one is given (else None).

resolve_result_location(result_line, results_func)

The part name and key of a stored row’s location, taken out of the row.

A database can override it to translate keys (from an index it stored, say) before the location is looked up in the model.

to_result(result_line, results_func, result_cls, source_unit_system=None, **kwargs)

One stored row as a result: its location found in the model, its values passed to result_cls.

Parameters

Name Type Description
result_line dict The row, by column; step, part and key are taken out of it.
results_func str The model’s lookup method for the location ("find_node_by_key"…).
result_cls type The result class to build.
source_unit_system optional The unit system the row was written in, passed to the result.
to_results(results_set, results_func, result_cls, source_unit_system=None, **kwargs)

Stored rows as results, grouped by step: {step: [result, ...]}.

Rows whose step is not in the problem are left out; see to_result() for the parameters.

RowSchema(
    columns: list[ColumnSpec],
    results_func: str = '',
    components_names: list[str] | None = None,
    invariants_names: list[str] | None = None,
)

The layout of one result row: its columns, and which of them are the result’s components.

Parameters

Name Type Description
columns list[ColumnSpec] The row’s columns, in order.
results_func str, optional The model’s lookup method that finds the row’s location from its key ("find_node_by_key"…).
components_names list[str], optional The columns that are the result’s components (["x", "y", "z"]…).
invariants_names list[str], optional The values a result computes from its components (["magnitude"]…).
Properties
schemadict[str, Any]read-only

{"columns": [...]}: the row’s columns.

TableSchema(table_name: str, row_cls: type[Any])

A results table: its name and the result class whose schema gives its columns.

Parameters

Name Type Description
table_name str The table’s name ("u", "s"…).
row_cls type The result class, with a schema (RowSchema).
Properties
columnslist[ColumnSpec]read-only

The table’s columns, from the row class’s schema.

schemadict[str, Any]read-only

{"table_name": ..., "columns": [...]}.

Module: xfea.results.registry

The results database plugins (SQLite today): registered by name, found through entry points.

create_results_database(
    problem,
    name: Optional[str] = None,
    **kwargs,
) -> ResultsDatabase

A results database for problem: the one named, else the default, else SQLite.

Parameters

Name Type Description
problem Problem The problem whose results it will hold.
name str, optional The database plugin’s name; None for the default.
**kwargs Passed to the database’s constructor.
failed_results_databases() -> Mapping[str, str]

The databases that failed to load, with their errors: {name: error}.

get_default_results_database() -> Optional[str]

The session’s default results database name, else the configured one (settings.DEFAULT_DATABASE), or None.

get_results_database(name: str) -> Type[ResultsDatabase]

The results database class registered under name (an installed plugin’s, loaded on first use).

list_results_databases(available_only: bool = False) -> list[str]

The names of the registered results databases.

Parameters

Name Type Description
available_only bool, optional Only those that load and can be used here (default False: all).
load_entry_points()

Load the results database plugins installed as xfea.results_databases entry points.

register_results_database(name: str, cls: Type[ResultsDatabase])

Register a results database class under a name.

Parameters

Name Type Description
name str The name to find it by ("sqlite"…).
cls type A ResultsDatabase subclass.
resolve_results_database(name: Optional[str] = None) -> Type[ResultsDatabase]

The results database class for name, else the default, else "sqlite".

results_database(name: str)

A class decorator that registers a results database class under name.

set_results_database(name: Optional[str])

Set the results database new problems use in this session (None or "" to unset).

Raises if no database is registered under name.

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