ShmemDistributedDirect.cpp 3.57 KB
Newer Older
1
2
/** Example of shared memory interface
 *
Steffen Vogel's avatar
Steffen Vogel committed
3
 * @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
4
 * @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC
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/>.
 *********************************************************************************/

22
#include <DPsim.h>
23
24

using namespace DPsim;
25
using namespace CPS::DP;
26
using namespace CPS::DP::Ph1;
27

28
int main(int argc, char *argv[]) {
29
30
31
32
33
34
35
	// Testing the interface with a simple circuit,
	// but the load is simulated in a different instance.
	// Values are exchanged using the ideal transformator model: an ideal
	// current source on the supply side and an ideal voltage source on the
	// supply side, whose values are received from the respective other circuit.
	// Here, the two instances directly communicate with each other without using
	// VILLASnode in between.
36

37
	Interface::Config conf;
38
39
40
41
42
43
44
45
46
	conf.samplelen = 4;
	conf.queuelen = 1024;
	conf.polling = false;

	if (argc < 2) {
		std::cerr << "not enough arguments (either 0 or 1 for the test number)" << std::endl;
		std::exit(1);
	}

47
48
49
50
51
52
53
54
55
56
57
	String in, out;

	if (String(argv[1]) == "0") {
		in  = "/dpsim10";
		out = "/dpsim01";
	}
	else if (String(argv[1]) == "1") {
		in  = "/dpsim01";
		out = "/dpsim10";
	}

58
	auto intf = Interface(in, out, &conf);
59

60
61
	Real timeStep = 0.000150;

62
	if (String(argv[1]) == "0") {
63
		// Nodes
Markus Mirz's avatar
Markus Mirz committed
64
65
		auto n1 = Node::make("n1");
		auto n2 = Node::make("n2");
66

67
		// Components
68
69
		auto evs = VoltageSource::make("v_intf", Logger::Level::DEBUG);
		auto vs1 = VoltageSource::make("vs_1", Logger::Level::DEBUG);
Steffen Vogel's avatar
Steffen Vogel committed
70
71
		auto r01 = Resistor::make("r_0_1", 1, Logger::Level::DEBUG);

72
73
74
75
76
77
		evs->setParameters(Complex(5, 0));
		vs1->setParameters(Complex(10, 0));

		evs->connect({ Node::GND, n2 });
		vs1->connect({ Node::GND, n1 });
		r01->connect({ n1, n2 });
78

Steffen Vogel's avatar
Steffen Vogel committed
79
		intf.addImport(evs->attribute<Complex>("V_ref"), 0);
Steffen Vogel's avatar
merge    
Steffen Vogel committed
80
		intf.addExport(evs->attribute<Complex>("i_comp"), 0);
81

Steffen Vogel's avatar
Steffen Vogel committed
82
		auto sys = SystemTopology(50, SystemNodeList{n1, n2}, SystemComponentList{evs, vs1, r01});
83
		auto sim = Simulation("ShmemDistributedDirect_1", sys, timeStep, 0.1);
84

85
		sim.addInterface(&intf);
Markus Mirz's avatar
Markus Mirz committed
86
		sim.run();
87
	}
88
	else if (String(argv[1]) == "1") {
89
		// Nodes
Markus Mirz's avatar
Markus Mirz committed
90
		auto n1 = Node::make("n1");
91

92
		// Components
Steffen Vogel's avatar
Steffen Vogel committed
93
94
95
		auto ecs = CurrentSource::make("i_intf", Complex(5, 0), Logger::Level::DEBUG);
		auto rgnd0 = Resistor::make("r_gnd_0", 1, Logger::Level::DEBUG);

96
97
		ecs->connect({ Node::GND, n1 });
		rgnd0->connect({ Node::GND, n1 });
Steffen Vogel's avatar
Steffen Vogel committed
98

99
100
		//auto ecs_switch = CurrentSource::make("i_switch", GND, 1, Complex(0, 0));
		//auto r01 = Resistor::make("r_0_1", 0, 1, 1);
101

Steffen Vogel's avatar
Steffen Vogel committed
102
		intf.addImport(ecs->attribute<Complex>("I_ref"), 0);
Steffen Vogel's avatar
merge    
Steffen Vogel committed
103
104
		intf.addExport(ecs->attribute<Complex>("v_comp"), 0);
		//intf.addImport(ecs_switch->attribute('CurrentRef'), 1);
Steffen Vogel's avatar
Steffen Vogel committed
105

Steffen Vogel's avatar
Steffen Vogel committed
106
		auto sys = SystemTopology(50, SystemNodeList{n1}, SystemComponentList{ecs, rgnd0});
107
		auto sim = Simulation("ShmemDistributedDirect_2", sys, timeStep, 0.1);
108

109
		sim.addInterface(&intf);
Markus Mirz's avatar
Markus Mirz committed
110
		sim.run();
111
112
	}
	else {
113
114
115
		std::cerr << "invalid test number" << std::endl;
		std::exit(1);
	}
Steffen Vogel's avatar
Steffen Vogel committed
116

117
	return 0;
118
}