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

fvOptions - sign for sources in scalarCodedSource

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By user
  • 1 Post By mAlletto
  • 1 Post By sharonyue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 17, 2021, 16:22
Default fvOptions - sign of sources in scalarCodedSource
  #1
New Member
 
Join Date: Apr 2009
Posts: 13
Rep Power: 17
user is on a distinguished road
Hello foamers,


I'm struggling with adding a heat source via scalarCodedSource because it seems that negative values are needed to have a positive source.

For further investigations I made a simple test case with rhoPimpleFoam where I used a scalarSemiImplicitSource in a cellZone to define a positive heat source in a closed system:

Code:
heatSource1
{
    type            scalarSemiImplicitSource;
    active          true;
 
    scalarSemiImplicitSourceCoeffs
    {
        selectionMode   cellZone; // all, cellSet, cellZone, points
        cellZone        sourceZone;
        volumeMode      absolute;
        injectionRateSuSp
        {
            h   (0.1 0);
        }
    }
}
and additionally a scalarCode which simply reads out the eqn.source() and printing the sum of it:

Code:
heatSource2
{
    type            scalarCodedSource;
    active          true;
    name            heatSource2; 
   
    scalarCodedSourceCoeffs
    {
        selectionMode   cellZone;
        cellZone        sourceZone;
        fields          (h); 

        codeInclude
        #{
        #};

        codeCorrect
        #{
        #};

        codeAddSup
        #{
            scalarField& hSource = eqn.source();
            
            const scalarField& V = mesh_.V();     
            double hSourceTot = 0;

            forAll(V, i)  
            {
                hSourceTot += hSource[i]; 
            }
            Pout << " hSourceTot = " << hSourceTot << " with dimension " << eqn.dimensions() << endl; 
                       
        #};

        codeConstrain
        #{
        #};            

        code
        #{
            $codeInclude
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }
    
}
In the above case the toal sum of the heat sources are "-0.1" - a negative value. Could somebody explain why sources in scalarCodedSources must be negative? Is this specific to the energy equation?

I tested it with OpenFOAM-v2006 and v2012 and have attached the test case. Just unpack and run "./runMesh" and after that rhoPimpleFoam

Thanks in advance
Ulf
Attached Files
File Type: zip heatsource_rhoPimpleFoam.zip (8.5 KB, 10 views)
saladbowl likes this.

Last edited by user; March 23, 2021 at 11:47.
user is offline   Reply With Quote

Old   March 20, 2021, 09:29
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
If I'm not mistaken, the function below gives you a reference to the source of the whole equation (the term on the right hand side the equation . If you are solving the temperature equation there is not only coded source in it but a lot more staff. Think about the laplacian discretization on non ortognonal grids. There you get also explicit source term.



Code:

eqn.source();
mAlletto is offline   Reply With Quote

Old   March 22, 2021, 15:39
Default
  #3
New Member
 
Join Date: Apr 2009
Posts: 13
Rep Power: 17
user is on a distinguished road
Yes, thanks for your reply - your are absolutely right and I also thought about this. That's why I tested it without the scalarSemiImplicitSource and then the reported sources from scalarCodedSource is zero.



Any ideas? I also looked at the code and couldn't find any difference (regarding the sign) between scalarCoded and scalarSemiImplicit. Maybe some C/C++ expert could analyse this ;-)
user is offline   Reply With Quote

Old   August 30, 2021, 13:01
Default
  #4
New Member
 
Zhen WANG
Join Date: Jul 2021
Posts: 4
Rep Power: 5
zhenFoam is on a distinguished road
Hello, everyone

I'm stuck with the same problem. Can someone please explain?

1. why sources in scalarCodedSources must be negative?

2. why sources in scalarCodedSources always multiply by voluMe V[i] ?
zhenFoam is offline   Reply With Quote

Old   September 3, 2021, 09:24
Default
  #5
Senior Member
 
René Thibault
Join Date: Dec 2019
Location: Canada
Posts: 114
Rep Power: 7
Tibo99 is on a distinguished road
Hi,

This maybe could answer your question #2 (see picture in attachment).

I don't have the answer for your 1st question though. I encounter the same question and don't have the answer yet.

If someone can answer this one, it would be appreciated.

Best Regards,
Attached Images
File Type: png FVM_Sp.png (125.9 KB, 89 views)
Tibo99 is offline   Reply With Quote

Old   September 3, 2021, 09:59
Default
  #6
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
the answer to queston 2 is that if you discretize a source term in a fine volume framework you integrate it over the cell volume. For a source term which is constant in the volume (this is the usual assumption made) you have to multiply it by the cell volume
SHUBHAM9595 likes this.
mAlletto is offline   Reply With Quote

Old   September 3, 2021, 10:53
Default
  #7
New Member
 
Zhen WANG
Join Date: Jul 2021
Posts: 4
Rep Power: 5
zhenFoam is on a distinguished road
I got it! Great thanks for your reply @Tibo99, @mAlletto

Could somebody explain the queston 2: why sources in scalarCodedSources must be negative?
zhenFoam is offline   Reply With Quote

Old   September 3, 2021, 11:02
Default
  #8
Senior Member
 
René Thibault
Join Date: Dec 2019
Location: Canada
Posts: 114
Rep Power: 7
Tibo99 is on a distinguished road
You mean question 1?
Tibo99 is offline   Reply With Quote

Old   September 3, 2021, 20:28
Default
  #9
New Member
 
Zhen WANG
Join Date: Jul 2021
Posts: 4
Rep Power: 5
zhenFoam is on a distinguished road
Yes, I mean question 1. Sorry for the type error.
zhenFoam is offline   Reply With Quote

Old   September 4, 2021, 04:44
Default
  #10
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
Can you formulate your question a bit more clearly?
mAlletto is offline   Reply With Quote

Old   March 10, 2023, 07:06
Default
  #11
Senior Member
 
Dongyue Li
Join Date: Jun 2012
Location: Beijing, China
Posts: 849
Rep Power: 18
sharonyue is on a distinguished road
I run into this problem today. I did some research. I think its because of the following:

Code:
code.template<class Type>
Foam::tmp<Foam::fvMatrix<Type>> Foam::operator==
(
    const fvMatrix<Type>& A,
    const fvMatrix<Type>& B
)
{
    checkMethod(A, B, "==");
    return (A - B);
}
ShaneheSSSS likes this.
__________________
My OpenFOAM algorithm website: http://dyfluid.com
By far the largest Chinese CFD-based forum: http://www.cfd-china.com/category/6/openfoam
We provide lots of clusters to Chinese customers, and we are considering to do business overseas: http://dyfluid.com/DMCmodel.html
sharonyue 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
Howto use scalarCodedSource in fvOptions hanness OpenFOAM Running, Solving & CFD 61 November 18, 2022 13:11
scalarCodedSource fvOptions example moving heat source superkelle OpenFOAM Running, Solving & CFD 1 March 4, 2021 16:59
Configuration of boundary conditions and fvOptions file Raza Javed OpenFOAM Running, Solving & CFD 16 May 3, 2019 17:35
[ICEM] ICEM wind tunnel sign panel mesh tigerdroppings ANSYS Meshing & Geometry 5 July 30, 2018 14:28
reading in a field into fvOptions with type: scalarCodedSource Ali Blues OpenFOAM Programming & Development 4 June 7, 2018 11:25


All times are GMT -4. The time now is 19:20.