From 66cb533420e0e3763418a42a310f88993f8ae78f Mon Sep 17 00:00:00 2001 From: Congjian Wang Date: Sat, 25 Aug 2018 19:54:59 -0600 Subject: [PATCH] Fix scaling issue in DataSet when Grid sampler is used as restart. (#730) * fix std in data comparison * add test to test restart with constant variables, test issue #690 * rename folder name, since 'con' is not acceptable in windows --- framework/DataObjects/DataSet.py | 4 + .../Samplers/Restart/gold/constant/coarse.csv | 3 + .../Restart/gold/constant/restart.csv | 10 ++ .../Restart/test_restart_constant.xml | 113 ++++++++++++++++++ tests/framework/Samplers/Restart/tests | 7 ++ 5 files changed, 137 insertions(+) create mode 100644 tests/framework/Samplers/Restart/gold/constant/coarse.csv create mode 100644 tests/framework/Samplers/Restart/gold/constant/restart.csv create mode 100644 tests/framework/Samplers/Restart/test_restart_constant.xml diff --git a/framework/DataObjects/DataSet.py b/framework/DataObjects/DataSet.py index dcf5c89e98..8467bd1795 100644 --- a/framework/DataObjects/DataSet.py +++ b/framework/DataObjects/DataSet.py @@ -1380,6 +1380,10 @@ def _getRealizationFromDataByValue(self,match, tol=1e-15, unpackXArray=False): # variable doesn't have a scale factor (yet? Why not?) loc = 0.0 scale = 1.0 + if scale == 0: + # TODO: Seem to me, we need to find a better way to compare data + # The scale will be zero if Grid Sampler is used, reset to 1.0 + scale = 1.0 scaleVal = (val-loc)/scale # create mask of where the dataarray matches the desired value mask *= abs((self._data[var]-loc)/scale - scaleVal) < tol diff --git a/tests/framework/Samplers/Restart/gold/constant/coarse.csv b/tests/framework/Samplers/Restart/gold/constant/coarse.csv new file mode 100644 index 0000000000..b0d9eccd51 --- /dev/null +++ b/tests/framework/Samplers/Restart/gold/constant/coarse.csv @@ -0,0 +1,3 @@ +x1,x2,ans +1.0,2.0,1.0 +2.0,2.0,1.0 diff --git a/tests/framework/Samplers/Restart/gold/constant/restart.csv b/tests/framework/Samplers/Restart/gold/constant/restart.csv new file mode 100644 index 0000000000..48385c4abf --- /dev/null +++ b/tests/framework/Samplers/Restart/gold/constant/restart.csv @@ -0,0 +1,10 @@ +x1,x2,ans +1.0,2.0,1.0 +1.0,2.5,2.0 +1.0,3.0,2.0 +1.5,2.0,2.0 +1.5,2.5,2.0 +1.5,3.0,2.0 +2.0,2.0,1.0 +2.0,2.5,2.0 +2.0,3.0,2.0 diff --git a/tests/framework/Samplers/Restart/test_restart_constant.xml b/tests/framework/Samplers/Restart/test_restart_constant.xml new file mode 100644 index 0000000000..c9c48bfe72 --- /dev/null +++ b/tests/framework/Samplers/Restart/test_restart_constant.xml @@ -0,0 +1,113 @@ + + + + framework/Samplers/Restart.Constant + wangc + 2018-08-04 + Samplers.Grid + + The essence of this test is to demonstrate the restart capability with constant variable, + i.e. test the scaling factor for constant samples as mentioned in issue #690 + + + + + constant + makeCoarse, makeFineRestart,print + 1 + + + + + dummyIN + coarsemod + coarse + solns + + + solns + finemod + fineRestart + solnsRestart + + + solns + solnsRestart + coarse + restart + + + + + + 1 + 2 + + + 2 + 3 + + + + + + + u1 + 0.0 1.0 + + 2.0 + + + + u1 + 0.0 1.0 + + + u2 + 0.0 1.0 + + solns + + + + + + + + x1,x2,ans + + + x1,x2,ans + + + + + + x1,x2 + OutputPlaceHolder + + + x1,x2 + ans + + + x1,x2 + ans + + + + + + csv + solns + input,output + + + csv + solnsRestart + input,output + + + + diff --git a/tests/framework/Samplers/Restart/tests b/tests/framework/Samplers/Restart/tests index 0de2766ad7..8503749034 100644 --- a/tests/framework/Samplers/Restart/tests +++ b/tests/framework/Samplers/Restart/tests @@ -40,4 +40,11 @@ output = 'large/large_restart.xml' UnorderedCsv = 'large/large_restart.csv' [../] + + [./Constant] + type = 'RavenFramework' + input = 'test_restart_constant.xml' + UnorderedCsv = 'constant/coarse.csv constant/restart.csv' + remove_unicode_identifier = true + [../] []