Skip to content

Commit b60221c

Browse files
committed
feat: empty constructor for DifferentialEquation and HarmonicEquation with Jac
1 parent a7d95b5 commit b60221c

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

.github/workflows/Downstream.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ jobs:
2929
test:
3030
name: ${{ matrix.package.repo }}/${{ matrix.julia-version }}
3131
runs-on: ${{ matrix.os }}
32-
env:
33-
GROUP: ${{ matrix.package.group }}
3432
strategy:
3533
fail-fast: false
3634
matrix:

src/DifferentialEquation.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ mutable struct DifferentialEquation
3232
return new(eqs, OrderedDict(var => OrderedSet() for var in keys(eqs)))
3333
end
3434

35+
function DifferentialEquation()
36+
return new(OrderedDict{Num,Equation}(), OrderedDict{Num,OrderedSet{Num}}())
37+
end
38+
3539
# uses the above constructor if no harmonics defined
3640
function DifferentialEquation(eqs::Vector{Equation}, vars::Vector{Num})
3741
if length(eqs) != length(vars)

src/HarmonicEquation.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,29 @@ mutable struct HarmonicEquation
1919
jacobian::Matrix{Num}
2020

2121
# use a self-referential constructor with _parameters
22-
function HarmonicEquation(equations, variables, nat_eq)
22+
function HarmonicEquation(
23+
equations::Vector{Equation},
24+
variables::Vector{HarmonicVariable},
25+
nat_eq::DifferentialEquation,
26+
)
2327
return (
24-
x=new(
28+
x = new(
2529
equations,
2630
variables,
2731
Num[],
2832
nat_eq,
2933
dummy_symbolic_Jacobian(length(variables)),
3034
);
31-
x.parameters=_parameters(x);
35+
x.parameters = _parameters(x);
3236
x
3337
)
3438
end
35-
function HarmonicEquation(equations, variables, parameters, natural_equation)
39+
function HarmonicEquation(
40+
equations::Vector{Equation},
41+
variables::Vector{HarmonicVariable},
42+
parameters::Vector{Num},
43+
natural_equation::DifferentialEquation,
44+
)
3645
return new(
3746
equations,
3847
variables,
@@ -41,6 +50,20 @@ mutable struct HarmonicEquation
4150
dummy_symbolic_Jacobian(length(variables)),
4251
)
4352
end
53+
function HarmonicEquation(
54+
equations::Vector{Equation},
55+
variables::Vector{HarmonicVariable},
56+
parameters::Vector{Num},
57+
jacobian::Matrix{Num},
58+
)
59+
return new(
60+
equations,
61+
variables,
62+
parameters,
63+
DifferentialEquation(),
64+
jacobian,
65+
)
66+
end
4467
end
4568

4669
"Get the parameters (not time nor variables) of a HarmonicEquation"

test/DifferentialEquations.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ using QuestBase:
4242
diff_eq3 = DifferentialEquation(expr, x)
4343
@test length(diff_eq3.equations) == 1
4444
@test diff_eq3.equations[x].rhs == 0
45+
46+
# Test empty constructor
47+
diff = DifferentialEquation()
48+
@test isempty(diff.equations)
49+
@test isempty(diff.harmonics)
4550
end
4651

4752
@testset "Helper Functions" begin

test/HarmonicEquation.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ hv2 = HarmonicVariable(v, "test", "v", Num(1.0), y)
4646
@test heq.parameters == Num[]
4747
@test heq.jacobian isa Matrix{Num}
4848
end
49+
50+
heq3 = HarmonicEquation([eq1, eq2], [hv1, hv2], Num[], Num[1 1; 1 1])
51+
@test isempty(heq3.natural_equation.harmonics)
4952
end
5053

5154
@testset "Parameter handling" begin

0 commit comments

Comments
 (0)