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

Need help with Adaptive Mesh Refinement

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 30, 2024, 13:07
Default Need help with Adaptive Mesh Refinement
  #1
New Member
 
Shawn Sri
Join Date: Dec 2024
Posts: 1
Rep Power: 0
astro_guy is on a distinguished road
Hello,
I am a new OpenFOAM user and will be applying it for supersonic flow simulations. To understand more on the software, I am trying to apply AMR to capture shock in the sonicFoam forwardStep tutorial case.

The case runs normally and produces the shock as well, however, the dynamicMeshDict that I have written does not seem to be doing anything. I am trying to refine the mesh based on velocity magnitude but OpenFOAM simply skips it and there is no mention of AMR check in the output as well.

Also made changes to the controlDict file so OpenFOAM knows AMR is implemented and placed dynamicMeshDict in the constant folder.

Below I have put my dynamicMeshDict, controlDict and sample output.
Can someone kindly help me implement AMR for shock capture in this case?
Thank you.

dynamicMeshDict -

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2312                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      dynamicMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dynamicFvMesh   dynamicRefineFvMesh;

dynamicRefineFvMeshCoeffs
{
    // How often to refine
    refineInterval  1;

    // Field to be refinement on
    field           mag(U);

    // Refine field inbetween lower..upper
    lowerRefineLevel 2.5;
    upperRefineLevel 2.8;

    // If value < unrefineLevel unrefine
    unrefineLevel   2.4
;
    // Have slower than 2:1 refinement
    nBufferLayers   1;

    // Refine cells only up to maxRefinement levels
    maxRefinement   2;

    // Stop refinement if maxCells reached
    maxCells        40000;

    // Flux field and corresponding velocity field. Fluxes on changed
    // faces get recalculated by interpolating the velocity. Use 'none'
    // on surfaceScalarFields that do not need to be reinterpolated.
    correctFluxes   yes;

    // Write the refinement level as a volScalarField
    dumpLevel       true;
}


// ************************************************************************* //


controlDict -

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2312                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     sonicFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         10;

deltaT          0.002;

writeControl    runTime;

writeInterval   0.5;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;

//Dynamic mesh handling

dynamicFvMesh	yes;

functions
{
    libs            (fieldFunctionObjects);

    Ma
    {
        type            MachNo;
        executeControl  writeTime;
        writeControl    writeTime;
    }
}


// ************************************************************************* //

Sample output log -

Time = 10

Courant Number mean: 0.166934 max: 0.250001
diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
PIMPLE: iteration 1
smoothSolver: Solving for Ux, Initial residual = 0.000262107, Final residual = 3.48538e-08, No Iterations 1
smoothSolver: Solving for Uy, Initial residual = 0.000317927, Final residual = 7.95802e-08, No Iterations 1
smoothSolver: Solving for e, Initial residual = 0.00114365, Final residual = 9.90534e-06, No Iterations 1
smoothSolver: Solving for p, Initial residual = 0.00118706, Final residual = 8.06804e-08, No Iterations 2
diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 7.7176e-08, global = 4.93997e-08, cumulative = 0.000688502
PIMPLE: iteration 2
smoothSolver: Solving for Ux, Initial residual = 0.000152919, Final residual = 1.2346e-10, No Iterations 1
smoothSolver: Solving for Uy, Initial residual = 0.000110653, Final residual = 3.15338e-10, No Iterations 1
smoothSolver: Solving for e, Initial residual = 0.001027, Final residual = 8.37661e-06, No Iterations 1
smoothSolver: Solving for p, Initial residual = 0.00109848, Final residual = 1.05704e-07, No Iterations 2
diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 1.01108e-07, global = 4.5618e-09, cumulative = 0.000688507
ExecutionTime = 52.68 s ClockTime = 76 s

functionObjects::MachNo Ma writing field: Ma
End
Attached Images
File Type: jpg Capture.JPG (39.3 KB, 9 views)
astro_guy is offline   Reply With Quote

Old   January 11, 2025, 05:50
Default
  #2
Member
 
Amirhossein Taran
Join Date: Sep 2016
Location: Dublin, Ireland
Posts: 60
Rep Power: 10
amirhosseintaran is on a distinguished road
Quote:
Originally Posted by astro_guy View Post
Hello,
I am a new OpenFOAM user and will be applying it for supersonic flow simulations. To understand more on the software, I am trying to apply AMR to capture shock in the sonicFoam forwardStep tutorial case.

The case runs normally and produces the shock as well, however, the dynamicMeshDict that I have written does not seem to be doing anything. I am trying to refine the mesh based on velocity magnitude but OpenFOAM simply skips it and there is no mention of AMR check in the output as well.

Also made changes to the controlDict file so OpenFOAM knows AMR is implemented and placed dynamicMeshDict in the constant folder.

Below I have put my dynamicMeshDict, controlDict and sample output.
Can someone kindly help me implement AMR for shock capture in this case?
Thank you.

dynamicMeshDict -

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2312                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      dynamicMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dynamicFvMesh   dynamicRefineFvMesh;

dynamicRefineFvMeshCoeffs
{
    // How often to refine
    refineInterval  1;

    // Field to be refinement on
    field           mag(U);

    // Refine field inbetween lower..upper
    lowerRefineLevel 2.5;
    upperRefineLevel 2.8;

    // If value < unrefineLevel unrefine
    unrefineLevel   2.4
;
    // Have slower than 2:1 refinement
    nBufferLayers   1;

    // Refine cells only up to maxRefinement levels
    maxRefinement   2;

    // Stop refinement if maxCells reached
    maxCells        40000;

    // Flux field and corresponding velocity field. Fluxes on changed
    // faces get recalculated by interpolating the velocity. Use 'none'
    // on surfaceScalarFields that do not need to be reinterpolated.
    correctFluxes   yes;

    // Write the refinement level as a volScalarField
    dumpLevel       true;
}


// ************************************************************************* //


controlDict -

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v2312                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     sonicFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         10;

deltaT          0.002;

writeControl    runTime;

writeInterval   0.5;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;

//Dynamic mesh handling

dynamicFvMesh	yes;

functions
{
    libs            (fieldFunctionObjects);

    Ma
    {
        type            MachNo;
        executeControl  writeTime;
        writeControl    writeTime;
    }
}


// ************************************************************************* //

Sample output log -

Time = 10

Courant Number mean: 0.166934 max: 0.250001
diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
PIMPLE: iteration 1
smoothSolver: Solving for Ux, Initial residual = 0.000262107, Final residual = 3.48538e-08, No Iterations 1
smoothSolver: Solving for Uy, Initial residual = 0.000317927, Final residual = 7.95802e-08, No Iterations 1
smoothSolver: Solving for e, Initial residual = 0.00114365, Final residual = 9.90534e-06, No Iterations 1
smoothSolver: Solving for p, Initial residual = 0.00118706, Final residual = 8.06804e-08, No Iterations 2
diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 7.7176e-08, global = 4.93997e-08, cumulative = 0.000688502
PIMPLE: iteration 2
smoothSolver: Solving for Ux, Initial residual = 0.000152919, Final residual = 1.2346e-10, No Iterations 1
smoothSolver: Solving for Uy, Initial residual = 0.000110653, Final residual = 3.15338e-10, No Iterations 1
smoothSolver: Solving for e, Initial residual = 0.001027, Final residual = 8.37661e-06, No Iterations 1
smoothSolver: Solving for p, Initial residual = 0.00109848, Final residual = 1.05704e-07, No Iterations 2
diagonal: Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
time step continuity errors : sum local = 1.01108e-07, global = 4.5618e-09, cumulative = 0.000688507
ExecutionTime = 52.68 s ClockTime = 76 s

functionObjects::MachNo Ma writing field: Ma
End
Hello,

It is an interesting point, maybe dynamicRefineFvMesh doesnt accept mag(U)
as a valid field, Could you try with U ?

Alternatively, you could create a new field for mag(U) during the solution and register this field to the mesh, then it would be possible to use it in dynamicRefineFvMesh I think.


Regards,
Amir.
amirhosseintaran is offline   Reply With Quote

Old   January 16, 2025, 09:15
Default
  #3
Member
 
Lorenzo
Join Date: Apr 2020
Location: Italy
Posts: 48
Rep Power: 6
Lorenzo210 is on a distinguished road
Hi,



It looks like sonicFoam does not support dynamic meshes.


https://www.openfoam.com/documentati...8C_source.html


Regards,
Lorenzo
Lorenzo210 is offline   Reply With Quote

Reply

Tags
adaptive mesh refinement, shock capturing

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Breakup of VOF droplets due to adaptive mesh refinement dplthuy OpenFOAM Running, Solving & CFD 5 July 12, 2024 08:49
Data mapping with Adaptive Mesh Refinement kapten_zoom STAR-CCM+ 0 June 7, 2021 10:28
[snappyHexMesh] Error snappyhexmesh - Multiple outside loops avinashjagdale OpenFOAM Meshing & Mesh Conversion 53 March 8, 2019 10:42
[snappyHexMesh] SnappyHexMesh for internal Flow vishwa OpenFOAM Meshing & Mesh Conversion 24 June 27, 2016 09:54
killed "snappyHexMesh" parkh32 OpenFOAM Pre-Processing 2 April 8, 2012 18:12


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