4040
4141#define n_debug_bc
4242
43- BoundaryCondition::BoundaryCondition (const std::string& vtp_file_path, const std::vector<std::string>& array_names, const StringBoolMap& flags, const faceType& face)
43+ BoundaryCondition::BoundaryCondition (const std::string& vtp_file_path, const std::vector<std::string>& array_names, const StringBoolMap& flags, const faceType& face, SimulationLogger& logger )
4444 : face_(&face)
4545 , global_num_nodes_(face.nNo)
4646 , local_num_nodes_(0 )
4747 , array_names_(array_names)
4848 , spatially_variable(true )
4949 , vtp_file_path_(vtp_file_path)
5050 , flags_(flags)
51+ , logger_(&logger)
5152{
5253 try {
5354 global_data_ = read_data_from_vtp_file (vtp_file_path, array_names);
@@ -73,13 +74,14 @@ BoundaryCondition::BoundaryCondition(const std::string& vtp_file_path, const std
7374 }
7475}
7576
76- BoundaryCondition::BoundaryCondition (const StringDoubleMap& uniform_values, const StringBoolMap& flags, const faceType& face)
77+ BoundaryCondition::BoundaryCondition (const StringDoubleMap& uniform_values, const StringBoolMap& flags, const faceType& face, SimulationLogger& logger )
7778 : face_(&face)
7879 , global_num_nodes_(face.nNo)
7980 , local_num_nodes_(0 )
8081 , spatially_variable(false )
8182 , vtp_file_path_(" " )
8283 , flags_(flags)
84+ , logger_(&logger)
8385{
8486 try {
8587 // Store array names, validate and store values
@@ -107,6 +109,7 @@ BoundaryCondition::BoundaryCondition(const BoundaryCondition& other)
107109 , vtp_file_path_(other.vtp_file_path_)
108110 , flags_(other.flags_)
109111 , global_node_map_(other.global_node_map_)
112+ , logger_(other.logger_)
110113{
111114 if (other.vtp_data_ ) {
112115 vtp_data_ = std::make_unique<VtkVtpData>(*other.vtp_data_ );
@@ -126,6 +129,7 @@ void swap(BoundaryCondition& lhs, BoundaryCondition& rhs) noexcept {
126129 swap (lhs.flags_ , rhs.flags_ );
127130 swap (lhs.global_node_map_ , rhs.global_node_map_ );
128131 swap (lhs.vtp_data_ , rhs.vtp_data_ );
132+ swap (lhs.logger_ , rhs.logger_ );
129133}
130134
131135BoundaryCondition& BoundaryCondition::operator =(BoundaryCondition other) {
@@ -145,6 +149,7 @@ BoundaryCondition::BoundaryCondition(BoundaryCondition&& other) noexcept
145149 , flags_(std::move(other.flags_))
146150 , global_node_map_(std::move(other.global_node_map_))
147151 , vtp_data_(std::move(other.vtp_data_))
152+ , logger_(other.logger_)
148153{
149154 other.face_ = nullptr ;
150155 other.global_num_nodes_ = 0 ;
@@ -203,6 +208,11 @@ BoundaryCondition::StringArrayMap BoundaryCondition::read_data_from_vtp_file(con
203208 #endif
204209 }
205210
211+ logger_ -> log_message (" [BoundaryCondition] Loaded from VTP file" );
212+ logger_ -> log_message (" \t File path:" , vtp_file_path);
213+ logger_ -> log_message (" \t Arrays:" , array_names);
214+ logger_ -> log_message (" \t Face:" , face_->name );
215+
206216 return result;
207217}
208218
@@ -375,11 +385,20 @@ void BoundaryCondition::distribute_spatially_variable(const ComMod& com_mod, con
375385 // Get VTP points for position matching
376386 Array<double > vtp_points = vtp_data_->get_points ();
377387
378- // Look up data for all nodes using point matching
388+ // Get mesh scale factor from the face's mesh
389+ double mesh_scale_factor = 1.0 ; // Default scale factor
390+ if (face_ != nullptr ) {
391+ mesh_scale_factor = com_mod.msh [face_->iM ].scF ;
392+ #ifdef debug_distribute_spatially_variable
393+ dmsg << " Mesh scale factor: " << mesh_scale_factor << std::endl;
394+ #endif
395+ }
396+
397+ // Look up data for all nodes using point matching
379398 for (const auto & array_name : array_names_) {
380399 all_values[array_name].resize (total_num_nodes);
381400 for (int i = 0 ; i < total_num_nodes; i++) {
382- int vtp_idx = find_vtp_point_index (all_positions (0 ,i), all_positions (1 ,i), all_positions (2 ,i), vtp_points);
401+ int vtp_idx = find_vtp_point_index (all_positions (0 ,i), all_positions (1 ,i), all_positions (2 ,i), vtp_points, mesh_scale_factor );
383402 all_values[array_name](i) = global_data_[array_name](vtp_idx, 0 );
384403 }
385404 }
@@ -474,10 +493,13 @@ void BoundaryCondition::distribute_flags(const CmMod& cm_mod, const cmType& cm,
474493}
475494
476495int BoundaryCondition::find_vtp_point_index (double x, double y, double z,
477- const Array<double >& vtp_points) const
496+ const Array<double >& vtp_points, double mesh_scale_factor ) const
478497{
479498 const int num_points = vtp_points.ncols ();
480- Vector<double > target_point{x, y, z};
499+
500+ // Scale down the target coordinates to match the unscaled VTP coordinates
501+ // The simulation coordinates are scaled by mesh_scale_factor, but VTP coordinates are not
502+ Vector<double > target_point{x / mesh_scale_factor, y / mesh_scale_factor, z / mesh_scale_factor};
481503
482504 // Simple linear search through all points in the VTP file
483505 for (int i = 0 ; i < num_points; i++) {
@@ -490,6 +512,7 @@ int BoundaryCondition::find_vtp_point_index(double x, double y, double z,
490512 #ifdef debug_bc_find_vtp_point_index
491513 DebugMsg dmsg (__func__, 0 );
492514 dmsg << " Found VTP point index for node at position (" << x << " , " << y << " , " << z << " )" << std::endl;
515+ dmsg << " Scaled target position (" << target_point (0 ) << " , " << target_point (1 ) << " , " << target_point (2 ) << " )" << std::endl;
493516 dmsg << " VTP point index: " << i << std::endl;
494517 #endif
495518
0 commit comments