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;
69 precision = precision_default;
70 pad_digits = pad_digits_default;
76 name = collection_name;
94 precision = precision_default;
95 pad_digits = pad_digits_default;
101 if (own_data) {
delete mesh; }
119 if (own_data && HasField(name))
121 delete field_map[name];
123 field_map[name] = gf;
128 if (HasField(field_name))
130 return field_map[field_name];
142 prefix_path = prefix;
143 if (!prefix_path.empty() && prefix_path[prefix_path.size()-1] !=
'/')
158 if (error) {
return; }
160 for (map<string,GridFunction*>::iterator it = field_map.begin();
161 it != field_map.end(); ++it)
167 static int create_directory(
const string &dir_name,
const Mesh *mesh,
int myid)
171 err = mkdir(dir_name.c_str(), 0777);
172 err = (err && (errno != EEXIST)) ? 1 : 0;
175 if (myid == 0 || pmesh == NULL)
177 err = mkdir(dir_name.c_str(), 0777);
178 err = (err && (errno != EEXIST)) ? 1 : 0;
181 MPI_Bcast(&err, 1, MPI_INT, 0, pmesh->
GetComm());
187 MPI_Bcast(&err, 1, MPI_INT, 0, pmesh->
GetComm());
196 if (!prefix_path.empty())
198 err = create_directory(prefix_path, mesh, myid);
202 MFEM_WARNING(
"Error creating directory: " << prefix_path);
207 string dir_name = prefix_path;
216 err = create_directory(dir_name, mesh, myid);
220 MFEM_WARNING(
"Error creating directory: " << dir_name);
227 mesh_name = dir_name +
"/mesh";
233 ofstream mesh_file(mesh_name.c_str());
234 mesh_file.precision(precision);
235 mesh->
Print(mesh_file);
239 MFEM_WARNING(
"Error writing mesh to file: " << mesh_name);
244 const std::map<std::string,GridFunction*>::iterator &it)
246 string dir_name = prefix_path;
259 file_name = dir_name +
"/" + it->first;
263 file_name = dir_name +
"/" + it->first +
"." +
266 ofstream field_file(file_name.c_str());
267 field_file.precision(precision);
268 (it->second)->Save(field_file);
272 MFEM_WARNING(
"Error writting field to file: " << it->first);
278 const map<string,GridFunction*>::iterator it = field_map.find(field_name);
279 if (it != field_map.end())
292 for (map<string,GridFunction*>::iterator it = field_map.begin();
293 it != field_map.end(); ++it)
315 for (map<string,GridFunction*>::iterator it = field_map.begin();
316 it != field_map.end(); ++it)
387 ofstream root_file(root_name.c_str());
392 MFEM_WARNING(
"Error writting VisIt Root file: " << root_name);
424 ifstream root_file(root_name.c_str());
426 buffer << root_file.rdbuf();
430 MFEM_WARNING(
"Error reading the VisIt Root file: " << root_name);
443 ifstream file(mesh_fname.c_str());
447 MFEM_WARNING(
"Unable to open mesh file: " << mesh_fname);
452 mesh =
new Mesh(file, 1, 1);
464 for (map<string,VisItFieldInfo>::iterator it =
field_info_map.begin();
467 string fname = path_left + it->first + path_right;
468 ifstream file(fname.c_str());
472 MFEM_WARNING(
"Unable to open field file: " << fname);
487 picojson::object top, dsets,
main,
mesh, fields, field, mtags, ftags;
494 mesh[
"path"] = picojson::value(path_str +
"mesh" + file_ext_format);
495 mesh[
"tags"] = picojson::value(mtags);
498 for (map<string,VisItFieldInfo>::iterator it =
field_info_map.begin();
501 ftags[
"assoc"] = picojson::value((it->second).association);
502 ftags[
"comps"] = picojson::value(
to_string((it->second).num_components));
503 field[
"path"] = picojson::value(path_str + it->first + file_ext_format);
504 field[
"tags"] = picojson::value(ftags);
505 fields[it->first] = picojson::value(field);
508 main[
"cycle"] = picojson::value(
double(
cycle));
509 main[
"time"] = picojson::value(
time);
510 main[
"domains"] = picojson::value(
double(
num_procs));
511 main[
"mesh"] = picojson::value(mesh);
514 main[
"fields"] = picojson::value(fields);
517 dsets[
"main"] = picojson::value(main);
518 top[
"dsets"] = picojson::value(dsets);
520 return picojson::value(top).serialize(
true);
525 picojson::value top, dsets,
main,
mesh, fields;
526 string parse_err = picojson::parse(top, json);
527 if (!parse_err.empty())
530 MFEM_WARNING(
"Unable to parse visit root data.");
535 dsets = top.get(
"dsets");
536 main = dsets.get(
"main");
537 cycle = int(main.get(
"cycle").get<
double>());
538 time = main.get(
"time").get<
double>();
539 num_procs = int(main.get(
"domains").get<
double>());
540 mesh = main.get(
"mesh");
541 fields = main.get(
"fields");
546 string path = mesh.get(
"path").get<
string>();
547 size_t right_sep = path.find(
'_');
548 if (right_sep == string::npos)
551 MFEM_WARNING(
"Unable to parse visit root data.");
554 name = path.substr(0, right_sep);
557 topo_dim =
to_int(mesh.get(
"tags").get(
"topo_dim").get<
string>());
559 to_int(mesh.get(
"tags").get(
"max_lods").get<
string>());
563 if (fields.is<picojson::object>())
565 picojson::object fields_obj = fields.get<picojson::object>();
566 for (picojson::object::iterator it = fields_obj.begin();
567 it != fields_obj.end(); ++it)
569 picojson::value tags = it->second.get(
"tags");
572 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.
int main(int argc, char *argv[])
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
virtual void Print(std::ostream &out=std::cout) const
Print the mesh to the given stream using the default MFEM mesh format.
std::map< std::string, VisItFieldInfo > field_info_map
void LoadVisItRootFile(std::string root_name)
void SetPrefixPath(const char *prefix)
Set the path where the DataCollection will be saved.
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.
std::string prefix_path
A path where the directory with results is saved.
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.