TBTK
Need a break? Support the development by playing Polarity Puzzles
SourceAmplitude.h
Go to the documentation of this file.
1 /* Copyright 2018 Kristofer Björnson
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
23 #ifndef COM_DAFER45_TBTK_SOURCE_AMPLITUDE
24 #define COM_DAFER45_TBTK_SOURCE_AMPLITUDE
25 
26 #include "TBTK/Index.h"
27 #include "TBTK/Serializable.h"
28 
29 #include <complex>
30 #include <initializer_list>
31 #include <vector>
32 
33 namespace TBTK{
34 
41 public:
45  public:
54  virtual std::complex<double> getSourceAmplitude(
55  const Index &index
56  ) const = 0;
57  };
58 
61 
66  SourceAmplitude(std::complex<double> amplitude, Index index);
67 
77  const AmplitudeCallback &amplitudeCallback,
78  Index index
79  );
80 
89  const std::string &serializeation,
91  );
92 
96  std::complex<double> getAmplitude() const;
97 
101  const Index& getIndex() const;
102 
106  std::string toString() const;
107 
116  std::string serialize(Serializable::Mode mode) const;
117 
121  unsigned int getSizeInBytes() const;
122 private:
125  std::complex<double> amplitude;
126 
129  const AmplitudeCallback *amplitudeCallback;
130 
132  Index index;
133 
134 };
135 
136 inline SourceAmplitude::SourceAmplitude() : amplitudeCallback(nullptr){
137 }
138 
139 inline std::complex<double> SourceAmplitude::getAmplitude() const{
140  if(amplitudeCallback)
141  return amplitudeCallback->getSourceAmplitude(index);
142  else
143  return amplitude;
144 }
145 
146 inline const Index& SourceAmplitude::getIndex() const{
147  return index;
148 }
149 
150 inline std::string SourceAmplitude::toString() const{
151  std::string str;
152  str += "("
153  + std::to_string(real(amplitude))
154  + ", " + std::to_string(imag(amplitude))
155  + ")"
156  + ", " + index.toString();
157 
158  return str;
159 }
160 
161 inline unsigned int SourceAmplitude::getSizeInBytes() const{
162  return sizeof(SourceAmplitude)
163  - sizeof(index)
164  + index.getSizeInBytes();
165 }
166 
167 }; //End of namespace TBTK
168 
169 #endif
std::complex< double > getAmplitude() const
Definition: SourceAmplitude.h:139
SourceAmplitude()
Definition: SourceAmplitude.h:136
Physical index.
unsigned int getSizeInBytes() const
Definition: Index.h:548
Definition: Serializable.h:43
Source amplitude for equations with a source term.
Definition: SourceAmplitude.h:40
std::string toString() const
Definition: Index.h:349
Definition: SourceAmplitude.h:44
virtual std::complex< double > getSourceAmplitude(const Index &index) const =0
Physical index.
Definition: Index.h:44
Definition: Boolean.h:32
Mode
Definition: Serializable.h:47
unsigned int getSizeInBytes() const
Definition: SourceAmplitude.h:161
std::string serialize(Serializable::Mode mode) const
std::string toString() const
Definition: SourceAmplitude.h:150
const Index & getIndex() const
Definition: SourceAmplitude.h:146
Abstract base class for serializable objects.