|
[Sponsors] |
Accessing a vector in a volVectorField by cell label |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
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: 17 |
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: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
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]; 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]; Code:
scalar u = U[celli].x(); scalar v = U[celli].y(); scalar w = U[celli].z(); Code:
scalarField u = U.component(0); scalarField v = U.component(1); scalarField w = U.component(2); Best regards Niels |
|
March 13, 2011, 05:53 |
|
#3 |
Member
Andrew Ryan
Join Date: Mar 2009
Posts: 47
Rep Power: 17 |
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: 17 |
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? |
|
April 18, 2016, 12:45 |
|
#5 |
Member
Ali
Join Date: Oct 2013
Location: Scotland
Posts: 66
Rep Power: 13 |
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, 09:32 |
|
#6 | |
Member
Ali
Join Date: Oct 2013
Location: Scotland
Posts: 66
Rep Power: 13 |
I solved my problem. I used the dot product on the velocity vector and the direction vector.
Quote:
|
||
April 21, 2016, 07:51 |
|
#7 | |
New Member
Pavlos Alexias
Join Date: Apr 2016
Posts: 1
Rep Power: 0 |
Quote:
scalar constValue = ... ; vector const(constValue, constValue, constValue); U[cellLabel] += const; |
||
June 8, 2018, 05:48 |
|
#8 | |
Senior Member
Elham
Join Date: Oct 2009
Posts: 184
Rep Power: 17 |
Quote:
Hello everyone, My question is vice versa. How can I create volVectorField from a vector? I have tried the follwong: Code:
// //volVectorField gradAlpha(fvc::grad(alpha1)); volVectorField gradAlpha(pos(alpha1)*fvc::grad(alpha1)); const dimensionedScalar deltaN = 1e-8/pow(average(mixture.U().mesh().V()), 1.0/3.0); // Face unit interface normal volVectorField nHatfv(gradAlpha/(mag(gradAlpha) + deltaN)); volVectorField Vr(mDotU / rho * nHatfv) ; label celli; const cellList& Cells = mesh.cells(); //list of all cell IDs const faceList& faces = mesh.faces(); //list of all face IDs for(celli = 0; celli < mesh.nCells(); celli++) { if(alpha1[celli] > 0 && alpha1[celli] < 1) { vector um[celli]=U[celli]+Vr[celli]; } else { vector um[celli]=U[celli]; } } volVectorField U1 ( IOobject ( "U1", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar ("U1",dimVelocity,1) ); volVectorField Um = um * U1 ; 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 |
||
Tags |
datastructures, fields |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
FvMatrix coefficients | shrina | OpenFOAM Running, Solving & CFD | 10 | October 3, 2013 15:38 |
Cells with t below lower limit | Purushothama | Siemens | 2 | May 31, 2010 22:58 |
accessing upstream cell - UDF | bohis | FLUENT | 0 | April 7, 2008 06:12 |
[Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues | michele | OpenFOAM Meshing & Mesh Conversion | 2 | July 15, 2005 05:15 |
Warning 097- | AB | Siemens | 6 | November 15, 2004 05:41 |