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

coded energysource in fvModels

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 25, 2022, 15:59
Default coded energysource in fvModels
  #1
New Member
 
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17
borrbyper is on a distinguished road
In OF8, I used "scalarCodedSource" in fvOptions to add a source to the field e. The source term is a function of coordinate and resides in a field, sourceTerm.

In OF9, I had to rephrase a bit to "coded" in fvModels to get it running.
It does however not seem to add any source in the energy equation - the temperatures are unaffected by it.

Would you have an idea why (or alternatives how to add a constant heat source which is a function of coordinate)?

Code:
energySource
{
	type		coded;

	selectionMode   all;

	field e;

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

	 	volScalarField ST
 		(
 			IOobject
        		(
 				"sourceTerm",
				"0",
				mesh(),
				IOobject::MUST_READ,
				IOobject::NO_WRITE
			),
 			mesh()
	 	);

		const scalarField& V = mesh().V();
		scalarField& heSource = eqn.source();
		//heSource = 1e8;
 		heSource = -1*ST*V;

	#};

}
ibitscholar likes this.
borrbyper is offline   Reply With Quote

Old   January 26, 2022, 05:06
Default
  #2
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 798
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Not sure.

Possibly it helps to first replace "V = mesh().V()" by "V = mesh_().V()" (adding underscore) as given by the example here https://www.openfoam.com/documentati...ces-coded.html and run a test with replacing "heSource = -1*ST*V" by "heSource = -1*V" (thus leaving leaving ST out). I am very curious to see whether that would work.

In a second step I would reconsider the ST factor. I currently fail to understand how the value of ST is set. I wonder whether the use of the object registry is recommended here.

Good luck.
dlahaye is offline   Reply With Quote

Old   January 26, 2022, 12:28
Default
  #3
New Member
 
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17
borrbyper is on a distinguished road
Thanks for your reply!


I did try the underscore already with OF8 "mesh_.V()" and it gives

Code:
 ‘const Mesh& Foam::DimensionedField<double, Foam::volMesh>::mesh_’ is private within this context
so I changed to parantheses as given in
https://cpp.openfoam.org/v9/classFoa...edFvModel.html


The ST field should be fetched from a file named sourceTerm located in /0/.
I tried both a codeStream version of that file (which seems to work as there are lists created in the processor0/0 directories),
as well as a uniform version (though that is not sufficient for the purpose - to have it nonuniform).


The ST field does however not seem to be the problem.
There does e.g. not seem to be any impact on the temperature even if I replace
Code:
heSource = -1*ST*V;
with
Code:
forAll(V, i)
{
  heSource[i] -= 1e8;
};

Is there another way to set a test field into eqn.source(), e.g. a uniform constant?
Alternatively, is there a way to inspect what is actually set, e.g. save it in a file?

Is the problem "V"?
Can I confirm that it is actually referring to the volumes of the model mesh in the code previously shown?
borrbyper is offline   Reply With Quote

Old   January 26, 2022, 12:48
Default
  #4
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 798
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
No clue.

Are you (maybe?) adding to h and solving for e (or vice versa)?
dlahaye is offline   Reply With Quote

Old   January 27, 2022, 02:39
Default
  #5
New Member
 
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17
borrbyper is on a distinguished road
I do not think so.

I solve for sensibleInternalEnergy (e) as specified in thermoType of thermoPhysicalProperties and the coded energySource is also acting on the field specified as e. It worked like that in OF8 too.
borrbyper is offline   Reply With Quote

Old   January 27, 2022, 08:21
Default
  #6
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 798
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Three questions:

1/ Do you see the result of the Pout statement when running the code?

2/ What happens in case you toss mesh().V and merely set heSource = - 1e8?

3/ What happens in case you place the Pout statement inside of the loop over cell?
borrbyper likes this.
dlahaye is offline   Reply With Quote

Old   January 27, 2022, 09:19
Default
  #7
New Member
 
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17
borrbyper is on a distinguished road
Thanks for the suggestions!

1. No, a grep does not show any output of "codeAddSup".
The line does occur, as repeated input, in dynamicCode/energySource/codedFvModelTemplate.C.
The output also shows evidence of using the code:
Code:
Selecting finite volume model type coded
    Name: energySource
    - selecting all cells
    - selected 3600 cell(s) with volume 0.0012942422
Using dynamicCode for fvModel:: energySource at line 22 in ... etc
2. Just setting heSource = -1e8 or -= 1e8 gives no difference, still no source.
Is that valid though, as 1e8 is a scalar but heSource is a field (unless it is indexed)?

3. Pout inside the loop gives no difference, no output. (That loop relies on V though.)

All this is on sensibleInternalEnergy. Along with your previous suggestion that it might be related to e/h, I did another test.
I copied the heatedDuct tutorial.
Then I copied exactly the example of
https://cpp.openfoam.org/v9/classFoa...edFvModel.html into constant/fluid/fvModels and changed heSource to 1e8.
It runs and shows evidence as above, but no impact on temperature.
borrbyper is offline   Reply With Quote

Old   January 27, 2022, 11:42
Default
  #8
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 798
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Do you need to add

codeInclude
#{
#include "fvCFD.H"
#include <cmath>
#include <iostream>
#};

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
#};

or similar?
dlahaye is offline   Reply With Quote

Old   January 27, 2022, 12:41
Default
  #9
New Member
 
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17
borrbyper is on a distinguished road
I did not think that either, because if a reference to a library function or similar was missing the compiler should complain, right?

Neither were there any such references in the example at cpp.openfoam.org/v9.

I did try to add the ones you suggest anyway though, before codeAddSup.
(Maybe it could be other libraries but that would be pure guessing from my side.)
These made no difference.
borrbyper is offline   Reply With Quote

Old   February 3, 2022, 08:10
Default
  #10
New Member
 
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17
borrbyper is on a distinguished road
I could have found the answer by investigating why the Pout string does not occur in the output.

The solver is compressible, so the source term should be added by codeAddRhoSup instead of codeAddSup. Then it seems to work. :-)
dlahaye, Mars409 and sunafegon like this.
borrbyper is offline   Reply With Quote

Old   February 3, 2022, 08:29
Default
  #11
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 798
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Well done! Congrats! Happy that this is resolved.

Question: is my (always very limited) understanding correct that this construction allows not only to add source terms, but replace implemented source terms altogether?

What I meant is to proceed in two steps by

1/ first subtract in the codedSource the negative of what is in the source code;

2/ add a user defined contribution?

Tak, Domenico.
dlahaye is offline   Reply With Quote

Old   July 2, 2022, 16:11
Default
  #12
ewe
New Member
 
Join Date: May 2022
Posts: 2
Rep Power: 0
ewe is on a distinguished road
Hello Per,


I have the same problem, could you elaborate how you fixed the issue? How did you choose codeAddRhoSup instead of codeAddSup? Which solver did you use? Thank you very much!
ewe is offline   Reply With Quote

Old   July 7, 2022, 02:26
Default
  #13
New Member
 
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17
borrbyper is on a distinguished road
As you can see in the code included at the top of this thread, the code is written under the keyword codeAddSup. For this solver (chtMultiRegionFoam) it should be under codeAddRhoSup.
borrbyper is offline   Reply With Quote

Old   July 7, 2022, 02:31
Default
  #14
New Member
 
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17
borrbyper is on a distinguished road
I think "source term" can be defined in different ways, so I am not sure what is meant by a replacement or addition. As I see it here, this is the only external or user defined source term in the energy equation. If there would be another source term, e.g. from viscous heating, I strongly doubt it can be replaced in this relatively simple manner.
borrbyper is offline   Reply With Quote

Old   September 15, 2023, 23:44
Default Quick Question!!!
  #15
New Member
 
Vittorio Nardin
Join Date: Jun 2023
Posts: 5
Rep Power: 3
vitto is on a distinguished road
Quote:
Originally Posted by borrbyper View Post
I think "source term" can be defined in different ways, so I am not sure what is meant by a replacement or addition. As I see it here, this is the only external or user defined source term in the energy equation. If there would be another source term, e.g. from viscous heating, I strongly doubt it can be replaced in this relatively simple manner.

Can you write ST field each writeTime Interval??

Last edited by vitto; September 15, 2023 at 23:51. Reason: xD
vitto is offline   Reply With Quote

Old   February 19, 2024, 01:05
Default
  #16
New Member
 
Shubham
Join Date: Jan 2024
Posts: 8
Rep Power: 2
shubhamkv1 is on a distinguished road
Hello
I am having a similar problem where I am applying a energy source. However, I need to apply this source term to a particular volume of geometry. I tried it by doing

select cellZone;
cellZone c0;

In log file, it is showing that the source term is being applied to zone c0, but in actual it is being applied to whole volume (from the results it is being visualized).

So, just want to know, where I am going wrong.
Is there any other way to do?

Thanks
Shubham
shubhamkv1 is offline   Reply With Quote

Old   February 19, 2024, 10:03
Default
  #17
New Member
 
Vittorio Nardin
Join Date: Jun 2023
Posts: 5
Rep Power: 3
vitto is on a distinguished road
Quote:
Originally Posted by shubhamkv1 View Post
Hello
I am having a similar problem where I am applying a energy source. However, I need to apply this source term to a particular volume of geometry. I tried it by doing

select cellZone;
cellZone c0;

In log file, it is showing that the source term is being applied to zone c0, but in actual it is being applied to whole volume (from the results it is being visualized).

So, just want to know, where I am going wrong.
Is there any other way to do?

Thanks
Shubham
You need to check your c0 cellZone.
Where it is being created? in the blockMeshDict or in the topoSetDict?
vitto is offline   Reply With Quote

Old   February 19, 2024, 10:50
Default
  #18
New Member
 
Shubham
Join Date: Jan 2024
Posts: 8
Rep Power: 2
shubhamkv1 is on a distinguished road
1. I have checked the c0 cellzone number of times. It is modelled and assigned properly. Even I am able to visualise that zone in ParaFoam. Also, the log file indicates that a source term is being applied to cellZone c0.
2. I have created the model using gmsh and assigned the names there only.
shubhamkv1 is offline   Reply With Quote

Old   February 19, 2024, 11:44
Default
  #19
New Member
 
Vittorio Nardin
Join Date: Jun 2023
Posts: 5
Rep Power: 3
vitto is on a distinguished road
Quote:
Originally Posted by shubhamkv1 View Post
1. I have checked the c0 cellzone number of times. It is modelled and assigned properly. Even I am able to visualise that zone in ParaFoam. Also, the log file indicates that a source term is being applied to cellZone c0.
2. I have created the model using gmsh and assigned the names there only.
what type of energy source you are using?
It is a codedFvModel or a heatSource??
vitto is offline   Reply With Quote

Old   February 19, 2024, 11:53
Default
  #20
New Member
 
Shubham
Join Date: Jan 2024
Posts: 8
Rep Power: 2
shubhamkv1 is on a distinguished road
I am using coded fvModel for this.
shubhamkv1 is offline   Reply With Quote

Reply

Tags
coded, fvmodels, fvoptions, heatsource


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
Accessing species in coded function object Swirl OpenFOAM Programming & Development 2 January 24, 2022 05:52
coded functionObjects behaving not as expected alexfells OpenFOAM 2 October 28, 2020 04:58
Coded function object in openfoam v5 kit607 OpenFOAM Post-Processing 3 September 29, 2020 16:43
Unknown character in name of output variable when using coded function object pvergnol OpenFOAM Post-Processing 5 August 12, 2020 14:29
codeInclude in coded function in controlDict, and yPlus LuisAlberto OpenFOAM Programming & Development 4 August 18, 2015 13:48


All times are GMT -4. The time now is 12:28.