MFEM  v3.2
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::string prefix_path;
34 
36  std::map<std::string, GridFunction*> field_map;
39 
42  int cycle;
44  double time;
45 
47  bool serial;
49  int myid;
51  int num_procs;
52 
54  int precision;
57 
59  static const int precision_default = 6;
61  static const int pad_digits_default = 6;
62 
64  bool own_data;
65 
67  int error;
68 
70  DataCollection(const char *collection_name);
72  void DeleteData();
74  void DeleteAll();
75 
77  void SaveOneField(const std::map<std::string,GridFunction*>::iterator &it);
78 
79 public:
81  DataCollection(const char *collection_name, Mesh *_mesh);
82 
84  virtual void RegisterField(const char *field_name, GridFunction *gf);
87  GridFunction *GetField(const char *field_name);
89  bool HasField(const char *name) { return field_map.count(name) == 1; }
90 
92  Mesh *GetMesh() { return mesh; }
94  virtual void SetMesh(Mesh *new_mesh);
95 
97  void SetCycle(int c) { cycle = c; }
99  void SetTime(double t) { time = t; }
100 
102  int GetCycle() { return cycle; }
104  double GetTime() { return time; }
106  const char* GetCollectionName() { return name.c_str(); }
108  void SetOwnData(bool o) { own_data = o; }
109 
111  void SetPrecision(int prec) { precision = prec; }
113  void SetPadDigits(int digits) { pad_digits = digits; }
115  void SetPrefixPath(const char *prefix);
116 
120  virtual void Save();
122  virtual void SaveMesh();
124  virtual void SaveField(const char *field_name);
125 
127  virtual ~DataCollection();
128 
130  enum { NO_ERROR = 0, READ_ERROR = 1, WRITE_ERROR = 2 };
131 
133  int Error() const { return error; }
135  void ResetError(int err = NO_ERROR) { error = err; }
136 };
137 
138 
141 {
142 public:
143  std::string association;
146  VisItFieldInfo(std::string _association, int _num_components)
147  { association = _association; num_components = _num_components; }
148 };
149 
152 {
153 protected:
154  // Additional data needed in the VisIt root file, which describes the mesh
155  // and all the fields in the collection
158  std::map<std::string, VisItFieldInfo> field_info_map;
159 
161  std::string GetVisItRootString();
163  void ParseVisItRootString(std::string json);
164 
165  // Helper functions for Load()
166  void LoadVisItRootFile(std::string root_name);
167  void LoadMesh();
168  void LoadFields();
169 
170 public:
173  VisItDataCollection(const char *collection_name);
175  VisItDataCollection(const char *collection_name, Mesh *_mesh);
176 
178  virtual void SetMesh(Mesh *new_mesh);
179 
181  virtual void RegisterField(const char *field_name, GridFunction *gf);
182 
184  void SetMaxLevelsOfDetail(int max_levels_of_detail);
185 
188  void DeleteAll();
189 
191  virtual void Save();
192 
194  void SaveRootFile();
195 
197  void Load(int _cycle = 0);
198 
200  virtual ~VisItDataCollection() {}
201 };
202 
203 }
204 
205 #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)
void SetPrefixPath(const char *prefix)
Set the path where the DataCollection will be saved.
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.
std::string prefix_path
A path where the directory with results is saved.
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.