# Accessing a vector in a volVectorField by cell label

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 March 12, 2011, 16:50 Accessing a vector in a volVectorField by cell label #1 Member   Andrew Ryan Join Date: Mar 2009 Posts: 47 Rep Power: 9 Given a volVectorField how can I access the vector corresponding to a given cell label? Simple question, but I couldn't figure it out so far. For example I want to access the value of U at a boundary as defined in 0/U how can I do that? Also as far as I can see the underlying data structure of volVectorField is a linked list, is that correct? I don't understand how the mapping of the cell labels to the physical data such as U and V works. thx for any help!

 March 12, 2011, 17:43 #2 Senior Member   Niels Gjoel Jacobsen Join Date: Mar 2009 Location: Deltares, Delft, The Netherlands Posts: 1,713 Rep Power: 27 Good evening Let me try answering you questions, as I understand them. Accessing an internal value is done as: Code: ```label celli(100); vector uCell = U[celli];``` This is the easy part. Knowing the cell label you can directly get the data, as it is always internal. To access the values on a boundary, you need to get a reference to the boundary field. This is done in the following way: Code: ```label patchID = mesh.boundaryMesh().whichPatchID("myBoundaryName"); vectorField & Uw = U.boundaryField()[patchID];``` In the above, Uw is a list of velocities which has the same length as the number of faces on that specific boundary. To access the velocity component you can do it in two ways. The first only works on cell level: Code: ```scalar u = U[celli].x(); scalar v = U[celli].y(); scalar w = U[celli].z();``` and the other method allows you to access the entire field Code: ```scalarField u = U.component(0); scalarField v = U.component(1); scalarField w = U.component(2);``` The latter method does only return the velocity components of the internal values, thus if you need the boundary values merely replace U with Uw in the last expression. Best regards Niels sushant, sina_mech, kiddmax and 7 others like this.

 March 13, 2011, 05:53 #3 Member   Andrew Ryan Join Date: Mar 2009 Posts: 47 Rep Power: 9 thx a lot for you quick answer

 January 15, 2012, 06:48 Accessing vector components #4 New Member   Ali Sh Join Date: Jun 2009 Location: London Posts: 28 Rep Power: 9 Hi guys, I am wondering if you can help me on the following problem: The velocity vector components can be accessed using U.componet(0), U.componet(1), U.componet(2). I intend to add a constant to velocity Y component during the iteration. Initially I tried: U.component(1) += constant; The outcome shows that (Obviously) U has not been changed. Is it possible to define constant as a vector and add it to the velocity vector? how should it be written? codder likes this.

 April 18, 2016, 11:45 #5 Member   Ali Join Date: Oct 2013 Location: Scotland Posts: 44 Rep Power: 5 Hi All Thanks for the tips. Is there any way to call the cell normal component? My cells lie in the x-y-z plane at the moment, but I want my code to work with any angled cells too. I want to extract the velocity component through a boundary face normal. Any help is appreciated. regards Ali

April 19, 2016, 08:32
#6
Member

Ali
Join Date: Oct 2013
Location: Scotland
Posts: 44
Rep Power: 5
I solved my problem. I used the dot product on the velocity vector and the direction vector.
Quote:
 vectorField normalSlaveVector = mesh.Sf().boundaryField()[slave];
Where slave is the patch name. Hope this helps anyone else.

April 21, 2016, 06:51
#7
New Member

Pavlos Alexias
Join Date: Apr 2016
Posts: 1
Rep Power: 0
Quote:
 Originally Posted by ICL Hi guys, I am wondering if you can help me on the following problem: The velocity vector components can be accessed using U.componet(0), U.componet(1), U.componet(2). I intend to add a constant to velocity Y component during the iteration. Initially I tried: U.component(1) += constant; The outcome shows that (Obviously) U has not been changed. Is it possible to define constant as a vector and add it to the velocity vector? how should it be written?
You can simply do

scalar constValue = ... ;

vector const(constValue, constValue, constValue);

U[cellLabel] += const;

 Tags datastructures, fields

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post shrina OpenFOAM Running, Solving & CFD 10 October 3, 2013 14:38 Purushothama CD-adapco 2 May 31, 2010 21:58 bohis FLUENT 0 April 7, 2008 05:12 michele OpenFOAM Other Meshers: ICEM, Star, Ansys, Pointwise, GridPro, Ansa, ... 2 July 15, 2005 04:15 AB CD-adapco 6 November 15, 2004 05:41

All times are GMT -4. The time now is 21:00.

 Contact Us - CFD Online - Top