Create a LinearAlgebra::distributed::Vector<float> from a LinearAlgebra::distributed::Vector<double>

42 views
Skip to first unread message

Maxi Miller

unread,
Sep 13, 2019, 10:39:12 AM9/13/19
to deal.II User Group
In my program I have to reuse old solutions (due to time dependency), but would like to use them both as double values and float values (preconditioning does not require double values). Unfortunately my old solution is only given as a LinearAlgebra::distributed::Vector<double>(), but I have to use a LinearAlgebra::distributed::Vector<float>. Direct conversion via LinearAlgebra::distributed::Vector<float> float_solution(old_solution) does not work. Are there other ways for conversion?

Wolfgang Bangerth

unread,
Sep 13, 2019, 11:53:37 AM9/13/19
to dea...@googlegroups.com
I think that the other classes all have conversion constructors or
conversion operator=. If this class doesn't have one, you probably want
to add it to support what you need. It should be a relatively easy patch
to write, and we'd of course be happy to take it, as always!

Best
W.

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

Maxi Miller

unread,
Sep 23, 2019, 11:07:30 AM9/23/19
to deal.II User Group
When doing that in my code, I get the error
error: conversion from Vector<double,[...]>’ to non-scalar type Vector<float,[...]>’ requested

thus I assume I have to implement it myself...

Martin Kronbichler

unread,
Sep 23, 2019, 11:17:09 AM9/23/19
to dea...@googlegroups.com

Dear Maxi,

Did you try to call 'operator=' in the same line as you declare the variable? In that case, you still go through the (missing) constructor. It should work if you first declare the float vector in one statement and then assign in the next. We have this function:

https://dealii.org/current/doxygen/deal.II/classLinearAlgebra_1_1distributed_1_1Vector.html#ad364c47c5b3b7b991490cd626c729f0b

Furthermore, there is also a function LinearAlgebra::distributed::Vector::copy_locally_owned_subrange_from() which also works with different number types, say double to float:

https://dealii.org/current/doxygen/deal.II/classLinearAlgebra_1_1distributed_1_1Vector.html#ab792ddb04b95a220e489f2d7f9eee990

(In that case, no data is exchanged, and the vectors need to have compatible locally owned dofs before calling.)

Best,
Martin

--
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 on the web visit https://groups.google.com/d/msgid/dealii/1e88472a-6dce-4a26-ada0-197a82adea63%40googlegroups.com.

Maxi Miller

unread,
Sep 23, 2019, 1:34:29 PM9/23/19
to deal.II User Group
Yes, that worked, thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to dea...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages