Hi, Dr. Bangerth,
Thank you very much for prompt reply!
> 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.
OK, I misunderstood it. I thought the numbering of the dof is same as that
of the cell since the degrees of freedom is 1 in FE_DGQ(0).
They are still different, right?
> 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.
OK, got it. I should get the index of dofs instead of that of cells.
> 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.
Again now I understand they are different.
However, for my project, I need to access both
DoFHandler<dim> dof_handler;
DoFHandler<dim> dof_handler_dg;
at the same time.
If I use the following loop,
for (const auto &cell : opt->dof_handler.active_cell_iterators())
{
...
}
how can I access to dof_handler_dg?
My attempting solution is to set up multiple iterator, just as in the
tutorial:
https://www.dealii.org/current/doxygen/deal.II/group__Iterators.html,
typename Triangulation<dim>::active_cell_iterator ti =
opt->triangulation.begin_active();
typename DoFHandler<dim>::active_cell_iterator di1 =
opt->dof_handler.begin_active();
typename DoFHandler<dim>::active_cell_iterator di2 =
opt->dof_handler_dg.begin_active();
Therefore, I set up the loop as follows,
while (cell != opt->triangulation.end())
{
// do someting
++ti;
++di1;
++di2;
}
(Note: now I can access to the cell-based vector x successfully as follows,
di2->get_dof_indices(local_dof_indices_dg);
unsigned int local_dof_indices_dg_int = local_dof_indices_dg.at(0);
opt->x(local_dof_indices_dg_int);
)
However, I found this method is very time-consuming compared to "for (const
auto &cell : opt->dof_handler.active_cell_iterators())", like 11s vs. 1 s.
My question now is: is there other method to access multiple DoFHandler
or/and Triangulation?
Thank you a lot in advance!
Best regards,
Z. B. Zhang
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> www: http://www.math.colostate.edu/~bangerth/
>
>
On Sunday, October 20, 2019 at 1:50:49 PM UTC-4, Wolfgang Bangerth wrote:
>
> 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]
> <javascript:>
> 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/ef6bec01-bf0f-47d1-8c0a-5cc3108f3db8%40googlegroups.com.