# Conditional change of UEqn

 Register Blogs Members List Search Today's Posts Mark Forums Read

 November 6, 2015, 16:45 Conditional change of fvVectorMatrix content #1 New Member   Algis Dziugys Join Date: Apr 2015 Posts: 10 Rep Power: 11 Hi, I need to change conditionally fvVectorMatrix (UEqn for example) independently on fvOptions. For example, can I do like that: Foam::fvVectorMatrix UEqn ( Foam::fvm::div(phi, U) - Foam::fvm::laplacian(nu, U) == fvOptions(U) ); if(f_include_turbulence) UEqn += Foam::turbulence->divDevReff(U); if(f_include_gravity) UEqn -= g; UEqn().relax(); Or in other words, how do "-=" and "+=" work for fvVectorMatrix, what rules are? How to be sure that operators "-=" and "+=" will change UEqn.A or UEqn.H, or rhs? Thanks in advance. Last edited by Algis; November 7, 2015 at 16:24.

 November 6, 2015, 17:07 #2 Senior Member   Alexey Matveichev Join Date: Aug 2011 Location: Nancy, France Posts: 1,938 Rep Power: 39 Hi, it depends on rhs of += or -= operator. Since UEqn is fvVectorMatrix, look for meaning of operators, for example, at http://foam.sourceforge.net/docs/cpp...31bccd419a176b. Basically you are able to add another matrix, so it will be sum of matrices, or you can add volume field, in this case field will be added to equation source term.

 November 10, 2015, 11:32 #3 New Member   Algis Dziugys Join Date: Apr 2015 Posts: 10 Rep Power: 11 Hi, I did an experiment. Add gravity (defined as uniformDimensionedVectorField g) by two ways: 1) in definition of UEqn and 2) after definition of UEqn: 1) fvVectorMatrix UEqn_1 ( fvm::ddt(U) fvm::div(phi, U) - fvm::laplacian(nu, U) == -g ); 2) fvVectorMatrix UEqn_2 ( fvm::ddt(U) fvm::div(phi, U) - fvm::laplacian(nu, U) ); UEqn_2 -= g; and then compared both UEqn_1 and UEqn_2. The result was that A(), H1, source() and residual() were the same for UEqn_1 and UEqn_2, while H() was different. Why H() was different? Thank you very much in advance, Algis

 November 10, 2015, 14:38 #4 Member   Mattia de\' Michieli Vitturi Join Date: Mar 2009 Posts: 51 Rep Power: 17 Hi Algis, please can you try with: UEqn_2 += g; Ciao Mattia

November 10, 2015, 16:17
#5
New Member

Algis Dziugys
Join Date: Apr 2015
Posts: 10
Rep Power: 11
Hi Mattia,

I did it and now there is no difference in H() and others. So, analog of

fvVectorMatrix UEqn
(
fvm::ddt(U)
fvm::div(phi, U)
- fvm::laplacian(nu, U)
==
-g
);

is
fvVectorMatrix UEqn_2
(
fvm::ddt(U)
fvm::div(phi, U)
- fvm::laplacian(nu, U)
);
UEqn_2 += g;

but not "UEqn_2 -= g";

Thanks Mattia, now I see in what was my misunderstanding.

Best regards,

Algis

Quote:
 Originally Posted by demichie Hi Algis, please can you try with: UEqn_2 += g; Ciao Mattia

 Tags fvvectormatrix