Skip to content

Commit 715dac1

Browse files
committed
Adding pygeosx integrated test
1 parent d0a4088 commit 715dac1

File tree

5 files changed

+181
-7
lines changed

5 files changed

+181
-7
lines changed

inputFiles/pygeos/modified_sedov.xml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" ?>
2+
3+
<Problem>
4+
5+
<Included>
6+
<File
7+
name="../solidMechanics/sedov_base.xml"/>
8+
</Included>
9+
10+
<Mesh>
11+
<InternalMesh
12+
name="mesh1"
13+
elementTypes="{ C3D8 }"
14+
xCoords="{ 0, 10 }"
15+
yCoords="{ 0, 10 }"
16+
zCoords="{ 0, 10 }"
17+
nx="{ 10 }"
18+
ny="{ 10 }"
19+
nz="{ 10 }"
20+
cellBlockNames="{ cb1 }"/>
21+
</Mesh>
22+
23+
<Solvers>
24+
<SolidMechanics_LagrangianFEM
25+
name="lagsolve"
26+
strainTheory="1"
27+
cflFactor="0.25"
28+
discretization="FE1"
29+
targetRegions="{ Region2 }"
30+
/>
31+
</Solvers>
32+
33+
<Events
34+
maxTime="1.0e-3">
35+
<!-- This event is applied every cycle, and overrides the
36+
solver time-step request -->
37+
<PeriodicEvent
38+
name="solverApplications"
39+
forceDt="1.0e-5"
40+
target="/Solvers/lagsolve"/>
41+
42+
<PeriodicEvent
43+
name="timeHistoryCollection"
44+
target="/Tasks/velocityCollection"/>
45+
46+
<PeriodicEvent
47+
name="timeHistoryOutput"
48+
timeFrequency="5.0e-4"
49+
targetExactTimestep="0"
50+
target="/Outputs/timeHistoryOutput"/>
51+
52+
<PeriodicEvent
53+
name="restarts"
54+
timeFrequency="5.0e-4"
55+
targetExactTimestep="0"
56+
target="/Outputs/restartOutput"/>
57+
58+
<PeriodicEvent
59+
name="python"
60+
cycleFrequency="5"
61+
target="/Outputs/pythonOutput"/>
62+
</Events>
63+
64+
</Problem>
65+

inputFiles/pygeos/pygeos.ats

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Integrated Test Docs Begin Parameters
2+
import geos_ats
3+
from geos_ats.test_builder import generate_geos_tests, RestartcheckParameters, TestDeck, CurveCheckParameters
4+
5+
restartcheck_params = {}
6+
restartcheck_params["atol"] = 2.0E-10
7+
restartcheck_params["rtol"] = 2.0E-13
8+
9+
curvecheck_params = {}
10+
curvecheck_params['filename'] = 'veloc_history.hdf5'
11+
curvecheck_params['tolerance'] = 1e-10
12+
curvecheck_params['time_units'] = 'milliseconds'
13+
curvecheck_params['curves'] = [['velocity', 'source']]
14+
# Integrated Test Docs End Parameters
15+
16+
# Integrated Test Docs Begin Test Loop
17+
partitions = ((1, 1, 1), (2, 2, 2), (3, 3, 3))
18+
19+
decks = [
20+
TestDeck(
21+
name="modified_sedov",
22+
pygeos_script="run_sedov_problem.py",
23+
description="Sedov problem with initial conditions modified using pygeos",
24+
partitions=partitions,
25+
restart_step=50,
26+
check_step=100,
27+
restartcheck_params=RestartcheckParameters(**restartcheck_params),
28+
curvecheck_params=CurveCheckParameters(**curvecheck_params))
29+
]
30+
31+
generate_geos_tests(decks)
32+
# Integrated Test Docs End Test Loop
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
import numpy as np
3+
from mpi4py import MPI
4+
import pygeosx
5+
from pygeosx_tools import wrapper
6+
from geosx_xml_tools.main import preprocess_parallel
7+
8+
9+
# PYGEOSX_STRESS_FN
10+
def stress_fn(x):
11+
"""
12+
Function to set stress values
13+
14+
Args:
15+
x (np.ndarray) the element centers
16+
17+
Returns:
18+
np.ndarray: stress values
19+
"""
20+
R = x[:, 0]**2 + x[:, 1]**2 + x[:, 2]**2
21+
return np.sin(2.0 * np.pi * R / np.amax(R))
22+
# PYGEOSX_STRESS_FN_END
23+
24+
25+
def run_problem():
26+
"""
27+
Run the GEOSX problem
28+
"""
29+
# PYGEOSX_INITIALIZATION
30+
# Get the MPI rank
31+
comm = MPI.COMM_WORLD
32+
rank = comm.Get_rank()
33+
34+
# Initialize the code and set initial conditions
35+
problem = pygeosx.initialize(rank, args)
36+
pygeosx.apply_initial_conditions()
37+
38+
# Rather than specifying the wrapper paths explicitly,
39+
# search for them using a set of filters
40+
location_key = wrapper.get_matching_wrapper_path(problem, ['Level0', 'Region2', 'elementCenter'])
41+
stress_key = wrapper.get_matching_wrapper_path(problem, ['Level0', 'Region2', 'shale', 'stress'])
42+
ghost_key = wrapper.get_matching_wrapper_path(problem, ['Level0', 'Region2', 'cb1', 'ghostRank'])
43+
# PYGEOSX_INITIALIZATION_END
44+
45+
# PYGEOSX_STRESS_IC
46+
# Print initial stress
47+
wrapper.print_global_value_range(problem, stress_key, 'stress')
48+
49+
# Zero out stress
50+
wrapper.set_wrapper_to_value(problem, stress_key, 0.0)
51+
wrapper.print_global_value_range(problem, stress_key, 'stress')
52+
53+
# Set stress via a function
54+
wrapper.set_wrapper_with_function(problem, stress_key, location_key, stress_fn, target_index=0)
55+
wrapper.set_wrapper_with_function(problem, stress_key, location_key, stress_fn, target_index=1)
56+
wrapper.set_wrapper_with_function(problem, stress_key, location_key, stress_fn, target_index=2)
57+
wrapper.print_global_value_range(problem, stress_key, 'stress')
58+
# PYGEOSX_STRESS_IC_END
59+
60+
# PYGEOSX_MAIN_LOOP
61+
# Run the code
62+
while pygeosx.run() != pygeosx.COMPLETED:
63+
wrapper.print_global_value_range(problem, stress_key, 'stress')
64+
65+
# Gather/allgather tests
66+
tmp = wrapper.gather_wrapper(problem, stress_key)
67+
print(wrapper.rank, 'gather', np.shape(tmp), flush=True)
68+
69+
tmp = wrapper.allgather_wrapper(problem, stress_key)
70+
print(wrapper.rank, 'allgather', np.shape(tmp), flush=True)
71+
72+
tmp = wrapper.allgather_wrapper(problem, stress_key, ghost_key=ghost_key)
73+
print(wrapper.rank, 'allgather_ghost_filtered', np.shape(tmp), flush=True)
74+
# PYGEOSX_MAIN_LOOP_END
75+
76+
77+
if __name__ == '__main__':
78+
run_problem()
79+
80+

inputFiles/solidMechanics/sedov_base.xml

+2-7
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,8 @@
9090
</FieldSpecifications>
9191

9292
<Outputs>
93-
<Blueprint
94-
name="blueprint"
95-
plotLevel="3"/>
96-
97-
<Silo
98-
name="siloOutput"
99-
plotLevel="3"/>
93+
<Python
94+
name="pythonOutput"/>
10095

10196
<Restart
10297
name="restartOutput"/>

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ install( FILES ${CMAKE_BINARY_DIR}/schema.xsd
234234
################################
235235
# message(WARNING "Temporarily changing the geosPythonBranch to cusini/fix-streak-cert-fail")
236236
# set(GEOS_PYTHON_PACKAGES_BRANCH "cusini/fix-streak-cert-fail" CACHE STRING "" FORCE)
237+
message(WARNING "Temporarily changing the geosPythonBranch to feature/sherman/addPygeosxIntegratedTests")
238+
set(GEOS_PYTHON_PACKAGES_BRANCH "cusini/fix-streak-cert-fail" CACHE STRING "" FORCE)
237239

238240

239241
if ( Python3_EXECUTABLE )

0 commit comments

Comments
 (0)