|
[Sponsors] |
January 25, 2022, 15:59 |
coded energysource in fvModels
|
#1 |
New Member
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17 |
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; #}; } |
|
January 26, 2022, 05:06 |
|
#2 |
Senior Member
|
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. |
|
January 26, 2022, 12:28 |
|
#3 |
New Member
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17 |
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 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; 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? |
|
January 27, 2022, 02:39 |
|
#5 |
New Member
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17 |
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. |
|
January 27, 2022, 08:21 |
|
#6 |
Senior Member
|
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? |
|
January 27, 2022, 09:19 |
|
#7 |
New Member
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17 |
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 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. |
|
January 27, 2022, 11:42 |
|
#8 |
Senior Member
|
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? |
|
January 27, 2022, 12:41 |
|
#9 |
New Member
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17 |
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. |
|
February 3, 2022, 08:10 |
|
#10 |
New Member
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17 |
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. :-) |
|
February 3, 2022, 08:29 |
|
#11 |
Senior Member
|
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. |
|
July 2, 2022, 16:11 |
|
#12 |
New Member
Join Date: May 2022
Posts: 2
Rep Power: 0 |
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! |
|
July 7, 2022, 02:26 |
|
#13 |
New Member
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17 |
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.
|
|
July 7, 2022, 02:31 |
|
#14 |
New Member
Per Nilsson
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 21
Rep Power: 17 |
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.
|
|
September 15, 2023, 23:44 |
Quick Question!!!
|
#15 | |
New Member
Vittorio Nardin
Join Date: Jun 2023
Posts: 5
Rep Power: 3 |
Quote:
Can you write ST field each writeTime Interval?? Last edited by vitto; September 15, 2023 at 23:51. Reason: xD |
||
February 19, 2024, 01:05 |
|
#16 |
New Member
Shubham
Join Date: Jan 2024
Posts: 8
Rep Power: 2 |
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 |
|
February 19, 2024, 10:03 |
|
#17 | |
New Member
Vittorio Nardin
Join Date: Jun 2023
Posts: 5
Rep Power: 3 |
Quote:
Where it is being created? in the blockMeshDict or in the topoSetDict? |
||
February 19, 2024, 10:50 |
|
#18 |
New Member
Shubham
Join Date: Jan 2024
Posts: 8
Rep Power: 2 |
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. |
|
February 19, 2024, 11:44 |
|
#19 | |
New Member
Vittorio Nardin
Join Date: Jun 2023
Posts: 5
Rep Power: 3 |
Quote:
It is a codedFvModel or a heatSource?? |
||
February 19, 2024, 11:53 |
|
#20 |
New Member
Shubham
Join Date: Jan 2024
Posts: 8
Rep Power: 2 |
I am using coded fvModel for this.
|
|
Tags |
coded, fvmodels, fvoptions, heatsource |
|
|
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 |