Accessing a vector in a volVectorField by cell label
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. :confused: 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! |
Good evening
Let me try answering you questions, as I understand them. Accessing an internal value is done as: Code:
label celli(100); 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"); Code:
scalar u = U[celli].x(); Code:
scalarField u = U.component(0); Best regards Niels |
thx a lot for you quick answer :)
|
Accessing vector components
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? |
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 |
I solved my problem. I used the dot product on the velocity vector and the direction vector.
Quote:
|
Quote:
scalar constValue = ... ; vector const(constValue, constValue, constValue); U[cellLabel] += const; |
Quote:
Hello everyone, My question is vice versa. How can I create volVectorField from a vector? I have tried the follwong: Code:
// Code:
UEqn.H:49:5: error: no matching function for call to ‘Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject, Foam::dynamicFvMesh&, Foam::dimensionedScalar)’ Elham |
All times are GMT -4. The time now is 04:30. |