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  void 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 setupLegacy( HypreMatrix const & mat );
146 
147  void applyHypredrive( HypreVector const & rhs,
148  HypreVector & sol ) const;
149 
150  void syncExecutionAnnotations();
151 
152  void closeExecutionAnnotations();
153 
154  void syncLegacyResult() const;
155 
156  void destroyHypredrive();
157 
158  void resetHypredriveState();
159 
160  using Base::m_params;
161  using Base::m_result;
162 
163  friend class HypredriveSolverTestPeer;
164 
165  LinearSolverExecutionContext m_executionContext{};
166  std::string m_configurationSignature;
167  std::string m_structureSignature;
168  std::string m_activeTimestepScope;
169  std::string m_activeNewtonScope;
170  bool m_hasExecutionContext = false;
171  bool m_timestepScopeActive = false;
172  bool m_newtonScopeActive = false;
173  arrayView1d< HypreVector const > m_nearNullKernel;
174  bool m_reportedGeneratedYamlFailure = false;
175  size_t m_hypredriveGeneration = 0;
176  HYPREDRV_t m_hypredrive{};
177  bool m_linearSolverCreated = false;
178  mutable HypreVector m_dummyRhs;
179  mutable HypreVector m_dummySol;
180  mutable HypreVector m_residual;
181  std::unique_ptr< HypreSolver > m_legacySolver;
182 };
183 
184 }
185 
186 #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
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