CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

reference to a velocity component

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 15, 2022, 14:07
Default reference to a velocity component
  #1
New Member
 
Join Date: Feb 2022
Posts: 25
Rep Power: 4
theBananaTrick is on a distinguished road
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
theBananaTrick is offline   Reply With Quote

Old   March 16, 2022, 10:59
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,689
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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.
olesen 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
Setting the height of the stream in the free channel kevinmccartin CFX 12 October 13, 2022 21:43
Compression stoke is giving higher pressure than calculated nickjuana CFX 62 May 19, 2015 13:32
OF211: ThirdParty and /src compiled, but not /applications... vkrastev OpenFOAM Installation 8 October 18, 2012 15:53
error message cuteapathy CFX 14 March 20, 2012 06:45
Windows Installation BugsComments on Petrbs patch brooksmoses OpenFOAM Installation 48 April 16, 2006 00:20


All times are GMT -4. The time now is 03:54.