From 39edc7f96e0c514488fd3ce78ef8bf65cfc0f113 Mon Sep 17 00:00:00 2001 From: "V. Ferreira" Date: Tue, 24 Feb 2026 03:47:06 +0100 Subject: [PATCH] corrected periodic boundaries, more to be done on this --- density.vtk | 2 +- electric_field.vtk | 2 +- nufi_poisson.cc | 25 ++++++++++++++++++++----- plotting.ipynb | 6 +++--- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/density.vtk b/density.vtk index e91f56c..80de449 100644 --- a/density.vtk +++ b/density.vtk @@ -1,5 +1,5 @@ # vtk DataFile Version 3.0 -#This file was generated by the deal.II library on 2026/2/23 at 20:47:29 +#This file was generated by the deal.II library on 2026/2/24 at 3:42:25 ASCII DATASET UNSTRUCTURED_GRID diff --git a/electric_field.vtk b/electric_field.vtk index 5ac1196..cc32d28 100644 --- a/electric_field.vtk +++ b/electric_field.vtk @@ -1,5 +1,5 @@ # vtk DataFile Version 3.0 -#This file was generated by the deal.II library on 2026/2/23 at 20:47:29 +#This file was generated by the deal.II library on 2026/2/24 at 3:42:25 ASCII DATASET UNSTRUCTURED_GRID diff --git a/nufi_poisson.cc b/nufi_poisson.cc index b7fbc6a..8d8c5fe 100644 --- a/nufi_poisson.cc +++ b/nufi_poisson.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -21,6 +22,7 @@ #include #include +#include #include #include @@ -28,6 +30,7 @@ #include #include +#include #include #include @@ -116,6 +119,16 @@ private: const unsigned int Nv; }; +template +class BoundaryValues : public Function +{ +public: + virtual double value(const Point &p, + const unsigned int component = 0) const override + { + return 0.; // boundary value at periodic boundary + } +}; // =-=-=-=-= Poisson Solver =-=-=-=-= @@ -147,6 +160,8 @@ private: Vector solution; // phi Vector system_rhs; + MappingQ mapping; + unsigned int Nv; }; @@ -161,6 +176,7 @@ template PoissonProblem::PoissonProblem(unsigned int degree, unsigned int Nv) : fe(degree) , dof_handler(triangulation) + , mapping(degree) , Nv(Nv) {} @@ -175,14 +191,16 @@ void PoissonProblem::create_mesh() X_DOMAIN_RIGHT); // Make x-dim boundaries periodic + Tensor<1, dim> offset; std::vector::cell_iterator>> periodicity_vector; - + GridTools::collect_periodic_faces(triangulation, 0, 1, 0, - periodicity_vector); + periodicity_vector, + offset); triangulation.add_periodicity(periodicity_vector); @@ -215,7 +233,6 @@ void PoissonProblem::setup_system() system_rhs.reinit(dof_handler.n_dofs()); } - // =-=-=-=-= E_field = -dPhi/dx =-=-=-=-= template @@ -320,7 +337,6 @@ void PoissonProblem::output_results() const // --- extract DoF coordinates --- std::vector> support_points(dof_handler.n_dofs()); - MappingQ1 mapping; DoFTools::map_dofs_to_support_points(mapping, dof_handler, support_points); @@ -370,7 +386,6 @@ template void PoissonProblem::run() { create_mesh(); - setup_system(); assemble_system(); solve(); diff --git a/plotting.ipynb b/plotting.ipynb index c9b47df..8fb68f7 100644 --- a/plotting.ipynb +++ b/plotting.ipynb @@ -35,12 +35,12 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "aa222ee6ba03446d87ead5ffb3d25af2", + "model_id": "aa88a047e54c4ea7befbb1b0f6e71ec6", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Widget(value='