Constructing a Cartesian meshΒΆ
The cart_mesh program is used to generate Cartesian meshes for the cgcam code. Cart_mesh reads inputs from file cart_mesh.inp, using a strategy very similar to that which is used to read inputs for the main cgcam code (see section User Input Variables). All possible inputs for cart_mesh.inp are listed below:
Nx: | Number of points in x. |
---|---|
Ny: | Number of points in y. |
Nz: | Number of points in z. |
x0: | Minimum value of the x coordinate. |
x1: | Maximum value of the x coordinate. |
xL: | Box size in the x-direction. |
y0: | Minimum value of the y coordinate. |
y1: | Maximum value of the y coordinate. |
yL: | Box size in the y-direction. |
z0: | Minimum value of the z coordinate. |
z1: | Maximum value of the z coordinate. |
zL: | Box size in the z-direction. |
dx0: | x mesh spacing for the uniform mesh region. |
dy0: | y mesh spacing for the uniform mesh region. |
dz0: | z mesh spacing for the uniform mesh region. |
dz1: | Mesh spacing at the surface when i_type_z=2. |
x_trans1: | x location for the start of the uniform mesh region. |
x_trans2: | x location for the end of the uniform mesh region. |
y_trans1: | y location for the start of the uniform mesh region. |
y_trans2: | y location for the end of the uniform mesh region. |
z_trans1: | z location for the start of the uniform mesh region. |
z_trans2: | z location for the end of the uniform mesh region. |
rot: | Rotation angle about the y-axis. |
flare: | Tangent of the flare angle when i_grid=11. |
i_grid: | Grid type: 0-Cartesian grid written as a full 3D grid file, 1-Cartesian grid written as a compact file, 11-Cartesian grid with a flared region near the top boundary. Default is 1. |
i_type_z: | Vertical mesh stretching control: 0-attempt to match the stretching rates in the two stretched regions, 1-attempt to match the mesh spacings at the ends of the two stretched regions, 2-stretch from dz1 at the surface to dz0 at z_trans1. Default is 1. |
Of these possible inputs, only the number of mesh points (Nx, Ny, and Nz) are strictly required. It is also required to specify the computational box dimensions in some fashion. This can be done by specifying the box dimension itself (e.g. xL in which case x will range between -0.5*xL to 0.5xL) or by specifying the coordinate ranges (e.g. x0=1.0, x1=11.0, or x0=1.0, xL=10.0, or x1=11.0, xL=10.0). If only the number of mesh points and the box dimensions are given for a particular direction, cart_mesh will assume a uniform mesh spacing in that direction. For example, the minimal input file
Nx 10 Number of points in x
Ny 1 Number of points in y
Nz 5 Number of points in z
xL 100.0 Box size in the x-direction
yL 1.0 Box size in the y-direction
z0 0.0 Minimum value of the z coordinate
z1 30.0 Maximum value of the z coordinate
generates the mesh below
Note that Ny=1 is specified in the input file, which results in a 2D mesh. While this was done for illustrative purposes, cart_mesh will generally be used to generate 3D meshes. The remaining examples in this section will also be 2D, but all of the concepts covered extend to 3D.
Often it is desirable to cluster mesh points in a portion of the domain where smaller-scale structures will develop. The current strategy is to use a uniform fine mesh spacing in the refined zone, and then stretch the mesh towards the boundaries (the procedure will be made more clear in the examples below). In order to obtain a refined zone, it is necessary to specify the limits of the uniform mesh region, as well as the mesh spacing there (e.g. x_trans1, x_trans2, dx0). For example, the input file
Nx 60 Number of points in x
Ny 1 Number of points in y
Nz 60 Number of points in z
x0 -1.0 Minimum x coordinate
x1 1.0 Maximum x coordinate
yL 0.1 Spanwise box size
z0 0.0 Altitude for bottom of domain
z1 1.0 Altitude for top of domain
dx0 0.015 x mesh spacing for uniform section
x_trans1 -0.2 x-coordinate for start of uniform section
x_trans2 0.3 x-coordinate for end of uniform section
generates the mesh below
Similar refinements can be made in the y and z directions by specifying the optional input parameters y_trans1, y_trans2, dy0, z_trans1, z_trans2, and dz0. Additional options are available for the z direction only in order to provide more on the mesh stretching strategy and to accommodate terrain features that may exist at the lower boundary. In the x and y directions, cart_mesh will attempt to make the largest mesh cells in the two stretched regions (at the two ends of the domain) equal in size. This is also the default behavior in the z direction, but it not produce the desired effect. For example, it might make sense to have a reasonably fine vertical mesh spacing near the lower boundary, but a much larger spacing near the upper boundary. The optional input i_type_z=0 will change the behavior so that the mesh stretching rates are equal in the two stretched zones. By placing the refined mesh zone appropriately, it is then possible to achieve the desired inequality between the vertical mesh spacings at the lower and upper boundaries. An example of this feature is shown below
Nx 60 Number of points in x
Ny 1 Number of points in y
Nz 40 Number of points in z
x0 -1.0 Minimum x coordinate
x1 1.0 Maximum x coordinate
yL 0.1 Spanwise box size
z0 0.0 Altitude for bottom of domain
z1 1.0 Altitude for top of domain
dx0 0.015 x mesh spacing for uniform section
x_trans1 -0.2 x-coordinate for start of uniform section
x_trans2 0.3 x-coordinate for end of uniform section
dz0 0.015 z mesh spacing for uniform section
z_trans1 0.2 z-coordinate for start of uniform section
z_trans2 0.4 z-coordinate for end of uniform section
i_type_z 0 0-match sf, 1-match dz, 2-stretch from surface
A second option, i_type_z=2 is available in order to allow for very fine vertical spacing near the surface (specified by optional input dz1), followed by a stretching zone where the spacings increase in the vertical until meeting the uniform mesh zone with spacing dz1 at z_trans1. This feature is illustrated below
Nx 60 Number of points in x
Ny 1 Number of points in y
Nz 50 Number of points in z
x0 -1.0 Minimum x coordinate
x1 1.0 Maximum x coordinate
yL 0.1 Spanwise box size
z0 0.0 Altitude for bottom of domain
z1 1.0 Altitude for top of domain
dx0 0.015 x mesh spacing for uniform section
x_trans1 -0.2 x-coordinate for start of uniform section
x_trans2 0.3 x-coordinate for end of uniform section
dz0 0.015 z mesh spacing for uniform section
z_trans1 0.2 z-coordinate for start of uniform section
z_trans2 0.4 z-coordinate for end of uniform section
i_type_z 2 0-match sf, 1-match dz, 2-stretch from surface
dz1 0.008 z mesh spacing at the lower boundary
The numerical algorithm used in cgcam is rather sensitive to mesh smoothness and oscillations will often appear in the solution variables if the mesh is stretched too aggressively. As a general rule, the mesh stretching rates should be limited to a maximum of about 2%. In order to assist the user in this regard, the cart mesh prints the computed stretching rates to the screen as it runs. A sample output is shown below.
x-direction:
n_stretch1 = 39 n_uniform = 37 n_stretch2 = 32
sf1 = 1.01622 sf2 = 1.01932
Delta_end1 = 2.7396E-02 Delta_end2 = 2.6906E-02
y-direction:
n_stretch1 = 0 n_uniform = 1 n_stretch2 = 0
sf1 = 1.00000 sf2 = 1.00000
Delta_end1 = 1.0000E-01 Delta_end2 = 1.0000E-01
z-direction:
n_stretch1 = 12 n_uniform = 13 n_stretch2 = 29
sf1 = 1.01443 sf2 = 1.02035
Delta_end1 = 1.8011E-02 Delta_end2 = 2.7047E-02
The stretching rates are reported as sf1 and sf2 for each direction and are quoted as the ratio of two adjacent mesh spacings. Thus a number like 1.0195 indicates a stretching rate of 1.95%. Note that the stretching rates are generally unequal in the two stretched regions for each direction. It is thus necessary to scan for both values and then increase the number of mesh points as required in order to lower the larger of the two to about 1.02.
Note that the stretching rates for the examples in this section grossly violate the 2% rule. This was done for illustrative purposes only as it is difficult for the human eye to register stretching rates as low as 2%.
the cgcam code is often used for atmospheric simulations where the upper boundary is placed at an altitude of 200 km or higher. Fine mesh spacings near the upper boundary for these cases can result in a severe time step restriction due to the explicit time advancement scheme in connection with the large values of kinematic viscosity found at high altitudes. Mesh stretching in the vertical does not help too much in these cases since the time step is still limited by diffusion across the fine mesh dimensions in the horizontal directions. One strategy aimed at combating this problem is to bend the mesh lines in the upper portion of the domain in order to increase their horizontal spacings there. Although this procedure moves the mesh topology from strict Cartesian to distorted Cartesian, it can nonetheless be done within cart_mesh. In order to use this feature, it is necessary to supply the optional input flare=tan(flare angle). This feature is illustrated in the example below.
Nx 60 Number of points in x
Ny 1 Number of points in y
Nz 40 Number of points in z
x0 -1.0 Minimum x coordinate
x1 1.0 Maximum x coordinate
yL 0.1 Spanwise box size
z0 0.0 Altitude for bottom of domain
z1 1.0 Altitude for top of domain
dx0 0.015 x mesh spacing for uniform section
x_trans1 -0.2 x-coordinate for start of uniform section
x_trans2 0.3 x-coordinate for end of uniform section
dz0 0.015 z mesh spacing for uniform section
z_trans1 0.3 z-coordinate for start of uniform section
z_trans2 0.6 z-coordinate for end of uniform section
flare 0.2