| 111 | |
| 112 | |
| 113 | void example_ecvs_async (void) |
| 114 | { |
| 115 | char infile[] = "../../../example_ecvs.net"; |
| 116 | |
| 117 | printf ("\nRunning example_ecvs_async function\n"); |
| 118 | printf ("Demonstrates setting a voltage source from external code\nduring simulation.\n"); |
| 119 | printf ("Evaluates netlist file %s.\n\n", infile); |
| 120 | |
| 121 | char * ecvsname = "ECVS1"; |
| 122 | char * iprobename = "Pr1"; |
| 123 | |
| 124 | double probe_current; |
| 125 | |
| 126 | int exists = -1; |
| 127 | |
| 128 | trsolver_interface qtr; |
| 129 | |
| 130 | qtr.prepare_netlist (infile); |
| 131 | |
| 132 | qtr.setMessageFcn (&testmessage); |
| 133 | |
| 134 | double tend = 1; |
| 135 | double start = 0.0; |
| 136 | double delta = (tend - start) / 10; |
| 137 | |
| 138 | qtr.init (start, delta, ETR_MODE_ASYNC); |
| 139 | |
| 140 | exists = qtr.setECVSVoltage(ecvsname, 0); |
| 141 | |
| 142 | qtr.printSolution (); |
| 143 | |
| 144 | for (double t = start; t <= tend; t += delta) |
| 145 | { |
| 146 | exists = qtr.setECVSVoltage (ecvsname, std::sin(2 * 3.142 * 1.0 * t)); |
| 147 | |
| 148 | qtr.stepsolve_async (t); |
| 149 | |
| 150 | // prints the whole solution, all node voltages and branch currents |
| 151 | qtr.printSolution (); |
| 152 | |
| 153 | exists = qtr.getIProbeI (iprobename, probe_current); |
| 154 | |
| 155 | if (exists == 0) |
| 156 | { |
| 157 | printf ("%s probe current: %f\n", iprobename, probe_current); |
| 158 | } |
| 159 | |
| 160 | // the solution must be explicitly accepted for it to become a |
| 161 | // part of the circuit solution history |
| 162 | qtr.acceptstep_async (); |
| 163 | } |
| 164 | } |
| 165 | |