Skip to content
Snippets Groups Projects
Commit fb9deb4b authored by Adrien Crovato's avatar Adrien Crovato
Browse files

Add capability to save mesh and results as list in Gmsh for adaptive mesh refinement

parent c11ff6ee
Branches feat_amr
No related tags found
No related merge requests found
Pipeline #50457 passed
...@@ -298,6 +298,73 @@ void GmshExport::save(std::string const &fname, Results const &r) const ...@@ -298,6 +298,73 @@ void GmshExport::save(std::string const &fname, Results const &r) const
std::cout << "done" << std::endl; std::cout << "done" << std::endl;
} }
/**
* @brief Save results as a list view, i.e. with the underlying mesh, on disk
* @todo Check if useful with newer Gmsh versions
* @todo Remove if remeshing is not done through Gmsh
*/
void GmshExport::saveList(std::string const &fname, Results const &r) const
{
std::string wname = fname + ".pos";
std::cout << "writing file: " << wname << "... " << std::flush;
FILE *file;
file = fopen(wname.c_str(), "wt");
if (!file)
throw std::runtime_error("tbox::GmshExport::saveList Error opening file!\n");
if (!r.scalars_at_elems.empty() || !r.vectors_at_nodes.empty() || !r.vectors_at_elems.empty() || !r.tensors_at_nodes.empty() || !r.tensors_at_elems.empty())
throw std::runtime_error("tbox::GmshExport::saveList Only scalars_at_nodes Result type is supported!\n");
for (auto &p : r.scalars_at_nodes)
{
// name of view
fprintf(file, "View \"%s\" {\n", p.first.c_str());
// element and data
for (auto e : msh->elems)
{
std::string str;
if (e->type() == ElType::POINT1)
{
str = "SP(";
}
else if (e->type() == ElType::LINE2)
{
str = "SL(";
}
else if (e->type() == ElType::TRI3)
{
str = "ST(";
}
else if (e->type() == ElType::TETRA4)
{
str = "SS(";
}
else
throw std::runtime_error("tbox::GmshExport::saveList Element type not supported!\n");
// node coordinates and values
for (auto n : e->nodes)
str += std::to_string(n->pos(0)) + "," + std::to_string(n->pos(1)) + "," + std::to_string(n->pos(2)) + ",";
str.erase(str.length() - 1);
str += "){";
for (auto n : e->nodes)
{
if (std::isnan((*(p.second))[n->row]))
str += "-nan,"; // find a nicer way to handle nan
else
str += std::to_string((*(p.second))[n->row]) + ",";
}
str.erase(str.length() - 1);
str += "};\n";
fprintf(file, "%s", str.c_str());
}
fprintf(file, "};\n");
}
// close file
fclose(file);
std::cout << "done" << std::endl;
}
void GmshExport::write(std::ostream &out) const void GmshExport::write(std::ostream &out) const
{ {
out << "GmshExport on " << *msh << std::endl; out << "GmshExport on " << *msh << std::endl;
......
...@@ -39,6 +39,7 @@ public: ...@@ -39,6 +39,7 @@ public:
virtual void save(std::string const &fname) const override; virtual void save(std::string const &fname) const override;
#ifndef SWIG #ifndef SWIG
virtual void save(std::string const &fname, Results const &r) const override; virtual void save(std::string const &fname, Results const &r) const override;
virtual void saveList(std::string const &fname, Results const &r) const override;
#endif #endif
virtual void write(std::ostream &out) const override; virtual void write(std::ostream &out) const override;
......
...@@ -32,3 +32,7 @@ void MshExport::save(std::string const &fname, Results const &r) const ...@@ -32,3 +32,7 @@ void MshExport::save(std::string const &fname, Results const &r) const
{ {
throw std::runtime_error("tbox::MshExport::save not implemented!\n"); throw std::runtime_error("tbox::MshExport::save not implemented!\n");
} }
void MshExport::saveList(std::string const &fname, Results const &r) const
{
throw std::runtime_error("tbox::MshExport::save_ not implemented!\n");
}
...@@ -54,6 +54,7 @@ public: ...@@ -54,6 +54,7 @@ public:
virtual void save(std::string const &fname) const; virtual void save(std::string const &fname) const;
#ifndef SWIG #ifndef SWIG
virtual void save(std::string const &fname, Results const &r) const; virtual void save(std::string const &fname, Results const &r) const;
virtual void saveList(std::string const &fname, Results const &r) const;
#endif #endif
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment