1#ifndef PHYTH_POINT_CHARGE_HPP
2#define PHYTH_POINT_CHARGE_HPP
98 throw std::runtime_error(
"PointCharge: field diverges at charge location");
107 }
catch (std::runtime_error &) {
122 const auto hat_R =
R.Normalized();
159 }
catch (std::runtime_error &) {
164 const auto hat_R =
R.Normalized();
184 const auto dist =
r.Length();
187 throw std::runtime_error(
"PointCharge: potential diverges at charge location");
197 }
catch (std::runtime_error &) {
205 const auto R =
R_vec.Length();
212 throw std::runtime_error(
"PointCharge: line-of-sight aligns with charge velocity at light speed");
275 Particle::Integrate();
347 throw std::runtime_error(
348 "PointCharge: signal has not reached observation point or no solution in interval");
388 throw std::runtime_error(
389 "PointCharge: signal has not reached observation point or no solution in interval");
409 throw std::runtime_error(
"PointCharge: bisection failed to converge");
Abstract base class for all charge distributions.
Abstract base class for all magnetic field sources.
Point charge with full electromagnetic field and dynamics.
void ApplyElectricFieldForce(const Vector3< Quantity< NewtonPerCoulomb > > &field)
Apply force from an electric field: F = q * E.
TimeHistory< Vector3< Quantity< MeterPerSecond > > > velocity_history_
Vector3< Quantity< Meter > > GetPositionAtOffset(const Quantity< Second > &offset) const
Get position at a time offset in the past.
PointCharge(const Quantity< Kilogram > mass, const Vector3< Quantity< Meter > > &position, const Quantity< Coulomb > charge_value)
Construct a point charge.
Quantity< Volt > GetElectricPotentialAt(const Vector3< Quantity< Meter > > &point) const override
Get the electric potential at a point.
TimeHistory< Vector3< Quantity< Meter > > > position_history_
Vector3< Quantity< MeterPerSecondSquared > > GetAccelerationAtOffset(const Quantity< Second > &offset) const
Get acceleration at a time offset in the past.
Quantity< Meter > GetMinimumDistanceTo(const Vector3< Quantity< Meter > > &point) const override
Get the minimum distance from a point to the charge location.
Quantity< Second > SolveRetardedTimeOffset(const Vector3< Quantity< Meter > > &point) const
Solve for the retarded time offset using Newton's method.
Vector3< Quantity< Tesla > > GetMagneticFieldAt(const Vector3< Quantity< Meter > > &point) const override
Get the magnetic field at a point using Liénard-Wiechert formulas.
Vector3< Quantity< NewtonPerCoulomb > > GetElectricFieldAt(const Vector3< Quantity< Meter > > &point) const override
Get the electric field at a point using Liénard-Wiechert formulas.
Vector3< Quantity< MeterPerSecond > > GetVelocityAtOffset(const Quantity< Second > &offset) const
Get velocity at a time offset in the past.
TimeHistory< Vector3< Quantity< MeterPerSecondSquared > > > acceleration_history_
Quantity< Coulomb > GetTotalChargeValue() const override
Get the total charge value.
void ApplyLorentzForce(const Vector3< Quantity< NewtonPerCoulomb > > &electric_field, const Vector3< Quantity< Tesla > > &magnetic_field)
Apply the full Lorentz force: F = q * (E + v cross B)
Quantity< Second > SolveRetardedTimeOffsetBisection(const Vector3< Quantity< Meter > > &point, Quantity< Second > dt_low, Quantity< Second > dt_high) const
Solve for the retarded time offset using bisection method.
void SetComputeForcesFunction(const std::function< void(PointCharge *)> &func) noexcept
Set the force computation function.
Quantity< Coulomb > charge_value_
void ApplyMagneticFieldForce(const Vector3< Quantity< Tesla > > &field)
Apply force from a magnetic field: F = q * v cross B.
void Integrate() noexcept override
Integrate dynamics using velocity Verlet.
Physical particle with mass, position, velocity, and force accumulation.
Quantity< Kilogram > mass_
Vector3< Quantity< MeterPerSecond > > velocity_
Vector3< Quantity< Meter > > position_
Vector3< Quantity< Newton > > external_force_
Particle(const Quantity< Kilogram > &mass, const Vector3< Quantity< Meter > > &position) noexcept
Construct a particle with mass and initial position.
void ApplyForce(const Vector3< Quantity< Newton > > &force)
Accumulate an external force on the particle.
Time-based history with linear interpolation.
bool isnan(Quantity< UnitT > x)
Determine whether a quantity is nan.
auto square(Quantity< UnitT > q)
Square of a quantity.
auto sqrt(Quantity< UnitT > q)
Square root of a quantity.
auto cube(Quantity< UnitT > q)
Cube of a quantity.
auto abs(Quantity< UnitT > q)
Absolute value of a quantity.
Dimension< std::ratio< 1 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 > > Length
Physical quantity with a value and a compile-time unit.
3D vector with Quantity components
Vector3< Scalar > Normalized() const
Normalized vector (unit vector in the same direction)