Skip to content

Commit

Permalink
Add testing for cubitpy created input files
Browse files Browse the repository at this point in the history
  • Loading branch information
isteinbrecher committed Feb 11, 2025
1 parent 18ac4ce commit cd4a7f8
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 8 deletions.
7 changes: 5 additions & 2 deletions tests/create_cubit_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""This script creates a solid input files with cubitpy."""
"""This script creates solid input files with CubitPy which are then used in
MeshPy testing."""

import os

Expand Down Expand Up @@ -304,7 +305,9 @@ def rotate_list(original_list, n):
dir_path = os.path.abspath(os.path.dirname(__file__))

# Create the input file for the solid tube.
file_path = os.path.join(dir_path, "reference-files/4C_input_solid_tube.dat")
file_path = os.path.join(
dir_path, "reference-files/test_create_cubit_input_tube.dat"
)
create_tube(file_path)

# Create the input files for the solid cube.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// -----------------------------------------------------------------------------
// This input file was created with MeshPy.
// Copyright (c) 2018-2025
// Ivo Steinbrecher
// Institute for Mathematics and Computer-Based Simulation
// Universitaet der Bundeswehr Muenchen
// https://www.unibw.de/imcs-en
// -----------------------------------------------------------------------------
---------------------------------------------------------------------NODE COORDS
NODE 1 COORD -0.05 -1 2
NODE 2 COORD -0.05 -1 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

-------------------------------------------------------NODE COORDS
NODE 1 COORD 0.0000000000000000e+00 -1.0000000000000000e+00 0.0000000000000000e+00
NODE 2 COORD 3.4202014332566932e-01 -9.3969262078590821e-01 0.0000000000000000e+00
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
// Universitaet der Bundeswehr Muenchen
// https://www.unibw.de/imcs-en
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// This input file was created with MeshPy.
// Copyright (c) 2018-2025
// Ivo Steinbrecher
// Institute for Mathematics and Computer-Based Simulation
// Universitaet der Bundeswehr Muenchen
// https://www.unibw.de/imcs-en
// -----------------------------------------------------------------------------
-----------------------------------------------------------------------MATERIALS
MAT 1 MAT_BeamReissnerElastHyper YOUNG -1.0 POISSONRATIO 0.0 DENS 0.0 CROSSAREA 3.141592653589793 SHEARCORR 1 MOMINPOL 1.5707963267948966 MOMIN2 0.7853981633974483 MOMIN3 0.7853981633974483
---------------------------------------------------------------------NODE COORDS
Expand Down
105 changes: 105 additions & 0 deletions tests/test_create_cubit_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# MeshPy: A beam finite element input generator
#
# MIT License
#
# Copyright (c) 2018-2025
# Ivo Steinbrecher
# Institute for Mathematics and Computer-Based Simulation
# Universitaet der Bundeswehr Muenchen
# https://www.unibw.de/imcs-en
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Test that the input files created with CubitPy are up to date."""

import pytest

from .create_cubit_input import (
create_block,
create_solid_shell_meshes,
create_tube,
create_tube_tutorial,
)


@pytest.mark.cubitpy
def test_create_cubit_input_tube(
tmp_path,
current_test_name,
get_corresponding_reference_file_path,
assert_results_equal,
):
"""Test that the solid tube reference file is up to date."""

file_path = tmp_path / (current_test_name + ".dat")
create_tube(file_path)
assert_results_equal(file_path, get_corresponding_reference_file_path())


@pytest.mark.cubitpy
def test_create_cubit_input_tutorial(
tmp_path,
reference_file_directory,
assert_results_equal,
):
"""Test the creation of the solid input file for the tutorial."""

# Create the tube for the tutorial.
result_path = tmp_path / "tutorial.dat"
create_tube_tutorial(result_path)

tutorial_path = (
reference_file_directory.parents[1] / "tutorial" / "4C_input_solid_tutorial.dat"
)
assert_results_equal(tutorial_path, result_path)


@pytest.mark.cubitpy
def test_create_cubit_input_block(
tmp_path,
current_test_name,
get_corresponding_reference_file_path,
assert_results_equal,
):
"""Test that the solid block reference file is up to date."""

file_path = tmp_path / (current_test_name + ".dat")
create_block(file_path)
assert_results_equal(file_path, get_corresponding_reference_file_path())


@pytest.mark.cubitpy
def test_create_cubit_input_solid_shell(
tmp_path,
current_test_name,
get_corresponding_reference_file_path,
assert_results_equal,
):
"""Test that the solid shell reference files are up to date."""

file_path_blocks = tmp_path / (current_test_name + "_blocks.dat")
file_path_dome = tmp_path / (current_test_name + "_dome.dat")
create_solid_shell_meshes(file_path_blocks, file_path_dome)
assert_results_equal(
file_path_blocks,
get_corresponding_reference_file_path(additional_identifier="blocks"),
)
assert_results_equal(
file_path_dome,
get_corresponding_reference_file_path(additional_identifier="dome"),
)
6 changes: 4 additions & 2 deletions tests/test_four_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def test_four_c_solid_shell_direction_detection(
# Test the plates
mpy.import_mesh_full = True
mesh_block = InputFile(
dat_file=reference_file_directory / "4C_input_solid_shell_thickness_blocks.dat"
dat_file=reference_file_directory
/ "test_create_cubit_input_solid_shell_blocks.dat"
)
# Add a beam element to check the function also works with beam elements
mat = MaterialReissner()
Expand All @@ -186,7 +187,8 @@ def test_four_c_solid_shell_direction_detection(

# Test the dome
mesh_dome_original = InputFile(
dat_file=reference_file_directory / "4C_input_solid_shell_thickness_dome.dat"
dat_file=reference_file_directory
/ "test_create_cubit_input_solid_shell_dome.dat"
)

# Test that the thickness version works
Expand Down
2 changes: 1 addition & 1 deletion tests/test_four_c_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_four_c_simulation_beam_and_solid_tube(
# Create the input file and read solid mesh data.
mpy.import_mesh_full = full_import
input_file = InputFile(description="Solid tube with beam tube")
input_file.read_dat(reference_file_directory / "4C_input_solid_tube.dat")
input_file.read_dat(reference_file_directory / "test_create_cubit_input_tube.dat")

# Add options for beam_output.
input_file.add(
Expand Down
8 changes: 5 additions & 3 deletions tests/test_meshpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ def create_beam_to_solid_conditions_model(reference_file_directory):

# Create input file.
input_file = InputFile(
dat_file=reference_file_directory / "test_meshpy_btsvm_coupling_solid_mesh.dat"
dat_file=reference_file_directory / "test_create_cubit_input_block.dat"
)

# Add beams to the model.
Expand Down Expand Up @@ -1532,7 +1532,7 @@ def test_meshpy_vtk_writer_solid(
# Create the input file and read solid mesh data.
input_file = InputFile()
input_file.read_dat(
os.path.join(reference_file_directory, "4C_input_solid_tube.dat")
os.path.join(reference_file_directory, "test_create_cubit_input_tube.dat")
)

# Write VTK output.
Expand Down Expand Up @@ -1651,7 +1651,9 @@ def test_meshpy_cubitpy_import(
input_file_cubit = InputFile(cubit=create_tube_cubit())

# Load the file from the reference folder.
file_path_ref = os.path.join(reference_file_directory, "4C_input_solid_tube.dat")
file_path_ref = os.path.join(
reference_file_directory, "test_create_cubit_input_tube.dat"
)
input_file_ref = InputFile(dat_file=file_path_ref)

# Compare the input files.
Expand Down

0 comments on commit cd4a7f8

Please sign in to comment.