DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
EulerP_Evaluator.hpp
Go to the documentation of this file.
1/** @file EulerP_Evaluator.hpp
2 * @brief Main evaluator class for the EulerP compressible Navier-Stokes solver module.
3 *
4 * Defines the Evaluator class and its associated argument structs for dispatching
5 * CFD kernels (gradient reconstruction, face reconstruction, conservative-to-primitive
6 * conversion, eigenvalue estimation, and flux computation) to Host or CUDA backends.
7 * Also provides the EvaluatorDeviceView for device-callable access and the
8 * EvaluatorConfig for JSON-based runtime configuration.
9 */
10#pragma once
11
12#include "CFV/FiniteVolume.hpp"
13#include "DNDS/ArrayDOF.hpp"
14#include "DNDS/Defines.hpp"
16#include "DNDS/Errors.hpp"
17#include "EulerP.hpp"
18#include "EulerP_BC.hpp"
19#include "EulerP_Physics.hpp"
20#include <vector>
22#include "DNDS/ObjectUtils.hpp"
23
24namespace DNDS::EulerP
25{
26
28
29 /**
30 * @brief Device-callable view of the Evaluator, combining finite volume, BC handler, and physics views.
31 *
32 * This trivially-copyable struct bundles the device views needed by GPU/Host kernels
33 * so they can access mesh geometry, boundary conditions, and gas physics without
34 * indirecting through shared pointers.
35 *
36 * @tparam B The DeviceBackend (Host or CUDA).
37 */
38 template <DeviceBackend B>
40 {
41 public:
43 t_fv fv; /**< @brief Device view of the finite volume / VFV reconstruction object. */
45 t_bcHandler bcHandler; /**< @brief Device view of the boundary condition handler. */
47 t_physics physics; /**< @brief Device view of the gas physics model. */
48
51 t_fv n_fv,
52 t_bcHandler n_bcHandler,
53 t_physics n_physics) : fv(n_fv), bcHandler(n_bcHandler), physics(n_physics) {}
54 };
55
56 /**
57 * @brief JSON-configurable settings for the Evaluator.
58 *
59 * Stores runtime configuration such as CUDA threads-per-block, whether to pull
60 * all input arguments before kernel dispatch, and serialization of CUDA execution.
61 * Configuration is applied via JSON merge-patch semantics.
62 */
64 {
65 t_jsonconfig config_data;
66
67 public:
68 /** @brief Constructs the config with default values (threadsPerBlock=128, etc.). */
70
71 /**
72 * @brief Validates that all keys in @p config_in exist in the current defaults.
73 * @param config_in JSON patch to validate.
74 * @throws std::runtime_error if an unrecognized key is found.
75 */
76 void valid_patch_keys(const t_jsonconfig &config_in);
77
78 /**
79 * @brief Validates and applies a JSON merge-patch to the configuration.
80 * @param config_in JSON patch to merge.
81 */
82 void merge_patch(const t_jsonconfig &config_in)
83 {
84 valid_patch_keys(config_in);
85 config_data.merge_patch(config_in);
86 }
87
88 /** @brief Returns a const reference to the underlying JSON configuration. */
89 const t_jsonconfig &config() const { return config_data; }
90 };
91
92 /**
93 * @brief Main EulerP evaluator orchestrating CFD kernel dispatch for compressible N-S solvers.
94 *
95 * Holds the finite volume reconstruction object, boundary condition handler, gas physics
96 * model, and internal face buffers. Provides methods for each stage of a 2nd-order finite
97 * volume time step: gradient reconstruction (Green-Gauss + Barth-Jespersen limiter),
98 * face value reconstruction, conservative-to-primitive conversion, eigenvalue/timestep
99 * estimation, and inviscid+viscous flux evaluation.
100 *
101 * Each method accepts a packed argument struct (e.g., RecGradient_Arg) that bundles
102 * all input/output arrays. The dispatch logic selects Host or CUDA backend at runtime
103 * and delegates to Evaluator_impl<B>.
104 */
106 {
107 public:
110 t_fv fv; /**< @brief Shared pointer to the Compact Finite Volume (VFV) reconstruction object. */
112 t_bcHandler bcHandler; /**< @brief Shared pointer to the boundary condition handler. */
114 t_physics physics; /**< @brief Shared pointer to the gas physics model. */
115
117
118 t_config config; /**< @brief Runtime configuration (Riemann solver, CUDA settings, etc.). */
119
120 /** @brief Returns a const reference to the JSON configuration. */
121 const t_jsonconfig &get_config() { return config.config(); }
122
123 /**
124 * @brief Merges a JSON patch into the evaluator configuration.
125 * @tparam Tc Forwarding reference type for the JSON config.
126 * @param config_in JSON config patch to apply.
127 */
128 template <typename Tc>
133
134 // internal buffers
135 TUDof u_face_bufferL; /**< @brief Left-side face DOF buffer for boundary value storage. */
136 TUDof u_face_bufferR; /**< @brief Right-side face DOF buffer for boundary value storage. */
137 std::vector<TUScalar> uScalar_face_bufferL; /**< @brief Left-side face scalar buffers for additional transported scalars. */
138 std::vector<TUScalar> uScalar_face_bufferR; /**< @brief Right-side face scalar buffers for additional transported scalars. */
139
140 /**
141 * @brief Allocates or resizes the face DOF buffer @p u to match the current mesh face count.
142 *
143 * Creates the father (owned faces) and son (ghost faces) arrays if they do not exist,
144 * or resizes them if the mesh topology has changed. Also transfers to the active device
145 * backend if one is set.
146 *
147 * @param u Face DOF buffer to build (in-out).
148 */
150 {
151 // TODO: upgrade to matching face quad instead
153 bool father_changed{false}, son_changed{false};
154 if (!u.father)
155 u.father = make_ssp<decltype(u.father)::element_type>(ObjName{"EulerPEvaluator::BuildFaceBufferDof::u.father"}, fv->mesh->getMPI()), father_changed = true;
156 if (u.father->Size() != fv->mesh->NumFace())
157 u.father->Resize(fv->mesh->NumFace(), nVarsFlow, 1), father_changed = true;
158
159 if (!u.son)
160 u.son = make_ssp<decltype(u.son)::element_type>(ObjName{"EulerPEvaluator::BuildFaceBufferDof::u.son"}, fv->mesh->getMPI()), son_changed = true;
161 if (u.son->Size() != fv->mesh->NumFaceGhost())
162 u.son->Resize(fv->mesh->NumFaceGhost(), nVarsFlow, 1), son_changed = true;
163 auto B = fv->device();
165 u.father->to_device(B);
167 u.son->to_device(B);
168 }
169
170 /**
171 * @brief Allocates or resizes a scalar face buffer to match the current mesh face count.
172 *
173 * Similar to BuildFaceBufferDof but for single-component scalar quantities.
174 *
175 * @param u Scalar face buffer to build (in-out).
176 */
178 {
179 // TODO: upgrade to matching face quad instead
181 bool father_changed{false}, son_changed{false};
182 if (!u.father)
183 u.father = make_ssp<decltype(u.father)::element_type>(ObjName{"EulerPEvaluator::BuildFaceBufferDofScalar::u.father"}, fv->mesh->getMPI()), father_changed = true;
184 if (u.father->Size() != fv->mesh->NumFace())
185 u.father->Resize(fv->mesh->NumFace(), 1, 1), father_changed = true;
186
187 if (!u.son)
188 u.son = make_ssp<decltype(u.son)::element_type>(ObjName{"EulerPEvaluator::BuildFaceBufferDofScalar::u.son"}, fv->mesh->getMPI()), son_changed = true;
189 if (u.son->Size() != fv->mesh->NumFaceGhost())
190 u.son->Resize(fv->mesh->NumFaceGhost(), 1, 1), son_changed = true;
191 auto B = fv->device();
192 // because ArrayPair's to_device is father and son to device:
194 u.father->to_device(B);
196 u.son->to_device(B);
197 }
198
199 /**
200 * @brief Prepares all face buffers (DOF + scalars) for left and right states.
201 * @param nVarsScalar Number of additional transported scalar variables.
202 */
215
216 /** @brief Returns a tuple of member pointers to face buffer arrays for device transfer. */
225
226 /**
227 * @brief Constructs the Evaluator with the given finite volume, BC handler, and physics objects.
228 * @param n_fv Shared pointer to the finite volume reconstruction object.
229 * @param n_bcHandler Shared pointer to the boundary condition handler.
230 * @param n_physics Shared pointer to the gas physics model.
231 */
238
239 /**
240 * @brief Writes cell-centered and node-centered field data to a VTK-HDF5 file.
241 *
242 * Outputs primitive variables (density, velocity) along with user-specified scalar
243 * and vector fields at both cell centers and nodes.
244 *
245 * @param fname Output file path.
246 * @param series_name Name for the VTK time series.
247 * @param arrCellCentScalar Cell-centered scalar field arrays.
248 * @param arrCellCentScalar_names_in Names for each cell-centered scalar field.
249 * @param arrCellCentVec Cell-centered vector field arrays.
250 * @param arrCellCentVec_names_in Names for each cell-centered vector field.
251 * @param arrNodeScalar Node-centered scalar field arrays.
252 * @param arrNodeScalar_names_in Names for each node-centered scalar field.
253 * @param arrNodeVec Node-centered vector field arrays.
254 * @param arrNodeVec_names_in Names for each node-centered vector field.
255 * @param uPrimCell Cell-centered primitive variable DOF (density + velocity); may be null.
256 * @param uPrimNode Node-centered primitive variable DOF; may be null.
257 * @param t Physical simulation time.
258 */
259 void PrintDataVTKHDF(std::string fname, std::string series_name,
260 std::vector<ssp<TUScalar>> &arrCellCentScalar,
261 const std::vector<std::string> &arrCellCentScalar_names_in,
262 std::vector<ssp<TUVec>> &arrCellCentVec,
263 const std::vector<std::string> &arrCellCentVec_names_in,
264 std::vector<ssp<TUScalar>> &arrNodeScalar,
265 const std::vector<std::string> &arrNodeScalar_names_in,
266 std::vector<ssp<TUVec>> &arrNodeVec,
267 const std::vector<std::string> &arrNodeVec_names_in,
268 ssp<TUDof> uPrimCell,
269 ssp<TUDof> uPrimNode,
270 double t);
271
272 /**
273 * @brief Queries and validates the device backend across all sub-objects.
274 *
275 * Checks that the finite volume, mesh, BC handler, and physics objects all agree
276 * on the active device backend.
277 *
278 * @return The active DeviceBackend (Host, CUDA, or Unknown).
279 * @throws std::runtime_error if backends are inconsistent.
280 */
282 {
283 DeviceBackend B = fv->device();
284 DeviceBackend B_mesh = fv->mesh->device();
286 DeviceBackend B_physics = physics->device();
290
291 return B;
292 }
293
294 /**
295 * @brief Non-trivially-copyable device view holding shared_ptr to fv and device views of BC/physics.
296 *
297 * Unlike EvaluatorDeviceView (trivially copyable for kernels), this struct retains
298 * ownership of the fv shared_ptr and is move-only to prevent accidental copies
299 * that would interfere with device memory management.
300 *
301 * @tparam B The DeviceBackend.
302 */
303 template <DeviceBackend B>
305 {
309
310 //! only permit moving to avoid host_device_vector to change
311 // also avoids accidentally copying this to device...
312 t_deviceView(t_deviceView &&R) noexcept = default;
313 t_deviceView(const t_deviceView &R) = delete;
316
317 operator EvaluatorDeviceView<B>() const
318 {
319 static_assert(std::is_trivially_copyable_v<remove_cvref_t<decltype(fv->deviceView<B>())>>);
320 return {fv->deviceView<B>(), bcHandler, physics};
321 }
322 };
323
324 /**
325 * @brief Creates a device view for backend B from the current evaluator state.
326 * @tparam B The target DeviceBackend.
327 * @return A move-only t_deviceView<B> combining fv, bcHandler, and physics views.
328 * @throws std::runtime_error if the fv device backend does not match B.
329 */
330 template <DeviceBackend B>
332 {
333 DeviceBackend B_fv = fv->device();
335 fmt::format("B_fv is {} ", device_backend_name(B_fv)) +
336 fmt::format("B is {} ", device_backend_name(B)));
337
338 return t_deviceView<B>{
339 fv,
340 bcHandler->deviceView<B>(),
341 physics->deviceView<B>()};
342 }
343
344 /** @brief Transfers all sub-objects and face buffers from device memory back to host. */
345 void to_host()
346 {
347 fv->to_host();
348 bcHandler->to_host();
349 physics->to_host();
350
353 for (auto &a : uScalar_face_bufferL)
354 a.to_host();
355 for (auto &a : uScalar_face_bufferR)
356 a.to_host();
357 }
358
359 /**
360 * @brief Transfers all sub-objects and face buffers to the specified device backend.
361 * @param B Target device backend (e.g., DeviceBackend::CUDA).
362 */
364 {
365 fv->to_device(B);
366 bcHandler->to_device(B);
367 physics->to_device(B);
370 for (auto &a : uScalar_face_bufferL)
371 a.to_device(B);
372 for (auto &a : uScalar_face_bufferR)
373 a.to_device(B);
374 }
375
376 /****************************** */
377
378 /**
379 * @brief Validates that a DOF array pair has the expected sizes and device placement.
380 *
381 * Checks father/son existence, device backend match, and array sizes against the mesh
382 * topology for the specified variable location.
383 *
384 * @tparam TPair ArrayPair type (e.g., TUDof, TUScalar).
385 * @param u The DOF array pair to validate.
386 * @param name Human-readable name for error messages.
387 * @param varloc Variable location: 0=cell, 1=face, 2=node, -1=skip size check.
388 * @param includeSon Whether to also validate the son (ghost) array.
389 * @param B Expected device backend.
390 * @param optional If true, a null @p u is allowed without error.
391 */
392 template <class TPair>
394 const ssp<TPair> &u,
395 const std::string &name = "unknown",
396 int varloc = 0,
397 bool includeSon = true,
399 bool optional = false)
400 {
401 std::string emit_info = fmt::format("{} varloc {} check failure", name, varloc);
402 if (optional && !u)
403 return;
404
407 if (includeSon)
409 DNDS_check_throw_info(u->father->device() == B, emit_info);
410 if (includeSon)
411 DNDS_check_throw_info(u->son->device() == B, emit_info);
412 if (varloc == -1)
413 {
414 }
415 else if (varloc == 0)
416 {
417 DNDS_check_throw_info(u->father->Size() == fv->mesh->NumCell(), emit_info);
418 if (includeSon)
419 DNDS_check_throw_info(u->son->Size() == fv->mesh->NumCellGhost(), emit_info);
420 }
421 else if (varloc == 1)
422 {
423 DNDS_check_throw_info(u->father->Size() == fv->mesh->NumFace(), emit_info);
424 if (includeSon)
425 DNDS_check_throw_info(u->son->Size() == fv->mesh->NumFaceGhost(), emit_info);
426 }
427 else if (varloc == 2)
428 {
429 DNDS_check_throw_info(u->father->Size() == fv->mesh->NumNode(), emit_info);
430 if (includeSon)
431 DNDS_check_throw_info(u->son->Size() == fv->mesh->NumNodeGhost(), emit_info);
432 }
433 else
434 DNDS_check_throw_info(false, "varloc should be -1, 0, 1 or 2");
435 }
436
437 /**
438 * @brief Packed argument struct for Green-Gauss gradient reconstruction with Barth-Jespersen limiting.
439 *
440 * Inherits EvaluatorArgBase for CRTP-based device transfer and validation.
441 * Contains the conservative state and its gradient, plus optional transported scalars
442 * and their gradients. The gradient fields are both input (initial guess) and output
443 * (reconstructed + limited gradients).
444 */
445 struct RecGradient_Arg : public EvaluatorArgBase<RecGradient_Arg>
446 {
447 ssp<TUDof> u; /**< @brief Conservative state vector (cell-centered, nVarsFlow components). */
448 ssp<TUGrad> uGrad; /**< @brief Gradient of conservative state (in-out: reconstructed by Green-Gauss). */
449 // out
450 std::vector<ssp<TUScalar>> uScalar; /**< @brief Additional transported scalar fields (cell-centered). */
451 std::vector<ssp<TUScalarGrad>> uScalarGrad; /**< @brief Gradients of transported scalars (in-out). */
452
454
455 /** @brief Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer. */
464 /**
465 * @brief Validates all member arrays against the mesh topology and device backend.
466 * @param self Reference to the owning Evaluator.
467 */
468 void Validate(Evaluator &self)
469 {
470 DeviceBackend B = self.device();
471 self.checkValidUDof(u, "u", 0, true, B);
472 self.checkValidUDof(uGrad, "uGrad", 0, true, B);
473 for (size_t i = 0; i < uScalar.size(); i++)
474 self.checkValidUDof(uScalar[i], "uScalar_" + std::to_string(i), 0, true, B);
475 for (size_t i = 0; i < uScalarGrad.size(); i++)
476 self.checkValidUDof(uScalarGrad[i], "uScalarGrad_" + std::to_string(i), 0, true, B);
477 }
478 };
479
480 /**
481 * @brief Performs Green-Gauss gradient reconstruction with Barth-Jespersen limiting.
482 *
483 * Computes cell gradients via the Green-Gauss theorem (face-area-weighted averaging),
484 * then applies the Barth-Jespersen monotonicity limiter to prevent spurious oscillations.
485 * Dispatches to Host or CUDA backend based on the current device().
486 *
487 * @param arg Packed input/output arguments (conservative state, gradients, scalars).
488 */
489 void RecGradient(RecGradient_Arg &arg);
490
491 /**
492 * @brief Packed argument struct for conservative-to-primitive conversion with viscosity computation.
493 *
494 * Holds conservative and primitive states (both flow DOF and scalars), their gradients,
495 * and output thermodynamic quantities (pressure, temperature, speed of sound, gamma, viscosity).
496 */
497 struct Cons2PrimMu_Arg : public EvaluatorArgBase<Cons2PrimMu_Arg>
498 {
500
501 ssp<TUDof> u; /**< @brief Conservative state (input). */
502 ssp<TUGrad> uGrad; /**< @brief Gradient of conservative state (input). */
503 std::vector<ssp<TUScalar>> uScalar; /**< @brief Transported scalar fields (input). */
504 std::vector<ssp<TUScalarGrad>> uScalarGrad; /**< @brief Gradients of transported scalars (input). */
505 // out
506 ssp<TUDof> uPrim; /**< @brief Primitive state (output). */
507 ssp<TUGrad> uGradPrim; /**< @brief Gradient of primitive state (output). */
508 std::vector<ssp<TUScalar>> uScalarPrim; /**< @brief Primitive transported scalars (output). */
509 std::vector<ssp<TUScalarGrad>> uScalarGradPrim; /**< @brief Gradients of primitive scalars (output). */
510 ssp<TUScalar> p; /**< @brief Pressure (output). */
511 ssp<TUScalar> T; /**< @brief Temperature (output). */
512 ssp<TUScalar> a; /**< @brief Speed of sound (output). */
513 ssp<TUScalar> gamma; /**< @brief Ratio of specific heats (output). */
514 ssp<TUScalar> mu; /**< @brief Total (laminar + turbulent) viscosity (output). */
515 std::vector<ssp<TUScalar>> muComp; /**< @brief Component-wise viscosity contributions (output). */
516
517 /** @brief Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer. */
536
537 /**
538 * @brief Validates all member arrays against the mesh topology and device backend.
539 * @param self Reference to the owning Evaluator.
540 */
541 void Validate(Evaluator &self)
542 {
543 DeviceBackend B = self.device();
544 using namespace std::string_literals;
545 int varloc = -1;
546 // TODO: improve to check if all sizes are compatible (varloc = -1 does not check size now)
547
548 auto validate_member = [&](std::string name, auto &v)
549 {
550 if constexpr (is_ssp_v<remove_cvref_t<decltype(v)>>)
551 {
552 self.checkValidUDof(v, name,
553 varloc, true, B);
554 }
555 else
556 {
557 for (size_t i = 0; i < v.size(); i++)
558 self.checkValidUDof(v[i], name + "_"s + std::to_string(i),
559 varloc, true, B);
560 }
561 };
565 }
566 };
567
568 /**
569 * @brief Converts conservative variables to primitive variables and computes viscosity.
570 *
571 * For each cell, converts (rho, rho*u, rho*E, ...) to (rho, u, T, ...) and
572 * computes primitive gradients, pressure, temperature, speed of sound, gamma, and
573 * total viscosity (laminar + turbulent).
574 *
575 * @param arg Packed input/output arguments.
576 */
577 void Cons2PrimMu(Cons2PrimMu_Arg &arg);
578
579 /**
580 * @brief Packed argument struct for conservative-to-primitive conversion without gradients or viscosity.
581 *
582 * A simpler variant of Cons2PrimMu_Arg that only computes primitive variables and
583 * thermodynamic scalars (p, T, a, gamma) without gradient transformation or viscosity.
584 */
585 struct Cons2Prim_Arg : public EvaluatorArgBase<Cons2Prim_Arg>
586 {
588
589 ssp<TUDof> u; /**< @brief Conservative state (input). */
590 std::vector<ssp<TUScalar>> uScalar; /**< @brief Transported scalar fields (input). */
591 // out
592 ssp<TUDof> uPrim; /**< @brief Primitive state (output). */
593 std::vector<ssp<TUScalar>> uScalarPrim; /**< @brief Primitive transported scalars (output). */
594 ssp<TUScalar> p; /**< @brief Pressure (output). */
595 ssp<TUScalar> T; /**< @brief Temperature (output). */
596 ssp<TUScalar> a; /**< @brief Speed of sound (output). */
597 ssp<TUScalar> gamma; /**< @brief Ratio of specific heats (output). */
598
599 /** @brief Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer. */
612 /**
613 * @brief Validates all member arrays against the mesh topology and device backend.
614 * @param self Reference to the owning Evaluator.
615 */
616 void Validate(Evaluator &self)
617 {
618 DeviceBackend B = self.device();
619 using namespace std::string_literals;
620 int varloc = -1;
621
622 auto validate_member = [&](std::string name, auto &v)
623 {
624 if constexpr (is_ssp_v<remove_cvref_t<decltype(v)>>)
625 {
626 self.checkValidUDof(v, name,
627 varloc, true, B);
628 }
629 else
630 {
631 for (size_t i = 0; i < v.size(); i++)
632 self.checkValidUDof(v[i], name + "_"s + std::to_string(i),
633 varloc, true, B);
634 }
635 };
639 }
640 };
641
642 /**
643 * @brief Converts conservative variables to primitive variables (no gradients or viscosity).
644 *
645 * Simplified version of Cons2PrimMu that computes only primitive state, pressure,
646 * temperature, speed of sound, and gamma.
647 *
648 * @param arg Packed input/output arguments.
649 */
650 void Cons2Prim(Cons2Prim_Arg &arg);
651
652 /**
653 * @brief Packed argument struct for eigenvalue estimation and local time-step computation.
654 *
655 * Provides the conservative state, per-cell viscosity and speed of sound, and outputs
656 * per-face eigenvalue estimates (acoustic waves), per-face viscous eigenvalue estimates,
657 * face/cell delta-lambda for H-correction, and the local CFL time step.
658 */
659 struct EstEigenDt_Arg : public EvaluatorArgBase<EstEigenDt_Arg>
660 {
662 ssp<TUDof> u; /**< @brief Conservative state (cell-centered, input). */
663 ssp<TUScalar> muCell; /**< @brief Per-cell total viscosity (input). */
664 ssp<TUScalar> aCell; /**< @brief Per-cell speed of sound (input). */
665 ssp<TUScalarGrad> faceLamEst; /**< @brief Per-face eigenvalue estimates [lam-, lam0, lam+] (output). */
666 ssp<TUScalar> faceLamVisEst; /**< @brief Per-face viscous eigenvalue estimate (output). */
667 ssp<TUScalar> deltaLamFace; /**< @brief Per-face eigenvalue difference for H-correction (output). */
668 ssp<TUScalar> deltaLamCell; /**< @brief Per-cell maximum eigenvalue difference (output). */
669 ssp<TUScalar> dt; /**< @brief Per-cell local time step (output). */
670
671 /** @brief Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer. */
684 /**
685 * @brief Validates all member arrays, distinguishing cell-located from face-located fields.
686 * @param self Reference to the owning Evaluator.
687 */
688 void Validate(Evaluator &self)
689 {
690 DeviceBackend B = self.device();
691
692 auto validate_member = [&](std::string name, auto &v)
693 {
694 int varloc = 0;
695 if (std::set<std::string>{
696 "faceLamEst",
697 "faceLamVisEst",
698 "deltaLamFace",
699 }
700 .count(name))
701 varloc = 1;
702 self.checkValidUDof(v, name, varloc, true, B);
703 };
707 }
708 };
709
710 /**
711 * @brief Estimates per-face eigenvalues and computes per-cell local time steps.
712 *
713 * First pass: computes face-level convective and viscous eigenvalue estimates.
714 * Second pass: accumulates face eigenvalues to cells and computes dt = Vol / sum(lambda * area).
715 *
716 * @param arg Packed input/output arguments.
717 */
718 void EstEigenDt(EstEigenDt_Arg &arg);
719
720 /**
721 * @brief Packed argument struct for 2nd-order face value reconstruction.
722 *
723 * Takes cell-centered conservative state and gradients, and outputs left/right
724 * reconstructed face values (uFL, uFR) and face-averaged gradients (uGradFF).
725 * Boundary faces receive ghost values via the BC handler.
726 */
727 struct RecFace2nd_Arg : public EvaluatorArgBase<RecFace2nd_Arg>
728 {
730 ssp<TUDof> u; /**< @brief Conservative state (cell-centered, input). */
731 ssp<TUGrad> uGrad; /**< @brief Cell gradient of conservative state (input). */
732 std::vector<ssp<TUScalar>> uScalar; /**< @brief Cell-centered transported scalars (input). */
733 std::vector<ssp<TUScalarGrad>> uScalarGrad; /**< @brief Gradients of transported scalars (input). */
734 // out
735 ssp<TUDof> uFL; /**< @brief Left reconstructed face values (face-located, output). */
736 ssp<TUDof> uFR; /**< @brief Right reconstructed face values (face-located, output). */
737 ssp<TUGrad> uGradFF; /**< @brief Face-averaged gradient (face-located, output). */
738 std::vector<ssp<TUScalar>> uScalarFL; /**< @brief Left reconstructed scalar face values (output). */
739 std::vector<ssp<TUScalar>> uScalarFR; /**< @brief Right reconstructed scalar face values (output). */
740 std::vector<ssp<TUScalarGrad>> uScalarGradFF; /**< @brief Face-averaged scalar gradients (output). */
741
742 /** @brief Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer. */
758 /**
759 * @brief Validates member arrays, auto-detecting cell vs. face location by name suffix.
760 * @param self Reference to the owning Evaluator.
761 */
762 void Validate(Evaluator &self)
763 {
764 DeviceBackend B = self.device();
765 using namespace std::string_literals;
766
767 auto validate_member = [&](std::string name, auto &v)
768 {
769 int varloc = 0;
770 auto name_last2 = name.substr(std::max(name.size(), 2ul) - 2, 2);
771 if (name_last2 == "FL" || name_last2 == "FR" || name_last2 == "FF")
772 varloc = 1;
773 if constexpr (is_ssp_v<remove_cvref_t<decltype(v)>>)
774 self.checkValidUDof(v, name,
775 varloc, true, B);
776
777 else
778
779 for (size_t i = 0; i < v.size(); i++)
780 self.checkValidUDof(v[i], name + "_"s + std::to_string(i),
781 varloc, true, B);
782 };
786 }
787 };
788
789 /**
790 * @brief Performs 2nd-order face value reconstruction from cell-centered data.
791 *
792 * Extrapolates cell values and gradients to face quadrature points to produce left/right
793 * face states. Applies boundary conditions at domain boundaries via the BC handler.
794 *
795 * @param arg Packed input/output arguments.
796 */
797 void RecFace2nd(RecFace2nd_Arg &arg);
798
799 /**
800 * @brief Packed argument struct for 2nd-order inviscid (and eventually viscous) flux evaluation.
801 *
802 * The largest argument struct, combining cell-centered state and gradients,
803 * face-reconstructed left/right values, thermodynamic scalars, viscosity, eigenvalue
804 * corrections, face flux output, and accumulated RHS output.
805 */
806 struct Flux2nd_Arg : public EvaluatorArgBase<Flux2nd_Arg>
807 {
809 ssp<TUDof> u; /**< @brief Conservative state (cell-centered, input). */
810 ssp<TUGrad> uGrad; /**< @brief Gradient of conservative state (input). */
811 std::vector<ssp<TUScalar>> uScalar; /**< @brief Transported scalar fields (input). */
812 std::vector<ssp<TUScalarGrad>> uScalarGrad; /**< @brief Gradients of transported scalars (input). */
813 ssp<TUDof> uPrim; /**< @brief Primitive state (cell-centered, input). */
814 ssp<TUGrad> uGradPrim; /**< @brief Gradient of primitive state (input). */
815 std::vector<ssp<TUScalar>> uScalarPrim; /**< @brief Primitive transported scalars (input). */
816 std::vector<ssp<TUScalarGrad>> uScalarGradPrim; /**< @brief Gradients of primitive scalars (input). */
817 ssp<TUScalar> p; /**< @brief Pressure (cell-centered, input). */
818 ssp<TUScalar> T; /**< @brief Temperature (cell-centered, input). */
819 ssp<TUScalar> a; /**< @brief Speed of sound (cell-centered, input). */
820 ssp<TUScalar> mu; /**< @brief Total viscosity (cell-centered, input). */
821 std::vector<ssp<TUScalar>> muComp; /**< @brief Component-wise viscosity contributions (input). */
822 ssp<TUScalar> gamma; /**< @brief Ratio of specific heats (cell-centered, input). */
823 ssp<TUScalar> deltaLamCell; /**< @brief Per-cell eigenvalue difference for H-correction (input). */
824
825 ssp<TUDof> uFL; /**< @brief Left reconstructed face values (face-located, input). */
826 ssp<TUDof> uFR; /**< @brief Right reconstructed face values (face-located, input). */
827 ssp<TUGrad> uGradFF; /**< @brief Face-averaged gradient (face-located, input). */
828 std::vector<ssp<TUScalar>> uScalarFL; /**< @brief Left reconstructed scalar face values (input). */
829 std::vector<ssp<TUScalar>> uScalarFR; /**< @brief Right reconstructed scalar face values (input). */
830 std::vector<ssp<TUScalarGrad>> uScalarGradFF; /**< @brief Face-averaged scalar gradients (input). */
831
832 ssp<TUScalar> pFL; /**< @brief Left face pressure (face-located, input). */
833 ssp<TUScalar> pFR; /**< @brief Right face pressure (face-located, input). */
834
835 // out
836 ssp<TUDof> fluxFF; /**< @brief Numerical flux at each face (face-located, output). */
837 std::vector<ssp<TUScalar>> fluxScalarFF; /**< @brief Scalar numerical flux at each face (output). */
838 // out added
839 ssp<TUDof> rhs; /**< @brief Accumulated right-hand-side residual (cell-centered, in-out). */
840 std::vector<ssp<TUScalar>> rhsScalar; /**< @brief Accumulated scalar RHS residual (cell-centered, in-out). */
841
842 /** @brief Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer. */
878 /**
879 * @brief Validates member arrays, auto-detecting cell vs. face location by name suffix.
880 * @param self Reference to the owning Evaluator.
881 */
882 void Validate(Evaluator &self)
883 {
884 DeviceBackend B = self.device();
885 using namespace std::string_literals;
886
887 auto validate_member = [&](std::string name, auto &v)
888 {
889 int varloc = 0;
890 auto name_last2 = name.substr(std::max(name.size(), 2ul) - 2, 2);
891 if (name_last2 == "FL" || name_last2 == "FR" || name_last2 == "FF")
892 varloc = 1;
893 if constexpr (is_ssp_v<remove_cvref_t<decltype(v)>>)
894 self.checkValidUDof(v, name,
895 varloc, true, B);
896
897 else
898
899 for (size_t i = 0; i < v.size(); i++)
900 self.checkValidUDof(v[i], name + "_"s + std::to_string(i),
901 varloc, true, B);
902 };
906 }
907 };
908
909 /**
910 * @brief Evaluates 2nd-order inviscid (Roe) flux and accumulates into the cell RHS residual.
911 *
912 * First pass: computes face-level numerical flux using Roe-averaged states with
913 * eigenvalue fixing (H-correction). Second pass: scatters face fluxes to cell RHS
914 * weighted by face area / cell volume.
915 *
916 * @param arg Packed input/output arguments (state, face values, flux, RHS).
917 */
918 void Flux2nd(Flux2nd_Arg &arg);
919 };
920
921 /********************************************************************************** */
922
923 /********************************************************************************** */
924
925}
Degree-of-freedom array with vector-space operations (MPI-collective).
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE_NO_EMPTY_CTOR(T, T_Self)
Definition Defines.hpp:91
Helpers for shipping an array-of-views (e.g., ArrayDeviceView) to the device in one contiguous buffer...
Device memory abstraction layer with backend-specific storage and factory creation.
Assertion / error-handling macros and supporting helper functions.
#define DNDS_check_throw_info(expr, info)
Same as DNDS_check_throw but attaches a user-supplied info message to the thrown std::runtime_error.
Definition Errors.hpp:96
#define DNDS_check_throw(expr)
Runtime check active in both debug and release builds. Throws std::runtime_error if expr evaluates to...
Definition Errors.hpp:89
Core type definitions and utilities for the EulerP alternative Navier-Stokes evaluator module.
Boundary condition types, implementations, and handler for the EulerP module.
Physics model definitions for the EulerP module: gas properties, state conversions,...
Tiny reflection-style helpers (MemberRef, MemberPtr) and for_each_member_* visitors used by config / ...
#define DNDS_MAKE_1_MEMBER_PTR_SELF(member)
Like DNDS_MAKE_1_MEMBER_PTR but uses the surrounding t_self alias, common in DNDSR member definitions...
void to_device(DeviceBackend backend)
Mirror both father and son to the given device backend.
void to_host()
Bring both father and son mirrors back to host memory.
Device-callable view of the BC handler providing BC lookup by zone ID.
CRTP base class for packed kernel argument structs used by the Evaluator.
Definition EulerP.hpp:92
JSON-configurable settings for the Evaluator.
void merge_patch(const t_jsonconfig &config_in)
Validates and applies a JSON merge-patch to the configuration.
const t_jsonconfig & config() const
Returns a const reference to the underlying JSON configuration.
EvaluatorConfig()
Constructs the config with default values (threadsPerBlock=128, etc.).
void valid_patch_keys(const t_jsonconfig &config_in)
Validates that all keys in config_in exist in the current defaults.
Device-callable view of the Evaluator, combining finite volume, BC handler, and physics views.
t_bcHandler bcHandler
Device view of the boundary condition handler.
t_fv fv
Device view of the finite volume / VFV reconstruction object.
t_physics physics
Device view of the gas physics model.
Main EulerP evaluator orchestrating CFD kernel dispatch for compressible N-S solvers.
const t_jsonconfig & get_config()
Returns a const reference to the JSON configuration.
void RecGradient(RecGradient_Arg &arg)
Performs Green-Gauss gradient reconstruction with Barth-Jespersen limiting.
t_bcHandler bcHandler
Shared pointer to the boundary condition handler.
void to_host()
Transfers all sub-objects and face buffers from device memory back to host.
void Flux2nd(Flux2nd_Arg &arg)
Evaluates 2nd-order inviscid (Roe) flux and accumulates into the cell RHS residual.
void checkValidUDof(const ssp< TPair > &u, const std::string &name="unknown", int varloc=0, bool includeSon=true, DeviceBackend B=DeviceBackend::Unknown, bool optional=false)
Validates that a DOF array pair has the expected sizes and device placement.
DeviceBackend device()
Queries and validates the device backend across all sub-objects.
void PrintDataVTKHDF(std::string fname, std::string series_name, std::vector< ssp< TUScalar > > &arrCellCentScalar, const std::vector< std::string > &arrCellCentScalar_names_in, std::vector< ssp< TUVec > > &arrCellCentVec, const std::vector< std::string > &arrCellCentVec_names_in, std::vector< ssp< TUScalar > > &arrNodeScalar, const std::vector< std::string > &arrNodeScalar_names_in, std::vector< ssp< TUVec > > &arrNodeVec, const std::vector< std::string > &arrNodeVec_names_in, ssp< TUDof > uPrimCell, ssp< TUDof > uPrimNode, double t)
Writes cell-centered and node-centered field data to a VTK-HDF5 file.
void PrepareFaceBuffer(int nVarsScalar)
Prepares all face buffers (DOF + scalars) for left and right states.
void to_device(DeviceBackend B)
Transfers all sub-objects and face buffers to the specified device backend.
void EstEigenDt(EstEigenDt_Arg &arg)
Estimates per-face eigenvalues and computes per-cell local time steps.
t_config config
Runtime configuration (Riemann solver, CUDA settings, etc.).
TUDof u_face_bufferL
Left-side face DOF buffer for boundary value storage.
void BuildFaceBufferDof(TUDof &u)
Allocates or resizes the face DOF buffer u to match the current mesh face count.
void BuildFaceBufferDofScalar(TUScalar &u)
Allocates or resizes a scalar face buffer to match the current mesh face count.
void Cons2Prim(Cons2Prim_Arg &arg)
Converts conservative variables to primitive variables (no gradients or viscosity).
t_fv fv
Shared pointer to the Compact Finite Volume (VFV) reconstruction object.
void RecFace2nd(RecFace2nd_Arg &arg)
Performs 2nd-order face value reconstruction from cell-centered data.
void set_config(Tc &&config_in)
Merges a JSON patch into the evaluator configuration.
t_physics physics
Shared pointer to the gas physics model.
TUDof u_face_bufferR
Right-side face DOF buffer for boundary value storage.
static auto device_array_list_Buffer()
Returns a tuple of member pointers to face buffer arrays for device transfer.
std::vector< TUScalar > uScalar_face_bufferR
Right-side face scalar buffers for additional transported scalars.
Evaluator(t_fv n_fv, t_bcHandler n_bcHandler, t_physics n_physics)
Constructs the Evaluator with the given finite volume, BC handler, and physics objects.
t_deviceView< B > deviceView()
Creates a device view for backend B from the current evaluator state.
void Cons2PrimMu(Cons2PrimMu_Arg &arg)
Converts conservative variables to primitive variables and computes viscosity.
std::vector< TUScalar > uScalar_face_bufferL
Left-side face scalar buffers for additional transported scalars.
Namespace for the EulerP alternative evaluator module with GPU support.
Definition EulerP.hpp:29
DeviceBackend
Enumerates the backends a DeviceStorage / Array can live on.
@ Unknown
Unset / sentinel.
@ Host
Plain CPU memory.
const char * device_backend_name(DeviceBackend B)
Canonical string name for a DeviceBackend (used in log messages).
constexpr bool is_ssp_v
Definition Defines.hpp:152
std::remove_cv_t< std::remove_reference_t< T > > remove_cvref_t
Convenience remove_cv + remove_reference composition (C++17 port of C++20's std::remove_cvref_t).
Definition Defines.hpp:156
void for_each_member_ptr_list(Class &obj, TList &&obj_member_ptr_list, F &&f)
Invoke f(name, obj.*ptr) for every member in a list of MemberPtr.
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
Definition Defines.hpp:138
ssp< T > make_ssp(Args &&...args)
Type-safe replacement for DNDS_MAKE_SSP. Creates ssp<T> with forwarded args.
Definition Defines.hpp:255
nlohmann::ordered_json t_jsonconfig
Project-wide JSON type alias: nlohmann/json with ordered keys.
Definition JsonUtil.hpp:19
ssp< TArray > father
Owned-side array (must be resized before ghost setup).
ssp< TArray > son
Ghost-side array (sized automatically by createMPITypes / BorrowAndPull).
Packed argument struct for conservative-to-primitive conversion with viscosity computation.
ssp< TUGrad > uGrad
Gradient of conservative state (input).
static auto member_list()
Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer.
ssp< TUScalar > gamma
Ratio of specific heats (output).
ssp< TUScalar > mu
Total (laminar + turbulent) viscosity (output).
std::vector< ssp< TUScalar > > muComp
Component-wise viscosity contributions (output).
ssp< TUScalar > a
Speed of sound (output).
ssp< TUDof > uPrim
Primitive state (output).
std::vector< ssp< TUScalarGrad > > uScalarGradPrim
Gradients of primitive scalars (output).
ssp< TUGrad > uGradPrim
Gradient of primitive state (output).
std::vector< ssp< TUScalar > > uScalar
Transported scalar fields (input).
void Validate(Evaluator &self)
Validates all member arrays against the mesh topology and device backend.
std::vector< ssp< TUScalarGrad > > uScalarGrad
Gradients of transported scalars (input).
ssp< TUScalar > p
Pressure (output).
ssp< TUScalar > T
Temperature (output).
ssp< TUDof > u
Conservative state (input).
std::vector< ssp< TUScalar > > uScalarPrim
Primitive transported scalars (output).
Packed argument struct for conservative-to-primitive conversion without gradients or viscosity.
ssp< TUScalar > a
Speed of sound (output).
ssp< TUScalar > p
Pressure (output).
static auto member_list()
Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer.
ssp< TUScalar > gamma
Ratio of specific heats (output).
ssp< TUScalar > T
Temperature (output).
void Validate(Evaluator &self)
Validates all member arrays against the mesh topology and device backend.
ssp< TUDof > u
Conservative state (input).
std::vector< ssp< TUScalar > > uScalarPrim
Primitive transported scalars (output).
ssp< TUDof > uPrim
Primitive state (output).
std::vector< ssp< TUScalar > > uScalar
Transported scalar fields (input).
Packed argument struct for eigenvalue estimation and local time-step computation.
ssp< TUDof > u
Conservative state (cell-centered, input).
ssp< TUScalar > deltaLamFace
Per-face eigenvalue difference for H-correction (output).
static auto member_list()
Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer.
ssp< TUScalar > faceLamVisEst
Per-face viscous eigenvalue estimate (output).
ssp< TUScalar > deltaLamCell
Per-cell maximum eigenvalue difference (output).
ssp< TUScalarGrad > faceLamEst
Per-face eigenvalue estimates [lam-, lam0, lam+] (output).
ssp< TUScalar > muCell
Per-cell total viscosity (input).
ssp< TUScalar > aCell
Per-cell speed of sound (input).
ssp< TUScalar > dt
Per-cell local time step (output).
void Validate(Evaluator &self)
Validates all member arrays, distinguishing cell-located from face-located fields.
Packed argument struct for 2nd-order inviscid (and eventually viscous) flux evaluation.
std::vector< ssp< TUScalar > > uScalarFR
Right reconstructed scalar face values (input).
std::vector< ssp< TUScalarGrad > > uScalarGradFF
Face-averaged scalar gradients (input).
std::vector< ssp< TUScalarGrad > > uScalarGrad
Gradients of transported scalars (input).
ssp< TUDof > uPrim
Primitive state (cell-centered, input).
ssp< TUScalar > T
Temperature (cell-centered, input).
std::vector< ssp< TUScalar > > fluxScalarFF
Scalar numerical flux at each face (output).
ssp< TUGrad > uGradPrim
Gradient of primitive state (input).
std::vector< ssp< TUScalar > > muComp
Component-wise viscosity contributions (input).
std::vector< ssp< TUScalar > > uScalar
Transported scalar fields (input).
ssp< TUGrad > uGrad
Gradient of conservative state (input).
ssp< TUScalar > pFL
Left face pressure (face-located, input).
static auto member_list()
Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer.
ssp< TUGrad > uGradFF
Face-averaged gradient (face-located, input).
std::vector< ssp< TUScalar > > rhsScalar
Accumulated scalar RHS residual (cell-centered, in-out).
ssp< TUScalar > gamma
Ratio of specific heats (cell-centered, input).
std::vector< ssp< TUScalar > > uScalarPrim
Primitive transported scalars (input).
ssp< TUScalar > mu
Total viscosity (cell-centered, input).
ssp< TUDof > uFR
Right reconstructed face values (face-located, input).
std::vector< ssp< TUScalar > > uScalarFL
Left reconstructed scalar face values (input).
ssp< TUDof > u
Conservative state (cell-centered, input).
ssp< TUScalar > deltaLamCell
Per-cell eigenvalue difference for H-correction (input).
ssp< TUScalar > a
Speed of sound (cell-centered, input).
void Validate(Evaluator &self)
Validates member arrays, auto-detecting cell vs. face location by name suffix.
ssp< TUDof > uFL
Left reconstructed face values (face-located, input).
ssp< TUScalar > pFR
Right face pressure (face-located, input).
std::vector< ssp< TUScalarGrad > > uScalarGradPrim
Gradients of primitive scalars (input).
ssp< TUDof > fluxFF
Numerical flux at each face (face-located, output).
ssp< TUScalar > p
Pressure (cell-centered, input).
ssp< TUDof > rhs
Accumulated right-hand-side residual (cell-centered, in-out).
Packed argument struct for 2nd-order face value reconstruction.
std::vector< ssp< TUScalar > > uScalarFR
Right reconstructed scalar face values (output).
std::vector< ssp< TUScalarGrad > > uScalarGradFF
Face-averaged scalar gradients (output).
std::vector< ssp< TUScalar > > uScalarFL
Left reconstructed scalar face values (output).
void Validate(Evaluator &self)
Validates member arrays, auto-detecting cell vs. face location by name suffix.
ssp< TUGrad > uGradFF
Face-averaged gradient (face-located, output).
std::vector< ssp< TUScalar > > uScalar
Cell-centered transported scalars (input).
ssp< TUDof > uFL
Left reconstructed face values (face-located, output).
ssp< TUGrad > uGrad
Cell gradient of conservative state (input).
ssp< TUDof > u
Conservative state (cell-centered, input).
static auto member_list()
Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer.
ssp< TUDof > uFR
Right reconstructed face values (face-located, output).
std::vector< ssp< TUScalarGrad > > uScalarGrad
Gradients of transported scalars (input).
Packed argument struct for Green-Gauss gradient reconstruction with Barth-Jespersen limiting.
std::vector< ssp< TUScalar > > uScalar
Additional transported scalar fields (cell-centered).
ssp< TUDof > u
Conservative state vector (cell-centered, nVarsFlow components).
void Validate(Evaluator &self)
Validates all member arrays against the mesh topology and device backend.
std::vector< ssp< TUScalarGrad > > uScalarGrad
Gradients of transported scalars (in-out).
ssp< TUGrad > uGrad
Gradient of conservative state (in-out: reconstructed by Green-Gauss).
static auto member_list()
Returns a tuple of member-to-pointer mappings for CRTP iteration / device transfer.
Non-trivially-copyable device view holding shared_ptr to fv and device views of BC/physics.
t_physics::element_type::t_deviceView< B > physics
t_deviceView(const t_deviceView &R)=delete
t_deviceView & operator=(t_deviceView &&R)=delete
t_bcHandler::element_type::t_deviceView< B > bcHandler
t_deviceView & operator=(const t_deviceView &R)=delete
t_deviceView(t_deviceView &&R) noexcept=default
only permit moving to avoid host_device_vector to change
Device-callable view of physics parameters providing thermodynamic operations.
Tag type for naming objects created via make_ssp.
Definition Defines.hpp:249
Eigen::Matrix< real, 5, 1 > v