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

[Other] 2D adaptive Mesh Refinement

Register Blogs Community New Posts Updated Threads Search

Like Tree38Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 1, 2017, 09:55
Default
  #21
New Member
 
XuDongNa
Join Date: Feb 2012
Location: Harbin Heilongjiang Province,China
Posts: 11
Rep Power: 14
supersoldier is on a distinguished road
Send a message via ICQ to supersoldier
Quote:
Originally Posted by ahmad12982 View Post
2D+axisy. dynamic mesh refinement can be found in the link below.
http://faculty.yu.edu.jo/ahmad_a/Lis.../AllItems.aspx
Thank you so much! Excelent work
supersoldier is offline   Reply With Quote

Old   March 15, 2017, 08:59
Default
  #22
Member
 
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10
OlegSutyrin is on a distinguished road
In my previous post, I have somehow managed to put wrong version of some file(s) in the archive. I cannot find the way to edit that post, so correct version of the archive is attached here.
Attached Files
File Type: zip dynamicRefineFvMesh2D_OpenFOAM4_fixed.zip (43.2 KB, 220 views)
klilla likes this.
OlegSutyrin is offline   Reply With Quote

Old   March 27, 2017, 07:29
Default
  #23
New Member
 
David Kinast
Join Date: Nov 2016
Posts: 15
Rep Power: 9
david112 is on a distinguished road
Hi Oleg,
I want to try your dynamicRefineFvMesh2D tool for OpneFoam4, but got problems while compiling it. Doint exactly aus you described it I get
Code:
In file included from dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.C:26:0:
dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.H:80:22: fatal error: hexRef2D.H: Datei oder Verzeichnis nicht gefunden
compilation terminated.
/opt/openfoam4/wmake/rules/General/transform:8: die Regel für Ziel „/opt/openfoam4/platforms/linux64GccDPInt32Opt/src/dynamicFvMesh/dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.o“ scheiterte
make: *** [/opt/openfoam4/platforms/linux64GccDPInt32Opt/src/dynamicFvMesh/dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.o] Fehler 1
when the wmake command is exequted in the /opt/openfoam4/src/dynamicFvMesh folder.

Do you know what I'm doing wrong?

Greetings
David
david112 is offline   Reply With Quote

Old   March 27, 2017, 08:00
Default
  #24
Member
 
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10
OlegSutyrin is on a distinguished road
david112,
my mistake! You need to put hexRef2D codes to the place before trying to compile 'wmaking' dynamicFvMesh folder. Here is updated and extended installation guide (still assuming you installed OF4 into '/opt/openfoam4/'):

0. go into root mode: run 'sudo -i'

1. put 'dynamicRefineFvMesh2D' folder into '/opt/openfoam4/src/dynamicFvMesh/' folder;
add 'dynamicRefineFvMesh2D/dynamicRefineFvMesh2D.C' line into '/opt/openfoam4/src/dynamicFvMesh/Make/files';

2. put 'hexRef2D' folder into 'opt/openfoam4/src/dynamicMesh/polyTopoChange/polyTopoChange/' folder;
add 'polyTopoChange/polyTopoChange/hexRef2D/hexRef2D.C' line into '/opt/openfoam4/src/dynamicMesh/Make/files';

3. compile code:
'cd /opt/openfoam4/src/dynamicFvMesh/'
'wmake'
cd '/opt/openfoam4/src/dynamicMesh/'
'wmake'
This works for me. Hope it will work for you too!
OlegSutyrin is offline   Reply With Quote

Old   March 28, 2017, 03:22
Default
  #25
New Member
 
David Kinast
Join Date: Nov 2016
Posts: 15
Rep Power: 9
david112 is on a distinguished road
Thank you for the quick answer. Quiet easy... I when tried it yesterday in this order I forgot to change to root mode. Now it seems to work for me too.

I will try some 2D cases but atually I want to adapt to a 3D-Case for refining the Mesh in 2 directions. Do you know whether anyone did that before?

Greetings
David
david112 is offline   Reply With Quote

Old   March 28, 2017, 03:37
Default
  #26
Member
 
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10
OlegSutyrin is on a distinguished road
David, I believe that no one had posted such code. Obviously, if I found such code here, I would use it instead of aforementioned 2D libraries: refining only in 2 dimensions is exactly what is needed in 2D cases.
OlegSutyrin is offline   Reply With Quote

Old   March 28, 2017, 07:37
Default
  #27
New Member
 
David Kinast
Join Date: Nov 2016
Posts: 15
Rep Power: 9
david112 is on a distinguished road
Hi Oleg,
the compiling works now without errors, but the solver doesnt run. I got this error while running the pimpleDyMFoam solver:
Code:
Starting time loop

Courant Number mean: 0.04210927 max: 0.1690338
deltaT = 2.4e-05
Time = 2.4e-05

Selected 1373 cells for refinement out of 50868.
Refined from 50868 to 54987 cells.
#0  Foam::error::printStack(Foam::Ostream&) at ??:?
#1  Foam::sigSegv::sigHandler(int) at ??:?
#2  ? in "/lib/x86_64-linux-gnu/libc.so.6"
#3  Foam::dynamicRefineFvMesh2D::refine(Foam::List<int> const&) at ??:?
#4  Foam::dynamicRefineFvMesh2D::update() at ??:?
#5  ? at ??:?
#6  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#7  ? at ??:?
Speicherzugriffsfehler (Speicherabzug geschrieben)
perhaps you can solve my problem es fast as the other one.
greetings David
david112 is offline   Reply With Quote

Old   March 28, 2017, 07:55
Default
  #28
Member
 
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10
OlegSutyrin is on a distinguished road
David,
I have tested this lib only on the simplest meshes (rectangular, even-sized cells) and rhoCentralFoam solver, so cannot predict it's behavior in more complex cases. I remember it kind of randomly (after thousands of successful time steps and un/refinements) crashing on forwardStep tutorial, though. But that was with my custom solver, so I'm not sure the problem was in the refinement lib.
Don't know why your case crashes, sorry :-(
OlegSutyrin is offline   Reply With Quote

Old   March 28, 2017, 11:27
Default
  #29
New Member
 
Luca Cornolti
Join Date: Jun 2016
Location: Switzerland
Posts: 13
Rep Power: 9
Luca Cornolti is on a distinguished road
Checking some computation with my code in foam ext 3.2, it seems that sometimes the simulations crash when the fields are mapped from the old mesh to the new one.
This problem rarely appears with planar configurations, while it takes place more often when wedges are considered.

Anyway, I have no clear idea about the reason of this, as these events are quite random.
Luca Cornolti is offline   Reply With Quote

Old   March 29, 2017, 03:43
Default
  #30
MSF
New Member
 
Join Date: Apr 2014
Location: Germany
Posts: 24
Rep Power: 12
MSF is on a distinguished road
Hi,

I tried to compile the library from Ahmad but I get the following error message(OF 2.2.2):

Code:
g++: error: unrecognized command line option ‘-fvMotionSolver’
Anyone an idea what that means?

Best,
Moritz
MSF is offline   Reply With Quote

Old   May 10, 2017, 05:57
Default
  #31
New Member
 
David Kinast
Join Date: Nov 2016
Posts: 15
Rep Power: 9
david112 is on a distinguished road
Hi Oleg and all other interested!

I took the code from Oleg and tried to change it for my purpose. So I changed the dicision which Face has to be cutted in 4 faces. Instead of looking for empty faces the code now looks for faces where all points have the same y-position.
here you can see the changes:
Code:
    boolList isDivisibleFace(mesh_.nFaces(), false); //OS: change to PackedBoolList?
    boolList isDivisibleEdge(mesh_.nEdges(), false); //OS: change to PackedBoolList?
    boolList isXZPlaneFace2(mesh_.nFaces(), true);

    
    // deciding which face is to split in 4 faces
    for (label facei = 0; facei < mesh_.nFaces(); facei++)
    {
        const label & patchID = mesh_.boundaryMesh().whichPatch(facei);
        
        //my code ----------------------------------------------------------------------
        const Foam::face theFace = mesh_.faces()[facei];
        // comparing the y-values of every point of the face        
        for (int myPointCounter1=0; myPointCounter1 < 4;myPointCounter1++)
        {
            for (int myPointCounter2=0; myPointCounter2 < 4;myPointCounter2++)
            {             
                if (myPointCounter1 > myPointCounter2 )    // to get every combination only once            
                {
                    const Foam::Vector<double> point1 = mesh_.points()[theFace[myPointCounter1]];
                    const Foam::Vector<double> point2 = mesh_.points()[theFace[myPointCounter2]];
                    scalar yValuePoint1 = point1.y(); 
                    scalar yValuePoint2 = point2.y();            
                    /*if (debug)  {Pout<< "comparisons between"
                                     << yValuePoint1 << " and " 
                                     << yValuePoint2 << endl;}*/ 
                    if ((yValuePoint1 - yValuePoint2) != 0 )
                    {
                        isXZPlaneFace2[facei] = false;
                    }
                }
            }
        }


        // checking for 2D empty faces not used in this case 
    /*    if (mesh_.boundaryMesh()[patchID].type() == "empty" || mesh_.boundaryMesh()[patchID].type() == "wedge")
        {
            isXZPlaneFace[facei] = true;
        }
        if (debug)  {Pout<< "checking face: " << myFaceCounter << endl;} 
        myFaceCounter++; */
        
        //if (isA<emptyPolyPatch>(mesh_.boundaryMesh()[patchID])


        if (debug)  
        {
            Pout<< "facei: " << facei << endl;
            Pout<< "isXZPlaneFace2[facei]: " << isXZPlaneFace2[facei] << endl;
        }

        if (isXZPlaneFace2[facei] == true) //OS: added wedge type
        {
            isDivisibleFace[facei] = true;
            const labelList& fEdges = mesh_.faceEdges(facei);

            forAll(fEdges, i)
            {
                label edgej = fEdges[i];
                isDivisibleEdge[edgej] = true;
            }
        }
    }
That works in the easiest cases, but still leads to problems in 3D meshes.
A mesh consiting of a single cell will be splitted perfectly. Also meshes with only 1 cell in the y-direction work fine (case1unrefined.png -> case1refined.png).

When getting more cells in y-direction the order of some faces isn't correct anymore. (case2unrefined.png -> case2refined.png). Perhaps it helpes to find the mistake if we do more cells in the y-direction. Here you can see, that the first cell is spitted correct, at all the following cells one of the new split cells is uncorrect for the last cell two of the new splitted cells are uncorrect (case3 refined.png).


Do you have an idea where in the code I should look for solving this problem?
Attached Images
File Type: png Case1unrefined.png (13.3 KB, 37 views)
File Type: png case1refined.png (17.7 KB, 32 views)
File Type: png case2unrefined.png (6.5 KB, 30 views)
File Type: png case2refined.png (8.5 KB, 36 views)
File Type: png case3refined.png (10.3 KB, 38 views)
david112 is offline   Reply With Quote

Old   May 10, 2017, 07:14
Default
  #32
New Member
 
David Kinast
Join Date: Nov 2016
Posts: 15
Rep Power: 9
david112 is on a distinguished road
I looked into the faces, owner and neighbour files in the polyMesh folder of case2 and figured out where the mistakes happen. Here are the corrected files. Perhaps that helps to find the mistake.
faces
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.1                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       faceList;
    location    "2.4e-05/polyMesh";
    object      faces;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


36
(
4(2 16 24 15)
4(13 25 24 16)
4(24 25 12 15)
4(16 24 26 19)//4(15 24 26 19)
4(26 24 15 18)//4(26 24 16 18)
4(21 25 24 22)
4(8 22 24 16)
4(14 25 24 17)
4(9 17 24 22)
4(3 15 24 17)
4(22 24 26 23)//4(17 24 26 23)
4(17 24 26 20)//4(22 24 26 20)
4(0 12 25 13)
4(1 14 25 12)
4(7 21 25 14)
4(6 13 25 21)
4(4 19 26 18)
4(10 23 26 19)
4(11 20 26 23)
4(5 18 26 20)
4(0 13 16 2)
4(2 16 19 4)
4(8 16 13 6)
4(10 19 16 8)
4(3 17 14 1)
4(5 20 17 3)
4(7 14 17 9)
4(9 17 20 11)
4(2 15 12 0)
4(4 18 15 2)
4(1 12 15 3)
4(3 15 18 5)
4(6 21 22 8)
4(8 22 23 10)
4(9 22 21 7)
4(11 23 22 9)
)


// ************************************************************************* //
owner
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.1                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       labelList;
    note        "nPoints:27  nCells:8  nFaces:36  nInternalFaces:12";
    location    "2.4e-05/polyMesh";
    object      owner;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


36
(
0
0
0
1
1
2
2
3
3
4
5
6
0
4
3
2
1
5
6
7
0
1
2
5
4
7
3
6
0
1
4
7//5
2
5//7
3
6
)


// ************************************************************************* //
neighbour
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.1                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       labelList;
    note        "nPoints:27  nCells:8  nFaces:36  nInternalFaces:12";
    location    "2.4e-05/polyMesh";
    object      neighbour;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


12
(
1
2
4
5
7
3
5//7
4
6
7//5
6
7
)


// ************************************************************************* //
greetings,
David

Last edited by david112; May 10, 2017 at 07:21. Reason: added missing words
david112 is offline   Reply With Quote

Old   May 12, 2017, 14:35
Default
  #33
Member
 
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10
OlegSutyrin is on a distinguished road
Hi, David!
Unfortunately, I'm not able to perform proper analysis of the code, because it's still too complex for me. But one thing have catched my eye:
Quote:
if ((yValuePoint1 - yValuePoint2) != 0 )
As a general rule, comparison between two floating point values should not be done in that way, since it will almost always return true due to floating point computation error. The proper way would be like
Quote:
if (fabs(yValuePoint1 - yValuePoint2) < eps )
where "eps" is something like 0.00000001. Although, I'm not sure that in OpenFOAM the operator "!=" for "scalar" class is not already overloaded with such functionality.
OlegSutyrin is offline   Reply With Quote

Old   May 15, 2017, 10:17
Default
  #34
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12
ssss is on a distinguished road
Quote:
Originally Posted by OlegSutyrin View Post
Hi, David!
with such functionality.
Hi @OlegSutyrin, first of all thank you very much for adapting the code to OF4! In your posts you say that it supports wedge meshes, but I can't see any mention of it inside the code. Moreover, when I run a wedge simulation I observe 3D refinement in the wedge direction.Do you know if there something extra I should add to my dict for wedge simulations?

Thank you very much for your help
ssss is offline   Reply With Quote

Old   May 15, 2017, 10:53
Default
  #35
New Member
 
David Kinast
Join Date: Nov 2016
Posts: 15
Rep Power: 9
david112 is on a distinguished road
Quote:
Originally Posted by OlegSutyrin View Post
Hi, David!
Unfortunately, I'm not able to perform proper analysis of the code, because it's still too complex for me. But one thing have catched my eye:

As a general rule, comparison between two floating point values should not be done in that way, since it will almost always return true due to floating point computation error. The proper way would be like where "eps" is something like 0.00000001. Although, I'm not sure that in OpenFOAM the operator "!=" for "scalar" class is not already overloaded with such functionality.
Hi Oleg,

good point. I fixed that.

the problems I mentioned befor where caused by the diffent orientation of the faces which where cutted into 4 faces. So, checking which faces are owned and which neighbours of a cell and reordering the points if neccesary solved that. Now i have problems with the cells at the border of the refinement, but hope for sol

@ssss:
in the hexRef2D.C file there is a line saying:
Code:
if (mesh_.boundaryMesh()[patchID].type() == "empty" || mesh_.boundaryMesh()[patchID].type() == "wedge")
which should lead to a same treatment of wedge and empty faces. Does it work for you with empty faces?
david112 is offline   Reply With Quote

Old   May 15, 2017, 11:04
Default
  #36
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 12
ssss is on a distinguished road
Hi @david112 I swear that I searched both .C files for the wedge string, but it seems I made a mistake somewhere. It is true that wedge and empty patches are treated equally. However, I observe 3D refinement in my ("complex") axisymmetric testcase while in simple 2D with empty BCs simulations there is no refinement at all in the empty direction, so maybe some additions need to be added to the code to manage wedge meshes...
ssss is offline   Reply With Quote

Old   May 15, 2017, 11:31
Default
  #37
Member
 
Oleg Sutyrin
Join Date: Feb 2016
Location: Russia
Posts: 41
Rep Power: 10
OlegSutyrin is on a distinguished road
Hi, @ssss!
I've just run a simple test for 2D wedge refining, it works OK (but, as I mentioned before, it ignores cells that adjoin symmetry axis, since they are not hexahedrons): there was no refinement in the 3rd axis. I have no idea why that doesn't work for you :-(

Quote:
Originally Posted by ssss View Post
However, I observe 3D refinement in my ("complex") axisymmetric testcase while in simple 2D with empty BCs simulations there is no refinement at all in the empty direction, so maybe some additions need to be added to the code to manage wedge meshes...
OlegSutyrin is offline   Reply With Quote

Old   February 19, 2018, 07:01
Default
  #38
New Member
 
Jung Min Oh
Join Date: Feb 2018
Posts: 1
Rep Power: 0
jmo0902 is on a distinguished road
Thanks for your contribution.
However, when I compile your files in OpenFoam 5.0 and 4.1, it gave me many errors. Can you give me some tips to debug?

Quote:
Originally Posted by ahmad12982 View Post
2D+axisy. dynamic mesh refinement can be found in the link below.
http://faculty.yu.edu.jo/ahmad_a/Lis.../AllItems.aspx
jmo0902 is offline   Reply With Quote

Old   August 21, 2018, 06:01
Default
  #39
New Member
 
Luca Cornolti
Join Date: Jun 2016
Location: Switzerland
Posts: 13
Rep Power: 9
Luca Cornolti is on a distinguished road
Dear all,

after some time I was able to work again on this topic and I completed a class which is able to refine 2D cases for both planar and axis symmetric (wedge) configurations.

Attached you can find the developed classes for OpenFOAM-6, foam-extend-4.0 and OpenFOAM-v1806.

The folders are arranged to be copied into the user directory ($WM_PROJECT_USER_DIR).

In the OpenFOAM-6 version there are also two tests for planar and wedge configurations.

I tested quite extensively the foam-extend-4.0 version.
The OpenFOAM-6 version should work as well as the code is almost the same, but I tested it only with the attached two tests as I don’t use the foundation version a lot.
The same is true for the v1806 version.


I hope that everything will work properly.

Note that a problem reported previously by me in this thread regarding mapping was solved by following the suggestion given in:

mapFields major bug
Attached Files
File Type: gz meshRefinement2D_of6.tar.gz (51.0 KB, 202 views)
File Type: gz meshRefinement2D_ofext4.tar.gz (40.4 KB, 90 views)
File Type: gz meshRefinement2D_ofv1806.tar.gz (43.5 KB, 132 views)

Last edited by Luca Cornolti; September 10, 2018 at 01:52. Reason: Updating
Luca Cornolti is offline   Reply With Quote

Old   September 12, 2018, 16:15
Default
  #40
New Member
 
Qi Yang
Join Date: Oct 2017
Posts: 6
Rep Power: 8
qiyang is on a distinguished road
Quote:
Originally Posted by Luca Cornolti View Post
Dear all,

after some time I was able to work again on this topic and I completed a class which is able to refine 2D cases for both planar and axis symmetric (wedge) configurations.

Attached you can find the developed classes for OpenFOAM-6, foam-extend-4.0 and OpenFOAM-v1806.

The folders are arranged to be copied into the user directory ($WM_PROJECT_USER_DIR).

In the OpenFOAM-6 version there are also two tests for planar and wedge configurations.

I tested quite extensively the foam-extend-4.0 version.
The OpenFOAM-6 version should work as well as the code is almost the same, but I tested it only with the attached two tests as I don’t use the foundation version a lot.
The same is true for the v1806 version.


I hope that everything will work properly.

Note that a problem reported previously by me in this thread regarding mapping was solved by following the suggestion given in:

mapFields major bug
Dear Luca Cornolti,

I am now also working on utilizing 1D AMR method in OpenFOAM, I want to know that could the 2D dynamicRefineFvMesh you write changed into 1D dynamicRefineFvMesh? Thanks.
qiyang 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
[snappyHexMesh] SnappyHexMesh for internal Flow vishwa OpenFOAM Meshing & Mesh Conversion 24 June 27, 2016 08:54
[Workbench] mesh refinement of vortex tube using workbench aqsa1590 ANSYS Meshing & Geometry 3 December 25, 2014 08:57
[snappyHexMesh] snapEdge - failure Tobi OpenFOAM Meshing & Mesh Conversion 33 March 18, 2014 03:58
Mesh motion with Translation & Rotation Doginal CFX 2 January 12, 2014 06:21
Icemcfd 11: Loss of mesh from surface mesh option? Joe CFX 2 March 26, 2007 18:10


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