9 #include <vtkCellType.h>
10 #include <vtkIdList.h>
11 #include <vtkGenericCell.h>
12 #include <vtkPoints.h>
13 #include <vtkSmartPointer.h>
14 #include <vtkUnstructuredGrid.h>
16 #include <vtkDoubleArray.h>
17 #include <vtkPointData.h>
18 #include <vtkPolyData.h>
19 #include <vtkProbeFilter.h>
65 .pretty_name(
"Source Mesh")
66 .description(
"Mesh to interpolate from. Warning: this is modified in parallel to make all elements known on each rank.")
70 .pretty_name(
"Target Mesh")
71 .description(
"Mesh to interpolate to")
74 create_static_component<mesh::BoundingBox>(
"BoundingBox");
103 const Uint nb_target_points = target_dict->
size();
112 bounding_box->
build(*target_mesh);
113 std::vector<Real> my_bbox(dim*2);
114 for(
Uint i = 0; i != dim; ++i)
116 my_bbox[i] = bounding_box->
min()[i];
117 my_bbox[dim+i] = bounding_box->
max()[i];
120 std::vector< std::vector<Real> > recv_bbox;
121 comm.all_gather(my_bbox, recv_bbox);
122 const Uint nb_ranks = comm.size();
124 std::vector<RealVector> box_mins(nb_ranks);
125 std::vector<RealVector> box_maxs(nb_ranks);
126 for(
Uint rank = 0; rank != nb_ranks; ++rank)
128 const std::vector<Real>& other_bbox = recv_bbox[rank];
129 const Eigen::Map<RealVector const> b_min(&other_bbox[0], dim);
130 const Eigen::Map<RealVector const> b_max(&other_bbox[dim], dim);
131 box_mins[rank] = b_min;
132 box_maxs[rank] = b_max;
139 std::vector< std::vector< std::vector<Uint> > > elements_to_send(nb_procs, std::vector< std::vector<Uint> > (source_mesh->
elements().size()));
143 const Uint nb_elems = elements.
size();
144 for(
Uint elem_idx = 0; elem_idx != nb_elems; ++elem_idx)
146 for(
Uint rank = 0; rank != nb_ranks; ++rank)
148 if(rank == comm.rank())
150 BOOST_FOREACH(
const Uint node_idx, conn[elem_idx])
152 const Eigen::Map<RealVector const> coord(&source_coords[node_idx][0], dim);
153 if((coord.array() <= box_maxs[rank].array()).all() && (coord.array() >= box_mins[rank].array()).all())
155 elements_to_send[rank][elements.
entities_idx()].push_back(elem_idx);
163 std::vector< std::vector< std::vector<Uint> > > nodes_to_send;
166 std::vector< std::vector< std::vector<boost::uint64_t> > > imported_elements;
171 std::vector< std::vector< std::vector<boost::uint64_t> > > imported_nodes;
172 adaptor.
send_nodes(nodes_to_send,imported_nodes);
179 const Uint nb_source_points = source_dict->size();
183 vtkSmartPointer<vtkPoints>
points = vtkSmartPointer<vtkPoints>::New();
184 points->Allocate(nb_source_points);
187 points->InsertNextPoint(coord[
XX], coord[
YY], coord[
ZZ]);
190 vtkSmartPointer<vtkUnstructuredGrid> vtk_unstruc_grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
191 vtk_unstruc_grid->SetPoints(points);
194 std::vector<mesh::Field*> source_fields, target_fields;
203 target_field = target_dict->create_field(source_field->
name(), source_field->
descriptor().
description()).handle<mesh::Field>();
204 BOOST_FOREACH(
const std::string& tag, source_field->
get_tags())
209 nb_scalars += source_field->
row_size();
211 source_fields.push_back(source_field.
get());
212 target_fields.push_back(target_field.
get());
215 vtkSmartPointer<vtkDoubleArray> source_data = vtkSmartPointer<vtkDoubleArray>::New();
216 source_data->SetNumberOfComponents(nb_scalars);
217 source_data->SetName(
"SourceData");
218 source_data->Allocate(nb_source_points);
219 std::vector<Real> field_values_row(nb_scalars);
220 for(
Uint i = 0; i != nb_source_points; ++i)
223 BOOST_FOREACH(
const mesh::Field* source_field, source_fields)
226 std::copy(fd_row.begin(), fd_row.end(), field_values_row.begin()+offset);
229 source_data->InsertNextTuple(&field_values_row[0]);
231 vtk_unstruc_grid->GetPointData()->SetScalars(source_data);
239 cell_type = VTK_TETRA;
241 cell_type = VTK_HEXAHEDRON;
243 cell_type = VTK_WEDGE;
248 const Uint nb_elems = connectivity.
size();
249 const Uint nb_elem_nodes = connectivity.row_size();
250 vtkSmartPointer<vtkIdList> id_list = vtkSmartPointer<vtkIdList>::New();
251 id_list->SetNumberOfIds(nb_elem_nodes);
252 for(
Uint i = 0; i != nb_elems; ++i)
255 for(
int j = 0; j != nb_elem_nodes; ++j)
256 id_list->SetId(j, row[j]);
257 vtk_unstruc_grid->InsertNextCell(cell_type, id_list);
262 vtkSmartPointer<vtkPolyData> probe_poly = vtkSmartPointer<vtkPolyData>::New();
263 vtkSmartPointer<vtkPoints> probe_points = vtkSmartPointer<vtkPoints>::New();
264 probe_points->Allocate(nb_target_points);
267 probe_points->InsertNextPoint(coord[
XX], coord[
YY], coord[
ZZ]);
269 probe_poly->SetPoints(probe_points);
272 vtkSmartPointer<vtkProbeFilter> prober = vtkSmartPointer<vtkProbeFilter>::New();
273 prober->SetInputData(probe_poly);
274 prober->SetSourceData(vtk_unstruc_grid);
277 if(
is_null(prober->GetOutput()))
280 vtkDataArray* interpolated_scalars = prober->GetOutput()->GetPointData()->GetScalars();
284 for(
Uint i = 0; i != nb_target_points; ++i)
287 interpolated_scalars->GetTuple(i, &field_values_row[0]);
288 BOOST_FOREACH(
mesh::Field* target_field, target_fields)
291 std::copy(field_values_row.begin()+offset, field_values_row.begin()+offset+target_field->
row_size(), fd_row.begin());
296 BOOST_FOREACH(
mesh::Field* target_field, target_fields)
const RealVector & min() const
minimum coordinates, defining one corner of the bounding box
void build(const Region ®ion)
Build bounding box with a mesh.
std::string name(ComponentWrapper &self)
bool is_null(T ptr)
predicate for comparison to nullptr
const std::vector< Handle< Entities > > & elements() const
Helper class to create the Builder and place it in the factory.
Space & geometry_space() const
Type
Enumeration of the Shapes recognized in CF.
void copy(const std::vector< Real > &vector, RealMatrix &realmatrix)
Copy std::vector to dynamic RealMatrix types.
virtual ~MeshInterpolator()
const RealVector & max() const
maximum coordinates, defining one corner of the bounding box
ElementType & element_type() const
return the elementType
MeshInterpolator(const std::string &name)
const std::string & name() const
Access the name of the component.
void flush_elements()
Apply all changes to elements.
virtual void execute()
execute the action
void flush_nodes()
Apply all changes to nodes.
Uint size() const
return the number of elements
common::PE::CommPattern & parallelize()
GeoShape::Type shape() const
void find_nodes_to_export(const std::vector< std::vector< std::vector< Uint > > > &exported_elements_loc_id, std::vector< std::vector< std::vector< Uint > > > &exported_nodes_loc_id)
Assemble a change-set of nodes to be sent together with elements.
Handle< Component > get_child(const std::string &name)
TableConstRow< Real >::type ConstRow
the const type of a row in the internal structure of the table
Top-level namespace for coolfluid.
const TYPE value(const std::string &opt_name) const
Get the value of the option with given name.
void finish()
Apply the changes the mesh adaptor for changes and fix inconsistent state.
void add_tag(const std::string &tag)
TableRow< Real >::type Row
the type of a row in the internal structure of the table
Uint row_size(Uint i=0) const
boost::proto::terminal< SFOp< CoordinatesOp > >::type const coordinates
std::vector< std::string > get_tags() const
void send_nodes(const std::vector< std::vector< std::vector< Uint > > > &exported_nodes_loc_id, std::vector< std::vector< std::vector< boost::uint64_t > > > &imported_nodes_glb_id)
Send/Receive nodes according to an nodes-changeset.
std::string description() const
Get the string description for all the variables.
common::ComponentBuilder< MeshInterpolator, common::Action, LibVTK > MeshInterpolator_Builder
unsigned int Uint
typedef for unsigned int
bool has_tag(const std::string &tag) const
Uint entities_idx() const
void prepare()
Prepare the mesh adaptor for changes.
Region & topology() const
Handle< Component > handle()
Get a handle to the component.
math::VariablesDescriptor & descriptor() const
void send_elements(const std::vector< std::vector< std::vector< Uint > > > &exported_elements_loc_id, std::vector< std::vector< std::vector< boost::uint64_t > > > &imported_elements_glb_id)
Send/Receive elements according to an elements-changeset.
SelectOptionType< T >::type & add(const std::string &name, const T &default_value=T())
Dictionary & geometry_fields() const
static Comm & instance()
Return a reference to the current PE.
Uint size() const
Number of rows of contained fields.
Connectivity & connectivity()
connectivity table to dictionary entries
T * get() const
Raw pointer to the stored value, or null if there is none.
bool is_not_null(T ptr)
predicate for comparison to nullptr