On 10/19/19 3:01 PM, Zhidong Brian Zhang wrote:
> 
> And I initialize the cell-based vector (the pesudo density in topology 
> optimization) as follows,
> 
> opt->locally_owned_cells= opt->dof_handler_dg.locally_owned_dofs();
> DoFTools::extract_locally_relevant_dofs(opt->dof_handler_dg,
>                                              opt->locally_relevant_cells);
> opt->x.reinit(opt->locally_owned_cells,
>                    opt->locally_relevant_cells,
>                    opt->mpi_communicator);
> 
> Is this process correct?

Yes. Though it seems confusing to me that you call these variables 
locally_*_cells, because they really are index sets for degrees of freedom, 
not cells.


> Moreover, I wonder how to access opt->x by the cell ("cell" represents the 
> cell iterator)?

You need to find out which DoF lives on the cell. So you can do
   cell_dg->get_dof_indices(...)
and obtain an array of the local DoF indices (which for a DGQ(0) element has a 
single element) that contains the global index of the DoF that lives on this 
cell.


> My attempting solution is to use the syntax of PETSc directly as follows,
> 
> PetscScalar *xp;
> VecGetArray(opt->x, &xp);  // getting a local array of the global vector
> 
> But when I access it by
> 
> xp[cell->active_cell_index()]

Yes, this does not work. That's because you confuse the index of the cell and 
the index of the DoF that lives on it. You want the latter.

Best
  W.

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

-- 
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/b13ae677-412b-f7c0-40b6-56470833d5e9%40colostate.edu.

Reply via email to