feat(discretization): added implementation of checked_block_size
tho see the note in the header, this could be made more general likeley
This commit is contained in:
20
src/lib/serif/discretization/blocks/system_layout.cpp
Normal file
20
src/lib/serif/discretization/blocks/system_layout.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "serif/discretization/blocks/system_layout.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include "serif/utils/error/errors.hpp"
|
||||
|
||||
namespace serif::discretization::blocks
|
||||
{
|
||||
std::size_t checked_block_size(const std::span<const std::size_t> sizes)
|
||||
{
|
||||
using namespace utils::errors;
|
||||
|
||||
std::size_t total = 0;
|
||||
for (const std::size_t size : sizes) {
|
||||
serif_ensure<SERiFErrorCode::INVALID_DOF_COUNT, std::overflow_error>(size <= std::numeric_limits<std::size_t>::max() - total, "The system's packed coefficient count overflows size_t. Check the individual coordinate sizes.");
|
||||
total += size;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
} // namespace serif::discretization::blocks
|
||||
Reference in New Issue
Block a user