GEOS
ExplicitQDRateAndState.hpp
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 
16 #ifndef GEOS_PHYSICSSOLVERS_INDUCEDSEISMICITY_QUASIDYNAMICEQRK32_HPP
17 #define GEOS_PHYSICSSOLVERS_INDUCEDSEISMICITY_QUASIDYNAMICEQRK32_HPP
18 
19 #include "QDRateAndStateBase.hpp"
20 #include "kernels/ExplicitRateAndStateKernels.hpp"
21 
22 namespace geos
23 {
24 
26 {
27 public:
30 
32  ExplicitQDRateAndState( const string & name,
33  Group * const parent );
34 
36  virtual ~ExplicitQDRateAndState() override;
37 
38  static string derivedSolverPrefix() { return "Explicit";};
39 
41  virtual void registerDataOnMesh( Group & meshBodies ) override;
42 
44  {
46  constexpr static char const * timeStepTol() { return "timeStepTol"; }
47  };
48 
49  virtual real64 solverStep( real64 const & time_n,
50  real64 const & dt,
51  integer const cycleNumber,
52  DomainPartition & domain ) override final;
53 
54 
55  virtual real64 setNextDt( real64 const & currentDt,
56  DomainPartition & domain ) override final;
57 
62  void evalTimestep( DomainPartition & domain );
63 
69  void stepRateStateODEInitialSubstage( real64 const dt, DomainPartition & domain ) const;
70 
77  void stepRateStateODESubstage( integer const stageIndex,
78  real64 const dt,
79  DomainPartition & domain ) const;
80 
86  void stepRateStateODEAndComputeError( real64 const dt, DomainPartition & domain ) const;
87 
92  void updateSlipVelocity( real64 const & time_n,
93  real64 const & dt,
94  DomainPartition & domain ) const;
95 
96 protected:
97 
99  // TODO: The specific type should not be hardcoded!
100  // Should be possible to change RK-method based on the table.
102 
103  bool m_successfulStep; // Flag indicating if the adative time step was accepted
104 
105  real64 m_stepUpdateFactor; // Factor to update timestep with
106 
112  {
113 public:
114 
116  PIDController( std::array< const real64, 3 > const & cparams,
117  const real64 atol,
118  const real64 rtol,
119  const real64 safety ):
120  controlParameters{ cparams },
121  absTol( atol ),
122  relTol( rtol ),
123  acceptSafety( safety ),
124  errors{ {0.0, 0.0, 0.0} }
125  {}
126 
128  PIDController( PIDController const & ) = default;
129 
131  PIDController( PIDController && ) = default;
132 
134  PIDController() = delete;
135 
137  PIDController & operator=( PIDController const & ) = delete;
138 
141 
143  const std::array< const real64, 3 > controlParameters; // Controller parameters
144 
145  real64 const absTol; // absolut tolerence
146 
147  real64 const relTol; // relative tolerence
148 
149  real64 const acceptSafety; // Acceptance safety
150 
151  std::array< real64, 3 > errors; // Errors for current and two previous updates
152  // stored as [n+1, n, n-1]
153 
154  real64 computeUpdateFactor( integer const algHighOrder, integer const algLowOrder )
155  {
156  // PID error controller + limiter
157  real64 const k = LvArray::math::min( algHighOrder, algLowOrder ) + 1.0;
158  real64 const eps0 = 1.0/(errors[0] + std::numeric_limits< real64 >::epsilon()); // n + 1
159  real64 const eps1 = 1.0/(errors[1] + std::numeric_limits< real64 >::epsilon()); // n
160  real64 const eps2 = 1.0/(errors[2] + std::numeric_limits< real64 >::epsilon()); // n-1
161  // Compute update factor eps0^(beta0/k)*eps1^(beta1/k)*eps2^(beta2/k) where
162  // beta0 - beta2 are the control parameters. Also apply limiter to smoothen changes.
163  // Limiter is 1.0 + atan(x - 1.0). Here use atan(x) = atan2(x, 1.0).
164  return 1.0 + LvArray::math::atan2( pow( eps0, controlParameters[0] / k ) *
165  pow( eps1, controlParameters[1] / k ) *
166  pow( eps2, controlParameters[2] / k ) - 1.0, 1.0 );
167  }
168  };
169 
170  PIDController m_controller;
171 
172 };
173 
174 } /* namespace geos */
175 
176 #endif /* GEOS_PHYSICSSOLVERS_INDUCEDSEISMICITY_QUASIDYNAMICEQRK32_HPP */
#define GEOS_HOST_DEVICE
Marks a host-device function.
Definition: GeosxMacros.hpp:49
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
Proportional-integral-derivative controller used for updating time step based error estimate in the c...
PIDController & operator=(PIDController const &)=delete
Deleted copy assignment operator.
PIDController(PIDController const &)=default
Default copy constructor.
PIDController(PIDController &&)=default
Default move constructor.
PIDController()=delete
Deleted default constructor.
PIDController & operator=(PIDController &&)=delete
Deleted move assignment operator.
const std::array< const real64, 3 > controlParameters
Parameters for the PID error controller.
void stepRateStateODEAndComputeError(real64 const dt, DomainPartition &domain) const
Updates slip and state to t + dt and approximates the error.
virtual void registerDataOnMesh(Group &meshBodies) override
This method ties properties with their supporting mesh.
void evalTimestep(DomainPartition &domain)
Evaluates whether an adaptive time step was successful.
virtual real64 solverStep(real64 const &time_n, real64 const &dt, integer const cycleNumber, DomainPartition &domain) override final
entry function to perform a solver step
void updateSlipVelocity(real64 const &time_n, real64 const &dt, DomainPartition &domain) const
Updates rate-and-state slip velocity.
rateAndStateKernels::BogackiShampine32Table m_butcherTable
Runge-Kutta Butcher table (specifies the embedded RK method)
void stepRateStateODESubstage(integer const stageIndex, real64 const dt, DomainPartition &domain) const
Computes stage rates at the Runge-Kutta substage specified by stageIndex and updates slip and state.
virtual real64 setNextDt(real64 const &currentDt, DomainPartition &domain) override final
function to set the next time step size
ExplicitQDRateAndState(const string &name, Group *const parent)
The constructor needs a user-defined "name" and a parent Group (to place this instance in the tree st...
void stepRateStateODEInitialSubstage(real64 const dt, DomainPartition &domain) const
Computes stage rates for the initial Runge-Kutta substage and updates slip and state.
ExplicitQDRateAndState()=delete
The default nullary constructor is disabled to avoid compiler auto-generation:
virtual ~ExplicitQDRateAndState() override
Destructor.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
constexpr static char const * timeStepTol()
target slip increment
Butcher table for the BogackiShampine 3(2) method.