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

scalarCodedSource fvOptions example moving heat source

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 6 Post By superkelle

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 28, 2020, 07:18
Post scalarCodedSource fvOptions example moving heat source
  #1
Member
 
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 6
superkelle is on a distinguished road
Hi,
I had some trouble to implement a scalarCodedSource in fvOptions for rhoPimpleFoam. But I got it working and I want to share it with you, maybe it is helpful for someone, since I read some other posts that had trouble with it. Here is my example for the sqareBendLiq tutorial ( /rhoPimpleFoamTutorials/RAS/squareBendLiq/ ) , you can just create an fvOptions file in system directory and run rhoPimpleFoam after blockMesh.

It will create an sinodial moving heat source upward the stream. It has no physical meaning and was just for testing. Have fun, I will attach a gif.

https://media.giphy.com/media/lrc8Xa...G8aE/giphy.gif

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  7
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
energySource
{
    type            scalarCodedSource;    //scalarSemiImplicitSource
    active          true; //for activation either don't use any "active" or use value "true", for deactivation "false"
    name            sourceTime;

    scalarCodedSourceCoeffs
    {
        fields          (e);

        fieldNames        (e);

        name            sourceTime;
       
        selectionMode   all;

        codeInclude
        #{

        #};

        codeCorrect
        #{
        #};
       
        codeAddSup
        #{
            const Time& time = mesh().time();
           
           
           
            const scalarField& V = mesh_.V();
           
            const vectorField& C = mesh_.C();
                       
            const scalar endTime = 0.5;
                       
            const scalar xt = -0.45 + time.value()*2;

            const scalar yt = -0.05+0.01*sin(time.value()*100.0);
           
            const scalar rt = 0.00005;
           
           
            //const scalar  zt = -0.05;
                       
            scalarField& heSource = eqn.source();

            forAll (C,i)
            {   
                const scalar & Cx =C[i].component(0);
                const scalar & Cy =C[i].component(1);
                const scalar & Cz =C[i].component(2);
               
                if ( (sqr(Cx-xt) + sqr(Cy-yt) ) <= rt && time.value() < endTime)
                {   
                    heSource[i] = - 2e10 * V[i];
                }
               
                /*
                if (Cx <= xt && Cy >= 0.8*yt && Cy <= 1.2*yt && time.value() < endTime)
                {   
                    heSource[i] = - 5e9 * V[i];
                }
                */
               
           
            }
        #};
       
        codeSetValue
        #{
        #};
       
        code
        #{
            $codeInclude
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
   
    }

    sourceTimeCoeffs
    {
       selectionMode   all;
    }

//************************************************************************** //
Attached Images
File Type: jpg resized.jpg (4.0 KB, 85 views)

Last edited by superkelle; May 28, 2020 at 07:22. Reason: gif was to big, added link
superkelle is offline   Reply With Quote

Old   March 4, 2021, 16:59
Default
  #2
Member
 
Jonathan Wells
Join Date: Oct 2020
Location: Indiana
Posts: 44
Rep Power: 6
jdw135 is on a distinguished road
Hi,

I am trying to get a scalarCodedSource working as well, but I am getting a warning during runtime that says "Source ICM defined for field qq but never used". Below is my fvOptions code. I would greatly appreciate any help!

Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      fvOptions;
}

energySource
    {
        type            scalarCodedSource;
        name            sourceTime;

        active          yes;

        scalarCodedSourceCoeffs
        {
            selectionMode   all;
            fields          (qq);

            codeInclude
            #{
            #};

            codeCorrect
            #{
                Pout<< "**codeCorrect**" << endl;
            #};

            codeAddSup
            #{
                const Time& time = mesh().time();
                const volScalarField& rhoS = mesh_.lookupObject<volScalarField>("rho");
                const volVectorField& uS = mesh_.lookupObject<volVectorField>("U");
                const volScalarField& pS = mesh_.lookupObject<volScalarField>("p");
                const vectorField& C = mesh_.C();
                const scalarField& V = mesh_.V();
                scalarField& SoS = sqrt(1.4*(pS/rhoS));
                scalarField& mach = uS/SoS;
                scalarField& rhoQ = (pS*(1-(mach*mach))1005)/(1.4*(mach*mach)*287.058);
                scalarField& qq = eqn.source();
                qq -= rhoQ*V;
            #};

            codeConstrain
            #{
                Pout<< "**codeConstrain**" << endl;
            #};

            // Dummy entry. Make dependent on above to trigger recompilation
            code
            #{
                $codeInclude
                $codeCorrect
                $codeAddSup
                $codeConstrain
            #};
    }
        sourceTimeCoeffs
        {
            // Dummy entry
        }
    }
jdw135 is offline   Reply With Quote

Reply

Tags
fvoptions, moving source, scalarcodedsource


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] swak4foam for OpenFOAM 4.0 mnikku OpenFOAM Community Contributions 80 May 17, 2022 09:06
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 10:07
OpenFOAM without MPI kokizzu OpenFOAM Installation 4 May 26, 2014 10:17
Moving Heat Source on a CV Tomster0815 OpenFOAM Running, Solving & CFD 8 November 3, 2013 05:10
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 11:57


All times are GMT -4. The time now is 05:41.