GEOS
CoupledSolver.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
21 #ifndef GEOS_PHYSICSSOLVERS_MULTIPHYSICS_COUPLEDSOLVER_HPP_
22 #define GEOS_PHYSICSSOLVERS_MULTIPHYSICS_COUPLEDSOLVER_HPP_
23 
26 
27 #include <tuple>
28 
29 namespace geos
30 {
31 
32 template< typename ... SOLVERS >
34 {
35 
36 public:
37 
43  CoupledSolver( const string & name,
44  Group * const parent )
45  : PhysicsSolverBase( name, parent )
46  {
47  forEachArgInTuple( m_solvers, [&]( auto solver, auto idx )
48  {
49  using SolverType = TYPEOFPTR( solver );
50  string const key = SolverType::coupledSolverAttributePrefix() + "SolverName";
51  registerWrapper( key, &m_names[idx()] ).
52  setRTTypeName( rtTypes::CustomTypes::groupNameRef ).
54  setDescription( "Name of the " + SolverType::coupledSolverAttributePrefix() + " solver used by the coupled solver" );
55  } );
56 
57  this->getWrapper< string >( PhysicsSolverBase::viewKeyStruct::discretizationString() ).
58  setInputFlag( dataRepository::InputFlags::FALSE );
59 
60  addLogLevel< logInfo::Coupling >();
61  }
62 
64  CoupledSolver( CoupledSolver const & ) = delete;
65 
67  CoupledSolver( CoupledSolver && ) = default;
68 
70  CoupledSolver & operator=( CoupledSolver const & ) = delete;
71 
74 
75  template< typename T >
76  void throwSolversNotFound( std::ostringstream & errorMessage,
77  string const & solverWrapperKey,
78  string const & solverType )
79  {
80  GEOS_UNUSED_VAR( solverWrapperKey );
81  string_array availableSolvers;
82 
83  this->getParent().template forSubGroups< T >( [&]( T & group )
84  {
85 
86  availableSolvers.emplace_back( group.getName());
87 
88  } );
89 
90  if( availableSolvers.empty() )
91  {
92  errorMessage << GEOS_FMT( "No {} solver has been found.", solverType );
93  }
94  else
95  {
96  errorMessage << GEOS_FMT( "Available {} solvers are: {}. ", solverType,
97  stringutilities::join( availableSolvers, ", " ) );
98  }
99 
100  GEOS_THROW( errorMessage.str(),
101  InputError, getWrapperDataContext( solverWrapperKey ) );
102  }
106  void
108  {
109  forEachArgInTuple( m_solvers, [&]( auto & solver, auto idx )
110  {
111  using SolverPtr = TYPEOFREF( solver );
112  using SolverType = TYPEOFPTR( SolverPtr {} );
113  auto const & solverName = m_names[idx()];
114  solver = this->getParent().template getGroupPointer< SolverType >( solverName );
115  if( solver== nullptr )
116  {
117  string const solverWrapperKey = SolverType::coupledSolverAttributePrefix() + "SolverName";
118  std::ostringstream errorMessage;
119  errorMessage << GEOS_FMT( "Could not find solver named '{}'.\n", solverName );
120  throwSolversNotFound< SolverType >( errorMessage, solverWrapperKey, SolverType::coupledSolverAttributePrefix() );
121  }
122 
123 
124  GEOS_LOG_LEVEL_RANK_0( logInfo::Coupling,
125  GEOS_FMT( "{}: found {} solver named {}",
126  getName(), solver->getCatalogName(), solverName ) );
127  } );
128  }
129 
130 
136  virtual void
138  DofManager & dofManager ) const
139  { GEOS_UNUSED_VAR( domain, dofManager ); }
140 
150  virtual void
152  real64 const dt,
153  DomainPartition const & domain,
154  DofManager const & dofManager,
155  CRSMatrixView< real64, globalIndex const > const & localMatrix,
156  arrayView1d< real64 > const & localRhs )
157  { GEOS_UNUSED_VAR( time_n, dt, domain, dofManager, localMatrix, localRhs ); }
158 
166  void
167  setupDofs( DomainPartition const & domain,
168  DofManager & dofManager ) const override
169  {
170  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
171  {
172  solver->setupDofs( domain, dofManager );
173  } );
174 
175  setupCoupling( domain, dofManager );
176  }
177 
178  virtual void
179  implicitStepSetup( real64 const & time_n,
180  real64 const & dt,
181  DomainPartition & domain ) override
182  {
183  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
184  {
185  solver->implicitStepSetup( time_n, dt, domain );
186  } );
187  }
188 
189  virtual void
190  implicitStepComplete( real64 const & time_n,
191  real64 const & dt,
192  DomainPartition & domain ) override
193  {
194  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
195  {
196  solver->implicitStepComplete( time_n, dt, domain );
197  } );
198  }
199 
200  // general version of assembleSystem function, keep in mind many solvers will override it
201  virtual void
202  assembleSystem( real64 const time_n,
203  real64 const dt,
204  DomainPartition & domain,
205  DofManager const & dofManager,
206  CRSMatrixView< real64, globalIndex const > const & localMatrix,
207  arrayView1d< real64 > const & localRhs ) override
208  {
210 
211  // 1. Assemble matrix blocks of each individual solver
212  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
213  {
214  solver->assembleSystem( time_n, dt, domain, dofManager, localMatrix, localRhs );
215  } );
216 
217  // 2. Assemble coupling blocks
218  assembleCouplingTerms( time_n, dt, domain, dofManager, localMatrix, localRhs );
219  }
220 
221  virtual void
222  applySystemSolution( DofManager const & dofManager,
223  arrayView1d< real64 const > const & localSolution,
224  real64 const scalingFactor,
225  real64 const dt,
226  DomainPartition & domain ) override
227  {
228  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
229  {
230  solver->applySystemSolution( dofManager, localSolution, scalingFactor, dt, domain );
231  } );
232  }
233 
234  virtual void
235  updateState( DomainPartition & domain ) override
236  {
237  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
238  {
239  solver->updateState( domain );
240  } );
241  }
242 
243  virtual void
245  {
246  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
247  {
248  solver->resetStateToBeginningOfStep( domain );
249  } );
250  }
251 
254  real64
255  solverStep( real64 const & time_n,
256  real64 const & dt,
257  int const cycleNumber,
258  DomainPartition & domain ) override final
259  {
261 
263  {
264  return fullyCoupledSolverStep( time_n, dt, cycleNumber, domain );
265  }
267  {
268  return sequentiallyCoupledSolverStep( time_n, dt, cycleNumber, domain );
269  }
270  else
271  {
272  GEOS_ERROR( "Invalid coupling type option.", getDataContext() );
273  return 0;
274  }
275 
276  }
277 
278  real64
279  nonlinearImplicitStep( real64 const & time_n,
280  real64 const & dt,
281  integer const cycleNumber,
282  DomainPartition & domain ) override final
283  {
285 
287  {
288  return PhysicsSolverBase::nonlinearImplicitStep( time_n, dt, cycleNumber, domain );
289  }
291  {
292  return sequentiallyNonlinearImplicitStep( time_n, dt, cycleNumber, domain );
293  }
294  else
295  {
296  GEOS_ERROR( "Invalid coupling type option.", getDataContext() );
297  return 0;
298  }
299  }
300 
301  virtual void
303  DofManager & dofManager,
304  CRSMatrix< real64, globalIndex > & localMatrix,
305  ParallelVector & rhs,
306  ParallelVector & solution,
307  bool const setSparsity = true ) override
308  {
310 
312  {
313  PhysicsSolverBase::setupSystem( domain, dofManager, localMatrix, rhs, solution, setSparsity );
314  }
316  {
317  sequentiallySetupSystem( domain );
318  }
319  else
320  {
321  GEOS_ERROR( "Invalid coupling type option.", getDataContext() );
322  }
323  }
324 
325  virtual void
326  updateAndWriteConvergenceStep( real64 const & time_n, real64 const & dt,
327  integer const cycleNumber, integer const iteration ) override
328  {
329  PhysicsSolverBase::updateAndWriteConvergenceStep( time_n, dt, cycleNumber, iteration );
330  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
331  {
332  solver->updateAndWriteConvergenceStep( time_n, dt, cycleNumber, iteration );
333  } );
334  }
335 
336  virtual real64
337  calculateResidualNorm( real64 const & time_n,
338  real64 const & dt,
339  DomainPartition const & domain,
340  DofManager const & dofManager,
341  arrayView1d< real64 const > const & localRhs ) override
342  {
343  real64 norm = 0.0;
344  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
345  {
346  real64 const singlePhysicsNorm = solver->calculateResidualNorm( time_n, dt, domain, dofManager, localRhs );
347  norm += singlePhysicsNorm * singlePhysicsNorm;
348  } );
349 
350  return sqrt( norm );
351  }
352 
353  virtual void
355  real64 const dt,
356  DomainPartition & domain,
357  DofManager const & dofManager,
358  CRSMatrixView< real64, globalIndex const > const & localMatrix,
359  arrayView1d< real64 > const & localRhs ) override
360  {
361  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
362  {
363  solver->applyBoundaryConditions( time_n, dt, domain, dofManager, localMatrix, localRhs );
364  } );
365  }
366 
367  virtual bool
369  DofManager const & dofManager,
370  arrayView1d< real64 const > const & localSolution,
371  real64 const scalingFactor ) override
372  {
373  bool validSolution = true;
374  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
375  {
376  bool const validSinglePhysicsSolution = solver->checkSystemSolution( domain, dofManager, localSolution, scalingFactor );
377  if( !validSinglePhysicsSolution )
378  {
379  GEOS_LOG_RANK_0( GEOS_FMT( " {}/{}: Solution check failed. Newton loop terminated.", getName(), solver->getName()) );
380  }
381  validSolution = validSolution && validSinglePhysicsSolution;
382  } );
383  return validSolution;
384  }
385 
386  virtual real64
388  DofManager const & dofManager,
389  arrayView1d< real64 const > const & localSolution ) override
390  {
391  real64 scalingFactor = PhysicsSolverBase::scalingForSystemSolution( domain, dofManager, localSolution );
392  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
393  {
394  real64 const singlePhysicsScalingFactor = solver->scalingForSystemSolution( domain, dofManager, localSolution );
395  scalingFactor = LvArray::math::min( scalingFactor, singlePhysicsScalingFactor );
396  } );
397  return scalingFactor;
398  }
399 
400  virtual real64
401  setNextDt( real64 const & currentTime,
402  real64 const & currentDt,
403  DomainPartition & domain ) override
404  {
405  real64 nextDt = PhysicsSolverBase::setNextDt( currentTime, currentDt, domain );
406  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
407  {
408  real64 const singlePhysicsNextDt =
409  solver->setNextDt( currentTime, currentDt, domain );
410  nextDt = LvArray::math::min( singlePhysicsNextDt, nextDt );
411  } );
412  return nextDt;
413  }
414 
415  virtual void cleanup( real64 const time_n,
416  integer const cycleNumber,
417  integer const eventCounter,
418  real64 const eventProgress,
419  DomainPartition & domain ) override
420  {
421  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
422  {
423  solver->cleanup( time_n, cycleNumber, eventCounter, eventProgress, domain );
424  } );
425  PhysicsSolverBase::cleanup( time_n, cycleNumber, eventCounter, eventProgress, domain );
426  }
427 
430  virtual bool checkSequentialSolutionIncrements( DomainPartition & domain ) const override
431  {
432  bool isConverged = true;
433  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
434  {
435  isConverged &= solver->checkSequentialSolutionIncrements( domain );
436  } );
437  return isConverged;
438  }
439 
440  virtual bool updateConfiguration( DomainPartition & domain,
441  integer const configurationLoopIter ) override
442  {
443  bool result = true;
444  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
445  {
446  result &= solver->updateConfiguration( domain, configurationLoopIter );
447  } );
448  return result;
449  }
450 
451  virtual void outputConfigurationStatistics( DomainPartition const & domain ) const override
452  {
453  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
454  {
455  solver->outputConfigurationStatistics( domain );
456  } );
457  }
458 
459  virtual void resetConfigurationToBeginningOfStep( DomainPartition & domain ) override
460  {
461  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
462  {
463  solver->resetConfigurationToBeginningOfStep( domain );
464  } );
465  }
466 
467  virtual bool resetConfigurationToDefault( DomainPartition & domain ) const override
468  {
469  bool result = true;
470  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
471  {
472  result &= solver->resetConfigurationToDefault( domain );
473  } );
474  return result;
475  }
476 
477  virtual void
479  {
480  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
481  {
482  solver->getNonlinearSolverParameters() = getNonlinearSolverParameters();
483  solver->synchronizeNonlinearSolverParameters();
484  } );
485  }
486 
487 protected:
488 
498  virtual real64 fullyCoupledSolverStep( real64 const & time_n,
499  real64 const & dt,
500  int const cycleNumber,
501  DomainPartition & domain )
502  {
503  return PhysicsSolverBase::solverStep( time_n, dt, cycleNumber, domain );
504  }
505 
516  virtual real64 sequentiallyCoupledSolverStep( real64 const & time_n,
517  real64 const & dt,
518  integer const cycleNumber,
519  DomainPartition & domain )
520  {
522 
523  sequentiallySetupSystem( domain );
524 
525  implicitStepSetup( time_n, dt, domain );
526 
527  real64 const stepDt = sequentiallyNonlinearImplicitStep( time_n, dt, cycleNumber, domain );
528 
529  implicitStepComplete( time_n, stepDt, domain );
530 
531  return stepDt;
532  }
533 
534  virtual void sequentiallySetupSystem( DomainPartition & domain )
535  {
537 
538  // Only build the sparsity pattern if the mesh has changed
539  Timestamp const meshModificationTimestamp = getMeshModificationTimestamp( domain );
540  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
541  {
542  if( meshModificationTimestamp > solver->getSystemSetupTimestamp() )
543  {
544  solver->setupSystem( domain,
545  solver->getDofManager(),
546  solver->getLocalMatrix(),
547  solver->getSystemRhs(),
548  solver->getSystemSolution() );
549  solver->setSystemSetupTimestamp( meshModificationTimestamp );
550  }
551  } );
552  }
553 
565  real64 const & dt,
566  integer const cycleNumber,
567  DomainPartition & domain )
568  {
570  integer const maxNumberDtCuts = solverParams.m_maxTimeStepCuts;
571  real64 const dtCutFactor = solverParams.m_timeStepCutFactor;
572  integer & dtAttempt = solverParams.m_numTimeStepAttempts;
573 
574  bool isConverged = false;
575  // dt may be cut during the course of this step, so we are keeping a local
576  // value to track the achieved dt for this step.
577  real64 stepDt = dt;
578 
579  // outer loop attempts to apply full timestep, and managed the cutting of the timestep if
580  // required.
581  for( dtAttempt = 0; dtAttempt < maxNumberDtCuts; ++dtAttempt )
582  {
583  // TODO configuration loop
584 
585  // Reset the states of all solvers if any of them had to restart
586  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
587  {
588  solver->resetStateToBeginningOfStep( domain );
589  solver->getIterationStats().resetCurrentTimeStepStatistics(); // initialize counters for subsolvers
590  } );
591  resetStateToBeginningOfStep( domain );
592 
593  integer & iter = solverParams.m_numNewtonIterations;
594 
596  for( iter = 0; iter < solverParams.m_maxIterNewton; iter++ )
597  {
598  // Increment the solver statistics for reporting purposes
600 
601  startSequentialIteration( iter, domain );
602 
603  // Solve the subproblems nonlinearly
604  forEachArgInTuple( m_solvers, [&]( auto & solver, auto idx )
605  {
606  GEOS_LOG_LEVEL_RANK_0( logInfo::NonlinearSolver,
607  GEOS_FMT( " Iteration {:2}: {}", iter + 1, solver->getName() ) );
608  real64 solverDt = solver->nonlinearImplicitStep( time_n,
609  stepDt,
610  cycleNumber,
611  domain );
612 
613  // save fields (e.g. pressure and temperature) after inner solve
614  if( solver->getNonlinearSolverParameters().couplingType() == NonlinearSolverParameters::CouplingType::Sequential )
615  {
616  solver->saveSequentialIterationState( domain );
617  }
618 
619  mapSolutionBetweenSolvers( domain, idx() );
620 
621  if( solverDt < stepDt ) // subsolver had to cut the time step
622  {
623  iter = 0; // restart outer loop
624  stepDt = solverDt; // sync time step
626  }
627  } );
628  // Check convergence of the outer loop
629  isConverged = checkSequentialConvergence( cycleNumber,
630  iter,
631  time_n,
632  stepDt,
633  domain );
634 
635  if( isConverged )
636  {
637  // we still want to count current iteration
638  ++iter;
639  // exit outer loop
640  break;
641  }
642  else
643  {
644  finishSequentialIteration( iter, domain );
645  }
646  }
647 
648  if( isConverged )
649  {
650  // Save time step statistics for the subsolvers
651  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
652  {
653  solver->getIterationStats().iterateTimeStepStatistics();
654  } );
655  // get out of the time loop
656  break;
657  }
658  else
659  {
660  // cut timestep, go back to beginning of step and restart the Newton loop
661  stepDt *= dtCutFactor;
663  GEOS_LOG_LEVEL_RANK_0( logInfo::TimeStep, GEOS_FMT( "New dt = {}", stepDt ) );
664 
665  // notify the solver statistics counter that this is a time step cut
667  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
668  {
669  solver->getIterationStats().updateTimeStepCut();
670  } );
671  }
672  }
673 
674  if( !isConverged )
675  {
676  GEOS_LOG_RANK_0( "Convergence not achieved." );
677 
679  {
680  GEOS_LOG_RANK_0( "The accepted solution may be inaccurate." );
681  }
682  else
683  {
684  GEOS_ERROR( "Nonconverged solutions not allowed. Terminating...", getDataContext() );
685  }
686  }
687 
688  return stepDt;
689  }
690 
698  integer const solverType )
699  {
700  GEOS_UNUSED_VAR( domain, solverType );
701  }
702 
703  virtual bool checkSequentialConvergence( integer const cycleNumber,
704  integer const iter,
705  real64 const & time_n,
706  real64 const & dt,
707  DomainPartition & domain )
708  {
710  bool isConverged = true;
711 
712  if( params.m_subcyclingOption == 0 )
713  {
714  GEOS_LOG_LEVEL_RANK_0( logInfo::Convergence, "***** Single Pass solver, no subcycling *****" );
715  }
716  else
717  {
718  GEOS_LOG_LEVEL_RANK_0( logInfo::Convergence, GEOS_FMT( " Iteration {:2}: outer-loop convergence check", iter + 1 ) );
719 
721  {
722  real64 residualNorm = 0;
723 
724  // loop over all the single-physics solvers
725  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
726  {
727 
728  solver->getLocalMatrix().toViewConstSizes().zero();
729  solver->getSystemRhs().zero();
730  arrayView1d< real64 > const localRhs = solver->getSystemRhs().open();
731 
732  // for each solver, we have to recompute the residual (and Jacobian, although not necessary)
733  solver->assembleSystem( time_n,
734  dt,
735  domain,
736  solver->getDofManager(),
737  solver->getLocalMatrix().toViewConstSizes(),
738  localRhs );
739  solver->applyBoundaryConditions( time_n,
740  dt,
741  domain,
742  solver->getDofManager(),
743  solver->getLocalMatrix().toViewConstSizes(),
744  localRhs );
745  solver->getSystemRhs().close();
746 
747  // once this is done, we recompute the single-physics residual
748  real64 const singlePhysicsNorm =
749  solver->calculateResidualNorm( time_n,
750  dt,
751  domain,
752  solver->getDofManager(),
753  solver->getSystemRhs().values() );
754  residualNorm += singlePhysicsNorm * singlePhysicsNorm;
755  } );
756 
757  // finally, we perform the convergence check on the multiphysics residual
758  residualNorm = sqrt( residualNorm );
759  GEOS_LOG_LEVEL_RANK_0( logInfo::ResidualNorm,
760  GEOS_FMT( " ( R ) = ( {:4.2e} )", residualNorm ) );
761  getConvergenceStats().setResidualValue( "R", residualNorm );
762  updateAndWriteConvergenceStep( time_n, dt, cycleNumber, iter );
763 
764  isConverged = ( residualNorm < params.m_newtonTol );
765 
766  }
768  {
769  // TODO also make recursive?
770  forEachArgInTuple( m_solvers, [&]( auto & solver, auto )
771  {
772  NonlinearSolverParameters const & singlePhysicsParams = solver->getNonlinearSolverParameters();
773  if( singlePhysicsParams.m_numNewtonIterations > singlePhysicsParams.m_minIterNewton )
774  {
775  isConverged = false;
776  }
777  } );
778  }
780  {
781  isConverged = checkSequentialSolutionIncrements( domain );
782  }
783  else
784  {
785  GEOS_ERROR( "Invalid sequential convergence criterion.", getDataContext() );
786  }
787 
788  if( isConverged )
789  {
790  GEOS_LOG_LEVEL_RANK_0( logInfo::Convergence,
791  GEOS_FMT( "***** The iterative coupling has converged in {} iteration(s) *****", iter + 1 ) );
792  }
793  }
794  return isConverged;
795  }
796 
797  virtual void
799  {
800  setSubSolvers();
801 
803 
806  GEOS_THROW_IF( isSequential && usesLineSearch,
807  GEOS_FMT( "{}: line search is not supported by the coupled solver when {} is set to `{}`. Please set {} to `{}` to remove this error",
808  getNonlinearSolverParameters().getWrapperDataContext( NonlinearSolverParameters::viewKeysStruct::couplingTypeString() ),
809  NonlinearSolverParameters::viewKeysStruct::couplingTypeString(),
811  NonlinearSolverParameters::viewKeysStruct::lineSearchActionString(),
813  InputError, getNonlinearSolverParameters().getWrapperDataContext( NonlinearSolverParameters::viewKeysStruct::couplingTypeString() ) );
814 
816  {
817  validateNonlinearAcceleration();
818  }
819  }
820 
821  virtual void validateNonlinearAcceleration()
822  {
823  GEOS_THROW ( GEOS_FMT( "{}: Nonlinear acceleration {} is not supported by {} solver '{}'",
824  getWrapperDataContext( NonlinearSolverParameters::viewKeysStruct::nonlinearAccelerationTypeString() ),
826  getCatalogName(), getName()),
827  InputError );
828  }
829 
830  virtual void initializePreSubGroups() override
831  {
833 
835  if( !isSequential )
836  {
838  }
839  }
840 
841  virtual void startSequentialIteration( integer const & iter,
842  DomainPartition & domain )
843  {
844  GEOS_UNUSED_VAR( iter, domain );
845  }
846 
847  virtual void finishSequentialIteration( integer const & iter,
848  DomainPartition & domain )
849  {
850  GEOS_UNUSED_VAR( iter, domain );
851  }
852 
853 protected:
854 
856  std::tuple< SOLVERS *... > m_solvers;
857 
859  std::array< string, sizeof...( SOLVERS ) > m_names;
860 };
861 
862 } /* namespace geos */
863 
864 #endif /* GEOS_PHYSICSSOLVERS_MULTIPHYSICS_COUPLEDSOLVER_HPP_ */
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
#define GEOS_THROW(MSG,...)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:299
#define GEOS_ERROR(...)
Raise a hard error and terminate the program.
Definition: Logger.hpp:220
#define GEOS_LOG_RANK_0(msg)
Log a message on screen on rank 0.
Definition: Logger.hpp:99
#define GEOS_THROW_IF(COND, MSG,...)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:289
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
void setResidualValue(string const &key, real64 const value)
Set a residual value given a key ( column in the CSV )
virtual void assembleCouplingTerms(real64 const time_n, real64 const dt, DomainPartition const &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs)
Utility function to compute coupling terms.
CoupledSolver & operator=(CoupledSolver const &)=delete
deleted assignment operator
virtual real64 sequentiallyNonlinearImplicitStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain)
Nonlinear implicit step for sequentially coupled solver. It solves a nonlinear system of equations us...
virtual real64 fullyCoupledSolverStep(real64 const &time_n, real64 const &dt, int const cycleNumber, DomainPartition &domain)
Fully coupled solution approach solution step.
virtual bool resetConfigurationToDefault(DomainPartition &domain) const override
resets the configuration to the default value.
CoupledSolver(const string &name, Group *const parent)
main constructor for CoupledSolver Objects
virtual void outputConfigurationStatistics(DomainPartition const &domain) const override
CoupledSolver(CoupledSolver &&)=default
default move constructor
virtual void resetConfigurationToBeginningOfStep(DomainPartition &domain) override
resets the configuration to the beginning of the time-step.
virtual void initializePreSubGroups() override
Called by Initialize() prior to initializing sub-Groups.
virtual real64 sequentiallyCoupledSolverStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain)
Sequentially coupled solver step. It solves a nonlinear system of equations using a sequential approa...
CoupledSolver(CoupledSolver const &)=delete
deleted copy constructor
virtual void synchronizeNonlinearSolverParameters() override
synchronize the nonlinear solver parameters.
virtual void setupCoupling(DomainPartition const &domain, DofManager &dofManager) const
Utility function to set the coupling between degrees of freedom.
virtual bool checkSequentialSolutionIncrements(DomainPartition &domain) const override
Check if the solution increments are ok to use.
virtual bool updateConfiguration(DomainPartition &domain, integer const configurationLoopIter) override
updates the configuration (if needed) based on the state after a converged Newton loop.
virtual void postInputInitialization() override
std::array< string, sizeof...(SOLVERS) > m_names
Names of the single-physics solvers.
std::tuple< SOLVERS *... > m_solvers
Pointers of the single-physics solvers.
CoupledSolver & operator=(CoupledSolver &&)=delete
deleted move operator
void setSubSolvers()
Utility function to set the subsolvers pointers using the names provided by the user.
virtual void mapSolutionBetweenSolvers(DomainPartition &domain, integer const solverType)
Maps the solution obtained from one solver to the fields used by the other solver(s)
The DoFManager is responsible for allocating global dofs, constructing sparsity patterns,...
Definition: DofManager.hpp:45
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
void updateNonlinearIteration(integer const numLinearIterations)
Tell the solverStatistics that we have done a newton iteration.
void updateTimeStepCut()
Tell the solverStatistics that we cut the time step and we increment the cumulative counters for disc...
SequentialConvergenceCriterion sequentialConvergenceCriterion() const
Getter for the sequential convergence criterion.
integer m_allowNonConverged
Flag to allow for a non-converged nonlinear solution and continue with the problem.
real64 m_newtonTol
The tolerance for the nonlinear convergence check.
NonlinearAccelerationType m_nonlinearAccelerationType
Type of nonlinear acceleration for sequential solver.
integer m_maxIterNewton
The maximum number of nonlinear iterations that are allowed.
real64 m_timeStepCutFactor
Factor by which the time step will be cut if a timestep cut is required.
integer m_numNewtonIterations
The number of nonlinear iterations that have been exectued.
integer m_numTimeStepAttempts
Number of times that the time-step had to be cut.
integer m_maxTimeStepCuts
Max number of time step cuts.
CouplingType couplingType() const
Getter for the coupling type.
LineSearchAction m_lineSearchAction
Flag to apply a line search.
@ ResidualNorm
convergence achieved when the residual drops below a given norm
@ NumberOfNonlinearIterations
convergence achieved when the subproblems convergence is achieved in less than minNewtonIteration
@ SolutionIncrements
convergence achieved when the solution increments are small enough
integer m_subcyclingOption
Flag to specify whether subcycling is allowed or not in sequential schemes.
Base class for all physics solvers.
virtual string getCatalogName() const =0
IterationsStatistics & getIterationStats()
integer m_numTimestepsSinceLastDtCut
Number of cycles since last timestep cut.
virtual void cleanup(real64 const time_n, integer const cycleNumber, integer const eventCounter, real64 const eventProgress, DomainPartition &domain) override
Called as the code exits the main run loop.
Timestamp getMeshModificationTimestamp(DomainPartition &domain) const
getter for the timestamp of the mesh modification on the mesh levels
virtual void postInputInitialization() override
ConvergenceStatistics & getConvergenceStats()
NonlinearSolverParameters & getNonlinearSolverParameters()
accessor for the nonlinear solver parameters.
NonlinearSolverParameters m_nonlinearSolverParameters
Nonlinear solver parameters.
virtual void initializePreSubGroups()
Called by Initialize() prior to initializing sub-Groups.
Definition: Group.hpp:1544
Wrapper< TBASE > & registerWrapper(string const &name, wrapperMap::KeyIndex::index_type *const rkey=nullptr)
Create and register a Wrapper around a new object.
DataContext const & getDataContext() const
Definition: Group.hpp:1343
string const & getName() const
Get group name.
Definition: Group.hpp:1329
Group & getParent()
Access the group's parent.
Definition: Group.hpp:1362
DataContext const & getWrapperDataContext(KEY key) const
Definition: Group.hpp:1354
#define GEOS_LOG_LEVEL_RANK_0(logInfoStruct, msg)
Output messages (only on rank 0) based on current Group's log level.
virtual void implicitStepSetup(real64 const &time_n, real64 const &dt, DomainPartition &domain) override
function to perform setup for implicit timestep
virtual void cleanup(real64 const time_n, integer const cycleNumber, integer const eventCounter, real64 const eventProgress, DomainPartition &domain) override
Called as the code exits the main run loop.
virtual real64 scalingForSystemSolution(DomainPartition &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localSolution) override
Function to determine if the solution vector should be scaled back in order to maintain a known const...
virtual void updateAndWriteConvergenceStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, integer const iteration) override
Update the convergence information and write then into a CSV file.
virtual void updateState(DomainPartition &domain) override
Recompute all dependent quantities from primary variables (including constitutive models)
virtual void implicitStepComplete(real64 const &time_n, real64 const &dt, DomainPartition &domain) override
perform cleanup for implicit timestep
virtual void applyBoundaryConditions(real64 const time_n, real64 const dt, DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) override
apply boundary condition to system
virtual real64 nonlinearImplicitStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain)
Function for a nonlinear implicit integration step.
virtual real64 scalingForSystemSolution(DomainPartition &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localSolution)
Function to determine if the solution vector should be scaled back in order to maintain a known const...
virtual real64 calculateResidualNorm(real64 const &time_n, real64 const &dt, DomainPartition const &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localRhs) override
calculate the norm of the global system residual
real64 solverStep(real64 const &time_n, real64 const &dt, int const cycleNumber, DomainPartition &domain) override final
virtual real64 setNextDt(real64 const &currentTime, real64 const &currentDt, DomainPartition &domain) override
function to set the next time step size
virtual void setupSystem(DomainPartition &domain, DofManager &dofManager, CRSMatrix< real64, globalIndex > &localMatrix, ParallelVector &rhs, ParallelVector &solution, bool const setSparsity=true)
Set up the linear system (DOF indices and sparsity patterns)
virtual real64 solverStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain)
entry function to perform a solver step
virtual void setupSystem(DomainPartition &domain, DofManager &dofManager, CRSMatrix< real64, globalIndex > &localMatrix, ParallelVector &rhs, ParallelVector &solution, bool const setSparsity=true) override
Set up the linear system (DOF indices and sparsity patterns)
void setupDofs(DomainPartition const &domain, DofManager &dofManager) const override
Populate degree-of-freedom manager with fields relevant to this solver.
virtual void applySystemSolution(DofManager const &dofManager, arrayView1d< real64 const > const &localSolution, real64 const scalingFactor, real64 const dt, DomainPartition &domain) override
Function to apply the solution vector to the state.
virtual real64 setNextDt(real64 const &currentTime, real64 const &currentDt, DomainPartition &domain)
function to set the next time step size
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.
real64 nonlinearImplicitStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain) override final
Function for a nonlinear implicit integration step.
virtual void assembleSystem(real64 const time_n, real64 const dt, DomainPartition &domain, DofManager const &dofManager, CRSMatrixView< real64, globalIndex const > const &localMatrix, arrayView1d< real64 > const &localRhs) override
function to assemble the linear system matrix and rhs
virtual bool checkSystemSolution(DomainPartition &domain, DofManager const &dofManager, arrayView1d< real64 const > const &localSolution, real64 const scalingFactor) override
Function to check system solution for physical consistency and constraint violation.
virtual void resetStateToBeginningOfStep(DomainPartition &domain) override
reset state of physics back to the beginning of the step.
@ FALSE
Not read from input.
@ REQUIRED
Required in input.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
stdVector< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:361
unsigned long long int Timestamp
Timestamp type (used to perform actions such a sparsity pattern computation after mesh modifications)
Definition: DataTypes.hpp:126
LvArray::CRSMatrix< T, COL_INDEX, INDEX_TYPE, LvArray::ChaiBuffer > CRSMatrix
Alias for CRS Matrix class.
Definition: DataTypes.hpp:305
std::string string
String type.
Definition: DataTypes.hpp:90
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
LvArray::CRSMatrixView< T, COL_INDEX, INDEX_TYPE const, LvArray::ChaiBuffer > CRSMatrixView
Alias for CRS Matrix View.
Definition: DataTypes.hpp:309
int integer
Signed integer type.
Definition: DataTypes.hpp:81
LAInterface::ParallelVector ParallelVector
Alias for ParallelVector.
Provides enum <-> string conversion facilities.
Exception class used to report errors in user input.
static constexpr char const * discretizationString()