Skip to content

Commit 1ff10fb

Browse files
committed
adding regressiont ests
1 parent b262974 commit 1ff10fb

24 files changed

+1349
-0
lines changed

regression_test/exodiff_file.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DEFAULT TOLERANCE relative 1.E-8 absolute 1.E-7 floor 1.E-14
2+
COORDINATES absolute 1.E-12
3+
TIME STEPS absolute 1.E-14
4+
NODAL VARIABLES absolute 1.E-8

regression_test/pytest.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[pytest]
2+
markers =
3+
push: marks tests that are to be run after pushing to branch (deselect with '-m "not push"')
4+
daily: marks tests that are to be run daily (deselect with '-m "not daily"')
5+
weekly: marks tests that are to be run weekly (deselect with '-m "not weekly"')
6+
incompressible: marks tests for incompressible model.
7+
mhd: marks for mhd model.
8+
gpu: marks for regression tests to run on GPU node.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Import Python modules
2+
import sys
3+
import glob
4+
import argparse
5+
import os
6+
from os import path
7+
8+
# Description:
9+
# This Python script implements logic to rename nodal and element variables
10+
# in Exodus files. The values remain un-changed. The changes in the Exodus
11+
# files are performed in place. Files to update are to be specified at the
12+
# command line. See documentation in the Wiki page under Software quality
13+
# assurance for further details.
14+
15+
# Adding trilinos folder to the system path and import exodus3
16+
sys.path.insert(
17+
0, '@TRILINOS_LIB@')
18+
import exodus3 as exodus
19+
20+
# Argument parser
21+
parser = argparse.ArgumentParser(
22+
description='Replace field names in Exodus files')
23+
parser.add_argument('-v',
24+
'--verbose',
25+
action='store_true',
26+
help='more verbose output')
27+
parser.add_argument('files',
28+
nargs='+',
29+
help='exodus file(s) to modify',
30+
metavar='file')
31+
parser.add_argument('-n',
32+
'--node',
33+
nargs=2,
34+
action='append',
35+
help='node variable',
36+
metavar=('old-name', 'new-name'))
37+
parser.add_argument('-e',
38+
'--element',
39+
nargs=2,
40+
action='append',
41+
help='element variable',
42+
metavar=('old-name', 'new-name'))
43+
args = parser.parse_args()
44+
45+
# Assign variable based on parsed arguments
46+
nodal_list = args.node
47+
elem_list = args.element
48+
if nodal_list is None and elem_list is None:
49+
print("\nPlease provide a list of node or element fields to replace.\n")
50+
parser.print_help()
51+
sys.exit()
52+
filename_list = args.files
53+
54+
# Collect all Exodus files specified at the command line
55+
for f in filename_list:
56+
if not os.path.isfile(f):
57+
sys.exit(f"ERROR: The file '{f}' is not found.")
58+
59+
60+
# Verbose function (used when --verbose flag is passed to command line)
61+
def print_verbose(msg):
62+
if args.verbose:
63+
print(msg)
64+
65+
66+
# Funtion to replace fields
67+
def replace_field(exo, field_list, field_type):
68+
print_verbose(f"\n\tLoop over {field_type} fields to replace:")
69+
# Set `exo_put_node` function and field type
70+
exo_put_node = lambda: None
71+
if field_type == "nodal":
72+
exo_put_node = exo.put_node_variable_name
73+
field_type = "EX_NODAL"
74+
elif field_type == "element":
75+
exo_put_node = exo.put_element_variable_name
76+
field_type = "EX_ELEM_BLOCK"
77+
else:
78+
exo.close()
79+
sys.exit(
80+
f"\t\tError: Current field type '{field_type}' is not supported. Field type options are 'nodal' or 'element'."
81+
)
82+
83+
# Loop over fields to replace
84+
exo_field_list = exo.get_variable_names(field_type)
85+
field_not_found = []
86+
for old_field, new_field in field_list:
87+
print_verbose(f"\n\t\t\tField to replace: {old_field}...")
88+
found = False
89+
# Look for exact match
90+
if old_field in exo_field_list:
91+
index = exo_field_list.index(old_field) + 1
92+
exo_put_node(new_field, index)
93+
found = True
94+
print_verbose(
95+
f"\t\t\t...Field {old_field} found with index {index} and replaced with {new_field}."
96+
)
97+
if not found:
98+
field_not_found.append(old_field)
99+
print_verbose(f"\t\t\t...WARNING: field {old_field} not found.")
100+
if field_not_found:
101+
print_verbose(
102+
f"\n\t\tWARNING: List of field(s) not found in the Exodus file {exo.fileName}:"
103+
)
104+
for old_field in field_not_found:
105+
print_verbose(f"\t\t- {old_field}")
106+
107+
# Return list of fields not found
108+
return field_not_found
109+
110+
111+
# Loop over file list
112+
full_report = {}
113+
sep = 100 * "*"
114+
for filename in filename_list:
115+
print("\n" + sep)
116+
117+
# Create exodus object from file
118+
exo = exodus.exodus(filename, mode='a')
119+
120+
nodal_field_not_found = None
121+
elem_field_not_found = None
122+
123+
try:
124+
# Nodal fields
125+
if nodal_list is not None:
126+
nodal_field_not_found = replace_field(exo, nodal_list, "nodal")
127+
128+
# Element fields
129+
if elem_list is not None:
130+
elem_field_not_found = replace_field(exo, elem_list, "element")
131+
finally:
132+
# Close exodus object
133+
exo.close()
134+
135+
# Store data in report (dictionary)
136+
full_report[filename] = {}
137+
if nodal_field_not_found is not None:
138+
full_report[filename]["nodal"] = nodal_field_not_found
139+
if elem_field_not_found is not None:
140+
full_report[filename]["element"] = elem_field_not_found
141+
142+
# Print full report
143+
print("\n" + sep)
144+
print("Full report:")
145+
for filename in filename_list:
146+
print(f"\tFile name: {filename}")
147+
for key, values in full_report[filename].items():
148+
if values:
149+
print("\t\t" + key + " variables not updated:")
150+
for v in values:
151+
print(f"\t\t - {v}")
152+
else:
153+
print("\t\tall " + key + " variables updated.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:9291bb12ce740d707a9cab981467d99678af8ff088fe5e3ee007053e9bf53852
3+
size 1274912
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:9f58f9193002e8726c3fb3d66bc5d87b0c6f5767f76aa2dff9824f38693a5071
3+
size 1274912
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:7077218589ce653a2a0f8f3cc7f3c775c4511c392588bb3890b451097bce68c9
3+
size 1274912
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import sys
2+
import os
3+
import pytest
4+
5+
import vertexcfd_test
6+
7+
8+
class TestCavity:
9+
# setup method for class
10+
@classmethod
11+
def setup_class(self):
12+
""" setup any state specific to the execution of the
13+
given class (which usually contains tests)."""
14+
print('\n***************** Setup class method *******************')
15+
16+
# Class variables (to not change)
17+
self.mesh_file_path = vertexcfd_test.mesh_file_path
18+
self.input_file_path = vertexcfd_test.input_file_path
19+
self.vertexcfd_exec = vertexcfd_test.vertexcfd_exec
20+
self.exodiff_exec = vertexcfd_test.exodiff_exec
21+
self.main_path = vertexcfd_test.main_path
22+
self.no_exodiff_file = None
23+
24+
# Change working directory to test directory
25+
self.test_path = os.path.dirname(os.path.realpath(__file__))
26+
os.chdir(self.test_path)
27+
28+
# teardown method for class
29+
@classmethod
30+
def teardown_class(self):
31+
""" teardown any state that was previously
32+
setup with a call to setup_class."""
33+
print('\n****************** Teardown class method ******************')
34+
# Change working directory back to main directory
35+
os.chdir(vertexcfd_test.main_path)
36+
37+
# setup method for each function
38+
def setup_method(self):
39+
""" setup test."""
40+
print('\nSetup method')
41+
# Initialize input file, mesh file and output file names
42+
self.input_file = None
43+
self.mesh_file = None
44+
self.output_file = None
45+
46+
# teardown method for each function
47+
def teardown_method(self):
48+
""" teardown test."""
49+
print('\nTeardown method')
50+
# Delete input file, mesh file and output file
51+
vertexcfd_test.clean_working_directory(self)
52+
53+
#############################################################################
54+
#############################################################################
55+
#############################################################################
56+
@pytest.mark.push
57+
@pytest.mark.daily
58+
@pytest.mark.weekly
59+
@pytest.mark.incompressible
60+
def test_2d_triangular_cavity(self, request):
61+
# Parameters
62+
mark_expr = request.config.option.markexpr
63+
vertexcfd_options = ()
64+
copy_xml_file = False
65+
66+
# default parameters to be used on 'push'
67+
base_input_file = "incompressible_2d_triangular_cavity"
68+
self.input_file = base_input_file + "_Re100.xml"
69+
source_input_file = self.input_file
70+
output_name = base_input_file + "_Re100_solution.exo"
71+
nu = 0.8
72+
73+
if ("daily" in mark_expr):
74+
self.input_file = base_input_file + "_Re400.xml"
75+
output_name = base_input_file + "_Re400_solution.exo"
76+
nu = 0.2
77+
elif ("weekly" in mark_expr):
78+
self.input_file = base_input_file + "_Re800.xml"
79+
output_name = base_input_file + "_Re800_solution.exo"
80+
nu = 0.1
81+
82+
xml_args_to_replace_list = []
83+
xml_args_to_replace_list.append(
84+
vertexcfd_test.xml_args_to_replace('Parameter', 'name',
85+
'Kinematic viscosity', nu))
86+
xml_args_to_replace_list.append(
87+
vertexcfd_test.xml_args_to_replace('Parameter', 'name',
88+
'Exodus Output File',
89+
output_name))
90+
91+
vertexcfd_test.create_xml_file_from_base_file(
92+
self, source_input_file, xml_args_to_replace_list)
93+
94+
# Parameters for exodiff executables
95+
exodiff_options = ()
96+
97+
#### The following code should not be modified ####
98+
# Run VertexCFD and call exodiff to compare to gold file
99+
vertexcfd_test.run_test(self, vertexcfd_options, exodiff_options,
100+
copy_xml_file)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DEFAULT TOLERANCE relative 1.E-8 absolute 1.E-7 floor 1.E-14
2+
COORDINATES absolute 1.E-12
3+
TIME STEPS absolute 1.E-8
4+
NODAL VARIABLES absolute 1.E-8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:a4fa171ad1cb4cb9bc294c82c08c75b6642abdf2d0e0dc26d449e92ac23a5827
3+
size 688136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:829352490118d2033883d361f46406a73f65b7c153dae48d80c9e18f3476cd9b
3+
size 932072

0 commit comments

Comments
 (0)