View Issue Details

IDProjectCategoryView StatusLast Update
0002729OpenFOAM[All Projects] Bugpublic2017-10-20 10:48
ReporterKerghanAssigned Tohenry 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformGNU/LinuxOSGNU/Linux Ubuntu 16.04OS Version15.04
Product Version4.x 
Fixed in Version5.x 
Summary0002729: nearWallFields doesn't really take into account distance parameter and thus produce incorrect value
DescriptionnearWallFields is supposed to sample field for given patches and fields at provided distance from patches' faces . It looks like, that points to sample values are calculated correctly, but eventually effectively not used - visually field looks like as if it was taken just from neighboring cell of patch face..
Steps To Reproduce!for OpenFOAM-4.x
1. Prepare $FOAM_TUTORIALS/incompressible/simpleFoam/motorBike
2. In $YOUR_CASE/system/controlDict add in functions dictionary:

functions
{
............
............

    nearField1
    {
        type nearWallFields;
        libs ("libfieldFunctionObjects.so");
        writeControl timeStep;
        writeInterval 1;
        fields ((U UNear1e0));
        patches (motorBikeGroup);
        distance 1e0;
    }

    nearField2
    {
        type nearWallFields;
        libs ("libfieldFunctionObjects.so");
        writeControl timeStep;
        writeInterval 1;
        fields ((U UNear1em1));
        patches (motorBikeGroup);
        distance 1e-1;
    }

    nearField3
    {
        type nearWallFields;
        libs ("libfieldFunctionObjects.so");
        writeControl timeStep;
        writeInterval 1;
        fields ((U UNear1em6));
        patches (motorBikeGroup);
        distance 1e-6;
    }
}
3. Run the case
4. After completion open the case in paraview and, in spreadsheet view and check field values UNear1em6, UNear1em1, UNear1e0 for motorbike patches - they will be identical (also one may diff values in field files, changed output to ascii in advance - they contain identical field data).
Additional InformationIf turn on debugging and dump *.obj files for points it's seen, that both obtained tracks and desired tracks look as expected - desired are located at provided distance from surface, while obtained may be "stopped" by domain boundaries.
TagsNo tags attached.

Activities

Kerghan

2017-10-19 20:53

reporter   ~0008893

Ok, so here is the patch.
The issue was with creation of the IOobject for new field, which was just created from original field and renamed (it might also appear that there is an issue with IOobject itself as well). And thus all further changes in new field were not used.

So because this function object probably was mostly used only for drawing nice surface bounded streamlines, it's alright / nobody cared - velocity surface field was just recreated from volume field (boundary cells).

With this fix some issues with point tracking may become visible and obtained surface field may appear lower quality for those purposes than with buggy version, thus this bug may appear as feature there. It may be worth to add boolean parameter like "sampleAtDistance" and only if it's true - sample at given distance, otherwise just use older approach. It also might be worth for volume field output uniform T(0) - as it's not needed/invalid. But not sure if this should be discussed in this issue.

patch_nearWallFieldsTemplates.patch (1,360 bytes)
diff --git a/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C b/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
index e2ed65c..706bcee 100644
--- a/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
+++ b/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
@@ -56,12 +56,19 @@ void Foam::functionObjects::nearWallFields::createFields
                 label sz = sflds.size();
                 sflds.setSize(sz+1);
 
-                IOobject io(fld);
-                io.readOpt() = IOobject::NO_READ;
-                io.writeOpt() = IOobject::NO_WRITE;
-                io.rename(sampleFldName);
-
-                sflds.set(sz, new VolFieldType(io, fld));
+                sflds.set(sz,
+                    new VolFieldType(
+                            IOobject(
+                                sampleFldName,
+                                time_.timeName(),
+                                mesh_,
+                                IOobject::NO_READ,
+                                IOobject::AUTO_WRITE
+                            ),
+                            mesh_,
+                            fld.dimensions()
+                    )
+                );
 
                 Log << "    created " << sflds[sz].name()
                     << " to sample " << fld.name() << endl;

Kerghan

2017-10-19 20:54

reporter  

patch_nearWallFieldsTemplates-2.patch (1,360 bytes)
diff --git a/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C b/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
index e2ed65c..706bcee 100644
--- a/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
+++ b/src/functionObjects/field/nearWallFields/nearWallFieldsTemplates.C
@@ -56,12 +56,19 @@ void Foam::functionObjects::nearWallFields::createFields
                 label sz = sflds.size();
                 sflds.setSize(sz+1);
 
-                IOobject io(fld);
-                io.readOpt() = IOobject::NO_READ;
-                io.writeOpt() = IOobject::NO_WRITE;
-                io.rename(sampleFldName);
-
-                sflds.set(sz, new VolFieldType(io, fld));
+                sflds.set(sz,
+                    new VolFieldType(
+                            IOobject(
+                                sampleFldName,
+                                time_.timeName(),
+                                mesh_,
+                                IOobject::NO_READ,
+                                IOobject::AUTO_WRITE
+                            ),
+                            mesh_,
+                            fld.dimensions()
+                    )
+                );
 
                 Log << "    created " << sflds[sz].name()
                     << " to sample " << fld.name() << endl;

henry

2017-10-19 21:09

manager   ~0008894

Last edited: 2017-10-20 10:37

View 2 revisions

Thanks for the patch, I will test and push it after some tweaking.

However the code layout of the patch is not consistent with the rest of OpenFOAM which I will fix before pushing but in future it would be useful if you followed the code style guide and the rest of OpenFOAM code.

You changed the registration from NO_WRITE to AUTO_WRITE even though the writing of the field is handled directly by the functionObject write controls; was this a necessary change?

The issue is not with IOobject or object registration but with the patch types which need to be set to calculated.

Kerghan

2017-10-19 21:55

reporter   ~0008895

Thank you.

Certainly will study coding style guide.

Indeed, there is no need in that change. Need to get more experience with OpenFOAM source code.

Cheers.

henry

2017-10-20 10:23

manager   ~0008897

> It also might be worth for volume field output uniform T(0)

On balance I think it is slightly more convenient if the internal field values are set to those of the source field rather than set to 0. In the longer term it would be good if direct support for boundary field IO and post-processing were added and then the internal field would not need to be written out.

henry

2017-10-20 10:48

manager   ~0008898

Resolved in OpenFOAM-5.x by commit 638557bb4cbff2605d0dc1d36f63654e0f2f0fc8

Resolved in OpenFOAM-dev by commit e903a088ee38a76593d1652d170ce64a45702338

Issue History

Date Modified Username Field Change
2017-10-18 21:25 Kerghan New Issue
2017-10-19 20:53 Kerghan File Added: patch_nearWallFieldsTemplates.patch
2017-10-19 20:53 Kerghan Note Added: 0008893
2017-10-19 20:54 Kerghan File Added: patch_nearWallFieldsTemplates-2.patch
2017-10-19 21:09 henry Note Added: 0008894
2017-10-19 21:55 Kerghan Note Added: 0008895
2017-10-20 10:23 henry Note Added: 0008897
2017-10-20 10:37 henry Note Edited: 0008894 View Revisions
2017-10-20 10:48 henry Assigned To => henry
2017-10-20 10:48 henry Status new => resolved
2017-10-20 10:48 henry Resolution open => fixed
2017-10-20 10:48 henry Fixed in Version => 5.x
2017-10-20 10:48 henry Note Added: 0008898