MFEM  v3.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
datacollection.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_DATACOLLECTION
13 #define MFEM_DATACOLLECTION
14 
15 #include "../config/config.hpp"
16 #include "gridfunc.hpp"
17 #include <string>
18 #include <map>
19 
20 namespace mfem
21 {
22 
27 {
28 protected:
30  std::string name;
31 
33  std::map<std::string, GridFunction*> field_map;
36 
39  int cycle;
41  double time;
42 
44  bool serial;
46  int myid;
48  int num_procs;
49 
51  int precision;
54 
56  static const int precision_default = 6;
58  static const int pad_digits_default = 6;
59 
61  bool own_data;
62 
64  int error;
65 
67  DataCollection(const char *collection_name);
69  void DeleteData();
71  void DeleteAll();
72 
74  void SaveOneField(const std::map<std::string,GridFunction*>::iterator &it);
75 
76 public:
78  DataCollection(const char *collection_name, Mesh *_mesh);
79 
81  virtual void RegisterField(const char *field_name, GridFunction *gf);
84  GridFunction *GetField(const char *field_name);
86  bool HasField(const char *name) { return field_map.count(name) == 1; }
87 
89  Mesh *GetMesh() { return mesh; }
91  virtual void SetMesh(Mesh *new_mesh);
92 
94  void SetCycle(int c) { cycle = c; }
96  void SetTime(double t) { time = t; }
97 
99  int GetCycle() { return cycle; }
101  double GetTime() { return time; }
103  const char* GetCollectionName() { return name.c_str(); }
105  void SetOwnData(bool o) { own_data = o; }
106 
108  void SetPrecision(int prec) { precision = prec; }
110  void SetPadDigits(int digits) { pad_digits = digits; }
111 
115  virtual void Save();
117  virtual void SaveMesh();
119  virtual void SaveField(const char *field_name);
120 
122  virtual ~DataCollection();
123 
125  enum { NO_ERROR = 0, READ_ERROR = 1, WRITE_ERROR = 2 };
126 
128  int Error() const { return error; }
130  void ResetError(int err = NO_ERROR) { error = err; }
131 };
132 
133 
136 {
137 public:
138  std::string association;
141  VisItFieldInfo(std::string _association, int _num_components)
142  { association = _association; num_components = _num_components; }
143 };
144 
147 {
148 protected:
149  // Additional data needed in the VisIt root file, which describes the mesh
150  // and all the fields in the collection
153  std::map<std::string, VisItFieldInfo> field_info_map;
154 
156  std::string GetVisItRootString();
158  void ParseVisItRootString(std::string json);
159 
160  // Helper functions for Load()
161  void LoadVisItRootFile(std::string root_name);
162  void LoadMesh();
163  void LoadFields();
164 
165 public:
168  VisItDataCollection(const char *collection_name);
170  VisItDataCollection(const char *collection_name, Mesh *_mesh);
171 
173  virtual void SetMesh(Mesh *new_mesh);
174 
176  virtual void RegisterField(const char *field_name, GridFunction *gf);
177 
179  void SetMaxLevelsOfDetail(int max_levels_of_detail);
180 
183  void DeleteAll();
184 
186  virtual void Save();
187 
189  void SaveRootFile();
190 
192  void Load(int _cycle = 0);
193 
195  virtual ~VisItDataCollection() {}
196 };
197 
198 }
199 
200 #endif
virtual void SaveMesh()
Save the mesh, creating the collection directory.
void SetPrecision(int prec)
Set the precision (number of digits) used for the text output of doubles.
std::map< std::string, GridFunction * > field_map
The fields and their names (used when saving)
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:27
bool HasField(const char *name)
Check if a grid function is part of the collection.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
int error
Error state.
virtual void RegisterField(const char *field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
void DeleteAll()
Delete data owned by the DataCollection including field information.
Helper class for VisIt visualization data.
double GetTime()
Get physical time (for time-dependent simulations)
virtual void Save()
Save the collection and a VisIt root file.
int Error() const
Get the current error state.
bool own_data
Should the collection delete its mesh and fields.
double time
Physical time (for time-dependent simulations)
void ResetError(int err=NO_ERROR)
Reset the error state.
Mesh * mesh
The (common) mesh for the collected fields.
void SetPadDigits(int digits)
Set the number of digits used for the cycle and MPI rank in filenames.
VisItFieldInfo(std::string _association, int _num_components)
bool serial
Serial or parallel run? If false, append rank (myid) to file names.
void ParseVisItRootString(std::string json)
Read in a VisIt root file in JSON format.
Data collection with VisIt I/O routines.
GridFunction * GetField(const char *field_name)
void DeleteData()
Delete data owned by the DataCollection keeping field information.
static const int pad_digits_default
Default value for pad_digits.
virtual void SaveField(const char *field_name)
Save one field, assuming the collection directory already exists.
void Load(int _cycle=0)
Load the collection based on its VisIt data (described in its root file)
void SetTime(double t)
Set physical time (for time-dependent simulations)
void SetOwnData(bool o)
Set the ownership of collection data.
virtual ~VisItDataCollection()
We will delete the mesh and fields if we own them.
std::map< std::string, VisItFieldInfo > field_info_map
void LoadVisItRootFile(std::string root_name)
int precision
Precision (number of digits) used for the text output of doubles.
int myid
MPI rank (in parallel)
const char * GetCollectionName()
Get the name of the collection.
static const int precision_default
Default value for precision.
void SetMaxLevelsOfDetail(int max_levels_of_detail)
Set VisIt parameter: maximum levels of detail for the MultiresControl.
virtual ~DataCollection()
Delete the mesh and fields if owned by the collection.
int GetCycle()
Get time cycle (for time-dependent simulations)
void SaveRootFile()
Save a VisIt root file for the collection.
VisItDataCollection(const char *collection_name)
virtual void RegisterField(const char *field_name, GridFunction *gf)
Add a grid function to the collection.
DataCollection(const char *collection_name)
Create an empty collection with the given name.
Mesh * GetMesh()
Get a pointer to the mesh in the collection.
int pad_digits
Number of digits used for the cycle and MPI rank in filenames.
virtual void SetMesh(Mesh *new_mesh)
Set/change the mesh associated with the collection.
std::string name
Name of the collection, used as a directory name when saving.
virtual void SetMesh(Mesh *new_mesh)
Set/change the mesh associated with the collection.
void SaveOneField(const std::map< std::string, GridFunction * >::iterator &it)
Save one field to disk, assuming the collection directory exists.
int num_procs
Number of MPI ranks (in parallel)
std::string GetVisItRootString()
Prepare the VisIt root file in JSON format for the current collection.