7 #ifndef PORTAGE_INTERPOLATE_INTERPOLATE_2ND_ORDER_H_ 8 #define PORTAGE_INTERPOLATE_INTERPOLATE_2ND_ORDER_H_ 24 #include "wonton/support/CoordinateSystem.h" 27 #include "tangram/driver/driver.h" 28 #include "tangram/driver/CellMatPoly.h" 29 #include "tangram/support/MatPoly.h" 59 int D, Entity_kind on_what,
60 typename SourceMeshType,
61 typename TargetMeshType,
62 typename SourceStateType,
63 typename TargetStateType,
65 template<
class,
int,
class,
class>
66 class InterfaceReconstructorType = DummyInterfaceReconstructor,
67 class Matpoly_Splitter = void,
class Matpoly_Clipper = void,
68 class CoordSys = Wonton::DefaultCoordSys
73 using InterfaceReconstructor =
75 InterfaceReconstructorType, D, SourceMeshType,
76 Matpoly_Splitter, Matpoly_Clipper
90 TargetMeshType
const& target_mesh,
91 SourceStateType
const& source_state,
93 : source_mesh_(source_mesh),
94 target_mesh_(target_mesh),
95 source_state_(source_state),
96 variable_name_(
"VariableNameNotSet"),
97 source_values_(nullptr),
98 num_tols_(num_tols) { CoordSys::template verify_coordinate_system<D>(); }
111 TargetMeshType
const& target_mesh,
112 SourceStateType
const& source_state,
114 std::shared_ptr<InterfaceReconstructor> ir)
115 : source_mesh_(source_mesh),
116 target_mesh_(target_mesh),
117 source_state_(source_state),
118 variable_name_(
"VariableNameNotSet"),
119 source_values_(
nullptr),
121 interface_reconstructor_(ir) { CoordSys::template verify_coordinate_system<D>(); }
130 Interpolate_2ndOrder&
operator = (
const Interpolate_2ndOrder& other) =
delete;
155 std::cerr <<
"Interpolation is available for only cells and nodes";
156 std::cerr << std::endl;
175 std::vector<Weights_t>
const& sources_and_weights)
const {
178 std::cerr <<
"Error: interpolation operator not implemented for this entity type";
179 std::cerr << std::endl;
186 SourceMeshType
const& source_mesh_;
187 TargetMeshType
const& target_mesh_;
188 SourceStateType
const& source_state_;
189 std::string variable_name_ =
"";
190 T
const* source_values_;
192 int material_id_ = 0;
194 Field_type field_type_ = Field_type::UNKNOWN_TYPE_FIELD;
196 std::shared_ptr<InterfaceReconstructor> interface_reconstructor_;
217 typename SourceMeshType,
218 typename TargetMeshType,
219 typename SourceStateType,
220 typename TargetStateType,
221 template<
class,
int,
class,
class>
222 class InterfaceReconstructorType,
223 class Matpoly_Splitter,
class Matpoly_Clipper,
class CoordSys
226 D, Entity_kind::CELL,
227 SourceMeshType, TargetMeshType,
228 SourceStateType, TargetStateType,
230 InterfaceReconstructorType,
231 Matpoly_Splitter, Matpoly_Clipper, CoordSys> {
235 D, SourceMeshType, SourceStateType,
236 TargetMeshType, TargetStateType
240 D, Entity_kind::CELL,
241 SourceMeshType, SourceStateType,
242 InterfaceReconstructorType,
243 Matpoly_Splitter, Matpoly_Clipper, CoordSys
247 using InterfaceReconstructor = Tangram::Driver<
248 InterfaceReconstructorType, D, SourceMeshType,
249 Matpoly_Splitter, Matpoly_Clipper
263 TargetMeshType
const& target_mesh,
264 SourceStateType
const& source_state,
266 const Parts*
const parts =
nullptr)
267 : source_mesh_(source_mesh),
268 target_mesh_(target_mesh),
269 source_state_(source_state),
270 variable_name_(
"VariableNameNotSet"),
271 source_values_(nullptr),
273 parts_(parts) { CoordSys::template verify_coordinate_system<D>(); }
286 TargetMeshType
const& target_mesh,
287 SourceStateType
const& source_state,
289 std::shared_ptr<InterfaceReconstructor> ir,
290 const Parts*
const parts =
nullptr)
291 : source_mesh_(source_mesh),
292 target_mesh_(target_mesh),
293 source_state_(source_state),
294 variable_name_(
"VariableNameNotSet"),
295 source_values_(
nullptr),
297 interface_reconstructor_(ir),
298 parts_(parts) { CoordSys::template verify_coordinate_system<D>(); }
307 Interpolate_2ndOrder &
operator=(
const Interpolate_2ndOrder &) =
delete;
332 variable_name_ = variable_name;
333 gradients_ = gradient_field;
334 field_type_ = source_state_.field_type(Entity_kind::CELL, variable_name);
336 if (field_type_ == Field_type::MESH_FIELD) {
337 source_state_.mesh_get_data(Entity_kind::CELL, variable_name, &source_values_);
339 source_state_.mat_get_celldata(variable_name, material_id_, &source_values_);
360 std::vector<Weights_t>
const& sources_and_weights)
const {
362 if (sources_and_weights.empty())
365 auto const& gradient_field = *gradients_;
366 double total_value = 0.;
367 double normalization = 0.;
376 for (
auto&& current : sources_and_weights) {
378 int src_cell = current.entityID;
379 auto intersect_weights = current.weights;
380 double intersect_volume = intersect_weights[0];
382 if (fabs(intersect_volume) <= num_tols_.min_absolute_volume)
386 Point<D> source_centroid;
387 if (field_type_ == Field_type::MESH_FIELD) {
388 source_mesh_.cell_centroid(src_cell, &source_centroid);
391 else if (field_type_ == Field_type::MULTIMATERIAL_FIELD) {
392 int const nb_mats = source_state_.cell_get_num_mats(src_cell);
393 std::vector<int> cellmats;
394 source_state_.cell_get_mats(src_cell, &cellmats);
397 (nb_mats == 0 or (nb_mats == 1 and cellmats[0] == material_id_));
400 source_mesh_.cell_centroid(src_cell, &source_centroid);
402 assert(interface_reconstructor_ !=
nullptr);
404 auto pos = std::find(cellmats.begin(), cellmats.end(), material_id_);
405 bool found_material = (pos != cellmats.end());
407 if (found_material) {
410 auto const& cellmatpoly = interface_reconstructor_->cell_matpoly_data(src_cell);
411 auto matpolys = cellmatpoly.get_matpolys(material_id_);
413 for (
int k = 0; k < D; k++)
414 source_centroid[k] = 0;
422 for (
auto&& poly : matpolys) {
423 auto moments = poly.moments();
425 for (
int k = 0; k < D; k++)
426 source_centroid[k] += moments[k + 1];
429 for (
int k = 0; k < D; k++)
430 source_centroid[k] /= mvol;
437 Point<D> intersect_centroid;
439 for (
int k = 0; k < D; ++k)
440 intersect_centroid[k] = intersect_weights[1 + k] / intersect_volume;
443 int const source_index = (field_type_ == Field_type::MULTIMATERIAL_FIELD
444 ? source_state_.cell_index_in_material(src_cell, material_id_)
447 Vector<D> gradient = gradient_field[source_index];
448 Vector<D> dr = intersect_centroid - source_centroid;
449 CoordSys::modify_line_element(dr, source_centroid);
451 double value = source_values_[source_index] + dot(gradient, dr);
452 value *= intersect_volume;
453 total_value += value;
454 normalization += intersect_volume;
466 return nb_summed ? total_value / normalization : 0.;
472 SourceMeshType
const& source_mesh_;
473 TargetMeshType
const& target_mesh_;
474 SourceStateType
const& source_state_;
475 std::string variable_name_;
476 double const* source_values_;
478 int material_id_ = 0;
480 Field_type field_type_ = Field_type::UNKNOWN_TYPE_FIELD;
482 std::shared_ptr<InterfaceReconstructor> interface_reconstructor_;
503 typename SourceMeshType,
504 typename TargetMeshType,
505 typename SourceStateType,
506 typename TargetStateType,
507 template<
class,
int,
class,
class>
508 class InterfaceReconstructorType,
509 class Matpoly_Splitter,
class Matpoly_Clipper,
class CoordSys
512 D, Entity_kind::NODE,
513 SourceMeshType, TargetMeshType,
514 SourceStateType, TargetStateType,
516 InterfaceReconstructorType,
517 Matpoly_Splitter, Matpoly_Clipper, CoordSys> {
521 D, Entity_kind::NODE,
522 SourceMeshType, SourceStateType,
523 InterfaceReconstructorType,
524 Matpoly_Splitter, Matpoly_Clipper, CoordSys
528 using InterfaceReconstructor = Tangram::Driver<
529 InterfaceReconstructorType, D, SourceMeshType,
530 Matpoly_Splitter, Matpoly_Clipper
535 static auto const Node = Entity_kind::NODE;
548 TargetMeshType
const& target_mesh,
549 SourceStateType
const& source_state,
551 source_mesh_(source_mesh),
552 target_mesh_(target_mesh),
553 source_state_(source_state),
554 variable_name_(
"VariableNameNotSet"),
555 source_values_(nullptr),
556 num_tols_(num_tols) {}
569 TargetMeshType
const& target_mesh,
570 SourceStateType
const& source_state,
572 std::shared_ptr<InterfaceReconstructor> ir) :
573 source_mesh_(source_mesh),
574 target_mesh_(target_mesh),
575 source_state_(source_state),
576 variable_name_(
"VariableNameNotSet"),
577 source_values_(
nullptr),
579 interface_reconstructor_(ir) {}
612 variable_name_ = variable_name;
613 gradients_ = gradient_field;
616 field_type_ = source_state_.field_type(Entity_kind::NODE, variable_name);
618 if (field_type_ == Field_type::MESH_FIELD) {
619 source_state_.mesh_get_data(Entity_kind::NODE, variable_name, &source_values_);
621 std::cerr <<
"Sorry: cannot remap node-centered multi-material data.";
622 std::cerr << std::endl;
644 std::vector<Weights_t>
const& sources_and_weights)
const {
646 if (sources_and_weights.empty())
649 auto const& gradient_field = *gradients_;
650 double total_value = 0.;
651 double normalization = 0.;
657 for (
auto&& current : sources_and_weights) {
658 int src_node = current.entityID;
659 auto intersect_weights = current.weights;
660 double intersect_volume = intersect_weights[0];
662 if (fabs(intersect_volume) <= num_tols_.min_absolute_volume)
667 Point<D> source_coord;
668 source_mesh_.node_get_coordinates(src_node, &source_coord);
670 Point<D> intersect_centroid;
672 for (
int k = 0; k < D; ++k)
673 intersect_centroid[k] = intersect_weights[1 + k] / intersect_volume;
675 Vector<D> gradient = gradient_field[src_node];
676 Vector<D> dr = intersect_centroid - source_coord;
677 CoordSys::modify_line_element(dr, source_coord);
679 double value = source_values_[src_node] + dot(gradient, dr);
680 value *= intersect_volume;
681 total_value += value;
682 normalization += intersect_volume;
696 return nb_summed ? total_value / normalization : 0.;
702 SourceMeshType
const& source_mesh_;
703 TargetMeshType
const& target_mesh_;
704 SourceStateType
const& source_state_;
705 std::string variable_name_;
706 double const* source_values_;
708 int material_id_ = 0;
710 Field_type field_type_ = Field_type::UNKNOWN_TYPE_FIELD;
712 std::shared_ptr<InterfaceReconstructor> interface_reconstructor_;
718 #endif // PORTAGE_INTERPOLATE_INTERPOLATE_2ND_ORDER_H_ void set_material(int m)
Set the material we are operating on.
Definition: interpolate_2nd_order.h:144
Portage::Interpolate_2ndOrder< D, Entity_kind::NODE, SourceMeshType, TargetMeshType, SourceStateType, TargetStateType, double, InterfaceReconstructorType, Matpoly_Splitter, Matpoly_Clipper, CoordSys >::set_interpolation_variable void set_interpolation_variable(std::string const variable_name, Portage::vector< Vector< D >> *gradient_field=nullptr)
Set the name of the interpolation variable and the gradient field.
Definition: interpolate_2nd_order.h:609
std::vector< T > vector
Definition: portage.h:238
Intersection and other tolerances to handle tiny values.
Definition: portage.h:152
Interpolate_2ndOrder(SourceMeshType const &source_mesh, TargetMeshType const &target_mesh, SourceStateType const &source_state, NumericTolerances_t num_tols)
Constructor without interface reconstructor.
Definition: interpolate_2nd_order.h:89
Compute limited gradient of a field or components of a field.
Definition: gradient.h:52
Interpolate_2ndOrder & operator=(const Interpolate_2ndOrder &other)=delete
Assignment operator (disabled).
Manages source and target sub-meshes for part-by-part remap.
Manages source and target sub-meshes for part-by-part remap. It detects boundaries mismatch and provi...
Definition: parts.h:234
Portage::Interpolate_2ndOrder< D, Entity_kind::NODE, SourceMeshType, TargetMeshType, SourceStateType, TargetStateType, double, InterfaceReconstructorType, Matpoly_Splitter, Matpoly_Clipper, CoordSys >::set_material void set_material(int m)
Set the material we are operating on.
Definition: interpolate_2nd_order.h:601
Portage::Interpolate_2ndOrder< D, Entity_kind::CELL, SourceMeshType, TargetMeshType, SourceStateType, TargetStateType, double, InterfaceReconstructorType, Matpoly_Splitter, Matpoly_Clipper, CoordSys >::set_material void set_material(int m)
Set the material we are operating on.
Definition: interpolate_2nd_order.h:320
Portage::Interpolate_2ndOrder< D, Entity_kind::CELL, SourceMeshType, TargetMeshType, SourceStateType, TargetStateType, double, InterfaceReconstructorType, Matpoly_Splitter, Matpoly_Clipper, CoordSys >::operator() double operator()(int cell_id, std::vector< Weights_t > const &sources_and_weights) const
Functor to compute the interpolation of cell values.
Definition: interpolate_2nd_order.h:359
double operator()(int const targetCellID, std::vector< Weights_t > const &sources_and_weights) const
Functor to do the actual interpolate calculation.
Definition: interpolate_2nd_order.h:174
Definition: coredriver.h:42
Portage::Interpolate_2ndOrder< D, Entity_kind::NODE, SourceMeshType, TargetMeshType, SourceStateType, TargetStateType, double, InterfaceReconstructorType, Matpoly_Splitter, Matpoly_Clipper, CoordSys >::operator() double operator()(int node_id, std::vector< Weights_t > const &sources_and_weights) const
Functor to compute the interpolation of node values.
Definition: interpolate_2nd_order.h:643
~Interpolate_2ndOrder()=default
Destructor.
Portage::Interpolate_2ndOrder< D, Entity_kind::CELL, SourceMeshType, TargetMeshType, SourceStateType, TargetStateType, double, InterfaceReconstructorType, Matpoly_Splitter, Matpoly_Clipper, CoordSys >::set_interpolation_variable void set_interpolation_variable(std::string const &variable_name, const Portage::vector< Vector< D >> *gradient_field=nullptr)
Set the name of the interpolation variable and the gradient field.
Definition: interpolate_2nd_order.h:329
static constexpr int order
Definition: interpolate_2nd_order.h:183
Interpolate_2ndOrder does a 2nd order interpolation of scalars.
Definition: interpolate_2nd_order.h:70
Portage::Interpolate_2ndOrder< D, Entity_kind::NODE, SourceMeshType, TargetMeshType, SourceStateType, TargetStateType, double, InterfaceReconstructorType, Matpoly_Splitter, Matpoly_Clipper, CoordSys >::Interpolate_2ndOrder Interpolate_2ndOrder(SourceMeshType const &source_mesh, TargetMeshType const &target_mesh, SourceStateType const &source_state, NumericTolerances_t num_tols)
Constructor without interface reconstructor.
Definition: interpolate_2nd_order.h:547
void set_interpolation_variable(std::string const &variable_name, const Portage::vector< Vector< D >> *gradient_field=nullptr)
Set the name of the interpolation variable and the gradient field.
Definition: interpolate_2nd_order.h:153
Portage::Interpolate_2ndOrder< D, Entity_kind::CELL, SourceMeshType, TargetMeshType, SourceStateType, TargetStateType, double, InterfaceReconstructorType, Matpoly_Splitter, Matpoly_Clipper, CoordSys >::Interpolate_2ndOrder Interpolate_2ndOrder(SourceMeshType const &source_mesh, TargetMeshType const &target_mesh, SourceStateType const &source_state, NumericTolerances_t num_tols, const Parts *const parts=nullptr)
Constructor without interface reconstructor.
Definition: interpolate_2nd_order.h:262