21 #define mkdir(dir, mode) _mkdir(dir)
37 string out_str = ss.str();
38 out_str = out_str.substr(out_str.find_first_not_of(
" \t"));
45 oss << setw(digits) << setfill(
'0') << i;
52 stringstream(str) >> i;
60 name = collection_name;
68 precision = precision_default;
69 pad_digits = pad_digits_default;
75 name = collection_name;
92 precision = precision_default;
93 pad_digits = pad_digits_default;
99 if (own_data) {
delete mesh; }
117 if (own_data && HasField(name))
119 delete field_map[name];
121 field_map[name] = gf;
126 if (HasField(field_name))
128 return field_map[field_name];
140 if (error) {
return; }
142 for (map<string,GridFunction*>::iterator it = field_map.begin();
143 it != field_map.end(); ++it)
162 err = mkdir(dir_name.c_str(), 0777);
163 err = (err && (errno != EEXIST)) ? 1 : 0;
166 if (myid == 0 || pmesh == NULL)
168 err = mkdir(dir_name.c_str(), 0777);
169 err = (err && (errno != EEXIST)) ? 1 : 0;
172 MPI_Bcast(&err, 1, MPI_INT, 0, pmesh->
GetComm());
178 MPI_Bcast(&err, 1, MPI_INT, 0, pmesh->
GetComm());
184 MFEM_WARNING(
"Error creating directory: " << dir_name);
191 mesh_name = dir_name +
"/mesh";
197 ofstream mesh_file(mesh_name.c_str());
198 mesh_file.precision(precision);
199 mesh->Print(mesh_file);
203 MFEM_WARNING(
"Error writing mesh to file: " << mesh_name);
208 const std::map<std::string,GridFunction*>::iterator &it)
223 file_name = dir_name +
"/" + it->first;
226 file_name = dir_name +
"/" + it->first +
"." +
228 ofstream field_file(file_name.c_str());
229 field_file.precision(precision);
230 (it->second)->Save(field_file);
234 MFEM_WARNING(
"Error writting field to file: " << it->first);
240 const map<string,GridFunction*>::iterator it = field_map.find(field_name);
241 if (it != field_map.end())
254 for (map<string,GridFunction*>::iterator it = field_map.begin();
255 it != field_map.end(); ++it)
277 for (map<string,GridFunction*>::iterator it = field_map.begin();
278 it != field_map.end(); ++it)
349 ofstream root_file(root_name.c_str());
354 MFEM_WARNING(
"Error writting VisIt Root file: " << root_name);
386 ifstream root_file(root_name.c_str());
388 buffer << root_file.rdbuf();
392 MFEM_WARNING(
"Error reading the VisIt Root file: " << root_name);
404 ifstream file(mesh_fname.c_str());
408 MFEM_WARNING(
"Unable to open mesh file: " << mesh_fname);
424 for (map<string,VisItFieldInfo>::iterator it =
field_info_map.begin();
427 string fname = path_left + it->first + path_right;
428 ifstream file(fname.c_str());
432 MFEM_WARNING(
"Unable to open field file: " << fname);
447 picojson::object top, dsets,
main,
mesh, fields, field, mtags, ftags;
454 mesh[
"path"] = picojson::value(path_str +
"mesh" + file_ext_format);
455 mesh[
"tags"] = picojson::value(mtags);
458 for (map<string,VisItFieldInfo>::iterator it =
field_info_map.begin();
461 ftags[
"assoc"] = picojson::value((it->second).association);
462 ftags[
"comps"] = picojson::value(
to_string((it->second).num_components));
463 field[
"path"] = picojson::value(path_str + it->first + file_ext_format);
464 field[
"tags"] = picojson::value(ftags);
465 fields[it->first] = picojson::value(field);
468 main[
"cycle"] = picojson::value(
double(
cycle));
469 main[
"time"] = picojson::value(
time);
470 main[
"domains"] = picojson::value(
double(
num_procs));
471 main[
"mesh"] = picojson::value(mesh);
474 main[
"fields"] = picojson::value(fields);
477 dsets[
"main"] = picojson::value(main);
478 top[
"dsets"] = picojson::value(dsets);
480 return picojson::value(top).serialize(
true);
485 picojson::value top, dsets,
main,
mesh, fields;
486 string parse_err = picojson::parse(top, json);
487 if (!parse_err.empty())
490 MFEM_WARNING(
"Unable to parse visit root data.");
495 dsets = top.get(
"dsets");
496 main = dsets.get(
"main");
497 cycle = int(main.get(
"cycle").get<
double>());
498 time = main.get(
"time").get<
double>();
499 num_procs = int(main.get(
"domains").get<
double>());
500 mesh = main.get(
"mesh");
501 fields = main.get(
"fields");
506 string path = mesh.get(
"path").get<
string>();
507 size_t right_sep = path.find(
'_');
508 if (right_sep == string::npos)
511 MFEM_WARNING(
"Unable to parse visit root data.");
514 name = path.substr(0, right_sep);
517 topo_dim =
to_int(mesh.get(
"tags").get(
"topo_dim").get<
string>());
519 to_int(mesh.get(
"tags").get(
"max_lods").get<
string>());
523 if (fields.is<picojson::object>())
525 picojson::object fields_obj = fields.get<picojson::object>();
526 for (picojson::object::iterator it = fields_obj.begin();
527 it != fields_obj.end(); ++it)
529 picojson::value tags = it->second.get(
"tags");
532 to_int(tags.get(
"comps").get<
string>()));
virtual void SaveMesh()
Save the mesh, creating the collection directory.
std::map< std::string, GridFunction * > field_map
The fields and their names (used when saving)
Class for grid function - Vector with associated FE space.
virtual void RegisterField(const char *field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
string to_padded_string(int i, int digits)
void DeleteAll()
Delete data owned by the DataCollection including field information.
Helper class for VisIt visualization data.
virtual void Save()
Save the collection and a VisIt root file.
bool own_data
Should the collection delete its mesh and fields.
double time
Physical time (for time-dependent simulations)
Mesh * mesh
The (common) mesh for the collected fields.
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.
int visit_max_levels_of_detail
GridFunction * GetField(const char *field_name)
void DeleteData()
Delete data owned by the DataCollection keeping field information.
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)
int SpaceDimension() const
std::map< std::string, VisItFieldInfo > field_info_map
void LoadVisItRootFile(std::string root_name)
int main(int argc, char *argv[])
int myid
MPI rank (in parallel)
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.
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.
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)
Class for parallel meshes.
std::string GetVisItRootString()
Prepare the VisIt root file in JSON format for the current collection.