60 #define nrsolver_ERROR_NORM_SMALL_NUM 1.e-6 61 #define NRSOLVER_MAX_REL_ERROR_BOUND 1.e20 62 #define NRSOLVER_MAX_RESTARTS 4 63 #define NRSOLVER_RESET_STEP_REDUCE 0.25 64 #define NRSOLVER_DEFAULT_NRM_TICKS 10 76 NR_Mode = NR_OldMode = nrsolverModifiedNRM;
79 numberOfPrescribedDofs = 0;
80 prescribedDofsFlag =
false;
81 prescribedEqsInitFlag =
false;
82 prescribedDisplacementTF = 0;
85 constrainedNRFlag =
false;
86 this->forceErrVecOld.resize(0);
87 this->forceErrVec.resize(0);
88 constrainedNRalpha = 0.5;
90 smConstraintVersion = 0;
91 mCalcStiffBeforeRes =
true;
93 maxIncAllowed = 1.0e20;
156 OOFEM_ERROR(
"direct displacement mask size mismatch");
172 int calcStiffBeforeResFlag = 1;
174 if ( calcStiffBeforeResFlag == 0 ) {
192 for (
int i = 0; i < dofs.
giveSize(); ++i ) {
216 bool converged, errorOutOfRangeFlag;
227 OOFEM_LOG_INFO(
"\n----------------------------------------------------------------------------\n");
263 for ( nite = 0; ; ++nite ) {
273 converged = this->
checkConvergence(RT, F, rhs, ddX, X, RRT, internalForcesEBENorm, nite, errorOutOfRangeFlag);
275 if ( errorOutOfRangeFlag ) {
277 OOFEM_WARNING(
"Divergence reached after %d iterations", nite);
282 }
else if ( nite >=
nsmax ) {
294 if ( ( nite == 0 ) && (
deltaL < 1.0 ) ) {
310 if ( this->
lsFlag && ( nite > 0 ) ) {
328 for (
double inc : ddX ) {
329 if(fabs(inc) > maxInc) {
336 printf(
"Restricting increment. maxInc: %e\n", maxInc);
427 for (
int j = 1; j <= ndofman; j++ ) {
435 if ( inode == jglobnum ) {
443 for (
int i = 1; i <= count; i++ ) {
460 #ifdef __PETSC_MODULE 468 MatGetDiagonal(* lhs->
giveMtrx(), diag);
469 VecGetArray(diag, & ptr);
472 MatSetValue(* ( lhs->
giveMtrx() ), eq, eq, ptr [ eq ] * 1.e6, INSERT_VALUES);
475 MatAssemblyBegin(* lhs->
giveMtrx(), MAT_FINAL_ASSEMBLY);
476 MatAssemblyEnd(* lhs->
giveMtrx(), MAT_FINAL_ASSEMBLY);
477 VecRestoreArray(diag, & ptr);
486 #endif // __PETSC_MODULE 511 #ifdef __PETSC_MODULE 525 #ifdef __PETSC_MODULE 531 MatGetDiagonal(* ( const_cast< PetscSparseMtrx * >(lhs)->giveMtrx() ), diag);
532 VecGetArray(diag, & ptr);
539 VecRestoreArray(diag, & ptr);
562 fprintf(outputStream,
"\nQuasi reaction table:\n\n");
563 fprintf(outputStream,
" node dof force\n");
564 fprintf(outputStream,
"============================\n");
574 fprintf(outputStream,
"============================\n\n");
581 double RRT,
const FloatArray &internalForcesEBENorm,
582 int nite,
bool &errorOutOfRange)
584 double forceErr, dispErr;
585 FloatArray dg_forceErr, dg_dispErr, dg_totalLoadLevel, dg_totalDisp;
601 errorOutOfRange =
false;
610 if ( internalForcesEBENorm.
giveSize() > 1 ) {
616 dg_forceErr.
resize(nccdg);
620 dg_totalLoadLevel.
resize(nccdg);
621 dg_totalLoadLevel.
zero();
622 dg_totalDisp.
resize(nccdg);
626 if ( !parallel_context->
isLocal(dofman.get()) ) {
631 for (
Dof *dof: *dofman ) {
632 if ( !dof->isPrimaryDof() ) {
635 int eq = dof->giveEquationNumber(dn);
636 int dofid = dof->giveDofID();
641 dg_forceErr.
at(dofid) += rhs.
at(eq) * rhs.
at(eq);
642 dg_dispErr.
at(dofid) += ddX.
at(eq) * ddX.
at(eq);
643 dg_totalLoadLevel.
at(dofid) += RT.
at(eq) * RT.
at(eq);
644 dg_totalDisp.
at(dofid) += X.
at(eq) * X.
at(eq);
645 idsInUse.
at(dofid)++;
656 for (
int idofman = 1; idofman <= elem->giveNumberOfInternalDofManagers(); idofman++ ) {
657 DofManager *dofman = elem->giveInternalDofManager(idofman);
659 for (
Dof *dof: *dofman ) {
660 if ( !dof->isPrimaryDof() ) {
663 int eq = dof->giveEquationNumber(dn);
664 int dofid = dof->giveDofID();
670 dg_forceErr.
at(dofid) += rhs.
at(eq) * rhs.
at(eq);
671 dg_dispErr.
at(dofid) += ddX.
at(eq) * ddX.
at(eq);
672 dg_totalLoadLevel.
at(dofid) += RT.
at(eq) * RT.
at(eq);
673 dg_totalDisp.
at(dofid) += X.
at(eq) * X.
at(eq);
674 idsInUse.
at(dofid)++;
682 for (
int idofman = 1; idofman <= bc->giveNumberOfInternalDofManagers(); idofman++ ) {
683 DofManager *dofman = bc->giveInternalDofManager(idofman);
685 for (
Dof *dof: *dofman ) {
686 if ( !dof->isPrimaryDof() ) {
689 int eq = dof->giveEquationNumber(dn);
690 int dofid = dof->giveDofID();
696 dg_forceErr.
at(dofid) += rhs.
at(eq) * rhs.
at(eq);
697 dg_dispErr.
at(dofid) += ddX.
at(eq) * ddX.
at(eq);
698 dg_totalLoadLevel.
at(dofid) += RT.
at(eq) * RT.
at(eq);
699 dg_totalDisp.
at(dofid) += X.
at(eq) * X.
at(eq);
700 idsInUse.
at(dofid)++;
707 parallel_context->
accumulate(dg_forceErr, collectiveErr);
708 dg_forceErr = collectiveErr;
709 parallel_context->
accumulate(dg_dispErr, collectiveErr);
710 dg_dispErr = collectiveErr;
711 parallel_context->
accumulate(dg_totalLoadLevel, collectiveErr);
712 dg_totalLoadLevel = collectiveErr;
713 parallel_context->
accumulate(dg_totalDisp, collectiveErr);
714 dg_totalDisp = collectiveErr;
720 int maxNumPrintouts = 6;
721 int numPrintouts = 0;
725 for (
int dg = 1; dg <= nccdg; dg++ ) {
727 bool zeroFNorm =
false, zeroDNorm =
false;
729 if ( !idsInUse.
at(dg) ) {
742 forceErr = sqrt( dg_forceErr.
at(dg) / ( dg_totalLoadLevel.
at(dg) + internalForcesEBENorm.
at(dg) +
745 forceErr = sqrt( dg_forceErr.
at(dg) / ( dg_totalLoadLevel.
at(dg) + internalForcesEBENorm.
at(dg) ) );
750 forceErr = sqrt( dg_forceErr.
at(dg) );
754 errorOutOfRange =
true;
756 if ( forceErr >
rtolf.
at(1) ) {
773 dispErr = sqrt( dg_dispErr.
at(dg) / dg_totalDisp.
at(dg) );
778 dispErr = sqrt( dg_dispErr.
at(dg) );
781 errorOutOfRange =
true;
809 forceErr = parallel_context->
localNorm(rhs);
810 forceErr *= forceErr;
819 forceErr = sqrt( forceErr / ( RRT + internalForcesEBENorm.
at(1) ) );
821 forceErr = sqrt(forceErr);
824 errorOutOfRange =
true;
826 if ( fabs(forceErr) >
rtolf.
at(1) ) {
844 dispErr = sqrt(dXdX / dXX);
846 dispErr = sqrt(dXdX);
849 errorOutOfRange =
true;
851 if ( fabs(dispErr) >
rtold.
at(1) ) {
LinSystSolverType
The values of this type should be related not to specific solvers, but more to specific packages that...
virtual SparseLinearSystemNM * giveLinearSolver()
Constructs (if necessary) and returns a linear solver.
The representation of EngngModel default unknown numbering.
#define _IFT_NRSolver_linesearch
#define NM_Success
Numerical method exited with success.
void applyConstraintsToStiffness(SparseMtrx &k)
problemScale giveProblemScale()
Returns scale in multiscale simulation.
int giveGlobalNumber() const
double constrainedNRalpha
Scale factor for dX, dX_new = alpha * dX.
bool isLocal(DofManager *dman)
virtual IRResultType initializeFrom(InputRecord *ir)
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Base class for all matrices stored in sparse format.
#define _IFT_NRSolver_manrmsteps
void initPrescribedEqs()
Initiates prescribed equations.
int numberOfPrescribedDofs
number of prescribed displacement
This class implements Newton-Raphson Method, derived from abstract NumericalMethod class for solving ...
#define _IFT_NRSolver_forceScaleDofs
IntArray prescribedDofs
Array of pairs identifying prescribed dofs (node, dof)
LineSearchNM * giveLineSearchSolver()
Constructs and returns a line search solver.
void zero()
Sets all component to zero.
ExportModuleManager * giveExportModuleManager()
Returns receiver's export module manager.
double & at(int i)
Coefficient access function.
void createVecGlobal(Vec *answer) const
Creates a global vector that fits the instance of this matrix.
This base class is an abstraction for all numerical methods solving sparse linear system of equations...
#define _IFT_NRSolver_ddm
void clear()
Clears receiver (zero size).
REGISTER_SparseNonLinearSystemNM(CylindricalALM)
#define _IFT_NRSolver_calcstiffbeforeres
#define _IFT_NRSolver_rtolv
virtual IRResultType initializeFrom(InputRecord *ir)
double giveTargetTime()
Returns target time.
FloatArray rtold
Relative iterative displacement change tolerance for each group.
void incrementStateCounter()
Updates solution state counter.
void doOutput(TimeStep *tStep, bool substepFlag=false)
Writes the output.
Base class for dof managers.
std::vector< std::unique_ptr< DofManager > > & giveDofManagers()
bool lsFlag
Flag indicating whether to use line-search.
int giveNumber()
Returns domain number.
std::unique_ptr< LineSearchNM > linesearchSolver
Line search solver.
virtual double & at(int i, int j)=0
Returns coefficient at position (i,j).
#define _IFT_NRSolver_maxiter
std::unique_ptr< SparseLinearSystemNM > linSolver
linear system solver
unsigned long NM_Status
Mask defining NumMetod Status; which can be asked after finishing computation by Numerical Method...
#define OOFEM_LOG_DEBUG(...)
Class implementing an array of integers.
int & at(int i)
Coefficient access function.
std::map< int, double > dg_forceScale
Optional user supplied scale of forces used in convergence check.
LinSystSolverType solverType
linear system solver ID
void beDifferenceOf(const FloatArray &a, const FloatArray &b)
Sets receiver to be a - b.
int constrainedNRminiter
Minimum number of iterations before constraint is activated.
double giveTimeIncrement()
Returns solution step associated time increment.
bool isTheFirstStep()
Check if receiver is first step.
void incrementSubStepNumber()
Increments receiver's substep number.
#define NM_NoSuccess
Numerical method failed to solve problem.
Domain * domain
Pointer to domain.
std::vector< std::unique_ptr< GeneralBoundaryCondition > > & giveBcs()
#define OOFEM_LOG_INFO(...)
void applyConstraintsToLoadIncrement(int nite, const SparseMtrx &k, FloatArray &R, referenceLoadInputModeType rlm, TimeStep *tStep)
void clear()
Clears the array (zero size).
double computeSquaredNorm() const
Computes the square of the norm.
DofIDItem
Type representing particular dof type.
virtual void updateComponent(TimeStep *tStep, NumericalCmpn cmpn, Domain *d)
Updates components mapped to numerical method if necessary during solution process.
The reference incremental load vector is defined as totalLoadVector assembled at given time...
FloatArray rtolf
Relative unbalanced force tolerance for each group.
virtual ParallelContext * giveParallelContext(int n)
Returns the parallel context corresponding to given domain (n) and unknown type Default implementatio...
#define _IFT_NRSolver_miniterations
#define _IFT_NRSolver_rtolf
#define _IFT_NRSolver_ddv
referenceLoadInputModeType
The following parameter allows to specify how the reference load vector is obtained from given totalL...
void resize(int n)
Checks size of receiver towards requested bounds.
#define _IFT_NRSolver_maxinc
Function * giveFunction(int n)
Service for accessing particular domain load time function.
FloatArray forceErrVecOld
Initializes the variable VERBOSE, in order to get a few intermediate messages on screen: beginning an...
Class representing vector of real numbers.
SparseLinearSystemNM * createSparseLinSolver(LinSystSolverType st, Domain *d, EngngModel *m)
Creates new instance of SparseLinearSystemNM corresponding to given type.
bool mCalcStiffBeforeRes
Flag indicating if the stiffness should be evaluated before the residual in the first iteration...
virtual NM_Status solve(SparseMtrx &k, FloatArray &R, FloatArray *R0, FloatArray &X, FloatArray &dX, FloatArray &F, const FloatArray &internalForcesEBENorm, double &l, referenceLoadInputModeType rlm, int &nite, TimeStep *)
Solves the given sparse linear system of equations .
IRResultType initializeFrom(InputRecord *ir)
Element is local, there are no contributions from other domains to this element.
IRResultType
Type defining the return values of InputRecord reading operations.
virtual NM_Status solve(FloatArray &r, FloatArray &dr, FloatArray &F, FloatArray &R, FloatArray *R0, IntArray &eqnmask, double lambda, double &etaValue, LS_status &status, TimeStep *tStep)
Solves the line search optimization problem in the form of , The aim is to find so that the has dec...
virtual IRResultType initializeFrom(InputRecord *ir)
bool constrainedNRFlag
Flag indicating whether to use constrained Newton.
#define _IFT_NRSolver_forceScale
virtual void printState(FILE *outputStream)
Prints status message of receiver to output stream.
#define _IFT_NRSolver_lstype
#define NRSOLVER_MAX_REL_ERROR_BOUND
This class provides an communication context for distributed memory parallelism.
Dof * giveDofWithID(int dofID) const
Returns DOF with given dofID; issues error if not present.
IntArray prescribedEqs
Array of prescribed equations.
nrsolver_ModeType NR_OldMode
void zero()
Zeroes all coefficients of receiver.
int giveMaxDofID()
Gives the current maximum dof ID used.
void times(double s)
Multiplies receiver with scalar.
nrsolver_ModeType NR_Mode
double accumulate(double local)
Accumulates the global value.
ClassFactory & classFactory
std::string __DofIDItemToString(DofIDItem _value)
bool prescribedDofsFlag
Flag indicating that some dofs are controlled under displacement control.
int giveEquationNumber(const UnknownNumberingScheme &s)
Returns equation number of receiver for given equation numbering scheme.
std::vector< std::unique_ptr< Element > > & giveElements()
Abstract base class representing the "problem" under consideration.
#define _IFT_NRSolver_rtold
SparseMtrx::SparseMtrxVersionType smConstraintVersion
sparse matrix version, used to control constrains application to stiffness
int giveSize() const
Returns the size of receiver.
Node * giveNode(int n)
Service for accessing particular domain node.
the oofem namespace is to define a context or scope in which all oofem names are defined.
FloatArray lastReactions
Computed reactions. They are stored in order to print them in printState method.
Domain * giveDomain(int n)
Service for accessing particular problem domain.
int prescribedDisplacementTF
Load Time Function of prescribed values.
#define _IFT_NRSolver_ddfunc
Abstract class Dof represents Degree Of Freedom in finite element mesh.
#define _IFT_NRSolver_minsteplength
#define _IFT_NRSolver_constrainedNRminiter
EngngModel * engngModel
Pointer to engineering model.
double localNorm(const FloatArray &src)
Norm for a locally distributed array.
virtual double evaluateAtTime(double t)
Returns the value of the function at given time.
bool prescribedEqsInitFlag
Flag indicating that prescribedEqs were initialized.
This class provides an sparse matrix interface to PETSc Matrices.
#define OOFEM_WARNING(...)
Class representing solution step.
This base class is an abstraction for all numerical methods solving sparse nonlinear system of equati...
void add(const FloatArray &src)
Adds array src to receiver.
bool checkConvergence(FloatArray &RT, FloatArray &F, FloatArray &rhs, FloatArray &ddX, FloatArray &X, double RRT, const FloatArray &internalForcesEBENorm, int nite, bool &errorOutOfRange)
Determines whether or not the solution has reached convergence.
#define nrsolver_ERROR_NORM_SMALL_NUM
void resize(int s)
Resizes receiver towards requested size.
SparseMtrxVersionType giveVersion()
Return receiver version.
FloatArray prescribedDofsValues
Array of prescribed values.
This base class is an abstraction/implementation for numerical method solving line search optimizatio...