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-2026 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>
28
29#include <type_traits>
30
31namespace walberla {
32
33template <typename T, typename U = T> inline U es2walberla(T const &v) {
34 static_assert(std::is_arithmetic_v<T> and std::is_arithmetic_v<U>,
35 "a partial specialization of es2walberla is missing for the "
36 "type you are trying to convert");
37 return numeric_cast<U>(v);
38}
39template <> inline Vector3<float> es2walberla(Utils::Vector3d const &v) {
42}
43template <> inline Vector3<double> es2walberla(Utils::Vector3d const &v) {
44 return Vector3<double>{v[0], v[1], v[2]};
45}
46
47template <typename T> auto to_vector3d(Vector3<T> const &v) noexcept {
48 return Utils::Vector3d{Utils::detail::carray_alias<double, 3u>{
49 double_c(v[0]), double_c(v[1]), double_c(v[2])}};
50}
51
52inline Utils::Vector3i to_vector3i(Vector3<int> const &v) noexcept {
53 return Utils::Vector3i{
54 Utils::detail::carray_alias<int, 3u>{v[0], v[1], v[2]}};
55}
56
57inline Utils::Vector3i to_vector3i(Cell const &v) noexcept {
58 return Utils::Vector3i{
59 Utils::detail::carray_alias<int, 3u>{v.x(), v.y(), v.z()}};
60}
61
62template <typename T> auto to_vector3(Utils::Vector3d const &v) noexcept {
63 return Vector3<T>{numeric_cast<T>(v[0]), numeric_cast<T>(v[1]),
64 numeric_cast<T>(v[2])};
65}
66
67template <typename T> auto to_vector9d(Matrix3<T> const &m) noexcept {
68 return Utils::VectorXd<9>{Utils::detail::carray_alias<double, 9u>{
69 double_c(m[0]), double_c(m[1]), double_c(m[2]), double_c(m[3]),
70 double_c(m[4]), double_c(m[5]), double_c(m[6]), double_c(m[7]),
71 double_c(m[8])}};
72}
73
74} // namespace walberla
Vector implementation and trait types for boost qvm interoperability.
Definition Cell.hpp:96
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
\file PackInfoPdfDoublePrecision.cpp \author pystencils
auto to_vector3d(Vector3< T > const &v) noexcept
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)