Commit d09d1b55 authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

add shmem Python example


Former-commit-id: 905ff699
parent cfd9a483
#!/usr/bin/python3
import dpsim
comps = [dpsim.VoltSourceRes("v_s", 1, 0, 10000+0j, 1),
dpsim.Inductor("l_1", 1, 2, 1e-3)]
evs = dpsim.ExternalVoltageSource("v_ext", 2, 0, 0+0j, 1)
comps.append(evs)
intf = dpsim.ShmemInterface("/dpsim12", "/dpsim21", samplelen=2)
intf.register_source(evs, 0, 1)
intf.export_current(evs, 0, 1)
sim = dpsim.Simulation(comps, duration=1, llog="lvector-shmem1.csv")
sim.add_interface(intf)
sim.start()
sim.wait()
#!/usr/bin/python3
import dpsim
comps = [dpsim.LinearResistor("r_1", 1, 0, 1)]
ecs = dpsim.ExternalCurrentSource("i_ext", 1, 0, 0+0j)
comps.append(ecs)
intf = dpsim.ShmemInterface("/dpsim21", "/dpsim12", samplelen=2)
intf.register_source(ecs, 0, 1)
intf.export_voltage(1, 0, 0, 1)
sim = dpsim.Simulation(comps, duration=1, llog="lvector-shmem2.csv")
sim.add_interface(intf)
sim.start()
sim.wait()
......@@ -13,7 +13,12 @@ using namespace DPsim;
void ShmemInterface::init(const char* wname, const char* rname, struct shmem_conf* conf) {
/* using a static shmem_conf as a default argument for the constructor
* doesn't seem to work, so use this as a workaround */
if (shmem_int_open(wname, rname, &this->mShmem, conf) < 0) {
// make local copies of the filenames, because shmem_int doesn't make copies
// and needs them for the close function
this->wname = std::string(wname);
this->rname = std::string(rname);
if (shmem_int_open(this->wname.c_str(), this->rname.c_str(), &this->mShmem, conf) < 0) {
std::perror("Failed to open/map shared memory object");
std::exit(1);
}
......
......@@ -22,6 +22,7 @@ namespace DPsim {
struct shmem_int mShmem;
struct sample *mLastSample;
int mSeq;
std::string rname, wname;
void init(const char *wname, const char *rname, struct shmem_conf *conf);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment