Skip to content

Commit 2ec321d

Browse files
Use mesh_scale_factor when matching points
1 parent 4c17dee commit 2ec321d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Code/Source/solver/BoundaryCondition.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

476485
int 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

Code/Source/solver/BoundaryCondition.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ class BoundaryCondition {
198198
/// @param y Y coordinate
199199
/// @param z Z coordinate
200200
/// @param vtp_points VTP points array
201+
/// @param mesh_scale_factor Scale factor applied to mesh coordinates
201202
/// @return Index of the matching point in the VTP array
202203
/// @throws std::runtime_error if no matching point is found
203-
int find_vtp_point_index(double x, double y, double z, const Array<double>& vtp_points) const;
204+
int find_vtp_point_index(double x, double y, double z, const Array<double>& vtp_points, double mesh_scale_factor) const;
204205

205206
/// @brief Hook for derived classes to validate array values
206207
/// @param array_name Name of the array being validated

0 commit comments

Comments
 (0)