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

Uniform volume charge distribution in a rectangular box. More...

#include <VolumeSource.hpp>

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

Public Member Functions

 VolumeCharge (const Vector3< Quantity< Meter > > &center, const Vector3< Scalar > &axis_x, const Vector3< Scalar > &axis_y, const Vector3< Scalar > &axis_z, const Quantity< Meter > size_x, const Quantity< Meter > size_y, const Quantity< Meter > size_z, const Quantity< CoulombPerCubicMeter > rho)
 Construct a rectangular volume 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 numerical integration.
 
Quantity< Coulomb > GetTotalChargeValue () const override
 Get the total charge of the volume.
 
Quantity< Meter > GetMinimumDistanceTo (const Vector3< Quantity< Meter > > &point) const override
 Get the minimum distance from a point to the rectangular box.
 
Quantity< CoulombPerCubicMeter > GetChargeDensityAt (const Vector3< Quantity< Meter > > &point) const override
 Get the charge density at a point.
 
- Public Member Functions inherited from Phyth::Electromagnetics::ChargeSource
virtual ~ChargeSource ()=default
 

Private Member Functions

Vector3< Quantity< NewtonPerCoulomb > > NumericalIntegrateField (const Vector3< Quantity< Meter > > &point, const int nx, const int ny, const int nz) const
 Numerical integration of electric field over the volume.
 
Quantity< Volt > NumericalIntegratePotential (const Vector3< Quantity< Meter > > &point, const int nx, const int ny, const int nz) const
 Numerical integration of electric potential over the volume.
 

Private Attributes

Vector3< Quantity< Meter > > center_
 
Vector3< Scalar > axis_x_
 
Vector3< Scalar > axis_y_
 
Vector3< Scalar > axis_z_
 
Quantity< Meter > size_x_
 
Quantity< Meter > size_y_
 
Quantity< Meter > size_z_
 
Quantity< CoulombPerCubicMeter > rho_
 

Detailed Description

Uniform volume charge distribution in a rectangular box.

VolumeCharge represents a rectangular box with uniform volume charge density rho (C/m^3). The box is defined by its center, three orthogonal axes, and dimensions along each axis.

Field and potential are computed by numerical integration over the volume using the midpoint rule. Default resolution is 16x16x16 segments.

Example: auto center = Vector3<Quantity<Meter>>(0_m, 0_m, 0_m); auto ex = Vector3<Scalar>(1, 0, 0); auto ey = Vector3<Scalar>(0, 1, 0); auto ez = Vector3<Scalar>(0, 0, 1); auto rho = 1.0e-6_C/m3;

VolumeCharge volume(center, ex, ey, ez, 1.0_m, 1.0_m, 1.0_m, rho); auto point = Vector3<Quantity<Meter>>(0_m, 0_m, 0.5_m); auto E = volume.GetElectricFieldAt(point); auto V = volume.GetElectricPotentialAt(point);

Note: The field is evaluated numerically, so accuracy depends on the integration resolution. Higher resolution improves accuracy but increases computation time.

Definition at line 36 of file VolumeSource.hpp.

Constructor & Destructor Documentation

◆ VolumeCharge()

Phyth::Electromagnetics::VolumeCharge::VolumeCharge ( const Vector3< Quantity< Meter > > &  center,
const Vector3< Scalar > &  axis_x,
const Vector3< Scalar > &  axis_y,
const Vector3< Scalar > &  axis_z,
const Quantity< Meter >  size_x,
const Quantity< Meter >  size_y,
const Quantity< Meter >  size_z,
const Quantity< CoulombPerCubicMeter >  rho 
)
inline

Construct a rectangular volume charge.

Parameters
centerCenter of the box (meters)
axis_xDirection of the x-axis (must be unit vector)
axis_yDirection of the y-axis (must be unit vector)
axis_zDirection of the z-axis (must be unit vector)
size_xLength along axis_x (meters)
size_yLength along axis_y (meters)
size_zLength along axis_z (meters)
rhoVolume charge density (C/m^3)

The three axes must be mutually orthogonal. This is checked at runtime with asserts.

Definition at line 53 of file VolumeSource.hpp.

Member Function Documentation

◆ GetChargeDensityAt()

Quantity< CoulombPerCubicMeter > Phyth::Electromagnetics::VolumeCharge::GetChargeDensityAt ( const Vector3< Quantity< Meter > > &  point) const
inlineoverridevirtual

Get the charge density at a point.

Parameters
pointPosition to evaluate (meters)
Returns
rho if point is inside the box, 0 otherwise

This overrides the default implementation to return the actual charge density for points inside the volume.

Reimplemented from Phyth::Electromagnetics::ChargeSource.

Definition at line 141 of file VolumeSource.hpp.

◆ GetElectricFieldAt()

Vector3< Quantity< NewtonPerCoulomb > > Phyth::Electromagnetics::VolumeCharge::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 16x16x16 segments. Points inside the volume are skipped (their contribution is ignored).

Implements Phyth::Electromagnetics::ChargeSource.

Definition at line 79 of file VolumeSource.hpp.

◆ GetElectricPotentialAt()

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

Compute the electric potential at a point using numerical integration.

Parameters
pointPosition to evaluate the potential (meters)
Returns
Electric potential V (Volts)

The potential is integrated using the midpoint rule with 16x16x16 segments. Points inside the volume are skipped (their contribution is ignored).

Implements Phyth::Electromagnetics::ChargeSource.

Definition at line 93 of file VolumeSource.hpp.

◆ GetMinimumDistanceTo()

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

Get the minimum distance from a point to the rectangular box.

Parameters
pointPosition to compute distance from
Returns
Distance to the closest point on the box surface or interior (meters)

The closest point is found by projecting the point onto the box axes and clamping to the box bounds. If the point is inside the box, the minimum distance is 0.

Implements Phyth::Electromagnetics::ChargeSource.

Definition at line 117 of file VolumeSource.hpp.

◆ GetTotalChargeValue()

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

Get the total charge of the volume.

Returns
rho * size_x * size_y * size_z (Coulombs)

Implements Phyth::Electromagnetics::ChargeSource.

Definition at line 102 of file VolumeSource.hpp.

◆ NumericalIntegrateField()

Vector3< Quantity< NewtonPerCoulomb > > Phyth::Electromagnetics::VolumeCharge::NumericalIntegrateField ( const Vector3< Quantity< Meter > > &  point,
const int  nx,
const int  ny,
const int  nz 
) const
inlineprivate

Numerical integration of electric field over the volume.

Uses the midpoint rule with nx * ny * nz segments. Each segment contributes dE = k_E * dq / r^2 * hat_r.

Parameters
pointEvaluation point
nxNumber of segments along x axis
nyNumber of segments along y axis
nzNumber of segments along z axis
Returns
Electric field intensity E (N/C)

Definition at line 172 of file VolumeSource.hpp.

◆ NumericalIntegratePotential()

Quantity< Volt > Phyth::Electromagnetics::VolumeCharge::NumericalIntegratePotential ( const Vector3< Quantity< Meter > > &  point,
const int  nx,
const int  ny,
const int  nz 
) const
inlineprivate

Numerical integration of electric potential over the volume.

Uses the midpoint rule with nx * ny * nz segments. Each segment contributes dV = k_E * dq / r.

Parameters
pointEvaluation point
nxNumber of segments along x axis
nyNumber of segments along y axis
nzNumber of segments along z axis
Returns
Electric potential V (Volts)

Definition at line 214 of file VolumeSource.hpp.

Member Data Documentation

◆ axis_x_

Vector3<Scalar> Phyth::Electromagnetics::VolumeCharge::axis_x_
private

Definition at line 155 of file VolumeSource.hpp.

◆ axis_y_

Vector3<Scalar> Phyth::Electromagnetics::VolumeCharge::axis_y_
private

Definition at line 155 of file VolumeSource.hpp.

◆ axis_z_

Vector3<Scalar> Phyth::Electromagnetics::VolumeCharge::axis_z_
private

Definition at line 155 of file VolumeSource.hpp.

◆ center_

Vector3<Quantity<Meter> > Phyth::Electromagnetics::VolumeCharge::center_
private

Definition at line 154 of file VolumeSource.hpp.

◆ rho_

Quantity<CoulombPerCubicMeter> Phyth::Electromagnetics::VolumeCharge::rho_
private

Definition at line 157 of file VolumeSource.hpp.

◆ size_x_

Quantity<Meter> Phyth::Electromagnetics::VolumeCharge::size_x_
private

Definition at line 156 of file VolumeSource.hpp.

◆ size_y_

Quantity<Meter> Phyth::Electromagnetics::VolumeCharge::size_y_
private

Definition at line 156 of file VolumeSource.hpp.

◆ size_z_

Quantity<Meter> Phyth::Electromagnetics::VolumeCharge::size_z_
private

Definition at line 156 of file VolumeSource.hpp.


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