SimiLie
Loading...
Searching...
No Matches
coupled_fluid_electromagnetism.hpp
1// SPDX-FileCopyrightText: 2026 Baptiste Legouix
2// SPDX-License-Identifier: AGPL-3.0-or-later
3// AI-GENERATED
4
5#pragma once
6
7#include <array>
8
9#include <similie/exterior/form.hpp>
10#include <similie/physics/combine_physics.hpp>
11#include <similie/physics/coupling/electric_coupling_physics.hpp>
12#include <similie/physics/coupling/magnetic_coupling_physics.hpp>
13
14namespace similie::physics {
15
17
40template <
41 PhysicsConcept FluidPhysics,
42 PhysicsConcept ElectromagneticPhysics,
45 : public CombinePhysics<
46 FluidPhysics,
47 ElectromagneticPhysics,
48 coupling::ElectricCouplingPhysics,
49 coupling::MagneticCouplingPhysics>
50{
51 static constexpr bool has_electric
52 = requires(typename ElectromagneticPhysics::State state) { state.displacement; };
53 static constexpr bool has_magnetic
54 = requires(typename ElectromagneticPhysics::State state) { state.induction; };
55
56public:
59 static constexpr std::size_t N = FluidPhysics::N + ElectromagneticPhysics::N;
60 static constexpr bool IS_LINEAR = false;
61 struct State
62 {
63 typename FluidPhysics::State fluid;
64 typename ElectromagneticPhysics::State electromagnetic;
65 };
66
68 FluidPhysics const& fluid,
69 ElectromagneticPhysics const& electromagnetic)
71 FluidPhysics,
72 ElectromagneticPhysics,
73 coupling::ElectricCouplingPhysics,
74 coupling::MagneticCouplingPhysics>(
75 fluid,
76 electromagnetic,
77 coupling::ElectricCouplingPhysics(),
78 coupling::MagneticCouplingPhysics())
79 {
80 }
81
87 State const& state,
88 Vector const& total_current,
89 Vector const& velocity) const
90 {
92 shared.current = total_current;
93 if constexpr (has_electric) {
94 shared.charge_density = state.electromagnetic.charge_density;
95 shared.electric_field
96 = this->template get<1>().electric_field(state.electromagnetic.displacement);
97 } else {
98 shared.electric_field = this->template get<1>().ohm_electric_field(
99 velocity,
100 state.electromagnetic.induction,
101 total_current);
102 }
103 if constexpr (has_magnetic)
104 shared.induction = state.electromagnetic.induction;
105 coupling::ElectromagneticExchange result = this->template get<2>()(shared);
106 result += this->template get<3>()(shared);
107 return result;
108 }
109
111 State const& state,
112 Vector const& total_current) const
113 requires(has_electric)
114 {
115 return coupling_sources(state, total_current, {});
116 }
117
118 [[nodiscard]] KOKKOS_FUNCTION Scalar field_energy(State const& state) const
119 {
120 if constexpr (has_electric && has_magnetic)
121 return Scalar(this->template get<1>().hamiltonian(
122 state.electromagnetic.displacement,
123 state.electromagnetic.induction));
124 else if constexpr (has_electric)
125 return Scalar(this->template get<1>().hamiltonian(state.electromagnetic.displacement));
126 else
127 return Scalar(this->template get<1>().hamiltonian(state.electromagnetic.induction));
128 }
129
130 [[nodiscard]] KOKKOS_FUNCTION typename ElectromagneticPhysics::State field_rate(
131 Scalar const& current_divergence,
132 Vector const& curl_magnetic_field,
133 Vector const& curl_electric_field,
134 Vector const& total_current) const
135 {
136 if constexpr (has_electric && has_magnetic)
137 return this->template get<1>()(
138 current_divergence,
139 curl_magnetic_field,
140 curl_electric_field,
141 total_current);
142 else if constexpr (has_electric)
143 return {this->template get<1>()(current_divergence), {}};
144 else
145 return {this->template get<1>()(curl_electric_field)};
146 }
147
148 [[nodiscard]] KOKKOS_FUNCTION Vector current(State const& state, Vector const& velocity) const
149 requires(has_electric)
150 {
151 if constexpr (has_magnetic)
152 return this->template get<1>().current(
153 state.electromagnetic.charge_density,
154 velocity,
155 state.electromagnetic.displacement,
156 state.electromagnetic.induction);
157 else
158 return this->template get<1>().current(
159 state.electromagnetic.charge_density,
160 velocity,
161 state.electromagnetic.displacement);
162 }
163
164 [[nodiscard]] KOKKOS_FUNCTION typename FluidPhysics::State fluid_state(State const& state) const
165 {
166 typename FluidPhysics::State result = state.fluid;
167 if constexpr (Energy == EnergyConvention::FluidAndField) {
168 result.total_energy -= field_energy(state);
169 }
170 return result;
171 }
172
173 [[nodiscard]] KOKKOS_FUNCTION Vector current(State const& state) const
174 {
175 return current(state, this->template get<0>().primitives(fluid_state(state)).velocity);
176 }
177
178 template <class Fluid = FluidPhysics>
179 [[nodiscard]] KOKKOS_FUNCTION typename Fluid::Flux flux(
180 State const& state,
181 typename Fluid::VelocityGradient const& velocity_gradient,
182 Vector const& temperature_gradient,
183 int normal,
184 Vector const& total_current) const
185 {
186 KOKKOS_ASSERT(normal >= 0 && normal < 3);
187 typename Fluid::State const hydro = fluid_state(state);
188 typename Fluid::PrimitiveVariables const primitive
189 = this->template get<0>().primitives(hydro);
190 typename Fluid::Flux result
191 = this->template get<0>()
192 .flux(hydro, primitive, velocity_gradient, temperature_gradient, normal);
193 if constexpr (Energy == EnergyConvention::FluidAndField) {
194 static_assert(
195 has_magnetic,
196 "Electric quasistatics uses fluid energy with J.E exchange");
197 if constexpr (has_electric) {
198 Vector const poynting = this->template get<1>().poynting_flux(
199 state.electromagnetic.displacement,
200 state.electromagnetic.induction);
201 result.total_energy += poynting[normal];
202 } else {
203 Vector const electric = this->template get<1>().ohm_electric_field(
204 primitive.velocity,
205 state.electromagnetic.induction,
206 total_current);
207 Vector const poynting
208 = this->template get<1>()
209 .poynting_flux(electric, state.electromagnetic.induction);
210 result.total_energy += poynting[normal];
211 }
212 }
213 return result;
214 }
215
216 template <class Fluid = FluidPhysics>
217 [[nodiscard]] KOKKOS_FUNCTION typename Fluid::Flux flux(
218 State const& state,
219 typename Fluid::VelocityGradient const& velocity_gradient,
220 Vector const& temperature_gradient,
221 int normal) const
222 requires(has_electric)
223 {
224 return flux(state, velocity_gradient, temperature_gradient, normal, {});
225 }
226
227 template <class FluidFlux>
228 [[nodiscard]] KOKKOS_FUNCTION State operator()(
229 State const& state,
230 FluidFlux const& fluid_flux_divergence,
231 Scalar const& current_divergence,
232 Vector const& curl_magnetic_field,
233 Vector const& curl_electric_field,
234 Vector const& total_current) const
235 {
236 typename FluidPhysics::State rate = this->template get<0>()(fluid_flux_divergence);
238 state,
239 total_current,
240 this->template get<0>().primitives(fluid_state(state)).velocity);
241 for (int a = 0; a < 3; ++a)
242 rate.momentum[a] += exchange.momentum_source[a];
243 if constexpr (Energy == EnergyConvention::Fluid)
244 rate.total_energy += exchange.fluid_energy_source;
245 return {rate,
247 current_divergence,
248 curl_magnetic_field,
249 curl_electric_field,
250 total_current)};
251 }
252
253 [[nodiscard]] KOKKOS_FUNCTION Scalar combined_energy(State const& state) const
254 {
255 if constexpr (Energy == EnergyConvention::FluidAndField)
256 return Scalar(state.fluid.total_energy);
257 else
258 return Scalar(state.fluid.total_energy + field_energy(state));
259 }
260
261 [[nodiscard]] KOKKOS_FUNCTION Vector
262 transport(State const& state, Vector const& velocity, Vector const& total_current) const
263 {
264 Vector result = this->template get<0>().transport(velocity, state.fluid.vorticity);
266 = coupling_sources(state, total_current, velocity);
267 for (int a = 0; a < 3; ++a)
268 result[a] += exchange.momentum_source[a] / this->template get<0>().density;
269 return result;
270 }
271
272 [[nodiscard]] KOKKOS_FUNCTION Vector momentum_rate(
273 State const& state,
274 Vector const& velocity,
275 Vector const& bernoulli_gradient,
276 Vector const& velocity_laplacian,
277 Vector const& total_current) const
278 {
279 Vector result = this->template get<0>().momentum_rate(
280 velocity,
281 state.fluid.vorticity,
282 bernoulli_gradient,
283 velocity_laplacian);
285 = coupling_sources(state, total_current, velocity);
286 for (int a = 0; a < 3; ++a)
287 result[a] += exchange.momentum_source[a] / this->template get<0>().density;
288 return result;
289 }
290
291 [[nodiscard]] KOKKOS_FUNCTION State operator()(
292 Vector const& transport_curl,
293 Vector const& vorticity_laplacian,
294 Scalar const& current_divergence,
295 Vector const& curl_magnetic_field,
296 Vector const& curl_electric_field,
297 Vector const& total_current) const
298 {
299 typename FluidPhysics::State rate {};
300 rate.vorticity = this->template get<0>()(transport_curl, vorticity_laplacian);
301 return {rate,
303 current_divergence,
304 curl_magnetic_field,
305 curl_electric_field,
306 total_current)};
307 }
308};
309
310} // namespace similie::physics
Differential-form coefficients, pointwise or sampled over a spatial domain.
Definition form.hpp:32
Assemble fluid and electric, magnetic, or full Maxwell sectors with shared exchange laws.
KOKKOS_FUNCTION CoupledFluidElectromagnetism(FluidPhysics const &fluid, ElectromagneticPhysics const &electromagnetic)
KOKKOS_FUNCTION ElectromagneticPhysics::State field_rate(Scalar const &current_divergence, Vector const &curl_magnetic_field, Vector const &curl_electric_field, Vector const &total_current) const
KOKKOS_FUNCTION Vector transport(State const &state, Vector const &velocity, Vector const &total_current) const
KOKKOS_FUNCTION Fluid::Flux flux(State const &state, typename Fluid::VelocityGradient const &velocity_gradient, Vector const &temperature_gradient, int normal, Vector const &total_current) const
KOKKOS_FUNCTION FluidPhysics::State fluid_state(State const &state) const
KOKKOS_FUNCTION coupling::ElectromagneticExchange coupling_sources(State const &state, Vector const &total_current, Vector const &velocity) const
Evaluate both exchanges using the reconstructed current form.
KOKKOS_FUNCTION Vector momentum_rate(State const &state, Vector const &velocity, Vector const &bernoulli_gradient, Vector const &velocity_laplacian, Vector const &total_current) const
KOKKOS_FUNCTION State operator()(Vector const &transport_curl, Vector const &vorticity_laplacian, Scalar const &current_divergence, Vector const &curl_magnetic_field, Vector const &curl_electric_field, Vector const &total_current) const
KOKKOS_FUNCTION Fluid::Flux flux(State const &state, typename Fluid::VelocityGradient const &velocity_gradient, Vector const &temperature_gradient, int normal) const
KOKKOS_FUNCTION Vector current(State const &state, Vector const &velocity) const
sil::exterior::Form< std::array< double, 3 > > Vector
KOKKOS_FUNCTION Vector current(State const &state) const
KOKKOS_FUNCTION Scalar field_energy(State const &state) const
KOKKOS_FUNCTION State operator()(State const &state, FluidFlux const &fluid_flux_divergence, Scalar const &current_divergence, Vector const &curl_magnetic_field, Vector const &curl_electric_field, Vector const &total_current) const
KOKKOS_FUNCTION Scalar combined_energy(State const &state) const
KOKKOS_FUNCTION coupling::ElectromagneticExchange coupling_sources(State const &state, Vector const &total_current) const
sil::exterior::Form< std::array< double, 3 > > current
Device-compatible composition of physics objects with independent state laws.
sil::exterior::Form< std::array< double, 3 > > momentum_source