Skip to content

Commit 10cb4ef

Browse files
committed
Modifying the MainKratos.py so as to plot the displacements in the desired points of the structure
1 parent e1d3d3a commit 10cb4ef

File tree

1 file changed

+46
-35
lines changed

1 file changed

+46
-35
lines changed

co_simulation/validation/fsi_mok_iga_fem/source/MainKratos.py

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,61 @@ def OutputSolutionStep(self):
2525
solver = self._GetSolver()
2626

2727
if hasattr(solver, "model") and hasattr(solver.model, "solver_wrappers"):
28-
structure_solver = solver.model.solver_wrappers.get("structure") # Direct access
29-
28+
structure_solver = solver.model.solver_wrappers.get("structure")
3029
if structure_solver and hasattr(structure_solver, "model"):
3130
sub_model = structure_solver.model
3231
model_part_name = "IgaModelPart"
3332

3433
if hasattr(sub_model, "HasModelPart") and sub_model.HasModelPart(model_part_name):
3534
model_part = sub_model.GetModelPart(model_part_name)
36-
35+
3736
wet_interface_sub_model_part = model_part.GetSubModelPart("Load_4")
38-
3937
current_time = wet_interface_sub_model_part.ProcessInfo[KratosMultiphysics.TIME]
4038

41-
for condition in wet_interface_sub_model_part.Conditions:
42-
condition_geom = condition.GetGeometry()
43-
x = condition_geom.Center().X
44-
y = condition_geom.Center().Y
45-
46-
if condition.Id == 88:
47-
N = condition_geom.ShapeFunctionsValues()
48-
49-
solution_A = 0.0
50-
index = 0
51-
for node in condition.GetNodes():
52-
nodal_solution = node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X)
53-
54-
solution_A += nodal_solution * N[0,index]
55-
index += 1
56-
57-
self.time_history.append(current_time)
58-
self.disp_x_history_A.append(solution_A)
59-
60-
if condition.Id == 140:
61-
N = condition_geom.ShapeFunctionsValues()
62-
63-
solution_B = 0.0
64-
index = 0
65-
for node in condition.GetNodes():
66-
nodal_solution = node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X)
67-
68-
solution_B += nodal_solution * N[0,index]
69-
index += 1
70-
71-
self.disp_x_history_B.append(solution_B)
39+
# Only do this the first time
40+
if not hasattr(self, "tracking_conditions_initialized"):
41+
self.tracking_conditions_initialized = True
42+
43+
# Choose target locations
44+
self.point_A = (0.50025, 0.25) # Replace with your target coordinates
45+
self.point_B = (0.50, 0.125)
46+
47+
def get_closest_condition(target_point):
48+
min_dist = float("inf")
49+
closest_cond = None
50+
for cond in wet_interface_sub_model_part.Conditions:
51+
center = cond.GetGeometry().Center()
52+
dist = (center.X - target_point[0])**2 + (center.Y - target_point[1])**2
53+
if dist < min_dist:
54+
min_dist = dist
55+
closest_cond = cond
56+
return closest_cond
57+
58+
self.condition_A = get_closest_condition(self.point_A)
59+
self.condition_B = get_closest_condition(self.point_B)
60+
61+
# --- Evaluate displacement at A ---
62+
condition = self.condition_A
63+
geom = condition.GetGeometry()
64+
N = geom.ShapeFunctionsValues()
65+
66+
solution_A = 0.0
67+
for i, node in enumerate(condition.GetNodes()):
68+
solution_A += node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X) * N[0, i]
69+
70+
self.time_history.append(current_time)
71+
self.disp_x_history_A.append(solution_A)
72+
73+
# --- Evaluate displacement at B ---
74+
condition = self.condition_B
75+
geom = condition.GetGeometry()
76+
N = geom.ShapeFunctionsValues()
77+
78+
solution_B = 0.0
79+
for i, node in enumerate(condition.GetNodes()):
80+
solution_B += node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X) * N[0, i]
81+
82+
self.disp_x_history_B.append(solution_B)
7283

7384
def Finalize(self):
7485
super().Finalize()

0 commit comments

Comments
 (0)