Loading...
Searching...
No Matches
terra::io::GridLayout2D Struct Reference

Describes the 2D grid layout for a linearized data column. More...

#include <lookup_table_2d_reader.hpp>

Public Attributes

int nx
 Number of grid points along x.
 
int ny
 Number of grid points along y.
 
double x_min
 x coordinate of the first (ix=0) grid point
 
double y_min
 y coordinate of the first (iy=0) grid point
 
double dx
 Grid spacing along x (must be > 0)
 
double dy
 Grid spacing along y (must be > 0)
 
int stride_x
 Flat-index step when ix increases by 1 (see above)
 
int stride_y
 Flat-index step when iy increases by 1 (see above)
 

Detailed Description

Describes the 2D grid layout for a linearized data column.

A single column in a data file contains nx * ny scalar values (one value per data row), representing a 2D grid where

  • the x-axis has nx equally-spaced points: x_min, x_min+dx, ..., x_min+(nx-1)*dx
  • the y-axis has ny equally-spaced points: y_min, y_min+dy, ..., y_min+(ny-1)*dy

The flat file index k (0-based, counting only non-comment data rows) maps to the grid index pair (ix, iy) via

k = ix * stride_x + iy * stride_y
int stride_x
Flat-index step when ix increases by 1 (see above)
Definition lookup_table_2d_reader.hpp:115
int stride_y
Flat-index step when iy increases by 1 (see above)
Definition lookup_table_2d_reader.hpp:116

Exactly one of stride_x / stride_y must be 1 (the "fast" / innermost dimension); the other equals the size of that fast dimension.

Two common configurations (and their correct stride settings):


Example A — x varies slowest (C row-major): stride_x = ny, stride_y = 1

Suppose the grid maps pressure (x, 2 points) × temperature (y, 3 points) to density. The data author loops over pressure in the outer loop:

# pressure temperature density
# x=0.0 y=200 row k=0 → (ix=0, iy=0)
0.0 200 1.10
# x=0.0 y=300 row k=1 → (ix=0, iy=1)
0.0 300 1.05
# x=0.0 y=400 row k=2 → (ix=0, iy=2)
0.0 400 0.98
# x=1.0 y=200 row k=3 → (ix=1, iy=0)
1.0 200 1.08
# x=1.0 y=300 row k=4 → (ix=1, iy=1)
1.0 300 1.02
# x=1.0 y=400 row k=5 → (ix=1, iy=2)
1.0 400 0.95

For the density column (index 2): nx=2, ny=3. k = ix*3 + iy*1 → stride_x=3 (=ny), stride_y=1

GridLayout2D layout{ .nx=2, .ny=3,
.x_min=0.0, .y_min=200.0,
.dx=1.0, .dy=100.0,
.stride_x=3, // ny — one full y-row per x step
.stride_y=1 };
auto density = read_lookup_table_2d( "file.dat", 2, layout );
// density( 0.0, 200.0 ) == 1.10 (ix=0, iy=0)
// density( 1.0, 400.0 ) == 0.95 (ix=1, iy=2)
ScalarLookupTable2D< ScalarType > read_lookup_table_2d(const std::string &filename, int column_index, const GridLayout2D &layout, const std::string &label="lookup_table")
Convenience overload: read a single column from a data file.
Definition lookup_table_2d_reader.hpp:462
Describes the 2D grid layout for a linearized data column.
Definition lookup_table_2d_reader.hpp:108
int nx
Number of grid points along x.
Definition lookup_table_2d_reader.hpp:109

Example B — y varies slowest (column-major): stride_x = 1, stride_y = nx

Same grid, but the data author loops over temperature in the outer loop:

# pressure temperature density
# x=0.0 y=200 row k=0 → (ix=0, iy=0)
0.0 200 1.10
# x=1.0 y=200 row k=1 → (ix=1, iy=0)
1.0 200 1.08
# x=0.0 y=300 row k=2 → (ix=0, iy=1)
0.0 300 1.05
# x=1.0 y=300 row k=3 → (ix=1, iy=1)
1.0 300 1.02
# x=0.0 y=400 row k=4 → (ix=0, iy=2)
0.0 400 0.98
# x=1.0 y=400 row k=5 → (ix=1, iy=2)
1.0 400 0.95

For the density column (index 2): nx=2, ny=3. k = ix*1 + iy*2 → stride_x=1, stride_y=2 (=nx)

GridLayout2D layout{ .nx=2, .ny=3,
.x_min=0.0, .y_min=200.0,
.dx=1.0, .dy=100.0,
.stride_x=1, // 1 — consecutive rows differ by one x step
.stride_y=2 };// nx — one full x-row per y step
auto density = read_lookup_table_2d( "file.dat", 2, layout );
// density( 0.0, 200.0 ) == 1.10 (ix=0, iy=0)
// density( 1.0, 400.0 ) == 0.95 (ix=1, iy=2)

Both layouts produce the same ScalarLookupTable2D and the same interpolated values — only the file row order differs.

Member Data Documentation

◆ dx

double terra::io::GridLayout2D::dx

Grid spacing along x (must be > 0)

◆ dy

double terra::io::GridLayout2D::dy

Grid spacing along y (must be > 0)

◆ nx

int terra::io::GridLayout2D::nx

Number of grid points along x.

◆ ny

int terra::io::GridLayout2D::ny

Number of grid points along y.

◆ stride_x

int terra::io::GridLayout2D::stride_x

Flat-index step when ix increases by 1 (see above)

◆ stride_y

int terra::io::GridLayout2D::stride_y

Flat-index step when iy increases by 1 (see above)

◆ x_min

double terra::io::GridLayout2D::x_min

x coordinate of the first (ix=0) grid point

◆ y_min

double terra::io::GridLayout2D::y_min

y coordinate of the first (iy=0) grid point


The documentation for this struct was generated from the following file: