Neumann data and Kelly estimator: can't pass std::map argument

51 views
Skip to first unread message

bob bill

unread,
Jun 16, 2021, 6:29:12 AM6/16/21
to deal.II User Group
Hi everyone,

I'm trying to change a bit the step-7 (Helmotz Problem)

In particular, I'm going to change the estimate function
dof_handler,
QGauss<dim - 1>(fe->degree + 1),
std::map<types::boundary_id, const Function<dim> *>(),
solution,
estimated_error_per_cell);

since I want to encode the fact that we have Neumann data. To do so, I created a function that describes my Neumann data 


template<int dim>
class NeumannData: public Function<dim> {
virtual double value(const Point<dim> &p, const unsigned int) const override;
};

template<int dim>
double NeumannData<dim>::value(const Point<dim> &p, const unsigned int) const {return p[0] + p[1];}


and hence my refine function becomes (in red what I changed w.r.t the original tutorial program)

template<int dim>

void step7<dim>::refine_grid() {

const NeumannData<dim> neumann_func;

switch (refinement_mode) {
case global_refinement: {
triangulation.refine_global(1);

break;

}

case adaptive_refinement: {

Vector<float> estimated_error_per_cell(triangulation.n_active_cells());

KellyErrorEstimator<dim>::estimate(dof_handler,

QGauss<dim - 1>(fe->degree + 1),

std::map<types::boundary_id, const Function<dim> *>(1,&neumann_func),

estimated_error_per_cell);
GridRefinement::refine_and_coarsen_fixed_number(triangulation,

estimated_error_per_cell, 0.3, 0.03);

triangulation.execute_coarsening_and_refinement();
break;

}


default: {

Assert(false, ExcNotImplemented());

}

}

}

The boundary indicator for Neumann data is 1, and I gave a pointer to a constant function as argument.  Unfortunately, the compiler says: "no matching constructor for initialization of 'std::map<types::boundary_id, const Function<2> *>' (aka 'map<unsigned int, const Function<2> *>') std::map<types::boundary_id, const Function<dim> *>(1,&neumann_func),"

What am I missing?


Thanks,

Bob

Wolfgang Bangerth

unread,
Jun 16, 2021, 7:58:48 PM6/16/21
to dea...@googlegroups.com
On 6/16/21 4:29 AM, bob bill wrote:
>
> *The boundary indicator for Neumann data is 1, and I gave a pointer to a
> constant function as argument. **Unfortunately, the compiler says: "*no
> matching constructor for initialization of 'std::map<types::boundary_id, const
> Function<2> *>' (aka 'map<unsigned int, const Function<2> *>')
> std::map<types::boundary_id, const Function<dim> *>(1,&neumann_func),*"*
>
> *What am I missing?*

It has nothing to do with the function you're trying to call. You just can't
create a map by saying
std::map<U,V>(u,v)
where u is a key and v is a value. But you can
std::map<U,V>({{u,v}})

Here, the outer braces enclose a list of pairs, which here has only one
element and that element is initialized by the pair u,v.

Best
W.

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

Reply all
Reply to author
Forward
0 new messages