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

Changing boundary patch type on constant/polymesh/boundary in solver

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 26, 2022, 19:50
Default Changing boundary patch type on constant/polymesh/boundary in solver
  #1
New Member
 
Join Date: Dec 2021
Location: Argentina, BB
Posts: 5
Rep Power: 4
ariedinger is on a distinguished road
Hello foamers,

We are attempting to modify the boundary patches on constant/polymesh/boundary at runTime in a multi-region solver based upon interFoam. Here's what we are trying to do:
  1. We have two loops that solve two different sets of equations, where the second loop depends upon the results of the first.
  2. We read the fields for the first solver and solve the first set of equations. So far so good. To do this, we need to set the boundary patch types as walls in constant/polymesh/boundary, as the fields of the first solver need zeroGradient as boundary conditions.
  3. Then, we need to solve the second set of equations. But, the fields corresponding to this second set of equations need to have empty as boundary conditions, which we cannot set because the boundary patch type in constant/polymesh/boundary is already defined as wall.
  4. Therefore, we were thinking that before we read said fields, we need to change the boundary patch type on constant/polymesh/boundary.
If we don't do that, we get the following ERROR message:
Code:
--> FOAM FATAL IO ERROR: 

    patch type 'wall' not constraint type 'empty'
    for patch front of field p_rgh in file "/home/ar/OpenFOAM/ar-dev/run/ar/ar04/0/region/p_rgh"

file: /home/ariedinger/OpenFOAM/ariedinger-dev/run/ar/ar04/0/region/p_rgh/boundaryField/front from line 24 to line 24.

    From function Foam::emptyFvPatchField<Type>::emptyFvPatchField(const Foam::fvPatch&, const Foam::DimensionedField<Type, Foam::volMesh>&, const Foam::dictionary&) [with Type = double]
    in file fields/fvPatchFields/constraint/empty/emptyFvPatchField.C at line 54.

 FOAM exiting
We have tried several things; we are apparently able to change the name of the boundary patch types with


Code:
        const word& patchTypeEmpty = "empty";

    allRegions[2].boundaryMesh().types()[0] = patchTypeEmpty;
    allRegions[2].boundaryMesh().types()[1] = "empty";

    Info << "\nBoundary mesh patchTypes: " << allRegions[2].boundaryMesh().types() << nl << endl;
And this outputs
Code:
Boundary mesh patchTypes: 
3
(
wall
wall
mappedWall
)
But we still get the ERROR message, so the code isn't effectively modifying the mesh information. Furthermore, if we do this:
Code:
   const word& patchTypeEmpty = "empty";

    allRegions[2].boundaryMesh().types()[0] = patchTypeEmpty;
    allRegions[2].boundaryMesh().types()[1] = "empty";

    Info << "\nBoundary mesh patchTypes: " << allRegions[2].boundaryMesh().types() << nl << endl;

    forAll(allRegions[2].boundary(), patch)
    {
        /* Boundary patch name and types */
        const word& patchName = allRegions[2].boundary()[patch].name();
        const word& patchType = allRegions[2].boundary()[patch].type();

        Info << "Read patchName: " << patchName
             << ", patchType: " << patchType
             << " in region "  << allRegions[2].name()
             << nl << endl;

        if
        (
            (patchName == "front" ||
             patchName == "back") &&
            (patchType == "wall")
        )
        {

            Info << "Attempting to change patch "
                 << patchName << " from type "
                 << patchType << " to type "
                 << patchTypeEmpty
                 << nl << endl;
        }
    }
We have the following output


Code:
Boundary mesh patchTypes: 
3
(
wall
wall
mappedWall
)

Read patchName: front, patchType: wall in region region1

Attempting to change patch front from type wall to type empty

Read patchName: back, patchType: wall in region region1

Attempting to change patch back from type wall to type empty

Read patchName: region1_to_region2, patchType: mappedWall in region region1
Which shows that allRegions[2].boundaryMesh().types(); isn't changing the mesh information at all.


There are functions such as changePatchType() [https://cpp.openfoam.org/v8/classFoam_1_1boundaryMesh.html#ae598cc11969a83a0ec f2be3e967948dd] and renamePatches() [https://cpp.openfoam.org/v10/classFo...fe1147025538f5], but we are not sure how to use them.


EDIT1: mesh.boundaryMesh().changePatchType() does not seem to exist anymore in version 10. Is there any similar function that does the same?


EDIT2: We found the function changePatchType() in the class repatchMesh().changePatchType() (that is included with the dyamic meshes libraries). We are now testing the following code


Code:
Info << "Boundary mesh patchTypes: " << allRegions[2].boundaryMesh().types() << nl << endl;

Info << "Reading mesh with repatchMesh() ... " << nl << endl;
repatchMesh().read(allRegions[2]);

Info << "Boundary mesh read with repatchMesh(): "
     << repatchMesh().mesh() << nl << endl;

Info << "Boundary patches read with repatchMesh(): "
     << repatchMesh().patches() << nl << endl;

forAll(allRegions[2].boundary(), patch)
{
    /* Boundary patch name and types */
    const word& patchName = allRegions[2].boundary()[patch].name();
    const word& patchType = allRegions[2].boundary()[patch].type();

    Info << "Read patchName: " << patchName
         << ", patchType: " << patchType
         << " in region "  << allRegions[2].name()
         << nl << endl;

    if
    (
        (patchName == "front" ||
         patchName == "back") &&
        (patchType == "wall")
    )
    {
        Info << "Attempting to change patch "
             << patchName << " from type "
             << patchType << " to type empty"
             << nl << endl;

        allRegions[2].boundaryMesh().findPatchID("front");


        repatchMesh().changePatchType("back", "empty");

        Info << "Now patch "   << patchName
             << " is of type " << patchType
             << nl << endl;
    }
}

Info << "\nBoundary mesh patchTypes are now: " << allRegions[2].boundaryMesh().types() << nl << endl;
But we aren't able to read the mesh with repatchMesh().read(mesh);. This is the output we get


Code:
Reading mesh with repatchMesh() ... 

Boundary mesh read with repatchMesh(): 

--> FOAM FATAL ERROR: 
No mesh available. Probably mesh not yet read.

    From function const Foam::repatchMesh::rMesh& Foam::repatchMesh::mesh() const
    in file repatchMesh.H at line 185.

FOAM aborting
Which is an error in repatchMesh().mesh(). If we delete said line, we get


Code:
Reading mesh with repatchMesh() ... 

Boundary patches read with repatchMesh(): 
0
(
)


Read patchName: front, patchType: wall in region ferrofluid

Attempting to change patch front from type wall to type empty



--> FOAM FATAL ERROR: 
Can't find patch named back

    From function void Foam::repatchMesh::changePatchType(const Foam::word&, const Foam::word&)
    in file repatchMesh/repatchMesh.C at line 1243.

FOAM aborting
Which makes it obvious that repatchMesh().read(mesh); isn't working.



EDIT 3: Now tested

Code:
 Info << "Reading mesh with repatchMesh() ... " << nl << endl;
//repatchMesh().read(allRegions[2]);
repatchMesh().read(allRegions[2].boundaryMesh().mesh());
// repatchMesh().read(allRegions[2].boundary().mesh());

Info << "Boundary mesh read with repatchMesh(): "
<< repatchMesh().mesh() << nl << endl;

But both repatchMesh().read(allRegions[2].boundaryMesh().mesh()); and repatchMesh().read(allRegions[2].boundary().mesh()); result in the ERROR message: repatchMesh.mesh() isn't able to find a mesh.


Any help is appreciated.


Best Regards,

Last edited by ariedinger; September 29, 2022 at 13:33.
ariedinger is offline   Reply With Quote

Reply

Tags
boundary condition, patches, polymesh, programming, solver compilation


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
Illegal cell label -1, fluent3DMeshToFoam BenGher OpenFOAM 7 October 10, 2023 01:02
activeBaffleVelocity boundary condition ? om3ro OpenFOAM Programming & Development 10 November 17, 2020 00:26
twoPhaseEulerFoam confined plunging jet simulation failed ves OpenFOAM Running, Solving & CFD 2 June 17, 2020 06:08
rSF: p divergence in combustor (wt negative value) zonda OpenFOAM Pre-Processing 4 April 10, 2018 07:59
[Commercial meshers] Using starToFoam clo OpenFOAM Meshing & Mesh Conversion 33 September 26, 2012 05:04


All times are GMT -4. The time now is 07:42.