source: ThirdParty/mpqc_open/src/lib/util/misc/compute.cc@ b7e5b0

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since b7e5b0 was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 5.1 KB
Line 
1//
2// compute.cc
3//
4// Copyright (C) 1996 Limit Point Systems, Inc.
5//
6// Author: Curtis Janssen <cljanss@limitpt.com>
7// Maintainer: LPS
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifdef __GNUC__
29#pragma implementation
30#endif
31
32#include <math.h>
33#include <float.h>
34#ifdef HAVE_CONFIG_H
35#include <scconfig.h>
36#endif
37#include <util/class/scexception.h>
38#include <util/misc/formio.h>
39#include <util/misc/compute.h>
40#include <util/state/state.h>
41#include <util/state/stateio.h>
42
43using namespace std;
44using namespace sc;
45
46#ifdef EXPLICIT_TEMPLATE_INSTANTIATION
47template class Result<int>;
48template class Result<double>;
49template class NCAccResult<double>;
50#endif
51
52Compute::Compute()
53{
54}
55
56Compute::~Compute()
57{
58}
59
60void
61Compute::add(ResultInfo*r)
62{
63 _results.insert(r);
64}
65
66void
67Compute::obsolete()
68{
69 // go thru all of the results and mark them as obsolete
70 for (std::set<ResultInfoP>::iterator i = _results.begin();
71 i!=_results.end(); i++) {
72 (*i)->computed() = 0;
73 }
74}
75
76////////////////////////////////////////////////////////////////////////
77
78ResultInfo::ResultInfo(Compute*c):
79 _compute(0),_computed(0),_c(c)
80{
81 c->add(this);
82}
83
84void
85ResultInfo::update() {
86 if (!computed()) {
87 int oldcompute = compute(1);
88 _c->compute();
89 compute() = oldcompute;
90 if (!computed()) {
91 ExEnv::errn() << "ResultInfo::update: nothing was computed" << endl;
92 abort();
93 }
94 }
95}
96
97ResultInfo::~ResultInfo()
98{
99}
100
101ResultInfo::ResultInfo(StateIn&s,Compute*c):
102 _c(c)
103{
104 s.get(_compute);
105 s.get(_computed);
106
107 c->add(this);
108}
109
110ResultInfo::ResultInfo(const ResultInfo&r, Compute*c) :
111 _c(c)
112{
113 _compute=r._compute;
114 _computed=r._computed;
115
116 c->add(this);
117}
118
119void
120ResultInfo::restore_state(StateIn&s)
121{
122 s.get(_compute);
123 s.get(_computed);
124}
125
126void
127ResultInfo::save_data_state(StateOut&s)
128{
129 s.put(_compute);
130 s.put(_computed);
131}
132
133ResultInfo&
134ResultInfo::operator=(const ResultInfo&r)
135{
136 _compute=r._compute;
137 _computed=r._computed;
138 return *this;
139}
140
141int
142ResultInfo::needed() const
143{
144 return _compute && (!_computed);
145}
146
147/////////////////////////////////////////////////////////////////////////
148
149AccResultInfo::AccResultInfo(Compute*c):
150 ResultInfo(c),
151 _actual_accuracy(0.0),
152 _desired_accuracy(0.01)
153{
154}
155
156AccResultInfo::~AccResultInfo()
157{
158}
159
160double
161AccResultInfo::actual_accuracy() const
162{
163 return _actual_accuracy;
164}
165
166double
167AccResultInfo::desired_accuracy() const
168{
169 return _desired_accuracy;
170}
171
172void
173AccResultInfo::set_desired_accuracy(double a)
174{
175 _desired_accuracy = a;
176 if (_desired_accuracy < _actual_accuracy &&
177 (fabs(_actual_accuracy)-fabs(_desired_accuracy)) > DBL_EPSILON) {
178 computed() = 0;
179 }
180}
181
182void
183AccResultInfo::set_actual_accuracy(double a)
184{
185 _actual_accuracy = a;
186 computed() = 1;
187}
188
189AccResultInfo::AccResultInfo(StateIn&s,Compute*c):
190 ResultInfo(s,c)
191{
192 s.get(_actual_accuracy);
193 s.get(_desired_accuracy);
194}
195
196AccResultInfo::AccResultInfo(const AccResultInfo&a, Compute*c) :
197 ResultInfo(a,c)
198{
199 _actual_accuracy=a._actual_accuracy;
200 _desired_accuracy=a._desired_accuracy;
201}
202
203void
204AccResultInfo::restore_state(StateIn&s)
205{
206 ResultInfo::restore_state(s);
207 s.get(_actual_accuracy);
208 s.get(_desired_accuracy);
209}
210
211void
212AccResultInfo::save_data_state(StateOut&s)
213{
214 ResultInfo::save_data_state(s);
215 s.put(_actual_accuracy);
216 s.put(_desired_accuracy);
217}
218
219AccResultInfo&
220AccResultInfo::operator=(const AccResultInfo&a)
221{
222 ResultInfo::operator=(a);
223 _actual_accuracy=a._actual_accuracy;
224 _desired_accuracy=a._desired_accuracy;
225 return *this;
226}
227
228int
229AccResultInfo::needed() const
230{
231 return compute() && !computed_to_desired_accuracy();
232}
233
234void
235AccResultInfo::update() {
236 if (!computed_to_desired_accuracy()) {
237 int oldcompute = compute(1);
238 _c->compute();
239 compute() = oldcompute;
240 if (!computed()) {
241 ExEnv::outn() << "AccResultInfo::update: nothing was computed"
242 << endl;
243 abort();
244 }
245 if (_actual_accuracy > _desired_accuracy) {
246 throw ToleranceExceeded("AccResultInfo::update(): "
247 "desired accuracy not achieved",
248 __FILE__, __LINE__,
249 _desired_accuracy, _actual_accuracy);
250 }
251 }
252}
253
254/////////////////////////////////////////////////////////////////////////////
255
256// Local Variables:
257// mode: c++
258// c-file-style: "CLJ"
259// End:
Note: See TracBrowser for help on using the repository browser.