33 CBMBuilder::CBMBuilder()
40 auto target = make_shared<Mesh>(src.m_num_chemicals);
42 vector<Wall*> newWalls;
46 auto find_cell = [&target](
Cell* c) {
47 return (c->GetIndex() == -1 ?
48 target->m_boundary_polygon : target->m_cells[c->GetIndex()]);
50 auto find_node = [&target](
Node* n) {
51 return target->m_nodes[n->GetIndex()];
53 auto find_wall = [&newWalls](
Wall* w) {
54 return newWalls[w->GetIndex()];
58 for (
const auto& n : src.m_nodes) {
59 target->BuildNode(n->GetIndex(), *n, n->IsAtBoundary())->NodeAttributes::operator=(*n);
63 for (
auto c : src.m_cells) {
64 vector<unsigned int> node_ids;
66 c->GetNodes().begin(),
68 back_inserter(node_ids),
69 [](
Node* n){
return n->GetIndex();});
70 target->BuildCell(c->GetIndex(), node_ids)->CellAttributes::operator=(*c);
74 if (src.m_boundary_polygon !=
nullptr) {
75 vector<unsigned int> node_ids;
77 src.m_boundary_polygon->
GetNodes().begin(),
78 src.m_boundary_polygon->
GetNodes().end(),
79 back_inserter(node_ids),
80 [](
Node* n){
return n->GetIndex();});
81 target->BuildBoundaryPolygon(node_ids)->CellAttributes::operator=(*src.m_boundary_polygon);
85 for (
const auto& w : src.m_walls) {
86 Node* n1 = find_node(w->GetN1());
87 Node* n2 = find_node(w->GetN2());
88 Cell* c1 = find_cell(w->GetC1());
89 Cell* c2 = find_cell(w->GetC2());
90 target->BuildWall(w->GetIndex(), n1, n2, c1, c2)->WallAttributes::operator=(*w);
94 copy(target->m_walls.begin(), target->m_walls.end(), back_inserter(newWalls));
97 for (
auto c : src.m_cells) {
99 c->GetWalls().begin(),
101 back_inserter(find_cell(c)->GetWalls()),
104 if (src.m_boundary_polygon !=
nullptr) {
106 src.m_boundary_polygon->
GetWalls().begin(),
107 src.m_boundary_polygon->
GetWalls().end(),
108 back_inserter(target->m_boundary_polygon->GetWalls()),
115 for (
const auto& node_owning_wall : src.m_node_owning_walls) {
116 auto pair = target->m_node_owning_walls.insert(
117 make_pair(find_node(node_owning_wall.first), list<Wall*>()));
118 assert(pair.second &&
"node_owning_wall");
120 node_owning_wall.second.begin(),
121 node_owning_wall.second.end(),
122 back_inserter((pair.first)->second),
127 for (
const auto& wall_neighbor : src.m_wall_neighbors) {
128 auto pair = target->m_wall_neighbors.insert(
129 make_pair(find_cell(wall_neighbor.first), list<Cell*>()));
130 assert(pair.second &&
"m_wall_neighbors");
132 wall_neighbor.second.begin(),
133 wall_neighbor.second.end(),
134 back_inserter((pair.first)->second),
A cell contains walls and nodes.
const std::list< Wall * > & GetWalls() const
Access the cell's walls.
Namespace for the core simulator.
std::shared_ptr< Mesh > Build(const Mesh &mesh)
Build a mesh exactly like the given mesh.
const std::vector< Node * > & GetNodes() const
Access the nodes of cell's polygon.
Structure of cells; key data structure.
A cell wall, runs between cell corner points and consists of wall elements.