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) ? int(-1) : 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 <<
"()"
39 file <<
"% Parent data for a hybid 2D mesh" << std::endl;
42 std::shared_ptr<const mesh::Mesh> mesh = hier_mesh.
getMesh(level);
45 const std::vector<ParentInfo> &pt_parent_info(
47 const size_type no_nodes = mesh->NumEntities(2);
48 for (
int k = 0; k < no_nodes; k++) {
49 file <<
"PTPAR(" << k + 1 <<
",:) = ["
58 const std::vector<ParentInfo> &ed_parent_info(
60 const size_type no_edges = mesh->NumEntities(1);
61 for (
int k = 0; k < no_edges; k++) {
62 file <<
"EDPAR(" << k + 1 <<
",:) = ["
71 const std::vector<ParentInfo> &cell_parent_info(
73 const std::vector<glb_idx_t> &ref_eds(hier_mesh.
RefinementEdges(level));
74 const size_type no_cells = mesh->NumEntities(0);
75 for (
int k = 0; k < no_cells; k++) {
76 file <<
"CELLPAR(" << k + 1 <<
",:) = ["
87 for (
int level = 0; level < n_levels; level++) {
89 std::stringstream level_asc;
91 std::string filebase = basename +
"_L" + level_asc.str();
94 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.
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.