Unexpected data output with cell data vector

26 views
Skip to first unread message

vachanpo...@gmail.com

unread,
Jul 7, 2021, 2:08:17 AM7/7/21
to deal.II User Group
Dear all,

I am having some confusion regarding the index used in DataOut for a cell vector.

I have created a distributed vector for storing cell data using p::d::Triangulation::global_active_cell_index_partitioner(). I am accessing the elements using cell->global_active_cell_index().

LA::MPI::Vector vec(partitioner->locally_owned_range(), mpi_comm); // cell vector
LA::MPI::Vector gh_vec(
  partitioner->locally_owned_range(),
  partitioner->ghost_indices(),
  mpi_comm
); // ghosted cell vector

I want to visualise this vector so was adding this to DataOut like so:
// do some computations
// write data
Vector<double> temp_vec(gh_vec); // for data output
data_out.add_data_vector(temp_vec, "vector");

However, seeing the result, it looks like there is some mismatch of indices happening. The vector shows wrong values at wrong places. If I instead do

Vector<double> temp_vec(gh_vec); // for data output
for(auto &cell: dof_handler.active_cell_iterators()){
  if(!(cell->is_locally_owned())) continue;
  temp_vec[cell->index()] = gh_vec[cell->global_active_cell_index()];
}
data_out.add_data_vector(temp_vec, "vector");

... then the output looks as expected. So here I have manually set the entries of the temporary vector using cell->index(), rather than letting the constructor do the job. For 1d meshes both seem to produce the same output.

What is the correct procedure? What kind of cell index does DataOut use internally? Any clarification would be greatly appreciated!

Thanking in anticipation
Vachan

Wolfgang Bangerth

unread,
Jul 9, 2021, 11:28:34 PM7/9/21
to dea...@googlegroups.com
On 7/7/21 12:08 AM, vachanpo...@gmail.com wrote:
>
> Vector<double> temp_vec(gh_vec); // for data output
> for(auto &cell: dof_handler.active_cell_iterators()){
>   if(!(cell->is_locally_owned())) continue;
>   temp_vec[cell->index()] = gh_vec[cell->global_active_cell_index()];
> }
> data_out.add_data_vector(temp_vec, "vector");
>
> ... then the output looks as expected. So here I have manually set the entries
> of the temporary vector using cell->index(), rather than letting the
> constructor do the job. For 1d meshes both seem to produce the same output.
>
> What is the correct procedure? What kind of cell index does DataOut use
> internally? Any clarification would be greatly appreciated!

You want to use cell->active_cell_index() as the index into the vector. The
vector should have
triangulation.n_active_cells()
as its size. This corresponds to the *local* number of active cells, including
ghost and artificial cells (for which vector entries are then just ignored). I
think step-47 shows this (whether in parallel or not doesn't matter in this
regard).

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

vachan potluri

unread,
Jul 10, 2021, 1:15:20 AM7/10/21
to dea...@googlegroups.com
You want to use cell->active_cell_index() as the index into the vector. The
vector should have
   triangulation.n_active_cells()
as its size. This corresponds to the *local* number of active cells, including
ghost and artificial cells (for which vector entries are then just ignored). I
think step-47 shows this (whether in parallel or not doesn't matter in this
regard).

Thank you, that clarifies my doubts.

--
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 dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/fafa93e0-9da2-cf5b-b0f9-8bbfd4e1e75c%40colostate.edu.
Reply all
Reply to author
Forward
0 new messages