35 #include <unsupported/Eigen/KroneckerProduct> 37 using Eigen::KroneckerProduct;
38 using Eigen::MatrixXd;
39 using Eigen::VectorXd;
44 unsigned int numRows = matrix.rows();
45 unsigned int numCols = matrix.cols() - 1;
47 if (colToRemove < numCols)
48 matrix.block(0, colToRemove, numRows, numCols - colToRemove) =
49 matrix.rightCols(numCols - colToRemove);
51 matrix.conservativeResize(numRows, numCols);
59 const std::vector<unsigned int> &toRemove)
62 for (
int i = 0; i < matrix.cols(); ++i)
65 for (
unsigned int k : toRemove)
75 matrix_red.col(m) = matrix.col(i);
87 const std::vector<unsigned int> &toRemove)
90 for (
int i = 0; i < matrix.cols(); ++i)
93 for (
unsigned int k : toRemove)
103 matrix_red.row(m) = matrix.col(i);
123 toRemove = {5, 7, 8, 11, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25,
126 toRemove = {7, 10, 11, 13, 14, 15, 19, 22, 23, 25, 26,
127 27, 28, 29, 30, 31, 34, 35, 37, 38, 39, 40,
128 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52,
129 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63};
132 std::cerr <<
"Polynomial order greater than 3 is not supported" 140 const std::vector<double> &x,
141 const std::vector<double> &y,
142 const std::vector<double> &z)
154 const std::vector<std::vector<double>> &coords)
168 std::vector<double> x(coords.size());
169 std::vector<double> y(coords.size());
170 std::vector<double> z(coords.size());
172 for (
int i = 0; i < coords.size(); ++i)
178 std::cout <<
"non-unique coords" << std::endl;
225 opx = std::move(op.opx);
226 opy = std::move(op.opy);
227 opz = std::move(op.opz);
244 std::unique_ptr<orthoPoly3D>
246 const std::vector<std::vector<double>> &coords)
248 return std::unique_ptr<orthoPoly3D>(
262 MatrixXd tmp1 =
opx->phi *
opx->phiTphiInv;
263 MatrixXd tmp2 =
opy->phi *
opy->phiTphiInv;
264 MatrixXd tmp3 =
opz->phi *
opz->phiTphiInv;
269 MatrixXd kronProd_full = kroneckerProduct(tmp1, tmp2);
270 kronProd_full = kroneckerProduct(kronProd_full, tmp3).eval();
273 std::cout <<
"Time for building kronprod in constructor: " << T1.
elapsed()
275 std::cout <<
"kronProd_full: " << kronProd_full.rows() <<
" " 276 << kronProd_full.cols() <<
"\n";
277 std::cout <<
"Removing rows: ";
281 kronProd_full.rows());
286 std::cout <<
"kronProd_red: " << kronProd_red.rows() <<
" " 287 << kronProd_red.cols() <<
"\n";
288 std::cout <<
"sigma size: " << sigma.size() <<
"\n";
289 a = kronProd_red * sigma;
292 std::cout <<
"Time: " << T.
elapsed() << std::endl;
293 std::cout <<
"shape of a: " <<
a.rows() <<
" " <<
a.cols() << std::endl;
313 std::cerr <<
"Coefficients to basis have not been generated" << std::endl;
317 MatrixXd phix(1,
order + 1);
318 MatrixXd phiy(1,
order + 1);
319 MatrixXd phiz(1,
order + 1);
320 for (
int i = 0; i <
order + 1; ++i)
322 phix(0, i) =
opx->EvaluateOrthogonal(i, coord[0]);
323 phiy(0, i) =
opy->EvaluateOrthogonal(i, coord[1]);
324 phiz(0, i) =
opz->EvaluateOrthogonal(i, coord[2]);
327 MatrixXd Phi = kroneckerProduct(phix, phiy);
328 Phi = kroneckerProduct(Phi, phiz).eval();
330 std::cout << Phi.rows() <<
" " << Phi.cols() << std::endl;
332 MatrixXd Phi_red(Phi.rows(), Phi.cols() -
toRemove.size());
336 std::cout << Phi_red.rows() <<
" " << Phi_red.cols() << std::endl;
337 std::cout <<
a.rows() <<
" " <<
a.cols() << std::endl;
340 return (Phi_red *
a)(0, 0);
351 void orthoPoly3D::run1(
const VectorXd &sigma)
354 NewPhi = kroneckerProduct(
opx->phi,
opy->phi);
355 NewPhi = kroneckerProduct(NewPhi,
opz->phi).eval();
358 std::cout <<
"Removing stuff" << std::endl;
361 MatrixXd NewPhi_red(NewPhi.rows(), NewPhi.cols() -
toRemove.size());
366 std::cout <<
"Time spent removing: " << T.
elapsed() << std::endl;
368 VectorXd sigma_approx = NewPhi_red *
a;
370 VectorXd error = (sigma_approx - sigma).cwiseAbs();
371 std::cout <<
"max error " << error.maxCoeff() << std::endl;
372 std::cout <<
"min error " << error.minCoeff() << std::endl;
std::unique_ptr< orthoPoly1D > opy
double operator()(const std::vector< double > &coord)
std::unique_ptr< orthoPoly1D > opx
double eval(const std::vector< double > &coord)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixXdRM
static std::unique_ptr< orthoPoly3D > CreateUnique(int _order, const std::vector< std::vector< double >> &coords)
void removeRowT(const MatrixXd &matrix, MatrixXdRM &matrix_red, const std::vector< unsigned int > &toRemove)
std::vector< unsigned int > toRemove
void printVec(const std::vector< T > &v)
orthoPoly3D & operator=(orthoPoly3D &&op)
static orthoPoly3D * Create(int _order, const std::vector< std::vector< double >> &coords)
void removeColumn(MatrixXd &matrix, unsigned int colToRemove)
void computeA(const Eigen::VectorXd &sigma)
std::unique_ptr< orthoPoly1D > opz