Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong write time for functionObjectProperties in OpenFOAM.com #26

Closed
MakisH opened this issue Oct 4, 2018 · 9 comments
Closed

Wrong write time for functionObjectProperties in OpenFOAM.com #26

MakisH opened this issue Oct 4, 2018 · 9 comments
Assignees
Labels
bug Unexpected problems (crashes, numerical issues, etc) compatibility Affecting only specific OpenFOAM / preCICE versions

Comments

@MakisH
Copy link
Member

MakisH commented Oct 4, 2018

Issue reported by @derekrisseeuw, affecting at least OpenFOAM+ v1712 and v1806, but not affecting OpenFOAM 5.x or 6.

tl;dr: Empty entries in the results output are shown as "flickering" animation in ParaView.

The problem occurs when running a coupled implicit simulation where the openfoam write interval is larger than the coupling timestep. OpenFOAM will not only write a time at the defined 'write interval', but also at: time = write interval - coupling time

The only field that is written that time is uniform/functionObjects

Which contains the attached file, with no further information.

In terms of simulation this does not pose a problem, but for postprocessing it can be inconvenient. Also, I am not sure where this functionobject is written, but the fact that the time there is not updated might also be incorrect.

I actually first noticed this problem when running the CHT tutorial. Here the coupling time is 0.01s, and the writeInterval is 0.2s. Therefore I have timefolder 0, 0.19, 0.2, 0.39, 0.4, ... etc.

Even if this seems to be version-specific, maybe there is something wrong in the adapter, as well.

@MakisH MakisH added compatibility Affecting only specific OpenFOAM / preCICE versions bug Unexpected problems (crashes, numerical issues, etc) labels Oct 4, 2018
@MakisH
Copy link
Member Author

MakisH commented Dec 26, 2018

Some observations, while I am trying to fix this:

  • This only occurs in implicit coupling and any simulation, leading to "blinking time animation" effect in ParaView.
  • The "weird" additional file is [time]/uniform/functionObjects/functionObjectProperties. In the heated plate tutorial, the weird file is created for time 0.19, while the normal write is at 0.20.
  • This only occurs for openfoam.com, due to this commit from 10/2015.

In case you cannot acccess their GitLab repositories, the key method is Foam::functionObjectList::createStateDict() in the file src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C. Compare also the method Foam::Time::run() between .org/.com. If I understand correctly, they want to keep track of any changes in the configuration of the functionObjects during the simulation, making such a file necessary. However, I still have to understand why it is written at the wrong time in our case.

Commenting out this line didn't help:

const_cast<Time&>(runTime_).writeNow();

Edit: Here are the respective Release Notes of OpenFOAM v3.0+. See the section "Function objects updates".

@MakisH
Copy link
Member Author

MakisH commented Dec 26, 2018

As Derek mentioned, the additional file is written at time = write interval - coupling time step. The time is not dependent on the solver time step. It is also written at the normal time.

Apparently, this file is only written at the last coupling time step before writing (and at the times it is expected to be written). I was looking at the files during the simulation.

Consider the heated plate tutorial, with implicit coupling, and the following time steps:

  • solver's time step: 0.001s
  • coupling time step: 0.01s
  • write time interval: 0.1s

While the time directories 0 0.2 0.4 0.6 0.8 1 are expected, the directories 0 0.19 0.2 0.39 0.4 ... 0.99 1 are written.

I guess that at the coupling time step from t=0.199 to t=0.20 (or maybe t=0.20 to t=0.201), OpenFOAM enables a writeTime or similar switch. After reloading the checkpoint and the time value to t=0.19 with our hacky approach, the functionObjectProperties file is written at t=0.19. This must be the beginning of the solver's time step from t=0.190 to t=0.191.

Keeping in mind that the function object is technically triggered at the beginning of the next time step, instead of the end of the current one, I am pretty sure the problem is in this series of events. I will look at it again later. The answer lies somewhere in Foam::Time::run() or in preciceAdapter::Adapter::execute().

@MakisH MakisH self-assigned this Dec 26, 2018
@MakisH
Copy link
Member Author

MakisH commented Dec 27, 2018

Additional thoughts and observations:

  • The following line is the cause that functionObjectPropertiesis also written at the normal times. If we ommit this line, it is only written at time = write interval - coupling time step.

const_cast<Time&>(runTime_).writeNow();

  • Ommiting reseting the time "bypasses" the problem:

const_cast<Time&>(runTime_).setTime(couplingIterationTimeValue_, couplingIterationTimeIndex_);

This is of course undesired and wrong, but it supports my aforementioned theory.

  • Apart from this strange object, everything else is written when we want to (temperature, velocity, etc). Therefore, I start thinking that this may be an issue of inconsistency in OpenFOAM. But usually this is not the case.

@MakisH MakisH changed the title Empty result writes for some OpenFOAM versions Wrong write time for functionObjectProperties in OpenFOAM.com Dec 27, 2018
@MakisH
Copy link
Member Author

MakisH commented Dec 27, 2018

I think I found the speciality of this object, in the method Foam::functionObjectList::execute():

     // Force writing of state dictionary after function object execution
     if (time_.writeTime())
     {
         label oldPrecision = IOstream::precision_;
         IOstream::precision_ = 16;
 
         stateDictPtr_->writeObject
         (
             IOstream::ASCII,
             IOstream::currentVersion,
             time_.writeCompression(),
             true
         );
 
         IOstream::precision_ = oldPrecision;
  }

So, the series of events is the following:

  1. t = 0.20
  2. runTime.run(), which triggers the adapter's execute()
  3. Our execute() at some point reloads the time to t = 0.19, reads the coupling data, adjust the time step, and lets the solver continue
  4. After all these steps, Foam::functionObjectList::execute() sees that time_.writeTime() is true and writes the functionObjectProperties state dictionary.

Two cross-related questions:

A. Why, after we reset the time, time_.writeTime() is true? Can we force-set it to false?
B. Why is functionObjectProperties written at t=0.19 (which is not write-time) and not at t=20 (which is)?

@MakisH
Copy link
Member Author

MakisH commented Dec 27, 2018

I give up for now, as any solution for this would again be quite hacky. I think we are writing results correctly and we know the specific reason that only this object is written out of place. This only affects some versions of OpenFOAM and this file seems to be useless in most of the cases.

I suggest the following workaround for our tutorial scripts:

# Delete all [case]/[time]/[uniform]/functionObjects directories
rm -rfv */*/*/functionObjects

# Delete all empty directories
find . -type d -empty -delete

@derekrisseeuw what do you think of this workaround?

Apparently, paraFoam uses any directory with a numerical value as name to add time stamps. Or maybe the issue is that ParaView itself needs an option to only consider non-empty time sets when plotting a specific variable. I will open an issue/PR for this upstream.

@derekrisseeuw
Copy link
Contributor

This could work, but only for runs which don't use any other function objects.

I used a similar script
removeObsoleteFolders.sh in my tutorial cases which is called automatically after the simulation. This file removes all the time folders which don't include a U file, since every simulation with FSI would save the velocity field.

@MakisH
Copy link
Member Author

MakisH commented Dec 27, 2018

This could work, but only for runs which don't use any other function objects.

Do you have any example in mind where this could break? Maybe deleting all the functionObjects directory is overkill, deleting just the functionObjectProperties would be enough. For all the tutorials we have, it is empty (and it doesn't exist for the OpenFOAM Foundation versions).

To be honest, I have not really understood what this dictionary is meant for, as I have not encountered it in practice.

I think I will replace the removeObsoleteFolders.sh script with this, as more targeted and general (works also for laplacianFoam, for example).

@MakisH
Copy link
Member Author

MakisH commented Dec 27, 2018

I actually think your script is better for our use case. I extended it so that it also looks for T and to not delete the 0.orig directories.

I consider this closed, as soon as the respective commit gets merged into master.

@MakisH MakisH closed this as completed Jan 1, 2019
MakisH added a commit that referenced this issue Jun 23, 2020
Related to #26

Already implemented separately for the FSI tutorials
in the precice/tutorials repository.
MakisH added a commit that referenced this issue Jun 23, 2020
Related to #26

Already implemented separately for the FSI tutorials
in the precice/tutorials repository.
MakisH added a commit that referenced this issue Jun 23, 2020
Related to #26

Already implemented separately for the FSI tutorials
in the precice/tutorials repository.
pachesp added a commit that referenced this issue Sep 30, 2020
commit 045d0d2
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Wed Jul 29 13:54:01 2020 +0200

    Cleanup sonicLiquidFoam case files

commit 91160d7
Author: uekerman <benjamin.uekermann@gmail.com>
Date:   Wed Jul 29 10:13:52 2020 +0200

    Tune FF sonicLiquidFoam to converge

commit c0e61f5
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Fri Jul 24 14:04:39 2020 +0200

    Add todo for determining solverType of multiphase solvers

commit 35cc2c2
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Wed Jul 22 21:57:15 2020 +0200

    Add pressure-based solver type guessing

commit c38f109
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Wed Jul 22 21:41:43 2020 +0200

    Update FF/FF.C

commit 03cee93
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Wed Jul 22 21:38:32 2020 +0200

    Update preCICE logger for consistency

commit fcb2c37
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Wed Jul 22 21:35:14 2020 +0200

    Remove density from transportProperties

commit a39035d
Merge: 78fc865 46c1dcf
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Wed Jul 22 18:22:28 2020 +0200

    Merge branch 'develop' into FF

commit 46c1dcf
Merge: 84a3178 0eb0742
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Tue Jun 30 10:47:18 2020 +0200

    Merge pull request #131 from precice/refactor-assign-construct

    Refactor to reduce assigning fields at creation

commit 0eb0742
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Mon Jun 29 21:21:45 2020 +0200

    Refactor to reduce assigning fields at creation

    This replaces statements such as:

        scalarField one_field = another_field;

    by constructors:

        scalarField one_field(another_field);

    This can be safer and faster, as it avoids implicit conversions in between.

commit 84a3178
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Tue Jun 23 21:19:26 2020 +0200

    Tutorials: Add removeObsoleteFolders.sh script

    Related to #26

    Already implemented separately for the FSI tutorials
    in the precice/tutorials repository.

commit 55a1d57
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Tue Jun 23 21:03:51 2020 +0200

    Simplify precice-config.xml of tutorials

    Hides the timing:initial of mapping (not needed) and extrapolation-order (not important).
    Moves the max-iterations together with the relative-convergence-measure (more natural to explain).

commit 671104a
Author: David Schneider <dav.schneider@tum.de>
Date:   Mon Jun 8 10:27:37 2020 +0200

    Support stress data (#125)

    Add support for stress data writing

commit 42a3d6d
Author: Gerasimos Chourdakis <makishourdakis@gmail.com>
Date:   Tue Mar 24 10:07:35 2020 +0100

    Workaround for #109 (NP tutorial)

commit b7c7a7c
Author: David Schneider <dav.schneider@tum.de>
Date:   Fri Mar 20 20:39:04 2020 +0100

    Determine solver type by pressure dimension (#124)

    Determine solver type by pressure dimensions and throw error if automatic process fails.
@precice-bot
Copy link

This issue has been mentioned on preCICE Forum on Discourse. There might be relevant details there:

https://precice.discourse.group/t/openfoam-adapter-branch-for-version-8-and-solution-frequency/537/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected problems (crashes, numerical issues, etc) compatibility Affecting only specific OpenFOAM / preCICE versions
Projects
None yet
Development

No branches or pull requests

3 participants