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

Electric field composed of multiple charge sources. More...

#include <ElectricField.hpp>

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

Public Member Functions

 ElectricField ()=default
 
void AddSource (std::shared_ptr< ChargeSource > source)
 Add a single charge source to the field.
 
template<typename... Args>
void AddSources (Args &&... args)
 Add multiple charge sources.
 
Vector3< Quantity< NewtonPerCoulomb > > GetValueAt (const Vector3< Quantity< Meter > > &point) const override
 Compute the total electric field at a point.
 
Quantity< Volt > GetElectricPotential (const Vector3< Quantity< Meter > > &point) const
 Compute the total electric potential at a point.
 
Quantity< CoulombPerCubicMeter > GetChargeDensityAt (const Vector3< Quantity< Meter > > &point) const
 Compute the total charge density at a point.
 
template<typename T , typename = std::enable_if<is_charge_source_v<T> >>
std::unordered_set< std::shared_ptr< T > > GetChargeSources () const
 Get all sources of a specific charge source type.
 
Quantity< Coulomb > GetTotalChargeValue () const
 Get the total charge of all sources combined.
 
void Clear ()
 Remove all sources from the field.
 
void RemoveSource (const std::shared_ptr< ChargeSource > &source)
 Remove a specific source from the field.
 
template<typename... Args>
void RemoveSources (Args &&... args)
 Remove multiple sources.
 
std::unordered_set< std::shared_ptr< ChargeSource > > GetSources () const
 Get all sources currently in the field.
 
std::string toString () const
 Convert the field to a string representation.
 
- Public Member Functions inherited from Phyth::Field< Vector3< Quantity< NewtonPerCoulomb > > >
virtual ~Field ()=default
 
virtual void Update ()
 Update the field state (for time-varying fields)
 

Private Attributes

std::unordered_set< std::shared_ptr< ChargeSource > > sources_
 

Additional Inherited Members

- Public Types inherited from Phyth::Field< Vector3< Quantity< NewtonPerCoulomb > > >
using value_type = Vector3< Quantity< NewtonPerCoulomb > >
 

Detailed Description

Electric field composed of multiple charge sources.

ElectricField aggregates multiple ChargeSource objects and computes the total electric field, potential, and charge density at any point by summing their contributions.

This class implements the Field interface, returning a Vector3 of NewtonPerCoulomb quantities (electric field intensity E).

Example: ElectricField field;

auto point_charge = std::make_shared<PointCharge>(1.0_C, Vector3{0_m, 0_m, 0_m}); field.AddSource(point_charge);

auto point = Vector3<Quantity<Meter>>(1.0_m, 0_m, 0_m); auto E = field.GetValueAt(point); // Total E-field auto V = field.GetElectricPotential(point); // Total potential

Definition at line 31 of file ElectricField.hpp.

Constructor & Destructor Documentation

◆ ElectricField()

Phyth::Electromagnetics::ElectricField::ElectricField ( )
default

Member Function Documentation

◆ AddSource()

void Phyth::Electromagnetics::ElectricField::AddSource ( std::shared_ptr< ChargeSource >  source)
inline

Add a single charge source to the field.

Parameters
sourceShared pointer to the source to add

Duplicate sources are automatically handled by the unordered_set. Null pointers are silently ignored.

Definition at line 43 of file ElectricField.hpp.

◆ AddSources()

template<typename... Args>
void Phyth::Electromagnetics::ElectricField::AddSources ( Args &&...  args)
inline

Add multiple charge sources.

Template Parameters
ArgsParameter pack of shared_ptr<ChargeSource>
Parameters
argsThe sources to add

Example: field.AddSources(charge1, charge2, dipole);

Definition at line 59 of file ElectricField.hpp.

◆ Clear()

void Phyth::Electromagnetics::ElectricField::Clear ( )
inline

Remove all sources from the field.

Definition at line 152 of file ElectricField.hpp.

◆ GetChargeDensityAt()

Quantity< CoulombPerCubicMeter > Phyth::Electromagnetics::ElectricField::GetChargeDensityAt ( const Vector3< Quantity< Meter > > &  point) const
inline

Compute the total charge density at a point.

Sums the charge density contribution from all sources.

Parameters
pointPosition in 3D space (meters)
Returns
Total charge density (C/m^3)

Definition at line 106 of file ElectricField.hpp.

◆ GetChargeSources()

template<typename T , typename = std::enable_if<is_charge_source_v<T> >>
std::unordered_set< std::shared_ptr< T > > Phyth::Electromagnetics::ElectricField::GetChargeSources ( ) const
inline

Get all sources of a specific charge source type.

Template Parameters
TThe charge source type to filter by (must satisfy is_charge_source_v)
Returns
A set of shared_ptr<T> containing all sources that are of type T

Example: auto point_charges = field.GetChargeSources<PointCharge>(); // Only returns sources that are PointCharge instances

Definition at line 126 of file ElectricField.hpp.

◆ GetElectricPotential()

Quantity< Volt > Phyth::Electromagnetics::ElectricField::GetElectricPotential ( const Vector3< Quantity< Meter > > &  point) const
inline

Compute the total electric potential at a point.

Sums the electric potential contribution from all sources.

Parameters
pointPosition in 3D space (meters)
Returns
Total electric potential V (Volts)

Definition at line 89 of file ElectricField.hpp.

◆ GetSources()

std::unordered_set< std::shared_ptr< ChargeSource > > Phyth::Electromagnetics::ElectricField::GetSources ( ) const
inline

Get all sources currently in the field.

Definition at line 181 of file ElectricField.hpp.

◆ GetTotalChargeValue()

Quantity< Coulomb > Phyth::Electromagnetics::ElectricField::GetTotalChargeValue ( ) const
inline

Get the total charge of all sources combined.

Sums the total charge value from each source.

Returns
Total charge (Coulombs)

Definition at line 143 of file ElectricField.hpp.

◆ GetValueAt()

Vector3< Quantity< NewtonPerCoulomb > > Phyth::Electromagnetics::ElectricField::GetValueAt ( const Vector3< Quantity< Meter > > &  point) const
inlineoverridevirtual

Compute the total electric field at a point.

Sums the electric field contribution from all sources.

Parameters
pointPosition in 3D space (meters)
Returns
Total electric field intensity E (N/C) as a Vector3

Implements Phyth::Field< Vector3< Quantity< NewtonPerCoulomb > > >.

Definition at line 72 of file ElectricField.hpp.

◆ RemoveSource()

void Phyth::Electromagnetics::ElectricField::RemoveSource ( const std::shared_ptr< ChargeSource > &  source)
inline

Remove a specific source from the field.

Parameters
sourceShared pointer to the source to remove

If the source is not present, this function does nothing.

Definition at line 163 of file ElectricField.hpp.

◆ RemoveSources()

template<typename... Args>
void Phyth::Electromagnetics::ElectricField::RemoveSources ( Args &&...  args)
inline

Remove multiple sources.

Template Parameters
ArgsParameter pack of shared_ptr<ChargeSource>
Parameters
argsThe sources to remove

Definition at line 176 of file ElectricField.hpp.

◆ toString()

std::string Phyth::Electromagnetics::ElectricField::toString ( ) const
inline

Convert the field to a string representation.

Returns
String containing the total charge value

Definition at line 190 of file ElectricField.hpp.

Member Data Documentation

◆ sources_

std::unordered_set<std::shared_ptr<ChargeSource> > Phyth::Electromagnetics::ElectricField::sources_
private

Definition at line 197 of file ElectricField.hpp.


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