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

How to get the point coordinates in OpenFOAM?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 30, 2017, 21:38
Default How to get the point coordinates in OpenFOAM?
  #1
New Member
 
Xu Yiming
Join Date: Jan 2017
Posts: 11
Rep Power: 9
ousoweak is on a distinguished road
hi all

I am new to OpenFOAM programming and I want to get the distance between a specific point on the wall and the boundary-line of the wall. Related operations should be conducted in nutUspalding Wall Function file.

To achieve this, it is obviously that (1) I should get the point coordinate (x,y,z) and in .C file (2) get the 3D coordinate of the boundary-line. But I don’t know how to access them in openfoam?

Can anyone help me ? thanks.

Attached file is the sketch of the problem.

Yiming


The nutUspalding Wall Function file are list as fellow:

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //

tmp<scalarField> nutUSpaldingWallFunctionFvPatchScalarField::calcNu t() const
{
const label patchi = patch().index();

const turbulenceModel& turbModel = db().lookupObject<turbulenceModel>
(
IOobject::groupName
(
turbulenceModel:ropertiesName,
internalField().group()
)
);
const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
const scalarField magGradU(mag(Uw.snGrad()));
const tmp<scalarField> tnuw = turbModel.nu(patchi);
const scalarField& nuw = tnuw();

return max
(
scalar(0),
sqr(calcUTau(magGradU))/(magGradU + ROOTVSMALL) - nuw
);
}


tmp<scalarField> nutUSpaldingWallFunctionFvPatchScalarField::calcUT au
(
const scalarField& magGradU
) const
{
const label patchi = patch().index();

const turbulenceModel& turbModel = db().lookupObject<turbulenceModel>
(
IOobject::groupName
(
turbulenceModel:ropertiesName,
internalField().group()
)
);
const scalarField& y = turbModel.y()[patchi];

const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
const scalarField magUp(mag(Uw.patchInternalField() - Uw));

const tmp<scalarField> tnuw = turbModel.nu(patchi);
const scalarField& nuw = tnuw();

const scalarField& nutw = *this;

tmp<scalarField> tuTau(new scalarField(patch().size(), 0.0));
scalarField& uTau = tuTau.ref();

forAll(uTau, facei)
{
scalar ut = sqrt((nutw[facei] + nuw[facei])*magGradU[facei]);

if (ut > ROOTVSMALL)
{
int iter = 0;
scalar err = GREAT;

do
{
scalar kUu = min(kappa_*magUp[facei]/ut, 50);
scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);

scalar f =
- ut*y[facei]/nuw[facei]
+ magUp[facei]/ut
+ 1/(E_*exp(kappa_*0))*(fkUu - 1.0/6.0*kUu*sqr(kUu));

scalar df =
y[facei]/nuw[facei]
+ magUp[facei]/sqr(ut)
+ 1/(E_*exp(kappa_*0))*kUu*fkUu/ut;

scalar uTauNew = ut + f/df;
err = mag((ut - uTauNew)/ut);
ut = uTauNew;

} while (ut > ROOTVSMALL && err > 0.01 && ++iter < 10);

uTau[facei] = max(0.0, ut);
}
}

return tuTau;
}
Attached Images
File Type: jpg 20170331092635.jpg (22.8 KB, 131 views)
ousoweak is offline   Reply With Quote

Old   April 4, 2017, 07:04
Default
  #2
Member
 
Jibran
Join Date: Oct 2012
Location: UK
Posts: 61
Blog Entries: 1
Rep Power: 14
Jibran is on a distinguished road
Quote:
Originally Posted by ousoweak View Post
hi all

I am new to OpenFOAM programming and I want to get the distance between a specific point on the wall and the boundary-line of the wall. Related operations should be conducted in nutUspalding Wall Function file.

To achieve this, it is obviously that (1) I should get the point coordinate (x,y,z) and in .C file (2) get the 3D coordinate of the boundary-line. But I don’t know how to access them in openfoam?

Can anyone help me ? thanks.

Attached file is the sketch of the problem.

Yiming


The nutUspalding Wall Function file are list as fellow:

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //

tmp<scalarField> nutUSpaldingWallFunctionFvPatchScalarField::calcNu t() const
{
const label patchi = patch().index();

const turbulenceModel& turbModel = db().lookupObject<turbulenceModel>
(
IOobject::groupName
(
turbulenceModel:ropertiesName,
internalField().group()
)
);
const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
const scalarField magGradU(mag(Uw.snGrad()));
const tmp<scalarField> tnuw = turbModel.nu(patchi);
const scalarField& nuw = tnuw();

return max
(
scalar(0),
sqr(calcUTau(magGradU))/(magGradU + ROOTVSMALL) - nuw
);
}


tmp<scalarField> nutUSpaldingWallFunctionFvPatchScalarField::calcUT au
(
const scalarField& magGradU
) const
{
const label patchi = patch().index();

const turbulenceModel& turbModel = db().lookupObject<turbulenceModel>
(
IOobject::groupName
(
turbulenceModel:ropertiesName,
internalField().group()
)
);
const scalarField& y = turbModel.y()[patchi];

const fvPatchVectorField& Uw = turbModel.U().boundaryField()[patchi];
const scalarField magUp(mag(Uw.patchInternalField() - Uw));

const tmp<scalarField> tnuw = turbModel.nu(patchi);
const scalarField& nuw = tnuw();

const scalarField& nutw = *this;

tmp<scalarField> tuTau(new scalarField(patch().size(), 0.0));
scalarField& uTau = tuTau.ref();

forAll(uTau, facei)
{
scalar ut = sqrt((nutw[facei] + nuw[facei])*magGradU[facei]);

if (ut > ROOTVSMALL)
{
int iter = 0;
scalar err = GREAT;

do
{
scalar kUu = min(kappa_*magUp[facei]/ut, 50);
scalar fkUu = exp(kUu) - 1 - kUu*(1 + 0.5*kUu);

scalar f =
- ut*y[facei]/nuw[facei]
+ magUp[facei]/ut
+ 1/(E_*exp(kappa_*0))*(fkUu - 1.0/6.0*kUu*sqr(kUu));

scalar df =
y[facei]/nuw[facei]
+ magUp[facei]/sqr(ut)
+ 1/(E_*exp(kappa_*0))*kUu*fkUu/ut;

scalar uTauNew = ut + f/df;
err = mag((ut - uTauNew)/ut);
ut = uTauNew;

} while (ut > ROOTVSMALL && err > 0.01 && ++iter < 10);

uTau[facei] = max(0.0, ut);
}
}

return tuTau;
}
Hi,

The nodal coordinates can be obtained as
Code:
mesh.points()[nodeID]
and boundary face coordinates as
Code:
Cf.boundaryField()[patchID][facei]
Here the 'patchID' is the ID associated to a particular boundary and 'facei' is the local face numbering within that boundary.
__________________
Jibran Haider
https://jibranhaider.com/
Jibran is offline   Reply With Quote

Old   April 9, 2017, 11:45
Default
  #3
New Member
 
Xu Yiming
Join Date: Jan 2017
Posts: 11
Rep Power: 9
ousoweak is on a distinguished road
Quote:
Originally Posted by Jibran View Post
Hi,

The nodal coordinates can be obtained as
Code:
mesh.points()[nodeID]
and boundary face coordinates as
Code:
Cf.boundaryField()[patchID][facei]
Here the 'patchID' is the ID associated to a particular boundary and 'facei' is the local face numbering within that boundary.
Thanks so much for your reply.
With your help,I can get the nodal coordinates by using the code "turbModel.mesh().points()[nodeID]" successfully.

But I still don't know how to get the "nodeID" of the current calculation grid point in the USpalding wall function.Can you help me?

Thank you again.

Yiming
ousoweak is offline   Reply With Quote

Old   April 10, 2017, 06:59
Default
  #4
Member
 
Jibran
Join Date: Oct 2012
Location: UK
Posts: 61
Blog Entries: 1
Rep Power: 14
Jibran is on a distinguished road
Quote:
Originally Posted by ousoweak View Post
Thanks so much for your reply.
With your help,I can get the nodal coordinates by using the code "turbModel.mesh().points()[nodeID]" successfully.

But I still don't know how to get the "nodeID" of the current calculation grid point in the USpalding wall function.Can you help me?

Thank you again.

Yiming
You are welcome. A solution could be to have nested loops on boundary patches, patch faces and then the nodes attached to the faces. I haven't tested this but something like this should work!

Code:
forAll(mesh.boundary(), patchID) 
{
    const word& patchName = mesh.boundary()[patchID].name(); 
 
    forAll (mesh.boundary()[patchID],facei) 
    {
         const label& faceID = mesh.boundaryMesh()[patchID].start() + facei;
         forAll (mesh.faces()[faceID], nodei)
         {
               const label& nodeID = mesh.faces()[faceID][nodei];
         }
    }
}
__________________
Jibran Haider
https://jibranhaider.com/
Jibran is offline   Reply With Quote

Old   April 16, 2017, 22:43
Default
  #5
New Member
 
Xu Yiming
Join Date: Jan 2017
Posts: 11
Rep Power: 9
ousoweak is on a distinguished road
Quote:
Originally Posted by Jibran View Post
You are welcome. A solution could be to have nested loops on boundary patches, patch faces and then the nodes attached to the faces. I haven't tested this but something like this should work!

Code:
forAll(mesh.boundary(), patchID) 
{
    const word& patchName = mesh.boundary()[patchID].name(); 
 
    forAll (mesh.boundary()[patchID],facei) 
    {
         const label& faceID = mesh.boundaryMesh()[patchID].start() + facei;
         forAll (mesh.faces()[faceID], nodei)
         {
               const label& nodeID = mesh.faces()[faceID][nodei];
         }
    }
}
Thank you so much!!!
The code what you have written was exactly the right solution!

the code I used to get point coordinate in the wall function is:
Code:
vector pointX(0,0,0);
const label& faceID = patch().boundaryMesh()[patchi].start() + facei;
 forAll (turbModel.mesh().faces()[faceID], nodei)
         {
               const label& nodeID = turbModel.mesh().faces()[faceID][nodei];
        }
pointX=turbModel.mesh().points()[nodeID];
Thank you again~

Yiming
ousoweak is offline   Reply With Quote

Old   April 18, 2017, 04:07
Default
  #6
Member
 
Jibran
Join Date: Oct 2012
Location: UK
Posts: 61
Blog Entries: 1
Rep Power: 14
Jibran is on a distinguished road
Quote:
Originally Posted by ousoweak View Post
Thank you so much!!!
The code what you have written was exactly the right solution!

the code I used to get point coordinate in the wall function is:
Code:
vector pointX(0,0,0);
const label& faceID = patch().boundaryMesh()[patchi].start() + facei;
 forAll (turbModel.mesh().faces()[faceID], nodei)
         {
               const label& nodeID = turbModel.mesh().faces()[faceID][nodei];
        }
pointX=turbModel.mesh().points()[nodeID];
Thank you again~

Yiming

You are most welcome. I am glad that I could be of help. Enjoy!
__________________
Jibran Haider
https://jibranhaider.com/
Jibran is offline   Reply With Quote

Reply


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
Frequently Asked Questions about Installing OpenFOAM wyldckat OpenFOAM Installation 3 November 14, 2023 11:58
OpenFOAM Training Jan-Jul 2017, Virtual, London, Houston, Berlin CFDFoundation OpenFOAM Announcements from Other Sources 0 January 4, 2017 06:15
OpenFOAM Training Jan-Apr 2017, Virtual, London, Houston, Berlin cfd.direct OpenFOAM Announcements from Other Sources 0 September 21, 2016 11:50
[Gmsh] Gmsh and samplesurface touf OpenFOAM Meshing & Mesh Conversion 2 December 10, 2007 02:27
CFX4.3 -build analysis form Chie Min CFX 5 July 12, 2001 23:19


All times are GMT -4. The time now is 13:47.