|
[Sponsors] |
Why is this an invalid static_cast of scalarField rA? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 11, 2017, 15:22 |
Why is this an invalid static_cast of scalarField rA?
|
#1 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 250
Rep Power: 22 |
Why is this operation invalid and how can I fix it?
scalar rA_low = static_cast<float>(rA); rA is a scalarField in PCG.C, and I need a float version of it which I call rA_low. I get the following error message: myMPPCG.C: In member function ‘virtual Foam::solverPerformance Foam::myMPPCG::solve(Foam::scalarField&, const scalarField&, Foam::direction) const’: myMPPCG.C:115:42: error: invalid static_cast from type ‘Foam::scalarField {aka Foam::Field<double>}’ to type ‘float’ scalar rA_low = static_cast<float>(rA); How can I create float versions of scalarFields which are of double type? Klaus |
|
August 11, 2017, 16:02 |
|
#2 |
Senior Member
|
Hi,
scalarField is a field of scalars (or a list of scalars with certain additional operations defined). How you would like to convert a list into single value? If you know, that your field is uniform, then you can use just first element of the list. If your list is non-uniform, propose your way of converting arbitrary list of floats into single float. |
|
August 11, 2017, 16:51 |
I am looking for a typecast double > float of all values
|
#3 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 250
Rep Power: 22 |
Hello,
there's a misunderstanding. My question is about typecasting of the scalar field values. I need another scalarField with typecast rA(double type values) to rA_low (float type values). I tried the following to but that doesn't work either: label rAsize = rA.size(); const scalarField rA_low(rAsize); forAll(rA_low, i) { scalar s = static_cast<float>(rA[i]); rA_low[i] = s; } Klaus |
|
August 11, 2017, 17:19 |
|
#4 |
Senior Member
|
I think it would be better to call it mis-explanation, cause this:
Code:
scalar rA_low = static_cast<float>(rA); OK. It seems, your build is "DP", i.e. scalar is, let's call it alias of, double. So Code:
const scalarField rA_low(rAsize); Code:
scalar s = static_cast<float>(rA[i]); Why no use Field<float> if you want field of floats? Or you can use floatScalar if you want to stay in OpenFOAM types. Also it would be nice to decipher "that doesn't work either". Does not compile? Does not work as expected? Works from time to time? |
|
August 11, 2017, 18:23 |
How to convert and transfer the content of rA?
|
#5 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 250
Rep Power: 22 |
Thank you for the hints.
Yes the build is DP. And now I created an empty scalarField rA_low which can take values of type <float>: label rAsize = rA.size(); floatScalar rA_low(rAsize); The question is, how to typecast and load the data from rA into rA_low? |
|
August 12, 2017, 03:47 |
|
#6 |
Senior Member
|
It seems we are still do not understand each other.
What is wrong with, for example: Code:
Field<float> rA_low(rA.size()); forAll(rA, i) { rA_low[i] = static_cast<float>(rA[i]); } You are constantly trying to convert FIELD (i.e. list of numbers) into SCALAR (single number). |
|
August 12, 2017, 07:08 |
some steps back...
|
#7 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 250
Rep Power: 22 |
There's rA, a List which contains multiple entries in format <double>.
I need the same List with entries in format <float>, this one I call it rA_low. The question is how to do such a "typecast conversion" with the List rA? |
|
August 12, 2017, 07:28 |
|
#8 |
Senior Member
|
So I repeat my question, what is wrong with type conversion in cycle?
|
|
August 12, 2017, 16:19 |
|
#9 |
Senior Member
Klaus
Join Date: Mar 2009
Posts: 250
Rep Power: 22 |
An update, this seems to work:
Code:
List<float> rA_low(nCells); for (int cell=0; cell<nCells; cell++) { rA_low[cell] = static_cast<float>(rA[cell]); } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
parallel simulations - error message: "OPT_ITERATIONS: invalid option name" | v8areu | SU2 | 5 | July 23, 2015 02:57 |
[swak4Foam] GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh | gschaider | OpenFOAM Community Contributions | 300 | October 29, 2014 18:00 |
Problems building Paraview 3.12 on Gentoo Linux | pajot | OpenFOAM Installation | 11 | April 11, 2013 08:09 |
OpenFOAM install on Ubuntu Natty 11.04 | bkubicek | OpenFOAM | 13 | May 26, 2011 05:48 |
Phase locked average in run time | panara | OpenFOAM | 2 | February 20, 2008 14:37 |