nufi working but slow, need to save field from previous time step and/or parallel loop to solve eval_rho

This commit is contained in:
Vasco C. B. Ferreira
2026-03-08 17:05:18 +01:00
parent 51df7cc78a
commit bf7ad1e595
2 changed files with 15 additions and 5 deletions
+7 -4
View File
@@ -91,10 +91,12 @@ inline double NuFISolver::eval_ftilda(unsigned int n,
double Ex; double Ex;
// Initial half-step. // Initial half-step.
Ex = evaluate_E(x); Ex = evaluate_E(x);
u += 0.5*dt*Ex; u += 0.5*dt*Ex;
while ( --n ) while ( --n )
{ {
x -= dt*u; x -= dt*u;
@@ -106,7 +108,6 @@ inline double NuFISolver::eval_ftilda(unsigned int n,
x -= dt*u; x -= dt*u;
Ex = evaluate_E(x); Ex = evaluate_E(x);
u += 0.5*dt*Ex; // is this line useless ? u += 0.5*dt*Ex; // is this line useless ?
double x_periodic = x - Lx * std::floor(x / Lx); double x_periodic = x - Lx * std::floor(x / Lx);
double u_periodic = u - Lu * std::floor(u / Lu); double u_periodic = u - Lu * std::floor(u / Lu);
@@ -120,7 +121,6 @@ inline double NuFISolver::eval_rho(const unsigned int n,
const double dv = (Parameters::V_DOMAIN_RIGHT - Parameters::V_DOMAIN_LEFT) / Nv; const double dv = (Parameters::V_DOMAIN_RIGHT - Parameters::V_DOMAIN_LEFT) / Nv;
double integral = 0.0; double integral = 0.0;
for (unsigned int i = 0; i < Nv; ++i) for (unsigned int i = 0; i < Nv; ++i)
{ {
const double v = Parameters::V_DOMAIN_LEFT + (i + 0.5) * dv; const double v = Parameters::V_DOMAIN_LEFT + (i + 0.5) * dv;
@@ -170,13 +170,15 @@ inline void NuFISolver::run()
double dx = Lx / Nx; double dx = Lx / Nx;
std::cout << "Start of eval_rho step with Nx = "<< Nx<< "\n";
for (unsigned int i = 0; i < Nx; ++i) for (unsigned int i = 0; i < Nx; ++i)
{ {
double x = (i + 0.5) * dx; double x = (i + 0.5) * dx;
rho[i] = eval_rho(n, x); rho[i] = eval_rho(n, x);
} }
std::cout << "End of eval_rho step\n";
solve_poisson(n); solve_poisson(n);
} }
@@ -187,6 +189,7 @@ inline NuFISolver::NuFISolver()
: order(Parameters::FE_DEGREE), : order(Parameters::FE_DEGREE),
poisson(order, Parameters::NV) poisson(order, Parameters::NV)
{ {
std::cout << "Initializing Poisson\n";
poisson.initialize(); poisson.initialize();
Nx = poisson.get_dof_handler().n_dofs(); Nx = poisson.get_dof_handler().n_dofs();
+8 -1
View File
@@ -108,6 +108,8 @@ PoissonProblem<dim>::PoissonProblem(unsigned int degree, unsigned int Nv)
template<int dim> template<int dim>
void PoissonProblem<dim>::create_mesh() void PoissonProblem<dim>::create_mesh()
{ {
std::cout << "Creating Mesh\n";
GridGenerator::hyper_cube(triangulation, GridGenerator::hyper_cube(triangulation,
Parameters::X_DOMAIN_LEFT, Parameters::X_DOMAIN_LEFT,
Parameters::X_DOMAIN_RIGHT); Parameters::X_DOMAIN_RIGHT);
@@ -132,6 +134,8 @@ void PoissonProblem<dim>::create_mesh()
template <int dim> template <int dim>
void PoissonProblem<dim>::setup_system() void PoissonProblem<dim>::setup_system()
{ {
std::cout << "Setting up Poisson system\n";
dof_handler.distribute_dofs(fe); dof_handler.distribute_dofs(fe);
constraints.clear(); constraints.clear();
@@ -184,6 +188,7 @@ public:
template <int dim> template <int dim>
void PoissonProblem<dim>::assemble_system() void PoissonProblem<dim>::assemble_system()
{ {
std::cout << "Assembling Poisson System\n";
QGauss<dim> quadrature_formula(fe.degree + 1); QGauss<dim> quadrature_formula(fe.degree + 1);
FEValues<dim> fe_values(fe, quadrature_formula, FEValues<dim> fe_values(fe, quadrature_formula,
update_values | update_values |
@@ -238,6 +243,8 @@ void PoissonProblem<dim>::assemble_system()
template <int dim> template <int dim>
void PoissonProblem<dim>::solve() void PoissonProblem<dim>::solve()
{ {
std::cout << "Calling PoissonProblem::solve()\n";
SolverControl solver_control(1000, 1e-12); SolverControl solver_control(1000, 1e-12);
SolverCG<Vector<double>> solver(solver_control); SolverCG<Vector<double>> solver(solver_control);
@@ -313,7 +320,7 @@ void PoissonProblem<dim>::solve_step()
{ {
system_matrix = 0; system_matrix = 0;
system_rhs = 0; system_rhs = 0;
std::cout << "Calling PoissonProblem::solve_step()\n";
assemble_system(); assemble_system();
solve(); solve();
} }