Hi,

I'm trying to write out some data from a calculation being run in parallel. 
I've got two vectors, p_local_solution and p_local_rho of type 
PetscWrappers::MPI::Vector. The p_local_solution vector is initialized 
using a statement

p_local_solution.reinit(p_locally_owned_dofs,p_locally_relevant_dofs,p_comm)

and should have ghost nodes included in it and the vector p_local_rho is 
initialized as

p_local_rho.reinit(p_locally_owned_dofs,p_comm)

and doesn't have ghost nodes. The p_local_solution vector is filled with 
values as the result of solving a linear equation, p_local_rho is filled 
with values by looping over individual elements and assigning values 
calculated from other quantities. Part of the reason the p_local_rho vector 
doesn't have ghost nodes is that you can't  access individual elements for 
a ghosted vector. The code I'm using to write out the results looks like 
the following:

        DataOut<dim> data_out;
        data_out.attach_dof_handler(p_dof);
        LA::MPI::Vector phi;
        phi.reinit(p_locally_owned_dofs,p_comm);
        phi = p_local_solution;
        vecScale(phi,1.0/p_units.EP_from_V);
        phi.compress(VectorOperation::insert);
        p_local_solution = phi;
        data_out.add_data_vector(p_local_solution,"Phi");

        LA::MPI::Vector rho;
        vecScale(p_local_rho,1.0/p_charge);
        rho.reinit(p_locally_owned_dofs,p_locally_relevant_dofs,p_comm);
        p_local_rho.compress(VectorOperation::insert);
        rho = p_local_rho;
        data_out.add_data_vector(rho,"Rho");

The DataOut object appears to only handle ghosted vectors. It also appears 
that you need to call compress on non-ghosted vectors (this was determined 
empirically based on error messages). The vecScale function is just 
designed to multiply all values of an un-ghosted vector by a constant. The 
function has the form

    void vecScale(LA::MPI::Vector &vec, double scale)
    {
      std::pair<PETScWrappers::VectorBase::size_type,
        PETScWrappers::VectorBase::size_type> range;
      range = vec.local_range();
      unsigned int lo_idx = range.first;
      unsigned int hi_idx = range.second;
      for (unsigned int i=lo_idx; i<hi_idx; i++) {
        vec[i] *= scale;
      }
    }

If you don't change the values of the vectors using vecScale then the data 
for "Phi" and "Rho" appears smooth (but the scale is unwieldy). If you 
change the values of the vectors using vecScale, then "Phi" looks okay but 
"Rho" appears to have unscaled values at locations that look like they are 
at processor boundaries. I'm puzzled about how this is happening, since my 
understanding is that a data exchange happens when you do the assignment 
rho = p_local_rho. The vecScale function only operates on un-ghosted 
vectors, but is it possible that it is missing some values somewhere?

Bruce

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to