Operator*= works in Step-41 but not in my program

50 views
Skip to first unread message

Xuefeng Li

unread,
Feb 15, 2025, 10:29:47 PM2/15/25
to deal.II User Group
Hi, everyone!

I ran into a compiler error that feels strange to me. And I use C++ only occasionally.

/home/li/cbrc01.cc:1378:8: error: no match for ‘operator*=’ (operand types are ‘const dealii::TrilinosWrappers::MPI::Vector’ and ‘int’)
 1378 |     um *= -1;
      |     ~~~^~~~~
/home/li/share/dealii-9.6.0/include/deal.II/lac/trilinos_vector.h:1993:5: note: candidate: ‘dealii::TrilinosWrappers::MPI::Vector& dealii::TrilinosWrappers::MPI::Vector::operator*=(dealii::TrilinosScalar)’ (near match)
 1993 |     Vector::operator*=(const TrilinosScalar a)
      |     ^~~~~~
/home/li/share/dealii-9.6.0/include/deal.II/lac/trilinos_vector.h:1993:5: note:   passing ‘const dealii::TrilinosWrappers::MPI::Vector*’ as ‘this’ argument discards qualifiers
make[2]: *** [CMakeFiles/cbrc01.dir/build.make:76: CMakeFiles/cbrc01.dir/cbrc01.cc.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/cbrc01.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

According to the above error message, the compiler indeed recognized "um" to be a dealii::TrilinosWrappers::MPI::Vector object. It further suggested that it is a "near match" to the defined operator "Vector::operator*=(const TrilinosScalar a)".

Furthermore, Step-41 used exactly the same operation in method
      void ObstacleProblem<dim>::update_solution_and_constraints()
in the line
      contact_force *= -1;
I was able to compile and run Step-41 without error. That indicates that my installations of dealii and Trilinos work for the operator *=.

Your help is greatly appreciated. Thanks in advance.

Best,

X. Li




Praveen C

unread,
Feb 16, 2025, 1:18:50 AM2/16/25
to Deal. II Googlegroup
Maybe the clue is already in the error message


On 16 Feb 2025, at 8:59 AM, 'Xuefeng Li' via deal.II User Group <dea...@googlegroups.com> wrote:

/home/li/cbrc01.cc:1378:8: error: no match for ‘operator*=’ (operand types are ‘const dealii::TrilinosWrappers::MPI::Vector’ and ‘int’)
 1378 |     um *= -1;


Your um seems to be declared const in this context.

best
praveen

Xuefeng Li

unread,
Feb 16, 2025, 6:41:00 PM2/16/25
to dea...@googlegroups.com
I see. That's my newbie mistake. Thanks again for pointing out the root of the problem.

Best,

--Xuefeng Li, (504)865-3340(phone)
   Chair, Department of Mathematics and Computer Science
   Like floating clouds, the heart rests easy
   Like flowing water, the spirit stays free
      Loyola University New Orleans
   New Orleans, Louisiana (504)865-2051(fax)


--
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/EC795410-00E9-44BF-B001-46E181C08CB7%40gmail.com.
Reply all
Reply to author
Forward
0 new messages