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

[AMR] Adaptive mesh refinement only within a cell set

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes
  • 1 Post By edwinrajeev
  • 3 Post By clapointe
  • 1 Post By edwinrajeev
  • 2 Post By clapointe

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 21, 2021, 11:22
Default [AMR] Adaptive mesh refinement only within a cell set
  #1
New Member
 
Edwin Rajeev
Join Date: Dec 2019
Location: Florida
Posts: 15
Rep Power: 7
edwinrajeev is on a distinguished road
Hi all,
I am currently running a 3D VOF simulation to study wave interaction with a breakwater structure. I intend to use AMR to refine the interface only in the breakwater region and not the entire domain.

Is it possible to use topoSet to define the region and use AMR only on the prescribed cell set?

Thank you and Regards
Aabadani likes this.
edwinrajeev is offline   Reply With Quote

Old   July 21, 2021, 12:48
Default
  #2
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
It is -- I've done something similar in the past, well the opposite, really, but it gets the job done if I remember correctly. Based on code from PDRFoam (the amr version) we can protect some initial cell set from refinement (this way the cell set doesn't need to be updated as the mesh changes, because it shouldn't change). It looks something like this :

Code:
    // Test : disable refinement for some cells
    PackedBoolList& protectedCell = refCast<dynamicRefineBalanceMultiRegionFvMesh>(mesh).protectedCell();

    if (protectedCell.empty())
    {
        protectedCell.setSize(mesh.nCells());
        protectedCell = 0;
    }

        cellSet protectedCells
        (
            IOobject
            (
                "protectedCells",
                "constant/polyMesh/sets",
                mesh,
                IOobject::MUST_READ,
                IOobject::NO_WRITE
            )
        );

        forAll (mesh.C(), celli)
        {
            if (protectedCells[celli])
            {
                protectedCell[celli] = 1;
            }
        }
That code would go before the mesh.update() call inside the solver (you can also use a custom bool to toggle the option). I imagine you could put it inside dynamicRefineMesh too, but I've not bothered.

Caelan
__________________
Public git repository : https://github.com/clapointe2011/public
clapointe is offline   Reply With Quote

Old   July 21, 2021, 14:07
Default
  #3
New Member
 
Edwin Rajeev
Join Date: Dec 2019
Location: Florida
Posts: 15
Rep Power: 7
edwinrajeev is on a distinguished road
Thank you so much Caelan. This is great. I will try and implement this in waves2Foam and see if it works properly.

Additionally, as you mentioned what would be your suggestion on implementing this in dynamicRefineMesh? This could be quite a handy tool from a general standpoint.

Thanks
Aabadani likes this.
edwinrajeev is offline   Reply With Quote

Old   July 21, 2021, 14:11
Default
  #4
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
Off the top of my head, you'd likely add similar code to the initialization bit of the dynamicRefineFvMesh code -- simply updating the protectedCells list inside there instead of on the solver end.

Caelan
Aabadani and edwinrajeev like this.
__________________
Public git repository : https://github.com/clapointe2011/public
clapointe is offline   Reply With Quote

Old   February 27, 2023, 21:31
Default Code tested in SprayFoam
  #5
Member
 
Jairo A. Gutiérrez S
Join Date: Nov 2014
Posts: 60
Rep Power: 12
jairoandres is on a distinguished road
Thank you a lot. I want to mention that I tested the code (used parts of it you placed in another forum thread), which worked well under sprayFoam (or sprayDyMFoam) in OpenFOAM V2012.

Requirements:

1. to #include "dynamicRefineFvMesh.H" just after the base library is included (dynamicFvMesh)
2. to #include "cellSet.H"
3. This part of the code "protectedCells" is the name of the cellSet you are creating in toposetDict:
Code:
cellSet protectedCells
4. The given code was OK for running on a single processor. Under parallel processing, I had to replace the location of the original cellSet after decomposition: ie:

Code:
    "protectedCells",
 "6e-05/polyMesh/sets",
It is not very practical, but it worked well. In this case, 6e-05 was the name of the folder created by snappyHexMesh when prerefining a structured mesh created with blockMeshDict. Otherwise, the solver could not find the folder "constant" as it was not created for each processor. Maybe someone else can come out with a better solution.

Here is the complete piece of code:

Code:
    bitSet& protectedCell = refCast<dynamicRefineFvMesh>(mesh).protectedCell();

if (protectedCell.empty())
{
    protectedCell.setSize(mesh.nCells());
    protectedCell = false;
}


        cellSet protectedCells
        (
            IOobject
            (
                "protectedCells",
                "6e-05/polyMesh/sets",
                mesh,
                IOobject::MUST_READ,
                IOobject::NO_WRITE
            )
        );

        forAll (mesh.C(), celli)
        {
            if (protectedCells[celli])
            {
                protectedCell[celli] = 1;
            }
        }
Again, my thanks. Best regards,

J.A. Gutiérrez.

Ps: Last piece of advice: Remember you can add multiple regions to the same cellSet using "new" for the first and then "add" for the other definitions, i.e.:
Code:
    {
        name    protectedCells;
        type    cellSet;
        action  new;
        source      cylinderToCell;
       p1         (0 0 0);
       p2         (0 -0.5 0);
       radius          0.125;
    }

 {
        name    protectedCells;
        type    cellSet;
        action  add;
        source      cylinderToCell;
       p1         (0 0 0);
       p2         (0 -0.2 0);
       radius          0.19;
       }
jairoandres is offline   Reply With Quote

Reply

Tags
adaptive mesh refinement, mesh, vof, waves


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
[snappyHexMesh] snappyHexMesh stuck when snap is turned on yukuns OpenFOAM Meshing & Mesh Conversion 3 February 2, 2021 14:05
SimpleFoam & Theater jipai OpenFOAM Running, Solving & CFD 3 June 18, 2019 11:11
[snappyHexMesh] Number of cells in mesh don't match with size of cellLevel colinB OpenFOAM Meshing & Mesh Conversion 14 December 12, 2018 09:07
[snappyHexMesh] Removing further cells after SHM zonda OpenFOAM Meshing & Mesh Conversion 14 September 15, 2017 08:50
[snappyHexMesh] snappyHexMesh won't work - zeros everywhere! sc298 OpenFOAM Meshing & Mesh Conversion 2 March 27, 2011 22:11


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