Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
ioread.cpp File Reference
#include <cstdint>
#include <numeric>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <stdexcept>
#include <vector>
#include <sstream>
#include <ctime>
#include <array>
#include <sys/types.h>
#include <sys/stat.h>
#include <span>
#include <unordered_map>
#include <unordered_set>
#include "definitions.h"
#include "mpi.h"
#include "spatial_cells/spatial_cell_wrapper.hpp"
#include "vdf_compression/compression.h"
#include "common.h"
#include "ioread.h"
#include "phiprof.hpp"
#include "parameters.h"
#include "logger.h"
#include "vdf_compression/compression_tools.h"
#include "vlsv_reader_parallel.h"
#include "vlasovsolver/vlasovmover.h"
#include "object_wrapper.h"
#include "velocity_mesh_parameters.h"
#include "grid.h"
Include dependency graph for ioread.cpp:

Go to the source code of this file.

Functions

void checkExternalCommands ()
 Checks for command files written to the local directory. If a file STOP was written and is readable, then a bailout with restart writing is initiated. If a file KILL was written and is readable, then a bailout without a restart is initiated. If a file SAVE was written and is readable, then restart writing without a bailout is initiated. If a file DOLB was written and is readable, then a new load balancing is initiated. To avoid bailing out upfront on a new run the files are renamed with the date to keep a trace. The function should only be called by MASTER_RANK. This ensures that resetting P::bailout_write_restart works.
bool exitOnError (bool success, const string &message, MPI_Comm comm)
 Collective exit on error functions.
bool readCellIds (vlsv::ParallelReader &file, vector< CellID > &fileCells, const int masterRank, MPI_Comm comm)
 Read cell ID's Read in cell ID's from file. Note: Uses the newer version of vlsv parallel reader.
bool readNBlocks (vlsv::ParallelReader &file, const std::string &meshName, std::vector< size_t > &nBlocks, int masterRank, MPI_Comm comm)
template<typename T>
bool readScalarParameter (vlsv::ParallelReader &file, string name, T &value, int masterRank, MPI_Comm comm)
template<typename T>
bool checkScalarParameter (vlsv::ParallelReader &file, const string &name, T correctValue, int masterRank, MPI_Comm comm)
template<typename fileReal>
bool _readBlockDataCompressionNone (vlsv::ParallelReader &file, const std::string &spatMeshName, const std::vector< uint64_t > &fileCells, const uint64_t localCellStartOffset, const uint64_t localCells, const vmesh::LocalID *blocksPerCell, const std::vector< uint64_t > &blockSumOffsets, const uint64_t localBlockStartOffset, const uint64_t localBlocks, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, std::function< vmesh::GlobalID(vmesh::GlobalID)> blockIDremapper, const uint popID)
template<typename fileReal>
bool _readBlockData (vlsv::ParallelReader &file, const std::string &spatMeshName, const std::vector< uint64_t > &fileCells, const uint64_t localCellStartOffset, const uint64_t localCells, const vmesh::LocalID *blocksPerCell, const std::vector< uint64_t > &blockSumOffsets, const uint64_t localBlockStartOffset, const uint64_t localBlocks, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, std::function< vmesh::GlobalID(vmesh::GlobalID)> blockIDremapper, const uint popID)
bool readBlockData (vlsv::ParallelReader &file, const string &meshName, const vector< CellID > &fileCells, const uint64_t localCellStartOffset, const uint64_t localCells, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid)
template<typename fileReal>
static bool _readCellParamsVariable (vlsv::ParallelReader &file, const vector< uint64_t > &fileCells, const uint64_t localCellStartOffset, const uint64_t localCells, const string &variableName, const size_t cellParamsIndex, const size_t expectedVectorSize, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid)
bool readCellParamsVariable (vlsv::ParallelReader &file, const vector< CellID > &fileCells, const uint64_t localCellStartOffset, const uint64_t localCells, const string &variableName, const size_t cellParamsIndex, const size_t expectedVectorSize, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid)
template<unsigned long int N>
bool readFsGridVariable (vlsv::ParallelReader &file, const string &variableName, int numWritingRanks, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, std::span< std::array< Real, N > > targetData)
bool readIonosphereNodeVariable (vlsv::ParallelReader &file, const string &variableName, SBC::SphericalTriGrid &grid, ionosphereParameters index)
bool exec_readGrid (dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, fsgrids::perbspan perb, fsgrids::efieldspan e, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, const std::string &name)
 Read in state from a vlsv file in order to restart simulations.
bool readGrid (dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, fsgrids::perbspan perb, fsgrids::efieldspan e, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, const std::string &name)
 Read in state from a vlsv file in order to restart simulations.
bool readFileCells (dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::string &name)
 Refine the grid to be identical to the file's.
bool readFsgridDecomposition (vlsv::ParallelReader &file, std::array< fsgrid::Task_t, 3 > &decomposition)

Variables

Logger logFile
Logger diagnostic

Function Documentation

◆ _readBlockData()

template<typename fileReal>
bool _readBlockData ( vlsv::ParallelReader & file,
const std::string & spatMeshName,
const std::vector< uint64_t > & fileCells,
const uint64_t localCellStartOffset,
const uint64_t localCells,
const vmesh::LocalID * blocksPerCell,
const std::vector< uint64_t > & blockSumOffsets,
const uint64_t localBlockStartOffset,
const uint64_t localBlocks,
dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > & mpiGrid,
std::function< vmesh::GlobalID(vmesh::GlobalID)> blockIDremapper,
const uint popID )

Read velocity block mesh data and distribution function data belonging to this process for the given particle species. This function must be called simultaneously by all processes.

Parameters
fileVLSV reader with input file open.
spatMeshNameName of the spatial mesh.
fileCellsList of all spatial cell IDs.
localCellStartOffsetThe offset from which to start reading cells.
localCellsHow many spatial cells after the offset to read.
blocksPerCellNumber of velocity blocks for this particle species in each spatial cell belonging to this process.
localBlockStartOffsetOffset into velocity block data arrays from which to start reading data.
localBlocksNumber of velocity blocks for this species assigned to this process.
mpiGridParallel grid library.
popIDID of the particle species who's data is to be read.
Returns
If true, velocity block data was read successfully.

Definition at line 954 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _readBlockDataCompressionNone()

template<typename fileReal>
bool _readBlockDataCompressionNone ( vlsv::ParallelReader & file,
const std::string & spatMeshName,
const std::vector< uint64_t > & fileCells,
const uint64_t localCellStartOffset,
const uint64_t localCells,
const vmesh::LocalID * blocksPerCell,
const std::vector< uint64_t > & blockSumOffsets,
const uint64_t localBlockStartOffset,
const uint64_t localBlocks,
dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > & mpiGrid,
std::function< vmesh::GlobalID(vmesh::GlobalID)> blockIDremapper,
const uint popID )

Definition at line 371 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _readCellParamsVariable()

template<typename fileReal>
bool _readCellParamsVariable ( vlsv::ParallelReader & file,
const vector< uint64_t > & fileCells,
const uint64_t localCellStartOffset,
const uint64_t localCells,
const string & variableName,
const size_t cellParamsIndex,
const size_t expectedVectorSize,
dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > & mpiGrid )
static

Reads cell parameters from the file and saves them in the right place in mpiGrid

Parameters
fileSome parallel vlsv reader with a file open
fileCellsList of all cell ids
localCellStartOffsetOffset in the fileCells list for this process ( calculated so that the amount of blocks is distributed somewhat evenly between processes)
localCellsThe amount of cells to read in this process after localCellStartOffset
cellParamsIndexThe parameter of the cell index e.g. CellParams::RHOM
expectedVectorSizeThe amount of elements in the parameter (parameter can be a scalar or a vector of size N)
mpiGridVlasiator's grid (the parameters are saved here)
Returns
Returns true if the operation is successful

Definition at line 1239 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkExternalCommands()

void checkExternalCommands ( )

Checks for command files written to the local directory. If a file STOP was written and is readable, then a bailout with restart writing is initiated. If a file KILL was written and is readable, then a bailout without a restart is initiated. If a file SAVE was written and is readable, then restart writing without a bailout is initiated. If a file DOLB was written and is readable, then a new load balancing is initiated. To avoid bailing out upfront on a new run the files are renamed with the date to keep a trace. The function should only be called by MASTER_RANK. This ensures that resetting P::bailout_write_restart works.

Check in local directory for external commands passed to the simulation. Only executed by MASTER_RANK.

Definition at line 72 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkScalarParameter()

template<typename T>
bool checkScalarParameter ( vlsv::ParallelReader & file,
const string & name,
T correctValue,
int masterRank,
MPI_Comm comm )

A function for checking the scalar parameter

Parameters
fileSome parallel vlsv reader with a file open
nameName of the parameter
correctValueThe correct value of the parameter to compare to
masterRankThe master process' id (Vlasiator uses 0 so this should be 0 by default)
commMPI comm (Default should be MPI_COMM_WORLD)
Returns
Returns true if the operation is successful

Definition at line 350 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec_readGrid()

bool exec_readGrid ( dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > & mpiGrid,
fsgrids::perbspan perb,
fsgrids::efieldspan e,
fsgrids::technicalspan technical,
FieldSolverGrid & fsgrid,
const std::string & name )

Read in state from a vlsv file in order to restart simulations.

Parameters
mpiGridVlasiator's grid
nameName of the restart file e.g. "restart.00052.vlsv"
Returns
Returns true if the operation was successful
See also
readGrid

Definition at line 1628 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exitOnError()

bool exitOnError ( bool success,
const string & message,
MPI_Comm comm )

Collective exit on error functions.

If any process(es) have a false success values then the program will abort and write out the message to the logfile

Parameters
successThis process' value for successful execution
messageError message to be shown upon failure
commMPI comm
Returns
Returns true if the operation was successful

Definition at line 152 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readBlockData()

bool readBlockData ( vlsv::ParallelReader & file,
const string & meshName,
const vector< CellID > & fileCells,
const uint64_t localCellStartOffset,
const uint64_t localCells,
dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > & mpiGrid )

Read velocity block data of all existing particle species.

Parameters
fileVLSV reader.
meshNameName of the spatial mesh.
fileCellsVector containing spatial cell IDs.
localCellStartOffsetOffset into fileCells, determines where the cells belonging to this process start.
localCellsNumber of spatial cells assigned to this process.
mpiGridParallel grid library.
Returns
If true, velocity block data was read successfully.

Definition at line 1015 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readCellIds()

bool readCellIds ( vlsv::ParallelReader & file,
vector< CellID > & fileCells,
const int masterRank,
MPI_Comm comm )

Read cell ID's Read in cell ID's from file. Note: Uses the newer version of vlsv parallel reader.

Parameters
fileSome vlsv reader with a file open
fileCellsVector in whic to store the cell ids
masterRankThe simulation's master rank id (Vlasiator uses 0, which should be the default)
commMPI comm (MPI_COMM_WORLD should be the default)

Definition at line 178 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readCellParamsVariable()

bool readCellParamsVariable ( vlsv::ParallelReader & file,
const vector< CellID > & fileCells,
const uint64_t localCellStartOffset,
const uint64_t localCells,
const string & variableName,
const size_t cellParamsIndex,
const size_t expectedVectorSize,
dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > & mpiGrid )

Reads cell parameters from the file and saves them in the right place in mpiGrid

Parameters
fileSome parallel vlsv reader with a file open
fileCellsList of all cell ids
localCellStartOffsetOffset in the fileCells list for this process ( calculated so that the amount of blocks is distributed somewhat evenly between processes)
localCellsThe amount of cells to read in this process after localCellStartOffset
cellParamsIndexThe parameter of the cell index e.g. CellParams::RHOM
expectedVectorSizeThe amount of elements in the parameter (parameter can be a scalar or a vector of size N)
mpiGridVlasiator's grid (the parameters are saved here)
Returns
Returns true if the operation is successful

Definition at line 1291 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFileCells()

bool readFileCells ( dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > & mpiGrid,
const std::string & name )

Refine the grid to be identical to the file's.

Parameters
mpiGridVlasiator's grid
nameName of the restart file e.g. "restart.00052.vlsv"

Definition at line 1964 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFsgridDecomposition()

bool readFsgridDecomposition ( vlsv::ParallelReader & file,
std::array< fsgrid::Task_t, 3 > & decomposition )

Definition at line 1986 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFsGridVariable()

template<unsigned long int N>
bool readFsGridVariable ( vlsv::ParallelReader & file,
const string & variableName,
int numWritingRanks,
fsgrids::technicalspan technical,
FieldSolverGrid & fsgrid,
std::span< std::array< Real, N > > targetData )

Read a fsgrid variable (consinting of N real values) from the given vlsv file.

Parameters
fileVLSV parallel reader with a file open.
variableNameName of the variable in the file
numWritingRanksNumber of mpi ranks that were used to write this file (used for reconstruction of the spatial order)
targetGridtarget location where the data will be stored.

Definition at line 1352 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readGrid()

bool readGrid ( dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > & mpiGrid,
fsgrids::perbspan perb,
fsgrids::efieldspan e,
fsgrids::technicalspan technical,
FieldSolverGrid & fsgrid,
const std::string & name )

Read in state from a vlsv file in order to restart simulations.

Parameters
mpiGridVlasiator's grid
nameName of the restart file e.g. "restart.00052.vlsv"

Definition at line 1951 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readIonosphereNodeVariable()

bool readIonosphereNodeVariable ( vlsv::ParallelReader & file,
const string & variableName,
SBC::SphericalTriGrid & grid,
ionosphereParameters index )

Read an ionosphere variable from the given vlsv file. Note that only singular floating point values (no vectors) can be read at this time.

Parameters
fileVLSV parallel reader with a file open.
variableNameName of the variable in the file
gridthe ionosphere grid that data will be deposited into
indexindex into the nodes' parameters array, where the data will end up.

Definition at line 1570 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readNBlocks()

bool readNBlocks ( vlsv::ParallelReader & file,
const std::string & meshName,
std::vector< size_t > & nBlocks,
int masterRank,
MPI_Comm comm )

Definition at line 252 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readScalarParameter()

template<typename T>
bool readScalarParameter ( vlsv::ParallelReader & file,
string name,
T & value,
int masterRank,
MPI_Comm comm )

A function for reading parameters, e.g., 'timestep'.

Parameters
fileVLSV parallel reader with a file open.
nameName of the parameter.
valueVariable in which to store the scalar variable (double, float, int .. ).
masterRankThe master process' id (Vlasiator uses 0 so this should equal 0 by default).
commMPI comm (MPI_COMM_WORLD should be the default).
Returns
Returns true if the operation is successful.

Definition at line 331 of file ioread.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ diagnostic

Logger diagnostic

Definition at line 59 of file ioread.cpp.

◆ logFile

Logger logFile
extern

Definition at line 25 of file main.cpp.