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::CurrentSegment Class Reference

Magnetic field from a straight current-carrying wire segment. More...

#include <CurrentSegment.hpp>

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

Public Member Functions

 CurrentSegment (const Vector3< Quantity< Meter > > &start, const Vector3< Quantity< Meter > > &end, const Quantity< Ampere > &current)
 Construct a current segment from start to end.
 
Vector3< Quantity< Tesla > > GetMagneticFieldAt (const Vector3< Quantity< Meter > > &point) const override
 Compute the magnetic field at a point.
 
Quantity< Ampere > GetCurrent () const
 
Quantity< Meter > GetLength () const
 
const Vector3< Quantity< Meter > > & GetStart () const
 
const Vector3< Quantity< Meter > > & GetEnd () const
 
- Public Member Functions inherited from Phyth::Electromagnetics::MagneticSource
virtual ~MagneticSource ()=default
 

Private Member Functions

Vector3< Quantity< Tesla > > AnalyticSolution (const Vector3< Quantity< Meter > > &point) const
 Closed-form Biot-Savart solution for a finite straight wire.
 
bool IsPointOnWire (const Vector3< Quantity< Meter > > &point) const
 Check if a point lies on the wire segment.
 
Quantity< Meter > GetMinimumDistanceTo (const Vector3< Quantity< Meter > > &point) const
 Compute the minimum distance from a point to the wire segment.
 

Private Attributes

Vector3< Quantity< Meter > > start_
 
Vector3< Quantity< Meter > > end_
 
Vector3< Scalar > direction_
 
Quantity< Meter > length_
 
Quantity< Ampere > current_
 

Detailed Description

Magnetic field from a straight current-carrying wire segment.

CurrentSegment computes the magnetic field generated by a finite straight wire segment carrying a steady current, using the Biot-Savart law in closed form.

The magnetic field direction follows the right-hand rule around the current direction (from start to end).

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 current = 5.0_A;

CurrentSegment wire(start, end, current); auto point = Vector3<Quantity<Meter>>(0_m, 0.1_m, 0_m); auto B = wire.GetMagneticFieldAt(point);

Note: The field is singular on the wire axis. Points on the wire will throw an exception.

Definition at line 32 of file CurrentSegment.hpp.

Constructor & Destructor Documentation

◆ CurrentSegment()

Phyth::Electromagnetics::CurrentSegment::CurrentSegment ( const Vector3< Quantity< Meter > > &  start,
const Vector3< Quantity< Meter > > &  end,
const Quantity< Ampere > &  current 
)
inline

Construct a current segment from start to end.

Parameters
startStarting point of the segment (meters)
endEnding point of the segment (meters)
currentCurrent flowing from start to end (Amperes)
Exceptions
std::invalid_argumentIf segment length is zero

Definition at line 43 of file CurrentSegment.hpp.

Member Function Documentation

◆ AnalyticSolution()

Vector3< Quantity< Tesla > > Phyth::Electromagnetics::CurrentSegment::AnalyticSolution ( const Vector3< Quantity< Meter > > &  point) const
inlineprivate

Closed-form Biot-Savart solution for a finite straight wire.

The magnetic field at a point P is: B = (mu_0 * I / (4 * pi * rho)) * (z2/sqrt(rho^2 + z2^2) - z1/sqrt(rho^2 + z1^2)) * phi_hat

where:

  • rho is the perpendicular distance from P to the wire axis
  • z1, z2 are the distances from the projection point to the ends
  • phi_hat is the azimuthal unit vector around the wire
Parameters
pointPosition to evaluate the field
Returns
Magnetic field at that point

If rho is near zero (point on the wire axis), returns zero instead of throwing. The singularity is handled by the caller.

Definition at line 123 of file CurrentSegment.hpp.

◆ GetCurrent()

Quantity< Ampere > Phyth::Electromagnetics::CurrentSegment::GetCurrent ( ) const
inline
Returns
The current flowing through the segment (Amperes)

Definition at line 78 of file CurrentSegment.hpp.

◆ GetEnd()

const Vector3< Quantity< Meter > > & Phyth::Electromagnetics::CurrentSegment::GetEnd ( ) const
inline
Returns
The ending point of the segment

Definition at line 93 of file CurrentSegment.hpp.

◆ GetLength()

Quantity< Meter > Phyth::Electromagnetics::CurrentSegment::GetLength ( ) const
inline
Returns
The length of the segment (meters)

Definition at line 83 of file CurrentSegment.hpp.

◆ GetMagneticFieldAt()

Vector3< Quantity< Tesla > > Phyth::Electromagnetics::CurrentSegment::GetMagneticFieldAt ( const Vector3< Quantity< Meter > > &  point) const
inlineoverridevirtual

Compute the magnetic field at a point.

Parameters
pointPosition in 3D space (meters)
Returns
Magnetic flux density B (Tesla) as a Vector3
Exceptions
std::runtime_errorIf the point lies on the wire axis

The field is computed using the Biot-Savart law closed-form solution for a finite straight wire.

Implements Phyth::Electromagnetics::MagneticSource.

Definition at line 69 of file CurrentSegment.hpp.

◆ GetMinimumDistanceTo()

Quantity< Meter > Phyth::Electromagnetics::CurrentSegment::GetMinimumDistanceTo ( const Vector3< Quantity< Meter > > &  point) const
inlineprivate

Compute the minimum distance from a point to the wire segment.

Parameters
pointPosition to compute distance from
Returns
Minimum distance to the segment (meters)

This is used by MagneticSource interface for regularization.

Definition at line 189 of file CurrentSegment.hpp.

◆ GetStart()

const Vector3< Quantity< Meter > > & Phyth::Electromagnetics::CurrentSegment::GetStart ( ) const
inline
Returns
The starting point of the segment

Definition at line 88 of file CurrentSegment.hpp.

◆ IsPointOnWire()

bool Phyth::Electromagnetics::CurrentSegment::IsPointOnWire ( const Vector3< Quantity< Meter > > &  point) const
inlineprivate

Check if a point lies on the wire segment.

A point is considered "on the wire" if it is within tolerance of the wire axis and its projection falls within the segment bounds.

Parameters
pointPosition to check
Returns
true if the point is on the wire segment

Definition at line 162 of file CurrentSegment.hpp.

Member Data Documentation

◆ current_

Quantity<Ampere> Phyth::Electromagnetics::CurrentSegment::current_
private

Definition at line 102 of file CurrentSegment.hpp.

◆ direction_

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

Definition at line 100 of file CurrentSegment.hpp.

◆ end_

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

Definition at line 99 of file CurrentSegment.hpp.

◆ length_

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

Definition at line 101 of file CurrentSegment.hpp.

◆ start_

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

Definition at line 98 of file CurrentSegment.hpp.


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