https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Namespaces | Functions
RayTracingPackingUtils Namespace Reference

Namespaces

namespace  detail
 

Functions

template<class Cont , class InputIt >
void unpackCopy (Cont &container, InputIt &input_iterator)
 Like std::copy, but passes the input iterator by reference.
 
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.
 
template<typename BufferType , typename BufferIter , typename ValueType >
void reinterpretUnpackCopy (std::vector< ValueType > &values, BufferIter &in)
 Packs the data from in into the vector values.
 
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.
 
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().
 
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().
 
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().
 
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.
 
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.
 
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().
 
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.
 
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,
267 ((void)detail::mixedPackHelper(
268 out, dest, dest_offset, std::forward<ValueTypes const &>(values)),
269 0)...};
270 (void)expander;
271
272 if (dest_offset)
273 out++ = dest;
274}

◆ mixedPackSize()

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

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}

◆ 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}

◆ pack() [1/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 constexpr dof_id_type invalid_id

◆ 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 , 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}

◆ 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}
std::array< Real, 2 > values
OStreamProxy out(std::cout)

◆ 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.

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}

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

◆ 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}

◆ 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.

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

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