Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing for tutorial python script #26

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ requires = ["setuptools"]
packages = [
"cubitpy",
"cubitpy.cubit_wrapper",
"cubitpy_testing"
"cubitpy_testing",
"cubitpy_tutorial"
]

[tool.setuptools.package-dir]
cubitpy_testing = "tests"
cubitpy_tutorial = "tutorial"

[project]
name = "CubitPy"
Expand Down
144 changes: 144 additions & 0 deletions tests/input-files-ref/test_cubit_tutorial_cubitpy.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@

-------------------------------------------------------------------PROBLEM TYP
PROBLEMTYP Structure
----------------------------------------------------------------------------IO
OUTPUT_BIN no
STRUCT_DISP yes
FILESTEPS 1000
VERBOSITY Standard
STRUCT_STRAIN gl
STRUCT_STRESS cauchy
OUTPUT_SPRING Yes
WRITE_INITIAL_STATE yes
---------------------------------------------------------IO/RUNTIME VTK OUTPUT
OUTPUT_DATA_FORMAT binary
INTERVAL_STEPS 1
EVERY_ITERATION no
-----------------------------------------------IO/RUNTIME VTK OUTPUT/STRUCTURE
OUTPUT_STRUCTURE yes
DISPLACEMENT yes
ELEMENT_OWNER yes
STRESS_STRAIN yes
----------------------------------------------------------------------SOLVER 1
NAME Structure_Solver
SOLVER Superlu
------------------------------------------------------------STRUCTURAL DYNAMIC
INT_STRATEGY Standard
DYNAMICTYP Statics
PRESTRESSTOLDISP 1e-10
RESULTSEVRY 1
RESTARTEVRY 1
TIMESTEP 0.5
NUMSTEP 20
MAXTIME 10
TOLDISP 1e-10
TOLRES 1e-10
LINEAR_SOLVER 1
NLNSOL fullnewton
MAXITER 200
-----------------------------------------------------------STRUCT NOX/Printing
Outer Iteration = Yes
Inner Iteration = No
Outer Iteration StatusTest = No
---------------------------------------------------------------------MATERIALS
MAT 1 MAT_Struct_StVenantKirchhoff YOUNG 1.0E1 NUE 0.3 DENS 0
--------------------------------------------------------------------------FUNCT1
SYMBOLIC_FUNCTION_OF_SPACE_TIME t

----------------------------------------DESIGN SURF DIRICH CONDITIONS
DSURF 1
// fix
E 1 - NUMDOF 3 ONOFF 1 1 1 VAL 0 0 0 FUNCT 0 0 0
----------------------------------------DESIGN SURF NEUMANN CONDITIONS
DSURF 1
// load
E 2 - NUMDOF 3 ONOFF 0 1 0 VAL 0 0.1 0 FUNCT 0 1 0
-----------------------------------------------DNODE-NODE TOPOLOGY
-----------------------------------------------DLINE-NODE TOPOLOGY
-----------------------------------------------DSURF-NODE TOPOLOGY
NODE 18 DSURFACE 1
NODE 20 DSURFACE 1
NODE 21 DSURFACE 1
NODE 23 DSURFACE 1
NODE 26 DSURFACE 1
NODE 28 DSURFACE 1
NODE 42 DSURFACE 1
NODE 43 DSURFACE 1
NODE 46 DSURFACE 1
NODE 3 DSURFACE 2
NODE 4 DSURFACE 2
NODE 7 DSURFACE 2
NODE 8 DSURFACE 2
NODE 9 DSURFACE 2
NODE 11 DSURFACE 2
NODE 35 DSURFACE 2
NODE 36 DSURFACE 2
NODE 37 DSURFACE 2
-----------------------------------------------DVOL-NODE TOPOLOGY
-------------------------------------------------------NODE COORDS
NODE 1 COORD 1.8369701987210294e-16 3.0000000000000000e+00 0.0000000000000000e+00
NODE 2 COORD 2.1213203435596428e+00 2.1213203435596419e+00 0.0000000000000000e+00
NODE 3 COORD 5.0000000000000000e+00 5.0000000000000000e+00 0.0000000000000000e+00
NODE 4 COORD 0.0000000000000000e+00 5.0000000000000000e+00 0.0000000000000000e+00
NODE 5 COORD 1.8369701987210294e-16 3.0000000000000000e+00 5.0000000000000000e+00
NODE 6 COORD 2.1213203435596424e+00 2.1213203435596424e+00 5.0000000000000000e+00
NODE 7 COORD 5.0000000000000000e+00 5.0000000000000000e+00 5.0000000000000000e+00
NODE 8 COORD 0.0000000000000000e+00 5.0000000000000000e+00 5.0000000000000000e+00
NODE 9 COORD -5.0000000000000000e+00 5.0000000000000000e+00 0.0000000000000000e+00
NODE 10 COORD -2.1213203435596446e+00 2.1213203435596402e+00 0.0000000000000000e+00
NODE 11 COORD -5.0000000000000000e+00 5.0000000000000000e+00 5.0000000000000000e+00
NODE 12 COORD -2.1213203435596424e+00 2.1213203435596424e+00 5.0000000000000000e+00
NODE 13 COORD -5.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
NODE 14 COORD -3.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
NODE 15 COORD -5.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e+00
NODE 16 COORD -3.0000000000000000e+00 3.6739403974420589e-16 5.0000000000000000e+00
NODE 17 COORD -2.1213203435596446e+00 -2.1213203435596402e+00 -1.2490009027033011e-16
NODE 18 COORD -5.0000000000000000e+00 -5.0000000000000000e+00 0.0000000000000000e+00
NODE 19 COORD -2.1213203435596424e+00 -2.1213203435596424e+00 5.0000000000000000e+00
NODE 20 COORD -5.0000000000000000e+00 -5.0000000000000000e+00 5.0000000000000000e+00
NODE 21 COORD 0.0000000000000000e+00 -5.0000000000000000e+00 0.0000000000000000e+00
NODE 22 COORD 1.8369701987210294e-16 -3.0000000000000000e+00 8.3266726846886741e-17
NODE 23 COORD 0.0000000000000000e+00 -5.0000000000000000e+00 5.0000000000000000e+00
NODE 24 COORD 1.8369701987210294e-16 -3.0000000000000000e+00 5.0000000000000000e+00
NODE 25 COORD 2.1213203435596428e+00 -2.1213203435596419e+00 0.0000000000000000e+00
NODE 26 COORD 5.0000000000000000e+00 -5.0000000000000000e+00 0.0000000000000000e+00
NODE 27 COORD 2.1213203435596437e+00 -2.1213203435596419e+00 5.0000000000000000e+00
NODE 28 COORD 5.0000000000000000e+00 -5.0000000000000000e+00 5.0000000000000000e+00
NODE 29 COORD 3.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
NODE 30 COORD 5.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
NODE 31 COORD 3.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e+00
NODE 32 COORD 5.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e+00
NODE 33 COORD 1.8369701987210294e-16 3.0000000000000000e+00 -5.0000000000000000e+00
NODE 34 COORD 2.1213203435596437e+00 2.1213203435596419e+00 -5.0000000000000000e+00
NODE 35 COORD 5.0000000000000000e+00 5.0000000000000000e+00 -5.0000000000000000e+00
NODE 36 COORD 0.0000000000000000e+00 5.0000000000000000e+00 -5.0000000000000000e+00
NODE 37 COORD -5.0000000000000000e+00 5.0000000000000000e+00 -5.0000000000000000e+00
NODE 38 COORD -2.1213203435596424e+00 2.1213203435596424e+00 -5.0000000000000000e+00
NODE 39 COORD -5.0000000000000000e+00 0.0000000000000000e+00 -5.0000000000000000e+00
NODE 40 COORD -3.0000000000000000e+00 -3.6739403974420589e-16 -5.0000000000000000e+00
NODE 41 COORD -2.1213203435596424e+00 -2.1213203435596424e+00 -5.0000000000000000e+00
NODE 42 COORD -5.0000000000000000e+00 -5.0000000000000000e+00 -5.0000000000000000e+00
NODE 43 COORD 0.0000000000000000e+00 -5.0000000000000000e+00 -5.0000000000000000e+00
NODE 44 COORD 1.8369701987210294e-16 -3.0000000000000000e+00 -5.0000000000000000e+00
NODE 45 COORD 2.1213203435596424e+00 -2.1213203435596424e+00 -5.0000000000000000e+00
NODE 46 COORD 5.0000000000000000e+00 -5.0000000000000000e+00 -5.0000000000000000e+00
NODE 47 COORD 3.0000000000000000e+00 0.0000000000000000e+00 -5.0000000000000000e+00
NODE 48 COORD 5.0000000000000000e+00 0.0000000000000000e+00 -5.0000000000000000e+00
------------------------------------------------STRUCTURE ELEMENTS
1 SOLIDH8 HEX8 1 2 3 4 5 6 7 8 MAT 1 KINEM nonlinear EAS none
2 SOLIDH8 HEX8 4 9 10 1 8 11 12 5 MAT 1 KINEM nonlinear EAS none
3 SOLIDH8 HEX8 13 14 10 9 15 16 12 11 MAT 1 KINEM nonlinear EAS none
4 SOLIDH8 HEX8 17 14 13 18 19 16 15 20 MAT 1 KINEM nonlinear EAS none
5 SOLIDH8 HEX8 21 22 17 18 23 24 19 20 MAT 1 KINEM nonlinear EAS none
6 SOLIDH8 HEX8 25 22 21 26 27 24 23 28 MAT 1 KINEM nonlinear EAS none
7 SOLIDH8 HEX8 29 30 3 2 31 32 7 6 MAT 1 KINEM nonlinear EAS none
8 SOLIDH8 HEX8 29 25 26 30 31 27 28 32 MAT 1 KINEM nonlinear EAS none
9 SOLIDH8 HEX8 33 34 35 36 1 2 3 4 MAT 1 KINEM nonlinear EAS none
10 SOLIDH8 HEX8 36 37 38 33 4 9 10 1 MAT 1 KINEM nonlinear EAS none
11 SOLIDH8 HEX8 39 40 38 37 13 14 10 9 MAT 1 KINEM nonlinear EAS none
12 SOLIDH8 HEX8 41 40 39 42 17 14 13 18 MAT 1 KINEM nonlinear EAS none
13 SOLIDH8 HEX8 43 44 41 42 21 22 17 18 MAT 1 KINEM nonlinear EAS none
14 SOLIDH8 HEX8 45 44 43 46 25 22 21 26 MAT 1 KINEM nonlinear EAS none
15 SOLIDH8 HEX8 47 48 35 34 29 30 3 2 MAT 1 KINEM nonlinear EAS none
16 SOLIDH8 HEX8 47 45 46 48 29 25 26 30 MAT 1 KINEM nonlinear EAS none
---------------------------------------------------------------END
67 changes: 67 additions & 0 deletions tests/testing_tutorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# CubitPy: Cubit utility functions and a cubit wrapper for python3
#
# MIT License
#
# Copyright (c) 2018-2024
# 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.
# -----------------------------------------------------------------------------
"""
This script is used to test the tutorial.
"""

# Import python modules.
import unittest
import os
import sys

# Import tutorial
from cubitpy_tutorial import cubit_step_by_step_tutorial_cli

# Import Cubitpy
from cubitpy import CubitPy

# Import testing utilities.
from testing import testing_temp, compare


class TestTutorial(unittest.TestCase):
"""This class tests the tutorials in the repository."""

def test_tutorial(self):
"""
Test that the tutorial works.
"""
cubit = CubitPy()
tutorial_file = os.path.join(testing_temp, "tutorial.dat")
cubit_step_by_step_tutorial_cli(
tutorial_file, display=False, cubit=cubit, size=5.0
)
compare(cubit, name="test_cubit_tutorial", test_cubitpy=True)


if __name__ == "__main__":
# Execution part of script.
unittest.main()
35 changes: 35 additions & 0 deletions tutorial/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# CubitPy: Cubit utility functions and a cubit wrapper for python3
#
# MIT License
#
# Copyright (c) 2018-2024
# 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.
# -----------------------------------------------------------------------------
"""
This module contains extensions and utility functions for the cubit tutorial.
"""

from .tutorial import cubit_step_by_step_tutorial_cli
11 changes: 7 additions & 4 deletions tutorial/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
from cubitpy.cubit_utility import get_surface_center


def cubit_step_by_step_tutorial_cli(input_file_path, *, display=True):
def cubit_step_by_step_tutorial_cli(
input_file_path, *, display=True, cubit=None, size=1.0
):
"""This tutorial follows the Cubit step-by-step tutorial, which can be found
in the cubit documentation"""

Expand All @@ -52,7 +54,8 @@ def cubit_step_by_step_tutorial_cli(input_file_path, *, display=True):
# cubit python interface and provides all functionality of the direct cubit
# python interface and also adds some additional functionality to make the
# creation of 4C input files easier.
cubit = CubitPy()
if None == cubit:
cubit = CubitPy()

# Once the CubitPy object is initialized, we can create our first brick
# object. To do so we use the cubit python interface function `brick`.
Expand Down Expand Up @@ -115,7 +118,7 @@ def cubit_step_by_step_tutorial_cli(input_file_path, *, display=True):
# size for the volume. we begin by setting an overall volume size interval.
# Since the brick is 10 units in length on a side, this specifies that each
# straight curve is to receive approximately 10 mesh elements.
cubit.cmd(f"volume {brick.id()} size 1.0")
cubit.cmd(f"volume {brick.id()} size {size}")

# We will use a sweep mesh, so we will first mesh one surface of the body. We want to
# first mesh the top surface. This surface can be selected by looking for the only
Expand Down Expand Up @@ -145,7 +148,7 @@ def cubit_step_by_step_tutorial_cli(input_file_path, *, display=True):

if np.abs(radius - hole_radius) < 1e-10:
# The curve lies on the cylinder radius, now set the meshing interval
cubit.cmd(f"curve {curve.id()} interval size 0.5")
cubit.cmd(f"curve {curve.id()} interval size {size/2}")

# Now we can mesh the surface
cubit.cmd(f"mesh surface {mesh_surface.id()}")
Expand Down
Loading