Commit 075b0d50 authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

add support for external current sources


Former-commit-id: 95974fdc
parent ca60fa47
#include "ExternalCurrentSource.h"
using namespace DPsim;
ExternalCurrentSource::ExternalCurrentSource(std::string name, int src, int dest, Real current, Real phase) : CurrentSource(name, src, dest, current, phase) {
this->mPhase = phase;
}
void ExternalCurrentSource::setCurrent(Real current) {
this->currentr = current*cos(this->mPhase);
this->currenti = current*sin(this->mPhase);
}
#pragma once
#include "CurrentSource.h"
namespace DPsim {
/** Ideal current source, but the current value can be changed between simulation
* steps (for example for interfacing with another simulator) */
class ExternalCurrentSource : public CurrentSource {
private:
Real mPhase;
public:
ExternalCurrentSource() {};
ExternalCurrentSource(std::string name, int src, int dest, Real current, Real phase);
void setCurrent(Real current);
};
}
...@@ -7,16 +7,16 @@ using namespace DPsim; ...@@ -7,16 +7,16 @@ using namespace DPsim;
void DPsim::villasExample() void DPsim::villasExample()
{ {
// Very simple test circuit. Just 2 resistors and a voltage read from VILLASnode. // Very simple test circuit. Just 2 resistors and a current read from VILLASnode.
Logger log, llog, rlog; Logger log, llog, rlog;
std::vector<BaseComponent*> comps; std::vector<BaseComponent*> comps;
ExternalVoltageSource *evs = new ExternalVoltageSource("v1", 1, 0, 5, 0, 1); ExternalCurrentSource *ecs = new ExternalCurrentSource("i1", 1, 0, 0, 0);
comps.push_back(evs); comps.push_back(ecs);
comps.push_back(new LinearResistor("r1", 1, 2, 1)); comps.push_back(new LinearResistor("r1", 1, 2, 1));
comps.push_back(new LinearResistor("r2", 2, 0, 1)); comps.push_back(new LinearResistor("r1", 2, 0, 1));
VillasInterface *villas = new VillasInterface("/villas1"); VillasInterface *villas = new VillasInterface("/villas1");
villas->registerVoltageSource(evs, 0); villas->registerCurrentSource(ecs, 0);
// Set up simulation // Set up simulation
Real timeStep = 0.01; Real timeStep = 0.01;
......
...@@ -25,6 +25,10 @@ void VillasInterface::registerVoltageSource(ExternalVoltageSource *evs, int num) ...@@ -25,6 +25,10 @@ void VillasInterface::registerVoltageSource(ExternalVoltageSource *evs, int num)
mExtComponents[num] = evs; mExtComponents[num] = evs;
} }
void VillasInterface::registerCurrentSource(ExternalCurrentSource *ecs, int num) {
mExtComponents[num] = ecs;
}
void VillasInterface::readValues() { void VillasInterface::readValues() {
struct sample *sample; struct sample *sample;
int ret = 0; int ret = 0;
...@@ -42,8 +46,11 @@ void VillasInterface::readValues() { ...@@ -42,8 +46,11 @@ void VillasInterface::readValues() {
// TODO integer format? // TODO integer format?
ExternalVoltageSource *evs = dynamic_cast<ExternalVoltageSource*>(it->second); ExternalVoltageSource *evs = dynamic_cast<ExternalVoltageSource*>(it->second);
if (evs) if (evs)
evs->setVoltage(sample->data[0].f); evs->setVoltage(sample->data[it->first].f);
// TODO other classes
ExternalCurrentSource *ecs = dynamic_cast<ExternalCurrentSource*>(it->second);
if (ecs)
ecs->setCurrent(sample->data[it->first].f);
sample_put(sample); sample_put(sample);
} }
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <villas/shmem.h> #include <villas/shmem.h>
#include "ExternalInterface.h" #include "ExternalInterface.h"
#include "Components/ExternalCurrentSource.h"
#include "Components/ExternalVoltageSource.h" #include "Components/ExternalVoltageSource.h"
namespace DPsim { namespace DPsim {
...@@ -21,6 +22,7 @@ namespace DPsim { ...@@ -21,6 +22,7 @@ namespace DPsim {
VillasInterface(const char* name); VillasInterface(const char* name);
~VillasInterface(); ~VillasInterface();
void registerVoltageSource(ExternalVoltageSource* evs, int num); void registerVoltageSource(ExternalVoltageSource* evs, int num);
void registerCurrentSource(ExternalCurrentSource* ecs, int num);
virtual void readValues(); virtual void readValues();
}; };
}; };
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