9 #ifndef WONTON_LS_FITS_H_ 10 #define WONTON_LS_FITS_H_ 42 template<
int D,
typename CoordSys = CartesianCoordinates>
44 std::vector<double>
const & vals) {
46 CoordSys::template verify_coordinate_system<D>();
50 double val0 = vals[0];
56 int nvals = vals.size();
63 for (
int i = 0; i < nvals-1; ++i) {
64 for (
int j = 0; j < D; ++j)
65 A[i][j] = coords[i+1][j]-coord0[j];
72 Matrix AT = A.transpose();
80 std::vector<double> F(nvals-1);
81 for (
int i = 0; i < nvals-1; ++i)
82 F[i] = vals[i+1]-val0;
91 Matrix ATAinv = ATA.inverse();
95 auto gradient = ATAinv*ATF;
99 CoordSys::modify_gradient(gradient, coord0);
123 std::vector<double>
const & vals,
124 bool const boundary_element) {
126 double val0 = vals[0];
132 int nvals = vals.size();
134 if (boundary_element) {
139 for (
int i = 0; i < D*(D+3)/2; i++) result[i] = 0.0;
141 for (
int i = 0; i < D; i++) result[i] = grad[i];
155 Matrix A(nvals-1, D*(D+3)/2);
156 for (
int i = 0; i < nvals-1; i++) {
158 for (
int j0 = 0; j0 < D; ++j0) {
159 A[i][j0] = coords[i+1][j0]-coords[0][j0];
162 for (
int k=0; k <= j0; k++) {
163 A[i][j1] = A[i][k]*A[i][j0];
169 int const ma = D*(D+3)/2;
170 std::vector<std::vector<double> > u(nvals-1, std::vector<double>(ma));
171 std::vector<std::vector<double> > v(ma, std::vector<double>(ma));
172 std::vector<double> w(ma);
173 for (
int i = 0; i < nvals-1; i++) {
174 for (
int j = 0; j < ma; j++) {
187 for (
int j = 0; j < ma; j++) {
188 if (w[j] > wmax) wmax=w[j];
190 double thresh = scale*wmax;
191 for (
int j = 0; j < ma; j++) {
192 if (w[j] < thresh) w[j]=0.0;
199 std::vector<double> F(nvals-1);
200 for (
int i = 0; i < nvals-1; ++i) {
201 F[i] = vals[i+1]-val0;
205 std::vector<double> result(ma);
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
std::vector< T > vector
Definition: wonton.h:285
int svd(std::vector< std::vector< double > > &a, std::vector< double > &w, std::vector< std::vector< double > > &v)
Definition: svd.cc:46
Vector< D > ls_gradient(std::vector< Point< D >> const &coords, std::vector< double > const &vals)
Compute least squares gradient from set of values.
Definition: lsfits.h:43
Represents a point in an N-dimensional space.
Definition: Point.h:50
void svd_solve(const std::vector< std::vector< double > > &u, const std::vector< double > &w, const std::vector< std::vector< double > > &v, std::vector< double > &b, std::vector< double > &x)
Definition: svd.cc:320
Vector< D *(D+3)/2 > ls_quadfit(std::vector< Point< D >> const &coords, std::vector< double > const &vals, bool const boundary_element)
Compute least squares quadfit from set of values.
Definition: lsfits.h:122
Represents a vector in N-dimensional space.
Definition: Vector.h:40