|
| 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 | +/** |
| 17 | + * @file DLPhysicsSolverBase.hpp |
| 18 | + */ |
| 19 | + |
| 20 | +#ifndef GEOS_PHYSICSSOLVERS_DLPHYSICSSOLVERBASE_HPP_ |
| 21 | +#define GEOS_PHYSICSSOLVERS_DLPHYSICSSOLVERBASE_HPP_ |
| 22 | + |
| 23 | +#include "codingUtilities/traits.hpp" |
| 24 | +#include "common/DataTypes.hpp" |
| 25 | +#include "common/format/LogPart.hpp" |
| 26 | +#include "dataRepository/ExecutableGroup.hpp" |
| 27 | +#include "dataRepository/RestartFlags.hpp" |
| 28 | +#include "linearAlgebra/interfaces/InterfaceTypes.hpp" |
| 29 | +#include "linearAlgebra/utilities/LinearSolverResult.hpp" |
| 30 | +#include "linearAlgebra/DofManager.hpp" |
| 31 | +#include "mesh/MeshBody.hpp" |
| 32 | +#include "physicsSolvers/NonlinearSolverParameters.hpp" |
| 33 | +#include "physicsSolvers/LinearSolverParameters.hpp" |
| 34 | +#include "physicsSolvers/SolverStatistics.hpp" |
| 35 | +#include "physicsSolvers/PhysicsSolverBase.hpp" |
| 36 | +#include "DLSharedMemoryManager.hpp" |
| 37 | +#include "physicsSolvers/solidMechanics/SolidMechanicsFields.hpp" |
| 38 | +#include "physicsSolvers/fluidFlow/FlowSolverBaseFields.hpp" |
| 39 | + |
| 40 | +#include <limits> |
| 41 | + |
| 42 | +namespace geos |
| 43 | +{ |
| 44 | + |
| 45 | + class DomainPartition; |
| 46 | + |
| 47 | + /** |
| 48 | + * @class DLPhysicsSolverBase |
| 49 | + * @brief Base class for all DL physics solvers |
| 50 | + * |
| 51 | + * This class provides the base interface for all DL physics solvers. It provides the basic |
| 52 | + * functionality for setting up and solving a system using DL, as well as the interface for |
| 53 | + * performing a timestep. |
| 54 | + */ |
| 55 | + class DLPhysicsSolverBase : public PhysicsSolverBase |
| 56 | + { |
| 57 | + public: |
| 58 | + /** |
| 59 | + * @brief Constructor for DLPhysicsSolverBase |
| 60 | + * @param name the name of this instantiation of DLPhysicsSolverBase |
| 61 | + * @param parent the parent group of this instantiation of DLPhysicsSolverBase |
| 62 | + */ |
| 63 | + explicit DLPhysicsSolverBase(string const &name, |
| 64 | + Group *const parent); |
| 65 | + |
| 66 | + /** |
| 67 | + * @brief Move constructor for DLPhysicsSolverBase |
| 68 | + */ |
| 69 | + DLPhysicsSolverBase(DLPhysicsSolverBase &&) = default; |
| 70 | + |
| 71 | + /** |
| 72 | + * @brief Destructor for DLPhysicsSolverBase |
| 73 | + */ |
| 74 | + virtual ~DLPhysicsSolverBase() override; |
| 75 | + |
| 76 | + /** |
| 77 | + * @brief Deleted constructor |
| 78 | + */ |
| 79 | + DLPhysicsSolverBase() = delete; |
| 80 | + |
| 81 | + /** |
| 82 | + * @brief Deleted copy constructor |
| 83 | + */ |
| 84 | + DLPhysicsSolverBase(DLPhysicsSolverBase const &) = delete; |
| 85 | + |
| 86 | + /** |
| 87 | + * @brief Deleted copy assignment operator |
| 88 | + */ |
| 89 | + DLPhysicsSolverBase &operator=(DLPhysicsSolverBase const &) = delete; |
| 90 | + |
| 91 | + /** |
| 92 | + * @brief Deleted move assignment operator |
| 93 | + */ |
| 94 | + DLPhysicsSolverBase &operator=(DLPhysicsSolverBase &&) = delete; |
| 95 | + |
| 96 | + /** |
| 97 | + * @brief Function for a nonlinear implicit integration step |
| 98 | + * @param time_n time at the beginning of the step |
| 99 | + * @param dt the perscribed timestep |
| 100 | + * @param cycleNumber the current cycle number |
| 101 | + * @param domain the domain object |
| 102 | + * @return return the timestep that was achieved during the step. |
| 103 | + * |
| 104 | + * This function implements a nonlinear newton method for implicit DL problems. It requires that the |
| 105 | + * other functions in the solver interface are implemented in the derived physics solver. |
| 106 | + */ |
| 107 | + virtual real64 nonlinearImplicitStep(real64 const &time_n, |
| 108 | + real64 const &dt, |
| 109 | + integer const cycleNumber, |
| 110 | + DomainPartition &domain) override; |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + virtual void |
| 115 | + setupSystem( DomainPartition & domain, |
| 116 | + DofManager & dofManager, |
| 117 | + CRSMatrix< real64, globalIndex > & localMatrix, |
| 118 | + ParallelVector & rhs, |
| 119 | + ParallelVector & solution, |
| 120 | + bool const setSparsity = true ) override; |
| 121 | + |
| 122 | + |
| 123 | + protected: |
| 124 | + /** |
| 125 | + * @brief Solve a nonlinear system using a DL approach |
| 126 | + * @param time_n the time at the beginning of the step |
| 127 | + * @param dt the desired timestep |
| 128 | + * @param cycleNumber the current cycle number |
| 129 | + * @param domain the domain partition |
| 130 | + * @return true if the nonlinear system was solved, false otherwise |
| 131 | + */ |
| 132 | + virtual bool solveNonlinearSystemUsingDL(real64 const &time_n, |
| 133 | + real64 const &dt, |
| 134 | + integer const cycleNumber, |
| 135 | + DomainPartition &domain); |
| 136 | + |
| 137 | + virtual void initializePostInitialConditionsPostSubGroups() override; |
| 138 | + |
| 139 | + |
| 140 | + /** |
| 141 | + * @brief Populate m_dofXCoords/m_dofYCoords/m_dofZCoords for different dofs. |
| 142 | + * |
| 143 | + * @param dofManager DofManager holding DOF layout and rank offset |
| 144 | + * @param domain DomainPartition used to iterate mesh levels / element subregions |
| 145 | + * @param elemDofFieldKey The field key under which element DOF numbers are stored (e.g. "singlePhaseVariables") |
| 146 | + */ |
| 147 | + virtual void populateDofCoords( DofManager const & dofManager, |
| 148 | + DomainPartition & domain, |
| 149 | + string const & elemDofFieldKey ); |
| 150 | + |
| 151 | + /** |
| 152 | + * @brief Populate m_strainTrace for different dofs. |
| 153 | + * |
| 154 | + * @param dofManager DofManager holding DOF layout and rank offset |
| 155 | + * @param domain DomainPartition used to iterate mesh levels / element subregions |
| 156 | + * @param elemDofFieldKey The field key under which element DOF numbers are stored (e.g. "singlePhaseVariables") |
| 157 | + */ |
| 158 | + virtual void populateDofStrainTrace( DofManager const & dofManager, |
| 159 | + DomainPartition & domain, |
| 160 | + string const & elemDofFieldKey ); |
| 161 | + |
| 162 | + /** |
| 163 | + * @brief Populate m_prevSolution for different dofs. |
| 164 | + * |
| 165 | + * @param dofManager DofManager holding DOF layout and rank offset |
| 166 | + * @param domain DomainPartition used to iterate mesh levels / element subregions |
| 167 | + * @param elemDofFieldKey The field key under which element DOF numbers are stored (e.g. "singlePhaseVariables") |
| 168 | + */ |
| 169 | + virtual void populateDofPrevSolution( DofManager const & dofManager, |
| 170 | + DomainPartition & domain, |
| 171 | + string const & elemDofFieldKey ); |
| 172 | + |
| 173 | + |
| 174 | + /** |
| 175 | + * @brief Initialize shared memories needed for DL simulations |
| 176 | + * @return void |
| 177 | + */ |
| 178 | + virtual void initializeSharedMemories(); |
| 179 | + |
| 180 | + /** |
| 181 | + * @brief Share the DL model inputs through shared memory |
| 182 | + * @return void |
| 183 | + */ |
| 184 | + virtual void shareDLModelInputs(real64 const &time_n, |
| 185 | + real64 const &dt, |
| 186 | + integer const cycleNumber, |
| 187 | + DomainPartition &domain); |
| 188 | + |
| 189 | + /** |
| 190 | + * @brief Read the DL model outputs through shared memory |
| 191 | + * @return void |
| 192 | + */ |
| 193 | + virtual void readDLModelOutputs(real64 const &time_n, |
| 194 | + real64 const &dt, |
| 195 | + integer const cycleNumber, |
| 196 | + DomainPartition &domain); |
| 197 | + |
| 198 | + DLSharedMemoryManager m_sharedMemoryManager; |
| 199 | + |
| 200 | + // Data vectors for DL solver |
| 201 | + ParallelVector m_dofXCoords; |
| 202 | + ParallelVector m_dofYCoords; |
| 203 | + ParallelVector m_dofZCoords; |
| 204 | + ParallelVector m_prevSolution; |
| 205 | + ParallelVector m_strainTrace; //TODO: Consider Removing/Moving to a more suitable class. Like IFENNPoroMechanics |
| 206 | + |
| 207 | + |
| 208 | + private: |
| 209 | + }; |
| 210 | + |
| 211 | +} // namespace geos |
| 212 | + |
| 213 | +#endif /* GEOS_PHYSICSSOLVERS_DLPHYSICSSOLVERBASE_HPP_ */ |
0 commit comments