OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
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* grid_points, 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", "PolynomialPatch grid_points_ was nullptr");
44 if (validity_region_ == nullptr)
46 "PolynomialPatch::PolynomialPatch",
47 "PolynomialPatch validity_region_ was nullptr");
48 if (points_.size() == 0) {
50 "PolynomialPatch::PolynomialPatch",
51 "Could not make PolynomialPatch with 0 length polynomials vector");
52 }
54 if (int(points_.size()) != end.toInteger()) {
56 "PolynomialPatch::PolynomialPatch",
57 "Could not make PolynomialPatch with bad length polynomials vector");
58 }
62 "PolynomialPatch::PolynomialPatch",
63 "PolynomialPatch validity_region_ has bad dimension");
64 }
65 value_dimension_ = points_[0]->ValueDimension();
66 for (size_t i = 0; i < points_.size(); ++i) {
67 if (points_[i] == nullptr)
69 "PolynomialPatch::PolynomialPatch",
70 "PolynomialPatch points_ element was nullptr");
71 if (points_[i]->PointDimension() != point_dimension_) {
73 "PolynomialPatch::PolynomialPatch",
74 "Polynomial with mismatched PointDimension in PolynomialPatch");
75 }
76 if (points_[i]->ValueDimension() != value_dimension_)
78 "PolynomialPatch::PolynomialPatch",
79 "Polynomial with mismatched ValueDimension in PolynomialPatch");
80 }
81 }
82
84 Mesh* new_mesh = nullptr;
85 if (grid_points_ != nullptr) {
86 new_mesh = grid_points_->clone();
87 }
88 Mesh* new_validity = nullptr;
89 if (validity_region_ != nullptr) {
90 new_validity = validity_region_->clone();
91 }
92 std::vector<SquarePolynomialVector*> new_points(points_.size());
93 for (size_t i = 0; i < points_.size(); ++i) {
94 if (points_[i] == nullptr) {
95 new_points[i] = nullptr;
96 } else {
97 new_points[i] = new SquarePolynomialVector(*points_[i]);
98 }
99 }
100 return new PolynomialPatch(new_mesh, new_validity, new_points);
101 }
102
104 : validity_region_(nullptr),
105 grid_points_(nullptr),
106 points_(),
107 point_dimension_(0),
108 value_dimension_(0) {}
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
117 void 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} // namespace interpolation
virtual void getPosition(double *point) const
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
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.