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-2023 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/math/Matrix3.h>
24#include <core/math/Vector3.h>
25
26#include <utils/Vector.hpp>
28
29namespace walberla {
30
31template <typename T, typename U = T> inline U es2walberla(T v) {
32 return numeric_cast<U>(v);
33}
34template <> inline Vector3<float> es2walberla(Utils::Vector3d const v) {
35 return Vector3<float>{numeric_cast<float>(v[0]), numeric_cast<float>(v[1]),
36 numeric_cast<float>(v[2])};
37}
38template <> inline Vector3<double> es2walberla(Utils::Vector3d const v) {
39 return Vector3<double>{v[0], v[1], v[2]};
40}
41
42template <typename T> inline T walberla2es(T v) { return v; }
43inline Utils::Vector3d walberla2es(Vector3<float> const v) {
44 return Utils::Vector3d{double_c(v[0]), double_c(v[1]), double_c(v[2])};
45}
46inline Utils::Vector3d walberla2es(Vector3<double> const v) {
47 return Utils::Vector3d{v[0], v[1], v[2]};
48}
49
50// Vector conversion helpers
51inline Utils::Vector3d to_vector3d(Vector3<float> const &v) {
52 return {double_c(v[0]), double_c(v[1]), double_c(v[2])};
53}
54inline Utils::Vector3d to_vector3d(Vector3<double> const &v) {
55 return {v[0], v[1], v[2]};
56}
57template <typename FloatType>
58inline Vector3<FloatType> to_vector3(Utils::Vector3d const &v) {
59 return Vector3<FloatType>{numeric_cast<FloatType>(v[0]),
60 numeric_cast<FloatType>(v[1]),
61 numeric_cast<FloatType>(v[2])};
62}
63inline Utils::VectorXd<9> to_vector9d(Matrix3<double> const &m) {
64 return {m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]};
65}
66inline Utils::VectorXd<9> to_vector9d(Matrix3<float> const &m) {
67 return {double_c(m[0]), double_c(m[1]), double_c(m[2]),
68 double_c(m[3]), double_c(m[4]), double_c(m[5]),
69 double_c(m[6]), double_c(m[7]), double_c(m[8])};
70}
71
72template <typename Function>
73void interpolate_bspline_at_pos(Utils::Vector3d const &pos, Function const &f) {
74 Utils::Interpolation::bspline_3d<2>(
75 pos, f, Utils::Vector3d::broadcast(1.), // grid spacing
76 Utils::Vector3d::broadcast(.5)); // offset
77}
78
79} // namespace walberla
Vector implementation and trait types for boost qvm interoperability.
float f[3]
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
static Vector< T, N > broadcast(T const &s)
Create a vector that has all entries set to one value.
Definition Vector.hpp:110
void interpolate_bspline_at_pos(Utils::Vector3d const &pos, Function const &f)
Vector3< FloatType > to_vector3(Utils::Vector3d const &v)
Utils::VectorXd< 9 > to_vector9d(Matrix3< double > const &m)
Utils::Vector3d to_vector3d(Vector3< float > const &v)