svMultiPhysics
Loading...
Searching...
No Matches
RobinBoundaryCondition.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 ROBIN_BOUNDARY_CONDITION_H
5#define ROBIN_BOUNDARY_CONDITION_H
6
7#include "BoundaryCondition.h"
8#include <string>
9#include <map>
10#include <vector>
11
12/// @brief Class to handle Robin boundary condition with potentially spatially variable arrays
13///
14/// This class extends the generic BoundaryCondition class to handle Robin boundary conditions, which require
15/// stiffness and damping arrays. While it supports any number of named arrays through its base class,
16/// it provides specific validation and convenience methods for stiffness and damping values.
17///
18/// Example usage:
19/// ```cpp
20/// // Read multiple arrays from VTP file
21/// std::vector<std::string> array_names = {"Stiffness", "Damping"};
22/// RobinBoundaryCondition bc(vtp_file_path, array_names, face);
23///
24/// // Access values
25/// double stiffness = bc.get_stiffness(node_id); // Convenience method
26/// double damping = bc.get_damping(node_id); // Convenience method
27///
28/// // Create with uniform values
29/// std::map<std::string, double> uniform_values = {
30/// {"Stiffness", 1.0},
31/// {"Damping", 0.5},
32/// };
33/// RobinBoundaryCondition bc(uniform_values, face);
34/// ```
35
36#define debug_robin_bc
38public:
39 /// @brief Default constructor - creates an empty RobinBoundaryCondition
41
42 /// @brief Constructor - reads stiffness and damping from VTP file
43 /// @param vtp_file_path Path to VTP file containing Stiffness and Damping point arrays
44 /// @param normal_only Flag to apply only along normal direction
45 /// @param face Face associated with the Robin BC
46 /// @param logger Simulation logger used to write warnings
47 /// @throws BoundaryConditionFileException if file cannot be read
48 /// @throws BoundaryConditionVtpArrayException if arrays are missing
49 /// @throws BoundaryConditionValidationException if values are invalid
50 RobinBoundaryCondition(const std::string& vtp_file_path, bool normal_only, const faceType& face, SimulationLogger& logger)
51 : BoundaryCondition(vtp_file_path, std::vector<std::string>{"Stiffness", "Damping"}, StringBoolMap{{"normal_direction_only", normal_only}}, face, logger) {}
52
53
54 /// @brief Constructor for uniform values
55 /// @param uniform_stiffness Uniform stiffness value for all nodes
56 /// @param uniform_damping Uniform damping value for all nodes
57 /// @param normal_only Flag to apply only along normal direction
58 /// @param face Face associated with the Robin BC
59 /// @param logger Simulation logger used to write warnings
60 /// @throws BoundaryConditionValidationException if values are invalid
61 RobinBoundaryCondition(double uniform_stiffness, double uniform_damping, bool normal_only, const faceType& face, SimulationLogger& logger);
62
63 /// @brief Apply only along normal direction (getter)
64 /// @return true if BC should be applied only along normal direction
65 /// @throws BoundaryConditionFlagException if "normal_direction_only" flag not found
66 bool normal_direction_only() const { return this->get_flag("normal_direction_only"); }
67
68 /// @brief Get stiffness value for a specific node (convenience method)
69 /// @param node_id Node index on the face
70 /// @return Stiffness value for the node
71 /// @throws BoundaryConditionArrayException if "Stiffness" array not found
72 /// @throws BoundaryConditionNodeIdException if node_id is out of range
73 double get_stiffness(int node_id) const {
74 return get_value("Stiffness", node_id);
75 }
76
77 /// @brief Get damping value for a specific node (convenience method)
78 /// @param node_id Node index on the face
79 /// @return Damping value for the node
80 /// @throws BoundaryConditionArrayException if "Damping" array not found
81 /// @throws BoundaryConditionNodeIdException if node_id is out of range
82 double get_damping(int node_id) const {
83 return get_value("Damping", node_id);
84 }
85
86 /// @brief Assemble the Robin BC into the global residual vector and stiffness matrix
87 /// Currently not implemented
88 /// @return 0
89 double assemble() const { return 0; }
90
91protected:
92 /// @brief Validate array values for Robin BC
93 /// @param array_name Name of the array being validated
94 /// @param value Value to validate
95 /// @throws BoundaryConditionValidationException if validation fails
96 void validate_array_value(const std::string& array_name, double value) const override {
97 if (value < 0.0) {
98 throw BoundaryConditionValidationException(array_name, value);
99 }
100 }
101};
102
103#endif // ROBIN_BOUNDARY_CONDITION_H
Base class for boundary conditions with spatially variable arrays.
Definition BoundaryCondition.h:48
double get_value(const std::string &array_name, int node_id) const
Get value for a specific array and node.
Definition BoundaryCondition.cpp:192
bool get_flag(const std::string &name) const
Get a boolean flag by name.
Definition BoundaryCondition.cpp:211
Exception thrown when array validation fails.
Definition BoundaryCondition.h:238
Definition RobinBoundaryCondition.h:37
double get_stiffness(int node_id) const
Get stiffness value for a specific node (convenience method)
Definition RobinBoundaryCondition.h:73
RobinBoundaryCondition()
Default constructor - creates an empty RobinBoundaryCondition.
Definition RobinBoundaryCondition.h:40
RobinBoundaryCondition(const std::string &vtp_file_path, bool normal_only, const faceType &face, SimulationLogger &logger)
Constructor - reads stiffness and damping from VTP file.
Definition RobinBoundaryCondition.h:50
bool normal_direction_only() const
Apply only along normal direction (getter)
Definition RobinBoundaryCondition.h:66
void validate_array_value(const std::string &array_name, double value) const override
Validate array values for Robin BC.
Definition RobinBoundaryCondition.h:96
double get_damping(int node_id) const
Get damping value for a specific node (convenience method)
Definition RobinBoundaryCondition.h:82
double assemble() const
Assemble the Robin BC into the global residual vector and stiffness matrix Currently not implemented.
Definition RobinBoundaryCondition.h:89
The SimulationLogger class is used to write information to a text file and optionally to cout.
Definition SimulationLogger.h:13
The face type containing mesh at boundary.
Definition ComMod.h:511