7 #ifndef PORTAGE_DRIVER_MMDRIVER_H_ 8 #define PORTAGE_DRIVER_MMDRIVER_H_ 16 #include <type_traits> 22 #include "tangram/driver/driver.h" 33 #include "wonton/mesh/flat/flat_mesh_wrapper.h" 34 #include "wonton/state/flat/flat_state_mm_wrapper.h" 35 #include "wonton/support/Point.h" 36 #include "wonton/state/state_vector_multi.h" 40 #ifdef PORTAGE_ENABLE_MPI 87 template <
template <
int, Entity_kind,
class,
class>
class Search,
88 template <Entity_kind,
class,
class,
class,
89 template <
class,
int,
class,
class>
class,
91 template<int, Entity_kind, class, class, class, class, class,
92 template<class, int, class, class> class,
93 class, class, class=Wonton::DefaultCoordSys
96 class SourceMesh_Wrapper,
97 class SourceState_Wrapper,
98 class TargetMesh_Wrapper = SourceMesh_Wrapper,
99 class TargetState_Wrapper = SourceState_Wrapper,
100 template <
class,
int,
class,
class>
class InterfaceReconstructorType = DummyInterfaceReconstructor,
101 class Matpoly_Splitter = void,
102 class Matpoly_Clipper =
void>
108 template<
typename SourceMesh>
109 using InterfaceReconstructor = Tangram::Driver<InterfaceReconstructorType, D,
110 SourceMesh, Matpoly_Splitter,
125 SourceState_Wrapper
const& sourceState,
126 TargetMesh_Wrapper
const& targetMesh,
127 TargetState_Wrapper& targetState)
128 : source_mesh_(sourceMesh),
129 target_mesh_(targetMesh),
130 source_state_(sourceState),
131 target_state_(targetState),
132 dim_(sourceMesh.space_dimension()) {
133 assert(sourceMesh.space_dimension() == targetMesh.space_dimension());
156 set_remap_var_names(remap_var_names, remap_var_names);
168 std::vector<std::string>
const & source_remap_var_names,
169 std::vector<std::string>
const & target_remap_var_names) {
171 assert(source_remap_var_names.size() == target_remap_var_names.size());
174 source_target_varname_map_.clear();
176 int nvars = source_remap_var_names.size();
178 for (
int i = 0; i < nvars; ++i) {
179 Entity_kind srckind = source_state_.get_entity(source_remap_var_names[i]);
180 Entity_kind trgkind = target_state_.get_entity(target_remap_var_names[i]);
181 if (trgkind == Entity_kind::UNKNOWN_KIND)
184 assert(srckind == trgkind);
188 for (
int i = 0; i < nvars; i++) {
189 source_target_varname_map_[source_remap_var_names[i]] = target_remap_var_names[i];
194 partial_fixup_types_[target_remap_var_names[i]] =
196 empty_fixup_types_[target_remap_var_names[i]] =
206 for (
auto const& stpair : source_target_varname_map_) {
207 std::string
const& source_var_name = stpair.first;
208 limiters_[source_var_name] = limiter;
218 for (
auto const& stpair : source_target_varname_map_) {
219 std::string
const& source_var_name = stpair.first;
220 bnd_limiters_[source_var_name] = bnd_limiter;
231 limiters_[source_var_name] = limiter;
242 bnd_limiters_[source_var_name] = bnd_limiter;
252 for (
auto const& stpair : source_target_varname_map_) {
253 std::string
const& target_var_name = stpair.second;
254 partial_fixup_types_[target_var_name] = fixup_type;
267 partial_fixup_types_[target_var_name] = fixup_type;
276 for (
auto const& stpair : source_target_varname_map_) {
277 std::string
const& target_var_name = stpair.second;
278 empty_fixup_types_[target_var_name] = fixup_type;
290 empty_fixup_types_[target_var_name] = fixup_type;
295 max_fixup_iter_ = maxiter;
300 const double min_absolute_volume) {
301 num_tols_.min_absolute_distance = min_absolute_distance;
302 num_tols_.min_absolute_volume = min_absolute_volume;
303 num_tols_.user_tolerances =
true;
308 num_tols_ = num_tols;
317 T lower_bound, T upper_bound) {
318 if (
typeid(T) ==
typeid(
double)) {
319 double_lower_bounds_[target_var_name] = lower_bound;
320 double_upper_bounds_[target_var_name] = upper_bound;
322 std::cerr <<
"Type not supported \n";
331 T conservation_tol) {
332 if (
typeid(T) ==
typeid(
double))
333 conservation_tol_[target_var_name] = conservation_tol;
335 std::cerr <<
"Type not supported \n";
351 void set_reconstructor_options(
bool all_convex,
352 const std::vector<Tangram::IterativeMethodTolerances_t> &tols =
353 std::vector<Tangram::IterativeMethodTolerances_t>()){
354 reconstructor_tols_ = tols;
355 reconstructor_all_convex_ = all_convex;
366 std::vector<std::string> source_var_names;
367 source_var_names.reserve(source_target_varname_map_.size());
368 for (
auto const& stname_pair : source_target_varname_map_)
369 source_var_names.push_back(stname_pair.first);
370 return source_var_names;
379 std::vector<std::string> target_var_names;
380 target_var_names.reserve(source_target_varname_map_.size());
381 for (
auto const& stname_pair : source_target_varname_map_)
382 target_var_names.push_back(stname_pair.second);
383 return target_var_names;
390 unsigned int dim()
const {
409 template<
class SourceMesh_Wrapper2,
class SourceState_Wrapper2>
410 int cell_remap(SourceMesh_Wrapper2
const & source_mesh2,
411 SourceState_Wrapper2
const & source_state2,
412 std::vector<std::string>
const &src_meshvar_names,
413 std::vector<std::string>
const &trg_meshvar_names,
414 std::vector<std::string>
const &src_matvar_names,
415 std::vector<std::string>
const &trg_matvar_names,
416 Wonton::Executor_type
const *executor =
nullptr);
431 template<
class SourceMesh_Wrapper2,
class SourceState_Wrapper2>
432 int node_remap(SourceMesh_Wrapper2
const & source_mesh2,
433 SourceState_Wrapper2
const & source_state2,
434 std::vector<std::string>
const &src_meshvar_names,
435 std::vector<std::string>
const &trg_meshvar_names,
436 Wonton::Executor_type
const *executor =
nullptr);
454 template<
class SourceState_Wrapper2,Entity_kind onwhat>
456 std::vector<std::string>
const& src_meshvar_names,
457 std::vector<std::string>
const& trg_meshvar_names,
458 Wonton::Executor_type
const *executor =
nullptr) {
460 #ifdef PORTAGE_ENABLE_MPI 461 MPI_Comm mycomm = MPI_COMM_NULL;
462 auto mpiexecutor =
dynamic_cast<Wonton::MPIExecutor_type
const *
>(executor);
463 if (mpiexecutor && mpiexecutor->mpicomm != MPI_COMM_NULL) {
464 mycomm = mpiexecutor->mpicomm;
468 int const nvars = src_meshvar_names.size();
471 for (
int i = 0; i < nvars; i++) {
473 auto& src_var = src_meshvar_names[i];
474 auto& trg_var = trg_meshvar_names[i];
478 if (not double_lower_bounds_.count(trg_var) or
479 not double_upper_bounds_.count(trg_var)) {
485 int nsrcents = source_mesh_.num_entities(onwhat,
486 Entity_type::PARALLEL_OWNED);
488 double const *source_data;
489 source_state_.mesh_get_data(onwhat, src_var, &source_data);
490 double lower_bound = *std::min_element(source_data, source_data + nsrcents);
491 double upper_bound = *std::max_element(source_data, source_data + nsrcents);
493 #ifdef PORTAGE_ENABLE_MPI 494 if (mycomm != MPI_COMM_NULL) {
495 double global_bounds[2] = { 0.0, 0.0 };
496 MPI_Allreduce(&lower_bound, global_bounds+0, 1, MPI_DOUBLE, MPI_MIN, mycomm);
497 MPI_Allreduce(&upper_bound, global_bounds+1, 1, MPI_DOUBLE, MPI_MAX, mycomm);
498 lower_bound = global_bounds[0];
499 upper_bound = global_bounds[1];
503 double relbounddiff = std::abs((upper_bound-lower_bound)/lower_bound);
504 if (relbounddiff < consttol_) {
508 lower_bound -= 0.5*lower_bound;
509 upper_bound += 0.5*upper_bound;
513 set_remap_var_bounds(trg_var, lower_bound, upper_bound);
517 if (not conservation_tol_.count(trg_var)) {
518 set_conservation_tolerance(trg_var, DEFAULT_NUMERIC_TOLERANCES<D>.relative_conservation_eps);
529 int run(Wonton::Executor_type
const *executor =
nullptr,
530 std::string *errmsg =
nullptr) {
535 bool distributed =
false;
539 #ifdef PORTAGE_ENABLE_MPI 540 MPI_Comm mycomm = MPI_COMM_NULL;
541 auto mpiexecutor =
dynamic_cast<Wonton::MPIExecutor_type
const *
>(executor);
542 if (mpiexecutor && mpiexecutor->mpicomm != MPI_COMM_NULL) {
543 mycomm = mpiexecutor->mpicomm;
544 MPI_Comm_rank(mycomm, &comm_rank);
545 MPI_Comm_size(mycomm, &nprocs);
552 std::cout <<
"in MMDriver::run()...\n";
554 int numTargetCells = target_mesh_.num_owned_cells();
555 std::cout <<
"Number of target cells in target mesh on rank " 557 << numTargetCells << std::endl;
560 std::vector<std::string> src_meshvar_names, src_matvar_names;
561 std::vector<std::string> trg_meshvar_names, trg_matvar_names;
567 for (
auto const& stpair : source_target_varname_map_) {
568 std::string
const& srcvarname = stpair.first;
569 Entity_kind onwhat = source_state_.get_entity(srcvarname);
570 if (onwhat == CELL) {
574 std::string
const& trgvarname = stpair.second;
576 Field_type ftype = source_state_.field_type(onwhat, srcvarname);
578 if (ftype == Field_type::MESH_FIELD) {
579 src_meshvar_names.push_back(srcvarname);
580 trg_meshvar_names.push_back(trgvarname);
581 }
else if (ftype == Field_type::MULTIMATERIAL_FIELD) {
582 src_matvar_names.push_back(srcvarname);
583 trg_matvar_names.push_back(trgvarname);
593 #ifdef PORTAGE_ENABLE_MPI 598 Flat_Mesh_Wrapper<> source_mesh_flat;
599 Flat_State_Wrapper<Flat_Mesh_Wrapper<>> source_state_flat(source_mesh_flat);
601 bool redistributed_source =
false;
603 MPI_Bounding_Boxes distributor(mpiexecutor);
604 if (distributor.is_redistribution_needed(source_mesh_, target_mesh_)) {
607 source_mesh_flat.initialize(source_mesh_);
611 std::vector<std::string> source_remap_var_names;
612 for (
auto & stpair : source_target_varname_map_)
613 source_remap_var_names.push_back(stpair.first);
614 source_state_flat.initialize(source_state_, source_remap_var_names);
616 distributor.distribute(source_mesh_flat, source_state_flat,
617 target_mesh_, target_state_);
619 redistributed_source =
true;
623 std::cout <<
"Redistribution Time Rank " << comm_rank <<
" (s): " <<
624 tot_seconds_dist << std::endl;
629 if (redistributed_source) {
634 cell_remap<Flat_Mesh_Wrapper<>, Flat_State_Wrapper<Flat_Mesh_Wrapper<>>>
635 (source_mesh_flat, source_state_flat,
636 src_meshvar_names, trg_meshvar_names,
637 src_matvar_names, trg_matvar_names,
646 cell_remap<SourceMesh_Wrapper, SourceState_Wrapper>
647 (source_mesh_, source_state_,
648 src_meshvar_names, trg_meshvar_names,
649 src_matvar_names, trg_matvar_names,
659 src_meshvar_names.clear(); src_matvar_names.clear();
660 trg_meshvar_names.clear(); trg_matvar_names.clear();
662 for (
auto const& stpair : source_target_varname_map_) {
663 std::string
const& srcvarname = stpair.first;
664 Entity_kind onwhat = source_state_.get_entity(srcvarname);
665 if (onwhat == NODE) {
666 std::string
const& trgvarname = stpair.second;
668 Field_type ftype = source_state_.field_type(onwhat, srcvarname);
670 if (ftype == Field_type::MESH_FIELD) {
671 src_meshvar_names.push_back(srcvarname);
672 trg_meshvar_names.push_back(trgvarname);
673 }
else if (ftype == Field_type::MULTIMATERIAL_FIELD)
674 std::cerr <<
"Cannot handle multi-material fields on nodes\n";
678 if (not src_meshvar_names.empty()) {
679 #ifdef PORTAGE_ENABLE_MPI 680 if (redistributed_source)
681 node_remap<Flat_Mesh_Wrapper<>, Flat_State_Wrapper<Flat_Mesh_Wrapper<>>>
682 (source_mesh_flat, source_state_flat,
683 src_meshvar_names, trg_meshvar_names,
687 node_remap<SourceMesh_Wrapper, SourceState_Wrapper>
688 (source_mesh_, source_state_,
689 src_meshvar_names, trg_meshvar_names,
699 SourceMesh_Wrapper
const& source_mesh_;
700 TargetMesh_Wrapper
const& target_mesh_;
701 SourceState_Wrapper
const& source_state_;
702 TargetState_Wrapper& target_state_;
703 std::unordered_map<std::string, std::string> source_target_varname_map_;
704 std::unordered_map<std::string, Limiter_type> limiters_;
705 std::unordered_map<std::string, Boundary_Limiter_type> bnd_limiters_;
706 std::unordered_map<std::string, Partial_fixup_type> partial_fixup_types_;
707 std::unordered_map<std::string, Empty_fixup_type> empty_fixup_types_;
708 std::unordered_map<std::string, double> double_lower_bounds_;
709 std::unordered_map<std::string, double> double_upper_bounds_;
710 std::unordered_map<std::string, double> conservation_tol_;
713 int max_fixup_iter_ = 5;
731 std::vector<Tangram::IterativeMethodTolerances_t> reconstructor_tols_;
732 bool reconstructor_all_convex_ =
true;
741 template <
template <
int, Entity_kind,
class,
class>
class Search,
742 template <Entity_kind,
class,
class,
class,
743 template <
class,
int,
class,
class>
class,
745 template<int, Entity_kind, class, class, class, class, class,
746 template<class, int, class, class> class,
747 class, class, class=Wonton::DefaultCoordSys>
750 class SourceMesh_Wrapper,
751 class SourceState_Wrapper,
752 class TargetMesh_Wrapper,
753 class TargetState_Wrapper,
754 template <class, int, class, class> class InterfaceReconstructorType,
755 class Matpoly_Splitter,
756 class Matpoly_Clipper>
757 template<class SourceMesh_Wrapper2, class SourceState_Wrapper2>
758 int MMDriver<Search, Intersect, Interpolate, D,
759 SourceMesh_Wrapper, SourceState_Wrapper,
760 TargetMesh_Wrapper, TargetState_Wrapper,
761 InterfaceReconstructorType, Matpoly_Splitter,
763 >::cell_remap(SourceMesh_Wrapper2 const & source_mesh2,
764 SourceState_Wrapper2 const & source_state2,
765 std::vector<std::string> const &src_meshvar_names,
766 std::vector<std::string> const &trg_meshvar_names,
767 std::vector<std::string> const &src_matvar_names,
768 std::vector<std::string> const &trg_matvar_names,
769 Wonton::Executor_type const *executor) {
774 #ifdef PORTAGE_ENABLE_MPI 775 MPI_Comm mycomm = MPI_COMM_NULL;
776 auto mpiexecutor =
dynamic_cast<Wonton::MPIExecutor_type
const *
>(executor);
777 if (mpiexecutor && mpiexecutor->mpicomm != MPI_COMM_NULL) {
778 mycomm = mpiexecutor->mpicomm;
779 MPI_Comm_rank(mycomm, &comm_rank);
780 MPI_Comm_size(mycomm, &nprocs);
785 float tot_seconds = 0.0;
786 float tot_seconds_srch = 0.0;
787 float tot_seconds_xsect = 0.0;
788 float tot_seconds_interp = 0.0;
792 std::vector<std::string> source_remap_var_names;
793 for (
auto & stpair : source_target_varname_map_)
794 source_remap_var_names.push_back(stpair.first);
798 if (reconstructor_tols_.empty()) {
799 reconstructor_tols_ = { {1000, num_tols_.min_absolute_distance,
800 num_tols_.min_absolute_volume},
801 {100, num_tols_.min_absolute_distance,
802 num_tols_.min_absolute_distance} };
806 else if (!num_tols_.user_tolerances) {
807 num_tols_.min_absolute_distance = reconstructor_tols_[0].arg_eps;
808 num_tols_.min_absolute_volume = reconstructor_tols_[0].fun_eps;
815 SourceMesh_Wrapper2, SourceState_Wrapper2,
816 TargetMesh_Wrapper, TargetState_Wrapper,
817 InterfaceReconstructorType,
818 Matpoly_Splitter, Matpoly_Clipper>
819 coredriver_cell(source_mesh2, source_state2, target_mesh_, target_state_, executor);
821 coredriver_cell.set_num_tols(num_tols_);
823 coredriver_cell.set_interface_reconstructor_options(reconstructor_all_convex_,
824 reconstructor_tols_);
828 auto candidates = coredriver_cell.template search<Portage::SearchKDTree>();
832 int nmats = source_state2.num_materials();
839 auto source_ents_and_weights =
840 coredriver_cell.template intersect_meshes<Intersect>(candidates);
845 coredriver_cell.check_mismatch(source_ents_and_weights);
848 if (coredriver_cell.has_mismatch())
849 compute_bounds<SourceState_Wrapper2, CELL>
850 (source_state2, src_meshvar_names, trg_meshvar_names, executor);
853 int nvars = src_meshvar_names.size();
857 if (comm_rank == 0) {
858 std::cout <<
"Number of mesh variables on cells to remap is " <<
865 using Interpolator = Interpolate<D, CELL,
866 SourceMesh_Wrapper2, TargetMesh_Wrapper,
867 SourceState_Wrapper2, TargetState_Wrapper,
868 double, InterfaceReconstructorType,
869 Matpoly_Splitter, Matpoly_Clipper>;
872 for (
int i = 0; i < nvars; ++i) {
873 std::string
const& srcvar = src_meshvar_names[i];
874 std::string
const& trgvar = trg_meshvar_names[i];
876 if (Interpolator::order == 2) {
878 auto limiter = (limiters_.count(srcvar) ? limiters_[srcvar] :
DEFAULT_LIMITER);
879 auto bndlimit = (bnd_limiters_.count(srcvar) ? bnd_limiters_[srcvar] :
DEFAULT_BND_LIMITER);
883 coredriver_cell.template interpolate_mesh_var<double, Interpolate>
884 (srcvar, trgvar, source_ents_and_weights, &gradients);
887 coredriver_cell.template interpolate_mesh_var<double, Interpolate>
888 (srcvar, trgvar, source_ents_and_weights);
892 if (coredriver_cell.has_mismatch()) {
893 coredriver_cell.fix_mismatch(srcvar, trgvar,
894 double_lower_bounds_[trgvar],
895 double_upper_bounds_[trgvar],
896 conservation_tol_[trgvar],
898 partial_fixup_types_[trgvar],
899 empty_fixup_types_[trgvar]
913 auto source_ents_and_weights_mat =
914 coredriver_cell.template intersect_materials<Intersect>(candidates);
916 int nmatvars = src_matvar_names.size();
917 std::vector<Portage::vector<Vector<D>>> matgradients(nmats);
919 for (
int i = 0; i < nmatvars; ++i) {
920 std::string
const& srcvar = src_matvar_names[i];
921 std::string
const& trgvar = trg_matvar_names[i];
923 if (Interpolator::order == 2) {
925 auto limiter = (limiters_.count(srcvar) ? limiters_[srcvar] :
DEFAULT_LIMITER);
926 auto bndlimit = (bnd_limiters_.count(srcvar) ? bnd_limiters_[srcvar] :
DEFAULT_BND_LIMITER);
928 for (
int m = 0; m < nmats; m++) {
930 coredriver_cell.compute_source_gradient(src_matvar_names[i],
931 limiter, bndlimit, m);
934 coredriver_cell.template interpolate_mat_var<double, Interpolate>
935 (srcvar, trgvar, source_ents_and_weights_mat, &matgradients);
938 coredriver_cell.template interpolate_mat_var<double, Interpolate>
939 (srcvar, trgvar, source_ents_and_weights_mat);
947 tot_seconds = tot_seconds_srch + tot_seconds_xsect + tot_seconds_interp;
949 std::cout <<
"Transform Time for Cell remap on Rank " <<
950 comm_rank <<
" (s): " << tot_seconds << std::endl;
951 std::cout <<
" Search Time Rank " << comm_rank <<
" (s): " <<
952 tot_seconds_srch << std::endl;
953 std::cout <<
" Intersect Time Rank " << comm_rank <<
" (s): " <<
954 tot_seconds_xsect << std::endl;
955 std::cout <<
" Interpolate Time Rank " << comm_rank <<
" (s): " <<
956 tot_seconds_interp << std::endl;
966 template <
template <
int, Entity_kind,
class,
class>
class Search,
967 template <Entity_kind,
class,
class,
class,
968 template <
class,
int,
class,
class>
class,
969 class,
class>
class Intersect,
970 template<int, Entity_kind, class, class, class, class, class,
971 template<class, int, class, class> class,
972 class, class, class=Wonton::DefaultCoordSys>
975 class SourceMesh_Wrapper,
976 class SourceState_Wrapper,
977 class TargetMesh_Wrapper,
978 class TargetState_Wrapper,
979 template <class, int, class, class> class InterfaceReconstructorType,
980 class Matpoly_Splitter,
981 class Matpoly_Clipper>
982 template<class SourceMesh_Wrapper2, class SourceState_Wrapper2>
983 int MMDriver<Search, Intersect, Interpolate, D,
984 SourceMesh_Wrapper, SourceState_Wrapper,
985 TargetMesh_Wrapper, TargetState_Wrapper,
986 InterfaceReconstructorType, Matpoly_Splitter,
988 >::node_remap(SourceMesh_Wrapper2 const & source_mesh2,
989 SourceState_Wrapper2 const & source_state2,
990 std::vector<std::string> const &src_meshvar_names,
991 std::vector<std::string> const &trg_meshvar_names,
992 Wonton::Executor_type const *executor) {
997 #ifdef PORTAGE_ENABLE_MPI 998 MPI_Comm mycomm = MPI_COMM_NULL;
999 auto mpiexecutor =
dynamic_cast<Wonton::MPIExecutor_type
const *
>(executor);
1000 if (mpiexecutor && mpiexecutor->mpicomm != MPI_COMM_NULL) {
1001 mycomm = mpiexecutor->mpicomm;
1002 MPI_Comm_rank(mycomm, &comm_rank);
1003 MPI_Comm_size(mycomm, &nprocs);
1008 float tot_seconds = 0.0;
1009 float tot_seconds_srch = 0.0;
1010 float tot_seconds_xsect = 0.0;
1011 float tot_seconds_interp = 0.0;
1015 std::vector<std::string> source_remap_var_names;
1016 for (
auto & stpair : source_target_varname_map_)
1017 source_remap_var_names.push_back(stpair.first);
1023 if (!num_tols_.user_tolerances && (!reconstructor_tols_.empty()) ) {
1024 num_tols_.min_absolute_distance = reconstructor_tols_[0].arg_eps;
1025 num_tols_.min_absolute_volume = reconstructor_tols_[0].fun_eps;
1028 if (reconstructor_tols_.empty()) {
1029 reconstructor_tols_ = { {1000, num_tols_.min_absolute_distance,
1030 num_tols_.min_absolute_volume},
1031 {100, num_tols_.min_absolute_distance,
1032 num_tols_.min_absolute_distance} };
1038 SourceMesh_Wrapper2, SourceState_Wrapper2,
1039 TargetMesh_Wrapper, TargetState_Wrapper>
1040 coredriver_node(source_mesh2, source_state2, target_mesh_, target_state_, executor);
1042 coredriver_node.set_num_tols(num_tols_);
1044 coredriver_node.set_interface_reconstructor_options(reconstructor_all_convex_,
1045 reconstructor_tols_);
1050 auto candidates = coredriver_node.template search<Portage::SearchKDTree>();
1059 auto source_ents_and_weights =
1060 coredriver_node.template intersect_meshes<Intersect>(candidates);
1065 coredriver_node.check_mismatch(source_ents_and_weights);
1068 if (coredriver_node.has_mismatch())
1069 compute_bounds<SourceState_Wrapper2, NODE>
1070 (source_state2, src_meshvar_names, trg_meshvar_names, executor);
1073 int nvars = src_meshvar_names.size();
1077 if (comm_rank == 0) {
1078 std::cout <<
"Number of mesh variables on nodes to remap is " <<
1085 using Interpolator = Interpolate<D, NODE,
1086 SourceMesh_Wrapper2, TargetMesh_Wrapper,
1087 SourceState_Wrapper2, TargetState_Wrapper,
1088 double, InterfaceReconstructorType,
1089 Matpoly_Splitter, Matpoly_Clipper>;
1091 for (
int i = 0; i < nvars; ++i) {
1092 std::string
const& srcvar = src_meshvar_names[i];
1093 std::string
const& trgvar = trg_meshvar_names[i];
1095 if (Interpolator::order == 2) {
1097 auto limiter = (limiters_.count(srcvar) ? limiters_[srcvar] :
DEFAULT_LIMITER);
1098 auto bndlimit = (bnd_limiters_.count(srcvar) ? bnd_limiters_[srcvar] :
DEFAULT_BND_LIMITER);
1100 gradients = coredriver_node.compute_source_gradient(srcvar, limiter, bndlimit);
1102 coredriver_node.template interpolate_mesh_var<double, Interpolate>
1103 (srcvar, trgvar, source_ents_and_weights, &gradients);
1106 coredriver_node.template interpolate_mesh_var<double, Interpolate>
1107 (srcvar, trgvar, source_ents_and_weights);
1111 if (coredriver_node.has_mismatch()) {
1112 coredriver_node.fix_mismatch(srcvar, trgvar,
1113 double_lower_bounds_[trgvar],
1114 double_upper_bounds_[trgvar],
1115 conservation_tol_[trgvar],
1117 partial_fixup_types_[trgvar],
1118 empty_fixup_types_[trgvar]
1125 tot_seconds = tot_seconds_srch + tot_seconds_xsect + tot_seconds_interp;
1127 std::cout <<
"Transform Time for Node remap on Rank " <<
1128 comm_rank <<
" (s): " << tot_seconds << std::endl;
1129 std::cout <<
" Search Time Rank " << comm_rank <<
" (s): " <<
1130 tot_seconds_srch << std::endl;
1131 std::cout <<
" Intersect Time Rank " << comm_rank <<
" (s): " <<
1132 tot_seconds_xsect << std::endl;
1133 std::cout <<
" Interpolate Time Rank " << comm_rank <<
" (s): " <<
1134 tot_seconds_interp << std::endl;
1142 #endif // PORTAGE_DRIVER_MMDRIVER_H_ void set_partial_fixup_type(Partial_fixup_type fixup_type)
set repair method in partially filled cells for all variables
Definition: mmdriver.h:251
void set_remap_var_names(std::vector< std::string > const &source_remap_var_names, std::vector< std::string > const &target_remap_var_names)
Specify the names of the variables to be interpolated.
Definition: mmdriver.h:167
std::vector< std::string > target_remap_var_names() const
Get the names of the variables to be remapped to the target mesh.
Definition: mmdriver.h:378
std::chrono::high_resolution_clock::time_point now()
Get current time.
Definition: timer.h:19
Boundary_Limiter_type
Boundary limiter type.
Definition: portage.h:91
constexpr Boundary_Limiter_type DEFAULT_BND_LIMITER
Definition: portage.h:94
void set_num_tols(const double min_absolute_distance, const double min_absolute_volume)
Set core numerical tolerances.
Definition: mmdriver.h:299
void set_bnd_limiter(Boundary_Limiter_type bnd_limiter)
set boundary limiter for all variables
Definition: mmdriver.h:217
std::vector< T > vector
Definition: portage.h:238
MMDriver provides the API to mapping multi-material data from one mesh to another.
Definition: mmdriver.h:103
void set_bnd_limiter(std::string const &source_var_name, Boundary_Limiter_type bnd_limiter)
set boundary limiter for a variable
Definition: mmdriver.h:241
Intersection and other tolerances to handle tiny values.
Definition: portage.h:152
float elapsed(std::chrono::high_resolution_clock::time_point &tic, bool reset=false)
Get elapsed time in seconds.
Definition: timer.h:27
void set_remap_var_bounds(std::string target_var_name, T lower_bound, T upper_bound)
set the bounds of variable to be remapped on target
Definition: mmdriver.h:316
void set_empty_fixup_type(std::string const &target_var_name, Empty_fixup_type fixup_type)
set repair method in empty cells for all variables
Definition: mmdriver.h:288
MMDriver(SourceMesh_Wrapper const &sourceMesh, SourceState_Wrapper const &sourceState, TargetMesh_Wrapper const &targetMesh, TargetState_Wrapper &targetState)
Constructor for running the interpolation driver.
Definition: mmdriver.h:124
Partial_fixup_type
Fixup options for partially filled cells.
Definition: portage.h:114
void set_empty_fixup_type(Empty_fixup_type fixup_type)
set repair method in empty cells for all variables
Definition: mmdriver.h:275
unsigned int dim() const
Get the dimensionality of the meshes.
Definition: mmdriver.h:390
double const epsilon
Numerical tolerance.
Definition: weight.h:34
Limiter_type
Limiter type.
Definition: portage.h:85
void set_limiter(Limiter_type limiter)
set limiter for all variables
Definition: mmdriver.h:205
void set_limiter(std::string const &source_var_name, Limiter_type limiter)
set limiter for a variable
Definition: mmdriver.h:230
Definition: portage.h:134
Definition: portage.h:114
std::vector< std::string > source_remap_var_names() const
Get the names of the variables to be remapped from the source mesh.
Definition: mmdriver.h:365
Definition: coredriver.h:42
void set_num_tols(const NumericTolerances_t &num_tols)
Set all numerical tolerances.
Definition: mmdriver.h:307
void set_remap_var_names(std::vector< std::string > const &remap_var_names)
Specify the names of the variables to be interpolated.
Definition: mmdriver.h:154
void set_conservation_tolerance(std::string target_var_name, T conservation_tol)
set conservation tolerance of variable to be remapped on target
Definition: mmdriver.h:330
void set_max_fixup_iter(int maxiter)
Definition: mmdriver.h:294
constexpr Limiter_type DEFAULT_LIMITER
Definition: portage.h:88
Core driver for remapping.
void set_partial_fixup_type(std::string const &target_var_name, Partial_fixup_type fixup_type)
set repair method in partially filled cells for all variables
Definition: mmdriver.h:265
Portage::vector< Vector< D > > compute_source_gradient(std::string const field_name, Limiter_type limiter_type=NOLIMITER, Boundary_Limiter_type boundary_limiter_type=BND_NOLIMITER, int material_id=0, const Part< SourceMesh, SourceState > *source_part=nullptr) const
Compute the gradient field of the given variable on source mesh.
Definition: coredriver.h:909
void Intersect(const IsotheticBBox< D > &box, const KDTree< D > *kdtree, std::vector< int > &pfound)
Definition: kdtree.h:439
CoreDriver - Core driver that remaps fields on a particular Entity_kind (ONWHAT) like CELL or NODE...
Definition: coredriver.h:64
Empty_fixup_type
Fixup options for empty cells.
Definition: portage.h:134
int run(Wonton::Executor_type const *executor=nullptr, std::string *errmsg=nullptr)
Execute the remapping process.
Definition: mmdriver.h:529
void compute_bounds(SourceState_Wrapper2 const &source_state2, std::vector< std::string > const &src_meshvar_names, std::vector< std::string > const &trg_meshvar_names, Wonton::Executor_type const *executor=nullptr)
Compute mismatch fixup bounds dynamically.
Definition: mmdriver.h:455