ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
types_conversion.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020-2025 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <core/DataTypes.h>
23#include <core/cell/Cell.h>
24#include <core/math/Matrix3.h>
25#include <core/math/Vector3.h>
26
27#include <utils/Vector.hpp>
29
30#include <type_traits>
31
32namespace walberla {
33
34template <typename T, typename U = T> inline U es2walberla(T const &v) {
35 static_assert(std::is_arithmetic_v<T> and std::is_arithmetic_v<U>,
36 "a partial specialization of es2walberla is missing for the "
37 "type you are trying to convert");
38 return numeric_cast<U>(v);
39}
40template <> inline Vector3<float> es2walberla(Utils::Vector3d const &v) {
41 return Vector3<float>{numeric_cast<float>(v[0]), numeric_cast<float>(v[1]),
42 numeric_cast<float>(v[2])};
43}
44template <> inline Vector3<double> es2walberla(Utils::Vector3d const &v) {
45 return Vector3<double>{v[0], v[1], v[2]};
46}
47
48template <typename T> auto to_vector3d(Vector3<T> const &v) noexcept {
49 return Utils::Vector3d{Utils::detail::carray_alias<double, 3u>{
50 double_c(v[0]), double_c(v[1]), double_c(v[2])}};
51}
52
53inline Utils::Vector3i to_vector3i(Vector3<int> const &v) noexcept {
54 return {v[0], v[1], v[2]};
55}
56
57inline Utils::Vector3i to_vector3i(Cell const &v) noexcept {
58 return {v.x(), v.y(), v.z()};
59}
60
61template <typename T> auto to_vector3(Utils::Vector3d const &v) noexcept {
62 return Vector3<T>{numeric_cast<T>(v[0]), numeric_cast<T>(v[1]),
63 numeric_cast<T>(v[2])};
64}
65
66template <typename T> auto to_vector9d(Matrix3<T> const &m) noexcept {
67 return Utils::VectorXd<9>{Utils::detail::carray_alias<double, 9u>{
68 double_c(m[0]), double_c(m[1]), double_c(m[2]), double_c(m[3]),
69 double_c(m[4]), double_c(m[5]), double_c(m[6]), double_c(m[7]),
70 double_c(m[8])}};
71}
72
73template <typename Function>
74void interpolate_bspline_at_pos(Utils::Vector3d const &pos, Function const &f) {
75 Utils::Interpolation::bspline_3d<2>(
76 pos, f, Utils::Vector3d::broadcast(1.), // grid spacing
77 Utils::Vector3d::broadcast(.5)); // offset
78}
79
80} // namespace walberla
Vector implementation and trait types for boost qvm interoperability.
Definition Cell.hpp:97
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value) noexcept
Create a vector that has all entries set to the same value.
Definition Vector.hpp:110
\file PackInfoPdfDoublePrecision.cpp \author pystencils
auto to_vector3d(Vector3< T > const &v) noexcept
void interpolate_bspline_at_pos(Utils::Vector3d const &pos, Function const &f)
auto to_vector3(Utils::Vector3d const &v) noexcept
Utils::Vector3i to_vector3i(Vector3< int > const &v) noexcept
auto to_vector9d(Matrix3< T > const &m) noexcept
U es2walberla(T const &v)