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

Assigning time dependent heat Source terms

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 19, 2015, 02:43
Default Assigning time dependent heat Source terms
  #1
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
Hi all;
Maybe, my question is a frequent question in OpenFoam forums, however I haven't still found a definite answer for it:
How can we assign a time-dependent (transient) heat source term at OpenFoam.2.3.1 (for example by fvOptions) ?
An example for heat source (S(h)):

S(h)=2*physical_time/(1+physical_time); (h is the symbol of enthalpy.)

Thx in advance for any attention and help.

M.Asghari
rasool_soofi likes this.

Last edited by Asghari_M; May 19, 2015 at 15:38.
Asghari_M is offline   Reply With Quote

Old   July 28, 2015, 14:16
Default fvOption for time dependent momentum source
  #2
Member
 
Mahmoud Aboukhedr
Join Date: Feb 2014
Location: London
Posts: 40
Rep Power: 12
Mahmoud_aboukhedr is on a distinguished road
I was wondering if the modification can be done for the pressureGradientExplicitSource ,, I'm trying to solve pressure gradient source for time dependent icoFoam solver??
Mahmoud_aboukhedr is offline   Reply With Quote

Old   July 29, 2015, 13:15
Default
  #3
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
Did you try codedSource?
https://github.com/OpenFOAM/OpenFOAM.../CodedSource.H
__________________
@HIKassem | HassanKassem.me
hk318i is offline   Reply With Quote

Old   July 29, 2015, 13:27
Default
  #4
Member
 
Mahmoud Aboukhedr
Join Date: Feb 2014
Location: London
Posts: 40
Rep Power: 12
Mahmoud_aboukhedr is on a distinguished road
Quote:
Originally Posted by hk318i View Post

Thanks for the reply, but am not sure what you mean?
Mahmoud_aboukhedr is offline   Reply With Quote

Old   July 29, 2015, 14:59
Default
  #5
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
Sorry my response wasn't clear. I posted it using CFD-onlne app which it isn't very efficient. Actually, it is the second time to write this post because the first one wasn't posted for some reason, anyway . . .

The codedSource fvOption is general way to implement any source term on the run, on the other hand you could modify and existing fvOption to match your needs. Instead if you are planing to use only one solver you could implement it directly in the desired solver.

Regarding the heat source problem, I think this relation cannot be write because it is function in time only and dimensionless. It isn't consistent.

About the pressureGradientExplicitSource, for some reason OpenFOAM dropped it in OpenFOAM-dev, so I expect it will not be available in the next version or a new alternative will be introduced soon. Anyway, your question isn't clear, how do you want the pressure gradient to varies with time? The current implementation in OpenFOAM-2.4 calculates it based on average velocity and direction only both are constants and they are not like fixedTemperatureConstraint which has an option for that.

I think both problems need to be more clear, so the forum users could really help you with constrictive comments.
hk318i is offline   Reply With Quote

Old   July 29, 2015, 16:50
Default
  #6
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
S(h) has W/m3 unit. Heat source term presented by me isn't a physical relation. Dimensions are hidden in the coefficient number 2.0 as follows:

S(h)=2.0*t/(1+t);

Assume , the coefficient number 2.0 (specified at above by red color) has W/m3 unit. And also the source term type is specific and not absolute.

Last edited by Asghari_M; July 31, 2015 at 14:42.
Asghari_M is offline   Reply With Quote

Old   July 29, 2015, 17:27
Default
  #7
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
Quote:
Originally Posted by Asghari_M View Post
S(h) has J/m3 unit. Heat source term presented by me isn't a physical relation. Dimensions are hidden in the coefficient number 2.0 as follows:

S(h)=2.0*t/(1+t);

Assume , the coefficient number 2.0 (specified at above by red color) has J/m3 unit. And also the source term type is specific and not absolute.
It should be straight forward according to the source code description, attached before.
Your formula could be implemented like that;

Code:
     const Time& time = mesh().time();
     // cells volumes 
     const scalarField& V = mesh_.V(); 
     scalarField& heSource = eqn.source(); 
      //reference to the source term
     // your equation
     scalar hs = (2.0*time.value())/(1+time.value()); 
     // adding to source term
     heSource += scalarField(V.size(), hs); 
    // heSource +=  ((2.0*time.value())/(1+time.value()))*V; // in case you need it as absolute value
see also cfd.direct post about energy equation in OF, http://cfd.direct/openfoam/energy-equation/

Last edited by hk318i; July 29, 2015 at 19:47. Reason: Comments added to the code and link to cfd.direct post
hk318i is offline   Reply With Quote

Old   July 30, 2015, 09:41
Default
  #8
Member
 
Mahmoud Aboukhedr
Join Date: Feb 2014
Location: London
Posts: 40
Rep Power: 12
Mahmoud_aboukhedr is on a distinguished road
Quote:
Originally Posted by hk318i View Post
Sorry my response wasn't clear. I posted it using CFD-onlne app which it isn't very efficient. Actually, it is the second time to write this post because the first one wasn't posted for some reason, anyway . . .

The codedSource fvOption is general way to implement any source term on the run, on the other hand you could modify and existing fvOption to match your needs. Instead if you are planing to use only one solver you could implement it directly in the desired solver.

Regarding the heat source problem, I think this relation cannot be write because it is function in time only and dimensionless. It isn't consistent.

About the pressureGradientExplicitSource, for some reason OpenFOAM dropped it in OpenFOAM-dev, so I expect it will not be available in the next version or a new alternative will be introduced soon. Anyway, your question isn't clear, how do you want the pressure gradient to varies with time? The current implementation in OpenFOAM-2.4 calculates it based on average velocity and direction only both are constants and they are not like fixedTemperatureConstraint which has an option for that.

I think both problems need to be more clear, so the forum users could really help you with constrictive comments.

Thanks for your Reply, yes the app is not that good, you can use it just for browsing stuff,,, anyway..

1st of all I tried to use the (fvOption) and it works very good with the simpleFoam solver for the pressureGradientExplicitSource, but for some reason it didn't work with IcoFoam, the solver escape the file. So I modifaied the solver according to that post (http://www.cfd-online.com/Forums/ope...urce-term.html) and it work fine for single source value.

What you said with pressureGradientExplicitSource, is exactly my problem, you can define single value for the U Bar with a direction, what am looking for is instead of this single value, I would like to define a list of values which will vary in time .. its like the same idea of time dependent velocity inlet but in the source term. Can you help with this problem ?

I appreciate your response and sorry for not being very clear..
Mahmoud
Mahmoud_aboukhedr is offline   Reply With Quote

Old   July 30, 2015, 12:22
Default
  #9
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
Quote:
Originally Posted by hk318i View Post
It should be straight forward according to the source code description, attached before.
Your formula could be implemented like that;

Code:
     const Time& time = mesh().time();
     // cells volumes 
     const scalarField& V = mesh_.V(); 
     scalarField& heSource = eqn.source(); 
      //reference to the source term
     // your equation
     scalar hs = (2.0*time.value())/(1+time.value()); 
     // adding to source term
     heSource += scalarField(V.size(), hs); 
    // heSource +=  ((2.0*time.value())/(1+time.value()))*V; // in case you need it as absolute value
see also cfd.direct post about energy equation in OF, http://cfd.direct/openfoam/energy-equation/
I have four questions in connection with the issue .

1-Is your suggested code same scalarCodedSource as source term type called in the fvOptions dictionary file?
I presented scalarCodedSource as follows and also I have marked my questions with red colour in it:
Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

energySource 
{ 
 type            scalarCodedSource;//question.1//
    active          true;
    selectionMode   all;
    //Is following command applicable for defining specific or absolute mode correct in scalarCodedSource? question .2 
        volumeMode      specific;//  

    scalarCodedSourceCoeffs
    {
        fieldNames      (h);
        redirectType    sourceTime;
        codeInclude
        #{

        #};

        codeCorrect
        #{
            Pout<< "**codeCorrect**" << endl;
        #};

        codeAddSup
        #{
            const Time& time = mesh().time();
            const scalarField& V = mesh_.V();
            const vectorField& C = mesh_.C();
            scalarField& heSource = eqn.source();

             scalar hs = (2.0*time.value())/(1+time.value());
             heSource += scalarField(V.size(), hs) // should user use either this expression or following relation?
heSource += 2*time.value()/(1+time.value()); question.3&4//   

            Pout << "***codeAddSup***" << endl;
        #};

        codeSetValue
        #{
            Pout<< "**codeSetValue**" << endl;
        #};

        // Dummy entry. Make dependent on above to trigger recompilation
        code
        #{
            $codeInclude
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }

    sourceTimeCoeffs
    {
        // Dummy entry
    }
2-where should user assign the source term type as specific or absolute? Should user use Volume mode specific command in fvOption dictionary?

3- Suppose there is an energy source term in a simple solid conduction problem according to the above source term expression. As we know, the meaning of heSource += scalarField(V.size(), hs) relation is equal with the relation as follows:
heSource = heSource+scalarField(V.size(), hs) or heSource_new= heSource_old + scalarField(V.size(), hs).
What's old value of heSource? Whether this term is related to the previous time step? since the case is a simple solid thermal conduction, can user use the relation as follows?:

heSource = scalarField(V.size(), hs) (instead of += sign);

What's ur view?

4-Can user use heSource += hs instead of heSource = scalarField(V.size(), hs)?
In this manner how should user specify absolute or specific source term?

Also I have some questions & ambiguities that I prefer ask them in my next post in this thread.

Also, I'd appreciated if you consult the following thread?
http://www.cfd-online.com/Forums/ope...dedsource.html

Thanks for ur kind attention.

Last edited by Asghari_M; July 30, 2015 at 13:50.
Asghari_M is offline   Reply With Quote

Old   July 30, 2015, 12:58
Default
  #10
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
@Mahmoud
You are right icoFoam doesn't support fvOptions but it could be enabled. Tomislav Maric wrote a post on his blog about how to enable fvOption in an OF solver, if you still interested, [LINK 1].
About a time-varying pressureGradientExplicitSource for Ubar, it think it shouldn't be a big problem (maybe I'm too optimistic ). My idea is to use the DataEntry class [LINK 2] in a new modified time-varying pressureGradientExplicitSource, so the user can specify Ubar as any time-varying BC in OpenFOAM. I will have a deeper look and see how we could do it, hopefully this idea will work.

Best wishes,
Hassan
rasool_soofi likes this.
hk318i is offline   Reply With Quote

Old   July 30, 2015, 13:07
Default
  #11
Member
 
Mahmoud Aboukhedr
Join Date: Feb 2014
Location: London
Posts: 40
Rep Power: 12
Mahmoud_aboukhedr is on a distinguished road
Dear Hassan,

Thanks for your help, I will try your idea. Hopfully it works.

Thanks again
Mahmoud
Mahmoud_aboukhedr is offline   Reply With Quote

Old   July 30, 2015, 13:57
Default
  #12
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
@Asghari
  1. I think scalarCodedSource is suitable for your case because you are targeting the energy equation not the momentum equation.
  2. volumeMode option isn't available, I couldn't find any reference to it in the source code. You can verify that by replacing specific by dummy and run your case. OF will not show any error because it doesn't read it at all.
  3. Sure you can use the (=) operator instead of (+=) but that will disable any other source term in the energy equation. So be careful!
  4. Yes it is possible, when I wrote that I wasn't sure if the complier will complain about the size different between the two types or not. Therefore I Chose a more safer option, which isn't really needed here.

Best Wishes,
Hassan
hk318i is offline   Reply With Quote

Old   July 31, 2015, 04:40
Default
  #13
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
Quote:
Originally Posted by Mahmoud_aboukhedr View Post
Dear Hassan,

Thanks for your help, I will try your idea. Hopfully it works.

Thanks again
Mahmoud
About the input velocity, does the direction change or it is constant and only the velocity magnitude time-varying?
hk318i is offline   Reply With Quote

Old   July 31, 2015, 07:00
Default
  #14
Member
 
Mahmoud Aboukhedr
Join Date: Feb 2014
Location: London
Posts: 40
Rep Power: 12
Mahmoud_aboukhedr is on a distinguished road
Quote:
Originally Posted by hk318i View Post
About the input velocity, does the direction change or it is constant and only the velocity magnitude time-varying?

Dear Hassan,
The velocity magnitude is only time varying for the now.
Thanks.
Mahmoud
Mahmoud_aboukhedr is offline   Reply With Quote

Old   July 31, 2015, 08:16
Default
  #15
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
Quote:
Originally Posted by Mahmoud_aboukhedr View Post
Dear Hassan,
The velocity magnitude is only time varying for the now.
Thanks.
Mahmoud
Hello Mahmoud,

I made some modifications on the original code and upladed it to github, you can download it as follows
Code:
git clone https://github.com/HIKassem/varingPressureGradientExplicitSource.git
The direction is based on Ubar and it is constant. Unfortunately, I hadn't enough time to fully test it. I would suggest that you test it against pimpleFoam/channel395 tutorial.

Best wishes,
Hassan

PS. I just noticed right now that your surname looks familiar to me!
hk318i is offline   Reply With Quote

Old   July 31, 2015, 09:00
Default
  #16
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
@Hassan
I assigned heat source term as follows:
Code:
scalar hs = (2.0*time.value())/(1+time.value());
heSource += scalarField(V.size(), hs);
To my surprise, I saw the temperature of field decreases during solution. The initial condition for the temperature is 300 kelvin.However maximum temperature is 300 k during running and generally T of field<300k.
How is this interpretable?!! Is it a bug?!
Also, I have two other questions about your last helpful replies:
Quote:
Originally Posted by hk318i View Post
@Asghari

2- volumeMode option isn't available, I couldn't find any reference to it in the source code. You can verify that by replacing specific by dummy and run your case. OF will not show any error because it doesn't read it at all.
1-What's your purpose of replacing specific by dummy and run your case? Can u descibe with more details and or by an example?
(Excuse me if my questions are easy. I'm almost biginner in OF)

Quote:
Originally Posted by hk318i View Post
4-Yes it is possible, when I wrote that I wasn't sure if the complier will complain about the size different between the two types or not. Therefore I Chose a more safer option, which isn't really needed here.
2-What's the meaning of scalarField(A, B) operator in heSource += scalarField(V.size(), hs) ?
Meanwhile, I use OF2.3.1.
Thanks again for ur kind attention.

Last edited by Asghari_M; July 31, 2015 at 10:08.
Asghari_M is offline   Reply With Quote

Old   July 31, 2015, 10:22
Default
  #17
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
Sorry my answer was very concise in the previous post.
  • "dummy" is a famous trick in OpenFOAM, when you have doubt about the available options for any entry in a dictionary. Simply you put the word dummy or any word and run your case. OF will give you an error and shows you all the available options.
  • scalarField(A,B) is one of the many constructors of scalarField class. It creates scalarFiled of size A (A should be label or int) and all the values in this field is equal to a scalar B. Therefore heSource += scalarField(V.size(), hs) creates a field has the same size of your mesh with values equal to scalar hs and add it to heSource field. However as I said in my previous post you don't need that.

Regarding the results, it is really hard to comment on it because I don't know the physics of you problem and your case study. I think hs value is really small specially at the beginning of your simulation, isn't it?
hk318i is offline   Reply With Quote

Old   July 31, 2015, 13:42
Default
  #18
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
Quote:
Originally Posted by hk318i View Post
Regarding the results, it is really hard to comment on it because I don't know the physics of you problem and your case study. I think hs value is really small specially at the beginning of your simulation, isn't it?
Assume there is a specific heat source term at center of a cube. The faces of cube are adiabatic as BC. I expect temperature enhances with the passing of time. Variations aren't so small. The unit of heat source term is W/m3 or same specific. However, unfortunately I observe temperature decreasing. What's the real reason of this event?
Also, I have another question as follows:
Which expression in scalarCodedSource is suitable for this specific heat source term definition (I've indicited expressions in following code by red colour)?
Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

energySource 
{ 
 type            scalarCodedSource;
    active          true;
    selectionMode   all;
  

    scalarCodedSourceCoeffs
    {
        fieldNames      (h);
        redirectType    sourceTime;
        codeInclude
        #{

        #};

        codeCorrect
        #{
            Pout<< "**codeCorrect**" << endl;
        #};

        codeAddSup
        #{
            const Time& time = mesh().time();
            const scalarField& V = mesh_.V();
            const vectorField& C = mesh_.C();
            scalarField& heSource = eqn.source();

             scalar hs = (2.0*time.value())/(1+time.value());
           // Which following expression is suitable for mentioned specific source term ?
     heSource +=  hs 
              .OR.
       heSource +=  hs*V;//
        Pout << "***codeAddSup***" << endl;
        #};

        codeSetValue
        #{
            Pout<< "**codeSetValue**" << endl;
        #};

        // Dummy entry. Make dependent on above to trigger recompilation
        code
        #{
            $codeInclude
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }

    sourceTimeCoeffs
    {
        // Dummy entry
    }
I'd appreciated for any help.
Asghari_M is offline   Reply With Quote

Old   August 1, 2015, 08:57
Default
  #19
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: Germany
Posts: 242
Rep Power: 18
hk318i is on a distinguished road
First, because you are using [selectionMode all;] option, your source is applied every where in your domain.
I am not sure about if scalarCodedSource should be W/m3 or should be multiplied by V. Usually the source term is specified as w/m3 but I am not sure about that using this code.
I am confused because in the description of the class, the give example is multiplied by V. I believe more investigations are required to confirm this issue.
hk318i is offline   Reply With Quote

Old   August 1, 2015, 10:24
Default
  #20
Senior Member
 
Mehdi Asghari
Join Date: Feb 2010
Posts: 127
Rep Power: 16
Asghari_M is on a distinguished road
Quote:
Originally Posted by hk318i View Post
First, because you are using [selectionMode all;] option, your source is applied every where in your domain.
I am not sure about if scalarCodedSource should be W/m3 or should be multiplied by V. Usually the source term is specified as w/m3 but I am not sure about that using this code.
I am confused because in the description of the class, the give example is multiplied by V. I believe more investigations are required to confirm this issue.
Ok, assume heat source term is assigned everywhere within cube. Unfortunately results don't change. The temperature of cube decreases whereas it should increases. What's the reason?
In both my questions, I think it's better to refer source code. What's ur idea?
Sincerely;
Asghari_M is offline   Reply With Quote

Reply


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
Transient spacial dependent heat source Kumudu OpenFOAM Running, Solving & CFD 0 October 28, 2013 12:02
same geometry,structured and unstructured mesh,different behaviour. sharonyue OpenFOAM Running, Solving & CFD 13 January 2, 2013 23:40
plot over time fferroni OpenFOAM Post-Processing 7 June 8, 2012 08:56
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 11:57
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 12:44


All times are GMT -4. The time now is 04:36.