CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Access to the velocity at boundary cells

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By ybapat
  • 1 Post By fedvasu

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 21, 2012, 22:37
Default Access to the velocity at boundary cells
  #1
New Member
 
Wei Liu
Join Date: Apr 2011
Location: West Lafayette, IN
Posts: 29
Rep Power: 15
mathslw is on a distinguished road
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
mathslw is offline   Reply With Quote

Old   August 22, 2012, 00:21
Default
  #2
Senior Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 15
ybapat is on a distinguished road
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
ybapat is offline   Reply With Quote

Old   August 22, 2012, 02:33
Default
  #3
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
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").
Arnoldinho is offline   Reply With Quote

Old   August 22, 2012, 14:06
Default
  #4
New Member
 
Wei Liu
Join Date: Apr 2011
Location: West Lafayette, IN
Posts: 29
Rep Power: 15
mathslw is on a distinguished road
Quote:
Originally Posted by ybapat View Post
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 is offline   Reply With Quote

Old   August 22, 2012, 14:08
Default
  #5
New Member
 
Wei Liu
Join Date: Apr 2011
Location: West Lafayette, IN
Posts: 29
Rep Power: 15
mathslw is on a distinguished road
Quote:
Originally Posted by Arnoldinho View Post
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 is offline   Reply With Quote

Old   August 22, 2012, 14:13
Default
  #6
New Member
 
Wei Liu
Join Date: Apr 2011
Location: West Lafayette, IN
Posts: 29
Rep Power: 15
mathslw is on a distinguished road
Quote:
Originally Posted by ybapat View Post
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
mathslw is offline   Reply With Quote

Old   August 23, 2012, 00:16
Default
  #7
Senior Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 15
ybapat is on a distinguished road
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
ybapat is offline   Reply With Quote

Old   August 23, 2012, 10:53
Default
  #8
New Member
 
Wei Liu
Join Date: Apr 2011
Location: West Lafayette, IN
Posts: 29
Rep Power: 15
mathslw is on a distinguished road
Quote:
Originally Posted by ybapat View Post
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:perator=(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 is offline   Reply With Quote

Old   August 23, 2012, 14:12
Default
  #9
New Member
 
Wei Liu
Join Date: Apr 2011
Location: West Lafayette, IN
Posts: 29
Rep Power: 15
mathslw is on a distinguished road
Quote:
Originally Posted by ybapat View Post
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
mathslw is offline   Reply With Quote

Old   August 24, 2012, 00:00
Default
  #10
Senior Member
 
Yogesh Bapat
Join Date: Oct 2010
Posts: 102
Rep Power: 15
ybapat is on a distinguished road
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
saeed jamshidi likes this.
ybapat is offline   Reply With Quote

Old   August 24, 2012, 12:28
Default
  #11
New Member
 
Wei Liu
Join Date: Apr 2011
Location: West Lafayette, IN
Posts: 29
Rep Power: 15
mathslw is on a distinguished road
Quote:
Originally Posted by ybapat View Post
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
Hi Yogesh,

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
mathslw is offline   Reply With Quote

Old   October 3, 2012, 20:22
Default east and north cell values
  #12
Member
 
,...
Join Date: Apr 2011
Posts: 92
Rep Power: 14
hawkeye321 is an unknown quantity at this point
Is there any way (any function) to get the value of a parameter at the east and north of a specific cell?
hawkeye321 is offline   Reply With Quote

Old   November 22, 2017, 09:10
Default access to value of a quantity
  #13
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 305
Rep Power: 12
alimea is on a distinguished road
Hi
Basikly, how can I access to value of a quantity like U in a cell?

thanks
alimea is offline   Reply With Quote

Old   January 9, 2018, 18:17
Default
  #14
Member
 
Join Date: Oct 2013
Posts: 92
Rep Power: 12
fedvasu is on a distinguished road
Quote:
Originally Posted by alimea View Post
Hi
Basikly, how can I access to value of a quantity like U in a cell?

thanks
const scalarField& UCells = U.internalField();

forAll(UCells,CellI)
{
UCells[CellI];
}

you can find it in many places in OpenFOAM source.

is that what you want?
alimea likes this.
fedvasu is offline   Reply With Quote

Old   January 9, 2018, 23:31
Smile
  #15
Senior Member
 
A. Min
Join Date: Mar 2015
Posts: 305
Rep Power: 12
alimea is on a distinguished road
Quote:
Originally Posted by fedvasu View Post
const scalarField& UCells = U.internalField();

forAll(UCells,CellI)
{
UCells[CellI];
}

you can find it in many places in OpenFOAM source.

is that what you want?
Yes, thank you my friend
alimea is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wind turbine simulation Saturn CFX 58 July 3, 2020 01:13
[snappyHexMesh] SnappyHexMesh for internal Flow vishwa OpenFOAM Meshing & Mesh Conversion 24 June 27, 2016 08:54
[ICEM] error analysis despaired student ANSYS Meshing & Geometry 7 June 27, 2012 11:57
Velocity inlet boundary condition for porous medium Chander CFX 3 March 11, 2012 21:18
Variables Definition in CFX Solver 5.6 R P CFX 2 October 26, 2004 02:13


All times are GMT -4. The time now is 01:52.