NeTrainSim 0.1.1 beta
The Open-Source Network Trains Simulator
 
Loading...
Searching...
No Matches
Car Class Reference

A rail car. More...

#include <car.h>

Inheritance diagram for Car:
TrainComponent Battery Tank

Public Member Functions

 Car (double carLength_m, double carDragCoef, double carFrontalArea_sqm, double carEmptyWeight_t, double carCurrentWeight_t, int carNoOfAxles, int carType, double auxiliaryPower_kw=EC::DefaultCarAuxiliaryPower, double batteryMaxCapacity_kWh=EC::DefaultCarBatteryMaxCapacity, double batteryInitialCharge_perc=EC::DefaultCarBatteryInitialCharge, double tenderMaxCapacity_kg_l=EC::DefaultCarTenderMaxCapacity, double tenderInitialCapacity_perc=EC::DefaultCarTenderInitialCapacity, std::string carName=DefaultCarName)
 Constructor.
 
double getCargoNetWeight ()
 Gets the cargo net weight.
 
void setCarCurrentWeight (double newCurrentWeight)
 Sets the car's current weight.
 
double getResistance (double trainSpeed) override
 Gets the resistance contributed by this car to the whole train.
 
double getEnergyConsumption (double &timeStep)
 Gets the energy consumption of the car (in case there is auxiliary power).
 
std::pair< bool, double > consumeFuel (double timeStep, double trainSpeed, double EC_kwh, double carVirtualTractivePower=std::numeric_limits< double >::quiet_NaN(), double dieselConversionFactor=EC::DefaultDieselConversionFactor, double biodieselConversionFactor=EC::DefaultBiodieselConversionFactor, double hydrogenConversionFactor=EC::DefaultHydrogenConversionFactor, double dieselDensity=EC::DefaultDieselDensity, double biodieselDensity=EC::DefaultBioDieselDensity, double hydrogenDensity=EC::DefaultHydrogenDensity) override
 Consumes fuel from the tender.
 
double getMaxProvidedEnergy (double &timeStep)
 Gets the maximum energy provided by the car.
 
bool canProvideEnergy (double &EC, double &timeStep)
 Checks if the car can provide energy.
 
- Public Member Functions inherited from TrainComponent
virtual double getResistance (double trainSpeed)
 Gets the resistance applied on only this vehicle.
 
virtual void resetTimeStepConsumptions ()
 Resets the energy consumptions data for the current time step.
 
virtual void setCurrentWeight (double newCurrentWeight)
 sets the current weight of the vehicle
 
virtual std::pair< bool, double > consumeFuelDiesel (double EC_kwh, double dieselConversionFactor, double dieselDensity)
 consume the locomotive diesel fuel.
 
virtual std::pair< bool, double > consumeFuelBioDiesel (double EC_kwh, double bioDieselConversionFactor, double bioDieselDensity)
 consume the locomotive bio diesel fuel.
 
virtual std::pair< bool, double > consumeElectricity (double timeStep, double EC_kwh)
 consume any source of electricity in the locomotive; either the catenary or the batteries.
 
virtual std::pair< bool, double > consumeFuelHydrogen (double EC_kwh, double hydrogenConversionFactor, double hydrogenDensity)
 consume the locomotive hydrogen fuel.
 
virtual double refillBattery (double timeStep, double EC_kwh)
 refill the locomtoive battery
 
virtual bool rechargeCatenary (double EC_kwh)
 Rechage catenary and grid system if they are available.
 
virtual std::pair< bool, double > consumeFuel (double timeStep, double trainSpeed, double EC_kwh, double LocomotiveVirtualTractivePower=std::numeric_limits< double >::quiet_NaN(), double dieselConversionFactor=EC::DefaultDieselConversionFactor, double biodieselConversionFactor=EC::DefaultBiodieselConversionFactor, double hydrogenConversionFactor=EC::DefaultHydrogenConversionFactor, double dieselDensity=EC::DefaultDieselDensity, double biodieselDensity=EC::DefaultBioDieselDensity, double hydrogenDensity=EC::DefaultHydrogenDensity)
 Consume fuel or battery from the vehicle.
 
- Public Member Functions inherited from Battery
void setBattery (double maxCharge, double initialChargePercentage, double depthOfDischarge, double batteryCRate, double maxRechargeSOC=0.9, double minRechargeSOC=0.5)
 Sets the battery properties.
 
double getBatteryMaxCharge () const
 Gets the maximum charge of the battery.
 
void setBatteryMaxCharge (double newMaxCharge)
 Sets the maximum charge of the battery.
 
double getBatteryInitialCharge () const
 Gets the initial charge of the battery.
 
void setBatteryInitialCharge (double newInitialCharge)
 Sets the initial charge of the battery.
 
double getBatteryCurrentCharge () const
 Gets the current charge of the battery.
 
std::pair< bool, double > consumeBattery (double timeStep, double consumedCharge)
 Consumes charge from the battery.
 
double rechargeBatteryForHybrids (double timeStep, double recharge)
 Recharges the battery for hybrid vehicles.
 
double rechargeBatteryByRegeneratedEnergy (double timeStep, double recharge)
 Recharges the battery by regenerated energy.
 
double getBatteryStateOfCharge () const
 Gets the state of charge of the battery.
 
double getBatteryDOD () const
 Gets the depth of discharge of the battery.
 
void setBatteryDOD (double newBatteryDOD)
 Sets the depth of discharge of the battery.
 
double getBatteryCRate () const
 Gets the C-Rate of discharge for the battery.
 
void setBatteryCRate (double newBatteryCRate)
 Sets the C-Rate of discharge for the battery.
 
bool isBatteryDrainable (double requiredCharge)
 Checks if the battery can be drained by the required charge.
 
bool isBatteryRechargable ()
 Checks if the battery can be recharged.
 
double getBatteryMaxDischarge (double timeStep)
 Gets the maximum discharge of the battery.
 
double getBatteryMaxRecharge (double timeStep)
 Gets the maximum recharge of the battery.
 
bool isRechargeRequired () const
 Checks if the battery requires a recharge.
 
double getBatteryRechargeSOCUpperBound () const
 Gets the upper bound of the battery's recharge state of charge.
 
void setBatteryRechargeSOCUpperBound (double newBatteryMaxSOC)
 Sets the upper bound of the battery's recharge state of charge.
 
double getBatteryRechargeSOCLowerBound () const
 Gets the lower bound of the battery's recharge state of charge.
 
void setBatteryRechargeSOCLowerBound (double newBatteryRechargeSOCLowerBound)
 Sets the lower bound of the battery's recharge state of charge.
 
double getBatteryCumEnergyConsumption ()
 Gets the cumulative energy consumption for this battery only.
 
double getBatteryCumEnergyRegenerated ()
 Gets the cumulative energy regenerated for this battery only.
 
double getBatteryCumNetEnergyConsumption ()
 Gets the cumulative net energy consumption for this battery.
 
bool batteryHasCharge ()
 Checks if the battery has enough charge.
 
bool IsBatteryExceedingThresholds ()
 Checks if the battery exceeds certain thresholds.
 
- Public Member Functions inherited from Tank
void SetTank (double maxCapacity, double initialCapacityPercentage, double depthOfDischarge)
 Set the main properties of the tank (initialize the tank)
 
double getTankMaxCapacity () const
 Gets the maximum capacity of the tank.
 
void setTankMaxCapacity (double newMaxCapacity)
 Sets the maximum capacity of the tank.
 
double getTankInitialCapacity () const
 Gets the initial capacity of the tank.
 
void setTankInitialCapacity (double newInitialCapacityPercentage)
 Sets the initial capacity of the tank.
 
double getTankCurrentCapacity () const
 Gets the current capacity of the tank.
 
double consumeTank (double consumedAmount)
 Consumes fuel from the tank.
 
double getTankStateOfCapacity () const
 Gets the state of capacity of the tank.
 
bool isTankDrainable (double consumedAmount)
 Checks if the specified amount of fuel is drainable from the tank.
 
double getTankDOD () const
 Gets the depth of discharge of the tank.
 
void setTankDOD (double newTankDOD)
 Sets the depth of discharge of the tank.
 
bool tankHasFuel ()
 Checks if the tank has fuel (current capacity > 0)
 
double getTankCumConsumedFuel () const
 Gets the total amount of fuel consumed from the tank.
 

Public Attributes

TrainTypes::CarType carType
 The type of the car.
 
- Public Attributes inherited from TrainComponent
std::string name
 The name of the vehicle.
 
double length
 Length of the vehicle in meter.
 
double trackCurvature
 The current curvature the vehicle is experiencing.
 
double trackGrade
 The current grade the vehicle is experiencing.
 
double dragCoef
 The air drag factor for aerodynamics resistance.
 
double frontalArea
 The total frontal area of the vehicle for the aerodynamics resistance.
 
double currentWeight
 The gross weight of the vehicle when the train is travelling.
 
double emptyWeight
 The light weight of the vehicle when the train is travelling.
 
int noOfAxiles
 The number of axiles the car has.
 
double auxiliaryPower
 Auxiliary power.
 
double energyConsumed = 0.0
 The amount of energy consumed in kwh.
 
double cumEnergyConsumed = 0.0
 The amount of cummulative energy consumed in kwh.
 
double energyRegenerated = 0.0
 The amount of energy regenerated in kwh.
 
double cumEnergyRegenerated = 0.0
 The amount of cummulative energy regenerated in kwh.
 
std::shared_ptr< NetLinkhostLink
 Holds the current link this vehicle is on.
 

Friends

std::ostream & operator<< (std::ostream &ostr, Car &stud)
 Stream insertion operator.
 

Detailed Description

A rail car.

The Car class represents a rail car in a train system. It is a type of TrainComponent and can carry either commodities or fuel. Unlike the locomotive, the car does not provide power to the train. However, in the case of a fuel tender, it can provide power to the locomotive when its stored power is low. This is achieved by consuming fuel and reducing the weight of the car.

@Author Ahmed @Date 2/14/2023

Constructor & Destructor Documentation

◆ Car()

Car::Car ( double  carLength_m,
double  carDragCoef,
double  carFrontalArea_sqm,
double  carEmptyWeight_t,
double  carCurrentWeight_t,
int  carNoOfAxles,
int  carType,
double  auxiliaryPower_kw = EC::DefaultCarAuxiliaryPower,
double  batteryMaxCapacity_kWh = EC::DefaultCarBatteryMaxCapacity,
double  batteryInitialCharge_perc = EC::DefaultCarBatteryInitialCharge,
double  tenderMaxCapacity_kg_l = EC::DefaultCarTenderMaxCapacity,
double  tenderInitialCapacity_perc = EC::DefaultCarTenderInitialCapacity,
std::string  carName = DefaultCarName 
)

Constructor.

Parameters
carLength_mThe car length in meters.
carDragCoefThe car drag coefficient.
carFrontalArea_sqmThe car frontal area in square meters.
carEmptyWeight_tThe car empty weight in tons.
carCurrentWeight_tThe car current weight in tons.
carNoOfAxlesThe number of axles in the car.
carTypeThe type of the car.
auxiliaryPower_kw(Optional) The auxiliary power in kW. Default is 0.0.
batteryMaxCapacity_kWh(Optional) The battery maximum capacity in kWh. Default is 10,000.
batteryInitialCharge_perc(Optional) The battery initial charge percentage. Default is 0.9.
tenderMaxCapacity_kg_l(Optional) The tender maximum capacity in kilograms or liters.
tenderInitialCapacity_perc(Optional) The tender initial capacity percentage. Default is 0.9.
carName(Optional) The name of the car.

Member Function Documentation

◆ canProvideEnergy()

bool Car::canProvideEnergy ( double &  EC,
double &  timeStep 
)

Checks if the car can provide energy.

Parameters
ECThe EC.
timeStepThe time step.
Returns
True if the car can provide energy, false otherwise.

◆ consumeFuel()

std::pair< bool, double > Car::consumeFuel ( double  timeStep,
double  trainSpeed,
double  EC_kwh,
double  carVirtualTractivePower = std::numeric_limits<double>::quiet_NaN(),
double  dieselConversionFactor = EC::DefaultDieselConversionFactor,
double  biodieselConversionFactor = EC::DefaultBiodieselConversionFactor,
double  hydrogenConversionFactor = EC::DefaultHydrogenConversionFactor,
double  dieselDensity = EC::DefaultDieselDensity,
double  biodieselDensity = EC::DefaultBioDieselDensity,
double  hydrogenDensity = EC::DefaultHydrogenDensity 
)
overridevirtual

Consumes fuel from the tender.

Parameters
timeStepThe time step.
trainSpeedThe train speed.
EC_kWhThe EC kWh.
carVirtualTractivePower(Optional) The car's virtual tractive power.
dieselConversionFactor(Optional) The diesel conversion factor.
biodieselConversionFactor(Optional) The biodiesel conversion factor.
hydrogenConversionFactor(Optional) The hydrogen conversion factor.
dieselDensity(Optional) The diesel density.
biodieselDensity(Optional) The biodiesel density.
hydrogenDensity(Optional) The hydrogen density.
Returns
A std::pair<bool, double>.

Reimplemented from TrainComponent.

◆ getCargoNetWeight()

double Car::getCargoNetWeight ( )

Gets the cargo net weight.

Returns
The cargo net weight in tons.

◆ getEnergyConsumption()

double Car::getEnergyConsumption ( double &  timeStep)

Gets the energy consumption of the car (in case there is auxiliary power).

Otherwise, it returns 0.0.

Parameters
timeStepThe time step of the simulator in seconds.
Returns
The energy consumption in kWh.

◆ getMaxProvidedEnergy()

double Car::getMaxProvidedEnergy ( double &  timeStep)

Gets the maximum energy provided by the car.

Parameters
timeStepThe time step.
Returns
The maximum provided energy in kWh.

◆ getResistance()

double Car::getResistance ( double  trainSpeed)
overridevirtual

Gets the resistance contributed by this car to the whole train.

Parameters
trainSpeedThe train speed in m/s.
Returns
The car's resistance in Newton.

Reimplemented from TrainComponent.

◆ setCarCurrentWeight()

void Car::setCarCurrentWeight ( double  newCurrentWeight)

Sets the car's current weight.

Parameters
newCurrentWeightThe new gross weight of the car, which cannot be less than the light weight of the car.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  ostr,
Car stud 
)
friend

Stream insertion operator.

Parameters
ostrThe ostr.
studThe stud.
Returns
The shifted result.

Member Data Documentation

◆ carType

TrainTypes::CarType Car::carType

The type of the car.