9 #include <vtkCellType.h>
10 #include <vtkDataSetTriangleFilter.h>
11 #include <vtkIdList.h>
12 #include <vtkGenericCell.h>
13 #include <vtkPoints.h>
14 #include <vtkSmartPointer.h>
15 #include <vtkUnstructuredGrid.h>
60 const Uint nb_points = coordinates.
size();
62 vtkSmartPointer<vtkPoints>
points = vtkSmartPointer<vtkPoints>::New();
63 points->Allocate(nb_points);
66 points->InsertNextPoint(coord[
XX], coord[
YY], coord[
ZZ]);
69 vtkSmartPointer<vtkUnstructuredGrid> vtk_unstruc_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
70 vtk_unstruc_grid->SetPoints(points);
72 std::vector< Handle<common::Component> > to_remove;
85 cell_type = VTK_HEXAHEDRON;
87 cell_type = VTK_WEDGE;
91 to_remove.push_back(elems.
handle());
94 const Uint nb_elems = connectivity.
size();
96 vtkSmartPointer<vtkIdList> id_list = vtkSmartPointer<vtkIdList>::New();
97 id_list->SetNumberOfIds(nb_elem_nodes);
98 for(
Uint i = 0; i != nb_elems; ++i)
101 for(
int j = 0; j != nb_elem_nodes; ++j)
102 id_list->SetId(j, row[j]);
103 vtk_unstruc_grid->InsertNextCell(cell_type, id_list);
106 parent_region = common::find_parent_component_ptr<mesh::Region>(elems);
109 vtkSmartPointer<vtkDataSetTriangleFilter>
triangulator = vtkSmartPointer<vtkDataSetTriangleFilter>::New();
110 triangulator->SetTetrahedraOnly(
true);
111 triangulator->SetInputData(vtk_unstruc_grid);
113 vtkSmartPointer<vtkUnstructuredGrid> out_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
114 triangulator->SetOutput(out_grid);
115 triangulator->Update();
120 const Uint nb_tets = out_grid->GetNumberOfCells();
122 tetras->
initialize(
"cf3.mesh.LagrangeP1.Tetra3D",
mesh().geometry_fields());
125 vtkSmartPointer<vtkGenericCell> cell = vtkSmartPointer<vtkGenericCell>::New();
126 std::vector< std::set<Uint> > connectivity_sets(nb_points);
127 for(
Uint i = 0; i != nb_tets; ++i)
130 out_grid->GetCell(i, cell);
131 for(
Uint j = 0; j != 4; ++j)
133 row[j] = cell->GetPointId(j);
135 for(
Uint j = 0; j != 4; ++j)
137 connectivity_sets[row[j]].insert(row.begin(), row.end());
150 to_remove.push_back(elems.
handle());
153 const Uint nb_quads = connectivity.
size();
155 Handle<mesh::Faces> triags = common::find_parent_component<mesh::Region>(elems).create_component<mesh::Faces>(
"TriangulatedFaces");
156 triags->
initialize(
"cf3.mesh.LagrangeP1.Triag3D",
mesh().geometry_fields());
157 triags->
resize(nb_quads*2);
160 for(
Uint i = 0; i != nb_quads; ++i)
166 if(connectivity_sets[row[0]].
count(row[2]) > 0)
168 triag1_row[0] = quad_row[0]; triag1_row[1] = quad_row[1]; triag1_row[2] = quad_row[2];
169 triag2_row[0] = quad_row[0]; triag2_row[1] = quad_row[2]; triag2_row[2] = quad_row[3];
174 triag1_row[0] = quad_row[0]; triag1_row[1] = quad_row[1]; triag1_row[2] = quad_row[3];
175 triag2_row[0] = quad_row[1]; triag2_row[1] = quad_row[2]; triag2_row[2] = quad_row[3];
183 comp->
parent()->remove_component(*comp);
191 Uint mesh_nb_elems = 0;
192 BOOST_FOREACH(
mesh::Elements& elements , common::find_components_recursively<mesh::Elements>(
mesh()))
194 mesh_nb_elems += elements.
size();
197 std::vector<Uint> nb_elements_accumulated;
201 comm.
all_gather(mesh_nb_elems, nb_elements_accumulated);
205 nb_elements_accumulated.push_back(mesh_nb_elems);
210 nb_elements_accumulated[i] += nb_elements_accumulated[i-1];
213 Uint element_offset = rank == 0 ? 0 : nb_elements_accumulated[rank-1];
216 BOOST_FOREACH(
mesh::Elements& elements , common::find_components_recursively<mesh::Elements>(
mesh()))
218 const Uint nb_elems = elements.
size();
227 element_offset += nb_elems;
#define CFinfo
these are always defined
std::string name(ComponentWrapper &self)
bool check_sanity() const
Safe pointer to an object. This is the supported method for referring to components.
void resize(const Uint new_size)
Helper class to create the Builder and place it in the factory.
Space & geometry_space() const
Type
Enumeration of the Shapes recognized in CF.
Tetrahedralize(const std::string &name)
common::ComponentBuilder< Tetrahedralize, mesh::MeshTransformer, LibVTK > Tetrahedralize_Builder
ElementType & element_type() const
return the elementType
URI uri() const
Construct the full path.
const std::string & name() const
Access the name of the component.
const Field & coordinates() const
common::List< Uint > & rank()
Uint rank() const
Return rank, additionally, if is_init==0.
virtual void initialize(const std::string &element_type_name, Dictionary &geometry)
Initialize the Cells using the given type.
Uint size() const
Return the number of processes, or 1 if is_init==0.
virtual void execute()
execute the action
Uint size() const
return the number of elements
common::List< Uint > & glb_idx()
Mutable access to the list of nodes.
Handle< Component > parent() const
GeoShape::Type shape() const
TableConstRow< Real >::type ConstRow
the const type of a row in the internal structure of the table
Top-level namespace for coolfluid.
void resize(const Uint nb_elem)
TableRow< Uint >::type Row
the type of a row in the internal structure of the table
virtual void initialize(const std::string &element_type_name, Dictionary &geometry)
Initialize the Faces using the given type.
Uint row_size(Uint i=0) const
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
unsigned int Uint
typedef for unsigned int
virtual ~Tetrahedralize()
Handle< Component > handle()
Get a handle to the component.
Dictionary & geometry_fields() const
static Comm & instance()
Return a reference to the current PE.
Handle< Component > create_component(const std::string &name, const std::string &builder)
Build a (sub)component of this component using the extended type_name of the component.
T * all_gather(const T *in_values, const int in_n, T *out_values, const int stride=1)
Uint count(const RangeT &range)
Count the elements in a range.
Connectivity & connectivity()
connectivity table to dictionary entries
bool is_not_null(T ptr)
predicate for comparison to nullptr