9#include "write_matplotlib.h"
21 if (filename.compare(filename.size() - 4, 4,
".csv") != 0) {
25 std::ofstream file(filename);
28 const dim_t dim_mesh = mesh.
DimMesh();
29 LF_VERIFY_MSG(dim_mesh == 2,
30 "write_matplotlib() only available for 2D meshes");
33 for (
int codim = 0; codim <= dim_mesh; ++codim) {
35 const size_t obj_idx = mesh.
Index(*obj);
38 const Eigen::MatrixXd vertices =
43 file << codim <<
',' << obj_idx <<
',' << vertices(0, 0) <<
','
44 << vertices(1, 0) <<
'\n';
48 file << codim <<
',' << obj_idx <<
',';
50 for (
const auto *sub : obj->SubEntities(codim)) {
51 file << mesh.
Index(*sub) <<
',';
59 file << codim <<
',' << obj_idx <<
',';
61 for (
const auto *sub : obj->SubEntities(codim + 1)) {
62 file << mesh.
Index(*sub) <<
',';
69 LF_VERIFY_MSG(
false,
"Error for object " + std::to_string(obj_idx) +
70 " in codim " + std::to_string(codim) +
71 " of type " + obj_ref_el.
ToString());
Represents a reference element with all its properties.
static constexpr RefEl kSegment()
Returns the (1-dimensional) reference segment.
constexpr RefEl(RefElType type) noexcept
Create a RefEl from a lf::base::RefElType enum.
const Eigen::MatrixXd & NodeCoords() const
Get the coordinates of the nodes of this reference element.
static constexpr RefEl kPoint()
Returns the (0-dimensional) reference point.
static constexpr RefEl kTria()
Returns the reference triangle.
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
std::string ToString() const
Return a string representation of this Reference element.
Interface class for shape information on a mesh cell in the spirit of parametric finite element metho...
virtual Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const =0
Map a number of points in local coordinates into the global coordinate system.
Interface class representing a topological entity in a cellular complex
Abstract interface for objects representing a single mesh.
virtual std::span< const Entity *const > Entities(unsigned codim) const =0
All entities of a given codimension.
virtual unsigned DimMesh() const =0
The dimension of the manifold described by the mesh, or equivalently the maximum dimension of the ref...
virtual size_type Index(const Entity &e) const =0
Acess to the index of a mesh entity of any co-dimension.
Mesh input (from file) and output (in various formats) facilities.
void writeMatplotlib(const lf::mesh::Mesh &mesh, std::string filename)
Write affine triangulation data to file in matplotlib format.