CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

A simple question about adding Div and Grad of a source term to the momentum equation

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By adrin

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 22, 2016, 09:02
Default A simple question about adding Div and Grad of a source term to the momentum equation
  #1
New Member
 
Adkar
Join Date: Apr 2015
Posts: 18
Rep Power: 11
adkar is on a distinguished road
Hello foamers, I have a simple question regarding writing equations in OpenFoam. Could anybody please help me understand this?

I would like to write an equation like the following where I have to add div A and grad A to U equation. Here, A is set in boundary condition.

But when I solve this Equation, it gives me the same result as momentum equation without the addition of these two terms.
Here div (constant1, A) - grad (A) acts something like opposing force.

Do I have use fvc::Su () or fvc:: Sp ()?
like fvc::Su(fvc::div(constant1, A) - fvc::grad(A) )
Or am I missing something very basic?

I am not sure how to write this piece of code.

Please see the following code:

****************************************:
fvVectorMatrix UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
- fvm::laplacian(nu, U)
);

solve(UEqn == -fvc::grad(p) + fvc::div(constant1, A) - fvc::grad(A);

Then goes the Piso loop to couple p and U without A getting involved.

********************************************

Thank you in advance
adkar is offline   Reply With Quote

Old   May 23, 2016, 02:37
Default
  #2
New Member
 
Adkar
Join Date: Apr 2015
Posts: 18
Rep Power: 11
adkar is on a distinguished road
Could anybody please help??
adkar is offline   Reply With Quote

Old   May 23, 2016, 03:24
Default
  #3
Senior Member
 
adrin
Join Date: Mar 2009
Posts: 115
Rep Power: 17
adrin is on a distinguished road
I don't know much about openfoam, neither is it obvious what you're trying to achieve. But, I have a more fundamental question/concern regarding what you're trying to do.

It's possible openfoam's objects have certain (unusual) overloading options, but from equation -fvc::grad(p) + fvc::div(constant1, A) - fvc::grad(A); I can only suggest that you consider the accuracy of your formulation first, because:

grad(p) is a vector, and if A is a vector then div(A) is a scalar and grad(A) is a tensor. If A is a tensor then div(A) would be a vector but grad(A) would still not be correct. So, again, unless openfoam's objects have certain optional capabilities that allow one to do poor math you have a serious rank mismatch, both physically and mathematically.

adrin
abhi084 likes this.
adrin is offline   Reply With Quote

Old   May 23, 2016, 07:23
Default
  #4
New Member
 
Adkar
Join Date: Apr 2015
Posts: 18
Rep Power: 11
adkar is on a distinguished road
Quote:
Originally Posted by adrin View Post
I don't know much about openfoam, neither is it obvious what you're trying to achieve. But, I have a more fundamental question/concern regarding what you're trying to do.

It's possible openfoam's objects have certain (unusual) overloading options, but from equation -fvc::grad(p) + fvc::div(constant1, A) - fvc::grad(A); I can only suggest that you consider the accuracy of your formulation first, because:

grad(p) is a vector, and if A is a vector then div(A) is a scalar and grad(A) is a tensor. If A is a tensor then div(A) would be a vector but grad(A) would still not be correct. So, again, unless openfoam's objects have certain optional capabilities that allow one to do poor math you have a serious rank mismatch, both physically and mathematically.

adrin
First of all, I would like to thank you Adrin for taking your time in answering my question. I make a mistake in generalizing the terms as A when I pasted the piece of code thinking it would be harder to explain, but it ruined the meaning of my question.

The actual code is the following from mhdFoam solver.
Could you please be kind enough for having a look at it one more time?

B is a vector used in the boundary condition. Eg. (0 20 0)


My problem is that when I remove the B-Piso loop part, the solver will not calculate the effect of the extra terms in the momentum equation.


Am I missing something?
Please help. Any help is appreciated.
Thank you very much.

Code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "fvCFD.H"
#include "OSspecific.H"

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

int main(int argc, char *argv[])
{
    #include "setRootCase.H"

    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"
    #include "initContinuityErrs.H"

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

    Info<< nl << "Starting time loop" << endl;

    while (runTime.loop())
    {
        #include "readPISOControls.H"
        #include "readBPISOControls.H"

        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "CourantNo.H"

        {
            fvVectorMatrix UEqn
            (
                fvm::ddt(U)
              + fvm::div(phi, U)
              - fvc::div(phiB, 2.0*DBU*B)     //Extra term//
              - fvm::laplacian(nu, U)
              + fvc::grad(DBU*magSqr(B))  //Extra term//
            );

            solve(UEqn == -fvc::grad(p));


            // --- PISO loop

            for (int corr=0; corr<nCorr; corr++)
            {
                volScalarField rAU(1.0/UEqn.A());
                volVectorField HbyA("HbyA", U);
                HbyA = rAU*UEqn.H();

                surfaceScalarField phiHbyA
                (
                    "phiHbyA",
                    (fvc::interpolate(HbyA) & mesh.Sf())
                  + fvc::ddtPhiCorr(rAU, U, phi)
                );

                for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
                {
                    fvScalarMatrix pEqn
                    (
                        fvm::laplacian(rAU, p) == fvc::div(phiHbyA)
                    );

                    pEqn.setReference(pRefCell, pRefValue);
                    pEqn.solve();

                    if (nonOrth == nNonOrthCorr)
                    {
                        phi = phiHbyA - pEqn.flux();
                    }
                }

                #include "continuityErrs.H"

                U = HbyA - rAU*fvc::grad(p);
                U.correctBoundaryConditions();
            }
        }

/*
        // --- B-PISO loop                                       /////// I tried to remove this part of B-PISO loop since I would only need the first 
                                                                      /////// equation and the B-Piso loop part would take too much time for calculation 
                                                                      ///////and its effect  is very less. B is given by boundary condition.

        for (int Bcorr=0; Bcorr<nBcorr; Bcorr++)
        {
            fvVectorMatrix BEqn
            (
                fvm::ddt(B)
              + fvm::div(phi, B)
              - fvc::div(phiB, U)
              - fvm::laplacian(DB, B)
            );

            BEqn.solve();

            volScalarField rBA(1.0/BEqn.A());

            phiB = (fvc::interpolate(B) & mesh.Sf())
                + fvc::ddtPhiCorr(rBA, B, phiB);

            fvScalarMatrix pBEqn
            (
                fvm::laplacian(rBA, pB) == fvc::div(phiB)
            );
            pBEqn.solve();

            phiB -= pBEqn.flux();

            #include "magneticFieldErr.H"
        }

        runTime.write();
    }
    */

    Info<< "End\n" << endl;

    return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
adkar is offline   Reply With Quote

Old   May 23, 2016, 13:15
Default
  #5
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,768
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by adkar View Post
Here, A is set in boundary condition.

what do you mean?
FMDenaro is offline   Reply With Quote

Old   May 23, 2016, 17:31
Default
  #6
Senior Member
 
adrin
Join Date: Mar 2009
Posts: 115
Rep Power: 17
adrin is on a distinguished road
As I mentioned earlier, I'm not familiar enough with openfoam to be of help there. But there is actually an openfoam-specific forum on cfd-online, which I strongly recommend you post your question(s) to. I'm sure openfoam has its own user forum as well, so you're strongly recommended to try them as well

adrin
adrin 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
Source term in the compressible momentum equation dduque OpenFOAM Programming & Development 2 April 10, 2015 04:58


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