|  | 
|  | 1 | +using ModelingToolkit, BenchmarkTools | 
|  | 2 | +using ModelingToolkitStandardLibrary | 
|  | 3 | +using ModelingToolkitStandardLibrary.Thermal | 
|  | 4 | +using OrdinaryDiffEqDefault | 
|  | 5 | + | 
|  | 6 | +const SUITE = BenchmarkGroup() | 
|  | 7 | + | 
|  | 8 | +@mtkmodel DCMotor begin | 
|  | 9 | +    @structural_parameters begin | 
|  | 10 | +        R = 0.5 | 
|  | 11 | +        L = 4.5e-3 | 
|  | 12 | +        k = 0.5 | 
|  | 13 | +        J = 0.02 | 
|  | 14 | +        f = 0.01 | 
|  | 15 | +        V_step = 10 | 
|  | 16 | +        tau_L_step = -3 | 
|  | 17 | +    end | 
|  | 18 | +    @components begin | 
|  | 19 | +        ground = Ground() | 
|  | 20 | +        source = Voltage() | 
|  | 21 | +        voltage_step = Blocks.Step(height = V_step, start_time = 0) | 
|  | 22 | +        R1 = Resistor(R = R) | 
|  | 23 | +        L1 = Inductor(L = L, i = 0.0) | 
|  | 24 | +        emf = EMF(k = k) | 
|  | 25 | +        fixed = Fixed() | 
|  | 26 | +        load = Torque() | 
|  | 27 | +        load_step = Blocks.Step(height = tau_L_step, start_time = 3) | 
|  | 28 | +        inertia = Inertia(J = J) | 
|  | 29 | +        friction = Damper(d = f) | 
|  | 30 | +    end | 
|  | 31 | +    @equations begin | 
|  | 32 | +        connect(fixed.flange, emf.support, friction.flange_b) | 
|  | 33 | +        connect(emf.flange, friction.flange_a, inertia.flange_a) | 
|  | 34 | +        connect(inertia.flange_b, load.flange) | 
|  | 35 | +        connect(load_step.output, load.tau) | 
|  | 36 | +        connect(voltage_step.output, source.V) | 
|  | 37 | +        connect(source.p, R1.p) | 
|  | 38 | +        connect(R1.n, L1.p) | 
|  | 39 | +        connect(L1.n, emf.p) | 
|  | 40 | +        connect(emf.n, source.n, ground.g) | 
|  | 41 | +    end | 
|  | 42 | +end | 
|  | 43 | + | 
|  | 44 | +@named model = DCMotor() | 
|  | 45 | + | 
|  | 46 | +SUITE["mtkcompile"] = @benchmarkable mtkcompile($model) | 
|  | 47 | + | 
|  | 48 | +model = mtkcompile(model) | 
|  | 49 | +u0 = unknowns(model) .=> 0.0 | 
|  | 50 | +tspan = (0.0, 6.0) | 
|  | 51 | +SUITE["ODEProblem"] = @benchmarkable ODEProblem($model, $u0, $tspan) | 
|  | 52 | + | 
|  | 53 | +prob = ODEProblem(model, u0, tspan) | 
|  | 54 | +SUITE["init"] = init($prob) | 
0 commit comments