Non Linear Solver for Mechanical Analyses

class code_aster.Solvers.IterationSolver.iteration_solver.BaseIterationSolver[source]

Bases: ABC, ContextMixin, DispatcherMixin

Solves a step, loops on iterations.

class SubType(value)[source]

Bases: IntFlag

Types of time integrators.

classmethod factory(context)[source]

Factory that creates the appropriate object.

Parameters:

context (Context) – Context of the problem.

Returns:

New object.

Return type:

instance

__init__()[source]
property matr_prediction

Type of prediction matrix to be used.

Type:

str

property update_matr_incr

Number of increments between updating matrix.

Type:

int

initialize()[source]

Initialize the object for the next step.

setLoggingManager(logManager)[source]

Assign the logging manager.

Parameters:

logManager (LoggingManager) – Logging manager.

property matrix_type

Type of the matrix to be currently used.

Type:

str

abstract solve(current_matrix, callback=None)[source]

Solve a step.

Raises:

*ConvergenceError* exception in case of error.

class code_aster.Solvers.IterationSolver.newton_solver.NewtonSolver[source]

Bases: BaseIterationSolver, EventSource

Solves a step, loops on iterations.

classmethod builder(context)[source]

Builder of NewtonSolver object.

Parameters:

context (Context) – Context of the problem.

Returns:

New object.

Return type:

instance

__init__()[source]
initialize()[source]

Initialize the object for the next step.

update(deltaU, resi_fields=None, callback=None)[source]

Update the physical state.

Parameters:
  • deltaU (FieldOnNodes) – Displacement increment.

  • resi_fields (dict of FieldOnNodes) – Fields of residual values

_resetMatrix()[source]

Reset matrix if needed

Parameters:

current_incr (int) – index of the current increment

solve(current_matrix, callback=None)[source]

Solve a step.

Raises:

*ConvergenceError* exception in case of error.

solve_iteration(matrix_type, matrix=None, force=False)[source]

Solve the iteration.

Parameters:
Returns:

Tuple with incremental primal, Jacobian matrix used (if computed).

Return type:

tuple (FieldOnNodesReal, AssemblyMatrixDisplacementReal)

_compute_primal_incr(residuals, jacobian, force, scaling)[source]

Solve the linear system to obtain the current solution increment

_get_jacobian_iteration(matrix, matrix_type)[source]

Obtain the Jacobian matric (recompute or use the one provided)

Parameters:
Returns:

Stiffness matrix to use in the current iteration

Return type:

jacobian (AssemblyMatrixDisplacementReal)

_compute_residuals(scaling)[source]

Computation of the residual

_update_contact_geometry()[source]

Update the pairing for contact

notifyObservers(matrix_type)[source]

Notify observers about the convergence.

Parameters:

matrix_type (str) – Type of matrix used.

get_state()[source]

Returns the current residuals to be shared with observers.

class code_aster.Solvers.IterationSolver.convergence_manager.ConvergenceManager[source]

Bases: ContextMixin

Object that decides about the convergence status.

class UnDefined[source]

Bases: object

Used to identify undefined values.

class Parameter(reference)[source]

Bases: object

A parameter to be checked for convergence.

Parameters:

reference (float|int) – Reference value.

classmethod factory(name, reference)[source]

Build a parameter object.

Parameters:
  • name (str) – Parameter name.

  • reference (float|int) – Reference value.

__init__(reference)[source]
isSet()[source]

Tell if the parameter value has been assigned.

Returns:

True if the parameter has a value, False if not.

Return type:

bool

minSet()[source]

Tell if a minimal value has been assigned.

Returns:

True if the parameter has a minimum, False if not.

Return type:

bool

hasRef()[source]

Tell if a reference value is defined for the parameter.

Returns:

True if the parameter has a reference value, False if not.

Return type:

bool

reset()[source]

Reset the parameter value.

property reference

Reference value of the parameter.

Type:

float|int

property value

Current value of the parameter.

Type:

float|int

property minValue

Current minimal value of the parameter.

Type:

float|int

isConverged()[source]

Tell if the current value is converged.

Returns:

True if the value is converged, False otherwise.

Return type:

bool

isFinished()[source]

Tell if the current parameter should stop the calculation.

Returns:

True if the calculation should be stopped, False otherwise.

Return type:

bool

class ResidualParameter(reference)[source]

Bases: Parameter

Type of Parameter for a residual.

Parameters:
  • name (str) – Parameter name.

  • reference (float|int) – Reference value.

match(pos=0, endpos=9223372036854775807)

Scan through string looking for a match, and return a corresponding match object instance.

Return None if no position in the string matches.

__init__(reference)[source]
isConverged()[source]

Tell if the current value is converged.

Returns:

True if the value is converged, False otherwise.

Return type:

bool

isFinished()[source]

Tell if the current parameter should stop the calculation.

Returns:

True if the calculation should be stopped, False otherwise.

Return type:

bool

class IterationParameter(reference)[source]

Bases: Parameter

Type of Parameter for a number of iteration.

Parameters:
  • name (str) – Parameter name.

  • reference (float|int) – Reference value.

match(pos=0, endpos=9223372036854775807)

Scan through string looking for a match, and return a corresponding match object instance.

Return None if no position in the string matches.

isConverged()[source]

The number of iteration is not a convergence criteria. but it can nullify the convergence if it is less than a minimal value.

Returns:

True.

Return type:

bool

isPrediction()[source]

Return True if self._value<1

Returns:

True.

Return type:

bool

isFinished()[source]

Tell if the current parameter should stop the calculation.

Returns:

True if the calculation should be stopped, False otherwise.

Return type:

bool

class ReferenceParameter(reference)[source]

Bases: Parameter

reerences for RESI_REFE_RELA

match(pos=0, endpos=9223372036854775807)

Scan through string looking for a match, and return a corresponding match object instance.

Return None if no position in the string matches.

isConverged()[source]

Tell if the current value is converged.

Returns:

True if the value is converged, False otherwise.

Return type:

bool

isFinished()[source]

Tell if the current parameter should stop the calculation.

Returns:

True if the calculation should be stopped, False otherwise.

Return type:

bool

classmethod builder(context)[source]

Default builder for ContextMixin object. Should be subclassed for non trivial constructor.

Parameters:

context (Context) – Context of the problem.

Returns:

New object.

Return type:

instance

__init__()[source]
initialize(*mandatory)[source]

Initialize the object for a new iteration.

Mandatory parameters must be defined before checking their convergency (here they are assigned to a negative value, not converged).

Parameters:

mandatory (tuple) – Name of parameters that are mandatory.

isInitialStep()[source]

Tell if it is the initial time step

hasResidual()[source]

Tell if there is at least one residual convergence parameter.

Returns:

True if at least one parameter is defined, False otherwise.

Return type:

bool

setdefault(name, reference=UNDEF)[source]

Add a convergence parameter if it does not yet exist.

Parameters:
  • name (str) – Name of the parameter.

  • reference (float) – Reference value of the parameter.

Returns:

The existing parameter if it already exists or a newly created one.

Return type:

Parameter

get(name)[source]

Return the value of a convergence parameter.

Parameters:

name (str) – Name of the parameter.

Returns:

Parameter value or undef it the parameter is not defined.

Return type:

float|int

getParameters()[source]

Return a copy of the parameters with their current values.

Returns:

Dict of parameters

Return type:

dict

getDirichletResidual(residual)[source]

Return the residual with Dirichlet imposed values.

Parameters:

residual (FieldOnNodesReal) – Residual.

Returns:

Residual changed in place.

Return type:

FieldOnNodesReal

getRelativeScaling(residuals)[source]

Returns the scaling factor to compute the relative error

Parameters:

residuals (Residuals) – Collections of residuals.

Returns:

scaling factor.

Return type:

float

evalNormResidual(residuals)[source]

Evaluate global residual.

Parameters:

residuals (Residuals) – Collections of residuals.

evalGeometricResidual(displ_delta)[source]

Evaluate geometric residual.

Parameters:

displ_dela (FieldOnNodesReal) – variation of displacement.

isConverged()[source]

Tell if the convergence parameters are verified.

Returns:

True if converged, False otherwise.

Return type:

bool

isPrediction()[source]

Tell if the current Newton iteration is the prediction iteration.

Returns:

True if prediction, False otherwise.

Return type:

bool

isFinished()[source]

Tell if a parameter is stopping the calculation.

Returns:

True if the calculation should be stopped, False otherwise.

Return type:

bool

class code_aster.Solvers.IterationSolver.line_search.LineSearchType(value)[source]

Bases: IntFlag

Line Search types.

classmethod by_name(name)[source]

Return an option value by its name. AttributeError is raised if the option does not exist.

Parameters:

name (str) – Option name.

Returns:

Option value.

Return type:

int

class code_aster.Solvers.IterationSolver.line_search.BaseLineSearch[source]

Bases: ABC, ContextMixin

Base for line search methods

classmethod factory(context)[source]

Factory that creates the appropriate object.

Parameters:

context (Context) – Context of the problem.

Returns:

New object.

Return type:

BaseLineSearch

__init__()[source]
isEnabled()[source]

bool: True if LineSearch is activated.

compute_f(rho, solution, scaling=1.0)[source]

Compute functional

abstract solve(solution, scaling=1.0)[source]

Apply linear search for mechanical problems.

Parameters:
  • solution (FieldOnNodes) – Displacement solution.

  • scaling (float) – Scaling factor for Lagrange multipliers (default: 1.0).

Returns:

Accelerated solution by linear search.

Return type:

FieldOnNodes

class code_aster.Solvers.IterationSolver.line_search.SecantLineSearch[source]

Bases: BaseLineSearch

Line search for CORDE & MIXTE methods.

__init__()[source]
solve(solution, scaling=1.0)[source]

Apply linear search for mechanical problems.

Parameters:
  • solution (FieldOnNodes) – Displacement solution.

  • scaling (float) – Scaling factor for Lagrange multipliers (default: 1.0).

Returns:

Accelerated solution by linear search.

Return type:

FieldOnNodes

Useful objects used to build operators.

class code_aster.Solvers.Basics.bases.ProblemType(value)[source]

Bases: IntFlag

Types of physical problems.

class code_aster.Solvers.Basics.bases.DispatcherMixin[source]

Bases: object

Mixin class that provides a factory depending on the type of physical problem.

classmethod factory(context)[source]

Factory that creates the appropriate object.

Parameters:

context (Context) – Context of the problem.

Returns:

A new object of the relevant type.

Return type:

instance

class code_aster.Solvers.Basics.bases.Observer[source]

Bases: ABC

The Observer interface declares the notify method, used by events.

abstract notify(event)[source]

Receive notification from event.

Parameters:

event (EventSource) – Object that sends the notification.

class code_aster.Solvers.Basics.bases.EventId(value)[source]

Bases: IntFlag

Identifiers of EventSource objects.

class code_aster.Solvers.Basics.bases.EventSource[source]

Bases: ABC

The EventSource interface declares a set of methods for managing observers.

__init__() None[source]
property eid

Attribute that holds the id of the event.

Type:

EventId

add_observer(observer)[source]

Attach an observer to the event.

Parameters:

observer (Observer) – Observer object to be added.

remove_observer(observer)[source]

Detach an observer from the event.

Parameters:

observer (Observer) – Observer object to be removed.

notifyObservers()[source]

Notify all observers about an event.

abstract get_state()[source]

Returns the current state to be shared with observers.

Base objects used to solve generic non linear problems.

class code_aster.Solvers.Basics.context.Context[source]

Bases: object

Object that stores the objects required by a NonLinearOperator.

It only stores objects that are shared at different levels of the algorithm. Objects only used by one stage/object should be created there. If different objects should be created at each timestep for example, they should not be here.

problem

PhysicalProblem object

state

PhysicalState object

result

Result object (NonLinearResult, ThermalResult , DryingResult)

problem_type

ProblemType enum value

keywords

Part of the user keywords

oper

BaseOperators object

stepper

TimeStepper object

contact

ContactManager object

linear_solver

LinearSolver object

class KeywordsStore(keywords)[source]

Bases: object

Container that stores and gives access to some user keywords.

__init__(keywords)[source]
__getitem__(keyword)[source]

Return a keyword value.

Parameters:

keyword (str) – Simple keyword.

Returns:

Keyword value.

Return type:

misc

get(keyword, parameter=None, default=None)[source]

Return a keyword value.

Parameters:
  • keyword (str) – Simple or factor keyword.

  • parameter (str|None) – Simple keyword under the factor keyword, or None.

  • default (misc) – Default value if the keyword is undefined.

Returns:

Keyword value.

Return type:

misc

__init__()[source]
check()[source]

Check for required/optional attributes.

property problem_type

Attribute that holds the type of problem.

Type:

ProblemType

property keywords

Attribute that holds the keywords object.

Type:

Dict

get_keyword(keyword, parameter=None, default=None)[source]

“Return a keyword value.

Parameters:
  • keyword (str) – Simple or factor keyword.

  • parameter (str|None) – Simple keyword under the factor keyword, or None.

  • default (misc) – Default value if the keyword is undefined.

Returns:

Keyword value.

Return type:

misc

property problem

current problem description.

Type:

PhysicalProblem

property state

current state.

Type:

PhysicalState

property result

Attribute that holds the result object.

Type:

Result

property stepper

Attribute that holds the time stepper.

Type:

TimeStepper

property oper

Object that adapts operators for each type of problem.

Type:

Operators

property contact

Object to solve contact conditions

Type:

ContactManager

property linear_solver

Attribute that holds the linear solver.

Type:

LinearSolver

code_aster.Solvers.Basics.context.check_access(alt=None)[source]

Decorator to wrap TestCase methods by calling writeResult

class code_aster.Solvers.Basics.context.ContextMixin[source]

Bases: object

Mixin object that wraps access to the objects of Context.

problem

PhysicalProblem object

state

PhysicalState object

result

Result object (NonLinearResult, ThermalResult, DryingResult)

problem_type

ProblemType enum value

keywords

Part of the user keywords

oper

BaseOperators object

contact

ContactManager object

linear_solver

LinearSolver object

classmethod builder(context)[source]

Default builder for ContextMixin object. Should be subclassed for non trivial constructor.

Parameters:

context (Context) – Context of the problem.

Returns:

New object.

Return type:

instance

__init__()[source]
property context

Context attached to the object.

Type:

Data

property problem_type

Attribute that holds the type of problem.

Type:

ProblemType

property keywords

Attribute that holds the keywords object.

Type:

Dict

get_keyword(keyword, parameter=None, default=None)[source]

“Return a keyword value.

Parameters:
  • keyword (str) – Simple or factor keyword.

  • parameter (str|None) – Simple keyword under the factor keyword, or None.

  • default (misc) – Default value if the keyword is undefined.

Returns:

Keyword value.

Return type:

misc

property problem

current problem description.

Type:

PhysicalProblem

property state

current state.

Type:

PhysicalState

property result

Attribute that holds the result object.

Type:

Result

property stepper

Attribute that holds the time stepper.

Type:

TimeStepper

property oper

Object that adapts operators for each type of problem.

Type:

Operators

property contact

Object to solve contact conditions

Type:

ContactManager

property linear_solver

Attribute that holds the linear solver.

Type:

LinearSolver

code_aster.Solvers.Basics.physical_state.get_all_subclasses(cls)[source]

Return all subclasses of ‘cls’ recursively.

class code_aster.Solvers.Basics.physical_state.PhysicalState(pb_type, size=1)[source]

Bases: Observer

This object represents a Physical State of the model.

Actually, it stores a stack of physical states and works as an adapter on the current state. Only the current state, the working one, has setters and so is writable. All other states on the stack are read-only.

class State[source]

Bases: ABC

Represents an elementary physical state (private).

For the primal fields, one stores the field at the beginning of the step and its increment. They are accessed with U and eventually dU, d2U. The dual field is accessed with S (stress in mechanics) or Phi (heat flux in thermics) properties (value at t+dt). The other fields are accessed by name (value at t+dt).

classmethod factory(pb_type: ProblemType)[source]

Create a new State object of ProblemType.

__init__()[source]
abstract property U

Attribute that holds the primal unknown.

Type:

U

getFields()[source]

Return the list of available fields.

property time_prev

Previous time.

Type:

float

property time_curr

Current time.

Type:

float

property time_step

Time step.

Type:

float

property U_t

Primal field at previous time.

Type:

FieldOnNodesReal

property deltaU

Primal increment.

Type:

FieldOnNodesReal

property fields_prev

Dictionary of previous fields.

Type:

dict

property fields_step

Dictionary of fields steps.

Type:

dict

get(key)[source]

Return a field.

set(key, field)[source]

Assign a field.

property dual

Dual field.

Type:

FieldOnCellsReal

property internVar

Internal state variables.

Type:

FieldOnCellsReal

property externVar

External state variables.

Type:

FieldOnCellsReal

copy(other)[source]

Copy the content of an object into the current one.

Parameters:

other (PhysicalState.State) – Object to be copied.

Returns:

Current object.

Return type:

PhysicalState.State

duplicate()[source]

Duplicate the physical state.

Returns:

the new physical state.

Return type:

PhysicalState.State

swap(other)[source]

Swap the content of an object with the current one.

Parameters:

other (PhysicalState.State) – Object to be swaped.

asdict()[source]

Returns the fields as a dict.

Returns:

Dict of fields.

Return type:

dict

debugPrint(label='')[source]

Print a representation of the object.

class StateMecaStat[source]

Bases: State

property U

Attribute that holds the displacement field.

Type:

U

class StateMecaDyna[source]

Bases: StateMecaStat

property dU

Attribute that holds the derivative of displacement field.

Type:

dU

property d2U

Attribute that holds the second derivative of displacement field.

Type:

U

class StateThermal[source]

Bases: StateMecaStat

__init__(pb_type, size=1)[source]
copy(other)[source]

Copy the content of an object into the current one.

Parameters:

other (PhysicalState) – Object to be copied.

Returns:

Current object.

Return type:

PhysicalState

duplicate()[source]

Duplicate the physical state.

Returns:

the new physical state.

Return type:

PhysicalState

swap(other)[source]

Swap the content of the physical state.

Parameters:

other (PhysicalState) – the physical state to be swaped.

getState(index=0)[source]

Return a physical state by index (relative position).

Parameters:

index (int) – 0 means the current one, -1 the previous one and so on.

Returns:

physical state.

Return type:

PhysicalState.State

property pb_type

The type of the physical problem

Type:

ProblemType

setObservation(observation)[source]

Register the Observation object.

notify(event)[source]

Delegate to Observation object.

property current

The current physical state, the working one.

Type:

PhysicalState.State

property time_prev

Previous time.

Type:

float

property time_curr

Current time.

Type:

float

property time_step

Time step.

Type:

float

property U_t

Primal field at previous time.

Type:

FieldOnNodesReal

property U

Primal field at current time.

Type:

FieldOnNodesReal

property deltaU

Primal increment.

Type:

FieldOnNodesReal

property dual

Dual field.

Type:

FieldOnCellsReal

property stress

Dual field.

Type:

FieldOnCellsReal

property phi

Dual field.

Type:

FieldOnCellsReal

property internVar

Internal state variables.

Type:

FieldOnCellsReal

property externVar

External state variables.

Type:

FieldOnCellsReal

get(key)[source]

FieldOnCellsReal: The field stored at this key.

set(key, field)[source]

Assign a field at the given key.

Parameters:

field (FieldOnCellsReal) – Field

stash()[source]

Stores the object state to provide transactionality semantics.

revert()[source]

Revert the object to its previous state.

commit()[source]

Commits the current changes and add the state on the stack.

getCurrentDelta()[source]

Return the delta for the current state between it has been stashed.

Returns:

Delta between states as returned by py:method:asdict.

Return type:

dict

getDeltaBetweenStates(index1, index2)[source]

Return the delta between two states.

The states are extracted using getState(index). It returns the difference getState(index2) - getState(index1).

Parameters:
  • index1 (int) – Index of the first state.

  • index2 (int) – Index of the second state.

Returns:

Delta between states as returned by py:method:asdict.

Return type:

dict

static _states_difference(one, two)[source]

Delta between states as returned by py:method:asdict.

static createPrimal(phys_pb, value=0.0)[source]

Create primal field with a given value

Parameters:
  • phys_pb (PhysicalProblem) – Physical problem

  • value (Union[float, dict]) – value to set everywhere

Returns:

primal field with a given value (DEPL|TEMP)

Return type:

FieldOnNodes

static createFieldOnCells(phys_pb, localization, quantity, value=0.0)[source]

Create a field with a given value

Parameters:
  • phys_pb (PhysicalProblem) – Physical problem

  • localization (str) – localization of the field to create (ELNO, ELEM, ELGA)

  • quantity (str) – type of the field to create (ex: SIEF_R, …)

  • value (float) – value to set everywhere

Returns:

field with a given value of type “type”

Return type:

FieldOnCells

static createDual(phys_pb, value)[source]

Create the dual field with a given value

Parameters:
  • phys_pb (PhysicalProblem) – Physical problem

  • value (float) – value to set everywhere

Returns:

Stress field with a given value (SIEF_ELGA/FLUX_ELGA)

Return type:

FieldOnCells

static createInternalVariablesNext(phys_pb, value)[source]

Create internal state variables field with a given value

Parameters:
  • phys_pb (PhysicalProblem) – Physical problem

  • value (float) – value to set everywhere

Returns:

internal state variables field with a given value (VARI_ELGA)

Return type:

FieldOnCells

static createTimeField(phys_pb, value)[source]

Create time field with a given value

Parameters:
  • phys_pb (PhysicalProblem) – Physical problem

  • value (float) – value to set everywhere

Returns:

time field with a given value

Return type:

ConstantFieldOnCellsReal

zeroInitialState(phys_pb)[source]

Initialize with zero initial state

Parameters:

phys_pb (PhysicalProblem) – Physical problem

asdict()[source]

Returns the fields as a dict.

Returns:

Dict of fields.

Return type:

dict

debugPrint(label='', recursive=False)[source]

Print a representation of the object.

class code_aster.Solvers.Basics.residual.Residuals[source]

Bases: object

Container to store intermediate field.

resi

Global residual.

Type:

FieldOnNodesReal

resi_int

Internal residual.

Type:

FieldOnNodesReal

resi_ext

External residual.

Type:

FieldOnNodesReal

resi_dual

Dirichlet reactions.

Type:

FieldOnNodesReal

resi_stress

Internal forces.

Type:

FieldOnNodesReal

resi_cont

Contact residual.

Type:

FieldOnNodesReal

resi_mass

Inertial residual.

Type:

FieldOnNodesReal

class code_aster.Solvers.Basics.logging_manager.LoggingManager[source]

Bases: object

Object that decides about the logging.

__init__()[source]
addConvTableColumn(column)[source]

Add a colum to the table

Arguements:

column[str]: title of the column

printIntro(time, step)[source]

Print introduction

Arguements:

time[float]: current time step[int]: step

printConvTableSeparator()[source]

Print separator.

printConvTableEntries()[source]

Print titles of columns

printConvTableRow(values)[source]

Print values of colums