Lines Matching refs:ctx

41 static PetscErrorCode RHSFunction(TS ts, PetscReal t, Vec U, Vec F, AppCtx *ctx)  in RHSFunction()  argument
50 …if ((t > ctx->tf) && (t < ctx->tcl)) Pmax = 0.0; /* A short-circuit on the generator terminal that… in RHSFunction()
51 else Pmax = ctx->Pmax; in RHSFunction()
53 f[0] = ctx->omega_b * (u[1] - ctx->omega_s); in RHSFunction()
54 …f[1] = (-Pmax * PetscSinScalar(u[0]) - ctx->D * (u[1] - ctx->omega_s) + ctx->Pm) * ctx->omega_s / … in RHSFunction()
64 static PetscErrorCode RHSJacobian(TS ts, PetscReal t, Vec U, Mat A, Mat B, AppCtx *ctx) in RHSJacobian() argument
72 …if ((t > ctx->tf) && (t < ctx->tcl)) Pmax = 0.0; /* A short-circuit on the generator terminal that… in RHSJacobian()
73 else Pmax = ctx->Pmax; in RHSJacobian()
76 J[0][1] = ctx->omega_b; in RHSJacobian()
77 J[1][1] = -ctx->D * ctx->omega_s / (2.0 * ctx->H); in RHSJacobian()
78 J[1][0] = -Pmax * PetscCosScalar(u[0]) * ctx->omega_s / (2.0 * ctx->H); in RHSJacobian()
99 AppCtx ctx; in main() local
128 ctx.omega_b = 1.0; in main()
129 ctx.omega_s = 2.0 * PETSC_PI * 60.0; in main()
130 ctx.H = 5.0; in main()
131 PetscCall(PetscOptionsScalar("-Inertia", "", "", ctx.H, &ctx.H, NULL)); in main()
132 ctx.D = 5.0; in main()
133 PetscCall(PetscOptionsScalar("-D", "", "", ctx.D, &ctx.D, NULL)); in main()
134 ctx.E = 1.1378; in main()
135 ctx.V = 1.0; in main()
136 ctx.X = 0.545; in main()
137 ctx.Pmax = ctx.E * ctx.V / ctx.X; in main()
138 PetscCall(PetscOptionsScalar("-Pmax", "", "", ctx.Pmax, &ctx.Pmax, NULL)); in main()
139 ctx.Pm = 0.9; in main()
140 PetscCall(PetscOptionsScalar("-Pm", "", "", ctx.Pm, &ctx.Pm, NULL)); in main()
141 ctx.tf = 1.0; in main()
142 ctx.tcl = 1.05; in main()
143 PetscCall(PetscOptionsReal("-tf", "Time to start fault", "", ctx.tf, &ctx.tf, NULL)); in main()
144 PetscCall(PetscOptionsReal("-tcl", "Time to end fault", "", ctx.tcl, &ctx.tcl, NULL)); in main()
147 ctx.tf = -1; in main()
148 ctx.tcl = -1; in main()
152 u[0] = PetscAsinScalar(ctx.Pm / ctx.Pmax); in main()
161 ctx.tf = -1; in main()
162 ctx.tcl = -1; in main()
173 PetscCall(TSSetRHSFunction(ts, NULL, (TSRHSFunctionFn *)RHSFunction, &ctx)); in main()
174 PetscCall(TSSetRHSJacobian(ts, A, A, (TSRHSJacobianFn *)RHSJacobian, &ctx)); in main()
195 u[0] = PetscAsinScalar(ctx.Pm / ctx.Pmax); in main()
196 u[1] = ctx.omega_s; in main()