OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
PolynomialPatch.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, Chris Rogers
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * 1. Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * 2. Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * 3. Neither the name of STFC nor the names of its contributors may be used to
12 * endorse or promote products derived from this software without specific
13 * prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
29
32
33namespace interpolation {
35 Mesh* validity_region,
36 std::vector<SquarePolynomialVector*> polynomials) {
37 grid_points_ = grid_points;
38 validity_region_ = validity_region;
39 points_ = polynomials;
40 // validate input data
41 if (grid_points_ == nullptr)
43 "PolynomialPatch::PolynomialPatch",
44 "PolynomialPatch grid_points_ was nullptr");
45 if (validity_region_ == nullptr)
47 "PolynomialPatch::PolynomialPatch",
48 "PolynomialPatch validity_region_ was nullptr");
49 if (points_.size() == 0) {
51 "PolynomialPatch::PolynomialPatch",
52 "Could not make PolynomialPatch with 0 length polynomials vector");
53 }
55 if (int(points_.size()) != end.toInteger()) {
57 "PolynomialPatch::PolynomialPatch",
58 "Could not make PolynomialPatch with bad length polynomials vector"
59 );
60 }
64 "PolynomialPatch::PolynomialPatch",
65 "PolynomialPatch validity_region_ has bad dimension");
66 }
67 value_dimension_ = points_[0]->ValueDimension();
68 for (size_t i = 0; i < points_.size(); ++i) {
69 if (points_[i] == nullptr)
71 "PolynomialPatch::PolynomialPatch",
72 "PolynomialPatch points_ element was nullptr");
73 if (points_[i]->PointDimension() != point_dimension_) {
75 "PolynomialPatch::PolynomialPatch",
76 "Polynomial with mismatched PointDimension in PolynomialPatch");
77 }
78 if (points_[i]->ValueDimension() != value_dimension_)
80 "PolynomialPatch::PolynomialPatch",
81 "Polynomial with mismatched ValueDimension in PolynomialPatch");
82 }
83}
84
86 Mesh* new_mesh = nullptr;
87 if (grid_points_ != nullptr) {
88 new_mesh = grid_points_->clone();
89 }
90 Mesh* new_validity = nullptr;
91 if (validity_region_ != nullptr) {
92 new_validity = validity_region_->clone();
93 }
94 std::vector<SquarePolynomialVector*> new_points(points_.size());
95 for (size_t i = 0; i < points_.size(); ++i) {
96 if (points_[i] == nullptr) {
97 new_points[i] = nullptr;
98 } else {
99 new_points[i] = new SquarePolynomialVector(*points_[i]);
100 }
101 }
102 return new PolynomialPatch(new_mesh, new_validity, new_points);
103}
104
106 : validity_region_(nullptr), grid_points_(nullptr), points_(), point_dimension_(0),
107 value_dimension_(0) {
108}
109
111 delete grid_points_;
112 delete validity_region_;
113 for (size_t i = 0; i < points_.size(); ++i)
114 delete points_[i];
115}
116
117void PolynomialPatch::function(const double* point, double* value) const {
118 Mesh::Iterator nearest = grid_points_->getNearest(point);
119 std::vector<double> point_temp(point_dimension_);
120 std::vector<double> nearest_pos = nearest.getPosition();
121 for (size_t i = 0; i < point_dimension_; ++i)
122 point_temp[i] = point[i] - nearest_pos[i];
123 int points_index = nearest.toInteger();
124 points_[points_index]->F(&point_temp[0], value);
125}
126
128 Mesh::Iterator nearest = grid_points_->getNearest(point);
129 int points_index = nearest.toInteger();
130 return points_[points_index];
131}
132}
133
PartBunchBase< T, Dim >::ConstIterator end(PartBunchBase< T, Dim > const &bunch)
Base class for meshing routines.
Definition: Mesh.h:49
virtual int getPositionDimension() const =0
virtual Mesh::Iterator getNearest(const double *position) const =0
virtual Mesh::Iterator end() const =0
virtual Mesh * clone()=0
virtual void getPosition(double *point) const
std::vector< SquarePolynomialVector * > points_
virtual void function(const double *point, double *value) const
SquarePolynomialVector * getPolynomialVector(const double *point) const
SquarePolynomialVector describes a vector of multivariate polynomials.