Skip to content

Update Gap SBM worflow in 2D - #15019

Merged
andrewgorgi merged 5 commits into
masterfrom
PR_UpdatedGapSBMWorflow2D
Nov 27, 2026
Merged

andrewgorgi merged 5 commits into
masterfrom
PR_UpdatedGapSBMWorflow2D

Conversation

@andrewgorgi

Copy link
Copy Markdown
Contributor

Update Gap SBM worflow in 2D

About:
Optimized and debugged the 2D Gap SBM implementation. A 3D implementation, multipatch support, and box refinement in IGA are planned next.

Description
Moved the 2D Gap SBM implementation into its own .cpp file to prepare for a separate 3D implementation. Fixed projection and quadrature issues, added handling for multiple immersed geometry layers, and introduced CSR-based knot-span storage for faster, more efficient searches.

Key changes

  • Split the 2D Gap SBM implementation into a dedicated source file.
  • Fixed 2D skin projection and gap quadrature behavior.
  • Added support for multiple immersed geometry layers.
  • Added CSR storage for intersected knot spans.

Validation

  • Ran test_nurbs_geometry_modeler_gap_sbm.py; both tests passed.

Changelog

  • Optimized and fixed the 2D Gap SBM workflow, including layered geometry support and CSR-based knot-span search.

@andrewgorgi
andrewgorgi requested a review from a team as a code owner November 24, 2026 11:35
// System includes
#include <cmath>
#include <limits>
#include <memory>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

necessary?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more explicative name?

return SpanIndexY + rSkinBinsPerSpan.NumberOfSpansY * SpanIndexZ;
}

static std::size_t FindSpanNnzIndex(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep this one. It's nested but readable I think.

const NurbsVolumeType& rGapVolume) const;

/**
* @brief Prints diagnostic information about the orientation of a 3D gap Coons volume.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete?

const double Xi,
const double Eta,
const bool WithRespectToXi,
const bool with_respect_to_xi,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better naming?

};

// Select the closest admissible skin node using directional span probes.
auto select_candidate = [&](const Node::Pointer& pSurrogateNode) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't like define this in here...

std::unordered_set<IndexType> visited_candidate_ids;
visited_candidate_ids.reserve(16);

auto search_span = [&](const SpanId& r_span_id) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

candidate_conditions.reserve(2000);

const bool filter_by_layer = !rLayer.empty();
auto node_has_requested_layer = [&](Node::Pointer p_candidate_node) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

return std::find(candidate_layers.begin(), candidate_layers.end(), rLayer) != candidate_layers.end();
};

auto condition_matches_requested_layer = [&](const ConditionPointerType& p_condition) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

return node_has_requested_layer(p_geometry->pGetPoint(0)) || node_has_requested_layer(p_geometry->pGetPoint(1));
};

auto search_with_direction = [&](const array_1d<double, 3>& rSearchDirection) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@AlejandroCornejo AlejandroCornejo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll continue after some changes have been made

PointType& rLowPoint,
PointType& rHighPoint)
{
const auto& r_geometry = rObject->GetGeometry();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in the .cpp

const PointerType& rObject,
PointType& rCentralPoint)
{
rCentralPoint = rObject->GetGeometry().Center();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this is the updatod configuration center, not the reference one (relevant in finite strain)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s correct. These are auxiliary skin conditions used for the spatial search during geometry setup, before the analysis starts. At that point, the current and reference coordinates of the new skin nodes are the same. The center is not used for the finite-strain calculations or at the quadrature points.
In the future, we could reuse the search to recompute the gap elements with the moved skin, rebuilding the bins first. For now, it’s only called once in SetupGeometryModel, before solving.

PointType low, high;
CalculateBoundingBox(rObject, low, high, Radius);
for (std::size_t d = 0; d < Dimension; ++d) {
if (high[d] < rLowPoint[d] - Epsilon || low[d] > rHighPoint[d] + Epsilon) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think taht all these auxiliar methods should be gathered in some utilities and reused in many processes


static inline void Distance(
const PointerType& rObj_1,
const PointerType& rObj_2,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, it may be useful to have the current or ref distance..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added some comments saying that the distances are computed in the current configuration, but the process is called only during the geometry setup.

//
// License: BSD License
// Kratos default license: kratos/license.txt
//

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name of the developers?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beside why not using the IGA header?

if (mpIgaModelPart->GetRootModelPart().Conditions().size() > 0)
id = mpIgaModelPart->GetRootModelPart().Conditions().back().Id() + 1;

auto& neighbour_geometries = p_surrogate_1->GetValue(NEIGHBOUR_GEOMETRIES);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general is safer to check if this variable has been set before (Has) otherwise you may be gathering trash


auto& neighbour_geometries = p_surrogate_2->GetValue(NEIGHBOUR_GEOMETRIES);

if (norm_2(surrogate_middle_point-neighbour_geometries[0]->Center()) < 1e-12) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use unique tol

const auto& r_left_skin_node = rSkinSubModelPart.GetNode(LeftProjectionId);
const auto& r_right_skin_node = rSkinSubModelPart.GetNode(RightProjectionId);

CoordinatesArrayType skin_mid_point_coords = 0.5 * (r_left_skin_node.Coordinates() + r_right_skin_node.Coordinates());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current ones!


Vector normal_direction = r_right_skin_node.Coordinates() - r_left_skin_node.Coordinates();
const double direction_norm = norm_2(normal_direction);
if (direction_norm > 1.0e-16) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in here the tolerance is more strict?

rModelPart.AddConditions(new_condition_list.begin(), new_condition_list.end());
}

// Instantiate gap elements and attach surrogate reference data.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use standard commented separators to clearly identify the different methods...

…common to the SbanekSbm and SnakeGapSbm processes. Use of a single tolerance defined in the header. Little reorganization and cleaning of the code
@andrewgorgi

Copy link
Copy Markdown
Contributor Author

The code should be a little cleaner now. All the geometrical operations common to SnakeSbm and SnakeGapSbm processes have been moved to a common utility. We have defined a unique tollerance in the header for the gap sbm, scaled appropriately for all the operations by means of the physical quantities available.

Regarding the general comment on the Current Coordinates, right now the process is only called in the geometry setup, so they coincide with the material coordinates. For future applications, in which we might want to recompute the gap elements on the current configuration, I think it's convenient to keep this implementation and recreate the elements on the updated geometry.

@andrewgorgi
andrewgorgi merged commit f1a115a into master Nov 27, 2026
10 checks passed
@andrewgorgi
andrewgorgi deleted the PR_UpdatedGapSBMWorflow2D branch November 27, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants