Problem definition, the top-level class holding all data necessary to solve a problem.
It can be constructed from a ProblemConf instance using Problem.from_conf() or directly from a problem description file using Problem.from_conf_file()
For interactive use, the constructor requires only the equations, nls and ls keyword arguments.
Notes
The Problem is by default created with active_only set to True. Then the (tangent) matrices and residual vectors (right-hand sides) have reduced sizes and contain only the active DOFs, i.e., DOFs not constrained by EBCs or EPBCs. Setting active_only to False results in full-size vectors and matrices. Then the matrix size non-zeros structure does not depend on the actual E(P)BCs applied. It must be False when using parallel PETSc solvers.
Create evaluable object (equations and corresponding variables) from the expression string. Convenience function calling create_evaluable() with defaults provided by the Problem instance self.
The evaluable can be repeatedly evaluated by calling eval_equations(), e.g. for different values of variables.
Parameters: | expression : str
try_equations : bool
auto_init : bool
preserve_caches : bool
copy_materials : bool
integrals : Integrals instance, optional
ebcs : Conditions instance, optional
epbcs : Conditions instance, optional
lcbcs : Conditions instance, optional
ts : TimeStepper instance, optional
functions : Functions instance, optional
mode : one of ‘eval’, ‘el_avg’, ‘qp’, ‘weak’
var_dict : dict, optional
strip_variables : bool
extra_args : dict, optional
verbose : bool
**kwargs : keyword arguments
|
---|---|
Returns: | equations : Equations instance
variables : Variables instance
|
Examples
problem is Problem instance.
>>> out = problem.create_evaluable('dq_state_in_volume_qp.i1.Omega(u)')
>>> equations, variables = out
vec is a vector of coefficients compatible with the field of ‘u’ - let’s use all ones.
>>> vec = nm.ones((variables['u'].n_dof,), dtype=nm.float64)
>>> variables['u'].set_data(vec)
>>> vec_qp = eval_equations(equations, variables, mode='qp')
Try another vector:
>>> vec = 3 * nm.ones((variables['u'].n_dof,), dtype=nm.float64)
>>> variables['u'].set_data(vec)
>>> vec_qp = eval_equations(equations, variables, mode='qp')
Create materials with names in mat_names. Their definitions have to be present in self.conf.materials.
Notes
This method does not change self.equations, so it should not have any side effects.
Create a sub-problem with equations containing only terms with the given virtual variables.
Parameters: | var_names : list
known_var_names : list
|
---|---|
Returns: | subpb : Problem instance
|
Create variables with names in var_names. Their definitions have to be present in self.conf.variables.
Notes
This method does not change self.equations, so it should not have any side effects.
Evaluate (some of) the problem’s equations, convenience wrapper of eval_equations().
Parameters: | names : str or sequence of str, optional
preserve_caches : bool
mode : one of ‘eval’, ‘el_avg’, ‘qp’, ‘weak’
dw_mode : ‘vector’ or ‘matrix’
term_mode : str
verbose : bool
|
---|---|
Returns: | out : dict or result
|
Evaluate an expression, convenience wrapper of Problem.create_evaluable() and eval_equations().
Parameters: | dw_mode : ‘vector’ or ‘matrix’
term_mode : str
ret_variables : bool
other : arguments
|
---|---|
Returns: | out : array
variables : Variables instance
|
Returns mesh dimension, symmetric tensor dimension (if get_sym is True).
Either create a new Evaluator instance (reuse == False), or return an existing instance, created in a preceding call to Problem.init_solvers().
Get integrals, initialized from problem configuration if available.
Parameters: | names : list, optional
|
---|---|
Returns: | integrals : Integrals instance
|
Return default output file name, based on the output directory, output format, step suffix and mode. If present, the extra string is put just before the output format suffix.
If restarts are allowed in problem definition options, return the restart file name, based on the output directory and time step.
Create and return a TimeSteppingSolver instance.
Notes
Also sets self.ts attribute.
Create and initialize solver instances.
Parameters: | nls_status : dict-like, IndexedStruct, optional
ls_conf : Struct, optional
nls_conf : Struct, optional
force : bool
|
---|
Load the current state and time step from a restart file.
Alternatively, a regular output file in the HDF5 format can be used in place of the restart file. In that case the restart is only approximate, because higher order field DOFs (if any) were stripped out. Files with the adaptive linearization are not supported. Use with caution!
Parameters: | filename : str
state : State instance, optional
ts : TimeStepper instance, optional
|
---|---|
Returns: | new_state : State instance
|
Refine the mesh uniformly level-times.
Notes
This operation resets almost everything (fields, equations, ...) - it is roughly equivalent to creating a new Problem instance with the refined mesh.
Save essential boundary conditions as state variables.
Parameters: | filename : str
ebcs : Conditions instance, optional
epbcs : Conditions instance, optional
force : bool
default : float
|
---|
Save regions as meshes.
Parameters: | filename_trunk : str
region_names : list, optional
|
---|
Save regions in a single mesh but mark them by using different element/node group numbers.
See Domain.save_regions_as_groups() for more details.
Parameters: | filename_trunk : str
region_names : list, optional
|
---|
Save the current state and time step to a restart file.
Parameters: | filename : str
state : State instance, optional
ts : TimeStepper instance, optional
|
---|
Notes
Does not support terms with internal state.
Parameters: | file_per_var : bool or None
linearization : Struct or None
|
---|
Choose which solvers should be used. If solvers are not set in options, use first suitable in conf_solvers.
Set equations of the problem using the equations problem description entry.
Fields and Regions have to be already set.
Set equations of the problem to equations.
Set mesh coordinates.
Parameters: | coors : array
update_fields : bool
actual : bool
|
---|
Set the directory for output files.
The directory is created if it does not exist.
Set the instance of nonlinear solver that will be used in Problem.solve() call.
Provide default values to Problem.setup_output() from conf.options and options.
Setup various hooks (user-defined functions), as given in options.
Supported hooks:
- matrix_hook
- check/modify tangent matrix in each nonlinear solver iteration
- nls_iter_hook
- called prior to every iteration of nonlinear solver, if the solver supports that
- takes the Problem instance (self) as the first argument
Sets output options to given values, or uses the defaults for each argument that is None.
Solve self.equations in current time step.
Parameters: | var_data : dict
|
---|
Update equations for current time step.
The tangent matrix graph is automatically recomputed if the set of active essential or periodic boundary conditions changed w.r.t. the previous time step.
Parameters: | ts : TimeStepper instance, optional
ebcs : Conditions instance, optional
epbcs : Conditions instance, optional
lcbcs : Conditions instance, optional
functions : Functions instance, optional
create_matrix : bool
is_matrix : bool
|
---|
Update materials used in equations.
Parameters: | ts : TimeStepper instance
mode : ‘normal’, ‘update’ or ‘force’
verbose : bool
|
---|