refinment working with history of grids

This commit is contained in:
Vasco C. B. Ferreira
2026-07-21 22:58:39 +02:00
parent dfadd4766f
commit 9cbd3e71e7
11 changed files with 125 additions and 210 deletions
+49 -27
View File
@@ -1,36 +1,45 @@
# CMAKE generated file: DO NOT EDIT! # CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.31 # Generated by "Unix Makefiles" Generator, CMake Version 3.18
# Default target executed when no arguments are given to make. # Default target executed when no arguments are given to make.
default_target: all default_target: all
.PHONY : default_target .PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism. # Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL: .NOTPARALLEL:
#============================================================================= #=============================================================================
# Special targets provided by cmake. # Special targets provided by cmake.
# Disable implicit rules so canonical targets will work. # Disable implicit rules so canonical targets will work.
.SUFFIXES: .SUFFIXES:
# Disable VCS-based implicit rules. # Disable VCS-based implicit rules.
% : %,v % : %,v
# Disable VCS-based implicit rules. # Disable VCS-based implicit rules.
% : RCS/% % : RCS/%
# Disable VCS-based implicit rules. # Disable VCS-based implicit rules.
% : RCS/%,v % : RCS/%,v
# Disable VCS-based implicit rules. # Disable VCS-based implicit rules.
% : SCCS/s.% % : SCCS/s.%
# Disable VCS-based implicit rules. # Disable VCS-based implicit rules.
% : s.% % : s.%
.SUFFIXES: .hpux_make_needs_suffix_list .SUFFIXES: .hpux_make_needs_suffix_list
# Command-line flag to silence nested $(MAKE). # Command-line flag to silence nested $(MAKE).
$(VERBOSE)MAKESILENT = -s $(VERBOSE)MAKESILENT = -s
@@ -39,6 +48,7 @@ $(VERBOSE).SILENT:
# A target that is always out of date. # A target that is always out of date.
cmake_force: cmake_force:
.PHONY : cmake_force .PHONY : cmake_force
#============================================================================= #=============================================================================
@@ -48,10 +58,10 @@ cmake_force:
SHELL = /bin/sh SHELL = /bin/sh
# The CMake executable. # The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake CMAKE_COMMAND = /usr/local/bin/cmake
# The command to remove a file. # The command to remove a file.
RM = /usr/bin/cmake -E rm -f RM = /usr/local/bin/cmake -E rm -f
# Escaping for special characters. # Escaping for special characters.
EQUALS = = EQUALS = =
@@ -65,26 +75,28 @@ CMAKE_BINARY_DIR = /home/vf/Thesis/dealII_NuFI/1x1v
#============================================================================= #=============================================================================
# Targets provided globally by CMake. # Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/local/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target edit_cache # Special rule for the target edit_cache
edit_cache: edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake cache editor..." @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
/usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) /usr/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache .PHONY : edit_cache
# Special rule for the target edit_cache # Special rule for the target edit_cache
edit_cache/fast: edit_cache edit_cache/fast: edit_cache
.PHONY : edit_cache/fast .PHONY : edit_cache/fast
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# The main all target # The main all target
all: cmake_check_build_system all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/vf/Thesis/dealII_NuFI/1x1v/CMakeFiles /home/vf/Thesis/dealII_NuFI/1x1v//CMakeFiles/progress.marks $(CMAKE_COMMAND) -E cmake_progress_start /home/vf/Thesis/dealII_NuFI/1x1v/CMakeFiles /home/vf/Thesis/dealII_NuFI/1x1v//CMakeFiles/progress.marks
@@ -99,6 +111,7 @@ clean:
# The main clean target # The main clean target
clean/fast: clean clean/fast: clean
.PHONY : clean/fast .PHONY : clean/fast
# Prepare targets for installation. # Prepare targets for installation.
@@ -116,19 +129,6 @@ depend:
$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend .PHONY : depend
#=============================================================================
# Target rules for targets named nufi_lib
# Build rule for target.
nufi_lib: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 nufi_lib
.PHONY : nufi_lib
# fast build rule for target.
nufi_lib/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/nufi_lib.dir/build.make CMakeFiles/nufi_lib.dir/build
.PHONY : nufi_lib/fast
#============================================================================= #=============================================================================
# Target rules for targets named nufi_poisson # Target rules for targets named nufi_poisson
@@ -142,7 +142,21 @@ nufi_poisson/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/nufi_poisson.dir/build.make CMakeFiles/nufi_poisson.dir/build $(MAKE) $(MAKESILENT) -f CMakeFiles/nufi_poisson.dir/build.make CMakeFiles/nufi_poisson.dir/build
.PHONY : nufi_poisson/fast .PHONY : nufi_poisson/fast
#=============================================================================
# Target rules for targets named nufi_lib
# Build rule for target.
nufi_lib: cmake_check_build_system
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 nufi_lib
.PHONY : nufi_lib
# fast build rule for target.
nufi_lib/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/nufi_lib.dir/build.make CMakeFiles/nufi_lib.dir/build
.PHONY : nufi_lib/fast
src/main.o: src/main.cc.o src/main.o: src/main.cc.o
.PHONY : src/main.o .PHONY : src/main.o
# target to build an object file # target to build an object file
@@ -151,6 +165,7 @@ src/main.cc.o:
.PHONY : src/main.cc.o .PHONY : src/main.cc.o
src/main.i: src/main.cc.i src/main.i: src/main.cc.i
.PHONY : src/main.i .PHONY : src/main.i
# target to preprocess a source file # target to preprocess a source file
@@ -159,6 +174,7 @@ src/main.cc.i:
.PHONY : src/main.cc.i .PHONY : src/main.cc.i
src/main.s: src/main.cc.s src/main.s: src/main.cc.s
.PHONY : src/main.s .PHONY : src/main.s
# target to generate assembly for a file # target to generate assembly for a file
@@ -167,6 +183,7 @@ src/main.cc.s:
.PHONY : src/main.cc.s .PHONY : src/main.cc.s
src/nufi_solver.o: src/nufi_solver.cc.o src/nufi_solver.o: src/nufi_solver.cc.o
.PHONY : src/nufi_solver.o .PHONY : src/nufi_solver.o
# target to build an object file # target to build an object file
@@ -175,6 +192,7 @@ src/nufi_solver.cc.o:
.PHONY : src/nufi_solver.cc.o .PHONY : src/nufi_solver.cc.o
src/nufi_solver.i: src/nufi_solver.cc.i src/nufi_solver.i: src/nufi_solver.cc.i
.PHONY : src/nufi_solver.i .PHONY : src/nufi_solver.i
# target to preprocess a source file # target to preprocess a source file
@@ -183,6 +201,7 @@ src/nufi_solver.cc.i:
.PHONY : src/nufi_solver.cc.i .PHONY : src/nufi_solver.cc.i
src/nufi_solver.s: src/nufi_solver.cc.s src/nufi_solver.s: src/nufi_solver.cc.s
.PHONY : src/nufi_solver.s .PHONY : src/nufi_solver.s
# target to generate assembly for a file # target to generate assembly for a file
@@ -191,6 +210,7 @@ src/nufi_solver.cc.s:
.PHONY : src/nufi_solver.cc.s .PHONY : src/nufi_solver.cc.s
src/save_results.o: src/save_results.cc.o src/save_results.o: src/save_results.cc.o
.PHONY : src/save_results.o .PHONY : src/save_results.o
# target to build an object file # target to build an object file
@@ -199,6 +219,7 @@ src/save_results.cc.o:
.PHONY : src/save_results.cc.o .PHONY : src/save_results.cc.o
src/save_results.i: src/save_results.cc.i src/save_results.i: src/save_results.cc.i
.PHONY : src/save_results.i .PHONY : src/save_results.i
# target to preprocess a source file # target to preprocess a source file
@@ -207,6 +228,7 @@ src/save_results.cc.i:
.PHONY : src/save_results.cc.i .PHONY : src/save_results.cc.i
src/save_results.s: src/save_results.cc.s src/save_results.s: src/save_results.cc.s
.PHONY : src/save_results.s .PHONY : src/save_results.s
# target to generate assembly for a file # target to generate assembly for a file
+3 -3
View File
@@ -7,6 +7,6 @@ This simulation of the Vlasov-Poisson system in 1x1v dimensions uses
--- ---
status: status:
Fail Refinement working:
- grid versions saved on a vector
-------------------------------------------------------- - solutions point to a version of the grid
+5 -17
View File
@@ -37,30 +37,18 @@ if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING "FALSE") set(CMAKE_CROSSCOMPILING "FALSE")
endif() endif()
# Set path to fallback-tool for dependency-resolution. # Set default install directory permissions.
if(NOT DEFINED CMAKE_OBJDUMP) if(NOT DEFINED CMAKE_OBJDUMP)
set(CMAKE_OBJDUMP "/usr/bin/objdump") set(CMAKE_OBJDUMP "/usr/bin/objdump")
endif() endif()
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
"${CMAKE_INSTALL_MANIFEST_FILES}")
if(CMAKE_INSTALL_LOCAL_ONLY)
file(WRITE "/home/vf/Thesis/dealII_NuFI/1x1v/install_local_manifest.txt"
"${CMAKE_INSTALL_MANIFEST_CONTENT}")
endif()
if(CMAKE_INSTALL_COMPONENT) if(CMAKE_INSTALL_COMPONENT)
if(CMAKE_INSTALL_COMPONENT MATCHES "^[a-zA-Z0-9_.+-]+$") set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt")
else()
string(MD5 CMAKE_INST_COMP_HASH "${CMAKE_INSTALL_COMPONENT}")
set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INST_COMP_HASH}.txt")
unset(CMAKE_INST_COMP_HASH)
endif()
else() else()
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt") set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
endif() endif()
if(NOT CMAKE_INSTALL_LOCAL_ONLY) string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
file(WRITE "/home/vf/Thesis/dealII_NuFI/1x1v/${CMAKE_INSTALL_MANIFEST}" "${CMAKE_INSTALL_MANIFEST_FILES}")
file(WRITE "/home/vf/Thesis/dealII_NuFI/1x1v/${CMAKE_INSTALL_MANIFEST}"
"${CMAKE_INSTALL_MANIFEST_CONTENT}") "${CMAKE_INSTALL_MANIFEST_CONTENT}")
endif()
BIN
View File
Binary file not shown.
+14 -49
View File
@@ -48,6 +48,8 @@ template <int dim> struct GridStructure {
std::vector<double> values(points.size()); std::vector<double> values(points.size());
// Uses point_gradient
// #pragma omp parallel for // #pragma omp parallel for
// for (unsigned int p = 0; p < points.size(); ++p) { // for (unsigned int p = 0; p < points.size(); ++p) {
// //
@@ -60,6 +62,7 @@ template <int dim> struct GridStructure {
// return values; // return values;
// } // }
// Uses cell locator
#pragma omp parallel #pragma omp parallel
{ {
std::vector<double> local_solution_buffer(fe->n_dofs_per_cell()); std::vector<double> local_solution_buffer(fe->n_dofs_per_cell());
@@ -82,9 +85,6 @@ template <int dim> struct GridStructure {
values[p] = evaluator.get_gradient(0)[0]; values[p] = evaluator.get_gradient(0)[0];
} }
} }
// AssertThrow(dof_handler->n_dofs() == solution.size(),
// ExcMessage("Solution vector size does not match
// DoFHandler.)");
return values; return values;
} }
}; };
@@ -102,21 +102,11 @@ GridStructure<dim> make_grid_snapshot(PoissonProblem<dim> &poisson) {
grid.fe = std::make_unique<FE_Q<dim>>(poisson.get_fe()); grid.fe = std::make_unique<FE_Q<dim>>(poisson.get_fe());
grid.dof_handler = std::make_unique<DoFHandler<dim>>(*grid.triangulation); grid.dof_handler = std::make_unique<DoFHandler<dim>>(*grid.triangulation);
grid.dof_handler->distribute_dofs(*grid.fe); grid.dof_handler->distribute_dofs(*grid.fe);
grid.mapping = std::make_unique<MappingQ<dim>>(poisson.get_mapping()); grid.mapping = std::make_unique<MappingQ<dim>>(poisson.get_mapping());
grid.constraints =
std::make_unique<AffineConstraints<double>>(poisson.get_constraints());
grid.locator = std::make_unique<CellLocator<dim>>(); grid.constraints = std::make_unique<AffineConstraints<double>>();
// START: transfer poisson.solution to saved grid dofs
SolutionTransfer<dim> solution_transfer(*grid.dof_handler);
const Vector<double> coarse_solution = poisson.solution;
solution_transfer.prepare_for_coarsening_and_refinement(coarse_solution);
// START: setup_system();
grid.constraints->clear();
DoFTools::make_hanging_node_constraints(*grid.dof_handler, *grid.constraints); DoFTools::make_hanging_node_constraints(*grid.dof_handler, *grid.constraints);
DoFTools::make_periodicity_constraints(*grid.dof_handler, 0, 1, 0, DoFTools::make_periodicity_constraints(*grid.dof_handler, 0, 1, 0,
@@ -147,21 +137,10 @@ GridStructure<dim> make_grid_snapshot(PoissonProblem<dim> &poisson) {
grid.constraints->add_line(gauge_dof); grid.constraints->add_line(gauge_dof);
grid.constraints->set_inhomogeneity(gauge_dof, 0.0); grid.constraints->set_inhomogeneity(gauge_dof, 0.0);
grid.constraints->close(); grid.constraints->close();
DynamicSparsityPattern dsp(grid.dof_handler->n_dofs()); grid.locator = std::make_unique<CellLocator<dim>>();
DoFTools::make_sparsity_pattern(*grid.dof_handler, dsp, *grid.constraints);
poisson.sparsity_pattern.copy_from(dsp);
poisson.system_matrix.reinit(poisson.sparsity_pattern);
poisson.solution.reinit(grid.dof_handler->n_dofs());
poisson.system_rhs.reinit(grid.dof_handler->n_dofs());
grid.locator->rebuild(*grid.dof_handler, *grid.triangulation); grid.locator->rebuild(*grid.dof_handler, *grid.triangulation);
// END
solution_transfer.interpolate(coarse_solution, poisson.solution);
// END
// START: diagnostics // START: diagnostics
AssertThrow( AssertThrow(
@@ -169,32 +148,18 @@ GridStructure<dim> make_grid_snapshot(PoissonProblem<dim> &poisson) {
grid.constraints->n_constraints(), grid.constraints->n_constraints(),
ExcMessage( ExcMessage(
"PoissonProblem constraints doesn't match Snapshot constraints")); "PoissonProblem constraints doesn't match Snapshot constraints"));
for (auto c1 = poisson.get_dof_handler().begin_active(), // for (auto c1 = poisson.get_dof_handler().begin_active(),
c2 = grid.dof_handler->begin_active(); // c2 = grid.dof_handler->begin_active();
c1 != poisson.get_dof_handler().end(); ++c1, ++c2) { // c1 != poisson.get_dof_handler().end(); ++c1, ++c2) {
std::vector<types::global_dof_index> d1(c1->get_fe().dofs_per_cell); // std::vector<types::global_dof_index> d1(c1->get_fe().dofs_per_cell);
std::vector<types::global_dof_index> d2(c2->get_fe().dofs_per_cell); // std::vector<types::global_dof_index> d2(c2->get_fe().dofs_per_cell);
c1->get_dof_indices(d1);
c2->get_dof_indices(d2);
AssertThrow(d1 == d2, ExcInternalError());
}
// //
// auto support_points = // c1->get_dof_indices(d1);
// DoFTools::map_dofs_to_support_points(*grid.mapping, *grid.dof_handler); // c2->get_dof_indices(d2);
// //
// std::cout << "COPY\n"; // AssertThrow(d1 == d2, ExcInternalError());
//
// for (const auto &[dof, point] : support_points) {
// std::cout << dof << " : " << point[0] << "\n";
// } // }
// for (auto cell : grid.dof_handler->active_cell_iterators()) { // END: diagnostics
// std::cout << "@ GridStructure: " << cell->id() << " " <<
// cell->center()[0]
// << '\n';
// }
// END
return grid; return grid;
} }
+2 -2
View File
@@ -26,11 +26,11 @@ public:
const std::vector<SolutionSnapshot<1>> &phi_history, const std::vector<SolutionSnapshot<1>> &phi_history,
const unsigned int Nv = Parameters::NV) const; const unsigned int Nv = Parameters::NV) const;
std::vector<double> std::vector<double>
eval_ftilda(unsigned int, std::vector<double> &x, double u, eval_ftilda(unsigned int n, std::vector<double> x, double u,
const std::vector<GridStructure<1>> &grid_struct, const std::vector<GridStructure<1>> &grid_struct,
const std::vector<SolutionSnapshot<1>> &phi_history) const; const std::vector<SolutionSnapshot<1>> &phi_history) const;
std::vector<double> std::vector<double>
eval_f(unsigned int n, std::vector<double> &x, double u, eval_f(unsigned int n, std::vector<double> x, double u,
const std::vector<GridStructure<1>> &grid_struct, const std::vector<GridStructure<1>> &grid_struct,
const std::vector<SolutionSnapshot<1>> &phi_history) const; const std::vector<SolutionSnapshot<1>> &phi_history) const;
+3 -3
View File
@@ -23,7 +23,7 @@ constexpr unsigned int NV = 128;
constexpr double DV = std::abs(V_DOMAIN_RIGHT - V_DOMAIN_LEFT) / NV; constexpr double DV = std::abs(V_DOMAIN_RIGHT - V_DOMAIN_LEFT) / NV;
// deal.ii options // deal.ii options
constexpr unsigned int GLOBAL_REFINEMENT = 8; constexpr unsigned int GLOBAL_REFINEMENT = 6;
constexpr unsigned int FE_DEGREE = 3; constexpr unsigned int FE_DEGREE = 3;
constexpr unsigned int CONVERGENCE_ITERATIONS = 5000; constexpr unsigned int CONVERGENCE_ITERATIONS = 5000;
constexpr double CONVERGENCE_LIMIT = 1e-8; constexpr double CONVERGENCE_LIMIT = 1e-8;
@@ -39,10 +39,10 @@ constexpr double F0_FACTOR = 0.39894228040143267793994; // 1/sqrt(2pi)
// NUFI options // NUFI options
constexpr double DT = 1. / 10.; constexpr double DT = 1. / 10.;
constexpr unsigned int TMAX = 100; constexpr unsigned int TMAX = 100;
constexpr unsigned int REFINE_FREQUENCY = 3; constexpr unsigned int REFINE_FREQUENCY = 30;
// Plotting options // Plotting options
constexpr int PLOT_FREQUENCY = 1; constexpr int PLOT_FREQUENCY = 10;
constexpr size_t PLOT_NX = CALC_NX; constexpr size_t PLOT_NX = CALC_NX;
constexpr double PLOT_DX = LX / PLOT_NX; constexpr double PLOT_DX = LX / PLOT_NX;
const std::string PLOT_DIR = "results/"; const std::string PLOT_DIR = "results/";
+34 -56
View File
@@ -103,43 +103,27 @@ public:
void save_grid_to_file(std::string &filename) const; void save_grid_to_file(std::string &filename) const;
Triangulation<dim> triangulation;
DoFHandler<dim> dof_handler;
CellLocator<dim> cell_locator;
Vector<double> solution; // phi
SparsityPattern sparsity_pattern;
SparseMatrix<double> system_matrix;
Vector<double> system_rhs;
private: private:
void create_mesh(); void create_mesh();
void setup_system(); void setup_system();
void assemble_system(); void assemble_system();
void solve(size_t it); void solve(size_t it);
// Triangulation<dim> triangulation;
FE_Q<dim> fe;
// DoFHandler<dim> dof_handler;
AffineConstraints<double> constraints;
// SparsityPattern sparsity_pattern;
// SparseMatrix<double> system_matrix;
// Vector<double> solution; // phi
// Vector<double> system_rhs;
std::function<std::vector<double>(const std::vector<Point<dim>> &)> std::function<std::vector<double>(const std::vector<Point<dim>> &)>
rhs_function; rhs_function;
// Vector<double> rhs;
MappingQ<dim> mapping; MappingQ<dim> mapping;
FE_Q<dim> fe;
AffineConstraints<double> constraints;
Triangulation<dim> triangulation;
DoFHandler<dim> dof_handler;
CellLocator<dim> cell_locator;
Vector<double> solution; // phi
SparsityPattern sparsity_pattern;
SparseMatrix<double> system_matrix;
Vector<double> system_rhs;
const bool PRINT_GAUGE_DOF_POSITION = true; const bool PRINT_GAUGE_DOF_POSITION = true;
// mutable std::vector<double> local_solution_buffer;
// mutable std::unique_ptr<FEPointEvaluation<dim, dim>> evaluator;
}; };
//====//====// //====//====//
@@ -164,10 +148,10 @@ void PoissonProblem<dim>::set_rhs_function(
template <int dim> template <int dim>
PoissonProblem<dim>::PoissonProblem(unsigned int degree) PoissonProblem<dim>::PoissonProblem(unsigned int degree)
: // triangulation(Triangulation<dim>::limit_level_difference_at_vertices), : mapping(degree), fe(degree), triangulation(), dof_handler(triangulation) {
triangulation(), dof_handler(triangulation), fe(degree), mapping(degree) {
} }
// Uses FEPointEvaluation
template <int dim> template <int dim>
std::vector<double> std::vector<double>
PoissonProblem<dim>::sample_electric_field(double x_min, double x_max, PoissonProblem<dim>::sample_electric_field(double x_min, double x_max,
@@ -180,32 +164,27 @@ PoissonProblem<dim>::sample_electric_field(double x_min, double x_max,
const double x = x_min + i * dx; const double x = x_min + i * dx;
const Point<dim> point(x); const Point<dim> point(x);
// 1. Find the active cell containing x
const auto cell_point_pair = const auto cell_point_pair =
GridTools::find_active_cell_around_point(mapping, dof_handler, point); GridTools::find_active_cell_around_point(mapping, dof_handler, point);
const auto cell = cell_point_pair.first; const auto cell = cell_point_pair.first;
const Point<dim> &unit_point = cell_point_pair.second; const Point<dim> &unit_point = cell_point_pair.second;
// 2. FEPointEvaluation expects an ArrayView of points
std::vector<Point<dim>> points(1, unit_point); std::vector<Point<dim>> points(1, unit_point);
ArrayView<const Point<dim>> point_view(points); ArrayView<const Point<dim>> point_view(points);
FEPointEvaluation<1, dim> evaluator(mapping, dof_handler.get_fe(), FEPointEvaluation<1, dim> evaluator(mapping, dof_handler.get_fe(),
update_gradients); update_gradients);
// reinit with ArrayView of points
evaluator.reinit(cell, point_view); evaluator.reinit(cell, point_view);
Vector<double> local_dofs(dof_handler.get_fe().dofs_per_cell); Vector<double> local_dofs(dof_handler.get_fe().dofs_per_cell);
cell->get_dof_values(solution, local_dofs); cell->get_dof_values(solution, local_dofs);
// 3. Evaluate gradient at this point
evaluator.evaluate(local_dofs, EvaluationFlags::gradients); evaluator.evaluate(local_dofs, EvaluationFlags::gradients);
const Tensor<1, dim> grad_phi = evaluator.get_gradient(0); const Tensor<1, dim> grad_phi = evaluator.get_gradient(0);
// 4. Compute E = -grad(phi)
E_values[i] = -grad_phi[0]; E_values[i] = -grad_phi[0];
} }
@@ -471,6 +450,8 @@ template <int dim> void PoissonProblem<dim>::coarse_and_refine_grid(size_t it) {
template <int dim> void PoissonProblem<dim>::solve(size_t it) { template <int dim> void PoissonProblem<dim>::solve(size_t it) {
std::cout << "Calling PoissonProblem::solve for time-step " << it << "\n";
SolverControl solver_control(Parameters::CONVERGENCE_ITERATIONS, SolverControl solver_control(Parameters::CONVERGENCE_ITERATIONS,
Parameters::CONVERGENCE_LIMIT * Parameters::CONVERGENCE_LIMIT *
system_rhs.l2_norm()); system_rhs.l2_norm());
@@ -479,26 +460,26 @@ template <int dim> void PoissonProblem<dim>::solve(size_t it) {
solver.solve(system_matrix, solution, system_rhs, PreconditionIdentity()); solver.solve(system_matrix, solution, system_rhs, PreconditionIdentity());
constraints.distribute(solution); constraints.distribute(solution);
std::ofstream out("results/phi_after_solve_" + std::to_string(it) + ".dat"); // std::ofstream out("results/phi_after_solve_" + std::to_string(it) +
std::vector<std::pair<double, double>> data; // ".dat"); std::vector<std::pair<double, double>> data;
//
const auto support = // const auto support =
DoFTools::map_dofs_to_support_points(mapping, dof_handler); // DoFTools::map_dofs_to_support_points(mapping, dof_handler);
//
for (const auto &[dof, p] : support) { // for (const auto &[dof, p] : support) {
data.emplace_back(p[0], solution[dof]); // data.emplace_back(p[0], solution[dof]);
} // }
//
std::sort(data.begin(), data.end()); // std::sort(data.begin(), data.end());
//
for (const auto &[x, value] : data) { // for (const auto &[x, value] : data) {
out << x << " " << value << "\n"; // out << x << " " << value << "\n";
} // }
//
std::vector<double> E_x = // std::vector<double> E_x =
sample_electric_field(Parameters::X_DOMAIN_LEFT, // sample_electric_field(Parameters::X_DOMAIN_LEFT,
Parameters::X_DOMAIN_RIGHT, Parameters::PLOT_NX); // Parameters::X_DOMAIN_RIGHT, Parameters::PLOT_NX);
save_space_vector(E_x, "E_x_after_solve", it); // save_space_vector(E_x, "E_x_after_solve", it);
} }
template <int dim> void PoissonProblem<dim>::initialize() { template <int dim> void PoissonProblem<dim>::initialize() {
@@ -512,13 +493,10 @@ void PoissonProblem<dim>::solve_step(
if (refining) { if (refining) {
coarse_and_refine_grid(it); coarse_and_refine_grid(it);
setup_system(); setup_system();
update_grid_versions(grid_versions, *this);
} }
assemble_system(); assemble_system();
solve(it); solve(it);
if (refining)
update_grid_versions(grid_versions, *this);
} }
// NuFI doesnt use this, kept only for testing PoissonProblem // NuFI doesnt use this, kept only for testing PoissonProblem
+2 -7
View File
@@ -19,14 +19,9 @@ void save_rho(const NuFISolver &solver, unsigned int n,
std::vector<SolutionSnapshot<1>> &phi_history, std::vector<SolutionSnapshot<1>> &phi_history,
unsigned int Nx_out, const std::string &filename); unsigned int Nx_out, const std::string &filename);
void save_Efield(unsigned int n, GridStructure<1> &grid_struct, void save_Efield(unsigned int it, std::vector<GridStructure<1>> &grid_versions,
std::vector<SolutionSnapshot<1>> &phi_history, std::vector<SolutionSnapshot<1>> &phi_history,
unsigned int Nx_out, const std::string &filename); unsigned int Nx_out = Parameters::PLOT_NX);
void save_Efield_new(unsigned int it,
std::vector<GridStructure<1>> &grid_versions,
std::vector<SolutionSnapshot<1>> &phi_history,
unsigned int Nx_out = Parameters::PLOT_NX);
void save_space_vector(const std::vector<double> &vals, void save_space_vector(const std::vector<double> &vals,
const std::string &filename, size_t it); const std::string &filename, size_t it);
+9 -18
View File
@@ -27,7 +27,7 @@
using namespace dealii; using namespace dealii;
std::vector<double> NuFISolver::eval_ftilda( std::vector<double> NuFISolver::eval_ftilda(
unsigned int n, std::vector<double> &X, double u, unsigned int n, std::vector<double> X, double u,
const std::vector<GridStructure<1>> &grid_struct, const std::vector<GridStructure<1>> &grid_struct,
const std::vector<SolutionSnapshot<1>> &phi_history) const { const std::vector<SolutionSnapshot<1>> &phi_history) const {
@@ -38,7 +38,7 @@ std::vector<double> NuFISolver::eval_ftilda(
if (n == 0) { if (n == 0) {
for (size_t i = 0; i < x_size; ++i) for (size_t i = 0; i < x_size; ++i)
results[i] = f0(X[i], U[i]); results[i] = f0(X[i], U[i]);
reset_x_eval(X); // reset_x_eval(X);
return results; return results;
} }
@@ -86,12 +86,12 @@ std::vector<double> NuFISolver::eval_ftilda(
} }
for (size_t i = 0; i < x_size; ++i) for (size_t i = 0; i < x_size; ++i)
results[i] = f0(X[i], U[i]); results[i] = f0(X[i], U[i]);
reset_x_eval(X); // reset_x_eval(X);
return results; return results;
} }
std::vector<double> std::vector<double>
NuFISolver::eval_f(unsigned int n, std::vector<double> &X, double u, NuFISolver::eval_f(unsigned int n, std::vector<double> X, double u,
const std::vector<GridStructure<1>> &grid_struct, const std::vector<GridStructure<1>> &grid_struct,
const std::vector<SolutionSnapshot<1>> &phi_history) const { const std::vector<SolutionSnapshot<1>> &phi_history) const {
@@ -102,7 +102,7 @@ NuFISolver::eval_f(unsigned int n, std::vector<double> &X, double u,
if (n == 0) { if (n == 0) {
for (size_t i = 0; i < x_size; ++i) for (size_t i = 0; i < x_size; ++i)
results[i] = f0(X[i], U[i]); results[i] = f0(X[i], U[i]);
reset_x_eval(X); // reset_x_eval(X);
return results; return results;
} }
@@ -142,7 +142,7 @@ NuFISolver::eval_f(unsigned int n, std::vector<double> &X, double u,
for (size_t i = 0; i < x_size; ++i) for (size_t i = 0; i < x_size; ++i)
results[i] = f0(X[i], U[i]); results[i] = f0(X[i], U[i]);
reset_x_eval(X); // reset_x_eval(X);
return results; return results;
} }
@@ -243,8 +243,8 @@ void NuFISolver::run() {
<< std::endl; << std::endl;
// START: diagnostics // START: diagnostics
std::cout << "cells = " << poisson.triangulation.n_active_cells() << "\n" // std::cout << "cells = " << poisson.triangulation.n_active_cells() << "\n"
<< " dofs = " << poisson.dof_handler.n_dofs() << "\n"; // << " dofs = " << poisson.dof_handler.n_dofs() << "\n";
// double min_h = 1e100; // double min_h = 1e100;
// double max_h = 0; // double max_h = 0;
// //
@@ -311,16 +311,7 @@ void NuFISolver::run() {
save_rho(*this, it, grid_versions, phi_history, Parameters::PLOT_NX, save_rho(*this, it, grid_versions, phi_history, Parameters::PLOT_NX,
"results/rho_" + std::to_string(it) + ".dat"); "results/rho_" + std::to_string(it) + ".dat");
// std::vector<double> x_eval_Ex = make_x_eval(Parameters::PLOT_NX); save_Efield(it, grid_versions, phi_history);
// std::vector<double> tmp_Ex(x_eval_Ex.size());
// tmp_Ex = eval(x_eval_Ex, grid_versions[phi_history[it].grid_version],
// phi_history[it].solution);
//
// std::vector<double> E_x(Parameters::PLOT_NX);
// for (size_t i = 0; i < Parameters::PLOT_NX; ++i)
// E_x[i] = -tmp_Ex[i];
// save_space_vector(E_x, "field", it);
save_Efield_new(it, grid_versions, phi_history);
double int_val = 0.5 * integral_space_vector_squared( double int_val = 0.5 * integral_space_vector_squared(
grid_versions[phi_history[it].grid_version], grid_versions[phi_history[it].grid_version],
+4 -28
View File
@@ -72,10 +72,9 @@ void save_rho(const NuFISolver &solver, unsigned int n,
file.close(); file.close();
} }
void save_Efield_new(unsigned int it, void save_Efield(unsigned int it, std::vector<GridStructure<1>> &grid_versions,
std::vector<GridStructure<1>> &grid_versions, std::vector<SolutionSnapshot<1>> &phi_history,
std::vector<SolutionSnapshot<1>> &phi_history, unsigned int Nx_out) {
unsigned int Nx_out) {
std::vector<double> x_eval_E = make_x_eval(Nx_out); std::vector<double> x_eval_E = make_x_eval(Nx_out);
auto grad_phi = eval(x_eval_E, grid_versions[phi_history[it].grid_version], auto grad_phi = eval(x_eval_E, grid_versions[phi_history[it].grid_version],
@@ -96,34 +95,11 @@ void save_Efield_new(unsigned int it,
E_file << x << " " << E << "\n"; E_file << x << " " << E << "\n";
std::cout << "Saving iteration " << it << " using grid version " std::cout << "Saving iteration " << it << " using grid version "
<< phi_history[it].grid_version << "\n"; << phi_history[it].grid_version << "\n\n";
E_file.close(); E_file.close();
} }
void save_Efield([[maybe_unused]] unsigned int n, GridStructure<1> &grid_struct,
std::vector<SolutionSnapshot<1>> &phi_history,
unsigned int Nx_out, const std::string &filename) {
std::ofstream file(filename);
double xmin = Parameters::X_DOMAIN_LEFT;
double xmax = Parameters::X_DOMAIN_RIGHT;
std::vector<double> x_eval = make_x_eval(Nx_out);
// select from E_coeffs
file << Nx_out << "\n";
file << xmin << " " << xmax << "\n";
std::vector<double> tmp = eval(x_eval, grid_struct, phi_history[n].solution);
for (size_t i = 0; i < Nx_out; ++i) {
file << -tmp[i];
file << "\n";
}
file.close();
}
void save_space_vector(const std::vector<double> &vals, void save_space_vector(const std::vector<double> &vals,
const std::string &filename, size_t it) { const std::string &filename, size_t it) {
std::ofstream file("results/" + filename + "_" + std::to_string(it) + ".dat"); std::ofstream file("results/" + filename + "_" + std::to_string(it) + ".dat");