Skip to content

Commit 7b04023

Browse files
Fix compilation error for open/short components
1 parent d67af36 commit 7b04023

File tree

4 files changed

+110
-85
lines changed

4 files changed

+110
-85
lines changed

include/chowdsp_wdf/wdf/wdf_nonlinearities.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ namespace wdf
3131
public:
3232
Open() : WDF<T> ("Open")
3333
{
34-
this->R = (T) 1.0e15;
35-
this->G = (T) 1.0 / this->R;
34+
this->wdf.R = (T) 1.0e15;
35+
this->wdf.G = (T) 1.0 / this->wdf.R;
3636
}
3737

3838
inline void calcImpedance() override {}
3939

4040
/** Accepts an incident wave into a WDF open. */
4141
inline void incident (T x) noexcept override
4242
{
43-
this->a = x;
43+
this->wdf.a = x;
4444
}
4545

4646
/** Propogates a reflected wave from a WDF open. */
4747
inline T reflected() noexcept override
4848
{
49-
this->b = this->a;
50-
return this->b;
49+
this->wdf.b = this->wdf.a;
50+
return this->wdf.b;
5151
}
5252
};
5353

@@ -58,23 +58,23 @@ namespace wdf
5858
public:
5959
Short() : WDF<T> ("Short")
6060
{
61-
this->R = (T) 1.0e-15;
62-
this->G = (T) 1.0 / this->R;
61+
this->wdf.R = (T) 1.0e-15;
62+
this->wdf.G = (T) 1.0 / this->wdf.R;
6363
}
6464

6565
inline void calcImpedance() override {}
6666

6767
/** Accepts an incident wave into a WDF short. */
6868
inline void incident (T x) noexcept override
6969
{
70-
this->a = x;
70+
this->wdf.a = x;
7171
}
7272

7373
/** Propogates a reflected wave from a WDF short. */
7474
inline T reflected() noexcept override
7575
{
76-
this->b = -this->a;
77-
return this->b;
76+
this->wdf.b = -this->wdf.a;
77+
return this->wdf.b;
7878
}
7979
};
8080

tests/BasicCircuitTest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,28 @@ TEST_CASE ("Basic Circuits Test")
281281
doImpedanceChecks (
282282
ResistiveCurrentSource<float> { 1000.0f }, 1000.0f, 2000.0f, [=] (auto& r, float value) { r.setResistanceValue (value); }, [=] (float value) { return value; });
283283
}
284+
285+
SECTION ("Open Test")
286+
{
287+
ResistiveVoltageSource<float> Vin { 1.0e3f };
288+
Open<float> open {};
289+
290+
Vin.setVoltage (10.0f);
291+
open.incident (Vin.reflected());
292+
Vin.incident (open.reflected());
293+
294+
REQUIRE (open.voltage() == 10.0f);
295+
}
296+
297+
SECTION ("Short Test")
298+
{
299+
ResistiveVoltageSource<float> Vin { 1.0e3f };
300+
Short<float> sh {};
301+
302+
Vin.setVoltage (10.0f);
303+
sh.incident (Vin.reflected());
304+
Vin.incident (sh.reflected());
305+
306+
REQUIRE (sh.voltage() == 0.0f);
307+
}
284308
}

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_executable(chowdsp_wdf_tests)
22
target_include_directories(chowdsp_wdf_tests PRIVATE .)
33
target_link_libraries(chowdsp_wdf_tests PRIVATE ${PROJECT_NAME} chowdsp_wdf)
4+
target_compile_definitions(chowdsp_wdf_tests PRIVATE _USE_MATH_DEFINES=1)
45
target_sources(chowdsp_wdf_tests
56
PRIVATE
67
BasicCircuitTest.cpp

tests/CombinedComponentTest.cpp

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,81 @@ using namespace chowdsp::wdft;
66

77
TEST_CASE ("Combined Component Test")
88
{
9-
// SECTION ("Resistor/Capacitor Series")
10-
// {
11-
// static constexpr auto r_val = 2000.0f;
12-
// static constexpr auto c_val = 2.0e-6f;
13-
//
14-
// ResistorT<float> r1 { r_val };
15-
// CapacitorT<float> c1 { c_val };
16-
// WDFSeriesT<float, decltype (r1), decltype (c1)> s1 { r1, c1 };
17-
//
18-
// ResistorCapacitorSeriesT<float> rc1 { r_val, c_val };
19-
//
20-
// float inputs[] = { 0.0f, 1.0f, -1.0f, 2.0f, -3.0f };
21-
// for (auto& a : inputs)
22-
// {
23-
// s1.incident (a);
24-
// const auto ref = s1.reflected();
25-
//
26-
// rc1.incident (a);
27-
// const auto actual = rc1.reflected();
28-
//
29-
// REQUIRE (ref == Approx { actual }.margin (1.0e-4f));
30-
// }
31-
// }
32-
//
33-
// SECTION ("Resistor/Capacitor Parallel")
34-
// {
35-
// static constexpr auto r_val = 2000.0f;
36-
// static constexpr auto c_val = 2.0e-6f;
37-
//
38-
// ResistorT<float> r1 { r_val };
39-
// CapacitorT<float> c1 { c_val };
40-
// WDFParallelT<float, decltype (r1), decltype (c1)> p1 { r1, c1 };
41-
//
42-
// ResistorCapacitorParallelT<float> rc1 { r_val, c_val };
43-
//
44-
// float inputs[] = { 0.0f, 1.0f, -1.0f, 2.0f, -3.0f };
45-
// for (auto& a : inputs)
46-
// {
47-
// p1.incident (a);
48-
// const auto ref = p1.reflected();
49-
//
50-
// rc1.incident (a);
51-
// const auto actual = rc1.reflected();
52-
//
53-
// REQUIRE (ref == Approx { actual }.margin (1.0e-4f));
54-
// }
55-
// }
56-
//
57-
// SECTION ("Resistor/Capacitor/Voltage Source Series")
58-
// {
59-
// static constexpr auto r_val = 2000.0f;
60-
// static constexpr auto c_val = 2.0e-6f;
61-
// static constexpr auto source_v = 1.5f;
62-
//
63-
// ResistiveVoltageSourceT<float> rv1 { r_val };
64-
// rv1.setVoltage (source_v);
65-
// CapacitorT<float> c1 { c_val };
66-
// WDFSeriesT<float, decltype (rv1), decltype (c1)> s1 { rv1, c1 };
67-
//
68-
// ResistiveCapacitiveVoltageSourceT<float> rc1 { r_val, c_val };
69-
// rc1.setVoltage (source_v);
70-
// rc1.reset();
71-
//
72-
// float inputs[] = { 0.0f, 1.0f, -1.0f, 2.0f, -3.0f };
73-
// for (auto& a : inputs)
74-
// {
75-
// s1.incident (a);
76-
// const auto ref = s1.reflected();
77-
//
78-
// rc1.incident (a);
79-
// const auto actual = rc1.reflected();
80-
//
81-
// REQUIRE (ref == Approx { actual }.margin (1.0e-4f));
82-
// }
83-
// }
9+
SECTION ("Resistor/Capacitor Series")
10+
{
11+
static constexpr auto r_val = 2000.0f;
12+
static constexpr auto c_val = 2.0e-6f;
13+
14+
ResistorT<float> r1 { r_val };
15+
CapacitorT<float> c1 { c_val };
16+
WDFSeriesT<float, decltype (r1), decltype (c1)> s1 { r1, c1 };
17+
18+
ResistorCapacitorSeriesT<float> rc1 { r_val, c_val };
19+
20+
float inputs[] = { 0.0f, 1.0f, -1.0f, 2.0f, -3.0f };
21+
for (auto& a : inputs)
22+
{
23+
s1.incident (a);
24+
const auto ref = s1.reflected();
25+
26+
rc1.incident (a);
27+
const auto actual = rc1.reflected();
28+
29+
REQUIRE (ref == Approx { actual }.margin (1.0e-4f));
30+
}
31+
}
32+
33+
SECTION ("Resistor/Capacitor Parallel")
34+
{
35+
static constexpr auto r_val = 2000.0f;
36+
static constexpr auto c_val = 2.0e-6f;
37+
38+
ResistorT<float> r1 { r_val };
39+
CapacitorT<float> c1 { c_val };
40+
WDFParallelT<float, decltype (r1), decltype (c1)> p1 { r1, c1 };
41+
42+
ResistorCapacitorParallelT<float> rc1 { r_val, c_val };
43+
44+
float inputs[] = { 0.0f, 1.0f, -1.0f, 2.0f, -3.0f };
45+
for (auto& a : inputs)
46+
{
47+
p1.incident (a);
48+
const auto ref = p1.reflected();
49+
50+
rc1.incident (a);
51+
const auto actual = rc1.reflected();
52+
53+
REQUIRE (ref == Approx { actual }.margin (1.0e-4f));
54+
}
55+
}
56+
57+
SECTION ("Resistor/Capacitor/Voltage Source Series")
58+
{
59+
static constexpr auto r_val = 2000.0f;
60+
static constexpr auto c_val = 2.0e-6f;
61+
static constexpr auto source_v = 1.5f;
62+
63+
ResistiveVoltageSourceT<float> rv1 { r_val };
64+
rv1.setVoltage (source_v);
65+
CapacitorT<float> c1 { c_val };
66+
WDFSeriesT<float, decltype (rv1), decltype (c1)> s1 { rv1, c1 };
67+
68+
ResistiveCapacitiveVoltageSourceT<float> rc1 { r_val, c_val };
69+
rc1.setVoltage (source_v);
70+
rc1.reset();
71+
72+
float inputs[] = { 0.0f, 1.0f, -1.0f, 2.0f, -3.0f };
73+
for (auto& a : inputs)
74+
{
75+
s1.incident (a);
76+
const auto ref = s1.reflected();
77+
78+
rc1.incident (a);
79+
const auto actual = rc1.reflected();
80+
81+
REQUIRE (ref == Approx { actual }.margin (1.0e-4f));
82+
}
83+
}
8484

8585
SECTION ("Capacitive Voltage Source")
8686
{

0 commit comments

Comments
 (0)