Hi Wolfgang,

I took your advice and coded it up. Here dof_handler_1 and fe_1 correspond to 
the 1st mesh, and dof_handler_2, fe_2 correspond to the 2nd mesh.
I am reading both meshes from 2 separate files (I wrote them in ucd format).

  Assert (dim == 2, ExcInternalError());

  //initialize objects that will read in the triangulations
  GridIn<dim> grid_in_1;
  grid_in_1.attach_triangulation (tria_1);
  std::ifstream input_file_1("grid-1.ucd");

  GridIn<dim> grid_in_2;
  grid_in_2.attach_triangulation (tria_2);
  std::ifstream input_file_2("grid-2.ucd");

  //read the grid in UCD format
  grid_in_1.read_ucd (input_file_1);
  grid_in_2.read_ucd (input_file_2);

  //distribute the degrees of freedom
  dof_handler_1.distribute_dofs (fe_1);
  dof_handler_2.distribute_dofs (fe_2);

etc, etc... and then when I try to transfer the solution I wrote:

  typedef
        std::list<std::pair<typename DoFHandler<dim>::cell_iterator,
                  typename DoFHandler<dim>::cell_iterator> >
        CellList;

  CellList finest_common_cells = GridTools::get_finest_common_cells 
(dof_handler_1, dof_handler_2);

  Assert ( fe_1.dofs_per_cell == fe_2.dofs_per_cell, ExcInternalError() );

  Vector<double> local_dof_values( fe_1.dofs_per_cell );


  for (typename CellList::const_iterator cell_pair = 
finest_common_cells.begin();
                cell_pair != finest_common_cells.end();
                ++cell_pair)
    {
      std::cout << cell_pair->first << " " << cell_pair->second << std::endl;
      cell_pair->second->get_interpolated_dof_values(sol_2, local_dof_values);
      cell_pair->first->set_dof_values_by_interpolation(local_dof_values, 
sol_1);
    }

When I run this I encounter the following error:

An error occurred in line <1030> of file <source/grid/grid_tools.cc> in function
    static std::list<std::pair<typename Container::cell_iterator, typename 
Container::cell_iterator>, std::allocator<std::pair<typename 
Container::cell_iterator, typename Container::cell_iterator> > > 
dealii::GridTools::get_finest_common_cells(const Container&, const Container&) 
[with Container = dealii::DoFHandler<2, 2>]
The violated condition was: 
    have_same_coarse_mesh (mesh_1, mesh_2)
The name and call sequence of the exception was:
    ExcMessage ("The two containers must be represent triangulations that " 
"have the same coarse meshes")
Additional Information: 
The two containers must be represent triangulations that have the same coarse 
meshes

The thing is,both meshes come from the same coarse mesh. In fact, mesh # 2 is 
obtained by coarsening and refinement directly from mesh #1. Moreover, they 
both originate from my initial coarse mesh at the initial integration time T0. 
My guess is that reading from a file will only initialize the active cells at 
the moment the grid was written. The coarser "parents" are unknown and hence 
the function is unable to determine that both grids stem from the same parent. 
Is that true? How can I work around this?

Thanks!
-- Mihai




________________________________
Von: Wolfgang Bangerth <[email protected]>
An: [email protected]
CC: mihai alexe <[email protected]>
Gesendet: Freitag, den 19. Februar 2010, 18:12:05 Uhr
Betreff: Re: [deal.II] transfering solution between two different grids


Mihai,

> How can I transfer a discrete solution from one grid to another? My two
> grids are fixed - I am reading them from a file, and grid #2 holds my
> discontinuous Galerkin solution u^h. Grid #2 has been obtained through
> refinement and coarsening directly from grid #1. I want to transfer u^h
> back from grid #2 to grid #1. Is there an API function for doing this? I
> came upon static void VectorTools::interpolate, and I am wondering how I
> can set up my "transfer" matrix beforehand such that I successfully do
> the solution transfer.

Do you need the this as a matrix (i.e. for which you know the matrix 
entries), or would a function that does the job suffice?

In the latter case, this is what I would do:
  std::list<see doc> finest_common_cells
    = GridTools::get_finest_common_cells (dof_handler_1,
                       dof_handler_2);
  std::vector<double> local_dof_values (...);
  for (cell_pair=finest_common_cells.begin(); ...)
    {
       cell_pair.first->get_interpolated_function_values
                (solution_1, local_dof_values);
       cell_pair.first->set_function_values_by_interpolation
                (local_dof_values, solution_2);
    }

Does this setup make sense?

Best
W.

-------------------------------------------------------------------------
Wolfgang Bangerth                email:            [email protected]
                                 www: http://www.math.tamu.edu/~bangerth/

__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen 
Massenmails. 
http://mail.yahoo.com 
_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii

Reply via email to