Skip to content

Commit

Permalink
adapt AttractionPlane to match refactored RepulsionPlane
Browse files Browse the repository at this point in the history
rewrite init method
fix CUDA via removal template

SD-835
  • Loading branch information
elija-feigl committed Aug 6, 2024
1 parent 4edea11 commit 8322379
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
9 changes: 4 additions & 5 deletions src/CUDA/CUDAForces.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,14 @@ void init_RepulsionPlane_from_CPU(repulsion_plane *cuda_force, RepulsionPlane *c
/**
* @brief CUDA version of a AttractionPlane.
*/
template<typename number>
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;
Expand Down Expand Up @@ -497,7 +496,7 @@ union CUDA_trap {
COM_force comforce;
lt_com_trap ltcomtrap;
Yukawa_sphere yukawasphere;
attraction_plane<number> attractionplane;
attraction_plane attractionplane;
};

#endif /* CUDAFORCES_H_ */
40 changes: 19 additions & 21 deletions src/Forces/AttractionPlane.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file RepulsionPlane.cpp
* @file AttractionPlane.cpp
* @date 01/aug/2024
* @author Matthies, Tilibit
*
Expand All @@ -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::vector<int>, 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) {
Expand Down
11 changes: 4 additions & 7 deletions src/Forces/AttractionPlane.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file RepulsionPlane.h
* @file AttractionPlane.h
* @date 01/aug/2024
* @author Matthies, Tilibit
*
Expand Down Expand Up @@ -34,17 +34,14 @@ particle = <int> (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::vector<int>, std::string> init(input_file &inp) override;

virtual LR_vector value(llint step, LR_vector &pos);
virtual number potential(llint step, LR_vector &pos);
Expand Down

0 comments on commit 8322379

Please sign in to comment.