3#include "write_matlab.h"
10 using size_type = std::size_t;
12 const Eigen::MatrixXd zero(Eigen::MatrixXd::Zero(0, 1));
16 const size_type fn_len = filename.size();
17 if ((fn_len > 1) && (filename[fn_len - 2] !=
'.') &&
18 (filename[fn_len - 1] !=
'm')) {
23 std::ofstream file(filename);
29 file <<
"function [x,y,TRI,QUAD,EDS] = " << filename <<
"()" <<
'\n';
30 file <<
"% Data for an unstructure planar hybrid 2D mesh" <<
'\n';
33 const dim_t dim_mesh = mesh.
DimMesh();
34 LF_VERIFY_MSG(dim_mesh == 2,
35 "write_matlab() only avvailable for 2D meshes");
38 const dim_t node_codim(dim_mesh);
40 const size_type no_of_nodes = mesh.
NumEntities(node_codim);
41 file <<
"x = zeros(" << no_of_nodes <<
",1);" <<
'\n';
42 file <<
"y = zeros(" << no_of_nodes <<
",1);" <<
'\n';
45 size_type node_cnt = 0;
49 Eigen::MatrixXd node_coord(geo_ptr->
Global(zero));
50 file <<
"x(" << node_index + 1 <<
") = " << node_coord(0, 0) <<
"; "
52 file <<
"y(" << node_index + 1 <<
") = " << node_coord(1, 0) <<
"; "
56 LF_VERIFY_MSG(node_cnt == no_of_nodes,
"Node count mismatch");
60 file <<
"EDS = zeros(" << no_of_edges <<
",2);" <<
'\n';
66 "Edge must be a segment");
68 const auto sub_ent = edge->SubEntities(1);
69 file <<
"EDS(" << edge_index + 1 <<
",:) = ["
70 << mesh.
Index(*sub_ent[0]) + 1 <<
", " << mesh.
Index(*sub_ent[1]) + 1
76 file <<
"TRI = []; QUAD = [];" <<
'\n';
77 size_type cell_cnt = 0;
78 size_type triag_cnt = 0;
79 size_type quad_cnt = 0;
83 const auto sub_ent = e->SubEntities(2);
87 file <<
"TRI(" << triag_cnt + 1 <<
",:) = ["
88 << mesh.
Index(*sub_ent[0]) + 1 <<
", "
89 << mesh.
Index(*sub_ent[1]) + 1 <<
", "
90 << mesh.
Index(*sub_ent[2]) + 1 <<
", " << cell_index <<
" ];"
96 file <<
"QUAD(" << quad_cnt + 1 <<
",:) = ["
97 << mesh.
Index(*sub_ent[0]) + 1 <<
", "
98 << mesh.
Index(*sub_ent[1]) + 1 <<
", "
99 << mesh.
Index(*sub_ent[2]) + 1 <<
", "
100 << mesh.
Index(*sub_ent[3]) + 1 <<
", " << cell_index <<
" ];"
107 "write_matlab can only handle triangles and quads");
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.
static constexpr RefEl kTria()
Returns the reference triangle.
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
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 size_type NumEntities(unsigned codim) const =0
The number of Entities that have the 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.
unsigned int glb_idx_t
type for global index of mesh entities (nodes, edges, cells)
Mesh input (from file) and output (in various formats) facilities.
void writeMatlab(const lf::mesh::Mesh &mesh, std::string filename)
Writes affine triangulation data to file in MATLAB format.