Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
SurfaceForce.hpp
Go to the documentation of this file.
1#ifndef PHYTH_SURFACE_FORCE_HPP
2#define PHYTH_SURFACE_FORCE_HPP
3
4#include "ForceSource.hpp"
7
8#include <cassert>
9
10namespace Phyth::Mechanics {
29 class SurfaceForce : public ForceSource {
30 public:
62
71 ) const override {
72 return NumericalIntegrateStress(point, 32, 32);
73 }
74
82 ) const override {
83 return {};
84 }
85
92 return traction_ * width_ * height_;
93 }
94
103 ) const override {
104 const auto local = point - center_;
105 auto u_proj = local.Dot(u_axis_);
106 auto v_proj = local.Dot(v_axis_);
107
108 u_proj = std::clamp(u_proj, -width_ / 2, width_ / 2);
109 v_proj = std::clamp(v_proj, -height_ / 2, height_ / 2);
110
111 const auto closest = center_ + u_proj * u_axis_ + v_proj * v_axis_;
112 return (point - closest).Length();
113 }
114
119 return traction_;
120 }
121
128
129 private:
135
149 const int nu,
150 const int nv
151 ) const {
153
154 const auto poisson_ratio = material_.GetPoissonRatio();
155 const auto prefactor = -1.0 / (8.0 * Consts::pi * (1.0 - poisson_ratio));
156
157 const auto du = width_ / nu;
158 const auto dv = height_ / nv;
159 const auto dA = du * dv;
160 const auto dF = traction_ * dA;
161
162 for (int i = 0; i < nu; ++i) {
163 for (int j = 0; j < nv; ++j) {
164 const auto u = (i + 0.5) / nu * width_ - width_ / 2.0;
165 const auto v = (j + 0.5) / nv * height_ - height_ / 2.0;
166
167 const auto pos = center_ + u * u_axis_ + v * v_axis_;
168 const auto R = point - pos;
169 const auto R_mag = R.Length();
170
172 continue;
173 }
174
175 const auto R3 = R_mag * R_mag * R_mag;
176 const auto R5 = R3 * R_mag * R_mag;
177
178 const auto one_minus_2nu = 1.0 - 2.0 * poisson_ratio;
179 const auto dF_dot_R = dF.Dot(R);
180
181 for (int m = 0; m < 3; ++m) {
182 for (int n = 0; n < 3; ++n) {
183 const auto term1 = one_minus_2nu * (
184 dF[m] * R[n] + dF[n] * R[m]
185 - (m == n ? 1.0 : 0.0) * dF_dot_R
186 ) / R3;
187
188 const auto term2 = 3.0 * dF_dot_R * R[m] * R[n] / R5;
189
190 stress(m, n) += prefactor * (term1 - term2);
191 }
192 }
193 }
194 }
195
196 return stress;
197 }
198 };
199}
200
201#endif // PHYTH_SURFACE_FORCE_HPP
Linear elastic isotropic material model.
Scalar GetPoissonRatio() const
Get Poisson's ratio.
Abstract base class for all force/traction distributions.
Uniform surface traction on a rectangular patch.
Matrix3x3< Quantity< Pascal > > NumericalIntegrateStress(const Vector3< Quantity< Meter > > &point, const int nu, const int nv) const
Numerical integration of stress over the surface.
Vector3< Quantity< Meter > > center_
Matrix3x3< Quantity< Pascal > > GetStressAt(const Vector3< Quantity< Meter > > &point) const override
Compute stress tensor at a point using numerical integration.
Vector3< Quantity< Newton > > GetForceAt(const Vector3< Quantity< Meter > > &point) const override
Get the force vector at a point.
Vector3< Quantity< Newton > > GetTotalForce() const override
Get the total force of this source.
Vector3< Quantity< Pascal > > traction_
Vector3< Quantity< Pascal > > GetTraction() const
Get the traction vector.
Quantity< Meter > GetMinimumDistanceTo(const Vector3< Quantity< Meter > > &point) const override
Get the minimum distance from a point to the rectangular surface.
void SetTraction(const Vector3< Quantity< Pascal > > &traction)
Set the traction vector.
SurfaceForce(const Vector3< Quantity< Meter > > &center, const Vector3< Scalar > &u_axis, const Vector3< Scalar > &v_axis, const Quantity< Meter > width, const Quantity< Meter > height, const Vector3< Quantity< Pascal > > &traction, const IsotropicMaterial &material) noexcept
Construct a rectangular surface traction.
double epsilon
Definition Config.hpp:13
constexpr double pi
Definition Constants.hpp:5
auto abs(Quantity< UnitT > q)
Absolute value of a quantity.
constexpr bool is_unit_v
Definition Unit.hpp:79
3x3 matrix with Quantity components
Definition Matrix3x3.hpp:27
Physical quantity with a value and a compile-time unit.
Definition Quantity.hpp:27
3D vector with Quantity components
Definition Vector3.hpp:28