From daa99c922ccde420d2f31d3f832f3c30a5f23219 Mon Sep 17 00:00:00 2001 From: kstppd Date: Wed, 12 May 2021 13:50:50 +0300 Subject: [PATCH 1/6] vlsvdiff now works for AMR runs --- tools/vlsvdiff.cpp | 86 ++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/tools/vlsvdiff.cpp b/tools/vlsvdiff.cpp index ef1eb7a5e..95fd1d440 100644 --- a/tools/vlsvdiff.cpp +++ b/tools/vlsvdiff.cpp @@ -491,21 +491,40 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, } }else if (gridName==gridType::fsgrid){ - - + + + // Get Spatial Grid's max refinement Level + int maxRefLevel=0; + list> meshAttributesIn; + meshAttributesIn.push_back(make_pair("name", "SpatialGrid")); + map meshAttributesOut; + if (vlsvReader.getArrayAttributes("MESH", meshAttributesIn,meshAttributesOut) == false) + { + cerr << "ERROR, failed to get array info for '" << _varToExtract << "' at " << __FILE__ << " " << __LINE__ << endl; + return false; + } + + std::map::iterator attributesOutIt; + attributesOutIt = meshAttributesOut.find("max_refinement_level"); + if (attributesOutIt != meshAttributesOut.end()) + { + maxRefLevel = stoi(attributesOutIt->second); + } int numtasks; - int xcells,ycells,zcells; + int xcells,ycells,zcells; vlsvReader.readParameter("numWritingRanks",numtasks); vlsvReader.readParameter("xcells_ini",xcells); vlsvReader.readParameter("ycells_ini",ycells); vlsvReader.readParameter("zcells_ini",zcells); + xcells*=pow(2,maxRefLevel); + ycells*=pow(2,maxRefLevel); + zcells*=pow(2,maxRefLevel); std::array GlobalBox={xcells,ycells,zcells}; std::array thisDomainDecomp; //Compute Domain Decomposition Scheme for this vlsv file computeDomainDecomposition(GlobalBox,numtasks,thisDomainDecomp); - std::array taskSize,taskStart; std::array taskEnd; int readOffset=0; @@ -513,7 +532,6 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, int index,my_x,my_y,my_z; orderedData->clear(); - //Read into buffer for (int task=0; task readIn(variableVectorSize * variableDataSize*readSize); + readSize= taskSize[0] * taskSize[1] * taskSize[2] ; + //Allocate vector for reading + std::vector buffer(readSize*variableVectorSize); - - int counter2=0; - uint64_t globalindex; - int64_t counter=0; - for(int z=taskStart[2]; zinsert(pair(globalindex, data)); } - orderedData->insert(pair(globalindex, extract)); - counter++; - } } - } readOffset+=readSize; - } + counter++; + } }else{ cerr<<"meshName not recognized\t" << __FILE__ << " " << __LINE__ < Date: Tue, 18 May 2021 15:15:26 +0300 Subject: [PATCH 2/6] vlsvdiff now works for AMR runs --- tools/vlsvdiff.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/vlsvdiff.cpp b/tools/vlsvdiff.cpp index 95fd1d440..167dcf1e3 100644 --- a/tools/vlsvdiff.cpp +++ b/tools/vlsvdiff.cpp @@ -503,6 +503,7 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, cerr << "ERROR, failed to get array info for '" << _varToExtract << "' at " << __FILE__ << " " << __LINE__ << endl; return false; } + std::cerr << "read" << std::endl; std::map::iterator attributesOutIt; attributesOutIt = meshAttributesOut.find("max_refinement_level"); @@ -528,7 +529,6 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, std::array taskSize,taskStart; std::array taskEnd; int readOffset=0; - size_t readSize; int index,my_x,my_y,my_z; orderedData->clear(); @@ -551,7 +551,7 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, taskEnd[1]= taskStart[1]+taskSize[1]; taskEnd[2]= taskStart[2]+taskSize[2]; - readSize= taskSize[0] * taskSize[1] * taskSize[2] ; + int64_t readSize= taskSize[0] * taskSize[1] * taskSize[2] ; //Allocate vector for reading std::vector buffer(readSize*variableVectorSize); @@ -586,11 +586,12 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, } //Add to map orderedData->insert(pair(globalindex, data)); + counter++; } } } readOffset+=readSize; - counter++; + } }else{ cerr<<"meshName not recognized\t" << __FILE__ << " " << __LINE__ < Date: Tue, 18 May 2021 15:43:51 +0300 Subject: [PATCH 3/6] increment by variable vector size --- tools/vlsvdiff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/vlsvdiff.cpp b/tools/vlsvdiff.cpp index 167dcf1e3..dc8d2d2b2 100644 --- a/tools/vlsvdiff.cpp +++ b/tools/vlsvdiff.cpp @@ -586,7 +586,7 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, } //Add to map orderedData->insert(pair(globalindex, data)); - counter++; + counter+=variableVectorSize; } } } From f6b92acf78cab09844f316865057bc8081e479b2 Mon Sep 17 00:00:00 2001 From: kstppd Date: Wed, 19 May 2021 11:30:03 +0300 Subject: [PATCH 4/6] remove some print that was left in there by accident --- tools/vlsvdiff.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/vlsvdiff.cpp b/tools/vlsvdiff.cpp index dc8d2d2b2..6446a8099 100644 --- a/tools/vlsvdiff.cpp +++ b/tools/vlsvdiff.cpp @@ -503,7 +503,6 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, cerr << "ERROR, failed to get array info for '" << _varToExtract << "' at " << __FILE__ << " " << __LINE__ << endl; return false; } - std::cerr << "read" << std::endl; std::map::iterator attributesOutIt; attributesOutIt = meshAttributesOut.find("max_refinement_level"); From 2d833bacc449cd417a12f2cc39395d96c3c0930f Mon Sep 17 00:00:00 2001 From: kstppd Date: Thu, 20 May 2021 12:05:35 +0300 Subject: [PATCH 5/6] This will handle datasize mismatches --- tools/vlsvdiff.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/vlsvdiff.cpp b/tools/vlsvdiff.cpp index 6446a8099..dace7e2e1 100644 --- a/tools/vlsvdiff.cpp +++ b/tools/vlsvdiff.cpp @@ -554,10 +554,22 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, //Allocate vector for reading std::vector buffer(readSize*variableVectorSize); - if (vlsvReader.readArray("VARIABLE", variableAttributes, readOffset, readSize, (char*)buffer.data()) == false) { - cerr << "ERROR, failed to read variable '" << _varToExtract << "' at " << __FILE__ << " " << __LINE__ << endl; - variableSuccess = false; - break; + if ( variableDataSize==sizeof(Real)){ + if (vlsvReader.readArray("VARIABLE", variableAttributes, readOffset, readSize, (char*)buffer.data()) == false) { + cerr << "ERROR, failed to read variable '" << _varToExtract << "' at " << __FILE__ << " " << __LINE__ << endl; + variableSuccess = false; + break; + } + }else{ + std::vector tmpbuffer(readSize * variableVectorSize); + if (vlsvReader.readArray("VARIABLE", variableAttributes, readOffset, readSize, (char *)tmpbuffer.data()) == false){ + cerr << "ERROR, failed to read variable '" << _varToExtract << "' at " << __FILE__ << " " << __LINE__ << endl; + variableSuccess = false; + break; + } + for (int i = 0; i < readSize * variableVectorSize; i++){ + buffer[i] = tmpbuffer[i]; + } } uint64_t globalindex,counter=0;; From b3a852c7b03606ed1ecb1625db07cb730d69a7a2 Mon Sep 17 00:00:00 2001 From: Yann Kempf Date: Thu, 20 May 2021 12:16:34 +0300 Subject: [PATCH 6/6] vlsvdiff for ionosphere --- tools/vlsvdiff.cpp | 106 +++++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 32 deletions(-) diff --git a/tools/vlsvdiff.cpp b/tools/vlsvdiff.cpp index dace7e2e1..c0433230c 100644 --- a/tools/vlsvdiff.cpp +++ b/tools/vlsvdiff.cpp @@ -421,14 +421,13 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, cerr << "ERROR, failed to get array info for '" << _varToExtract << "' at " << __FILE__ << " " << __LINE__ << endl; return false; } + + if (gridName==gridType::SpatialGrid) { char *variableBuffer = new char[variableVectorSize * variableDataSize]; float *variablePtrFloat = reinterpret_cast(variableBuffer); double *variablePtrDouble = reinterpret_cast(variableBuffer); uint *variablePtrUint = reinterpret_cast(variableBuffer); int *variablePtrInt = reinterpret_cast(variableBuffer); - - - if (gridName==gridType::SpatialGrid){ // Read the mesh array one node (of a spatial cell) at a time // and create a map which contains each cell's CellID and variable to be extracted @@ -488,9 +487,9 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, if (storeCellOrder == true) { cellOrder[CellID] = i; } - } - - }else if (gridName==gridType::fsgrid){ + } + delete variableBuffer; + } else if (gridName==gridType::fsgrid) { // Get Spatial Grid's max refinement Level @@ -602,9 +601,57 @@ bool convertMesh(vlsvinterface::Reader& vlsvReader, } } readOffset+=readSize; + } + } else if (gridName==gridType::ionosphere) { + char *variableBuffer = new char[variableArraySize * variableVectorSize * variableDataSize]; + float *variablePtrFloat = reinterpret_cast(variableBuffer); + double *variablePtrDouble = reinterpret_cast(variableBuffer); + uint *variablePtrUint = reinterpret_cast(variableBuffer); + int *variablePtrInt = reinterpret_cast(variableBuffer); + + if (compToExtract + 1 > variableVectorSize) { + cerr << "ERROR invalid component, this variable has size " << variableVectorSize << endl; + abort(); + } + + if (storeCellOrder == true) { + cellOrder.clear(); + } + + orderedData->clear(); + + if (vlsvReader.readArray("VARIABLE", variableAttributes, 0, variableArraySize, variableBuffer) == false) { + cerr << "ERROR, failed to read variable '" << _varToExtract << "' at " << __FILE__ << " " << __LINE__ << endl; + variableSuccess = false; + } + + for (uint64_t i=0; iinsert(pair(i, extract)); + if (storeCellOrder == true) { + cellOrder[i] = i; + } + } + delete variableBuffer; + } else { cerr<<"meshName not recognized\t" << __FILE__ << " " << __LINE__ <& orderedData1, value = abs(it1->second - it2->second); *absolute = max(*absolute, value); length = max(length, abs(it1->second)); - - } - if (gridName==gridType::SpatialGrid){ + } + if (gridName==gridType::SpatialGrid) { array[cellOrder.at(it1->first)] = value; - }else if (gridName==gridType::fsgrid) { - + } else if (gridName==gridType::fsgrid || gridName==gridType::ionosphere) { array.at(it1->first)=value; - } + } } } else if (p == 1) { for (map::const_iterator it1=orderedData1.begin(); it1!=orderedData1.end(); ++it1) { @@ -778,13 +822,12 @@ bool pDistance(const map& orderedData1, value = abs(it1->second - it2->second); *absolute += value; length += abs(it1->second); - - } - if (gridName==gridType::SpatialGrid){ + } + if (gridName==gridType::SpatialGrid) { array[cellOrder.at(it1->first)] = value; - }else if (gridName==gridType::fsgrid){ + } else if (gridName==gridType::fsgrid || gridName==gridType::ionosphere) { array[it1->first]=value; - } + } } } else { for (map::const_iterator it1=orderedData1.begin(); it1!=orderedData1.end(); ++it1) { @@ -794,13 +837,12 @@ bool pDistance(const map& orderedData1, value = pow(abs(it1->second - it2->second), p); *absolute += value; length += pow(abs(it1->second), p); - - } - if (gridName==gridType::SpatialGrid){ + } + if (gridName==gridType::SpatialGrid) { array[cellOrder.at(it1->first)] = pow(value,1.0/p); - }else if (gridName==gridType::fsgrid){ + }else if (gridName==gridType::fsgrid || gridName==gridType::ionosphere) { array[it1->first]=pow(value,1.0/p); - } + } } *absolute = pow(*absolute, 1.0 / p); length = pow(length, 1.0 / p); @@ -1812,13 +1854,13 @@ int main(int argn,char* args[]) { //Figure out Meshname - if (attributes["--meshname"] == "SpatialGrid") { - gridName=gridType::SpatialGrid ; - }else if (attributes["--meshname"]=="fsgrid"){ - gridName=gridType::fsgrid ; - }else if (attributes["--meshname"]=="ionosphere"){ - gridName=gridType::ionosphere ; - }else{ + if (attributes["--meshname"] == "SpatialGrid") { + gridName=gridType::SpatialGrid; + } else if (attributes["--meshname"]=="fsgrid") { + gridName=gridType::fsgrid; + } else if (attributes["--meshname"]=="ionosphere") { + gridName=gridType::ionosphere; + } else { std::cout<