Skip to content

Commit bce3637

Browse files
authored
Merge pull request #105 from LemurPwned/fix/electrical-connection
Reworking optional synchronisation option
2 parents 8103141 + 1bb1c5e commit bce3637

File tree

9 files changed

+505
-109
lines changed

9 files changed

+505
-109
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
# 1.8.0
4+
5+
- Fixing bugs in electrical coupling
6+
- You can now have useKCL = True Stacks which will implicitly preserve Kirchoff's current law, and will simulate perfect voltage sources
7+
8+
# 1.7.0
9+
10+
- Adaptive simulation is now available again with Dormand-Price method
11+
- Adding curated simulation examples
12+
- Memory cells are now supported (you can specify two polarisation vectors per Layer now)
13+
- Import fixes and other minor bugfixes
14+
315
# 1.6.2-1.6.6
416

517
- Fixed a bug in the `ScalarDriver` class which prevented the use of custom drivers with no arguments.

cmtj/stack/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ParallelStack:
99
topId: str = "free",
1010
bottomId: str = "bottom",
1111
phaseOffset: float = 0,
12+
useKCL: bool = True,
1213
) -> None:
1314
"""
1415
Initialises a parallel connection of junctions.
@@ -104,6 +105,7 @@ class SeriesStack:
104105
topId: str = "free",
105106
bottomId: str = "bottom",
106107
phaseOffset: float = 0,
108+
useKCL: bool = True,
107109
) -> None:
108110
"""
109111
Initialises a series connection of junctions.

core/junction.hpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ template <typename T> class EnergyDriver {
108108
}
109109
};
110110

111+
// Forward declarations if needed
112+
template <typename T> class Layer;
113+
template <typename T> class Junction;
114+
115+
// Typedef declarations outside the class
116+
template <typename T>
117+
using SolverFn = bool (Layer<T>::*)(T t, T &timeStep, const CVector<T> &bottom,
118+
const CVector<T> &top);
119+
120+
template <typename T>
121+
using RunnerFn = void (Junction<T>::*)(SolverFn<T> &functor, T &t, T &timeStep,
122+
bool &step_accepted);
123+
111124
template <typename T> struct AdaptiveIntegrationParams {
112125
T abs_tol = 1e-6; // Absolute error tolerance
113126
T rel_tol = 1e-3; // Relative error tolerance
@@ -1641,10 +1654,6 @@ template <typename T> class Junction {
16411654
logFile.close();
16421655
}
16431656

1644-
typedef bool (Layer<T>::*solverFn)(T t, T &timeStep, const CVector<T> &bottom,
1645-
const CVector<T> &top);
1646-
typedef void (Junction<T>::*runnerFn)(solverFn &functor, T &t, T &timeStep,
1647-
bool &step_accepted);
16481657
/**
16491658
* @brief Run Euler-Heun or RK4 method for a single layer.
16501659
*
@@ -1655,7 +1664,7 @@ template <typename T> class Junction {
16551664
* @param t: current time
16561665
* @param timeStep: integration step
16571666
*/
1658-
void runSingleLayerSolver(solverFn &functor, T &t, T &timeStep,
1667+
void runSingleLayerSolver(SolverFn<T> &functor, T &t, T &timeStep,
16591668
bool &step_accepted) {
16601669
const CVector<T> dummy(0, 0, 0);
16611670
step_accepted = (layers[0].*functor)(t, timeStep, dummy, dummy);
@@ -1669,7 +1678,7 @@ template <typename T> class Junction {
16691678
* @param t: current time
16701679
* @param timeStep: integration step
16711680
* */
1672-
void runMultiLayerSolver(solverFn &functor, T &t, T &timeStep,
1681+
void runMultiLayerSolver(SolverFn<T> &functor, T &t, T &timeStep,
16731682
bool &step_accepted) {
16741683
// Run solver for each layer and check if all steps were accepted
16751684
step_accepted = true;
@@ -1696,7 +1705,7 @@ template <typename T> class Junction {
16961705
}
16971706
}
16981707

1699-
void eulerHeunSolverStep(solverFn &functor, T &t, T &timeStep,
1708+
void eulerHeunSolverStep(SolverFn<T> &functor, T &t, T &timeStep,
17001709
bool &step_accepted) {
17011710
/*
17021711
Euler Heun method (stochastic heun)
@@ -1743,7 +1752,7 @@ template <typename T> class Junction {
17431752
}
17441753
}
17451754

1746-
void heunSolverStep(solverFn &functor, T &t, T &timeStep,
1755+
void heunSolverStep(SolverFn<T> &functor, T &t, T &timeStep,
17471756
bool &step_accepted) {
17481757
/*
17491758
Heun method
@@ -1878,7 +1887,7 @@ template <typename T> class Junction {
18781887
}
18791888
}
18801889

1881-
std::tuple<runnerFn, solverFn, SolverMode>
1890+
std::tuple<RunnerFn<T>, SolverFn<T>, SolverMode>
18821891
getSolver(SolverMode mode, unsigned int totalIterations) {
18831892
SolverMode localMode = mode;
18841893
for (auto &l : this->layers) {

core/reservoir.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ void comb(int N, int K) {
3232

3333
typedef std::array<CVector<double>, 3> tensor;
3434
typedef std::vector<tensor> tensorList;
35-
template <typename T>
36-
using solverFn = bool (Layer<T>::*)(T t, T &timeStep, const CVector<T> &bottom,
37-
const CVector<T> &top);
38-
template <typename T>
39-
using runnerFn = void (Junction<T>::*)(solverFn<T> &functor, T &t, T &timeStep,
40-
bool &step_accepted);
4135

4236
const tensor getDipoleTensorFromRelPositions(const CVector<double> &r1,
4337
const CVector<double> &r2) {
@@ -134,7 +128,7 @@ class GroupInteraction {
134128

135129
void stepFunctionalSolver(double time, double &timeStep,
136130
interactionFunction interaction,
137-
runnerFn<double> runner, solverFn<double> solver,
131+
RunnerFn<double> runner, SolverFn<double> solver,
138132
bool &step_accepted) {
139133
// collect all frozen states
140134
// for each element, compute the extra field from all other elements

0 commit comments

Comments
 (0)