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:
46  SourceAmplitude(std::complex<double> amplitude, Index index);
47 
57  std::complex<double> (*amplitudeCallback)(const Index &index),
58  Index index
59  );
60 
69  const std::string &serializeation,
71  );
72 
76  std::complex<double> getAmplitude() const;
77 
81  const Index& getIndex() const;
82 
86  std::string toString() const;
87 
96  std::string serialize(Serializable::Mode mode) const;
97 
101  unsigned int getSizeInBytes() const;
102 private:
105  std::complex<double> amplitude;
106 
109  std::complex<double> (*amplitudeCallback)(const Index &index);
110 
112  Index index;
113 
114 };
115 
116 inline std::complex<double> SourceAmplitude::getAmplitude() const{
117  if(amplitudeCallback)
118  return amplitudeCallback(index);
119  else
120  return amplitude;
121 }
122 
123 inline const Index& SourceAmplitude::getIndex() const{
124  return index;
125 }
126 
127 inline std::string SourceAmplitude::toString() const{
128  std::string str;
129  str += "("
130  + std::to_string(real(amplitude))
131  + ", " + std::to_string(imag(amplitude))
132  + ")"
133  + ", " + index.toString();
134 
135  return str;
136 }
137 
138 inline unsigned int SourceAmplitude::getSizeInBytes() const{
139  return sizeof(SourceAmplitude)
140  - sizeof(index)
141  + index.getSizeInBytes();
142 }
143 
144 }; //End of namespace TBTK
145 
146 #endif
Flexible physical index.
std::string serialize(Serializable::Mode mode) const
unsigned int getSizeInBytes() const
Definition: Index.h:384
Source amplitude for equations with a source term.
Definition: SourceAmplitude.h:40
const Index & getIndex() const
Definition: SourceAmplitude.h:123
Flexible physical index.
Definition: Index.h:70
Definition: ModelFactory.h:35
std::string toString() const
Definition: SourceAmplitude.h:127
Mode
Definition: Serializable.h:44
std::complex< double > getAmplitude() const
Definition: SourceAmplitude.h:116
SourceAmplitude(std::complex< double > amplitude, Index index)
Abstract base class for serializable objects.
unsigned int getSizeInBytes() const
Definition: SourceAmplitude.h:138
std::string toString() const
Definition: Index.h:265