Loading...
Searching...
No Matches
rbf.hpp
1/*---------------------------------------------------------------------------*\
2*
3* bitpit
4*
5* Copyright (C) 2015-2021 OPTIMAD engineering Srl
6*
7* -------------------------------------------------------------------------
8* License
9* This file is part of bitpit.
10*
11* bitpit is free software: you can redistribute it and/or modify it
12* under the terms of the GNU Lesser General Public License v3 (LGPL)
13* as published by the Free Software Foundation.
14*
15* bitpit is distributed in the hope that it will be useful, but WITHOUT
16* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18* License for more details.
19*
20* You should have received a copy of the GNU Lesser General Public License
21* along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22*
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_RBF_HPP__
26#define __BITPIT_RBF_HPP__
27
28#include "bitpit_discretization.hpp"
29#include <array>
30#include <set>
31#include <vector>
32
33namespace bitpit{
34
40enum class RBFBasisFunction {
41 CUSTOM = 0,
42 WENDLANDC2 = 1,
43 LINEAR = 2,
44 GAUSS90 = 3,
45 GAUSS95 = 4,
46 GAUSS99 = 5,
47 C1C0 = 6,
48 C2C0 = 7,
49 C0C1 = 8,
50 C1C1 = 9,
51 C2C1 = 10,
52 C0C2 = 11,
53 C1C2 = 12,
54 C2C2 = 13,
55 COSINUS = 14,
56 THINPLATE = 15,
57};
58
64enum class RBFMode {
65 INTERP = 1,
66 PARAM = 2
67};
68
77 class LinearPolynomial : public ReconstructionPolynomial
78 {
79private:
80 int m_dim;
81 int m_fields;
83 public:
84 LinearPolynomial();
85 void clear();
86 void setDimension(int dim);
87 void setDataCount(int fields);
88 void evalBasis(const double *x, double *basis);
89 void initialize();
90 };
91
92private:
93 int m_fields;
94 RBFMode m_mode;
95 std::vector<double> m_supportRadii;
96 RBFBasisFunction m_typef;
97 double (*m_fPtr)(double);
98
99 std::vector<double> m_error;
101protected:
102 std::vector<std::vector<double>> m_value;
103 std::vector<std::vector<double>> m_weight;
104 std::vector<bool> m_activeNodes;
108 std::vector<int> m_polyActiveBasis;
109 LinearPolynomial m_polynomial;
111public:
112 RBFKernel();
113 RBFKernel(const RBFKernel & other);
114
115 virtual ~RBFKernel() = default;
116
118 void setFunction(double (&funct)(double ));
119
121 int getDataCount();
122 int getActiveCount();
123 std::vector<int> getActiveSet();
124
125 void enablePolynomial(bool enable = true);
126 int getPolynomialDimension();
128
129 bool isActive(int );
130
131 bool activateNode(int );
132 bool activateNode(const std::vector<int> &);
133 void activateAllNodes();
134 bool deactivateNode(int );
135 bool deactivateNode(const std::vector<int> &);
136 void deactivateAllNodes();
137
138 void setSupportRadius(double);
139 void setSupportRadius(const std::vector<double> &);
140 double getSupportRadius();
141 double getSupportRadius(int);
142
143 void setMode(RBFMode mode);
145
146 void setDataToNode (int , const std::vector<double> &);
147 void setDataToAllNodes(int , const std::vector<double> &);
148
149 int addData();
150 int addData(const std::vector<double> &);
151 bool removeData(int);
152 bool removeData(std::vector<int> &);
153 void removeAllData();
154
155 void fitDataToNodes();
156 void fitDataToNodes(int);
157
158 std::vector<double> evalRBF(const std::array<double,3> &);
159 std::vector<double> evalRBF(int jnode);
160 double evalBasis(double);
161 double evalBasisPair(int i, int j);
162
163 int solve();
164 int greedy(double);
165
166 const std::vector<std::vector<double>> & getWeights() const;
167
168protected:
169 double evalError();
170 int addGreedyPoint();
171 int solveLSQ();
172 void swap(RBFKernel & x) noexcept;
173
174private:
175
176 virtual double calcDist(int i, int j) = 0;
177 virtual double calcDist(const std::array<double,3> & point, int j) = 0;
178 virtual std::vector<double> evalPolynomialBasis(int i) = 0;
179 virtual std::vector<double> evalPolynomialBasis(const std::array<double,3> &point) = 0;
180 virtual void initializePolynomialActiveBasis() = 0;
181 virtual void initializePolynomial() = 0;
182};
183
184class RBF : public RBFKernel {
185
186protected:
187 std::vector<std::array<double,3>> m_node;
189public:
190 ~RBF();
192 RBF(const RBF & other);
193 RBF & operator=(RBF other);
194
195 int getTotalNodesCount();
196
197 int addNode(const std::array<double,3> &);
198 std::vector<int> addNode(const std::vector<std::array<double,3>> &);
199 bool removeNode(int);
200 bool removeNode(std::vector<int> &);
201 void removeAllNodes();
202
203protected:
204 void swap(RBF & x) noexcept;
205
206private:
207 double calcDist(int i, int j) override;
208 double calcDist(const std::array<double,3> & point, int j) override;
209 void initializePolynomialActiveBasis() override;
210 void initializePolynomial() override;
211 std::vector<double> evalPolynomialBasis(int i) override;
212 std::vector<double> evalPolynomialBasis(const std::array<double, 3> &point) override;
213};
214
219namespace rbf
220{
221 double wendlandc2(double);
222 double linear(double);
223 double gauss90(double);
224 double gauss95(double);
225 double gauss99(double);
226 double c1c0(double);
227 double c2c0(double);
228 double c0c1(double);
229 double c1c1(double);
230 double c2c1(double);
231 double c0c2(double);
232 double c1c2(double);
233 double c2c2(double);
234 double cosinus(double);
235 double thinplate(double);
236} // namespace rbf
237}
238
239#endif
Base class to handle Radial Basis Function with a large set of nodes.
Definition rbf.hpp:69
bool deactivateNode(int)
Definition rbf.cpp:335
std::vector< std::vector< double > > m_weight
Definition rbf.hpp:103
void enablePolynomial(bool enable=true)
Definition rbf.cpp:1100
void setMode(RBFMode mode)
Definition rbf.cpp:432
bool m_polyEnabled
Definition rbf.hpp:107
bool activateNode(int)
Definition rbf.cpp:294
void removeAllData()
Definition rbf.cpp:582
double evalError()
Definition rbf.cpp:940
std::vector< std::vector< double > > m_value
Definition rbf.hpp:102
void swap(RBFKernel &x) noexcept
Definition rbf.cpp:103
double getSupportRadius()
Definition rbf.cpp:397
int greedy(double)
Definition rbf.cpp:788
void setSupportRadius(double)
Definition rbf.cpp:375
void setFunction(RBFBasisFunction)
Definition rbf.cpp:125
int getDataCount()
Definition rbf.cpp:236
double evalBasis(double)
Definition rbf.cpp:884
const std::vector< std::vector< double > > & getWeights() const
Definition rbf.cpp:842
RBFBasisFunction getFunctionType()
Definition rbf.cpp:225
int addGreedyPoint()
Definition rbf.cpp:908
RBFMode getMode()
Definition rbf.cpp:423
int getActiveCount()
Definition rbf.cpp:245
std::vector< double > evalRBF(const std::array< double, 3 > &)
Definition rbf.cpp:597
void activateAllNodes()
Definition rbf.cpp:325
std::vector< int > m_polyActiveBasis
Definition rbf.hpp:108
double evalBasisPair(int i, int j)
Definition rbf.cpp:897
std::vector< int > getActiveSet()
Definition rbf.cpp:259
void setDataToNode(int, const std::vector< double > &)
Definition rbf.cpp:444
std::vector< bool > m_activeNodes
Definition rbf.hpp:104
void setDataToAllNodes(int, const std::vector< double > &)
Definition rbf.cpp:476
LinearPolynomial m_polynomial
Definition rbf.hpp:109
bool removeData(int)
Definition rbf.cpp:543
void fitDataToNodes()
Definition rbf.cpp:856
bool isActive(int)
Definition rbf.cpp:280
void deactivateAllNodes()
Definition rbf.cpp:366
int getPolynomialWeightsCount()
Definition rbf.cpp:1108
Class to handle Radial Basis Function with a large set of 3D points as nodes.
Definition rbf.hpp:184
bool removeNode(int)
Definition rbf.cpp:1311
void swap(RBF &x) noexcept
Definition rbf.cpp:1249
int getTotalNodesCount()
Definition rbf.cpp:1260
void removeAllNodes()
Definition rbf.cpp:1347
int addNode(const std::array< double, 3 > &)
Definition rbf.cpp:1271
std::vector< std::array< double, 3 > > m_node
Definition rbf.hpp:187
RBF(RBFBasisFunction=RBFBasisFunction::WENDLANDC2)
Definition rbf.cpp:1219
RBF & operator=(RBF other)
Definition rbf.cpp:1237
The ReconstructionPolynomial class allows to apply a reconstruction polynomial previously assembled.
RBFBasisFunction
Enum class defining types of RBF kernel functions that could be used in bitpit::RBF class.
Definition rbf.hpp:40
RBFMode
Enum class defining behaviour of the bitpit::RBF class.
Definition rbf.hpp:64
double gauss90(double)
Definition rbf.cpp:1503
double c2c2(double)
Definition rbf.cpp:1645
double c1c2(double)
Definition rbf.cpp:1630
double gauss95(double)
Definition rbf.cpp:1515
double c0c2(double)
Definition rbf.cpp:1615
double wendlandc2(double)
Definition rbf.cpp:1475
double gauss99(double)
Definition rbf.cpp:1527
double cosinus(double)
Definition rbf.cpp:1660
double c2c1(double)
Definition rbf.cpp:1600
double thinplate(double)
Definition rbf.cpp:1674
double linear(double)
Definition rbf.cpp:1489
double c1c0(double)
Definition rbf.cpp:1540
double c0c1(double)
Definition rbf.cpp:1570
double c1c1(double)
Definition rbf.cpp:1585
double c2c0(double)
Definition rbf.cpp:1555
--- layout: doxygen_footer ---