Skip to content

Commit

Permalink
changes values
Browse files Browse the repository at this point in the history
  • Loading branch information
knarfnitram committed Nov 15, 2024
1 parent e92c299 commit 6aa525d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 30 deletions.
65 changes: 41 additions & 24 deletions meshpy/four_c/dbc_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ def dbc_monitor_to_input(input_file, file_path, step=-1, function=1, n_dof=3):
def all_dbc_monitor_values_to_input(
input_file,
file_path,
step=-1,
steps=[0, -1],
n_dof=3,
time_span=[0, 1, 2],
type=None,
flip_forces=False,
fun_array=[],
):
"""
Extracts all the force values of the monitored Dirichlet Boundary Condition and converts
"""Extracts all the force values of the monitored Dirichlet Boundary Condition and converts
them into a Function with a Neumann Boundary Condition for the input_file.
The Monitor log force values must be obtained from a previous simulation with constant step size.
The discretization of the previous simulation must be identical to the one within the input_file.
Expand All @@ -158,8 +158,8 @@ def all_dbc_monitor_values_to_input(
in input_file.
file_path: str
Path to the Dirichlet boundary condition log file.
step: int
Indicates until which step the values are used. Default is -1, i.e. the last step.
steps: [int,int]
Index range of which the force values are extracted. Default 0 and -1 extracts every point from the array.
n_dof: int
Number of DOFs per node.
time_span: [t1, t2, t3] in float
Expand All @@ -179,8 +179,8 @@ def all_dbc_monitor_values_to_input(

# The forces are the negative reactions at the Dirichlet boundaries.
force *= -1.0
time = time[0:step]
force = force[0:step, :]
time = time[steps[0] : steps[1]]
force = force[steps[0] : steps[1], :]

# apply transformations to time and forces according to the schema
if type is None:
Expand All @@ -190,6 +190,8 @@ def all_dbc_monitor_values_to_input(
)

time, force = linear_time_transformation(time, force, time_span, flip_forces)
if len(fun_array) != 3:
print("Please provide a list with three valid Functions.")

elif type == "hat":

Expand All @@ -198,6 +200,16 @@ def all_dbc_monitor_values_to_input(
f"Please provide a time_span with size 1x3 not {len(time_span)}"
)

if len(fun_array) > 0:
print(
"You selected type",
type,
", however the provided functions ",
fun_array,
" are overwritten.",
)
fun_array = []

# create the two intervals
time1, force1 = linear_time_transformation(
time, force, time_span[0:2], flip_forces
Expand All @@ -221,26 +233,30 @@ def all_dbc_monitor_values_to_input(
+ " is currently not supported. Feel free to add it here."
)

# set up function array containing all the functions which will be added to the input file
fun_array = []
# overwrite the function, if one is provided since for the specific types the function is generated
if type:

for dim in range(force.shape[1]):
for dim in range(force.shape[1]):

# Extract the elements of each dimension
forces_per_dimension = [
force_per_direction[dim] for force_per_direction in force
]
# Extract the elements of each dimension
forces_per_dimension = [
force_per_direction[dim] for force_per_direction in force
]

# create a linear function with the force values
fun = create_linear_interpolation_function(
time, forces_per_dimension, function_type="SYMBOLIC_FUNCTION_OF_TIME"
)
# create a linear function with the force values
fun = create_linear_interpolation_function(
time, forces_per_dimension, function_type="SYMBOLIC_FUNCTION_OF_TIME"
)

# add the function to the input array
input_file.add(fun)

# add the function to the input array
input_file.add(fun)
# store the id of the function
# fun_array.append(str(len(input_file.functions)))
fun_array.append(fun)

# store the id of the function
fun_array.append(str(len(input_file.functions)))
elif len(fun_array) != 3:
raise ValueError("Please provide fun_array with ")

# now set forces to 1 since the force values are extracted already in the function
force = 0 * force + 1
Expand All @@ -253,8 +269,9 @@ def all_dbc_monitor_values_to_input(
geo,
(
"NUMDOF {n_dof} ONOFF 1 1 1{edz} VAL {data[0]} {data[1]} {data[2]}"
"{edz} FUNCT {function[0]} {function[1]} {function[2]}{edz}"
).format(n_dof=n_dof, data=force[step], edz=extra_dof_zero, function=fun_array),
"{edz} FUNCT {{}} {{}} {{}}{edz}"
).format(n_dof=n_dof, data=force[steps[1]], edz=extra_dof_zero),
bc_type=mpy.bc.neumann,
format_replacement=fun_array,
)
input_file.add(bc)
9 changes: 6 additions & 3 deletions tests/testing_four_c_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def test_four_c_simulation_dirichlet_boundary_to_neumann_boundary(self):
"TIMES 1.0 11.0 VALUES 1.0 0.0"
)
restart_simulation.add(function_nbc)
dbc_monitor_to_input(
all_dbc_monitor_values_to_input(
restart_simulation,
os.path.join(
testing_temp,
Expand All @@ -794,7 +794,9 @@ def test_four_c_simulation_dirichlet_boundary_to_neumann_boundary(self):
f"{initial_run_name}_102_monitor_dbc.csv",
),
n_dof=9,
function=function_nbc,
time_span=[10 * 0.5, 21 * 0.5],
steps=[10, 10],
fun_array=[function_nbc, function_nbc, function_nbc],
)
restart_simulation.add(
"""--RESULT DESCRIPTION
Expand Down Expand Up @@ -916,7 +918,7 @@ def test_four_c_simulation_dirichlet_boundary_to_neumann_boundary_with_all_value
force_simulation,
os.path.join(monitor_db_path, file_name),
n_dof=9,
step=n_steps + 1,
steps=[0, n_steps + 1],
time_span=[0, n_steps * dt, 2 * n_steps * dt],
type="hat",
)
Expand All @@ -934,6 +936,7 @@ def test_four_c_simulation_dirichlet_boundary_to_neumann_boundary_with_all_value
self,
force_simulation.get_string(check_nox=False, header=False),
additional_identifier="neumann",
atol=1e-6,
)
set_runtime_output(force_simulation)
initial_run_name = "all_dbc_to_nbc_initial_2"
Expand Down
5 changes: 2 additions & 3 deletions tests/testing_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
# Python imports
import unittest
import numpy as np
import numpy.testing as npt

# Meshpy imports
from meshpy.utility import is_node_on_plane, linear_time_transformation
Expand Down Expand Up @@ -79,7 +78,7 @@ def test_is_node_on_plane(self):

def test_linear_time_transformation_scaling(self):
"""
test the scaling of the intervall the function
Test the scaling of the intervall the function
it starts with a function in the intervall between [0,1] and transforms them
"""

Expand Down Expand Up @@ -125,7 +124,7 @@ def test_linear_time_transformation_scaling(self):

def test_linear_time_transformation_flip(self):
"""
test the flip flag option of linear_time_transformationto mirror the function
Test the flip flag option of linear_time_transformationto mirror the function
"""

# base case no scaling no end points should be attached
Expand Down

0 comments on commit 6aa525d

Please sign in to comment.