18 #ifndef viskores_cont_ArrayHandleXGCCoordinates_h
19 #define viskores_cont_ArrayHandleXGCCoordinates_h
34 template <
typename PortalType>
35 struct VISKORES_ALWAYS_EXPORT ArrayPortalXGCCoordinates
41 ArrayPortalXGCCoordinates()
43 , NumberOfPointsPerPlane(0)
45 , NumberOfPlanesOwned(0)
47 , UseCylindrical(false){};
51 ArrayPortalXGCCoordinates(
const PortalType& p,
55 bool cylindrical =
false)
57 , NumberOfPlanes(numOfPlanes)
58 , NumberOfPlanesOwned(numOfPlanesOwned)
59 , PlaneStartId(planeStartId)
60 , UseCylindrical(cylindrical)
62 this->NumberOfPointsPerPlane = this->Portal.GetNumberOfValues() / 2;
69 return (this->NumberOfPointsPerPlane *
static_cast<viskores::Id>(NumberOfPlanesOwned));
76 const viskores::Id realIdx = ((index * 2) % this->Portal.GetNumberOfValues()) / 2;
78 (index * 2) / this->Portal.GetNumberOfValues() + this->PlaneStartId;
86 using CompType =
typename ValueType::ComponentType;
90 const auto phi =
static_cast<CompType
>(whichPlane * (viskores::TwoPi() / this->NumberOfPlanes));
92 auto r = this->Portal.Get(realIdx);
93 auto z = this->Portal.Get(realIdx + 1);
94 if (this->UseCylindrical)
96 return ValueType(r, phi, z);
108 using CompType =
typename ValueType::ComponentType;
111 for (
int j = 0; j < 2; ++j)
114 static_cast<CompType
>(index.Planes[j] * (viskores::TwoPi() / this->NumberOfPlanes));
115 for (
int i = 0; i < 3; ++i)
118 auto r = this->Portal.Get(realIdx);
119 auto z = this->Portal.Get(realIdx + 1);
120 result[3 * j + i] = this->UseCylindrical
121 ? ValueType(r, phi, z)
152 struct XGCCoordinatesMetaData
157 bool UseCylindrical =
false;
159 XGCCoordinatesMetaData() =
default;
165 : NumberOfPlanes(numberOfPlanes)
166 , NumberOfPlanesOwned(numberOfPlanesOwned)
167 , PlaneStartId(planeStartId)
168 , UseCylindrical(useCylindrical)
176 template <
typename T>
177 class XGCCoordinatesStorageImpl
179 using SourceStorage = Storage<T, StorageTagBasic>;
180 using MetaData = XGCCoordinatesMetaData;
182 static MetaData& GetMetaData(
const std::vector<viskores::cont::internal::Buffer>& buffers)
184 return buffers[0].GetMetaData<MetaData>();
188 VISKORES_CONT static std::vector<viskores::cont::internal::Buffer> SourceBuffers(
189 const std::vector<viskores::cont::internal::Buffer>& buffers)
191 return std::vector<viskores::cont::internal::Buffer>(buffers.begin() + 1, buffers.end());
195 using ReadPortalType =
196 viskores::internal::ArrayPortalXGCCoordinates<typename SourceStorage::ReadPortalType>;
199 const std::vector<viskores::cont::internal::Buffer>&)
205 const std::vector<viskores::cont::internal::Buffer>& buffers)
207 return GetNumberOfValuesPerPlane(buffers) * GetNumberOfPlanesOwned(buffers);
211 const std::vector<viskores::cont::internal::Buffer>& buffers)
213 return SourceStorage::GetNumberOfValues(SourceBuffers(buffers)) / 2;
217 const std::vector<viskores::cont::internal::Buffer>& buffers)
219 return GetMetaData(buffers).NumberOfPlanes;
223 const std::vector<viskores::cont::internal::Buffer>& buffers)
225 return GetMetaData(buffers).NumberOfPlanesOwned;
229 const std::vector<viskores::cont::internal::Buffer>& buffers)
231 return GetMetaData(buffers).PlaneStartId;
235 const std::vector<viskores::cont::internal::Buffer>& buffers)
237 return GetMetaData(buffers).UseCylindrical;
241 const std::vector<viskores::cont::internal::Buffer>& buffers,
245 return ReadPortalType(SourceStorage::CreateReadPortal(SourceBuffers(buffers), device, token),
246 GetNumberOfPlanes(buffers),
247 GetNumberOfPlanesOwned(buffers),
248 GetPlaneStartId(buffers),
249 GetUseCylindrical(buffers));
252 VISKORES_CONT static std::vector<viskores::cont::internal::Buffer> CreateBuffers(
259 return viskores::cont::internal::CreateBuffers(
260 MetaData(numberOfPlanes, numberOfPlanesOwned, planeStartId, useCylindrical), array);
263 VISKORES_CONT static std::vector<viskores::cont::internal::Buffer> CreateBuffers()
269 const std::vector<viskores::cont::internal::Buffer>& buffers)
279 :
public detail::XGCCoordinatesStorageImpl<viskores::Float32>
288 :
public detail::XGCCoordinatesStorageImpl<viskores::Float64>
297 template <
typename T>
300 viskores::cont::StorageTagXGCCoordinates>
329 return StorageType::GetNumberOfPlanes(this->GetBuffers());
334 return StorageType::GetNumberOfPlanesOwned(this->GetBuffers());
339 return StorageType::GetPlaneStartId(this->GetBuffers());
344 return StorageType::GetUseCylindrical(this->GetBuffers());
349 return StorageType::GetNumberOfValuesPerPlane(this->GetBuffers());
354 return StorageType::GetArrayHandle(this->GetBuffers());
358 template <
typename T>
366 if (numberOfPlanes == -1)
368 numberOfPlanes = numberOfPlanesOwned;
371 arrHandle, numberOfPlanes, numberOfPlanesOwned, planeStartId, cylindrical);
374 template <
typename T>
384 if (numberOfPlanes == -1)
386 numberOfPlanes = numberOfPlanesOwned;
396 template <
typename T>
398 const std::vector<T>& array,
407 if (numberOfPlanes == -1)
409 numberOfPlanes = numberOfPlanesOwned;
411 return make_ArrayHandleXGCCoordinates<T>(&array.front(),
437 template <
typename T>
438 struct SerializableTypeString<
viskores::cont::ArrayHandleXGCCoordinates<T>>
447 template <
typename T>
448 struct SerializableTypeString<
449 viskores::cont::ArrayHandle<viskores::Vec<T, 3>, viskores::cont::StorageTagXGCCoordinates>>
450 : SerializableTypeString<viskores::cont::ArrayHandleXGCCoordinates<T>>
459 template <
typename T>
460 struct Serialization<
viskores::cont::ArrayHandleXGCCoordinates<T>>
467 static VISKORES_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
470 viskoresdiy::save(bb, ah.GetNumberOfPlanes());
471 viskoresdiy::save(bb, ah.GetNumberOfPlanesOwned());
472 viskoresdiy::save(bb, ah.GetPlaneStartId());
473 viskoresdiy::save(bb, ah.GetUseCylindrical());
474 viskoresdiy::save(bb, ah.GetArray());
492 array, numberOfPlanes, numberOfPlanesOwned, planeStartId, isCylindrical);
496 template <
typename T>
497 struct Serialization<
498 viskores::cont::ArrayHandle<viskores::Vec<T, 3>, viskores::cont::StorageTagXGCCoordinates>>
499 : Serialization<viskores::cont::ArrayHandleXGCCoordinates<T>>