ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ResetForce.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
24#if defined(__CUDACC__)
27#endif
28
29#include "../utils/types_conversion.hpp"
30
31#include <core/math/Vector3.h>
32#include <domain_decomposition/BlockDataID.h>
33#include <domain_decomposition/IBlock.h>
34
35#include <utils/Vector.hpp>
36
37namespace walberla {
38
39/** Sweep that swaps @c force_to_be_applied and @c last_applied_force
40 * and resets @c force_to_be_applied to the global external force.
41 */
42template <typename PdfField, typename ForceField> class ResetForce {
43 using FloatType = typename PdfField::value_type;
44
45public:
46 ResetForce(BlockDataID const &last_applied_force_field_id,
47 BlockDataID const &force_to_be_applied_id)
48 : m_last_applied_force_field_id(last_applied_force_field_id),
49 m_force_to_be_applied_id(force_to_be_applied_id),
50 m_ext_force(Vector3<FloatType>{0, 0, 0}) {}
51
52 void set_ext_force(Utils::Vector3d const &ext_force) {
53 m_ext_force = to_vector3<FloatType>(ext_force);
54 }
55
56 Utils::Vector3d get_ext_force() const { return to_vector3d(m_ext_force); }
57
58 void operator()(IBlock *block) {
59 auto force_field =
60 block->template getData<ForceField>(m_last_applied_force_field_id);
61 auto force_to_be_applied =
62 block->template getData<ForceField>(m_force_to_be_applied_id);
63
64 force_field->swapDataPointers(force_to_be_applied);
65
66 lbm::accessor::Vector::add_to_all(force_field, m_ext_force);
67 lbm::accessor::Vector::initialize(force_to_be_applied,
68 Vector3<FloatType>{0});
69 }
70
71private:
72 const BlockDataID m_last_applied_force_field_id;
73 const BlockDataID m_force_to_be_applied_id;
74 Vector3<FloatType> m_ext_force;
75};
76
77} // namespace walberla
Vector implementation and trait types for boost qvm interoperability.
Sweep that swaps force_to_be_applied and last_applied_force and resets force_to_be_applied to the glo...
ResetForce(BlockDataID const &last_applied_force_field_id, BlockDataID const &force_to_be_applied_id)
void operator()(IBlock *block)
void set_ext_force(Utils::Vector3d const &ext_force)
Utils::Vector3d get_ext_force() const
static double * block(double *p, std::size_t index, std::size_t size)
Definition elc.cpp:172
void initialize(GhostLayerField< double, uint_t{3u}> *vec_field, Vector3< double > const &vec)
void add_to_all(GhostLayerField< double, uint_t{3u}> *vec_field, Vector3< double > const &vec)
\file PackInfoPdfDoublePrecision.cpp \author pystencils
Utils::Vector3d to_vector3d(Vector3< float > const &v)