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>
135 [[nodiscard]]
const std::array<double, 3> &
getF()
const {
return _f; }
141 void setF(
const std::array<double, 3> &f) {
_f = f; }
147 void addF(
const std::array<double, 3> &f) {
148 using namespace autopas::utils::ArrayMath::literals;
156 void subF(
const std::array<double, 3> &f) {
157 using namespace autopas::utils::ArrayMath::literals;
177 [[nodiscard]]
const std::array<double, 3> &
getR()
const {
return _r; }
183 void setR(
const std::array<double, 3> &r) {
_r = r; }
185#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
190 [[nodiscard]]
const std::array<double, 3> &getRAtRebuild()
const {
return _rAtRebuild; }
195 void setRAtRebuild(
const std::array<double, 3> &r) { _rAtRebuild = r; }
200 void resetRAtRebuild() { this->setRAtRebuild(
_r); }
207 const std::array<double, 3> calculateDisplacementSinceRebuild()
const {
222 using namespace autopas::utils::ArrayMath::literals;
223 const auto distanceVec = r -
_r;
226 const bool distanceIsFine =
227 distanceSquared < maxDistSquared or autopas::utils::Math::isNearAbs(maxDistSquared, 0., 1e-12);
228 if (not distanceIsFine) {
229 AutoPasLog(WARN,
"Particle {}: Distance between old and new position is larger than expected: {} > {}",
_id,
230 distanceSquared, maxDistSquared);
232 return distanceIsFine;
239 void addR(
const std::array<double, 3> &r) {
240 using namespace autopas::utils::ArrayMath::literals;
256 using namespace autopas::utils::ArrayMath::literals;
257 const auto newR =
_r + r;
265 [[nodiscard]]
const std::array<double, 3> &
getV()
const {
return _v; }
271 void setV(
const std::array<double, 3> &v) {
_v = v; }
277 void addV(
const std::array<double, 3> &v) {
278 using namespace autopas::utils::ArrayMath::literals;
286 [[nodiscard]]
virtual std::string
toString()
const {
287 std::ostringstream text;
297 <<
"\nOwnershipState : "
336 enum AttributeNames :
int { ptr, id, posX, posY, posZ, forceX, forceY, forceZ, ownershipState };
354 floatType , floatType , floatType , floatType ,
362 template <AttributeNames attribute, std::enable_if_t<attribute == AttributeNames::ptr,
bool> = true>
363 constexpr typename std::tuple_element<attribute, SoAArraysType>::type::value_type
get() {
373 template <AttributeNames attribute, std::enable_if_t<attribute != AttributeNames::ptr,
bool> = true>
374 constexpr typename std::tuple_element<attribute, SoAArraysType>::type::value_type
get()
const {
375 if constexpr (attribute == AttributeNames::id) {
377 }
else if constexpr (attribute == AttributeNames::posX) {
379 }
else if constexpr (attribute == AttributeNames::posY) {
381 }
else if constexpr (attribute == AttributeNames::posZ) {
383 }
else if constexpr (attribute == AttributeNames::forceX) {
385 }
else if constexpr (attribute == AttributeNames::forceY) {
387 }
else if constexpr (attribute == AttributeNames::forceZ) {
389 }
else if constexpr (attribute == AttributeNames::ownershipState) {
402 template <AttributeNames attribute>
403 constexpr void set(
typename std::tuple_element<attribute, SoAArraysType>::type::value_type value) {
404 if constexpr (attribute == AttributeNames::id) {
406 }
else if constexpr (attribute == AttributeNames::posX) {
408 }
else if constexpr (attribute == AttributeNames::posY) {
410 }
else if constexpr (attribute == AttributeNames::posZ) {
412 }
else if constexpr (attribute == AttributeNames::forceX) {
414 }
else if constexpr (attribute == AttributeNames::forceY) {
416 }
else if constexpr (attribute == AttributeNames::forceZ) {
418 }
else if constexpr (attribute == AttributeNames::ownershipState) {
419 this->_ownershipState = value;
432 void markAsDeleted() {
453template <
typename floatType,
typename idType>
455 using utils::ArrayUtils::operator<<;
457 <<
"\nID : " << particle.
_id <<
"\nPosition: " << particle.
_r <<
"\nVelocity: " << particle.
_v
458 <<
"\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:147
bool isHalo() const
Defines whether the particle is a halo particle, i.e., not owned by the current AutoPas object (aka (...
Definition: ParticleBase.h:313
bool isOwned() const
Defines whether the particle is owned by the current AutoPas object (aka (MPI-)process)
Definition: ParticleBase.h:306
void addR(const std::array< double, 3 > &r)
Add a distance vector to the position of the particle.
Definition: ParticleBase.h:239
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:171
virtual std::string toString() const
Creates a string containing all data of the particle.
Definition: ParticleBase.h:286
floatType ParticleSoAFloatPrecision
Floating Point Type used for this particle.
Definition: ParticleBase.h:341
bool isDummy() const
Returns whether the particle is a dummy particle.
Definition: ParticleBase.h:319
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:183
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:355
void setV(const std::array< double, 3 > &v)
Set the velocity of the particle.
Definition: ParticleBase.h:271
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:336
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:156
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:221
OwnershipState getOwnershipState() const
Returns the particle's ownership state.
Definition: ParticleBase.h:325
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:374
bool operator==(const ParticleBase &rhs) const
Equality operator for ParticleBase class.
Definition: ParticleBase.h:120
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:331
void addV(const std::array< double, 3 > &v)
Add a vector to the current velocity of the particle.
Definition: ParticleBase.h:277
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:403
idType getID() const
Get the id of the particle.
Definition: ParticleBase.h:165
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:255
void setF(const std::array< double, 3 > &f)
Set the force acting on the particle.
Definition: ParticleBase.h:141
const std::array< double, 3 > & getV() const
Get the velocity of the particle.
Definition: ParticleBase.h:265
bool operator!=(const ParticleBase &rhs) const
Not-Equals operator for ParticleBase class.
Definition: ParticleBase.h:129
constexpr std::tuple_element< attribute, SoAArraysType >::type::value_type get()
Non-const getter for the pointer of this object.
Definition: ParticleBase.h:363
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:346
const std::array< double, 3 > & getF() const
get the force acting on the particle
Definition: ParticleBase.h:135
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:177
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:102
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