From 3a0741da1536cc4a0fc62b01fb95dcc3d115323a Mon Sep 17 00:00:00 2001 From: hiwis <hiwis@irmb.tu-bs.de> Date: Mon, 25 Mar 2019 17:10:59 +0100 Subject: [PATCH] added kernel for applyRules --- src/Traffic/GPU/TrafficTimestep.cu | 369 ++++++++++++++++++ src/Traffic/GPU/TrafficTimestep.h | 76 ++++ src/Traffic/GPU/package.include | 0 src/Traffic/Junction/Junction.h | 4 +- src/Traffic/Junction/JunctionRandom.cpp | 26 +- src/Traffic/Junction/JunctionRandom.h | 6 +- .../Output/ConcBySpeedAndAcceleration.cpp | 17 +- .../Output/ConcBySpeedAndAcceleration.h | 1 + .../Output/ConcentrationByPosition.cpp | 14 +- src/Traffic/Output/ConcentrationByPosition.h | 1 + src/Traffic/Output/ConcentrationOutwriter.h | 2 +- src/Traffic/RoadNetwork/RoadNetworkData.h | 8 +- src/Traffic/TrafficMovement.cpp | 138 ++++--- src/Traffic/TrafficMovement.h | 27 +- src/Traffic/TrafficMovementFactoryImpl.cpp | 2 +- src/Traffic/TrafficMovementFactoryTest.cpp | 136 +++---- src/Traffic/TrafficMovementFactoryTest.h | 42 +- targets/apps/LBM/TrafficTest/TrafficTest.cpp | 52 ++- targets/libs/Traffic/3rdPartyLinking.cmake | 4 +- 19 files changed, 738 insertions(+), 187 deletions(-) create mode 100644 src/Traffic/GPU/TrafficTimestep.cu create mode 100644 src/Traffic/GPU/TrafficTimestep.h create mode 100644 src/Traffic/GPU/package.include diff --git a/src/Traffic/GPU/TrafficTimestep.cu b/src/Traffic/GPU/TrafficTimestep.cu new file mode 100644 index 000000000..cbc4b18bb --- /dev/null +++ b/src/Traffic/GPU/TrafficTimestep.cu @@ -0,0 +1,369 @@ +#include "TrafficTimestep.h" + +#include <cuda.h> +#include <cuda_runtime.h> +#include <helper_cuda.h> +#include <curand.h> +#include <curand_kernel.h> + +#include <cmath> +#include <sstream> + +#include <thrust/device_vector.h> +#include <thrust/reduce.h> +#include <thrust/device_ptr.h> +#include <thrust/host_vector.h> + +#include <iomanip> + +//#include "TrafficMovement.h" +#include "RoadNetwork/RoadNetworkData.h" +#include "Junction/Junction.h" +#include "Sink/Sink.h" + +__global__ void trafficTimestepKernel(int* roadCurrent, int* roadNext, int* neighbors, int* oldSpeeds, uint* junctionInCellIndices, bool* junctionCarCanEnter, int* junctionCarsOnJunction, uint* junctionAlreadyMoved, uint* JunctionOldSpeeds, bool* sinkCarCanEnter, + uint size_road, uint maxVelocity, uint maxAcceleration, uint safetyDistance, bool useSlowToStart, real slowStartPossibility, real dawdlePossibility, std::mt19937* engine, std::uniform_real_distribution<real> distFloat); + +__host__ __device__ inline void trafficTimestepFunction(int* roadCurrent, int* roadNext, int* neighbors, int* oldSpeeds, uint* junctionInCellIndices, bool* junctionCarCanEnter, int* junctionCarsOnJunction, uint* junctionAlreadyMoved, uint* JunctionOldSpeeds, bool* sinkCarCanEnter, + uint size_road, uint maxVelocity, uint maxAcceleration, uint safetyDistance, bool useSlowToStart, real slowStartPossibility, real dawdlePossibility, std::mt19937* engine, std::uniform_real_distribution<real> distFloat, uint index); +__host__ __device__ inline uint getInCellsVectorIndex(uint * junctionInCellIndices, uint size_road, uint cell); +__host__ __device__ inline void sourceTimestepFunction(int* roadCurrent, int* roadNext, int* neighbors, int* oldSpeeds); +//__host__ __device__ inline void trafficTimestepFunction( uint index); + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +TrafficTimestep::TrafficTimestep(std::shared_ptr<RoadNetworkData> road) +{ + //calculate sizes + size_roads = road->roadLength; + size_junctions = road->junctions.size(); + size_sources = road->sources.size(); + size_sinks = road->sinks.size(); + + //set attributes + maxVelocity = road->maxVelocity; + safetyDistance = road->safetyDistance; + + dawdlePossibility = 0.5f; + useSlowToStart = false; + slowStartPossibility = 0.1f; + maxAcceleration = 2; + + //prepare road + this->neighbors.resize(size_roads); + this->neighbors = road->neighbors; + roadCurrent.resize(size_roads); + roadNext.resize(size_roads); + oldSpeeds.resize(size_roads); + + //prepare junctions + combineJunctionInCellIndices(road->junctions); + junctionCarCanEnter.resize(junctionInCellIndices.size()); + junctionCarsOnJunction.resize(junctionInCellIndices.size()); + junctionAlreadyMoved.resize(junctionInCellIndices.size()); + JunctionOldSpeeds.resize(junctionInCellIndices.size()); + + //prepare sinks + sinkCarCanEnter.resize(size_sinks); +} + +void TrafficTimestep::run(std::shared_ptr<RoadNetworkData> road) +{ + //copy road to device + this->roadCurrent = *road->pcurrent; + std::fill(roadNext.begin(), roadNext.end(), -1); + + //reset oldSpeeds + std::fill(oldSpeeds.begin(), oldSpeeds.end(), -1); + + //copy junctions an sinks to device + combineJunctionCarCanEnter(road->junctions); + combineJunctionCarsOnJunction(road->junctions); + combineJunctionAlreadyMoved(road->junctions); + combineJunctionOldSpeeds(road->junctions); + combineSinkCarCanEnterSink(road->sinks); + + //calculate grid and threads + unsigned int numberOfThreads = 128; + int Grid = (size_roads / numberOfThreads) + 1; + int Grid1, Grid2; + if (Grid > 512) + { + Grid1 = 512; + Grid2 = (Grid / Grid1) + 1; + } + else + { + Grid1 = 1; + Grid2 = Grid; + } + dim3 grid(Grid1, Grid2); + dim3 threads(numberOfThreads, 1, 1); + + //call kernel + trafficTimestepKernel << < grid, threads >> > ( + roadCurrent.data().get(), + roadNext.data().get(), + neighbors.data().get(), + oldSpeeds.data().get(), + junctionInCellIndices.data().get(), + junctionCarCanEnter.data().get(), + junctionCarsOnJunction.data().get(), + junctionAlreadyMoved.data().get(), + JunctionOldSpeeds.data().get(), + sinkCarCanEnter.data().get(), + size_roads, + maxVelocity, + maxAcceleration, + safetyDistance, + useSlowToStart, + slowStartPossibility, + dawdlePossibility, + &engine, + distFloat); + + cudaDeviceSynchronize(); + + getLastCudaError("trafficTimestepKernel execution failed"); + + thrust::copy(roadNext.begin(), roadNext.end(), (*road->pnext).begin()); + thrust::copy(roadCurrent.begin(), roadCurrent.end(), (*road->pcurrent).begin()); + thrust::copy(oldSpeeds.begin(), oldSpeeds.end(), road->oldSpeeds.begin()); + + //combineJunctionCarCanEnter(road->junctions); + //combineJunctionCarsOnJunction(road->junctions); + //combineJunctionAlreadyMoved(road->junctions); + //combineJunctionOldSpeeds(road->junctions); + + +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +__global__ void trafficTimestepKernel(int* roadCurrent, int* roadNext, int* neighbors, int* oldSpeeds, uint* junctionInCellIndices, bool* junctionCarCanEnter, int* junctionCarsOnJunction, uint* junctionAlreadyMoved, uint* JunctionOldSpeeds, bool* sinkCarCanEnter, + uint size_road, uint maxVelocity, uint maxAcceleration, uint safetyDistance, bool useSlowToStart, real slowStartPossibility, real dawdlePossibility, std::mt19937* engine, std::uniform_real_distribution<real> distFloat) +{ + ////////////////////////////////////////////////////////////////////////// + const uint x = threadIdx.x; // Globaler x-Index + const uint y = blockIdx.x; // Globaler y-Index + const uint z = blockIdx.y; // Globaler z-Index + + const uint nx = blockDim.x; + const uint ny = gridDim.x; + + const uint index = nx*(ny*z + y) + x; + //////////////////////////////////////////////////////////////////////////////// + + if (index >= size_road) return; + + + trafficTimestepFunction(roadCurrent, roadNext, neighbors, oldSpeeds, junctionInCellIndices, junctionCarCanEnter, junctionCarsOnJunction, junctionAlreadyMoved, JunctionOldSpeeds, sinkCarCanEnter, + size_road, maxVelocity, maxAcceleration, safetyDistance, useSlowToStart, slowStartPossibility, dawdlePossibility, engine, distFloat, index); +} + +__host__ __device__ void trafficTimestepFunction(int* roadCurrent, int* roadNext, int* neighbors, int* oldSpeeds, uint* junctionInCellIndices, bool* junctionCarCanEnter, int* junctionCarsOnJunction, uint* junctionAlreadyMoved, uint* JunctionOldSpeeds, bool* sinkCarCanEnter, + uint size_road, uint maxVelocity, uint maxAcceleration, uint safetyDistance, bool useSlowToStart, real slowStartPossibility, real dawdlePossibility, std::mt19937* engine, std::uniform_real_distribution<real> distFloat, uint index) +{ + if (roadCurrent[index] < 0) return; + + uint speed = roadCurrent[index]; + + + + //// accelerate car //////////////////////////////////////////////////////////////////// + + if (speed <= maxVelocity - maxAcceleration) speed += maxAcceleration; + + + + //// brake car ///////////////////////////////////////////////////////////////////////// + + //getGapAfterCar + uint gap; + int neighbor = neighbors[index]; + uint currentCell = index; + for (uint i = 0; i < (speed + safetyDistance); i++) { + + //sink + if (neighbor <= -2000) { + if (i <= speed && sinkCarCanEnter[(neighbor + 2000)*-1]) gap = speed; + else gap = i; + break; + } + + //junction + if (neighbor <= -1000) { + if (junctionCarCanEnter[getInCellsVectorIndex(junctionInCellIndices, size_road, currentCell)] && i <= speed) gap = speed; + else gap = i; + break; + } + + //car in Cell + if (roadCurrent[neighbor] > -1) { + if (i <= safetyDistance) gap = 0; + else gap = i - safetyDistance; + break; + } + + //empty cell -> get next neighbor, update currentCell + currentCell = neighbor; + neighbor = neighbors[neighbor]; + } + //brake + if (speed > gap) + speed = gap; + + + + //// dawdleCar /////////////////////////////////////////////////////////////////////////// + float randomNumber; + #if defined(__CUDA_ARCH__) + curandState state; + curand_init((unsigned long long)clock(), index, 0, &state); + randomNumber = curand_uniform_double(&state); + #else + randomNumber = distFloat(*engine); + #endif + + + //Barlovic / SlowToStart + if (useSlowToStart == true && roadCurrent[index] == 0) { + if (randomNumber < slowStartPossibility) speed = 0; + } + else if (randomNumber < dawdlePossibility) //Standard NaSch + if (speed >= maxAcceleration) + speed -= maxAcceleration; + else + speed = 0; + + + + //// moveCar ///////////////////////////////////////////////////////////////////////////// + if (speed == 0) { + (roadNext)[index] = 0; + oldSpeeds[index] = roadCurrent[index]; + return; + } + + neighbor = neighbors[index]; + currentCell = index; + + // iterateNeighborsInMove + uint numberOfCellsMoved = 1; + for (uint i = 2; i <= speed; i++) { + if (neighbor >= 0) { + currentCell = neighbor; + neighbor = neighbors[neighbor]; + ++numberOfCellsMoved; + } + else + break; + } + + + if (neighbor <= -1000 && neighbor > -2000) { + //registerCar + uint index = getInCellsVectorIndex(junctionInCellIndices, size_road, currentCell); + junctionCarsOnJunction[index] = speed - 1; //all cars, which enter the junction have to slow down by one increment + //getCarsOnJunction[index] = 0; //all cars, which enter the junction have to stop + JunctionOldSpeeds[index] = roadCurrent[index]; + junctionCarCanEnter[index] = false; + junctionAlreadyMoved[index] = numberOfCellsMoved; + return; + } + + if (neighbor >= 0) { + roadNext[neighbor] = speed; + //writeConcentration(neighbor, (*pcurrent)[carIndex]); + } +} + + + + + +__host__ __device__ uint getInCellsVectorIndex(uint* junctionInCellIndices, uint size_road, uint cell) { + for (uint i = 0; i < size_road; i++) + if (junctionInCellIndices[i] == cell) + return i; + // Error: "no matching incoming cell to a junction found in: getInCellsVectorIndex()"; + return 65000; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +//TrafficTimestep::TrafficTimestep(RoadNetworkData* road, TrafficMovement* traffic) +//{ +// maxVelocity = road->maxVelocity; +// vehicleLength = road->vehicleLength; +// safetyDistance = road->safetyDistance; +// +// dawdlePossibility = traffic->getDawdlePossibility(); +// useSlowToStart = traffic->getUseSlowToStart(); +// slowStartPossibility = traffic->getSlowToStartPossibility(); +// maxAcceleration = traffic->getMaxAcceleration(); +//} + + + +void TrafficTimestep::combineJunctionInCellIndices(std::vector<std::shared_ptr<Junction>> junctions) +{ + uint it = 0; + for (auto& j : junctions) + for (uint i : j->getInCellIndices()) { + this->junctionInCellIndices.push_back(i); + it++; + } +} + +void TrafficTimestep::combineJunctionCarCanEnter(std::vector<std::shared_ptr<Junction>> junctions) +{ + uint index = 0; + for (auto& j : junctions) + for (bool i : j->getCarCanEnter()) { + this->junctionCarCanEnter[index] = i; + index++; + } + +} + +void TrafficTimestep::combineJunctionCarsOnJunction(std::vector<std::shared_ptr<Junction>> junctions) +{ + uint index = 0; + for (auto& j : junctions) + for (int i : j->getCarsOnJunction()) { + this->junctionCarsOnJunction[index] = i; + index++; + } +} + + +void TrafficTimestep::combineSinkCarCanEnterSink(std::vector<std::shared_ptr<Sink>> sinks) +{ + uint index = 0; + for (auto& s : sinks) { + this->sinkCarCanEnter.push_back(s->carCanEnter()); + index++; + } +} + +void TrafficTimestep::combineJunctionAlreadyMoved(std::vector<std::shared_ptr<Junction>> junctions) +{ + uint index = 0; + for (auto& j : junctions) + for (int i : j->getCarsOnJunction()) { + this->junctionAlreadyMoved[index] = i; + index++; + } +} + +void TrafficTimestep::combineJunctionOldSpeeds(std::vector<std::shared_ptr<Junction>> junctions) +{ + uint index = 0; + for (auto& j : junctions) + for (int i : j->getCarsOnJunction()) { + this->JunctionOldSpeeds[index] = i; + index++; + } +} \ No newline at end of file diff --git a/src/Traffic/GPU/TrafficTimestep.h b/src/Traffic/GPU/TrafficTimestep.h new file mode 100644 index 000000000..4e90545f3 --- /dev/null +++ b/src/Traffic/GPU/TrafficTimestep.h @@ -0,0 +1,76 @@ +#ifndef TrafficTimestep_H +#define TrafficTimestep_H + +#include <vector> +//#include <string> +#include <memory> +#include <random> +#include <thrust/device_vector.h> + +#include "VirtualFluidsDefinitions.h" +#include "Utilities/RandomHelper.h" +#include "Core/PointerDefinitions.h" +#include "Core/DataTypes.h" + +//#include "TrafficMovement.h" + +struct RoadNetworkData; +//class TrafficMovement; +class Sink; +class Junction; +class Source; + +class VF_PUBLIC TrafficTimestep +{ +private: + + //std::vector<real> kineticEnergyTimeSeries; + int size_roads; + uint maxVelocity; + uint safetyDistance; + + real dawdlePossibility; + bool useSlowToStart; + real slowStartPossibility; + uint maxAcceleration; + + int size_junctions; + int size_sources; + int size_sinks; + + thrust::device_vector<int> neighbors; + + thrust::device_vector<int> roadCurrent; + thrust::device_vector<int> roadNext; + thrust::device_vector<int> oldSpeeds; + + thrust::device_vector<uint> junctionInCellIndices; + thrust::device_vector<bool> junctionCarCanEnter; + thrust::device_vector<int> junctionCarsOnJunction; + thrust::device_vector<uint> junctionAlreadyMoved; + thrust::device_vector<uint> JunctionOldSpeeds; + + thrust::device_vector<bool> sinkCarCanEnter; + + thrust::device_vector<float> sourcePossibilities; + + std::mt19937 engine = RandomHelper::make_engine(); + std::uniform_real_distribution<float> distFloat{ 0.0, 1.0 }; +public: + + + TrafficTimestep(std::shared_ptr<RoadNetworkData> road); + //TrafficTimestep(RoadNetworkData* road, TrafficMovement* traffic); + void run(std::shared_ptr<RoadNetworkData> road); + + void combineJunctionInCellIndices(std::vector<std::shared_ptr<Junction> > junctions); + void combineJunctionCarCanEnter(std::vector<std::shared_ptr<Junction> > junctions); + void combineJunctionCarsOnJunction(std::vector<std::shared_ptr<Junction> > junctions); + void combineSinkCarCanEnterSink(std::vector<std::shared_ptr<Sink> > sinks); + void combineSourcePossibilities(std::vector<std::shared_ptr<Source>> sources); + void combineJunctionAlreadyMoved(std::vector<std::shared_ptr<Junction> > junctions); + void combineJunctionOldSpeeds(std::vector<std::shared_ptr<Junction> > junctions); + +}; + +#endif diff --git a/src/Traffic/GPU/package.include b/src/Traffic/GPU/package.include new file mode 100644 index 000000000..e69de29bb diff --git a/src/Traffic/Junction/Junction.h b/src/Traffic/Junction/Junction.h index 8af481aef..259bdcb9e 100644 --- a/src/Traffic/Junction/Junction.h +++ b/src/Traffic/Junction/Junction.h @@ -20,7 +20,9 @@ public: virtual void updateJunction() = 0; virtual const std::vector<uint>& getInCellIndices() const = 0; + virtual const std::vector<bool>& getCarCanEnter() const = 0; + virtual const std::vector<int>& getCarsOnJunction()const = 0; virtual void dispJunction(const uint index, const uint roadLength) const = 0; - virtual const uint getNumCarsOnJunction() const = 0; + virtual uint getNumCarsOnJunction() const = 0; }; \ No newline at end of file diff --git a/src/Traffic/Junction/JunctionRandom.cpp b/src/Traffic/Junction/JunctionRandom.cpp index f5c427f89..97b05ba9e 100644 --- a/src/Traffic/Junction/JunctionRandom.cpp +++ b/src/Traffic/Junction/JunctionRandom.cpp @@ -70,9 +70,7 @@ uint JunctionRandom::getInCellsVectorIndex(uint cellIndex) auto it = find(data.inCellIndices.begin(), data.inCellIndices.end(), cellIndex); if (it != data.inCellIndices.end()) - { return static_cast <uint> (distance(data.inCellIndices.begin(), it)); - } throw std::runtime_error("The passed cell is not an incoming cell to this junction."); } @@ -121,7 +119,7 @@ void JunctionRandom::applyRules(int & carSpeed, int index, TrafficMovement& road } } data.carsOnJunction[index] = 0; //cars, which can't cross the junctionin one timestep, because they already moved to many cells, loose their speed. - //data.carsOnJunction[index] = carSpeed; //cars, which can't cross the junction in one timestep, because they already moved to many cells, keep their speed. + //data.getCarsOnJunction[index] = carSpeed; //cars, which can't cross the junction in one timestep, because they already moved to many cells, keep their speed. } @@ -211,6 +209,26 @@ const std::vector<uint>& JunctionRandom::getInCellIndices() const return data.inCellIndices; } +const std::vector<bool>& JunctionRandom::getCarCanEnter() const +{ + return data.carCanEnter; +} + +const std::vector<int>& JunctionRandom::getCarsOnJunction() const +{ + return data.carsOnJunction; +} + +const std::vector<uint>& JunctionRandom::getAlreadyMoved() const +{ + return data.alreadyMoved; +} + +const std::vector<uint>& JunctionRandom::getOldSpeeds() const +{ + return data.oldSpeeds; +} + void JunctionRandom::dispJunction(const uint index, const uint roadLength) const { if (find(data.inCellIndices.begin(), data.inCellIndices.end(), (roadLength - index - 1)) != data.inCellIndices.end()) { @@ -224,7 +242,7 @@ void JunctionRandom::dispJunction(const uint index, const uint roadLength) const } } -const uint JunctionRandom::getNumCarsOnJunction() const +uint JunctionRandom::getNumCarsOnJunction() const { uint num = 0; for (auto car : data.carsOnJunction) { diff --git a/src/Traffic/Junction/JunctionRandom.h b/src/Traffic/Junction/JunctionRandom.h index 531eb210f..cb6cd2931 100644 --- a/src/Traffic/Junction/JunctionRandom.h +++ b/src/Traffic/Junction/JunctionRandom.h @@ -28,9 +28,13 @@ public: virtual void updateJunction(); virtual const std::vector<uint>& getInCellIndices() const; + virtual const std::vector<bool>& getCarCanEnter() const; + virtual const std::vector<int>& getCarsOnJunction()const; + virtual const std::vector<uint>& getAlreadyMoved()const; + virtual const std::vector<uint>& getOldSpeeds()const; virtual void dispJunction(const uint index, const uint roadLength) const; - virtual const uint getNumCarsOnJunction() const; + virtual uint getNumCarsOnJunction() const; virtual void checkOutCellIndices(const uint roadLength) const; diff --git a/src/Traffic/Output/ConcBySpeedAndAcceleration.cpp b/src/Traffic/Output/ConcBySpeedAndAcceleration.cpp index cf9760ee2..03fdaf8c3 100644 --- a/src/Traffic/Output/ConcBySpeedAndAcceleration.cpp +++ b/src/Traffic/Output/ConcBySpeedAndAcceleration.cpp @@ -2,17 +2,18 @@ #include <iostream> -ConcBySpeedAndAcceleration::ConcBySpeedAndAcceleration(uint roadlength, real * concArrayStart, uint maxSpeed) +ConcBySpeedAndAcceleration::ConcBySpeedAndAcceleration(uint roadLength, real * concArrayStart, uint maxSpeed) { if (concArrayStart == nullptr) { - std::cout << "using ConcBySpeedAndAcceleration::concentration for concentrations" << std::endl; - concentration.resize(roadlength); + std::cout << "using ConcBySpeedAndAcceleration::concentration-vector for concentrations" << std::endl; + concentration.resize(roadLength); + this->roadLength = roadLength; this->maxSpeed = static_cast<real>(maxSpeed); } else { std::cout << "using passed array for concentrations" << std::endl; useLBMConcArray = true; - this->roadLength = roadlength; + this->roadLength = roadLength; this->concArrayStart = concArrayStart; this->maxSpeed = static_cast<real>(maxSpeed); } @@ -25,6 +26,14 @@ void ConcBySpeedAndAcceleration::calculateConcForSingleCar(uint index, uint oldS } +void ConcBySpeedAndAcceleration::calculateConcForAllCars(const std::vector<int> oldSpeeds, const std::vector<int> newSpeeds) +{ + for (uint i = 0; i < roadLength; i++) { + if (newSpeeds[i] > -1) + putConcIntoArrayOrVector(i, chooseConc(oldSpeeds[i], newSpeeds[i])); + } +} + void ConcBySpeedAndAcceleration::calculateConcForJunctionCar(uint index, uint oldSpeed, uint speed) { addConcToArrayOrVector(index, chooseConc(oldSpeed, speed)); diff --git a/src/Traffic/Output/ConcBySpeedAndAcceleration.h b/src/Traffic/Output/ConcBySpeedAndAcceleration.h index 71ef332e0..3bb36e927 100644 --- a/src/Traffic/Output/ConcBySpeedAndAcceleration.h +++ b/src/Traffic/Output/ConcBySpeedAndAcceleration.h @@ -11,6 +11,7 @@ public: virtual void calculateConcForSingleCar(uint index, uint oldSpeed, uint speed); virtual void calculateConcForJunctionCar(uint index, uint oldSpeed, uint speed); + virtual void calculateConcForAllCars(const std::vector<int> oldSpeeds, const std::vector<int> newSpeeds); private: diff --git a/src/Traffic/Output/ConcentrationByPosition.cpp b/src/Traffic/Output/ConcentrationByPosition.cpp index cc28bcad2..bdfc46e13 100644 --- a/src/Traffic/Output/ConcentrationByPosition.cpp +++ b/src/Traffic/Output/ConcentrationByPosition.cpp @@ -2,11 +2,12 @@ #include <iostream> -ConcentrationByPosition::ConcentrationByPosition(uint roadlength, real * concArrayStart, uint maxSpeed) +ConcentrationByPosition::ConcentrationByPosition(uint roadLength, real * concArrayStart, uint maxSpeed) { if (concArrayStart == nullptr) { - std::cout << "using ConcentrationByPosition::concentration for concentrations" << std::endl; - concentration.resize(roadlength); + std::cout << "using ConcentrationByPosition::concentration-vector for concentrations" << std::endl; + concentration.resize(roadLength); + this->roadLength = roadLength; } else { std::cout << "using passed array for concentrations" << std::endl; @@ -40,4 +41,11 @@ void ConcentrationByPosition::calculateConcForJunctionCar(uint index, uint oldSp addConcToArrayOrVector(index, 1.0); } +void ConcentrationByPosition::calculateConcForAllCars(const std::vector<int> oldSpeeds, const std::vector<int> newSpeeds) +{ + for (uint i = 0; i < roadLength; i++) + if (newSpeeds[i] >= 0) + putConcIntoArrayOrVector(i, 1.0); +} + diff --git a/src/Traffic/Output/ConcentrationByPosition.h b/src/Traffic/Output/ConcentrationByPosition.h index 7bcf89d08..48c93878e 100644 --- a/src/Traffic/Output/ConcentrationByPosition.h +++ b/src/Traffic/Output/ConcentrationByPosition.h @@ -11,5 +11,6 @@ public: virtual void calculateConcForSingleCar(uint index, uint oldSpeed = 0, uint speed = 0); virtual void calculateConcForJunctionCar(uint index, uint oldSpeed = 0, uint speed = 0); + virtual void calculateConcForAllCars(const std::vector<int> oldSpeeds, const std::vector<int> newSpeeds) = 0; }; diff --git a/src/Traffic/Output/ConcentrationOutwriter.h b/src/Traffic/Output/ConcentrationOutwriter.h index 8908b508c..0c6082912 100644 --- a/src/Traffic/Output/ConcentrationOutwriter.h +++ b/src/Traffic/Output/ConcentrationOutwriter.h @@ -11,7 +11,7 @@ public: virtual void resetConcentrations(); virtual void calculateConcForSingleCar(uint index, uint oldSpeed = 0, uint speed = 0) = 0; virtual void calculateConcForJunctionCar(uint index, uint oldSpeed = 0, uint speed = 0) = 0; - + virtual void calculateConcForAllCars(const std::vector<int> oldSpeeds, const std::vector<int> newSpeeds)=0; void dispConcentrations(); protected: diff --git a/src/Traffic/RoadNetwork/RoadNetworkData.h b/src/Traffic/RoadNetwork/RoadNetworkData.h index 1a19822bf..904b89230 100644 --- a/src/Traffic/RoadNetwork/RoadNetworkData.h +++ b/src/Traffic/RoadNetwork/RoadNetworkData.h @@ -12,7 +12,7 @@ struct VF_PUBLIC RoadNetworkData { -protected: +public: friend class TrafficMovement; uint roadLength; @@ -28,5 +28,11 @@ protected: std::vector<std::shared_ptr<Sink> > sinks; std::vector<std::shared_ptr<Junction> > junctions; std::vector<std::shared_ptr<Source> > sources; + + std::vector<int> *pcurrent; + std::vector<int> *pnext; + std::vector<int> *pdummy; + + std::vector<int> oldSpeeds; }; diff --git a/src/Traffic/TrafficMovement.cpp b/src/Traffic/TrafficMovement.cpp index b4ff8b056..0e90e2653 100644 --- a/src/Traffic/TrafficMovement.cpp +++ b/src/Traffic/TrafficMovement.cpp @@ -9,12 +9,14 @@ #include "Output/ConcentrationOutwriter.h" #include "Output/CarDisplay.h" -TrafficMovement::TrafficMovement(std::unique_ptr<RoadNetworkData> road, const real dawdlePossibility) +#include "GPU/TrafficTimestep.h" + +TrafficMovement::TrafficMovement(std::shared_ptr<RoadNetworkData> road, const real dawdlePossibility) { this->road = std::move(road); - pcurrent = &this->road->current; - pnext = &(this->road->next); + this->road->pcurrent = &this->road->current; + this->road->pnext = &(this->road->next); checkCurrentForSafetyDistance(); @@ -24,9 +26,9 @@ TrafficMovement::TrafficMovement(std::unique_ptr<RoadNetworkData> road, const re TrafficMovement::~TrafficMovement() { - pcurrent = NULL; - pnext = NULL; - pdummy = NULL; + road->pcurrent = NULL; + road->pnext = NULL; + road->pdummy = NULL; } @@ -68,6 +70,14 @@ void TrafficMovement::setSlowToStart(const real slowStartPossibility) } } +void TrafficMovement::setUseGPU() +{ + useGPU = true; + this->road->oldSpeeds.resize(this->road->roadLength); + VectorHelper::fillVector(this->road->oldSpeeds, -1); + gpuCalculation = std::make_unique<TrafficTimestep>(TrafficTimestep(this->road)); +} + void TrafficMovement::setMaxAcceleration(uint maxAcceleration) { this->maxAcceleration = maxAcceleration; @@ -81,43 +91,65 @@ void TrafficMovement::setConcentrationOutwriter(std::unique_ptr<ConcentrationOut void TrafficMovement::setSaveResultsTrue(uint timeSteps) { - this->display = std::make_unique<CarDisplay>(&pcurrent, road->safetyDistance); + this->display = std::make_unique<CarDisplay>(&road->pcurrent, road->safetyDistance); if (display != nullptr) display->initResults(timeSteps); } -const uint TrafficMovement::getNumberOfCars() const +uint TrafficMovement::getNumberOfCars() const { uint num = 0; for (auto& junc : road->junctions) { num += junc->getNumCarsOnJunction(); } - for (auto cell : *pcurrent) { + for (auto cell : *road->pcurrent) { if (cell >= 0) ++num; } return num; } -const int TrafficMovement::getSpeedAtPosition(uint pos) const +int TrafficMovement::getSpeedAtPosition(uint pos) const { - return (*pcurrent)[pos]; + return (*road->pcurrent)[pos]; } -const uint TrafficMovement::getRoadLength() const +uint TrafficMovement::getRoadLength() const { return road->roadLength; } -const uint TrafficMovement::getMaxVelocity() const +uint TrafficMovement::getMaxVelocity() const { return road->maxVelocity; } +real TrafficMovement::getDawdlePossibility() +{ + return dawdlePossibility; +} + +bool TrafficMovement::getUseSlowToStart() +{ + return useSlowToStart; +} + +real TrafficMovement::getSlowToStartPossibility() +{ + return slowStartPossibility; +} + +uint TrafficMovement::getMaxAcceleration() +{ + return maxAcceleration; +} + + + void TrafficMovement::loopTroughTimesteps(uint timeSteps) { for (uint step = 1; step < timeSteps + 1; step++) { @@ -132,15 +164,19 @@ void TrafficMovement::calculateTimestep(uint step) //if (display != nullptr) display->dispCurrentRoad(); //if (concWriter != nullptr) concWriter->dispConcentrations(); - VectorHelper::fillVector(*pnext, -1); + VectorHelper::fillVector(*(road->pnext), -1); if (concWriter != nullptr) concWriter->resetConcentrations(); - //apply rules on all cars - for (uint i = 0; i < road->roadLength; i++) { - if ((*pcurrent)[i] > -1) { - applyRules(i); - } + //apply rules on all cars + if (useGPU) { + this->gpuCalculation->run(road); + if (concWriter != nullptr) concWriter->calculateConcForAllCars(road->oldSpeeds, *(road->pcurrent)); } + else + for (uint i = 0; i < road->roadLength; i++) + if ((*road->pcurrent)[i] > -1) + applyRules(i); + calculateJunctionStep(); @@ -163,7 +199,7 @@ void TrafficMovement::calculateSourceStep() gap = getGapAfterOutCell(sourceIndex, road->maxVelocity); if (gap > 0) { uint speed = source->getSourceCar(); - (*pnext)[sourceIndex] = speed; + (*road->pnext)[sourceIndex] = speed; writeConcentration(sourceIndex, speed); } } @@ -179,14 +215,14 @@ void TrafficMovement::calculateJunctionStep() void TrafficMovement::switchCurrentNext() { - pdummy = pcurrent; - pcurrent = pnext; - pnext = pdummy; + road->pdummy = road->pcurrent; + road->pcurrent = road->pnext; + road->pnext = road->pdummy; } void TrafficMovement::applyRules(uint carIndex) { - uint speed = (*pcurrent)[carIndex]; + uint speed = (*road->pcurrent)[carIndex]; accelerateCar(speed); brakeCar(carIndex, speed); dawdleCar(carIndex, speed); @@ -195,18 +231,16 @@ void TrafficMovement::applyRules(uint carIndex) void TrafficMovement::accelerateCar(uint & speed) { - if (speed <= road->maxVelocity - maxAcceleration) { + if (speed <= road->maxVelocity - maxAcceleration) speed += maxAcceleration; - } } void TrafficMovement::brakeCar(uint carIndex, uint &speed) { int neighbor = road->neighbors[carIndex]; gap = getGapAfterCar(carIndex, speed, neighbor); - if (speed > gap) { + if (speed > gap) speed = gap; - } } void TrafficMovement::dawdleCar(uint carIndex, uint & speed) @@ -214,7 +248,7 @@ void TrafficMovement::dawdleCar(uint carIndex, uint & speed) randomNumber = distFloat(engine); //Barlovic / SlowToStart - if (useSlowToStart == true && (*pcurrent)[carIndex] == 0) { + if (useSlowToStart == true && (*road->pcurrent)[carIndex] == 0) { if (randomNumber < slowStartPossibility) { speed = 0; } @@ -233,8 +267,8 @@ void TrafficMovement::dawdleCar(uint carIndex, uint & speed) void TrafficMovement::moveCar(const uint carIndex, uint speed) { if (speed == 0) { - (*pnext)[carIndex] = 0; - writeConcentration(carIndex, (*pcurrent)[carIndex]); + (*road->pnext)[carIndex] = 0; + writeConcentration(carIndex, (*road->pcurrent)[carIndex]); return; } @@ -244,13 +278,13 @@ void TrafficMovement::moveCar(const uint carIndex, uint speed) uint numberOfCellsMoved = iterateNeighborsInMove(currentCell, speed, neighbor); if (neighbor <= -1000 && neighbor > -2000) { - getJunctionFromNeighbor(neighbor)->registerCar(currentCell, numberOfCellsMoved, speed, (*pcurrent)[carIndex]); + getJunctionFromNeighbor(neighbor)->registerCar(currentCell, numberOfCellsMoved, speed, (*road->pcurrent)[carIndex]); return; } if (neighbor >= 0) { - (*pnext)[neighbor] = speed; - writeConcentration(neighbor, (*pcurrent)[carIndex]); + (*road->pnext)[neighbor] = speed; + writeConcentration(neighbor, (*road->pcurrent)[carIndex]); } } @@ -258,7 +292,7 @@ void TrafficMovement::moveCar(const uint carIndex, uint speed) void TrafficMovement::moveJunctionCar(uint outCellIndex, uint remainingDistance, uint speed, uint oldSpeed) { if (remainingDistance == 1) { - (*pnext)[outCellIndex] = speed; + (*road->pnext)[outCellIndex] = speed; writeConcentration(outCellIndex, oldSpeed); return; } @@ -267,10 +301,10 @@ void TrafficMovement::moveJunctionCar(uint outCellIndex, uint remainingDistance, uint numberOfCellsMoved = iterateNeighborsInMove(outCellIndex, remainingDistance, neighbor); - try{ - if (neighbor <= -1000 && neighbor > -2000) { - throw std::runtime_error("car entered two junctions in one timestep"); - } + try { + if (neighbor <= -1000 && neighbor > -2000) { + throw std::runtime_error("car entered two junctions in one timestep"); + } } catch (const std::exception& e) { std::cerr << e.what() << std::endl; @@ -279,7 +313,7 @@ void TrafficMovement::moveJunctionCar(uint outCellIndex, uint remainingDistance, } if (neighbor >= 0) { - (*pnext)[neighbor] = speed; + (*road->pnext)[neighbor] = speed; writeConcentration(neighbor, oldSpeed); } } @@ -327,7 +361,7 @@ uint TrafficMovement::getGapAfterCar(uint carIndex, uint speed, int neighbor) return getGapToJunction(neighbor, i, speed, carIndex); //car in Cell - if ((*pcurrent)[neighbor] > -1) + if ((*road->pcurrent)[neighbor] > -1) return adjustGapToSafetyDist(i); //empty cell -> get next neighbor, update currentCell @@ -340,9 +374,9 @@ uint TrafficMovement::getGapAfterCar(uint carIndex, uint speed, int neighbor) uint TrafficMovement::getGapAfterOutCell(uint outCellIndex, uint speed) { - if ((*pcurrent)[outCellIndex] > -1) + if ((*road->pcurrent)[outCellIndex] > -1) return 0; - + int neighbor = outCellIndex; for (uint i = 0; i < (speed + road->safetyDistance); i++) { @@ -353,7 +387,7 @@ uint TrafficMovement::getGapAfterOutCell(uint outCellIndex, uint speed) return i; //car in Cell - if ((*pcurrent)[neighbor] > -1) + if ((*road->pcurrent)[neighbor] > -1) return adjustGapToSafetyDist(i); //empty cell -> get next neighbor @@ -390,7 +424,7 @@ uint TrafficMovement::adjustGapToSafetyDist(uint gap) void TrafficMovement::writeConcentration(uint index, uint oldSpeed) { if (concWriter != nullptr) { - concWriter->calculateConcForSingleCar(index, oldSpeed, (*pnext)[index]); + concWriter->calculateConcForSingleCar(index, oldSpeed, (*road->pnext)[index]); } } @@ -416,13 +450,13 @@ void TrafficMovement::checkCurrentForSafetyDistance() if (road->safetyDistance > 0) { uint neighbor; for (uint i = 0; i < road->roadLength; i++) { - if ((*pcurrent)[i] > -1) { + if ((*road->pcurrent)[i] > -1) { neighbor = road->neighbors[i]; for (uint j = 1; j <= road->safetyDistance; j++) { if (neighbor <= -1000) break; - if ((*pcurrent)[neighbor] > -1) { + if ((*road->pcurrent)[neighbor] > -1) { std::cerr << "timestep 0: safetyDistance was violated: carIndex: " << i << std::endl; break; } @@ -442,24 +476,24 @@ const std::vector<int> & TrafficMovement::getVehiclesForVTK() void TrafficMovement::visualizeVehicleLengthForVTK() { - road->currentWithLongVehicles = *pcurrent; + road->currentWithLongVehicles = *road->pcurrent; if (road->safetyDistance != 0) { for (uint i = 0; i < road->roadLength; i++) { - if ((*pcurrent)[i] > -1) { - checkSpeed((*pcurrent)[i]); + if ((*road->pcurrent)[i] > -1) { + checkSpeed((*road->pcurrent)[i]); int neighbor = road->neighbors[i]; for (uint j = 1; j <= road->safetyDistance; j++) { if (neighbor <= -1000) break; - if ((*pcurrent)[neighbor] > -1) { + if ((*road->pcurrent)[neighbor] > -1) { std::cerr << "safetyDistance was violated: timestep: " << currentStep << "\t carIndex: " << i << std::endl; break; } else - (road->currentWithLongVehicles)[neighbor] = (*pcurrent)[i]; + (road->currentWithLongVehicles)[neighbor] = (*road->pcurrent)[i]; neighbor = road->neighbors[neighbor]; } } diff --git a/src/Traffic/TrafficMovement.h b/src/Traffic/TrafficMovement.h index ccd7c8c74..a86dfa799 100644 --- a/src/Traffic/TrafficMovement.h +++ b/src/Traffic/TrafficMovement.h @@ -8,14 +8,16 @@ #include "Core/DataTypes.h" #include "RoadNetwork/RoadNetworkData.h" +#include "Utilities/RandomHelper.h" class ConcentrationOutwriter; class CarDisplay; +class TrafficTimestep; class VF_PUBLIC TrafficMovement { public: - TrafficMovement(std::unique_ptr<RoadNetworkData> road, const real dawdlePossibility); + TrafficMovement(std::shared_ptr<RoadNetworkData> road, const real dawdlePossibility); //TrafficMovement() {}; TrafficMovement(const TrafficMovement&) = delete; ~TrafficMovement(); @@ -25,16 +27,22 @@ public: void setMaxAcceleration(uint maxAcceleration); void setConcentrationOutwriter(std::unique_ptr<ConcentrationOutwriter> writer); void setSaveResultsTrue(uint timeSteps); + void setUseGPU(); //timpestep void loopTroughTimesteps(uint numberOfTimesteps); void calculateTimestep(uint step); //get - const uint getRoadLength() const; - const uint getMaxVelocity() const; - const uint getNumberOfCars() const; //only use for testing - const int getSpeedAtPosition(uint pos) const; //only use for testing + uint getRoadLength() const; + uint getMaxVelocity() const; + uint getNumberOfCars() const; //only use for testing + int getSpeedAtPosition(uint pos) const; //only use for testing + real getDawdlePossibility(); + bool getUseSlowToStart(); + real getSlowToStartPossibility(); + uint getMaxAcceleration(); + //methods used by junctions and sources uint getGapAfterOutCell(uint outCellIndex, uint speed); @@ -83,13 +91,12 @@ private: void writeConcentration(uint index, uint oldSpeed); private: - std::unique_ptr<RoadNetworkData> road; + std::shared_ptr<RoadNetworkData> road; std::unique_ptr<ConcentrationOutwriter> concWriter = nullptr; std::unique_ptr<CarDisplay> display = nullptr; - std::vector<int> *pcurrent; - std::vector<int> *pnext; - std::vector<int> *pdummy; + bool useGPU = false; + std::unique_ptr<TrafficTimestep> gpuCalculation; real dawdlePossibility; @@ -106,6 +113,6 @@ private: private: //temporary variables for calculation uint gap; - double randomNumber; + float randomNumber; }; diff --git a/src/Traffic/TrafficMovementFactoryImpl.cpp b/src/Traffic/TrafficMovementFactoryImpl.cpp index a01625ef0..ec1eb8cce 100644 --- a/src/Traffic/TrafficMovementFactoryImpl.cpp +++ b/src/Traffic/TrafficMovementFactoryImpl.cpp @@ -90,7 +90,7 @@ void TrafficMovementFactoryImpl::initTrafficMovement(real * pconcArrayStart) this->simulator = std::make_shared<TrafficMovement>(move(roadNetwork), dawdlePossibility); simulator->setSlowToStart(slowToStartPossibility); simulator->setMaxAcceleration(2); - + simulator->setUseGPU(); //init ConcentrationOutwriter std::unique_ptr<ConcentrationOutwriter> writer = std::make_unique<ConcBySpeedAndAcceleration>(ConcBySpeedAndAcceleration(simulator->getRoadLength(), pconcArrayStart)); diff --git a/src/Traffic/TrafficMovementFactoryTest.cpp b/src/Traffic/TrafficMovementFactoryTest.cpp index b8ab1051e..358a335eb 100644 --- a/src/Traffic/TrafficMovementFactoryTest.cpp +++ b/src/Traffic/TrafficMovementFactoryTest.cpp @@ -1,68 +1,68 @@ -#include "TrafficMovementFactoryTest.h" - -#include <iostream> - -#include "GridGenerator/StreetPointFinder/JunctionReader.h" -#include "GridGenerator/StreetPointFinder/SourceReader.h" -#include "GridGenerator/StreetPointFinder/SinkReader.h" - -#include "RoadNetwork/RoadMaker.h" -#include "TrafficMovement.h" -#include "Source/SourceRandom.h" -#include "Junction/JunctionRandom.h" -#include "Sink/SinkRandom.h" -#include "Output/ConcentrationByPosition.h" -#include "Output/ConcBySpeedAndAcceleration.h" -#include "Utilities/safe_casting.h" - - -void TrafficMovementFactoryTest::initTrafficMovement(real * pconcArrayStart) -{ - //Variables - - real vehicleDensity = 0.1f; - - const uint maxVelocity = 14; - real dawdlePossibility = (real) 0.2; //typical value: 0.2 - real slowToStartPossibility = (real) 0.4; - - uint vehicleLength = 7; - - uint roadLength = 10; - - - //make RoadNetwork - auto roadNetwork = std::make_unique<RoadMaker>(roadLength, maxVelocity, vehicleLength, vehicleDensity); - - - //Sources - std::unique_ptr<Source> source = std::make_unique <SourceRandom>(SourceRandom(0, 0.7f, maxVelocity)); - roadNetwork->addSource(source); - - - //Sinks - std::unique_ptr<Sink> s = std::make_unique <SinkRandom>(SinkRandom(9, 0.5f)); - roadNetwork->addSink(move(s)); - - - //init TrafficMovement - this->simulator = std::make_shared<TrafficMovement>(move(roadNetwork), dawdlePossibility); - simulator->setSlowToStart(slowToStartPossibility); - simulator->setMaxAcceleration(2); - - - ////init ConcentrationOutwriter - //std::unique_ptr<ConcentrationOutwriter> writer = std::make_unique<ConcBySpeedAndAcceleration>(ConcBySpeedAndAcceleration(simulator->getRoadLength(), pconcArrayStart)); - //simulator->setConcentrationOutwriter(move(writer)); -} - -void TrafficMovementFactoryTest::calculateTimestep(uint step, uint stepForVTK) -{ - simulator->calculateTimestep(step); -} - -void TrafficMovementFactoryTest::loopThroughTimesteps(uint timeSteps) -{ - simulator->setSaveResultsTrue(timeSteps); - simulator->loopTroughTimesteps(timeSteps); -} +//#include "TrafficMovementFactoryTest.h" +// +//#include <iostream> +// +//#include "GridGenerator/StreetPointFinder/JunctionReader.h" +//#include "GridGenerator/StreetPointFinder/SourceReader.h" +//#include "GridGenerator/StreetPointFinder/SinkReader.h" +// +//#include "RoadNetwork/RoadMaker.h" +//#include "TrafficMovement.h" +//#include "Source/SourceRandom.h" +//#include "Junction/JunctionRandom.h" +//#include "Sink/SinkRandom.h" +//#include "Output/ConcentrationByPosition.h" +//#include "Output/ConcBySpeedAndAcceleration.h" +//#include "Utilities/safe_casting.h" +// +// +//void TrafficMovementFactoryTest::initTrafficMovement(real * pconcArrayStart) +//{ +// //Variables +// +// real vehicleDensity = 0.1f; +// +// const uint maxVelocity = 14; +// real dawdlePossibility = (real) 0.2; //typical value: 0.2 +// real slowToStartPossibility = (real) 0.4; +// +// uint vehicleLength = 7; +// +// uint roadLength = 10; +// +// +// //make RoadNetwork +// auto roadNetwork = std::make_unique<RoadMaker>(roadLength, maxVelocity, vehicleLength, vehicleDensity); +// +// +// //Sources +// std::unique_ptr<Source> source = std::make_unique <SourceRandom>(SourceRandom(0, 0.7f, maxVelocity)); +// roadNetwork->addSource(source); +// +// +// //Sinks +// std::unique_ptr<Sink> s = std::make_unique <SinkRandom>(SinkRandom(9, 0.5f)); +// roadNetwork->addSink(move(s)); +// +// +// //init TrafficMovement +// this->simulator = std::make_shared<TrafficMovement>(move(roadNetwork), dawdlePossibility); +// simulator->setSlowToStart(slowToStartPossibility); +// simulator->setMaxAcceleration(2); +// +// +// ////init ConcentrationOutwriter +// //std::unique_ptr<ConcentrationOutwriter> writer = std::make_unique<ConcBySpeedAndAcceleration>(ConcBySpeedAndAcceleration(simulator->getRoadLength(), pconcArrayStart)); +// //simulator->setConcentrationOutwriter(move(writer)); +//} +// +//void TrafficMovementFactoryTest::calculateTimestep(uint step, uint stepForVTK) +//{ +// simulator->calculateTimestep(step); +//} +// +//void TrafficMovementFactoryTest::loopThroughTimesteps(uint timeSteps) +//{ +// simulator->setSaveResultsTrue(timeSteps); +// simulator->loopTroughTimesteps(timeSteps); +//} diff --git a/src/Traffic/TrafficMovementFactoryTest.h b/src/Traffic/TrafficMovementFactoryTest.h index 77df69e16..846702949 100644 --- a/src/Traffic/TrafficMovementFactoryTest.h +++ b/src/Traffic/TrafficMovementFactoryTest.h @@ -1,21 +1,21 @@ -# pragma once - -//#include <VirtualFluidsDefinitions.h> -#include "TrafficMovementFactoryImpl.h" - -#include <vector> -#include <memory> - -#include "Core/DataTypes.h" -#include "GridGenerator/StreetPointFinder/StreetPointFinder.h" - - -class VF_PUBLIC TrafficMovementFactoryTest: -public TrafficMovementFactoryImpl{ -public: - TrafficMovementFactoryTest() {}; - ~TrafficMovementFactoryTest() {}; - virtual void initTrafficMovement(real * pconcArrayStart = nullptr); - virtual void calculateTimestep(uint step, uint stepForVTK); - void loopThroughTimesteps(uint timeSteps); -}; \ No newline at end of file +//# pragma once +// +////#include <VirtualFluidsDefinitions.h> +//#include "TrafficMovementFactoryImpl.h" +// +//#include <vector> +//#include <memory> +// +//#include "Core/DataTypes.h" +//#include "GridGenerator/StreetPointFinder/StreetPointFinder.h" +// +// +//class VF_PUBLIC TrafficMovementFactoryTest: +//public TrafficMovementFactoryImpl{ +//public: +// TrafficMovementFactoryTest() {}; +// ~TrafficMovementFactoryTest() {}; +// virtual void initTrafficMovement(real * pconcArrayStart = nullptr); +// virtual void calculateTimestep(uint step, uint stepForVTK); +// void loopThroughTimesteps(uint timeSteps); +//}; \ No newline at end of file diff --git a/targets/apps/LBM/TrafficTest/TrafficTest.cpp b/targets/apps/LBM/TrafficTest/TrafficTest.cpp index f6dbc40b7..681cd350c 100644 --- a/targets/apps/LBM/TrafficTest/TrafficTest.cpp +++ b/targets/apps/LBM/TrafficTest/TrafficTest.cpp @@ -7,44 +7,60 @@ #include "Traffic/TrafficMovementFactoryImpl.h" -#include "TrafficMovementFactoryTest.h" +//#include "Traffic/TrafficMovementFactoryTest.h" int main() { - //{uint numberOfTimesteps = 30; + {uint numberOfTimesteps = 2; + + //Logger + logging::Logger::addStream(&std::cout); + logging::Logger::setDebugLevel(logging::Logger::Level::INFO_LOW); + logging::Logger::timeStamp(logging::Logger::ENABLE); + logging::Logger::enablePrintedRankNumbers(logging::Logger::ENABLE); + + + TrafficMovementFactory * factory = new TrafficMovementFactoryImpl(); + factory->initTrafficMovement(); + + for (uint step = 1; step <= numberOfTimesteps; step++) { + factory->calculateTimestep(step, step); + } + + std::cout << std::endl << std::endl; } + - ////Logger - //logging::Logger::addStream(&std::cout); - //logging::Logger::setDebugLevel(logging::Logger::Level::INFO_LOW); - //logging::Logger::timeStamp(logging::Logger::ENABLE); - //logging::Logger::enablePrintedRankNumbers(logging::Logger::ENABLE); - //TrafficMovementFactory * factory = new TrafficMovementFactoryImpl(); - //factory->initTrafficMovement(); - //for (uint step = 1; step <= numberOfTimesteps; step++) { - // factory->calculateTimestep(step,step); - //} - //std::cout << std::endl << std::endl;} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - {uint numberOfTimesteps = 20; + //{uint numberOfTimesteps = 20; - TrafficMovementFactoryTest * factory = new TrafficMovementFactoryTest(); - factory->initTrafficMovement(); - factory->loopThroughTimesteps(numberOfTimesteps); + //TrafficMovementFactoryTest * factory = new TrafficMovementFactoryTest(); + //factory->initTrafficMovement(); + //factory->loopThroughTimesteps(numberOfTimesteps); - std::cout << std::endl << std::endl; } + //std::cout << std::endl << std::endl; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + + + + + + + + + //std::vector<int> oneCar = { -1,1,-1,-1,-1,-1 }; //std::vector<int> fiveCars = { 1, -1,-1, 1, -1, -1, -1, -1, 1, -1,-1,-1,-1,0,-1,-1,1,-1,-1,-1 }; //int roadLength = 20; diff --git a/targets/libs/Traffic/3rdPartyLinking.cmake b/targets/libs/Traffic/3rdPartyLinking.cmake index 0c6183ae8..e7057893a 100644 --- a/targets/libs/Traffic/3rdPartyLinking.cmake +++ b/targets/libs/Traffic/3rdPartyLinking.cmake @@ -1,5 +1,5 @@ -#include (${CMAKE_SOURCE_DIR}/${cmakeMacroPath}/Cuda/Link.cmake) -#linkCuda(${targetName}) +include (${CMAKE_SOURCE_DIR}/${cmakeMacroPath}/Cuda/Link.cmake) +linkCuda(${targetName}) #include (${CMAKE_SOURCE_DIR}/${cmakeMacroPath}/MPI/Link.cmake) #linkMPI(${targetName}) #include (${CMAKE_SOURCE_DIR}/${cmakeMacroPath}/Boost/Link.cmake) -- GitLab