BaseSolver

TACS: Base Solver Class

This is the base class from which all other TACS solvers are derived. It is an abstract class, so cannot be used directly. Instead, it defines the methods that all solvers must implement.

API Reference

class tacs.solvers.BaseSolver(assembler: Assembler, setStateFunc: Callable, resFunc: Callable, stateVec: Vec | None = None, resVec: Vec | None = None, options: dict | None = None, comm: Comm | None = None)[source]

Create a solver instance

Parameters:
  • assembler (tacs.TACS.Assembler) -- TACS assembler object related to the problem being solved, required in order for the solver to create it's own vectors

  • setStateFunc (function) -- Function to set the state vector, with signature setStateFunc(stateVec: tacs.TACS.Vec) -> None

  • resFunc (function) -- Function to evaluate the residual at the current state, with signature resFunc(resVec: tacs.TACS.Vec) -> None

  • stateVec (tacs.TACS.Vec, optional) -- Vector to store the state in, by default the solver will create it's own but these can be passed to save additional allocations

  • resVec (tacs.TACS.Vec, optional) -- Vector to store the residual in, by default the solver will create it's own but these can be passed to save additional allocations

  • options (dict, optional) -- Dictionary holding solver-specific option parameters (case-insensitive)., by default None

  • comm (mpi4py.MPI.Intracomm, optional) -- The comm object on which to create the pyTACS object., by default mpi4py.MPI.COMM_WORLD

abstract getHistoryVariables() Dict[str, Dict][source]

Get the variables to be stored in the solver history

This method allows for implementation of any logic that dictates any changes in the stored variables depending on the current options.

Returns:

Dictionary of solver variables, keys are the variable names, value is another dictionary with keys "type" and "print", where "type" is the data type of the variable and "print" is a boolean indicating whether or not to print the variable to the screen

Return type:

Dict[str, Dict]

property hasConverged: bool

Whether the solver has converged, set as a property rather than an attribute so that it is read-only

property fatalFailure: bool

Whether the solver has failed, set as a property rather than an attribute so that it is read-only

Note that a fatalFailure is not the same as not converging, this flag is meant to reflect that there has been a fatal failure in the solver which requires a full reset

property iterationCount: int

Number of iterations performed, set as a property rather than an attribute so that it is read-only

abstract solve(u0: Vec | None = None, result: Vec | None = None) None[source]

Solve the residual equations r(u) = 0

Parameters:
  • u0 (TACS vector, optional) -- Initial guess, by default uses the current state

  • result (TACS vector, optional) -- Vector in which to store the solution, by default None. The problem's state is updated with the solution whether or not this is provided.

abstract setConvergenceTolerance(absTol: float | None = None, relTol: float | None = None) None[source]

Set the convergence tolerance of the solver

Parameters:
  • absTol (float, optional) -- Absolute tolerance, not changed if no value is provided

  • relTol (float, optional) -- Relative tolerance, not changed if no value is provided

initializeSolve(u0: Vec | None = None) None[source]

Perform any initialization required before the solve

Parameters:

u0 (TACS vector, optional) -- Initial guess, by default uses the current state

reset() None[source]

Reset the solver

Currently this just zeros out the state vector, but more functionality may be added in future

setRefNorm(norm: float) None[source]

Set the reference norm used to compute relative convergence measures

Parameters:

norm (float) -- Reference norm

setCallback(callback: Callable) None[source]

Set a callback function to be called at each iteration

Parameters:

callback (callable, optional) -- Callback function, should have the following signature: callback(solver: tacs.solver, u: tacs.TACS.Vec, res: tacs.TACS.Vec, monitorVars: dict) -> None Where: - solver is the solver object - u is the current state vector - res is the current residual vector - monitorVars is a dictionary of variables to monitor, which can be specified through the "nonlinearSolverMonitorVars" option

dtype

alias of float64

getOption(name)

Get a solver option value. The name is not case sensitive.

Parameters:

name (str) -- Name of option to get

classmethod printDefaultOptions()

Prints a nicely formatted dictionary of all the default solver options to the stdout

printModifiedOptions()

Prints a nicely formatted table of all the options that have been modified from their defaults

printOptions()

Prints a nicely formatted dictionary of all the current solver options to the stdout on the root processor

setOption(name, value)

Set a solver option value. The name is not case sensitive.

Parameters:
  • name (str) -- Name of option to modify

  • value (depends on option) -- New option value to set

setOptions(options)

Set multiple solver options at once. The names are not case sensitive.

Parameters:

options (dict) -- Dictionary of option names and values to set