4#ifndef COUPLED_BOUNDARY_CONDITION_H
5#define COUPLED_BOUNDARY_CONDITION_H
11#include <unordered_map>
15#include "SolutionStates.h"
22namespace fsi_linear_solver {
55 const char* what()
const noexcept override {
return message_.c_str(); }
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.") {}
90 std::to_string(vtk_cell_type) +
". Only VTK_TRIANGLE (TRI3) is supported.") {}
98 std::to_string(eNoN) +
" (expected " + std::to_string(expected) +
").") {}
112 "functions: " + nested) {}
143 const std::string& coupled_face_name);
153 consts::MechanicalConfigurationType cfg);
162 const Array<double>&
valM()
const {
return valM_; }
166 std::unique_ptr<faceType> face_;
170 Array<double> normals_;
173 static constexpr int cap_nsd_ = 3;
175 static constexpr int cap_insd_ = 2;
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;
184 std::pair<double, Vector<double>> compute_jacobian_and_normal(
const Array<double>& xl,
int e,
int g)
const;
187 mutable Array<double> valM_;
203 std::string cap_face_vtp_file_;
206 consts::BoundaryConditionType bc_type_ = consts::BoundaryConditionType::bType_Neu;
209 std::string block_name_;
210 std::string face_name_;
212 std::string oned_input_file_;
214 int oned_ramp_steps_ = 0;
215 double oned_ramp_ref_pressure_ = 0.0;
220 double oned_relax_factor_ = 1.0;
224 int ramp_step_count_ = 0;
225 double P_prev_sent_old_ = 0.0;
226 double P_prev_sent_new_ = 0.0;
227 double Q_prev_sent_ = 0.0;
228 double P_neu_prev_ = 0.0;
229 double Q_input_prev_old_ = 0.0;
230 double Q_input_prev_new_ = 0.0;
239 double pressure_ = 0.0;
242 int flow_sol_id_ = -1;
243 int pressure_sol_id_ = -1;
244 double in_out_sign_ = 1.0;
247 bool follower_pressure_load_ =
false;
248 consts::EquationType phys_ = consts::EquationType::phys_NA;
249 consts::MechanicalConfigurationType flowrate_cfg_o_ = consts::MechanicalConfigurationType::reference;
250 consts::MechanicalConfigurationType flowrate_cfg_n_ = consts::MechanicalConfigurationType::reference;
253 bool has_cap_ =
false;
255 bool owns_cap_ =
false;
261 std::unordered_map<int, int> cap_g_to_cap_col_;
263 std::optional<CappingSurface> cap_;
271 void rebuild_cap_global_to_col_map();
274 void gather_global_mesh_state(
ComMod& com_mod,
const CmMod& cm_mod,
const SolutionStates& solutions,
bool gather_Y)
const;
304 const std::string& block_name, consts::EquationType phys,
bool follower_pressure_load);
315 const std::string& block_name,
const std::string& cap_face_vtp_file,
316 consts::EquationType phys,
bool follower_pressure_load);
319 consts::BoundaryConditionType
get_bc_type()
const {
return bc_type_; }
336 bool is_svOneD_face()
const {
return !oned_input_file_.empty(); }
345 oned_ramp_steps_ = steps;
346 oned_ramp_ref_pressure_ = P_ref;
377 P_prev_sent_old_ = old_val;
378 P_prev_sent_new_ = new_val;
401 Q_input_prev_old_ = old_val;
402 Q_input_prev_new_ = new_val;
437 consts::MechanicalConfigurationType cfg,
443 consts::MechanicalConfigurationType cfg_o,
444 consts::MechanicalConfigurationType cfg_n);
495 double pressure = 0.0;
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