Skip to content

Commit 429cf03

Browse files
Merge pull request #14482 from KratosMultiphysics/mapping/solve_bug_nearest_element_IBRA
2 parents 6c03e65 + 51c04a8 commit 429cf03

1 file changed

Lines changed: 31 additions & 31 deletions

File tree

applications/MappingApplication/custom_utilities/projection_utilities.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -66,41 +66,41 @@ void FillEquationIdVectorIBRA(const GeometryType::Pointer pGeometry,
6666
const IndexType polynomial_degree_u = pGeometry->PolynomialDegree(0);
6767
const IndexType polynomial_degree_v = pGeometry->PolynomialDegree(1);
6868

69-
// Get the knot vectors of the nurbs surface and extend them to be consistent
70-
std::vector<double> knot_vector_u, knot_vector_v;
71-
pGeometry->SpansLocalSpace(knot_vector_u, 0);
72-
pGeometry->SpansLocalSpace(knot_vector_v, 1);
73-
knot_vector_u.insert(knot_vector_u.begin(), polynomial_degree_u - 1, knot_vector_u.front());
74-
knot_vector_u.insert(knot_vector_u.end(), polynomial_degree_u - 1, knot_vector_u.back());
75-
knot_vector_v.insert(knot_vector_v.begin(), polynomial_degree_v - 1, knot_vector_v.front());
76-
knot_vector_v.insert(knot_vector_v.end(), polynomial_degree_v - 1, knot_vector_v.back());
77-
78-
// shape function container.
79-
NurbsSurfaceShapeFunction shape_function_container(
80-
polynomial_degree_u, polynomial_degree_v, 0);
81-
82-
// Transform the knot vectors to the required format for the shape function container
83-
Vector vector_knot_vector_u(knot_vector_u.size()), vector_knot_vector_v(knot_vector_v.size());
84-
for (IndexType i = 0; i < knot_vector_u.size(); ++i) {
85-
vector_knot_vector_u[i] = knot_vector_u[i];
86-
}
69+
// Downcast the geometry to a nurbs surface
70+
auto p_nurbs_surface = dynamic_cast<NurbsSurfaceGeometryType*>(pGeometry.get());
8771

88-
for (IndexType i = 0; i < knot_vector_v.size(); ++i) {
89-
vector_knot_vector_v[i] = knot_vector_v[i];
90-
}
72+
KRATOS_ERROR_IF_NOT(p_nurbs_surface) << "Geometry is not a NurbsSurfaceGeometryType!" << std::endl;
73+
74+
// Number of CPs in the u and v directions
75+
const SizeType num_cp_u = pGeometry->PointsNumberInDirection(0);
76+
const SizeType num_cp_v = pGeometry->PointsNumberInDirection(1);
77+
78+
// Knot vectors in the u and v directions with multiplicity of p at the beginning and end
79+
const Vector knots_u = p_nurbs_surface->KnotsU();
80+
const Vector knots_v = p_nurbs_surface->KnotsV();
81+
82+
NurbsSurfaceShapeFunction shape_function_container(polynomial_degree_u, polynomial_degree_v, 0);
83+
84+
shape_function_container.ComputeBSplineShapeFunctionValues(knots_u, knots_v, rCoordinates[0], rCoordinates[1]);
85+
86+
// Get the indices of the non-zero shape functions (i.e. the control points influencing the point defined by rCoordinates)
87+
const IndexType num_nonzero_cps = shape_function_container.NumberOfNonzeroControlPoints();
88+
const std::vector<int> cp_indices = shape_function_container.ControlPointIndices(num_cp_u, num_cp_v);
89+
90+
rEquationIds.clear();
91+
rEquationIds.resize(num_nonzero_cps);
92+
93+
for (IndexType j = 0; j < num_nonzero_cps; ++j) {
94+
const int cp_index = cp_indices[j];
9195

92-
shape_function_container.ComputeBSplineShapeFunctionValues(vector_knot_vector_u, vector_knot_vector_v, rCoordinates[0], rCoordinates[1]);
96+
KRATOS_ERROR_IF(cp_index < 0 || cp_index >= static_cast<int>(pGeometry->PointsNumber()))
97+
<< "Invalid control point index " << cp_index
98+
<< " for geometry with " << pGeometry->PointsNumber()
99+
<< " control points." << std::endl;
93100

94-
IndexType num_nonzero_cps = shape_function_container.NumberOfNonzeroControlPoints();
101+
auto p_point = pGeometry->pGetPoint(cp_index);
95102

96-
/// Get List of Control Points
97-
PointsArrayType nonzero_control_points(num_nonzero_cps);
98-
std::vector<int> cp_indices = shape_function_container.ControlPointIndices(
99-
pGeometry->PointsNumberInDirection(0), pGeometry->PointsNumberInDirection(1));
100-
101-
for (IndexType j = 0; j < num_nonzero_cps; j++) {
102-
KRATOS_DEBUG_ERROR_IF_NOT(pGeometry->pGetPoint(cp_indices[j])->Has(INTERFACE_EQUATION_ID)) << pGeometry->pGetPoint(cp_indices[j]) << " does not have an \"INTERFACE_EQUATION_ID\"" << std::endl;
103-
rEquationIds.push_back(pGeometry->pGetPoint(cp_indices[j])->GetValue(INTERFACE_EQUATION_ID));
103+
rEquationIds[j] = p_point->GetValue(INTERFACE_EQUATION_ID);
104104
}
105105

106106
KRATOS_CATCH("")

0 commit comments

Comments
 (0)