Skip to content

Commit 403567b

Browse files
Merge pull request #54 from mattfalcone1997/nonconformal-tests
2 parents 6673362 + 296f0eb commit 403567b

File tree

19 files changed

+521
-1410
lines changed

19 files changed

+521
-1410
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ moose/include/base/Precompiled.h.gch
145145
.*.swp
146146
.*.swo
147147

148+
# clang
149+
.clangd
150+
151+
# OpenFOAM mesh object files
152+
test/**/*.obj
153+
148154
framework/contrib/exodiff/exodiff
149155

150156
# Mac garbage

run_tests

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@ MOOSE_DIR = os.environ.get('MOOSE_DIR', MOOSE_DIR)
88

99
sys.path.append(os.path.join(MOOSE_DIR, 'python'))
1010

11+
# add python test to PYTHONPATH
12+
HIPPO_TEST_PYTHON_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), 'test', 'python'))
13+
pythonpath = os.environ.get('PYTHONPATH', '').split(':')
14+
pythonpath = [HIPPO_TEST_PYTHON_DIR] + pythonpath
15+
os.environ['PYTHONPATH'] = ':'.join(pythonpath)
16+
1117
from TestHarness import TestHarness
1218
TestHarness.buildAndRun(sys.argv, 'hippo', MOOSE_DIR)

test/python/analytical.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
""" # analytical.py
2+
3+
Module contains analytical solutions used in the test scripts
4+
"""
5+
6+
import numpy as np
7+
from scipy.special import erfc
8+
9+
def unsteady1d_temp(x: np.ndarray,
10+
time: float,
11+
temp_cold: float,
12+
temp_hot: float,
13+
k1: float,
14+
k2: float,
15+
rho_cp1: float,
16+
rho_cp2: float) -> np.ndarray:
17+
"""Returns the analytical solution to 1D unsteady heat conduction problem.
18+
19+
Parameters
20+
----------
21+
x : np.ndarray
22+
array of x coordinates to evaluate solution
23+
time : float
24+
time to evaluate solution
25+
temp_cold : float
26+
Cold temperature
27+
temp_hot : float
28+
Hot temperautre
29+
k1 : float
30+
thermal conductivity for x<0
31+
k2 : float
32+
thermal conductivity for x>0
33+
rho_cp1 : float
34+
\\rho c_p for x<0
35+
rho_cp2 : float
36+
\\rho c_p for x>0
37+
38+
Returns
39+
-------
40+
np.ndarray
41+
Temperature for x at time
42+
"""
43+
44+
def temp_minus(
45+
x: np.ndarray,
46+
time: float,
47+
temp_cold: float,
48+
temp_hot: float,
49+
k1: float,
50+
k2: float,
51+
rho_cp1: float,
52+
rho_cp2: float,
53+
) -> np.ndarray:
54+
numerator = (temp_hot - temp_cold) * np.sqrt(k2 * rho_cp2)
55+
denominator = np.sqrt(k1 * rho_cp1) + np.sqrt(k2 * rho_cp2)
56+
erfc_arg = -x / (2 * np.sqrt(k1 / rho_cp1 * time))
57+
return temp_hot - (numerator / denominator) * erfc(erfc_arg)
58+
59+
def temp_plus(
60+
x: np.ndarray,
61+
time: float,
62+
temp_cold: float,
63+
temp_hot: float,
64+
k1: float,
65+
k2: float,
66+
rho_cp1: float,
67+
rho_cp2: float,
68+
) -> np.ndarray:
69+
numerator = (temp_hot - temp_cold) * np.sqrt(k1 * rho_cp1)
70+
denominator = np.sqrt(k1 * rho_cp1) + np.sqrt(k2 * rho_cp2)
71+
erfc_arg = x / (2 * np.sqrt(k2 / rho_cp2 * time))
72+
return temp_cold + (numerator / denominator) * erfc(erfc_arg)
73+
74+
positive_x_idx = x >= 0
75+
temp = np.empty_like(x)
76+
temp[positive_x_idx] = temp_plus(
77+
x=x[positive_x_idx],
78+
time=time,
79+
temp_cold=temp_cold,
80+
temp_hot=temp_hot,
81+
k1=k1,
82+
k2=k2,
83+
rho_cp1=rho_cp1,
84+
rho_cp2=rho_cp2,
85+
)
86+
negative_x_idx = ~positive_x_idx
87+
temp[negative_x_idx] = temp_minus(
88+
x=x[negative_x_idx],
89+
time=time,
90+
temp_cold=temp_cold,
91+
temp_hot=temp_hot,
92+
k1=k1,
93+
k2=k2,
94+
rho_cp1=rho_cp1,
95+
rho_cp2=rho_cp2,
96+
)
97+
return temp

test/python/read_hippo_data.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
from pathlib import Path
3+
from typing import Literal
4+
import numpy as np
5+
import pyvista as pv
6+
7+
def read_moose_exodus_data(exo_file,
8+
time,
9+
variable,
10+
block: int | str=0):
11+
12+
reader: pv.ExodusIIReader = pv.get_reader(exo_file)
13+
reader.set_active_time_value(time)
14+
15+
if block != 0 or block != 'Element blocks':
16+
reader.node_sets.enable_all()
17+
reader.side_sets.enable_all()
18+
reader.node_sets.enable_all_arrays()
19+
reader.side_sets.enable_all_arrays()
20+
21+
data: pv.UnstructuredGrid = reader.read()[block].combine(True)
22+
23+
if variable in data.point_data.keys():
24+
coords = data.points
25+
foam_variable = data.point_data[variable]
26+
elif variable in data.cell_data.keys():
27+
coords = data.cell_centers().points
28+
foam_variable = data.cell_data[variable]
29+
30+
else:
31+
raise KeyError(f"Variable {variable} not found")
32+
33+
foam_coords = dict(zip(('x', 'y', 'z'), coords.T))
34+
return foam_coords, foam_variable
35+
36+
def read_openfoam_data(case_dir: Path | str | bytes,
37+
time: float,
38+
variable: str,
39+
block: str = 'internalMesh',
40+
case_type: Literal['decomposed', 'reconstructed'] = 'reconstructed'
41+
) -> tuple[np.ndarray, np.ndarray]:
42+
43+
file_name = Path(case_dir) / "case.foam"
44+
file_name.touch()
45+
46+
reader: pv.POpenFOAMReader = pv.get_reader(file_name)
47+
reader.case_type = case_type
48+
reader.set_active_time_value(time)
49+
data: pv.UnstructuredGrid = reader.read()[block]
50+
51+
coords = data.cell_centers().points
52+
foam_variable = data.cell_data[variable]
53+
foam_coords = dict(zip(('x', 'y', 'z'), coords.T))
54+
return foam_coords, foam_variable

test/tests/mesh/polygonal/gold/run_temp_over_line_csv_temp_over_line_0032.csv

Lines changed: 0 additions & 51 deletions
This file was deleted.

test/tests/mesh/polygonal/run.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
[]
4343

4444
[heat_flux_to_fluid]
45-
type = MultiAppProjectionTransfer
45+
type = MultiAppGeneralFieldShapeEvaluationTransfer
4646
source_variable = wall_heat_flux
4747
to_multi_app = hippo
4848
variable = solid_heat_flux

test/tests/mesh/polygonal/test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Test module for polygonal OpenFOAM meshes"""
2+
3+
import unittest
4+
from pathlib import Path
5+
6+
import numpy as np
7+
8+
#import Hippo test python functions
9+
from analytical import unsteady1d_temp
10+
from read_hippo_data import read_moose_exodus_data, read_openfoam_data
11+
12+
13+
RUN_DIR = Path(__file__).parent
14+
FOAM_CASE = RUN_DIR / "fluid-openfoam"
15+
K_SOLID = 1
16+
RHO_CP_SOLID = 1
17+
K_FLUID = 4
18+
RHO_CP_FLUID = 16
19+
T_HOT = 2.
20+
T_COLD = 1.
21+
L = 1
22+
23+
24+
class TestUnsteadyHeatConductionInInfiniteSystem(unittest.TestCase):
25+
"""Test class for 1D unsteady problem with polygonal elements for OpenFOAM"""
26+
def test_matches_analytic_solution_at_times(self):
27+
"""Compare against analytical solution."""
28+
times = [0.0025, 0.005, 0.01] # seconds
29+
for time in times:
30+
moose_coords, moose_temperature = read_moose_exodus_data(RUN_DIR / "run_out.e",
31+
time,
32+
"temp")
33+
foam_coords, foam_temperature = read_openfoam_data(FOAM_CASE,
34+
time,
35+
'T')
36+
x = np.concatenate([moose_coords['x'], foam_coords['x']])
37+
temp = np.concatenate([moose_temperature, foam_temperature])
38+
39+
analytic_temp = unsteady1d_temp(
40+
x=x,
41+
time=time,
42+
temp_cold=T_COLD,
43+
temp_hot=T_HOT,
44+
k1=K_SOLID,
45+
k2=K_FLUID,
46+
rho_cp1=RHO_CP_SOLID,
47+
rho_cp2=RHO_CP_FLUID,
48+
)
49+
50+
rmse = np.sqrt(np.sum(np.square(analytic_temp - temp)) / len(temp))
51+
self.assertLess(rmse, 5e-3, msg=f"for time = {time} s")

test/tests/mesh/polygonal/tests

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
[poly]
33
[setup]
44
type = RunCommand
5-
command = 'bash -c "cd fluid-openfoam && ./Allclean && fluentMeshToFoam constant/polygon.msh && polyDualMesh -overwrite 35"'
5+
command = 'bash -c "cd fluid-openfoam && ./Allclean && fluentMeshToFoam constant/polygon.msh && polyDualMesh -overwrite 75"'
66
[]
7-
[verify]
8-
type = CSVDiff
7+
[run]
8+
type = RunApp
99
input = run.i
10-
csvdiff = run_temp_over_line_csv_temp_over_line_0032.csv
1110
prereq = poly/setup
1211
[]
12+
13+
[verify]
14+
type = PythonUnitTest
15+
input = test.py
16+
prereq = poly/run
17+
[]
1318
[]
1419
[]

0 commit comments

Comments
 (0)