7 #ifndef SRC_INTERPOLATE_INTERPOLATE_3RD_ORDER_H_ 8 #define SRC_INTERPOLATE_INTERPOLATE_3RD_ORDER_H_ 45 template<
int D, Entity_kind on_what,
46 typename SourceMeshType,
47 typename TargetMeshType,
48 typename SourceStateType,
49 typename TargetStateType = SourceStateType>
62 TargetMeshType
const & target_mesh,
63 SourceStateType
const & source_state,
65 source_mesh_(source_mesh),
66 target_mesh_(target_mesh),
67 source_state_(source_state),
68 interp_var_name_(
"VariableNameNotSet"),
69 source_vals_(nullptr),
70 num_tols_(num_tols) {}
88 interp_var_name_ = interp_var_name;
92 source_state_.mesh_get_data(on_what, interp_var_name, &source_vals_);
97 limqfit(source_mesh_, source_state_, interp_var_name,
98 limiter_type, boundary_limiter_type);
101 int nentities = source_mesh_.end(on_what)-source_mesh_.begin(on_what);
102 quadfits_.resize(nentities);
114 quadfits_.begin(), limqfit);
136 std::vector<Weights_t>
const & sources_and_weights)
const {
139 std::cerr <<
"Interpolation operator not implemented for this entity type" 147 SourceMeshType
const & source_mesh_;
148 TargetMeshType
const & target_mesh_;
149 SourceStateType
const & source_state_;
150 std::string interp_var_name_;
151 double const * source_vals_;
170 typename SourceMeshType,
171 typename TargetMeshType,
172 typename SourceStateType,
173 typename TargetStateType>
175 D, Entity_kind::CELL,
176 SourceMeshType, TargetMeshType,
177 SourceStateType, TargetStateType> {
181 D, SourceMeshType, SourceStateType,
182 TargetMeshType, TargetStateType
187 TargetMeshType
const & target_mesh,
188 SourceStateType
const & source_state,
190 const Parts*
const parts =
nullptr) :
191 source_mesh_(source_mesh),
192 target_mesh_(target_mesh),
193 source_state_(source_state),
194 interp_var_name_(
"VariableNameNotSet"),
195 source_vals_(nullptr),
207 interp_var_name_ = interp_var_name;
211 source_state_.mesh_get_data(Entity_kind::CELL, interp_var_name, &source_vals_);
216 limqfit(source_mesh_, source_state_, interp_var_name_, limiter_type, boundary_limiter_type);
218 int nentities = source_mesh_.end(Entity_kind::CELL)-source_mesh_.begin(Entity_kind::CELL);
219 quadfits_.resize(nentities);
230 Portage::transform(source_mesh_.begin(Entity_kind::CELL), source_mesh_.end(Entity_kind::CELL),
231 quadfits_.begin(), limqfit);
268 std::vector<Weights_t>
const & sources_and_weights)
const {
270 int nsrccells = sources_and_weights.size();
273 std::cerr <<
"WARNING: No source cells contribute to target cell." <<
279 double totalval = 0.0;
286 for (
int j = 0; j < nsrccells; ++j) {
287 int srccell = sources_and_weights[j].entityID;
289 std::vector<double> xsect_weights = sources_and_weights[j].weights;
290 double xsect_volume = xsect_weights[0];
292 if (xsect_volume <= num_tols_.min_absolute_volume)
295 Point<D> srccell_centroid;
296 source_mesh_.cell_centroid(srccell, &srccell_centroid);
298 Point<D> xsect_centroid;
299 for (
int i = 0; i < D; ++i)
300 xsect_centroid[i] = xsect_weights[1+i]/xsect_volume;
302 Vector<D*(D+3)/2> quadfit = quadfits_[srccell];
303 Vector<D> vec = xsect_centroid - srccell_centroid;
304 Vector<D*(D+3)/2> dvec;
305 for (
int j = 0; j < D; ++j) {
309 for (
int k = 0; k <= j; ++k) {
310 dvec[j1] = dvec[k]*dvec[j];
315 double val = source_vals_[srccell] + dot(quadfit,dvec);
323 totalval /= target_mesh_.cell_volume(targetCellID);
331 SourceMeshType
const & source_mesh_;
332 TargetMeshType
const & target_mesh_;
333 SourceStateType
const & source_state_;
334 std::string interp_var_name_;
335 double const * source_vals_;
357 typename SourceMeshType,
358 typename TargetMeshType,
359 typename SourceStateType,
360 typename TargetStateType>
362 D, Entity_kind::NODE,
363 SourceMeshType, TargetMeshType,
364 SourceStateType, TargetStateType> {
368 TargetMeshType
const & target_mesh,
369 SourceStateType
const & source_state,
371 source_mesh_(source_mesh),
372 target_mesh_(target_mesh),
373 source_state_(source_state),
374 interp_var_name_(
"VariableNameNotSet"),
375 source_vals_(nullptr),
376 num_tols_(num_tols) {}
395 interp_var_name_ = interp_var_name;
399 source_state_.mesh_get_data(Entity_kind::NODE, interp_var_name, &source_vals_);
404 limqfit(source_mesh_, source_state_, interp_var_name, limiter_type, boundary_limiter_type);
406 int nentities = source_mesh_.end(Entity_kind::NODE)-source_mesh_.begin(Entity_kind::NODE);
407 quadfits_.resize(nentities);
418 Portage::transform(source_mesh_.begin(Entity_kind::NODE), source_mesh_.end(Entity_kind::NODE),
419 quadfits_.begin(), limqfit);
452 std::vector<Weights_t>
const & sources_and_weights)
const {
454 int nsrcnodes = sources_and_weights.size();
457 std::cerr <<
"WARNING: No source nodes contribute to target node." <<
463 double totalval = 0.0;
470 for (
int j = 0; j < nsrcnodes; ++j) {
471 int srcnode = sources_and_weights[j].entityID;
472 std::vector<double> xsect_weights = sources_and_weights[j].weights;
473 double xsect_volume = xsect_weights[0];
475 if (xsect_volume <= num_tols_.min_absolute_volume)
480 Point<D> srcnode_coord;
481 source_mesh_.node_get_coordinates(srcnode, &srcnode_coord);
483 Point<D> xsect_centroid;
484 for (
int i = 0; i < D; ++i)
486 xsect_centroid[i] = xsect_weights[1+i]/xsect_volume;
488 Vector<D*(D+3)/2> quadfit = quadfits_[srcnode];
489 Vector<D> vec = xsect_centroid - srcnode_coord;
490 Vector<D*(D+3)/2> dvec;
491 for (
int j = 0; j < D; ++j) {
495 for (
int k = 0; k <= j; ++k) {
496 dvec[j1] = dvec[k]*dvec[j];
501 double val = source_vals_[srcnode] + dot(quadfit,dvec);
508 totalval /= target_mesh_.dual_cell_volume(targetNodeID);
516 SourceMeshType
const & source_mesh_;
517 TargetMeshType
const & target_mesh_;
518 SourceStateType
const & source_state_;
519 std::string interp_var_name_;
520 double const * source_vals_;
529 #endif // SRC_INTERPOLATE_INTERPOLATE_3RD_ORDER_H_ Boundary_Limiter_type
Boundary limiter type.
Definition: portage.h:91
std::vector< T > vector
Definition: portage.h:238
OutputIterator transform(InputIterator first, InputIterator last, OutputIterator result, UnaryFunction op)
Definition: portage.h:250
Interpolate_3rdOrder does a 3rd order interpolation of scalars.
Definition: interpolate_3rd_order.h:50
Intersection and other tolerances to handle tiny values.
Definition: portage.h:152
Interpolate_3rdOrder(SourceMeshType const &source_mesh, TargetMeshType const &target_mesh, SourceStateType const &source_state, NumericTolerances_t num_tols, const Parts *const parts=nullptr)
Definition: interpolate_3rd_order.h:186
static constexpr int order
Definition: interpolate_3rd_order.h:144
void set_interpolation_variable(std::string const &interp_var_name, Limiter_type limiter_type=NOLIMITER, Boundary_Limiter_type boundary_limiter_type=BND_NOLIMITER, Portage::vector< Vector< D >> *gradients=nullptr)
Set the name of the interpolation variable and the limiter type.
Definition: interpolate_3rd_order.h:84
Interpolate_3rdOrder(SourceMeshType const &source_mesh, TargetMeshType const &target_mesh, SourceStateType const &source_state, NumericTolerances_t num_tols)
Constructor.
Definition: interpolate_3rd_order.h:61
Manages source and target sub-meshes for part-by-part remap.
Interpolate_3rdOrder(SourceMeshType const &source_mesh, TargetMeshType const &target_mesh, SourceStateType const &source_state, NumericTolerances_t num_tols)
Definition: interpolate_3rd_order.h:367
void set_interpolation_variable(std::string const &interp_var_name, Limiter_type limiter_type=NOLIMITER, Boundary_Limiter_type boundary_limiter_type=BND_NOLIMITER, Portage::vector< Vector< D >> *gradients=nullptr)
Set the name of the interpolation variable and the limiter type.
Definition: interpolate_3rd_order.h:202
Manages source and target sub-meshes for part-by-part remap. It detects boundaries mismatch and provi...
Definition: parts.h:234
Limiter_type
Limiter type.
Definition: portage.h:85
void set_interpolation_variable(std::string const &interp_var_name, Limiter_type limiter_type=NOLIMITER, Boundary_Limiter_type boundary_limiter_type=BND_NOLIMITER, Portage::vector< Vector< D >> *gradients=nullptr)
Set the name of the interpolation variable and the limiter type.
Definition: interpolate_3rd_order.h:390
Definition: coredriver.h:42
Compute limited quadfit of a field or components of a field.
Definition: quadfit.h:43
~Interpolate_3rdOrder()=default
Destructor.
Interpolate_3rdOrder & operator=(const Interpolate_3rdOrder &)=delete
Copy constructor (disabled)
double operator()(int const targetCellID, std::vector< Weights_t > const &sources_and_weights) const
Functor to do the actual interpolate calculation.
Definition: interpolate_3rd_order.h:135