Skip to content

Commit 2b9d3f5

Browse files
committed
add map from vertex in cut cell to parent entity (either vertex or facet)
1 parent fe71624 commit 2b9d3f5

13 files changed

+361
-210
lines changed

cpp/src/cell_types.h

+29
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,35 @@ namespace cutcells
7777
return vtk_type;
7878
};
7979

80+
inline type map_vtk_type_to_cell_type(vtk_types vtk_type)
81+
{
82+
type cell_type;
83+
84+
switch(vtk_type)
85+
{
86+
case vtk_types::VTK_VERTEX: cell_type = type::point;
87+
break;
88+
case vtk_types::VTK_LINE: cell_type = type::interval;
89+
break;
90+
case vtk_types::VTK_TRIANGLE: cell_type = type::triangle;
91+
break;
92+
case vtk_types::VTK_QUAD: cell_type = type::quadrilateral;
93+
break;
94+
case vtk_types::VTK_TETRA: cell_type = type::tetrahedron;
95+
break;
96+
case vtk_types::VTK_HEXAHEDRON: cell_type = type::hexahedron;
97+
break;
98+
case vtk_types::VTK_WEDGE: cell_type = type::prism;
99+
break;
100+
case vtk_types::VTK_PYRAMID: cell_type = type::pyramid;
101+
break;
102+
default: throw std::invalid_argument("vtk cell type not recognised in map_vtk_type_to_cell_type of cell_types.h");
103+
break;
104+
}
105+
106+
return cell_type;
107+
};
108+
80109
inline int get_num_vertices(type cell_type)
81110
{
82111
int num_vertices = 0;

cpp/src/cut_cell.cpp

+14-20
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ namespace cutcells::cell{
3838
std::cout << i << ": ";
3939
for(int j=0;j<cut_cell._connectivity[i].size();j++)
4040
{
41-
std::cout << cut_cell._connectivity[i][j];
42-
if(j<cut_cell._connectivity[i].size()-1)
41+
std::cout << cut_cell._connectivity[i][j];
42+
if(j<cut_cell._connectivity[i].size()-1)
4343
std::cout << ", ";
4444
}
4545
if(i<cut_cell._connectivity.size()-1)
@@ -50,11 +50,20 @@ namespace cutcells::cell{
5050
std::cout << "cell types=[";
5151
for(int i=0;i<cut_cell._types.size();i++)
5252
{
53-
std::cout << i << ": " << cell_type_to_str(cut_cell._types[i]);
53+
std::cout << i << ": " << cell_type_to_str(cut_cell._types[i]);
5454
if(i<cut_cell._types.size()-1)
5555
std::cout << ", ";
5656
}
5757
std::cout << "]" << std::endl;
58+
59+
std::cout << "local parent entity=[";
60+
for(int i=0;i<cut_cell._vertex_parent_entity.size();i++)
61+
{
62+
std::cout << i << ": " << cut_cell._vertex_parent_entity[i];
63+
if(i<cut_cell._vertex_parent_entity.size()-1)
64+
std::cout << ", ";
65+
}
66+
std::cout << "]" << std::endl;
5867
}
5968

6069
template <std::floating_point T>
@@ -201,7 +210,6 @@ namespace cutcells::cell{
201210
cutcells::cell::CutCell<T> tmp_cut_cell;
202211
cutcells::cell::cut<T>(cell_type, sub_vertex_coordinates, gdim, sub_ls_values, cut_type_str, tmp_cut_cell, triangulate);
203212
sub_cut_cells.push_back(tmp_cut_cell);
204-
sub_cut_cells[sub_cut_cell_id]._parent_cell_index.push_back(-1);
205213
sub_cut_cell_id++;
206214
break;
207215
}
@@ -211,7 +219,6 @@ namespace cutcells::cell{
211219
{
212220
cutcells::cell::CutCell<T> tmp_cut_cell = cutcells::cell::create_cut_cell<T>(cell_type, sub_vertex_coordinates, gdim);
213221
sub_cut_cells.push_back(tmp_cut_cell);
214-
sub_cut_cells[sub_cut_cell_id]._parent_cell_index.push_back(-1);
215222
sub_cut_cell_id++;
216223
}
217224
break;
@@ -222,7 +229,6 @@ namespace cutcells::cell{
222229
{
223230
cutcells::cell::CutCell<T> tmp_cut_cell = cutcells::cell::create_cut_cell<T>(cell_type, sub_vertex_coordinates, gdim);
224231
sub_cut_cells.push_back(tmp_cut_cell);
225-
sub_cut_cells[sub_cut_cell_id]._parent_cell_index.push_back(-1);
226232
sub_cut_cell_id++;
227233
}
228234
break;
@@ -259,11 +265,6 @@ namespace cutcells::cell{
259265
merged_cut_cell._gdim=gdim;
260266
merged_cut_cell._tdim=tdim;
261267

262-
for(std::size_t i=0;i<cut_cell_vec[0]._parent_cell_index.size();i++)
263-
{
264-
merged_cut_cell._parent_cell_index.push_back(cut_cell_vec[0]._parent_cell_index[i]);
265-
}
266-
267268
//Count the total number of cells in vector
268269
int num_cells =0;
269270
for(auto & cut_cell : cut_cell_vec)
@@ -286,12 +287,11 @@ namespace cutcells::cell{
286287
continue;
287288
}
288289
//check that current cut_cell has same dimensions and parent
289-
if((cut_cell._gdim!=gdim)||(cut_cell._tdim!=tdim)||(cut_cell._parent_cell_index[0]!=merged_cut_cell._parent_cell_index[0]))
290+
if((cut_cell._gdim!=gdim)||(cut_cell._tdim!=tdim))
290291
{
291292
std::cout << "gdim: (" << gdim << ", " << cut_cell._gdim << ")" << std::endl;
292293
std::cout << "tdim: (" << tdim << ", " << cut_cell._tdim << ")" << std::endl;
293-
std::cout << "parent_cell: (" << merged_cut_cell._parent_cell_index[0] << ", " << cut_cell._parent_cell_index[0] << ")" << std::endl;
294-
throw std::runtime_error ("Error in merging cutcells have differing dimensions or parent cell");
294+
throw std::runtime_error ("Error in merging cutcells have differing dimensions");
295295
}
296296

297297
int num_cut_cell_vertices = cut_cell._vertex_coords.size()/gdim;
@@ -374,7 +374,6 @@ namespace cutcells::cell{
374374
template <std::floating_point T>
375375
void recursive_cut(cutcells::cell::CutCell<T> &cut_cell,
376376
std::span<const T> ls_vals_all,
377-
const int& parent_cell_index,
378377
const std::string& cut_type_str,
379378
bool triangulate)
380379
{
@@ -414,7 +413,6 @@ namespace cutcells::cell{
414413
if(cell_domain == cutcells::cell::domain::intersected)
415414
{
416415
cutcells::cell::cut<T>(cut_cell_type, vertex_coords, gdim, ls_vals, cut_type_str, cut_cells[cut_cell_id], triangulate);
417-
cut_cells[cut_cell_id]._parent_cell_index.push_back(parent_cell_index);
418416
cut_cell_id++;
419417
}
420418
// cell is completely inside
@@ -424,7 +422,6 @@ namespace cutcells::cell{
424422
if((cut_type_str=="phi<0"))
425423
{
426424
cut_cells[cut_cell_id] = create_cut_cell<T>(cut_cell_type, vertex_coords, gdim);
427-
cut_cells[cut_cell_id]._parent_cell_index.push_back(parent_cell_index);
428425
cut_cell_id++;
429426
}
430427
else
@@ -439,7 +436,6 @@ namespace cutcells::cell{
439436
if((cut_type_str=="phi>0"))
440437
{
441438
cut_cells[cut_cell_id] = create_cut_cell<T>(cut_cell_type, vertex_coords, gdim);
442-
cut_cells[cut_cell_id]._parent_cell_index.push_back(parent_cell_index);
443439
cut_cell_id++;
444440
}
445441
else
@@ -490,12 +486,10 @@ namespace cutcells::cell{
490486

491487
template void recursive_cut(cutcells::cell::CutCell<double> &cut_cell,
492488
std::span<const double> ls_vals_all,
493-
const int& parent_cell_index,
494489
const std::string& cut_type_str,
495490
bool triangulate);
496491
template void recursive_cut(cutcells::cell::CutCell<float> &cut_cell,
497492
std::span<const float> ls_vals_all,
498-
const int& parent_cell_index,
499493
const std::string& cut_type_str,
500494
bool triangulate);
501495
//-----------------------------------------------------------------------------

cpp/src/cut_cell.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace cutcells
1717
{
18+
// Structure to represent mesh local to each cell
1819
namespace cell
1920
{
2021
/// @brief Stores the sub-cells resulting from cutting a cell
@@ -38,9 +39,10 @@ namespace cutcells
3839
/// Cell type of cut cells
3940
std::vector<type> _types;
4041

41-
/// Parent index for cell, pair of indices for interfaces
42-
std::vector<std::int32_t> _parent_cell_index;
43-
42+
/// parent facet or vertex of vertex coordinates
43+
/// these correspond to the local numbering of intersected facets or vertices
44+
/// vertices are indicated by a shift of 100 in the numbering vertex 1 -> 101 etc.
45+
std::vector<int32_t> _vertex_parent_entity;
4446
};
4547

4648
template <std::floating_point T>
@@ -76,7 +78,6 @@ namespace cutcells
7678
template <std::floating_point T>
7779
void recursive_cut(cutcells::cell::CutCell<T> &cut_cell,
7880
std::span<const T> ls_vals_all,
79-
const int& parent_cell_index,
8081
const std::string& cut_type_str,
8182
bool triangulate);
8283
}

cpp/src/cut_interval.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "cut_interval.h"
77
#include "cell_flags.h"
88
#include "span_math.h"
9+
#include "utils.h"
910
#include <unordered_map>
1011

1112
namespace cutcells::cell
@@ -162,6 +163,8 @@ namespace cutcells::cell
162163
{
163164
throw std::invalid_argument("cutting type unknown");
164165
}
166+
167+
cutcells::utils::create_vertex_parent_entity_map<T>(vertex_case_map, cut_cell._vertex_parent_entity);
165168
}
166169

167170
// cut interval

0 commit comments

Comments
 (0)