ShmemExample.cpp 2.21 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
	// Very simple test circuit. Just a few resistors and an inductance.
	// Voltage is read from VILLASnode and current through everything is written back.
32

33
34
35
36
37
38
39
	// Nodes
	auto n1 = Node::make("n1");
	auto n2 = Node::make("n2");
	auto n3 = Node::make("n3");
	auto n4 = Node::make("n4");

	// Components
40
41
42
43
44
	auto evs = VoltageSource::make("v_s");
	auto rs =  Resistor::make("r_s");
	auto rl =  Resistor::make("r_line");
	auto ll =  Inductor::make("l_line");
	auto rL =  Resistor::make("r_load");
45

46
47
48
49
50
51
	// Topology
	evs->connect({ Node::GND, n1 });
	rs->connect({ n1, n2 });
	rl->connect({ n2, n3 });
	ll->connect({ n3, n4 });
	rL->connect({ n4, Node::GND });
Steffen Vogel's avatar
Steffen Vogel committed
52

53
54
55
56
57
58
	// Parameters
	evs->setParameters(Complex(0, 0));
	rs->setParameters(1);
	rl->setParameters(1);
	ll->setParameters(1);
	rL->setParameters(1000);
59

60
61
	auto sys = SystemTopology(50, SystemNodeList{Node::GND, n1, n2, n3, n4}, SystemComponentList{evs, rs, rl, ll, rL});

62
	auto intf = Interface("/villas1-in", "/villas1-out");
Steffen Vogel's avatar
Steffen Vogel committed
63
	intf.addImport(evs->attribute<Complex>("V_ref"), 0);
Steffen Vogel's avatar
merge    
Steffen Vogel committed
64
	intf.addExport(evs->attribute<Complex>("i_comp"), 0);
65
66

	Real timeStep = 0.001;
67
	auto sim = Simulation("ShmemExample", sys, timeStep, 0.3);
68

69
	sim.addInterface(&intf);
70
	sim.run();
71

72
	return 0;
73
}