From: michael Date: Sat, 1 May 2021 20:53:01 +0000 (+0200) Subject: Preparing the use of PETSc Newton type algorithm X-Git-Tag: V9_7_0~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2e48ea441d1807157f3ec8dbdf7cc59cff5fb275;p=tools%2Fsolverlab.git Preparing the use of PETSc Newton type algorithm --- diff --git a/CoreFlows/Models/inc/ProblemCoreFlows.hxx b/CoreFlows/Models/inc/ProblemCoreFlows.hxx index be45af3..2b1116a 100755 --- a/CoreFlows/Models/inc/ProblemCoreFlows.hxx +++ b/CoreFlows/Models/inc/ProblemCoreFlows.hxx @@ -54,6 +54,17 @@ enum preconditioner CHOLESKY/**< preconditioner is actually a direct solver for symmetric matrices (CHOLESKY factorisation)*/ }; +//! enumeration nonLinearSolver +/*! the nonLinearSolver can be Newton_SOLVERLAB or using PETSc, Newton_PETSC_LINESEARCH, Newton_PETSC_TRUSTREGION (see Petsc documentation) */ +enum nonLinearSolver +{ + Newton_SOLVERLAB,/**< nonLinearSolver is Newton_SOLVERLAB */ + Newton_PETSC_LINESEARCH,/**< nonLinearSolver is Newton_PETSC_LINESEARCH */ + Newton_PETSC_TRUSTREGION,/**< nonLinearSolver is Newton_PETSC_TRUSTREGION */ + Newton_PETSC_NGMRES,/**< nonLinearSolver is Newton_PETSC_NGMRES */ + Newton_PETSC_ASPIN/**< nonLinearSolver is Newton_PETSC_ASPIN */ +}; + //! enumeration saveFormat /*! the numerical results are saved using MED, VTK or CSV format */ enum saveFormat @@ -418,6 +429,16 @@ public : return _ksptype; }; + /** \fn getNonLinearSolver + * \brief renvoie _nonLinearSolver (le type du solveur de Newton utilisé) + * \details + * \param [in] void + * \param [out] string + * */ + nonLinearSolver getNonLinearSolver() { + return _nonLinearSolver; + }; + /** \fn getNumberOfVariables * \brief le nombre d'inconnues du problème * \details @@ -445,16 +466,13 @@ public : void setLinearSolver(linearSolver solverName, preconditioner pcType); /** \fn setNewtonSolver - * \brief set the Newton algorithm parameters - * \param [in] int maximum number of newton iterations - * \param [in] double precision required for the convergence of the newton scheme + * \brief sets the Newton type algorithm for solving the nonlinear algebraic system arising from the discretisation of the PDE + * \param [in] double : precision required for the convergence of the newton scheme + * \param [in] int : maximum number of newton iterations + * \param [in] nonLinearSolver : the algorithm to be used to solve the nonlinear system * \param [out] void * */ - void setNewtonSolver(double precision,int iterations=20) - { - _maxNewtonIts=iterations; - _precision_Newton=precision; - }; + void setNewtonSolver(double precision, int iterations=20, nonLinearSolver solverName=Newton_SOLVERLAB); /** \fn displayConditionNumber * \brief display the condition number of the preconditioned linear systems @@ -656,11 +674,12 @@ protected : PC _pc; PCType _pctype; string _pc_hypre; + nonLinearSolver _nonLinearSolver; int _maxPetscIts;//nombre maximum d'iteration gmres autorise au cours d'une resolution de systeme lineaire int _PetscIts;//the number of iterations of the linear solver int _maxNewtonIts;//nombre maximum d'iteration de Newton autorise au cours de la resolution d'un pas de temps int _NEWTON_its; - Mat _A;//Linear system matrix + Mat _A;//Linear system matrix Vec _b;//Linear system right hand side double _MaxIterLinearSolver;//nombre maximum d'iteration gmres obtenu au cours par les resolution de systemes lineaires au cours d'un pas de tmeps bool _conditionNumber;//computes an estimate of the condition number diff --git a/CoreFlows/Models/src/ProblemCoreFlows.cxx b/CoreFlows/Models/src/ProblemCoreFlows.cxx index 7d69103..8ad77cb 100755 --- a/CoreFlows/Models/src/ProblemCoreFlows.cxx +++ b/CoreFlows/Models/src/ProblemCoreFlows.cxx @@ -53,6 +53,7 @@ ProblemCoreFlows::ProblemCoreFlows() int _PetscIts=0;//the number of iterations of the linear solver _ksptype = (char*)&KSPGMRES; _pctype = (char*)&PCLU; + _nonLinearSolver = Newton_SOLVERLAB; _heatPowerFieldSet=false; _heatTransfertCoeff=0; _rodTemperatureFieldSet=false; @@ -184,7 +185,7 @@ void ProblemCoreFlows::setInitialField(string fileName, string fieldName, int ti void ProblemCoreFlows::setInitialFieldConstant(string fileName, const vector Vconstant) { Mesh M(fileName); - Field VV("Primitive", CELLS, M, Vconstant.size()); + Field VV("SOLVERLAB results", CELLS, M, Vconstant.size()); for (int j = 0; j < M.getNumberOfCells(); j++) { for (int i=0; i< VV.getNumberOfComponents(); i++) @@ -195,7 +196,7 @@ void ProblemCoreFlows::setInitialFieldConstant(string fileName, const vector Vconstant) { - Field VV("Primitive", CELLS, M, Vconstant.size()); + Field VV("SOLVERLAB results", CELLS, M, Vconstant.size()); for (int j = 0; j < M.getNumberOfCells(); j++) { for (int i=0; i< VV.getNumberOfComponents(); i++) @@ -255,7 +256,7 @@ void ProblemCoreFlows::setInitialFieldStepFunction(const Mesh M, const Vector VV _runLogFile->close(); throw CdmathException( "ProblemCoreFlows::setStepFunctionInitialField: Vectors VV_Left and VV_Right have different sizes"); } - Field VV("Primitive", CELLS, M, VV_Left.getNumberOfRows()); + Field VV("SOLVERLAB results", CELLS, M, VV_Left.getNumberOfRows()); double component_value; @@ -402,6 +403,14 @@ void ProblemCoreFlows::setLinearSolver(linearSolver kspType, preconditioner pcTy } } +void ProblemCoreFlows::setNewtonSolver(double precision, int iterations, nonLinearSolver solverName) +{ + _maxNewtonIts=iterations; + _precision_Newton=precision; + _nonLinearSolver=solverName; +} + + // Description: // Cette methode lance une execution du ProblemCoreFlows // Elle peut etre utilisee si le probleme n'est couple a aucun autre. @@ -533,6 +542,7 @@ void ProblemCoreFlows::setFileName(string fileName){ void ProblemCoreFlows::setFreqSave(int freqSave){ _freqSave = freqSave; } + bool ProblemCoreFlows::solveTimeStep(){ _NEWTON_its=0; bool converged=false, ok=true;