20 #ifndef GEOS_PHYSICSSOLVERS_WELLNEWTONSOLVER_HPP_
21 #define GEOS_PHYSICSSOLVERS_WELLNEWTONSOLVER_HPP_
23 #include "codingUtilities/traits.hpp"
33 #include "physicsSolvers/NonlinearSolverParameters.hpp"
35 #include "physicsSolvers/SolverStatistics.hpp"
45 class DomainPartition;
64 none, iteration, convergence, all
73 Group *
const parent );
182 template<
typename T >
187 bool const setSparsity =
true );
189 template<
typename T >
191 solveNonlinearSystem( T & well,
real64 const & time_n,
241 virtual std::unique_ptr< PreconditionerBase< LAInterface > >
256 integer const nonlinearIteration,
270 integer const nonlinearIteration,
365 static constexpr
char const * estimateWellSolutionString() {
return "estimateWellSolution"; }
465 virtual bool registerCallback(
void * func,
const std::type_info & funcType )
final override;
538 bool getNumActiveCoupledIterations()
const {
return m_activeCoupledIterations; }
574 std::unique_ptr< PreconditionerBase< LAInterface > >
m_precond;
614 integer m_activeCoupledIterations;
617 bool m_thermalEffectsEnabled;
618 integer m_enableIsoThermalEstimator;
627 void logEndOfCycleInformation(
integer const cycleNumber,
632 template<
typename T >
633 void WellNewtonSolver::setupSystem( T & well,
DomainPartition & domain,
637 bool const setSparsity )
646 regions.emplace_back( wellElementRegion.
getName() );
647 auto const key = std::make_pair( meshBodyName, meshLevel.
getName() );
648 meshTargets[key] = std::move( regions );
653 well.numDofPerWellElement(),
657 well.wellElementDofName(),
665 m_localMatrix.assimilate< parallelDevicePolicy<> >( std::move( pattern ) );
677 template<
typename T >
678 bool WellNewtonSolver::solveNonlinearSystem( T & well,
real64 const & time_n,
681 DomainPartition & domain,
683 ElementRegionManager & elemManager,
684 WellElementSubRegion & subRegion )
695 bool isNewtonConverged =
false;
697 for( newtonIter = 0; newtonIter < maxNewtonIter; ++newtonIter )
701 GEOS_FMT(
" Well: {} Est Attempt: NewtonIter: {:2}", subRegion.getName(), stepDt, newtonIter ));
704 Timer timer(
m_timers.get_inserted(
"assemble" ) );
715 arrayView1d< real64 >
const localRhs =
m_rhs.open();
718 well.assembleSystem( time_n,
728 well.applyWellBoundaryConditions( time_n,
741 array1d< real64 > localRhsCopy(
m_rhs.localSize() );
742 localRhsCopy.setValues< parallelDevicePolicy<> >(
m_rhs.values() );
751 Timer timer(
m_timers.get_inserted(
"convergence check" ) );
757 GEOS_FMT(
" ( R ) = ( {:4.2e} )", residualNorm ) );
764 if( residualNorm < newtonTol && newtonIter >= minNewtonIter )
766 isNewtonConverged =
true;
774 string const maxAllowedResidualNormString = NonlinearSolverParameters::viewKeysStruct::maxAllowedResidualNormString();
777 GEOS_FMT(
" The residual norm is above the {} of {}. Newton loop terminated.",
778 maxAllowedResidualNormString,
780 isNewtonConverged =
false;
785 Timer timer(
m_timers.get_inserted(
"linear solver total" ) );
794 Timer timer_setup(
m_timers.get_inserted(
"linear solver create" ) );
818 Timer timer(
m_timers.get_inserted(
"apply solution" ) );
824 GEOS_FMT(
" {}: Global solution scaling factor = {}",
getName(), scaleFactor ) );
826 real64 minPressure = 0.0, minDensity = 0.0, minTotalDensity = 0.0;
827 bool const solutionLogActive = isLogLevelActive< logInfo::Solution >(
getLogLevel() );
828 bool const solutionDetailsLogActive = isLogLevelActive< logInfo::SolutionDetails >(
getLogLevel() );
829 ElementsReporterBuffer rankNegPressureIds{ solutionLogActive, solutionDetailsLogActive ? 16 : 0 };
830 ElementsReporterBuffer rankNegDensityIds{ solutionLogActive, solutionDetailsLogActive ? 16 : 0 };
832 ElementsReporterBuffer rankTotalNegDensityIds{ solutionLogActive, 0 };
833 if( !well.checkWellSystemSolution( subRegion,
m_dofManager,
m_solution.values(), scaleFactor, minPressure, minDensity, minTotalDensity, rankNegPressureIds, rankNegDensityIds,
834 rankTotalNegDensityIds ) )
843 well.applyWellSystemSolution(
m_dofManager,
m_solution.values(), scaleFactor, stepDt, domain, mesh, subRegion );
847 Timer timer(
m_timers.get_inserted(
"update state" ) );
850 well.updateWellState( domain.getMeshBody( mesh.getParent().getParent().getName() ), elemManager, subRegion );
854 return isNewtonConverged;
#define GEOS_LOG_RANK_0(msg)
Log a message on screen on rank 0.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
Class containing convergence information given a time-step.
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
void addField(string const &fieldName, FieldLocation location, integer components, stdVector< FieldSupport > const ®ions={})
Add a new field and enumerate its degrees-of-freedom.
void addCoupling(string const &rowFieldName, string const &colFieldName, Connector connectivity, stdVector< FieldSupport > const ®ions={}, bool symmetric=true)
Add coupling between two fields.
void reorderByRank()
Finish populating fields and apply appropriate dof renumbering.
localIndex numLocalDofs(string const &fieldName) const
@ Node
connectivity is node (like in finite volumes MPFA)
void setDomain(DomainPartition &domain)
Assign a domain.
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
Class containing solver iterations data for a time-step.
void updateNonlinearIteration(integer const numLinearIterations)
Tell the solverStatistics that we have done a newton iteration.
Class facilitating the representation of a multi-level discretization of a MeshBody.
real64 m_newtonTol
The tolerance for the nonlinear convergence check.
integer m_maxIterNewton
The maximum number of nonlinear iterations that are allowed.
real64 m_maxAllowedResidualNorm
The maximum value of residual norm that we allow (otherwise, we cut the time step)
integer m_minIterNewton
The minimum number of nonlinear iterations that may be applied.
This class records solver statistics for each time step.
IterationsStatistics m_iterationsStats
Contain iteration data given a time step.
ConvergenceStatistics m_convergenceStats
Contain convergence data given a time step.
This class specializes the element region for the case of a well. This class is also in charge of sta...
This class describes a collection of local well elements and perforations.
Base class for all physics solvers.
static CatalogInterface::CatalogType & getCatalog()
Get the singleton catalog for WellNewtonSolver.
StatsOutputType
Type of the stat output.
ParallelMatrix & getSystemMatrix()
Getter for system matrix.
WellNewtonSolver & operator=(WellNewtonSolver const &)=delete
Deleted copy assignment operator.
virtual void setupDofs(DomainPartition const &domain, DofManager &dofManager) const
Populate degree-of-freedom manager with fields relevant to this solver.
std::function< void(CRSMatrix< real64, globalIndex >, array1d< real64 >) > m_assemblyCallback
Callback function for assembly step.
void debugOutputSystem(real64 const &time, integer const cycleNumber, integer const nonlinearIteration, ParallelMatrix const &matrix, ParallelVector const &rhs) const
Output the assembled linear system for debug purposes.
ParallelVector m_scaling
Diagonal scaling vector D (Ahat = D * A * D, bhat = D * b, x = D * xhat)
bool thermalEffectsEnabled() const
Are thermal effects enabled.
virtual ~WellNewtonSolver() override
Destructor for WellNewtonSolver.
LinearSolverParametersInput m_linearSolverParameters
Linear solver parameters.
WellNewtonSolver(WellNewtonSolver const &)=delete
Deleted copy constructor.
virtual void updateAndWriteConvergenceStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, integer const iteration)
Update the convergence information and write then into a CSV file.
virtual void synchronizeNonlinearSolverParameters()
synchronize the nonlinear solver parameters.
virtual Group * createChild(string const &childKey, string const &childName) override
creates a child group of of this WellNewtonSolver instantiation
void generateMeshTargetsFromTargetRegions(Group const &meshBodies)
Generate mesh targets from target regions.
ConvergenceStatistics & getConvergenceStats()
Timestamp m_systemSetupTimestamp
Timestamp of the last call to setup system.
WellNewtonSolver & operator=(WellNewtonSolver &&)=delete
Deleted move assignment operator.
stdMap< std::string, std::chrono::system_clock::duration > m_timers
Timers for the aggregate profiling of the solver.
void debugOutputSolution(real64 const &time, integer const cycleNumber, integer const nonlinearIteration, ParallelVector const &solution) const
Output the linear system solution for debug purposes.
IterationsStatistics const & getIterationStats() const
std::unique_ptr< LinearSolverBase< LAInterface > > m_linearSolver
Custom linear solver for the "native" solver type.
localIndex targetRegionIndex(string const ®ionName) const
Get position of a given region within solver's target region list.
ArrayOfArrays< real64 > m_solutionHistory
History of the solution vector, used for oscillation detection.
static string catalogName()
name of the node manager in the object catalog
Timestamp getSystemSetupTimestamp() const
getter for the timestamp of the system setup
WellNewtonSolver()=delete
Deleted constructor.
ParallelVector m_rhs
System right-hand side vector.
LinearSolverParameters const & getLinearSolverParameters() const
const accessor for the linear solver parameters.
DofManager const & getDofManager() const
Getter for degree-of-freedom manager.
ParallelMatrix const & getSystemMatrix() const
Getter for system rhs vector.
IterationsStatistics & getIterationStats()
NonlinearSolverParameters m_nonlinearSolverParameters
Nonlinear solver parameters.
NonlinearSolverParameters & getNonlinearSolverParameters()
accessor for the nonlinear solver parameters.
WellNewtonSolver(WellNewtonSolver &&)=default
Move constructor for WellNewtonSolver.
ConvergenceStatistics const & getConvergenceStats() const
ParallelVector & getSystemSolution()
Getter for system solution vector.
integer m_usePhysicsScaling
Flag to decide whether to apply physics-based scaling to the linear system.
StatsOutputType m_writeStatisticsCSV
Parameter for outputing statistics information.
virtual std::unique_ptr< PreconditionerBase< LAInterface > > createPreconditioner(DomainPartition &domain) const
Create a preconditioner for this solver's linear system.
void enableThermalEffects(bool enable)
Set thermal effects enable.
SolverStatistics & getSolverStatistics()
accessor for the solver statistics.
ParallelVector & getSystemRhs()
Getter for system rhs vector.
CRSMatrix< real64, globalIndex > m_localMatrix
Local system matrix and rhs.
SolverStatistics const & getSolverStatistics() const
const accessor for the solver statistics.
LinearSolverResult m_linearSolverResult
Result of the last linear solver.
virtual bool registerCallback(void *func, const std::type_info &funcType) final override
function to set the value of m_assemblyCallback
string_array const & getTargetRegionNames() const
return the list of target regions
std::unique_ptr< PreconditionerBase< LAInterface > > m_precond
Custom preconditioner for the "native" iterative solver.
SolverStatistics m_solverStatistics
Solver statistics.
virtual void postInputInitialization() override
integer m_writeLinearSystem
flag for debug output of matrix, rhs, and solution
CRSMatrix< real64, globalIndex > & getLocalMatrix()
Getter for local matrix.
virtual void solveLinearSystem(DofManager const &dofManager, ParallelMatrix &matrix, ParallelVector &rhs, ParallelVector &solution)
function to apply a linear system solver to the assembled system.
CRSMatrixView< real64 const, globalIndex const > getLocalMatrix() const
Getter for local matrix.
integer m_allowNonConvergedLinearSolverSolution
behavior in case of linear solver failure
ParallelVector m_solution
System solution vector.
NonlinearSolverParameters const & getNonlinearSolverParameters() const
const accessor for the nonlinear solver parameters.
bool detectOscillations() const
Detect oscillations in the solution.
virtual void setSparsityPattern(DomainPartition &domain, DofManager &dofManager, CRSMatrix< real64, globalIndex > &localMatrix, SparsityPattern< globalIndex > &pattern)
Set up the linear system (DOF indices and sparsity patterns)
DofManager m_dofManager
Data structure to handle degrees of freedom.
DofManager & getDofManager()
Getter for degree-of-freedom manager.
ParallelMatrix m_matrix
System matrix.
bool isoThermalEstimatorEnabled() const
Is isoThermalEstimator enabled.
ParallelVector const & getSystemRhs() const
Getter for system rhs vector.
WellNewtonSolver(string const &name, Group *const parent)
Constructor for WellNewtonSolver.
LinearSolverParameters & getLinearSolverParameters()
accessor for the linear solver parameters.
ParallelVector const & getSystemSolution() const
Getter for system solution vector.
void setSystemSetupTimestamp(Timestamp timestamp)
set the timestamp of the system setup
This class provides the base class/interface for the catalog value objects.
stdUnorderedMap< std::string, std::unique_ptr< CatalogInterface< BASETYPE, ARGS... > > > CatalogType
This is the type that will be used for the catalog. The catalog is actually instantiated in the BASET...
string const & getName() const
Get group name.
integer getLogLevel() const
Base template for ordered and unordered maps.
#define GEOS_LOG_LEVEL_RANK_0(logInfoStruct, msg)
Output messages (only on rank 0) based on current Group's log level.
stdVector< string > string_array
A 1-dimensional array of geos::string types.
unsigned long long int Timestamp
Timestamp type (used to perform actions such a sparsity pattern computation after mesh modifications)
int MPI_COMM_GEOS
Global MPI communicator used by GEOSX.
LvArray::CRSMatrix< T, COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > CRSMatrix
Alias for CRS Matrix class.
std::string string
String type.
LvArray::SparsityPattern< COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > SparsityPattern
Alias for Sparsity pattern class.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
@ Elem
location is element (like pressure in finite volumes)
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
internal::StdMapWrapper< std::map< Key, T, Compare, Allocator >, USE_STD_CONTAINER_BOUNDS_CHECKING > stdMap
LAInterface::ParallelMatrix ParallelMatrix
Alias for ParallelMatrix.
int integer
Signed integer type.
Array< T, 1 > array1d
Alias for 1D array.
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
ENUM_STRINGS(LinearSolverParameters::SolverType, "direct", "cg", "gmres", "fgmres", "bicgstab", "richardson", "preconditioner")
Declare strings associated with enumeration values.
LAInterface::ParallelVector ParallelVector
Alias for ParallelVector.
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
Set of parameters for a linear solver or preconditioner.
Results/stats of a linear solve.
integer numIterations
Number of solver iterations performed.
Structure to hold scoped key names.
static constexpr char const * nonlinearSolverParametersString()
static constexpr char const * linearSolverParametersString()
static constexpr char const * solverStatisticsString()
Structure to hold scoped key names.
static constexpr char const * targetRegionsString()
static constexpr char const * discretizationString()
static constexpr char const * enableIsoThermalEstimatorString()
string key for the enable iso thermal estimator flag
static constexpr char const * usePhysicsScalingString()
static constexpr char const * writeLinearSystemString()
static constexpr char const * activeCoupledIterationsString()
string key for the esitmate well solution flag
static constexpr char const * writeStatisticsCSVString()
static constexpr char const * minDtIncreaseIntervalString()
static constexpr char const * cflFactorString()
static constexpr char const * allowNonConvergedLinearSolverSolutionString()
static constexpr char const * initialDtString()
static constexpr char const * numTimestepsSinceLastDtCutString()