ReferenceCircuits.cpp 16.4 KB
Newer Older
1
2
3
4
5
6
7
8
#include "ReferenceCircuits.h"

#include "../Simulation.h"
#include "../Utilities.h"


using namespace DPsim;

9
void DPsim::simulationExample1()
10
{
11
12
	Real timeStep = 0.001;

13
	// Define Object for saving data on a file
14
15
16
17
18
	std::ostringstream fileName;
	fileName << "SimulationExample1_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
19
20

	std::vector<BaseComponent*> circElements0;
21
	circElements0.push_back(new VoltSourceRes("v_in", 1, 0, Complex(10, 0), 1));
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
	circElements0.push_back(new Inductor("l_1", 1, 2, 0.02));
	circElements0.push_back(new Inductor("l_2", 2, 0, 0.1));
	circElements0.push_back(new Inductor("l_3", 2, 3, 0.05));
	circElements0.push_back(new LinearResistor("r_2", 3, 0, 2));

	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() <<  std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

45
46
	for (auto elem : circElements0)
		delete elem;
47
48
}

49
void DPsim::simulationExample1L2()
50
{
51
52
	Real timeStep = 0.001;

53
	// Define Object for saving data on a file
54
55
56
57
58
	std::ostringstream fileName;
	fileName << "SimulationExample1L2_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
59
60

	std::vector<BaseComponent*> circElements0;
61
	circElements0.push_back(new VoltSourceRes("v_in", 1, 0, Complex(10, 0), 1));
62
63
64
	circElements0.push_back(new Inductor("l_1", 1, 2, 0.02));
	circElements0.push_back(new Inductor("l_2", 2, 0, 0.1));
	circElements0.push_back(new Inductor("l_3", 2, 3, 0.05));
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
	circElements0.push_back(new LinearResistor("r_2", 3, 0, 2));

	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

85
86
	for (auto elem : circElements0)
		delete elem;
87
88
}

89
void DPsim::simulationExample2()
90
{
91
92
	Real timeStep = 0.001;

93
	// Define Object for saving data on a file
94
95
96
97
98
	std::ostringstream fileName;
	fileName << "SimulationExample2_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
99
100

	std::vector<BaseComponent*> circElements0;
101
	circElements0.push_back(new VoltSourceRes("v_in", 1, 0, Complex(10, 0), 1));
102
103
	circElements0.push_back(new Inductor("l_1", 1, 2, 0.02));
	circElements0.push_back(new Inductor("l_2", 2, 0, 0.1));
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
	
	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

123
124
	for (auto elem : circElements0)
		delete elem;
125
126
}

127
void DPsim::simulationExample3()
128
{
129
130
	Real timeStep = 0.001;

131
	// Define Object for saving data on a file
132
133
134
135
136
	std::ostringstream fileName;
	fileName << "SimulationExample3_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
137
138

	std::vector<BaseComponent*> circElements0;
139
	circElements0.push_back(new VoltSourceRes("v_in", 1, 0, Complex(10, 0), 1));
140
	circElements0.push_back(new Capacitor("c_1", 1, 2, 0.001));
141
	circElements0.push_back(new Inductor("l_1", 2, 0, 0.001));
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	circElements0.push_back(new LinearResistor("r_2", 2, 0, 1));

	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

162
163
	for (auto elem : circElements0)
		delete elem;
Viviane's avatar
Viviane committed
164
165
}

166
void DPsim::simulationExampleIdealVS()
Viviane's avatar
Viviane committed
167
{
168
169
	Real timeStep = 0.001;

Viviane's avatar
Viviane committed
170
	// Define Object for saving data on a file
171
172
173
174
175
	std::ostringstream fileName;
	fileName << "SimulationExampleIdealVS_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
Viviane's avatar
Viviane committed
176
177

	std::vector<BaseComponent*> circElements0;
178
	circElements0.push_back(new IdealVoltageSource("v_in", 1, 2, Complex(10, 0), 1));
Viviane's avatar
Viviane committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	circElements0.push_back(new LinearResistor("r_1", 1, 0, 1));
	circElements0.push_back(new LinearResistor("r_2", 2, 0, 1));
	circElements0.push_back(new LinearResistor("r_3", 2, 0, 1));

	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

201
202
	for (auto elem : circElements0)
		delete elem;
203
204
}

205
void DPsim::simulationExampleIdealVS2()
206
{
207
208
	Real timeStep = 0.001;

209
	// Define Object for saving data on a file
210
211
212
213
214
	std::ostringstream fileName;
	fileName << "SimulationExampleIdealVS2_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
215
216

	std::vector<BaseComponent*> circElements0;
217
	circElements0.push_back(new IdealVoltageSource("v_in", 1, 0, Complex(10, 0), 1));
218
219
	circElements0.push_back(new LinearResistor("r_1", 1, 2, 1));
	circElements0.push_back(new Capacitor("c_1", 2, 3, 0.001));
220
	circElements0.push_back(new Inductor("l_1", 3, 0, 0.001));
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
	circElements0.push_back(new LinearResistor("r_2", 3, 0, 1));

	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

241
242
	for (auto elem : circElements0)
		delete elem;
243
244
245
}


246
void DPsim::simulationExampleIdealVS3()
247
{
248
249
	Real timeStep = 0.001;

250
	// Define Object for saving data on a file
251
252
253
254
255
	std::ostringstream fileName;
	fileName << "SimulationExampleIdealVS3_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
256
257

	std::vector<BaseComponent*> circElements0;
258
	circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(10, 0), 1));
259
260
261
262
263
	circElements0.push_back(new LinearResistor("r_1", 1, 2, 1));
	circElements0.push_back(new LinearResistor("r_2", 2, 0, 1));
	circElements0.push_back(new LinearResistor("r_3", 2, 3, 1));
	circElements0.push_back(new LinearResistor("r_4", 3, 0, 1));
	circElements0.push_back(new LinearResistor("r_5", 3, 4, 1));
264
	circElements0.push_back(new IdealVoltageSource("v_2", 4, 0, Complex(20, 0), 2));
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286




	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

287
288
	for (auto elem : circElements0)
		delete elem;
289
}
Viviane's avatar
Viviane committed
290

291
void DPsim::simulationExampleRXLine()
Viviane's avatar
Viviane committed
292
{
293
294
	Real timeStep = 0.001;

Viviane's avatar
Viviane committed
295
	// Define Object for saving data on a file
296
297
298
299
300
	std::ostringstream fileName;
	fileName << "SimulationExampleRXLine_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
Viviane's avatar
Viviane committed
301
302

	std::vector<BaseComponent*> circElements0;
303
	circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(10, 0), 1));
Viviane's avatar
Viviane committed
304
305
306
307
308
309
310
311
312
313
314
	circElements0.push_back(new RxLine("Line_1", 1, 2, 3, 0.1, 0.001));
	circElements0.push_back(new LinearResistor("r_1", 2, 0, 20));


	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
315
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);
Viviane's avatar
Viviane committed
316
317
318
319
320
321
322
323
324
325

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

326
327
	for (auto elem : circElements0)
		delete elem;
Viviane's avatar
Viviane committed
328
329
}

330
void DPsim::simulationExampleRXLine2()
Viviane's avatar
Viviane committed
331
{
332
333
	Real timeStep = 0.001;

Viviane's avatar
Viviane committed
334
	// Define Object for saving data on a file
335
336
337
338
339
	std::ostringstream fileName;
	fileName << "SimulationExampleRXLine2_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
Viviane's avatar
Viviane committed
340
341

	std::vector<BaseComponent*> circElements0;
342
	circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(10, 0), 1));
Markus Mirz's avatar
merge    
Markus Mirz committed
343
344

	circElements0.push_back(new Inductor("l_L", 2, 3, 0.001));
Viviane's avatar
Viviane committed
345
346
	circElements0.push_back(new LinearResistor("r_L", 1, 2, 0.1));
	circElements0.push_back(new LinearResistor("r_1", 3, 0, 20));
Viviane's avatar
Viviane committed
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366


	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

367
368
	for (auto elem : circElements0)
		delete elem;
Viviane's avatar
Viviane committed
369
}
Viviane's avatar
Viviane committed
370
371
372

void DPsim::simulationExampleRXLine3()
{
373
374
	Real timeStep = 0.001;

Viviane's avatar
Viviane committed
375
	// Define Object for saving data on a file
376
377
378
379
380
	std::ostringstream fileName;
	fileName << "SimulationExampleRXLine3_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
Viviane's avatar
Viviane committed
381
382

	std::vector<BaseComponent*> circElements0;
383
	circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(10, 0), 1));
Viviane's avatar
Viviane committed
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
	circElements0.push_back(new RxLine("Line_1", 1, 2, 0.1, 0.001));
	circElements0.push_back(new LinearResistor("r_1", 2, 0, 20));


	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

406
407
	for (auto elem : circElements0)
		delete elem;
Viviane's avatar
Viviane committed
408
409
410
411
}

void DPsim::simulationExamplePiLine()
{
412
413
	Real timeStep = 0.001;

Viviane's avatar
Viviane committed
414
	// Define Object for saving data on a file
415
416
417
418
419
	std::ostringstream fileName;
	fileName << "SimulationExamplePiLine_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
Viviane's avatar
Viviane committed
420
421

	std::vector<BaseComponent*> circElements0;
422
	circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(345, 0), 1));
Viviane's avatar
Viviane committed
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
	circElements0.push_back(new LinearResistor("r1", 1, 2, 5));
	circElements0.push_back(new PiLine("PiLine1", 2, 3, 4, 6.4, 0.186, 0.004));
	circElements0.push_back(new LinearResistor("r_load", 3, 0, 150));



	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

447
448
	for (auto elem : circElements0)
		delete elem;
Viviane's avatar
Viviane committed
449
450
451
452
}

void DPsim::simulationExamplePiLine2()
{
453
454
	Real timeStep = 0.001;

Viviane's avatar
Viviane committed
455
	// Define Object for saving data on a file
456
457
458
459
460
	std::ostringstream fileName;
	fileName << "SimulationExamplePiLine2_" << timeStep;
	Logger log("Logs/Log_" + fileName.str() + ".log"),
		leftVectorLog("Logs/LeftVectorLog_" + fileName.str() + ".csv"),
		rightVectorLog("Logs/RightVectorLog_" + fileName.str() + ".csv");
Viviane's avatar
Viviane committed
461
462

	std::vector<BaseComponent*> circElements0;
463
	circElements0.push_back(new IdealVoltageSource("v_1", 1, 0, Complex(345, 0), 1));
Viviane's avatar
Viviane committed
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
	circElements0.push_back(new LinearResistor("r1", 1, 2, 5));
	circElements0.push_back(new Capacitor("c_1", 2, 0, 0.002));
	circElements0.push_back(new LinearResistor("r_load", 2, 4, 6.4));
	circElements0.push_back(new Inductor("l_1", 4, 3, 0.186));
	circElements0.push_back(new Capacitor("c_2", 3, 0, 0.002));
	circElements0.push_back(new LinearResistor("r_load", 3, 0, 150));



	std::cout << "The contents of circElements0 are:";
	for (std::vector<BaseComponent*>::iterator it = circElements0.begin(); it != circElements0.end(); ++it) {
		std::cout << "Added " << (*it)->getName() << std::endl;
	}
	std::cout << '\n';

	// Set up simulation
	Simulation newSim(circElements0, 2.0*M_PI*50.0, timeStep, 0.3, log);

	// Main Simulation Loop
	std::cout << "Start simulation." << std::endl;
	while (newSim.step(log, leftVectorLog, rightVectorLog))
	{
		newSim.increaseByTimeStep();
		updateProgressBar(newSim.getTime(), newSim.getFinalTime());
	}
	std::cout << "Simulation finished." << std::endl;

491
492
493
	for (auto elem : circElements0)
		delete elem;
}