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

problem in label patchID = mesh.boundaryMesh()[patchi];

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 4 Post By Daniel_Khazaei
  • 1 Post By frobaux

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 7, 2019, 10:49
Default problem in label patchID = mesh.boundaryMesh()[patchi];
  #1
Senior Member
 
Hojatollah Gholami
Join Date: Jan 2019
Posts: 171
Rep Power: 7
Hgholami is on a distinguished road
Dear All

I want to assign Ta value to boundaryField via internalField. I defined a Ta in only internalField. Then need to assign the center or surface value of near cells of boundary to its boundaryField, I used code

Quote:
forAll(mesh.boundaryMesh(), patchi)
{
label patchID = mesh.boundaryMesh()[patchi];
forAll(patchID, cellID)
{
if (patchID[cellID] >= LMin+Li*(i-1) //???
&& patchID[cellID] < LMin+Li*i) //???
{
Ta_boundaryField()[cellID] = Ta[i]????;
}
}
}
Before I modify the ???? section, the major problem in compiling is

Quote:
error: cannot convert ‘const Foam::polyPatch’ to ‘Foam::label {aka int}’ in initialization
label patchID = mesh.boundaryMesh()[patchi];
Do you have any suggestion for this error?
regards,
Hojatollah

Last edited by Hgholami; September 7, 2019 at 13:07.
Hgholami is offline   Reply With Quote

Old   September 7, 2019, 15:52
Default
  #2
Senior Member
 
Daniel
Join Date: Mar 2013
Location: Noshahr, Iran
Posts: 348
Rep Power: 21
Daniel_Khazaei will become famous soon enough
Dear Hgholami,

I think you need to see a few examples of how to use loops in OpenFOAM as the code you have posted doesn't make any sense apart from that error! I will describe a few basic information so you can try and make use of them in your code (I wrote these codes for the explanation purpose and you may find a few typos):

1- Loop over the cell centers of a volScalarField variable, e.g. Ta

Code:
scalarField& TaInternal = Ta.internalField();

// loops over cell centers of Ta
forAll (TaInternal, cellI)
{
    TaInternal[cellI] = ...; // make your changes here

}
2- Loop over the cell centers of a volVectorField variable, e.g. Ta

Code:
vectorField& TaInternal = Ta.internalField();

// loops over cell centers of Ta
forAll (TaInternal, cellI)
{
    TaInternal[cellI].x() = ...; // make your changes here
    TaInternal[cellI].y() = ...; // make your changes here
    TaInternal[cellI].z() = ...; // make your changes here

    // or directly with a vector
    TaInternal[cellI] = vector::zero;
}
3- Loop over the faces of a volScalarField boundary, e.g. Ta

Code:
// loops over boundary patches which depend on your case
forAll (Ta.boundaryField(), patchI)
{
    fvPatchScalarField& pTa = Ta.boundaryField()[patchI];

    // This now loops over the faces of the corresponding boundary
    forAll (pTa, faceI)
    {
        pTa[faceI] = ...; //  make your changes here
    }
}
3- Loop over the faces of a volVectorField boundary, e.g. Ta

Code:
// loops over boundary patches which depend on your case
forAll (Ta.boundaryField(), patchI)
{
    fvPatchVectorField& pTa = Ta.boundaryField()[patchI];

    // This now loops over the faces of the corresponding boundary
    forAll (pTa, faceI)
    {
        pTa[faceI].x() = ...; //  make your changes here
        pTa[faceI].y() = ...; //  make your changes here
        pTa[faceI].z() = ...; //  make your changes here
    }
}
Finally, the error you get could not be more self-explanatory, you are converting a FoamolyPatch variable to a Foam::label which is not possible. If you need the patch ID, you can find it for example by its name:
Code:
label patchID = mesh.boundaryMesh().findPatchID("name_of_your_desired_patch");

Regards,
D. Khazaei
frobaux, ruloz, Hgholami and 1 others like this.
Daniel_Khazaei is offline   Reply With Quote

Old   September 9, 2019, 13:01
Default
  #3
Senior Member
 
Hojatollah Gholami
Join Date: Jan 2019
Posts: 171
Rep Power: 7
Hgholami is on a distinguished road
Dear Khazaei
Yes. I think the above code had different types and it make the error.

As my variable is scalar, so I use your third code and it compiled successfully. For check the solution, I use "Info" for print position of face center for a case.
Quote:
forAll(Tb.boundaryField(), patchI)
{
fvPatchScalarField& pTb_ = Tb.boundaryField()[patchI];
forAll(pTb_, faceI)
{
Info << mesh.Cf()[faceI] <<"position"<< faceI <<":"<<patchI<< endl;
}
}
}
The result show that the all faces and patchs of case is correct but position is not cover all range of domain. For example, the domain in x direction is [0 2.5] meter. but the reported position x is in [0 0.12]
Quote:
(0.01 0.00076882 0.0075)positionx0:4
(0.005 0.00153764 0.0075)positionx1:4
(0.02 0.00076882 0.0075)positionx2:4
(0.015 0.00153764 0.0075)positionx3:4
(0.03 0.00076882 0.0075)positionx4:4
(0.025 0.00153764 0.0075)positionx5:4
(0.04 0.00076882 0.0075)positionx6:4
(0.035 0.00153764 0.0075)positionx7:4
(0.05 0.00076882 0.0075)positionx8:4
(0.045 0.00153764 0.0075)positionx9:4
(0.06 0.00076882 0.0075)positionx10:4
(0.055 0.00153764 0.0075)positionx11:4
(0.07 0.00076882 0.0075)positionx12:4
(0.065 0.00153764 0.0075)positionx13:4
(0.08 0.00076882 0.0075)positionx14:4
(0.075 0.00153764 0.0075)positionx15:4
(0.09 0.00076882 0.0075)positionx16:4
(0.085 0.00153764 0.0075)positionx17:4
(0.1 0.00076882 0.0075)positionx18:4
(0.095 0.00153764 0.0075)positionx19:4
(0.11 0.00076882 0.0075)positionx20:4
(0.105 0.00153764 0.0075)positionx21:4
(0.115 0.00153764 0.0075)positionx22:4
(0.12 0.00076882 0.0075)positionx23:4
(0.01 0.00237139 0.0075)positionx24:4
(0.005 0.00320514 0.0075)positionx25:4
(0.02 0.00237139 0.0075)positionx26:4
(0.015 0.00320514 0.0075)positionx27:4
(0.03 0.00237139 0.0075)positionx28:4
(0.025 0.00320514 0.0075)positionx29:4
(0.04 0.00237139 0.0075)positionx30:4
(0.035 0.00320514 0.0075)positionx31:4
(0.05 0.00237139 0.0075)positionx32:4
(0.045 0.00320514 0.0075)positionx33:4
(0.06 0.00237139 0.0075)positionx34:4
(0.055 0.00320514 0.0075)positionx35:4
(0.07 0.00237139 0.0075)positionx36:4
(0.065 0.00320514 0.0075)positionx37:4
(0.08 0.00237139 0.0075)positionx38:4
(0.075 0.00320514 0.0075)positionx39:4
(0.09 0.00237139 0.0075)positionx40:4
(0.085 0.00320514 0.0075)positionx41:4
(0.1 0.00237139 0.0075)positionx42:4
(0.095 0.00320514 0.0075)positionx43:4
(0.11 0.00237139 0.0075)positionx44:4
(0.105 0.00320514 0.0075)positionx45:4
(0.115 0.00320514 0.0075)positionx46:4
(0.12 0.00237139 0.0075)positionx47:4
(0.01 0.0041093 0.0075)positionx48:4
(0.005 0.00501347 0.0075)positionx49:4
(0.02 0.0041093 0.0075)positionx50:4
(0.015 0.00501347 0.0075)positionx51:4
(0.03 0.0041093 0.0075)positionx52:4
(0.025 0.00501347 0.0075)positionx53:4
(0.04 0.0041093 0.0075)positionx54:4
(0.035 0.00501347 0.0075)positionx55:4
(0.05 0.0041093 0.0075)positionx56:4
(0.045 0.00501347 0.0075)positionx57:4
(0.06 0.0041093 0.0075)positionx58:4
(0.055 0.00501347 0.0075)positionx59:4
(0.07 0.0041093 0.0075)positionx60:4
(0.065 0.00501347 0.0075)positionx61:4
(0.08 0.0041093 0.0075)positionx62:4
(0.075 0.00501347 0.0075)positionx63:4
(0.09 0.0041093 0.0075)positionx64:4
(0.085 0.00501347 0.0075)positionx65:4
(0.1 0.0041093 0.0075)positionx66:4
(0.095 0.00501347 0.0075)positionx67:4
(0.11 0.0041093 0.0075)positionx68:4
(0.105 0.00501347 0.0075)positionx69:4
(0.115 0.00501346 0.0075)positionx70:4
(0.12 0.0041093 0.0075)positionx71:4
(0.01 0.005994 0.0075)positionx72:4
(0.005 0.00697453 0.0075)positionx73:4
(0.02 0.005994 0.0075)positionx74:4
(0.015 0.00697453 0.0075)positionx75:4
(0.03 0.005994 0.0075)positionx76:4
(0.025 0.00697453 0.0075)positionx77:4
(0.04 0.005994 0.0075)positionx78:4
(0.035 0.00697453 0.0075)positionx79:4
(0.05 0.005994 0.0075)positionx80:4
(0.045 0.00697453 0.0075)positionx81:4
(0.06 0.005994 0.0075)positionx82:4
(0.055 0.00697453 0.0075)positionx83:4
(0.07 0.005994 0.0075)positionx84:4
(0.065 0.00697453 0.0075)positionx85:4
(0.08 0.005994 0.0075)positionx86:4
(0.075 0.00697452 0.0075)positionx87:4
(0.09 0.005994 0.0075)positionx88:4
(0.085 0.00697452 0.0075)positionx89:4
(0.1 0.005994 0.0075)positionx90:4
(0.095 0.00697452 0.0075)positionx91:4
(0.11 0.005994 0.0075)positionx92:4
(0.105 0.00697452 0.0075)positionx93:4
(0.115 0.00697452 0.0075)positionx94:4
(0.12 0.00599399 0.0075)positionx95:4
(0.01 0.00803787 0.0075)positionx96:4
(0.005 0.00910121 0.0075)positionx97:4
(0.02 0.00803787 0.0075)positionx98:4
(0.015 0.00910121 0.0075)positionx99:4
(0.03 0.00803787 0.0075)positionx100:4
(0.025 0.00910121 0.0075)positionx101:4
(0.04 0.00803787 0.0075)positionx102:4
(0.035 0.00910121 0.0075)positionx103:4
(0.05 0.00803786 0.0075)positionx104:4
(0.045 0.00910121 0.0075)positionx105:4
(0.06 0.00803786 0.0075)positionx106:4
(0.055 0.0091012 0.0075)positionx107:4
(0.07 0.00803787 0.0075)positionx108:4
(0.065 0.0091012 0.0075)positionx109:4
(0.08 0.00803787 0.0075)positionx110:4
(0.075 0.00910121 0.0075)positionx111:4
(0.09 0.00803786 0.0075)positionx112:4
(0.085 0.0091012 0.0075)positionx113:4
(0.1 0.00803786 0.0075)positionx114:4
(0.095 0.0091012 0.0075)positionx115:4
(0.11 0.00803786 0.0075)positionx116:4
(0.01 0.00076882 0.0075)positionx0:5
(0.005 0.00153764 0.0075)positionx1:5
(0.02 0.00076882 0.0075)positionx2:5
(0.015 0.00153764 0.0075)positionx3:5
(0.03 0.00076882 0.0075)positionx4:5
(0.025 0.00153764 0.0075)positionx5:5
(0.04 0.00076882 0.0075)positionx6:5
(0.035 0.00153764 0.0075)positionx7:5
(0.05 0.00076882 0.0075)positionx8:5
(0.045 0.00153764 0.0075)positionx9:5
(0.06 0.00076882 0.0075)positionx10:5
(0.055 0.00153764 0.0075)positionx11:5
(0.07 0.00076882 0.0075)positionx12:5
(0.065 0.00153764 0.0075)positionx13:5
(0.08 0.00076882 0.0075)positionx14:5
(0.075 0.00153764 0.0075)positionx15:5
(0.09 0.00076882 0.0075)positionx16:5
(0.085 0.00153764 0.0075)positionx17:5
(0.1 0.00076882 0.0075)positionx18:5
(0.095 0.00153764 0.0075)positionx19:5
(0.11 0.00076882 0.0075)positionx20:5
(0.105 0.00153764 0.0075)positionx21:5
(0.115 0.00153764 0.0075)positionx22:5
(0.12 0.00076882 0.0075)positionx23:5
(0.01 0.00237139 0.0075)positionx24:5
(0.005 0.00320514 0.0075)positionx25:5
(0.02 0.00237139 0.0075)positionx26:5
(0.015 0.00320514 0.0075)positionx27:5
(0.03 0.00237139 0.0075)positionx28:5
(0.025 0.00320514 0.0075)positionx29:5
(0.04 0.00237139 0.0075)positionx30:5
(0.035 0.00320514 0.0075)positionx31:5
(0.05 0.00237139 0.0075)positionx32:5
(0.045 0.00320514 0.0075)positionx33:5
(0.06 0.00237139 0.0075)positionx34:5
(0.055 0.00320514 0.0075)positionx35:5
(0.07 0.00237139 0.0075)positionx36:5
(0.065 0.00320514 0.0075)positionx37:5
(0.08 0.00237139 0.0075)positionx38:5
(0.075 0.00320514 0.0075)positionx39:5
(0.09 0.00237139 0.0075)positionx40:5
(0.085 0.00320514 0.0075)positionx41:5
(0.1 0.00237139 0.0075)positionx42:5
(0.095 0.00320514 0.0075)positionx43:5
(0.11 0.00237139 0.0075)positionx44:5
(0.105 0.00320514 0.0075)positionx45:5
(0.115 0.00320514 0.0075)positionx46:5
(0.12 0.00237139 0.0075)positionx47:5
(0.01 0.0041093 0.0075)positionx48:5
(0.005 0.00501347 0.0075)positionx49:5
(0.02 0.0041093 0.0075)positionx50:5
(0.015 0.00501347 0.0075)positionx51:5
(0.03 0.0041093 0.0075)positionx52:5
(0.025 0.00501347 0.0075)positionx53:5
(0.04 0.0041093 0.0075)positionx54:5
(0.035 0.00501347 0.0075)positionx55:5
(0.05 0.0041093 0.0075)positionx56:5
(0.045 0.00501347 0.0075)positionx57:5
(0.06 0.0041093 0.0075)positionx58:5
(0.055 0.00501347 0.0075)positionx59:5
(0.07 0.0041093 0.0075)positionx60:5
(0.065 0.00501347 0.0075)positionx61:5
(0.08 0.0041093 0.0075)positionx62:5
(0.075 0.00501347 0.0075)positionx63:5
(0.09 0.0041093 0.0075)positionx64:5
(0.085 0.00501347 0.0075)positionx65:5
(0.1 0.0041093 0.0075)positionx66:5
(0.095 0.00501347 0.0075)positionx67:5
(0.11 0.0041093 0.0075)positionx68:5
(0.105 0.00501347 0.0075)positionx69:5
(0.115 0.00501346 0.0075)positionx70:5
(0.12 0.0041093 0.0075)positionx71:5
(0.01 0.005994 0.0075)positionx72:5
(0.005 0.00697453 0.0075)positionx73:5
(0.02 0.005994 0.0075)positionx74:5
(0.015 0.00697453 0.0075)positionx75:5
(0.03 0.005994 0.0075)positionx76:5
(0.025 0.00697453 0.0075)positionx77:5
(0.04 0.005994 0.0075)positionx78:5
(0.035 0.00697453 0.0075)positionx79:5
(0.05 0.005994 0.0075)positionx80:5
(0.045 0.00697453 0.0075)positionx81:5
(0.06 0.005994 0.0075)positionx82:5
(0.055 0.00697453 0.0075)positionx83:5
(0.07 0.005994 0.0075)positionx84:5
(0.065 0.00697453 0.0075)positionx85:5
(0.08 0.005994 0.0075)positionx86:5
(0.075 0.00697452 0.0075)positionx87:5
(0.09 0.005994 0.0075)positionx88:5
(0.085 0.00697452 0.0075)positionx89:5
(0.1 0.005994 0.0075)positionx90:5
(0.095 0.00697452 0.0075)positionx91:5
(0.11 0.005994 0.0075)positionx92:5
(0.105 0.00697452 0.0075)positionx93:5
(0.115 0.00697452 0.0075)positionx94:5
(0.12 0.00599399 0.0075)positionx95:5
(0.01 0.00803787 0.0075)positionx96:5
(0.005 0.00910121 0.0075)positionx97:5
(0.02 0.00803787 0.0075)positionx98:5
(0.015 0.00910121 0.0075)positionx99:5
(0.03 0.00803787 0.0075)positionx100:5
(0.025 0.00910121 0.0075)positionx101:5
(0.04 0.00803787 0.0075)positionx102:5
(0.035 0.00910121 0.0075)positionx103:5
(0.05 0.00803786 0.0075)positionx104:5
(0.045 0.00910121 0.0075)positionx105:5
(0.06 0.00803786 0.0075)positionx106:5
(0.055 0.0091012 0.0075)positionx107:5
(0.07 0.00803787 0.0075)positionx108:5
(0.065 0.0091012 0.0075)positionx109:5
(0.08 0.00803787 0.0075)positionx110:5
(0.075 0.00910121 0.0075)positionx111:5
(0.09 0.00803786 0.0075)positionx112:5
(0.085 0.0091012 0.0075)positionx113:5
(0.1 0.00803786 0.0075)positionx114:5
(0.095 0.0091012 0.0075)positionx115:5
(0.11 0.00803786 0.0075)positionx116:5
The case is a horizontal channel and faceI 4,5 are top and bottom walls with 117 faces. the prediction is y direction should be constant and x direction distribution be between [0, 2.5].

Last edited by Hgholami; September 9, 2019 at 15:33.
Hgholami is offline   Reply With Quote

Old   October 3, 2019, 12:36
Default
  #4
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 10
frobaux is on a distinguished road
If you iterate over a patch, faceI will cover the indices of the PATCH faces. (from 0 to nFaces)


You either need to print the pTb_ faces or convert the local indice into global indice!


What you do is you print mesh.Cf() , which returns the center of the MESH faces. (So the 117 first faces of the mesh)

Code:
forAll(pTb_, faceI)
{ 
      Info << pTb_[faceI] 

            <<" face indice: "<< faceI 

            <<" patch indice:"<<patchI<< endl;
}
Previously if there were 100 face on a given patch, you would return the 100 first faces of the mesh.
(Look at the first output of each new patch :

Code:
(0.01 0.00076882 0.0075)positionx0:4
 (0.01 0.00076882 0.0075)positionx0:5
)
Hgholami likes this.
frobaux 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
[blockMesh] Internal walls of zero thickness anger OpenFOAM Meshing & Mesh Conversion 23 February 6, 2020 19:25
BuoyantBoussinesqSimpleFoam_Facing problem Mondal131211 OpenFOAM Running, Solving & CFD 1 April 10, 2019 20:41
Gambit - meshing over airfoil wrapping (?) problem JFDC FLUENT 1 July 11, 2011 06:59
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 07:29
Adiabatic and Rotating wall (Convection problem) ParodDav CFX 5 April 29, 2007 20:13


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