source: ThirdParty/mpqc_open/src/lib/util/misc/compute.h@ bbc982

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 bbc982 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: 4.4 KB
Line 
1//
2// compute.h
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 interface
30#endif
31
32#ifndef _util_misc_compute_h
33#define _util_misc_compute_h
34
35#include <set>
36
37#include <util/state/state.h>
38#include <util/state/stateio.h>
39
40namespace sc {
41
42class ResultInfo;
43class StateIn;
44class StateOut;
45
46typedef ResultInfo* ResultInfoP;
47
48/** The Compute class provides a means of keeping results up
49 to date. Derived classes can have member data which is
50 registered with the compute class. When this member data
51 is accessed and it is not available, the compute member
52 function is called. The compute member must be implemented
53 in derived classes and is responsible for computed the
54 requested result. */
55class Compute
56{
57 friend class ResultInfo;
58 friend class AccResultInfo;
59 private:
60 std::set<ResultInfoP> _results;
61 void add(ResultInfo*);
62
63 // Prohibit copy
64 Compute(const Compute&) {};
65
66 protected:
67 /** Recompute at least the results that have compute true
68 and are not already computed. This should only be called
69 by Result's members. */
70 virtual void compute() = 0;
71 public:
72 Compute();
73 virtual ~Compute();
74
75 /** Marks all results as being out of date. Any subsequent access
76 to results will cause Compute::compute() to be called. */
77 virtual void obsolete();
78};
79
80/** This is a base class for all of Compute's result types. Usually
81 Result<Type> will be used to create a result that has a particular datum
82 associated with it, however a ResultInfo can also be declared to keep
83 track of datum's for which it is awkward to use Result_dec. */
84class ResultInfo
85{
86 protected:
87 int _compute;
88 int _computed;
89 Compute* _c;
90 // This make sure that the datum is up to date. If it is not then
91 // Compute::compute() will be called.
92 virtual void update();
93 protected:
94 ResultInfo(StateIn&,Compute*);
95 ResultInfo(const ResultInfo&,Compute*);
96 virtual void save_data_state(StateOut&);
97 virtual void restore_state(StateIn&);
98 ResultInfo& operator=(const ResultInfo&);
99 public:
100 ResultInfo(Compute*c);
101 virtual ~ResultInfo();
102 int& compute() { return _compute; }
103 const int& compute() const { return _compute; }
104 int compute(int c) { int r = _compute; _compute = c; return r; }
105 int& computed() { return _computed; }
106 const int& computed() const { return _computed; }
107 virtual int needed() const;
108};
109
110/** This is like ResultInfo but the accuracy with which a result was
111 computed as well as the desired accuracy are stored. */
112class AccResultInfo: public ResultInfo
113{
114 private:
115 double _actual_accuracy;
116 double _desired_accuracy;
117 protected:
118 AccResultInfo(StateIn&,Compute*);
119 AccResultInfo(const AccResultInfo&,Compute*);
120 virtual void save_data_state(StateOut&);
121 virtual void restore_state(StateIn&);
122 AccResultInfo& operator=(const AccResultInfo&);
123 void update();
124 public:
125 AccResultInfo(Compute*c);
126 ~AccResultInfo();
127 double actual_accuracy() const;
128 double desired_accuracy() const;
129 void set_desired_accuracy(double);
130 void set_actual_accuracy(double);
131 int computed_to_desired_accuracy() const
132 { return computed() && _actual_accuracy <= _desired_accuracy; }
133 int needed() const;
134};
135
136}
137
138#include <util/misc/comptmpl.h>
139
140namespace sc {
141
142typedef NCResult<int> Resultint;
143typedef NCResult<double> Resultdouble;
144typedef NCAccResult<double> AccResultdouble;
145
146}
147
148#endif
149
150// Local Variables:
151// mode: c++
152// c-file-style: "CLJ"
153// End:
Note: See TracBrowser for help on using the repository browser.