8#include <lf/mesh/utils/utils.h>
15 LF_ASSERT_MSG(idx ==
idx_nil || idx <= std::numeric_limits<int>::max(),
16 "Error, trying to convert " << idx <<
"into an int");
17 return (idx ==
idx_nil) ? -1 :
static_cast<int>(idx);
21 std::string filename) {
25 if ((fn_len > 1) && (filename[fn_len - 2] !=
'.') &&
26 (filename[fn_len - 1] !=
'm')) {
31 std::ofstream file(filename);
37 file <<
"function [PTPAR,EDPAR,CELLPAR] = " << filename <<
"()" <<
'\n';
38 file <<
"% Parent data for a hybid 2D mesh" <<
'\n';
41 const std::shared_ptr<const mesh::Mesh>
mesh = hier_mesh.
getMesh(level);
44 const std::vector<ParentInfo> &pt_parent_info(
47 for (
int k = 0; k < no_nodes; k++) {
48 file <<
"PTPAR(" << k + 1 <<
",:) = ["
50 <<
normalize_idx(pt_parent_info[k].child_number) <<
"];" <<
'\n';
56 const std::vector<ParentInfo> &ed_parent_info(
59 for (
int k = 0; k < no_edges; k++) {
60 file <<
"EDPAR(" << k + 1 <<
",:) = ["
62 <<
normalize_idx(ed_parent_info[k].child_number) <<
"];" <<
'\n';
68 const std::vector<ParentInfo> &cell_parent_info(
70 const std::vector<glb_idx_t> &ref_eds(hier_mesh.
RefinementEdges(level));
72 for (
int k = 0; k < no_cells; k++) {
73 file <<
"CELLPAR(" << k + 1 <<
",:) = ["
84 for (
int level = 0; level < n_levels; level++) {
86 std::stringstream level_asc;
88 const std::string filebase = basename +
"_L" + level_asc.str();
91 const std::shared_ptr<const mesh::Mesh>
mesh = hier_mesh.
getMesh(level);
A hierarchy of nested 2D hybrid meshes created by refinement.
std::shared_ptr< const mesh::Mesh > getMesh(size_type level) const
access the mesh on a particular level
const std::vector< ParentInfo > & ParentInfos(size_type level, dim_t codim) const
Fetch information about parents.
const std::vector< sub_idx_t > & RefinementEdges(size_type level) const
Access refinement edge indices.
size_type NumLevels() const
number of meshes contained in the hierarchy, 1 for a single mesh
unsigned int size_type
general type for variables related to size of arrays
unsigned int glb_idx_t
type for global index of mesh entities (nodes, edges, cells)
void writeMatlab(const lf::mesh::Mesh &mesh, std::string filename)
Writes affine triangulation data to file in MATLAB format.
Defines a set of interface classes that define a mesh manager and provides mesh-related tools that bu...
tools for regular or local refinement of 2D hybrid meshes
void WriteMatlab(const MeshHierarchy &hier_mesh, const std::string &basename)
Generate MATLAB code describing a multilevel hierarchy of meshes.
const unsigned int idx_nil
int normalize_idx(glb_idx_t idx)
void WriteMatlabLevel(const MeshHierarchy &hier_mesh, size_type level, std::string filename)
Generate MATLAB function providing parent/child information.