-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a new Force: Attraction Plane Implements an attraction plane that constrains particles to stay on one side of it while attracting them with a constant force (`type = attraction_plane`). Documentation is also included.
- Loading branch information
1 parent
08dcc2c
commit f0e0c9d
Showing
12 changed files
with
218 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @file AttractionPlane.cpp | ||
* @date 01/aug/2024 | ||
* @author Matthies, Tilibit | ||
* | ||
*/ | ||
|
||
#include "AttractionPlane.h" | ||
#include "../Utilities/oxDNAException.h" | ||
#include "../Particles/BaseParticle.h" | ||
|
||
AttractionPlane::AttractionPlane() : | ||
BaseForce() { | ||
_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); | ||
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()); | ||
} | ||
_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) { | ||
number distance_from_plane = this->_direction*pos + this->_position; | ||
|
||
if(distance_from_plane >= 0.) { | ||
number force = -this->_stiff * 1.0; // constant times * unit of length | ||
return force * this->_direction; | ||
} | ||
else | ||
return -(distance_from_plane*this->_stiff)*this->_direction; | ||
} | ||
|
||
number AttractionPlane::potential(llint step, LR_vector &pos) { | ||
number distance_from_plane = this->_direction*pos + this->_position; | ||
|
||
if(distance_from_plane >= 0.) | ||
return (number) (this->_stiff*distance_from_plane); | ||
else | ||
return (number) (0.5*this->_stiff*SQR(distance_from_plane)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @file AttractionPlane.h | ||
* @date 01/aug/2024 | ||
* @author Matthies, Tilibit | ||
* | ||
*/ | ||
|
||
#ifndef ATTRACTIONPLANE_H_ | ||
#define ATTRACTIONPLANE_H_ | ||
|
||
#include "BaseForce.h" | ||
|
||
/** | ||
* @brief External force field that attracts particles towards a plane. | ||
* | ||
* The definition of the plane is given by dir * (x,y,z) + position = 0. | ||
* Example section in the external forces file: | ||
\n | ||
{\n | ||
particle = -1 # acts on all particles\n | ||
type = attraction_plane\n | ||
position = 7. # in simulation unit lengths\n | ||
stiff = 50. # quite stiff. Good for MC, not for MD\n | ||
dir = 0.,0.,1. # points towards positive z\n | ||
}\n\n | ||
* @verbatim | ||
stiff = <float> (stiffness of the attraction.) | ||
dir = <float>,<float>,<float> (the vector normal to the plane: it should point towards the half-plane where the repulsion is not acting.) | ||
position = <float> (defines the position of the plane along the direction identified by the plane normal.) | ||
particle = <int> (index of the particle on which the force shall be applied. If -1, the force will be exerted on all the particles.) | ||
@endverbatim | ||
*/ | ||
|
||
class AttractionPlane : public BaseForce { | ||
public: | ||
number _position; | ||
|
||
AttractionPlane (); | ||
virtual ~AttractionPlane() { | ||
} | ||
|
||
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); | ||
}; | ||
|
||
#endif // ATTRACTIONPLANE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters