DP_VS_RC1.cpp 1.95 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_RC1";

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

	// Components
Markus Mirz's avatar
Markus Mirz committed
39
	auto vs = VoltageSource::make("vs", Logger::Level::DEBUG);
Markus Mirz's avatar
Markus Mirz committed
40
	vs->setParameters(Complex(10, 0));
Markus Mirz's avatar
Markus Mirz committed
41
	auto r1 = Resistor::make("r_1", Logger::Level::DEBUG);
Markus Mirz's avatar
Markus Mirz committed
42
	r1->setParameters(1);
Markus Mirz's avatar
Markus Mirz committed
43
	auto c1 = Capacitor::make("c_1", Logger::Level::DEBUG);
Markus Mirz's avatar
Markus Mirz committed
44
	c1->setParameters(0.001);
Markus Mirz's avatar
Markus Mirz committed
45

Markus Mirz's avatar
Markus Mirz committed
46
47
48
49
	// Topology
	vs->connect({ Node::GND, n1 });
	r1->connect({ n1, n2 });
	c1->connect({ n2, Node::GND });
Markus Mirz's avatar
Markus Mirz committed
50

Markus Mirz's avatar
Markus Mirz committed
51
	auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{vs, r1, c1});
Steffen Vogel's avatar
Steffen Vogel committed
52

Markus Mirz's avatar
Markus Mirz committed
53
	// Logging
Markus Mirz's avatar
Markus Mirz committed
54
55
56
	auto logger = DataLogger::make(simName);
	logger->addAttribute("v1", n1->attribute("voltage"));
	logger->addAttribute("v2", n2->attribute("voltage"));
Markus Mirz's avatar
Markus Mirz committed
57
	logger->addAttribute("i1", r1->attribute("i_intf"));
Markus Mirz's avatar
Markus Mirz committed
58

Petra Raussi's avatar
Petra Raussi committed
59
	Simulation sim(simName, sys, timeStep, finalTime);
Markus Mirz's avatar
Markus Mirz committed
60
61
	sim.addLogger(logger);

Petra Raussi's avatar
Petra Raussi committed
62
63
64
65
	sim.run();

	return 0;
}