mirror of
https://codeberg.org/vcbferreira/NuFI_deal.ii
synced 2026-08-12 14:33:18 +02:00
refinment working with history of grids
This commit is contained in:
@@ -1,36 +1,45 @@
|
||||
# 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: all
|
||||
|
||||
.PHONY : default_target
|
||||
|
||||
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
|
||||
.NOTPARALLEL:
|
||||
|
||||
|
||||
#=============================================================================
|
||||
# Special targets provided by cmake.
|
||||
|
||||
# Disable implicit rules so canonical targets will work.
|
||||
.SUFFIXES:
|
||||
|
||||
|
||||
# Disable VCS-based implicit rules.
|
||||
% : %,v
|
||||
|
||||
|
||||
# Disable VCS-based implicit rules.
|
||||
% : RCS/%
|
||||
|
||||
|
||||
# Disable VCS-based implicit rules.
|
||||
% : RCS/%,v
|
||||
|
||||
|
||||
# Disable VCS-based implicit rules.
|
||||
% : SCCS/s.%
|
||||
|
||||
|
||||
# Disable VCS-based implicit rules.
|
||||
% : s.%
|
||||
|
||||
|
||||
.SUFFIXES: .hpux_make_needs_suffix_list
|
||||
|
||||
|
||||
# Command-line flag to silence nested $(MAKE).
|
||||
$(VERBOSE)MAKESILENT = -s
|
||||
|
||||
@@ -39,6 +48,7 @@ $(VERBOSE).SILENT:
|
||||
|
||||
# A target that is always out of date.
|
||||
cmake_force:
|
||||
|
||||
.PHONY : cmake_force
|
||||
|
||||
#=============================================================================
|
||||
@@ -48,10 +58,10 @@ cmake_force:
|
||||
SHELL = /bin/sh
|
||||
|
||||
# The CMake executable.
|
||||
CMAKE_COMMAND = /usr/bin/cmake
|
||||
CMAKE_COMMAND = /usr/local/bin/cmake
|
||||
|
||||
# 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.
|
||||
EQUALS = =
|
||||
@@ -65,26 +75,28 @@ CMAKE_BINARY_DIR = /home/vf/Thesis/dealII_NuFI/1x1v
|
||||
#=============================================================================
|
||||
# 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
|
||||
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)
|
||||
.PHONY : edit_cache
|
||||
|
||||
# Special rule for the target edit_cache
|
||||
edit_cache/fast: edit_cache
|
||||
|
||||
.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
|
||||
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
|
||||
@@ -99,6 +111,7 @@ clean:
|
||||
|
||||
# The main clean target
|
||||
clean/fast: clean
|
||||
|
||||
.PHONY : clean/fast
|
||||
|
||||
# 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
|
||||
.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
|
||||
|
||||
@@ -142,7 +142,21 @@ nufi_poisson/fast:
|
||||
$(MAKE) $(MAKESILENT) -f CMakeFiles/nufi_poisson.dir/build.make CMakeFiles/nufi_poisson.dir/build
|
||||
.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
|
||||
|
||||
.PHONY : src/main.o
|
||||
|
||||
# target to build an object file
|
||||
@@ -151,6 +165,7 @@ src/main.cc.o:
|
||||
.PHONY : src/main.cc.o
|
||||
|
||||
src/main.i: src/main.cc.i
|
||||
|
||||
.PHONY : src/main.i
|
||||
|
||||
# target to preprocess a source file
|
||||
@@ -159,6 +174,7 @@ src/main.cc.i:
|
||||
.PHONY : src/main.cc.i
|
||||
|
||||
src/main.s: src/main.cc.s
|
||||
|
||||
.PHONY : src/main.s
|
||||
|
||||
# target to generate assembly for a file
|
||||
@@ -167,6 +183,7 @@ src/main.cc.s:
|
||||
.PHONY : src/main.cc.s
|
||||
|
||||
src/nufi_solver.o: src/nufi_solver.cc.o
|
||||
|
||||
.PHONY : src/nufi_solver.o
|
||||
|
||||
# target to build an object file
|
||||
@@ -175,6 +192,7 @@ src/nufi_solver.cc.o:
|
||||
.PHONY : src/nufi_solver.cc.o
|
||||
|
||||
src/nufi_solver.i: src/nufi_solver.cc.i
|
||||
|
||||
.PHONY : src/nufi_solver.i
|
||||
|
||||
# target to preprocess a source file
|
||||
@@ -183,6 +201,7 @@ src/nufi_solver.cc.i:
|
||||
.PHONY : src/nufi_solver.cc.i
|
||||
|
||||
src/nufi_solver.s: src/nufi_solver.cc.s
|
||||
|
||||
.PHONY : src/nufi_solver.s
|
||||
|
||||
# target to generate assembly for a file
|
||||
@@ -191,6 +210,7 @@ src/nufi_solver.cc.s:
|
||||
.PHONY : src/nufi_solver.cc.s
|
||||
|
||||
src/save_results.o: src/save_results.cc.o
|
||||
|
||||
.PHONY : src/save_results.o
|
||||
|
||||
# target to build an object file
|
||||
@@ -199,6 +219,7 @@ src/save_results.cc.o:
|
||||
.PHONY : src/save_results.cc.o
|
||||
|
||||
src/save_results.i: src/save_results.cc.i
|
||||
|
||||
.PHONY : src/save_results.i
|
||||
|
||||
# target to preprocess a source file
|
||||
@@ -207,6 +228,7 @@ src/save_results.cc.i:
|
||||
.PHONY : src/save_results.cc.i
|
||||
|
||||
src/save_results.s: src/save_results.cc.s
|
||||
|
||||
.PHONY : src/save_results.s
|
||||
|
||||
# target to generate assembly for a file
|
||||
|
||||
@@ -7,6 +7,6 @@ This simulation of the Vlasov-Poisson system in 1x1v dimensions uses
|
||||
---
|
||||
status:
|
||||
|
||||
Fail
|
||||
|
||||
--------------------------------------------------------
|
||||
Refinement working:
|
||||
- grid versions saved on a vector
|
||||
- solutions point to a version of the grid
|
||||
|
||||
+4
-16
@@ -37,30 +37,18 @@ if(NOT DEFINED CMAKE_CROSSCOMPILING)
|
||||
set(CMAKE_CROSSCOMPILING "FALSE")
|
||||
endif()
|
||||
|
||||
# Set path to fallback-tool for dependency-resolution.
|
||||
# Set default install directory permissions.
|
||||
if(NOT DEFINED CMAKE_OBJDUMP)
|
||||
set(CMAKE_OBJDUMP "/usr/bin/objdump")
|
||||
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 MATCHES "^[a-zA-Z0-9_.+-]+$")
|
||||
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()
|
||||
set(CMAKE_INSTALL_MANIFEST "install_manifest.txt")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_INSTALL_LOCAL_ONLY)
|
||||
file(WRITE "/home/vf/Thesis/dealII_NuFI/1x1v/${CMAKE_INSTALL_MANIFEST}"
|
||||
string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT
|
||||
"${CMAKE_INSTALL_MANIFEST_FILES}")
|
||||
file(WRITE "/home/vf/Thesis/dealII_NuFI/1x1v/${CMAKE_INSTALL_MANIFEST}"
|
||||
"${CMAKE_INSTALL_MANIFEST_CONTENT}")
|
||||
endif()
|
||||
|
||||
Binary file not shown.
+14
-49
@@ -48,6 +48,8 @@ template <int dim> struct GridStructure {
|
||||
|
||||
std::vector<double> values(points.size());
|
||||
|
||||
// Uses point_gradient
|
||||
|
||||
// #pragma omp parallel for
|
||||
// for (unsigned int p = 0; p < points.size(); ++p) {
|
||||
//
|
||||
@@ -60,6 +62,7 @@ template <int dim> struct GridStructure {
|
||||
// return values;
|
||||
// }
|
||||
|
||||
// Uses cell locator
|
||||
#pragma omp parallel
|
||||
{
|
||||
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];
|
||||
}
|
||||
}
|
||||
// AssertThrow(dof_handler->n_dofs() == solution.size(),
|
||||
// ExcMessage("Solution vector size does not match
|
||||
// DoFHandler.)");
|
||||
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.dof_handler = std::make_unique<DoFHandler<dim>>(*grid.triangulation);
|
||||
|
||||
grid.dof_handler->distribute_dofs(*grid.fe);
|
||||
|
||||
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>>();
|
||||
|
||||
// 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();
|
||||
grid.constraints = std::make_unique<AffineConstraints<double>>();
|
||||
|
||||
DoFTools::make_hanging_node_constraints(*grid.dof_handler, *grid.constraints);
|
||||
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->set_inhomogeneity(gauge_dof, 0.0);
|
||||
|
||||
grid.constraints->close();
|
||||
|
||||
DynamicSparsityPattern dsp(grid.dof_handler->n_dofs());
|
||||
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 = std::make_unique<CellLocator<dim>>();
|
||||
grid.locator->rebuild(*grid.dof_handler, *grid.triangulation);
|
||||
// END
|
||||
|
||||
solution_transfer.interpolate(coarse_solution, poisson.solution);
|
||||
// END
|
||||
|
||||
// START: diagnostics
|
||||
AssertThrow(
|
||||
@@ -169,32 +148,18 @@ GridStructure<dim> make_grid_snapshot(PoissonProblem<dim> &poisson) {
|
||||
grid.constraints->n_constraints(),
|
||||
ExcMessage(
|
||||
"PoissonProblem constraints doesn't match Snapshot constraints"));
|
||||
for (auto c1 = poisson.get_dof_handler().begin_active(),
|
||||
c2 = grid.dof_handler->begin_active();
|
||||
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> d2(c2->get_fe().dofs_per_cell);
|
||||
|
||||
c1->get_dof_indices(d1);
|
||||
c2->get_dof_indices(d2);
|
||||
|
||||
AssertThrow(d1 == d2, ExcInternalError());
|
||||
}
|
||||
// for (auto c1 = poisson.get_dof_handler().begin_active(),
|
||||
// c2 = grid.dof_handler->begin_active();
|
||||
// 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> d2(c2->get_fe().dofs_per_cell);
|
||||
//
|
||||
// auto support_points =
|
||||
// DoFTools::map_dofs_to_support_points(*grid.mapping, *grid.dof_handler);
|
||||
// c1->get_dof_indices(d1);
|
||||
// c2->get_dof_indices(d2);
|
||||
//
|
||||
// std::cout << "COPY\n";
|
||||
//
|
||||
// for (const auto &[dof, point] : support_points) {
|
||||
// std::cout << dof << " : " << point[0] << "\n";
|
||||
// AssertThrow(d1 == d2, ExcInternalError());
|
||||
// }
|
||||
// for (auto cell : grid.dof_handler->active_cell_iterators()) {
|
||||
// std::cout << "@ GridStructure: " << cell->id() << " " <<
|
||||
// cell->center()[0]
|
||||
// << '\n';
|
||||
// }
|
||||
// END
|
||||
// END: diagnostics
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
+2
-2
@@ -26,11 +26,11 @@ public:
|
||||
const std::vector<SolutionSnapshot<1>> &phi_history,
|
||||
const unsigned int Nv = Parameters::NV) const;
|
||||
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<SolutionSnapshot<1>> &phi_history) const;
|
||||
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<SolutionSnapshot<1>> &phi_history) const;
|
||||
|
||||
|
||||
+3
-3
@@ -23,7 +23,7 @@ constexpr unsigned int NV = 128;
|
||||
constexpr double DV = std::abs(V_DOMAIN_RIGHT - V_DOMAIN_LEFT) / NV;
|
||||
|
||||
// deal.ii options
|
||||
constexpr unsigned int GLOBAL_REFINEMENT = 8;
|
||||
constexpr unsigned int GLOBAL_REFINEMENT = 6;
|
||||
constexpr unsigned int FE_DEGREE = 3;
|
||||
constexpr unsigned int CONVERGENCE_ITERATIONS = 5000;
|
||||
constexpr double CONVERGENCE_LIMIT = 1e-8;
|
||||
@@ -39,10 +39,10 @@ constexpr double F0_FACTOR = 0.39894228040143267793994; // 1/sqrt(2pi)
|
||||
// NUFI options
|
||||
constexpr double DT = 1. / 10.;
|
||||
constexpr unsigned int TMAX = 100;
|
||||
constexpr unsigned int REFINE_FREQUENCY = 3;
|
||||
constexpr unsigned int REFINE_FREQUENCY = 30;
|
||||
|
||||
// Plotting options
|
||||
constexpr int PLOT_FREQUENCY = 1;
|
||||
constexpr int PLOT_FREQUENCY = 10;
|
||||
constexpr size_t PLOT_NX = CALC_NX;
|
||||
constexpr double PLOT_DX = LX / PLOT_NX;
|
||||
const std::string PLOT_DIR = "results/";
|
||||
|
||||
+34
-56
@@ -103,43 +103,27 @@ public:
|
||||
|
||||
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:
|
||||
void create_mesh();
|
||||
void setup_system();
|
||||
void assemble_system();
|
||||
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>> &)>
|
||||
rhs_function;
|
||||
// Vector<double> rhs;
|
||||
|
||||
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;
|
||||
|
||||
// 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>
|
||||
PoissonProblem<dim>::PoissonProblem(unsigned int degree)
|
||||
: // triangulation(Triangulation<dim>::limit_level_difference_at_vertices),
|
||||
triangulation(), dof_handler(triangulation), fe(degree), mapping(degree) {
|
||||
: mapping(degree), fe(degree), triangulation(), dof_handler(triangulation) {
|
||||
}
|
||||
|
||||
// Uses FEPointEvaluation
|
||||
template <int dim>
|
||||
std::vector<double>
|
||||
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 Point<dim> point(x);
|
||||
|
||||
// 1. Find the active cell containing x
|
||||
const auto cell_point_pair =
|
||||
GridTools::find_active_cell_around_point(mapping, dof_handler, point);
|
||||
|
||||
const auto cell = cell_point_pair.first;
|
||||
const Point<dim> &unit_point = cell_point_pair.second;
|
||||
|
||||
// 2. FEPointEvaluation expects an ArrayView of points
|
||||
std::vector<Point<dim>> points(1, unit_point);
|
||||
ArrayView<const Point<dim>> point_view(points);
|
||||
|
||||
FEPointEvaluation<1, dim> evaluator(mapping, dof_handler.get_fe(),
|
||||
update_gradients);
|
||||
|
||||
// reinit with ArrayView of points
|
||||
evaluator.reinit(cell, point_view);
|
||||
|
||||
Vector<double> local_dofs(dof_handler.get_fe().dofs_per_cell);
|
||||
cell->get_dof_values(solution, local_dofs);
|
||||
|
||||
// 3. Evaluate gradient at this point
|
||||
evaluator.evaluate(local_dofs, EvaluationFlags::gradients);
|
||||
|
||||
const Tensor<1, dim> grad_phi = evaluator.get_gradient(0);
|
||||
|
||||
// 4. Compute E = -grad(phi)
|
||||
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) {
|
||||
|
||||
std::cout << "Calling PoissonProblem::solve for time-step " << it << "\n";
|
||||
|
||||
SolverControl solver_control(Parameters::CONVERGENCE_ITERATIONS,
|
||||
Parameters::CONVERGENCE_LIMIT *
|
||||
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());
|
||||
constraints.distribute(solution);
|
||||
|
||||
std::ofstream out("results/phi_after_solve_" + std::to_string(it) + ".dat");
|
||||
std::vector<std::pair<double, double>> data;
|
||||
|
||||
const auto support =
|
||||
DoFTools::map_dofs_to_support_points(mapping, dof_handler);
|
||||
|
||||
for (const auto &[dof, p] : support) {
|
||||
data.emplace_back(p[0], solution[dof]);
|
||||
}
|
||||
|
||||
std::sort(data.begin(), data.end());
|
||||
|
||||
for (const auto &[x, value] : data) {
|
||||
out << x << " " << value << "\n";
|
||||
}
|
||||
|
||||
std::vector<double> E_x =
|
||||
sample_electric_field(Parameters::X_DOMAIN_LEFT,
|
||||
Parameters::X_DOMAIN_RIGHT, Parameters::PLOT_NX);
|
||||
save_space_vector(E_x, "E_x_after_solve", it);
|
||||
// std::ofstream out("results/phi_after_solve_" + std::to_string(it) +
|
||||
// ".dat"); std::vector<std::pair<double, double>> data;
|
||||
//
|
||||
// const auto support =
|
||||
// DoFTools::map_dofs_to_support_points(mapping, dof_handler);
|
||||
//
|
||||
// for (const auto &[dof, p] : support) {
|
||||
// data.emplace_back(p[0], solution[dof]);
|
||||
// }
|
||||
//
|
||||
// std::sort(data.begin(), data.end());
|
||||
//
|
||||
// for (const auto &[x, value] : data) {
|
||||
// out << x << " " << value << "\n";
|
||||
// }
|
||||
//
|
||||
// std::vector<double> E_x =
|
||||
// sample_electric_field(Parameters::X_DOMAIN_LEFT,
|
||||
// Parameters::X_DOMAIN_RIGHT, Parameters::PLOT_NX);
|
||||
// save_space_vector(E_x, "E_x_after_solve", it);
|
||||
}
|
||||
|
||||
template <int dim> void PoissonProblem<dim>::initialize() {
|
||||
@@ -512,13 +493,10 @@ void PoissonProblem<dim>::solve_step(
|
||||
if (refining) {
|
||||
coarse_and_refine_grid(it);
|
||||
setup_system();
|
||||
update_grid_versions(grid_versions, *this);
|
||||
}
|
||||
|
||||
assemble_system();
|
||||
solve(it);
|
||||
|
||||
if (refining)
|
||||
update_grid_versions(grid_versions, *this);
|
||||
}
|
||||
|
||||
// NuFI doesnt use this, kept only for testing PoissonProblem
|
||||
|
||||
+1
-6
@@ -19,12 +19,7 @@ void save_rho(const NuFISolver &solver, unsigned int n,
|
||||
std::vector<SolutionSnapshot<1>> &phi_history,
|
||||
unsigned int Nx_out, const std::string &filename);
|
||||
|
||||
void save_Efield(unsigned int n, GridStructure<1> &grid_struct,
|
||||
std::vector<SolutionSnapshot<1>> &phi_history,
|
||||
unsigned int Nx_out, const std::string &filename);
|
||||
|
||||
void save_Efield_new(unsigned int it,
|
||||
std::vector<GridStructure<1>> &grid_versions,
|
||||
void save_Efield(unsigned int it, std::vector<GridStructure<1>> &grid_versions,
|
||||
std::vector<SolutionSnapshot<1>> &phi_history,
|
||||
unsigned int Nx_out = Parameters::PLOT_NX);
|
||||
|
||||
|
||||
+9
-18
@@ -27,7 +27,7 @@
|
||||
using namespace dealii;
|
||||
|
||||
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<SolutionSnapshot<1>> &phi_history) const {
|
||||
|
||||
@@ -38,7 +38,7 @@ std::vector<double> NuFISolver::eval_ftilda(
|
||||
if (n == 0) {
|
||||
for (size_t i = 0; i < x_size; ++i)
|
||||
results[i] = f0(X[i], U[i]);
|
||||
reset_x_eval(X);
|
||||
// reset_x_eval(X);
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ std::vector<double> NuFISolver::eval_ftilda(
|
||||
}
|
||||
for (size_t i = 0; i < x_size; ++i)
|
||||
results[i] = f0(X[i], U[i]);
|
||||
reset_x_eval(X);
|
||||
// reset_x_eval(X);
|
||||
return results;
|
||||
}
|
||||
|
||||
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<SolutionSnapshot<1>> &phi_history) const {
|
||||
|
||||
@@ -102,7 +102,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);
|
||||
// reset_x_eval(X);
|
||||
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)
|
||||
results[i] = f0(X[i], U[i]);
|
||||
reset_x_eval(X);
|
||||
// reset_x_eval(X);
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -243,8 +243,8 @@ void NuFISolver::run() {
|
||||
<< std::endl;
|
||||
|
||||
// START: diagnostics
|
||||
std::cout << "cells = " << poisson.triangulation.n_active_cells() << "\n"
|
||||
<< " dofs = " << poisson.dof_handler.n_dofs() << "\n";
|
||||
// std::cout << "cells = " << poisson.triangulation.n_active_cells() << "\n"
|
||||
// << " dofs = " << poisson.dof_handler.n_dofs() << "\n";
|
||||
// double min_h = 1e100;
|
||||
// double max_h = 0;
|
||||
//
|
||||
@@ -311,16 +311,7 @@ void NuFISolver::run() {
|
||||
save_rho(*this, it, grid_versions, phi_history, Parameters::PLOT_NX,
|
||||
"results/rho_" + std::to_string(it) + ".dat");
|
||||
|
||||
// std::vector<double> x_eval_Ex = make_x_eval(Parameters::PLOT_NX);
|
||||
// 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);
|
||||
save_Efield(it, grid_versions, phi_history);
|
||||
|
||||
double int_val = 0.5 * integral_space_vector_squared(
|
||||
grid_versions[phi_history[it].grid_version],
|
||||
|
||||
+2
-26
@@ -72,8 +72,7 @@ void save_rho(const NuFISolver &solver, unsigned int n,
|
||||
file.close();
|
||||
}
|
||||
|
||||
void save_Efield_new(unsigned int it,
|
||||
std::vector<GridStructure<1>> &grid_versions,
|
||||
void save_Efield(unsigned int it, std::vector<GridStructure<1>> &grid_versions,
|
||||
std::vector<SolutionSnapshot<1>> &phi_history,
|
||||
unsigned int Nx_out) {
|
||||
std::vector<double> x_eval_E = make_x_eval(Nx_out);
|
||||
@@ -96,34 +95,11 @@ void save_Efield_new(unsigned int it,
|
||||
E_file << x << " " << E << "\n";
|
||||
|
||||
std::cout << "Saving iteration " << it << " using grid version "
|
||||
<< phi_history[it].grid_version << "\n";
|
||||
<< phi_history[it].grid_version << "\n\n";
|
||||
|
||||
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,
|
||||
const std::string &filename, size_t it) {
|
||||
std::ofstream file("results/" + filename + "_" + std::to_string(it) + ".dat");
|
||||
|
||||
Reference in New Issue
Block a user