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
+13 -5
View File
@@ -19,14 +19,18 @@ template <int dim> struct CellInfo {
double h;
};
template <int dim> struct CellLocation {
const CellInfo<dim> *info;
Point<dim> reference_point;
};
template <int dim> class CellLocator {
public:
using CellIterator = typename DoFHandler<dim>::active_cell_iterator;
void rebuild(const DoFHandler<dim> &dof_handler,
const Triangulation<dim> &triangulation);
CellIterator locate(const Point<dim> &p) const;
CellLocation<dim> locate(const Point<dim> &p) const;
private:
std::vector<CellInfo<dim>> cells;
@@ -58,8 +62,7 @@ void CellLocator<dim>::rebuild(const DoFHandler<dim> &dof_handler,
}
template <int dim>
typename DoFHandler<dim>::active_cell_iterator
CellLocator<dim>::locate(const Point<dim> &p) const {
CellLocation<dim> CellLocator<dim>::locate(const Point<dim> &p) const {
static_assert(dim == 1,
"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,
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
+4 -4
View File
@@ -24,8 +24,8 @@ constexpr double DV = std::abs(V_DOMAIN_RIGHT - V_DOMAIN_LEFT) / NV;
// deal.ii options
constexpr unsigned int GLOBAL_REFINEMENT = 6;
constexpr unsigned int FE_DEGREE = 2;
constexpr unsigned int CONVERGENCE_ITERATIONS = 15000;
constexpr unsigned int FE_DEGREE = 3;
constexpr unsigned int CONVERGENCE_ITERATIONS = 5000;
constexpr double CONVERGENCE_LIMIT = 1e-8;
constexpr double EPS = 0.01;
@@ -35,10 +35,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 = 5;
constexpr unsigned int REFINE_FREQUENCY = 10;
// Plotting options
constexpr int PLOT_FREQUENCY = 5;
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/";
+7 -5
View File
@@ -132,7 +132,7 @@ void PoissonProblem<dim>::set_rhs_function(
template <int dim>
PoissonProblem<dim>::PoissonProblem(unsigned int degree)
: 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>
std::vector<double>
@@ -208,12 +208,14 @@ std::vector<double> PoissonProblem<dim>::eval_vector_grad(
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(),
local_solution_buffer.end());
cell_location.info->cell->get_dof_values(
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);
values[p] = evaluator->get_gradient(0)[0];