On 11/1/22 01:57, Kev Se wrote:
*** Caution: EXTERNAL Sender ***
Hi,
after some tinkering - and considering the example/tutorial step-23,
where the same project method was supposed to be used - I think I found
a solution. The only difference to my code was that my output_results
method, where the project() function was called, was declared as a
/const/ function. Removing that keyword removed the linking error. So in
the class definition in the above mwe.cc, one changes the declaration from
void output_results(const unsigned int cycle) const;
to
void output_results(const unsigned int cycle);
and identical replacements for the definition. I guess one could have
concluded that by thinking harder about what that const was doing there.
Anyway, thanks for the help and keep up the great work!
Kev -- I still had this on my TODO list, but you already found the
answer. The error message the compiler gives is not useful because it
doesn't point out the error. The issue is that the function being called
has this signature:
template <int dim, typename VectorType, int spacedim>
void
project(const DoFHandler<dim, spacedim> & dof,
const AffineConstraints<typename VectorType::value_type>
&constraints,
const Quadrature<dim> &
quadrature,
const Function<spacedim, typename VectorType::value_type>
&function,
VectorType & vec,
const bool enforce_zero_boundary = false,
const Quadrature<dim - 1> &q_boundary = (...),
const bool project_to_boundary_first = false);
The output, `vec`, of course needs to be a writable vector, but since
you are in a `const` member function, in this line
VectorTools::project(
dof_handler, constraints, QGauss<dim>(degree + 2), DeltaX,
Delta_profile);
your `Delta_profile` vector is `const` as well. This makes no logical
sense, but for the compiler, it just means that it matches
VectorType = const dealii::Vector<std::complex<double> >
for which the *template* makes sense, but no implementation would make
sense, and so deal.II doesn't provide any instantiation either.
The problem with these sorts of things is that C++ does not (or better:
did not) provide convenient ways to say "this template can only be used
if VectorType is not a 'const' type". If we were using C++20, we could
have written this as
template <int dim, typename VectorType, int spacedim>
void project(...)
requires (std::is_const_v(VectorType) == false);
which tells the compiler to only consider the template whenever
VectorType is not a `const` type. In that case, you would have gotten a
compiler error, rather than a linker error, and the problem would have
been clearer. But we're not using C++20 yet, so this will have to wait
for a few years :-)
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/6182d1cf-361e-3292-027c-2a0c29cb97b2%40colostate.edu.