Skip to content

Commit 1375d2c

Browse files
fix pake snake_case buat method/function
mau konsisten make snake_case buat method/function camelCase buat Variabel, dan PascalCase buat tipe data
1 parent ab5c922 commit 1375d2c

File tree

1 file changed

+82
-82
lines changed

1 file changed

+82
-82
lines changed

electrical/component/include/default_electrical_component.hxx

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
#include <thread>
77
#include <cmath>
88

9-
namespace ELC{
9+
namespace elc {
1010
template<typename T>
11-
struct Node {
11+
struct node {
1212
size_t n;
1313
std::vector<std::shared_ptr<T>> data, muatan, impedansi;
1414
double timestep;
1515

16-
Node(size_t n, double timestep = 1e-7)
16+
node(size_t n, double timestep = 1e-7)
1717
: n(n), data(n), muatan(n), impedansi(n), timestep(timestep) {
1818
for (size_t i = 0; i < n; ++i) {
1919
data[i] = std::make_shared<T>(0);
@@ -22,140 +22,140 @@ struct Node {
2222
}
2323
}
2424

25-
virtual ~Node() = default;
25+
virtual ~node() = default;
2626

2727
T& operator[](size_t i) { return this->data[i]; }
2828
const T& operator[](size_t i) const { return this->data[i]; }
2929
T& q(size_t i) { return *muatan[i]; }
3030
const T& q(size_t i) const { return *muatan[i]; }
3131

32-
virtual void updateTegangan() {
32+
virtual void update_tegangan() {
3333
for (size_t i = 0; i < n; ++i)
3434
this->data[i] = (*muatan[i]) * (*impedansi[i]);
3535
}
3636

37-
void connect(Node<T>& other, size_t pinThis, size_t pinOther) {
38-
if (pinThis >= n || pinOther >= other.n) return;
39-
data[pinThis] = other.data[pinOther];
40-
muatan[pinThis] = other.muatan[pinOther];
41-
impedansi[pinThis] = other.impedansi[pinOther];
37+
void connect(node<T>& other, size_t pin_this, size_t pin_other) {
38+
if (pin_this >= n || pin_other >= other.n) return;
39+
data[pin_this] = other.data[pin_other];
40+
muatan[pin_this] = other.muatan[pin_other];
41+
impedansi[pin_this] = other.impedansi[pin_other];
4242
}
4343

44-
void setTimestep(double t) { timestep = t; }
44+
void set_timestep(double t) { timestep = t; }
4545

46-
void runLoop(size_t iterations = 100) {
46+
void run_loop(size_t iterations = 100) {
4747
for (size_t i = 0; i < iterations; ++i) {
4848
auto start = std::chrono::high_resolution_clock::now();
49-
updateTegangan();
49+
update_tegangan();
5050
auto end = std::chrono::high_resolution_clock::now();
5151
double dur = std::chrono::duration<double>(end - start).count();
52-
double sleepTime = timestep - dur;
53-
if (sleepTime > 0)
54-
std::this_thread::sleep_for(std::chrono::duration<double>(sleepTime));
52+
double sleep_time = timestep - dur;
53+
if (sleep_time > 0)
54+
std::this_thread::sleep_for(std::chrono::duration<double>(sleep_time));
5555
}
5656
}
5757
};
5858

5959
template<typename T>
60-
struct Kapasitor : Node<T> {
61-
T C; double dt; T I;
62-
Kapasitor(T C, double dt, double ts = 1e-7)
63-
: Node<T>(2, ts), C(C), dt(dt), I(0) {}
64-
65-
void alirkanArus(T Iin) {
66-
I = Iin;
67-
this->q(0) += I * dt;
68-
this->q(1) -= I * dt;
60+
struct kapasitor : node<T> {
61+
T c; double dt; T i;
62+
kapasitor(T c, double dt, double ts = 1e-7)
63+
: node<T>(2, ts), c(c), dt(dt), i(0) {}
64+
65+
void alirkan_arus(T iin) {
66+
i = iin;
67+
this->q(0) += i * dt;
68+
this->q(1) -= i * dt;
6969
}
7070

71-
void updateTegangan() override {
72-
T V = (this->q(0) - this->q(1)) / C;
73-
this->data[0] = V;
74-
this->data[1] = -V;
71+
void update_tegangan() override {
72+
T v = (this->q(0) - this->q(1)) / c;
73+
this->data[0] = v;
74+
this->data[1] = -v;
7575
}
7676
};
7777

7878
template<typename T>
79-
struct Induktor : Node<T> {
80-
T L; double dt; T I;
81-
Induktor(T L, double dt, double ts = 1e-7)
82-
: Node<T>(2, ts), L(L), dt(dt), I(0) {}
79+
struct induktor : node<T> {
80+
T l; double dt; T i;
81+
induktor(T l, double dt, double ts = 1e-7)
82+
: node<T>(2, ts), l(l), dt(dt), i(0) {}
8383

84-
void terapkanTegangan(T V) {
85-
I += (V / L) * dt;
84+
void terapkan_tegangan(T v) {
85+
i += (v / l) * dt;
8686
}
8787

88-
void updateTegangan() override {
89-
this->data[0] = I;
90-
this->data[1] = -I;
88+
void update_tegangan() override {
89+
this->data[0] = i;
90+
this->data[1] = -i;
9191
}
9292
};
9393

9494
template<typename T>
95-
struct Resistor : Node<T> {
96-
T R;
97-
Resistor(T R, double ts = 1e-7)
98-
: Node<T>(2, ts), R(R) {}
99-
100-
void updateTegangan() override {
101-
T V = this->q(0) * R;
102-
this->data[0] = V;
95+
struct resistor : node<T> {
96+
T r;
97+
resistor(T r, double ts = 1e-7)
98+
: node<T>(2, ts), r(r) {}
99+
100+
void update_tegangan() override {
101+
T v = this->q(0) * r;
102+
this->data[0] = v;
103103
this->data[1] = 0;
104104
}
105105
};
106106

107107
template<typename T>
108-
struct Transistor : Node<T> {
109-
T beta, Vth;
110-
Transistor(T beta, T Vth, double ts = 1e-7)
111-
: Node<T>(3, ts), beta(beta), Vth(Vth) {}
112-
113-
void updateTegangan() override {
114-
T Vbe = (this->data[1] - this->data[2]);
115-
T Ic = Vbe > Vth ? beta * (Vbe - Vth) : 0;
116-
this->q(0) = Ic; // kolektor muatan
117-
this->q(2) = -Ic; // emitor muatan
118-
this->data[0] = Ic;
119-
this->data[1] = Vbe;
108+
struct transistor : node<T> {
109+
T beta, vth;
110+
transistor(T beta, T vth, double ts = 1e-7)
111+
: node<T>(3, ts), beta(beta), vth(vth) {}
112+
113+
void update_tegangan() override {
114+
T vbe = (this->data[1] - this->data[2]);
115+
T ic = vbe > vth ? beta * (vbe - vth) : 0;
116+
this->q(0) = ic;
117+
this->q(2) = -ic;
118+
this->data[0] = ic;
119+
this->data[1] = vbe;
120120
this->data[2] = 0;
121121
}
122122
};
123123

124124
template<typename T>
125-
struct Memristor : Node<T> {
126-
T M;
127-
Memristor(T M, double ts = 1e-7)
128-
: Node<T>(2, ts), M(M) {}
129-
130-
void updateTegangan() override {
131-
T V = M * this->q(0);
132-
this->data[0] = V;
133-
this->data[1] = -V;
125+
struct memristor : node<T> {
126+
T m;
127+
memristor(T m, double ts = 1e-7)
128+
: node<T>(2, ts), m(m) {}
129+
130+
void update_tegangan() override {
131+
T v = m * this->q(0);
132+
this->data[0] = v;
133+
this->data[1] = -v;
134134
}
135135
};
136136

137137
template<typename T>
138-
struct Dioda : Node<T> {
139-
T I0, VT;
140-
Dioda(T I0, T VT, double ts = 1e-7)
141-
: Node<T>(2, ts), I0(I0), VT(VT) {}
142-
143-
void updateTegangan() override {
144-
T Iin = this->q(0);
145-
T V = Iin > 0 ? VT * std::log(Iin / I0) : 0;
146-
this->data[0] = V;
138+
struct dioda : node<T> {
139+
T i0, vt;
140+
dioda(T i0, T vt, double ts = 1e-7)
141+
: node<T>(2, ts), i0(i0), vt(vt) {}
142+
143+
void update_tegangan() override {
144+
T iin = this->q(0);
145+
T v = iin > 0 ? vt * std::log(iin / i0) : 0;
146+
this->data[0] = v;
147147
this->data[1] = 0;
148148
}
149149
};
150150

151151
template<typename T>
152-
struct SumberTegangan : Node<T> {
153-
T Vsrc;
154-
SumberTegangan(T Vsrc, double ts = 1e-7)
155-
: Node<T>(2, ts), Vsrc(Vsrc) {}
152+
struct sumber_tegangan : node<T> {
153+
T vsrc;
154+
sumber_tegangan(T vsrc, double ts = 1e-7)
155+
: node<T>(2, ts), vsrc(vsrc) {}
156156

157-
void updateTegangan() override {
158-
this->data[0] = Vsrc;
157+
void update_tegangan() override {
158+
this->data[0] = vsrc;
159159
this->data[1] = 0;
160160
}
161161
};

0 commit comments

Comments
 (0)