Dear Wolfgang, 

thank you for the elaborate and detailed response. I think I can understand 
the problem at hand. The "fix" of removing the "const" keyword indeed 
solved my problem, but I realized only later that it only works when have 
datatype "double" - for complex numbers I still got some error at linking, 
which should then not be related to non-access to a constant vector. I 
ended up running into similar problems with complex numbers when trying to 
use Petsc wrappers at a later stage, so I've know decided to switch to a 
coupled set of real equations instead. It is mentioned several times in the 
tutorials that this is the easier route, that seems to be the case for me.
Either way, your comments were very helpful in getting a clearer picture of 
the issue I ran into - time to extend my knowledge of (modern) C++ it would 
seem. 

Thanks again and best regards,
Kev 

On Thursday, November 10, 2022 at 1:07:10 AM UTC+1 Wolfgang Bangerth wrote:

> 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/d1584ad3-e9b9-4012-80d8-57e6a195bb45n%40googlegroups.com.

Reply via email to