TBTK
CenteredDifference.h
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_CENTERED_DIFFERENCE
24 #define COM_DAFER45_TBTK_CENTERD_DIFFERENCE
25 
27 
28 namespace TBTK{
29 
32 public:
41  unsigned int subindex,
42  const Index &index,
43  double dx = 1
44  );
45 };
46 
48  unsigned int subindex,
49  const Index &index,
50  double dx
51 ){
52  TBTKAssert(
53  subindex < index.getSize(),
54  "CenteredDifference::CenteredDifference()",
55  "Invalid subindex. The subindex '" << subindex << "' is larger"
56  << " than the size of the Index '" << index.getSize() << "'.",
57  ""
58  );
59  TBTKAssert(
60  index[subindex] > 0,
61  "CenteredDifference::CenteredDifference()",
62  "Invalid subindex value. Unable to add a centered difference"
63  " for subindex '" << subindex << "' at '" << index.toString()
64  << "' since the centered difference would contain a negative"
65  << " subindex.",
66  "Modify the domain of the differential equation to ensure that"
67  << " no negative subindices are needed."
68  );
69 
70  Index backward = index;
71  backward[subindex]--;
72  Index forward = index;
73  forward[subindex]++;
74  add(HoppingAmplitude(1/(2*dx), index, backward));
75  add(HoppingAmplitude(-1/(2*dx), index, forward));
76 }
77 
78 }; //End of namespace TBTK
79 
80 #endif
List of HoppingAmplitudes .
Definition: HoppingAmplitudeList.h:34
void add(const HoppingAmplitude &hoppingAmplitude)
Definition: HoppingAmplitudeList.h:85
CenteredDifference(unsigned int subindex, const Index &index, double dx=1)
Definition: CenteredDifference.h:47
HoppingAmplitudeList corresponding to a centered difference.
Definition: CenteredDifference.h:31
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: HoppingAmplitude.h:49
Flexible physical index.
Definition: Index.h:69
Definition: ModelFactory.h:35
unsigned int getSize() const
Definition: Index.h:359
List of HoppingAmplitudes .
std::string toString() const
Definition: Index.h:282