Parser does not read nans
NANs are printed as "-nan" is ASCII format, and the parser cannot read them back.
The specific error message is:
--> FOAM FATAL IO ERROR:
wrong token type - expected Scalar, found on line 24216: punctuation '-'
file: <...> at line 24216.
From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::doubleScalar&)
in file lnInclude/Scalar.C at line 160.
The content of the mentioned line is
-nan
No child items are currently assigned. Use child items to break down this issue into smaller parts.
Link issues together to show that they're related. Learn more.
Activity
- Maintainer
Hi @ilyapopov , could you please provide us a Minimal Working Example?
You can access the guides for this as shown below in the links:
How to create a Minimal, Complete, and Verifiable example
Many thanks for your time.
- Author Maintainer
#include <limits> #include "fvCFD.H" #include "IFstream.H" int main() { { Foam::OFstream f1("data.txt"); f1 << std::numeric_limits<double>::quiet_NaN() << Foam::endl; } { Foam::IFstream f2("data.txt"); double x; f2 >> x; } }
Output:
--> FOAM FATAL IO ERROR: wrong token type - expected Scalar, found on line 1: word 'nan' file: data.txt at line 1. From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::doubleScalar&) in file lnInclude/Scalar.C at line 160. FOAM exiting
By Ilya Popov on 2019-02-05T18:26:12 (imported from GitLab project)
Edited by Admin - Maintainer
Hi,
Why do you want to initialise (or read at least) 'not-a-point' into an OF container?
You would use quiet NaN to allow the "missing value" to propagate through a computation, true. Yet sooner or later, signalling NaN will occur to catch a floating point exception in OpenFOAM wherein you cannot proceed with "missing values". Since no NaN is comparable to any other NaN, there is also no use for them in boolean comparisons.
You may want your C++ container contains a "missing value" (pretend this corresponds to a spreadsheet column, for instance, in which some of the cells do not have a value, but their existence is significant). This might be valid approach in some C++ code.
For some operations, like in OpenFOAM, you do not want to allow a container to possess a "missing value.", anyways.
Could you please elaborate the purpose of this in OpenFOAM context, if possible?
- Author Maintainer
My parallel simulation has generated a NAN value in one of the fields. I want to a) reconstruct it b) visualize it to see where it occurred. Currently, I can not. The only thing I can do is open the field file in a text editor and there is a NAN somewhere.
By Ilya Popov on 2019-02-05T22:05:04 (imported from GitLab project)
- Maintainer
IMHO, you can grep the nans, and replace them with a very great scalar or vector value (or sed inplace), and reconstruct it to see their whereabouts.
Edited by Kutalmış Berçin - Author Maintainer
Yes, this is what I decided to do.
I believe this is a bug if data does not round-trip through the save-load process. Imagine a Word document that after saving could not be loaded back into Word. Would you consider it a bug or "support question"?
By Ilya Popov on 2019-02-05T23:23:04 (imported from GitLab project)
- Maintainer
Of course, probably shouldn't be generating NaN at all. But even if we wanted to parse fields with NaN, we would definitely want to abort immediately after that. I wouldn't like the idea of reading a field with a bunch of NaN and trying to calculate with it.
Does the VTK OpenFOAM reader manage to parse NaN? That might be a way. /mark
- Maintainer
If you write in binary, there should be no parsing error.
- Kutalmış Berçin closed
closed