This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Reading Data from External Files
Chris White edited this page Oct 9, 2018
·
3 revisions
Some applications require having on-hand arrays of precomputed values, such as equation-of-state tables for non-ideal gases or opacity tables for computing radiation transfer. The src/inputs/
directory contains functions designed to facilitate reading such data into Athena. For example, these functions can be called during problem set up to load data into user-allocated arrays.
Currently, only HDF5 data files are supported.
hdf5_reader.hpp
declares the following function:
- Inputs:
-
const char *filename
: name of data file, including any necessary path. -
const char *dataset_name
: name of dataset to load from, including any necessary path (i.e. HDF5 groups). -
int rank_file
: number of dimensions in file dataset. -
const int *start_file
: array of lengthrank_file
indexing starting position (starting from 0's) from which to read data. -
const int *count_file
: array of lengthrank_file
giving number of consecutive elements to read in each dimension. The product of these numbers will be the total number of elements read. -
int rank_mem
: number of dimensions inarray
. -
const int *start_mem
: array of lengthrank_mem
indexing starting position (starting from 0's) where read data should be placed. -
const int *count_mem
: array of lengthrank_mem
giving number of consecutive elements to read in each dimension. The product of these numbers must match the product of therank_file
elements ofcount_file
. -
AthenaArray<Real> &array
: AthenaArray, already allocated, into which results should be placed. -
bool collective=false
: When set totrue
and the code is compiled with MPI, the file reads will be done collectively. By default, reads will be serial and thus safe (though possibly slow when running on many MPI ranks). If using collective reads, each MPI rank (i.e. Mesh) must make the same number of calls to this function. -
bool noop=false
: When set totrue
, no data will be read. This is intended to be used with collective calls in cases where different ranks would otherwise make different numbers of calls to this function.
-
- Outputs:
-
array
will contain the values from the file.
-
- Notes:
- This function is designed to read floating-point data.
- The data in the file will be cast to the length of
Real
when placed in the output array. - The function will automatically determine the extent of each dimension for both the input dataset and the output array.
- Example: Suppose
example.hdf5
contains a 12×15 array namedvals
in groupdata_group
from which we want to extract just the last 2 rows into a 2×15 array. A problem generator could do this based on the following snippet:
#include "../inputs/hdf5_reader.hpp"
int start_file[2] = {10, 0};
int count_file[2] = {2, 15};
int start_mem[2] = {0, 0};
int count_mem[2] = {2, 15};
AthenaArray<Real> array;
array.NewAthenaArray(2, 15);
HDF5ReadRealArray("example.hdf5", "/data_group/vals", 2, start_file, count_file,
2, start_mem, count_mem, array);
Getting Started
User Guide
- Configuring
- Compiling
- The Input File
- Problem Generators
- Boundary Conditions
- Coordinate Systems and Meshes
- Running the Code
- Outputs
- Using MPI and OpenMP
- Static Mesh Refinement
- Adaptive Mesh Refinement
- Load Balancing
- Special Relativity
- General Relativity
- Passive Scalars
- Shearing Box
- Diffusion Processes
- General Equation of State
- FFT
- High-Order Methods
- Super-Time-Stepping
- Orbital Advection
- Rotating System
- Reading Data from External Files
Programmer Guide