svMultiPhysics
Loading...
Searching...
No Matches
CoupledBoundaryCondition.h
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef COUPLED_BOUNDARY_CONDITION_H
5#define COUPLED_BOUNDARY_CONDITION_H
6
7#include <string>
8#include <memory>
9#include <exception>
10#include <optional>
11#include <unordered_map>
12#include <utility>
13#include "consts.h"
14#include "CmMod.h"
15#include "SolutionStates.h"
16
17// Forward declarations to avoid heavy includes
19class faceType;
20class ComMod;
21
22namespace fsi_linear_solver {
23 class FSILS_faceType;
24}
25
26/// @brief Cap-surface nodal state: \c n_cap columns, column \c a is cap node \c a (same order as cap face \c gN / broadcast id list).
28 int n_cap = 0;
29 Array<double> x;
30 Array<double> Do;
31 Array<double> Dn;
32 Array<double> Yo;
33 Array<double> Yn;
34
35 void clear()
36 {
37 n_cap = 0;
38 x.resize(0, 0);
39 Do.resize(0, 0);
40 Dn.resize(0, 0);
41 Yo.resize(0, 0);
42 Yn.resize(0, 0);
43 }
44};
45
46/// @brief Base exception for capping surface (cap VTP) errors.
47///
48/// These indicate fatal errors while loading or using a cap surface. They are not
49/// expected to be recovered; callers may catch \ref CappingSurfaceBaseException to
50/// handle all cap-related failures.
51class CappingSurfaceBaseException : public std::exception {
52public:
53 explicit CappingSurfaceBaseException(std::string msg) : message_(std::move(msg)) {}
54
55 const char* what() const noexcept override { return message_.c_str(); }
56
57private:
58 std::string message_;
59};
60
61/// @brief Cap VTP file cannot be opened.
63public:
64 explicit CappingSurfaceFileException(const std::string& path)
65 : CappingSurfaceBaseException("[CappingSurface::load_from_vtp] Cannot open cap VTP file '" + path +
66 "' for reading.") {}
67};
68
69/// @brief VTP read, parse, or validation error during cap load.
71public:
72 explicit CappingSurfaceVtpException(const std::string& detail)
73 : CappingSurfaceBaseException("[CappingSurface::load_from_vtp] " + detail) {}
74};
75
76/// @brief Cap mesh shares no nodes with the coupled boundary face.
78public:
79 explicit CappingSurfaceCouplingTopologyException(const std::string& vtp_path, const std::string& coupled_face_name)
80 : CappingSurfaceBaseException("[CappingSurface::load_from_vtp] Cap VTP file '" + vtp_path +
81 "' has no GlobalNodeID entries in common with coupled face '" +
82 coupled_face_name + "'. The cap must share at least one mesh node with that face.") {}
83};
84
85/// @brief Cap VTP uses an unsupported cell type (only TRI3 is supported).
87public:
88 explicit CappingSurfaceUnsupportedCellException(int vtk_cell_type)
89 : CappingSurfaceBaseException("[CappingSurface::load_from_vtp] Unsupported cap cell type " +
90 std::to_string(vtk_cell_type) + ". Only VTK_TRIANGLE (TRI3) is supported.") {}
91};
92
93/// @brief Cap VTP connectivity does not match expected TRI3 topology.
95public:
96 explicit CappingSurfaceInvalidElementNodesException(int eNoN, int expected)
97 : CappingSurfaceBaseException("[CappingSurface::load_from_vtp] Invalid nodes-per-element for triangle cap: " +
98 std::to_string(eNoN) + " (expected " + std::to_string(expected) + ").") {}
99};
100
101/// @brief Geometry or Jacobian error during cap surface integration.
103public:
104 explicit CappingSurfaceGeometryException(const std::string& detail) : CappingSurfaceBaseException(detail) {}
105};
106
107/// @brief Cap face quadrature (shape functions on TRI3) setup failed.
109public:
110 explicit CappingSurfaceQuadratureException(const std::string& nested)
111 : CappingSurfaceBaseException("[CappingSurface::init_cap_face_quadrature] Failed to initialize cap face shape "
112 "functions: " + nested) {}
113};
114
115/// @brief Inconsistent cap connectivity or assembly indexing.
117public:
118 explicit CappingSurfaceAssemblyException(const std::string& detail) : CappingSurfaceBaseException(detail) {}
119};
120
121/// @brief Failure copying a \ref CappingSurface or its internal face.
123public:
124 explicit CappingSurfaceCopyException(std::string msg) : CappingSurfaceBaseException(std::move(msg)) {}
125};
126
127/// @brief Capping surface geometry and integration for a coupled boundary.
129 public:
130 /// @brief Default constructor.
131 CappingSurface() = default;
132 /// @brief Copy constructor.
133 CappingSurface(const CappingSurface& other);
134 /// @brief Copy assignment operator.
136 /// @brief Move constructor.
137 CappingSurface(CappingSurface&& other) noexcept = default;
138 /// @brief Move assignment operator.
139 CappingSurface& operator=(CappingSurface&& other) noexcept = default;
140
141 /// @brief Load the cap face from a VTP file.
142 void load_from_vtp(const std::string& vtp_file_path, const faceType& coupled_face,
143 const std::string& coupled_face_name);
144
145 /// @brief Initialize the cap face quadrature.
146 void init_cap_face_quadrature(const ComMod& com_mod);
147
148 /// @brief Initialize the cap contribution storage.
149 void initialize_valM();
150
151 /// Surface velocity flux through the cap using \a st columns indexed by cap IEN / GlobalNodeID (master / serial).
152 double integrate_velocity_flux(const CapGlobalMeshState& st, bool use_Yn_velocity,
153 consts::MechanicalConfigurationType cfg);
154
155 /// @brief Compute the cap contribution to the linear solver face (fills \ref valM_; safe under \c const *this).
156 void compute_valM(consts::MechanicalConfigurationType cfg, const CapGlobalMeshState& st) const;
157
158 /// @brief Get the cap face.
159 const faceType* face() const { return face_.get(); }
160
161 /// @brief Get the cap contribution.
162 const Array<double>& valM() const { return valM_; }
163
164 private:
165 /// @brief The cap face.
166 std::unique_ptr<faceType> face_;
167 /// @brief The global node IDs.
168 Vector<int> global_node_ids_;
169 /// @brief The normals.
170 Array<double> normals_;
171
172 /// @brief The number of spatial dimensions (3D).
173 static constexpr int cap_nsd_ = 3;
174 /// @brief The number of independent spatial dimensions (2D).
175 static constexpr int cap_insd_ = 2;
176
177 /// @brief Update the element position using cap-compact mesh columns (\a gn_to_cap_local maps global node id to column).
178 Array<double> update_element_position_global(int e, consts::MechanicalConfigurationType cfg,
179 const Array<double>& mesh_x, const Array<double>& mesh_Do,
180 const Array<double>& mesh_Dn,
181 const std::unordered_map<int, int>& gn_to_cap_local) const;
182
183 /// @brief Compute the Jacobian and normal vector for a given element and Gauss point.
184 std::pair<double, Vector<double>> compute_jacobian_and_normal(const Array<double>& xl, int e, int g) const;
185
186 /// @brief Cap contribution to the linear solver face; \c mutable so it can be refreshed under \c const *this.
187 mutable Array<double> valM_;
188 };
189
190/// @brief Object-oriented Coupled boundary condition
191///
192/// This class provides an interface for:
193/// - computing flowrates on the face for coupling, and
194/// - getting/setting pressure values from/to a 0D solver, and
195/// - (optionally) loading a cap face VTP for struct/ustruct coupling.
196///
197/// The class manages its own coupling data. svZeroD interface code accesses
198/// coupled boundary conditions by iterating through com_mod.eq[].bc[].
200private:
201 /// @brief Data members for BC
202 const faceType* face_ = nullptr; ///< Face associated with the BC (not owned by CoupledBoundaryCondition)
203 std::string cap_face_vtp_file_; ///< Path to VTP file (empty if no cap)
204
205 /// @brief 3D boundary condition type (Dirichlet or Neumann) for this Coupled BC.
206 consts::BoundaryConditionType bc_type_ = consts::BoundaryConditionType::bType_Neu;
207
208 /// @brief svZeroD coupling data
209 std::string block_name_; ///< Block name in svZeroDSolver configuration
210 std::string face_name_; ///< Face name from the mesh
211 /// @brief svOneD coupling data
212 std::string oned_input_file_; ///< Path to svOneDSolver input file (empty for svZeroD BCs)
213 /// @brief Pressure ramp parameters for 1D coupling initialization.
214 int oned_ramp_steps_ = 0; ///< Number of ramp steps (0 = disabled)
215 double oned_ramp_ref_pressure_ = 0.0; ///< Reference pressure at step used for ramping pressure
216
217 /// @brief Under-relaxation factor for pressure or flowrate passed to the 1D solver.
218 /// Applied as: P_sent = omega * P_new + (1 - omega) * P_prev_sent.
219 /// Range: (0, 1]. Default 1.0 = no relaxation.
220 double oned_relax_factor_ = 1.0;
221
222 /// @brief Ramp/relax runtime state (shared by both 0D and 1D coupling).
223 /// Updated only on committed ('L') time steps.
224 int ramp_step_count_ = 0; ///< Number of committed steps taken (used for ramp fraction).
225 double P_prev_sent_old_ = 0.0; ///< Under-relaxed pressure sent at t_old on last 'L' step (DIR input).
226 double P_prev_sent_new_ = 0.0; ///< Under-relaxed pressure sent at t_new on last 'L' step (DIR input).
227 double Q_prev_sent_ = 0.0; ///< Under-relaxed flow output on last 'L' step (DIR output).
228 double P_neu_prev_ = 0.0; ///< Under-relaxed pressure output on last 'L' step (NEU output).
229 double Q_input_prev_old_ = 0.0; ///< Under-relaxed flow sent at t_old on last 'L' step (NEU input).
230 double Q_input_prev_new_ = 0.0; ///< Under-relaxed flow sent at t_new on last 'L' step (NEU input).
231
232 /// @brief Flowrate data
233 double Qo_ = 0.0; ///< Flowrate at old timestep (t_n)
234 double Qn_ = 0.0; ///< Flowrate at new timestep (t_{n+1})
235
236 /// @brief Pressure data
237 double Po_ = 0.0; ///< Pressure at old timestep (for completeness)
238 double Pn_ = 0.0; ///< Pressure at new timestep (for completeness)
239 double pressure_ = 0.0; ///< Current pressure value from 0D solver (result)
240
241 /// @brief svZeroD solution IDs
242 int flow_sol_id_ = -1; ///< ID in svZeroD solution vector for flow
243 int pressure_sol_id_ = -1; ///< ID in svZeroD solution vector for pressure
244 double in_out_sign_ = 1.0; ///< Sign for inlet/outlet (+1 inlet to 0D model, -1 outlet)
245
246 /// @brief Configuration for flowrate computation
247 bool follower_pressure_load_ = false; ///< Whether to use follower pressure load (for struct/ustruct)
248 consts::EquationType phys_ = consts::EquationType::phys_NA; ///< Equation physics for this coupled BC (set at construction)
249 consts::MechanicalConfigurationType flowrate_cfg_o_ = consts::MechanicalConfigurationType::reference;
250 consts::MechanicalConfigurationType flowrate_cfg_n_ = consts::MechanicalConfigurationType::reference;
251
252 /// @brief True if this BC uses a chamber cap (broadcast in distribute so all ranks agree).
253 bool has_cap_ = false;
254 /// @brief True on ranks that hold \ref cap_ mesh/quadrature (MPI master when \ref has_cap_; true in serial when cap loaded).
255 bool owns_cap_ = false;
256 /// @brief Number of cap surface nodes (same as \ref cap_mesh_global_node_ids_.size(); broadcast in \c distribute()).
257 int cap_n_no_ = 0;
258 /// @brief Global mesh node id per cap surface node column (0-based solver ids; broadcast in \c distribute()).
259 Vector<int> cap_mesh_global_node_ids_;
260 /// @brief Cached map: global cap node id -> cap column index (derived from \ref cap_mesh_global_node_ids_).
261 std::unordered_map<int, int> cap_g_to_cap_col_;
262 /// @brief Cap geometry on ranks with \ref owns_cap_; empty on non-owning MPI ranks.
263 std::optional<CappingSurface> cap_;
264 /// @brief Cap-only mesh state for integration (columns 0..n_cap-1); refreshed by \ref gather_global_mesh_state.
265 mutable CapGlobalMeshState cap_global_mesh_state_;
266
267 /// @brief Simulation \c CmMod copy; set in \c distribute() for cap MPI (e.g. \c copy_cap_surface_to_linear_solver_face).
268 CmMod cm_mod_{};
269
270 /// Build \ref cap_g_to_cap_col_ from \ref cap_mesh_global_node_ids_.
271 void rebuild_cap_global_to_col_map();
272
273 /// Fill \ref cap_global_mesh_state_ with cap nodes only (uses \ref cap_mesh_global_node_ids_).
274 void gather_global_mesh_state(ComMod& com_mod, const CmMod& cm_mod, const SolutionStates& solutions, bool gather_Y) const;
275
276
277public:
278 /// @brief Default constructor - creates an uninitialized object
280
281 /// @brief Destructor
283
284 /// @brief Copy constructor
286
287 /// @brief Copy assignment operator
289
290 /// @brief Move constructor
292
293 /// @brief Move assignment operator
295
296 /// @brief Construct with a face association (no VTP data loaded)
297 /// @param bc_type The 3D boundary condition type (must be bType_Dir or bType_Neu)
298 /// @param face Face associated with this BC
299 /// @param face_name Face name from the mesh
300 /// @param block_name Block name in svZeroDSolver configuration
301 /// @param phys Equation physics for this boundary (struct, fluid, FSI, etc.)
302 /// @param follower_pressure_load Follower pressure load flag (struct/ustruct); false for fluid-like physics
303 CoupledBoundaryCondition(consts::BoundaryConditionType bc_type, const faceType& face, const std::string& face_name,
304 const std::string& block_name, consts::EquationType phys, bool follower_pressure_load);
305
306 /// @brief Construct and optionally point to a cap face VTP file
307 /// @param bc_type The 3D boundary condition type (must be bType_Dir or bType_Neu)
308 /// @param face Face associated with this BC
309 /// @param face_name Face name from the mesh
310 /// @param block_name Block name in svZeroDSolver configuration
311 /// @param cap_face_vtp_file Path to the cap face VTP file
312 /// @param phys Equation physics for this boundary (struct, fluid, FSI, etc.)
313 /// @param follower_pressure_load Follower pressure load flag (struct/ustruct); false for fluid-like physics
314 CoupledBoundaryCondition(consts::BoundaryConditionType bc_type, const faceType& face, const std::string& face_name,
315 const std::string& block_name, const std::string& cap_face_vtp_file,
316 consts::EquationType phys, bool follower_pressure_load);
317
318 /// @brief Get the 3D BC type for this Coupled boundary condition.
319 consts::BoundaryConditionType get_bc_type() const { return bc_type_; }
320
321 // =========================================================================
322 // svZeroD block configuration
323 // =========================================================================
324
325 /// @brief Get the svZeroD block name
326 /// @return Block name
327 const std::string& get_block_name() const;
328
329 /// @brief Get the svOneD input file path
330 /// @return Path to the 1D solver input file (empty for svZeroD BCs)
331 const std::string& get_oned_input_file() const;
332
333 /// @brief Set the svOneD input file path
334 void set_oned_input_file(const std::string& path);
335
336 bool is_svOneD_face() const { return !oned_input_file_.empty(); }
337
338 /// @brief Get the pressure ramp step count (0 = disabled).
339 int get_oned_ramp_steps() const { return oned_ramp_steps_; }
340
341 /// @brief Set the pressure ramp parameters for 1D coupling initialization.
342 /// @param steps Number of time steps over which to ramp (0 = disabled).
343 /// @param P_ref Reference pressure at step 0 (typically the 1D initial pressure).
344 void set_oned_ramp(int steps, double P_ref) {
345 oned_ramp_steps_ = steps;
346 oned_ramp_ref_pressure_ = P_ref;
347 }
348
349 /// @brief Get the ramp reference pressure.
350 double get_oned_ramp_ref_pressure() const { return oned_ramp_ref_pressure_; }
351
352 /// @brief Get the under-relaxation factor for DIR coupling pressure (1.0 = no relaxation).
353 double get_oned_relax_factor() const { return oned_relax_factor_; }
354
355 /// @brief Set the under-relaxation factor for DIR coupling pressure.
356 /// @param omega Relaxation factor in (0, 1]. 1.0 disables relaxation.
357 void set_oned_relax_factor(double omega) { oned_relax_factor_ = omega; }
358
359 // =========================================================================
360 // Ramp/relax runtime state accessors (shared by 0D and 1D coupling)
361 // =========================================================================
362
363 /// @brief Get the number of committed time steps (used for ramp fraction).
364 int get_ramp_step_count() const { return ramp_step_count_; }
365
366 /// @brief Increment the committed step counter (call once per 'L' step).
367 void increment_ramp_step_count() { ramp_step_count_++; }
368
369 /// @brief Get the under-relaxed pressure sent at t_old on the last 'L' step (DIR input).
370 double get_P_prev_sent_old() const { return P_prev_sent_old_; }
371
372 /// @brief Get the under-relaxed pressure sent at t_new on the last 'L' step (DIR input).
373 double get_P_prev_sent_new() const { return P_prev_sent_new_; }
374
375 /// @brief Set the DIR input pressure history (call on 'L' steps).
376 void set_P_prev_sent(double old_val, double new_val) {
377 P_prev_sent_old_ = old_val;
378 P_prev_sent_new_ = new_val;
379 }
380
381 /// @brief Get the under-relaxed flow output on the last 'L' step (DIR output).
382 double get_Q_prev_sent() const { return Q_prev_sent_; }
383
384 /// @brief Set the DIR output flow history (call on 'L' steps).
385 void set_Q_prev_sent(double Q) { Q_prev_sent_ = Q; }
386
387 /// @brief Get the under-relaxed pressure output on the last 'L' step (NEU output).
388 double get_P_neu_prev() const { return P_neu_prev_; }
389
390 /// @brief Set the NEU output pressure history (call on 'L' steps).
391 void set_P_neu_prev(double P) { P_neu_prev_ = P; }
392
393 /// @brief Get the under-relaxed flow sent at t_old on the last 'L' step (NEU input).
394 double get_Q_input_prev_old() const { return Q_input_prev_old_; }
395
396 /// @brief Get the under-relaxed flow sent at t_new on the last 'L' step (NEU input).
397 double get_Q_input_prev_new() const { return Q_input_prev_new_; }
398
399 /// @brief Set the NEU input flow history (call on 'L' steps).
400 void set_Q_input_prev(double old_val, double new_val) {
401 Q_input_prev_old_ = old_val;
402 Q_input_prev_new_ = new_val;
403 }
404
405 /// @brief Set the svZeroD solution IDs for flow and pressure
406 /// @param flow_id Flow solution ID
407 /// @param pressure_id Pressure solution ID
408 /// @param in_out_sign Sign for inlet/outlet
409 void set_solution_ids(int flow_id, int pressure_id, double in_out_sign);
410
411 /// @brief Get the flow solution ID
412 int get_flow_sol_id() const;
413
414 /// @brief Get the pressure solution ID
415 int get_pressure_sol_id() const;
416
417 /// @brief Get the inlet/outlet sign
418 double get_in_out_sign() const;
419
420 // =========================================================================
421 // Flowrate computation and access
422 // =========================================================================
423
424 /// @brief Set follower load flag and mechanical configs used for flowrate integration (also run from the face constructors).
425 void set_flowrate_mechanical_configurations(consts::EquationType phys, bool follower_pressure_load);
426
427 /// @brief Compute flowrates at the boundary face at old and new timesteps
428 /// @param com_mod ComMod reference containing simulation data
429 /// @param cm_mod CmMod reference for communication
430 void compute_flowrates(ComMod& com_mod, const CmMod& cm_mod, const SolutionStates& solutions);
431
432 /// @brief Initialize cap quadrature on the master (call from \c baf_ini after partition).
433 void initialize_cap(ComMod& com_mod);
434
435 /// @brief Compute cap \a valM from current cap mesh state on owner and copy/broadcast cap data to FSILS face.
436 void copy_cap_surface_to_linear_solver_face(ComMod& com_mod, fsi_linear_solver::FSILS_faceType& lhs_face,
437 consts::MechanicalConfigurationType cfg,
438 const SolutionStates& solutions) const;
439
440 /// @brief Extra volumetric flux through the cap (old/new timestep); {0,0} if no cap; MPI-safe on all ranks.
441 std::pair<double, double> calculate_cap_contribution(ComMod& com_mod, const CmMod& cm_mod,
442 const SolutionStates& solutions,
443 consts::MechanicalConfigurationType cfg_o,
444 consts::MechanicalConfigurationType cfg_n);
445
446 /// @brief Compute average pressures at the boundary face at old and new timesteps (for Dirichlet BCs)
447 /// @param com_mod ComMod reference containing simulation data
448 /// @param cm_mod CmMod reference for communication
449 void compute_pressures(ComMod& com_mod, const CmMod& cm_mod, const SolutionStates& solutions);
450
451 /// @brief Get the flowrate at old timestep
452 /// @return Flowrate at t_n
453 double get_Qo() const;
454
455 /// @brief Get the flowrate at new timestep
456 /// @return Flowrate at t_{n+1}
457 double get_Qn() const;
458
459 /// @brief Set the flowrates directly
460 /// @param Qo Flowrate at old timestep
461 /// @param Qn Flowrate at new timestep
462 void set_flowrates(double Qo, double Qn);
463
464 /// @brief Perturb the new timestep flowrate by a given amount
465 /// @param diff Perturbation to add to Qn
466 void perturb_flowrate(double diff);
467
468 // =========================================================================
469 // Pressure access (result from 0D solver)
470 // =========================================================================
471
472 /// @brief Set the pressure value from 0D solver
473 /// @param pressure Pressure value to be applied as Neumann BC
474 void set_pressure(double pressure);
475
476 /// @brief Get the current pressure value
477 /// @return Current pressure value from 0D solver
478 double get_pressure() const;
479
480 /// @brief Get the pressure at old timestep
481 /// @return Pressure at t_n
482 double get_Po() const;
483
484 /// @brief Get the pressure at new timestep
485 /// @return Pressure at t_{n+1}
486 double get_Pn() const;
487
488 // =========================================================================
489 // State management for derivative computation
490 // =========================================================================
491
492 /// @brief State struct for saving/restoring Qn and pressure
493 struct State {
494 double Qn = 0.0;
495 double pressure = 0.0;
496 };
497
498 /// @brief Save current state (Qn and pressure)
499 /// @return Current state
500 State save_state() const;
501
502 /// @brief Restore state from a saved state
503 /// @param state State to restore
504 void restore_state(const State& state);
505
506 // =========================================================================
507 // Utility methods
508 // =========================================================================
509
510 /// @brief Distribute BC metadata from master to slave processes
511 /// @param com_mod Reference to ComMod object
512 /// @param cm_mod Reference to CmMod object for MPI communication
513 /// @param cm Reference to cmType object for MPI communication
514 /// @param face Face associated with the BC (after distribution)
515 void distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmType& cm, const faceType& face);
516
517 /// @brief Load the cap face VTP file and associate it with this boundary condition
518 /// @param vtp_file_path Path to the cap face VTP file
519 void load_cap_face_vtp(const std::string& vtp_file_path);
520
521 /// @brief Check if this BC has a cap (broadcast in distribute so all ranks agree).
522 bool has_cap() const { return has_cap_; }
523
524 /// @brief True if this rank stores the cap mesh / quadrature in \ref cap_.
525 bool owns_cap() const { return owns_cap_; }
526
527 /// @brief Master reads Neumann pressure, one scalar \c MPI_Bcast, all ranks set pressure (svZeroD sync).
528 void bcast_coupled_neumann_pressure(const CmMod& cm_mod, cmType& cm);
529
530 /// @brief Master reads DIR flowrates (Qo, Qn), two scalar \c MPI_Bcast, all ranks set flowrates (svZeroD sync).
531 void bcast_coupled_dir_flowrate(const CmMod& cm_mod, cmType& cm);
532
533};
534
535#endif // COUPLED_BOUNDARY_CONDITION_H
Inconsistent cap connectivity or assembly indexing.
Definition CoupledBoundaryCondition.h:116
Base exception for capping surface (cap VTP) errors.
Definition CoupledBoundaryCondition.h:51
Failure copying a CappingSurface or its internal face.
Definition CoupledBoundaryCondition.h:122
Cap mesh shares no nodes with the coupled boundary face.
Definition CoupledBoundaryCondition.h:77
Cap VTP file cannot be opened.
Definition CoupledBoundaryCondition.h:62
Geometry or Jacobian error during cap surface integration.
Definition CoupledBoundaryCondition.h:102
Capping surface geometry and integration for a coupled boundary.
Definition CoupledBoundaryCondition.h:128
void compute_valM(consts::MechanicalConfigurationType cfg, const CapGlobalMeshState &st) const
Compute the cap contribution to the linear solver face (fills valM_; safe under const *this).
Definition CoupledBoundaryCondition.cpp:1242
void load_from_vtp(const std::string &vtp_file_path, const faceType &coupled_face, const std::string &coupled_face_name)
Load the cap face from a VTP file.
Definition CoupledBoundaryCondition.cpp:985
void initialize_valM()
Initialize the cap contribution storage.
Definition CoupledBoundaryCondition.cpp:1096
const Array< double > & valM() const
Get the cap contribution.
Definition CoupledBoundaryCondition.h:162
CappingSurface()=default
Default constructor.
CappingSurface & operator=(CappingSurface &&other) noexcept=default
Move assignment operator.
CappingSurface & operator=(const CappingSurface &other)
Copy assignment operator.
Definition CoupledBoundaryCondition.cpp:966
double integrate_velocity_flux(const CapGlobalMeshState &st, bool use_Yn_velocity, consts::MechanicalConfigurationType cfg)
Surface velocity flux through the cap using st columns indexed by cap IEN / GlobalNodeID (master / se...
Definition CoupledBoundaryCondition.cpp:1207
CappingSurface(CappingSurface &&other) noexcept=default
Move constructor.
const faceType * face() const
Get the cap face.
Definition CoupledBoundaryCondition.h:159
void init_cap_face_quadrature(const ComMod &com_mod)
Initialize the cap face quadrature.
Definition CoupledBoundaryCondition.cpp:1065
Cap VTP connectivity does not match expected TRI3 topology.
Definition CoupledBoundaryCondition.h:94
Cap face quadrature (shape functions on TRI3) setup failed.
Definition CoupledBoundaryCondition.h:108
Cap VTP uses an unsupported cell type (only TRI3 is supported).
Definition CoupledBoundaryCondition.h:86
VTP read, parse, or validation error during cap load.
Definition CoupledBoundaryCondition.h:70
The CmMod class duplicates the data structures in the Fortran CMMOD module defined in COMU....
Definition CmMod.h:36
The ComMod class duplicates the data structures in the Fortran COMMOD module defined in MOD....
Definition ComMod.h:1597
Object-oriented Coupled boundary condition.
Definition CoupledBoundaryCondition.h:199
double get_pressure() const
Get the current pressure value.
Definition CoupledBoundaryCondition.cpp:397
void perturb_flowrate(double diff)
Perturb the new timestep flowrate by a given amount.
Definition CoupledBoundaryCondition.cpp:383
void bcast_coupled_dir_flowrate(const CmMod &cm_mod, cmType &cm)
Master reads DIR flowrates (Qo, Qn), two scalar MPI_Bcast, all ranks set flowrates (svZeroD sync).
Definition CoupledBoundaryCondition.cpp:1398
void set_Q_input_prev(double old_val, double new_val)
Set the NEU input flow history (call on 'L' steps).
Definition CoupledBoundaryCondition.h:400
std::pair< double, double > calculate_cap_contribution(ComMod &com_mod, const CmMod &cm_mod, const SolutionStates &solutions, consts::MechanicalConfigurationType cfg_o, consts::MechanicalConfigurationType cfg_n)
Extra volumetric flux through the cap (old/new timestep); {0,0} if no cap; MPI-safe on all ranks.
Definition CoupledBoundaryCondition.cpp:800
int get_ramp_step_count() const
Get the number of committed time steps (used for ramp fraction).
Definition CoupledBoundaryCondition.h:364
double get_Qn() const
Get the flowrate at new timestep.
Definition CoupledBoundaryCondition.cpp:372
double get_Po() const
Get the pressure at old timestep.
Definition CoupledBoundaryCondition.cpp:402
CoupledBoundaryCondition & operator=(const CoupledBoundaryCondition &other)
Copy assignment operator.
Definition CoupledBoundaryCondition.cpp:59
double get_P_prev_sent_old() const
Get the under-relaxed pressure sent at t_old on the last 'L' step (DIR input).
Definition CoupledBoundaryCondition.h:370
void set_oned_ramp(int steps, double P_ref)
Set the pressure ramp parameters for 1D coupling initialization.
Definition CoupledBoundaryCondition.h:344
bool has_cap() const
Check if this BC has a cap (broadcast in distribute so all ranks agree).
Definition CoupledBoundaryCondition.h:522
double get_oned_relax_factor() const
Get the under-relaxation factor for DIR coupling pressure (1.0 = no relaxation).
Definition CoupledBoundaryCondition.h:353
void increment_ramp_step_count()
Increment the committed step counter (call once per 'L' step).
Definition CoupledBoundaryCondition.h:367
CoupledBoundaryCondition()=default
Default constructor - creates an uninitialized object.
~CoupledBoundaryCondition()=default
Destructor.
void initialize_cap(ComMod &com_mod)
Initialize cap quadrature on the master (call from baf_ini after partition).
Definition CoupledBoundaryCondition.cpp:561
void copy_cap_surface_to_linear_solver_face(ComMod &com_mod, fsi_linear_solver::FSILS_faceType &lhs_face, consts::MechanicalConfigurationType cfg, const SolutionStates &solutions) const
Compute cap valM from current cap mesh state on owner and copy/broadcast cap data to FSILS face.
Definition CoupledBoundaryCondition.cpp:1350
const std::string & get_block_name() const
Get the svZeroD block name.
Definition CoupledBoundaryCondition.cpp:250
void set_flowrates(double Qo, double Qn)
Set the flowrates directly.
Definition CoupledBoundaryCondition.cpp:377
void compute_pressures(ComMod &com_mod, const CmMod &cm_mod, const SolutionStates &solutions)
Compute average pressures at the boundary face at old and new timesteps (for Dirichlet BCs)
Definition CoupledBoundaryCondition.cpp:346
double get_Q_input_prev_old() const
Get the under-relaxed flow sent at t_old on the last 'L' step (NEU input).
Definition CoupledBoundaryCondition.h:394
void set_oned_input_file(const std::string &path)
Set the svOneD input file path.
Definition CoupledBoundaryCondition.cpp:260
void set_pressure(double pressure)
Set the pressure value from 0D solver.
Definition CoupledBoundaryCondition.cpp:392
int get_flow_sol_id() const
Get the flow solution ID.
Definition CoupledBoundaryCondition.cpp:272
void set_oned_relax_factor(double omega)
Set the under-relaxation factor for DIR coupling pressure.
Definition CoupledBoundaryCondition.h:357
void set_P_prev_sent(double old_val, double new_val)
Set the DIR input pressure history (call on 'L' steps).
Definition CoupledBoundaryCondition.h:376
int get_oned_ramp_steps() const
Get the pressure ramp step count (0 = disabled).
Definition CoupledBoundaryCondition.h:339
double get_P_prev_sent_new() const
Get the under-relaxed pressure sent at t_new on the last 'L' step (DIR input).
Definition CoupledBoundaryCondition.h:373
double get_P_neu_prev() const
Get the under-relaxed pressure output on the last 'L' step (NEU output).
Definition CoupledBoundaryCondition.h:388
double get_in_out_sign() const
Get the inlet/outlet sign.
Definition CoupledBoundaryCondition.cpp:282
void distribute(const ComMod &com_mod, const CmMod &cm_mod, const cmType &cm, const faceType &face)
Distribute BC metadata from master to slave processes.
Definition CoupledBoundaryCondition.cpp:446
double get_Q_input_prev_new() const
Get the under-relaxed flow sent at t_new on the last 'L' step (NEU input).
Definition CoupledBoundaryCondition.h:397
void set_Q_prev_sent(double Q)
Set the DIR output flow history (call on 'L' steps).
Definition CoupledBoundaryCondition.h:385
void restore_state(const State &state)
Restore state from a saved state.
Definition CoupledBoundaryCondition.cpp:421
double get_Qo() const
Get the flowrate at old timestep.
Definition CoupledBoundaryCondition.cpp:367
int get_pressure_sol_id() const
Get the pressure solution ID.
Definition CoupledBoundaryCondition.cpp:277
bool owns_cap() const
True if this rank stores the cap mesh / quadrature in cap_.
Definition CoupledBoundaryCondition.h:525
void load_cap_face_vtp(const std::string &vtp_file_path)
Load the cap face VTP file and associate it with this boundary condition.
Definition CoupledBoundaryCondition.cpp:519
void set_flowrate_mechanical_configurations(consts::EquationType phys, bool follower_pressure_load)
Set follower load flag and mechanical configs used for flowrate integration (also run from the face c...
Definition CoupledBoundaryCondition.cpp:294
void set_solution_ids(int flow_id, int pressure_id, double in_out_sign)
Set the svZeroD solution IDs for flow and pressure.
Definition CoupledBoundaryCondition.cpp:265
double get_Q_prev_sent() const
Get the under-relaxed flow output on the last 'L' step (DIR output).
Definition CoupledBoundaryCondition.h:382
State save_state() const
Save current state (Qn and pressure)
Definition CoupledBoundaryCondition.cpp:416
double get_Pn() const
Get the pressure at new timestep.
Definition CoupledBoundaryCondition.cpp:407
const std::string & get_oned_input_file() const
Get the svOneD input file path.
Definition CoupledBoundaryCondition.cpp:255
consts::BoundaryConditionType get_bc_type() const
Get the 3D BC type for this Coupled boundary condition.
Definition CoupledBoundaryCondition.h:319
void compute_flowrates(ComMod &com_mod, const CmMod &cm_mod, const SolutionStates &solutions)
Compute flowrates at the boundary face at old and new timesteps.
Definition CoupledBoundaryCondition.cpp:316
double get_oned_ramp_ref_pressure() const
Get the ramp reference pressure.
Definition CoupledBoundaryCondition.h:350
void set_P_neu_prev(double P)
Set the NEU output pressure history (call on 'L' steps).
Definition CoupledBoundaryCondition.h:391
void bcast_coupled_neumann_pressure(const CmMod &cm_mod, cmType &cm)
Master reads Neumann pressure, one scalar MPI_Bcast, all ranks set pressure (svZeroD sync).
Definition CoupledBoundaryCondition.cpp:1381
Definition LPNSolverInterface.h:18
The Vector template class is used for storing int and double data.
Definition Vector.h:26
The cmType class stores data and defines methods used for mpi communication.
Definition CmMod.h:56
The face type containing mesh at boundary.
Definition ComMod.h:469
Cap-surface nodal state: n_cap columns, column a is cap node a (same order as cap face gN / broadcast...
Definition CoupledBoundaryCondition.h:27
State struct for saving/restoring Qn and pressure.
Definition CoupledBoundaryCondition.h:493
Holds solution state at old, current, and intermediate time levels.
Definition SolutionStates.h:39