Passing Cell Obejct to self defined function

27 views
Skip to first unread message

Junxiang Wang

unread,
Dec 4, 2024, 1:44:22 AM12/4/24
to deal.II User Group
Dear DEAL.II Communities,

I encountered the following compile error in the function interpolate(cell,beta) where I wanted to access cell data inside the function and failed to debug it after several methods....
"""
error: passing ‘const multiphyProblem<3>’ as ‘this’ argument discards qualifiers [-fpermissive]
 1018 |             double g_o = interpolate(cell,beta);
"""


The definition of  cell is:
""
   5       typename DoFHandler<dim>::active_cell_iterator cell = dof_handler
   4                                                               .begin_active(),
   3                                                      endc = dof_handler.end();
""
The definition of function interpolate() is:
"""
  13 template <int dim>
  12 double
  11 multiphyProblem<dim>::interpolate(TriaActiveIterator<dealii::DoFCellAccessor<dim, dim, false>>& cell, double      &beta)
  10 {
   9   double g{0};
   8
   7   double x = cell->center()[0] - 0.5;
   6   double y = cell->center()[1] - 0.5;
   5
   4   double r = std::sqrt(std::pow(x,2) + std::pow(y,2));
   3   // definition of g
   8
   9   return g;
  10
  11 }
"""


Do you know any issue may involved in the code? and can give me some hint.

Thanks a lot.

Best regard,

Junxiang Wang

Daniel Arndt

unread,
Dec 4, 2024, 8:30:32 AM12/4/24
to dea...@googlegroups.com
Junxiang Wang,

it looks like you are using a const multiphyProblem instance but its
member function interpolate is not const. Try

multiphyProblem<dim>::interpolate(TriaActiveIterator<dealii::DoFCellAccessor<dim,
dim, false>>& cell, double &beta) const

Best,
Daniel
> --
> 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 visit https://groups.google.com/d/msgid/dealii/35e14bbf-7409-4c59-bedc-1b62f3d118fen%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages