32template <
typename floatType,
typename idType>
36 :
_r({0.0, 0.0, 0.0}),
41#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
43 _rAtRebuild({0.0, 0.0, 0.0})
55 ParticleBase(
const std::array<double, 3> &r,
const std::array<double, 3> &v, idType
id,
62#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
78 std::array<floatType, 3>
_r;
80#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
84 std::array<floatType, 3> _rAtRebuild;
90 std::array<floatType, 3>
_v;
95 std::array<floatType, 3>
_f;
112 template <
typename T,
typename P>
119 [[nodiscard]]
const std::array<double, 3> &
getF()
const {
return _f; }
125 void setF(
const std::array<double, 3> &f) {
_f = f; }
131 void addF(
const std::array<double, 3> &f) {
132 using namespace autopas::utils::ArrayMath::literals;
140 void subF(
const std::array<double, 3> &f) {
141 using namespace autopas::utils::ArrayMath::literals;
161 [[nodiscard]]
const std::array<double, 3> &
getR()
const {
return _r; }
167 void setR(
const std::array<double, 3> &r) {
_r = r; }
169#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
174 [[nodiscard]]
const std::array<double, 3> &getRAtRebuild()
const {
return _rAtRebuild; }
179 void setRAtRebuild(
const std::array<double, 3> &r) { _rAtRebuild = r; }
184 void resetRAtRebuild() { this->setRAtRebuild(
_r); }
191 const std::array<double, 3> calculateDisplacementSinceRebuild()
const {
206 using namespace autopas::utils::ArrayMath::literals;
207 const auto distanceVec = r -
_r;
210 const bool distanceIsFine =
211 distanceSquared < maxDistSquared or autopas::utils::Math::isNearAbs(maxDistSquared, 0., 1e-12);
212 if (not distanceIsFine) {
213 AutoPasLog(WARN,
"Particle {}: Distance between old and new position is larger than expected: {} > {}",
_id,
214 distanceSquared, maxDistSquared);
216 return distanceIsFine;
223 void addR(
const std::array<double, 3> &r) {
224 using namespace autopas::utils::ArrayMath::literals;
240 using namespace autopas::utils::ArrayMath::literals;
241 const auto newR =
_r + r;
249 [[nodiscard]]
const std::array<double, 3> &
getV()
const {
return _v; }
255 void setV(
const std::array<double, 3> &v) {
_v = v; }
261 void addV(
const std::array<double, 3> &v) {
262 using namespace autopas::utils::ArrayMath::literals;
270 [[nodiscard]]
virtual std::string
toString()
const {
271 std::ostringstream text;
281 <<
"\nOwnershipState : "
320 enum AttributeNames :
int { ptr, id, posX, posY, posZ, forceX, forceY, forceZ, ownershipState };
338 floatType , floatType , floatType , floatType ,
346 template <AttributeNames attribute, std::enable_if_t<attribute == AttributeNames::ptr,
bool> = true>
347 constexpr typename std::tuple_element<attribute, SoAArraysType>::type::value_type
get() {
357 template <AttributeNames attribute, std::enable_if_t<attribute != AttributeNames::ptr,
bool> = true>
358 constexpr typename std::tuple_element<attribute, SoAArraysType>::type::value_type
get()
const {
359 if constexpr (attribute == AttributeNames::id) {
361 }
else if constexpr (attribute == AttributeNames::posX) {
363 }
else if constexpr (attribute == AttributeNames::posY) {
365 }
else if constexpr (attribute == AttributeNames::posZ) {
367 }
else if constexpr (attribute == AttributeNames::forceX) {
369 }
else if constexpr (attribute == AttributeNames::forceY) {
371 }
else if constexpr (attribute == AttributeNames::forceZ) {
373 }
else if constexpr (attribute == AttributeNames::ownershipState) {
386 template <AttributeNames attribute>
387 constexpr void set(
typename std::tuple_element<attribute, SoAArraysType>::type::value_type value) {
388 if constexpr (attribute == AttributeNames::id) {
390 }
else if constexpr (attribute == AttributeNames::posX) {
392 }
else if constexpr (attribute == AttributeNames::posY) {
394 }
else if constexpr (attribute == AttributeNames::posZ) {
396 }
else if constexpr (attribute == AttributeNames::forceX) {
398 }
else if constexpr (attribute == AttributeNames::forceY) {
400 }
else if constexpr (attribute == AttributeNames::forceZ) {
402 }
else if constexpr (attribute == AttributeNames::ownershipState) {
403 this->_ownershipState = value;
416 void markAsDeleted() {
437template <
typename floatType,
typename idType>
439 using utils::ArrayUtils::operator<<;
441 <<
"\nID : " << particle.
_id <<
"\nPosition: " << particle.
_r <<
"\nVelocity: " << particle.
_v
442 <<
"\nForce : " << particle.
_f <<
"\nOwnershipState : " << particle.
_ownershipState;
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:24
Provides a struct to easily generate the desired SoAType.
Minimal definition of a basic particle.
Definition: ParticleBase.h:33
void addF(const std::array< double, 3 > &f)
Add a partial force to the force acting on the particle.
Definition: ParticleBase.h:131
bool isHalo() const
Defines whether the particle is a halo particle, i.e., not owned by the current AutoPas object (aka (...
Definition: ParticleBase.h:297
bool isOwned() const
Defines whether the particle is owned by the current AutoPas object (aka (MPI-)process)
Definition: ParticleBase.h:290
void addR(const std::array< double, 3 > &r)
Add a distance vector to the position of the particle.
Definition: ParticleBase.h:223
friend std::ostream & operator<<(std::ostream &os, const autopas::ParticleBase< T, P > &D)
Stream operator for instances of ParticleBase class.
void setID(idType id)
Set the id of the particle.
Definition: ParticleBase.h:155
virtual std::string toString() const
Creates a string containing all data of the particle.
Definition: ParticleBase.h:270
floatType ParticleSoAFloatPrecision
Floating Point Type used for this particle.
Definition: ParticleBase.h:325
bool isDummy() const
Returns whether the particle is a dummy particle.
Definition: ParticleBase.h:303
std::array< floatType, 3 > _r
Particle position as 3D coordinates.
Definition: ParticleBase.h:78
void setR(const std::array< double, 3 > &r)
Set the position of the particle.
Definition: ParticleBase.h:167
typename autopas::utils::SoAType< ParticleBase< floatType, idType > *, idType, floatType, floatType, floatType, floatType, floatType, floatType, OwnershipState >::Type SoAArraysType
The type for the soa storage.
Definition: ParticleBase.h:339
void setV(const std::array< double, 3 > &v)
Set the velocity of the particle.
Definition: ParticleBase.h:255
OwnershipState _ownershipState
Defines the state of the ownership of the particle.
Definition: ParticleBase.h:105
AttributeNames
Enums used as ids for accessing and creating a dynamically sized SoA.
Definition: ParticleBase.h:320
virtual ~ParticleBase()=default
Destructor of ParticleBase class.
void subF(const std::array< double, 3 > &f)
Substract a partial force from the force acting on the particle.
Definition: ParticleBase.h:140
bool setRDistanceCheck(const std::array< double, 3 > &r, double maxDistSquared)
Add a distance vector to the position of the particle and check if the distance between the old and n...
Definition: ParticleBase.h:205
OwnershipState getOwnershipState() const
Returns the particle's ownership state.
Definition: ParticleBase.h:309
idType _id
Particle id.
Definition: ParticleBase.h:100
constexpr std::tuple_element< attribute, SoAArraysType >::type::value_type get() const
Getter, which allows access to an attribute using the corresponding attribute name (defined in Attrib...
Definition: ParticleBase.h:358
std::array< floatType, 3 > _f
Force the particle experiences as 3D vector.
Definition: ParticleBase.h:95
void setOwnershipState(OwnershipState ownershipState)
Set the OwnershipState to the given value.
Definition: ParticleBase.h:315
void addV(const std::array< double, 3 > &v)
Add a vector to the current velocity of the particle.
Definition: ParticleBase.h:261
constexpr void set(typename std::tuple_element< attribute, SoAArraysType >::type::value_type value)
Setter, which allows set an attribute using the corresponding attribute name (defined in AttributeNam...
Definition: ParticleBase.h:387
idType getID() const
Get the id of the particle.
Definition: ParticleBase.h:149
bool addRDistanceCheck(const std::array< double, 3 > &r, double maxDistSquared)
Add a distance vector to the position of the particle and check if the distance between the old and n...
Definition: ParticleBase.h:239
void setF(const std::array< double, 3 > &f)
Set the force acting on the particle.
Definition: ParticleBase.h:125
const std::array< double, 3 > & getV() const
Get the velocity of the particle.
Definition: ParticleBase.h:249
constexpr std::tuple_element< attribute, SoAArraysType >::type::value_type get()
Non-const getter for the pointer of this object.
Definition: ParticleBase.h:347
std::array< floatType, 3 > _v
Particle velocity as 3D vector.
Definition: ParticleBase.h:90
idType ParticleIdType
Id Type used for this particle.
Definition: ParticleBase.h:330
const std::array< double, 3 > & getF() const
get the force acting on the particle
Definition: ParticleBase.h:119
ParticleBase(const std::array< double, 3 > &r, const std::array< double, 3 > &v, idType id, OwnershipState ownershipState=OwnershipState::owned)
Constructor of the Particle class.
Definition: ParticleBase.h:55
const std::array< double, 3 > & getR() const
Get the position of the particle.
Definition: ParticleBase.h:161
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
void markParticleAsDeleted(Particle_T &p)
Marks a particle as deleted.
Definition: markParticleAsDeleted.h:23
constexpr T dot(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Generates the dot product of two arrays.
Definition: ArrayMath.h:233
constexpr std::array< T, SIZE > sub(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Subtracts array b from array a and returns the result.
Definition: ArrayMath.h:45
void to_string(std::ostream &os, const Container &container, const std::string &delimiter, const std::array< std::string, 2 > &surround, Fun elemToString)
Generates a string representation of a container which fulfills the Container requirement (provide cb...
Definition: ArrayUtils.h:54
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
static std::ostream & operator<<(std::ostream &os, const OwnershipState &ownershipState)
Insertion operator for OwnershipState.
Definition: OwnershipState.h:65
OwnershipState
Enum that specifies the state of ownership.
Definition: OwnershipState.h:19
@ dummy
Dummy or deleted state, a particle with this state is not an actual particle!
@ halo
Halo state, a particle with this state is an actual particle, but not owned by the current AutoPas ob...
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...
Type
Enum describing all types that are allowed in a rule program.
Definition: RuleBasedProgramTree.h:10
Helper struct to get a the SoAType.
Definition: SoAType.h:23