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/)
-   -   Question: How to vectorField & dimensionedVector? (https://www.cfd-online.com/Forums/openfoam-programming-development/184394-question-how-vectorfield-dimensionedvector.html)

Santiago March 1, 2017 10:30

Question: How to vectorField & dimensionedVector?
 
So, I was wondering how to do the inner product between a dimensionedVector and a vectorField other than looping directly over the vectorField itself.

me.ouda March 1, 2017 11:39

Did you try just using "&" operator.

I've used it and I get the expected values as if I dot the vector by each vector in the vector field. Here is the code:
Code:

    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField  nonuniform List<vector>
9
(
(-9.66371e-05 0 -0.133191)
(-0.000274768 0 -0.132876)
(-0.000411 0 -0.131537)
(-0.000544201 0 -0.129738)
(-0.000672783 0 -0.12728)
(-0.00077639 0 -0.124466)
(-0.000874089 0 -0.121203)
(-0.000942926 0 -0.117627)
(-0.00100253 0 -0.113825)
)
;

Code:

dimensionedVector v1 ("v1", dimVelocity, vector (0.2, 0.3, 0.4));

Info << (v1.value() & U ) << endl;

The result field:
Code:

dimensions      [0 1 -1 0 0 0 0];

internalField  nonuniform List<scalar> 9(-0.0532957 -0.0532054 -0.052697 -0.052004 -0.0510466 -0.0499417 -0.048656 -0.0472394 -0.0457305);

The old boundary conditions was "zeroGradient", for the new field it becomes "calculated":
Code:

outlet
    {
        type            calculated;
        value          nonuniform List<scalar> 3(-0.052697 -0.0499417 -0.0457305);

May be someone can help on how the resultant boundary condition is defined when we multiply two fields

Santiago March 1, 2017 13:54

Not so fast...
 
Hi @me.ouda


Well, I though so as well, that the & operator should be overloaded. But the thing is that my vectorField is not a volVectorField, but rather is over a patch. When I do the operation, the compiler throws a type-cast error. Ok, to be precise let me show what I'm trying to do:

Code:


    vectorField topPatchVelocity =
        interpolatorBotToTop.faceInterpolate
        (
            UBot.boundaryField()[botPatchID]
        );

    topPatchVelocity = momentumDensityRatio & topPatchVelocity;
    topBC = topPatchVelocity;

This piece of code throws me an error in the last-but-one line. Note that momentumDensityRatio is a dimensionedVector.

Zeppo March 1, 2017 15:53

Quote:

Originally Posted by Santiago (Post 639076)
Code:

topPatchVelocity = momentumDensityRatio & topPatchVelocity;

This won't compile unless momentumDensityRatio's dimension is dimLess. Dimensions to the left of = should be the same as dimensions on the r.h.s.

Extracting the non-dimensional value should work too:
Code:

topPatchVelocity = momentumDensityRatio.value() & topPatchVelocity;

Santiago March 1, 2017 16:45

Quote:

Originally Posted by Zeppo (Post 639090)
This won't compile unless momentumDensityRatio's dimension is dimLess. Dimensions to the left of = should be the same as dimensions on the r.h.s.

Extracting the non-dimensional value should work too:
Code:

topPatchVelocity = momentumDensityRatio.value() & topPatchVelocity;

Nope, It didn't work. Now I get a type-cast error on the assignment operator:

Code:

setDirichlet.H: In function ‘int main(int, char**)’:
setDirichlet.H:10:19: error: no match for ‘operator=’ (operand types are ‘Foam::vectorField {aka Foam::Field<Foam::Vector<double> >}’ and ‘Foam::tmp<Foam::Field<double> >’)
  topPatchVelocity = momentumDensityRatio.value() & topPatchVelocity;


Santiago March 2, 2017 05:57

I kind of forgot my lessons on Tensor Analysis... Sorry
 
Guys, I saw what the problem was: I was doing the contraction of two vector, and I needed a linear application on a vector (to scale it of course). I changed the scaling term to a dimensionedTensor and everything runs smoothly. Now I'll run the code and see what comes out.

Thanks


All times are GMT -4. The time now is 18:57.