Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Phyth::Electromagnetics::LineCharge Class Reference

Uniform line charge along a straight segment. More...

#include <LineCharge.hpp>

Inheritance diagram for Phyth::Electromagnetics::LineCharge:
Inheritance graph
[legend]
Collaboration diagram for Phyth::Electromagnetics::LineCharge:
Collaboration graph
[legend]

Public Member Functions

 LineCharge (const Vector3< Quantity< Meter > > &start, const Vector3< Quantity< Meter > > &end, const Quantity< CoulombPerMeter > lambda)
 Construct a uniform line charge.
 
Vector3< Quantity< NewtonPerCoulomb > > GetElectricFieldAt (const Vector3< Quantity< Meter > > &point) const override
 Compute the electric field at a point using numerical integration.
 
Quantity< Volt > GetElectricPotentialAt (const Vector3< Quantity< Meter > > &point) const override
 Compute the electric potential at a point using analytic formula.
 
Quantity< Coulomb > GetTotalChargeValue () const override
 Get the total charge of the line.
 
Quantity< Meter > GetMinimumDistanceTo (const Vector3< Quantity< Meter > > &point) const override
 Get the minimum distance from a point to the line segment.
 
- Public Member Functions inherited from Phyth::Electromagnetics::ChargeSource
virtual ~ChargeSource ()=default
 
virtual Quantity< CoulombPerCubicMeter > GetChargeDensityAt (const Vector3< Quantity< Meter > > &point) const
 Get the charge density at a point.
 

Private Member Functions

Quantity< Volt > AnalyticPotential (const Vector3< Quantity< Meter > > &point) const
 Analytic potential for finite line charge.
 
Vector3< Quantity< NewtonPerCoulomb > > NumericalIntegrateField (const Vector3< Quantity< Meter > > &point, const int segments) const
 Numerical integration of electric field along the line.
 

Private Attributes

Vector3< Quantity< Meter > > start_
 
Vector3< Quantity< Meter > > end_
 
Vector3< Scalar > direction_
 
Quantity< Meter > length_
 
Quantity< CoulombPerMeter > lambda_
 

Detailed Description

Uniform line charge along a straight segment.

LineCharge represents a straight segment with uniform linear charge density lambda (C/m). The electric field is computed by numerical integration (64 segments by default), while the potential uses an analytic closed-form solution.

Example: auto start = Vector3<Quantity<Meter>>(-1.0_m, 0_m, 0_m); auto end = Vector3<Quantity<Meter>>(1.0_m, 0_m, 0_m); auto lambda = 1.0e-9_C/m;

LineCharge line(start, end, lambda); auto point = Vector3<Quantity<Meter>>(0_m, 0.1_m, 0_m); auto E = line.GetElectricFieldAt(point); auto V = line.GetElectricPotentialAt(point);

Note: The field and potential diverge on the line charge itself. Querying at points on the line throws an exception.

Definition at line 28 of file LineCharge.hpp.

Constructor & Destructor Documentation

◆ LineCharge()

Phyth::Electromagnetics::LineCharge::LineCharge ( const Vector3< Quantity< Meter > > &  start,
const Vector3< Quantity< Meter > > &  end,
const Quantity< CoulombPerMeter >  lambda 
)
inline

Construct a uniform line charge.

Parameters
startStarting point of the line (meters)
endEnding point of the line (meters)
lambdaLinear charge density (C/m)

Definition at line 37 of file LineCharge.hpp.

Member Function Documentation

◆ AnalyticPotential()

Quantity< Volt > Phyth::Electromagnetics::LineCharge::AnalyticPotential ( const Vector3< Quantity< Meter > > &  point) const
inlineprivate

Analytic potential for finite line charge.

The formula is: V = k_E * lambda * ln((r1 + r2 + L) / (r1 + r2 - L))

where r1 = |point - start|, r2 = |point - end|, L = segment length.

Parameters
pointPosition to evaluate the potential
Returns
Electric potential V (Volts)
Exceptions
std::runtime_errorIf point is on the line charge

Note: The denominator (r1 + r2 - L) approaches zero when the point lies on the line segment, causing a logarithmic divergence.

Definition at line 122 of file LineCharge.hpp.

◆ GetElectricFieldAt()

Vector3< Quantity< NewtonPerCoulomb > > Phyth::Electromagnetics::LineCharge::GetElectricFieldAt ( const Vector3< Quantity< Meter > > &  point) const
inlineoverridevirtual

Compute the electric field at a point using numerical integration.

Parameters
pointPosition to evaluate the field (meters)
Returns
Electric field intensity E (N/C)

The field is integrated using the midpoint rule with 64 segments. Points on the line are skipped (their contribution is ignored).

Implements Phyth::Electromagnetics::ChargeSource.

Definition at line 55 of file LineCharge.hpp.

◆ GetElectricPotentialAt()

Quantity< Volt > Phyth::Electromagnetics::LineCharge::GetElectricPotentialAt ( const Vector3< Quantity< Meter > > &  point) const
inlineoverridevirtual

Compute the electric potential at a point using analytic formula.

The potential for a finite line charge is: V = k_E * lambda * ln((r1 + r2 + L) / (r1 + r2 - L)) where r1, r2 are distances to the endpoints and L is the segment length.

Parameters
pointPosition to evaluate the potential (meters)
Returns
Electric potential V (Volts)
Exceptions
std::runtime_errorIf point is on the line charge

Implements Phyth::Electromagnetics::ChargeSource.

Definition at line 72 of file LineCharge.hpp.

◆ GetMinimumDistanceTo()

Quantity< Meter > Phyth::Electromagnetics::LineCharge::GetMinimumDistanceTo ( const Vector3< Quantity< Meter > > &  point) const
inlineoverridevirtual

Get the minimum distance from a point to the line segment.

Parameters
pointPosition to compute distance from
Returns
Distance to the closest point on the segment (meters)

Implements Phyth::Electromagnetics::ChargeSource.

Definition at line 92 of file LineCharge.hpp.

◆ GetTotalChargeValue()

Quantity< Coulomb > Phyth::Electromagnetics::LineCharge::GetTotalChargeValue ( ) const
inlineoverridevirtual

Get the total charge of the line.

Returns
lambda * length (Coulombs)

Implements Phyth::Electromagnetics::ChargeSource.

Definition at line 81 of file LineCharge.hpp.

◆ NumericalIntegrateField()

Vector3< Quantity< NewtonPerCoulomb > > Phyth::Electromagnetics::LineCharge::NumericalIntegrateField ( const Vector3< Quantity< Meter > > &  point,
const int  segments 
) const
inlineprivate

Numerical integration of electric field along the line.

Uses the midpoint rule with the specified number of segments. Each segment contributes dE = k_E * dq / r^2 * hat_r.

Parameters
pointEvaluation point
segmentsNumber of line segments for integration
Returns
Electric field intensity E (N/C)

Definition at line 151 of file LineCharge.hpp.

Member Data Documentation

◆ direction_

Vector3<Scalar> Phyth::Electromagnetics::LineCharge::direction_
private

Definition at line 101 of file LineCharge.hpp.

◆ end_

Vector3<Quantity<Meter> > Phyth::Electromagnetics::LineCharge::end_
private

Definition at line 100 of file LineCharge.hpp.

◆ lambda_

Quantity<CoulombPerMeter> Phyth::Electromagnetics::LineCharge::lambda_
private

Definition at line 103 of file LineCharge.hpp.

◆ length_

Quantity<Meter> Phyth::Electromagnetics::LineCharge::length_
private

Definition at line 102 of file LineCharge.hpp.

◆ start_

Vector3<Quantity<Meter> > Phyth::Electromagnetics::LineCharge::start_
private

Definition at line 100 of file LineCharge.hpp.


The documentation for this class was generated from the following file: