Nalu
Nalu: a generalized unstructured massively parallel low Mach flow code designed to support a variety of energy applications of interest (most notably Wind ECP) built on the Sierra Toolkit and Trilinos solver Tpetra/Epetra stack. The open source BSD, clause 3 license model has been chosen for the code base. See LICENSE for more information. http://NaluCFD.org
LinearSystem.h
Go to the documentation of this file.
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2014 Sandia Corporation. */
3 /* This software is released under the license detailed */
4 /* in the file, LICENSE, which is located in the top-level Nalu */
5 /* directory structure */
6 /*------------------------------------------------------------------------*/
7 
8 
9 #ifndef LinearSystem_h
10 #define LinearSystem_h
11 
12 #include <LinearSolverTypes.h>
13 #include <KokkosInterface.h>
14 
15 #include <Teuchos_RCP.hpp>
16 #include <Tpetra_DefaultPlatform.hpp>
17 
18 #include <Teuchos_GlobalMPISession.hpp>
19 #include <Teuchos_oblackholestream.hpp>
20 
21 #include <vector>
22 #include <string>
23 
24 namespace stk { namespace mesh { struct Entity; } }
25 
26 namespace stk{
27 namespace mesh{
28 class FieldBase;
29 class Part;
30 typedef std::vector< Part * > PartVector ;
31 }
32 }
33 namespace sierra{
34 namespace nalu{
35 
36 class EquationSystem;
37 class Realm;
38 class LinearSolver;
39 
41 {
42 public:
43 
45  Realm &realm,
46  const unsigned numDof,
47  EquationSystem *eqSys,
48  LinearSolver *linearSolver);
49 
50  virtual ~LinearSystem() {}
51 
52  static LinearSystem *create(Realm& realm, const unsigned numDof, EquationSystem *eqSys, LinearSolver *linearSolver);
53 
54  // Graph/Matrix Construction
55  virtual void buildNodeGraph(const stk::mesh::PartVector & parts)=0; // for nodal assembly (e.g., lumped mass and source)
56  virtual void buildFaceToNodeGraph(const stk::mesh::PartVector & parts)=0; // face->node assembly
57  virtual void buildEdgeToNodeGraph(const stk::mesh::PartVector & parts)=0; // edge->node assembly
58  virtual void buildElemToNodeGraph(const stk::mesh::PartVector & parts)=0; // elem->node assembly
59  virtual void buildReducedElemToNodeGraph(const stk::mesh::PartVector & parts)=0; // elem (nearest nodes only)->node assembly
60  virtual void buildFaceElemToNodeGraph(const stk::mesh::PartVector & parts)=0; // elem:face->node assembly
61  virtual void buildNonConformalNodeGraph(const stk::mesh::PartVector & parts)=0; // nonConformal->elem_node assembly
62  virtual void buildOversetNodeGraph(const stk::mesh::PartVector & parts)=0; // overset->elem_node assembly
63  virtual void finalizeLinearSystem()=0;
64 
65  // Matrix Assembly
66  virtual void zeroSystem()=0;
67 
68  virtual void sumInto(
69  unsigned numEntities,
70  const stk::mesh::Entity* entities,
73  const SharedMemView<int*> & localIds,
74  const SharedMemView<int*> & sortPermutation,
75  const char * trace_tag
76  )=0;
77 
78 
79 
80  virtual void sumInto(
81  const std::vector<stk::mesh::Entity> & sym_meshobj,
82  std::vector<int> &scratchIds,
83  std::vector<double> &scratchVals,
84  const std::vector<double> & rhs,
85  const std::vector<double> & lhs,
86  const char *trace_tag=0
87  )=0;
88 
89  virtual void applyDirichletBCs(
90  stk::mesh::FieldBase * solutionField,
91  stk::mesh::FieldBase * bcValuesField,
92  const stk::mesh::PartVector & parts,
93  const unsigned beginPos,
94  const unsigned endPos)=0;
95 
96  virtual void prepareConstraints(
97  const unsigned beginPos,
98  const unsigned endPos)=0;
99 
106  virtual void resetRows(
107  std::vector<stk::mesh::Entity> nodeList,
108  const unsigned beginPos,
109  const unsigned endPos) = 0;
110 
111  // Solve
112  virtual int solve(stk::mesh::FieldBase * linearSolutionField)=0;
113  virtual void loadComplete()=0;
114 
115  virtual void writeToFile(const char * filename, bool useOwned=true)=0;
116  virtual void writeSolutionToFile(const char * filename, bool useOwned=true)=0;
117  unsigned numDof() const { return numDof_; }
118  const int & linearSolveIterations() {return linearSolveIterations_; }
119  const double & linearResidual() {return linearResidual_; }
120  const double & nonLinearResidual() {return nonLinearResidual_; }
121  const double & scaledNonLinearResidual() {return scaledNonLinearResidual_; }
122  void setNonLinearResidual(const double nlr) { nonLinearResidual_ = nlr;}
123  const std::string name() { return eqSysName_; }
124  bool & recomputePreconditioner() {return recomputePreconditioner_;}
125  bool & reusePreconditioner() {return reusePreconditioner_;}
126  double get_timer_precond();
127  void zero_timer_precond();
128 
129 protected:
130  virtual void beginLinearSystemConstruction()=0;
131  virtual void checkError(
132  const int err_code,
133  const char * msg)=0;
134 
135  void sync_field(const stk::mesh::FieldBase *field);
136  bool debug();
137 
142 
143  const unsigned numDof_;
144  const std::string eqSysName_;
153 
154 public:
156 };
157 
158 } // namespace nalu
159 } // namespace Sierra
160 
161 #endif
std::vector< Part * > PartVector
Definition: Algorithm.h:16
Definition: ABLForcingAlgorithm.C:26
const int & linearSolveIterations()
Definition: LinearSystem.h:118
virtual ~LinearSystem()
Definition: LinearSystem.h:50
double linearResidual_
Definition: LinearSystem.h:148
int writeCounter_
Definition: LinearSystem.h:141
Definition: Algorithm.h:14
bool & recomputePreconditioner()
Definition: LinearSystem.h:124
unsigned numDof() const
Definition: LinearSystem.h:117
const std::string name()
Definition: LinearSystem.h:123
const double & nonLinearResidual()
Definition: LinearSystem.h:120
bool & reusePreconditioner()
Definition: LinearSystem.h:125
int linearSolveIterations_
Definition: LinearSystem.h:146
static constexpr double lhs[8][8]
Definition: UnitTestContinuityAdvElem.C:25
Base class representation of a PDE.
Definition: EquationSystem.h:46
bool reusePreconditioner_
Definition: LinearSystem.h:152
Realm & realm_
Definition: LinearSystem.h:138
bool provideOutput_
Definition: LinearSystem.h:155
static constexpr double rhs[8]
Definition: UnitTestContinuityAdvElem.C:18
bool recomputePreconditioner_
Definition: LinearSystem.h:151
void setNonLinearResidual(const double nlr)
Definition: LinearSystem.h:122
EquationSystem * eqSys_
Definition: LinearSystem.h:139
const double & linearResidual()
Definition: LinearSystem.h:119
const unsigned numDof_
Definition: LinearSystem.h:143
double scaledNonLinearResidual_
Definition: LinearSystem.h:150
const double & scaledNonLinearResidual()
Definition: LinearSystem.h:121
Kokkos::View< T, Kokkos::LayoutRight, DeviceShmem, Kokkos::MemoryUnmanaged > SharedMemView
Definition: KokkosInterface.h:25
double firstNonLinearResidual_
Definition: LinearSystem.h:149
LinearSolver * linearSolver_
Definition: LinearSystem.h:145
const std::string eqSysName_
Definition: LinearSystem.h:144
Definition: LinearSolver.h:55
Definition: Realm.h:82
double nonLinearResidual_
Definition: LinearSystem.h:147
Definition: LinearSystem.h:40
bool inConstruction_
Definition: LinearSystem.h:140