Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
SurfaceCharge.hpp
Go to the documentation of this file.
1#ifndef PHYTH_SURFACE_CHARGE_HPP
2#define PHYTH_SURFACE_CHARGE_HPP
3
4#include <cassert>
5
6#include "ChargeSource.hpp"
8
34 class SurfaceCharge : public ChargeSource {
35 public:
60
72 return NumericalIntegrateField(point, 32, 32);
73 }
74
86 return NumericalIntegratePotential(point, 32, 32);
87 }
88
95 return sigma_ * width_ * height_;
96 }
97
109 const auto local = point - center_;
110 auto u_proj = local.Dot(u_axis_);
111 auto v_proj = local.Dot(v_axis_);
112
113 u_proj = std::clamp(u_proj, -width_ / 2, width_ / 2);
114 v_proj = std::clamp(v_proj, -height_ / 2, height_ / 2);
115
116 const auto closest = center_ + u_proj * u_axis_ + v_proj * v_axis_;
117 return (point - closest).Length();
118 }
119
122 GetSurfaceDensity() const { return sigma_; }
123
124 private:
129
143 const int nu, const int nv) const {
145 const auto du = width_ / nu;
146 const auto dv = height_ / nv;
147
148 for (int i = 0; i < nu; ++i) {
149 for (int j = 0; j < nv; ++j) {
150 const auto u = (i + 0.5) / nu * width_ - width_ / 2;
151 const auto v = (j + 0.5) / nv * height_ - height_ / 2;
152 const auto pos = center_ + u * u_axis_ + v * v_axis_;
153
154 const auto r = point - pos;
155 const auto dist = r.Length();
156 if (dist < Quantity<Meter>(Config::epsilon)) continue;
157
158 const auto dq = sigma_ * du * dv;
159 const auto dE = Consts::k_E * dq / (dist * dist) * r.Normalized();
160 E += dE;
161 }
162 }
163 return E;
164 }
165
179 const int nu, const int nv) const {
180 auto V = 0_V;
181 const auto du = width_ / nu;
182 const auto dv = height_ / nv;
183
184 for (int i = 0; i < nu; ++i) {
185 for (int j = 0; j < nv; ++j) {
186 const auto u = (i + 0.5) / nu * width_ - width_ / 2;
187 const auto v = (j + 0.5) / nv * height_ - height_ / 2;
188 const auto pos = center_ + u * u_axis_ + v * v_axis_;
189
190 const auto r = point - pos;
191 const auto dist = r.Length();
192 if (dist < Quantity<Meter>(Config::epsilon)) continue;
193
194 const auto dq = sigma_ * du * dv;
195 V += Consts::k_E * dq / dist;
196 }
197 }
198 return V;
199 }
200 };
201}
202
203#endif // PHYTH_SURFACE_CHARGE_HPP
Abstract base class for all charge distributions.
Uniform surface charge distribution on a rectangular patch.
Quantity< Volt > NumericalIntegratePotential(const Vector3< Quantity< Meter > > &point, const int nu, const int nv) const
Numerical integration of electric potential over the surface.
Quantity< Coulomb > GetTotalChargeValue() const override
Get the total charge of the surface.
Vector3< Quantity< NewtonPerCoulomb > > GetElectricFieldAt(const Vector3< Quantity< Meter > > &point) const override
Compute the electric field at a point using numerical integration.
Vector3< Quantity< NewtonPerCoulomb > > NumericalIntegrateField(const Vector3< Quantity< Meter > > &point, const int nu, const int nv) const
Numerical integration of electric field over the surface.
Vector3< Quantity< Meter > > center_
Quantity< CoulombPerSquareMeter > sigma_
Quantity< Volt > GetElectricPotentialAt(const Vector3< Quantity< Meter > > &point) const override
Compute the electric potential at a point using numerical integration.
Quantity< Meter > GetMinimumDistanceTo(const Vector3< Quantity< Meter > > &point) const override
Get the minimum distance from a point to the rectangular surface.
Quantity< CoulombPerSquareMeter > GetSurfaceDensity() const
SurfaceCharge(const Vector3< Quantity< Meter > > &center, const Vector3< Scalar > &u_axis, const Vector3< Scalar > &v_axis, const Quantity< Meter > width, const Quantity< Meter > height, const Quantity< CoulombPerSquareMeter > sigma)
Construct a rectangular surface charge.
double epsilon
Definition Config.hpp:13
constexpr auto k_E
auto abs(Quantity< UnitT > q)
Absolute value of a quantity.
constexpr bool is_unit_v
Definition Unit.hpp:79
Physical quantity with a value and a compile-time unit.
Definition Quantity.hpp:27
3D vector with Quantity components
Definition Vector3.hpp:28