Giter Club home page Giter Club logo

gradientamr's Introduction

GradientAMR

This project shows how to use the gradient of flow variables as a criteria to control Adaptive Mesh Refinement (AMR) for OpenFOAM simulations.

Getting Started

  • Run the prepare.sh to generate the mesh and setup the simulation.
  • Then run the case with pimpleFoam

How it works

The following coded function object in controlDict creates a field which, in each timestep, contains the magnitude of the velocity gradient (which is a tensor):

    calcGradient
    {
        libs        ("libutilityFunctionObjects.so");
        type        coded;
        name        computeVelocityGradientMag;
        executeControl      timeStep;
        executeInterval     1;
        writeControl        writeTime;
        writeInterval       1;

        codeExecute
        #{
            const volVectorField& U  =  mesh().lookupObject<volVectorField>("U");

            static autoPtr<volScalarField> velocityGradientMagPtr;
            if(!velocityGradientMagPtr.valid()) {
              Info << "Creating velocityGradientMag" << nl;

              velocityGradientMagPtr.set
              (
                  new volScalarField
                  (
                    IOobject
                    (
                        "velocityGradientMag",
                        time_.timeName(),
                        U.mesh(),
                        IOobject::NO_READ,
                        IOobject::AUTO_WRITE
                    ),
                    mag(fvc::grad(U))
                  )
              );
            }
            volScalarField &velocityGradientMag = velocityGradientMagPtr();
            velocityGradientMag.checkIn();
            velocityGradientMag = mag(fvc::grad(U));
            Info << " max velocityGradientMag " << max(velocityGradientMag) << nl;
        #};
    }

That field is defined as refinement criteria on dynamicMeshDict:

dynamicFvMesh   dynamicRefineFvMesh;

dynamicRefineFvMeshCoeffs
{
    // How often to refine
    refineInterval  2;

    // Field to be refinement on
    field           velocityGradientMag;

    // Refine field inbetween lower..upper
    lowerRefineLevel 30;
    upperRefineLevel 1e6;

    // If value < unrefineLevel unrefine
    unrefineLevel   10;

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

    ...
}

The mesh is dynamically refined when the magnitude of the velocity gradient exceeds 30 1/s, and is unrefined when it goes below 10 1/s.

Results

Watch the video

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Author

Nicolás Diego Badano (https://www.linkedin.com/in/nicolas-diego-badano/)

gradientamr's People

Contributors

nicolasbadano avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.