View Issue Details

IDProjectCategoryView StatusLast Update
0002455OpenFOAMBugpublic2017-02-09 17:55
ReporterSahas Assigned Tohenry  
Status resolvedResolutionfixed 
Product Versiondev 
Summary0002455: singleGraph with csv and axis=xyz produce some trash in ouput file
DescriptionRunning functionObject singleGraph with csv-format and axis=xyz produce some trash in the header of the output csv-file (like this:
x,y,z,^@,^@,^@,^@,^@,0,^@,^@,^@,^@,^@,^@,^@,!,^@,^@,^@,^@,^@,^@,^@,.,^@,^@,^@,^@,^@,^@,^@,.,.,.,^@,^@,^@,^@,U_0,U_1,U_2 -- copied from mcedit)
Steps To ReproduceIn tutorial tutorials/incompressible/pimpleFoam/laminar/planarPoiseuille
change system/singleGraph as follows:
setFormat csv;
    type midPoint; // midPoint
    axis xyz; // x, y, z, xyz
Run tutorial. There is some kind of trash in postProcessing/singleGraph/'time'/line_U.csv.
TagsNo tags attached.



2017-02-09 08:47

reporter   ~0007728

Yes, I can confirm this bug. I think the reason for this bug is due to flawed logic in csvSetWriter.C in function writeCoordHeader. With xyz, the condition points.hasVectorAxis() is true. The code then enters in a loop, which goes through all the points in the set, but the index is used to access the points.axis(), which returns the word "xyz". Thus, the first three items will be x,y,z, and the rest are read beyond the buffer and garbage.


2017-02-09 09:17


patch.diff (522 bytes)   
diff --git a/src/fileFormats/sampledSetWriters/csv/csvSetWriter.C b/src/fileFormats/sampledSetWriters/csv/csvSetWriter.C
index 8d69d32..b989428 100644
--- a/src/fileFormats/sampledSetWriters/csv/csvSetWriter.C
+++ b/src/fileFormats/sampledSetWriters/csv/csvSetWriter.C
@@ -185,7 +185,7 @@ void Foam::csvSetWriter<Type>::writeCoordHeader
     if (points.hasVectorAxis())
-        forAll(points, i)
+        forAll(points.axis(), i)
             os << points.axis()[i];
patch.diff (522 bytes)   


2017-02-09 09:19

reporter   ~0007729

I have uploaded a minimal fix, where the looping is done over points.axis().


2017-02-09 17:01

manager   ~0007732

Do you get a lot of compiler warnings from this change?

I get

sampledSetWriters/csv/csvSetWriter.C: In instantiation of ‘void
Foam::csvSetWriter<Type>::writeCoordHeader(const Foam::coordSet&, Foam::Ostream&) const [with Type = double]’:
sampledSetWriters/csv/csvSetWriter.C:137:9: required from here
/home/dm2/henry/OpenFOAM/OpenFOAM-dev/src/OpenFOAM/lnInclude/UList.H:430:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (Foam::label i=0; i<(list).size(); i++)
sampledSetWriters/csv/csvSetWriter.C:188:9: note: in expansion of macro ‘forAll’
         forAll(points.axis(), i)

The problem is that points.axis() returns a word (which should be cached) for which forAll is not really appropriate.


2017-02-09 17:55

manager   ~0007733

Resolved in OpenFOAM-4.x by commit e964d879e2b30756f27f5e7765a78e0b8e5390c9

Resolved in OpenFOAM-dev by commit 868651b1674413f31ed4a621999ef3c3b08db950

Issue History

Date Modified Username Field Change
2017-02-08 13:02 Sahas New Issue
2017-02-09 08:47 tniemi Note Added: 0007728
2017-02-09 09:17 tniemi File Added: patch.diff
2017-02-09 09:19 tniemi Note Added: 0007729
2017-02-09 17:01 henry Note Added: 0007732
2017-02-09 17:55 henry Assigned To => henry
2017-02-09 17:55 henry Status new => resolved
2017-02-09 17:55 henry Resolution open => fixed
2017-02-09 17:55 henry Fixed in Version => 4.x
2017-02-09 17:55 henry Note Added: 0007733