Commit 16b66a99 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

integral constant user-defined literals added

parent 8a92fa8e
#pragma once
#include "Basic.hpp"
namespace AMDiS
{
// inspired by Boost.hana
namespace Impl
{
constexpr unsigned char2digit(const char c)
{
assert(c >= '0' && c <= '9' && "Unknown digit in integral constant");
return unsigned(c) - unsigned('0');
}
template <size_t N>
constexpr size_t string2num(const char (&arr)[N])
{
assert(arr[0] != '-' && "Negative integral constant");
size_t result = 0;
size_t power = 1;
for (size_t i = 0; i < N; ++i) {
char c = arr[N - 1 - i];
result+= char2digit(c) * power;
power *= 10u;
}
return result;
}
} // end namespace Impl
template <char... digits>
constexpr auto operator"" _c()
{
return index_<Impl::string2num<sizeof...(digits)>({digits...})>();
}
} // end namespace AMDiS
......@@ -2,6 +2,8 @@
#pragma once
#include <array>
#include <boost/numeric/mtl/matrices.hpp>
#include <dune/amdis/Basic.hpp>
......@@ -47,13 +49,13 @@ namespace AMDiS
std::array<mtl::irange, _M> r_cols;
getRanges(r_rows, r_cols);
For<0, _N>::loop([this, &r_rows, &r_cols, &b, &x](const auto _r) {
For<0, _N>::loop([this, &r_rows, &r_cols, &b, &x](const auto _i) {
bool first = true;
VectorOut x_i(x[r_rows[_r]]);
For<0, _M>::loop([this, &b, &x_i, &r_cols, &first, _r](const auto _c) {
auto const& block = this->operator()(_r, _c);
VectorOut x_i(x[r_rows[_i]]);
For<0, _M>::loop([this, &b, &x_i, &r_cols, &first, _i](const auto _j) {
auto const& block = this->operator()(_i, _j);
if (num_rows(block) > 0) {
const VectorIn b_j(b[r_cols[_c]]);
const VectorIn b_j(b[r_cols[_j]]);
if (first) {
Assign::first_update(x_i, block * b_j);
first = false;
......
......@@ -10,6 +10,7 @@
#include <dune/amdis/AMDiS.hpp>
#include <dune/amdis/ProblemInstat.hpp>
#include <dune/amdis/ProblemStat.hpp>
#include <dune/amdis/Literals.hpp>
#ifndef DIM
#define DIM 2
......@@ -66,7 +67,7 @@ int main(int argc, char** argv)
opLhs.addSOT( constant(1.0) );
Op opRhs;
opRhs.addZOT( valueOf(prob.getSolution<0>(), 1.0/tau) );
opRhs.addZOT( valueOf(prob.getSolution(0_c), 1.0/tau) );
opRhs.addZOT( eval([](auto const& x) { return -1.0; }) );
prob.addMatrixOperator(opLhs, 0, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment