NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
orthoPoly3D.H
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #ifndef NEMOSYS_ORTHOPOLY3D_H_
30 #define NEMOSYS_ORTHOPOLY3D_H_
31 
32 #include "nemosys_export.h"
33 
34 #include <memory>
35 #include <vector>
36 
38 
39 #include <Eigen/Core>
40 
41 /* This class takes 3 dimensional points and n dimensional data
42  to build a multidimensional orthogonal polynomial approximant
43  to data in a cubic domain defined by the minmax x,y,z coordinates
44  of the points. Orthogonality is accomplished by tensor-product construction
45  using 1D orthogonal polynomials defined by x,y and z coordinates. As such,
46  the points must be representable by a cartesian product. For example, the
47  4 points (x1,y1),(x1,y2),(x2,y1),(x2,y2) can equivalently be written as
48  (x1,x2) <X> (y1,y2) where <X> is the cartesian product */
49 
50 /* Based on the requirements above, this class is suitable for use with
51  rectilinear, structured quad/hex grids */
52 
53 
54 // TODO: Generalize to higher order elements with more than one internal node
55 // per patch where averages need to be taken for duplicate recovered values
56 
57 
58 // defines dynamically sized matrix type with row-major storage
59 // this is used to optimize computations involving access to entire rows
60 using MatrixXdRM =
61  Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
62 
63 // remove given row from matrix
64 void removeRow(Eigen::MatrixXd &matrix, unsigned int rowToRemove);
65 
66 // remove rows from given matrix
67 void removeRow(const MatrixXdRM &matrix,
68  MatrixXdRM &matrix_red,
69  const std::vector<unsigned int> &toRemove);
70 void removeRow(const Eigen::MatrixXd &matrix,
71  MatrixXdRM &matrix_red,
72  const std::vector<unsigned int> &toRemove);
73 // remove given column from matrix
74 void removeColumn(Eigen::MatrixXd &matrix, unsigned int colToRemove);
75 
76 
77 class NEMOSYS_EXPORT orthoPoly3D
78 {
79  // constructors and destructors
80  public:
81  // default ctor
82  orthoPoly3D();
83 
84  // complete ctor
85  orthoPoly3D(int _order,
86  const Eigen::VectorXd &_sigma,
87  const std::vector<double> &_x,
88  const std::vector<double> &_y,
89  const std::vector<double> &_z);
90 
91  // partial ctor, must manually call computeA
92  orthoPoly3D(int _order, const std::vector<std::vector<double>> &coords);
93 
94  // move constructor
96 
97  // move assignment
98  orthoPoly3D &operator=(orthoPoly3D &&op);
99 
100  // disable copy and copy-assignment constructors
101  orthoPoly3D(const orthoPoly3D &) = delete;
102  orthoPoly3D &operator=(const orthoPoly3D &) = delete;
103 
104  // factories
105  static orthoPoly3D *
106  Create(int _order, const std::vector<std::vector<double>> &coords);
107  static std::unique_ptr<orthoPoly3D>
108  CreateUnique(int _order, const std::vector<std::vector<double>> &coords);
109 
110  // dtor
111  ~orthoPoly3D() = default;
112 
113  // methods
114  public:
115 #ifdef NEMOSYS_DEBUG
116  // compute multivariate polynomial approximation of prescribed order to sigma
117  void run1(const Eigen::VectorXd &sigma);
118 #endif
119  // compute coefficients for polynomial expansion of sampled function
120  void computeA(const Eigen::VectorXd &sigma);
121  // evaluate the fitting polynomial at coord
122  double operator()(const std::vector<double> &coord);
123  double eval(const std::vector<double> &coord);
124 
125  // return the status of the approximant object
126  // 1 indicates approximant is available, 0 otherwise
127  bool status() const { return finished; }
128 
129  // reset coefficients to default state
130  void resetA();
131  // reset the object to its default state
132  void Reset();
133 
134  Eigen::VectorXd getCoeffs() const { return a; }
135 
136  private:
137  // total order of basis
138  int order;
139  // 1D orthogonal basis generated by x coords
140  std::unique_ptr<orthoPoly1D> opx;
141  // 1D orthogonal basis generated by y coords
142  std::unique_ptr<orthoPoly1D> opy;
143  // 1D orthogonal basis generated by z coords
144  std::unique_ptr<orthoPoly1D> opz;
145  // coefficients of polynomial approximant
146  Eigen::VectorXd a;
147  // rows/cols to remove from basis matrices to limit total order
148  std::vector<unsigned int> toRemove;
149  // status bool
150  bool finished;
151 
152  private:
153  // checks order compatibility and determines toRemove array
154  void initCheck();
155 };
156 
157 #endif // NEMOSYS_ORTHOPOLY3D_H_
Eigen::VectorXd a
Definition: orthoPoly3D.H:146
std::unique_ptr< orthoPoly1D > opy
Definition: orthoPoly3D.H:142
std::unique_ptr< orthoPoly1D > opx
Definition: orthoPoly3D.H:140
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixXdRM
Definition: orthoPoly3D.H:61
Eigen::VectorXd getCoeffs() const
Definition: orthoPoly3D.H:134
bool status() const
Definition: orthoPoly3D.H:127
std::vector< unsigned int > toRemove
Definition: orthoPoly3D.H:148
void removeColumn(Eigen::MatrixXd &matrix, unsigned int colToRemove)
void removeRow(Eigen::MatrixXd &matrix, unsigned int rowToRemove)
std::unique_ptr< orthoPoly1D > opz
Definition: orthoPoly3D.H:144