CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)

 mathslw August 21, 2012 22:37

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

 ybapat August 22, 2012 00:21

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

 Arnoldinho August 22, 2012 02:33

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").

 mathslw August 22, 2012 14:06

Quote:
 Originally Posted by ybapat (Post 378088) 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
Hi Yogesh,

According you your suggestion, I write the following:
const labelList cells = patch().faceCells();
vectorField Uac = Ua[cells];
Is that right?

Thanks!

Wei

 mathslw August 22, 2012 14:08

Quote:
 Originally Posted by Arnoldinho (Post 378095) 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").
Do you mean "U.boundaryField()[patchi].patchInternalField()" is the velocity vector?
Thanks!

Wei

 mathslw August 22, 2012 14:13

Quote:
 Originally Posted by ybapat (Post 378088) 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

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

 ybapat August 23, 2012 00:16

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

 mathslw August 23, 2012 10:53

Quote:
 Originally Posted by ybapat (Post 378252) 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
Hi Yogesh,

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

 mathslw August 23, 2012 14:12

Quote:
 Originally Posted by ybapat (Post 378252) 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
Hi Yogesh,

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

 ybapat August 24, 2012 00:00

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

 mathslw August 24, 2012 12:28

Quote:
 Originally Posted by ybapat (Post 378461) Hello Wei, const volVectorField& Uc = db().lookupObject("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
Hi Yogesh,

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

 hawkeye321 October 3, 2012 20:22

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?

 All times are GMT -4. The time now is 04:53.