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

Magnetic field composed of multiple magnetic sources. More...

#include <MagneticField.hpp>

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

Public Member Functions

 MagneticField ()=default
 
void AddSource (std::shared_ptr< MagneticSource > source)
 Add a single magnetic source to the field.
 
template<typename... Args>
void AddSources (Args &&... args)
 Add multiple magnetic sources.
 
Vector3< Quantity< Tesla > > GetValueAt (const Vector3< Quantity< Meter > > &point) const override
 Compute the total magnetic field at a point.
 
template<typename T , typename = std::enable_if<is_magnetic_source_v<T> >>
std::unordered_set< std::shared_ptr< T > > GetMagneticSources () const
 Get all sources of a specific type.
 
void Clear ()
 Remove all sources from the field.
 
void RemoveSource (const std::shared_ptr< MagneticSource > &source)
 Remove a specific source from the field.
 
template<typename... Args>
void RemoveSources (Args &&... args)
 Remove multiple sources.
 
std::unordered_set< std::shared_ptr< MagneticSource > > GetSources () const
 Get all sources currently in the field.
 
- Public Member Functions inherited from Phyth::Field< Vector3< Quantity< Tesla > > >
virtual ~Field ()=default
 
virtual void Update ()
 Update the field state (for time-varying fields)
 

Private Attributes

std::unordered_set< std::shared_ptr< MagneticSource > > sources_
 

Additional Inherited Members

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

Detailed Description

Magnetic field composed of multiple magnetic sources.

MagneticField aggregates multiple MagneticSource objects and computes the total magnetic field at any point by summing their contributions.

This class implements the Field interface, returning a Vector3 of Tesla quantities (magnetic flux density B).

Example: MagneticField field;

auto dipole = std::make_shared<MagneticDipole>(...); field.AddSource(dipole);

auto point = Vector3<Quantity<Meter>>(1.0_m, 0_m, 0_m); auto B = field.GetValueAt(point); // Total B-field at that point

Definition at line 29 of file MagneticField.hpp.

Constructor & Destructor Documentation

◆ MagneticField()

Phyth::Electromagnetics::MagneticField::MagneticField ( )
default

Member Function Documentation

◆ AddSource()

void Phyth::Electromagnetics::MagneticField::AddSource ( std::shared_ptr< MagneticSource >  source)
inline

Add a single magnetic 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 41 of file MagneticField.hpp.

◆ AddSources()

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

Add multiple magnetic sources.

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

Example: field.AddSources(dipole1, dipole2, coil);

Definition at line 57 of file MagneticField.hpp.

◆ Clear()

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

Remove all sources from the field.

Definition at line 102 of file MagneticField.hpp.

◆ GetMagneticSources()

template<typename T , typename = std::enable_if<is_magnetic_source_v<T> >>
std::unordered_set< std::shared_ptr< T > > Phyth::Electromagnetics::MagneticField::GetMagneticSources ( ) const
inline

Get all sources of a specific type.

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

Example: auto dipoles = field.GetMagneticSources<MagneticDipole>(); // Only returns sources that are MagneticDipole instances

Definition at line 91 of file MagneticField.hpp.

◆ GetSources()

std::unordered_set< std::shared_ptr< MagneticSource > > Phyth::Electromagnetics::MagneticField::GetSources ( ) const
inline

Get all sources currently in the field.

Definition at line 131 of file MagneticField.hpp.

◆ GetValueAt()

Vector3< Quantity< Tesla > > Phyth::Electromagnetics::MagneticField::GetValueAt ( const Vector3< Quantity< Meter > > &  point) const
inlineoverridevirtual

Compute the total magnetic field at a point.

Sums the magnetic field contribution from all sources.

Parameters
pointPosition in 3D space (meters)
Returns
Total magnetic flux density B (Tesla) as a Vector3

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

Definition at line 70 of file MagneticField.hpp.

◆ RemoveSource()

void Phyth::Electromagnetics::MagneticField::RemoveSource ( const std::shared_ptr< MagneticSource > &  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 113 of file MagneticField.hpp.

◆ RemoveSources()

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

Remove multiple sources.

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

Definition at line 126 of file MagneticField.hpp.

Member Data Documentation

◆ sources_

std::unordered_set<std::shared_ptr<MagneticSource> > Phyth::Electromagnetics::MagneticField::sources_
private

Definition at line 136 of file MagneticField.hpp.


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