GEOS
hypredrive.hpp
1 #ifndef GEOS_LINEARALGEBRA_INTERFACES_HYPRE_HYPREDRIVE_HPP_
2 #define GEOS_LINEARALGEBRA_INTERFACES_HYPRE_HYPREDRIVE_HPP_
3 
6 
7 #include <HYPREDRV.h>
8 
9 #include <memory>
10 #include <string>
11 
12 namespace geos
13 {
14 
15 class HypreSolver;
16 class HypredriveSolverTestPeer;
17 
18 namespace hypre
19 {
20 
21 namespace hypredrive
22 {
23 
27 enum class InputSource
28 {
30  authoritativeFile,
32  generatedFallback
33 };
34 
39 {
41  InputSource source = InputSource::generatedFallback;
44 };
45 
46 bool shouldUse( LinearSolverParameters const & params );
47 
48 bool buildInputArgsParseTarget( LinearSolverParameters const & params,
49  InputArgsParseTarget & target );
50 
51 bool buildInputArgsParseTarget( LinearSolverParameters const & params,
52  stdVector< string > const & fieldNames,
53  arrayView1d< int const > const & numComponentsPerField,
54  InputArgsParseTarget & target );
55 
56 std::string formatInputArgsParseTargetYaml( InputArgsParseTarget const & target );
57 
58 bool wasInputArgsParseTargetLogged( InputArgsParseTarget const & target );
59 
60 void markInputArgsParseTargetLogged( InputArgsParseTarget const & target );
61 
62 void logInputArgsParseTarget( LinearSolverParameters const & params,
63  InputArgsParseTarget const & target );
64 
65 void initializeRuntime();
66 
67 void finalizeRuntime();
68 
69 }
70 
71 }
72 
79 class HypredriveSolver final : public LinearSolverBase< HypreInterface >
80 {
81 public:
82 
85 
91 
93  ~HypredriveSolver() override;
94 
99  void setExecutionContext( LinearSolverExecutionContext const & context ) override;
100 
105  void setNearNullKernel( arrayView1d< HypreVector const > const & nearNullKernel ) override;
106 
111  void setup( HypreMatrix const & mat ) override;
112 
118  void apply( HypreVector const & src,
119  HypreVector & dst ) const override;
120 
126  void solve( HypreVector const & rhs,
127  HypreVector & sol ) const override;
128 
130  void clear() override;
131 
132 private:
133 
134  bool configureHypredrive( HypreMatrix const & mat );
135 
136  bool createHypredrive( HypreMatrix const & mat,
137  hypre::hypredrive::InputArgsParseTarget const & parseTarget,
138  std::string const & configurationSignature,
139  std::string const & structureSignature,
140  arrayView1d< int > const & pointMarkers );
141 
142  void refreshBoundObjects( HypreMatrix const & mat,
143  arrayView1d< int > const & pointMarkers );
144 
145  void updateKrylovDofTags( arrayView1d< int > const & pointMarkers,
146  MPI_Comm const & comm );
147 
148  void setupLegacy( HypreMatrix const & mat );
149 
150  void applyHypredrive( HypreVector const & rhs,
151  HypreVector & sol ) const;
152 
153  void tagKrylovDofVector( HypreVector const & vec ) const;
154 
155  void syncExecutionAnnotations();
156 
157  void closeExecutionAnnotations();
158 
159  void syncLegacyResult() const;
160 
161  void destroyHypredrive();
162 
163  void resetHypredriveState();
164 
165  char const * solverNameForLogs() const;
166 
167  void reportGeneratedYamlFailure( char const * const reason );
168 
169  using Base::m_params;
170  using Base::m_result;
171 
172  friend class HypredriveSolverTestPeer;
173 
174  LinearSolverExecutionContext m_executionContext{};
175  std::string m_configurationSignature;
176  std::string m_structureSignature;
177  std::string m_activeTimestepScope;
178  std::string m_activeNewtonScope;
179  bool m_hasExecutionContext = false;
180  bool m_timestepScopeActive = false;
181  bool m_newtonScopeActive = false;
182  arrayView1d< HypreVector const > m_nearNullKernel;
183  bool m_reportedGeneratedYamlFailure = false;
184  size_t m_hypredriveGeneration = 0;
185  HYPREDRV_t m_hypredrive{};
186  bool m_linearSolverCreated = false;
187  mutable HypreVector m_dummyRhs;
188  mutable HypreVector m_dummySol;
189  mutable HypreVector m_residual;
190  array1d< HYPRE_Int > m_krylovDofTags;
191  HYPRE_Int m_numKrylovDofTags = 1;
192  std::unique_ptr< HypreSolver > m_legacySolver;
193 };
194 
195 }
196 
197 #endif
Wrapper class for hypre's ParCSRMatrix.
Definition: HypreMatrix.hpp:56
Wrapper class for hypre's ParVector.
Definition: HypreVector.hpp:54
Linear solver adapter that routes GEOS Hypre systems through hypredrive.
Definition: hypredrive.hpp:80
void clear() override
Reset solver-owned state and destroy any active hypredrive object.
void solve(HypreVector const &rhs, HypreVector &sol) const override
Solve the linear system with hypredrive.
void setNearNullKernel(arrayView1d< HypreVector const > const &nearNullKernel) override
Set near-null-space modes to pass to HypreDrive during setup.
void setup(HypreMatrix const &mat) override
Build or refresh the solver/preconditioner for a matrix.
HypredriveSolver(LinearSolverParameters parameters)
Construct a hypredrive-backed linear solver.
void setExecutionContext(LinearSolverExecutionContext const &context) override
Update the execution metadata associated with subsequent solves.
void apply(HypreVector const &src, HypreVector &dst) const override
Apply the configured operator as a preconditioner action.
~HypredriveSolver() override
Destroys the managed hypredrive object and releases any fallback solver state.
Simple interface for linear solvers that allows to extract solution results.
LinearSolverResult m_result
Result of most recent solve (status, timings)
LinearSolverParameters m_params
Parameters for the solver.
LinearSolverParameters const & parameters() const
virtual MPI_Comm comm() const override
Get the MPI communicator the matrix was created with.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:179
std::string string
String type.
Definition: DataTypes.hpp:90
internal::StdVectorWrapper< T, Allocator, USE_STD_CONTAINER_BOUNDS_CHECKING > stdVector
Execution metadata associated with a linear-solver invocation.
Set of parameters for a linear solver or preconditioner.
Parsed-input payload passed to HYPREDRV_InputArgsParse.
Definition: hypredrive.hpp:39
InputSource source
Origin of the payload stored in argument.
Definition: hypredrive.hpp:41
std::string argument
File path or YAML string consumed by HYPREDRV_InputArgsParse.
Definition: hypredrive.hpp:43