MRBF.hpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo 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  * mimmo 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 mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23 \*---------------------------------------------------------------------------*/
24 #ifndef __MRBF_HPP__
25 #define __MRBF_HPP__
26 
27 #include "BaseManipulation.hpp"
28 #include <bitpit_RBF.hpp>
29 
30 namespace mimmo{
31 
38 enum class MRBFBasisFunction {
39  HEAVISIDE10 = 101,
40  HEAVISIDE50 = 102,
41  HEAVISIDE100 = 103,
42  HEAVISIDE1000 = 104,
43  DSIGMOID = 105,
44 };
45 
50 enum class MRBFSol{
51  NONE = 0,
52  WHOLE = 1,
53  GREEDY= 2
54 };
55 
146 class MRBF: public BaseManipulation, public bitpit::RBF {
147 
148 protected:
149  double m_tol;
152  bool m_bfilter;
154  bool m_srIsReal;
164  bool m_isCompact;
172 public:
173  MRBF(MRBFSol mode = MRBFSol::NONE);
174  MRBF(const bitpit::Config::Section & rootXML);
175 
176  virtual ~MRBF();
177 
178  //copy operators/constructors
179  MRBF(const MRBF & other);
180  MRBF& operator=(MRBF other);
181 
182  void buildPorts();
183 
184  dvecarr3E* getNodes();
185 
186  MRBFSol getMode();
188 
189  bool isSupportRadiusReal();
192  double getDiagonalFactor();
193 
194  int getFunctionType();
197 
198  bool isCompact();
199  bool areResultsInScalarMode();
200 
201  int addNode(darray3E);
203 
204  void setNode(darray3E);
205  void setNode(dvecarr3E);
207  void setFilter(dmpvector1D * );
208 
209  ivector1D checkDuplicatedNodes(double tol=1.0E-12);
210  bool removeDuplicatedNodes(ivector1D * list=nullptr);
211 
212  void setSupportRadiusLocal(double suppR_);
213  void setSupportRadiusReal(double suppR_);
214  void setVariableSupportRadii(dvector1D sradii);
215  void setVariableSupportRadii(dmpvector1D* sradii);
216  void setDiagonalFactor(double diagonalFactor);
217 
218 BITPIT_DEPRECATED(
219  void setSupportRadiusValue(double suppR_));
220 
221  void setTol(double tol);
222  void setDisplacements(dvecarr3E displ);
223  void setDisplacements(dmpvecarr3E* displ);
224  void setScalarDisplacements(dvector1D displ);
225  void setScalarDisplacements(dmpvector1D* displ);
226 
227  void setFunction(const MRBFBasisFunction & funct, bool isCompact = false);
228  void setFunction(const bitpit::RBFBasisFunction & funct, bool isCompact = false);
229  void setCompactSupport(bool isCompact = true);
230 
231  void clear();
232  void clearFilter();
233 
234  void execute();
235  void apply();
236 
237  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name="");
238  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name="");
239 
240 protected:
241  void swap(MRBF & x) noexcept;
242  void checkFilter();
243  void setWeight(dvector2D value);
244  void plotCloud(std::string directory, std::string filename, int counterFile, bool binary, bool deformed);
245  virtual void plotOptionalResults();
246 
248 
249  bool initRBFwGeometry();
250 
251  //reimplemented from RBFKernel
252  void setMode(MRBFSol solver);
253  std::vector<double> evalRBF(const std::array<double,3> & val);
254 
255 private:
256 
257  // redeclared to be private in the current class:
258  // they behave exactly as in the base class but they are not accessible in MRBF.
259 
260  void setSupportRadius(double val){bitpit::RBFKernel::setSupportRadius(val);};
261  double getSupportRadius(){return bitpit::RBFKernel::getSupportRadius();};
262  void setMode(bitpit::RBFMode mode){bitpit::RBFKernel::setMode(mode);};
263 
264  void setDataToNode (int n, const std::vector<double> &data){bitpit::RBFKernel::setDataToNode(n,data);};
265  void setDataToAllNodes(int n , const std::vector<double> & data){bitpit::RBFKernel::setDataToAllNodes(n,data);};
266 
267  int addData(){return bitpit::RBFKernel::addData();};
268  int addData(const std::vector<double> & data){return bitpit::RBFKernel::addData(data);};
269  bool removeData(int n){return bitpit::RBFKernel::removeData(n);};
270  bool removeData(std::vector<int> &nn){return bitpit::RBFKernel::removeData(nn);};
271  void removeAllData(){bitpit::RBFKernel::removeAllData();};
272 
273  std::vector<double> evalRBF(int jnode){return bitpit::RBFKernel::evalRBF(jnode);};
274 
275  int solve(){return bitpit::RBFKernel::solve();};
276  int greedy(double tol){return bitpit::RBFKernel::greedy(tol);};
277 };
278 
279 double heaviside10( double dist );
280 double heaviside50( double dist );
281 double heaviside100( double dist );
282 double heaviside1000( double dist );
283 double dsigmoid( double dist );
284 
285 REGISTER_PORT(M_COORDS, MC_VECARR3, MD_FLOAT ,__MRBF_HPP__)
286 REGISTER_PORT(M_DISPLS, MC_VECARR3, MD_FLOAT ,__MRBF_HPP__)
290 REGISTER_PORT(M_GEOM, MC_SCALAR, MD_MIMMO_ ,__MRBF_HPP__)
296 
297 REGISTER(BaseManipulation, MRBF, "mimmo.MRBF")
298 
299 };
300 
301 #endif /* __MRBF_HPP__ */
dmpvecarr3E * getDisplacements()
Definition: MRBF.cpp:262
void plotCloud(std::string directory, std::string filename, int counterFile, bool binary, bool deformed)
Definition: MRBF.cpp:1069
bool isSupportRadiusReal()
Definition: MRBF.cpp:206
#define M_GDISPLS
void computeEffectiveSupportRadiusList()
Definition: MRBF.cpp:1146
dmpvector1D * getFilter()
Definition: MRBF.cpp:195
dvector1D m_supportRadii
Definition: MRBF.hpp:155
bool isVariableSupportRadiusSet()
Definition: MRBF.cpp:216
void setWeight(dvector2D value)
Definition: MRBF.cpp:1043
dmpvector1D * m_rbfSupportRadii
Definition: MRBF.hpp:169
#define M_DATAFIELD
#define M_DATAFIELD2
void execute()
Definition: MRBF.cpp:681
#define M_DISPLS
#define M_GEOM
void setNode(darray3E)
Definition: MRBF.cpp:329
MRBF(MRBFSol mode=MRBFSol::NONE)
Definition: MRBF.cpp:32
double getDiagonalFactor()
Definition: MRBF.cpp:236
std::vector< double > evalRBF(const std::array< double, 3 > &val)
Definition: MRBF.cpp:1209
ivector1D checkDuplicatedNodes(double tol=1.0E-12)
Definition: MRBF.cpp:373
#define MD_FLOAT
void setDisplacements(dvecarr3E displ)
Definition: MRBF.cpp:514
void setTol(double tol)
Definition: MRBF.cpp:498
std::vector< darray3E > dvecarr3E
bool m_srIsReal
Definition: MRBF.hpp:154
void setSupportRadiusReal(double suppR_)
Definition: MRBF.cpp:436
MRBF & operator=(MRBF other)
Definition: MRBF.cpp:116
int getFunctionType()
Definition: MRBF.cpp:244
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
Definition: MRBF.cpp:865
dvector1D m_effectiveSR
Definition: MRBF.hpp:163
dmpvecarr3E m_displ
Definition: MRBF.hpp:160
#define M_GEOM2
double m_supportRadiusValue
Definition: MRBF.hpp:153
bool m_areScalarResults
Definition: MRBF.hpp:170
MRBFSol getMode()
Definition: MRBF.cpp:187
void setMode(MRBFSol solver)
Definition: MRBF.cpp:1237
void setSupportRadiusLocal(double suppR_)
Definition: MRBF.cpp:419
bool m_isCompact
Definition: MRBF.hpp:164
BaseManipulation is the base class of any manipulation object of the library.
dvecarr3E * getNodes()
Definition: MRBF.cpp:177
MRBFSol
Solver enum for MRBF data fields interpolation/ direct parameterization.
Definition: MRBF.hpp:50
#define M_VECTORFIELD
void apply()
Definition: MRBF.cpp:820
double m_diagonalFactor
Definition: MRBF.hpp:156
MRBFSol m_solver
Definition: MRBF.hpp:150
virtual ~MRBF()
Definition: MRBF.cpp:90
#define MC_SCALAR
dvector1D & getEffectivelyUsedSupportRadii()
Definition: MRBF.cpp:226
std::vector< int > ivector1D
#define MD_MPVECARR3FLOAT_
#define REGISTER_PORT(Name, Container, Datatype, ManipBlock)
void setVariableSupportRadii(dvector1D sradii)
Definition: MRBF.cpp:462
dmpvector1D m_filter
Definition: MRBF.hpp:151
bool initRBFwGeometry()
Definition: MRBF.cpp:1248
void clearFilter()
Definition: MRBF.cpp:668
std::vector< double > dvector1D
void setDiagonalFactor(double diagonalFactor)
Definition: MRBF.cpp:489
void buildPorts()
Definition: MRBF.cpp:154
#define MC_VECTOR
void setSupportRadiusValue(double suppR_)
Definition: MRBF.cpp:447
void setFilter(dmpvector1D *)
Definition: MRBF.cpp:360
void setScalarDisplacements(dvector1D displ)
Definition: MRBF.cpp:562
void swap(MRBF &x) noexcept
Definition: MRBF.cpp:125
dmpvecarr3E * m_rbfdispl
Definition: MRBF.hpp:167
bool isCompact()
Definition: MRBF.cpp:301
double m_tol
Definition: MRBF.hpp:149
#define MD_MIMMO_
bool areResultsInScalarMode()
Definition: MRBF.cpp:291
std::vector< dvector1D > dvector2D
void clear()
Definition: MRBF.cpp:657
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
Definition: MRBF.cpp:970
int m_functype
Definition: MRBF.hpp:159
bool removeDuplicatedNodes(ivector1D *list=nullptr)
Definition: MRBF.cpp:398
virtual void plotOptionalResults()
Definition: MRBF.cpp:1131
#define MD_MPVECFLOAT_
#define M_SCALARFIELD
std::array< double, 3 > darray3E
void checkFilter()
Definition: MRBF.cpp:1015
int addNode(darray3E)
Definition: MRBF.cpp:311
dmpvector1D m_scalarDispl
Definition: MRBF.hpp:161
Radial Basis Function evaluation from clouds of control points.
Definition: MRBF.hpp:146
MRBFBasisFunction
Enum class defining types of mimmo RBF kernel functions that could be used also in MRBF class,...
Definition: MRBF.hpp:38
#define M_SCALARFIELD2
bool m_bfilter
Definition: MRBF.hpp:152
MimmoSharedPointer is a custom implementation of shared pointer.
dmpvector1D * m_rbfScalarDispl
Definition: MRBF.hpp:168
void setCompactSupport(bool isCompact=true)
Definition: MRBF.cpp:650
dmpvector1D * getScalarDisplacements()
Definition: MRBF.cpp:276
#define M_COORDS
#define MC_VECARR3
void setFunction(const MRBFBasisFunction &funct, bool isCompact=false)
Definition: MRBF.cpp:594
#define M_FILTER
#define REGISTER(Base, Derived, name)
Definition: factory.hpp:206
MimmoSharedPointer< MimmoObject > m_rbfgeometry
Definition: MRBF.hpp:166