Skip to content

Using adaptivity

Samuel Parkinson edited this page Jun 11, 2014 · 1 revision

Mesh adaptivity produces a mesh with more resolution in particular regions.

Mesh adaptivity options

Basic options

In order to use adaptivity, you must switch on the mesh_adaptivity option at the bottom of the flml in diamond, and then switch on the hr_adaptivity option:

Adaptivity options

The options must then be filled in.

  • Period: the amount of time/ number of time steps between each adapt
  • maximum number of nodes: the maximum number of nodes in the simulation. You should not really reach this number, the number of nodes should be limited by the other options
  • enable gradation: if you switch this on you can reset the gradation parameter. This controls how fast the mesh size may change by constraining the jump in desired edge-length along an edge. It must be a number between 1 and 2. 1.5 is the default. 2 allows a doubling of element size from one element to the next. 1 enforces a constant size everywhere. It's best to start with 1.5. If you find that there is too much diffusion at a boundary between eg. low and high salinity regions, then try increasing the number to about 1.7 to start with. You would normally avoid a very low or high value.
  • Minimum/MaximumEdgeLengths bound the edge lengths.

Adapt at first time step

This allows the mesh to be adapted after initialisation and before the simulation begins and is selected with:

Adapt at first time step

The number of adapts is the number of times the mesh is adapted after initialisation and before the simulation begins. 4-6 is usually a good value to start with but you will need to experiment.

Adaptivity settings for fields

You must choose which field(s) you wish to adapt to. It's normally best to start off by adapting to just one field and then add more if you wish to. The simulation dynamics will determine which field is best to adapt to. Remember that more elements will be added to regions with higher curvature of the field you are adapting to. So chose a field with a high curvature in the region you wish to add more resolution to. You must then add the adaptivity options under the field you are adapting to:

Adapt to temperature

Setting the interpolation error bound

The InterpolationErrorBound (referred to here as ε) needs to be filled in for each field that you are adapting to. It will be a scalar for scalar fields and a vector for vector fields. A good rule of thumb is to start with a value ~ 10-20% of the maximum value of the field. This is very rough and you will need to experiment. In general, decreasing ε will result in smaller elements and vie versa.

It is possible to give it a different value in different regions or vary it by time using [http://amcg-www.ese.ic.ac.uk/index.php?title=Initialise_From_Python a python function].

Interpolation method

The interpolation method determines how the field is interpolated between meshes. The options are found below the adaptivity options but are separate to them and can be varied regardless of whether adaptivity is being used or not:

Interpolation method

In general it is best to start out with consistent_interpolation as this is the fastest method. See the manual for more information about the different methods.

Debugging adaptivity

Diamond has several options that allow output, such as the metric to be output by Fluidity. This can be useful for diagnosing what adaptivity is doing and how to improve your mesh. The options are found under mesh_adaptivity/hr_adaptivity/debug:

Debugging

  • write_metric_stages writes out the error metric to a vtu at each stage of the processing pipeline. Note, you will also be able to view the adapted mesh when viewing the vtu.
  • write_adapted_mesh writes out the Coordinate field to a triangle mesh for every state adapt (and you can make a vtu with triangle2vtu). In parallel the .halo files are also written out.
  • write_adapted_state writes the system state (mesh, fields etc) to a vtu at every state adapt. In parallel a vtu will be written for every parallel adapt iteration. *checkpoint will checkpoint the simulation after every adapt. In parallel, a checkpoint will be written only after the final adapt iteration. Checkpoints are postfixed with "adapt_checkpoint". *max_checkpoint_count is the number of checkpoints to write before overwriting existing checkpoints.

Common things to try

  • If you start with a high resolution mesh, there is a chance that you could lose resolution as soon as you adapt. To get around this you could use a python function to set an ε value that starts off very low, then increases with time.

  • You may find that there are particular regions of the mesh that need more resolution than other areas with a similar gradient. These regions could be boundaries for example, so use a python function to set a lower ε values there.

  • If you are decreasing your value of ε but the elements do not appear to be getting any smaller or the mesh does not appear to be adapting to the fields as it should you may be hitting your minimum edge length. Try reducing it further. If this is the case you will then need to work on a balance between ε and the minimum edge length.

  • If the field you are adapting to has a linear gradient then the field has no curvature (Hessian will be zero) and adaptivity will not have anything to adapt to so you will most likely end up with a mesh of elements with edge lengths close to your maximum element size. Your best option is to constrain the maximum element size, possibly with a python function if you want temporal or spatial variation.

Clone this wiki locally