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/)
-   -   reference to a velocity component (https://www.cfd-online.com/Forums/openfoam-programming-development/241707-reference-velocity-component.html)

theBananaTrick March 15, 2022 14:07

reference to a velocity component
 
Hello to all,


I would like to know if it is possible to get a reference to a component of the velocity.



Code:

    volVectorField U
    (
        IOobject
        (
            "U",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );

Code:

scalarField& Ux = U.component(0) // This does not appear to work

olesen March 16, 2022 10:59

If you take U.component(vector::X), you are extracting a tmp field, cannot bind this to a reference!
Code:

tmp<scalarField> tcompx = U.component(vector::X);


// OR
scalarField tcompx(U.component(vector::X));


You need to think about how the data is stored. The vector field (U) is a array of structs x/y/z. But you wish to have something like a struct of arrays, which is not there.


If you want to be memory efficient, you can loop over the velocity field and return the x() component of the individual velocity entry. This will be memory efficient. Not sure if it fits nicely into your code though.


All times are GMT -4. The time now is 07:38.