WSCC_9bus_mult_coupled.cpp 4.67 KB
Newer Older
1
2
/* Copyright 2017-2020 Institute for Automation of Complex Power Systems,
 *                     EONERC, RWTH Aachen University
Markus Mirz's avatar
Markus Mirz committed
3
 *
4
5
6
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
Markus Mirz's avatar
Markus Mirz committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 *********************************************************************************/

#include <iostream>
#include <list>
#include <fstream>

#include <DPsim.h>
#include <dpsim/ThreadLevelScheduler.h>

using namespace DPsim;
using namespace CPS;

void multiply_connected(SystemTopology& sys, int copies,
	Real resistance, Real inductance, Real capacitance) {

	sys.multiply(copies);
	int counter = 0;
    std::vector<String> nodes = {"BUS5", "BUS8", "BUS6"};

	for (auto orig_node : nodes) {
		std::vector<String> nodeNames{orig_node};
    	for (int i = 2; i < copies+2; i++) {
			nodeNames.push_back(orig_node + "_" + std::to_string(i));
		}
		nodeNames.push_back(orig_node);

        // if only a single copy is added, it does not really make sense to
		// "close the ring" by adding another line
		int nlines = copies == 1 ? 1 : copies+1;
		for (int i = 0; i < nlines; i++) {
            // TODO lumped resistance?
Markus Mirz's avatar
Markus Mirz committed
38
            auto rl_node = std::make_shared<DP::SimNode>("N_add_" + std::to_string(counter));
Markus Mirz's avatar
Markus Mirz committed
39
40
41
42
43
44
45
46
47
48
            auto res = DP::Ph1::Resistor::make("R_" + std::to_string(counter));
            res->setParameters(resistance);
            auto ind = DP::Ph1::Inductor::make("L_" + std::to_string(counter));
            ind->setParameters(inductance);
            auto cap1 = DP::Ph1::Capacitor::make("C1_" + std::to_string(counter));
            cap1->setParameters(capacitance / 2.);
            auto cap2 = DP::Ph1::Capacitor::make("C2_" + std::to_string(counter));
            cap2->setParameters(capacitance / 2.);

            sys.addNode(rl_node);
Markus Mirz's avatar
Markus Mirz committed
49
50
51
52
            res->connect({sys.node<DP::SimNode>(nodeNames[i]), rl_node});
            ind->connect({rl_node, sys.node<DP::SimNode>(nodeNames[i+1])});
            cap1->connect({sys.node<DP::SimNode>(nodeNames[i]), DP::SimNode::GND});
            cap2->connect({sys.node<DP::SimNode>(nodeNames[i+1]), DP::SimNode::GND});
Markus Mirz's avatar
Markus Mirz committed
53
54
55
56
57
58
            counter += 1;

            sys.addComponent(res);
            sys.addComponent(ind);
            sys.addComponent(cap1);
            sys.addComponent(cap2);
Markus Mirz's avatar
Markus Mirz committed
59
60
61
62

			// TODO use line model
			//auto line = DP::Ph1::PiLine::make("line" + std::to_string(counter));
            //line->setParameters(resistance, inductance, capacitance);
Markus Mirz's avatar
Markus Mirz committed
63
            //line->connect({sys.node<DP::SimNode>(nodeNames[i]), sys.node<DP::SimNode>(nodeNames[i+1])});
Markus Mirz's avatar
Markus Mirz committed
64
65
66
67
		}
	}
}

68
void simulateCoupled(std::list<fs::path> filenames, CommandLineArgs& args, Int copies, Int threads, Int seq = 0) {
Markus Mirz's avatar
Markus Mirz committed
69
70
	String simName = "WSCC_9bus_coupled_" + std::to_string(copies)
		+ "_" + std::to_string(threads) + "_" + std::to_string(seq);
Markus Mirz's avatar
Markus Mirz committed
71
72
	Logger::setLogDir("logs/"+simName);

73
	CIM::Reader reader(simName, args.logLevel, args.logLevel);
Markus Mirz's avatar
Markus Mirz committed
74
75
	SystemTopology sys = reader.loadCIM(60, filenames);

Markus Mirz's avatar
Markus Mirz committed
76
77
	if (copies > 0)
		multiply_connected(sys, copies, 12.5, 0.16, 1e-6);
Markus Mirz's avatar
Markus Mirz committed
78

79
	Simulation sim(simName, args);
Markus Mirz's avatar
Markus Mirz committed
80
	sim.setSystem(sys);
Markus Mirz's avatar
Markus Mirz committed
81
82
	if (threads > 0)
		sim.setScheduler(std::make_shared<OpenMPLevelScheduler>(threads));
Markus Mirz's avatar
Markus Mirz committed
83
84
85

	// Logging
	//auto logger = DataLogger::make(simName);
Markus Mirz's avatar
Markus Mirz committed
86
87
88
89
90
91
92
93
	//for (Int cop = 1; cop <= copies; cop++) {
	//	for (Int bus  = 1; bus <= 9; bus++) {
	//		String attrName = "v" + std::to_string(bus) + "_" + std::to_string(cop);
	//		String nodeName = "BUS" + std::to_string(bus) + "_" + std::to_string(cop);
	//		if (cop == 1) {
	//			attrName = "v" + std::to_string(bus);
	//			nodeName = "BUS" + std::to_string(bus);
	//		}
Markus Mirz's avatar
Markus Mirz committed
94
	//		logger->addAttribute(attrName, sys.node<DP::SimNode>(nodeName)->attribute("v"));
Markus Mirz's avatar
Markus Mirz committed
95
96
	//	}
	//}
Markus Mirz's avatar
Markus Mirz committed
97
	//sim.addLogger(logger);
Markus Mirz's avatar
Markus Mirz committed
98
99

	sim.run();
Markus Mirz's avatar
Markus Mirz committed
100
	sim.logStepTimes(simName + "_step_times");
Markus Mirz's avatar
Markus Mirz committed
101
102
103
}

int main(int argc, char *argv[]) {
Markus Mirz's avatar
Markus Mirz committed
104
	CommandLineArgs args(argc, argv);
105
106
107
108
	args.timeStep = 0.0001;
	args.duration = 0.5;
	args.solver.domain = Domain::DP;
	args.solver.type = Solver::Type::MNA;
Markus Mirz's avatar
Markus Mirz committed
109

Markus Mirz's avatar
Markus Mirz committed
110
111
112
113
114
115
	std::list<fs::path> filenames;
	filenames = DPsim::Utils::findFiles({
		"WSCC-09_RX_DI.xml",
		"WSCC-09_RX_EQ.xml",
		"WSCC-09_RX_SV.xml",
		"WSCC-09_RX_TP.xml"
116
	}, "build/_deps/cim-data-src/WSCC-09/WSCC-09_RX", "CIMPATH");
Markus Mirz's avatar
Markus Mirz committed
117
118
119
120
121
122
123
124
125

	//for (Int copies = 0; copies < 20; copies++) {
	//	for (Int threads = 0; threads <= 12; threads = threads+2)
	//		simulateCoupled(filenames, copies, threads);
	//}

	std::cout << "Simulate with " << Int(args.options["copies"]) << " copies, "
		<< Int(args.options["threads"]) << " threads, sequence number "
		<< Int(args.options["seq"]) << std::endl;
126
127
	simulateCoupled(filenames, args, Int(args.options["copies"]),
		Int(args.options["threads"]), Int(args.options["seq"]));
Markus Mirz's avatar
Markus Mirz committed
128
}