adaptive refining online! it seems to use a single cpu at a time instead of all, need to check this

This commit is contained in:
Vasco C. B. Ferreira
2026-07-08 22:42:04 +02:00
parent 59b95dd096
commit 5651dd580a
7 changed files with 49 additions and 26 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
digraph G {
graph [layout=dot rankdir=LR]
// This is just an example for you to use as a template.
// Edit as you like. Whenever you save a legal graph
// the layout in the graphviz window will be updated.
vim [href="http://www.vim.org/"]
dot [href="http://www.graphviz.org/"]
vimdot [href="file:///usr/bin/vimdot"]
{vim dot} -> vimdot
}
+13 -5
View File
@@ -19,14 +19,18 @@ template <int dim> struct CellInfo {
double h; double h;
}; };
template <int dim> struct CellLocation {
const CellInfo<dim> *info;
Point<dim> reference_point;
};
template <int dim> class CellLocator { template <int dim> class CellLocator {
public: public:
using CellIterator = typename DoFHandler<dim>::active_cell_iterator; using CellIterator = typename DoFHandler<dim>::active_cell_iterator;
void rebuild(const DoFHandler<dim> &dof_handler, void rebuild(const DoFHandler<dim> &dof_handler,
const Triangulation<dim> &triangulation); const Triangulation<dim> &triangulation);
CellLocation<dim> locate(const Point<dim> &p) const;
CellIterator locate(const Point<dim> &p) const;
private: private:
std::vector<CellInfo<dim>> cells; std::vector<CellInfo<dim>> cells;
@@ -58,8 +62,7 @@ void CellLocator<dim>::rebuild(const DoFHandler<dim> &dof_handler,
} }
template <int dim> template <int dim>
typename DoFHandler<dim>::active_cell_iterator CellLocation<dim> CellLocator<dim>::locate(const Point<dim> &p) const {
CellLocator<dim>::locate(const Point<dim> &p) const {
static_assert(dim == 1, static_assert(dim == 1,
"Current CellLocator implementation only supports 1D."); "Current CellLocator implementation only supports 1D.");
@@ -82,7 +85,12 @@ CellLocator<dim>::locate(const Point<dim> &p) const {
AssertThrow(x >= it->lower[0] - 1e-12 && x <= it->upper[0] + 1e-12, AssertThrow(x >= it->lower[0] - 1e-12 && x <= it->upper[0] + 1e-12,
ExcMessage("CellLocator failed to find containing cell.")); ExcMessage("CellLocator failed to find containing cell."));
return it->cell; CellLocation<dim> location;
location.info = &(*it);
location.reference_point[0] = (p[0] - it->lower[0]) / it->h;
return location;
} }
#endif // !CELLS_H #endif // !CELLS_H
+4 -4
View File
@@ -24,8 +24,8 @@ constexpr double DV = std::abs(V_DOMAIN_RIGHT - V_DOMAIN_LEFT) / NV;
// deal.ii options // deal.ii options
constexpr unsigned int GLOBAL_REFINEMENT = 6; constexpr unsigned int GLOBAL_REFINEMENT = 6;
constexpr unsigned int FE_DEGREE = 2; constexpr unsigned int FE_DEGREE = 3;
constexpr unsigned int CONVERGENCE_ITERATIONS = 15000; constexpr unsigned int CONVERGENCE_ITERATIONS = 5000;
constexpr double CONVERGENCE_LIMIT = 1e-8; constexpr double CONVERGENCE_LIMIT = 1e-8;
constexpr double EPS = 0.01; constexpr double EPS = 0.01;
@@ -35,10 +35,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 = 5; constexpr unsigned int REFINE_FREQUENCY = 10;
// Plotting options // Plotting options
constexpr int PLOT_FREQUENCY = 5; 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/";
+7 -5
View File
@@ -132,7 +132,7 @@ 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), : triangulation(Triangulation<dim>::limit_level_difference_at_vertices),
fe(degree), dof_handler(triangulation), mapping(degree) {} dof_handler(triangulation), fe(degree), mapping(degree) {}
template <int dim> template <int dim>
std::vector<double> std::vector<double>
@@ -208,12 +208,14 @@ std::vector<double> PoissonProblem<dim>::eval_vector_grad(
for (unsigned int p = 0; p < points.size(); ++p) { for (unsigned int p = 0; p < points.size(); ++p) {
const auto cell = cell_locator.locate(points[p]); const auto cell_location = cell_locator.locate(points[p]);
cell->get_dof_values(solution, local_solution_buffer.begin(), cell_location.info->cell->get_dof_values(
local_solution_buffer.end()); solution, local_solution_buffer.begin(), local_solution_buffer.end());
evaluator->reinit(cell, ArrayView<const Point<dim>>(&points[p], 1)); evaluator->reinit(
cell_location.info->cell,
ArrayView<const Point<dim>>(&cell_location.reference_point, 1));
evaluator->evaluate(local_solution_buffer, EvaluationFlags::gradients); evaluator->evaluate(local_solution_buffer, EvaluationFlags::gradients);
values[p] = evaluator->get_gradient(0)[0]; values[p] = evaluator->get_gradient(0)[0];
+12 -12
View File
@@ -206,17 +206,17 @@ void NuFISolver::run() {
<< std::endl; << std::endl;
// START: diagnostics // START: diagnostics
std::cout << "cells = " << poisson.triangulation.n_active_cells() std::cout << "cells = " << poisson.triangulation.n_active_cells() << "\n"
<< " dofs = " << poisson.dof_handler.n_dofs() << std::endl; << " dofs = " << poisson.dof_handler.n_dofs() << "\n";
double min_h = 1e100; // double min_h = 1e100;
double max_h = 0; // double max_h = 0;
//
for (auto cell : poisson.triangulation.active_cell_iterators()) { // for (auto cell : poisson.triangulation.active_cell_iterators()) {
min_h = std::min(min_h, cell->diameter()); // min_h = std::min(min_h, cell->diameter());
max_h = std::max(max_h, cell->diameter()); // max_h = std::max(max_h, cell->diameter());
} // }
//
std::cout << "h ratio = " << max_h / min_h << std::endl; // std::cout << "h ratio = " << max_h / min_h << std::endl;
// END: diagnostics // END: diagnostics
@@ -248,7 +248,7 @@ void NuFISolver::run() {
poisson.coarse_and_refine_grid(it, phi_history); poisson.coarse_and_refine_grid(it, phi_history);
refine_time = timer.elapsed() - refine_start; refine_time = timer.elapsed() - refine_start;
std::cout << "Refinement step done in " std::cout << "Refinement step done in "
<< std::to_string(std::floor(refine_time)) << "[s]"; << std::to_string(std::floor(refine_time)) << "[s]" << "\n";
} }
double timer_elapsed = timer.elapsed(); double timer_elapsed = timer.elapsed();