Commit 0a8ddc89 authored by Gerrit Erichsen's avatar Gerrit Erichsen
Browse files

Added way to check upon location's existence when configuring grid with...

Added way to check upon location's existence when configuring grid with CharLGUI::configureAlgorithm().
Also added functionality to add/replace, when said location does not exist.
This hopefully resolves nullptr issues with MonteCarlo runs
parent ef9fbc3b
......@@ -261,6 +261,34 @@ size_t CharLAlgorithm::createLocation(size_t node, string name, double lat, doub
return m_nodes[node]->addLocation(location);
}
void CharLAlgorithm::insertOrReplaceLocation(size_t node, size_t location, string name,
double lat, double lon, double areaSolar, double areaWind)
{
if (node < m_nodes.size())
{
if (m_nodes.size() < location)
{
if (m_nodes.size() != location)
{
int diff = location - m_nodes.size();
for (int i = 0; i < diff; i++)
{
Location dummy("dummy" + to_string(i), 54., 9., 0., 0., m_preferences);
m_nodes[node]->addLocation(dummy);
}
cout << "WARNING: had to create " << diff << "dummy locations" << endl;
}
Location newLocation(name, lat, lon, areaSolar, areaWind, m_preferences);
m_nodes[node]->addLocation(newLocation);
}
}
else
{
Location newLocation(name, lat, lon, areaSolar, areaWind, m_preferences);
m_nodes[node]->setLocation(location, newLocation);
}
}
void CharLAlgorithm::addConventionalPlant(size_t network, size_t location, string name, double gradient,
double nominalPower, double co2, double actualCO2,
vector<pair<double,double>> efficiencyCurve,
......@@ -466,6 +494,20 @@ void CharLAlgorithm::run()
}
}
bool CharLAlgorithm::hasLocationDataForNodeAt(size_t nodeIndex, size_t locationIndex,
const string & name)
{
if (nodeIndex < m_nodes.size())
{
const Location * location = m_nodes[nodeIndex]->getLocationPtr(locationIndex);
if (location != nullptr)
{
return location->getName() == name;
}
}
return false;
}
Result * CharLAlgorithm::getResult()
{
......
......@@ -91,6 +91,9 @@ public:
int createNode(string name); // former network
size_t createLocation(size_t node, string name, double lat , double lon, double areaSolar, double areaWind); // local in node
void insertOrReplaceLocation(size_t node, size_t location,
string name, double lat , double lon,
double areaSolar, double areaWind);
void addConventionalPlant(size_t network, size_t location, string name,
double gradient, double nominalPower,
double co2, double actualCO2,
......@@ -140,6 +143,10 @@ public:
void run();
//get-functions
/// configuration info
bool hasLocationDataForNodeAt(size_t nodeIndex,
size_t locationIndex,
const string & name);
/// Results
Result * getResult();
......
......@@ -129,6 +129,11 @@ void Location::setTemperaturesForecast(const vector<vector<float> > * temps)
if (temps != nullptr) m_forecastTemperature = temps;
}
string Location::getName() const
{
return m_name;
}
double Location::getLatitude() const
{
return m_lat;
......
......@@ -49,6 +49,7 @@ public:
void setTemperaturesForecast(const vector<vector<float>> * temps);
//get functions ---------------------------------------
string getName() const;
double getLatitude() const;
double getLongitude() const;
bool hasDemandData() const;
......
......@@ -207,6 +207,16 @@ size_t Node::addLocation(Location & location)
return m_locations.size() - 1;
}
void Node::setLocation(size_t index, Location & location)
{
if (index < m_locations.size())
{
delete m_locations[index];
m_locations[index] = nullptr;
m_locations[index] = new Location(location);
}
}
void Node::setWindSpeeds(size_t index, const vector<float> * data, bool isZonal)
{
if (index < m_locations.size())
......
......@@ -68,6 +68,7 @@ public:
double reactiveDemand); //Reactive powerdemand of grid
//locations
size_t addLocation(Location & location);
void setLocation(size_t index, Location & location);
//data of network bubble (weather)
void setWindSpeeds(size_t index,
......
......@@ -1187,6 +1187,16 @@ bool CharLGui::configureAlgorithm(CharLAlgorithm * algorithm,
if (m_mapNodesLocations.contains(location))
{
locationIndex = m_mapNodesLocations.value(location).second;
if (!algorithm->hasLocationDataForNodeAt(nodeIndex, locationIndex,
location->getUniqueName().toStdString()))
{
algorithm->insertOrReplaceLocation(nodeIndex, locationIndex,
location->getUniqueName().toStdString(),
location->getLatitude(),
location->getLongitude(),
location->getAreaSolar(),
location->getAreaWind());
}
}
else
{
......
Markdown is supported
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