OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ConcreteVar.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: ConcreteVar.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.5 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: ConcreteVar
10 // This class is the concrete class for a single variable to be varied
11 // during matching. It implements the setting and retrieving of the
12 // value in the system to be adjusted.
13 //
14 // JMJ 7/4/2000: changed to make output from MATCH like OPAL input.
15 //
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2002/03/28 21:27:54 $
19 // $Author: jsberg $
20 //
21 // ------------------------------------------------------------------------
22 
23 #include "Match/ConcreteVar.h"
25 #include "Attributes/Attributes.h"
26 #include <cmath>
27 #include <iomanip>
28 #include <iostream>
29 #include <algorithm>
30 
31 
32 // Class ConcreteVar
33 // ------------------------------------------------------------------------
34 
35 
37 (const std::string &name, Attribute &attr, int limits, double pars[4]):
38  AbstractVar(name),
39  itsAttr(attr),
40  itsStep(std::abs(pars[1])),
41  itsLimits(limits),
42  itsMin(pars[2]),
43  itsMax(pars[3]) {
44  // Builtin constant.
45  const double stplim = 0.2;
46 
47  // Convert the step sizes.
48  switch(limits) {
49  case UPPER_LIMIT:
50  case LOWER_LIMIT:
51  if(pars[0] != 0.0) itsStep /= pars[0];
52  break;
53  case BOTH_LIMITS:
54  itsStep /= sqrt(pars[0] * (pars[0] - itsMin - itsMax) + itsMin * itsMax);
55  break;
56  default:
57  break;
58  }
59 
60  // Bring the step in range.
61  if(itsStep > stplim) itsStep = stplim;
62 }
63 
64 
66 {}
67 
68 
70  double value = Attributes::getReal(itsAttr);
71 
72  switch(itsLimits) {
73  case LOWER_LIMIT:
74  if(value < itsMin) value = itsMin;
75  return sqrt(value - itsMin);
76  case UPPER_LIMIT:
77  if(value > itsMax) value = itsMax;
78  return sqrt(itsMax - value);
79  case BOTH_LIMITS:
80  if(value < itsMin) value = itsMin;
81  if(value > itsMax) value = itsMax;
82  return asin((value + value - itsMin - itsMax) / (itsMax - itsMin));
83  default:
84  return value;
85  }
86 }
87 
88 
89 void ConcreteVar::setInternalValue(double value) {
90  // Store internal value to chache.
91  switch(itsLimits) {
92  case LOWER_LIMIT:
93  value = itsMin + value * value;
94  break;
95  case UPPER_LIMIT:
96  value = itsMax - value * value;
97  break;
98  case BOTH_LIMITS:
99  value = ((itsMin + itsMax) + (itsMax - itsMin) * sin(value)) / 2.0;
100  break;
101  default:
102  break;
103  }
104 
105  // Transmit to data structure.
106  setExternalValue(value);
107 }
108 
109 
112 }
113 
114 
115 void ConcreteVar::setExternalValue(double value) {
116  // Transmit external value to cache and to data structure.
119 }
120 
121 
122 void ConcreteVar::print(std::ostream &os) const {
123  std::streamsize old_prec = os.precision(10);
124  os << itsName << " := "
125  << std::setw(16) << getExternalValue() << ";" << std::endl;
126  os.precision(old_prec);
127 }
128 // Above changed by JMJ, 7/4/2000, increased precision to 10, swapped columns
129 // and slipped in the ":=".
130 // Doesn't seem to be happening in version of July 2000 ??
void setReal(Attribute &attr, double val)
Set real value.
Definition: Attributes.cpp:236
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
Tps< T > sin(const Tps< T > &x)
Sine.
Definition: TpsMath.h:111
const std::string itsName
Name of the variable.
Definition: AbstractVar.h:62
static OpalData * getInstance()
Definition: OpalData.cpp:209
A representation of an Object attribute.
Definition: Attribute.h:55
virtual void setExternalValue(double)
Set the current external parameter value.
virtual double getInternalValue() const
Get the current internal parameter value.
Definition: ConcreteVar.cpp:69
virtual double getExternalValue() const
Get the current external parameter value.
int precision() const
Definition: Inform.h:115
Tps< T > sqrt(const Tps< T > &x)
Square root.
Definition: TpsMath.h:91
double itsMin
Definition: ConcreteVar.h:86
Attribute itsAttr
Definition: ConcreteVar.h:79
virtual void print(std::ostream &) const
Print the variable name and value.
const std::string name
PETE_TUTree< FnArcSin, typename T::PETE_Expr_t > asin(const PETE_Expr< T > &l)
Definition: PETE.h:809
virtual void setInternalValue(double)
Set the current internal parameter value.
Definition: ConcreteVar.cpp:89
Abstract base for a matching variable.
Definition: AbstractVar.h:31
double getReal(const Attribute &attr)
Return real value.
Definition: Attributes.cpp:217
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
void makeDirty(Object *object)
Invalidate expressions.
Definition: OpalData.cpp:629
virtual ~ConcreteVar()
Definition: ConcreteVar.cpp:65
double itsMax
Definition: ConcreteVar.h:87