File tree Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Expand file tree Collapse file tree 4 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,12 @@ PQEvaluatorType PQEvaluatorBasic::typeintused() const
86
86
}
87
87
88
88
89
+ void PQEvaluatorBasic::validate (PairQuantity& pq) const
90
+ {
91
+ return ;
92
+ }
93
+
94
+
89
95
void PQEvaluatorBasic::updateValue (
90
96
PairQuantity& pq, StructureAdapterPtr stru)
91
97
{
@@ -162,6 +168,14 @@ PQEvaluatorType PQEvaluatorOptimized::typeint() const
162
168
}
163
169
164
170
171
+ void PQEvaluatorOptimized::validate (PairQuantity& pq) const
172
+ {
173
+ // Check if PairQuantity provides stashPartialValue.
174
+ pq.stashPartialValue ();
175
+ pq.restorePartialValue ();
176
+ }
177
+
178
+
165
179
void PQEvaluatorOptimized::updateValue (
166
180
PairQuantity& pq, StructureAdapterPtr stru)
167
181
{
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ class PQEvaluatorBasic
65
65
virtual PQEvaluatorType typeint () const ;
66
66
PQEvaluatorType typeintused () const ;
67
67
virtual void updateValue (PairQuantity&, StructureAdapterPtr);
68
+ virtual void validate (PairQuantity&) const ;
68
69
void setFlag (PQEvaluatorFlag flag, bool value);
69
70
bool getFlag (PQEvaluatorFlag flag) const ;
70
71
void setupParallelRun (int cpuindex, int ncpu);
@@ -103,6 +104,7 @@ class PQEvaluatorOptimized : public PQEvaluatorBasic
103
104
104
105
// methods
105
106
virtual PQEvaluatorType typeint () const ;
107
+ virtual void validate (PairQuantity&) const ;
106
108
virtual void updateValue (PairQuantity&, StructureAdapterPtr);
107
109
108
110
private:
Original file line number Diff line number Diff line change @@ -143,7 +143,20 @@ const double& PairQuantity::getRmax() const
143
143
void PairQuantity::setEvaluatorType (PQEvaluatorType evtp)
144
144
{
145
145
if (mevaluator.get () && mevaluator->typeint () == evtp) return ;
146
- mevaluator = createPQEvaluator (evtp, mevaluator);
146
+ PQEvaluatorPtr pqev = createPQEvaluator (evtp, mevaluator);
147
+ // validate the new evaluator object
148
+ try
149
+ {
150
+ pqev->validate (*this );
151
+ }
152
+ catch (logic_error e)
153
+ {
154
+ string emsg (" EvaluatorType not supported. " );
155
+ emsg += e.what ();
156
+ throw invalid_argument (emsg);
157
+ }
158
+ // validator is good here, use it now.
159
+ mevaluator = pqev;
147
160
this ->resetValue ();
148
161
}
149
162
Original file line number Diff line number Diff line change 25
25
#include < diffpy/srreal/PQEvaluator.hpp>
26
26
#include < diffpy/srreal/AtomicStructureAdapter.hpp>
27
27
#include < diffpy/srreal/PDFCalculator.hpp>
28
+ #include < diffpy/srreal/OverlapCalculator.hpp>
28
29
29
30
namespace diffpy {
30
31
namespace srreal {
@@ -70,6 +71,7 @@ class TestPQEvaluator : public CxxTest::TestSuite
70
71
mstru9->erase (9 );
71
72
}
72
73
74
+
73
75
void test_PDF_change_atom ()
74
76
{
75
77
PDFCalculator pdfcb;
@@ -148,6 +150,16 @@ class TestPQEvaluator : public CxxTest::TestSuite
148
150
TS_ASSERT (allclose (gb, go));
149
151
}
150
152
153
+
154
+ void test_optimized_unsupported ()
155
+ {
156
+ OverlapCalculator olc;
157
+ TS_ASSERT_EQUALS (BASIC, olc.getEvaluatorType ());
158
+ TS_ASSERT_THROWS (
159
+ olc.setEvaluatorType (OPTIMIZED), invalid_argument);
160
+ TS_ASSERT_EQUALS (BASIC, olc.getEvaluatorType ());
161
+ }
162
+
151
163
}; // class TestPQEvaluator
152
164
153
165
} // namespace srreal
You can’t perform that action at this time.
0 commit comments