OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
SFunction.cpp
Go to the documentation of this file.
1 // ------------------------------------------------------------------------
2 // $RCSfile: SFunction.cpp,v $
3 // ------------------------------------------------------------------------
4 // $Revision: 1.1.1.1 $
5 // ------------------------------------------------------------------------
6 // Copyright: see Copyright.readme
7 // ------------------------------------------------------------------------
8 //
9 // Class: SFunction
10 // Object handling the position funcitions SI(), SC(), and SO().
11 //
12 // ------------------------------------------------------------------------
13 //
14 // $Date: 2000/03/27 09:33:42 $
15 // $Author: Andreas Adelmann $
16 //
17 // ------------------------------------------------------------------------
18 
19 #include "Expressions/SFunction.h"
21 
22 
23 // The pointer to the current s-dependent function.
24 // ------------------------------------------------------------------------
25 
26 const SFunction *SFunction::sfun = 0;
27 
28 
29 // Class SFunction
30 // ------------------------------------------------------------------------
31 
33  reset();
34  sfun = this;
35 }
36 
37 
39  sfun = 0;
40 }
41 
42 
43 double SFunction::arcIn() {
44  if(sfun) {
45  return sfun->position(1.0);
46  } else {
47  throw OpalException("arcIn()",
48  "The use of function \"SI()\" "
49  "is not valid in this context.");
50  }
51 }
52 
53 
55  if(sfun) {
56  return sfun->position(0.5);
57  } else {
58  throw OpalException("arcCtr()",
59  "The use of function \"SC()\" "
60  "is not valid in this context.");
61  }
62 }
63 
64 
66  if(sfun) {
67  return sfun->position(0.0);
68  } else {
69  throw OpalException("arcOut()",
70  "The use of function \"SO()\" "
71  "is not valid in this context.");
72  }
73 }
74 
75 
77  elementLength = 0.0;
78  exitArc = 0.0;
79 }
80 
81 
82 void SFunction::update(double length) {
83  elementLength = length;
85 }
86 
87 
88 double SFunction::position(double flag) const {
89  // Backtrack to desired position.
90  return exitArc - flag * elementLength;
91 }
~SFunction()
Destructor.
Definition: SFunction.cpp:38
Functions of arc length.
Definition: SFunction.h:31
static double arcIn()
Return arc length at entrance SI().
Definition: SFunction.cpp:43
The base class for all OPAL exceptions.
Definition: OpalException.h:28
static double arcOut()
Return arc length at exit SO().
Definition: SFunction.cpp:65
SFunction()
Default constructor.
Definition: SFunction.cpp:32
void update(double length)
Advance position by element length.
Definition: SFunction.cpp:82
double exitArc
Definition: SFunction.h:73
static double arcCtr()
Return arc length at center SC().
Definition: SFunction.cpp:54
void reset()
Reset the arc length to zero.
Definition: SFunction.cpp:76
double position(double flag) const
Definition: SFunction.cpp:88
double elementLength
Definition: SFunction.h:70
static const SFunction * sfun
Definition: SFunction.h:77