Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • am-dept/amfe
  • Paul.Dechamps/amfe
2 results
Show changes
Commits on Source (1)
......@@ -298,6 +298,73 @@ void GmshExport::save(std::string const &fname, Results const &r) const
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
{
out << "GmshExport on " << *msh << std::endl;
......
......@@ -39,6 +39,7 @@ public:
virtual void save(std::string const &fname) const override;
#ifndef SWIG
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
virtual void write(std::ostream &out) const override;
......
......@@ -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");
}
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:
virtual void save(std::string const &fname) const;
#ifndef SWIG
virtual void save(std::string const &fname, Results const &r) const;
virtual void saveList(std::string const &fname, Results const &r) const;
#endif
};
......