1#ifndef PHYTH_PARTICLE_H
2#define PHYTH_PARTICLE_H
192 os <<
"Particle{pos=" <<
p.position_ <<
", mass=" <<
p.mass_ <<
"}";
Physical particle with mass, position, velocity, and force accumulation.
constexpr const auto & GetVelocity() const noexcept
Quantity< Kilogram > mass_
Vector3< Quantity< MeterPerSecond > > velocity_
Vector3< Quantity< Meter > > position_
Quantity< Joule > GetPotentialEnergy(const Quantity< Meter > y_ref=0) const
Compute gravitational potential energy relative to a reference height.
constexpr bool IsFixed() const noexcept
void SetExternalForce(const Vector3< Quantity< Newton > > &external_force) noexcept
Manually set the external force (N)
Quantity< Joule > GetKineticEnergy() const noexcept
Compute kinetic energy.
Vector3< Quantity< Newton > > external_force_
void SetMass(const Quantity< Kilogram > &mass) noexcept
Set the particle mass (kg)
void SetPosition(const Vector3< Quantity< Meter > > &position) noexcept
Set the particle position (m)
constexpr const auto & GetPosition() const noexcept
void SetVelocity(const Vector3< Quantity< MeterPerSecond > > &velocity) noexcept
Set the particle velocity (m/s)
void SetFixed(const bool fixed) noexcept
Set whether the particle is fixed (immovable)
Particle(const Quantity< Kilogram > &mass, const Vector3< Quantity< Meter > > &position) noexcept
Construct a particle with mass and initial position.
friend std::ostream & operator<<(std::ostream &os, const Particle &p)
Stream insertion operator for Particle.
std::function< void(Particle *)> compute_forces_func_
virtual void Integrate() noexcept
Integrate equations of motion using velocity Verlet.
void ApplyForce(const Vector3< Quantity< Newton > > &force)
Accumulate an external force on the particle.
Quantity< Joule > GetTotalEnergy(const Quantity< Meter > y_ref=0) const noexcept
Compute total mechanical energy.
virtual ~Particle()=default
constexpr const auto & GetExternalForce() const noexcept
void SetComputeForcesFunction(const std::function< void(Particle *)> &func) noexcept
Set the user-defined force computation function.
constexpr auto GetMass() const noexcept
Physical quantity with a value and a compile-time unit.
3D vector with Quantity components