TBTK
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:
44 
49  SourceAmplitude(std::complex<double> amplitude, Index index);
50 
60  std::complex<double> (*amplitudeCallback)(const Index &index),
61  Index index
62  );
63 
72  const std::string &serializeation,
74  );
75 
79  std::complex<double> getAmplitude() const;
80 
84  const Index& getIndex() const;
85 
89  std::string toString() const;
90 
99  std::string serialize(Serializable::Mode mode) const;
100 
104  unsigned int getSizeInBytes() const;
105 private:
108  std::complex<double> amplitude;
109 
112  std::complex<double> (*amplitudeCallback)(const Index &index);
113 
115  Index index;
116 
117 };
118 
119 inline SourceAmplitude::SourceAmplitude() : amplitudeCallback(nullptr){
120 }
121 
122 inline std::complex<double> SourceAmplitude::getAmplitude() const{
123  if(amplitudeCallback)
124  return amplitudeCallback(index);
125  else
126  return amplitude;
127 }
128 
129 inline const Index& SourceAmplitude::getIndex() const{
130  return index;
131 }
132 
133 inline std::string SourceAmplitude::toString() const{
134  std::string str;
135  str += "("
136  + std::to_string(real(amplitude))
137  + ", " + std::to_string(imag(amplitude))
138  + ")"
139  + ", " + index.toString();
140 
141  return str;
142 }
143 
144 inline unsigned int SourceAmplitude::getSizeInBytes() const{
145  return sizeof(SourceAmplitude)
146  - sizeof(index)
147  + index.getSizeInBytes();
148 }
149 
150 }; //End of namespace TBTK
151 
152 #endif
SourceAmplitude()
Definition: SourceAmplitude.h:119
Flexible physical index.
std::string serialize(Serializable::Mode mode) const
unsigned int getSizeInBytes() const
Definition: Index.h:414
Source amplitude for equations with a source term.
Definition: SourceAmplitude.h:40
const Index & getIndex() const
Definition: SourceAmplitude.h:129
Flexible physical index.
Definition: Index.h:69
Definition: ModelFactory.h:35
std::string toString() const
Definition: SourceAmplitude.h:133
Mode
Definition: Serializable.h:44
std::complex< double > getAmplitude() const
Definition: SourceAmplitude.h:122
Abstract base class for serializable objects.
unsigned int getSizeInBytes() const
Definition: SourceAmplitude.h:144
std::string toString() const
Definition: Index.h:282