From 83223795f2e8e98b174eb96e2b65a93f8444b244 Mon Sep 17 00:00:00 2001 From: elija feigl Date: Tue, 6 Aug 2024 13:57:36 +0200 Subject: [PATCH] adapt AttractionPlane to match refactored RepulsionPlane rewrite init method fix CUDA via removal template SD-835 --- src/CUDA/CUDAForces.h | 9 ++++---- src/Forces/AttractionPlane.cpp | 40 ++++++++++++++++------------------ src/Forces/AttractionPlane.h | 11 ++++------ 3 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/CUDA/CUDAForces.h b/src/CUDA/CUDAForces.h index 5cd0e75d..cd703a42 100644 --- a/src/CUDA/CUDAForces.h +++ b/src/CUDA/CUDAForces.h @@ -157,15 +157,14 @@ void init_RepulsionPlane_from_CPU(repulsion_plane *cuda_force, RepulsionPlane *c /** * @brief CUDA version of a AttractionPlane. */ -template struct attraction_plane { int type; - number stiff; - number position; + c_number stiff; + c_number position; float3 dir; }; -void init_AttractionPlane_from_CPU(repulsion_plane *cuda_force, RepulsionPlane *cpu_force) { +void init_AttractionPlane_from_CPU(attraction_plane *cuda_force, AttractionPlane *cpu_force) { cuda_force->type = CUDA_ATTRACTION_PLANE; cuda_force->stiff = cpu_force->_stiff; cuda_force->position = cpu_force->_position; @@ -497,7 +496,7 @@ union CUDA_trap { COM_force comforce; lt_com_trap ltcomtrap; Yukawa_sphere yukawasphere; - attraction_plane attractionplane; + attraction_plane attractionplane; }; #endif /* CUDAFORCES_H_ */ diff --git a/src/Forces/AttractionPlane.cpp b/src/Forces/AttractionPlane.cpp index f44e9c0d..18ca8ee0 100755 --- a/src/Forces/AttractionPlane.cpp +++ b/src/Forces/AttractionPlane.cpp @@ -1,5 +1,5 @@ /** - * @file RepulsionPlane.cpp + * @file AttractionPlane.cpp * @date 01/aug/2024 * @author Matthies, Tilibit * @@ -11,36 +11,34 @@ AttractionPlane::AttractionPlane() : BaseForce() { - _particle = -1; _position = -1.; } -void AttractionPlane::get_settings (input_file &inp) { - getInputInt (&inp, "particle", &_particle, 1); - getInputNumber(&inp, "stiff", &this->_stiff, 1); - getInputNumber(&inp, "position", &this->_position, 1); +std::tuple, std::string> AttractionPlane::init(input_file &inp) { + BaseForce::init(inp); + + std::string particles_string; + getInputString(&inp, "particle", particles_string, 1); + + getInputNumber(&inp, "stiff", &_stiff, 1); + getInputNumber(&inp, "position", &_position, 1); int tmpi; double tmpf[3]; std::string strdir; - getInputString (&inp, "dir", strdir, 1); + getInputString(&inp, "dir", strdir, 1); tmpi = sscanf(strdir.c_str(), "%lf,%lf,%lf", tmpf, tmpf + 1, tmpf + 2); - if(tmpi != 3) throw oxDNAException ("Could not parse dir %s in external forces file. Aborting", strdir.c_str()); - this->_direction = LR_vector((number) tmpf[0], (number) tmpf[1], (number) tmpf[2]); - this->_direction.normalize(); -} - -void AttractionPlane::init (BaseParticle ** particles, int N, BaseBox * box_ptr) { - if (_particle >= N || N < -1) throw oxDNAException ("Trying to add a AttractionPlane on non-existent particle %d. Aborting", _particle); - if (_particle != -1) { - OX_LOG (Logger::LOG_INFO, "Adding AttractionPlane (stiff=%g, position=%g, dir=%g,%g,%g, on particle %d", this->_stiff, this->_position, this->_direction.x, this->_direction.y, this->_direction.z, _particle); - particles[_particle]->add_ext_force(this); - } - else { // force affects all particles - OX_LOG (Logger::LOG_INFO, "Adding AttractionPlane (stiff=%g, position=%g, dir=%g,%g,%g, on ALL particles", this->_stiff, this->_position, this->_direction.x, this->_direction.y, this->_direction.z); - for(int i = 0; i < N; i ++) particles[i]->add_ext_force(this); + if(tmpi != 3) { + throw oxDNAException("Could not parse dir %s in external forces file. Aborting", strdir.c_str()); } + _direction = LR_vector((number) tmpf[0], (number) tmpf[1], (number) tmpf[2]); + _direction.normalize(); + + auto particle_ids = Utils::get_particles_from_string(CONFIG_INFO->particles(), particles_string, "AttractionPlane"); + std::string description = Utils::sformat("AttractionPlane (stiff=%g, position=%g, dir=%g,%g,%g", _stiff, _position, _direction.x, _direction.y, _direction.z); + + return std::make_tuple(particle_ids, description); } LR_vector AttractionPlane::value(llint step, LR_vector &pos) { diff --git a/src/Forces/AttractionPlane.h b/src/Forces/AttractionPlane.h index 07538227..fa2f458f 100755 --- a/src/Forces/AttractionPlane.h +++ b/src/Forces/AttractionPlane.h @@ -1,5 +1,5 @@ /** - * @file RepulsionPlane.h + * @file AttractionPlane.h * @date 01/aug/2024 * @author Matthies, Tilibit * @@ -34,17 +34,14 @@ particle = (index of the particle on which the force shall be applied. If */ class AttractionPlane : public BaseForce { -private: - int _particle; - public: number _position; AttractionPlane (); - virtual ~AttractionPlane() {} + virtual ~AttractionPlane() { + } - void get_settings (input_file &); - void init (BaseParticle **, int, BaseBox *); + std::tuple, std::string> init(input_file &inp) override; virtual LR_vector value(llint step, LR_vector &pos); virtual number potential(llint step, LR_vector &pos);