zoomy_core.model.basemodel#
Base class Model of the Model layer, where the user writes the physics as symbolic
equations or operator methods. A Model is lifted to a SystemModel by SystemModel.from_model.
Module Contents#
Classes#
Base class of the Model layer: named equations plus variables, parameters, boundary and
initial conditions, lifted to a SystemModel by |
|
Markdown / plain-text rendering of a |
Functions#
Drop all cached symbolic derivations. |
|
Turn an int or list field spec into a |
|
Flatten a sympy |
|
Default simplifier, |
|
Turn an int, list, dict or |
|
Merge user |
|
Numeric defaults of a parameter declaration (feeds |
Data#
API#
- zoomy_core.model.basemodel.clear_derivation_model_cache()#
Drop all cached symbolic derivations.
- zoomy_core.model.basemodel.register_sympy_attribute(definition, prefix='q')#
Turn an int or list field spec into a
Zstructof sympy Symbols (legacy; preferparse_definition_to_zstruct).
- zoomy_core.model.basemodel.eigenvalue_dict_to_matrix(eigenvals_dict)#
Flatten a sympy
eigenvals()dict{eigenvalue: multiplicity}into aZArray.
- zoomy_core.model.basemodel.default_simplify(expr)#
Default simplifier,
powsimpwithcombine='all'.
- zoomy_core.model.basemodel.SYMBOL_CONSTRAINTS#
None
- zoomy_core.model.basemodel.parse_definition_to_zstruct(definition, prefix='q_')#
Turn an int, list, dict or
Zstructspec into aZstructof constrained sympy Symbols. List entries arenameor(name, constraint), dict entriesname: defaultorname: (default, constraint); seeSYMBOL_CONSTRAINTS.
- zoomy_core.model.basemodel.merge_parameter_overrides(declared, overrides)#
Merge user
parameters=over the declared parameter dict, keeping the declared constraint unless the override carries its own(value, constraint)pair.
- zoomy_core.model.basemodel.extract_parameter_defaults(definition)#
Numeric defaults of a parameter declaration (feeds
model.parameter_values).
- class zoomy_core.model.basemodel.Model(init_functions=True, **params)#
Bases:
zoomy_core.misc.options.Configurable,zoomy_core.model.basefunction.SymbolicRegistrarBase class of the Model layer: named equations plus variables, parameters, boundary and initial conditions, lifted to a SystemModel by
SystemModel.from_model. Subclasses populate equations inderive_modelor override the operator methods (flux,source, …).Initialization
Declare variables and parameters, run the derivation, and (unless
_finalize_lazy) finalize for the SystemModel.Args
init_functions: register the operator methods as symbolic functions during finalization.
- name#
‘String(…)’
- dimension#
‘Integer(…)’
- disable_differentiation#
‘Boolean(…)’
- quadrature_order#
‘Integer(…)’
- eigenvalue_mode#
‘Selector(…)’
- equilibrium_reconstruction#
‘Selector(…)’
- variables#
‘Parameter(…)’
- aux_variables#
‘Parameter(…)’
- parameters#
‘Parameter(…)’
- boundary_conditions#
‘ClassSelector(…)’
- aux_boundary_conditions#
‘ClassSelector(…)’
- initial_conditions#
‘ClassSelector(…)’
- aux_initial_conditions#
‘ClassSelector(…)’
- property derivation#
The symbolic derivation object, built or restored lazily on first access for cacheable models.
- derive_model()#
Subclass hook that populates equations via
add_equationandapply; no-op on the base class.
- add_equation(name, expression=None, shape=None)#
Insert an equation under
name, accessible asself.<name>.Args
shape:Nonefor a scalar equation, else a shape or list of component labels giving one sub-equationname_i_jper index.
- remove_equation(name)#
Remove the equation
name.
- apply(op, *, level='major', description=None)#
Broadcast an Operation, substitution dict, Relation or callable over every equation (whole-model operations are applied once).
Args
level: history level,"major"or"minor".description: free text recorded in the history.
- describe(*, show_history=False, include_minor=False)#
Return a
ModelDescriptionthat renders the equation set (LaTeX in Jupyter, plain text otherwise).
- print_boundary_conditions()#
Definition of the boundary-condition function.
- flux()#
Flux
F(Q, Qaux, p), rank-2ZArray(n_eq, n_dim); by default tag-extracted from the equations, else zeros.
- diffusion_matrix()#
Implicitly treated diffusion tensor
A(Q, Qaux, p)of shape(n_var, n_var, dim, dim)withF_diff[i, d] = sum_{j,e} A[i,j,d,e] d_e Q[j]. Default is zero; seediffusion_matrix_explicitfor the explicit slot.
- diffusion_matrix_explicit()#
Explicitly treated diffusion tensor with the same shape and contract as
diffusion_matrix(subject to the parabolic CFL); default zero.
- dflux()#
Legacy flux derivative slot; zeros.
- hydrostatic_pressure()#
Hydrostatic pressure flux
P(Q, Qaux, p), rank-2(n_eq, n_dim); tag-extracted, else zeros.
- nonconservative_matrix()#
Nonconservative matrix
B(Q, Qaux, p), rank-3(n_eq, n_state, n_dim); tag-extracted, else zeros.
- source()#
Implicitly treated source (friction, stiff terms), length
n_variables; tag-extracted, else zeros.
- source_explicit()#
Explicitly treated source (non-stiff body forces), length
n_variables; tag-extracted, else zeros.
- mass_matrix()#
Mass matrix
M[i, j]= coefficient ofd_t Q[j]in equationi, extracted fromtime_derivative-tagged terms. Rows without a time derivative (elliptic constraints) are zero, soMis singular for such models.
- residual()#
Residual slot; zeros.
- interpolate()#
Interpolation slot; the state itself.
- interpolate_to_3d()#
Vertical reconstruction
{profile_slot: expr}, taken from the derivation byproduct, else zeros.
- project_from_3d()#
Profile-to-state projection
{state_field_or_slot: expr}; seeinterpolate_to_3d.
- initial_condition()#
Initial state expression; zeros.
- initial_aux_condition()#
Initial aux-state expression; zeros.
- update_variables()#
Per-cell state update applied after each step; identity.
- update_aux_variables()#
Per-cell aux update applied after each step; identity.
- reconstruction_variables()#
Symbolic map from the state to the (primitive, well-balanced) variables the MUSCL reconstruction limits; identity by default. Override to limit primitives such as
eta = h + bandu = q/hinstead of(h, q).Returns
ZArrayof lengthn_variables.References
Audusse et al. 2004, https://doi.org/10.1137/S1064827503431090
- state_from_reconstruction()#
Symbolic inverse of
reconstruction_variables, auto-derived byinvert_reconstructionin terms ofWB_<state>symbols; override only if sympy cannot close the inverse.
- update_variables_jacobian_wrt_variables()#
Jacobian of
update_variableswith respect to the state.
- update_aux_variables_jacobian_wrt_variables()#
Jacobian of
update_aux_variableswith respect to the state.
- quasilinear_matrix()#
Quasilinear matrix
dF/dQ + dP/dQ + Bof shape(n_var, n_var, dim).
- source_jacobian_wrt_variables()#
Jacobian of the implicit source with respect to the state.
- source_jacobian_wrt_aux_variables()#
Jacobian of the implicit source with respect to the aux variables.
- eigenvalues()#
Eigenvalues of the normal-projected quasilinear matrix, from the characteristic polynomial; a placeholder of zeros in
'numerical'mode.
- left_eigenvectors()#
Left eigenvector slot; zeros.
- right_eigenvectors()#
Right eigenvector slot; zeros.
- eigensystem()#
Packed eigendecomposition
[Lambda(n), R(n*n), L(n*n)]of the normal-projected quasilinear matrix, as opaqueeigensystemkernel calls evaluated numerically in the backends.
- print_model_functions(function_names=None)#
Print the definitions of the named model functions (default: flux, nonconservative_matrix, source, residual).
- summarize_model(tex=False)#
Model summary with the PDE form,
Q,Qaux,F,P,B,S, eigenvalues, parameters and configuration.Args
tex: return sympy objects as LaTeX strings.
Returns
dict keyed by those names.
- class zoomy_core.model.basemodel.ModelDescription(model, *, show_history=False, include_minor=False)#
Markdown / plain-text rendering of a
Modelreturned byModel.describe.Initialization
Store the model and the history options.