38#include <initializer_list>
65 const dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
66 const std::vector<CellID>& cells, MPI_Comm comm);
69 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
70 const std::vector<CellID>& cells,std::vector<std::vector<char>>&mpl_bytes,MPI_Comm comm);
79bool updateLocalIds(dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
80 const std::vector<CellID>& local_cells,
83 MPI_Comm_rank(comm, &
myRank);
86 vector<CellID>::const_iterator it;
88 CellID thisProcessLocalId = 0;
90 for (it = local_cells.begin(); it != local_cells.end(); ++it) {
93 mpiGrid[(*it)]->ioLocalCellId = thisProcessLocalId;
110bool globalSuccess(
bool success,
const string& errorMessage, MPI_Comm comm) {
112 int globalSuccessInt;
119 MPI_Allreduce(&successInt, &globalSuccessInt, 1, MPI_INT, MPI_MIN, comm);
121 if (globalSuccessInt == 1) {
136 const dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
137 const vector<CellID>& cells, MPI_Comm comm) {
146 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
147 const vector<CellID>& cells,std::vector<std::vector<char>>&mlp_bytes,MPI_Comm comm) {
162 const dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
163 const std::vector<CellID>& cells, MPI_Comm comm) {
167 map<string, string> attribs;
169 const string spatMeshName =
"SpatialGrid";
170 attribs[
"name"] = popName;
174 uint64_t totalBlocks = 0;
175 vector<vmesh::LocalID> blocksPerCell;
176 for (
size_t i = 0;
i < cells.size(); ++
i) {
177 totalBlocks += mpiGrid[cells[
i]]->get_number_of_velocity_blocks(popID);
178 blocksPerCell.push_back(mpiGrid[cells[
i]]->get_number_of_velocity_blocks(popID));
182 attribs[
"mesh"] = spatMeshName;
184 const unsigned int vectorSize = 1;
186 if (vlsvWriter.writeArray(
"CELLSWITHBLOCKS", attribs, cells.size(), vectorSize, cells.data()) ==
false) success =
false;
187 if (success ==
false)
logFile <<
"(MAIN) writeGrid: ERROR failed to write CELLSWITHBLOCKS to file!" << endl <<
writeVerbose;
189 if (vlsvWriter.writeArray(
"BLOCKSPERCELL", attribs, blocksPerCell.size(), vectorSize, blocksPerCell.data()) ==
false) success =
false;
190 if (success ==
false)
logFile <<
"(MAIN) writeGrid: ERROR failed to write CELLSWITHBLOCKS to file!" << endl <<
writeVerbose;
207 attribs[
"type"] = vlsv::mesh::STRING_UCD_AMR;
212 ss << static_cast<unsigned int>(0);
213 attribs[
"max_velocity_ref_level"] = ss.str();
216 if (vlsvWriter.writeArray(
"MESH_BBOX", attribs, 6, 1, bbox) ==
false) success =
false;
218 for (
int crd = 0; crd < 3; ++crd) {
219 const size_t N_nodes = bbox[crd] * bbox[crd + 3] + 1;
223 for (
size_t i = 0;
i < N_nodes; ++
i) {
228 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_X", attribs, N_nodes, 1, crds) ==
false) success =
false;
231 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Y", attribs, N_nodes, 1, crds) ==
false) success =
false;
234 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Z", attribs, N_nodes, 1, crds) ==
false) success =
false;
240 if (vlsvWriter.writeArray(
"MESH_BBOX", attribs, 0, 1, bbox) ==
false) success =
false;
242 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_X", attribs, 0, 1, crds) ==
false) success =
false;
243 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Y", attribs, 0, 1, crds) ==
false) success =
false;
244 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Z", attribs, 0, 1, crds) ==
false) success =
false;
248 vector<vmesh::GlobalID> velocityBlockIds(totalBlocks);
252 for (
size_t i = 0;
i < cells.size(); ++
i) {
261 velocityBlockIds[blockIndex + block_i] = block;
264 blockIndex += nBlocks;
267 cerr <<
"FAILED TO WRITE VELOCITY BLOCK IDS AT: " << __FILE__ <<
" " << __LINE__ << endl;
271 if (
globalSuccess(success,
"(MAIN) writeGrid: ERROR: Failed to fill temporary array velocityBlockIds", MPI_COMM_WORLD) ==
false) {
277 attribs[
"mesh"] = spatMeshName;
278 attribs[
"name"] = popName;
279 if (vlsvWriter.writeArray(
"BLOCKIDS", attribs, totalBlocks, vectorSize, velocityBlockIds.data()) ==
false) success =
false;
280 if (success ==
false)
logFile <<
"(MAIN) writeGrid: ERROR failed to write BLOCKIDS to file!" << endl <<
writeVerbose;
282 vector<vmesh::GlobalID>().swap(velocityBlockIds);
287 attribs[
"mesh"] = spatMeshName;
288 attribs[
"name"] = popName;
289 const string datatype_avgs =
"float";
290 const uint64_t arraySize_avgs = totalBlocks;
291 const uint64_t vectorSize_avgs =
WID3;
294 uint64_t dataSize_avgs =
sizeof(
Realf);
297 vlsvWriter.startMultiwrite(datatype_avgs, arraySize_avgs, vectorSize_avgs, dataSize_avgs);
301 uint64_t bufferOffset = 0;
305 for (
size_t i = 0;
i < cells.size(); ++
i) {
313 char* arrayToWrite =
IObuffer + bufferOffset;
314 if (arrayElements > 0) {
316 bufferOffset += arrayElements *
WID3 *
sizeof(
Realf);
319 char* arrayToWrite =
reinterpret_cast<char*
>(SC->
get_data(popID));
321 vlsvWriter.addMultiwriteUnit(arrayToWrite, arrayElements);
323 if (cells.size() == 0) {
324 vlsvWriter.addMultiwriteUnit(NULL, 0);
328 vlsvWriter.endMultiwrite(
"BLOCKVARIABLE", attribs);
330 if (
globalSuccess(success,
"(MAIN) writeGrid: ERROR: Failed to fill temporary velocityBlockData array", MPI_COMM_WORLD) ==
false) {
335 if (success ==
false) {
336 logFile <<
"(MAIN) writeGrid: ERROR occurred when writing BLOCKVARIABLE f" << endl <<
writeVerbose;
343 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
344 const std::vector<CellID>& cells,std::size_t totalBlocks, MPI_Comm comm){
347 vlsvWriter.writeParameter(
"COMPRESSION",&cmp);
350 const string spatMeshName =
"SpatialGrid";
351 map<string,string> attribs;
352 vector<vmesh::GlobalID> velocityBlockIds;
354 velocityBlockIds.reserve( totalBlocks );
356 for (
size_t cell=0; cell<cells.size(); ++cell) {
360 velocityBlockIds.push_back( block );
364 cerr <<
"FAILED TO WRITE VELOCITY BLOCK IDS AT: " << __FILE__ <<
" " << __LINE__ << endl;
368 if (
globalSuccess(success,
"(MAIN) writeGrid: ERROR: Failed to fill temporary array velocityBlockIds",MPI_COMM_WORLD) ==
false) {
374 attribs[
"mesh"] = spatMeshName;
375 attribs[
"name"] = popName;
376 if (vlsvWriter.writeArray(
"BLOCKIDS", attribs, totalBlocks, 1, velocityBlockIds.data()) ==
false) success =
false;
377 if (success ==
false)
logFile <<
"(MAIN) writeGrid: ERROR failed to write BLOCKIDS to file!" << endl <<
writeVerbose;
379 vector<vmesh::GlobalID>().swap(velocityBlockIds);
383 attribs[
"mesh"] = spatMeshName;
384 attribs[
"name"] = popName;
385 attribs[
"compression"] =
"None";
386 const string datatype_avgs =
"float";
387 const uint64_t arraySize_avgs = totalBlocks;
388 const uint64_t vectorSize_avgs =
WID3;
391 uint64_t dataSize_avgs =
sizeof(
Realf);
394 vlsvWriter.startMultiwrite(datatype_avgs,arraySize_avgs,vectorSize_avgs,dataSize_avgs);
397 for (
size_t cell = 0; cell<cells.size(); ++cell) {
403 char* arrayToWrite =
reinterpret_cast<char*
>(SC->
get_data(popID));
406 vlsvWriter.addMultiwriteUnit(arrayToWrite, arrayElements);
408 if (cells.size() == 0) {
409 vlsvWriter.addMultiwriteUnit(NULL, 0);
412 vlsvWriter.endMultiwrite(
"BLOCKVARIABLE", attribs);
414 if (
globalSuccess(success,
"(MAIN) writeGrid: ERROR: Failed to fill temporary velocityBlockData array",MPI_COMM_WORLD) ==
false) {
423bool writeVspaceDataCompressionZFP(
const uint popID,Writer& vlsvWriter,
424 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
425 const std::vector<CellID>& cells,std::size_t totalBlocks, MPI_Comm comm){
431 if(!vlsvWriter.writeParameter(
"COMPRESSION",&cmp)){
432 logFile<<
"ERROR: Failed to write COMPRESSION parameter in vlsv file"<<std::endl<<
write;
437 const string spatMeshName =
"SpatialGrid";
438 map<string,string> attribs;
439 vector<vmesh::GlobalID> velocityBlockIds;
441 velocityBlockIds.reserve( totalBlocks );
443 for (
size_t cell=0; cell<
cells.size(); ++cell) {
447 velocityBlockIds.push_back( block );
451 cerr <<
"FAILED TO WRITE VELOCITY BLOCK IDS AT: " << __FILE__ <<
" " << __LINE__ << endl;
455 if (
globalSuccess(success,
"(MAIN) writeGrid: ERROR: Failed to fill temporary array velocityBlockIds",MPI_COMM_WORLD) ==
false) {
461 attribs[
"mesh"] = spatMeshName;
462 attribs[
"name"] = popName;
463 if (vlsvWriter.writeArray(
"BLOCKIDS", attribs, totalBlocks, 1, velocityBlockIds.data()) ==
false) success =
false;
464 if (success ==
false)
logFile <<
"(MAIN) writeGrid: ERROR failed to write BLOCKIDS to file!" << endl <<
writeVerbose;
466 vector<vmesh::GlobalID>().swap(velocityBlockIds);
469 std::size_t totalElements=0;
470 for (
const auto& cid:cells){
471 totalElements+=mpiGrid[cid]->get_population(popID).compressed_state_buffer.size();
475 attribs[
"mesh"] = spatMeshName;
476 attribs[
"name"] = popName;
477 attribs[
"compression"] =
"ZFP";
478 const string datatype_avgs =
"uint";
479 const uint64_t arraySize_avgs = totalElements;
480 const uint64_t vectorSize_avgs = 1;
483 uint64_t dataSize_avgs = 1;
486 vlsvWriter.startMultiwrite(datatype_avgs,arraySize_avgs,vectorSize_avgs,dataSize_avgs);
489 for (
size_t cell = 0; cell<
cells.size(); ++cell) {
495 char* arrayToWrite =
reinterpret_cast<char*
>(SC->
get_population(popID).compressed_state_buffer.data());
498 vlsvWriter.addMultiwriteUnit(arrayToWrite, arrayElements);
500 if (
cells.size() == 0) {
501 vlsvWriter.addMultiwriteUnit(NULL, 0);
504 vlsvWriter.endMultiwrite(
"BLOCKVARIABLE", attribs);
506 if (
globalSuccess(success,
"(MAIN) writeGrid: ERROR: Failed to fill temporary velocityBlockData array",MPI_COMM_WORLD) ==
false) {
517bool writeVspaceDataCompressionOCTREE(
const uint popID,Writer& vlsvWriter,
518 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
519 const std::vector<CellID>& cells,std::size_t totalBlocks, MPI_Comm comm){
523 if (!vlsvWriter.writeParameter(
"COMPRESSION",&cmp)){
524 logFile<<
"ERROR: Failed to write COMPRESSION parameter in vlsv file"<<std::endl<<
write;
527 std::size_t totalElements=0;
528 for (
const auto& cid:cells){
529 totalElements+=mpiGrid[cid]->get_population(popID).compressed_state_buffer.size();
532 map<string,string> attribs;
534 const string spatMeshName =
"SpatialGrid";
535 attribs[
"mesh"] = spatMeshName;
536 attribs[
"name"] = popName;
537 attribs[
"compression"] =
"OCTREE";
538 const string datatype_avgs =
"uint";
539 const uint64_t arraySize_avgs = totalElements;
540 const uint64_t vectorSize_avgs = 1;
543 uint64_t dataSize_avgs =1;
546 vlsvWriter.startMultiwrite<
char>(arraySize_avgs,vectorSize_avgs);
549 for (
size_t cell = 0; cell<
cells.size(); ++cell) {
555 char* arrayToWrite =
reinterpret_cast<char*
>(SC->
get_population(popID).compressed_state_buffer.data());
558 vlsvWriter.addMultiwriteUnit<
char>(arrayToWrite, arrayElements);
560 if (
cells.size() == 0) {
561 vlsvWriter.addMultiwriteUnit(NULL, 0);
564 vlsvWriter.endMultiwrite(
"BLOCKVARIABLE", attribs);
566 if (
globalSuccess(success,
"(MAIN) writeGrid: ERROR: Failed to fill temporary velocityBlockData array",MPI_COMM_WORLD) ==
false) {
576bool writeVspaceDataCompressionMLP(
const uint popID,Writer& vlsvWriter,
577 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
578 const std::vector<CellID>& cells,std::vector<std::vector<char>>&mlp_bytes,std::size_t totalBlocks, MPI_Comm comm){
582 const string spatMeshName =
"SpatialGrid";
584 if (!vlsvWriter.writeParameter(
"COMPRESSION",&cmp)){
585 logFile<<
"ERROR: Failed to write COMPRESSION parameter in vlsv file"<<std::endl<<
write;
589 if (!vlsvWriter.writeParameter(
"FOURIER_ORDER",&fourier_order)){
590 logFile<<
"ERROR: Failed to write FOURIER_ORDER parameter in vlsv file"<<std::endl<<
write;
593 map<string,string> attribs;
595 attribs[
"mesh"] = spatMeshName;
596 attribs[
"name"] = popName;
598 if (!vlsvWriter.writeArrayMaster(
"MLP_ARCH",attribs,
"int",array_size,1,
sizeof(
size_t),(
const char*)
P::mlp_arch.data())){
599 logFile<<
"ERROR: Failed to write MLP_ARCH in vlsv file"<<std::endl<<
write;
604 std::size_t totalElements=0;
605 for (
const auto& b: mlp_bytes){
606 totalElements+=
b.size();
610 attribs[
"mesh"] = spatMeshName;
611 attribs[
"name"] = popName;
612 attribs[
"compression"] =
"MLP";
613 const string datatype_avgs =
"uint";
614 const uint64_t arraySize_avgs = totalElements;
615 const uint64_t vectorSize_avgs = 1;
616 vlsvWriter.startMultiwrite(datatype_avgs,arraySize_avgs,vectorSize_avgs,1);
617 for (
const auto& b: mlp_bytes){
618 const auto arrayElements =
b.size();
619 if (arrayElements>0){
620 vlsvWriter.addMultiwriteUnit(
b.data(), arrayElements);
622 vlsvWriter.addMultiwriteUnit(
nullptr, 0);
625 vlsvWriter.endMultiwrite(
"BLOCKVARIABLE", attribs);
626 if (
globalSuccess(success,
"(MAIN) writeGrid: ERROR: Failed to fill temporary velocityBlockData array",MPI_COMM_WORLD) ==
false) {
635 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
636 const std::vector<CellID>& cells,std::vector<std::vector<char>>&bytes,MPI_Comm comm) {
640 map<string,string> attribs;
642 const string spatMeshName =
"SpatialGrid";
643 attribs[
"name"] = popName;
647 uint64_t totalBlocks = 0;
648 vector<vmesh::LocalID> blocksPerCell;
649 vector<std::size_t> bytesPerCell;
650 vector<std::size_t> mlpBytesPerRank;
651 for (
size_t cell=0; cell<cells.size(); ++cell){
652 totalBlocks+=mpiGrid[cells[cell]]->get_number_of_velocity_blocks(popID);
653 blocksPerCell.push_back(mpiGrid[cells[cell]]->get_number_of_velocity_blocks(popID));
654 bytesPerCell.push_back(mpiGrid[cells[cell]]->get_population(popID).compressed_state_buffer.size());
662 for (
const auto& b:bytes){
665 if (!vlsvWriter.writeArray<std::size_t>(
"MLP_BYTES_PER_RANK",attribs,1,1,&bpr)){
666 logFile<<
"ERROR: Failed to write mlp bytes per rank to restart file"<<endl<<
write;
670 const std::size_t mlp_clusters_per_rank=bytes.size();
671 if (!vlsvWriter.writeArray<std::size_t>(
"MLP_CLUSTERS_PER_RANK",attribs,1,1,&mlp_clusters_per_rank)){
672 logFile<<
"ERROR: Failed to write mlp cluster per rank to restart file"<<endl<<
write;
678 attribs[
"mesh"] = spatMeshName;
680 const unsigned int vectorSize = 1;
682 if (vlsvWriter.writeArray(
"CELLSWITHBLOCKS",attribs,cells.size(),vectorSize,cells.data()) ==
false) success =
false;
683 if (success ==
false)
logFile <<
"(MAIN) writeGrid: ERROR failed to write CELLSWITHBLOCKS to file!" << endl <<
writeVerbose;
685 if(vlsvWriter.writeArray(
"BLOCKSPERCELL",attribs,blocksPerCell.size(),vectorSize,blocksPerCell.data()) ==
false) success =
false;
686 if(vlsvWriter.writeArray(
"BYTESPERCELL",attribs,bytesPerCell.size(),1,bytesPerCell.data()) ==
false) success =
false;
687 if (success ==
false)
logFile <<
"(MAIN) writeGrid: ERROR failed to write CELLSWITHBLOCKS to file!" << endl <<
writeVerbose;
704 attribs[
"type"] = vlsv::mesh::STRING_UCD_AMR;
709 ss << static_cast<unsigned int>(0);
710 attribs[
"max_velocity_ref_level"] = ss.str();
712 if (vlsvWriter.writeArray(
"MESH_BBOX",attribs,6,1,bbox) ==
false) success =
false;
714 for (
int crd=0; crd<3; ++crd) {
715 const size_t N_nodes = bbox[crd]*bbox[crd+3]+1;
719 for (
size_t i=0;
i<N_nodes; ++
i) {
724 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_X",attribs,N_nodes,1,crds) ==
false) success =
false;
727 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Y",attribs,N_nodes,1,crds) ==
false) success =
false;
730 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Z",attribs,N_nodes,1,crds) ==
false) success =
false;
732 delete [] crds; crds = NULL;
735 if (vlsvWriter.writeArray(
"MESH_BBOX",attribs,0,1,bbox) ==
false) success =
false;
737 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_X",attribs,0,1,crds) ==
false) success =
false;
738 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Y",attribs,0,1,crds) ==
false) success =
false;
739 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Z",attribs,0,1,crds) ==
false) success =
false;
742 const std::size_t vdf_byte_size=
sizeof(
Realf);
743 if (!vlsvWriter.writeParameter<
size_t>(
"VDF_BYTE_SIZE",&vdf_byte_size)){
744 logFile<<
"ERROR: Failed to write compression type parameter in vlsv!"<<endl<<
write;
754 success=writeVspaceDataCompressionMLP(popID,vlsvWriter,mpiGrid,cells,bytes,totalBlocks,comm);
757 success=writeVspaceDataCompressionMLP(popID,vlsvWriter,mpiGrid,cells,bytes,totalBlocks,comm);
762 success=writeVspaceDataCompressionZFP(popID,vlsvWriter,mpiGrid,cells,totalBlocks,comm);
767 success=writeVspaceDataCompressionOCTREE(popID,vlsvWriter,mpiGrid,cells,totalBlocks,comm);
771 std::cout<<
"ABORT DEFAULT"<<std::endl;
775 if (success ==
false) {
776 logFile <<
"(MAIN) writeGrid: ERROR occurred when writing BLOCKVARIABLE f" << endl <<
writeVerbose;
791 const std::vector<CellID>& cells,
const FieldSolverData& fieldSolverData,
const bool writeAsFloat,
792 const bool writeFsGrid,
DataReducer& dataReducer,
cint dataReducerIndex, Writer& vlsvWriter) {
793 map<string, string> attribs;
794 string variableName, dataType, unitString, unitStringLaTeX, variableStringLaTeX, unitConversionFactor;
798 variableName = dataReducer.
getName(dataReducerIndex);
799 if (variableName.find(
"fg_", 0) == 0) {
804 const string meshName =
"SpatialGrid";
805 variableName = dataReducer.
getName(dataReducerIndex);
806 phiprof::Timer droTimer{
"DRO_" + variableName};
809 uint dataSize, vectorSize;
810 attribs[
"mesh"] = meshName;
811 attribs[
"name"] = variableName;
812 if (dataReducer.
getDataVectorInfo(dataReducerIndex, dataType, dataSize, vectorSize) ==
false) {
813 cerr <<
"ERROR when requesting info from DRO " << dataReducerIndex << endl;
818 if (dataReducer.
getMetadata(dataReducerIndex, unitString, unitStringLaTeX, variableStringLaTeX, unitConversionFactor) ==
false) {
819 cerr <<
"ERROR when requesting unit metadata from DRO " << dataReducerIndex << endl;
822 attribs[
"unit"] = unitString;
823 attribs[
"unitLaTeX"] = unitStringLaTeX;
824 attribs[
"unitConversion"] = unitConversionFactor;
825 attribs[
"variableLaTeX"] = variableStringLaTeX;
828 if (vectorSize == 0) {
832 const uint64_t varBufferArraySize = cells.size() * vectorSize * dataSize;
835 char* varBuffer = NULL;
837 varBuffer =
new char[varBufferArraySize];
838 }
catch (bad_alloc&) {
839 cerr <<
"ERROR, FAILED TO ALLOCATE MEMORY AT: " << __FILE__ <<
" " << __LINE__ << endl;
840 logFile <<
"(MAIN) writeGrid: ERROR FAILED TO ALLOCATE MEMORY AT: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
844 for (
size_t cell = 0; cell < cells.size(); ++cell) {
846 if (dataReducer.
reduceData(mpiGrid[cells[cell]], dataReducerIndex, varBuffer + cell * vectorSize * dataSize) ==
false) {
852 if (dataReducer.
getName(dataReducerIndex).find(
"fg_", 0) == 0) {
854 phiprof::Timer writeFsTimer{
"writeFsGrid"};
855 success = dataReducer.
writeFsGridData(fieldSolverData,
"fsgrid", dataReducerIndex, vlsvWriter, writeAsFloat);
858 }
else if (dataReducer.
getName(dataReducerIndex).find(
"ig_", 0) == 0) {
860 phiprof::Timer writeIonosphereTimer{
"writeIonosphere"};
862 writeIonosphereTimer.stop();
865 if ((writeAsFloat ==
true && dataType.compare(
"float") == 0) && dataSize ==
sizeof(
double)) {
866 double* varBuffer_double =
reinterpret_cast<double*
>(varBuffer);
868 const uint64_t arraySize_smaller = cells.size();
869 const uint32_t vectorSize_smaller = vectorSize;
870 const uint32_t dataSize_smaller =
sizeof(float);
871 const string dataType_smaller = dataType;
872 float* varBuffer_smaller = NULL;
874 varBuffer_smaller =
new float[arraySize_smaller * vectorSize_smaller];
875 }
catch (bad_alloc&) {
876 cerr <<
"ERROR, FAILED TO ALLOCATE MEMORY AT: " << __FILE__ <<
" " << __LINE__ << endl;
877 logFile <<
"(MAIN) writeGrid: ERROR FAILED TO ALLOCATE MEMORY AT: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
883 for (uint64_t
i = 0;
i < arraySize_smaller * vectorSize_smaller; ++
i) {
884 const double value = varBuffer_double[
i];
885 varBuffer_smaller[
i] = (float)(value);
888 char* varBuffer_smaller_char =
reinterpret_cast<char*
>(varBuffer_smaller);
890 phiprof::Timer writeArrayTimer{
"writeArray"};
891 if (vlsvWriter.writeArray(
"VARIABLE", attribs, dataType_smaller, arraySize_smaller, vectorSize_smaller, dataSize_smaller, varBuffer_smaller_char) ==
false) {
893 logFile <<
"(MAIN) writeGrid: ERROR failed to write datareductionoperator data to file!" << endl <<
writeVerbose;
895 writeArrayTimer.stop();
896 delete[] varBuffer_smaller;
897 varBuffer_smaller = NULL;
900 phiprof::Timer writeArrayTimer{
"writeArray"};
901 if (vlsvWriter.writeArray(
"VARIABLE", attribs, dataType, cells.size(), vectorSize, dataSize, varBuffer) ==
false) {
903 logFile <<
"(MAIN) writeGrid: ERROR failed to write datareductionoperator data to file!" << endl <<
writeVerbose;
928 const dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
929 const vector<uint64_t>& local_cells,
930 const uint& fileIndex,
935 MPI_Comm_rank(comm, &
myRank);
938 const short unsigned int vectorSize = 1;
939 const uint32_t arraySize = local_cells.size();
940 map<string, string> xmlAttributes;
941 xmlAttributes[
"name"] =
"CellID";
942 xmlAttributes[
"mesh"] =
"SpatialGrid";
943 if (vlsvWriter.writeArray(
"VARIABLE", xmlAttributes, arraySize, vectorSize, local_cells.data()) ==
false) {
948 if (vlsvWriter.writeParameter(
"time", &
P::t) ==
false) {
return false; }
949 if (vlsvWriter.writeParameter(
"dt", &
P::dt) ==
false) {
return false; }
950 if (vlsvWriter.writeParameter(
"timestep", &
P::tstep) ==
false) {
return false; }
952 if (vlsvWriter.writeParameter(
"fileIndex", &fileIndex) ==
false) {
return false; }
953 if (vlsvWriter.writeParameter(
"xmin", &
P::xmin) ==
false) {
return false; }
954 if (vlsvWriter.writeParameter(
"xmax", &
P::xmax) ==
false) {
return false; }
955 if (vlsvWriter.writeParameter(
"ymin", &
P::ymin) ==
false) {
return false; }
956 if (vlsvWriter.writeParameter(
"ymax", &
P::ymax) ==
false) {
return false; }
957 if (vlsvWriter.writeParameter(
"zmin", &
P::zmin) ==
false) {
return false; }
958 if (vlsvWriter.writeParameter(
"zmax", &
P::zmax) ==
false) {
return false; }
959 if (vlsvWriter.writeParameter(
"xcells_ini", &
P::xcells_ini) ==
false) {
return false; }
960 if (vlsvWriter.writeParameter(
"ycells_ini", &
P::ycells_ini) ==
false) {
return false; }
961 if (vlsvWriter.writeParameter(
"zcells_ini", &
P::zcells_ini) ==
false) {
return false; }
964 const int writewid =
WID;
965 if (vlsvWriter.writeParameter(
"velocity_block_width", &writewid) ==
false) {
return false; }
973 float version = 3.00;
974 if (vlsvWriter.writeParameter(
"version", &version) ==
false) {
return false; }
988 const string& meshName,
989 const vector<uint64_t>& ghost_cells) {
991 vector<uint64_t> ghostDomainIds;
992 ghostDomainIds.reserve(ghost_cells.size());
993 vector<uint64_t> ghostLocalIds;
994 ghostLocalIds.reserve(ghost_cells.size());
997 vector<uint64_t>::const_iterator it;
998 for (it = ghost_cells.begin(); it != ghost_cells.end(); ++it) {
1015 ghostDomainIds.push_back(mpiGrid.get_process(*it));
1016 ghostLocalIds.push_back(mpiGrid[(*it)]->ioLocalCellId);
1020 uint64_t numberOfGhosts = ghost_cells.size();
1023 map<string, string> xmlAttributes;
1025 xmlAttributes[
"mesh"] = meshName;
1026 const unsigned int vectorSize = 1;
1028 if (vlsvWriter.writeArray(
"MESH_GHOST_DOMAINS", xmlAttributes, numberOfGhosts, vectorSize, ghostDomainIds.data()) ==
false) {
1029 cerr <<
"Error, failed to write MEST_GHOST_DOMAINS at: " << __FILE__ <<
" " << __LINE__ << endl;
1030 logFile <<
"(MAIN) writeGrid: ERROR failed to write MEST_GHOST_DOMAINS at: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
1034 if (vlsvWriter.writeArray(
"MESH_GHOST_LOCALIDS", xmlAttributes, numberOfGhosts, vectorSize, ghostLocalIds.data()) ==
false) {
1035 cerr <<
"Error, failed to write MEST_GHOST_LOCALIDS at: " << __FILE__ <<
" " << __LINE__ << endl;
1036 logFile <<
"(MAIN) writeGrid: ERROR failed to write MEST_GHOST_LOCALIDS at: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
1050bool writeDomainSizes(Writer& vlsvWriter,
const string& meshName,
const unsigned int& numberOfLocalZones,
const unsigned int& numberOfGhostZones) {
1052 const unsigned int numberOfDomainTypes = 2;
1053 uint32_t domainSize[numberOfDomainTypes];
1054 domainSize[0] = numberOfLocalZones + numberOfGhostZones;
1055 domainSize[1] = numberOfGhostZones;
1058 map<string, string> xmlAttributes;
1060 xmlAttributes[
"mesh"] = meshName;
1061 const unsigned int arraySize = 1;
1062 const unsigned int vectorSize = 2;
1064 if (vlsvWriter.writeArray(
"MESH_DOMAIN_SIZES", xmlAttributes, arraySize, vectorSize, domainSize) ==
false) {
1065 cerr <<
"Error at: " << __FILE__ <<
" " << __LINE__ <<
", FAILED TO WRITE MESH_DOMAIN_SIZES" << endl;
1066 logFile <<
"(MAIN) writeGrid: ERROR FAILED TO WRITE MESH_DOMAIN_SIZES AT: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
1080bool writeDomainExtents(Writer& vlsvWriter,
const string& meshName,
const std::vector<CellID>& local_cells,
1081 const dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid) {
1082 vector<CellID>::const_iterator it;
1085 map<string, string> xmlAttributes;
1087 xmlAttributes[
"mesh"] = meshName;
1088 Real ret[6] = {0., 0., 0., 0., 0., 0.};
1091 for (it = local_cells.begin(); it != local_cells.end(); it++) {
1095 Real lowcorner[6] = {
1100 if (it == local_cells.begin()) {
1101 for (uint8_t
i = 0;
i != 6;
i++) {
1102 ret[
i] = lowcorner[
i];
1106 for (uint8_t
i = 0;
i != 6;
i++) {
1108 if ((lowcorner[
i] < ret[
i]) && (
i % 2 == 0)) {
1109 ret[
i] = lowcorner[
i];
1111 }
else if ((lowcorner[
i] > ret[
i]) && (
i % 2 != 0)) {
1112 ret[
i] = lowcorner[
i];
1116 const unsigned int arraySize = 1;
1117 const unsigned int vectorSize = 6;
1120 if (vlsvWriter.writeArray(
"MESH_DOMAIN_EXTENTS", xmlAttributes, arraySize, vectorSize, ret) ==
false) {
1121 cerr <<
"Error at: " << __FILE__ <<
" " << __LINE__ <<
", FAILED TO WRITE MESH_DOMAIN_EXTENTS" << endl;
1122 logFile <<
"(MAIN) writeGrid: ERROR FAILED TO WRITE MESH_DOMAIN_EXTENTS AT: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
1143 const string& meshName,
1144 const vector<uint64_t>& local_cells,
1145 const vector<uint64_t>& ghost_cells) {
1146 if (local_cells.empty()) {
1147 if (!ghost_cells.empty()) {
1149 cerr <<
"ERROR, LOCAL ZONES EMPTY BUT GHOST ZONES NOT AT " << __FILE__ << __LINE__ << endl;
1154 vector<uint64_t> globalIds;
1155 globalIds.reserve(local_cells.size() + ghost_cells.size());
1159 vector<uint64_t>::const_iterator it;
1160 for (it = local_cells.begin(); it != local_cells.end(); ++it) {
1162 cerr <<
"ERROR, Invalid cell id at " << __FILE__ <<
" " << __LINE__ << endl;
1167 globalIds.push_back((*it) - 1);
1170 for (it = ghost_cells.begin(); it != ghost_cells.end(); ++it) {
1172 cerr <<
"ERROR, Invalid cell id at " << __FILE__ <<
" " << __LINE__ << endl;
1176 globalIds.push_back((*it) - 1);
1180 const uint64_t numberOfZones = globalIds.size();
1183 map<string, string> xmlAttributes;
1185 xmlAttributes[
"name"] = meshName;
1187 xmlAttributes[
"type"] = vlsv::mesh::STRING_UCD_AMR;
1188 char refLevelString[] =
"0";
1191 xmlAttributes[
"max_refinement_level"] = refLevelString;
1194 if (mpiGrid.topology.is_periodic(0)) { xmlAttributes[
"xperiodic"] =
"yes"; }
else { xmlAttributes[
"xperiodic"] =
"no"; }
1195 if (mpiGrid.topology.is_periodic(1)) { xmlAttributes[
"yperiodic"] =
"yes"; }
else { xmlAttributes[
"yperiodic"] =
"no"; }
1196 if (mpiGrid.topology.is_periodic(2)) { xmlAttributes[
"zperiodic"] =
"yes"; }
else { xmlAttributes[
"zperiodic"] =
"no"; }
1198 if (numberOfZones == 0) {
1199 const uint64_t dummy_data = 0;
1200 const unsigned int dummy_array = 0;
1201 if (vlsvWriter.writeArray(
"MESH", xmlAttributes, dummy_array, 1, &dummy_data) ==
false) {
1202 cerr <<
"Unsuccessful writing of MESH at: " << __FILE__ <<
" " << __LINE__ << endl;
1206 if (vlsvWriter.writeArray(
"MESH", xmlAttributes, numberOfZones, 1, globalIds.data()) ==
false) {
1207 cerr <<
"Unsuccessful writing of MESH at: " << __FILE__ <<
" " << __LINE__ << endl;
1226 const string& meshName,
1227 const int masterRank,
1249 vector<Real> xNodeCoordinates;
1250 xNodeCoordinates.reserve(xCells + 1);
1251 vector<Real> yNodeCoordinates;
1252 yNodeCoordinates.reserve(yCells + 1);
1253 vector<Real> zNodeCoordinates;
1254 zNodeCoordinates.reserve(zCells + 1);
1257 for (
unsigned int i = 0;
i < xCells + 1; ++
i) {
1259 xNodeCoordinates.push_back(xmin + xCellLength *
i);
1261 for (
unsigned int i = 0;
i < yCells + 1; ++
i) {
1262 yNodeCoordinates.push_back(ymin + yCellLength *
i);
1264 for (
unsigned int i = 0;
i < zCells + 1; ++
i) {
1265 zNodeCoordinates.push_back(zmin + zCellLength *
i);
1269 map<string, string> xmlAttributes;
1271 xmlAttributes[
"mesh"] = meshName;
1273 bool success =
true;
1277 MPI_Comm_rank(comm, &
myRank);
1279 const unsigned int vectorSize = 1;
1281 if (
myRank == masterRank) {
1283 arraySize = xCells + 1;
1284 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_X", xmlAttributes, arraySize, vectorSize, xNodeCoordinates.data()) ==
false) success =
false;
1285 arraySize = yCells + 1;
1286 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Y", xmlAttributes, arraySize, vectorSize, yNodeCoordinates.data()) ==
false) success =
false;
1287 arraySize = zCells + 1;
1288 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Z", xmlAttributes, arraySize, vectorSize, zNodeCoordinates.data()) ==
false) success =
false;
1292 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_X", xmlAttributes, arraySize, vectorSize, xNodeCoordinates.data()) ==
false) success =
false;
1293 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Y", xmlAttributes, arraySize, vectorSize, yNodeCoordinates.data()) ==
false) success =
false;
1294 if (vlsvWriter.writeArray(
"MESH_NODE_CRDS_Z", xmlAttributes, arraySize, vectorSize, zNodeCoordinates.data()) ==
false) success =
false;
1297 xNodeCoordinates.clear();
1298 yNodeCoordinates.clear();
1299 zNodeCoordinates.clear();
1314 MPI_Comm_rank(comm, &
myRank);
1317 const unsigned int box_size = 6;
1318 const unsigned int notBlockBasedMesh = 1;
1325 uint64_t boundaryBox[box_size] = {numberOfXCells, numberOfYCells, numberOfZCells,
1326 notBlockBasedMesh, notBlockBasedMesh, notBlockBasedMesh};
1330 map<string, string> xmlAttributes;
1332 xmlAttributes[
"mesh"] = meshName;
1336 if (
myRank == masterRank) {
1339 const unsigned int arraySize = 6;
1340 const unsigned int vectorSize = 1;
1341 success = vlsvWriter.writeArray(
"MESH_BBOX", xmlAttributes, arraySize, vectorSize, boundaryBox);
1343 const unsigned int arraySize = 0;
1344 const unsigned int vectorSize = 1;
1345 success = vlsvWriter.writeArray(
"MESH_BBOX", xmlAttributes, arraySize, vectorSize, boundaryBox);
1358 MPI_Comm_rank(comm, &
myRank);
1360 std::map<std::string, std::string> xmlAttributes;
1361 xmlAttributes[
"name"] =
"version_information";
1365 retval = vlsvWriter.writeArray(
"VERSION", xmlAttributes, version.size(), 1, &version[0]);
1367 retval = vlsvWriter.writeArray(
"VERSION", xmlAttributes, 0, 1, &version[0]);
1381 MPI_Comm_rank(comm, &
myRank);
1383 std::map<std::string, std::string> xmlAttributes;
1384 xmlAttributes[
"name"] =
"config_file";
1388 retval = vlsvWriter.writeArray(
"CONFIG", xmlAttributes, config.size(), 1, &config[0]);
1390 retval = vlsvWriter.writeArray(
"CONFIG", xmlAttributes, 0, 1, &config[0]);
1402 std::map<std::string, std::string> xmlAttributes;
1403 const std::string meshName =
"fsgrid";
1404 xmlAttributes[
"mesh"] = meshName;
1408 const std::array<fsgrid::FsSize_t, 3>& globalSize =
fsgrid.getGlobalSize();
1409 std::array<fsgrid::FsSize_t, 6> boundaryBox({globalSize[0], globalSize[1], globalSize[2], 1, 1, 1});
1411 if (
fsgrid.getRank() == 0) {
1412 const unsigned int arraySize = 6;
1413 const unsigned int vectorSize = 1;
1414 vlsvWriter.writeArray(
"MESH_BBOX", xmlAttributes, arraySize, vectorSize, &boundaryBox[0]);
1416 const unsigned int arraySize = 0;
1417 const unsigned int vectorSize = 1;
1418 vlsvWriter.writeArray(
"MESH_BBOX", xmlAttributes, arraySize, vectorSize, &boundaryBox);
1423 std::vector<double> xNodeCoordinates(globalSize[0] + 1);
1424 for (int64_t
i = 0;
i < globalSize[0] + 1;
i++) {
1425 xNodeCoordinates[
i] =
fsgrid.getPhysicalCoords(
i, 0, 0)[0];
1427 std::vector<double> yNodeCoordinates(globalSize[1] + 1);
1428 for (int64_t
i = 0;
i < globalSize[1] + 1;
i++) {
1429 yNodeCoordinates[
i] =
fsgrid.getPhysicalCoords(0,
i, 0)[1];
1431 std::vector<double> zNodeCoordinates(globalSize[2] + 1);
1432 for (int64_t
i = 0;
i < globalSize[2] + 1;
i++) {
1433 zNodeCoordinates[
i] =
fsgrid.getPhysicalCoords(0, 0,
i)[2];
1435 if (
fsgrid.getRank() == 0) {
1437 vlsvWriter.writeArray(
"MESH_NODE_CRDS_X", xmlAttributes, globalSize[0] + 1, 1, xNodeCoordinates.data());
1438 vlsvWriter.writeArray(
"MESH_NODE_CRDS_Y", xmlAttributes, globalSize[1] + 1, 1, yNodeCoordinates.data());
1439 vlsvWriter.writeArray(
"MESH_NODE_CRDS_Z", xmlAttributes, globalSize[2] + 1, 1, zNodeCoordinates.data());
1444 vlsvWriter.writeArray(
"MESH_NODE_CRDS_X", xmlAttributes, 0, 1, xNodeCoordinates.data());
1445 vlsvWriter.writeArray(
"MESH_NODE_CRDS_Y", xmlAttributes, 0, 1, yNodeCoordinates.data());
1446 vlsvWriter.writeArray(
"MESH_NODE_CRDS_Z", xmlAttributes, 0, 1, zNodeCoordinates.data());
1451 vlsvWriter.writeArray(
"MESH_GHOST_DOMAINS", xmlAttributes, 0, 1, &dummyghost);
1452 vlsvWriter.writeArray(
"MESH_GHOST_LOCALIDS", xmlAttributes, 0, 1, &dummyghost);
1455 const std::array<fsgrid::FsIndex_t, 3>& localSize =
fsgrid.getLocalSize();
1456 std::array<uint64_t, 2> meshDomainSize({(uint64_t)localSize[0] * (uint64_t)localSize[1] * (uint64_t)localSize[2], 0});
1457 vlsvWriter.writeArray(
"MESH_DOMAIN_SIZES", xmlAttributes, 1, 2, &meshDomainSize[0]);
1460 int size =
fsgrid.getNumFsRanks();
1461 vlsvWriter.writeParameter(
"numWritingRanks", &size);
1464 std::array<fsgrid::Task_t, 3> decom =
fsgrid.getDecomposition();
1465 if (
fsgrid.getRank() == 0) {
1466 vlsvWriter.writeArray(
"MESH_DECOMPOSITION", xmlAttributes, 3u, 1u, &decom[0]);
1468 vlsvWriter.writeArray(
"MESH_DECOMPOSITION", xmlAttributes, 0u, 3u, &decom[0]);
1472 xmlAttributes.clear();
1473 xmlAttributes[
"name"] = meshName;
1474 xmlAttributes[
"type"] = vlsv::mesh::STRING_UCD_MULTI;
1475 xmlAttributes[
"xperiodic"] =
fsgrid.getPeriodic()[0] ?
"yes" :
"no";
1476 xmlAttributes[
"yperiodic"] =
fsgrid.getPeriodic()[1] ?
"yes" :
"no";
1477 xmlAttributes[
"zperiodic"] =
fsgrid.getPeriodic()[2] ?
"yes" :
"no";
1481 std::vector<fsgrid::FsSize_t> globalIds(
static_cast<fsgrid::FsSize_t
>(localSize[0] * localSize[1] * localSize[2]));
1483 fsgrid.parallel_for([](
int timerId) -> phiprof::Timer {
return phiprof::Timer{timerId}; }, phiprof::initializeTimer(
"Map Refinement Level to FsGrid"), technical,
1484 [=, &globalIds](
const fsgrid::Coordinates& coordinates,
const fsgrid::FsStencil& stencil,
cuint sysBoundaryFlag,
cuint sysBoundaryLayer) {
1485 cint index = stencil.k * coordinates.localSize[1] * coordinates.localSize[0] + stencil.j * coordinates.localSize[0] + stencil.i;
1486 const std::array<fsgrid::FsSize_t, 3> globalIndex = coordinates.localToGlobal(stencil.i, stencil.j, stencil.k);
1487 globalIds[
index] = globalIndex[2] * globalSize[0] * globalSize[1] + globalIndex[1] * globalSize[0] + globalIndex[0];
1489 vlsvWriter.writeArray(
"MESH", xmlAttributes, globalIds.size(), 1, globalIds.data());
1503 std::map<std::string, std::string> xmlAttributes;
1504 const std::string meshName =
"ionosphere";
1505 xmlAttributes[
"mesh"] = meshName;
1514 std::array<int64_t, 6> boundaryBox({1, 1, 1, 1, 1, 1});
1517 const unsigned int arraySize = 6;
1518 const unsigned int vectorSize = 1;
1519 vlsvWriter.writeArray(
"MESH_BBOX", xmlAttributes, arraySize, vectorSize, &boundaryBox[0]);
1521 const unsigned int arraySize = 0;
1522 const unsigned int vectorSize = 1;
1523 vlsvWriter.writeArray(
"MESH_BBOX", xmlAttributes, arraySize, vectorSize, &boundaryBox[0]);
1529 vlsvWriter.writeArray(
"MESH_DOMAIN_SIZES", xmlAttributes, 1, 4, &meshDomainSize[0]);
1531 vlsvWriter.writeArray(
"MESH_DOMAIN_SIZES", xmlAttributes, 0, 4, &meshDomainSize[0]);
1537 vlsvWriter.writeArray(
"MESH_OFFSETS", xmlAttributes, 1, 2, &meshOffsets[0]);
1539 vlsvWriter.writeArray(
"MESH_OFFSETS", xmlAttributes, 0, 2, &meshOffsets[0]);
1551 vlsvWriter.writeArray(
"MESH_NODE_CRDS", xmlAttributes,
SBC::ionosphereGrid.nodes.size(), 3, nodeCoordinates.data());
1554 vlsvWriter.writeArray(
"MESH_NODE_CRDS", xmlAttributes, 0, 3, nodeCoordinates.data());
1563 std::vector<uint32_t> ionosphereGridElementsAndCorners;
1565 ionosphereGridElementsAndCorners.push_back(vlsv::celltype::TRIANGLE);
1566 ionosphereGridElementsAndCorners.push_back(3);
1573 xmlAttributes.clear();
1574 xmlAttributes[
"name"] = meshName;
1575 xmlAttributes[
"type"] = vlsv::mesh::STRING_UCD_GENERIC_MULTI;
1576 xmlAttributes[
"domains"] =
"1";
1582 vlsvWriter.writeArray(
"MESH", xmlAttributes, ionosphereGridElementsAndCorners.size(), 1, ionosphereGridElementsAndCorners.data());
1584 vlsvWriter.writeArray(
"MESH", xmlAttributes, 0, 1, ionosphereGridElementsAndCorners.data());
1604 Writer& vlsvWriter,
int index,
const vector<uint64_t>& cells) {
1606 vector<uint64_t> velSpaceCells;
1607 int lineX, lineY, lineZ;
1608 Real shellRadiusSquare;
1609 Real cellX, cellY, cellZ, DX, DY, DZ;
1610 Real dx_rm, dx_rp, dy_rm, dy_rp, dz_rm, dz_rp;
1611 Real rsquare_minus, rsquare_plus;
1612 bool withinshell, stridecheck;
1614 for (uint
i = 0;
i < cells.size();
i++) {
1618 velSpaceCells.push_back(cells[
i]);
1626 uint startindex = 1;
1629 int AMRm = 1u << AMR;
1631 startindex = endindex;
1632 endindex = endindex + cellsthislevel;
1635 if ((cells[
i] >= startindex) && (cells[
i] < endindex)) {
1655 velSpaceCells.push_back(cells[
i]);
1674 dx_rm = cellX < 0 ? DX : 0;
1675 dx_rp = cellX < 0 ? 0 : DX;
1676 dy_rm = cellY < 0 ? DY : 0;
1677 dy_rp = cellY < 0 ? 0 : DY;
1678 dz_rm = cellZ < 0 ? DZ : 0;
1679 dz_rp = cellZ < 0 ? 0 : DZ;
1680 rsquare_minus = (cellX + dx_rm) * (cellX + dx_rm) + (cellY + dy_rm) * (cellY + dy_rm) + (cellZ + dz_rm) * (cellZ + dz_rm);
1681 rsquare_plus = (cellX + dx_rp) * (cellX + dx_rp) + (cellY + dy_rp) * (cellY + dy_rp) + (cellZ + dz_rp) * (cellZ + dz_rp);
1687 std::array<Real, 3> s = {
abs(cellX + 0.5 * DX),
abs(cellY + 0.5 * DY),
abs(cellZ + 0.5 * DZ)};
1688 std::sort(s.begin(), s.end());
1704 T =
sqrt(s[0] * s[0] + s[1] * s[1]);
1705 clock = T * atan(s[0] / s[1]);
1708 Real dist = shellR * atan(T / D);
1710 Real dist2 = DX * shellS * round(dist / DX / shellS);
1711 Real clock2 = DX * shellS * round(clock / DX / shellS);
1714 Real D2 = shellR * cos(dist2 / shellR);
1715 Real T2 = shellR * sin(dist2 / shellR);
1717 stridecheck =
false;
1721 if ((D2 >= D - 0.5 * DX) && (D2 < D + 0.5 * DX) && (T2 >= T - 0.5 * DX) && (T2 < T + 0.5 * DX))
1724 if ((
abs(D - T) < 0.5 * DX) && (dist2 > dist))
1728 if ((
P::ycells_ini == 1) && (((cellX > -1.1 * DX) && (cellX < 0)) || ((cellZ > -1.1 * DZ) && (cellZ < 0))))
1729 stridecheck =
false;
1730 if ((
P::zcells_ini == 1) && (((cellX > -1.1 * DX) && (cellX < 0)) || ((cellY > -1.1 * DY) && (cellY < 0))))
1731 stridecheck =
false;
1735 Real T2A = T2 * cos(clock2 / T2);
1736 Real T2B = T2 * sin(clock2 / T2);
1738 bool ring = (D2 >= D - 0.5 * DX) && (D2 < D + 0.5 * DX) && (T2 >= T - 0.5 * DX) && (T2 < T + 0.5 * DX);
1740 ring = ring || ((
abs(D - T) < 0.5 * DX) && (dist2 > dist));
1742 bool clockcheck = (T2A >= s[1] - 0.5 * DX) && (T2A < s[1] + 0.5 * DX) && (T2B >= s[0] - 0.5 * DX) && (T2B < s[0] + 0.5 * DX);
1744 clockcheck = clockcheck || ((
abs(s[1] - s[0]) < 0.5 * DX) && (clock2 > clock));
1745 if (ring && clockcheck)
1749 if ((s[1] < DX) && (s[0] < DX) && (D2 >= D - 0.5 * DX) && (D2 < D + 0.5 * DX))
1753 if ((
abs(s[2] - s[1]) < DX) && (
abs(s[1] - s[0]) < DX) && (
abs(s[2] - s[0]) < DX))
1757 if (((cellX > -1.1 * DX) && (cellX < 0)) || ((cellY > -1.1 * DY) && (cellY < 0)) || ((cellZ > -1.1 * DZ) && (cellZ < 0)))
1758 stridecheck =
false;
1762 velSpaceCells.push_back(cells[
i]);
1770 uint64_t numVelSpaceCells;
1771 uint64_t localNumVelSpaceCells;
1772 localNumVelSpaceCells = velSpaceCells.size();
1773 MPI_Allreduce(&localNumVelSpaceCells, &numVelSpaceCells, 1, MPI_UINT64_T, MPI_SUM, MPI_COMM_WORLD);
1777 std::vector<std::vector<char>> mlp_clustered_bytes;
1778 phiprof::Timer compression_interface{
"asterix-compression"};
1781 compression_interface.stop();
1789 cerr <<
"ERROR, FAILED TO WRITE VELOCITY DISTRIBUTION DATA AT " << __FILE__ <<
" " << __LINE__ << endl;
1790 logFile <<
"(MAIN) writeGrid: ERROR FAILED TO WRITE VELOCITY DISTRIBUTION DATA AT: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
1803 vector<uint64_t>::const_iterator
i = local_cells.begin();
1804 vector<uint64_t>::const_iterator
j = ghost_cells.begin();
1805 while (
i != local_cells.end() &&
j != ghost_cells.end()) {
1808 }
else if ((*
i) > (*
j)) {
1812 cerr <<
"ERROR SAME CELL ID " << *
i <<
" -" << endl;
1813 logFile <<
"(MAIN) writeGrid: ERROR SAME CELL ID AT: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
1830 dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
1833 const std::string& versionInfo,
1834 const std::string& configInfo,
1836 const uint& outputFileTypeIndex,
1838 const bool writeGhosts,
1841 bool success =
true;
1843 phiprof::Timer barrierWritegridTimer{
"Barrier-entering-writegrid", {
"MPI",
"Barrier"}};
1844 MPI_Barrier(MPI_COMM_WORLD);
1845 barrierWritegridTimer.stop();
1847 MPI_Comm_rank(MPI_COMM_WORLD, &
myRank);
1848 phiprof::Timer writeReducedTimer{
"writeGrid-reduced"};
1852 if (compress_vdfs) {
1853 fname <<
"_compressed";
1862 const int masterProcessId = 0;
1866 MPIinfo = MPI_INFO_NULL;
1868 MPI_Info_create(&MPIinfo);
1870 for (std::vector<std::pair<std::string, std::string>>::const_iterator it =
P::systemWriteHints.begin();
1874 MPI_Info_set(MPIinfo, it->first.c_str(), it->second.c_str());
1878 cerr <<
"Error: trying to set an invalid lustre stripe count in bulk IO. Ignoring value." << endl;
1880 if (MPIinfo == MPI_INFO_NULL) {
1881 MPI_Info_create(&MPIinfo);
1884 sprintf(stripeChar,
"%d", stripe);
1886 char factor[] =
"striping_factor";
1887 MPI_Info_set(MPIinfo, factor, stripeChar);
1890 phiprof::Timer openTimer{
"open"};
1891 vlsvWriter.open(fname.str(), MPI_COMM_WORLD, masterProcessId, MPIinfo);
1894 if (MPIinfo != MPI_INFO_NULL) {
1895 MPI_Info_free(&MPIinfo);
1900 phiprof::Timer metadataTimer{
"metadataIO"};
1906 vector<CellID> ghost_cells;
1914 if (local_cells.empty()) {
1915 if (!ghost_cells.empty()) {
1917 cerr <<
"ERROR! LOCAL CELLS EMPTY BUT GHOST CELLS NOT AT: " << __FILE__ <<
" " << __LINE__ << endl;
1922 const string meshName =
"SpatialGrid";
1945 if (
writeDomainSizes(vlsvWriter, meshName, local_cells.size(), ghost_cells.size()) ==
false) {
1953 if (
updateLocalIds(mpiGrid, local_cells, MPI_COMM_WORLD) ==
false) {
1978 if (
writeConfigInfo(configInfo, vlsvWriter, MPI_COMM_WORLD) ==
false) {
1982 metadataTimer.stop();
1984 phiprof::Timer vspaceTimer{
"velocityspaceIO"};
1985 if (
writeVelocitySpace(mpiGrid, vlsvWriter, outputFileTypeIndex, local_cells) ==
false) {
1990 phiprof::Timer reducedTimer{
"reduceddataIO"};
1993 phiprof::Timer writeDataTimer{
"writeDataReducer"};
1994 if (dataReducer != NULL)
1995 for (uint
i = 0;
i < dataReducer->
size(); ++
i) {
2000 writeDataTimer.stop();
2002 phiprof::Timer barrierTimer{
"Barrier", {
"MPI",
"Barrier"}};
2003 MPI_Barrier(MPI_COMM_WORLD);
2004 barrierTimer.stop();
2006 const uint64_t bytesWritten = vlsvWriter.getBytesWritten();
2007 const double writeTime = vlsvWriter.getWriteTime();
2008 logFile <<
"(writeGrid) Wrote ";
2010 if (bytesWritten > 1.0e9)
logFile << bytesWritten / 1.0e9 <<
" GB in ";
2011 else if (bytesWritten > 1e6)
logFile << bytesWritten / 1.0e6 <<
" MB in ";
2012 else if (bytesWritten > 1e3)
logFile << bytesWritten / 1.0e3 <<
" kB in ";
2013 else logFile << bytesWritten <<
" B in ";
2015 logFile << writeTime <<
" seconds, approximate data rate is ";
2017 if (bytesWritten / writeTime > 1e9)
logFile << bytesWritten / writeTime / 1e9 <<
" GB/s";
2018 else if (bytesWritten / writeTime > 1e6)
logFile << bytesWritten / writeTime / 1e6 <<
" MB/s";
2019 else if (bytesWritten / writeTime > 1e3)
logFile << bytesWritten / writeTime / 1e3 <<
" kB/s";
2020 else logFile << bytesWritten / writeTime <<
" B/s";
2023 reducedTimer.stop();
2025 phiprof::Timer closeTimer{
"close"};
2028 writeReducedTimer.stop(bytesWritten * 1e-9,
"GB");
2049 dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
2052 const std::string& versionInfo,
2053 const std::string& configInfo,
2056 const uint& fileIndex,
2057 const bool dateInFileName,
2062 bool success =
true;
2065 MPI_Comm_rank(MPI_COMM_WORLD, &
myRank);
2066 phiprof::Timer barrierEnteringTimer{
"BarrierEnteringWriteRestart", {
"MPI",
"Barrier"}};
2067 MPI_Barrier(MPI_COMM_WORLD);
2068 barrierEnteringTimer.stop();
2070 phiprof::Timer writeTimer{
"writeRestart"};
2071 phiprof::Timer deallocateTimer{
"DeallocateRemoteBlocks"};
2074 deallocateTimer.stop();
2078 char currentDate[80];
2079 if (dateInFileName) {
2081 const time_t rawTime = time(NULL);
2082 const struct tm* timeInfo = localtime(&rawTime);
2083 strftime(currentDate, 80,
".%F_%H-%M-%S", timeInfo);
2085 MPI_Bcast(¤tDate, 80, MPI_CHAR,
MASTER_RANK, MPI_COMM_WORLD);
2087 currentDate[0] =
'\0';
2092 if (dateInFileName) {
2097 fname <<
"/" << name <<
".";
2098 if (dateInFileName) {
2102 fname << fileIndex << currentDate <<
".vlsv";
2104 phiprof::Timer openTimer{
"open"};
2107 const int masterProcessId = 0;
2110 MPIinfo = MPI_INFO_NULL;
2112 MPI_Info_create(&MPIinfo);
2114 for (std::vector<std::pair<std::string, std::string>>::const_iterator it =
P::restartWriteHints.begin();
2118 MPI_Info_set(MPIinfo, it->first.c_str(), it->second.c_str());
2122 cerr <<
"Error: trying to set an invalid lustre stripe count in restart IO. Ignoring value." << endl;
2124 if (MPIinfo == MPI_INFO_NULL) {
2125 MPI_Info_create(&MPIinfo);
2128 sprintf(stripeChar,
"%d", stripe);
2130 char factor[] =
"striping_factor";
2131 MPI_Info_set(MPIinfo, factor, stripeChar);
2134 if (vlsvWriter.open(fname.str(), MPI_COMM_WORLD, masterProcessId, MPIinfo) ==
false)
return false;
2136 if (MPIinfo != MPI_INFO_NULL) {
2137 MPI_Info_free(&MPIinfo);
2144 phiprof::Timer metadataTimer{
"metadataIO"};
2149 std::sort(local_cells.begin(), local_cells.end());
2152 const vector<CellID> ghost_cells;
2155 const string meshName =
"SpatialGrid";
2167 if (
writeCommonGridData(vlsvWriter, mpiGrid, local_cells, fileIndex, MPI_COMM_WORLD) ==
false) {
2175 if (
writeDomainSizes(vlsvWriter, meshName, local_cells.size(), ghost_cells.size()) ==
false) {
2191 if (
writeConfigInfo(configInfo, vlsvWriter, MPI_COMM_WORLD) ==
false) {
2203 if (compress_vdfs) {
2204 std::vector<std::vector<char>> mlp_clustered_bytes;
2205 phiprof::Timer compression_interface{
"asterix-compression"};
2208 compression_interface.stop();
2209 phiprof::Timer vspaceTimer{
"velocityspaceIO"};
2213 phiprof::Timer vspaceTimer{
"velocityspaceIO"};
2218 cerr <<
"ERROR, FAILED TO WRITE VELOCITY DISTRIBUTION DATA AT " << __FILE__ <<
" " << __LINE__ << endl;
2219 logFile <<
"(MAIN) writeGrid: ERROR FAILED TO WRITE VELOCITY DISTRIBUTION DATA AT: " << __FILE__ <<
" " << __LINE__ << endl <<
writeVerbose;
2223 metadataTimer.stop();
2224 phiprof::Timer reducedTimer{
"reduceddataIO"};
2243 restartReducer.
addMetadata(restartReducer.
size() - 1,
"T",
"$\\mathrm{T}$",
"$B_\\mathrm{vol,vg}$",
"1.0");
2253 const auto* localSize = &fieldSolverData.
fsgrid.getLocalSize()[0];
2254 std::vector<Real> retval(localSize[0] * localSize[1] * localSize[2] * 3);
2256 fieldSolverData.
fsgrid.serial_for([](
int timerId) -> phiprof::Timer {
return phiprof::Timer{timerId}; }, phiprof::initializeTimer(
"DRO_fg_E"), fieldSolverData.
technical,
2257 [=, &retval](
const fsgrid::Coordinates coordinates,
const fsgrid::FsStencil& stencil,
cuint sysBoundaryFlag,
cuint sysBoundaryLayer) {
2258 const auto lid = stencil.ooo();
2259 const auto ri = localSize[1] * localSize[0] * stencil.k + localSize[0] * stencil.j + stencil.i;
2261 retval[3 * ri + 1] = fieldSolverData.
E[lid][
fsgrids::EY];
2262 retval[3 * ri + 2] = fieldSolverData.
E[lid][
fsgrids::EZ];
2268 const auto* localSize = &fieldSolverData.
fsgrid.getLocalSize()[0];
2269 std::vector<Real> retval(localSize[0] * localSize[1] * localSize[2] * 3);
2271 fieldSolverData.
fsgrid.serial_for([](
int timerId) -> phiprof::Timer {
return phiprof::Timer{timerId}; }, phiprof::initializeTimer(
"DRO_fg_PERB"), fieldSolverData.
technical,
2272 [=, &retval](
const fsgrid::Coordinates coordinates,
const fsgrid::FsStencil& stencil,
cuint sysBoundaryFlag,
cuint sysBoundaryLayer) {
2273 const auto lid = stencil.ooo();
2274 const auto ri = localSize[1] * localSize[0] * stencil.k + localSize[0] * stencil.j + stencil.i;
2287 std::vector<Real> retval(grid.nodes.size());
2289 for (uint
i = 0;
i < grid.nodes.size();
i++) {
2291 for (uint e = 0; e < grid.nodes[
i].numTouchingElements; e++) {
2292 area += grid.elementArea(grid.nodes[
i].touchingElements[e]);
2301 std::vector<Real> retval(grid.nodes.size());
2303 for (uint
i = 0;
i < grid.nodes.size();
i++) {
2310 std::vector<Real> retval(grid.nodes.size());
2312 for (uint
i = 0;
i < grid.nodes.size();
i++) {
2319 std::vector<Real> retval(grid.nodes.size());
2321 for (uint
i = 0;
i < grid.nodes.size();
i++) {
2332 std::vector<Real> retval(grid.nodes.size());
2334 for (uint
i = 0;
i < grid.nodes.size();
i++) {
2341 std::vector<Real> retval(grid.nodes.size());
2343 for (uint
i = 0;
i < grid.nodes.size();
i++) {
2350 std::vector<Real> retval(grid.nodes.size());
2352 for (uint
i = 0;
i < grid.nodes.size();
i++) {
2359 std::vector<Real> retval(grid.nodes.size());
2361 for (uint
i = 0;
i < grid.nodes.size();
i++) {
2371 for (uint
i = 0;
i < restartReducer.
size(); ++
i) {
2372 writeDataReducer(mpiGrid, local_cells, fieldSolverData, writeAsFloat,
true, restartReducer,
i, vlsvWriter);
2374 reducedTimer.stop();
2376 phiprof::Timer closeTimer{
"close"};
2387 phiprof::Timer updateRemoteTimer{
"updateRemoteBlocks"};
2392 updateRemoteTimer.stop();
2394 const uint64_t bytesWritten = vlsvWriter.getBytesWritten();
2395 const double writeTime = vlsvWriter.getWriteTime();
2396 logFile <<
"(writeGrid) Wrote ";
2398 if (bytesWritten > 1.0e9)
logFile << bytesWritten / 1.0e9 <<
" GB in ";
2399 else if (bytesWritten > 1e6)
logFile << bytesWritten / 1.0e6 <<
" MB in ";
2400 else if (bytesWritten > 1e3)
logFile << bytesWritten / 1.0e3 <<
" kB in ";
2401 else logFile << bytesWritten <<
" B in ";
2403 logFile << writeTime <<
" seconds, approximate data rate is ";
2405 if (bytesWritten / writeTime > 1e9)
logFile << bytesWritten / writeTime / 1e9 <<
" GB/s";
2406 else if (bytesWritten / writeTime > 1e6)
logFile << bytesWritten / writeTime / 1e6 <<
" MB/s";
2407 else if (bytesWritten / writeTime > 1e3)
logFile << bytesWritten / writeTime / 1e3 <<
" kB/s";
2408 else logFile << bytesWritten / writeTime <<
" B/s";
2411 writeTimer.stop(bytesWritten * 1e-9,
"GB");
2424 MPI_Comm_rank(MPI_COMM_WORLD, &
myRank);
2427 uint dataSize, vectorSize;
2429 cuint nCells = cells.size();
2433 if (nOps == 0)
return true;
2435 vector<Real> localMin(nOps), localMax(nOps), localSum(nOps+1), localAvg(nOps),
2436 globalMin(nOps), globalMax(nOps), globalSum(nOps+1), globalAvg(nOps);
2437 localSum[0] = 1.0 * nCells;
2439 bool success =
true;
2440 static bool printDiagnosticHeader =
true;
2447 diagnostic <<
"# Column 2 Simulation time" << endl;
2448 diagnostic <<
"# Column 3 Time step dt" << endl;
2449 for (uint
i = 0;
i < nOps; ++
i) {
2450 diagnostic <<
"# Columns " << 4 +
i * 4 <<
" to " << 7 +
i * 4 <<
": " << dataReducer.
getName(
i) <<
" min max sum average" << endl;
2452 printDiagnosticHeader =
false;
2455 for (uint
i = 0;
i < nOps; ++
i) {
2458 cerr <<
"ERROR when requesting info from diagnostic DRO " << dataReducer.
getName(
i) << endl;
2460 localMin[
i] = std::numeric_limits<Real>::max();
2461 localMax[
i] = std::numeric_limits<Real>::min();
2462 localSum[
i + 1] = 0.0;
2466 for (uint64_t cell = 0; cell < nCells; ++cell) {
2468 if (dataReducer.
reduceDiagnostic(mpiGrid[cells[cell]],
i, &buffer) ==
false) success =
false;
2469 localMin[
i] =
min(buffer, localMin[
i]);
2470 localMax[
i] =
max(buffer, localMax[
i]);
2471 localSum[
i + 1] += buffer;
2473 localAvg[
i] = localSum[
i + 1];
2475 if (success ==
false) {
2476 logFile <<
"(MAIN) writeDiagnostic: ERROR datareductionoperator '" << dataReducer.
getName(
i) <<
"' returned false!" << endl <<
writeVerbose;
2480 MPI_Reduce(&localMin[0], &globalMin[0], nOps,
MPI_Type<Real>(), MPI_MIN, 0, MPI_COMM_WORLD);
2481 MPI_Reduce(&localMax[0], &globalMax[0], nOps,
MPI_Type<Real>(), MPI_MAX, 0, MPI_COMM_WORLD);
2482 MPI_Reduce(&localSum[0], &globalSum[0], nOps + 1,
MPI_Type<Real>(), MPI_SUM, 0, MPI_COMM_WORLD);
2489 for (uint
i = 0;
i < nOps; ++
i) {
2490 if (globalSum[0] != 0.0) {
2491 globalAvg[
i] = globalSum[
i + 1] / globalSum[0];
2493 globalAvg[
i] = globalSum[
i + 1];
2496 diagnostic << globalMin[
i] <<
"\t" << globalMax[
i] <<
"\t" << globalSum[
i + 1] <<
"\t" << globalAvg[
i] <<
"\t";
sqrt(1.0+vA *vA/(c *c))) % Ion-acoustic wave cS
#define gpuMemcpyDeviceToHost
bool reduceDiagnostic(const SpatialCell *cell, const unsigned int &operatorID, Real *result)
bool getMetadata(const unsigned int &operatorID, std::string &unit, std::string &unitLaTeX, std::string &variableLaTeX, std::string &unitConversion) const
unsigned int size() const
bool writeFsGridData(const FieldSolverData &fieldSolverData, const std::string &meshName, const unsigned int operatorID, vlsv::Writer &vlsvWriter, const bool writeAsFloat=false)
bool addOperator(DRO::DataReductionOperator *op)
bool hasParameters(const unsigned int &operatorID) const
bool addMetadata(const unsigned int operatorID, std::string unit, std::string unitLaTeX, std::string variableLaTeX, std::string unitConversion)
bool writeParameters(const unsigned int &operatorID, vlsv::Writer &vlsvWriter)
std::string getName(const unsigned int &operatorID) const
bool reduceData(const SpatialCell *cell, const unsigned int &operatorID, char *buffer)
bool writeIonosphereGridData(SBC::SphericalTriGrid &grid, const std::string &meshName, const unsigned int operatorID, vlsv::Writer &vlsvWriter)
bool getDataVectorInfo(const unsigned int &operatorID, std::string &dataType, unsigned int &dataSize, unsigned int &vectorSize) const
static Real downmapRadius
static Real couplingInterval
static Real couplingTimescale
const vmesh::GlobalID * get_velocity_grid(const uint popID)
vmesh::LocalID get_number_of_velocity_blocks(const uint popID) const
vmesh::GlobalID get_velocity_block_global_id(const vmesh::LocalID &blockLID, const uint popID) const
static void set_mpi_transfer_type(const uint64_t type, bool atSysBoundaries=false)
Realf * get_data(const uint popID)
Population & get_population(const uint popID)
std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > parameters
const std::vector< CellID > & getLocalCells()
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
void deallocateRemoteCellBlocks(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid)
void updateRemoteVelocityBlockLists(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const uint popID, const uint neighborhood)
ObjectWrapper & getObjectWrapper()
bool checkForSameMembers(const vector< uint64_t > &local_cells, const vector< uint64_t > &ghost_cells)
bool updateLocalIds(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &local_cells, MPI_Comm comm)
bool writeVspaceDataCompressionNone(const uint popID, Writer &vlsvWriter, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, std::size_t totalBlocks, MPI_Comm comm)
bool writeVersionInfo(const std::string &version, vlsv::Writer &vlsvWriter, MPI_Comm comm)
bool writeGrid(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const FieldSolverData &fieldSolverData, fsgrids::consttechnicalspan technical, const std::string &versionInfo, const std::string &configInfo, DataReducer *dataReducer, const uint &outputFileTypeIndex, const int &stripe, const bool writeGhosts, bool compress_vdfs)
Write out system into a vlsv file.
bool writeZoneGlobalIdNumbers(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, Writer &vlsvWriter, const string &meshName, const vector< uint64_t > &local_cells, const vector< uint64_t > &ghost_cells)
bool writeDomainSizes(Writer &vlsvWriter, const string &meshName, const unsigned int &numberOfLocalZones, const unsigned int &numberOfGhostZones)
bool writeVelocityDistributionDataAsterix(const uint popID, Writer &vlsvWriter, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, std::vector< std::vector< char > > &mpl_bytes, MPI_Comm comm)
bool writeRestart(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const FieldSolverData &fieldSolverData, fsgrids::consttechnicalspan technical, const std::string &versionInfo, const std::string &configInfo, DataReducer &dataReducer, const string &name, const uint &fileIndex, const bool dateInFileName, const int &stripe, bool compress_vdfs)
Write out a restart of the simulation into a vlsv file. All block data in remote cells will be reset.
bool writeDataReducer(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, const FieldSolverData &fieldSolverData, const bool writeAsFloat, const bool writeFsGrid, DataReducer &dataReducer, cint dataReducerIndex, Writer &vlsvWriter)
bool writeDiagnostic(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, DataReducer &dataReducer)
Write out simulation diagnostics into diagnostic.txt.
bool writeIonosphereGridMetadata(vlsv::Writer &vlsvWriter)
bool writeConfigInfo(const std::string &config, vlsv::Writer &vlsvWriter, MPI_Comm comm)
bool globalSuccess(bool success, const string &errorMessage, MPI_Comm comm)
bool writeMeshBoundingBox(Writer &vlsvWriter, const string &meshName, const int masterRank, MPI_Comm comm)
bool writeBoundingBoxNodeCoordinates(Writer &vlsvWriter, const string &meshName, const int masterRank, MPI_Comm comm)
bool writeCommonGridData(Writer &vlsvWriter, const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< uint64_t > &local_cells, const uint &fileIndex, MPI_Comm comm)
bool writeGhostZoneDomainAndLocalIdNumbers(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, Writer &vlsvWriter, const string &meshName, const vector< uint64_t > &ghost_cells)
bool writeFsGridMetadata(FieldSolverGrid &fsgrid, fsgrids::consttechnicalspan technical, vlsv::Writer &vlsvWriter, bool writeIDs=false)
bool writeDomainExtents(Writer &vlsvWriter, const string &meshName, const std::vector< CellID > &local_cells, const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid)
bool writeVelocityDistributionData(const uint popID, Writer &vlsvWriter, const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, MPI_Comm comm)
bool writeVelocitySpace(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, Writer &vlsvWriter, int index, const vector< uint64_t > &cells)
Logger & writeVerbose(Logger &logger)
Logger & write(Logger &logger)
void compress_vdfs(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &local_cells, P::ASTERIX_COMPRESSION_METHODS method, bool update_weights, std::vector< std::vector< char > > &mpl_bytes, uint32_t downsampling_factor=1)
FieldTracingParameters fieldTracingParameters
SphericalTriGrid ionosphereGrid
std::span< const technical > consttechnicalspan
static const uint64_t CELL_IOLOCALCELLID
ARCH_HOSTDEV MeshWrapper * getMeshWrapper()
fsgrids::consttechnicalspan technical
fsgrids::constefieldspan E
fsgrids::constperbspan perB
std::vector< species::Species > particleSpecies
static std::vector< int > systemWriteDistributionWriteZlineStride
static int writeRestartAsFloat
static std::string restartWritePath
static int amrMaxSpatialRefLevel
static std::vector< int > systemWriteDistributionWriteShellStride
static std::vector< bool > systemWriteFsGrid
static std::vector< int > systemWriteDistributionWriteYlineStride
static std::vector< int > systemWrites
static std::vector< Real > systemWriteDistributionWriteShellRadius
static std::vector< std::size_t > mlp_arch
static std::vector< std::string > systemWritePath
static std::vector< std::pair< std::string, std::string > > restartWriteHints
static std::vector< int > systemWriteDistributionWriteXlineStride
static std::string recoverWritePath
static uint64_t vlsvBufferSize
static std::string restartFileName
static uint fieldSolverSubcycles
static ASTERIX_COMPRESSION_METHODS vdf_compression_method
static std::vector< std::pair< std::string, std::string > > systemWriteHints
static std::vector< int > systemWriteDistributionWriteStride
static std::size_t mlp_fourier_order
static bool systemWriteDistributionCompressed
static std::vector< std::string > systemWriteName
std::vector< char > compressed_state_buffer
std::array< vmesh::MeshParameters, MAX_VMESH_PARAMETERS_COUNT > * velocityMeshes
static ARCH_HOSTDEV VecSimple< T > min(VecSimple< T > const &l, VecSimple< T > const &r)
static ARCH_HOSTDEV VecSimple< T > max(VecSimple< T > const &l, VecSimple< T > const &r)
static ARCH_HOSTDEV VecSimple< T > abs(const VecSimple< T > &l)