EMT_VS_R1.cpp 2.05 KB
Newer Older
Markus Mirz's avatar
Markus Mirz committed
1
2
3
/** Reference Circuits
 *
 * @author Markus Mirz <mmirz@eonerc.rwth-aachen.de>
4
 * @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC
Markus Mirz's avatar
Markus Mirz committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 *
 * 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/>.
 *********************************************************************************/

Markus Mirz's avatar
Markus Mirz committed
22

23
#include <DPsim.h>
Markus Mirz's avatar
Markus Mirz committed
24
25

using namespace DPsim;
Steffen Vogel's avatar
Steffen Vogel committed
26
using namespace CPS::EMT;
27
using namespace CPS::EMT::Ph1;
Markus Mirz's avatar
Markus Mirz committed
28

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

Steffen Vogel's avatar
Steffen Vogel committed
35
36
37
38
39
40
41
	// Nodes
	auto n1 = Node::make("n1");
	auto n2 = Node::make("n2");
	auto n3 = Node::make("n3");

	// Components
	auto vin = VoltageSource::make("v_in");
Markus Mirz's avatar
Markus Mirz committed
42
	vin->setParameters(10);
Steffen Vogel's avatar
Steffen Vogel committed
43
	auto r1 = Resistor::make("r_1");
Markus Mirz's avatar
Markus Mirz committed
44
	r1->setParameters(5);
Steffen Vogel's avatar
Steffen Vogel committed
45
	auto r2 = Resistor::make("r_2");
Markus Mirz's avatar
Markus Mirz committed
46
	r2->setParameters(10);
Steffen Vogel's avatar
Steffen Vogel committed
47
	auto r3 = Resistor::make("r_3");
Markus Mirz's avatar
Markus Mirz committed
48
	r3->setParameters(2);
Steffen Vogel's avatar
Steffen Vogel committed
49
50
51
52
53
54
55

	// Topology
	vin->connect({ n1, n2 });
	r1->connect({ n1, Node::GND });
	r2->connect({ n2, Node::GND });
	r3->connect({ n2, Node::GND });

Markus Mirz's avatar
Markus Mirz committed
56
	// Define system topology
Steffen Vogel's avatar
Steffen Vogel committed
57
	SystemTopology system(50, SystemNodeList{n1, n2, n3, Node::GND}, SystemComponentList{vin, r1, r2, r3});
Markus Mirz's avatar
Markus Mirz committed
58

Markus Mirz's avatar
Markus Mirz committed
59
60
61
62
63
	// Logging
	auto logger = DataLogger::make(simName);
	logger->addAttribute("v1", n1->attribute("voltage"));
	logger->addAttribute("v2", n2->attribute("voltage"));
	logger->addAttribute("v3", n3->attribute("voltage"));
Steffen Vogel's avatar
Steffen Vogel committed
64

65
	Simulation sim(simName, system, timeStep, finalTime, Domain::EMT);
Markus Mirz's avatar
Markus Mirz committed
66
67
	sim.addLogger(logger);

68
	sim.run();
69

Steffen Vogel's avatar
Steffen Vogel committed
70
71
	return 0;
}