https://mooseframework.inl.gov
Namespaces | Functions
RayTracingPackingUtils Namespace Reference

Namespaces

 detail
 

Functions

template<class Cont , class InputIt >
void unpackCopy (Cont &container, InputIt &input_iterator)
 Like std::copy, but passes the input iterator by reference. More...
 
template<typename BufferType , typename BufferIter , typename ValueType >
void reinterpretPackCopy (const std::vector< ValueType > &values, BufferIter &out)
 Packs the data in values into the iterator out and minimizes memory storage in said iterator. More...
 
template<typename BufferType , typename BufferIter , typename ValueType >
void reinterpretUnpackCopy (std::vector< ValueType > &values, BufferIter &in)
 Packs the data from in into the vector values. More...
 
template<typename ValueType , typename BufferType >
std::size_t reinterpretCopySize (const std::size_t input_size)
 Gets the minimum number of values of BufferType needed to represent input_size values of ValueType. More...
 
template<typename BufferType , typename BufferIter , typename... ValueTypes>
void mixedUnpack (BufferIter &in, ValueTypes &... values)
 Unpacks the mixed-values from in into values that were packed with mixedPack(). More...
 
template<typename BufferType , typename BufferIter , typename... ValueTypes>
void mixedPack (BufferIter &out, ValueTypes const &... values)
 Packs the mixed-type values in values into out to be unpacked with mixedUnpack(). More...
 
template<typename BufferType , typename... InputTypes>
constexpr std::size_t mixedPackSize ()
 Gets the number of BufferType required to store the expanded InputTypes for use with mixedPack() and mixedUnpack(). More...
 
template<typename BufferType , typename ValueType >
BufferType pack (const ValueType value)
 Packs value into a value of type BufferType at a byte level, to be unpacked with the unpack() routines in this namespace. More...
 
template<typename BufferType , typename ValueType >
void unpack (const BufferType value_as_buffer_type, ValueType &value)
 Unpacks value_as_buffer_type (which is packed with pack()) into value at a byte level. More...
 
template<typename BufferType >
BufferType pack (const Elem *elem, MeshBase *mesh_base=nullptr)
 Packs the ID of elem into a type of BufferType to be unpacked later into another const Elem * with unpack(). More...
 
template<typename BufferType >
void unpack (const Elem *&elem, const BufferType id_as_buffer_type, MeshBase *mesh_base)
 Unpacks the const Elem * from id_as_buffer_type (packed using pack()) into elem. More...
 
template<typename BufferType >
BufferType pack (const Elem *elem, MeshBase *libmesh_dbg_var(mesh_base))
 

Function Documentation

◆ mixedPack()

template<typename BufferType , typename BufferIter , typename... ValueTypes>
void RayTracingPackingUtils::mixedPack ( BufferIter &  out,
ValueTypes const &...  values 
)

Packs the mixed-type values in values into out to be unpacked with mixedUnpack().

Uses as few entries in out needed to represent values in order.

Definition at line 261 of file RayTracingPackingUtils.h.

262 {
263  std::size_t dest_offset = 0;
264  BufferType dest;
265 
266  int expander[] = {0,
268  out, dest, dest_offset, std::forward<ValueTypes const &>(values)),
269  0)...};
270  (void)expander;
271 
272  if (dest_offset)
273  out++ = dest;
274 }
void mixedPackHelper(BufferIter &out, BufferType &dest, std::size_t &dest_offset, const ValueType &input)
Helper for mixedPack()
OStreamProxy out
class infix_ostream_iterator if void

◆ mixedPackSize()

template<typename BufferType , typename... InputTypes>
constexpr std::size_t RayTracingPackingUtils::mixedPackSize ( )

Gets the number of BufferType required to store the expanded InputTypes for use with mixedPack() and mixedUnpack().

Can be stored as constexpr to evaluate the size at compile time only.

Definition at line 278 of file RayTracingPackingUtils.h.

279 {
280  // Call the recursive helper with an initial offset and size of 0
281  return detail::mixedPackSizeHelper<BufferType, InputTypes...>(/* offset = */ 0, /* size = */ 0);
282 }
constexpr std::size_t mixedPackSizeHelper(std::size_t offset, std::size_t size)
Recursive helper for mixedPackSize().

◆ mixedUnpack()

template<typename BufferType , typename BufferIter , typename... ValueTypes>
void RayTracingPackingUtils::mixedUnpack ( BufferIter &  in,
ValueTypes &...  values 
)

Unpacks the mixed-values from in into values that were packed with mixedPack().

Definition at line 247 of file RayTracingPackingUtils.h.

248 {
249  std::size_t src_offset = sizeof(BufferType);
250  const BufferType * src = nullptr;
251 
252  int expander[] = {
253  0,
254  ((void)detail::mixedUnpackHelper(in, src, src_offset, std::forward<ValueTypes &>(values)),
255  0)...};
256  (void)expander;
257 }
void mixedUnpackHelper(BufferIter &in, const BufferType *&src, std::size_t &src_offset, ValueType &output)
Helper for mixedUnpack()
class infix_ostream_iterator if void

◆ pack() [1/3]

template<typename BufferType , typename ValueType >
BufferType RayTracingPackingUtils::pack ( const ValueType  value)

Packs value into a value of type BufferType at a byte level, to be unpacked with the unpack() routines in this namespace.

Definition at line 286 of file RayTracingPackingUtils.h.

287 {
288  static_assert(sizeof(ValueType) <= sizeof(BufferType), "Value will won't fit into buffer type");
289 
290  BufferType value_as_buffer_type;
291  std::memcpy(&value_as_buffer_type, &value, sizeof(ValueType));
292  return value_as_buffer_type;
293 }

◆ pack() [2/3]

template<typename BufferType >
BufferType RayTracingPackingUtils::pack ( const Elem *  elem,
MeshBase *  mesh_base = nullptr 
)

Packs the ID of elem into a type of BufferType to be unpacked later into another const Elem * with unpack().

◆ pack() [3/3]

template<typename BufferType >
BufferType RayTracingPackingUtils::pack ( const Elem *  elem,
MeshBase *  libmesh_dbg_varmesh_base 
)

Definition at line 305 of file RayTracingPackingUtils.h.

306 {
307  const dof_id_type id = elem ? elem->id() : libMesh::DofObject::invalid_id;
308  mooseAssert(mesh_base ? mesh_base->query_elem_ptr(id) == elem : true,
309  "Elem doesn't exist in mesh");
310 
311  return pack<BufferType>(id);
312 }
static const dof_id_type invalid_id
uint8_t dof_id_type

◆ reinterpretCopySize()

template<typename ValueType , typename BufferType >
std::size_t RayTracingPackingUtils::reinterpretCopySize ( const std::size_t  input_size)

Gets the minimum number of values of BufferType needed to represent input_size values of ValueType.

To be used with sizing for reinterpretPackCopy() and reinterpretUnpackCopy().

Definition at line 239 of file RayTracingPackingUtils.h.

240 {
241  const double input_per_output = std::floor(sizeof(BufferType) / sizeof(ValueType));
242  return (std::size_t)std::ceil((double)input_size / input_per_output);
243 }

◆ reinterpretPackCopy()

template<typename BufferType , typename BufferIter , typename ValueType >
void RayTracingPackingUtils::reinterpretPackCopy ( const std::vector< ValueType > &  values,
BufferIter &  out 
)

Packs the data in values into the iterator out and minimizes memory storage in said iterator.

In specific, ValueType is packed into BufferType at a byte level. That is, if sizeof(ValueType) == 4 and sizeof(BufferType) == 8, two values of type ValueType objects will be stored in a single value of type BufferType.

Definition at line 190 of file RayTracingPackingUtils.h.

191 {
192  static_assert(sizeof(ValueType) <= sizeof(BufferType), "ValueType will not fit into BufferType");
193 
194  BufferType dest;
195  const ValueType * src = values.data();
196 
197  std::size_t dest_offset = 0;
198  for (std::size_t i = 0; i < values.size(); ++i)
199  {
200  if (dest_offset + sizeof(ValueType) > sizeof(BufferType))
201  {
202  out++ = dest;
203  dest_offset = 0;
204  }
205 
206  std::memcpy((char *)&dest + dest_offset, &src[i], sizeof(ValueType));
207  dest_offset += sizeof(ValueType);
208  }
209 
210  if (dest_offset)
211  out++ = dest;
212 }
OStreamProxy out

◆ reinterpretUnpackCopy()

template<typename BufferType , typename BufferIter , typename ValueType >
void RayTracingPackingUtils::reinterpretUnpackCopy ( std::vector< ValueType > &  values,
BufferIter &  in 
)

Packs the data from in into the vector values.

values MUST be resized ahead of time in order to know how much to advance in.

This is to be used in the unpacking of values stored by reinterpretPackCopy().

Definition at line 216 of file RayTracingPackingUtils.h.

217 {
218  static_assert(sizeof(ValueType) <= sizeof(BufferType), "ValueType will not fit into BufferType");
219 
220  ValueType * dest = values.data();
221  const BufferType * src = nullptr;
222 
223  std::size_t src_offset = sizeof(BufferType);
224  for (std::size_t i = 0; i < values.size(); ++i)
225  {
226  if (src_offset + sizeof(ValueType) > sizeof(BufferType))
227  {
228  src = &(*in++);
229  src_offset = 0;
230  }
231 
232  std::memcpy(&dest[i], (char *)src + src_offset, sizeof(ValueType));
233  src_offset += sizeof(ValueType);
234  }
235 }

◆ unpack() [1/2]

template<typename BufferType , typename ValueType >
void RayTracingPackingUtils::unpack ( const BufferType  value_as_buffer_type,
ValueType &  value 
)

Unpacks value_as_buffer_type (which is packed with pack()) into value at a byte level.

Definition at line 297 of file RayTracingPackingUtils.h.

Referenced by libMesh::Parallel::Packing< ViewFactorRayStudy::StartElem >::unpack(), and libMesh::Parallel::Packing< std::shared_ptr< Ray > >::unpack().

298 {
299  static_assert(sizeof(ValueType) <= sizeof(BufferType), "Value will won't fit into buffer type");
300  std::memcpy(&value, &value_as_buffer_type, sizeof(ValueType));
301 }

◆ unpack() [2/2]

template<typename BufferType >
void RayTracingPackingUtils::unpack ( const Elem *&  elem,
const BufferType  id_as_buffer_type,
MeshBase *  mesh_base 
)

Unpacks the const Elem * from id_as_buffer_type (packed using pack()) into elem.

Definition at line 316 of file RayTracingPackingUtils.h.

317 {
318  dof_id_type id;
319  unpack<BufferType>(id_as_buffer_type, id);
320 
321  elem = (id == libMesh::DofObject::invalid_id ? nullptr : mesh_base->query_elem_ptr(id));
322 }
static const dof_id_type invalid_id
uint8_t dof_id_type

◆ unpackCopy()

template<class Cont , class InputIt >
void RayTracingPackingUtils::unpackCopy ( Cont &  container,
InputIt &  input_iterator 
)

Like std::copy, but passes the input iterator by reference.

Definition at line 181 of file RayTracingPackingUtils.h.

Referenced by libMesh::Parallel::Packing< std::shared_ptr< Ray > >::unpack().

182 {
183  auto first = container.begin();
184  while (first != container.end())
185  *first++ = *input_iterator++;
186 }