TBTK
Need a break? Support the development by playing Polarity Puzzles
BoundaryCondition.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 
26 #ifndef COM_DAFER45_TBTK_BOUNDARY_CONDITION
27 #define COM_DAFER45_TBTK_BOUNDARY_CONDITION
28 
29 #include "TBTK/HoppingAmplitude.h"
31 #include "TBTK/Serializable.h"
32 #include "TBTK/SourceAmplitude.h"
33 
34 #include <vector>
35 
36 namespace TBTK{
37 
50 public:
53 
62  const std::string &serializeation,
64  );
65 
69  void add(const HoppingAmplitude &hoppingAmplitude);
70 
78 
82  void set(const SourceAmplitude &sourceAmplitude);
83 
87  const SourceAmplitude& getSourceAmplitude() const;
88 
93  void setEliminationIndex(const Index &eliminationIndex);
94 
99  const Index& getEliminationIndex() const;
100 
107  std::string serialize(Serializable::Mode mode) const;
108 
112  unsigned int getSizeInBytes() const;
113 private:
115  HoppingAmplitudeList hoppingAmplitudeList;
116 
118  SourceAmplitude sourceAmplitude;
119 
121  Index eliminationIndex;
122 };
123 
125 }
126 
127 inline void BoundaryCondition::add(const HoppingAmplitude &hoppingAmplitude){
128  if(hoppingAmplitudeList.getSize() > 0){
129  TBTKAssert(
130  hoppingAmplitude.getToIndex().equals(
131  hoppingAmplitudeList[0].getToIndex()
132  ),
133  "BoundaryCondition::add()",
134  "Incompatible to-Indices. All HoppingAmplitudes in a"
135  << " BoundaryCondition must have the same to-Index."
136  << " The added HoppingAmplitude has to-Index '"
137  << hoppingAmplitude.getToIndex().toString() << "'"
138  << " while a HoppingAmplitude with to-Index '"
139  << hoppingAmplitudeList[0].getToIndex().toString()
140  << "' already has been added.",
141  ""
142  );
143  }
144  else{
145  if(!sourceAmplitude.getIndex().equals({})){
146  TBTKAssert(
147  hoppingAmplitude.getToIndex().equals(
148  sourceAmplitude.getIndex()
149  ),
150  "BoundaryCondition::add()",
151  "Incompatible Indices. The HoppingAmplitude"
152  << " must have the same to-Index as the Index"
153  << " of the SourceAmplitude. The"
154  << " HoppingAmplitude has to-Index '"
155  << hoppingAmplitude.getToIndex().toString()
156  << "' while the SourceAmplitude has Index '"
157  << sourceAmplitude.getIndex().toString() << "'.",
158  ""
159  );
160  }
161  }
162 
163  hoppingAmplitudeList.add(hoppingAmplitude);
164 }
165 
167  return hoppingAmplitudeList;
168 }
169 
170 inline void BoundaryCondition::set(const SourceAmplitude &sourceAmplitude){
171  TBTKAssert(
172  !sourceAmplitude.getIndex().equals({}),
173  "BoundaryCondition::set()",
174  "Invalid Index. The SourceAmplitudes Index cannot be the empty"
175  << "Index.",
176  ""
177  );
178  if(hoppingAmplitudeList.getSize() > 0){
179  TBTKAssert(
180  sourceAmplitude.getIndex().equals(
181  hoppingAmplitudeList[0].getToIndex()
182  ),
183  "BoundaryCondition::set()",
184  "Incompatible Indices. The SourceAmplitude must have"
185  << " the same Index as the HoppingAmplitudes"
186  << " to-Indices. The SourceAmplitude has Index '"
187  << sourceAmplitude.getIndex().toString() << "' while a"
188  << " HoppingAmplitude with to-Index '"
189  << hoppingAmplitudeList[0].getToIndex().toString()
190  << "' already has been added.",
191  ""
192  );
193  }
194 
195  this->sourceAmplitude = sourceAmplitude;
196 }
197 
199  return sourceAmplitude;
200 }
201 
202 inline void BoundaryCondition::setEliminationIndex(const Index &eliminationIndex){
203  bool eliminationIndexFound = false;
204  for(unsigned int n = 0; n < hoppingAmplitudeList.getSize(); n++){
205  if(
206  hoppingAmplitudeList[n].getFromIndex().equals(
207  eliminationIndex
208  )
209  ){
210  eliminationIndexFound = true;
211  break;
212  }
213  }
214  TBTKAssert(
215  eliminationIndexFound,
216  "BoundaryCondition::setEliminationIndex()",
217  "Invalid elimination Index. The elimination Index must be"
218  << " equal to the from-Index of at least one HoppingAmplitude"
219  << " added to the BoundaryCondition but no such from-Index was"
220  << " found.",
221  "First add HoppingAmplitudes using BoundaryCondition::add()"
222  );
223 
224  this->eliminationIndex = eliminationIndex;
225 }
226 
228  return eliminationIndex;
229 }
230 
231 inline unsigned int BoundaryCondition::getSizeInBytes() const{
232  return sizeof(*this)
233  + hoppingAmplitudeList.getSizeInBytes() - sizeof(hoppingAmplitudeList)
234  + sourceAmplitude.getSizeInBytes() - sizeof(sourceAmplitude)
235  + eliminationIndex.getSizeInBytes() - sizeof(eliminationIndex);
236 }
237 
238 }; //End of namespace TBTK
239 
240 #endif
HoppingAmplitudeList.h
List of HoppingAmplitudes .
TBTK::HoppingAmplitudeList
List of HoppingAmplitudes .
Definition: HoppingAmplitudeList.h:34
TBTK::BoundaryCondition::setEliminationIndex
void setEliminationIndex(const Index &eliminationIndex)
Definition: BoundaryCondition.h:202
TBTK::Index::toString
std::string toString() const
Definition: Index.h:349
TBTK::BoundaryCondition::getHoppingAmplitudeList
const HoppingAmplitudeList & getHoppingAmplitudeList() const
Definition: BoundaryCondition.h:166
TBTK::Index::equals
bool equals(const Index &index, bool allowWildcard=false) const
Definition: Index.h:411
TBTK::BoundaryCondition::getEliminationIndex
const Index & getEliminationIndex() const
Definition: BoundaryCondition.h:227
TBTK::Index::getSizeInBytes
unsigned int getSizeInBytes() const
Definition: Index.h:548
TBTK::BoundaryCondition::getSizeInBytes
unsigned int getSizeInBytes() const
Definition: BoundaryCondition.h:231
TBTK::BoundaryCondition::add
void add(const HoppingAmplitude &hoppingAmplitude)
Definition: BoundaryCondition.h:127
TBTK::HoppingAmplitudeList::getSizeInBytes
unsigned int getSizeInBytes() const
Definition: HoppingAmplitudeList.h:101
TBTK::Serializable
Definition: Serializable.h:43
TBTK::BoundaryCondition
A set of HoppingAmplitudes , a SourceAmplitude, and an elimination Index, which together form a singl...
Definition: BoundaryCondition.h:49
SourceAmplitude.h
Source amplitude for equations with a source term.
TBTK::HoppingAmplitudeList::add
void add(const HoppingAmplitude &hoppingAmplitude)
Definition: HoppingAmplitudeList.h:85
TBTK::SourceAmplitude
Source amplitude for equations with a source term.
Definition: SourceAmplitude.h:40
TBTK::HoppingAmplitude::getToIndex
const Index & getToIndex() const
Definition: HoppingAmplitude.h:264
Serializable.h
Abstract base class for serializable objects.
TBTK::BoundaryCondition::serialize
std::string serialize(Serializable::Mode mode) const
TBTK::SourceAmplitude::getSizeInBytes
unsigned int getSizeInBytes() const
Definition: SourceAmplitude.h:161
TBTK::HoppingAmplitude
Hopping amplitude from state 'from' to state 'to'.
Definition: HoppingAmplitude.h:53
TBTK::BoundaryCondition::BoundaryCondition
BoundaryCondition()
Definition: BoundaryCondition.h:124
HoppingAmplitude.h
Hopping amplitude from state 'from' to state 'to'.
TBTK::Serializable::Mode
Mode
Definition: Serializable.h:47
TBTK::SourceAmplitude::getIndex
const Index & getIndex() const
Definition: SourceAmplitude.h:146
TBTK::BoundaryCondition::set
void set(const SourceAmplitude &sourceAmplitude)
Definition: BoundaryCondition.h:170
TBTK::HoppingAmplitudeList::getSize
unsigned int getSize() const
Definition: HoppingAmplitudeList.h:91
TBTK::Index
Physical index.
Definition: Index.h:44
TBTK::BoundaryCondition::getSourceAmplitude
const SourceAmplitude & getSourceAmplitude() const
Definition: BoundaryCondition.h:198