@@ -48,7 +48,6 @@ BoundaryCondition::BoundaryCondition(const std::string& vtp_file_path, const std
4848 , spatially_variable(true )
4949 , vtp_file_path_(vtp_file_path)
5050 , flags_(flags)
51- , defined_(false ) // Start as undefined, set to true only if successful
5251{
5352 try {
5453 global_data_ = read_data_from_vtp_file (vtp_file_path, array_names);
@@ -68,11 +67,8 @@ BoundaryCondition::BoundaryCondition(const std::string& vtp_file_path, const std
6867 for (int i = 0 ; i < global_num_nodes_; i++) {
6968 global_node_map_[face_->gN (i)] = i;
7069 }
71-
72- defined_ = true ; // Mark as successfully defined
7370 } catch (const std::exception& e) {
74- // Constructor failed - object remains in undefined state
75- // defined_ remains false, resources are automatically cleaned up
71+ // Constructor failed - resources are automatically cleaned up
7672 throw ; // Re-throw the exception
7773 }
7874}
@@ -84,7 +80,6 @@ BoundaryCondition::BoundaryCondition(const StringDoubleMap& uniform_values, cons
8480 , spatially_variable(false )
8581 , vtp_file_path_(" " )
8682 , flags_(flags)
87- , defined_(false ) // Start as undefined, set to true only if successful
8883{
8984 try {
9085 // Store array names, validate and store values
@@ -95,11 +90,8 @@ BoundaryCondition::BoundaryCondition(const StringDoubleMap& uniform_values, cons
9590 local_data_[name] = Array<double >(1 , 1 );
9691 local_data_[name](0 , 0 ) = value;
9792 }
98-
99- defined_ = true ; // Mark as successfully defined
10093 } catch (const std::exception& e) {
101- // Constructor failed - object remains in undefined state
102- // defined_ remains false, resources are automatically cleaned up
94+ // Constructor failed - resources are automatically cleaned up
10395 throw ; // Re-throw the exception
10496 }
10597}
@@ -115,7 +107,6 @@ BoundaryCondition::BoundaryCondition(const BoundaryCondition& other)
115107 , vtp_file_path_(other.vtp_file_path_)
116108 , flags_(other.flags_)
117109 , global_node_map_(other.global_node_map_)
118- , defined_(other.defined_)
119110{
120111 if (other.vtp_data_ ) {
121112 vtp_data_ = std::make_unique<VtkVtpData>(*other.vtp_data_ );
@@ -135,7 +126,6 @@ void swap(BoundaryCondition& lhs, BoundaryCondition& rhs) noexcept {
135126 swap (lhs.flags_ , rhs.flags_ );
136127 swap (lhs.global_node_map_ , rhs.global_node_map_ );
137128 swap (lhs.vtp_data_ , rhs.vtp_data_ );
138- swap (lhs.defined_ , rhs.defined_ );
139129}
140130
141131BoundaryCondition& BoundaryCondition::operator =(BoundaryCondition other) {
@@ -155,13 +145,11 @@ BoundaryCondition::BoundaryCondition(BoundaryCondition&& other) noexcept
155145 , flags_(std::move(other.flags_))
156146 , global_node_map_(std::move(other.global_node_map_))
157147 , vtp_data_(std::move(other.vtp_data_))
158- , defined_(other.defined_)
159148{
160149 other.face_ = nullptr ;
161150 other.global_num_nodes_ = 0 ;
162151 other.local_num_nodes_ = 0 ;
163152 other.spatially_variable = false ;
164- other.defined_ = false ;
165153}
166154
167155
@@ -195,16 +183,15 @@ BoundaryCondition::StringArrayMap BoundaryCondition::read_data_from_vtp_file(con
195183 StringArrayMap result;
196184 for (const auto & array_name : array_names) {
197185 if (!vtp_data_->has_point_data (array_name)) {
198- throw std::runtime_error ( " VTP file ' " + vtp_file_path + " ' does not contain ' " + array_name + " ' point array. " );
186+ throw BoundaryConditionVtpArrayException ( vtp_file_path, array_name);
199187 }
200188
201189 auto array_data = vtp_data_->get_point_data (array_name);
202190
203191 if (array_data.nrows () != global_num_nodes_ || array_data.ncols () != 1 ) {
204- throw std::runtime_error (" '" + array_name + " ' array in VTP file '" + vtp_file_path +
205- " ' has incorrect dimensions. Expected " + std::to_string (global_num_nodes_) +
206- " x 1, got " + std::to_string (array_data.nrows ()) + " x " +
207- std::to_string (array_data.ncols ()) + " ." );
192+ throw BoundaryConditionVtpArrayDimensionException (vtp_file_path, array_name,
193+ global_num_nodes_, 1 ,
194+ array_data.nrows (), array_data.ncols ());
208195 }
209196
210197 // Store array in result map
@@ -223,12 +210,11 @@ double BoundaryCondition::get_value(const std::string& array_name, int node_id)
223210{
224211 auto it = local_data_.find (array_name);
225212 if (it == local_data_.end ()) {
226- throw std::runtime_error ( " Array ' " + array_name + " ' not found. " );
213+ throw BoundaryConditionArrayException ( array_name);
227214 }
228215
229216 if (node_id < 0 || node_id >= global_num_nodes_) {
230- throw std::runtime_error (" Node ID " + std::to_string (node_id) +
231- " is out of range [0, " + std::to_string (global_num_nodes_ - 1 ) + " ]." );
217+ throw BoundaryConditionNodeIdException (node_id, global_num_nodes_);
232218 }
233219
234220 // Return value
@@ -257,8 +243,7 @@ int BoundaryCondition::get_local_index(int global_node_id) const
257243 if (spatially_variable) {
258244 auto it = global_node_map_.find (global_node_id);
259245 if (it == global_node_map_.end ()) {
260- throw std::runtime_error (" Global node ID " + std::to_string (global_node_id) +
261- " not found in global-to-local map." );
246+ throw BoundaryConditionGlobalNodeIdException (global_node_id);
262247 }
263248 return it->second ;
264249 } else {
@@ -292,7 +277,6 @@ void BoundaryCondition::distribute(const ComMod& com_mod, const CmMod& cm_mod, c
292277 distribute_uniform (cm_mod, cm, is_slave);
293278 }
294279 distribute_flags (cm_mod, cm, is_slave);
295- defined_ = true ;
296280
297281 #ifdef debug_distribute
298282 dmsg << " Finished distributing BC data" << std::endl;
@@ -338,7 +322,7 @@ void BoundaryCondition::distribute_spatially_variable(const ComMod& com_mod, con
338322 #endif
339323
340324 if (face_ == nullptr ) {
341- throw std::runtime_error ( " face_ is nullptr during distribute " );
325+ throw BoundaryConditionNullFaceException ( );
342326 }
343327 // Each processor collects the global node IDs and nodal positions of its
344328 // associated face portion
@@ -513,9 +497,7 @@ int BoundaryCondition::find_vtp_point_index(double x, double y, double z,
513497 }
514498 }
515499
516- throw std::runtime_error (" Could not find matching point in VTP file for node at position (" +
517- std::to_string (x) + " , " + std::to_string (y) + " , " +
518- std::to_string (z) + " )" );
500+ throw BoundaryConditionPointNotFoundException (x, y, z);
519501}
520502
521503std::string BoundaryCondition::flags_to_string () const {
0 commit comments