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

adding values to transportProperties in interFoam

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By herbert
  • 1 Post By l_r_mcglashan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 15, 2010, 04:13
Default adding values to transportProperties in interFoam
  #1
New Member
 
Dan Gadensgaard
Join Date: Apr 2010
Posts: 13
Rep Power: 16
dgadensg is on a distinguished road
Hi all!

I am trying to implement a temperature equation to the interFoam solver for simulation of the filling stage in a injection molding process. I have looked at the implementation made in: Diverging result for Temperature field in interFoam.

The solver compiles just fine, but when i try to run a case, the solver stops before the equations are solved. I have found out that the error occurs in createFields.H when reading the specifik heat (cp) and thermal conductivity (kT) that i have added. Somehow OF reads the values i have specified in transportProperties wrong! Can anyone give me some idea as too what might be the problem?

Code from createFields.H:
Code:
...
    const dimensionedScalar& rho1 = twoPhaseProperties.rho1();
    const dimensionedScalar& rho2 = twoPhaseProperties.rho2();

    const dimensionedScalar& cp1 = twoPhaseProperties.cp1();
    const dimensionedScalar& cp2 = twoPhaseProperties.cp2();

    const dimensionedScalar& kT1 = twoPhaseProperties.kT1();
    const dimensionedScalar& kT2 = twoPhaseProperties.kT2();
	
Info << "Read transportproperties succesfully\n" << endl;

    // Need to store rho for ddt(rho, U)
    volScalarField rho
    (
        IOobject
        (
            "rho",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT
        ),
        alpha1*rho1 + (scalar(1) - alpha1)*rho2,
        alpha1.boundaryField().types()
    );
    rho.oldTime();

	// Need to store cp for TEqn!
	Info << "Saving cp values!\n" << endl;
    volScalarField cp
    (
        IOobject
        (
            "cp",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT
        ),
        alpha1*cp1 + (scalar(1) - alpha1)*cp2,
        alpha1.boundaryField().types()
    );
    // cp.oldTime(); // what does this do?

	// Need to store kT for TEqn!
	Info << "Saving kT values!\n" << endl;    
	volScalarField kT
    (
        IOobject
        (
            "kT",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT
        ),
        alpha1*kT1 + (scalar(1) - alpha1)*kT2,
        alpha1.boundaryField().types()
    );
    // kT.oldTime(); // what does this do?
...
My transportproperties file:
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  1.6                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

phase1 // Liquid
{
    transportModel  Newtonian;
    nu              nu [ 0 2 -1 0 0 0 0 ] 1e-06;
    rho             rho [ 1 -3 0 0 0 0 0 ] 1000;
    cp    	      cp [ 0 2 -2 -1 0 0 0 ] 660;
    kT 	      kT [ 1 1 -3 -1 0 0 0 ] 1.54;
}

phase2 // Air
{
    transportModel  Newtonian;
    nu              nu [ 0 2 -1 0 0 0 0 ] 1.48e-05;
    rho             rho [ 1 -3 0 0 0 0 0 ] 1;
    cp		      cp [ 0 2 -2 -1 0 0 0 ] 1009;
    kT	      kT [ 1 1 -3 -1 0 0 0 ] 2.85e-02;
}

sigma           sigma [ 1 0 -2 0 0 0 0 ] 0.07;


// ************************************************************************* //
dgadensg is offline   Reply With Quote

Old   April 15, 2010, 08:27
Default
  #2
Senior Member
 
Stefan Herbert
Join Date: Dec 2009
Location: Darmstadt, Germany
Posts: 129
Rep Power: 17
herbert is on a distinguished road
Hi,

I've successfully implemented exactly this some time ago. Try this for reading cp (and kT as well):

dictionary phase1 = transportProperties.subDict("phase1");
dimensionedScalar cp1 = phase1.lookup("cp");

Good luck
Stefan
vivek05 and Alpha001 like this.
herbert is offline   Reply With Quote

Old   April 15, 2010, 09:13
Default
  #3
New Member
 
Dan Gadensgaard
Join Date: Apr 2010
Posts: 13
Rep Power: 16
dgadensg is on a distinguished road
Thanks a lot herbert!

That worked like a charm!
dgadensg is offline   Reply With Quote

Old   January 17, 2011, 09:46
Default
  #4
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
Hi interFoamers,

if I want to define temperature-dependent densities for each phase, which implementation of twoPhaseMixture would you suggest me?

Simply imitating already existing fields I came up with a couple of variants, but I haven't a clue what's the difference between them:

in twoPhaseMixture.H:
a)
Code:
volScalarField rho1_;
virtual tmp<volScalarField> rho1() const
        {
            return rho1_;
        }
b)
Code:
tmp<volScalarField> rho1() const;
or neither of them would be correct? What does tmp<> mean?

I will also need the T-field (temperature), so should I add following lines:
twoPhaseMixture.H:
Code:
const surfaceScalarField& T_;
twoPhaseMixture.C:
Code:
T_(T),
like it is implemented for U or phi?

And why twoPhaseMixture.C looks so complicated for alpha1?
Code:
alpha1_(U_.db().lookupObject<const volScalarField> (alpha1Name)),
Why not
Code:
alpha1_(alpha1),
linch is offline   Reply With Quote

Old   January 17, 2011, 09:53
Default
  #5
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
Well, yet another question:
Defining a temperature dependent rho1()-field would imply calculation of rho1-values even for those cells without phase1. Is there a more efficient way?

Edit:
Trying to answer my own question from the previous post (the first one), I guess that the a) variant makes sense since rho1_ is being used repeatedly in twoPhaseMixture.C. But it's still isn't clear to me if the public rho1() field has to be declared as virtual and tmp<>. The T_(T)-question is still open.

Last edited by linch; January 17, 2011 at 12:37.
linch is offline   Reply With Quote

Old   May 27, 2011, 12:04
Default
  #6
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
Some more questions:
1).
Being newcomer in C++ I don't really understand the implementation of the constructor for twoPhaseMixture objects.

I walked though a C++ tutorial and learned, that a constructor for an object of the class
Code:
class someClass {...};
should look like:
Code:
someClass::someClass (inputParameters,...) {...};
But in case of twoPhaseMixture it looks different:
Code:
twoPhaseMixture::twoPhaseMixture (inputParameters,...):somethingElse,... {...};
What does the stuff after the colon mean?

2). For example
twoPhaseMixture.H:
Code:
const volVectorField& U_; //intern protected parameter
...
const volVectorField& U, //public input parameter
Do I understand it right, that both of them (because of &) are pointers to U?
twoPhaseMixture.C (within the constructor):
Code:
U_(U),
Is it a common way to initialize a constant in C++ and means something like &U_=&U;? What's the reason for doing this since &U is already a constant and can't be changed even being public?
linch is offline   Reply With Quote

Old   May 28, 2011, 14:06
Default
  #7
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
1) The stuff after the colon is the initialiser list. It constructs other objects (such as transportModel) and its own member variables that you can see declared in the header file.

2) U_ is a reference to the velocity, U, that is passed by reference through the constructor for twoPhaseMixture.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   May 30, 2011, 05:16
Default
  #8
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
1) Thanks a lot, I've got it

2) What's the need of creating U_ if it is equal to U (both are const and both are pointers to the U-storage)?
linch is offline   Reply With Quote

Old   May 30, 2011, 06:41
Default
  #9
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Don't think of references as pointers. Think of a reference as an alias for an object; U_is in fact U. U_ is needed if any of the member functions in twoPhaseMixture require knowledge of U.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   May 30, 2011, 07:30
Default
  #10
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
Quote:
Originally Posted by l_r_mcglashan View Post
U_is in fact U. U_ is needed if any of the member functions in twoPhaseMixture require knowledge of U.
But then, why can't U be used directly? What's the reason for declaring an alias?
linch is offline   Reply With Quote

Old   May 30, 2011, 07:41
Default
  #11
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
You can use U in the class constructor to initialize objects and variables, but functions in the class cannot see U. Try accessing it from within a class member function and you'll see it doesn't compile.

That's why there is an alias, U_.
vivek05 likes this.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   May 30, 2011, 07:50
Default
  #12
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
I see...Thank you very much once again.
linch is offline   Reply With Quote

Old   May 30, 2011, 08:20
Default
  #13
Senior Member
 
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17
linch is on a distinguished road
And how can one understand the initialisation of alpha1_ with:
Code:
U_.db().lookupObject<const volScalarField> (alpha1Name)
linch is offline   Reply With Quote

Old   September 4, 2011, 02:27
Default
  #14
New Member
 
Join Date: Nov 2010
Posts: 10
Rep Power: 16
siavash_abadeh is on a distinguished road
hi dear
i have a case that i want to solve 2 phase (liq-air) with heat transfer.
i read your note then i ask u to help me for solve this problem.(if its possible give me your code)
thanks in advance.
siavash_abadeh is offline   Reply With Quote

Old   September 27, 2012, 17:59
Default newbie question about changes to interFoam
  #15
Member
 
Join Date: Mar 2010
Posts: 31
Rep Power: 16
bunni is on a distinguished road
Hi,

I've been using openFoam for a couple of years now, have gotten comfortable with using the solvers that exist. Now it's time to get elbows deep and change a solver to deal with a new problem. I've read through the programmer's guide, and managed a tutorial or two I found on the web.

In principle, I should be able to make the changes I need in a local solver, and not make changes at the top(library) level, is that correct? I'd like to add a new scalar and vector field to the interFoam example. Not unlike the transport discussed here (we'll save the vector field for another day).

As the original poster had trouble defining the variables in createFields.H, I too had problems there. The solution which seemed to work was:

dictionary phase1 = transportProperties.subDict("phase1");
dimensionedScalar cp1 = phase1.lookup("cp");

My question is: where does this get defined? In createFields.H ? or do I have to edit the class twoPhaseMixture?

One of the examples I worked through just had a new vector field that got its own *.H in the */applications/solvers/(example) directory. The new data was included in the case/0 directory, and a local compile was all that was necessary.

Any help would be appreciated. Or, more examples to work through. I have found tutorials of new variables specifically applied to interFoam, so if anyone knows of those I'd really appreciate that.

Thanks
bunni is offline   Reply With Quote

Old   April 16, 2019, 09:29
Default
  #16
New Member
 
xena
Join Date: Mar 2019
Posts: 13
Rep Power: 7
xena is on a distinguished road
hi,

What does (sigma) in the transportproporties script mean?
is it a constraint ? what does induce it ?
xena is offline   Reply With Quote

Reply

Tags
density, interfoam, programming, specifik heat, temperature, thermal conductivity


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
Adding temperature field to InterFoam yapalparvi OpenFOAM Running, Solving & CFD 8 October 14, 2009 21:18
max node values exceed max element values in contour plot jason_t FLUENT 0 August 19, 2009 12:32
Adding imaginary patch for calculation of average values bboonacker OpenFOAM Running, Solving & CFD 4 June 2, 2009 00:00
strange node values @ solid/fluid interface - help JB FLUENT 2 November 1, 2008 13:04
Adding all the values in a post register Cb Siemens 3 March 11, 2005 14:40


All times are GMT -4. The time now is 16:40.