@@ -375,11 +375,20 @@ void BoundaryCondition::distribute_spatially_variable(const ComMod& com_mod, con
375375 // Get VTP points for position matching
376376 Array<double > vtp_points = vtp_data_->get_points ();
377377
378- // Look up data for all nodes using point matching
378+ // Get mesh scale factor from the face's mesh
379+ double mesh_scale_factor = 1.0 ; // Default scale factor
380+ if (face_ != nullptr ) {
381+ mesh_scale_factor = com_mod.msh [face_->iM ].scF ;
382+ #ifdef debug_distribute_spatially_variable
383+ dmsg << " Mesh scale factor: " << mesh_scale_factor << std::endl;
384+ #endif
385+ }
386+
387+ // Look up data for all nodes using point matching
379388 for (const auto & array_name : array_names_) {
380389 all_values[array_name].resize (total_num_nodes);
381390 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);
391+ int vtp_idx = find_vtp_point_index (all_positions (0 ,i), all_positions (1 ,i), all_positions (2 ,i), vtp_points, mesh_scale_factor );
383392 all_values[array_name](i) = global_data_[array_name](vtp_idx, 0 );
384393 }
385394 }
@@ -474,10 +483,13 @@ void BoundaryCondition::distribute_flags(const CmMod& cm_mod, const cmType& cm,
474483}
475484
476485int BoundaryCondition::find_vtp_point_index (double x, double y, double z,
477- const Array<double >& vtp_points) const
486+ const Array<double >& vtp_points, double mesh_scale_factor ) const
478487{
479488 const int num_points = vtp_points.ncols ();
480- Vector<double > target_point{x, y, z};
489+
490+ // Scale down the target coordinates to match the unscaled VTP coordinates
491+ // The simulation coordinates are scaled by mesh_scale_factor, but VTP coordinates are not
492+ Vector<double > target_point{x / mesh_scale_factor, y / mesh_scale_factor, z / mesh_scale_factor};
481493
482494 // Simple linear search through all points in the VTP file
483495 for (int i = 0 ; i < num_points; i++) {
@@ -490,6 +502,7 @@ int BoundaryCondition::find_vtp_point_index(double x, double y, double z,
490502 #ifdef debug_bc_find_vtp_point_index
491503 DebugMsg dmsg (__func__, 0 );
492504 dmsg << " Found VTP point index for node at position (" << x << " , " << y << " , " << z << " )" << std::endl;
505+ dmsg << " Scaled target position (" << target_point (0 ) << " , " << target_point (1 ) << " , " << target_point (2 ) << " )" << std::endl;
493506 dmsg << " VTP point index: " << i << std::endl;
494507 #endif
495508
0 commit comments