mirror of
https://codeberg.org/vcbferreira/NuFI_deal.ii
synced 2026-08-12 22:43:17 +02:00
problem identified, ready to converge all branches
This commit is contained in:
Binary file not shown.
@@ -1,6 +1,7 @@
|
|||||||
#ifndef NUFI_SOLVER_H
|
#ifndef NUFI_SOLVER_H
|
||||||
#define NUFI_SOLVER_H
|
#define NUFI_SOLVER_H
|
||||||
|
|
||||||
|
#include <boost/qvm/mat_access.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <deal.II/base/point.h>
|
#include <deal.II/base/point.h>
|
||||||
@@ -30,6 +31,9 @@ private:
|
|||||||
|
|
||||||
double Lx = Parameters::LX;
|
double Lx = Parameters::LX;
|
||||||
|
|
||||||
|
double x_min = Parameters::X_DOMAIN_LEFT;
|
||||||
|
double x_max = Parameters::X_DOMAIN_RIGHT;
|
||||||
|
|
||||||
std::vector<double> rho;
|
std::vector<double> rho;
|
||||||
|
|
||||||
unsigned int order;
|
unsigned int order;
|
||||||
|
|||||||
@@ -23,4 +23,7 @@ void save_Efield(unsigned int n,
|
|||||||
unsigned int Nx_out,
|
unsigned int Nx_out,
|
||||||
const std::string &filename);
|
const std::string &filename);
|
||||||
|
|
||||||
|
|
||||||
|
void save_space_vector(const std::vector<double>& vals, const std::string& filename, size_t it);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+10
-21
@@ -28,7 +28,7 @@ double NuFISolver::eval_ftilda(unsigned int n,
|
|||||||
if ( n == 0 ) return f0(x,u);
|
if ( n == 0 ) return f0(x,u);
|
||||||
|
|
||||||
const size_t stride_x = 1;
|
const size_t stride_x = 1;
|
||||||
const size_t stride_t = stride_x*(Parameters::SPLINE_NX + Parameters::SPLINE_ORDER - 1);
|
const size_t stride_t = stride_x*(Nx + Parameters::SPLINE_ORDER - 1);
|
||||||
|
|
||||||
double Ex;
|
double Ex;
|
||||||
const double *c;
|
const double *c;
|
||||||
@@ -81,7 +81,7 @@ void NuFISolver::run()
|
|||||||
|
|
||||||
if ( rho == nullptr ) throw std::bad_alloc {};
|
if ( rho == nullptr ) throw std::bad_alloc {};
|
||||||
|
|
||||||
Gradient grad(Parameters::X_DOMAIN_LEFT, Parameters::X_DOMAIN_RIGHT, Parameters::SPLINE_NX);
|
Gradient grad(x_min, x_max, Nx);
|
||||||
|
|
||||||
for (unsigned int it = 0; it < Nt; ++it)
|
for (unsigned int it = 0; it < Nt; ++it)
|
||||||
{
|
{
|
||||||
@@ -99,28 +99,17 @@ void NuFISolver::run()
|
|||||||
rho.get()[i] = ith_rho;
|
rho.get()[i] = ith_rho;
|
||||||
}
|
}
|
||||||
|
|
||||||
poisson.set_rhs_function(std::make_unique<ChargeDensity_NuFI<1>>(rho.get(), Parameters::SPLINE_NX));
|
poisson.set_rhs_function(std::make_unique<ChargeDensity_NuFI<1>>(rho.get(), Nx));
|
||||||
poisson.solve_step();
|
poisson.solve_step();
|
||||||
|
|
||||||
// std::vector<double> sampled_potential = poisson.sample_electric_potential(Parameters::X_DOMAIN_LEFT, Parameters::X_DOMAIN_RIGHT, Parameters::SPLINE_NX);
|
std::vector<double> sampled_potential = poisson.sample_electric_potential(x_min, x_max, Nx);
|
||||||
|
|
||||||
// sampled_potential.erase(sampled_potential.begin());
|
save_space_vector(sampled_potential, "potential", it);
|
||||||
// sampled_potential.erase(sampled_potential.end()-1);
|
|
||||||
//
|
std::vector<double> E_vals = grad.compute(sampled_potential);
|
||||||
// std::ofstream file("results/potential_" + std::to_string(it) + ".dat");
|
// std::vector<double> E_vals = poisson.sample_electric_field(x_min, x_max, Nx);
|
||||||
// file << sampled_potential.size() << "\n";
|
|
||||||
// file << Parameters::X_DOMAIN_LEFT << " " << Parameters::X_DOMAIN_RIGHT << "\n";
|
save_space_vector(E_vals, "electric", it);
|
||||||
// file << std::fixed << std::setprecision(8);
|
|
||||||
// for (double val : sampled_potential) file << val << "\n";
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// std::vector<double> E_vals = grad.compute(sampled_potential);
|
|
||||||
std::vector<double> E_vals = poisson.sample_electric_field(Parameters::X_DOMAIN_LEFT, Parameters::X_DOMAIN_RIGHT,Parameters::SPLINE_NX);
|
|
||||||
std::ofstream file("results/potential_" + std::to_string(it) + ".dat");
|
|
||||||
file << E_vals.size() << "\n";
|
|
||||||
file << Parameters::X_DOMAIN_LEFT << " " << Parameters::X_DOMAIN_RIGHT << "\n";
|
|
||||||
file << std::fixed << std::setprecision(8);
|
|
||||||
for (double val : E_vals) file << val << "\n";
|
|
||||||
|
|
||||||
double* current_coeffs = coeffs.get() + it*stride_t;
|
double* current_coeffs = coeffs.get() + it*stride_t;
|
||||||
interpolate<double, Parameters::SPLINE_ORDER>(current_coeffs, E_vals.data());
|
interpolate<double, Parameters::SPLINE_ORDER>(current_coeffs, E_vals.data());
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include "nufi/parameters.h"
|
#include "nufi/parameters.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include "nufi/nufi_solver.h"
|
#include "nufi/nufi_solver.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -102,3 +104,15 @@ void save_Efield(unsigned int n,
|
|||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void save_space_vector(const std::vector<double>& vals, const std::string& filename, size_t it)
|
||||||
|
{
|
||||||
|
std::ofstream file("results/" + filename + "_" + std::to_string(it) + ".dat");
|
||||||
|
|
||||||
|
if (!file) throw std::runtime_error("failed to start file in results/");
|
||||||
|
|
||||||
|
file << vals.size() << "\n";
|
||||||
|
file << Parameters::X_DOMAIN_LEFT << " " << Parameters::X_DOMAIN_RIGHT << "\n";
|
||||||
|
file << std::fixed << std::setprecision(8);
|
||||||
|
for (double val : vals) file << val << "\n";
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user