opencmp.solvers package
Subpackages
- opencmp.solvers.adaptive_transient_solvers package
- Submodules
- opencmp.solvers.adaptive_transient_solvers.adaptive_IMEX module
- opencmp.solvers.adaptive_transient_solvers.adaptive_three_step module
- opencmp.solvers.adaptive_transient_solvers.adaptive_two_step module
- opencmp.solvers.adaptive_transient_solvers.base_adaptive_transient_RK module
- opencmp.solvers.adaptive_transient_solvers.base_adaptive_transient_multistep module
- Module contents
Submodules
opencmp.solvers.base_solver module
- class opencmp.solvers.base_solver.Solver(model_class, config)[source]
Bases:
abc.ABC
Base class for the different stationary/transient solvers.
- abstract _apply_boundary_conditions()[source]
Apply the boundary conditions to all of the GridFunctions used by the model.
- Return type
None
- abstract _create_linear_and_bilinear_forms()[source]
Create the linear and bilinear forms of the model and add any required time integration terms.
- Return type
None
- abstract _create_preconditioners()[source]
Create the preconditioner(s) used by this time integration scheme.
- Return type
None
- _dt_for_next_time_to_hit()[source]
Function that calculate the time step till the next time that the model MUST be solved at due to a variety of constraints.
This time is used to set the time step in order to ensure that the model is solved at this time.
- Return type
float
- Returns
The next time that the model MUST be solved at.
- abstract _load_and_apply_initial_conditions()[source]
Function to load the initial conditions.
- Return type
None
- _log_timestep(accepted, error_abs, error_rel, component)[source]
Function to print out information about the current timestep’s iteration
- Parameters
accepted (
bool
) – Boolean indicating if the current timestep was accepted, or if it being rerun with a smaller dt.error_abs (
float
) – The absolute local error for this timestep. (not absolute value, but raw error value)error_rel (
float
) – The relative local error for this timestep.
- Return type
None
- abstract _re_assemble()[source]
Assemble the linear and bilinear forms of the model and update the preconditioner.
- Return type
None
- abstract _single_solve()[source]
Function to solve the model for the current time step.
- Return type
None
- abstract _startup()[source]
Higher order methods need to be started up with a first order implicit solve.
- Return type
None
- _update_bcs(bc_dict_patch)[source]
Function to update the model’s BCs to arbitrary values, and then recreate the linear/bilinear forms and the preconditioner.
This function is used by controllers in order to act on the manipulated variables.
- Parameters
bc_dict_patch (
Dict
[str
,Dict
[str
,Dict
[str
,List
[Optional
[CoefficientFunction
]]]]]) – Dictionary containing new values for the BCs being updated.- Return type
None
- abstract _update_preconditioners(precond_lst=None)[source]
Update the preconditioner(s) used by this time integration scheme. This is needed because the preconditioner(s) can’t be updated if it is None.
- Return type
None
- abstract _update_time_step()[source]
Function to calculate the new timestep and update the time (if a step is being taken).
If the model is stationary, this does nothing.
- Return type
Tuple
[bool
,float
,float
,str
]- Returns
Tuple containing a bool, a float, and a string. The bool indicates whether or not the result of the current iteration was accepted based on all of the criteria established by the individual solver (a stationary solver MUST return True). The float indicates the current local error. The string contains the variable name for the variable with the highest local error.
opencmp.solvers.misc module
- opencmp.solvers.misc.get_solver_class(config)[source]
Function to get the solver to use.
- Parameters
config (
ConfigParser
) – The config file from which to get information for which solver to use.- Return type
Type
[Solver
]- Returns
The solver to use.
opencmp.solvers.stationary module
- class opencmp.solvers.stationary.StationarySolver(model_class, config)[source]
Bases:
opencmp.solvers.base_solver.Solver
Stationary solver.
opencmp.solvers.time_integration_schemes module
- opencmp.solvers.time_integration_schemes.CNLF(model, gfu_0, dt)[source]
Crank Nicolson Leap Frog IMEX time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of previous time steps ordered from most recent to oldest.dt (
List
[Parameter
]) – List of timestep sizes ordered from most recent to oldest.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
- opencmp.solvers.time_integration_schemes.RK_222(model, gfu_0, dt, step)[source]
Two-step second-order Runge Kutta IMEX time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of intermediate steps in reverse step order (ie: [step n+1 sol, step 2 sol, step 1 sol, step n sol]).dt (
List
[Parameter
]) – List of current time step size.step (
int
) – Which step of the Runge Kutta scheme should be assembled.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
- opencmp.solvers.time_integration_schemes.RK_232(model, gfu_0, dt, step)[source]
Three-step second-order Runge Kutta IMEX time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of intermediate steps in reverse step order (ie: [step n+1 sol, step 2 sol, step 1 sol, step n sol]).dt (
List
[Parameter
]) – List of current time step size.step (
int
) – Which step of the Runge Kutta scheme should be assembled.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
- opencmp.solvers.time_integration_schemes.SBDF(model, gfu_0, dt)[source]
Third order semi-implicit backwards differencing time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of previous time steps ordered from most recent to oldest.dt (
List
[Parameter
]) – List of timestep sizes ordered from most recent to oldest.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
- opencmp.solvers.time_integration_schemes._add_dt_terms(a, L, gfu_lst, model, time_discretization_scheme)[source]
Function to handle the adding of the time discretization terms to the linear and bilinear forms.
- Parameters
a (
List
[BilinearForm
]) – List of all of the bilinear forms for the modelL (
List
[BilinearForm
]) – List of all of the linear forms for the modelgfu_lst (
List
[List
[GridFunction
]]) – List of the solutions of previous time steps in reverse chronological order.model (
Model
) –time_discretization_scheme (
str
) – The name of the time integration discretization being used.
- Return type
None
- opencmp.solvers.time_integration_schemes._split_gfu(gfu)[source]
Function to separate out the various components of each gridfunction solution to a previous timestep.
The first entry in gfu_lst is None so that its indexing matches the indexing for dt and the step argument in the functions for constructing the weak form (ie: gfu_lst[1], dt[1] and step=1 all refer to values at time n). The final result should be gfu_lst = [None, [component 0, component 1…] at t^n, [component 0, component 1…] at t^n-1, …].
- Parameters
gfu (
List
[GridFunction
]) – List of gridfunctions to split up- Return type
List
[List
[GridFunction
]]- Returns
[[component 0, component 1…] at t^n, [component 0, component 1…] at t^n-1, …]
- opencmp.solvers.time_integration_schemes.adaptive_IMEX_pred(model, gfu_0, dt)[source]
Predictor for the adaptive time-stepping IMEX time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of previous time steps ordered from most recent to oldest.dt (
List
[Parameter
]) – List of timestep sizes ordered from most recent to oldest.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
- opencmp.solvers.time_integration_schemes.crank_nicolson(model, gfu_0, dt)[source]
Crank Nicolson (trapezoidal rule) time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of previous time steps ordered from most recent to oldest.dt (
List
[Parameter
]) – List of timestep sizes ordered from most recent to oldest.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
- opencmp.solvers.time_integration_schemes.euler_IMEX(model, gfu_0, dt)[source]
First order IMEX time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of previous time steps ordered from most recent to oldest.dt (
List
[Parameter
]) – List of timestep sizes ordered from most recent to oldest.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
- opencmp.solvers.time_integration_schemes.explicit_euler(model, gfu_0, dt)[source]
Explicit Euler time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of previous time steps ordered from most recent to oldest.dt (
List
[Parameter
]) – List of timestep sizes ordered from most recent to oldest.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
- opencmp.solvers.time_integration_schemes.implicit_euler(model, gfu_0, dt, step=0)[source]
Implicit Euler time integration scheme.
This function constructs the final bilinear and linear forms for the time integration scheme by adding the necessary time-dependent terms to the model’s stationary terms. The returned bilinear and linear forms have NOT been assembled.
- Parameters
model (
Model
) – The model to solve.gfu_0 (
List
[GridFunction
]) – List of the solutions of previous time steps ordered from most recent to oldest.dt (
List
[Parameter
]) – List of timestep sizes ordered from most recent to oldest.step (
int
) – Used for adaptive_three_step to ensure the correct boundary condition and model function values are used when the half steps are taken.
- Returns
a: A list of the final bilinear forms (as a BilinearForm but not assembled).
L: A list of the final linear forms (as a LinearForm but not assembled).
- Return type
Tuple[BilinearForm, LinearForm]
opencmp.solvers.transient_RK module
- class opencmp.solvers.transient_RK.TransientRKSolver(model_class, config)[source]
Bases:
opencmp.solvers.base_solver.Solver
Transient Runge Kutta solver with a fixed time step.
opencmp.solvers.transient_multistep module
- class opencmp.solvers.transient_multistep.TransientMultiStepSolver(model_class, config)[source]
Bases:
opencmp.solvers.base_solver.Solver
Transient multistep solver with a fixed time step.