DP_VS_R2L3.cpp 2.43 KB
Newer Older
Petra Raussi's avatar
Petra Raussi committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** Reference Circuits
 *
 * @author Markus Mirz <mmirz@eonerc.rwth-aachen.de>
 * @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC
 *
 * DPsim
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *********************************************************************************/

22
#include <DPsim.h>
Petra Raussi's avatar
Petra Raussi committed
23
24
25
26
27
28

using namespace DPsim;
using namespace CPS::DP;
using namespace CPS::DP::Ph1;

int main(int argc, char* argv[]) {
Markus Mirz's avatar
Markus Mirz committed
29
30
31
32
33
	// Define simulation scenario
	Real timeStep = 0.0001;
	Real finalTime = 0.1;
	String simName = "DP_VS_R2L3";

Petra Raussi's avatar
Petra Raussi committed
34
35
36
37
38
39
40
	// Nodes
	auto n1 = Node::make("n1");
	auto n2 = Node::make("n2");
	auto n3 = Node::make("n3");
	auto n4 = Node::make("n4");

	// Components
Petra Raussi's avatar
Petra Raussi committed
41
	auto vs = VoltageSource::make("vs");
Petra Raussi's avatar
Petra Raussi committed
42
	vs->setParameters(10);
Petra Raussi's avatar
Petra Raussi committed
43
	auto r1 = Resistor::make("r_1");
Steffen Vogel's avatar
Steffen Vogel committed
44
	r1->setParameters(1);
Petra Raussi's avatar
Petra Raussi committed
45
	auto l1 = Inductor::make("l_1");
Steffen Vogel's avatar
Steffen Vogel committed
46
	l1->setParameters(0.02);
Petra Raussi's avatar
Petra Raussi committed
47
	auto l2 = Inductor::make("l_2");
Steffen Vogel's avatar
Steffen Vogel committed
48
	l2->setParameters(0.1);
Petra Raussi's avatar
Petra Raussi committed
49
	auto l3 = Inductor::make("l_3");
Steffen Vogel's avatar
Steffen Vogel committed
50
	l3->setParameters(0.05);
Petra Raussi's avatar
Petra Raussi committed
51
	auto r2 = Resistor::make("r_2");
Steffen Vogel's avatar
Steffen Vogel committed
52
	r2->setParameters(2);
Markus Mirz's avatar
Markus Mirz committed
53
54
55
56
57
58
59

	// Topology
	vs->connect(Node::List{ Node::GND, n1 });
	r1->connect(Node::List{ n1, n2 });
	l1->connect(Node::List{ n2, n3 });
	l2->connect(Node::List{ n3, Node::GND });
	l3->connect(Node::List{ n3, n4 });
60
	r2->connect(Node::List{ n4, Node::GND });
Steffen Vogel's avatar
Steffen Vogel committed
61

Petra Raussi's avatar
Petra Raussi committed
62
	auto sys = SystemTopology(50, SystemNodeList{n1, n2, n3, n4}, SystemComponentList{vs, r1, l1, l2, l3, r2});
Steffen Vogel's avatar
Steffen Vogel committed
63

Markus Mirz's avatar
Markus Mirz committed
64
65
66
67
68
69
70
71
72
	// Logging
	auto logger = DataLogger::make(simName);
	logger->addAttribute("v1", n1->attribute("voltage"));
	logger->addAttribute("v2", n2->attribute("voltage"));
	logger->addAttribute("v3", n3->attribute("voltage"));
	logger->addAttribute("v4", n4->attribute("voltage"));
	logger->addAttribute("i30", l2->attribute("i_intf"));
	logger->addAttribute("i34", l3->attribute("i_intf"));

Petra Raussi's avatar
Petra Raussi committed
73
	Simulation sim(simName, sys, timeStep, finalTime);
Markus Mirz's avatar
Markus Mirz committed
74
75
	sim.addLogger(logger);

Petra Raussi's avatar
Petra Raussi committed
76
77
78
79
	sim.run();

	return 0;
}