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   May 3, 2022, 05:36
Smile
  #41
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
Greetings Svensen,

There are a few boundary conditions that demonstrate how lookup tables can be used. Using lookup tables as OpenFOAM already does, would ensure that the bug is not coming from a possibly flawed implementation of the lookup mechanism you currently have implemented.

The boundary "src/finiteVolume/fields/fvPatchFields/derived/uniformFixedValue" has such an example:
  1. The lookup table object is defined like this in the header file ".H":
    Code:
    autoPtr<Function1<Type>> uniformValue_;
    • In your case:
      Code:
      autoPtr<Function1<scalar>> visc;
  2. Constructed like this:
    Code:
    uniformValue_(Function1<Type>::New("uniformValue", dict))
    • In your case:
      Code:
      visc(Function1<scalar>::New("viscTable", dict))
      Then the entry "viscTable" needs to be in "transportProperties", within the respective "*Coefs" section.
  3. Then used like this:
    Code:
        const scalar t = this->db().time().timeOutputValue();
        fvPatchField<Type>::operator==(uniformValue_->value(t));
    • Although in your case, it would be something like:
      Code:
      visc->value(strainRate[celli])
  4. Don't forget to include the header file:
    Code:
    #include "Function1.H"
  5. In the "transportProperties" file, you will need something like what's described here: http://openfoam.org/release/2-1-0/bo...ime-dependent/ - possibly this:
    Code:
    viscTable     table
    (
        (0.0     0.014)
        (0.125   0.0123715)
        (0.25    0.011782)
    ...
        (????  0.00409976)
    );


If you still have trouble implementing it, please do the following steps, so it's easier to help you:
  1. Provide the source code by following these steps:
    1. Run inside the source code folder of your custom library:
      Code:
      wclean all
    2. Then go to the parent folder and package the source code folder, e.g. if the folder is named "splineTransport":
      Code:
      tar -czf splineLib.tar.gz splineTransport
    3. Then attach the file "splineLib.tar.gz" to your next post.
  2. Then we either need a test case, or instructions on how to change a tutorial in OpenFOAM to use your transport model.
Best regards,
Bruno


Dear Santos,

I am trying to simulate rising bubble in a solution that its density, viscosity nad surface tension are chaning with the concentration of solvent. I am using interFoam and I would like to implement my own correlations for calculating density, viscosity and surfance tension. I am new in OpenFoam and I am looking for a tutorial or any guidance to start it. Could you please help me or share any tutorial if you have for this problem?

Thanks and best regards,
Sadra
sadra2003 is offline   Reply With Quote

Old   May 3, 2022, 05:41
Smile
  #42
Member
 
sadra mahmoudi
Join Date: Feb 2021
Location: Austria
Posts: 39
Rep Power: 5
sadra2003 is on a distinguished road
Quote:
Originally Posted by Svensen View Post
Hi, I'm trying to implement a precise viscosity model from experimental measurements.

I've created a folder "Spline" and two files "Spline.C" and "Spline.H".
I've redefined calcNu() method in the following was:


Code:
Foam::tmp<Foam::volScalarField>
Foam::viscosityModels::Spline::calcNu() const
{
    volScalarField strain = strainRate();
     volScalarField nu = strain;
     
//for each element of a field
     for (unsigned i=0; i<strain.size(); i++){
         double n = strain[i]; //get a strain-rate
    
        const double dn = 250/sizeof(visc);
        n /= dn; //scale it to match an index of array
    
/*visc array includes 2000 values of measured viscosity*/
        unsigned x1 = floor(n);
        if (x1 < 1) x1 = 0; //check minimum value
        if (x1 >= sizeof(visc)) x1 = sizeof(visc)-2; //check maximum value
        
        unsigned x2 = x1 + 1;
    
        if (x1 != x2){
            double y1 = visc[x1];
            double y2 = visc[x2];
        
            double k = y2 - y1; //linear interpolation
            double b = x2*y1 - x1*y2;
        
            nu[i] = k*n + b;
        }
        else{
            nu[i] = visc[x1];
        }
     }
    
    return nu;
}
It compiles with no error, however after start of pimpleFoam it exits with the following log:
Code:
#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::sigFpe::sigHandler(int) at ??:?
#2  ? in "/lib/x86_64-linux-gnu/libc.so.6"
#3  Foam::viscosityModels::Spline::calcNu() const at ??:?
#4  Foam::viscosityModels::Spline::Spline(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) at ??:?
#5  Foam::viscosityModel::adddictionaryConstructorToTable<Foam::viscosityModels::Spline>::New(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) at ??:?
#6  Foam::viscosityModel::New(Foam::word const&, Foam::dictionary const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) at ??:?
#7  Foam::singlePhaseTransportModel::singlePhaseTransportModel(Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&) at ??:?
#8  ? at ??:?
#9  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#10  ? at ??:?
What can be wrong with my code ?


Dear Sevensen,

I am trying to simulate rising bubble in a solution that its density, viscosity nad surface tension are chaning with the concentration of solvent. I am using interFoam and I would like to implement my own correlations for calculating density, viscosity and surfance tension. I am new in OpenFoam and I am looking for a tutorial or any guidance to start it. Could you please help me or share any tutorial if you have for this problem?

Thanks and best regards,
Sadra
sadra2003 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 07:00
New Viscosity Model - Best Practice for Temporary Values MaSch OpenFOAM Programming & Development 6 March 16, 2018 04:51
Time constant in Herschel-Bulkley viscosity model Mikel6 Main CFD Forum 0 October 17, 2016 05:52
Viscosity ratio in gamma-theta transition model based on k-w sst turb model Qiaol618 Main CFD Forum 8 June 9, 2012 07:43
How to modify the viscosity model mpml OpenFOAM Running, Solving & CFD 4 October 13, 2010 08:44


All times are GMT -4. The time now is 20:25.