File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,12 @@ PQEvaluatorType PQEvaluatorBasic::typeintused() const
8686}
8787
8888
89+ void PQEvaluatorBasic::validate (PairQuantity& pq) const
90+ {
91+ return ;
92+ }
93+
94+
8995void PQEvaluatorBasic::updateValue (
9096 PairQuantity& pq, StructureAdapterPtr stru)
9197{
@@ -162,6 +168,14 @@ PQEvaluatorType PQEvaluatorOptimized::typeint() const
162168}
163169
164170
171+ void PQEvaluatorOptimized::validate (PairQuantity& pq) const
172+ {
173+ // Check if PairQuantity provides stashPartialValue.
174+ pq.stashPartialValue ();
175+ pq.restorePartialValue ();
176+ }
177+
178+
165179void PQEvaluatorOptimized::updateValue (
166180 PairQuantity& pq, StructureAdapterPtr stru)
167181{
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ class PQEvaluatorBasic
6565 virtual PQEvaluatorType typeint () const ;
6666 PQEvaluatorType typeintused () const ;
6767 virtual void updateValue (PairQuantity&, StructureAdapterPtr);
68+ virtual void validate (PairQuantity&) const ;
6869 void setFlag (PQEvaluatorFlag flag, bool value);
6970 bool getFlag (PQEvaluatorFlag flag) const ;
7071 void setupParallelRun (int cpuindex, int ncpu);
@@ -103,6 +104,7 @@ class PQEvaluatorOptimized : public PQEvaluatorBasic
103104
104105 // methods
105106 virtual PQEvaluatorType typeint () const ;
107+ virtual void validate (PairQuantity&) const ;
106108 virtual void updateValue (PairQuantity&, StructureAdapterPtr);
107109
108110 private:
Original file line number Diff line number Diff line change @@ -143,7 +143,20 @@ const double& PairQuantity::getRmax() const
143143void PairQuantity::setEvaluatorType (PQEvaluatorType evtp)
144144{
145145 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;
147160 this ->resetValue ();
148161}
149162
Original file line number Diff line number Diff line change 2525#include < diffpy/srreal/PQEvaluator.hpp>
2626#include < diffpy/srreal/AtomicStructureAdapter.hpp>
2727#include < diffpy/srreal/PDFCalculator.hpp>
28+ #include < diffpy/srreal/OverlapCalculator.hpp>
2829
2930namespace diffpy {
3031namespace srreal {
@@ -70,6 +71,7 @@ class TestPQEvaluator : public CxxTest::TestSuite
7071 mstru9->erase (9 );
7172 }
7273
74+
7375 void test_PDF_change_atom ()
7476 {
7577 PDFCalculator pdfcb;
@@ -148,6 +150,16 @@ class TestPQEvaluator : public CxxTest::TestSuite
148150 TS_ASSERT (allclose (gb, go));
149151 }
150152
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+
151163}; // class TestPQEvaluator
152164
153165} // namespace srreal
You can’t perform that action at this time.
0 commit comments