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

adding a constant volumetric source term to transport equation in a particular region

Register Blogs Community New Posts Updated Threads Search

Like Tree33Likes
  • 2 Post By cfdonline2mohsen
  • 4 Post By zfaraday
  • 1 Post By Cyp
  • 8 Post By fabian_roesler
  • 1 Post By cfdonline2mohsen
  • 3 Post By fabian_roesler
  • 2 Post By Cyp
  • 8 Post By ARTem
  • 1 Post By Cyp
  • 3 Post By michall

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 17, 2014, 06:02
Smile adding a constant volumetric source term to transport equation in a particular region
  #1
Senior Member
 
cfdonline2mohsen's Avatar
 
Mohsen KiaMansouri
Join Date: Jan 2010
Location: CFD Lab
Posts: 118
Rep Power: 16
cfdonline2mohsen is on a distinguished road
Dear Foamers
Hi!

I want to add a constant volumetric source term to the scalar transport equation which acts only in a particular volumetric region of the domain.

I modified the scalar transport equation as follows:
Code:
solve
	(
	  fvm::ddt(T)
	  + fvm::div(phi, T)
	  - fvm::laplacian(DT, T)
	  ==
	  sourceValue
	);
Then I defined the sourceValue in the createFields.H file as follows:

Code:
dimensionedScalar sourceValue(twoPhaseProperties.lookup("sourceValue"));
It will read the sourceValue from the transportProperties file of my case. In the transportProperties file,I gave the sourceValue as follows:

Code:
sourceValue      sourceValue [0 0 -1 0 0 0 0] 0.42;
By using this approach, the sourceValue=0.42 is used for the entire domain but I want to use the sourceValue=0.42 for only a specific volumetric region inside my domain.

I have two questions:

1) How can I define this volumetric region inside my domain? is there any utility?

2) How can I change the transportProperties file to consider sourceValue=0.42 only for this specific volumetric region and sourceValue=0 for the rest of the domain?


Any help in this regard would be much appreciated.
Thank you so much in advance.
BlnPhoenix and Luttappy like this.
__________________
“If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas.”
cfdonline2mohsen is offline   Reply With Quote

Old   November 17, 2014, 11:25
Default
  #2
Senior Member
 
Alex
Join Date: Oct 2013
Posts: 337
Rep Power: 22
zfaraday will become famous soon enough
Maybe your approach would be to create your source region by using topoSet utility first. Then, once you have created your zone where you want to locate your source, you can use the fvOption framework in order to create the source (I assume it's a heat source). It's an easy approach and you don't need to modify your solver!

Regards,

Alex
__________________
Web site where I present my Master's Thesis: foamingtime.wordpress.com

The case I talk about in this site was solved with chtMultiRegionSimpleFoam solver and involves radiation. Some basic tutorials are also resolved step by step in the web. If you are interested in these matters, you are invited to come in!
zfaraday is offline   Reply With Quote

Old   November 17, 2014, 18:23
Default
  #3
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18
Cyp is on a distinguished road
or declare your sourceTerm as a volScalarField and assign it different values (0 and 0.42) with setField
cfdonline2mohsen likes this.
Cyp is offline   Reply With Quote

Old   November 18, 2014, 03:22
Default fvOption source with cellZones
  #4
Senior Member
 
Fabian Roesler
Join Date: Mar 2009
Location: Germany
Posts: 213
Rep Power: 18
fabian_roesler is on a distinguished road
The tip with the cellZone is correct. You can add whatever source you like throughout a fvOption:

Code:
energySource 
{ 
    type            scalarSemiImplicitSource; 
    active          true; 
    selectionMode   cellZone; 
    cellZone        porosity; 
 
    scalarSemiImplicitSourceCoeffs 
    { 
        volumeMode      absolute; 
        injectionRateSuSp 
        { 
            h           (10 0); 
        } 
    } 
}
The value for an absolute heat source is given in unit [W] while the specific heat is volume specific and is given in [W/mł]. Some other possible sources are:
  • Mass source in kg/s (absolute) or kg/młs (specific)
  • Momentum source in kg m/s˛ (absolute) or kg/m˛s˛ (specific)
  • Heat source in J/s (absolute) or J/młs (specific)
Cheers

Fabian
fabian_roesler is offline   Reply With Quote

Old   November 18, 2014, 04:18
Default
  #5
Senior Member
 
cfdonline2mohsen's Avatar
 
Mohsen KiaMansouri
Join Date: Jan 2010
Location: CFD Lab
Posts: 118
Rep Power: 16
cfdonline2mohsen is on a distinguished road
Thanks Cyprien
I thought that setFields can only be used for initial conditions (initialization) like the dam break example in the user guide?
Am I wrong?
Because my source exists there all the time not only at t=0.
I quote the user guide:
Code:
setFields     Set values on a selected set of cells/patchfaces through a dictionary
Can I use setFields to set my sourceValue on a particular volumetric region of the domain for all the timesteps? and How?

It's so kind of you.
Kummi likes this.
__________________
“If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas.”
cfdonline2mohsen is offline   Reply With Quote

Old   November 18, 2014, 04:27
Default
  #6
Senior Member
 
Fabian Roesler
Join Date: Mar 2009
Location: Germany
Posts: 213
Rep Power: 18
fabian_roesler is on a distinguished road
No you can't. As a source term is not just setting a simple value but solving for it implicit during the solution process, setFields will not help you much. It's only a tool to set initial conditions.
Create a cellZone and use fvOptions or change your solver code to implement a source to your equation.

Cheers

Fabian
fabian_roesler is offline   Reply With Quote

Old   November 18, 2014, 13:23
Default
  #7
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18
Cyp is on a distinguished road
Once you have assign different values to your "sourceTerm" with setFields your source term will have the same value for all the time steps.
cfdonline2mohsen and Kummi like this.
Cyp is offline   Reply With Quote

Old   November 20, 2014, 04:56
Default
  #8
Member
 
Artem Shaklein
Join Date: Feb 2010
Location: Russia, Izhevsk
Posts: 43
Rep Power: 16
ARTem is on a distinguished road
Also you can use more general approach, if e.g. you have a function describing the source distribution S = f(x,y,z). You should edit createFields.H by adding
Code:
volScalarField S
(   
    IOobject
    (   
        "S",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    mesh,
    // yourSourceDimension is dimensionSet(0,0,0,0,0) with appropriate dimensions
    dimensionedScalar("S",yourSourceDimension,scalar(0))
);

forAll(mesh.C(), celli)
{
   vector Ci = mesh.C()[celli];
   // For a general case
   // S[celli] = yourFunction(Ci.x(), Ci.y(), Ci.z());

   // For your case
   if(Ci.x() > x1 && Ci.x() < x2) S[celli] = S1;
   else S[celli] = S2; 
}

S.write() // Writing just ones for checking S distribution in paraview
with yourFunction beeing "scalar yourFunction(scalar x, scalar y, scalar z) const;" and x1, x2 being scalar type.
ARTem is offline   Reply With Quote

Old   November 22, 2014, 04:43
Default
  #9
Senior Member
 
cfdonline2mohsen's Avatar
 
Mohsen KiaMansouri
Join Date: Jan 2010
Location: CFD Lab
Posts: 118
Rep Power: 16
cfdonline2mohsen is on a distinguished road
Quote:
Originally Posted by Cyp View Post
Once you have assign different values to your "sourceTerm" with setFields your source term will have the same value for all the time steps.
Thanks Cyprien
But I think you are wrong!
When you assign different values to your field with setFields, It will not have the same value for all the time steps!
setFields is only designed for setting the initial conditions on your fields as stated by fabian_roesler in this post and also by Bernhard in #4 and also in #5.
If you take a look at Figure 2.21 on page U-60 of the user guide and compare it with Figure 2.22, you will see that it will change.

Thanks you so much again.
__________________
“If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas.”
cfdonline2mohsen is offline   Reply With Quote

Old   November 22, 2014, 05:22
Default
  #10
Senior Member
 
cfdonline2mohsen's Avatar
 
Mohsen KiaMansouri
Join Date: Jan 2010
Location: CFD Lab
Posts: 118
Rep Power: 16
cfdonline2mohsen is on a distinguished road
Thank you all.

I think I can not use setFields as stated by Cyp for this purpose.
Then I have two options:

1) fvOptions and topoSet utilities as stated by zfaraday and fabian_roesler
which is only available after OpenFOAM v2.2.0.

2) Modifying my solver to implement my source into the equation as stated by ARTem and fabian_roesler.

Since I use OF 2.1.1., I prefer to use the second approach as suggested by ARTem.

Any further advice and suggestions will be highly appreciated.
__________________
“If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas.”
cfdonline2mohsen is offline   Reply With Quote

Old   November 22, 2014, 17:03
Default
  #11
Cyp
Senior Member
 
Cyprien
Join Date: Feb 2010
Location: Stanford University
Posts: 299
Rep Power: 18
Cyp is on a distinguished road
Quote:
Originally Posted by cfdonline2mohsen View Post
Thanks Cyprien
But I think you are wrong!
When you assign different values to your field with setFields, It will not have the same value for all the time steps!
setFields is only designed for setting the initial conditions on your fields as stated by fabian_roesler in this post and also by Bernhard in #4 and also in #5.
If you take a look at Figure 2.21 on page U-60 of the user guide and compare it with Figure 2.22, you will see that it will change.

Thanks you so much again.

Of course it will have the same value at all the time steps!! In the tutorial you mentioned, setFields is used to initialise your field alpha1, that will be modified later with the solver interFoam.

In your case, you want to assign different value to your volScalarField called "sourceTerm". You CAN do that with setFields (and it is actually the fastest way and is kind of similar to the method suggested by ARTem). Since there is no equation that will modify "sourceTerm", it will keep the same value for all the time step.

Best,
cfdonline2mohsen likes this.
Cyp is offline   Reply With Quote

Old   November 23, 2014, 03:27
Default
  #12
Senior Member
 
cfdonline2mohsen's Avatar
 
Mohsen KiaMansouri
Join Date: Jan 2010
Location: CFD Lab
Posts: 118
Rep Power: 16
cfdonline2mohsen is on a distinguished road
Quote:
Originally Posted by Cyp View Post
Of course it will have the same value at all the time steps!! In the tutorial you mentioned, setFields is used to initialise your field alpha1, that will be modified later with the solver interFoam.

In your case, you want to assign different value to your volScalarField called "sourceTerm". You CAN do that with setFields (and it is actually the fastest way and is kind of similar to the method suggested by ARTem). Since there is no equation that will modify "sourceTerm", it will keep the same value for all the time step.

Best,
Thank you Cyprien for your supplementary comments.Then I will try setFields first to see the results.
It's so nice of you.
__________________
“If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas.”
cfdonline2mohsen is offline   Reply With Quote

Old   September 2, 2015, 07:33
Default source
  #13
New Member
 
Michal
Join Date: Jul 2015
Location: Poland
Posts: 5
Rep Power: 11
michall is on a distinguished road
Hi,

The topic is quite old and probably obvious for more advanced users yet I don't see final answer. Recently I had to add a source term in the enthalpy equation in the OF 2.1.1 (so no fvOption yet).

I merge discussed solution of cfdonline2mohsen and ARTem. I added my source in createFields.H (like in ARTem post #8) and used setFields to set a constant value of my source in certain region only. It worked, but the problem was that in the next time step the value of the source was 0 again. The problem was the following line:
Code:
 
dimensionedScalar("S",yourSourceDimension,scalar(0))
which was setting the value of the source back to 0. Without this line it works ok. and the dimensions are specified in my source file in startTime directory. In summary:
1) Add "source" to your equation
2) Modify createFields.H:
Code:
volScalarField hSource
(   
    IOobject
    (   
        "hSource",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);
(AUTO_WRITE is not needed but I wanted to check if it works.)
3) Compile
4) Use setFields
So this is working solution in my case.
linyanx, DavidFernandes and Kummi like this.
michall is offline   Reply With Quote

Old   November 24, 2015, 01:11
Default
  #14
Member
 
Robert Ong
Join Date: Aug 2010
Posts: 86
Rep Power: 16
rob3rt 0ng is on a distinguished road
Hi,

Is there a way to specify the actual initial value of a variable (i.e. concentration) and its diffusivity in the fvOptions?

Thanks and regards,
Robert
rob3rt 0ng is offline   Reply With Quote

Old   December 14, 2015, 04:13
Default
  #15
Senior Member
 
Fabian Roesler
Join Date: Mar 2009
Location: Germany
Posts: 213
Rep Power: 18
fabian_roesler is on a distinguished road
I didn't get your question entirely. Initial values are defined in the fields them selves.
In fvOptions you can define extra sources acting inside the conservation equations.

Cheers

Fabian
fabian_roesler is offline   Reply With Quote

Old   February 16, 2017, 10:55
Default
  #16
Member
 
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11
sisetrun is on a distinguished road
Hey everybody,

thank you for the discretion how to add the source to solver.

I am trying to modify the scalarTransport solver. The goal is to add the tracer directly in front of an obstacle and not at the inlet patch. I want to set the value of the tracer to 1 to obtain same info as from common scalarTransportFoam.

I managed to add a tracer source (T_source) to scalarTransportFoam and to set its value to 1 in my domain. When I run the modified scalarTransportFoam, my T_source stays constant at 1 and the tracer is spread through the volume. BUT: the values for T are very small (around 5e-3).

Do you have an idea to fix this? Is there maybe something wring with the dimensions?

Thank you for your time

Best regards
sisetrun 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
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 06:18
How to write UDF to add a source term to the new transport equation ? 89566008 Fluent UDF and Scheme Programming 2 October 22, 2012 08:23
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 12:44
Source Term on Scalar Transport Equation alessio.nz OpenFOAM Programming & Development 9 January 31, 2011 08:56
[Gmsh] Import gmsh msh to Foam adorean OpenFOAM Meshing & Mesh Conversion 24 April 27, 2005 09:19


All times are GMT -4. The time now is 14:06.