Commit 71ab3b89 authored by Georg Martin Reinke's avatar Georg Martin Reinke
Browse files

first steps for integrating CIM-XML


Former-commit-id: c18e2790
parent 9dba1807
[submodule "Source/CIM-XML-Parser"]
path = Source/CIM-XML-Parser
url = git@git.rwth-aachen.de:CIM-XML-Interface/CIM-XML-Parser.git
Subproject commit 42a5b7bf5ab40c05684c51d0b43a09398466d35a
#include "CIMReader.h"
#include "CIMModel.hpp"
#include "IEC61970.hpp"
#include "Components/RxLine.h"
using namespace DPsim;
using namespace IEC61970::Base::Domain;
using namespace IEC61970::Base::Core;
using namespace IEC61970::Base::Topology;
using namespace IEC61970::Base::Wires;
// TODO is UnitMulitplier actually used/set anywhere?
double CIMReader::unitValue(double value, UnitMultiplier mult) {
switch (mult) {
case UnitMultiplier::p:
value *= 1e-12;
break;
case UnitMultiplier::n:
value *= 1e-9;
break;
case UnitMultiplier::micro:
value *= 1e-6;
break;
case UnitMultiplier::m:
value *= 1e-3;
break;
case UnitMultiplier::c:
value *= 1e-2;
break;
case UnitMultiplier::d:
value *= 1e-1;
break;
case UnitMultiplier::k:
value *= 1e3;
break;
case UnitMultiplier::M:
value *= 1e6;
break;
case UnitMultiplier::G:
value *= 1e9;
break;
case UnitMultiplier::T:
value *= 1e12;
break;
default:
break;
}
return value;
}
CIMReader::CIMReader() {
mModel.setDependencyCheckOff();
}
CIMReader::~CIMReader() {
}
BaseComponent* CIMReader::mapACLineSegment(ACLineSegment* line) {
std::vector<int> &nodes = mEqNodeMap.at(line->mRID); // TODO can fail
if (nodes.size() != 2) {
std::cerr << "ACLineSegment " << line->mRID << " has " << nodes.size() << " terminals, ignoring" << std::endl;
// TODO better error handling (throw exception?)
return nullptr;
}
Real r = line->r.value;
Real x = line->x.value;
std::cerr << "RxLine " << line->name << " rid=" << line->mRID << " node1=" << nodes[0] << " node2=" << nodes[1];
std::cerr << " R=" << r << " X=" << x << std::endl;
return new RxLine(line->name, nodes[0], nodes[1], r, x);
}
BaseComponent* CIMReader::mapComponent(BaseClass* obj) {
// TODO can we do this nicer than with a giant dynamic switch?
ACLineSegment* line;
if ((line = dynamic_cast<ACLineSegment*>(obj)))
return mapACLineSegment(line);
return nullptr;
}
bool CIMReader::addFile(std::string filename) {
return mModel.addCIMFile(filename);
}
std::vector<BaseComponent*> CIMReader::mapComponents() {
std::vector<BaseComponent*> compVector;
mModel.parseFiles();
// First, go through all topological nodes and collect them in a list.
// Since all nodes have references to the equipment connected to them (via Terminals), but not
// the other way around (which we need for instantiating the components), we collect that information here as well.
for (BaseClass* obj : mModel.Objects) {
TopologicalNode* topNode = dynamic_cast<TopologicalNode*>(obj);
if (topNode) {
std::cerr << "TopologicalNode " << mTopNodes.size()+1 << " rid=" << topNode->mRID << " Terminals:" << std::endl;
mTopNodes.push_back(topNode);
for (Terminal* term : topNode->Terminal) {
std::cerr << " " << term->mRID << std::endl;
ConductingEquipment *eq = term->ConductingEquipment;
if (!eq) {
std::cerr << "Terminal " << term->mRID << " has no Conducting Equipment, ignoring!" << std::endl;
} else {
std::cerr << " eq " << eq->mRID << " sequenceNumber " << term->sequenceNumber << std::endl;
std::vector<int> &nodesVec = mEqNodeMap[eq->mRID];
if (nodesVec.size() < term->sequenceNumber)
nodesVec.resize(term->sequenceNumber);
nodesVec[term->sequenceNumber-1] = mTopNodes.size();
}
}
}
}
for (BaseClass* obj : mModel.Objects) {
BaseComponent* comp = mapComponent(obj);
if (comp)
compVector.push_back(comp);
}
return compVector;
}
#ifndef CIMREADER_H
#define CIMREADER_H
#include <vector>
#include "Components/BaseComponent.h"
#include "CIMModel.hpp"
#include "IEC61970.hpp"
using namespace DPsim;
using namespace IEC61970::Base::Domain;
using namespace IEC61970::Base::Topology;
using namespace IEC61970::Base::Wires;
namespace DPsim {
class CIMReader {
private:
CIMModel mModel;
// List of topological nodes. Offset by 1 to the index used for the
// component constructors (first entry in this vector should correspond
// to giving a 1 in the component constructor).
//
// TODO do we even need this?
std::vector<TopologicalNode*> mTopNodes;
// Maps the RID of a ConductingEquipment to a list of nodes as given in
// the component constructors.
std::map<std::string, std::vector<int>> mEqNodeMap;
BaseComponent* mapComponent(BaseClass* obj);
BaseComponent* mapACLineSegment(ACLineSegment* line);
public:
CIMReader();
virtual ~CIMReader();
bool addFile(std::string filename);
std::vector<BaseComponent*> mapComponents();
static double unitValue(double value, UnitMultiplier mult);
};
};
#endif
#include <iostream>
#include <string>
#include "NetlistSim.h"
#include "CIMReader.h"
#include "Examples/SynchronGenUnitTest.h"
#include "Examples/SyncGenUnitTestVBR.h"
#include "Examples/ReferenceCircuits.h"
......@@ -10,11 +10,16 @@
using namespace DPsim;
int main(int argc, char* argv[]) {
CIMReader reader;
for (int i = 1; i < argc; i++) {
if (!reader.addFile(argv[i]))
std::cerr << "Failed to read file " << argv[i] << std::endl;
}
std::vector<BaseComponent*> components = reader.mapComponents();
//shmemRTExample();
//shmemDistributed(argc, argv);
//shmemRTExample();
//shmemDistributedExample(argc, argv);
//shmemDistributedRef();
/*simulationExample1();
simulationExample2();
......@@ -46,7 +51,7 @@ int main(int argc, char* argv[]) {
//SynGenUnitTestPhaseToPhaseFault();
//SynGenUnitTestThreePhaseFault();
//SynGenDPUnitTestBalancedResLoad();
SynGenUnitTestVBR();
//SynGenUnitTestVBR();
//RXLineResLoad();
//VarFreqRXLineResLoad();
......
# Declaration of variables
CC = g++
CC_FLAGS = -O3 -w -std=c++11 $(INCLUDES)
LD_FLAGS = -lvillas-ext -lrt
CC_FLAGS = -03 -w -std=c++11 $(INCLUDES)
LD_FLAGS = -lvillas-ext -lrt -LCIM-XML-Parser/build/thirdparty/arabica -larabica -LCIM-XML-Parser/build -lCIMParser
# File names
EXEC = DPSolver
......@@ -12,7 +12,7 @@ TEST_SOURCES = $(wildcard Tests/Test*.cpp)
TEST_OBJS = $(TEST_SOURCES:.cpp=.o)
TEST_BINS = $(TEST_SOURCES:.cpp=)
INCLUDES = -I /usr/local/include/eigen -I /usr/include/eigen3
INCLUDES = -I /usr/local/include/eigen -I /usr/include/eigen3 -ICIM-XML-Parser/src -ICIM-XML-Parser/IEC61970CIM16v29a
.PHONY: tests clean
......@@ -26,7 +26,7 @@ $(EXEC): $(OBJECTS) DPsimMain.o
# To remove generated files
clean:
rm -f $(EXEC) $(OBJECTS) $(TEST_BINS)
rm -f $(EXEC) $(OBJECTS) DPsimMain.o $(TEST_BINS)
Tests/Test%: $(OBJECTS) Tests/Test%.o
$(CC) $^ $(LD_FLAGS) -o $@
......
......@@ -3,4 +3,4 @@
void updateProgressBar(double time, double finalTime);
#endif
\ No newline at end of file
#endif
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