CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   coded energysource in fvModels (https://www.cfd-online.com/Forums/openfoam-solving/240825-coded-energysource-fvmodels.html)

borrbyper January 25, 2022 14:59

coded energysource in fvModels
 
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;

        #};

}


dlahaye January 26, 2022 04:06

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.

borrbyper January 26, 2022 11:28

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?

dlahaye January 26, 2022 11:48

No clue.

Are you (maybe?) adding to h and solving for e (or vice versa)?

borrbyper January 27, 2022 01:39

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.

dlahaye January 27, 2022 07:21

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 January 27, 2022 08:19

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.

dlahaye January 27, 2022 10:42

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?

borrbyper January 27, 2022 11:41

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 February 3, 2022 07:10

I could have found the answer by investigating why the Pout string does not occur in the output. :o

The solver is compressible, so the source term should be added by codeAddRhoSup instead of codeAddSup. Then it seems to work. :-)

dlahaye February 3, 2022 07:29

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.

ewe July 2, 2022 15:11

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!

borrbyper July 7, 2022 01:26

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 July 7, 2022 01:31

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.

vitto September 15, 2023 22:44

Quick Question!!!
 
Quote:

Originally Posted by borrbyper (Post 831141)
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??

shubhamkv1 February 19, 2024 00:05

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

vitto February 19, 2024 09:03

Quote:

Originally Posted by shubhamkv1 (Post 864923)
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?

shubhamkv1 February 19, 2024 09:50

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.

vitto February 19, 2024 10:44

Quote:

Originally Posted by shubhamkv1 (Post 864956)
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??

shubhamkv1 February 19, 2024 10:53

I am using coded fvModel for this.


All times are GMT -4. The time now is 18:32.