Hi Peter,
Thanks a lot for your help! I was trying to implement a MWE with the first
method you suggested. However, the function
VectorTools::interpolate_to_different_mesh() seems to be causing a linker
error:
/home/usrname/Projects/hdg_dealii/adr/ip/multilevel_refinement/MultilevelRefinement.cc:
66: error: undefined reference to 'void
dealii::VectorTools::interpolate_to_different_mesh<2, 2,
dealii::Vector<int> >(dealii::DoFHandler<2, 2> const&, dealii::Vector<int>
const&, dealii::DoFHandler<2, 2> const&, dealii::Vector<int>&)' collect2:
error: ld returned 1 exit status make[2]: ***
[CMakeFiles/MultilevelRefinement.dir/build.make:133: MultilevelRefinement]
Error 1 make[1]: *** [CMakeFiles/Makefile2:90:
CMakeFiles/MultilevelRefinement.dir/all] Error 2 make: *** [Makefile:91:
all] Error 2
Here is, I think, the relevant chunk of code (original code file is also
attached):
// ... #include <deal.II/numerics/vector_tools.h> // ... Triangulation<dim>
triangulation_old; triangulation_old.copy_triangulation(triangulation);
DoFHandler<dim> dof_handler_old(triangulation_old);
dof_handler_old.distribute_dofs(fe); Vector<int> ref_level_old(ref_level);
triangulation.execute_coarsening_and_refinement();
dof_handler.reinit(triangulation); dof_handler.distribute_dofs(fe);
ref_level.reinit(dof_handler.n_dofs());
VectorTools::interpolate_to_different_mesh(dof_handler_old, ref_level_old,
dof_handler, ref_level); // ...
Can you help shed some light on this?
Best regards,
Yuan
On Thursday, November 9, 2023 at 6:25:45 AM UTC [email protected] wrote:
> Hi Greg,
>
> I guess what you could do is to treat the vector as vector associated with
> a DoFHandler with FE_DGQ(0). During each refinement you "interpolate" the
> vector to the new mesh and decrease the value by one. This approach
> naturally extends to a parallel setting.
>
> Alternately, you could create a single vector associated the coarse cells
> and while looping over active cells of the refined mesh you would
> recursively call the parent cell until you reach the coarsest cell whose id
> you can use to access the vector. In the parallel setting, the vector
> associated to the coarse cells would need to replicated between processes.
>
> Hope this help,
> PM
>
> On Thursday, 9 November 2023 at 03:32:42 UTC+1 [email protected] wrote:
>
>> Dear all,
>>
>> This might be a somewhat odd feature request but I was wondering whether
>> the functionality described below can be readily achieved in deal.II
>> already:
>>
>> Say we are given a coarse mesh with every cell never refined, and a
>> vector of non-negative integers associated with each cell. The integer is
>> the level of isotropic refinement to be applied to each cell. The number
>> can be 0, which means not doing anything here; it can be 1, which
>> corresponds to what set_refine_flag() does. But it can also be any
>> number bigger than 1. Say we have a quadrilateral cell and the number
>> associated with it is 2, then the cell is to be refined isotropically once
>> into four children and then every child is refined again, resulting in 16
>> grandchildren.
>>
>> If we were to hard code this, would it be sound to simply rely on
>> set_refine_flag() and execute the refinement one level after another for
>> M levels, with M being the maximum number of the given vector? And perhaps
>> to do this we would need iterators triangulation.begin(n),
>> triangulation.end(n) and isotropic_child() involved somehow?
>>
>> Any help and/or pro tips would be greatly appreciated!
>>
>> Best regards,
>> Yuan
>>
>>
>
--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see
https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/dealii/578acf33-d519-4f8c-bd41-d8a5f3e11b9en%40googlegroups.com.
#include <deal.II/grid/tria.h>
#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/grid_refinement.h>
#include <deal.II/grid/grid_out.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/fe/fe_dgq.h>
#include <deal.II/fe/fe_values.h>
#include <deal.II/lac/vector.h>
#include <deal.II/numerics/vector_tools.h>
#include <experimental/random>
#include <iostream>
#include <fstream>
using namespace dealii;
int main()
{
const unsigned int dim = 2;
FE_DGQ<dim> fe(0);
Triangulation<dim> triangulation;
GridGenerator::hyper_cube(triangulation);
triangulation.refine_global(1);
DoFHandler<dim> dof_handler(triangulation);
dof_handler.distribute_dofs(fe);
Vector<int> ref_level(dof_handler.n_dofs());
for (auto &element : ref_level) {
element = std::experimental::randint(0, 2);
std::cout << "refinement level at this cell: " << element << '\n';
}
unsigned int flags = 0;
while (flags > 0){
flags = 0;
for (auto &cell : triangulation.active_cell_iterators()) {
unsigned int cell_index = cell->active_cell_index();
unsigned int ref_left = ref_level(cell_index);
if (ref_left > 0){
ref_level(cell_index) -= 1;
if (ref_left == 1)
continue;
cell->set_refine_flag();
flags += 1;
}
}
if (flags > 0){
Triangulation<dim> triangulation_old;
triangulation_old.copy_triangulation(triangulation);
DoFHandler<dim> dof_handler_old(triangulation_old);
dof_handler_old.distribute_dofs(fe);
Vector<int> ref_level_old(ref_level);
triangulation.execute_coarsening_and_refinement();
dof_handler.reinit(triangulation);
dof_handler.distribute_dofs(fe);
ref_level.reinit(dof_handler.n_dofs());
VectorTools::interpolate_to_different_mesh(dof_handler_old,
ref_level_old,
dof_handler,
ref_level);
}
}
std::ofstream out_gnu("amr.gnuplot");
GridOut().write_gnuplot(triangulation, out_gnu);
}