tested sim with hint on cell index for location for constant uniform grid

This commit is contained in:
Vasco C. B. Ferreira
2026-07-06 13:21:05 +02:00
parent 208ccb2bd0
commit f603af19c9
5 changed files with 107 additions and 38 deletions
+21 -15
View File
@@ -9,6 +9,7 @@
#include <deal.II/numerics/vector_tools.h>
#include <cstddef>
#include <fstream>
#include <iostream>
#include <memory>
#include <ostream>
@@ -34,6 +35,7 @@ NuFISolver::eval_ftilda(unsigned int n, std::vector<double> &X, double u,
if (n == 0) {
for (size_t i = 0; i < x_size; ++i)
results[i] = f0(X[i], U[i]);
reset_x_eval(X);
return results;
}
@@ -65,6 +67,7 @@ NuFISolver::eval_ftilda(unsigned int n, std::vector<double> &X, double u,
}
for (size_t i = 0; i < x_size; ++i)
results[i] = f0(X[i], U[i]);
reset_x_eval(X);
return results;
}
@@ -80,6 +83,7 @@ NuFISolver::eval_f(unsigned int n, std::vector<double> &X, double u,
if (n == 0) {
for (size_t i = 0; i < x_size; ++i)
results[i] = f0(X[i], U[i]);
reset_x_eval(X);
return results;
}
@@ -116,6 +120,7 @@ NuFISolver::eval_f(unsigned int n, std::vector<double> &X, double u,
for (size_t i = 0; i < x_size; ++i)
results[i] = f0(X[i], U[i]);
reset_x_eval(X);
return results;
}
@@ -134,14 +139,14 @@ NuFISolver::eval_rho(unsigned int n, std::vector<double> &X,
std::vector<double> tmp_int(x_size);
for (unsigned int i = 0; i < Nv; ++i) {
tmp_int = eval_ftilda(n, X, v_min + i * dv, poisson, phi_history);
tmp_int = eval_ftilda(n, X, v_min + i * dv, poisson,
phi_history); // used eval_ftilda once per i
for (size_t ii = 0; ii < x_size; ++ii)
integral[ii] += tmp_int[ii];
}
for (size_t i = 0; i < x_size; ++i)
integral[i] = 1 - integral[i] * dv;
reset_x_eval(X);
return integral;
}
@@ -155,20 +160,20 @@ void NuFISolver::run() {
reinterpret_cast<double *>(std::aligned_alloc(64, sizeof(double) * Nx)),
std::free};
if (rho == nullptr)
throw std::bad_alloc{};
std::vector<double> int_E_squared;
int_E_squared.reserve(Nt);
std::vector<Vector<double>> phi_history;
size_t CALC_NX = Parameters::CALC_NX;
std::vector<double> x_eval = make_x_eval(CALC_NX);
std::vector<double> x_eval(Parameters::CALC_NX);
if (rho == nullptr)
throw std::bad_alloc{};
std::ofstream time_file("results/simulation_time.dat");
double total_time = 0;
std::ofstream time_file("results/simulation_time.txt");
time_file << "# it step_time total_time" << "\n";
time_file << "it step_time total_time" << "\n";
const double x_min = Parameters::X_DOMAIN_LEFT;
double dx = Parameters::CALC_DX;
@@ -183,10 +188,11 @@ void NuFISolver::run() {
<< std::endl;
// compute rho
std::vector<double> x_eval = make_x_eval(Nx);
std::vector<double> tmp_rho =
eval_rho(it, x_eval, poisson, phi_history, Parameters::NV);
for (size_t i = 0; i < CALC_NX; ++i) {
for (size_t i = 0; i < Nx; i++) {
AssertThrow(std::isfinite(tmp_rho[i]), ExcMessage("NaN detected in rho"));
rho.get()[i] = tmp_rho[i];
}
@@ -223,12 +229,12 @@ void NuFISolver::run() {
// save_Efield(it, coeffs.get(), 128, "results/field_" +
// std::to_string(it) + ".dat");
std::vector<double> E_x(CALC_NX);
std::vector<double> x_eval_Ex = make_x_eval(Parameters::PLOT_NX);
std::vector<double> tmp_Ex = eval(x_eval_Ex, poisson, phi_history[it]);
reset_x_eval(x_eval_Ex);
for (size_t i = 0; i < CALC_NX; ++i)
E_x[i] = -tmp_Ex[i];
tmp_rho = eval(x_eval_Ex, poisson, phi_history[it]);
std::vector<double> E_x(Parameters::PLOT_NX);
for (size_t i = 0; i < Parameters::PLOT_NX; ++i)
E_x[i] = -tmp_rho[i];
save_space_vector(E_x, "field", it);
double int_val =