MFEM  v3.0
 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.googlecode.com.
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 
52 
54  static const int pad_digits_default = 6;
55 
57  bool own_data;
58 
60  int error;
61 
63  DataCollection(const char *collection_name);
65  void DeleteData();
67  void DeleteAll();
68 
69 public:
71  DataCollection(const char *collection_name, Mesh *_mesh);
72 
74  virtual void RegisterField(const char *field_name, GridFunction *gf);
76  GridFunction *GetField(const char *field_name);
78  bool HasField(const char *name) { return field_map.count(name) == 1; }
79 
81  Mesh *GetMesh() { return mesh; }
82 
84  void SetCycle(int c) { cycle = c; }
86  void SetTime(double t) { time = t; }
87 
89  int GetCycle() { return cycle; }
91  double GetTime() { return time; }
93  const char* GetCollectionName() { return name.c_str(); }
95  void SetOwnData(bool o) { own_data = o; }
96 
98  void SetPadDigits(int digits) { pad_digits = digits; }
99 
103  virtual void Save();
104 
106  virtual ~DataCollection();
107 
109  enum { NO_ERROR = 0, READ_ERROR = 1, WRITE_ERROR = 2 };
110 
112  int Error() const { return error; }
114  void ResetError(int err = NO_ERROR) { error = err; }
115 };
116 
117 
120 {
121 public:
122  std::string association;
125  VisItFieldInfo(std::string _association, int _num_components)
126  { association = _association; num_components = _num_components; }
127 };
128 
131 {
132 protected:
133  // Additional data needed in the VisIt root file, which describes the mesh
134  // and all the fields in the collection
137  std::map<std::string, VisItFieldInfo> field_info_map;
138 
140  std::string GetVisItRootString();
142  void ParseVisItRootString(std::string json);
143 
144  // Helper functions for Load()
145  void LoadVisItRootFile(std::string root_name);
146  void LoadMesh();
147  void LoadFields();
148 
149 public:
152  VisItDataCollection(const char *collection_name);
154  VisItDataCollection(const char *collection_name, Mesh *_mesh);
155 
157  virtual void RegisterField(const char *field_name, GridFunction *gf);
158 
160  void SetMaxLevelsOfDetail(int max_levels_of_detail);
161 
164  void DeleteAll();
165 
167  virtual void Save();
168 
170  void Load(int _cycle = 0);
171 
173  virtual ~VisItDataCollection() {}
174 };
175 
176 }
177 
178 #endif
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:26
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)
Get a pointer to a grid function in the collection.
void DeleteData()
Delete data owned by the DataCollection keeping field information.
static const int pad_digits_default
Default value for pad_digits.
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 myid
MPI rank (in parallel)
const char * GetCollectionName()
Get the name of the collection.
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)
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.
std::string name
Name of the collection, used as a directory name when saving.
int num_procs
Number of MPI ranks (in parallel)
std::string GetVisItRootString()
Prepare the VisIt root file in JSON format for the current collection.