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:
2026-10-14 10:58:52 -04:00
parent d3ff5add71
commit d2e43c82f1

View 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