new paradigm, grids saved when changed old solutions not interpolated to new grids

This commit is contained in:
Vasco C. B. Ferreira
2026-07-09 19:23:15 +02:00
parent 47d7540961
commit 43eec84c40
9 changed files with 219 additions and 154 deletions
+7 -54
View File
@@ -1,6 +1,7 @@
#ifndef FIELDS_H
#define FIELDS_H
#include "grids.h"
#include "nufi/parameters.h"
#include "nufi/poisson_problem.h"
#include <cmath>
@@ -11,54 +12,6 @@
using namespace dealii;
// inline std::vector<int> Indices_of_points(const std::vector<double> &points,
// double x_min, double x_max, double dx, int grid_type=0)
// {
// // grid type:
// // 0 => uniform
// // 1 => non uniform (TODO)
//
// if (dx <= 0.0) {
// throw std::invalid_argument("dx must be positive");
// }
// if (x_max <= x_min) {
// throw std::invalid_argument("x_max must be > x_min");
// }
//
// std::vector<int> indices;
// indices.reserve(points.size());
//
// switch (grid_type) {
// case 0:
// {
// const double L = x_max - x_min;
// const int N = std::floor(L/dx);
//
//
// for (double x : points) //GPT loop, to check
// {
// x-= x_min;
// x = x - L * std::floor(x/L);
//
// int i = static_cast<int>(std::floor(x / dx));
//
// // safety: handle rare edge case due to floating precision
// if (i == N) i = 0;
//
// indices.push_back(i);
// }
// }
// case 1:
// {
// throw std::invalid_argument("Case for non uniform grid is not
// completed");
// }
// default:
// throw std::invalid_argument("Invalid grid_type argument");
//
// }
// return indices;
// }
inline std::vector<double> make_x_eval(size_t Nx) {
std::vector<double> x_eval(Nx);
const double dx = Parameters::LX / Nx;
@@ -86,7 +39,7 @@ inline double f0(const double x, const double v,
// wrapper for eval_point() { VectorTools::point_values() }
inline std::vector<double> eval(std::vector<double> &X,
const PoissonProblem<1> &poisson,
const GridStructure<1> &grid,
const Vector<double> &solution) noexcept {
size_t x_size = X.size();
std::vector<double> evals(x_size);
@@ -99,10 +52,10 @@ inline std::vector<double> eval(std::vector<double> &X,
Points[i][0] = X[i];
}
return poisson.eval_vector_grad(solution, Points);
return grid.eval_vector_grad(solution, Points);
}
inline double integral_space_vector(const PoissonProblem<1> &poisson,
inline double integral_space_vector(const GridStructure<1> &grid,
const Vector<double> &solution,
double dx = Parameters::PLOT_DX,
size_t Nx = Parameters::PLOT_NX) {
@@ -112,13 +65,13 @@ inline double integral_space_vector(const PoissonProblem<1> &poisson,
for (size_t i = 0; i < Nx; ++i)
x_eval[i] = xmin + i * dx;
std::vector<double> tmp = eval(x_eval, poisson, solution);
std::vector<double> tmp = eval(x_eval, grid, solution);
for (size_t i = 0; i < Nx; ++i)
integral += tmp[i];
return integral * dx;
};
inline double integral_space_vector_squared(const PoissonProblem<1> &poisson,
inline double integral_space_vector_squared(const GridStructure<1> &grid,
const Vector<double> &solution,
double dx = Parameters::PLOT_DX,
size_t Nx = Parameters::PLOT_NX) {
@@ -128,7 +81,7 @@ inline double integral_space_vector_squared(const PoissonProblem<1> &poisson,
for (size_t i = 0; i < Nx; ++i)
x_eval[i] = xmin + i * dx;
std::vector<double> tmp = eval(x_eval, poisson, solution);
std::vector<double> tmp = eval(x_eval, grid, solution);
for (size_t i = 0; i < Nx; ++i)
integral += tmp[i] * tmp[i];
return integral * dx;