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 setup( HypreMatrix const & mat ) override;
106 
112  void apply( HypreVector const & src,
113  HypreVector & dst ) const override;
114 
120  void solve( HypreVector const & rhs,
121  HypreVector & sol ) const override;
122 
124  void clear() override;
125 
126 private:
127 
128  bool configureHypredrive( HypreMatrix const & mat );
129 
130  void createHypredrive( HypreMatrix const & mat,
131  hypre::hypredrive::InputArgsParseTarget const & parseTarget,
132  std::string const & configurationSignature,
133  std::string const & structureSignature,
134  arrayView1d< int > const & pointMarkers );
135 
136  void refreshBoundObjects( HypreMatrix const & mat,
137  arrayView1d< int > const & pointMarkers );
138 
139  void setupLegacy( HypreMatrix const & mat );
140 
141  void applyHypredrive( HypreVector const & rhs,
142  HypreVector & sol ) const;
143 
144  void syncExecutionAnnotations();
145 
146  void closeExecutionAnnotations();
147 
148  void syncLegacyResult() const;
149 
150  void destroyHypredrive();
151 
152  void resetHypredriveState();
153 
154  using Base::m_params;
155  using Base::m_result;
156 
157  friend class HypredriveSolverTestPeer;
158 
159  LinearSolverExecutionContext m_executionContext{};
160  std::string m_configurationSignature;
161  std::string m_structureSignature;
162  std::string m_activeTimestepScope;
163  std::string m_activeNewtonScope;
164  bool m_hasExecutionContext = false;
165  bool m_timestepScopeActive = false;
166  bool m_newtonScopeActive = false;
167  size_t m_hypredriveGeneration = 0;
168  HYPREDRV_t m_hypredrive{};
169  mutable HypreVector m_dummyRhs;
170  mutable HypreVector m_dummySol;
171  std::unique_ptr< HypreSolver > m_legacySolver;
172 };
173 
174 }
175 
176 #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 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