libROM  v1.0
Data-driven physical simulation library
SampleMesh.hpp
1 
11 #ifndef SAMPLEMESH_H
12 #define SAMPLEMESH_H
13 
14 #include <set>
15 #include <string>
16 
17 #include "mfem.hpp"
18 #include "mpi.h"
19 
20 #include "linalg/Matrix.h"
21 
22 using namespace mfem;
23 using std::vector;
24 using std::set;
25 using std::map;
26 using std::string;
27 
28 namespace CAROM {
29 
30 void SampleVisualization(ParMesh *pmesh, set<int> const& elems,
31  set<int> const& intElems, set<int> const& faces,
32  set<int> const& edges, set<int> const& vertices,
33  string const& filename,
34  mfem::Vector *elemCount=nullptr,
35  double elementScaling=1.0);
36 
45 {
46 public:
60  SampleMeshManager(vector<ParFiniteElementSpace*> & fespace_,
61  string visFileName="", double visScale=1.0);
62 
74  void RegisterSampledVariable(const string variable, const int space,
75  vector<int> const& sample_dofs_v, vector<int> const& num_sample_dofs_per_proc);
76 
80  void ConstructSampleMesh();
81 
93  void GatherDistributedMatrixRows(const string variable, CAROM::Matrix const& B,
94  const int rdim, CAROM::Matrix& Bsp) const;
95 
103  ParFiniteElementSpace* GetSampleFESpace(const int space) const {
104  return spfespace[space];
105  }
106 
112  ParMesh* GetSampleMesh() const {
113  MFEM_VERIFY(finalized, "Sample mesh is not constructed");
114  return sample_pmesh;
115  }
116 
124  int GetNumVarSamples(const string variable) const;
125 
135  void GetSampledValues(const string variable, mfem::Vector const& v,
136  CAROM::Vector & s) const;
137 
138 
145  set<int>* GetSampleElements() {
146  return &elems;
147  }
148 
157  void WriteVariableSampleMap(const string variable, string file_name) const;
158 
163  {
164  for (int i=0; i<nspaces; ++i)
165  delete spfespace[i];
166 
167  delete sample_pmesh;
168  }
169 
170 private:
171  void CreateSampleMesh();
172 
173  int GetVariableIndex(const string variable) const;
174 
175  void SetSampleMaps();
176  void FinishSampleMaps();
177 
178  bool finalized;
179 
180  const int nspaces;
181  int nvar = 0;
182 
183  map<string, int> vmap; // Variable name to index map
184 
185  int myid, nprocs;
186  MPI_Comm root_comm;
187 
188  vector<ParFiniteElementSpace*> fespace;
189  vector<ParFiniteElementSpace*> spfespace;
190 
191  ParMesh *pmesh = nullptr;
192  ParMesh *sample_pmesh = nullptr;
193 
194  vector<vector<set<int>>> sample_dofs_proc;
195 
196  vector<int> sample_dofs; // block true DOFs for all spaces, for all processes.
197 
198  vector<int> num_sample_dofs_per_proc_merged;
199 
200  vector<int> varSpace;
201  vector<vector<int>> sample_dofs_var;
202  vector<vector<int>> num_sample_dofs_per_proc_var;
203  vector<vector<int>> s2sp_var;
204  vector<int> s2sp, st2sp;
205  vector<int>
206  sprows; // Local true DOFs on the original full mesh, restricted to the sample mesh stencil.
207  vector<int> all_sprows; // sprows gathered over all processes
208 
209  vector<int> spaceTOS, spaceOS, spaceOSSP;
210  vector<vector<int>> spaceOSall;
211 
212  set<int> elems;
213 
214  string filename; // For visualization output
215 
216  double elemVisScale; // Scaling for sample element visualization
217 };
218 
227 public:
228  SampleDOFSelector() { }
229 
238  void ReadMapFromFile(const string variable, string file_name);
239 
250  void GetSampledValues(const string variable, mfem::Vector const& v,
251  CAROM::Vector & s) const;
252 
257  { }
258 
259 private:
260  int nvar = 0;
261  map<string, int> vmap; // Variable name to index map
262  vector<vector<int>> s2sp_var;
263 
264  int GetVariableIndex(const string variable) const;
265 };
266 
267 } // namespace CAROM
268 
269 #endif // SAMPLEMESH_H
~SampleDOFSelector()
Destructor.
Definition: SampleMesh.hpp:256
ParMesh * GetSampleMesh() const
Returns the sample mesh.
Definition: SampleMesh.hpp:112
~SampleMeshManager()
Destructor.
Definition: SampleMesh.hpp:162
ParFiniteElementSpace * GetSampleFESpace(const int space) const
Returns a sample mesh space.
Definition: SampleMesh.hpp:103
set< int > * GetSampleElements()
Returns a set of indices of local FOM mesh elements corresponding to sample elements.
Definition: SampleMesh.hpp:145