Access to the velocity at boundary cells
Hi all,
I want to use the velocity at boundary cells and velocity at the boundary face. I found that this code "const fvPatchField<vector>& Up = patch().lookupPatchField<volVectorField, vector>("U");" could obtain the velocity vector at the boundary face. Is there any similar code to obtain the velocity vector at the boundary cell? or other methods? Many thanks! Mathslw |
Hello,
patch.faceCells() will give you list of cells adjecent to boundary. To get adjecent cell for a face, do patch.faceCells()[facei]. Using this cell id and volVectorField U you can access value of velocity in the cell. Regards, -Yogesh |
Another way to directly access the patch-nearest cells is to use U.boundaryField()[patchi].patchInternalField(), whereas patchi is your patch id which is found using const label patchi = mesh.boundaryMesh().findPatchID("bottom").
|
Quote:
According you your suggestion, I write the following: const labelList cells = patch().faceCells(); vectorField Uac = Ua[cells]; Is that right? Thanks! Wei |
Quote:
Thanks! Wei |
Quote:
Hi Yogesh, According you your suggestion, I write the following: const fvPatchField<vector>& Uf = patch().lookupPatchField<volVectorField, vector>("U"); const labelList cells = patch().faceCells(); vectorField Uc = U[cells]; Is that right? Thanks! Wei |
Hello Wei,
You need to loop over cellList to access value of individual cell. forAll(cells,celli) { vector Ui = U[celli] } If you need directly field of boundary velocities, better option is suggested by Arne in his post. Regards, -Yogesh |
Quote:
Actually, I want to modify the boudary condition define in the adjointShapeOptimizationFoam. The original code is as following: const fvsPatchField<scalar>& phiap = patch().lookupPatchField<surfaceScalarField, scalar>("phia"); const fvPatchField<vector>& Up = patch().lookupPatchField<volVectorField, vector>("U"); scalarField Un(mag(patch().nf() & Up)); vectorField UtHat((Up - patch().nf()*Un)/(Un + SMALL)); vectorField Uan(patch().nf()*(patch().nf() & patchInternalField())); vectorField::operator=(phiap*patch().Sf()/sqr(patch().magSf()) + UtHat); In this code, it uses the velocity on the boundary face and there is no loop. Then I want to use the velocity at the boundary cell, in the same way, I think there should not have any loop. Do you have any idea about that? Moreover, I also need the gradient of the velocity at the boundary cell, can I use volTensorField gradUc=fvc::grad(Uc) if Uc is the velocity at the boundary cell. Many thanks! Wei |
Quote:
Actually, I am trying to program a BC class. I found that the following code could obtain the velocity at the boundary cell: const volVectorField& Uc = db().lookupObject<volVectorField>("U"); What about if I want the gradient of this velocity at the boundary cell? Thanks! Wei |
Hello Wei,
const volVectorField& Uc = db().lookupObject<volVectorField>("U") would give you velocity field over entire domain. To get at boundary you need to do as Arne suggested in his post U.boundaryField()[patchi].patchInternalField(). About gradient I am not very sure, but I think you need to calculate it and then use it by accessing its patch internalField in the same way as for velocity. Regards, -Yogesh |
Quote:
Thanks for your reply! If I use U.boundaryField()[patchi].patchInternalField(), the code would be: vectorField& Uac = U.boundaryField()[patch()].patchInternalField();? Since this is in the BC class, can I use patch() here? When I compiled, I was told ‘U’ was not declared in this scope. Then how can I declare the U here. Many thanks! Wei |
east and north cell values
Is there any way (any function) to get the value of a parameter at the east and north of a specific cell?
|
access to value of a quantity
Hi
Basikly, how can I access to value of a quantity like U in a cell? thanks |
Quote:
forAll(UCells,CellI) { UCells[CellI]; } you can find it in many places in OpenFOAM source. is that what you want? |
Quote:
|
All times are GMT -4. The time now is 20:08. |