CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Custom viscosity model

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 6, 2016, 07:08
Default
  #21
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
Dear wyldcat,

thank you very much for help. I rewrote the sources according to your remarks, but the problem remains the same: serial runs OK, parallel - fails.

The test case is here: https://yadi.sk/d/jsG0qm_dyA9Mj
The sources are here: https://yadi.sk/d/wp7xIpUZyA9VK

Remarks to test case:
./compute_all-spline.sh will setup a case and run a pimpleFoam in parallel. After this you can run pimpleFoam in serial and you will see that it works fine.

./clear.sh will remove all processor and time directories.
Svensen is offline   Reply With Quote

Old   November 6, 2016, 07:14
Default
  #22
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
And by the way, nu field is not saved in time folders, like 0.001, 0.002 and so on
Svensen is offline   Reply With Quote

Old   November 6, 2016, 08:43
Default
  #23
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
Is it an issue for bug tracker ?
Svensen is offline   Reply With Quote

Old   November 6, 2016, 11:07
Default
  #24
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Quote:
Originally Posted by Svensen View Post
And by the way, nu field is not saved in time folders, like 0.001, 0.002 and so on
Code:
tmp<volScalarField> tNu
    (
        new volScalarField
        (
            IOobject
            (
                "nu",
                strain_Rate.time().timeName(),
                strain_Rate.mesh(),
                strain_Rate.readOpt(),
                IOobject::AUTO_WRITE
            ),
...
Zeppo is offline   Reply With Quote

Old   November 6, 2016, 11:41
Default
  #25
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
Dear Zeppo,

unfortunately
Code:
IOobject::AUTO_WRITE
does not work.
Svensen is offline   Reply With Quote

Old   November 6, 2016, 12:01
Default
  #26
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Code:
//- Return the laminar viscosity
virtual tmp<volScalarField> nu() const
{
    nu_.write(); //- force writing to test if it ever works
    return nu_;
}
Zeppo is offline   Reply With Quote

Old   November 6, 2016, 12:15
Default
  #27
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
Yes, in this case it writes tnu field. But it writes it as dictionary! Just look on the attached file.
Attached Files
File Type: txt tnu.txt (1.3 KB, 12 views)
Svensen is offline   Reply With Quote

Old   November 6, 2016, 12:17
Default
  #28
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
The internal field have to contain point by point values. But instead of this it simply writes one value for internalField...
Svensen is offline   Reply With Quote

Old   November 6, 2016, 12:30
Default
  #29
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
it means that is uniform oll over the cells as if it was calculated only once with default uniform falue of stress rate (which is calculated based on value of U-field). Secondly, why is it tnu when it should be nu?
Code:
FoamFile
{
    version     2.0;
    format      binary;
    class       volScalarField;
    location    "0.005";
    object      tnu;
}
try this:
Code:
//- Correct the laminar viscosity
virtual void correct()
{
    nu_ = calcNu();
    Info << "nu corrected" << endl;
    nu_.write();
}
Zeppo is offline   Reply With Quote

Old   November 6, 2016, 12:39
Default
  #30
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
I've simply passed "tnu" string param to constructor of tNu object. Now I've changed this string back to "nu" and modified code of correct() method according to your remark.

Unfortunately the output for "nu" is still the same: only one value for internal field!
Svensen is offline   Reply With Quote

Old   November 6, 2016, 12:54
Default
  #31
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: Although it took me some considerable time to do this, it was a good training exercise.

Attached is the package "Spline_v2.tar.gz" that contains the working code.

I changed the construction to this:
Code:
    nu_
    (
        IOobject
        (
            name,
            U_.time().timeName(),
            U_.db(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        calcNu()
    )
"calcNu()" now has this:
Code:
    tmp<volScalarField> tstrain_Rate = strainRate();

    volScalarField& strain_Rate = tstrain_Rate.ref();

    tmp<volScalarField> tNu
    (
        new volScalarField
        (
            IOobject
            (
                "tmpNu",
                U_.time().timeName(),
                U_.db(),
                IOobject::NO_READ,
                IOobject::NO_WRITE,
                false
            ),
            U_.mesh(),
            dimensionedScalar
            (
                "oneNu", 
                sqr(dimLength)*strain_Rate.dimensions(),
                visc->value(250.0)
            )
        )
    );

    volScalarField& nu = tNu.ref();

    nu.primitiveFieldRef() = visc->value(strainRate());
The last line works accordingly to how OpenFOAM does things, but it's essentially the same loop you had, because "value()" has an overload that allows going over the whole field automatically: http://cpp.openfoam.org/v4/a00876.ht...df4d6ef7cf6313

In order to initialize the values on the boundaries, I defined directly in the creation of the field.

As for the problem when running in parallel, it may have been do to who the boundary values were defined. The attached package has the following commented code that should work:
Code:
    //alter the boundary values:
    volScalarField::Boundary& bNu = nu.boundaryFieldRef();
    forAll(bNu, patchi)
    {
        if(!isA<processorFvPatch>(bNu[patchi]))
        {
            scalarField& pNu = bNu[patchi]; // patch field
            pNu = visc->value(250);
        }
    }
Attached Files
File Type: gz Spline_v2.tar.gz (2.2 KB, 22 views)
wyldckat is offline   Reply With Quote

Old   November 6, 2016, 13:46
Default
  #32
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Quote:
Originally Posted by wyldckat View Post
Quick answer: Although it took me some considerable time to do this, it was a good training exercise.
Attached is the package "Spline_v2.tar.gz" that contains the working code.
Bruno, can you explain to us what was wrong with the initially proposed code. I don't get it.
Zeppo is offline   Reply With Quote

Old   November 6, 2016, 14:52
Default
  #33
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by Zeppo View Post
Bruno, can you explain to us what was wrong with the initially proposed code. I don't get it.
Sorry, was and am in a hurry... in a nutshell, from what I remember:
  1. This:
    Code:
    tmp<volScalarField> tNu
        (
            new volScalarField
            (
                IOobject
                (
                    "nu",
                    strain_Rate.time().timeName(),
                    strain_Rate.mesh(),
                    strain_Rate.readOpt(),
                    IOobject::AUTO_WRITE
                ),
    is a bad initialization because the strain rate creation is generic and possibly doesn't have all of the options defined as we might expect (path, time name, read options, etc), as shown here: https://github.com/OpenFOAM/OpenFOAM...ityModel.C#L58
  2. Although this should work without problems:
    Code:
        forAll(nu, i)
        {
            nu[i] = visc->value(strain_Rate[i]);        
        }
  3. This will not with processor patches (the ones between the decomposed sub-domains):
    Code:
        volScalarField::Boundary& bNu = nu.boundaryFieldRef();
        forAll(bNu, i)
        {
            scalarField& pNu = bNu[i]; // patch field
            forAll(pNu, j)
            {
                pNu[j] = visc->value(250);
            }
        }
    because the processor patches are in the middle of the domain, therefore would create artificial obstacles.
  4. And I forgot to mention the "false" at the end of this block (in the code I provided):
    Code:
                IOobject
                (
                    "tmpNu",
                    U_.time().timeName(),
                    U_.db(),
                    IOobject::NO_READ,
                    IOobject::NO_WRITE,
                    false
                ),
    is so that the object is not registered on the object registry, more details here: http://openfoamwiki.net/index.php/Op...objectRegistry


edit: When in doubt, look for examples in OpenFOAM's source code Ideas for searching strategies: http://openfoamwiki.net/index.php/In...hing_for_files
Svensen likes this.

Last edited by wyldckat; November 6, 2016 at 14:53. Reason: see "edit:"
wyldckat is offline   Reply With Quote

Old   November 6, 2016, 15:12
Default
  #34
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Quote:
Originally Posted by wyldckat View Post
[*]This:
Code:
tmp<volScalarField> tNu
    (
        new volScalarField
        (
            IOobject
            (
                "nu",
                strain_Rate.time().timeName(),
                strain_Rate.mesh(),
                strain_Rate.readOpt(),
                IOobject::AUTO_WRITE
            ),
is a bad initialization because the strain rate creation is generic and possibly doesn't have all of the options defined as we might expect (path, time name, read options, etc), as shown here: https://github.com/OpenFOAM/OpenFOAM...ityModel.C#L58
But does it really matter how we get a reference to the Time object, either through U_ or srtainRate()?. Shouldn't they both hold references to the same Time? And the write options are explicitly specified as IOobject::AUTO_WRITE.
Zeppo is offline   Reply With Quote

Old   November 6, 2016, 15:24
Default
  #35
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quote:
Originally Posted by Zeppo View Post
But does it really matter how we get a reference to the Time object, either through U_ or srtainRate()?. Shouldn't they both hold references to the same Time? And the write options are explicitly specified as IOobject::AUTO_WRITE.
Sorry, I went with the path of least resistance on that one... i.e. followed what the sibling classes were using and had to guess that the other possibility wasn't working as intended, as described in the previous posts between you two.

But feel free to test it out yourself The package that I attached in the other post is ready to be built and can be added to "system/controlDict" inside the "libs" list as "libCustomTransport.so", if I remember correctly... make sure to double-check the name in "Spline/Make/files".
wyldckat is offline   Reply With Quote

Old   November 6, 2016, 16:11
Default
  #36
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Well, now Svensen has the last word on the matter of applicability of Bruno's code. Svensen, did it work for you?
Zeppo is offline   Reply With Quote

Old   November 6, 2016, 16:47
Default
  #37
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
On the first two simulations it worked fine. However I will test it carefully in the nearest time using more sophisticated cases.
I will report the results as soon as possible.
Svensen is offline   Reply With Quote

Old   November 8, 2016, 16:15
Default
  #38
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
Dear wyldcat,

I've tested a Spline model on four different flow ratios between main pipe and branch (branch / main pipe). The ratios was 0.3; 0.5; 0.7 and 0.9.

For the flow ratios 0.3; 0.5 and 0.9 all was OK. The simulation successfully ran in parallel mode.

However for ratio 0.7 the simulation crashes in parallel mode at time step 0.016. Meanwhile, the serial execution works fine. I really don't know what is so special in this ratio, because I've tested the code on 0.3 ratio, where velocity in branch is lower and on 0.9 ratio, where velocity is higher in comparison with 0.7 ratio. It looks strange that 0.7 ratio is not working.

I've attached the project files for 0.7 ratio as well as Spline viscosity sources here: https://yadi.sk/d/A3Ktekm3yHUcd

Thanks.
Svensen is offline   Reply With Quote

Old   November 13, 2016, 11:34
Default
  #39
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer @Svensen: Did you always use 12 cores for all of the tests you've mentioned?

Because the problem is specifically triggered due to the number of faces that exist between processors, as reported by decomposePar:
Code:
Processor 0
    Number of cells = 10411
    Number of faces shared with processor 1 = 197
    Number of faces shared with processor 4 = 84
    Number of processor patches = 2
    Number of processor faces = 281
    Number of boundary faces = 5102

[...]

Processor 4
    Number of cells = 10513
    Number of faces shared with processor 0 = 84
    Number of faces shared with processor 5 = 492
    Number of processor patches = 2
    Number of processor faces = 576
    Number of boundary faces = 4138
When I can these entries in "system/fvSolution":
Code:
nCellsInCoarsestLevel    100;
to this:
Code:
nCellsInCoarsestLevel    80;
the solver no longer crashes.

This seems to suggest that there is a bug in OpenFOAM, but this case is too complicated for isolating the real origin of the bug
Nonetheless, I do have an idea of what might help track this down... I'll check what I have in mind and get back to this when I have more details.

Either way, the solution for your problem is already provided above.
wyldckat is offline   Reply With Quote

Old   November 13, 2016, 11:53
Default
  #40
Senior Member
 
Join Date: Jan 2015
Posts: 150
Rep Power: 11
Svensen is on a distinguished road
Dear wyldcat,
yes, the same number of cores was used for testing. For every case only the boundary conditions were different.
Svensen is offline   Reply With Quote

Reply

Tags
openfoam-dev, viscosity model


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with divergence TDK FLUENT 13 December 14, 2018 06:00
New Viscosity Model - Best Practice for Temporary Values MaSch OpenFOAM Programming & Development 6 March 16, 2018 03:51
Time constant in Herschel-Bulkley viscosity model Mikel6 Main CFD Forum 0 October 17, 2016 04:52
Viscosity ratio in gamma-theta transition model based on k-w sst turb model Qiaol618 Main CFD Forum 8 June 9, 2012 06:43
How to modify the viscosity model mpml OpenFOAM Running, Solving & CFD 4 October 13, 2010 07:44


All times are GMT -4. The time now is 10:34.