Program Listing for File gamer.h

Return to documentation for file (include/gamer/gamer.h)

// This file is part of the GAMer software.
// Copyright (C) 2016-2021
// by Christopher T. Lee and contributors
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see <http://www.gnu.org/licenses/>
// or write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA

#pragma once

#include "gamer/tensor.h"
#include <Eigen/Dense>
#include <sstream>

namespace gamer {
namespace detail {
template <typename... T>
void throw_runtime_error(const char *function, const char *file, const int line,
                         T &&...ts) {
  std::stringstream ss;
  ss << "Error: ";
  int dummy[] = {0, ((ss << std::forward<T>(ts)), 0)...};
  static_cast<void>(dummy); // Avoid warning for unused variable
  ss << " in function " << function << " at " << file << ":" << line;
  throw std::runtime_error(ss.str());
}
} // namespace detail
} // namespace gamer

#ifdef _MSC_VER
  #define __PRETTY_FUNCTION__ __FUNCSIG__
#endif

#define gamer_runtime_error(...)                                               \
  gamer::detail::throw_runtime_error(__PRETTY_FUNCTION__, __FILE__, __LINE__,  \
                                     __VA_ARGS__);

namespace gamer {
#define BLOBBYNESS -0.2f

#define DIM_SCALE 1.99

#define MIN_VOLUME 333333

#ifdef SINGLE
#define REAL float
#else
#define REAL double
#endif

using Vector = tensor<REAL, 3, 1>;
using Vector3d = tensor<double, 3, 1>;
using Vector3f = tensor<float, 3, 1>;
using Vector3i = tensor<int, 3, 1>;
using Vector3szt = tensor<std::size_t, 3, 1>;

using EigenMatrix = Eigen::Matrix<REAL, 3, 3>;
using EigenVector = Eigen::Matrix<REAL, 3, 1>;
using EigenMatrixN = Eigen::Matrix<REAL, Eigen::Dynamic, Eigen::Dynamic>;
using EigenVectorN = Eigen::Matrix<REAL, Eigen::Dynamic, 1>;

inline std::size_t Vect2Index(const std::size_t i, const std::size_t j,
                              const std::size_t k, const Vector3szt &dim) {
  return k * dim[0] * dim[1] + j * dim[0] + i;
}
} // end namespace gamer