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

[Other] Mirror CellZones

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 26, 2017, 11:04
Default Mirror CellZones
  #1
New Member
 
Roberto
Join Date: May 2016
Posts: 17
Rep Power: 9
RobertoCirolini is on a distinguished road
Dear Foamers,

I've been looking for a way to mirror my cellZones. I want to generate a cylinder, however I have just managed to create a veery thin slice of it, if you see the picture below, the red part is my porous medium. The fluid flows from the left to the right and I would like to mirror this slice till I get the full cylinder. However, I realized that when I mirror my mesh the cellZones, in this case porous medium, are not mirrored. Is there somebody who could please give me a hint? I generated the mesh using blockMeshDict and I am trying different ways to obtain this full cylinder with the CellZones, but I am stuck in this part...

Thank you!!!

Roberto
Attached Images
File Type: png slice_cylinder.png (3.7 KB, 20 views)
RobertoCirolini is offline   Reply With Quote

Old   September 16, 2022, 10:09
Question
  #2
F42
New Member
 
Join Date: Jun 2018
Posts: 20
Rep Power: 7
F42 is on a distinguished road
Hi Roberto, did you or anybody find a solution to that?
I want to mirror a mesh for a multi region case.

Mirroring the whole mesh works but I cannot run splitMeshRegions to split the mesh into regions because the cellZones are not mirrored.


Thank you, any hints are appreciated.
F42 is offline   Reply With Quote

Old   September 19, 2022, 10:24
Default
  #3
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 339
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
This is actually quite straight forward: loop over your cells belonging to a set or zone, and find its mirror image.


Here's some code, which has last been used using OpenFOAM 6 and/or 7.


Note that I will not provide any support.



Code:
//     mirrorCellSets                             
                           
                            #include "argList.H"                             #include "Time.H"                              
                            #include "volFields.H"                              
                            #include "plane.H"                              
                            #include "topoSetSource.H"                             #include "cellSet.H"                             #include "faceSet.H"                             #include "pointSet.H"                             #include "cellZoneSet.H"                              
                            #include "IOobjectList.H"                             #include "SortableList.H"                              
                            using namespace Foam;                              
                            // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //                              
                            int main(int argc, char *argv[])                             {                                 argList::addBoolOption                                 (                                     "verbose",                                     "be more talkative"                                 );                                 argList::addOption                                 (                                     "dict",                                     "file",                                     "specify alternative dictionary for the mirrorMesh description"                                 );                                 argList::addOption                                 (                                     "excludeSet",                                     "name",                                     "exclude the specified cellSet from mirroring"                                 );                                 
                                #include "setRootCase.H"                                 #include "createTime.H"                                 #include "createMesh.H"                                 
                                const bool verbose = args.optionFound("verbose");                                 
                                
                                
                                const word dictName("mirrorMeshDict");                                 
                                fileName dictPath = dictName;                              
                                // Check if the dictionary is specified on the command-line                                 if (args.optionFound("dict"))                                 {                                     dictPath = args["dict"];                              
                                    dictPath =                                     (                                         isDir(dictPath)                                       ? dictPath/dictName                                       : dictPath                                     );                                 }                                 
                                
                                // read the excludeSetName from command-line                                 word excludeSetName;                                 if (args.optionReadIfPresent("excludeSet", excludeSetName))                                 {                                     Info<< "Excluding " << excludeSetName << " from mirroring." << nl << endl;                                 }                              
                                
                                // read mirrorMeshDict and create mirror plane                                 IOdictionary mirrorMeshDict                                 (                                     IOobject                                     (                                         dictPath,                                         runTime.system(),                                         mesh,                                         IOobject::MUST_READ_IF_MODIFIED,                                         IOobject::NO_WRITE                                     )                                 );                                 
                                
                                plane mirrorPlane(mirrorMeshDict);                                 
                                
                                // get all cell centroid positions                                 const volVectorField& cellCenters(mesh.C());                                 
                                
                                // Process cell sets                                 Info<< "Listing all cell sets." << endl;                                 
                                // Search for list of objects for the time of the mesh                                 word setsInstance = runTime.findInstance                                 (                                     polyMesh::meshSubDir/"sets",                                     word::null,                                     IOobject::MUST_READ,                                     mesh.facesInstance()                                 );                              
                                IOobjectList objects(mesh, setsInstance, polyMesh::meshSubDir/"sets");                                 IOobjectList cellObjects(objects.lookupClass(cellSet::typeName));                                 
                                forAllConstIter(IOobjectList, cellObjects, iter)                                 {                                     // Not in memory. Load it.                                     cellSet set(*iter());                                     SortableList<label> cellLabels(set.toc());                              
                                    label zoneID = mesh.cellZones().findZoneID(set.name());                                     
                                    // skip the excluded set                                     if (set.name() == excludeSetName)                                     {                                         continue;                                     }                                     
                                    if (zoneID == -1)                                     {                                         Info<< nl << "Operating on set " << set.name() << endl;                                     }                                     else                                     {                                         Info<< nl << "Operating on set/zone " << set.name() << endl;                                     }                                     
                                    if (verbose)                                     {                                         Info<< "    " << set.type() << " "                                             << set.name()                                             << " now size "                                             << returnReduce(set.size(), sumOp<label>())                                             << endl;                                     }                                     
                                    
                                    labelList sourceCells(set.size());                                     label nNewCells = 0;                                     
                                    forAll(set.toc(), i)                                     {                                         label cellI = set.toc()[i];                                         
                                        // mirror cell centroid's position and find corresponding cell                                         scalar alpha =                                             mirrorPlane.normalIntersect                                             (                                                 cellCenters.internalField()[cellI],                                                 mirrorPlane.normal()                                             );                                         
                                        label newCellI = mesh.findCell(cellCenters.internalField()[cellI] + 2.0*alpha*mirrorPlane.normal());                                         
                                        
                                        sourceCells[nNewCells] = newCellI;                                         nNewCells++;                                     }                                     
                                    // add found cells to current cellSet                                     dictionary sourceDict01;                                     sourceDict01.name() = "sourceInfo";                                     sourceDict01.set("value", sourceCells);                                     
                                    autoPtr<topoSetSource> sourceCellSet = topoSetSource::New                                     (                                         "labelToCell",                                         static_cast<polyMesh&>(mesh),                                         sourceDict01                                     );                                     
                                    sourceCellSet().applyToSet(topoSetSource::NEW, set);                                     
                                    if (verbose)                                     {                                         Info<< "    " << set.type() << " "                                             << set.name()                                             << " now size "                                             << returnReduce(set.size(), sumOp<label>())                                             << nl << endl;                                     }                                     
                                    set.sync(mesh);                                     set.write();                                     
                                    
                                    // add cells to cellZone                                     if (zoneID > -1)                                     {                                         // read cellZoneSet                                         autoPtr<topoSet> currentZone = topoSet::New                                         (                                             "cellZoneSet",                                             static_cast<polyMesh&>(mesh),                                             set.name()                                         );                                         if (verbose and currentZone.valid())                                         {                                             Info<< "    " << currentZone().type() << " "                                                 << currentZone().name()                                                 << " now size "                                                 << returnReduce(currentZone().size(), sumOp<label>())                                                 << endl;                                         }                                         
                                        // build source topoSet                                         dictionary sourceDict;                                         sourceDict.name() = "sourceInfo";                                         sourceDict.set("set", mesh.cellZones()[zoneID].name());                                         
                                        autoPtr<topoSetSource> source = topoSetSource::New                                         (                                             "setToCellZone",                                             static_cast<polyMesh&>(mesh),                                             sourceDict                                         );                                         
                                        
                                        // add the source to current zone                                         source().applyToSet(topoSetSource::ADD, currentZone());                                         
                                        if (verbose and currentZone.valid())                                         {                                             Info<< "    " << currentZone().type() << " "                                                 << currentZone().name()                                                 << " now size "                                                 << returnReduce(currentZone().size(), sumOp<label>())                                                 << endl;                                         }                                         
                                        currentZone().sync(mesh);                                         currentZone().write();                                     }                                     
                                }                                 
                             
                                Info<< "End\n" << endl;                                 
                                
                                 return 0;
                             }

Somehow, the pretty formatting got lost in copy&paste.
GerhardHolzinger is offline   Reply With Quote

Old   October 6, 2022, 12:20
Default
  #4
F42
New Member
 
Join Date: Jun 2018
Posts: 20
Rep Power: 7
F42 is on a distinguished road
Thanks you! Sounds good



I would love to try that.
The code is actually pretty blown up .
Would you mind to append the original file?
F42 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



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