diff --git a/libnufi_lib.a b/libnufi_lib.a index e581d10..708e8e1 100644 Binary files a/libnufi_lib.a and b/libnufi_lib.a differ diff --git a/nufi/cells.h b/nufi/cells.h index 76abf15..a6f852c 100644 --- a/nufi/cells.h +++ b/nufi/cells.h @@ -11,11 +11,12 @@ using namespace dealii; template struct CellInfo { + // what needs to be given to evaluator typename DoFHandler::active_cell_iterator cell; - + // usefull for locator Point lower; - Point upper; - double h; + // Point upper; + // double h; }; template class CellLocator { @@ -43,9 +44,8 @@ void CellLocator::rebuild(const DoFHandler &dof_handler, info.cell = cell; info.lower = cell->vertex(0); - info.upper = cell->vertex(GeometryInfo::vertices_per_cell - 1); - - info.h = info.upper[0] - info.lower[0]; + // info.upper = cell->vertex(GeometryInfo::vertices_per_cell - 1); + // info.h = info.upper[0] - info.lower[0]; cells.push_back(info); } diff --git a/nufi/poisson_problem.h b/nufi/poisson_problem.h index 3903126..54755e7 100644 --- a/nufi/poisson_problem.h +++ b/nufi/poisson_problem.h @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -34,8 +35,10 @@ #include #include +#include #include #include +#include #include #include @@ -63,6 +66,7 @@ public: void initialize(); void solve_step(); + void coarse_and_refine_grid(); void run(); void set_rhs_function(std::function &)> f); @@ -104,16 +108,16 @@ private: MappingQ mapping; - // typename DoFHandler::active_cell_iterator - // find_cell(const DoFHandler &dof_handler, const Point x); - - std::vector::active_cell_iterator> active_cells; + CellLocator cell_locator; + // std::vector::active_cell_iterator> active_cells; mutable std::vector local_solution_buffer; mutable std::unique_ptr> evaluator; }; +//====//====// // Utilities +//====//====// template void PoissonProblem::set_rhs_function( @@ -195,31 +199,16 @@ std::vector PoissonProblem::eval_vector_grad( const Vector &solution, const std::vector> &points) const { - const unsigned int n_cells = active_cells.size(); - const double xmin = Parameters::X_DOMAIN_LEFT; - const double h = Parameters::LX / static_cast(n_cells); - std::vector values(points.size()); for (unsigned int p = 0; p < points.size(); ++p) { - const double x = points[p][0]; - const unsigned int cell_index = - std::min(static_cast(std::floor((x - xmin) / h)), - n_cells - 1); // index is at most n_cells - 1 - - const auto cell = active_cells[cell_index]; - - const double xi = (x - cell->vertex(0)[0]) / h; - - Point unit_point; - unit_point[0] = xi; + const auto cell = cell_locator.locate(points[p]); cell->get_dof_values(solution, local_solution_buffer.begin(), local_solution_buffer.end()); - evaluator->reinit(cell, ArrayView>(&unit_point, 1)); - + evaluator->reinit(cell, ArrayView>(&points[p], 1)); evaluator->evaluate(local_solution_buffer, EvaluationFlags::gradients); values[p] = evaluator->get_gradient(0)[0]; @@ -228,15 +217,14 @@ std::vector PoissonProblem::eval_vector_grad( return values; } -// template -// std::vector eval_point_grad(const Mapping &mapping, -// const DoFHandler &dof_handler, -// const Vector &solution, -// const Point &point) { -// Tensor Ex = VectorTools::point_gradient(mapping, dof_handler, solution, -// points); -// return Ex[0]; -// } +template +std::vector +eval_point_grad(const Mapping &mapping, const DoFHandler &dof_handler, + const Vector &solution, const Point &point) { + Tensor Ex = + VectorTools::point_gradient(mapping, dof_handler, solution, point); + return Ex[0]; +} // // template // std::vector eval_vector_grad(const Mapping &mapping, @@ -270,7 +258,9 @@ void PoissonProblem::save_grid_to_file(const std::string &filename) const { std::cout << "Grid written to " << filename << "\n"; } +//======//======// // dealii Poisson +//======//======// template void PoissonProblem::create_mesh() { GridGenerator::hyper_cube(triangulation, Parameters::X_DOMAIN_LEFT, @@ -328,11 +318,7 @@ template void PoissonProblem::setup_system() { system_rhs.reinit(dof_handler.n_dofs()); // used for evaluator to avoid running it anytime there is an eval - active_cells.clear(); - - for (auto cell = dof_handler.begin_active(); cell != dof_handler.end(); - ++cell) - active_cells.push_back(cell); + cell_locator.rebuild(dof_handler, triangulation); local_solution_buffer.resize(fe.n_dofs_per_cell()); evaluator = std::make_unique>(mapping, fe, @@ -383,6 +369,35 @@ template void PoissonProblem::assemble_system() { } } +template void PoissonProblem::coarse_and_refine_grid() { + // Add refinement and coasring algorithm here + Vector error_per_cell(triangulation.n_active_cells()); + + KellyErrorEstimator::estimate( + dof_handler, QGauss(fe.degree + 1), + std::map *>(), solution, + error_per_cell); + + GridRefinement::refine_and_coarsen_fixed_number( + triangulation, error_per_cell, 0.3, + 0.03); // These numbers are to be reviewd and changed + + triangulation.prepare_coarsening_and_refinement(); + + // solution tranafer + + // setup_system + + // solution_transfer interpolate + // non_zero_constraint.distribute(current solution) + // + //======//======// + // CHECK step-15. + + // rebuild cells with the grid + cell_locator.rebuild(dof_handler, triangulation); +} + template void PoissonProblem::solve() { SolverControl solver_control(Parameters::CONVERGENCE_ITERATIONS,