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/)
-   -   Howto use scalarCodedSource in fvOptions (https://www.cfd-online.com/Forums/openfoam-solving/123670-howto-use-scalarcodedsource-fvoptions.html)

hanness September 18, 2013 08:59

Howto use scalarCodedSource in fvOptions
 
Hi,

currently I'm struggling with setting up a volumetric source. In my case I would like to add a volumetric heat source for a given cellSet and run the simulation with the buoyantBoussinesqSimpleFoam solver, later with the respective Pimple solver.
I tried creating a fvOptions file but unfortunately I don't really know what to put where... I adapted the below code from the CodedSource.H and now my question is where can I put the source term and in which form?
Code:

mySource
{
    type            scalarCodedSource;
    active          on;
    selectionMode  cellSet;
    cellSet        myCellSet;
    rampCoeffs      {};
    scalarCodedSourceCoeffs
    {
        fieldNames      (T);
        redirectType    ramp;
        codeCorrect
        #{
            Pout<< "**codeCorrect**" << endl;
        #};
        codeAddSup
        #{
            Pout<< "**codeAddSup**" << endl;
        #};
        codeSetValue
        #{
            Pout<< "**codeSetValue**" << endl;
        #};
        code
        #{
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }
}

Moreover, I see a general problem with this approach because I don't actually want to set a source for the temperature but for the heat (I know the value in terms of W/m³) and the Boussinesq-solvers solve a T-equation and not a h/e-equation.
Does anybody have any suggestions?

Thanks a lot
Hannes

rbaud November 29, 2013 07:49

Hi Hanness,

I'm interesting in your case, do you finally work out how to tackle your problem?

(i.e volumetric "heat source" in buoyantBoussinesqSimple/PimpleFoam)

Why are you trying with a codedSource, an explicit or semi-implicit should be able to do the job, shouldn't it?

I'm currently able to add a source of "temperature", (i.e I set a value with an explicitSource and the temperature raise up in my selected region) but I'm struggling to understand which amount of heat I'm setting in my model.

Is it wrong to try to link it to a proper heat load? (as we are solving only temperature?)

I'm currently trying the same basic "testing" than in this post:
http://www.cfd-online.com/Forums/ope...implefoam.html

And it doesn't make sense. (does the source's unit is really in K/s? --> seems ok for me regarding the equation i.e homogeneous with the dT/dt)

Thanks for sharing any hints,
R

hanness December 6, 2013 04:25

Hi R,

Eventually I got it working. I don't know whether it is the best approach but it works for me:

Code:

heatSource
{
    type            scalarSemiImplicitSource;
    active          true;
    selectionMode  cellZone;
    cellZone        heatSourceCells;
    scalarSemiImplicitSourceCoeffs
    {
        volumeMode      specific;
        injectionRateSuSp
        {
            T          (0.1 0); //DT = PHI''' / (rho * cp)
        }
    }
}

Maybe my comment behind the source term might help you to calculate the correct value for DT?

Regards,
Hannes

rbaud December 9, 2013 10:23

volumetric heat source in TEqn, dimension understanding
 
1 Attachment(s)
Hi Hannes,

Many thanks for your reply,
I use the same functionality as you to get it run (well), (i.e. semiimplicitsource)

I've took the week end to sleep on it and reach the following:

I like the idea of your: Q/(rho*cp) = Ts (1)
It fits with the TEqn solved, which is, I think an energy equation divided by rho*cp, considered as constant.
With:
Ts : source of temperature (0.1 in your example).
Q : heat source
Is that correct with your notation, I try to avoid any confusion with your PHI'''.

I’m still kind of struggle with the dimension of all of this.
Based on the attached small test case (air flow in a duct with a heat source in the middle of the duct.), I get the relation:
Ts = phi*DT
With:
phi : (openfoam calculated) flow (m3/s as we have an incompressible solver)???
DT variation of temperature along the duct (K)

Coupled with the (1), it fits with the classic Q=phi*rho*cp*DT.

I could stop there and be happy but 2 questions remained:
- Which value are you using for your rho and cp, as in the transport property we don't set them explicitly but hidden under the Pr and nu. The solver probably don't use rho and cp at all, so I'm not confident with this step. (do you just use the value which fit the model environment, without any link with the model?)

- This approach leads for the Ts a dimension in m3.K/s where I think K/s is more correct, regarding the TEqn. I guess somewhere the source module link it to the volume to reduce it in K/s. ???

(I’m aware of the absolute/specific functionality, and I’ve understand what is doing in the fact but I’ve not fully understand the code), and so can’t explain my dimension issue..

I hope my post is clear,
I’m probably doing a mistake somewhere or missing something, certainly trivial… :(
Thanks for any reply,
Remi

yanxiang March 20, 2014 12:59

Hi Hannes,

Thanks for the comments first of all.

It looks like "specific", instead of "absolute", is required for this to work properly. However, it is kind of confusing to me when it is named "specific" and "absolute". To me, it sounds more like "intensive" property versus "extensive" because when I calculated the source for T, I didn't really have a m^3 in the denominator.

yanxiang

zfaraday May 6, 2014 14:36

Volumetric heat source (W/m³)
 
Hello everybody!

I'm aware that this thread is maybe dead by now but I have a quick question related to what it has been said here. I hope that someone can answer me.

My case is that I have to define a volumetric heat source in chtMultiRegionSimpleFoam in a solid region defined as, say, heatSource. The approach I thought about is similar to what suggested hanness but I don't want to define a "source of temperature" (K) but a "source of heat" (W/m³). I have tried the following fvOptions settings to do so:

Code:

heatSource
{
    type            scalarSemiImplicitSource;
    active          true;
    selectionMode  all;

    scalarSemiImplicitSourceCoeffs
    {
        volumeMode      specific;//absolute;
        injectionRateSuSp
        {
            h          (X Y);
        }
    }
}

I have tried a few combinations of Su-Sp coefficients but I don't really understand the meaning and use of them. What values should I give to the coeffs if I want to set up a source of, for instance, 50 W/m³?

Another question I have is if it's correct or not to use the h variable (enthalpy, if I am not wrong) to create a heat source in a solid region.

I have also made some other attempts using T instead of h but I noticed that nothing happened, like if no source existed. But, according to what I read in this topic above, it shoud have been because I used absolute mode instead of specific. Am I right?

Thanks in advance. Any suggestion or hint will be welcome!


Alex

massive_turbulence May 6, 2014 20:33

Quote:


My case is that I have to define a volumetric heat source in chtMultiRegionSimpleFoam in a solid region defined as, say, heatSource. The approach I thought about is similar to what suggested hanness but I don't want to define a "source of temperature" (K) but a "source of heat" (W/m³). I have tried the following fvOptions settings to do so:
I'm almost positive this would work with the chtMultiRegionSimpleFoam using the heat flux in W/m³.

Code:

        type            compressible::turbulentHeatFluxTemperature;
        heatSource      flux;
        q              uniform 1000;
        alphaEff        kappaEff;
        K              basicThermo;
        Cp              uniform 1000;
        value          uniform 273.5;//set initially?
        KName            K;

I'm assuming that you know the initial temperature of your entire system which means in this case it would be set to 273.5k.

zfaraday May 7, 2014 12:37

Quote:

Originally Posted by massive_turbulence (Post 490221)
I'm almost positive this would work with the chtMultiRegionSimpleFoam using the heat flux in W/m³.

Thanks for your quick replay Andrew!

Yes, I guess it should work at least this configuration of the fvOptions file makes sense to me. But my hesitation is about the values I have to set as Su-Sp coefficients (assuming the configuration is ok) to define the heat generation (for example, 50 W/m³) inside the region.

Regards

Alex

a19910112a December 1, 2014 15:07

Hi,Alex.
Did you figure out what X and Y stand for? I know that they basically describe a source as s=X+Yx where the small x is coordinate. Is that right?

Thanks
Zech

alexeym December 1, 2014 15:32

Hi,

you can find an answer in the SemiImplicitSource.H:

Code:

Description
    Semi-implicit source, described using an input dictionary.  The injection
    rate coefficients are specified as pairs of Su-Sp coefficients, i.e.

        \f[
            S(x) = S_u + S_p x
        \f]

    where
    \vartable
        S(x)    | net source for field 'x'
        S_u    | explicit source contribution
        S_p    | linearised implicit contribution
    \endvartable

or if you prefer code, SemiImplicitSource.C

Code:

    UIndirectList<Type>(Su, cells_) = injectionRate_[fieldI].first()/VDash_;
   
    DimensionedField<scalar, volMesh> Sp
    (
        IOobject
        (
            name_ + fieldNames_[fieldI] + "Sp",
            mesh_.time().timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        mesh_,
        dimensioned<scalar>
        (
            "zero",
            Su.dimensions()/psi.dimensions(),
            0.0
        ),
        false
    );

    UIndirectList<scalar>(Sp, cells_) = injectionRate_[fieldI].second()/VDash_;

    eqn += Su + fvm::SuSp(Sp, psi);

I.e. x is a field for which source is calculated.

a19910112a December 2, 2014 05:50

yeah, thanks for answering. I have looked at that some time ago. But that doesn't really make sense to me. As I don't really know how to express my heat resource in an implicit and explicit form.
1. Any suggestions on where can I learn about that?
2. What I want to define is a volumetric heat generation rate that changes along x axis, rather than with a field (heat generation rate q"'=cos (x) where x is the system coordinate). Any idea on how to define that?
3. A more challenging question is: what if the source is not even a regular function. It is just a bunch of random numbers. Say a table like
when x=1 q"'=4
when x=2 q"'=7
when x=3 q"'=1 ..... irregular (x is still system coordinate and as assume the q"' doesn't change along y and z direction. )

wishes
Zech

alexeym December 2, 2014 06:01

Hi,

1. Sources. Tutorial. Google.

2. Lots of. Usually at this point people suggest swak4Foam. Or you can modify solver. Or you can take SemiImplicitSource and modify it.

3. In fvOptions file.

a19910112a December 2, 2014 06:40

1. that means nothing. every body doing Foam knows.... :)
3. can you say something more? How? If you can do this, question 2 is not even question !!!

alexeym December 2, 2014 08:24

Well,

If you need someone to Google for you, there is http://www.esi-cfd.com/content/blogcategory/99/128/, you know.

For your case you can take a look at CodedSource. In this case you can just use C++ to extract coordinates from field and to calculate your source term.

a19910112a December 3, 2014 06:36

Thank again for your reply.

Yes,I'm looking at the codedSource. That is exactly what this thread start with discussing, isn't it? Do you have any examples of this? If you know how to use it can you post it here, which, I believe, will be helpful for a lot of people.
I'm asking because I have exhausted the searching result from Google without finding some answers and could not understand what the source code is doing as many new comers to openFoam cannot.

alexeym December 3, 2014 10:12

2 Attachment(s)
Guess, you're right. Google search leads to the first message of this thread. There were other links though with less information.

So here's an example of the codedSource:

Code:

harmonic
{
    type            scalarCodedSource;

    active          true;
    selectionMode  all;

    scalarCodedSourceCoeffs
    {
        fieldNames      (T);
        redirectType    sourceTime;

        codeInclude
        #{

        #};

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

        codeAddSup
        #{
            const Time& time = mesh().time();
            const scalarField& V = mesh_.V();
            const vectorField& C = mesh_.C();
            scalarField& TSource = eqn.source();
            forAll(C, i)
            {
                TSource[i] -= 10*sin(6.28*C[i].x())*V[i];
            }
            Pout << "***codeAddSup***" << endl;
        #};

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

        // Dummy entry. Make dependent on above to trigger recompilation
        code
        #{
            $codeInclude
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }

    sourceTimeCoeffs
    {
        // Dummy entry
    }
}

As the configuration is more or less taken from CodedSource.H file (well, sin addition is mine), I don't know what questions this will arise. So I skip commenting the configuration and wait till further questions.

Also I've attached archive of the case (hotRoom case from buoyantBoussinesqSimpleFoam tutorial with removed gravitation (therefore no convection) and suppressed heat diffusivity) and a screen shot of temperature distribution.

a19910112a December 3, 2014 12:18

Thank you so much for sharing the example!

I haven't get a chance to run the case yet, but it might be helpful anyway to explain what kind of heat source you have defined here. what it depends on? I mean I see it depends on C[i], V[i] and x(). What are they? I roughly know C and V are values extract from mesh, but not quite sure what are they. And x() is not even defined in advance, is it recognised as the system coordinate by default?

Comparing with the example in the codedSource.H file, you kept the codeCorrect and codeSetValue as they were. I assume their functions are irrelevant to the source your are defining here. If you happen to know, can you please say something on what they can be used to define?

alexeym December 4, 2014 03:30

Well, at this point your answers for the questions are can be easily found in documentation (http://openfoam.org/docs/cpp/). I will answer some of them, the rest - it is up to you to look up.

You've deduced that V and C are properties of the mesh, so you enter mesh in search dialog in documentation (well, I will just enter fvMesh), click on fvMesh in drop-down menu and go to fvMesh documentation. There we'll find that V is a list of cell volumes, C is a list of cell centers (or centres if you prefer). Also from documentation you've learned that C is a list of vectors. Enter vector in search box, click on the link in the drop-down list, et voilà, x is a method of vector class and it returns x-component of the vector. As there's no convection, no diffusion, and no heat exchange with outer space, strange steady state with negative temperatures reached in 44 iterations.

As it was just a test, I've taken mesh with sizes 2x1x1, and source term in T-equation that is proportional to sin(2*pi*x), so in x-direction we have 2 periods (and there are two periods on temperature field).

As to other methods. Take a look at TEqn.H, relevant part is:

Code:

...
    fvScalarMatrix TEqn
    (
        fvm::div(phi, T)
      - fvm::laplacian(alphaEff, T)
    ==
        fvOptions(T)
    );

    TEqn.relax();

    fvOptions.constrain(TEqn);

    TEqn.solve();

    fvOptions.correct(T);
...

then take a look at solver's log:

Code:

DILUPBiCG:  Solving for Ux, Initial residual = 0, Final residual = 0, No Iterations 0
DILUPBiCG:  Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
DILUPBiCG:  Solving for Uz, Initial residual = 0, Final residual = 0, No Iterations 0
***codeAddSup***
**codeSetValue**
DILUPBiCG:  Solving for T, Initial residual = 0.331723, Final residual = 0.00127055, No Iterations 1
**codeCorrect**
DICPCG:  Solving for p_rgh, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 0, global = 0, cumulative = 0
ExecutionTime = 0.36 s  ClockTime = 7 s

So, AddSup is called during construction of the linear system matrix and it is just a source term in temperature equation, SetValue is called before solution of the linear system and can be imagined as a constraint like BC (well, it is called fvOptions.constrain(TEqn)), and finally correct is called after solution of the linear system and can be used to modify T field (well, in fact you can modify almost anything as you've got access to the volScalarField, from where you can get mesh reference, and then other fields, runtime object etc). Surely the same conclusions can be achieved by analysing of the sources of fvOptions framework.

a19910112a December 5, 2014 06:27

Thanks for your answer Alex. I have run your case and don't understand the flowing things:
1. You have set it to stop running after steady state is arrived (44s) somewhere? I wanted to see what happens as time goes, so I set it to run between 0-1000s in the controlDict. But it still runs from 0-44? What is the problem?

2. Because I cannot play with time, I played with the function in the codeAddSup part. I'm so sorry. Although you have told me so clear what V C x are, I'm still not quite sure about what how it defines the source.
Quote:

forAll(C, i)
{
TSource[i] -= 10*sin(6.28*C[i].x())*V[i];
}
a. One of the problem is, what is the value of C ? ‘C is a list of centers’, what is the value of it? I tried to look at the link you gave me on cpp. But I could not even tell ‘C is a list of centers’ from the page.

b. V is the volume, then the quantity 10*sin(6.28*C[i].x()) gives should be q’’’/(rho*Cp). Is that right?

3. As I cannot figure out the previous questions. I thought that I at least know the example you gave defined a temperature source with a period of 1. So, I applied the source into one that I’m familiar with. That is the planeWall2D case. I changed the bottom air with a heat generation solid, and it worked fine as a constant source. I replaced the source with the 1-period source in your example. I changed the proportion to observe a more obvious phenomenon. But sadly, no period could be observed. I have the case uploaded here.

alexeym December 5, 2014 07:58

1 Attachment(s)
Quote:

Originally Posted by a19910112a (Post 522615)
1. You have set it to stop running after steady state is arrived (44s) somewhere? I wanted to see what happens as time goes, so I set it to run between 0-1000s in the controlDict. But it still runs from 0-44? What is the problem?

It's convergence criterion set in SIMPLE dictionary in fvSolution file. So you can set endTime to any value greater the 44, if solution converges is 44 iterations it will run for 44 iterations. Also in SIMPLE it's not time, it's iterations.

Quote:

a. One of the problem is, what is the value of C ? ‘C is a list of centers’, what is the value of it? I tried to look at the link you gave me on cpp. But I could not even tell ‘C is a list of centers’ from the page.
Just of curiosity I've clicked on the link I've posted and here's a screen shot of what I've got. To make it easier I've underlined a line you need to read. See attached image.

Quote:

b. V is the volume, then the quantity 10*sin(6.28*C[i].x()) gives should be q’’’/(rho*Cp). Is that right?
Not quite sure I've counted number of primes correctly but it should be power over rhoCp.

Concerning your case: maybe there's no period, I don't know.

EnricoA March 31, 2015 17:07

Hello alexeym,

I am trying to implement a source term for turbulent dissipation in a simulation using the standard k-epsilon model following your explanation about the scalarCodedSource. I ended up with this fvOptions file (where there is also a source for the momentum equation):

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.3.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    location    "system";
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


momentumSource
{
    type            vectorSemiImplicitSource;
    selectionMode  cellZone;
    cellZone        disk;
    active          true;

    vectorSemiImplicitSourceCoeffs
    {
        volumeMode      absolute;
        injectionRateSuSp
        {
            U          ((0 0 -180e3) 0);
        }
    }
}

dissipationSource
{
    type            scalarCodedSource;
    selectionMode  cellZone;
    cellZone        disk;
    active          true;

    scalarCodedSourceCoeffs
    {
        fieldNames      (epsilon);
        redirectType    sourceTime;

        codeInclude
        #{

        #};

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

        codeAddSup
        #{
            const Time& time = mesh().time();
            const scalarField& V = mesh_.V();
            const vectorField& C = mesh_.C();
            const scalarField& nut_ = nut();
            const vectorField& U_ = U();
            const scalarField& k_ = k();
            const scalarField& Pt = nut_*2*magSqr(symm(fvc::grad(U_)));
            scalarField& epsilonSource = eqn.source();
            forAll(C, i)
            {
                epsilonSource[i] -= 0.37*Pt[i]*Pt[i]/k_[i]*V[i];
            }
            Pout << "***codeAddSup***" << endl;
        #};

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

        // Dummy entry. Make dependent on above to trigger recompilation
        code
        #{
            $codeInclude
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }

    sourceTimeCoeffs
    {
        // Dummy entry
    }
}

// ************************************************************************* //

Apparently there are some mistakes in my file which I cannot find, because when I run the simulation the output is:

Code:

--> FOAM Warning :
From function void option::checkApplied() const
in file fvOptions/fvOption.C at line 368
Source dissipationSource defined for field epsilon but never used

Do you have any advises to give me?

Thanks

alexeym April 1, 2015 01:50

Hi,

My advice: implement your own turbulence model ;) I.e. you take k-epsilon family model, copy it, rename it, add your code.

There are certain conditions for fvOptions to work, see, for example, UEqn.H of pimpleFoam:

Code:

tmp<fvVectorMatrix> UEqn
(
    fvm::ddt(U)
  + fvm::div(phi, U)
  + turbulence->divDevReff(U)
 ==
    fvOptions(U)
);

UEqn().relax();

fvOptions.constrain(UEqn());

See all these calls to fvOptions. Now if you look at kEpsilon.C, there are no such calls.

During last workshop there was an idea of implementation of turbulence models, which use fvOptions framework. I do not know if there is any progress, for me it is still on TODO list.

sandeeprapol April 28, 2015 05:36

fvOptions heatsource in chtmultiregionsimpleFoam case in openfoam2.3.x
 
Hello everyone
I am implementing volumetric heat source in chtmultiregionsimplefoam with help of fvoptions files
in that "duration ....." and " h(.... 0)" so my problem is

1) how to convert 200 W source into enthalpy h(... 0) with help of "duration ...." in sec
2) in that "fvOptions" file "duration..." so which time put here in duration

zfaraday April 28, 2015 05:49

Quote:

Originally Posted by sandeeprapol (Post 544087)
Hello everyone
I am implementing volumetric heat source in chtmultiregionsimplefoam with help of fvoptions files
in that "duration ....." and " h(.... 0)" so my problem is

1) how to convert 200 W source into enthalpy h(... 0) with help of "duration ...." in sec
2) in that "fvOptions" file "duration..." so which time put here in duration

Hello Sandeep!

1) You don't need to convert nothing into nothing. For the case of using chtMultiRegionSimpleFoam you just have to put the thermal power value into the first place within the brackets, like that:
Code:

energySource
{
    type            scalarSemiImplicitSource;
    active          true;
    selectionMode  all;

    scalarSemiImplicitSourceCoeffs
    {
        volumeMode      absolute;//specific;//
        injectionRateSuSp
        {
            h          (q 0); //  q in [W]; or in [W/m³] if you use specific mode
        }
    }
}

2) Never used the duration field (I don't even know wether it exist) as you can see in the piece of code above.

Hope it helps.

Best regards,

Alex

alexeym April 28, 2015 06:03

@faraday

Quote:

Originally Posted by zfaraday (Post 544092)
2) Never used the duration field (I don't even know wether it exist) as you can see in the piece of code above.

In fact the field comes from base abstract fvOption and defines duration of time the option is active:

Code:

inline bool Foam::fv::option::inTimeLimits(const scalar time) const
{
    return
    (
        (timeStart_ < 0)
    ||
        (
            (mesh_.time().value() >= timeStart_)
        && (mesh_.time().value() <= (timeStart_ + duration_))
        )
    );
}

Code:

bool Foam::fv::option::isActive()
{
    if (active_ && inTimeLimits(mesh_.time().value()))
    {
        ---
        return true;
    }
    else
    {
        return false;
    }
}


zfaraday April 28, 2015 06:10

Thanks for the clarification Alexey! I didn't remember that because I never had to specify the duration of the source.

Everything must be clear now for @Sandeep.

sandeeprapol April 28, 2015 07:42

fvOptions heatsource in chtmultiregionsimpleFoam case in openfoam2.3.x
 
hello alex,
thank you for the replay , I used that syntax in fvOptions file but result showing no heat generation, it shows constant temperature

when I use my fvOptins that showing heat generation it include "duration....." of time
-------#---------------------------#-----------------------------#--------------------
heatSource
{
type scalarSemiImplicitSource;
active on;
timeStart 0.;
duration 1e3;
selectionMode cellSet;
cellSet IC1;

scalarSemiImplicitSourceCoeffs
{
// volumeMode absolute; // Values are given as <quantity>
volumeMode specific; // Values are given as <quantity>/m3

injectionRateSuSp // Semi-implicit source term S(x) = S_u + S_p x
{
h (200000 0);
}
}
}
--------------------#--------------------------------#-----------------------#------------------#---
am trying to implement 200 W/m3 volumetric heat generating source for circuit board cooling

zfaraday April 28, 2015 08:09

Well, I don't understand why my specification is not working. As per what I see you are using a cellSet as a selection mode, while I sellect all cells belonging to one region. If you just copypasted all my specification of course it's not going to work...

Another point I don't get is why you are setting a generation of 200000 when you say your generation is supposed to be of 200 W/m2... If you give a higher value than the one you need, obviously the effect will be more visual and bigger...

Regards,

Alex

Ps: excuse me if I wrote something wrong, I'm writing from my phone

sandeeprapol April 29, 2015 07:01

hello alex,
you are on the right way you see in src/fvOptios/lninclude/fvOptionListTemplates.C
at line no 135
ds = rho.dimensions()*fld.dimensions()/dimTime*dimVolume
rho * h *1/time * vol
kg/m3 * j/kg * m3 / sec
j/s
W
so here is dimTime in sec plese tell me how to implement 200 W/m3 heat generating source

zfaraday April 29, 2015 07:47

check this out!

sandeeprapol April 30, 2015 06:25

hello alex
thank you for your humble reolay
in fvoptions
volumeMode absolute; // Values are given as <quantity>
volumeMode specific; // Values are given as <quantity>/m3
what is "absolute" and "specific"
if my heat generating element is 200 W having dimension 0.2m*0.01m*0.05m
1) if I consider "absolute" then total element given value is 200 W is this correct or not?
2) if I consider "specific" then total element each cell point given value is 200 W is this correct or not?

zfaraday April 30, 2015 07:40

Dear Sandeep,

the meaning of "absolute" and "specific" is given behind "//". Then, if you consider "absolute" mode you just have to give the constant source term a value of 200. On the other hand, if you prefer to use "specific" mode you have to use a value of 200/(0.2*0.01*0.05).

That's all!

Best regards,

Alex

sandeeprapol May 4, 2015 04:49

thank you alex,
which parameter analyze in post processing.I thought that only temp of oullet, & velocity is analyze in chtmultiregionSimpleFoam and chtmultiRegionFoam please suggest me

EnricoA May 11, 2015 14:08

Hi,

I would like to follow up my previous post regarding the implementation of a source term for the turbulent dissipation rate with scalarCodedSource.
I eventually implemented my own turbulence model of the k-epsilon family. This is the main modification which takes into account the possible source term:

Code:

// Dissipation equation
tmp<fvScalarMatrix> epsEqn
(
    fvm::ddt(epsilon_)
  + fvm::div(phi_, epsilon_)
  - fvm::laplacian(DepsilonEff(), epsilon_)
 ==
    C1_*G*epsilon_/k_
  - fvm::Sp(C2_*epsilon_/k_, epsilon_)
  + fvOptions(epsilon_)
);

epsEqn().relax();
fvOptions.constrain(epsEqn());
epsEqn().boundaryManipulate(epsilon_.boundaryField());
solve(epsEqn);
fvOptions.correct(epsilon_);
bound(epsilon_, epsilonMin_);

Then I was trying to add a source of the following form in a particular region:

S = 0.37 G^2 / k

where G is the the generation of turbulent kinetic energy computed in the sandard k-epsilon model and k is the turbulent kinetic energy. In order to do this, I added the following piece of code to fvOptions:

Code:

dissipationSource
{
    type            scalarCodedSource;
    selectionMode  cellZone;
    cellZone        diss;
    active          true;

    scalarCodedSourceCoeffs
    {
        fieldNames      (epsilon);
        redirectType    sourceTime;

        codeInclude
        #{
            #include "fvCFD.H"
        #};

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

        codeAddSup
        #{
            const scalarField& V = mesh_.V();
            const vectorField& C = mesh_.C();
            const volScalarField& nut = mesh().lookupObject<volScalarField>("nut");
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            const volScalarField& k = mesh().lookupObject<volScalarField>("k");
            const volScalarField& G = nut*2*magSqr(symm(fvc::grad(U))); // as computed in the k-epsilon model
            scalarField& epsilonSource = eqn.source();
            forAll(C,i)
            {
                epsilonSource[i] -= 0.37*G[i]*G[i]/k[i];
            }
            Pout << "***codeAddSup***" << endl;
        #};

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

        // Dummy entry. Make dependent on above to trigger recompilation
        code
        #{
            $codeInclude
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }

    sourceTimeCoeffs
    {
        // Dummy entry
    }
}

When I run a simulation, the compilation of the dynamic library doesn't give errors but apparently there is something wrong with my implementation, since the results that I get don't match with the expected one.
Can you see any errors in the code?

Thanks

nimasam September 8, 2016 14:40

Dear Alex

How to set multiple discrete heat sources using scalarSemiImplicitSource ?

student666 January 3, 2017 11:24

what for solver using EEqn.C?
 
Quote:

Originally Posted by zfaraday (Post 544092)
{
type scalarSemiImplicitSource;
active true;
selectionMode all;

scalarSemiImplicitSourceCoeffs
{
volumeMode absolute;//specific;//
injectionRateSuSp
{
h (q 0); // q in [W]; or in [W/m³] if you use specific mode
}
}
}

Hi,

just a clarification for buoyantSimpleFoam.
This solver uses EEqn.C file, so you have to specify the thermal model.
In case you set the following dict for thermophysicalProperties
Code:

    {
        type heRhoThermo;
        mixture pureMixture;
        transport const;
        thermo hConst;
        equationOfState perfectGas;
        specie specie;
        energy sensibleEnthalpy;
    }

q parameter (specific) is equal to Watt only if you consider a fluid with Cp = 1kJ/(kg*K) and rho = 1 kg/m^3 as for Q= rho cp * T(1Kelvin)/1sec = 1W/m3 as h = Cp*T(1Kelvin)/1sec = 1W/kg

but if you consider a fluid with Cp = 4.186kJ/(kg*K) and rho = 1000 kg/m3, if you want to have 1W/m3 you have to set h value (q parameter [specific] ) equal to 0,000000239
Code:

q = Q = rho*Cp*T/t ==> 1/1000/4186
is it correct?

student666 January 4, 2017 17:38

1 Attachment(s)
I performed this simple test case.
3D simulation.
All patches have been set to "walls"(T=293K), but patch named "fondo" has been set to zeroGradient for T.
cellZone "c0" , at the bottom (coord z=0), has 500W power source.

laminar.

simulation performed with openFoam v4.1

run
Code:

blockMesh
topoSet
renumberMesh -overwrite
buoyantPimpleFoam > log.1

when steadyness is reached, stop running and
Code:

wallHeatFlux
you may see dissipation through patch "pareti" equal to heat (absolute) source 500W in fvOptions.

Code:

Time = 2.554868161131
Selecting thermodynamics package
{
    type            heRhoThermo;
    mixture        pureMixture;
    transport      const;
    thermo          hConst;
    equationOfState perfectGas;
    specie          specie;
    energy          sensibleEnthalpy;
}

Reading/calculating face flux field phi

Selecting turbulence model type laminar

Wall heat fluxes [W]
pareti
    convective: -497.79226
    radiative:  -0
    total:      -497.79226
fondo
    convective: 0
    radiative:  -0
    total:      0

Time = 2.9167083871732
Selecting thermodynamics package
{
    type            heRhoThermo;
    mixture        pureMixture;
    transport      const;
    thermo          hConst;
    equationOfState perfectGas;
    specie          specie;
    energy          sensibleEnthalpy;
}

Reading/calculating face flux field phi

Selecting turbulence model type laminar

Wall heat fluxes [W]
pareti
    convective: -498.87276
    radiative:  -0
    total:      -498.87276
fondo
    convective: 0
    radiative:  -0
    total:      0

Time = 3.27661601896623
Selecting thermodynamics package
{
    type            heRhoThermo;
    mixture        pureMixture;
    transport      const;
    thermo          hConst;
    equationOfState perfectGas;
    specie          specie;
    energy          sensibleEnthalpy;
}

Reading/calculating face flux field phi

Selecting turbulence model type laminar

Wall heat fluxes [W]
pareti
    convective: -499.42118
    radiative:  -0
    total:      -499.42118
fondo
    convective: 0
    radiative:  -0
    total:      0

End

Hope this can clarify any further doubt...mine too.

Regards.

ChrisBa February 14, 2017 02:37

Hello,

I'm trying to implement a volumetric source with scalarCodedSource.
At the surface the equation: q=q0 * e^(re^2/r^2)
In the depth the value q0 is described with functions.

I'm using Openfoam 4.1 and the solver buoyantBoussinesqSimpleFoam.

After calling the function I get this:
Code:

Creating finite volume options from "constant/fvOptions"



--> FOAM FATAL ERROR:
Attempt to return primitive entry ITstream : /home/cfd/OpenFOAM/cfd-4.1/run/elektronen/constant/fvOptions.heatSource.scalarCodedSourceCoeffs.codeInclude, line 31, IOstream: Version 2.0, format ASCII, line 0, OPENED, GOOD
    primitiveEntry 'codeInclude' comprises
        on line 31 the verbatim string "\
          \
        "
 as a sub-dictionary

    From function virtual const Foam::dictionary& Foam::primitiveEntry::dict() const
    in file db/dictionary/primitiveEntry/primitiveEntry.C at line 189.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::error::abort() at ??:?
#2  Foam::primitiveEntry::dict() const at primitiveEntry.C:?
#3  Foam::dictionary::substituteScopedKeyword(Foam::word const&) at ??:?
#4  Foam::entry::New(Foam::dictionary&, Foam::Istream&) at ??:?
#5  Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#6  Foam::dictionary::dictionary(Foam::fileName const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#7  Foam::dictionaryEntry::dictionaryEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#8  Foam::entry::New(Foam::dictionary&, Foam::Istream&) at ??:?
#9  Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#10  Foam::dictionary::dictionary(Foam::fileName const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#11  Foam::dictionaryEntry::dictionaryEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#12  Foam::entry::New(Foam::dictionary&, Foam::Istream&) at ??:?
#13  Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#14  Foam::dictionary::dictionary(Foam::fileName const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#15  Foam::dictionaryEntry::dictionaryEntry(Foam::keyType const&, Foam::dictionary const&, Foam::Istream&) at ??:?
#16  Foam::entry::New(Foam::dictionary&, Foam::Istream&) at ??:?
#17  Foam::dictionary::read(Foam::Istream&, bool) at ??:?
#18  Foam::operator>>(Foam::Istream&, Foam::dictionary&) at ??:?
#19  Foam::IOdictionary::readFile(bool) at ??:?
#20  Foam::IOdictionary::IOdictionary(Foam::IOobject const&) at ??:?
#21  Foam::fv::options::options(Foam::fvMesh const&) at ??:?
#22  Foam::fv::options::New(Foam::fvMesh const&) at ??:?
#23  ? at ??:?
#24  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#25  ? at ??:?
Abgebrochen (Speicherabzug geschrieben)


My fvOption-file looks like this:

Code:

heatSource
{
    type            scalarCodedSource;

    active          true;
    selectionMode  all;

    scalarCodedSourceCoeffs
    {
        fieldNames      (T);
        name            sourceTime;

        codeInclude
        #{
         
        #};

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

        codeAddSup
        #{
            scalarField& TSource = eqn.source();


            //Values for checking the equations
            const scalar power = 1000;
            const scalar Radius = 0.5;
            const scalar rho = 1000;
            const scalar Cp = 4.19;
            const scalar xCenter = 3;
            const scalar yCenter = 0.01;
            const scalar zCenter = 2;           
           
            // Equations

            // -Face centers
            const List<point>& cf = p.Cf();
            const scalar xCF = cf[c][0];
            const scalar XF = xCenter - xCF;
            const scalar check+ = xCenter + Radius;
            const scalar check- = xCenter - Radius;

            if ((xCF < check+) && (xCF > check-))
            {
                const scalar r2 = XF * XF;
                const scalar re2 = Radius * Radius;
                const scalar factor = r2/re2;
                const scalar pre = exp(factor);
                const scalar qfa_ [c] = power * exp;
                const scalar TzuF_ [c] = (1/(rho*Cp))*qfa 
            }
            else
            {
                const scalar qfa_ [c] = 0;
            };
           
            // -Depth centers or cell centers
           
           
           
           
           
                     
       

            TSource -= Tzuf;
            Pout << "***codeAddSup***" << endl;

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

        // Dummy entry. Make dependent on above to trigger recompilation
        code
        {
          $codeInclude
          $codeCorrect
          $codeAddSup
          $codeSetValue
        };
    }

    sourceTimeCoeffs
    {
        // Dummy entry
    }
}

Maybe somebody can help me.

regards
Chris

hanness February 14, 2017 04:53

Hi Chris,

I'm not too much into the scalarCodedSource fvOptions but just by looking at the error message it tells you that on line 31 of your code something is going wrong. More precisely it is in the section codeInclude (I suppose that is line 31 when looking at the entiere fvOptions file including its header.
This section supposedly must be filled and cannot be left blank. As I'm not familiar with this tool I can't help you any further but maybe it helps.
Regards
Hannes

ChrisBa February 14, 2017 05:42

Thanks for your reply.
I look into this.


All times are GMT -4. The time now is 11:33.