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

#include <iostream>
#include <list>

26
#include <DPsim.h>
27
#include <dpsim/Interface.h>
28
#include <cps/CIM/Reader.h>
29
30
31

using namespace DPsim;
using namespace CPS;
32
using namespace CPS::DP::Ph1;
Markus Mirz's avatar
Markus Mirz committed
33
using namespace CPS::Signal;
34
35

int main(int argc, char *argv[]) {
36

37
	CommandLineArgs args(argc, argv, "Shmem_WSCC-9bus_CtrlDist", 0.001, 20, 60);
Markus Mirz's avatar
Markus Mirz committed
38

39
	if (args.scenario == 0) {
40

41
		// Specify CIM files
42
		String path("Examples/CIM/WSCC-09_RX/");
43
		std::list<String> filenames = {
44
45
46
47
			path + "WSCC-09_RX_DI.xml",
			path + "WSCC-09_RX_EQ.xml",
			path + "WSCC-09_RX_SV.xml",
			path + "WSCC-09_RX_TP.xml"
48
		};
49

50
		CIM::Reader reader(args.name, Logger::Level::INFO, Logger::Level::INFO);
51
		SystemTopology sys = reader.loadCIM(args.sysFreq, filenames);
52

53
		// Extend system with controllable load (Profile)
Steffen Vogel's avatar
Steffen Vogel committed
54
		auto load_profile = PQLoadCS::make("load_cs_profile", 0, 0, 230000, Logger::Level::INFO);
55
		load_profile->connect({ sys.node<DP::Node>("BUS7") });
56
57
		sys.mComponents.push_back(load_profile);

Markus Mirz's avatar
Markus Mirz committed
58
		// Extend system with controllable load
Steffen Vogel's avatar
Steffen Vogel committed
59
		auto ecs = CurrentSource::make("i_intf", Complex(0, 0), Logger::Level::DEBUG);
60
		ecs->connect({ sys.node<DP::Node>("BUS4"), DP::Node::GND });
61
		sys.mComponents.push_back(ecs);
Markus Mirz's avatar
Markus Mirz committed
62

63
		RealTimeSimulation sim(args.name + "_1", sys, args.timeStep, args.duration,
64
			Domain::DP, Solver::Type::MNA, Logger::Level::DEBUG, true);
65

66
67
68
69
70
71
72
		// Create shmem interface and add it to simulation
		String in  = "/dpsim10";
		String out = "/dpsim01";
		Interface::Config conf;
		conf.samplelen = 64;
		conf.queuelen = 1024;
		conf.polling = false;
73
74
75
76
77
78
79
80
81
82
83
84
85
		Interface intf1(out, in, &conf);
		sim.addInterface(&intf1, false, true);

		// Create shmem interface 2
		String in2  = "/villas-dpsim1";
		String out2 = "/dpsim1-villas";
		Interface::Config conf2;
		conf2.samplelen = 64;
		conf2.queuelen = 1024;
		conf2.polling = false;
		Interface intf2(out2, in2, &conf2);
		sim.addInterface(&intf2, false, false);

86
87
88
		// Controllers and filter
		std::vector<Real> coefficients_profile = std::vector(2000, 1./2000);

89
		auto filtP_profile = FIRFilter::make("filter_p_profile", coefficients_profile, 0, Logger::Level::INFO);
90
		filtP_profile->setPriority(1);
Steffen Vogel's avatar
merge    
Steffen Vogel committed
91
92
		filtP_profile->setConnection(load_profile->attribute<Real>("power_active"));
		filtP_profile->attribute<Real>("input")->set(0.);
93
94
		sys.mComponents.push_back(filtP_profile);

95
		// Register interface current source and voltage drop
Steffen Vogel's avatar
Steffen Vogel committed
96
		intf1.addImport(ecs->attribute<Complex>("I_ref"), 0);
Steffen Vogel's avatar
merge    
Steffen Vogel committed
97
		intf1.addExport(ecs->attribute<Complex>("v_comp"), 0);
98

Steffen Vogel's avatar
merge    
Steffen Vogel committed
99
100
		// TODO: gain by 20e8
		intf2.addImport(filtP_profile->attribute<Real>("input"), 0);
101

102
		// Register exportable node voltages
103
		for (auto n : sys.mNodes) {
104
			UInt i;
Steffen Vogel's avatar
Steffen Vogel committed
105
106
			if (sscanf(n->name().c_str(), "BUS%u", &i) != 1) {
				std::cerr << "Failed to determine bus no of bus: " << n->name() << std::endl;
107
108
109
110
111
				continue;
			}

			i--;

Steffen Vogel's avatar
merge    
Steffen Vogel committed
112
			auto v = n->attributeComplex("voltage");
113

Steffen Vogel's avatar
Steffen Vogel committed
114
115
			std::cout << "Signal << " << (i*2)+0 << ": Mag " << n->name() << std::endl;
			std::cout << "Signal << " << (i*2)+1 << ": Phas " << n->name() << std::endl;
116

Steffen Vogel's avatar
merge    
Steffen Vogel committed
117
118
			intf2.addExport(v->mag(),   (i*2)+0);
			intf2.addExport(v->phase(), (i*2)+1);
119
		}
120

121
		sim.run(args.startTime);
122
123
	}

124
	if (args.scenario == 1) {
125
		// Nodes
Steffen Vogel's avatar
Steffen Vogel committed
126
		auto n1 = DP::Node::make("n1", PhaseType::Single, std::vector<Complex>({Complex(02.180675e+05, -1.583367e+04)}));
127
128

		// Add interface voltage source
Markus Mirz's avatar
Markus Mirz committed
129
130
		auto evs = VoltageSource::make("v_intf", Logger::Level::DEBUG);
		evs->setParameters(Complex(0, 0));
Steffen Vogel's avatar
Steffen Vogel committed
131
		evs->connect({ DP::Node::GND, n1 });
132

133
		// Extend system with controllable load
Steffen Vogel's avatar
Steffen Vogel committed
134
		auto load = PQLoadCS::make("load_cs", 0, 0, 230000);
Steffen Vogel's avatar
Steffen Vogel committed
135
		load->connect({ n1 });
136

137
138
		// Controllers and filter
		std::vector<Real> coefficients = std::vector(100, 1./100);
139
		auto filtP = FIRFilter::make("filter_p", coefficients, 0, Logger::Level::INFO);
140
		filtP->setPriority(1);
Steffen Vogel's avatar
merge    
Steffen Vogel committed
141
142
		filtP->setConnection(load->attribute<Real>("active_power"));
		filtP->attribute<Real>("input")->set(0.);
143

Steffen Vogel's avatar
Steffen Vogel committed
144
		auto sys = SystemTopology(args.sysFreq, SystemNodeList{n1}, SystemComponentList{evs, load, filtP});
145
		RealTimeSimulation sim(args.name + "_2", sys, args.timeStep, args.duration);
146
147
148
149
150
151
152
153
154

		// Create shmem interface 1
		String in1  = "/dpsim01";
		String out1 = "/dpsim10";
		Interface::Config conf1;
		conf1.samplelen = 64;
		conf1.queuelen = 1024;
		conf1.polling = false;
		Interface intf1(out1, in1, &conf1);
155
		sim.addInterface(&intf1, false, true);
156
157

		// Create shmem interface 2
158
159
		String in2  = "/villas-dpsim2";
		String out2 = "/dpsim2-villas";
160
161
162
163
164
		Interface::Config conf2;
		conf2.samplelen = 64;
		conf2.queuelen = 1024;
		conf2.polling = false;
		Interface intf2(out2, in2, &conf2);
165
		sim.addInterface(&intf2, false, false);
166
167
168

		// Register voltage source reference and current flowing through source
		// multiply with -1 to consider passive sign convention
Steffen Vogel's avatar
Steffen Vogel committed
169
		intf1.addImport(evs->attribute<Complex>("V_ref"), 0);
Steffen Vogel's avatar
merge    
Steffen Vogel committed
170
171
		// TODO: invalid sign
		intf1.addExport(evs->attribute<Complex>("i_comp"), 0);
172
173

		// Register controllable load
Steffen Vogel's avatar
merge    
Steffen Vogel committed
174
175
176
177
		intf2.addImport(filtP->attribute<Real>("input"), 0);
		intf2.addExport(load->attribute<Real>("power_active"), 0);
		intf2.addExport(load->attribute<Complex>("v_comp"), 1);
		intf2.addExport(load->attribute<Complex>("i_comp"), 2);
178

179
		sim.run(args.startTime);
180
181
182
183
	}

	return 0;
}