1#include "mesh_factory.h"
3#include <spdlog/spdlog.h>
8#include "lf/base/base.h"
20 "coord has incompatible number of rows.");
23 std::make_unique<geometry::Point>(coord);
24 nodes_.emplace_back(std::move(point_geo));
29 std::unique_ptr<geometry::Geometry>&& geometry) {
35 LF_ASSERT_MSG(geometry !=
nullptr,
36 "No creation of a point without a valid geometry");
37 LF_ASSERT_MSG(geometry->DimGlobal() ==
dim_world_,
38 "geometry->DimGlobal() != dim_world_");
40 "Geometry object must belong to a point");
41 nodes_.emplace_back(std::move(geometry));
46 base::RefEl ref_el,
const std::span<const size_type>& nodes,
47 std::unique_ptr<geometry::Geometry>&& geometry) {
49 "Use AddPoint() to add a node to a mesh.");
50 LF_ASSERT_MSG(ref_el.
Dimension() <= 2,
"ref_el.Dimension > 2");
51 if (geometry !=
nullptr) {
52 LF_ASSERT_MSG(geometry->DimGlobal() ==
dim_world_,
53 "geometry->DimGlobal() != dim_world_");
54 LF_ASSERT_MSG(geometry->RefEl() == ref_el,
"ref_el != geometry->RefEl()");
59 std::array<size_type, 2> ns{};
60 unsigned char count = 0;
61 for (
const auto& n : nodes) {
62 LF_ASSERT_MSG(n <
nodes_.size(),
64 <<
" specified in call to AddEntity must be "
65 "inserted with AddPoint() first.");
68 "ref_el = segment, but nodes contains more than 2 node indices");
72 LF_ASSERT_MSG(count == 2,
73 "ref_el = segment but size of nodes was " << count);
74 edges_.emplace_back(ns, std::move(geometry));
80 std::array<size_type, 4> ns{};
81 unsigned char count = 0;
82 for (
const auto& n : nodes) {
83 LF_ASSERT_MSG(count < ref_el.
NumNodes(),
84 "ref_el = " << ref_el <<
", but nodes contains " << count + 1
86 LF_ASSERT_MSG(n <
nodes_.size(),
87 " Node " << n <<
" for " << ref_el.
ToString()
88 <<
" must be inserted with AddNode() first.");
92 LF_ASSERT_MSG(count == ref_el.
NumNodes(),
93 "ref_el.NumNodes() = " << ref_el.
NumNodes()
94 <<
", but argument nodes contained "
95 << count <<
" nodes");
101 elements_.emplace_back(ns, std::move(geometry));
107 if (
Logger()->should_log(spdlog::level::trace)) {
108 std::stringstream ss;
110 SPDLOG_LOGGER_TRACE(
Logger(), ss.str());
124 return std::shared_ptr<mesh::Mesh>(mesh_ptr);
129 o <<
"hybrid2d::MeshFactory: Internal information" <<
'\n';
130 o <<
nodes_.size() <<
" nodes:" <<
'\n';
131 for (std::size_t j = 0; j <
nodes_.size(); j++) {
132 o <<
"Node " << j <<
" at ";
133 if (
nodes_[j] !=
nullptr) {
134 o << (
nodes_[j]->Global(Eigen::Matrix<double, 0, 1>())).transpose()
137 o <<
"with unknown location!" <<
'\n';
140 o <<
edges_.size() <<
" edges " <<
'\n';
141 for (std::size_t j = 0; j <
edges_.size(); j++) {
142 o <<
"Edge " << j <<
": " <<
edges_[j].first[0] <<
" <-> "
145 o <<
" with geometry";
150 std::cout <<
elements_.size() <<
" cells " <<
'\n';
151 for (std::size_t j = 0; j <
elements_.size(); j++) {
152 o <<
"Cell " << j <<
" : ";
153 for (
int l = 0; l < 4; l++) {
159 o <<
" with geometry";
161 o <<
"[no geometry]";
Represents a reference element with all its properties.
static constexpr RefEl kSegment()
Returns the (1-dimensional) reference segment.
constexpr dim_t Dimension() const
Return the dimension of this reference element.
static constexpr RefEl kPoint()
Returns the (0-dimensional) reference point.
constexpr size_type NumNodes() const
The number of nodes of this reference element.
std::string ToString() const
Return a string representation of this Reference element.
Eigen::VectorXd coord_t
Coordinate type of a point.
Abstract interface for objects representing a single mesh.
hybrid2d::Mesh::CellList elements_
static std::shared_ptr< spdlog::logger > & Logger()
logger that is used by the build method to output additional information to the command line.
std::shared_ptr< mesh::Mesh > Build() override
Construct a mesh out of the specified nodes and elements.
size_type AddEntity(base::RefEl ref_el, const std::span< const size_type > &nodes, std::unique_ptr< geometry::Geometry > &&geometry) override
Add an an entity (codim>0) to the mesh.
void PrintLists(std::ostream &o=std::cout) const
output function printing assembled lists of entity information
hybrid2d::Mesh::NodeCoordList nodes_
hybrid2d::Mesh::EdgeList edges_
size_type AddPoint(coord_t coord) override
Add a point to the mesh.
Basis 2D mesh type compliant with abstract mesh interface.
std::vector< std::pair< std::array< size_type, 4 >, GeometryPtr > > CellList
std::unique_ptr< geometry::Geometry > GeometryPtr
Data types for passing information about mesh intities.
std::vector< std::pair< std::array< size_type, 2 >, GeometryPtr > > EdgeList
std::vector< GeometryPtr > NodeCoordList
std::shared_ptr< spdlog::logger > InitLogger(const std::string &name)
Create a spdlog logger, register it in the spdlog registry and initialize it with LehrFEM++ specific ...
An alternative implementation of a hybrid2d mesh manager that uses Pointers to store sub-entity relat...