Node.cpp 121 KB
Newer Older
1 2
#include "Node.h"
#include "Utilities.h"
3 4 5

#include <iostream>

6
Node::Node(string name, const SimulationPreferences * preferences) :
7 8 9 10 11 12 13 14 15 16
    m_name(name),
    m_preferences(preferences),
    m_windCapacityGeneric(0.),
    m_solarCapacityGeneric(0.),
    m_installedBiomass(0.),
    m_installedConventional(0.),
    m_installedStoragePower(0.),
    m_installedStorageCapacity(0.),
    m_installedWind(0.),
    m_installedSolar(0.),
17 18 19 20
    m_installedCSP(0.),         //tb - CSP
    m_nodeType(BusType::undefined_bus_type),
    m_gridIndex(-1),
    m_voltageControlledGenerator(true)
21 22 23
{
    //create new internal result
    m_result = new InternalResult(name, m_preferences->getNumberOfTimeSteps(), m_preferences->getStepTime());
24 25 26 27 28
    //pre-assign vector-values
    m_connectedPower.assign(m_preferences->getNumberOfTimeSteps(), 0.);
    m_connectedReactivePower.assign(m_preferences->getNumberOfTimeSteps(), 0.);
    m_generatedPower.assign(m_preferences->getNumberOfTimeSteps(), 0.);
    m_generatedReactivePower.assign(m_preferences->getNumberOfTimeSteps(), 0.);
Daniela Vorwerk's avatar
Daniela Vorwerk committed
29 30 31
    m_gridDemand.assign(m_preferences->getNumberOfTimeSteps(), 0.);
    m_gridReactiveDemand.assign(m_preferences->getNumberOfTimeSteps(), 0.);
    m_voltage.assign(m_preferences->getNumberOfTimeSteps(), 0.);
32 33
}

34 35 36 37 38 39 40 41 42 43 44 45 46 47
Node::~Node()
{
    // almost nothing to do here, as the units get deleted by the internal results
    // the internal results get deleted by the Result class and the Result
    // class gets deleted by the user. The preferences are for the CharLAlgorithm to delete
    for (size_t i = m_locations.size() - 1; i < m_locations.size(); --i)
    {
        delete m_locations[i];
        m_locations[i] = nullptr;
    }
    m_locations.clear();
}

void Node::addBiomassPlant(Biomass & plant)
48 49 50 51 52 53
{
    //add biomass plant to network
    m_biomass.push_back(new Biomass(plant));
    //integrate installed biomass power
    m_installedBiomass += plant.getNominalPower();
    //calculate invest cost of biomass plant and add to result
54
    m_result->addToInvestCostOfNetworkBiomass(plant.getAnnuityCost());
55 56 57 58
    //calculate fixed operational cost of biomass plant and add to result
    m_result->addToOperationalCostOfNetworkBiomass(plant.getFixedOperationalCost());
}

59
void Node::addConventionalPlant(Conventional & plant)
60 61 62 63 64 65
{
    //add conventional plant to network
    m_conventional.push_back(new Conventional(plant));
    //integrate installed conventional power
    m_installedConventional += plant.getPower();
    //calculate invest cost of conventional plant and add to result
66
    m_result->addToInvestCostOfNetworkConventional(plant.getAnnuityCost());
67 68 69 70
    //calculate fixed operational cost of conventional plant and add to result
    m_result->addToOperationalCostOfNetworkConventional(plant.getFixedOperationalCost());
}

71
void Node::addStoragePlant(Storage & plant)
72 73 74 75 76 77 78
{
    //add storage plant to network
    m_storage.push_back(new Storage(plant));
    //integrate installed storage power
    m_installedStoragePower += plant.getNominalPower();
    m_installedStorageCapacity += plant.getStorageCapacity();
    //calculate invest cost of storage plant and add to result
79
    m_result->addToInvestCostOfNetworkStorage(plant.getAnnuityCost());
80 81 82 83
    //calculate fixed operational cost of storage plant and add to result
    m_result->addToOperationalCostOfNetworkStorage(plant.getFixedOperationalCost());
}

84
const Wind * Node::addWindPlant(Wind & turbine)
85 86 87 88 89 90
{
    //add wind park to network
    m_wind.push_back(new Wind(turbine));
    //integrate installed wind power
    m_installedWind += turbine.getInstalledPower();
    //calculate invest cost of wind park and add to result
91
    m_result->addToInvestCostOfNetworkVolatile(turbine.getAnnuityCost());
92 93
    //calculate fixed operational cost of wind park and add to result
    m_result->addToOperationalCostOfNetworkVolatile(turbine.getFixedOperationalCost());
94 95
    //return instance, so the efficinecy field can be saved to a file
    return m_wind.back();
96 97
}

98
void Node::addSolarPlant(Solar & module)
99 100 101 102 103 104
{
    //add solar park to network
    m_solar.push_back(new Solar(module));
    //integrate installed solar power
    m_installedSolar += module.getInstalledPower();
    //calculate invest cost of solar park and add to result
105
    m_result->addToInvestCostOfNetworkVolatile(module.getAnnuityCost());
106 107 108 109
    //calculate fixed operational cost of solar park and add to result
    m_result->addToOperationalCostOfNetworkVolatile(module.getFixedOperationalCost());
}

110
void Node::setGenericWindCapacity(double capacity)
111 112 113 114 115 116 117
{
    //validity control of request
    if (capacity >= 0.)
    {
        //set installed wind power
        m_windCapacityGeneric = capacity;
        //calculate invest cost of wind 'park' and add to result
118
        m_result->addToInvestCostOfNetworkVolatile(capacity * 1.6e6  * m_preferences->getAnnuityFactor(25));
119 120 121 122 123
        //calculate fixed operational cost of wind 'park' and add to result
        m_result->addToOperationalCostOfNetworkVolatile(capacity * 1.6e6 * 0.02);
    }
}

124
void Node::setGenericSolarCapacity(double capacity)
125 126 127 128 129 130 131
{
    //validity control of request
    if (capacity >= 0.)
    {
        //set installed solar power
        m_solarCapacityGeneric = capacity;
        //calculate invest cost of solar 'park' and add to result
132
        m_result->addToInvestCostOfNetworkVolatile(capacity * 1.2e6  * m_preferences->getAnnuityFactor(25));
133 134 135 136 137
        //calculate fixed operational cost of solar 'park' and add to result
        m_result->addToOperationalCostOfNetworkVolatile(capacity * 1.2e6 * 0.1);
    }
}

138
void Node::setType(BusType type)
139 140 141 142 143
{
    //simple setter
    m_nodeType = type;
}

144
void Node::setGridIndex(int index)
145 146 147 148 149
{
    //simple setter with rudimentary validity control
    if (index >= 0) m_gridIndex = index;
}

150
void Node::setConnectedPower(int timeStep, double power)
151 152 153 154 155 156 157 158
{
    //simple setter with accessibility control
    if (timeStep >= 0 && timeStep < m_connectedPower.size())
    {
        m_connectedPower[timeStep] = power;
    }
}

159
void Node::setConnectedReactivePower(int timeStep, double reactivePower)
160 161 162 163 164 165 166 167
{
    //simple setter with accessibility control
    if (timeStep >= 0 && timeStep < m_connectedReactivePower.size())
    {
        m_connectedReactivePower[timeStep] = reactivePower;
    }
}

168
void Node::setGeneratedPower(int timeStep, double power)
169 170 171 172 173 174 175 176
{
    //simple setter with accessibility control
    if (timeStep >= 0 && timeStep < m_generatedPower.size())
    {
        m_generatedPower[timeStep] = power;
    }
}

177
void Node::setGeneratedReactivePower(int timeStep, double reactivePower)
178 179 180 181 182 183 184 185
{
    //simple setter with accessibility control
    if (timeStep >= 0 && timeStep < m_generatedReactivePower.size())
    {
        m_generatedReactivePower[timeStep] = reactivePower;
    }
}

186
void Node::setGridDemand(int timeStep, double demand)
187 188 189 190 191 192 193 194
{
    //simple setter with accessibility control
    if (timeStep >= 0 && timeStep < m_gridDemand.size())
    {
        m_gridDemand[timeStep] = demand;
    }
}

195
void Node::setGridReactiveDemand(int timeStep, double reactiveDemand)
196 197 198 199 200 201 202 203
{
    //simple setter with accessibility control
    if (timeStep >= 0 && timeStep < m_gridReactiveDemand.size())
    {
        m_gridReactiveDemand[timeStep] = reactiveDemand;
    }
}

204
size_t Node::addLocation(Location & location)
205
{
206 207
    m_locations.push_back(new Location(location));
    return m_locations.size() - 1;
208 209
}

210 211 212 213 214 215 216 217 218 219
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);
    }
}

220
void Node::setWindSpeeds(size_t index, const vector<float> * data, bool isZonal)
221
{
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
    if (index < m_locations.size())
    {
        if (isZonal)
        {
            m_locations[index]->setWindSpeedsZonal(data);
        }
        else
        {
            m_locations[index]->setWindSpeedsMeridional(data);
        }
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        if (isZonal)
        {
            m_locations[0]->setWindSpeedsZonal(data);
        }
        else
        {
            m_locations[0]->setWindSpeedsMeridional(data);
        }
    }
246 247
}

248
void Node::setWindDirections(size_t index, const vector<float> * data)
249
{
250 251 252 253 254 255 256 257 258 259 260 261
    if (index < m_locations.size())
    {
        m_locations[index]->setWindDataMode(true);
        m_locations[index]->setWindSpeedsMeridional(data);
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        m_locations[0]->setWindDataMode(true);
        m_locations[0]->setWindSpeedsMeridional(data);
    }
262 263
}

264
void Node::setGHI_DHI(size_t index, const vector<float> * data)
265
{
266 267 268 269 270 271 272 273 274 275
    if (index < m_locations.size())
    {
        m_locations[index]->setGHI_DiffHI(data);
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        m_locations[0]->setGHI_DiffHI(data);
    }
276 277
}

278
void Node::setDirIrr(size_t index, const vector<float> * data)
279
{
280 281 282 283 284 285 286 287 288 289
    if (index < m_locations.size())
    {
        m_locations[index]->setDirIrr(data);
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        m_locations[0]->setDirIrr(data);
    }
290 291
}

292
void Node::setTemperatures(size_t index, const vector<float> * data)
293
{
294 295 296 297 298 299 300 301 302 303
    if (index < m_locations.size())
    {
        m_locations[index]->setTemperatures(data);
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        m_locations[0]->setTemperatures(data);
    }
304 305
}

306
void Node::setWindPercentages(const vector<float> * data)
307 308
{
    //simple setter
309
    m_windPercentages = vector<float>(*data);
310 311
}

312
void Node::setSolarPercentages(const vector<float> * data)
313 314
{
    //simple setter
315
    m_solarPercentages = vector<float>(*data);
316 317
}

318
void Node::setWindSpeedForecast(size_t index, const vector<vector<float>> * data, bool isZonal)
319
{
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
    if (index < m_locations.size())
    {
        if (isZonal)
        {
            m_locations[index]->setWindSpeedsZonalForecast(data);
        }
        else
        {
            m_locations[index]->setWindSpeedsMeridionalForecast(data);
        }
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        if (isZonal)
        {
            m_locations[0]->setWindSpeedsZonalForecast(data);
        }
        else
        {
            m_locations[0]->setWindSpeedsMeridionalForecast(data);
        }
    }
344 345
}

346
void Node::setWindDirectionForecast(size_t index, const vector<vector<float>> * data)
347
{
348 349 350 351 352 353 354 355 356 357 358 359 360
    //TODO: fitness test with previous (non-forecast data)
    if (index < m_locations.size())
    {
        m_locations[index]->setWindDataMode(true);
        m_locations[index]->setWindSpeedsMeridionalForecast(data);
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        m_locations[0]->setWindDataMode(true);
        m_locations[0]->setWindSpeedsMeridionalForecast(data);
    }
361 362
}

363
void Node::setGHI_DHI_Forecast(size_t index, const vector<vector<float>> * data)
364
{
365 366 367 368 369 370 371 372 373 374
    if (index < m_locations.size())
    {
        m_locations[index]->setGHI_DiffHIForecast(data);
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        m_locations[0]->setGHI_DiffHIForecast(data);
    }
375 376
}

377
void Node::setDirIrrForecast(size_t index, const vector<vector<float>> * data)
378
{
379 380 381 382 383 384 385 386 387 388 389 390
    if (index < m_locations.size())
    {
        m_locations[index]->setDirIrrForecast(data);
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        m_locations[0]->setDirIrrForecast(data);
    }
}

391
void Node::setTemperatureForecast(size_t index, const vector<vector<float>> * data)
392 393 394 395 396 397 398 399 400 401 402
{
    if (index < m_locations.size())
    {
        m_locations[index]->setTemperaturesForecast(data);
    }
    else if (m_locations.size() == 0)
    {
        m_locations.push_back(new Location("dummy", 0., 0., 0., 0., m_preferences));
        cout << "[Warning!] Needed to create dummy location!" << endl;
        m_locations[0]->setTemperaturesForecast(data);
    }
403 404
}

405
void Node::setWindPercentageForecast(const vector<vector<float>> * data)
406 407
{
    //simple setter
408
    m_forecastWindPercentages = vector<vector<float>>(*data);
409 410
}

411
void Node::setSolarPercentageForecast(const vector<vector<float>> * data)
412 413
{
    //simple setter
414
    m_forecastSolarPercentages = vector<vector<float>>(*data);
415 416
}

417
void Node::setForecastConventionalLoad(int index, int timeStep, double load)
418
{
Daniela Vorwerk's avatar
Daniela Vorwerk committed
419
    if (index >= 0 && index < m_conventional.size() && timeStep >= 0 && timeStep < m_preferences->getNumberOfTimeSteps())
420 421 422 423 424
    {
        m_conventional[index]->setForecastLoad(timeStep, load);
    }
}

425
void Node::setForecastStorageLoad(int index, int timeStep, double load)
426 427 428 429 430 431 432
{
    if (index >= 0 && index < m_storage.size())
    {
        m_storage[index]->setForecastLoad(timeStep, load);
    }
}

433
void Node::setForecastStorageLevel(int index, int timeStep, double load)
434 435 436 437 438 439 440
{
    if (index >= 0 && index < m_storage.size())
    {
        m_storage[index]->setForecastLevel(timeStep, load);
    }
}

441
void Node::setStorageDischargeEmissionStartup(int index, int timeStep, double data)
442
{
443 444 445 446 447 448
    if (index >= 0 && index < m_storage.size())
    {
        m_storage[index]->setDischargeEmissionStartup(timeStep, data);
    }
}

449
void Node::setStorageDischargeCostStartup(int index, int timeStep, double data)
450 451 452 453 454 455 456
{
    if (index >= 0 && index < m_storage.size())
    {
        m_storage[index]->setDischargeCostStartup(timeStep, data);
    }
}

457
void Node::setForecastStatistics(double objectiveOptimum, double objectiveReached, double relativeGap, double emissionFactorPenalty, double runTimeOptimizer)
458 459 460
{
    m_bestBound = objectiveOptimum;
    m_objective = objectiveReached;
461
    m_relativeGap = relativeGap;
462
    m_emissionFactorPenalty = emissionFactorPenalty;
463 464 465
    m_runTimeOptimizer = runTimeOptimizer;
}

466
void Node::setInitialStorageLevel(int index, double level)
467 468 469
{
    if (index >= 0 && index < m_storage.size())
    {
470 471 472 473
		m_storage[index]->setInitialStorageLevel(level);
    }
}

474
void Node::setStorageLevel(int time)
475 476 477 478 479
{
    //Every storage
    for (int i = 0; i < m_storage.size(); i++)
    {
        m_storage[i]->setStorageLevel(time, m_storage[i]->getForecastLevel(time));
480 481 482
    }
}

483
void Node::setPowerDemand(const vector<float> * data)
484 485
{
    //simple setter
486
    m_powerDemand = vector<float>(*data);
487 488
}

489
/*void Node::setReactiveDemand(vector<float> & data) //dv
Daniela Vorwerk's avatar
Daniela Vorwerk committed
490 491 492 493 494
{
    //simple setter
    m_reactivePowerDemand = data;
}*/

495
void Node::setVoltage(int timeStep, double voltage) //dv
Daniela Vorwerk's avatar
Daniela Vorwerk committed
496 497 498 499 500 501 502 503 504 505 506
{
    if (timeStep == 0 && m_voltage.size() == 0)
    {
        m_voltage.assign(m_preferences->getNumberOfTimeSteps(), 0.);
    }
    if (timeStep >= 0 && timeStep < m_voltage.size())
    {
        m_voltage[timeStep] = voltage;
    }
}

507
void Node::setPowerDemandForecast(const vector<vector<float>> * data)
508 509
{
    //simple setter
510
    m_powerDemandForecast = vector<vector<float>>(*data);
511 512
}

513
void Node::setReactivePowerDemand(vector<float> & data) //dv: Standard demand
514 515 516 517 518
{
    //simple setter
    m_reactivePowerDemand = data;
}

Daniela Vorwerk's avatar
Daniela Vorwerk committed
519

520
void Node::setPowerDemandResult(int timeStep, double demand)
Daniela Vorwerk's avatar
Daniela Vorwerk committed
521 522 523 524 525 526
{
    if (timeStep >= 0 && timeStep < m_preferences->getNumberOfTimeSteps())
    {
            m_result->setPowerDemandAtTime(timeStep, demand);
    }
}
527
void Node::setGridDemandResult(int timeStep, double demand)
528 529 530 531 532 533 534
{
    if (timeStep >= 0 && timeStep < m_preferences->getNumberOfTimeSteps())
    {
        m_result->setGridDemandAtTime(timeStep, demand);
    }
}

Daniela Vorwerk's avatar
Daniela Vorwerk committed
535

536
void Node::setGridReactiveDemandResult(int timeStep, double reactiveDemand) //dv
Daniela Vorwerk's avatar
Daniela Vorwerk committed
537 538 539 540 541 542 543
{
    if (timeStep >= 0 && timeStep < m_preferences->getNumberOfTimeSteps())
    {
        m_result->setGridReactiveDemandAtTime(timeStep, reactiveDemand);
    }
}

544
void Node::setReactivePowerDemandResult(int timeStep, double reactiveDemandExtern)
Daniela Vorwerk's avatar
Daniela Vorwerk committed
545 546 547 548 549 550
{
    if (timeStep >= 0 && timeStep < m_preferences->getNumberOfTimeSteps())
    {
        m_result->setReactivePowerDemandAtTime(timeStep, reactiveDemandExtern);
    }
}
551
void Node::setStoragePlannedDemand(int timeStep, double demand)
552 553 554 555 556 557 558
{
    if (timeStep == 0 && m_storageDemand.size() == 0)
    {
        m_storageDemand.assign(m_preferences->getNumberOfTimeSteps(), 0.);
    }
    if (timeStep >= 0 && timeStep < m_storageDemand.size())
    {
Daniela Vorwerk's avatar
Daniela Vorwerk committed
559
        m_storageDemand[timeStep] = demand;
560 561 562
    }
}

563
double Node::getInstalledBiomass() const
564 565 566 567 568
{
    //simple getter
    return m_installedBiomass;
}

569
double Node::getInstalledConventional() const
570 571 572 573 574
{
    //simple getter
    return m_installedConventional;
}

575
double Node::getInstalledStoragePower() const
576 577 578 579 580
{
    //simple getter
    return m_installedStoragePower;
}

581
double Node::getInstalledStorageCapacity() const
582 583 584 585 586
{
    //simple getter
    return m_installedStorageCapacity;
}

587
double Node::getInstalledWind() const
588 589 590 591 592 593 594 595 596
{
    //getter with distinction which value to return
    if (m_windCapacityGeneric > 0.) //if non-weather data was used
    {
        return m_windCapacityGeneric;
    }
    return m_installedWind;
}

597
double Node::getInstalledSolar() const
598 599 600 601 602 603 604 605 606
{
    //getter with distinction which value to return
    if (m_solarCapacityGeneric > 0.) //if non-weather data was used
    {
        return m_solarCapacityGeneric;
    }
    return m_installedSolar;
}

607
double Node::getInstalledCSP() const
608 609 610 611
{
    return m_installedCSP;
}

612
double Node::getVoltage(int timeStep) const
Daniela Vorwerk's avatar
Daniela Vorwerk committed
613 614 615 616 617
{
    return m_voltage[timeStep];
}


618
BusType Node::getType() const
619 620 621 622 623
{
    //simple getter
    return m_nodeType;
}

624
int Node::getGridIndex() const
625 626 627 628 629
{
    //simple getter
    return m_gridIndex;
}

630
double Node::getConnectedPowerAtStep(int timeStep) const
631 632 633 634 635 636 637 638 639
{
    //simple getter with accessibility conrtol
    if (timeStep >= 0 && timeStep < m_connectedPower.size())
    {
        return m_connectedPower[timeStep];
    }
    return 0.;
}

640
double Node::getConnectedReactivePowerAtStep(int timeStep) const
641 642 643 644 645 646 647 648 649
{
    //simple getter with accessibility conrtol
    if (timeStep >= 0 && timeStep < m_connectedReactivePower.size())
    {
        return m_connectedReactivePower[timeStep];
    }
    return 0.;
}

650
double Node::getGeneratedPowerAtStep(int timeStep) const
651 652 653 654 655 656 657 658 659
{
    //simple getter with accessibility conrtol
    if (timeStep >= 0 && timeStep < m_generatedPower.size())
    {
        return m_generatedPower[timeStep];
    }
    return 0.;
}

660
double Node::getGeneratedReactivePowerAtStep(int timeStep) const
661 662 663 664 665 666 667 668 669
{
    //simple getter with accessibility conrtol
    if (timeStep >= 0 && timeStep < m_generatedReactivePower.size())
    {
        return m_generatedReactivePower[timeStep];
    }
    return 0.;
}

670
bool Node::isGenerationVoltageControlled() const
671 672 673 674 675
{
    //simple getter
    return m_voltageControlledGenerator;
}

676
double Node::getGridDemandAtStep(int timeStep) const
677 678 679 680 681 682 683 684 685
{
    //simple getter with accessibility conrtol
    if (timeStep >= 0 && timeStep < m_gridDemand.size())
    {
        return m_gridDemand[timeStep];
    }
    return 0.;
}

686
double Node::getGridReactiveDemandAtStep(int timeStep) const
687 688 689 690 691 692 693 694 695
{
    //simple getter with accessibility conrtol
    if (timeStep >= 0 && timeStep < m_gridReactiveDemand.size())
    {
        return m_gridReactiveDemand[timeStep];
    }
    return 0.;
}

Daniela Vorwerk's avatar
Daniela Vorwerk committed
696

697
InternalResult * Node::getResult()
698 699 700 701 702 703 704
{
    //make config part of result
    transferConfigToResult();
    //return result
    return m_result;
}

705
vector<double> Node::getVolatilePowerForecast(int nPointsIntervall, int timeStep, int forecastStep)
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
{
    vector<double> targetVector;
    double combinedPower = 0.;
    if (m_preferences->getForecastType() == SimulationPreferences::ForecastDataType::Perfect)
    {
        double maxPowerCharge = 0.;
        for (int i = 0; i < m_storage.size(); i++)
        {
            maxPowerCharge += m_storage[i]->getMaxPowerChargeConst();
        }
        for (int i = timeStep; i < std::min(timeStep + nPointsIntervall, m_preferences->getNumberOfTimeSteps()); i++)
        {
            combinedPower = 0.;
            if (m_windSpeeds.size() > 0)             //use weather data
            {
                //TODO: create curve from weather data
            }
            else if (m_windPercentages.size() > 0)  //use scaled data
            {
                combinedPower += m_windCapacityGeneric * m_windPercentages[i];
            }
            //+++ SOLAR +++++++++++++++++++++++++++++++++++
            //choose way to calculate solar power from data
            if (m_ghi_dhi.size() > 0)               //use weather data
            {
                //result value (sum over partial results)
                double solarLoad = 0.;
                //helper values to correctly determine angles
                int dayOfYear = int(i * m_preferences->getStepTime() / 24.);
                int dayTimeInSeconds = int(i * m_preferences->getStepTime() - dayOfYear * 24.) * 3600;
                if (m_dni.size() > 0)   //use DNI and DHI
                {
                    //cummulate power for every "Solar" instance
739
                    for (auto park : m_solar)
740
                    {
741
                        //solarLoad += park->getPower(i, false, m_temperatures[i], m_windSpeeds[i], -1., m_dni[i], m_ghi_dhi[i]);
742 743 744 745 746 747 748 749 750
                    }
                    //add cummulated power to result
                    combinedPower += solarLoad;
                }
                else                    //use GHI
                {
                    //cummulate power for every "Solar" instance
                    for (int j = 0; j < m_solar.size(); j++)
                    {
751
                        //solarLoad += m_solar[j]->getPower(i, false, m_temperatures[i], m_windSpeeds[i], dayTimeInSeconds, dayOfYear, m_ghi_dhi[i]);
752 753 754 755 756 757 758 759 760
                    }
                    //add cummulated power to result
                    combinedPower += solarLoad;
                }
            }
            else if (m_solarPercentages.size() > 0) //use scaled data
            {
                combinedPower += m_solarCapacityGeneric * m_solarPercentages[i];
            }
761
            targetVector.push_back(std::min(combinedPower, getPowerDemandAtStep(timeStep) + maxPowerCharge));
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
        }
    }
    else if (m_preferences->getForecastType() == SimulationPreferences::ForecastDataType::Stepwise)
    {
        double maxPowerCharge = 0.;
        for (int i = 0; i < m_storage.size(); i++)
        {
            maxPowerCharge += m_storage[i]->getMaxPowerChargeConst();
        }
        for (int i = timeStep; i < std::min(timeStep + nPointsIntervall, m_preferences->getNumberOfTimeSteps()); i++)
        {
            combinedPower = 0.;
            if (m_windSpeeds.size() > 0)             //use weather data
            {
                //TODO: create curve from weather data
            }
            else if (m_windPercentages.size() > 0)  //use scaled data
            {
                combinedPower += m_windCapacityGeneric * m_forecastWindPercentages[0][i];
            }
            //+++ SOLAR +++++++++++++++++++++++++++++++++++
            //choose way to calculate solar power from data
            if (m_ghi_dhi.size() > 0)               //use weather data
            {
                //result value (sum over partial results)
                double solarLoad = 0.;
                //helper values to correctly determine angles
                int dayOfYear = int(i * m_preferences->getStepTime() / 24.);
                int dayTimeInSeconds = int(i * m_preferences->getStepTime() - dayOfYear * 24.) * 3600;
                if (m_dni.size() > 0)   //use DNI and DHI
                {
                    //cummulate power for every "Solar" instance
                    for (int j = 0; j < m_solar.size(); j++)
                    {
796
                        //solarLoad += m_solar[j]->getPower(i, true, m_forecastTemperature[0][i], m_forecastWindSpeeds[0][i], -1., m_forecastDNI[0][i], m_forecastGHI_DHI[0][i]);
797 798 799 800 801 802 803 804 805
                    }
                    //add cummulated power to result
                    combinedPower += solarLoad;
                }
                else                    //use GHI
                {
                    //cummulate power for every "Solar" instance
                    for (int j = 0; j < m_solar.size(); j++)
                    {
806
                        //solarLoad += m_solar[j]->getPower(i, true, m_forecastTemperature[0][i], m_forecastWindSpeeds[0][i], dayTimeInSeconds, dayOfYear, m_forecastGHI_DHI[0][i]);
807 808 809 810 811 812 813 814 815
                    }
                    //add cummulated power to result
                    combinedPower += solarLoad;
                }
            }
            else if (m_solarPercentages.size() > 0) //use scaled data
            {
                combinedPower += m_solarCapacityGeneric * m_forecastSolarPercentages[0][i];
            }
816
            targetVector.push_back(std::min(combinedPower, getPowerDemandAtStep(timeStep) + maxPowerCharge));
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
        }
    }
    else if (m_preferences->getForecastType() == SimulationPreferences::ForecastDataType::Periodwise)
    {
        double maxPowerCharge = 0.;
        for (int i = 0; i < m_storage.size(); i++)
        {
            maxPowerCharge += m_storage[i]->getMaxPowerChargeConst();
        }
        for (int i = 0; i < nPointsIntervall; i++)
        {
            combinedPower = 0.;
            if (m_windSpeeds.size() > 0)             //use weather data
            {
                //TODO: create curve from weather data
            }
            else if (m_windPercentages.size() > 0)  //use scaled data
            {
                combinedPower += m_windCapacityGeneric * m_forecastWindPercentages[forecastStep][i];
            }
            //+++ SOLAR +++++++++++++++++++++++++++++++++++
            //choose way to calculate solar power from data
            if (m_ghi_dhi.size() > 0)               //use weather data
            {
                //result value (sum over partial results)
                double solarLoad = 0.;
                //helper values to correctly determine angles
                int dayOfYear = int(forecastStep * m_preferences->getNumberOfStepsForeCastPeriod() * m_preferences->getStepTime() / 24.);
                int dayTimeInSeconds = int(forecastStep * m_preferences->getNumberOfStepsForeCastPeriod() * m_preferences->getStepTime() - dayOfYear * 24.) * 3600;
                if (m_dni.size() > 0)   //use DNI and DHI
                {
                    //cummulate power for every "Solar" instance
                    for (int j = 0; j < m_solar.size(); j++)
                    {
851
                        //solarLoad += m_solar[j]->getPower(i, true, m_forecastTemperature[forecastStep][i], m_forecastWindSpeeds[forecastStep][i], -1., m_forecastDNI[forecastStep][i], m_forecastGHI_DHI[forecastStep][i]);
852 853 854 855 856 857 858 859 860
                    }
                    //add cummulated power to result
                    combinedPower += solarLoad;
                }
                else                    //use GHI
                {
                    //cummulate power for every "Solar" instance
                    for (int j = 0; j < m_solar.size(); j++)
                    {
861
                        //solarLoad += m_solar[j]->getPower(i, true, m_forecastTemperature[forecastStep][i], m_forecastWindSpeeds[forecastStep][i], dayTimeInSeconds, dayOfYear, m_forecastGHI_DHI[forecastStep][i]);
862 863 864 865 866 867 868 869 870
                    }
                    //add cummulated power to result
                    combinedPower += solarLoad;
                }
            }
            else if (m_solarPercentages.size() > 0) //use scaled data
            {
                combinedPower += m_solarCapacityGeneric * m_forecastSolarPercentages[forecastStep][i];
            }
871
            targetVector.push_back(std::min(combinedPower, getPowerDemandAtStep(timeStep) + maxPowerCharge));
872 873 874 875 876 877
        }
    }
    return targetVector;
}


878
vector<float> Node::getPowerDemand() const
879 880 881 882 883
{
    //tz - simple getter
    return m_powerDemand;
}

884
vector<float> Node::getReactivePowerDemand() const //dv
885 886
{
    //tz - simple getter
887
    return m_reactivePowerDemand;
888 889
}

890

891
int Node::getNumberOfConventionals() const
892
{
893 894
                        
    return (int)m_conventional.size();
895 896
}

897

898
int Node::getNumberOfStorages() const
899 900 901 902
{
    //simple getter
    return (int)m_storage.size();
}
903
  
904

905
Conventional * Node::getConventional(int index) const
906
{
907 908 909 910 911 912
    //simple getter with safety
    if (index >= 0 && index < m_conventional.size())
    {
        return m_conventional[index];
    }
    return nullptr;
913 914
}

915
Storage * Node::getStorage(int index) const
916 917 918 919 920 921 922 923 924
{
    //simple getter with safety
    if (index >= 0 && index < m_storage.size())
    {
        return m_storage[index];
    }
    return nullptr;
}

925
const Location * Node::getLocationPtr(size_t index) const
926 927 928 929 930 931 932 933
{
    if (index < m_locations.size())
    {
        return m_locations[index];
    }
    return nullptr;
}

934
const SimulationPreferences * Node::getSimulationPreferences() const
935 936 937 938 939
{
    //tz - simple getter
    return m_preferences;
}

940
double Node::getPowerDemandAtStep(size_t timeStep) const
941
{
942
    if (m_locations.size() > 0 && m_locations.front()->hasDemandData())
943
    {
944 945 946 947 948 949 950 951 952 953
        double demand = 0.;
        for (auto location : m_locations)
        {
            demand += location->getPowerDemand(timeStep);
        }
        return demand;
    }
    else if (timeStep < m_powerDemand.size())
    {
        return static_cast<double>(m_powerDemand[timeStep]);
954 955 956 957
    }
    return 0.;
}

958
double Node::getReactivePowerDemandAtStep(size_t timeStep) const //dv
959
{
960
    if (m_locations.size() > 0 && m_locations.front()->hasDemandData())
961
    {
962 963 964 965 966 967 968 969 970 971
        double demand = 0.;
        for (auto location : m_locations)
        {
            demand += location->getReactivePowerDemand(timeStep);
        }
        return demand;
    }
    else if (timeStep < m_reactivePowerDemand.size())
    {
        return static_cast<double>(m_reactivePowerDemand[timeStep]);
972 973 974 975
    }
    return 0.;
}

976
double Node::getVolatilePowerOfStep(int timeStep) const
977 978 979 980 981 982 983 984
{
    if (timeStep >= 0 && timeStep < m_preferences->getNumberOfTimeSteps())
    {
        return m_result->getWindLoad(timeStep) + m_result->getSolarLoad(timeStep) + m_result->getCSPload(timeStep);
    }
    return 0.;
}

985
void Node::calculateVolatilePower(size_t timeStep)
986
{
987
    //+++ SOLAR -----------------------------------------------------------------------------------
988
    //choose way to calculate solar power from data
989
    if (m_solar.size() > 0)               //use weather data
990 991 992
    {
        //result value (sum over partial results)
        double solarLoad = 0.;
993 994
        //cumulate power for every "Solar" instance
        for (auto plant : m_solar)
995
        {
996
            solarLoad += plant->getPower(timeStep);
997
        }
998 999
        //add cumulated power to result
        m_result->setSolarLoad(timeStep, solarLoad);
1000 1001 1002
    }
    else if (m_solarPercentages.size() > 0) //use scaled data
    {
1003
        m_result->setSolarLoad(timeStep,
1004 1005
                               m_solarCapacityGeneric
                               * static_cast<double>(m_solarPercentages[timeStep]));
1006 1007 1008
    }
    else                                    //no data at all
    {
1009
        m_result->setSolarLoad(timeStep, 0.);
1010
    }
1011 1012
    //+++ WIND ------------------------------------------------------------------------------------
    //choose way to calculate wind power from data
1013
    if (m_wind.size() > 0)             //use weather data
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
    {
        double windLoad = 0.;
        for (size_t i = 0; i < m_wind.size(); i++)
        {
            windLoad += m_wind[i]->getPower(timeStep);
        }
        m_result->setWindLoad(timeStep, windLoad);
    }
    else if (m_windPercentages.size() > 0)  //use scaled data
    {
        m_result->setWindLoad(timeStep,
                              m_windCapacityGeneric
                              * static_cast<double>(m_windPercentages[timeStep]));
    }
    else                                    //no data at all
    {
        m_result->setWindLoad(timeStep, 0.);
    }
1032 1033 1034
}


1035
void Node::calculateStoragePower(size_t timeStep)
1036 1037
{

Daniela Vorwerk's avatar
Daniela Vorwerk committed
1038 1039 1040
        //result value
        double storageLoad = 0.;
        //current residual or surplus power
1041
        double currentResidual = this->getPowerDemandAtStep(timeStep)
1042 1043 1044
                                 - m_result->getWindLoad(timeStep)
                                 - m_result->getSolarLoad(timeStep)
                                 - m_result->getCSPload(timeStep); //tc - CSP
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1045
        double powerOfPlant = 0.;
1046
        for (size_t i = 0; i < m_storage.size() && fabs(currentResidual) > 0.; i++)
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1047
        {
1048
            if (currentResidual < 0. && m_storage[i]->isReadyToCharge(timeStep)) // charge
1049 1050
            {
                //power well within range
1051 1052 1053
                if (fabs(currentResidual) >= m_storage[i]->getMinPowerChargeConst()
                    && fabs(currentResidual) < m_storage[i]->getMaxPowerCharge(timeStep)
                    && currentResidual < 0.)  //tz >= minPower -> otherwise no minPower
1054
                {
1055 1056
                    powerOfPlant = currentResidual;
                    m_storage[i]->charge(fabs(powerOfPlant), timeStep);
1057
                    storageLoad += powerOfPlant;
1058
                    currentResidual = 0.;
1059 1060
                }
                //power equal or greater than maxPower
1061 1062
                else if (fabs(currentResidual) >= m_storage[i]->getMinPowerChargeConst()
                         && m_storage[i]->getMinPowerChargeConst() <= m_storage[i]->getMaxPowerCharge(timeStep))
1063
                {
1064 1065
                    powerOfPlant = -(m_storage[i]->getMaxPowerCharge(timeStep));
                    m_storage[i]->charge(fabs(powerOfPlant), timeStep);
1066
                    storageLoad += powerOfPlant;
1067 1068
                    currentResidual -= powerOfPlant;
                    if (isCloseEnoughToEqual(currentResidual, 0.)) currentResidual = 0.;
1069
                }
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1070
                else    //power less than minimum
1071
                {
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1072 1073 1074
                    storageLoad += 0.;
                }
            }
1075
            else if (currentResidual > 0. && m_storage[i]->canStartDischgargingAtStep(timeStep))        // discharge
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1076 1077 1078
            {
                //tz - no valid operation plan for timestep: don't unload further than targetcurve
                double targetStorageLevel = 0.;
1079
                if (m_preferences->createOperationPlan())
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1080
                {
1081 1082
                    int period = timeStep % m_preferences->getNumberOfStepsForeCastPeriod() + 2;
                    targetStorageLevel = m_preferences->getSupposedStorageLevelAtPeriodEnd(period);
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1083 1084 1085 1086 1087
                    //tz - +1 for first time step & +1 for next period
                }

                //tz - no dicharge when current Level is below target Level
                if(m_preferences->createOperationPlan()
1088 1089 1090
                   && timeStep != 0
                   && m_storage[i]->isLongTermStorage()
                   && m_storage[i]->getStorageLevelAtTimeStep(timeStep - 1) < m_storage[i]->getStorageCapacity() * targetStorageLevel)
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1091 1092 1093 1094 1095 1096
                {
                    storageLoad += 0;
                }
                else    //tz - do as before
                {
                    //power well within range
1097 1098 1099
                    if (currentResidual >= m_storage[i]->getMinPowerDischarge(timeStep)
                        && currentResidual < m_storage[i]->getMaxPowerDischarge(timeStep)
                        && currentResidual > 0.)
1100
                    {
1101 1102
                        powerOfPlant = currentResidual;
                        m_storage[i]->discharge(powerOfPlant, timeStep);
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1103
                        storageLoad += powerOfPlant;
1104
                        currentResidual = 0.;
1105
                    }
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1106
                    //power equal or greater than maxPower
1107 1108 1109
                    else if (currentResidual >= m_storage[i]->getMaxPowerDischarge(timeStep)
                             && m_storage[i]->getMaxPowerDischarge(timeStep) > 0.
                             && currentResidual > 0.)
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1110
                    {
1111 1112
                        powerOfPlant = m_storage[i]->getMaxPowerDischarge(timeStep);
                        m_storage[i]->discharge(powerOfPlant, timeStep);
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1113
                        storageLoad += powerOfPlant;
1114 1115
                        currentResidual -= powerOfPlant;
                        if (isCloseEnoughToEqual(currentResidual, 0.)) currentResidual = 0.;
Daniela Vorwerk's avatar
Daniela Vorwerk committed
1116
                    }