Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
vlsvdiff.cpp File Reference

File containing write IO for vlasiator. More info at: https://agora.fmi.fi/display/CORSAIR/VLSV+File+Format. More...

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <dirent.h>
#include <exception>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <set>
#include <sstream>
#include <stdint.h>
#include <string>
#include <typeinfo>
#include "../definitions.h"
#include "vlsvreaderinterface.h"
#include <vlsv_reader.h>
#include <vlsv_writer.h>
#include <fsgrid.hpp>
Include dependency graph for vlsvdiff.cpp:

Go to the source code of this file.

Enumerations

enum  GridType { SPATIALGRID , FSGRID , IONOSPHERE }

Functions

static uint64_t convUInt (const char *ptr, const vlsv::datatype::type &dataType, const uint64_t &dataSize)
bool copyArray (vlsv::Reader &input, vlsv::Writer &output, const std::string &tagName, const list< pair< string, string > > &inputAttribs, bool optional=false)
bool HandleFsGrid (const string &inputFileName, vlsv::Writer &output, std::map< uint, Real > orderedData)
bool getFsgridDecomposition (vlsvinterface::Reader &file, std::array< int, 3 > &decomposition)
bool cloneMesh (const string &inputFileName, vlsv::Writer &output, const string &meshName, std::map< uint, Real > orderedData)
bool convertMesh (vlsvinterface::Reader &vlsvReader, const string &meshName, const char *varToExtract, const uint compToExtract, map< uint, Real > *orderedData, unordered_map< size_t, size_t > &cellOrder, const bool &storeCellOrder)
template<class T>
bool convertSILO (const string fileName, const char *varToExtract, const uint compToExtract, map< uint, Real > *orderedData, unordered_map< size_t, size_t > &cellOrder, Real &time, const bool &storeCellOrder=false)
bool shiftAverage (const map< uint, Real > *const orderedData1, const map< uint, Real > *const orderedData2, map< uint, Real > *shiftedData2)
bool pDistance (const map< uint, Real > &orderedData1, const map< uint, Real > &orderedData2, creal p, Real *absolute, Real *relative, const bool doShiftAverage, const unordered_map< size_t, size_t > &cellOrder, vlsv::Writer &outputFile, const std::string &meshName, const std::string &varName)
bool outputDistance (const Real p, const Real *absolute, const Real *relative, const bool shiftedAverage, const bool verboseOutput, const bool lastCall)
bool outputDt (const Real dt, const bool verboseOutput, const bool lastCall)
bool singleStatistics (map< uint, Real > *orderedData, Real *size, Real *mini, Real *maxi, Real *avg, Real *stdev)
bool outputStats (const Real *size, const Real *mini, const Real *maxi, const Real *avg, const Real *stdev, const bool verboseOutput, const bool lastCall)
bool printNonVerboseData ()
bool getBlockIds (vlsvinterface::Reader &vlsvReader, const unordered_map< uint64_t, pair< uint64_t, uint32_t > > &cellsWithBlocksLocations, const uint64_t &cellId, vector< uint32_t > &blockIds)
uint32_t getBlockId (const double vx, const double vy, const double vz, const double dvx, const double dvy, const double dvz, const double vx_min, const double vy_min, const double vz_min, const double vx_length, const double vy_length, const double vz_length)
template<class T>
bool readAvgs (T &vlsvReader, string name, const unordered_map< uint64_t, pair< uint64_t, uint32_t > > &cellsWithBlocksLocations, const uint64_t &cellId, unordered_map< uint32_t, vector< double > > &avgs, uint64_t &vectorSize)
template<class T>
bool getCellsWithBlocksLocations (T &vlsvReader, unordered_map< uint64_t, pair< uint64_t, uint32_t > > &cellsWithBlocksLocations)
template<class T, class U>
bool compareAvgs (const string fileName1, const string fileName2, const bool verboseOutput, vector< uint64_t > &cellIds1, vector< uint64_t > &cellIds2)
bool process2Files (const string fileName1, const string fileName2, const char *varToExtract, const uint compToExtract, const bool verboseOutput, const uint compToExtract2=0)
bool processDirectory (DIR *dir, set< string > *fileList)
void printHelp (const map< string, string > &defAttribs, const map< string, string > &descriptions)
int main (int argn, char *args[])

Variables

static map< string, string > attributes
static int gridName

Detailed Description

File containing write IO for vlasiator. More info at: https://agora.fmi.fi/display/CORSAIR/VLSV+File+Format.

Tool to compare VLSV files.

Tool to compare two VLSV files, two folders with the same number of VLSV files or a folder to a reference file. The tool assumes the files have a name syntax 'grid.[0-9]+.vlsv'. It takes four arguments.

Calling patterns are:

"$ vlsvdiff <file1> <file2> <Variable> <component>": Gives single-file statistics and distances between the two files given, for the variable and component given

"$ vlsvdiff --diff --meshname=<Meshname> <file1> <file2> <Variable> <component>": Gives single-file statistics and distances between the two files given, for the variable and component given

"$ vlsvdiff <folder1> <folder2> <Variable> <component>": Gives single-file statistics and distances between pairs of files grid*.vlsv taken in alphanumeric order in the two folders given, for the variable and component given

"$ vlsvdiff <file1> <folder2> <Variable> <component>" or "$ vlsvdiff <folder1> <file2> <Variable> <component>": Gives single-file statistics and distances between a file, and files grid*.vlsv taken in alphanumeric order in the given folder, for the variable and component given

Definition in file vlsvdiff.cpp.

Enumeration Type Documentation

◆ GridType

enum GridType
Enumerator
SPATIALGRID 
FSGRID 
IONOSPHERE 

Definition at line 75 of file vlsvdiff.cpp.

Function Documentation

◆ cloneMesh()

bool cloneMesh ( const string & inputFileName,
vlsv::Writer & output,
const string & meshName,
std::map< uint, Real > orderedData )

Copy the spatial mesh from input to output.

Parameters
inputFileNameName of the input file where the mesh is copied from.
outputVLSV reader for the file where the cloned mesh is written.
meshNameName of the mesh.
Returns
If true, the mesh was successfully cloned.

Definition at line 383 of file vlsvdiff.cpp.

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

◆ compareAvgs()

template<class T, class U>
bool compareAvgs ( const string fileName1,
const string fileName2,
const bool verboseOutput,
vector< uint64_t > & cellIds1,
vector< uint64_t > & cellIds2 )

Definition at line 1317 of file vlsvdiff.cpp.

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

◆ convertMesh()

bool convertMesh ( vlsvinterface::Reader & vlsvReader,
const string & meshName,
const char * varToExtract,
const uint compToExtract,
map< uint, Real > * orderedData,
unordered_map< size_t, size_t > & cellOrder,
const bool & storeCellOrder )

Extracts the dataset from the VLSV file opened by convertSILO.

Parameters
vlsvReadervlsvinterface::Reader class object used to access the VLSV file
meshNameAddress of the string containing the name of the mesh to be extracted
varToExtractPointer to the char array containing the name of the variable to extract
compToExtractUnsigned int designating the component to extract (0 for scalars)
orderedDataPointer to the return argument map which will get the extracted dataset

Definition at line 433 of file vlsvdiff.cpp.

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

◆ convertSILO()

template<class T>
bool convertSILO ( const string fileName,
const char * varToExtract,
const uint compToExtract,
map< uint, Real > * orderedData,
unordered_map< size_t, size_t > & cellOrder,
Real & time,
const bool & storeCellOrder = false )

Opens the VLSV file and extracts the mesh names. Sends for processing to convertMesh.

Parameters
fileNameString containing the name of the file to be processed
varToExtractPointer to the char array containing the name of the variable to extract
compToExtractUnsigned int designating the component to extract (0 for scalars)
orderedDataPointer to the return argument map which will get the extracted dataset
See also
convertMesh

Definition at line 714 of file vlsvdiff.cpp.

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

◆ convUInt()

uint64_t convUInt ( const char * ptr,
const vlsv::datatype::type & dataType,
const uint64_t & dataSize )
static

Definition at line 81 of file vlsvdiff.cpp.

Here is the caller graph for this function:

◆ copyArray()

bool copyArray ( vlsv::Reader & input,
vlsv::Writer & output,
const std::string & tagName,
const list< pair< string, string > > & inputAttribs,
bool optional = false )

Read given array data from input file, and byte-copy it to the output file.

Parameters
inputInput file reader.
outputOutput file reader.
tagNameName of the copied array.
inputAttributesXML attributes for the copied array.
optionalIf true, this parameter is OK to be missing.
Returns
If true, the array was copied successfully.

Definition at line 111 of file vlsvdiff.cpp.

Here is the caller graph for this function:

◆ getBlockId()

uint32_t getBlockId ( const double vx,
const double vy,
const double vz,
const double dvx,
const double dvy,
const double dvz,
const double vx_min,
const double vy_min,
const double vz_min,
const double vx_length,
const double vy_length,
const double vz_length )

Definition at line 1136 of file vlsvdiff.cpp.

Here is the call graph for this function:

◆ getBlockIds()

bool getBlockIds ( vlsvinterface::Reader & vlsvReader,
const unordered_map< uint64_t, pair< uint64_t, uint32_t > > & cellsWithBlocksLocations,
const uint64_t & cellId,
vector< uint32_t > & blockIds )

Definition at line 1085 of file vlsvdiff.cpp.

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

◆ getCellsWithBlocksLocations()

template<class T>
bool getCellsWithBlocksLocations ( T & vlsvReader,
unordered_map< uint64_t, pair< uint64_t, uint32_t > > & cellsWithBlocksLocations )

Definition at line 1236 of file vlsvdiff.cpp.

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

◆ getFsgridDecomposition()

bool getFsgridDecomposition ( vlsvinterface::Reader & file,
std::array< int, 3 > & decomposition )

Definition at line 295 of file vlsvdiff.cpp.

Here is the caller graph for this function:

◆ HandleFsGrid()

bool HandleFsGrid ( const string & inputFileName,
vlsv::Writer & output,
std::map< uint, Real > orderedData )

Definition at line 170 of file vlsvdiff.cpp.

Here is the caller graph for this function:

◆ main()

int main ( int argn,
char * args[] )

Main function, detects which calling pattern is used and sends to the corresponding processing functions.

See also
process2Files processDirectory

Definition at line 1783 of file vlsvdiff.cpp.

Here is the call graph for this function:

◆ outputDistance()

bool outputDistance ( const Real p,
const Real * absolute,
const Real * relative,
const bool shiftedAverage,
const bool verboseOutput,
const bool lastCall )

In verbose mode print the distance, in non-verbose store them for later output when lastCall is true

Parameters
pParameter of the distance
absoluteAbsolute value pointer
relativeRelative value pointer
shiftedAverageBoolean parameter telling whether the dataset is average-shifted
verboseOutputBoolean parameter telling whether the output is verbose or compact
lastCallBoolean parameter telling whether this is the last call to the function
See also
shiftAverage pDistance

Definition at line 913 of file vlsvdiff.cpp.

Here is the caller graph for this function:

◆ outputDt()

bool outputDt ( const Real dt,
const bool verboseOutput,
const bool lastCall )

In verbose mode print delta t, in non-verbose store them for later output when lastCall is true

Parameters
dtdelta t
verboseOutputBoolean parameter telling whether the output is verbose or compact
lastCallBoolean parameter telling whether this is the last call to the function

Definition at line 947 of file vlsvdiff.cpp.

Here is the caller graph for this function:

◆ outputStats()

bool outputStats ( const Real * size,
const Real * mini,
const Real * maxi,
const Real * avg,
const Real * stdev,
const bool verboseOutput,
const bool lastCall )

In verbose mode print the statistics, in non-verbose store them for later output when lastCall is true

Parameters
sizePointer to dataset size
miniPointer to dataset minimum
maxiPointer to dataset maximum
avgPointer to dataset average
stdevPointer to dataset standard deviation
verboseOutputBoolean parameter telling whether the output is verbose or compact
lastCallBoolean parameter telling whether this is the last call to the function
See also
singleStatistics

Definition at line 1011 of file vlsvdiff.cpp.

Here is the caller graph for this function:

◆ pDistance()

bool pDistance ( const map< uint, Real > & orderedData1,
const map< uint, Real > & orderedData2,
creal p,
Real * absolute,
Real * relative,
const bool doShiftAverage,
const unordered_map< size_t, size_t > & cellOrder,
vlsv::Writer & outputFile,
const std::string & meshName,
const std::string & varName )

Compute the absolute and relative $ p $-distance between two datasets X(x) provided in the maps orderedData1 and orderedData2. Note that the dataset passed in orderedData1 will be taken as the reference dataset both when shifting averages and when computing relative distances.

For $ p \neq 0 $:

absolute $ p $-distance defined as:

$ \|X_1 - X_2\|_p = \left[\sum_i |X_1(i) - X_2(i)|^p\right]^{1/p}$,

relative $ p $-distance defined as:

$ \|X_1 - X_2\|_p = \left[\sum_i |X_1(i) - X_2(i)|^p\right]^{1/p} / \|X_1\|_p $.

For $ p = 0 $ it is the $ \infty $-distance:

absolute $ \infty $-distance defined as:

$ \|X_1 - X_2\|_\infty = \max_i\left(|X_1(i) - X_2(i)|\right)$

relative $ \infty $-distance defined as:

$ \|X_1 - X_2\|_\infty = \max_i\left(|X_1(i) - X_2(i)|\right) / \|X_1\|_\infty $

Parameters
orderedData1Pointer to the first file's data map
orderedData2Pointer to the second file's data map
pParameter of the distance formula
absoluteReturn argument pointer, absolute value
relativeReturn argument pointer, relative value
doShiftAverageBoolean argument to determine whether to shift the second file's data
See also
shiftAverage

Definition at line 810 of file vlsvdiff.cpp.

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

◆ printHelp()

void printHelp ( const map< string, string > & defAttribs,
const map< string, string > & descriptions )

Definition at line 1704 of file vlsvdiff.cpp.

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

◆ printNonVerboseData()

bool printNonVerboseData ( )

In folder-processing, non-verbose mode the data are stored during the processing and output at the end to have the data sorted properly

See also
outputStats outputDistance

Definition at line 1045 of file vlsvdiff.cpp.

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

◆ process2Files()

bool process2Files ( const string fileName1,
const string fileName2,
const char * varToExtract,
const uint compToExtract,
const bool verboseOutput,
const uint compToExtract2 = 0 )

Read in the contents of the variable component in both files passed in strings fileName1 and fileName2, and compute statistics and distances as wished

Parameters
fileName1String argument giving the location of the first file to process
fileName2String argument giving the location of the second file to process
varToExtractPointer to the char array containing the name of the variable to extract
compToExtractUnsigned int designating the component to extract (0 for scalars)
verboseOutputBoolean parameter telling whether the output will be verbose or compact
See also
convertSILO singleStatistics outputStats pDistance outputDistance printNonVerboseData

Definition at line 1570 of file vlsvdiff.cpp.

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

◆ processDirectory()

bool processDirectory ( DIR * dir,
set< string > * fileList )

Creates the list of grid*.vlsv files present in the folder passed

Parameters
dirDIR type pointer to the directory entry to process
fileListPointer to a set of strings, return argument for the produced file list

Definition at line 1681 of file vlsvdiff.cpp.

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

◆ readAvgs()

template<class T>
bool readAvgs ( T & vlsvReader,
string name,
const unordered_map< uint64_t, pair< uint64_t, uint32_t > > & cellsWithBlocksLocations,
const uint64_t & cellId,
unordered_map< uint32_t, vector< double > > & avgs,
uint64_t & vectorSize )

Definition at line 1157 of file vlsvdiff.cpp.

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

◆ shiftAverage()

bool shiftAverage ( const map< uint, Real > *const orderedData1,
const map< uint, Real > *const orderedData2,
map< uint, Real > * shiftedData2 )

Shift the second file to the average of the first

Parameters
orderedData1Pointer to the reference file's data
orderedData2Pointer to the data to be shifted
shiftedData2Pointer to where the shifted data of the second file will be put

Definition at line 757 of file vlsvdiff.cpp.

Here is the caller graph for this function:

◆ singleStatistics()

bool singleStatistics ( map< uint, Real > * orderedData,
Real * size,
Real * mini,
Real * maxi,
Real * avg,
Real * stdev )

Compute statistics on a single file

Parameters
sizeReturn argument pointer, dataset size
miniReturn argument pointer, dataset minimum
maxiReturn argument pointer, dataset maximum
avgReturn argument pointer, dataset average
stdevReturn argument pointer, dataset standard deviation

Definition at line 975 of file vlsvdiff.cpp.

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

Variable Documentation

◆ attributes

map<string, string> attributes
static

Definition at line 71 of file vlsvdiff.cpp.

◆ gridName

int gridName
static

Definition at line 74 of file vlsvdiff.cpp.