These guidelines are based on the working folder located here.

Advanced features


1) On-the-fly dictionary editing

On-the-fly editing was made available primarily for computations on a high-performance computer where days can be lost waiting in a priority queue. The different steps to follow are explained below depending on the dictionary that is affected by the changes.

For the transportProperties dictionary:

  • Open the transportProperties dictionary
  • Edit one or several entries inside the rarefiedParameters or transportModels subdictionaries
  • NB: if you save the file at this point, nothing will happen
  • Add a new key to the modified subdictionary
    applyChanges        true;
    
  • Save the file
  • NB: For safety, once the modification has taken effect, the file can be re-opened and the applyChanges entry can be removed. Save again.
  • If this operation worked, then your simulation should have entered into a second sub-phase of the run, as shown in the log file

Before:

Phase no 1.0  ExecutionTime = 72.29 s  ClockTime = 74 s  Iteration no 4504 (0.04 s)

After:

Phase no 1.1  ExecutionTime = 72.32 s  ClockTime = 74 s  Iteration no 4505 (0.03 s)

For the thermo2TModel dictionary:

  • The steps to follow are similar to the transportProperties dictionary: add the applyChanges key after editing the desired subdictionary and save.

For any other dictionaries:

  • Make modifications to the dictionary in question (e.g., adding additional chemical reactions, etc) and save.
  • Open the hTCProperties dictionary and add the applyChanges key
  • Save the hTCProperties dictionary

As shown in the log file, the simulation enters into a new stage/phase

Before:

Phase no 1.1  ExecutionTime = 153.02 s  ClockTime = 157 s  Iteration no 9074 (0.03 s)

After:

Phase no 2.0  ExecutionTime = 153.05 s  ClockTime = 157 s  Iteration no 9075 (0.03 s)

For all dictionaries,

    applyChangesAtWriteTime        true;

can be used instead of

    applyChanges        true;

should the solution needs to be printed before making modification(s) to the computation.


For boundary conditions:

  • Open the hTCProperties dictionary
  • Add the key
    applyChangesAtWriteTimeAndWait        #numberOfSeconds;
    

    where #numberOfSeconds is an integer value prescribing the time during which the simulation will be paused (give yourself enough time!).

  • Save the hTCProperties dictionary
  • Type in: tail -f log.hy2Foam into the terminal window and wait until the next write time
  • Once the simulation is sleeping, reconstructPar can be used (for a parallel job)
  • Edit the desired boundary condition and save
  • Delete the processors#ID folders and run: decomposePar -latestTime
  • Monitor the log file as the simulation restarts to make sure everything went well



2) Bounding the temperature field

In the thermophysicalProperties dictionary, the temperatureBounds subdictionary shown below can be copy-pasted to bound the temperature field and increase robustness. After stopping the simulation, please make sure that the minimum and maximum temperature values are strictly within these bounds.

temperatureBounds
{
    Tlow      200; //default is   100 K
    Thigh   40000; //default is 40000 K
}

If the temperature field goes unbounded, a warning will be printed in the log file for this iteration. It reports the number of times the limit function had to be called and the minimum/maximum temperature recorded before bounding.

Attempt to use rho2ReactionThermo out of temperature range 3197 times during this iteration.
		Thigh: 40000 < 45289



3) Adaptive mesh refinement

When added to the constant/ folder, the optional dynamicMeshDict dictionary will be read. In this section, we are interested in two types of dynamicFvMeshes: staticFvmesh and dynamicRefineFvMesh.

Use staticFvmesh or delete constant/dynamicMeshDict when the mesh should not be adapted.

Use dynamicRefineFvMesh otherwise and implement the dynamicRefineFvMeshCoeffs subdictionary as shown below. The field on which refinement/coarsening is based on is given by the key field. You can either provide the name of an existing scalar field or input any of hy2Foam’s hardcoded adaptation fields:

  • normalisedDensityGradient
  • normalisedPressureGradient
  • normalisedTemperatureGradient
  • normalisedViscosityGradient
  • MachGradient
  • massFractionGradient
  • normalisedGradients

normalisedTemperatureGradient and normalisedGradients are based on the gradients of more than one field and each can be weighted using coefficients (defaulted to 1) located in the gradientWeights subdictionary. These coefficients can also be used as 0/1 switches.

If you choose one of these adaptation fields, it will be printed in the results folders.

dynamicFvMesh   dynamicRefineFvMesh; // Write staticFvmesh to disable AMR

dynamicRefineFvMeshCoeffs
{
    // How often to refine
    refineInterval  10000;
    
    // Field to base refinement on
    field normalisedDensityGradient;
    
    // Weighting factors when there is more than one field to base refinement on
    gradientWeights
    {
        rho    1.0;
        p      1.0;
        Ttr    1.0;
        Tve    1.0;
        Mach   1.0;
        mu     1.0;
        Y      1.0;
    }
    
    // Refine field inbetween lower..upper
    lowerRefineLevel 2.0;
    upperRefineLevel 1e6;
    
    // Unrefine field inbetween 0..unrefine
    unrefineLevel 0.5;
    
    // Have slower than 2:1 refinement
    nBufferLayers   4;
    // Refine cells only up to maxRefinement levels
    maxRefinement   3;
    // Stop refinement if maxCells reached
    maxCells        2000000;
    // 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
    (
        (pos none)
        (neg none)
        (phi none)
        (phiEp none)
        (phiEv none)
        (amaxSf none)
    );
    
    // Write the refinement level as a volScalarField
    dumpLevel       true;
}

In the logfile, the number of adaptation cycles that the mesh has undergone is given before the execution time:

AdaptationCycle = 2
ExecutionTime = 153.02 s  ClockTime = 157 s  Iteration no 9074 (0.03 s)

NB1: If your results look off, please check that there aren’t any empty patches defined and if there are, redefine them as symmetry patches.

NB2: In Paraview, on the left-hand side panel, Properties tab, untick Decompose Polyhedra and then set Representation to Surface With Edges.

For further information on AMR, please refer to the official OpenFOAM tutorials. Typing the following command line will list all dynamicMeshDict available

tut
find . -type f -name "dynamicMeshDict"