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

Tabulated viscosity data, viscosity vs cell centers

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By Tobi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 16, 2017, 14:22
Default Tabulated viscosity data, viscosity vs cell centers
  #1
New Member
 
Pedro
Join Date: Feb 2016
Location: United States
Posts: 23
Rep Power: 10
pedramtx is on a distinguished road
Dear FOAMERS,
I have been trying to implement a non-Newtonian fluid for which no constitutive relation is developed yet. In other words, I have a data set of nu_t (y). I was wondering how I can have OpenFoam read the data from this dataset.
Any help is greatly appreciated.

Pedram

Last edited by pedramtx; June 19, 2017 at 19:28.
pedramtx is offline   Reply With Quote

Old   June 21, 2017, 18:42
Default
  #2
New Member
 
Pedro
Join Date: Feb 2016
Location: United States
Posts: 23
Rep Power: 10
pedramtx is on a distinguished road
Quote:
Originally Posted by pedramtx View Post
Dear FOAMERS,
I have been trying to implement a non-Newtonian fluid for which no constitutive relation is developed yet. In other words, I have a data set of nu_t (y). I was wondering how I can have OpenFoam read the data from this dataset.
Any help is greatly appreciated.

Pedram
The issue still persists.

Last edited by pedramtx; July 9, 2017 at 13:34.
pedramtx is offline   Reply With Quote

Old   July 9, 2017, 13:30
Default Tabulated viscosity data, viscosity vs cell centers
  #3
New Member
 
Pedro
Join Date: Feb 2016
Location: United States
Posts: 23
Rep Power: 10
pedramtx is on a distinguished road
Hello Foamers,
First, I should confess that I am not that expert in coding with OF.
I have been trying to make OpenFOAM read viscosity from a list of values with respect to y (cell centers) values instead of dictating a constant value in transportproperties. The values of viscosity with respect to y are already available from some precursor simulation. After browsing the net, I found something similar. The library (Spline) is developed for non-Newtonian flow properties, which means it reads viscosity with respect to strain rate.
However, my purpose is to read viscosity with respect to cell centers.
If you can guide me through implementing this idea, I would greatly appreciate it. Even similar codes which relate to this type of implementation would be really helpful.

By the way, the link to Spline model is:
Custom viscosity model

Thanks,
Pedram
pedramtx is offline   Reply With Quote

Old   July 10, 2017, 09:02
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi Pedram,

without thinking about the physical meaning of your implementation, you can achieve it as follow. I am assuming that you have a list of values (for the viscosity) and a list of points (for the cell center information). If you have both together in one list, you can use some bash scripts to extract the data to make two files (or excel or whatever you would like to have). In addition I am sure that there are better ways to do that than my suggestion but out of the box it is the first one that I can tell you:

The data list of the files should look like that (just for completeness; guess you know that):
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  dev                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      cellZoneValuesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

2
(
3
1
);

// ************************************************************************* //
In that example we would have two viscosities with the values of 3 and 1.
You can read this list by using the following command:
Code:
    const IOList<label> values
    (
        IOobject
        (
            "valuesDict",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );
The same you have to do with the points. Somehow like that:

Code:
    const IOList<point> points
    (
        IOobject
        (
            "pointsDict",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );
The corresponding data file for the points is similar to the first one but with point instead of integers. Then you can loop through your mesh cells and set the values of the viscosity based on the list values you have. The following is just an example. How you treat it, is up to you:

Code:
//- Get the cell centers of the field (including boundaries)
const volVectorField& cellCenters = mesh.C();

//- Just internal field (if needed)
const vectorField& cellCentersInternal = cellCenters.internalField();

//- Loop  through all internal cells
forAll(cellCentersInternal, cellI)
{
    //- Needed if no viscosity found
    bool found = false;

     //- Loop through the list of points available (read in) to find the 
     //  corresponding viscosity. forAll in a forAll loop might be not 
     //  the best solution. maybe there is a better solution but if this
     //  is only done once at the beginning of a simulation it is fine.
     forAll(points, pI)
     {
          //- Get the point 
          const point pointPosition = points[pI];
 
          if (mesh.pointInCell(pointPosition, cellI)
          {
                //- Set viscosity 
                mu[cellI] = values[pI]
                found = true;
                break;
          }
     }

     if (!found)
     {
            //- No viscosity found - error or maybe some default one?
     }
}
Keep in mind that this is just an idea that came into my mind. I am not the best programmer and FOAMer so I definetly think there is a better way. Maybe you can read in the points and viscosities once or use map containers. There are a lot of ways. Hope you feel somehow inspirit and it will give you some first ideas.
pedramtx likes this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   July 14, 2017, 19:28
Default
  #5
New Member
 
Pedro
Join Date: Feb 2016
Location: United States
Posts: 23
Rep Power: 10
pedramtx is on a distinguished road
Tobias,
I really appreciate your help. I will implement your idea and will let you know if it works.

Pedram

Last edited by pedramtx; July 18, 2017 at 19:38.
pedramtx is offline   Reply With Quote

Old   July 18, 2017, 19:38
Default
  #6
New Member
 
Pedro
Join Date: Feb 2016
Location: United States
Posts: 23
Rep Power: 10
pedramtx is on a distinguished road
Quote:
Originally Posted by Tobi View Post
[...]Keep in mind that this is just an idea that came into my mind. I am not the best programmer and FOAMer so I definetly think there is a better way. Maybe you can read in the points and viscosities once or use map containers. There are a lot of ways. Hope you feel somehow inspirit and it will give you some first ideas.
Dear Tobias,
I implemented your idea in my solver. Unfortunately, I am running into the error:


Code:
Create mesh for time = 0

Reading transportProperties



--> FOAM FATAL IO ERROR: 
wrong token type - expected int, found on line 20 the doubleScalar 8.074e-12

file: /scratch/user/ptazraei/tobi/constant/valuesDict at line 20.

    From function operator>>(Istream&, int&)
    in file primitives/ints/int/intIO.C at line 68.

FOAM exiting
The procedure I followed comes below:

I added the following part to the .C file of the solver.

Code:
const volVectorField& cellCenters = mesh.C();
    const vectorField& cellCentersInternal = cellCenters.internalField();
    forAll(cellCentersInternal, cellI)
    {
     bool found = false;
     forAll(points, pI)
     {
     const point pointPosition = points[pI];

     if (mesh.pointInCell(pointPosition, cellI))
     {
     nut[cellI] = values[pI];
     found = true;
     break;
      }
    }
    if (!found)
    {
     return false;
    }
    }

      volScalarField nuEff(0.5*(nut)+nu);

          fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
                -fvm::laplacian(nuEff, U)
              ==
                vector(1,0,0) * gradP
            );
......
Then I defined the fields in createFileds.H as follows:

Code:
const IOList<label> values
    (
        IOobject
        (
            "valuesDict",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );

    const IOList<point> points
    (
        IOobject
        (
            "pointsDict",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        )
    );
In the end, I created two files named pointsDict and valuesDict in constant directory.
The format of valuesDict and pointsDict is like this:



Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  dev                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      valuesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

99
(
0.000000000008074
0.000000000082256
0.000000000748006
0.000000004486520
0.000000019307300
0.000000065185300
0.000000182306000
0.000000436471000
0.000000914311000
0.000001705110000
0.000002877430000
0.000004465330000
0.000006471050000
0.000008877830000
0.000011662600000
0.000014803500000
.
.
.
);
// ************************************************************************* //
and for pointsDict:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  dev                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      pointsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

99
(
0.001321090000000
0.004052960000000
0.006970310000000
0.010085800000000
0.013412700000000
0.016965600000000
0.020759700000000
0.024811400000000
0.029138100000000
0.033758700000000
0.038693000000000
0.043962300000000
0.049589400000000
0.055598600000000
0.062015700000000
0.068868600000000
0.076186700000000
0.084001700000000
.
.
.
);
// ************************************************************************* //
I would greatly appreciate it if you could help me with this issue. By the way, the format of OF that I use is OpenFOAM/2.2.2-intel-2016a.


Pedram

Last edited by wyldckat; August 27, 2017 at 15:25. Reason: Added [CODE][/CODE] markers
pedramtx is offline   Reply With Quote

Old   July 19, 2017, 04:05
Default
  #7
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Please make use of the code tags. As it is stated in the message, FOAM searches an integer:
Code:
const IOList<label> values
(
     IOobject
     (
         "valuesDict",
         runTime.constant(),
         mesh,
         IOobject::MUST_READ,
         IOobject::NO_WRITE
     )
);
IOList<Type> is a template. You should use scalar (or double, or longDouble or doubleScalar) instead of label (label represents integer).

Code:
--> FOAM FATAL IO ERROR: 
wrong token type - expected int, found on line 20 the doubleScalar 8.074e-12

file: /scratch/user/ptazraei/tobi/constant/valuesDict at line 20.
As it tells you - it expects and integer on line 20 in your file valuesDict based on the fact that you made an IOList<label>instead of the one you need IOList<scalar>.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   July 19, 2017, 12:22
Default
  #8
New Member
 
Pedro
Join Date: Feb 2016
Location: United States
Posts: 23
Rep Power: 10
pedramtx is on a distinguished road
Quote:
Originally Posted by Tobi View Post
Please make use of the code tags. As it is stated in the message, FOAM searches an integer:
Code:
const IOList<label> values
(
     IOobject
     (
         "valuesDict",
         runTime.constant(),
         mesh,
         IOobject::MUST_READ,
         IOobject::NO_WRITE
     )
);
IOList<Type> is a template. You should use scalar (or double, or longDouble or doubleScalar) instead of label (label represents integer).

Code:
--> FOAM FATAL IO ERROR: 
wrong token type - expected int, found on line 20 the doubleScalar 8.074e-12

file: /scratch/user/ptazraei/tobi/constant/valuesDict at line 20.
As it tells you - it expects and integer on line 20 in your file valuesDict based on the fact that you made an IOList<label>instead of the one you need IOList<scalar>.
Dear Tobias,
I am grateful for your help. I implemented the change you suggested.

Last edited by pedramtx; July 20, 2017 at 00:19.
pedramtx is offline   Reply With Quote

Old   July 19, 2017, 19:46
Default
  #9
New Member
 
Pedro
Join Date: Feb 2016
Location: United States
Posts: 23
Rep Power: 10
pedramtx is on a distinguished road
Quote:
Originally Posted by Tobi View Post
Please make use of the code tags. As it is stated in the message, FOAM searches an integer:
Code:
const IOList<label> values
(
     IOobject
     (
         "valuesDict",
         runTime.constant(),
         mesh,
         IOobject::MUST_READ,
         IOobject::NO_WRITE
     )
);
IOList<Type> is a template. You should use scalar (or double, or longDouble or doubleScalar) instead of label (label represents integer).

Code:
--> FOAM FATAL IO ERROR: 
wrong token type - expected int, found on line 20 the doubleScalar 8.074e-12

file: /scratch/user/ptazraei/tobi/constant/valuesDict at line 20.
As it tells you - it expects and integer on line 20 in your file valuesDict based on the fact that you made an IOList<label>instead of the one you need IOList<scalar>.

Dear Tobias,
I am afraid if I have explained the case clearly! The eddy viscosity list that I want to be read is only for one cross section (x), meaning nut is just a function of wall distance (y). Since we have 100 grids in the normal direction, the total number of cell centers for which nut is saved would be 99. Now, I want to use these data for the whole modeling process. Knowing that the simulation is 3D.
After implementing your suggestion regarding scalar and label and starting the simulation, this error shows up! And I think this is because Openfoam is seeking all the cell centers of the flow domain in the list, while I just want the cell centers in the normal direction, with respect to which nut is known, to be called.

-> FOAM FATAL IO ERROR:
Expected a '(' while reading VectorSpace<Form, Cmpt, nCmpt>, found on line 20 the doubleScalar 0.00132109

file: /scratch/user/ptazraei/tobi/constant/pointsDict at line 20.

From function Istream::readBegin(const char*)
in file db/IOstreams/IOstreams/Istream.C at line 94.

Last edited by pedramtx; July 20, 2017 at 00:23.
pedramtx is offline   Reply With Quote

Old   August 27, 2017, 15:28
Default
  #10
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
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
Greetings to all!

@pedramtx: I've come looking for posts of yours on this topic, following a PM you sent me on the 26th of June 2017. I don't know if you have finally solved this issue, but if you haven't, then please provide a simple test case and an example dictionary file that we can use to try and implement this.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   August 29, 2017, 07:12
Default
  #11
New Member
 
Lucas Gasparino
Join Date: Jul 2017
Location: Swansea, UK
Posts: 23
Rep Power: 9
Lucas_Gasparino is on a distinguished road
In truth, you can't: constitutive laws enter the equations through viscous stresses, themselves a function of flow variables. If you had a continuous relationship, then I'd suggest an initial step in the loop where it generates tau_ij at that step to be used in the momentum eqn. Still, it would need to be triaxial data (all 6 components of the tensor). Now, with piecewise data, not sure how it would work: somehow, you'd need to implement the rheology at this step. Try looking at the way they deal with simpler models, might give you a hint.in truth though, I'd say it's better to implement the law, otherwise your desired phenomena may not be modelled. Even in solids, when you have test data, you have to select a base material model, like Mooney-Rivlin or Ogden, before setting up your data, since the model's coefficients will be calculated by curve fitting; can you do something similar in your case? Is there a material with similar behaviour?

Sent from my XT1635-02 using CFD Online Forum mobile app
Lucas_Gasparino is offline   Reply With Quote

Reply

Tags
cell center data, funkysetfields, setfield, tabulated format, viscosity model

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 12:04
[OpenFOAM] How to get the coordinates of velocity data at all cells and at all times vidyadhar ParaView 9 May 20, 2020 21:06
FvMatrix coefficients shrina OpenFOAM Running, Solving & CFD 10 October 3, 2013 15:38
How to read tabulated data in Fluent Siddhartha Pal FLUENT 0 August 30, 2007 06:18
Warning 097- AB Siemens 6 November 15, 2004 05:41


All times are GMT -4. The time now is 13:27.