50 bool getCellIds( std::vector<uint64_t> & cellIds,
const std::string& meshName=
"SpatialGrid");
52 template <
typename T,
size_t N>
53 bool getVariable(
const std::string & variableName,
const uint64_t & cellId, std::array<T, N> & variable );
54 bool getBlockIds(
const uint64_t& cellId,std::vector<uint64_t>& blockIds,
const std::string& popName );
65 bool getVelocityBlockVariables(
const std::string & variableName,
const uint64_t & cellId,
char*& buffer,
bool allocateMemory =
true );
69 std::unordered_map<uint64_t, std::pair<uint64_t,uint32_t> >::const_iterator it =
cellsWithBlocksLocations.find( cellId );
71 std::cerr <<
"COULDNT FIND CELL ID " << cellId <<
" AT " << __FILE__ <<
" " << __LINE__ << std::endl;
75 return std::get<0>(it->second);
79 std::unordered_map<uint64_t, std::pair<uint64_t,uint32_t> >::const_iterator it =
cellsWithBlocksLocations.find( cellId );
81 std::cerr <<
"COULDNT FIND CELL ID " << cellId <<
" AT " << __FILE__ <<
" " << __LINE__ << std::endl;
85 return std::get<1>(it->second);
90 bool Reader::getVariable(
const std::string & variableName,
const uint64_t & cellId, std::array<T, N> & variable ) {
92 std::cerr <<
"ERROR, CELL IDS NOT SET AT " << __FILE__ <<
" " << __LINE__ << std::endl;
96 std::unordered_map<uint64_t, uint64_t>::const_iterator findCell =
cellIdLocations.find(cellId);
98 std::cerr <<
"ERROR, CELL ID NOT FOUND AT " << __FILE__ <<
" " << __LINE__ << std::endl;
101 uint64_t vectorSize, byteSize;
103 vlsv::datatype::type dataType;
104 std::list< std::pair<std::string, std::string> > xmlAttributes;
105 xmlAttributes.push_back( std::make_pair(
"name", variableName ) );
106 xmlAttributes.push_back( std::make_pair(
"mesh",
"SpatialGrid" ) );
107 if( getArrayInfo(
"VARIABLE", xmlAttributes, arraySize, vectorSize, dataType, byteSize ) ==
false )
return false;
108 if( vectorSize != N ) {
109 std::cerr <<
"ERROR, BAD VECTORSIZE AT " << __FILE__ <<
" " << __LINE__ << std::endl;
112 const uint64_t amountToReadIn = 1;
113 char * buffer =
new char[vectorSize * amountToReadIn * byteSize];
115 const uint64_t begin = findCell->second;
116 if( readArray(
"VARIABLE", xmlAttributes, begin, amountToReadIn, buffer ) ==
false )
return false;
117 float * buffer_float =
reinterpret_cast<float*
>(buffer);
118 double * buffer_double =
reinterpret_cast<double*
>(buffer);
119 uint32_t * buffer_uint_small =
reinterpret_cast<uint32_t*
>(buffer);
120 uint64_t * buffer_uint_large =
reinterpret_cast<uint64_t*
>(buffer);
121 int32_t * buffer_int_small =
reinterpret_cast<int32_t*
>(buffer);
122 int64_t * buffer_int_large =
reinterpret_cast<int64_t*
>(buffer);
124 if( dataType == vlsv::datatype::type::FLOAT ) {
125 if( byteSize ==
sizeof(
double) ) {
126 for( uint
i = 0;
i < N; ++
i ) {
127 const double var = buffer_double[
i];
130 }
else if( byteSize ==
sizeof(
float) ) {
131 for( uint
i = 0;
i < N; ++
i ) {
132 const float var = buffer_float[
i];
136 std::cerr <<
"BAD BYTESIZE AT " << __FILE__ <<
" " << __LINE__ << std::endl;
140 }
else if( dataType == vlsv::datatype::type::UINT ) {
141 if( byteSize ==
sizeof(uint64_t) ) {
142 for( uint
i = 0;
i < N; ++
i ) {
143 const uint64_t var = buffer_uint_large[
i];
146 }
else if( byteSize ==
sizeof(uint32_t) ) {
147 for( uint
i = 0;
i < N; ++
i ) {
148 const uint32_t var = buffer_uint_small[
i];
152 std::cerr <<
"BAD BYTESIZE AT " << __FILE__ <<
" " << __LINE__ << std::endl;
156 }
else if( dataType == vlsv::datatype::type::INT ) {
157 if( byteSize ==
sizeof(int64_t) ) {
158 for( uint
i = 0;
i < N; ++
i ) {
159 const int64_t var = buffer_int_large[
i];
162 }
else if( byteSize ==
sizeof(int32_t) ) {
163 for( uint
i = 0;
i < N; ++
i ) {
164 const int32_t var = buffer_int_small[
i];
168 std::cerr <<
"BAD BYTESIZE AT " << __FILE__ <<
" " << __LINE__ << std::endl;
173 std::cerr <<
"BAD DATATYPE AT " << __FILE__ <<
" " << __LINE__ << std::endl;