Skip to content

Commit

Permalink
fix energy consumption addition bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedAredah committed Apr 8, 2023
1 parent bb8faa7 commit 2e5c2d4
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/TrainDefintion/Car.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ std::pair<bool, double> Car::consumeFuel(double timeStep, double trainSpeed,
// clear the variables for reassignning
this->energyConsumed = 0.0; // the step energy consumption of 1 tech
this->energyRegenerated = 0.0; // the step energy regeneration of 1 tech
this->cumEnergyConsumed = 0.0; // the step energy consumption of multiple technologies (e.g hybrid)
this->cumEnergyRegenerated = 0.0; // the step energy regeneration of multiple technologies (e.g hybrid)

// check if the energy consumption (in kWH) is energy consumption not regenerated energy
if (EC_kwh > 0.0) {
Expand Down
39 changes: 38 additions & 1 deletion src/TrainDefintion/Train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ double Train::getMinFollowingTrainGap() {
return DefaultMinFollowingGap;
}

double Train::getBatteryEnergyConsumed() {
double total = 0.0;
for (auto &vehicle:this->trainVehicles) {
total += vehicle->getBatteryCumEnergyConsumption();
}
return total;
}

double Train::getBatteryEnergyRegenerated() {
double total = 0.0;
for (auto &vehicle:this->trainVehicles) {
total += vehicle->getBatteryCumEnergyRegenerated();
}
return total;
}

double Train::getBatteryNetEnergyConsumed() {
double total = 0.0;
for (auto &vehicle:this->trainVehicles) {
total += vehicle->getBatteryCumNetEnergyConsumption();
}
return total;
}

double Train::getAverageLocomotivesBatteryStatus() {
double sum = 0;
for (auto& loco : this->locomotives) {
Expand Down Expand Up @@ -152,7 +176,7 @@ double Train::getTrainTotalTorque() {
double Train::getTrainConsumedTank() {
double consumption = 0.0;
for (auto &loco: this->locomotives) {
consumption += loco->getTankInitialCapacity() - loco->getTankCurrentCapacity();
consumption += loco->getTankCumConsumedFuel();
}
return consumption;
}
Expand Down Expand Up @@ -210,6 +234,19 @@ Map<TrainTypes::PowerType, int> Train::LocTypeCount() {
return typesCount;
}

Map<TrainTypes::CarType, int> Train::carTypeCount() {
Map<TrainTypes::CarType, int> typesCount;
for (auto& car : this->cars) {
if (typesCount.count(car->carType) > 0) {
typesCount[car->carType] += 1;
}
else {
typesCount[car->carType] = 1;
}
}
return typesCount;
}

void Train::rearrangeTrain() {
this->trainVehicles.clear();
int size = this->nlocs + this->nCars;
Expand Down
43 changes: 43 additions & 0 deletions src/TrainDefintion/Train.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ class Train {
*/
Map<TrainTypes::PowerType, int> LocTypeCount();

/**
* @brief car type count
*
* @author Ahmed Aredah
* @date 4/6/2023
*
* @returns A Map&lt;TrainTypes::CarTypes,int&gt;
*/
Map<TrainTypes::CarType, int> carTypeCount();
/**
* \brief This function returns the centroids of all vehicles in the train
*
Expand All @@ -348,6 +357,40 @@ class Train {
*/
int getActiveLocomotivesNumber();

/**
* @brief Gets the battery energy consumed in kWh.
*
* @details Gets the battery energy consumed only.
* it does not report the energy regenerated.
*
* @author Ahmed Aredah
* @date 2/28/2023
*
* @return the energy consumed in kWh.
*/
double getBatteryEnergyConsumed();
/**
* @brief Gets the battery energy regenerated in kWh.
*
* @author Ahmed Aredah
* @date 2/28/2023
*
* @return the energy regenerated in kWh.
*/
double getBatteryEnergyRegenerated();

/**
* @brief Gets the battery energy consumed in kWh.
*
* @details Gets the battery energy consumed and regenerated.
*
* @author Ahmed Aredah
* @date 2/28/2023
*
* @return the energy consumed in kWh.
*/
double getBatteryNetEnergyConsumed();

/**
* \brief Gets average locomotives battery status
*
Expand Down
2 changes: 2 additions & 0 deletions src/TrainDefintion/TrainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void TrainComponent::resetTimeStepConsumptions() {
// reset the energy consumption for the time step.
this->energyConsumed = 0.0;
this->energyRegenerated = 0.0;
this->cumEnergyConsumed = 0.0; // the step energy consumption of multiple technologies (e.g hybrid)
this->cumEnergyRegenerated = 0.0; // the step energy regeneration of multiple technologies (e.g hybrid)
}

void TrainComponent::setCurrentWeight(double newCurrentWeight) {
Expand Down

0 comments on commit 2e5c2d4

Please sign in to comment.