CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Need of Help: HowTo designate explicitely unknown variables of a question? (https://www.cfd-online.com/Forums/openfoam-programming-development/168765-need-help-howto-designate-explicitely-unknown-variables-question.html)

Democritus March 28, 2016 23:53

Solving Helmholtz Equations, HowTo calculate two fields' difference?
 
Hi~ Dear Foamers,

I'm a PhD students in Huazhong University of Science and Technology and I am studying OpenFOAM for simulating the acoustic radiation force in microfludic chips.

My question:
1.In a fvMatrix class, how user explicite point out the unknown variables which is needed to be solved? Actually in all the documents, no one explicitly point out the "unknown variables" in a fvMatrix, so what is the mechanism OpenFOAM identify the "known variables" and "unknown variables" in a equation( fvMatrix ).

Update: Thanks for akidess's answer!
fvm operations comprise the unknown variable and it admits only one unknown variable;
fvc operations comprise the already known variables

2. Is there a way to have explicte calculate two fields' difference as one iteration's residual?

These two question is too abstract and I would like to objectify them in my studying case:
I would like to solve the helmholtz equation as following:
Code:

laplacian(P) - sqr(k)*P == 0
P is the pression and k is the wave number.
the pression and k is all complex number, so I decide to seperate them as follwing:
Code:

surfaceScalarField p_Re;
surfaceScalarField p_Im;
surfaceScalarField kSq_Re; // constant already known
surfaceScalarField kSq_Im; // constant already known

and the equations is derivated as follwing form:
Code:

fvScalarMatrix pReEqn
(
    fvm::laplacian(p_Re)
    +
    fvm::Sp(kSq_Re, p_Re)
    -
    fvc::Sp(kSq_Im, p_Im)
);

fvScalarMatrix pImEqn
(
        fvm::laplacian(p_Im)
        +
        fvc::Sp(kSq_Im, p_Re)
        +
        fvm::Sp(kSq_Re, p_Im)
);

My idea is solving this coupled equation with the iteration method:
1. the first equation is solved in order to get the new p_Re
2. substituting the new p_Re into second equation and then solve it in order to get the new p_Im.
3. check the differences between new and old p_Re and p_Im. If the differences are small enough, finish; if not go back to step 1.

If I set up two temporary variable as following:
Code:

surfaceScalarField pOld_Re;
surfaceScalarField pOld_Im;

Is there method in surfaceScalarField for evaluating the difference between pOld_Re and p_Re?

Thanks very much for reading till here, I am open for suggestion and advice,Thanks!

akidess March 29, 2016 02:33

Use fvm for your unknown, fvc for your known variables.

http://www.cfd-online.com/Forums/ope...g-fvm-fvc.html

Democritus March 29, 2016 03:10

Thank you very much for your respond~!

In fvm operations, there may be two arguments, such as fvm::div(psi, phi)
The OpenFOAM treats phi as unknown variables by default and treats psi as known variable by default. In deduction, all the fvm operations only admit one argument as unknown and non-linear equations should be handled manually. Am I right? Thank you!

akidess March 29, 2016 03:18

Yes, that's correct :)

Democritus March 29, 2016 03:49

Quote:

Originally Posted by akidess (Post 592104)
Yes, that's correct :)

As a beginner of OpenFOAM, I really need the confirmed answer of such a basic question, thanks!

For the second question, is there a method within surfaceScalarField class for calculating the difference between two fields of the same mesh?

Thank you very much!

Democritus March 31, 2016 03:11

For the second question
 
Quick Update~!

In the GeometricField< Type, PatchField, GeoMesh > Class Template,
there is a operator -= I think it means that
Code:

volScalarField p1
    (
        IOobject
        (
            "p1",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

volScalarField p2
    (
        IOobject
        (
            "p2",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

p1 -= p2; // p1 = p1 - p2

As there is no annotation for this operator, I will try it and update the result:D

Democritus April 12, 2016 08:38

It seems that the operator -= works!
 
The operator seems working fine, the compiler has not threw any error.:)

Quote:

Originally Posted by Democritus (Post 592562)
Quick Update~!

In the GeometricField< Type, PatchField, GeoMesh > Class Template,
there is a operator -= I think it means that
Code:

volScalarField p1
    (
        IOobject
        (
            "p1",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

volScalarField p2
    (
        IOobject
        (
            "p2",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

p1 -= p2; // p1 = p1 - p2

As there is no annotation for this operator, I will try it and update the result:D



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