├── main ├── Euler ├── EulerMaterialParameters.hpp ├── EulerMaterialParameters.cpp ├── EulerEquationOfState.hpp ├── EulerEquationOfState.cpp ├── EulerStateVector.hpp └── EulerStateVector.cpp ├── Mathematics ├── VectorAlgebra.hpp ├── MatrixAlgebra.hpp ├── VectorAlgebra.cpp └── MatrixAlgebra.cpp ├── AMR ├── AMRHelper.hpp ├── AMRHelper.cpp ├── EulerAMR.hpp ├── RelativisticEulerAMR.hpp └── BlackHoleEulerAMR.hpp ├── RelativisticEuler ├── RelativisticEulerEquationOfState.hpp ├── RelativisticEulerEquationOfState.cpp └── RelativisticEulerStateVector.hpp ├── Tests ├── RelativisticEulerTests.hpp ├── EulerTests.hpp ├── BlackHoleEulerTests.hpp ├── BlackHoleEulerAMRTests.hpp ├── RelativisticEulerAMRTests.hpp ├── EulerAMRTests.hpp ├── EulerTests.cpp ├── RelativisticEulerTests.cpp └── BlackHoleEulerTests.cpp ├── BlackHoleEuler ├── BlackHoleEulerEigenvalues.hpp ├── BlackHoleEulerStateVector.hpp ├── BlackHoleSpacetime.hpp └── BlackHoleEulerEigenvalues.cpp ├── Solvers ├── BlackHoleEulerForcingSolver.hpp ├── EulerSecondOrderSolver.hpp ├── RelativisticEulerSecondOrderSolver.hpp ├── SlopeLimiters.hpp ├── RelativisticEulerSolvers.hpp ├── BlackHoleEulerSecondOrderSolver.hpp ├── EulerSolvers.hpp ├── RelativisticEulerFirstOrderSolver.hpp ├── EulerFirstOrderSolver.hpp ├── BlackHoleEulerFirstOrderSolver.hpp ├── BlackHoleEulerSolvers.hpp ├── SlopeLimiters.cpp ├── EulerSecondOrderSolver.cpp ├── RelativisticEulerSolvers.cpp ├── EulerSolvers.cpp ├── RelativisticEulerSecondOrderSolver.cpp ├── RelativisticEulerFirstOrderSolver.cpp └── EulerFirstOrderSolver.cpp └── main.cpp /main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JonathanGorard/Cosmos/HEAD/main -------------------------------------------------------------------------------- /Euler/EulerMaterialParameters.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerMaterialParameters_hpp 2 | #define EulerMaterialParameters_hpp 3 | 4 | class EulerMaterialParameters 5 | { 6 | public: 7 | EulerMaterialParameters(); 8 | EulerMaterialParameters(double newAdiabaticIndex); 9 | 10 | void setAdiabaticIndex(double newAdiabaticIndex); 11 | 12 | double getAdiabaticIndex(); 13 | 14 | private: 15 | double adiabaticIndex; 16 | double stiffeningParameter; 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Mathematics/VectorAlgebra.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VectorAlgebra_hpp 2 | #define VectorAlgebra_hpp 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class VectorAlgebra 9 | { 10 | public: 11 | static vector addVectors(vector vector1, vector vector2); 12 | static vector subtractVectors(vector vector1, vector vector2); 13 | 14 | static vector multiplyVector(double scalar1, vector vector1); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /AMR/AMRHelper.hpp: -------------------------------------------------------------------------------- 1 | #ifndef AMRHelper_hpp 2 | #define AMRHelper_hpp 3 | 4 | #include "../Solvers/EulerFirstOrderSolver.hpp" 5 | 6 | class AMRHelper 7 | { 8 | public: 9 | static void outputCoarseStatus(int coarseCurrentIteration, double coarseCurrentTime, double coarseTimeStep); 10 | static void outputIntermediateStatus(int intermediateCurrentIteration, double intermediateCurrentTime, double intermediateTimeStep); 11 | static void outputFineStatus(int fineCurrentIteration, double fineCurrentTime, double fineTimeStep); 12 | }; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /Euler/EulerMaterialParameters.cpp: -------------------------------------------------------------------------------- 1 | #include "EulerMaterialParameters.hpp" 2 | 3 | EulerMaterialParameters::EulerMaterialParameters() 4 | { 5 | adiabaticIndex = 1.0; 6 | } 7 | 8 | EulerMaterialParameters::EulerMaterialParameters(double newAdiabaticIndex) 9 | { 10 | adiabaticIndex = newAdiabaticIndex; 11 | } 12 | 13 | void EulerMaterialParameters::setAdiabaticIndex(double newAdiabaticIndex) 14 | { 15 | adiabaticIndex = newAdiabaticIndex; 16 | } 17 | 18 | double EulerMaterialParameters::getAdiabaticIndex() 19 | { 20 | return adiabaticIndex; 21 | } 22 | -------------------------------------------------------------------------------- /RelativisticEuler/RelativisticEulerEquationOfState.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RelativisticEulerEquationOfState_hpp 2 | #define RelativisticEulerEquationOfState_hpp 3 | 4 | #include "../Euler/EulerMaterialParameters.hpp" 5 | #include 6 | using namespace std; 7 | 8 | class RelativisticEulerEquationOfState 9 | { 10 | public: 11 | static double computeSpecificEnthalpy(double density, double pressure, EulerMaterialParameters materialParameters); 12 | static double computeSoundSpeed(double density, double pressure, EulerMaterialParameters materialParameters); 13 | }; 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /Euler/EulerEquationOfState.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerEquationOfState_hpp 2 | #define EulerEquationOfState_hpp 3 | 4 | #include "EulerMaterialParameters.hpp" 5 | #include 6 | using namespace std; 7 | 8 | class EulerEquationOfState 9 | { 10 | public: 11 | static double computeSpecificInternalEnergy(double density, double pressure, EulerMaterialParameters materialParameters); 12 | static double computePressure(double density, double specificInternalEnergy, EulerMaterialParameters materialParameters); 13 | static double computeSoundSpeed(double density, double pressure, EulerMaterialParameters materialParameters); 14 | }; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /RelativisticEuler/RelativisticEulerEquationOfState.cpp: -------------------------------------------------------------------------------- 1 | #include "RelativisticEulerEquationOfState.hpp" 2 | 3 | double RelativisticEulerEquationOfState::computeSpecificEnthalpy(double density, double pressure, EulerMaterialParameters materialParameters) 4 | { 5 | double adiabaticIndex = materialParameters.getAdiabaticIndex(); 6 | 7 | return 1.0 + ((pressure / density) * (adiabaticIndex / (adiabaticIndex - 1.0))); 8 | } 9 | 10 | double RelativisticEulerEquationOfState::computeSoundSpeed(double density, double pressure, EulerMaterialParameters materialParameters) 11 | { 12 | double adiabaticIndex = materialParameters.getAdiabaticIndex(); 13 | 14 | double numerator = (adiabaticIndex * pressure) / density; 15 | double denominator = 1.0 + ((pressure / density) * (adiabaticIndex / (adiabaticIndex - 1.0))); 16 | 17 | return sqrt(numerator / denominator); 18 | } 19 | -------------------------------------------------------------------------------- /AMR/AMRHelper.cpp: -------------------------------------------------------------------------------- 1 | #include "AMRHelper.hpp" 2 | 3 | void AMRHelper::outputCoarseStatus(int coarseCurrentIteration, double coarseCurrentTime, double timeStep) 4 | { 5 | cout << "Coarse Grid Iteration = " << coarseCurrentIteration << "; Time = " << coarseCurrentTime << "; Timestep = " << timeStep << endl; 6 | } 7 | 8 | void AMRHelper::outputIntermediateStatus(int intermediateCurrentIteration, double intermediateCurrentTime, double intermediateTimeStep) 9 | { 10 | cout << " Refinement Level 1 Iteration = " << intermediateCurrentIteration << "; Time = " << intermediateCurrentTime 11 | << "; Timestep = " << intermediateTimeStep << endl; 12 | } 13 | 14 | void AMRHelper::outputFineStatus(int fineCurrentIteration, double fineCurrentTime, double fineTimeStep) 15 | { 16 | cout << " Refinement Level 2 Iteration = " << fineCurrentIteration << "; Time = " << fineCurrentTime << "; Timestep = " << fineTimeStep << endl; 17 | } 18 | -------------------------------------------------------------------------------- /Euler/EulerEquationOfState.cpp: -------------------------------------------------------------------------------- 1 | #include "EulerEquationOfState.hpp" 2 | 3 | double EulerEquationOfState::computeSpecificInternalEnergy(double density, double pressure, EulerMaterialParameters materialParameters) 4 | { 5 | double adiabaticIndex = materialParameters.getAdiabaticIndex(); 6 | 7 | return pressure / ((adiabaticIndex - 1.0) * density); 8 | } 9 | 10 | double EulerEquationOfState::computePressure(double density, double specificInternalEnergy, EulerMaterialParameters materialParameters) 11 | { 12 | double adiabaticIndex = materialParameters.getAdiabaticIndex(); 13 | 14 | return specificInternalEnergy * (adiabaticIndex - 1.0) * density; 15 | } 16 | 17 | double EulerEquationOfState::computeSoundSpeed(double density, double pressure, EulerMaterialParameters materialParameters) 18 | { 19 | double adiabaticIndex = materialParameters.getAdiabaticIndex(); 20 | 21 | return sqrt((adiabaticIndex * pressure) / density); 22 | } 23 | -------------------------------------------------------------------------------- /Tests/RelativisticEulerTests.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RelativisticEulerTests_hpp 2 | #define RelativisticEulerTests_hpp 3 | 4 | #include "../Solvers/RelativisticEulerFirstOrderSolver.hpp" 5 | #include "../Solvers/RelativisticEulerSecondOrderSolver.hpp" 6 | #include 7 | using namespace std; 8 | 9 | class RelativisticEulerTests 10 | { 11 | public: 12 | static void solveMildlyRelativisticShock(int cellCount, int order); 13 | static void solveStronglyRelativisticBlast(int cellCount, int order); 14 | static void solvePerturbedDensityTest(int cellCount, int order); 15 | 16 | static void solve2DMildlyRelativisticShock(int cellCount, int order); 17 | static void solve2DStronglyRelativisticBlast(int cellCount, int order); 18 | static void solve2DPerturbedDensityTest(int cellCount, int order); 19 | 20 | static void outputSolution(vector solution); 21 | static void outputSolution2D(vector > solution); 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Mathematics/MatrixAlgebra.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MatrixAlgebra_hpp 2 | #define MatrixAlgebra_hpp 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class MatrixAlgebra 9 | { 10 | public: 11 | static vector > computeIdentityMatrix(int matrixDimension); 12 | 13 | static vector > addMatrices(vector > matrix1, vector > matrix2); 14 | static vector > subtractMatrices(vector > matrix1, vector > matrix2); 15 | static vector > multiplyMatrix(double scalar1, vector > matrix1); 16 | static vector > multiplyMatrices(vector > matrix1, vector > matrix2); 17 | 18 | static double computeMatrixTrace(vector > matrix1); 19 | static double computeMatrixDeterminant(vector > matrix1); 20 | 21 | static vector > computeMatrixInverse(vector > matrix1); 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Mathematics/VectorAlgebra.cpp: -------------------------------------------------------------------------------- 1 | #include "VectorAlgebra.hpp" 2 | 3 | vector VectorAlgebra::addVectors(vector vector1, vector vector2) 4 | { 5 | long componentCount = vector1.size(); 6 | vector sumVector(componentCount); 7 | 8 | #pragma omp parallel for 9 | for (int i = 0; i < componentCount; i++) 10 | { 11 | sumVector[i] = vector1[i] + vector2[i]; 12 | } 13 | 14 | return sumVector; 15 | } 16 | 17 | vector VectorAlgebra::subtractVectors(vector vector1, vector vector2) 18 | { 19 | return addVectors(vector1, multiplyVector(-1.0, vector2)); 20 | } 21 | 22 | vector VectorAlgebra::multiplyVector(double scalar1, vector vector1) 23 | { 24 | long componentCount = vector1.size(); 25 | vector productVector(componentCount); 26 | 27 | #pragma omp parallel for 28 | for (int i = 0; i < componentCount; i++) 29 | { 30 | productVector[i] = scalar1 * vector1[i]; 31 | } 32 | 33 | return productVector; 34 | } 35 | -------------------------------------------------------------------------------- /Tests/EulerTests.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerTests_hpp 2 | #define EulerTests_hpp 3 | 4 | #include "../Solvers/EulerFirstOrderSolver.hpp" 5 | #include "../Solvers/EulerSecondOrderSolver.hpp" 6 | #include 7 | using namespace std; 8 | 9 | class EulerTests 10 | { 11 | public: 12 | static void solveToroTest1(int cellCount, int order); 13 | static void solveToroTest2(int cellCount, int order); 14 | static void solveToroTest3(int cellCount, int order); 15 | static void solveToroTest4(int cellCount, int order); 16 | static void solveToroTest5(int cellCount, int order); 17 | 18 | static void solve2DToroTest1(int cellCount, int order); 19 | static void solve2DToroTest2(int cellCount, int order); 20 | static void solve2DToroTest3(int cellCount, int order); 21 | static void solve2DToroTest4(int cellCount, int order); 22 | static void solve2DToroTest5(int cellCount, int order); 23 | 24 | static void outputSolution(vector solution); 25 | static void outputSolution2D(vector > solution); 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Tests/BlackHoleEulerTests.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerTests_hpp 2 | #define BlackHoleEulerTests_hpp 3 | 4 | #include "../Solvers/BlackHoleEulerFirstOrderSolver.hpp" 5 | #include "../Solvers/BlackHoleEulerSecondOrderSolver.hpp" 6 | 7 | #include 8 | using namespace std; 9 | 10 | class BlackHoleEulerTests 11 | { 12 | public: 13 | static void solve1DSphericalAccretionTest(int cellCount, int order, int subcyclingIterations); 14 | static void solve1DSpinningSphericalAccretionTest(int cellCount, int order, int subcyclingIterations); 15 | 16 | static void solve2DSphericalAccretionTest(int cellCount, int order, int subcyclingIterations); 17 | static void solve2DSpinningSphericalAccretionTest(int cellCount, int order, int subcyclingIterations); 18 | 19 | static void solve2DSpheroidalAccretionTest(int cellCount, int order, int subcyclingIterations); 20 | static void solve2DSpinningSpheroidalAccretionTest(int cellCount, int order, int subcyclingIterations); 21 | 22 | static void outputSolution(vector solution, BlackHoleSpacetime blackHole); 23 | static void outputSolution2D(vector > solution, BlackHoleSpacetime blackHole); 24 | }; 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /BlackHoleEuler/BlackHoleEulerEigenvalues.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerEigenvalues_hpp 2 | #define BlackHoleEulerEigenvalues_hpp 3 | 4 | #include "BlackHoleSpacetime.hpp" 5 | #include "../RelativisticEuler/RelativisticEulerEquationOfState.hpp" 6 | #include "../Mathematics/VectorAlgebra.hpp" 7 | 8 | class BlackHoleEulerEigenvalues 9 | { 10 | public: 11 | static vector computeMaterialWaveEigenvalues(double xCoordinate, double yCoordinate, double zCoordinate, double xVelocity, double yVelocity, 12 | double zVelocity, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 13 | 14 | static vector computeFastAcousticWaveEigenvalues(double xCoordinate, double yCoordinate, double zCoordinate, double density, double pressure, 15 | double xVelocity, double yVelocity, double zVelocity, EulerMaterialParameters materialParameters, 16 | BlackHoleSpacetime blackHole); 17 | static vector computeSlowAcousticWaveEigenvalues(double xCoordinate, double yCoordinate, double zCoordinate, double density, double pressure, 18 | double xVelocity, double yVelocity, double zVelocity, EulerMaterialParameters materialParameters, 19 | BlackHoleSpacetime blackHole); 20 | }; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Tests/BlackHoleEulerAMRTests.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerAMRTests_hpp 2 | #define BlackHoleEulerAMRTests_hpp 3 | 4 | #include "../AMR/BlackHoleEulerAMR.hpp" 5 | #include 6 | using namespace std; 7 | 8 | class BlackHoleEulerAMRTests 9 | { 10 | public: 11 | static void solve1DSphericalAccretionTest(int cellCount, int order, int subcyclingIterations, double AMRTolerance, int AMRLevel); 12 | static void solve1DSpinningSphericalAccretionTest(int cellCount, int order, int subcyclingIterations, double AMRTolerance, int AMRLevel); 13 | 14 | static void solve2DSphericalAccretionTest(int cellCount, int order, int subcyclingIterations, double AMRTolerance, int AMRLevel); 15 | static void solve2DSpinningSphericalAccretionTest(int cellCount, int order, int subcyclingIterations, double AMRTolerance, int AMRLevel); 16 | 17 | static void solve2DSpheroidalAccretionTest(int cellCount, int order, int subcyclingIterations, double AMRTolerance, int AMRLevel); 18 | static void solve2DSpinningSpheroidalAccretionTest(int cellCount, int order, int subcyclingIterations, double AMRTolerance, int AMRLevel); 19 | 20 | static void outputSolutionLevel1AMR(tuple, vector, vector, vector> solution, 21 | BlackHoleSpacetime blackHole); 22 | static void outputSolutionLevel2AMR(tuple, vector, vector, 23 | vector, vector, vector> solution, BlackHoleSpacetime blackHole); 24 | 25 | static void outputSolution2DLevel1AMR(tuple >, vector >, vector >, 26 | vector >> solution, BlackHoleSpacetime spacetime); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Tests/RelativisticEulerAMRTests.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RelativisticEulerAMRTests_hpp 2 | #define RelativisticEulerAMRTests_hpp 3 | 4 | #include "../AMR/RelativisticEulerAMR.hpp" 5 | #include 6 | using namespace std; 7 | 8 | class RelativisticEulerAMRTests 9 | { 10 | public: 11 | static void solveMildlyRelativisticShock(int cellCount, int order, double AMRTolerance, int AMRLevel); 12 | static void solveStronglyRelativisticBlast(int cellCount, int order, double AMRTolerance, int AMRLevel); 13 | static void solvePerturbedDensityTest(int cellCount, int order, double AMRTolerance, int AMRLevel); 14 | 15 | static void solve2DMildlyRelativisticShock(int cellCount, int order, double AMRTolerance, int AMRLevel); 16 | static void solve2DStronglyRelativisticBlast(int cellCount, int order, double AMRTolerance, int AMRLevel); 17 | static void solve2DPerturbedDensityTest(int cellCount, int order, double AMRTolerance, int AMRLevel); 18 | 19 | static void outputSolutionLevel1AMR(tuple, vector, vector, vector> solution); 20 | static void outputSolutionLevel2AMR(tuple, vector, vector, 21 | vector, vector, vector> solution); 22 | 23 | static void outputSolution2DLevel1AMR(tuple >, vector >, vector >, 24 | vector >> solution); 25 | static void outputSolution2DLevel2AMR(tuple >, vector >, 26 | vector >, vector >, vector >, vector >> solution); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /RelativisticEuler/RelativisticEulerStateVector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RelativisticEulerStateVector_hpp 2 | #define RelativisticEulerStateVector_hpp 3 | 4 | #include "RelativisticEulerEquationOfState.hpp" 5 | #include 6 | using namespace std; 7 | 8 | class RelativisticEulerStateVector 9 | { 10 | public: 11 | RelativisticEulerStateVector(); 12 | RelativisticEulerStateVector(double newDensity, double newXVelocity, double newYVelocity, double newZVelocity, double newPressure); 13 | 14 | void setPrimitiveVariableVector(vector newPrimitiveVariableVector); 15 | void setConservedVariableVector(vector newConservedVariableVector, EulerMaterialParameters materialParameters); 16 | 17 | vector computePrimitiveVariableVector(); 18 | vector computeConservedVariableVector(EulerMaterialParameters materialParameters); 19 | 20 | static vector computeXFluxVector(vector conservedVariableVector, EulerMaterialParameters materialParameters); 21 | vector computeXFluxVector(EulerMaterialParameters materialParameters); 22 | 23 | static vector computeYFluxVector(vector conservedVariableVector, EulerMaterialParameters materialParameters); 24 | vector computeYFluxVector(EulerMaterialParameters materialParameters); 25 | 26 | double computeSoundSpeed(EulerMaterialParameters materialParameters); 27 | 28 | void setDensity(double newDensity); 29 | void setXVelocity(double newXVelocity); 30 | void setYVelocity(double newYVelocity); 31 | void setZVelocity(double newZVelocity); 32 | void setPressure(double newPressure); 33 | 34 | double getDensity(); 35 | double getXVelocity(); 36 | double getYVelocity(); 37 | double getZVelocity(); 38 | double getPressure(); 39 | 40 | private: 41 | double density; 42 | double xVelocity; 43 | double yVelocity; 44 | double zVelocity; 45 | double pressure; 46 | }; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Euler/EulerStateVector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerStateVector_hpp 2 | #define EulerStateVector_hpp 3 | 4 | #include "EulerEquationOfState.hpp" 5 | #include 6 | using namespace std; 7 | 8 | class EulerStateVector 9 | { 10 | public: 11 | EulerStateVector(); 12 | EulerStateVector(double newDensity, double newXVelocity, double newYVelocity, double newZVelocity, double newPressure); 13 | 14 | void setPrimitiveVariableVector(vector newPrimitiveVariableVector); 15 | void setConservedVariableVector(vector newConservedVariableVector, EulerMaterialParameters materialParameters); 16 | 17 | vector computePrimitiveVariableVector(); 18 | vector computeConservedVariableVector(EulerMaterialParameters materialParameters); 19 | 20 | static vector computeXFluxVector(vector conservedVariableVector, EulerMaterialParameters materialParameters); 21 | vector computeXFluxVector(EulerMaterialParameters materialParameters); 22 | 23 | static vector computeYFluxVector(vector conservedVariableVector, EulerMaterialParameters materialParameters); 24 | vector computeYFluxVector(EulerMaterialParameters materialParameters); 25 | 26 | double computeSpecificInternalEnergy(EulerMaterialParameters materialParameters); 27 | double computeTotalEnergy(EulerMaterialParameters materialParameters); 28 | double computeSoundSpeed(EulerMaterialParameters materialParameters); 29 | 30 | void setDensity(double newDensity); 31 | void setXVelocity(double newXVelocity); 32 | void setYVelocity(double newYVelocity); 33 | void setZVelocity(double newZVelocity); 34 | void setPressure(double newPressure); 35 | 36 | double getDensity(); 37 | double getXVelocity(); 38 | double getYVelocity(); 39 | double getZVelocity(); 40 | double getPressure(); 41 | 42 | private: 43 | double density; 44 | double xVelocity; 45 | double yVelocity; 46 | double zVelocity; 47 | double pressure; 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Tests/EulerAMRTests.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerAMRTests_hpp 2 | #define EulerAMRTests_hpp 3 | 4 | #include "../AMR/EulerAMR.hpp" 5 | #include 6 | using namespace std; 7 | 8 | class EulerAMRTests 9 | { 10 | public: 11 | static void solveToroTest1AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 12 | static void solveToroTest2AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 13 | static void solveToroTest3AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 14 | static void solveToroTest4AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 15 | static void solveToroTest5AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 16 | 17 | static void solve2DToroTest1AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 18 | static void solve2DToroTest2AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 19 | static void solve2DToroTest3AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 20 | static void solve2DToroTest4AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 21 | static void solve2DToroTest5AMR(int cellCount, int order, double AMRTolerance, int AMRLevel); 22 | 23 | static void outputSolutionLevel1AMR(tuple, vector, vector, vector> solution); 24 | static void outputSolutionLevel2AMR(tuple, vector, vector, vector, vector, 25 | vector> solution); 26 | 27 | static void outputSolution2DLevel1AMR(tuple >, vector >, vector >, vector >> solution); 28 | static void outputSolution2DLevel2AMR(tuple >, vector >, vector >, 29 | vector >, vector >, vector >> solution); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Solvers/BlackHoleEulerForcingSolver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerForcingSolver_hpp 2 | #define BlackHoleEulerForcingSolver_hpp 3 | 4 | #include "BlackHoleEulerSolvers.hpp" 5 | 6 | class BlackHoleEulerForcingSolver 7 | { 8 | public: 9 | static vector evolveConservedVariableVector(vector leftConservedVariableVector, vector middleConservedVariableVector, 10 | vector rightConservedVaraibleVector, double xCoordinate, double yCoordinate, double zCoordinate, 11 | double cellSpacing, double timeStep, double bias, int slopeLimiter, EulerMaterialParameters materialParameters, 12 | BlackHoleSpacetime blackHole); 13 | static vector evolveConservedVariableVector2D(vector leftConservedVariableVector, vector middleConservedVariableVector, 14 | vector rightConservedVariableVector, vector topConservedVariableVector, 15 | vector bottomConservedVariableVector, double xCoordinate, double yCoordinate, double zCoordinate, 16 | double cellSpacing, double timeStep, double bias, int slopeLimiter, 17 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 18 | 19 | static void computeRungeKuttaTimeStep(vector & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 20 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 21 | static void computeRungeKuttaTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, 22 | int slopeLimiter, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Solvers/EulerSecondOrderSolver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerSecondOrderSolver_hpp 2 | #define EulerSecondOrderSolver_hpp 3 | 4 | #include "EulerFirstOrderSolver.hpp" 5 | 6 | class EulerSecondOrderSolver 7 | { 8 | public: 9 | static vector computeXSLICFlux(EulerStateVector leftLeftStateVector, EulerStateVector leftStateVector, EulerStateVector rightStateVector, 10 | EulerStateVector rightRightStateVector, double cellSpacing, double timeStep, double bias, int slopeLimiter, 11 | EulerMaterialParameters materialParameters); 12 | static vector computeYSLICFlux(EulerStateVector topTopStateVector, EulerStateVector topStateVector, EulerStateVector bottomStateVector, 13 | EulerStateVector bottomBottomStateVector, double cellSpacing, double timeStep, double bias, int slopeLimiter, 14 | EulerMaterialParameters materialParameters); 15 | 16 | static void computeSLICTimeStep(vector & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 17 | EulerMaterialParameters materialParameters); 18 | 19 | static void computeXSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 20 | EulerMaterialParameters materialParameters); 21 | static void computeYSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 22 | EulerMaterialParameters materialParameters); 23 | 24 | static vector solve(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double bias, 25 | int slopeLimiter, EulerMaterialParameters materialParameters); 26 | 27 | static vector > solve2D(vector > initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 28 | double bias, int slopeLimiter, EulerMaterialParameters materialParameters); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Solvers/RelativisticEulerSecondOrderSolver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RelativisticEulerSecondOrderSolver_hpp 2 | #define RelativisticEulerSecondOrderSolver_hpp 3 | 4 | #include "RelativisticEulerFirstOrderSolver.hpp" 5 | 6 | class RelativisticEulerSecondOrderSolver 7 | { 8 | public: 9 | static vector computeXSLICFlux(RelativisticEulerStateVector leftLeftStateVector, RelativisticEulerStateVector leftStateVector, 10 | RelativisticEulerStateVector rightStateVector, RelativisticEulerStateVector rightRightStateVector, double cellSpacing, 11 | double timeStep, double bias, int slopeLimiter, EulerMaterialParameters materialParameters); 12 | static vector computeYSLICFlux(RelativisticEulerStateVector topTopStateVector, RelativisticEulerStateVector topStateVector, 13 | RelativisticEulerStateVector bottomStateVector, RelativisticEulerStateVector bottomBottomStateVector, double cellSpacing, 14 | double timeStep, double bias, int slopeLimiter, EulerMaterialParameters materialParameters); 15 | 16 | static void computeSLICTimeStep(vector & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 17 | EulerMaterialParameters materialParameters); 18 | 19 | static void computeXSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, 20 | int slopeLimiter, EulerMaterialParameters materialParameters); 21 | static void computeYSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, 22 | int slopeLimiter, EulerMaterialParameters materialParameters); 23 | 24 | static vector solve(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 25 | double bias, int slopeLimiter, EulerMaterialParameters materialParameters); 26 | 27 | static vector > solve2D(vector > initialCells, double cellSpacing, double CFLCoefficient, 28 | double finalTime, double bias, int slopeLimiter, EulerMaterialParameters materialParameters); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Solvers/SlopeLimiters.hpp: -------------------------------------------------------------------------------- 1 | #ifndef SlopeLimiters_hpp 2 | #define SlopeLimiters_hpp 3 | 4 | #include "../Euler/EulerStateVector.hpp" 5 | #include "../RelativisticEuler/RelativisticEulerStateVector.hpp" 6 | #include "../BlackHoleEuler/BlackHoleEulerStateVector.hpp" 7 | #include "../Mathematics/VectorAlgebra.hpp" 8 | #include "/usr/local/include/omp.h" 9 | 10 | class SlopeLimiters 11 | { 12 | public: 13 | 14 | static double computeGradientRatio(double steepness, double bias); 15 | 16 | static double computeSuperBeeSlopeLimiter(double steepness, double bias); 17 | static double computeVanLeerSlopeLimiter(double steepness, double bias); 18 | static double computeMinBeeSlopeLimiter(double steepness, double bias); 19 | 20 | static double computeSlopeLimiter(double steepness, double bias, int slopeLimiter); 21 | 22 | static vector computeSlopeVector(vector leftConservedVariableVector, vector middleConservedVariableVector, 23 | vector rightConservedVariableVector, double bias, int slopeLimiter); 24 | static vector computeSlopeVector(EulerStateVector leftStateVector, EulerStateVector middleSttaeVector, EulerStateVector rightStateVector, double bias, 25 | int slopeLimiter, EulerMaterialParameters materialParameters); 26 | static vector computeSlopeVector(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector middleStateVector, 27 | RelativisticEulerStateVector rightStateVector, double bias, int slopeLimiter, EulerMaterialParameters materialParameters); 28 | 29 | static vector computeSlopeVectorX(BlackHoleEulerStateVector leftStateVector, BlackHoleEulerStateVector middleStateVector, 30 | BlackHoleEulerStateVector rightStateVector, double cellSpacing, double bias, int slopeLimiter, double xCoordinate, 31 | double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 32 | static vector computeSlopeVectorY(BlackHoleEulerStateVector topStateVector, BlackHoleEulerStateVector middleStateVector, 33 | BlackHoleEulerStateVector bottomStateVector, double cellSpacing, double bias, int slopeLimiter, double xCoordinate, 34 | double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Tests/EulerTests.hpp" 4 | #include "Tests/EulerAMRTests.hpp" 5 | #include "Tests/RelativisticEulerTests.hpp" 6 | #include "Tests/RelativisticEulerAMRTests.hpp" 7 | #include "Tests/BlackHoleEulerTests.hpp" 8 | #include "Tests/BlackHoleEulerAMRTests.hpp" 9 | 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | //EulerTests::solveToroTest1(800, 2); 15 | //EulerTests::solveToroTest2(800, 2); 16 | //EulerTests::solveToroTest3(2000, 2); 17 | //EulerTests::solve2DToroTest1(200, 2); 18 | //EulerTests::solve2DToroTest2(200, 2); 19 | //EulerTests::solve2DToroTest3(200, 2); 20 | //EulerAMRTests::solveToroTest1AMR(200, 2, 1.0, 2); 21 | //EulerAMRTests::solve2DToroTest1AMR(100, 2, 1.0, 2); 22 | 23 | RelativisticEulerTests::solveMildlyRelativisticShock(800, 2); 24 | //RelativisticEulerTests::solveStronglyRelativisticBlast(400, 2); 25 | //RelativisticEulerTests::solvePerturbedDensityTest(400, 2); 26 | //RelativisticEulerTests::solve2DMildlyRelativisticShock(400, 2); 27 | //RelativisticEulerTests::solve2DStronglyRelativisticBlast(200, 2); 28 | //RelativisticEulerTests::solve2DPerturbedDensityTest(400, 2); 29 | //RelativisticEulerAMRTests::solveMildlyRelativisticShock(100, 2, 5.0, 2); 30 | //RelativisticEulerAMRTests::solveStronglyRelativisticBlast(100, 2, 100.0, 2); 31 | //RelativisticEulerAMRTests::solvePerturbedDensityTest(200, 2, 10.0, 2); 32 | //RelativisticEulerAMRTests::solve2DMildlyRelativisticShock(100, 2, 10.0, 2); 33 | //RelativisticEulerAMRTests::solve2DStronglyRelativisticBlast(100, 1, 1000.0, 2); 34 | //RelativisticEulerAMRTests::solve2DPerturbedDensityTest(100, 2, 20.0, 2); 35 | 36 | //BlackHoleEulerTests::solve1DSphericalAccretionTest(400, 2, 0); 37 | //BlackHoleEulerTests::solve1DSpinningSphericalAccretionTest(400, 2, 0); 38 | //BlackHoleEulerTests::solve2DSphericalAccretionTest(100, 2, 0); 39 | //BlackHoleEulerTests::solve2DSpinningSphericalAccretionTest(100, 2, 0); 40 | //BlackHoleEulerTests::solve2DSpheroidalAccretionTest(100, 2, 0); 41 | //BlackHoleEulerTests::solve2DSpinningSpheroidalAccretionTest(200, 2, 0); 42 | //BlackHoleEulerAMRTests::solve1DSphericalAccretionTest(200, 2, 0, 5.0, 2); 43 | //BlackHoleEulerAMRTests::solve1DSpinningSphericalAccretionTest(200, 2, 0, 5.0, 2); 44 | //BlackHoleEulerAMRTests::solve2DSphericalAccretionTest(100, 2, 0, 5.0, 1); 45 | //BlackHoleEulerAMRTests::solve2DSpinningSphericalAccretionTest(100, 2, 0, 5.0, 1); 46 | //BlackHoleEulerAMRTests::solve2DSpinningSpheroidalAccretionTest(100, 2, 0, 5.0, 1); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Solvers/RelativisticEulerSolvers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RelativisticEulerSolvers_hpp 2 | #define RelativisticEulerSolvers_hpp 3 | 4 | #include "../RelativisticEuler/RelativisticEulerStateVector.hpp" 5 | #include "EulerSolvers.hpp" 6 | 7 | class RelativisticEulerSolvers 8 | { 9 | public: 10 | static vector insertBoundaryCells(vector & currentCells, int boundarySize); 11 | static vector > insertBoundaryCells2D(vector > & currentCells, int boundarySize); 12 | 13 | static double computeMaximumWaveSpeed(vector & currentCells, EulerMaterialParameters materialParameters); 14 | static double computeMaximumWaveSpeed2D(vector > & currentCells, EulerMaterialParameters materialParameters); 15 | 16 | static double computeStableTimeStep(vector currentCells, double cellSpacing, double CFLCoefficient, double currentTime, 17 | double finalTime, int currentIteration, EulerMaterialParameters materialParameters); 18 | static double computeStableTimeStep2D(vector > currentCells, double cellSpacing, double CFLCoefficient, double currentTime, 19 | double finalTime, int currentIteration, EulerMaterialParameters materialParameters); 20 | 21 | static RelativisticEulerStateVector evolveStateByHalfTimeStep(vector leftExtrapolatedValue, vector rightExtrapolatedValue, 22 | vector evolutionVector, int side, EulerMaterialParameters materialParameters); 23 | static RelativisticEulerStateVector evolveStateByHalfXTimeStep(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector middleStateVector, 24 | RelativisticEulerStateVector rightStateVector, double cellSpacing, double timeStep, double bias, 25 | int slopeLimiter, int side, EulerMaterialParameters materialParameters); 26 | static RelativisticEulerStateVector evolveStateByHalfYTimeStep(RelativisticEulerStateVector topStateVector, RelativisticEulerStateVector middleStateVector, 27 | RelativisticEulerStateVector bottomStateVector, double cellSpacing, double timeStep, double bias, 28 | int slopeLimiter, int side, EulerMaterialParameters materialParameters); 29 | }; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Solvers/BlackHoleEulerSecondOrderSolver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerSecondOrderSolver_hpp 2 | #define BlackHoleEulerSecondOrderSolver_hpp 3 | 4 | #include "BlackHoleEulerFirstOrderSolver.hpp" 5 | 6 | class BlackHoleEulerSecondOrderSolver 7 | { 8 | public: 9 | static vector computeXSLICFlux(BlackHoleEulerStateVector leftLeftStateVector, BlackHoleEulerStateVector leftStateVector, 10 | BlackHoleEulerStateVector rightStateVector, BlackHoleEulerStateVector rightRightStateVector, double cellSpacing, 11 | double timeStep, double bias, int slopeLimiter, double xCoordinate, double yCoordinate, double zCoordinate, 12 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 13 | static vector computeYSLICFlux(BlackHoleEulerStateVector topTopStateVector, BlackHoleEulerStateVector topStateVector, 14 | BlackHoleEulerStateVector bottomStateVector, BlackHoleEulerStateVector bottomBottomStateVector, double cellSpacing, 15 | double timeStep, double bias, int slopeLimiter, double xCoordinate, double yCoordinate, double zCoordinate, 16 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 17 | 18 | static void computeSLICTimeStep(vector & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 19 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 20 | 21 | static void computeXSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, 22 | int slopeLimiter, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 23 | static void computeYSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, 24 | int slopeLimiter, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 25 | 26 | static vector solve(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 27 | double bias, int slopeLimiter, int subcyclingIterations, EulerMaterialParameters materialParameters, 28 | BlackHoleSpacetime blackHole); 29 | 30 | static vector > solve2D(vector > initialCells, double cellSpacing, double CFLCoefficient, 31 | double finalTime, double bias, int slopeLimiter, int subcyclingIterations, 32 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 33 | }; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /Solvers/EulerSolvers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerSolvers_hpp 2 | #define EulerSolvers_hpp 3 | 4 | #include "../Euler/EulerStateVector.hpp" 5 | #include "SlopeLimiters.hpp" 6 | #include "/usr/local/include/omp.h" 7 | #include 8 | using namespace std; 9 | 10 | class EulerSolvers 11 | { 12 | public: 13 | static vector insertBoundaryCells(vector & currentCells, int boundarySize); 14 | static vector > insertBoundaryCells2D(vector > & currentCells, int boundarySize); 15 | 16 | static double computeMaximumWaveSpeed(vector & currentCells, EulerMaterialParameters materialParameters); 17 | static double computeMaximumWaveSpeed2D(vector > & currentCells, EulerMaterialParameters materialParameters); 18 | 19 | static double computeStableTimeStep(double timeStep, double currentTime, double finalTime, int curentIteration); 20 | static double computeStableTimeStep(vector currentCells, double cellSpacing, double CFLCoefficient, double currentTime, double finalTime, 21 | int currentIteration, EulerMaterialParameters materialParameters); 22 | static double computeStableTimeStep2D(vector > currentCells, double cellSpacing, double CFLCoefficient, double currentTime, 23 | double finalTime, int currentIteration, EulerMaterialParameters materialParameters); 24 | 25 | static vector computeFractionalEvolutionVector(double stepFraction, vector leftFluxVector, vector rightFluxVector, double cellSpacing, 26 | double timeStep); 27 | static vector computeEvolutionVector(vector leftFluxVector, vector rightFluxVector, double cellSpacing, double timeStep); 28 | 29 | static EulerStateVector evolveStateByHalfTimeStep(vector leftExtrapolatedValue, vector rightExtrapolatedValue, vector evolutionVector, 30 | int side, EulerMaterialParameters materialParameters); 31 | static EulerStateVector evolveStateByHalfXTimeStep(EulerStateVector leftStateVector, EulerStateVector middleStateVector, EulerStateVector rightStateVector, 32 | double cellSpacing, double timeStep, double bias, int slopeLimiter, int side, 33 | EulerMaterialParameters materialParameters); 34 | static EulerStateVector evolveStateByHalfYTimeStep(EulerStateVector topStateVector, EulerStateVector middleStateVector, EulerStateVector bottomStateVector, 35 | double cellSpacing, double timeStep, double bias, int slopeLimiter, int side, 36 | EulerMaterialParameters materialParameters); 37 | 38 | static void outputStatus(int currentIteration, double currentTime, double timeStep); 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Solvers/RelativisticEulerFirstOrderSolver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RelativisticEulerFirstOrderSolver_hpp 2 | #define RelativisticEulerFirstOrderSolver_hpp 3 | 4 | #include "../Mathematics/VectorAlgebra.hpp" 5 | #include "RelativisticEulerSolvers.hpp" 6 | #include "EulerFirstOrderSolver.hpp" 7 | 8 | class RelativisticEulerFirstOrderSolver 9 | { 10 | public: 11 | static vector computeXLaxFriedrichsFlux(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector rightStateVector, double cellSpacing, 12 | double timeStep, EulerMaterialParameters materialParameters); 13 | static vector computeXRichtmyerFlux(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector rightStateVector, double cellSpacing, 14 | double timeStep, EulerMaterialParameters materialParameters); 15 | static vector computeXFORCEFlux(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector rightStateVector, double cellSpacing, 16 | double timeStep, EulerMaterialParameters materialParameters); 17 | 18 | static vector computeYLaxFriedrichsFlux(RelativisticEulerStateVector topStateVector, RelativisticEulerStateVector bottomStateVector, double cellSpacing, 19 | double timeStep, EulerMaterialParameters materialParameters); 20 | static vector computeYRichtmyerFlux(RelativisticEulerStateVector topStateVector, RelativisticEulerStateVector bottomStateVector, double cellSpacing, 21 | double timeStep, EulerMaterialParameters materialParameters); 22 | static vector computeYFORCEFlux(RelativisticEulerStateVector topStateVector, RelativisticEulerStateVector bottomStateVector, double cellSpacing, 23 | double timeStep, EulerMaterialParameters materialParameters); 24 | 25 | static void computeFORCETimeStep(vector & currentCells, double cellSpacing, double timeStep, 26 | EulerMaterialParameters materialParameters); 27 | 28 | static void computeXFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 29 | EulerMaterialParameters materialParameters); 30 | static void computeYFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 31 | EulerMaterialParameters materialParameters); 32 | 33 | static vector solve(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 34 | EulerMaterialParameters materialParameters); 35 | 36 | static vector > solve2D(vector > initialCells, double cellSpacing, double CFLCoefficient, 37 | double finalTime, EulerMaterialParameters materialParameters); 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /BlackHoleEuler/BlackHoleEulerStateVector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerStateVector_hpp 2 | #define BlackHoleEulerStateVector_hpp 3 | 4 | #include "../RelativisticEuler/RelativisticEulerEquationOfState.hpp" 5 | #include "BlackHoleSpacetime.hpp" 6 | #include "BlackHoleEulerEigenvalues.hpp" 7 | 8 | class BlackHoleEulerStateVector 9 | { 10 | public: 11 | BlackHoleEulerStateVector(); 12 | BlackHoleEulerStateVector(double newDensity, double newXVelocity, double newYVelocity, double newZVelocity, double newPressure); 13 | 14 | void setPrimitiveVariableVector(vector newPrimitiveVariableVector); 15 | void setConservedVariableVector(vector newConservedVariableVector, double xCoordinate, double yCoordinate, double zCoordinate, 16 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 17 | 18 | vector computePrimitiveVariableVector(); 19 | vector computeConservedVariableVector(double xCoordinate, double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, 20 | BlackHoleSpacetime blackHole); 21 | 22 | static vector computeXFluxVector(vector conservedVariableVector, double xCoordinate, double yCoordinate, double zCoordinate, 23 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 24 | vector computeXFluxVector(double xCoordinate, double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, 25 | BlackHoleSpacetime blackHole); 26 | 27 | static vector computeYFluxVector(vector conservedVariableVector, double xCoordinate, double yCoordinate, double zCoordinate, 28 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 29 | vector computeYFluxVector(double xCoordinate, double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, 30 | BlackHoleSpacetime blackHole); 31 | 32 | static vector computeSourceTermVector(vector conservedVariableVector, double xCoordinate, double yCoordinate, double zCoordinate, 33 | double cellSpacing, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 34 | vector computeSourceTermVector(double xCoordinate, double yCoordinate, double zCoordinate, double cellSpacing, 35 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 36 | 37 | double computeSoundSpeed(double xCoordinate, double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 38 | 39 | void setDensity(double newDensity); 40 | void setXVelocity(double newXVelocity); 41 | void setYVelocity(double newYVelocity); 42 | void setZVelocity(double newZVelocity); 43 | void setPressure(double newPressure); 44 | 45 | double getDensity(); 46 | double getXVelocity(); 47 | double getYVelocity(); 48 | double getZVelocity(); 49 | double getPressure(); 50 | 51 | private: 52 | double density; 53 | double xVelocity; 54 | double yVelocity; 55 | double zVelocity; 56 | double pressure; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /AMR/EulerAMR.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerAMR_hpp 2 | #define EulerAMR_hpp 3 | 4 | #include "../Solvers/EulerFirstOrderSolver.hpp" 5 | #include "../Solvers/EulerSecondOrderSolver.hpp" 6 | #include "AMRHelper.hpp" 7 | 8 | class EulerAMR 9 | { 10 | public: 11 | static void computeFORCETimeStepAMR(vector & currentCells, double cellSpacing, double timeStep, vector AMRStructure, 12 | EulerMaterialParameters materialParameters); 13 | 14 | static void computeXFORCETimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, vector > AMRStructure, 15 | EulerMaterialParameters materialParameters); 16 | static void computeYFORCETimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, vector > AMRStructure, 17 | EulerMaterialParameters materialParameters); 18 | 19 | static void computeSLICTimeStepAMR(vector & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 20 | vector AMRStructure, EulerMaterialParameters materialParameters); 21 | 22 | static void computeXSLICTimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 23 | vector > AMRStructure, EulerMaterialParameters materialParameters); 24 | static void computeYSLICTimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 25 | vector > AMRStructure, EulerMaterialParameters materialParameters); 26 | 27 | static tuple, vector, vector, vector> solveLevel1AMR(vector initialCells, 28 | double cellSpacing, double CFLCoefficient, 29 | double finalTime, double AMRTolerance, int order, 30 | EulerMaterialParameters materialParameters); 31 | static tuple >, vector >, vector >, vector >> 32 | solve2DLevel1AMR(vector > initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double AMRTolerance, int order, 33 | EulerMaterialParameters materialParameters); 34 | 35 | static tuple, vector, vector, vector, vector, vector> 36 | solveLevel2AMR(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double AMRTolerance, int order, 37 | EulerMaterialParameters materialParameters); 38 | static tuple >, vector >, vector >, vector >, vector >, 39 | vector >> solve2DLevel2AMR(vector > initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 40 | double AMRTolerance, int order, EulerMaterialParameters materialParameters); 41 | 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /BlackHoleEuler/BlackHoleSpacetime.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleSpacetime_hpp 2 | #define BlackHoleSpacetime_hpp 3 | 4 | #include "../Mathematics/VectorAlgebra.hpp" 5 | #include "../Mathematics/MatrixAlgebra.hpp" 6 | 7 | class BlackHoleSpacetime 8 | { 9 | public: 10 | BlackHoleSpacetime(); 11 | BlackHoleSpacetime(double newBlackHoleMass); 12 | BlackHoleSpacetime(double newBlackHoleMass, double newBlackHoleXPosition, double newBlackHoleYPosition, double newBlackHoleZPosition); 13 | BlackHoleSpacetime(double newBlackHoleMass, double newBlackHoleSpin); 14 | BlackHoleSpacetime(double newBlackHoleMass, double newBlackHoleSpin, double newBlackHoleXPosition, double newBlackHoleYPosition, double newBlackHoleZPosition); 15 | 16 | double computeKerrSchildScalar(double xCoordinate, double yCoordinate, double zCoordinate); 17 | vector computeKerrSchildVector(double xCoordinate, double yCoordinate, double zCoordinate); 18 | vector computeKerrSchildSpacetimeVector(double xCoordinate, double yCoordinate, double zCoordinate); 19 | 20 | vector computeKerrSchildScalarDerivative(double xCoordinate, double yCoordinate, double zCoordinate, double cellSpacing); 21 | vector > computeKerrSchildVectorDerivative(double xCoordinate, double yCoordinate, double zCoordinate, double cellSpacing); 22 | 23 | vector > computeSpatialMetricTensor(double xCoordinate, double yCoordinate, double zCoordinate); 24 | vector > computeSpacetimeMetricTensor(double xCoordinate, double yCoordinate, double zCoordinate); 25 | 26 | vector > computeInverseSpatialMetricTensor(double xCoordinate, double yCoordinate, double zCoordinate); 27 | vector > computeInverseSpacetimeMetricTensor(double xCoordiante, double yCoordinate, double zCoordinate); 28 | 29 | double computeSpatialMetricDeterminant(double xCoordinate, double yCoordinate, double zCoordinate); 30 | double computeSpacetimeMetricDeterminant(double xCoordinate, double yCoordinate, double zCoordinate); 31 | 32 | vector > > computeSpatialMetricTensorDerivative(double xCoordinate, double yCoordinate, double zCoordinate, double cellSpacing); 33 | 34 | double computeLapseFunction(double xCoordinate, double yCoordinate, double zCoordinate); 35 | vector computeShiftVector(double xCoordinate, double yCoordinate, double zCoordinate); 36 | 37 | vector computeLapseFunctionDerivative(double xCoordinate, double yCoordinate, double zCoordinate, double cellSpacing); 38 | vector > computeShiftVectorDerivative(double xCoordinate, double yCoordinate, double zCoordinate, double cellSpacing); 39 | 40 | vector > computeExtrinsicCurvatureTensor(double xCoordinate, double yCoordinate, double zCoordinate, double cellSpacing); 41 | 42 | bool inExcisionRegion(double xCoordinate, double yCoordinate, double zCoordinate); 43 | 44 | void setBlackHoleMass(double newBlackHoleMass); 45 | void setBlackHoleSpin(double newBlackHoleSpin); 46 | void setBlackHoleXPosition(double newBlackHoleXPosition); 47 | void setBlackHoleYPosition(double newBlackHoleYPosition); 48 | void setBlackHoleZPosition(double newBlackHoleZPosition); 49 | 50 | double getBlackHoleMass(); 51 | double getBlackHoleSpin(); 52 | double getBlackHoleXPosition(); 53 | double getBlackHoleYPosition(); 54 | double getBlackHoleZPosition(); 55 | 56 | private: 57 | double blackHoleMass; 58 | double blackHoleSpin; 59 | double blackHoleXPosition; 60 | double blackHoleYPosition; 61 | double blackHoleZPosition; 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /AMR/RelativisticEulerAMR.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RelativisticEulerAMR_hpp 2 | #define RelativisticEulerAMR_hpp 3 | 4 | #include "../Solvers/RelativisticEulerFirstOrderSolver.hpp" 5 | #include "../Solvers/RelativisticEulerSecondOrderSolver.hpp" 6 | #include "AMRHelper.hpp" 7 | 8 | class RelativisticEulerAMR 9 | { 10 | public: 11 | static void computeFORCETimeStepAMR(vector & currentCells, double cellSpacing, double timeStsep, vector AMRStructure, 12 | EulerMaterialParameters materialParameters); 13 | 14 | static void computeXFORCETimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, 15 | vector > AMRStructure, EulerMaterialParameters materialParameters); 16 | static void computeYFORCETimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, 17 | vector > AMRStructure, EulerMaterialParameters materialParameters); 18 | 19 | static void computeSLICTimeStepAMR(vector & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 20 | vector AMRStructure, EulerMaterialParameters materialParameters); 21 | 22 | static void computeXSLICTimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, double bias, 23 | int slopeLimiter, vector > AMRStructure, EulerMaterialParameters materialParameters); 24 | static void computeYSLICTimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, double bias, 25 | int slopeLimiter, vector > AMRStructure, EulerMaterialParameters materialParameters); 26 | 27 | static tuple, vector, vector, vector> 28 | solveLevel1AMR(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double AMRTolerance, int order, 29 | EulerMaterialParameters materialParameters); 30 | static tuple >, vector >, vector >, vector >> 31 | solve2DLevel1AMR(vector > initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double AMRTolerance, 32 | int order, EulerMaterialParameters materialParameters); 33 | 34 | static tuple, vector, vector, vector, vector, 35 | vector> solveLevel2AMR(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double AMRTolerance, 36 | int order, EulerMaterialParameters materialParameters); 37 | static tuple >, vector >, vector >, 38 | vector >, vector >, vector >> solve2DLevel2AMR(vector > initialCells, 39 | double cellSpacing, double CFLCoefficient, double finalTime, 40 | double AMRTolerance, int order, EulerMaterialParameters materialParameters); 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /Solvers/EulerFirstOrderSolver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef EulerFirstOrderSolver_hpp 2 | #define EulerFirstOrderSolver_hpp 3 | 4 | #include "../Euler/EulerStateVector.hpp" 5 | #include "../Mathematics/VectorAlgebra.hpp" 6 | #include "EulerSolvers.hpp" 7 | 8 | class EulerFirstOrderSolver 9 | { 10 | public: 11 | static vector computeLaxFriedrichsFlux(vector leftConservedVariableVector, vector rightConservedVariableVector, vector leftFluxVector, 12 | vector rightFluxVector, double cellSpacing, double timeStep); 13 | static vector computeRichtmyerFlux(vector leftConservedVariableVector, vector rightConservedVariableVector, vector leftFluxVector, 14 | vector rightFluxVector, double cellSpacing, double timeStep); 15 | static vector computeFORCEFlux(vector laxFriedrichsFlux, vector richtmyerFlux); 16 | 17 | static vector computeXLaxFriedrichsFlux(EulerStateVector leftStateVector, EulerStateVector rightStateVector, double cellSpacing, double timeStep, 18 | EulerMaterialParameters materialParameters); 19 | static vector computeXRichtmyerFlux(EulerStateVector leftStateVector, EulerStateVector rightStateVector, double cellSpacing, double timeStep, 20 | EulerMaterialParameters materialParameters); 21 | static vector computeXFORCEFlux(EulerStateVector leftStateVector, EulerStateVector rightStateVector, double cellSpacing, double timeStep, 22 | EulerMaterialParameters materialParameters); 23 | 24 | static vector computeYLaxFriedrichsFlux(EulerStateVector topStateVector, EulerStateVector bottomStateVector, double cellSpacing, double timeStep, 25 | EulerMaterialParameters materialParameters); 26 | static vector computeYRichtmyerFlux(EulerStateVector topStateVector, EulerStateVector bottomStateVector, double cellSpacing, double timeStep, 27 | EulerMaterialParameters materialParameters); 28 | static vector computeYFORCEFlux(EulerStateVector topStateVector, EulerStateVector bottomStateVector, double cellSpacing, double timeStep, 29 | EulerMaterialParameters materialParameters); 30 | 31 | static vector computeFORCEUpdate(vector conservedVariableVector, vector leftFluxVector, vector rightFluxVector, 32 | double cellSpacing, double timeStep); 33 | 34 | static void computeFORCETimeStep(vector & currentCells, double cellSpacing, double timeStep, 35 | EulerMaterialParameters materialParameters); 36 | 37 | static void computeXFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 38 | EulerMaterialParameters materialParameters); 39 | static void computeYFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 40 | EulerMaterialParameters materialParameters); 41 | 42 | static vector solve(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 43 | EulerMaterialParameters materialParameters); 44 | 45 | static vector > solve2D(vector > initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 46 | EulerMaterialParameters materialParameters); 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /AMR/BlackHoleEulerAMR.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerAMR_hpp 2 | #define BlackHoleEulerAMR_hpp 3 | 4 | #include "../Solvers/BlackHoleEulerFirstOrderSolver.hpp" 5 | #include "../Solvers/BlackHoleEulerSecondOrderSolver.hpp" 6 | #include "AMRHelper.hpp" 7 | 8 | class BlackHoleEulerAMR 9 | { 10 | public: 11 | static void computeFORCETimeStepAMR(vector & currentCells, double cellSpacing, double timeStep, vector AMRStructure, 12 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 13 | 14 | static void computeXFORCETimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, 15 | vector > AMRStructure, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 16 | static void computeYFORCETimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, 17 | vector > AMRStructure, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 18 | 19 | static void computeSLICTimeStepAMR(vector & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 20 | vector AMRStructure, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 21 | 22 | static void computeXSLICTimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, double bias, 23 | int slopeLimiter, vector > AMRStructure, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 24 | static void computeYSLICTimeStep2DAMR(vector > & currentCells, double cellSpacing, double timeStep, double bias, 25 | int slopeLimiter, vector > AMRStructure, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 26 | 27 | static tuple, vector, vector, vector> 28 | solveLevel1AMR(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double AMRTolerance, int order, 29 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 30 | static tuple >, vector >, vector >, vector >> 31 | solve2DLevel1AMR(vector > initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double AMRTolerance, 32 | int order, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 33 | 34 | static tuple, vector, vector, vector, vector, 35 | vector> solveLevel2AMR(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, double AMRTolerance, 36 | int order, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 37 | static tuple >, vector >, vector >, 38 | vector >, vector >, vector >> solve2DLevel2AMR(vector > initialCells, double cellSpacing, 39 | double CFLCoefficient, double finalTime, double AMRTolerance, int order, 40 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /Solvers/BlackHoleEulerFirstOrderSolver.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerFirstOrderSolver_hpp 2 | #define BlackHoleEulerFirstOrderSolver_hpp 3 | 4 | #include "../Mathematics/VectorAlgebra.hpp" 5 | #include "BlackHoleEulerForcingSolver.hpp" 6 | #include "EulerFirstOrderSolver.hpp" 7 | 8 | class BlackHoleEulerFirstOrderSolver 9 | { 10 | public: 11 | static vector computeXLaxFriedrichsFlux(BlackHoleEulerStateVector leftStateVector, BlackHoleEulerStateVector rightStateVector, double xCoordinate, 12 | double yCoordinate, double zCoordinate, double cellSpacing, double timeStep, 13 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 14 | static vector computeXRichtmyerFlux(BlackHoleEulerStateVector leftStateVector, BlackHoleEulerStateVector rightStateVector, double xCoordinate, 15 | double yCoordinate, double zCoordinate, double cellSpacing, double timeSep, 16 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 17 | static vector computeXFORCEFlux(BlackHoleEulerStateVector leftStateVector, BlackHoleEulerStateVector rightStateVector, double xCoordinate, 18 | double yCoordinate, double zCoordinate, double cellSpacing, double timeStep, 19 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 20 | 21 | static vector computeYLaxFriedrichsFlux(BlackHoleEulerStateVector topStateVector, BlackHoleEulerStateVector bottomStateVector, double xCoordinate, 22 | double yCoordinate, double zCoordinate, double cellSpacing, double timeStep, 23 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 24 | static vector computeYRichtmyerFlux(BlackHoleEulerStateVector topStateVector, BlackHoleEulerStateVector bottomStateVector, double xCoordinate, 25 | double yCoordinate, double zCoordinate, double cellSpacing, double timeStep, 26 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 27 | static vector computeYFORCEFlux(BlackHoleEulerStateVector topStateVector, BlackHoleEulerStateVector bottomStateVector, double xCoordinate, 28 | double yCoordinate, double zCoordinate, double cellSpacing, double timeStep, 29 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 30 | 31 | static void computeFORCETimeStep(vector & currentCells, double cellSpacing, double timeStep, EulerMaterialParameters materialParameters, 32 | BlackHoleSpacetime blackHole); 33 | 34 | static void computeXFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 35 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 36 | static void computeYFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 37 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 38 | 39 | static vector solve(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 40 | int subcyclingIterations, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 41 | 42 | static vector > solve2D(vector > initialCells, double cellSpacing, double CFLCoefficient, 43 | double finalTime, int subcyclingIterations, EulerMaterialParameters materialParameters, 44 | BlackHoleSpacetime blackHole); 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /BlackHoleEuler/BlackHoleEulerEigenvalues.cpp: -------------------------------------------------------------------------------- 1 | #include "BlackHoleEulerEigenvalues.hpp" 2 | 3 | vector BlackHoleEulerEigenvalues::computeMaterialWaveEigenvalues(double xCoordinate, double yCoordinate, double zCoordinate, double xVelocity, double yVelocity, 4 | double zVelocity, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole) 5 | { 6 | double lapseFunction = blackHole.computeLapseFunction(xCoordinate, yCoordinate, zCoordinate); 7 | vector shiftVector = blackHole.computeShiftVector(xCoordinate, yCoordinate, zCoordinate); 8 | 9 | vector materialWaveEigenvalues(3); 10 | 11 | materialWaveEigenvalues[0] = (lapseFunction * xVelocity) - shiftVector[0]; 12 | materialWaveEigenvalues[1] = (lapseFunction * yVelocity) - shiftVector[1]; 13 | materialWaveEigenvalues[2] = (lapseFunction * zVelocity) - shiftVector[2]; 14 | 15 | return materialWaveEigenvalues; 16 | } 17 | 18 | vector BlackHoleEulerEigenvalues::computeFastAcousticWaveEigenvalues(double xCoordinate, double yCoordinate, double zCoordinate, double density, 19 | double pressure, double xVelocity, double yVelocity, double zVelocity, 20 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole) 21 | { 22 | double lapseFunction = blackHole.computeLapseFunction(xCoordinate, yCoordinate, zCoordinate); 23 | vector shiftVector = blackHole.computeShiftVector(xCoordinate, yCoordinate, zCoordinate); 24 | 25 | vector > spatialMetricTensor = blackHole.computeSpatialMetricTensor(xCoordinate, yCoordinate, zCoordinate); 26 | vector > inverseSpatialMetricTensor = blackHole.computeInverseSpatialMetricTensor(xCoordinate, yCoordinate, zCoordinate); 27 | 28 | double soundSpeed = RelativisticEulerEquationOfState::computeSoundSpeed(density, pressure, materialParameters); 29 | 30 | vector velocityVector(3); 31 | 32 | velocityVector[0] = xVelocity; 33 | velocityVector[1] = yVelocity; 34 | velocityVector[2] = zVelocity; 35 | 36 | double velocitySquared = 0.0; 37 | for (int i = 0; i < 3; i++) 38 | { 39 | for (int j = 0; j < 3; j++) 40 | { 41 | velocitySquared += spatialMetricTensor[i][j] * velocityVector[i] * velocityVector[j]; 42 | } 43 | } 44 | 45 | vector fastAcousticWaveEigenvalues(3); 46 | 47 | for (int i = 0; i < 3; i++) 48 | { 49 | fastAcousticWaveEigenvalues[i] = (lapseFunction / (1.0 - (velocitySquared * (soundSpeed * soundSpeed)))) * 50 | ((velocityVector[i] * (1.0 - (soundSpeed * soundSpeed))) + 51 | (soundSpeed * sqrt((1.0 - velocitySquared) * (inverseSpatialMetricTensor[i][i] * (1.0 - (velocitySquared * (soundSpeed * soundSpeed))) - 52 | (velocityVector[i] * velocityVector[i]) * (1.0 - (soundSpeed * soundSpeed)))))) - shiftVector[i]; 53 | } 54 | 55 | return fastAcousticWaveEigenvalues; 56 | } 57 | 58 | vector BlackHoleEulerEigenvalues::computeSlowAcousticWaveEigenvalues(double xCoordinate, double yCoordinate, double zCoordinate, double density, 59 | double pressure, double xVelocity, double yVelocity, double zVelocity, 60 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole) 61 | { 62 | double lapseFunction = blackHole.computeLapseFunction(xCoordinate, yCoordinate, zCoordinate); 63 | vector shiftVector = blackHole.computeShiftVector(xCoordinate, yCoordinate, zCoordinate); 64 | 65 | vector > spatialMetricTensor = blackHole.computeSpatialMetricTensor(xCoordinate, yCoordinate, zCoordinate); 66 | vector > inverseSpatialMetricTensor = blackHole.computeInverseSpatialMetricTensor(xCoordinate, yCoordinate, zCoordinate); 67 | 68 | double soundSpeed = RelativisticEulerEquationOfState::computeSoundSpeed(density, pressure, materialParameters); 69 | 70 | vector velocityVector(3); 71 | 72 | velocityVector[0] = xVelocity; 73 | velocityVector[1] = yVelocity; 74 | velocityVector[2] = zVelocity; 75 | 76 | double velocitySquared = 0.0; 77 | for (int i = 0; i < 3; i++) 78 | { 79 | for (int j = 0; j < 3; j++) 80 | { 81 | velocitySquared += spatialMetricTensor[i][j] * velocityVector[i] * velocityVector[j]; 82 | } 83 | } 84 | 85 | vector slowAcousticWaveEigenvalues(3); 86 | 87 | for (int i = 0; i < 3; i++) 88 | { 89 | slowAcousticWaveEigenvalues[i] = (lapseFunction / (1.0 - (velocitySquared * (soundSpeed * soundSpeed)))) * 90 | ((velocityVector[i] * (1.0 - (soundSpeed * soundSpeed))) - 91 | (soundSpeed * sqrt((1.0 - velocitySquared) * (inverseSpatialMetricTensor[i][i] * (1.0 - (velocitySquared * (soundSpeed * soundSpeed))) - 92 | (velocityVector[i] * velocityVector[i]) * (1.0 - (soundSpeed * soundSpeed)))))) - shiftVector[i]; 93 | } 94 | 95 | return slowAcousticWaveEigenvalues; 96 | } 97 | -------------------------------------------------------------------------------- /Solvers/BlackHoleEulerSolvers.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BlackHoleEulerSolvers_hpp 2 | #define BlackHoleEulerSolvers_hpp 3 | 4 | #include "../BlackHoleEuler/BlackHoleEulerStateVector.hpp" 5 | #include "EulerSolvers.hpp" 6 | 7 | class BlackHoleEulerSolvers 8 | { 9 | public: 10 | static vector insertBoundaryCells(vector & currentCells, int boundarySize); 11 | static vector > insertBoundaryCells2D(vector > & currentCells, int boundarySize); 12 | 13 | static double computeMaximumWaveSpeed(vector & currentCells, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 14 | static double computeMaximumWaveSpeed2D(vector > & currentCells, EulerMaterialParameters materialParameters, 15 | BlackHoleSpacetime blackHole); 16 | 17 | static double computeStableTimeStep(vector currentCells, double cellSpacing, double CFLCoefficient, double currentTime, 18 | double finalTime, int currentIteration, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 19 | static double computeStableTimeStep2D(vector > currentCells, double cellSpacing, double CFLCoefficient, double currentTime, 20 | double finalTime, int currentIteration, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 21 | 22 | static BlackHoleEulerStateVector evolveStateByFractionalTimeStep(vector middleConservedVariableVector, vector conservedVariableVectorEvolution, 23 | double xCoordinate, double yCoordinate, double zCoordinate, 24 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 25 | 26 | static BlackHoleEulerStateVector evolveStateByFractionalXTimeStep(double stepFraction, BlackHoleEulerStateVector leftStateVector, 27 | BlackHoleEulerStateVector middleStateVector, BlackHoleEulerStateVector rightStateVector, 28 | double cellSpacing, double timeStep, double bias, int slopeLimiter, double xCoordinate, 29 | double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, 30 | BlackHoleSpacetime blackHole); 31 | static BlackHoleEulerStateVector evolveStateByFractionalYTimeStep(double stepFraction, BlackHoleEulerStateVector topStateVector, 32 | BlackHoleEulerStateVector middleStateVector, BlackHoleEulerStateVector bottomStateVector, 33 | double cellSpacing, double timeStep, double bias, int slopeLimiter, double xCoordinate, 34 | double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, 35 | BlackHoleSpacetime blackHole); 36 | 37 | static BlackHoleEulerStateVector evolveStateByHalfXTimeStep(vector leftExtrapolatedValue, vector rightExtrapolatedValue, 38 | vector evolutionVector, int side, double cellSpacing, double xCoordinate, double yCoordinate, 39 | double zCoordinate, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 40 | static BlackHoleEulerStateVector evolveStateByHalfXTimeStep(BlackHoleEulerStateVector leftStateVector, BlackHoleEulerStateVector middleStateVector, 41 | BlackHoleEulerStateVector rightStateVector, double cellSpacing, double timeStep, double bias, 42 | int slopeLimiter, int side, double xCoordinate, double yCoordinate, double zCoordinate, 43 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 44 | 45 | static BlackHoleEulerStateVector evolveStateByHalfYTimeStep(vector topExtrapolatedValue, vector bottomExtrapolatedValue, 46 | vector evolutionVector, int side, double cellSpacing, double xCoordinate, double yCoordinate, 47 | double zCoordinate, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 48 | static BlackHoleEulerStateVector evolveStateByHalfYTimeStep(BlackHoleEulerStateVector topStateVector, BlackHoleEulerStateVector middleStateVector, 49 | BlackHoleEulerStateVector bottomStateVector, double cellSpacing, double timeStep, double bias, 50 | int slopeLimiter, int side, double xCoordinate, double yCoordinate, double zCoordinate, 51 | EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole); 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Mathematics/MatrixAlgebra.cpp: -------------------------------------------------------------------------------- 1 | #include "MatrixAlgebra.hpp" 2 | 3 | vector > MatrixAlgebra::computeIdentityMatrix(int matrixDimension) 4 | { 5 | vector > identityMatrix(matrixDimension, vector(matrixDimension)); 6 | 7 | for (int i = 0; i < matrixDimension; i++) 8 | { 9 | for (int j = 0; j < matrixDimension; j++) 10 | { 11 | if (i == j) 12 | { 13 | identityMatrix[i][j] = 1.0; 14 | } 15 | else 16 | { 17 | identityMatrix[i][j] = 0.0; 18 | } 19 | } 20 | } 21 | 22 | return identityMatrix; 23 | } 24 | 25 | vector > MatrixAlgebra::addMatrices(vector > matrix1, vector > matrix2) 26 | { 27 | long rowCount = matrix1.size(); 28 | long columnCount = matrix1[0].size(); 29 | vector > sumMatrix(rowCount, vector(columnCount)); 30 | 31 | for (int i = 0; i < rowCount; i++) 32 | { 33 | for (int j = 0; j < columnCount; j++) 34 | { 35 | sumMatrix[i][j] = matrix1[i][j] + matrix2[i][j]; 36 | } 37 | } 38 | 39 | return sumMatrix; 40 | } 41 | 42 | vector > MatrixAlgebra::subtractMatrices(vector > matrix1, vector > matrix2) 43 | { 44 | return addMatrices(matrix1, multiplyMatrix(-1.0, matrix2)); 45 | } 46 | 47 | vector > MatrixAlgebra::multiplyMatrix(double scalar1, vector > matrix1) 48 | { 49 | long rowCount = matrix1.size(); 50 | long columnCount = matrix1[0].size(); 51 | vector > productMatrix(rowCount, vector(columnCount)); 52 | 53 | for (int i = 0; i < rowCount; i++) 54 | { 55 | for (int j = 0; j < columnCount; j++) 56 | { 57 | productMatrix[i][j] = scalar1 * matrix1[i][j]; 58 | } 59 | } 60 | 61 | return productMatrix; 62 | } 63 | 64 | vector > MatrixAlgebra::multiplyMatrices(vector > matrix1, vector > matrix2) 65 | { 66 | long matrix1RowCount = matrix1.size(); 67 | long matrix1ColumnCount = matrix1[0].size(); 68 | long matrix2ColumnCount = matrix2[0].size(); 69 | vector > productMatrix(matrix1RowCount, vector(matrix2ColumnCount)); 70 | 71 | for (int i = 0; i < matrix1RowCount; i++) 72 | { 73 | for (int j = 0; j < matrix2ColumnCount; j++) 74 | { 75 | productMatrix[i][j] = 0.0; 76 | } 77 | } 78 | 79 | for (int i = 0; i < matrix1RowCount; i++) 80 | { 81 | for (int j = 0; j < matrix2ColumnCount; j++) 82 | { 83 | for (int k = 0; k < matrix1ColumnCount; k++) 84 | { 85 | productMatrix[i][j] += matrix1[i][k] * matrix2[k][j]; 86 | } 87 | } 88 | } 89 | 90 | return productMatrix; 91 | } 92 | 93 | double MatrixAlgebra::computeMatrixTrace(vector > matrix1) 94 | { 95 | long rowCount = matrix1.size(); 96 | double trace = 0.0; 97 | 98 | for (int i = 0; i < rowCount; i++) 99 | { 100 | trace += matrix1[i][i]; 101 | } 102 | 103 | return trace; 104 | } 105 | 106 | double MatrixAlgebra::computeMatrixDeterminant(vector > matrix1) 107 | { 108 | long matrixDimension = matrix1.size(); 109 | 110 | if (matrixDimension == 2) 111 | { 112 | return (matrix1[0][0] * matrix1[1][1]) - (matrix1[1][0] * matrix1[0][1]); 113 | } 114 | else 115 | { 116 | double matrixDeterminant = 0.0; 117 | 118 | for (int i = 0; i < matrixDimension; i++) 119 | { 120 | vector > cofactorMatrix(matrixDimension - 1, vector(matrixDimension - 1)); 121 | 122 | for (int j = 0; j < matrixDimension - 1; j++) 123 | { 124 | for (int k = 0; k < matrixDimension - 1; k++) 125 | { 126 | if (k < i) 127 | { 128 | cofactorMatrix[j][k] = matrix1[j + 1][k]; 129 | } 130 | else 131 | { 132 | cofactorMatrix[j][k] = matrix1[j + 1][k + 1]; 133 | } 134 | } 135 | } 136 | 137 | if (i % 2 == 0) 138 | { 139 | matrixDeterminant += matrix1[0][i] * computeMatrixDeterminant(cofactorMatrix); 140 | } 141 | else 142 | { 143 | matrixDeterminant -= matrix1[0][i] * computeMatrixDeterminant(cofactorMatrix); 144 | } 145 | } 146 | 147 | return matrixDeterminant; 148 | } 149 | } 150 | 151 | vector > MatrixAlgebra::computeMatrixInverse(vector > matrix1) 152 | { 153 | long matrixDimension = matrix1.size(); 154 | 155 | if (matrixDimension == 2) 156 | { 157 | double matrixDeterminant = computeMatrixDeterminant(matrix1); 158 | double matrixTrace = computeMatrixTrace(matrix1); 159 | vector > identityMatrix = computeIdentityMatrix(2); 160 | 161 | return multiplyMatrix((1.0 / matrixDeterminant), subtractMatrices(multiplyMatrix(matrixTrace, identityMatrix), matrix1)); 162 | } 163 | else if (matrixDimension == 3) 164 | { 165 | double matrixDeterminant = computeMatrixDeterminant(matrix1); 166 | double matrixTrace = computeMatrixTrace(matrix1); 167 | double matrixSquaredTrace = computeMatrixTrace(multiplyMatrices(matrix1, matrix1)); 168 | vector > identityMatrix = computeIdentityMatrix(3); 169 | 170 | return multiplyMatrix((1.0 / matrixDeterminant), 171 | addMatrices(subtractMatrices(multiplyMatrix(0.5 * ((matrixTrace * matrixTrace) - matrixSquaredTrace), identityMatrix), 172 | multiplyMatrix(matrixTrace, matrix1)), multiplyMatrices(matrix1, matrix1))); 173 | } 174 | else if (matrixDimension == 4) 175 | { 176 | double matrixDeterminant = computeMatrixDeterminant(matrix1); 177 | double matrixTrace = computeMatrixTrace(matrix1); 178 | double matrixSquaredTrace = computeMatrixTrace(multiplyMatrices(matrix1, matrix1)); 179 | double matrixCubedTrace = computeMatrixTrace(multiplyMatrices(multiplyMatrices(matrix1, matrix1), matrix1)); 180 | vector > identityMatrix = computeIdentityMatrix(4); 181 | 182 | return multiplyMatrix((1.0 / matrixDeterminant), 183 | subtractMatrices(addMatrices(subtractMatrices(multiplyMatrix((1.0 / 6.0) * ((matrixTrace * matrixTrace * matrixTrace) - 184 | (3.0 * matrixTrace * matrixSquaredTrace) + 185 | (2.0 * matrixCubedTrace)), identityMatrix), 186 | multiplyMatrix(0.5 * ((matrixTrace * matrixTrace) - matrixSquaredTrace), matrix1)), 187 | multiplyMatrix(matrixTrace, multiplyMatrices(matrix1, matrix1))), 188 | multiplyMatrices(multiplyMatrices(matrix1, matrix1), matrix1))); 189 | } 190 | else 191 | { 192 | return matrix1; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /Euler/EulerStateVector.cpp: -------------------------------------------------------------------------------- 1 | #include "EulerStateVector.hpp" 2 | 3 | EulerStateVector::EulerStateVector() 4 | { 5 | density = 1.0; 6 | xVelocity = 0.0; 7 | yVelocity = 0.0; 8 | zVelocity = 0.0; 9 | pressure = 1.0; 10 | } 11 | 12 | EulerStateVector::EulerStateVector(double newDensity, double newXVelocity, double newYVelocity, double newZVelocity, double newPressure) 13 | { 14 | density = newDensity; 15 | xVelocity = newXVelocity; 16 | yVelocity = newYVelocity; 17 | zVelocity = newZVelocity; 18 | pressure = newPressure; 19 | } 20 | 21 | void EulerStateVector::setPrimitiveVariableVector(vector newPrimitiveVariableVector) 22 | { 23 | density = newPrimitiveVariableVector[0]; 24 | xVelocity = newPrimitiveVariableVector[1]; 25 | yVelocity = newPrimitiveVariableVector[2]; 26 | zVelocity = newPrimitiveVariableVector[3]; 27 | pressure = newPrimitiveVariableVector[4]; 28 | } 29 | 30 | void EulerStateVector::setConservedVariableVector(vector newConservedVariableVector, EulerMaterialParameters materialParameters) 31 | { 32 | density = newConservedVariableVector[0]; 33 | xVelocity = newConservedVariableVector[1] / density; 34 | yVelocity = newConservedVariableVector[2] / density; 35 | zVelocity = newConservedVariableVector[3] / density; 36 | 37 | double velocitySquared = (xVelocity * xVelocity) + (yVelocity * yVelocity) + (zVelocity * zVelocity); 38 | double specificInternalEnergy = (newConservedVariableVector[4] / density) - (0.5 * velocitySquared); 39 | pressure = EulerEquationOfState::computePressure(density, specificInternalEnergy, materialParameters); 40 | } 41 | 42 | vector EulerStateVector::computePrimitiveVariableVector() 43 | { 44 | vector primitiveVariableVector(5); 45 | 46 | primitiveVariableVector[0] = density; 47 | primitiveVariableVector[1] = xVelocity; 48 | primitiveVariableVector[2] = yVelocity; 49 | primitiveVariableVector[3] = zVelocity; 50 | primitiveVariableVector[4] = pressure; 51 | 52 | return primitiveVariableVector; 53 | } 54 | 55 | vector EulerStateVector::computeConservedVariableVector(EulerMaterialParameters materialParameters) 56 | { 57 | vector conservedVariableVector(5); 58 | 59 | conservedVariableVector[0] = density; 60 | conservedVariableVector[1] = density * xVelocity; 61 | conservedVariableVector[2] = density * yVelocity; 62 | conservedVariableVector[3] = density * zVelocity; 63 | conservedVariableVector[4] = computeTotalEnergy(materialParameters); 64 | 65 | return conservedVariableVector; 66 | } 67 | 68 | vector EulerStateVector::computeXFluxVector(vector conservedVariableVector, EulerMaterialParameters materialParameters) 69 | { 70 | vector fluxVector(5); 71 | 72 | double computedDensity = conservedVariableVector[0]; 73 | double computedXVelocity = conservedVariableVector[1] / computedDensity; 74 | double computedYVelocity = conservedVariableVector[2] / computedDensity; 75 | double computedZVelocity = conservedVariableVector[3] / computedDensity; 76 | 77 | double velocitySquared = (computedXVelocity * computedXVelocity) + (computedYVelocity * computedYVelocity) + (computedZVelocity * computedZVelocity); 78 | double totalEnergy = conservedVariableVector[4] / computedDensity; 79 | double specificInternalEnergy = totalEnergy - (0.5 * velocitySquared); 80 | double computedPressure = EulerEquationOfState::computePressure(computedDensity, specificInternalEnergy, materialParameters); 81 | 82 | fluxVector[0] = computedDensity * computedXVelocity; 83 | fluxVector[1] = (computedDensity * (computedXVelocity * computedXVelocity)) + computedPressure; 84 | fluxVector[2] = computedDensity * (computedXVelocity * computedYVelocity); 85 | fluxVector[3] = computedDensity * (computedXVelocity * computedZVelocity); 86 | fluxVector[4] = (computedDensity * (computedXVelocity * totalEnergy)) + (computedXVelocity * computedPressure); 87 | 88 | return fluxVector; 89 | } 90 | 91 | vector EulerStateVector::computeXFluxVector(EulerMaterialParameters materialParameters) 92 | { 93 | return computeXFluxVector(computeConservedVariableVector(materialParameters), materialParameters); 94 | } 95 | 96 | vector EulerStateVector::computeYFluxVector(vector conservedVariableVector, EulerMaterialParameters materialParameters) 97 | { 98 | vector fluxVector(5); 99 | 100 | double computedDensity = conservedVariableVector[0]; 101 | double computedXVelocity = conservedVariableVector[1] / computedDensity; 102 | double computedYVelocity = conservedVariableVector[2] / computedDensity; 103 | double computedZVelocity = conservedVariableVector[3] / computedDensity; 104 | 105 | double velocitySquared = (computedXVelocity * computedXVelocity) + (computedYVelocity * computedYVelocity) + (computedZVelocity * computedZVelocity); 106 | double totalEnergy = conservedVariableVector[4] / computedDensity; 107 | double specificInternalEnergy = totalEnergy - (0.5 * velocitySquared); 108 | double computedPressure = EulerEquationOfState::computePressure(computedDensity, specificInternalEnergy, materialParameters); 109 | 110 | fluxVector[0] = computedDensity * computedYVelocity; 111 | fluxVector[1] = computedDensity * (computedYVelocity * computedXVelocity); 112 | fluxVector[2] = (computedDensity * (computedYVelocity * computedYVelocity)) + computedPressure; 113 | fluxVector[3] = computedDensity * (computedYVelocity * computedZVelocity); 114 | fluxVector[4] = (computedDensity * (computedYVelocity * totalEnergy)) + (computedYVelocity * computedPressure); 115 | 116 | return fluxVector; 117 | } 118 | 119 | vector EulerStateVector::computeYFluxVector(EulerMaterialParameters materialParameters) 120 | { 121 | return computeYFluxVector(computeConservedVariableVector(materialParameters), materialParameters); 122 | } 123 | 124 | double EulerStateVector::computeSpecificInternalEnergy(EulerMaterialParameters materialParameters) 125 | { 126 | return EulerEquationOfState::computeSpecificInternalEnergy(density, pressure, materialParameters); 127 | } 128 | 129 | double EulerStateVector::computeTotalEnergy(EulerMaterialParameters materialParameters) 130 | { 131 | double velocitySquared = (xVelocity * xVelocity) + (yVelocity * yVelocity) + (zVelocity * zVelocity); 132 | 133 | return density * ((0.5 * velocitySquared) + computeSpecificInternalEnergy(materialParameters)); 134 | } 135 | 136 | double EulerStateVector::computeSoundSpeed(EulerMaterialParameters materialParameters) 137 | { 138 | return EulerEquationOfState::computeSoundSpeed(density, pressure, materialParameters); 139 | } 140 | 141 | void EulerStateVector::setDensity(double newDensity) 142 | { 143 | density = newDensity; 144 | } 145 | 146 | void EulerStateVector::setXVelocity(double newXVelocity) 147 | { 148 | xVelocity = newXVelocity; 149 | } 150 | 151 | void EulerStateVector::setYVelocity(double newYVelocity) 152 | { 153 | yVelocity = newYVelocity; 154 | } 155 | 156 | void EulerStateVector::setZVelocity(double newZVelocity) 157 | { 158 | zVelocity = newZVelocity; 159 | } 160 | 161 | void EulerStateVector::setPressure(double newPressure) 162 | { 163 | pressure = newPressure; 164 | } 165 | 166 | double EulerStateVector::getDensity() 167 | { 168 | return density; 169 | } 170 | 171 | double EulerStateVector::getXVelocity() 172 | { 173 | return xVelocity; 174 | } 175 | 176 | double EulerStateVector::getYVelocity() 177 | { 178 | return yVelocity; 179 | } 180 | 181 | double EulerStateVector::getZVelocity() 182 | { 183 | return zVelocity; 184 | } 185 | 186 | double EulerStateVector::getPressure() 187 | { 188 | return pressure; 189 | } 190 | -------------------------------------------------------------------------------- /Solvers/SlopeLimiters.cpp: -------------------------------------------------------------------------------- 1 | #include "SlopeLimiters.hpp" 2 | 3 | double SlopeLimiters::computeGradientRatio(double steepness, double bias) 4 | { 5 | return 2.0 / ((1.0 - bias) + ((1.0 + bias) * steepness)); 6 | } 7 | 8 | double SlopeLimiters::computeSuperBeeSlopeLimiter(double steepness, double bias) 9 | { 10 | if (steepness < 0.0) 11 | { 12 | return 0.0; 13 | } 14 | else if (steepness>= 0.0 && steepness < 0.5) 15 | { 16 | return 2.0 * steepness; 17 | } 18 | else if (steepness >= 0.5 && steepness < 1.0) 19 | { 20 | return 1.0; 21 | } 22 | else{ 23 | return min(min(steepness, computeGradientRatio(steepness, bias)), 2.0); 24 | } 25 | } 26 | 27 | double SlopeLimiters::computeVanLeerSlopeLimiter(double steepness, double bias) 28 | { 29 | if (steepness < 0.0) 30 | { 31 | return 0.0; 32 | } 33 | else 34 | { 35 | return min((2.0 * steepness) / (1.0 + steepness), computeGradientRatio(steepness, bias)); 36 | } 37 | } 38 | 39 | double SlopeLimiters::computeMinBeeSlopeLimiter(double steepness, double bias) 40 | { 41 | if (steepness < 0.0) 42 | { 43 | return 0.0; 44 | } 45 | else if (steepness >= 0.0 && steepness < 1.0) 46 | { 47 | return steepness; 48 | } 49 | else 50 | { 51 | return min(1.0, computeGradientRatio(steepness, bias)); 52 | } 53 | } 54 | 55 | double SlopeLimiters::computeSlopeLimiter(double steepness, double bias, int slopeLimiter) 56 | { 57 | if (slopeLimiter == 0) 58 | { 59 | return computeSuperBeeSlopeLimiter(steepness, bias); 60 | } 61 | else if (slopeLimiter == 1) 62 | { 63 | return computeVanLeerSlopeLimiter(steepness, bias); 64 | } 65 | else 66 | { 67 | return computeMinBeeSlopeLimiter(steepness, bias); 68 | } 69 | } 70 | 71 | vector SlopeLimiters::computeSlopeVector(vector leftConservedVariableVector, vector middleConservedVariableVector, 72 | vector rightConservedVariableVector, double bias, int slopeLimiter) 73 | { 74 | vector leftConservedVariableVectorDifference = VectorAlgebra::subtractVectors(middleConservedVariableVector, leftConservedVariableVector); 75 | vector rightConservedVariableVectorDifference = VectorAlgebra::subtractVectors(rightConservedVariableVector, middleConservedVariableVector); 76 | 77 | vector slopeVector = VectorAlgebra::addVectors(VectorAlgebra::multiplyVector(0.5 * (1.0 + bias), leftConservedVariableVectorDifference), 78 | VectorAlgebra::multiplyVector(0.5 * (1.0 - bias), rightConservedVariableVectorDifference)); 79 | long conservedVariableCount = slopeVector.size(); 80 | 81 | #pragma omp parallel for 82 | for (int i = 0; i < conservedVariableCount; i++) 83 | { 84 | double numerator = leftConservedVariableVectorDifference[i]; 85 | double denominator = rightConservedVariableVectorDifference[i]; 86 | 87 | if (abs(numerator) < pow(10.0, -5.0)) 88 | { 89 | numerator = pow(10.0, -5.0); 90 | } 91 | if (abs(denominator) < pow(10.0, -5.0)) 92 | { 93 | denominator = pow(10.0, -5.0); 94 | } 95 | 96 | double steepness = numerator / denominator; 97 | slopeVector[i] *= computeSlopeLimiter(steepness, bias, slopeLimiter); 98 | } 99 | 100 | return slopeVector; 101 | } 102 | 103 | vector SlopeLimiters::computeSlopeVector(EulerStateVector leftStateVector, EulerStateVector middleStateVector, EulerStateVector rightStateVector, 104 | double bias, int slopeLimiter, EulerMaterialParameters materialParameters) 105 | { 106 | vector leftConservedVariableVector = leftStateVector.computeConservedVariableVector(materialParameters); 107 | vector middleConservedVariableVector = middleStateVector.computeConservedVariableVector(materialParameters); 108 | vector rightConservedVariableVector = rightStateVector.computeConservedVariableVector(materialParameters); 109 | 110 | return computeSlopeVector(leftConservedVariableVector, middleConservedVariableVector, rightConservedVariableVector, bias, slopeLimiter); 111 | } 112 | 113 | vector SlopeLimiters::computeSlopeVector(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector middleStateVector, 114 | RelativisticEulerStateVector rightStateVector, double bias, int slopeLimiter, EulerMaterialParameters materialParameters) 115 | { 116 | vector leftConservedVariableVector = leftStateVector.computeConservedVariableVector(materialParameters); 117 | vector middleConservedVariableVector = middleStateVector.computeConservedVariableVector(materialParameters); 118 | vector rightConservedVariableVector = rightStateVector.computeConservedVariableVector(materialParameters); 119 | 120 | return computeSlopeVector(leftConservedVariableVector, middleConservedVariableVector, rightConservedVariableVector, bias, slopeLimiter); 121 | } 122 | 123 | vector SlopeLimiters::computeSlopeVectorX(BlackHoleEulerStateVector leftStateVector, BlackHoleEulerStateVector middleStateVector, 124 | BlackHoleEulerStateVector rightStateVector, double cellSpacing, double bias, int slopeLimiter, double xCoordinate, 125 | double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole) 126 | { 127 | vector leftConservedVariableVector = leftStateVector.computeConservedVariableVector(xCoordinate - cellSpacing, yCoordinate, zCoordinate, 128 | materialParameters, blackHole); 129 | vector middleConservedVariableVector = middleStateVector.computeConservedVariableVector(xCoordinate, yCoordinate, zCoordinate, materialParameters, blackHole); 130 | vector rightConservedVariableVector = rightStateVector.computeConservedVariableVector(xCoordinate + cellSpacing, yCoordinate, zCoordinate, 131 | materialParameters, blackHole); 132 | 133 | return computeSlopeVector(leftConservedVariableVector, middleConservedVariableVector, rightConservedVariableVector, bias, slopeLimiter); 134 | } 135 | 136 | vector SlopeLimiters::computeSlopeVectorY(BlackHoleEulerStateVector topStateVector, BlackHoleEulerStateVector middleStateVector, 137 | BlackHoleEulerStateVector bottomStateVector, double cellSpacing, double bias, int slopeLimiter, double xCoordinate, 138 | double yCoordinate, double zCoordinate, EulerMaterialParameters materialParameters, BlackHoleSpacetime blackHole) 139 | { 140 | vector topConservedVariableVector = topStateVector.computeConservedVariableVector(xCoordinate, yCoordinate - cellSpacing, zCoordinate, 141 | materialParameters, blackHole); 142 | vector middleConservedVariableVector = middleStateVector.computeConservedVariableVector(xCoordinate, yCoordinate, zCoordinate, materialParameters, blackHole); 143 | vector bottomConservedVariableVector = bottomStateVector.computeConservedVariableVector(xCoordinate, yCoordinate + cellSpacing, zCoordinate, 144 | materialParameters, blackHole); 145 | 146 | return computeSlopeVector(topConservedVariableVector, middleConservedVariableVector, bottomConservedVariableVector, bias, slopeLimiter); 147 | } 148 | -------------------------------------------------------------------------------- /Tests/EulerTests.cpp: -------------------------------------------------------------------------------- 1 | #include "EulerTests.hpp" 2 | 3 | void EulerTests::solveToroTest1(int cellCount, int order) 4 | { 5 | double cellSpacing = 1.0 / cellCount; 6 | 7 | vector initialCells(cellCount); 8 | EulerMaterialParameters materialParameters(1.4); 9 | 10 | for (int i = 0; i < cellCount; i++) 11 | { 12 | if (i <= (0.5 * cellCount)) 13 | { 14 | initialCells[i] = EulerStateVector(1.0, 0.0, 0.0, 0.0, 1.0); 15 | } 16 | else 17 | { 18 | initialCells[i] = EulerStateVector(0.125, 0.0, 0.0, 0.0, 0.1); 19 | } 20 | } 21 | 22 | if (order == 1) 23 | { 24 | outputSolution(EulerFirstOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.25, materialParameters)); 25 | } 26 | else 27 | { 28 | outputSolution(EulerSecondOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.25, 0.0, 1, materialParameters)); 29 | } 30 | } 31 | 32 | void EulerTests::solveToroTest2(int cellCount, int order) 33 | { 34 | double cellSpacing = 1.0 / cellCount; 35 | 36 | vector initialCells(cellCount); 37 | EulerMaterialParameters materialParameters(1.4); 38 | 39 | for (int i = 0; i < cellCount; i++) 40 | { 41 | if (i <= (0.5 * cellCount)) 42 | { 43 | initialCells[i] = EulerStateVector(1.0, -2.0, 0.0, 0.0, 0.4); 44 | } 45 | else 46 | { 47 | initialCells[i] = EulerStateVector(1.0, 2.0, 0.0, 0.0, 0.4); 48 | } 49 | } 50 | 51 | if (order == 1) 52 | { 53 | outputSolution(EulerFirstOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.15, materialParameters)); 54 | } 55 | else 56 | { 57 | outputSolution(EulerSecondOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.15, 0.0, 1, materialParameters)); 58 | } 59 | } 60 | 61 | void EulerTests::solveToroTest3(int cellCount, int order) 62 | { 63 | double cellSpacing = 1.0 / cellCount; 64 | 65 | vector initialCells(cellCount); 66 | EulerMaterialParameters materialParameters(1.4); 67 | 68 | for (int i = 0; i < cellCount; i++) 69 | { 70 | if (i <= (0.5 * cellCount)) 71 | { 72 | initialCells[i] = EulerStateVector(1.0, 0.0, 0.0, 0.0, 1000.0); 73 | } 74 | else 75 | { 76 | initialCells[i] = EulerStateVector(1.0, 0.0, 0.0, 0.0, 0.01); 77 | } 78 | } 79 | 80 | if (order == 1) 81 | { 82 | outputSolution(EulerFirstOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.012, materialParameters)); 83 | } 84 | else 85 | { 86 | outputSolution(EulerSecondOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.012, 0.0, 1, materialParameters)); 87 | } 88 | } 89 | 90 | void EulerTests::solve2DToroTest1(int cellCount, int order) 91 | { 92 | double cellSpacing = 1.0 / cellCount; 93 | 94 | vector > initialCells(cellCount, vector(cellCount)); 95 | EulerMaterialParameters materialParameters(1.4); 96 | 97 | for (int i = 0; i < cellCount; i++) 98 | { 99 | for (int j = 0; j < cellCount; j++) 100 | { 101 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount))) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)))) <= (0.2 * cellCount)) 102 | { 103 | initialCells[i][j] = EulerStateVector(1.0, 0.0, 0.0, 0.0, 1.0); 104 | } 105 | else 106 | { 107 | initialCells[i][j] = EulerStateVector(0.125, 0.0, 0.0, 0.0, 0.1); 108 | } 109 | } 110 | } 111 | 112 | if (order == 1) 113 | { 114 | outputSolution2D(EulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.125, materialParameters)); 115 | } 116 | else 117 | { 118 | outputSolution2D(EulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.125, 0.0, 1, materialParameters)); 119 | } 120 | } 121 | 122 | void EulerTests::solve2DToroTest2(int cellCount, int order) 123 | { 124 | double cellSpacing = 1.0 / cellCount; 125 | 126 | vector > initialCells(cellCount, vector(cellCount)); 127 | EulerMaterialParameters materialParameters(1.4); 128 | 129 | for (int i = 0; i < cellCount; i++) 130 | { 131 | for (int j = 0; j < cellCount; j++) 132 | { 133 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount))) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)))) <= (0.2 * cellCount)) 134 | { 135 | initialCells[i][j] = EulerStateVector(1.0, -2.0 * sin(atan2(j - (0.5 * cellCount), i - (0.5 * cellCount))), 136 | -2.0 * cos(atan2(j - (0.5 * cellCount), i - (0.5 * cellCount))), 0.0, 0.4); 137 | } 138 | else 139 | { 140 | initialCells[i][j] = EulerStateVector(1.0, 2.0 * sin(atan2(j - (0.5 * cellCount), i - (0.5 * cellCount))), 141 | 2.0 * cos(atan2(j - (0.5 * cellCount), i - (0.5 * cellCount))), 0.0, 0.4); 142 | } 143 | } 144 | } 145 | 146 | if (order == 1) 147 | { 148 | outputSolution2D(EulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.075, materialParameters)); 149 | } 150 | else 151 | { 152 | outputSolution2D(EulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.075, 0.0, 1, materialParameters)); 153 | } 154 | } 155 | 156 | void EulerTests::solve2DToroTest3(int cellCount, int order) 157 | { 158 | double cellSpacing = 1.0 / cellCount; 159 | 160 | vector > initialCells(cellCount, vector(cellCount)); 161 | EulerMaterialParameters materialParameters(1.4); 162 | 163 | for (int i = 0; i < cellCount; i++) 164 | { 165 | for (int j = 0; j < cellCount; j++) 166 | { 167 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount))) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)))) <= (0.2 * cellCount)) 168 | { 169 | initialCells[i][j] = EulerStateVector(1.0, 0.0, 0.0, 0.0, 1000.0); 170 | } 171 | else 172 | { 173 | initialCells[i][j] = EulerStateVector(1.0, 0.0, 0.0, 0.0, 0.01); 174 | } 175 | } 176 | } 177 | 178 | if (order == 1) 179 | { 180 | outputSolution2D(EulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.006, materialParameters)); 181 | } 182 | else 183 | { 184 | outputSolution2D(EulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.006, 0.0, 1, materialParameters)); 185 | } 186 | } 187 | 188 | 189 | void EulerTests::outputSolution(vector solution) 190 | { 191 | long cellCount = solution.size(); 192 | double cellSpacing = 1.0 / cellCount; 193 | 194 | ofstream densityFile("/Users/jonathangorard/Documents/Cosmos/density.dat"); 195 | ofstream xVelocityFile("/Users/jonathangorard/Documents/Cosmos/xVelocity.dat"); 196 | ofstream yVelocityFile("/Users/jonathangorard/Documents/Cosmos/yVelocity.dat"); 197 | ofstream zVelocityFile("/Users/jonathangorard/Documents/Cosmos/zVelocity.dat"); 198 | ofstream pressureFile("/Users/jonathangorard/Documents/Cosmos/pressure.dat"); 199 | 200 | for (int i = 0; i < cellCount; i++) 201 | { 202 | densityFile << (cellSpacing * i) << " " << solution[i].getDensity() << endl; 203 | xVelocityFile << (cellSpacing * i) << " " << solution[i].getXVelocity() << endl; 204 | yVelocityFile << (cellSpacing * i) << " " << solution[i].getYVelocity() << endl; 205 | zVelocityFile << (cellSpacing * i) << " " << solution[i].getZVelocity() << endl; 206 | pressureFile << (cellSpacing * i) << " " << solution[i].getPressure() << endl; 207 | } 208 | 209 | densityFile.close(); 210 | xVelocityFile.close(); 211 | yVelocityFile.close(); 212 | zVelocityFile.close(); 213 | pressureFile.close(); 214 | } 215 | 216 | void EulerTests::outputSolution2D(vector > solution) 217 | { 218 | long rowCount = solution.size(); 219 | long columnCount = solution[0].size(); 220 | double rowCellSpacing = 1.0 / rowCount; 221 | double columnCellSpacing = 1.0 / columnCount; 222 | 223 | ofstream densityFile("/Users/jonathangorard/Documents/Cosmos/density.dat"); 224 | ofstream xVelocityFile("/Users/jonathangorard/Documents/Cosmos/xVelocity.dat"); 225 | ofstream yVelocityFile("/Users/jonathangorard/Documents/Cosmos/yVelocity.dat"); 226 | ofstream zVelocityFile("/Users/jonathangorard/Documents/Cosmos/zVelocity.dat"); 227 | ofstream pressureFile("/Users/jonathangorard/Documents/Cosmos/pressure.dat"); 228 | 229 | for (int i = 0; i < rowCount; i++) 230 | { 231 | for (int j = 0; j < columnCount; j++) 232 | { 233 | densityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getDensity() << endl; 234 | xVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getXVelocity() << endl; 235 | yVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getYVelocity() << endl; 236 | zVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getZVelocity() << endl; 237 | pressureFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getPressure() << endl; 238 | } 239 | 240 | densityFile << endl; 241 | xVelocityFile << endl; 242 | yVelocityFile << endl; 243 | zVelocityFile << endl; 244 | pressureFile << endl; 245 | } 246 | 247 | densityFile.close(); 248 | xVelocityFile.close(); 249 | yVelocityFile.close(); 250 | zVelocityFile.close(); 251 | pressureFile.close(); 252 | } 253 | -------------------------------------------------------------------------------- /Solvers/EulerSecondOrderSolver.cpp: -------------------------------------------------------------------------------- 1 | #include "EulerSecondOrderSolver.hpp" 2 | 3 | vector EulerSecondOrderSolver::computeXSLICFlux(EulerStateVector leftLeftStateVector, EulerStateVector leftStateVector, EulerStateVector rightStateVector, 4 | EulerStateVector rightRightStateVector, double cellSpacing, double timeStep, double bias, int slopeLimiter, 5 | EulerMaterialParameters materialParameters) 6 | { 7 | EulerStateVector evolvedRightStateVector = EulerSolvers::evolveStateByHalfXTimeStep(leftLeftStateVector, leftStateVector, rightStateVector, cellSpacing, 8 | timeStep, bias, slopeLimiter, 1, materialParameters); 9 | EulerStateVector evolvedLeftStateVector = EulerSolvers::evolveStateByHalfXTimeStep(leftStateVector, rightStateVector, rightRightStateVector, cellSpacing, 10 | timeStep, bias, slopeLimiter, 0, materialParameters); 11 | 12 | return EulerFirstOrderSolver::computeXFORCEFlux(evolvedRightStateVector, evolvedLeftStateVector, cellSpacing, timeStep, materialParameters); 13 | } 14 | 15 | vector EulerSecondOrderSolver::computeYSLICFlux(EulerStateVector topTopStateVector, EulerStateVector topStateVector, EulerStateVector bottomStateVector, 16 | EulerStateVector bottomBottomStateVector, double cellSpacing, double timeStep, double bias, int slopeLimiter, 17 | EulerMaterialParameters materialParameters) 18 | { 19 | EulerStateVector evolvedBottomStateVector = EulerSolvers::evolveStateByHalfYTimeStep(topTopStateVector, topStateVector, bottomStateVector, cellSpacing, 20 | timeStep, bias, slopeLimiter, 1, materialParameters); 21 | EulerStateVector evolvedTopStateVector = EulerSolvers::evolveStateByHalfYTimeStep(topStateVector, bottomStateVector, bottomBottomStateVector, cellSpacing, 22 | timeStep, bias, slopeLimiter, 0, materialParameters); 23 | 24 | return EulerFirstOrderSolver::computeYFORCEFlux(evolvedBottomStateVector, evolvedTopStateVector, cellSpacing, timeStep, materialParameters); 25 | } 26 | 27 | void EulerSecondOrderSolver::computeSLICTimeStep(vector & currentCells, double cellSpacing, double timeStep, double bias, int slopeLimiter, 28 | EulerMaterialParameters materialParameters) 29 | { 30 | long cellCount = currentCells.size(); 31 | vector currentCellsWithBoundary = EulerSolvers::insertBoundaryCells(currentCells, 2); 32 | 33 | #pragma omp parallel for 34 | for (int i = 0; i < cellCount; i++) 35 | { 36 | vector conservedVariableVector = currentCells[i].computeConservedVariableVector(materialParameters); 37 | 38 | vector leftFluxVector = computeXSLICFlux(currentCellsWithBoundary[i], currentCellsWithBoundary[i + 1], currentCellsWithBoundary[i + 2], 39 | currentCellsWithBoundary[i + 3], cellSpacing, timeStep, bias, slopeLimiter, materialParameters); 40 | vector rightFluxVector = computeXSLICFlux(currentCellsWithBoundary[i + 1], currentCellsWithBoundary[i + 2], currentCellsWithBoundary[i + 3], 41 | currentCellsWithBoundary[i + 4], cellSpacing, timeStep, bias, slopeLimiter, materialParameters); 42 | 43 | currentCells[i].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, leftFluxVector, rightFluxVector, cellSpacing, 44 | timeStep), materialParameters); 45 | } 46 | } 47 | 48 | void EulerSecondOrderSolver::computeXSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, 49 | int slopeLimiter, EulerMaterialParameters materialParameters) 50 | { 51 | long rowCount = currentCells.size(); 52 | long columnCount = currentCells[0].size(); 53 | vector > currentCellsWithBoundary = EulerSolvers::insertBoundaryCells2D(currentCells, 2); 54 | 55 | #pragma omp parallel for 56 | for (int i= 0; i < rowCount; i++) 57 | { 58 | for (int j = 0; j < columnCount; j++) 59 | { 60 | vector conservedVariableVector = currentCells[i][j].computeConservedVariableVector(materialParameters); 61 | 62 | vector leftFluxVector = computeXSLICFlux(currentCellsWithBoundary[i + 2][j], currentCellsWithBoundary[i + 2][j + 1], 63 | currentCellsWithBoundary[i + 2][j + 2], currentCellsWithBoundary[i + 2][j + 3], cellSpacing, timeStep, 64 | bias, slopeLimiter, materialParameters); 65 | vector rightFluxVector = computeXSLICFlux(currentCellsWithBoundary[i + 2][j + 1], currentCellsWithBoundary[i + 2][j + 2], 66 | currentCellsWithBoundary[i + 2][j + 3], currentCellsWithBoundary[i + 2][j + 4], cellSpacing, timeStep, 67 | bias, slopeLimiter, materialParameters); 68 | 69 | currentCells[i][j].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, leftFluxVector, rightFluxVector, 70 | cellSpacing, timeStep), materialParameters); 71 | } 72 | } 73 | } 74 | 75 | void EulerSecondOrderSolver::computeYSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, double bias, 76 | int slopeLimiter, EulerMaterialParameters materialParameters) 77 | { 78 | long rowCount = currentCells.size(); 79 | long columnCount = currentCells[0].size(); 80 | vector > currentCellsWithBoundary = EulerSolvers::insertBoundaryCells2D(currentCells, 2); 81 | 82 | #pragma omp parallel for 83 | for (int i = 0; i < rowCount; i++) 84 | { 85 | for (int j = 0; j < columnCount; j++) 86 | { 87 | vector conservedVariableVector = currentCells[i][j].computeConservedVariableVector(materialParameters); 88 | 89 | vector topFluxVector = computeYSLICFlux(currentCellsWithBoundary[i][j + 2], currentCellsWithBoundary[i + 1][j + 2], 90 | currentCellsWithBoundary[i + 2][j + 2], currentCellsWithBoundary[i + 3][j + 2], cellSpacing, timeStep, 91 | bias, slopeLimiter, materialParameters); 92 | vector bottomFluxVector = computeYSLICFlux(currentCellsWithBoundary[i + 1][j + 2], currentCellsWithBoundary[i + 2][j + 2], 93 | currentCellsWithBoundary[i + 3][j + 2], currentCellsWithBoundary[i + 4][j + 2], cellSpacing, timeStep, 94 | bias, slopeLimiter, materialParameters); 95 | 96 | currentCells[i][j].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, topFluxVector, bottomFluxVector, 97 | cellSpacing, timeStep), materialParameters); 98 | } 99 | } 100 | } 101 | 102 | vector EulerSecondOrderSolver::solve(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 103 | double bias, int slopeLimiter, EulerMaterialParameters materialParameters) 104 | { 105 | double currentTime = 0.0; 106 | int currentIteration = 0; 107 | vector currentCells = initialCells; 108 | 109 | while (currentTime < finalTime) 110 | { 111 | double timeStep = EulerSolvers::computeStableTimeStep(currentCells, cellSpacing, CFLCoefficient, currentTime, finalTime, currentIteration, materialParameters); 112 | 113 | computeSLICTimeStep(currentCells, cellSpacing, timeStep, bias, slopeLimiter, materialParameters); 114 | 115 | currentTime += timeStep; 116 | currentIteration += 1; 117 | 118 | EulerSolvers::outputStatus(currentIteration, currentTime, timeStep); 119 | } 120 | 121 | return currentCells; 122 | } 123 | 124 | vector > EulerSecondOrderSolver::solve2D(vector > initialCells, double cellSpacing, double CFLCoefficient, 125 | double finalTime, double bias, int slopeLimiter, EulerMaterialParameters materialParameters) 126 | { 127 | double currentTime = 0.0; 128 | int currentIteration = 0; 129 | vector > currentCells = initialCells; 130 | 131 | while (currentTime < finalTime) 132 | { 133 | double timeStep = EulerSolvers::computeStableTimeStep2D(currentCells, cellSpacing, CFLCoefficient, currentTime, finalTime, currentIteration, 134 | materialParameters); 135 | 136 | computeXSLICTimeStep2D(currentCells, cellSpacing, 0.5 * timeStep, bias, slopeLimiter, materialParameters); 137 | computeYSLICTimeStep2D(currentCells, cellSpacing, timeStep, bias, slopeLimiter, materialParameters); 138 | computeXSLICTimeStep2D(currentCells, cellSpacing, 0.5 * timeStep, bias, slopeLimiter, materialParameters); 139 | 140 | currentTime += timeStep; 141 | currentIteration += 1; 142 | 143 | EulerSolvers::outputStatus(currentIteration, currentTime, timeStep); 144 | } 145 | 146 | return currentCells; 147 | } 148 | -------------------------------------------------------------------------------- /Tests/RelativisticEulerTests.cpp: -------------------------------------------------------------------------------- 1 | #include "RelativisticEulerTests.hpp" 2 | 3 | void RelativisticEulerTests::solveMildlyRelativisticShock(int cellCount, int order) 4 | { 5 | double cellSpacing = 1.0 / cellCount; 6 | 7 | vector initialCells(cellCount); 8 | EulerMaterialParameters materialParameters(5.0 / 3.0); 9 | 10 | for (int i = 0; i < cellCount; i++) 11 | { 12 | if (i <= (0.5 * cellCount)) 13 | { 14 | initialCells[i] = RelativisticEulerStateVector(10.0, 0.0, 0.0, 0.0, 13.3); 15 | } 16 | else 17 | { 18 | initialCells[i] = RelativisticEulerStateVector(1.0, 0.0, 0.0, 0.0, 0.0); 19 | } 20 | } 21 | 22 | if (order == 1) 23 | { 24 | outputSolution(RelativisticEulerFirstOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.4, materialParameters)); 25 | } 26 | else 27 | { 28 | outputSolution(RelativisticEulerSecondOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.01, 0.0, 1, materialParameters)); 29 | } 30 | } 31 | 32 | void RelativisticEulerTests::solveStronglyRelativisticBlast(int cellCount, int order) 33 | { 34 | double cellSpacing = 1.0 / cellCount; 35 | 36 | vector initialCells(cellCount); 37 | EulerMaterialParameters materialParameters(5.0 / 3.0); 38 | 39 | for (int i = 0; i < cellCount; i++) 40 | { 41 | if (i <= (0.5 * cellCount)) 42 | { 43 | initialCells[i] = RelativisticEulerStateVector(1.0, 0.0, 0.0, 0.0, 1000.0); 44 | } 45 | else 46 | { 47 | initialCells[i] = RelativisticEulerStateVector(1.0, 0.0, 0.0, 0.0, 0.01); 48 | } 49 | } 50 | 51 | if (order == 1) 52 | { 53 | outputSolution(RelativisticEulerFirstOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.4, materialParameters)); 54 | } 55 | else 56 | { 57 | outputSolution(RelativisticEulerSecondOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.4, 0.0, 1, materialParameters)); 58 | } 59 | } 60 | 61 | void RelativisticEulerTests::solvePerturbedDensityTest(int cellCount, int order) 62 | { 63 | double cellSpacing = 1.0 / cellCount; 64 | 65 | vector initialCells(cellCount); 66 | EulerMaterialParameters materialParameters(5.0 / 3.0); 67 | 68 | for (int i = 0; i < cellCount; i++) 69 | { 70 | if (i <= (0.5 * cellCount)) 71 | { 72 | initialCells[i] = RelativisticEulerStateVector(5.0, 0.0, 0.0, 0.0, 50.0); 73 | } 74 | else 75 | { 76 | initialCells[i] = RelativisticEulerStateVector(2.0 + 0.3 * sin(50.0 * (cellSpacing * i)), 0.0, 0.0, 0.0, 5.0); 77 | } 78 | } 79 | 80 | if (order == 1) 81 | { 82 | outputSolution(RelativisticEulerFirstOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.35, materialParameters)); 83 | } 84 | else 85 | { 86 | outputSolution(RelativisticEulerSecondOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.35, 0.0, 1, materialParameters)); 87 | } 88 | } 89 | 90 | void RelativisticEulerTests::solve2DMildlyRelativisticShock(int cellCount, int order) 91 | { 92 | double cellSpacing = 1.0 / cellCount; 93 | 94 | vector > initialCells(cellCount, vector(cellCount)); 95 | EulerMaterialParameters materialParameters(5.0 / 3.0); 96 | 97 | for (int i = 0; i < cellCount; i++) 98 | { 99 | for (int j = 0; j < cellCount; j++) 100 | { 101 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount))) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)))) <= (0.2 * cellCount)) 102 | { 103 | initialCells[i][j] = RelativisticEulerStateVector(10.0, 0.0, 0.0, 0.0, 13.3); 104 | } 105 | else 106 | { 107 | initialCells[i][j] = RelativisticEulerStateVector(1.0, 0.0, 0.0, 0.0, 0.0); 108 | } 109 | } 110 | } 111 | 112 | if (order == 1) 113 | { 114 | outputSolution2D(RelativisticEulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.2, materialParameters)); 115 | } 116 | else 117 | { 118 | outputSolution2D(RelativisticEulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.2, 0.0, 1, materialParameters)); 119 | } 120 | } 121 | 122 | void RelativisticEulerTests::solve2DStronglyRelativisticBlast(int cellCount, int order) 123 | { 124 | double cellSpacing = 1.0 / cellCount; 125 | 126 | vector > initialCells(cellCount, vector(cellCount)); 127 | EulerMaterialParameters materialParameters(5.0 / 3.0); 128 | 129 | for (int i = 0; i < cellCount; i++) 130 | { 131 | for (int j = 0; j < cellCount; j++) 132 | { 133 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount))) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)))) <= (0.2 * cellCount)) 134 | { 135 | initialCells[i][j] = RelativisticEulerStateVector(1.0, 0.0, 0.0, 0.0, 1000.0); 136 | } 137 | else 138 | { 139 | initialCells[i][j] = RelativisticEulerStateVector(1.0, 0.0, 0.0, 0.0, 0.01); 140 | } 141 | } 142 | } 143 | 144 | if (order == 1) 145 | { 146 | outputSolution2D(RelativisticEulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.15, materialParameters)); 147 | } 148 | else 149 | { 150 | outputSolution2D(RelativisticEulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.15, 0.0, 1, materialParameters)); 151 | } 152 | } 153 | 154 | void RelativisticEulerTests::solve2DPerturbedDensityTest(int cellCount, int order) 155 | { 156 | double cellSpacing = 1.0 / cellCount; 157 | 158 | vector > initialCells(cellCount, vector(cellCount)); 159 | EulerMaterialParameters materialParameters(5.0 / 3.0); 160 | 161 | for (int i = 0; i < cellCount; i++) 162 | { 163 | for (int j = 0; j < cellCount; j++) 164 | { 165 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount))) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)))) <= (0.2 * cellCount)) 166 | { 167 | initialCells[i][j] = RelativisticEulerStateVector(5.0, 0.0, 0.0, 0.0, 50.0); 168 | } 169 | else 170 | { 171 | initialCells[i][j] = RelativisticEulerStateVector(2.0 + 0.3 * sin(50.0 * sqrt(((cellSpacing * (i - (0.5 * cellCount))) * 172 | (cellSpacing * (i - (0.5 * cellCount)))) + 173 | ((cellSpacing * (j - (0.5 * cellCount))) * 174 | (cellSpacing * (j - (0.5 * cellCount)))))), 0.0, 0.0, 0.0, 5.0); 175 | } 176 | } 177 | } 178 | 179 | if (order == 1) 180 | { 181 | outputSolution2D(RelativisticEulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.175, materialParameters)); 182 | } 183 | else 184 | { 185 | outputSolution2D(RelativisticEulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.175, 0.0, 1, materialParameters)); 186 | } 187 | } 188 | 189 | void RelativisticEulerTests::outputSolution(vector solution) 190 | { 191 | long cellCount = solution.size(); 192 | double cellSpacing = 1.0 / cellCount; 193 | 194 | ofstream densityFile("/Users/jonathangorard/Documents/Cosmos/density.dat"); 195 | ofstream xVelocityFile("/Users/jonathangorard/Documents/Cosmos/xVelocity.dat"); 196 | ofstream yVelocityFile("/Users/jonathangorard/Documents/Cosmos/yVelocity.dat"); 197 | ofstream zVelocityFile("/Users/jonathangorard/Documents/Cosmos/zVelocity.dat"); 198 | ofstream pressureFile("/Users/jonathangorard/Documents/Cosmos/pressure.dat"); 199 | 200 | for (int i = 0; i < cellCount; i++) 201 | { 202 | densityFile << (cellSpacing * i) << " " << solution[i].getDensity() << endl; 203 | xVelocityFile << (cellSpacing * i) << " " << solution[i].getXVelocity() << endl; 204 | yVelocityFile << (cellSpacing * i) << " " << solution[i].getYVelocity() << endl; 205 | zVelocityFile << (cellSpacing * i) << " " << solution[i].getZVelocity() << endl; 206 | pressureFile << (cellSpacing * i) << " " << solution[i].getPressure() << endl; 207 | } 208 | 209 | densityFile.close(); 210 | xVelocityFile.close(); 211 | yVelocityFile.close(); 212 | zVelocityFile.close(); 213 | pressureFile.close(); 214 | } 215 | 216 | void RelativisticEulerTests::outputSolution2D(vector > solution) 217 | { 218 | long rowCount = solution.size(); 219 | long columnCount = solution[0].size(); 220 | double rowCellSpacing = 1.0 / rowCount; 221 | double columnCellSpacing = 1.0 / columnCount; 222 | 223 | ofstream densityFile("/Users/jonathangorard/Documents/Cosmos/density.dat"); 224 | ofstream xVelocityFile("/Users/jonathangorard/Documents/Cosmos/xVelocity.dat"); 225 | ofstream yVelocityFile("/Users/jonathangorard/Documents/Cosmos/yVelocity.dat"); 226 | ofstream zVelocityFile("/Users/jonathangorard/Documents/Cosmos/zVelocity.dat"); 227 | ofstream pressureFile("/Users/jonathangorard/Documents/Cosmos/pressure.dat"); 228 | 229 | for (int i = 0; i < rowCount; i++) 230 | { 231 | for (int j = 0; j < columnCount; j++) 232 | { 233 | densityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getDensity() << endl; 234 | xVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getXVelocity() << endl; 235 | yVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getYVelocity() << endl; 236 | zVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getZVelocity() << endl; 237 | pressureFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getPressure() << endl; 238 | } 239 | 240 | densityFile << endl; 241 | xVelocityFile << endl; 242 | yVelocityFile << endl; 243 | zVelocityFile << endl; 244 | pressureFile << endl; 245 | } 246 | 247 | densityFile.close(); 248 | xVelocityFile.close(); 249 | yVelocityFile.close(); 250 | zVelocityFile.close(); 251 | pressureFile.close(); 252 | } 253 | -------------------------------------------------------------------------------- /Solvers/RelativisticEulerSolvers.cpp: -------------------------------------------------------------------------------- 1 | #include "RelativisticEulerSolvers.hpp" 2 | 3 | vector RelativisticEulerSolvers::insertBoundaryCells(vector & currentCells, int boundarySize) 4 | { 5 | long cellCount = currentCells.size(); 6 | vector currentCellsWithBoundary(cellCount + (2 * boundarySize)); 7 | 8 | if (boundarySize == 1) 9 | { 10 | currentCellsWithBoundary[0] = currentCells[0]; 11 | currentCellsWithBoundary[cellCount + 1] = currentCells[cellCount - 1]; 12 | } 13 | else if (boundarySize == 2) 14 | { 15 | currentCellsWithBoundary[0] = currentCells[1]; 16 | currentCellsWithBoundary[1] = currentCells[0]; 17 | currentCellsWithBoundary[cellCount + 2] = currentCells[cellCount - 1]; 18 | currentCellsWithBoundary[cellCount + 3] = currentCells[cellCount - 2]; 19 | } 20 | 21 | #pragma omp parallel for 22 | for (int i = 0; i < cellCount; i++) 23 | { 24 | currentCellsWithBoundary[i + boundarySize] = currentCells[i]; 25 | } 26 | 27 | return currentCellsWithBoundary; 28 | } 29 | 30 | vector > RelativisticEulerSolvers::insertBoundaryCells2D(vector > & currentCells, 31 | int boundarySize) 32 | { 33 | long rowCount = currentCells.size(); 34 | long columnCount = currentCells[0].size(); 35 | vector > currentCellsWithBoundary(rowCount + (2 * boundarySize), 36 | vector(columnCount + (2 * boundarySize))); 37 | 38 | if (boundarySize == 1) 39 | { 40 | #pragma omp parallel for 41 | for (int i = 0; i < rowCount; i++) 42 | { 43 | currentCellsWithBoundary[i + 1][0] = currentCells[i][0]; 44 | currentCellsWithBoundary[i + 1][columnCount + 1] = currentCells[i][columnCount - 1]; 45 | } 46 | 47 | #pragma omp parallel for 48 | for (int i = 0; i < columnCount; i++) 49 | { 50 | currentCellsWithBoundary[0][i + 1] = currentCells[0][i]; 51 | currentCellsWithBoundary[rowCount + 1][i + 1] = currentCells[rowCount - 1][i]; 52 | } 53 | } 54 | else if (boundarySize == 2) 55 | { 56 | #pragma omp parallel for 57 | for (int i = 0; i < rowCount; i++) 58 | { 59 | currentCellsWithBoundary[i + 2][0] = currentCells[i][1]; 60 | currentCellsWithBoundary[i + 2][1] = currentCells[i][0]; 61 | 62 | currentCellsWithBoundary[i + 2][columnCount + 2] = currentCells[i][columnCount - 1]; 63 | currentCellsWithBoundary[i + 2][columnCount + 3] = currentCells[i][columnCount - 2]; 64 | } 65 | 66 | #pragma omp parallel for 67 | for (int i = 0; i < columnCount; i++) 68 | { 69 | currentCellsWithBoundary[0][i + 2] = currentCells[1][i]; 70 | currentCellsWithBoundary[1][i + 2] = currentCells[0][i]; 71 | 72 | currentCellsWithBoundary[rowCount + 2][i + 2] = currentCells[rowCount - 1][i]; 73 | currentCellsWithBoundary[rowCount + 3][i + 2] = currentCells[rowCount - 2][i]; 74 | } 75 | } 76 | 77 | #pragma omp parallel for 78 | for (int i = 0; i < rowCount; i++) 79 | { 80 | for (int j = 0; j < columnCount; j++) 81 | { 82 | currentCellsWithBoundary[i + boundarySize][j + boundarySize] = currentCells[i][j]; 83 | } 84 | } 85 | 86 | return currentCellsWithBoundary; 87 | } 88 | 89 | double RelativisticEulerSolvers::computeMaximumWaveSpeed(vector & currentCells, EulerMaterialParameters materialParameters) 90 | { 91 | double maximumWaveSpeed = 0.0; 92 | long cellCount = currentCells.size(); 93 | 94 | #pragma omp parallel for 95 | for (int i = 0; i < cellCount; i++) 96 | { 97 | double waveSpeed = abs(currentCells[i].getXVelocity()) + abs(currentCells[i].computeSoundSpeed(materialParameters)); 98 | 99 | if (waveSpeed > maximumWaveSpeed) 100 | { 101 | maximumWaveSpeed = waveSpeed; 102 | } 103 | } 104 | 105 | return maximumWaveSpeed; 106 | } 107 | 108 | double RelativisticEulerSolvers::computeMaximumWaveSpeed2D(vector > & currentCells, EulerMaterialParameters materialParameters) 109 | { 110 | double maximumWaveSpeed = 0.0; 111 | long rowCount = currentCells.size(); 112 | long columnCount = currentCells[0].size(); 113 | 114 | #pragma omp parallel for 115 | for (int i = 0; i < rowCount; i++) 116 | { 117 | for (int j = 0; j < columnCount; j++) 118 | { 119 | double waveSpeed = max(abs(currentCells[i][j].getXVelocity()), abs(currentCells[i][j].getYVelocity())) + 120 | abs(currentCells[i][j].computeSoundSpeed(materialParameters)); 121 | 122 | if (waveSpeed > maximumWaveSpeed) 123 | { 124 | maximumWaveSpeed = waveSpeed; 125 | } 126 | } 127 | } 128 | 129 | return maximumWaveSpeed; 130 | } 131 | 132 | double RelativisticEulerSolvers::computeStableTimeStep(vector currentCells, double cellSpacing, double CFLCoefficient, 133 | double currentTime, double finalTime, int currentIteration, EulerMaterialParameters materialParameters) 134 | { 135 | double timeStep = CFLCoefficient * (cellSpacing / computeMaximumWaveSpeed(currentCells, materialParameters)); 136 | 137 | return EulerSolvers::computeStableTimeStep(timeStep, currentTime, finalTime, currentIteration); 138 | } 139 | 140 | double RelativisticEulerSolvers::computeStableTimeStep2D(vector > currentCells, double cellSpacing, double CFLCoefficient, 141 | double currentTime, double finalTime, int currentIteration, EulerMaterialParameters materialParameters) 142 | { 143 | double timeStep = CFLCoefficient * (cellSpacing / computeMaximumWaveSpeed2D(currentCells, materialParameters)); 144 | 145 | return EulerSolvers::computeStableTimeStep(timeStep, currentTime, finalTime, currentIteration); 146 | } 147 | 148 | RelativisticEulerStateVector RelativisticEulerSolvers::evolveStateByHalfTimeStep(vector leftExtrapolatedValue, vector rightExtrapolatedValue, 149 | vector evolutionVector, int side, EulerMaterialParameters materialParameters) 150 | { 151 | RelativisticEulerStateVector evolvedStateVector; 152 | 153 | if (side == 0) 154 | { 155 | evolvedStateVector.setConservedVariableVector(VectorAlgebra::addVectors(leftExtrapolatedValue, evolutionVector), materialParameters); 156 | } 157 | else 158 | { 159 | evolvedStateVector.setConservedVariableVector(VectorAlgebra::addVectors(rightExtrapolatedValue, evolutionVector), materialParameters); 160 | } 161 | 162 | return evolvedStateVector; 163 | } 164 | 165 | RelativisticEulerStateVector RelativisticEulerSolvers::evolveStateByHalfXTimeStep(RelativisticEulerStateVector leftStateVector, 166 | RelativisticEulerStateVector middleStateVector, 167 | RelativisticEulerStateVector rightStateVector, double cellSpacing, double timeStep, 168 | double bias, int slopeLimiter, int side, EulerMaterialParameters materialParameters) 169 | { 170 | vector slopeVector = SlopeLimiters::computeSlopeVector(leftStateVector, middleStateVector, rightStateVector, bias, slopeLimiter, materialParameters); 171 | vector leftExtrapolatedValue = VectorAlgebra::subtractVectors(middleStateVector.computeConservedVariableVector(materialParameters), 172 | VectorAlgebra::multiplyVector(0.5, slopeVector)); 173 | vector rightExtrapolatedValue = VectorAlgebra::addVectors(middleStateVector.computeConservedVariableVector(materialParameters), 174 | VectorAlgebra::multiplyVector(0.5, slopeVector)); 175 | 176 | vector leftFluxVector = RelativisticEulerStateVector::computeXFluxVector(leftExtrapolatedValue, materialParameters); 177 | vector rightFluxVector = RelativisticEulerStateVector::computeXFluxVector(rightExtrapolatedValue, materialParameters); 178 | vector evolutionVector = EulerSolvers::computeEvolutionVector(leftFluxVector, rightFluxVector, cellSpacing, timeStep); 179 | 180 | return evolveStateByHalfTimeStep(leftExtrapolatedValue, rightExtrapolatedValue, evolutionVector, side, materialParameters); 181 | } 182 | 183 | RelativisticEulerStateVector RelativisticEulerSolvers::evolveStateByHalfYTimeStep(RelativisticEulerStateVector topStateVector, 184 | RelativisticEulerStateVector middleStateVector, 185 | RelativisticEulerStateVector bottomStateVector, double cellSpacing, double timeStep, 186 | double bias, int slopeLimiter, int side, EulerMaterialParameters materialParameters) 187 | { 188 | vector slopeVector = SlopeLimiters::computeSlopeVector(topStateVector, middleStateVector, bottomStateVector, bias, slopeLimiter, materialParameters); 189 | vector topExtrapolatedValue = VectorAlgebra::subtractVectors(middleStateVector.computeConservedVariableVector(materialParameters), 190 | VectorAlgebra::multiplyVector(0.5, slopeVector)); 191 | vector bottomExtrapolatedValue = VectorAlgebra::addVectors(middleStateVector.computeConservedVariableVector(materialParameters), 192 | VectorAlgebra::multiplyVector(0.5, slopeVector)); 193 | 194 | vector topFluxVector = RelativisticEulerStateVector::computeYFluxVector(topExtrapolatedValue, materialParameters); 195 | vector bottomFluxVector = RelativisticEulerStateVector::computeYFluxVector(bottomExtrapolatedValue, materialParameters); 196 | vector evolutionVector = EulerSolvers::computeEvolutionVector(topFluxVector, bottomFluxVector, cellSpacing, timeStep); 197 | 198 | return evolveStateByHalfTimeStep(topExtrapolatedValue, bottomExtrapolatedValue, evolutionVector, side, materialParameters); 199 | } 200 | -------------------------------------------------------------------------------- /Solvers/EulerSolvers.cpp: -------------------------------------------------------------------------------- 1 | #include "EulerSolvers.hpp" 2 | 3 | vector EulerSolvers::insertBoundaryCells(vector & currentCells, int boundarySize) 4 | { 5 | long cellCount = currentCells.size(); 6 | vector currentCellsWithBoundary(cellCount + (2 * boundarySize)); 7 | 8 | if (boundarySize == 1) 9 | { 10 | currentCellsWithBoundary[0] = currentCells[0]; 11 | currentCellsWithBoundary[cellCount + 1] = currentCells[cellCount - 1]; 12 | } 13 | else if (boundarySize == 2) 14 | { 15 | currentCellsWithBoundary[0] = currentCells[1]; 16 | currentCellsWithBoundary[1] = currentCells[0]; 17 | currentCellsWithBoundary[cellCount + 2] = currentCells[cellCount - 1]; 18 | currentCellsWithBoundary[cellCount + 3] = currentCells[cellCount - 2]; 19 | } 20 | 21 | #pragma omp parallel for 22 | for (int i = 0; i < cellCount; i++) 23 | { 24 | currentCellsWithBoundary[i + boundarySize] = currentCells[i]; 25 | } 26 | 27 | return currentCellsWithBoundary; 28 | } 29 | 30 | vector > EulerSolvers::insertBoundaryCells2D(vector > & currentCells, int boundarySize) 31 | { 32 | long rowCount = currentCells.size(); 33 | long columnCount = currentCells[0].size(); 34 | vector > currentCellsWithBoundary(rowCount + (2 * boundarySize), vector(columnCount + (2 * boundarySize))); 35 | 36 | if (boundarySize == 1) 37 | { 38 | #pragma omp parallel for 39 | for (int i = 0; i < rowCount; i++) 40 | { 41 | currentCellsWithBoundary[i + 1][0] = currentCells[i][0]; 42 | currentCellsWithBoundary[i + 1][columnCount + 1] = currentCells[i][columnCount - 1]; 43 | } 44 | 45 | #pragma omp parallel for 46 | for (int i = 0; i < columnCount; i++) 47 | { 48 | currentCellsWithBoundary[0][i + 1] = currentCells[0][i]; 49 | currentCellsWithBoundary[rowCount + 1][i + 1] = currentCells[rowCount - 1][i]; 50 | } 51 | } 52 | else if (boundarySize == 2) 53 | { 54 | #pragma omp parallel for 55 | for (int i = 0; i < rowCount; i++) 56 | { 57 | currentCellsWithBoundary[i + 2][0] = currentCells[i][1]; 58 | currentCellsWithBoundary[i + 2][1] = currentCells[i][0]; 59 | 60 | currentCellsWithBoundary[i + 2][columnCount + 2] = currentCells[i][columnCount - 1]; 61 | currentCellsWithBoundary[i + 2][columnCount + 3] = currentCells[i][columnCount - 2]; 62 | } 63 | 64 | #pragma omp parallel for 65 | for (int i = 0; i < columnCount; i++) 66 | { 67 | currentCellsWithBoundary[0][i + 2] = currentCells[1][i]; 68 | currentCellsWithBoundary[1][i + 2] = currentCells[0][i]; 69 | 70 | currentCellsWithBoundary[rowCount + 2][i + 2] = currentCells[rowCount - 1][i]; 71 | currentCellsWithBoundary[rowCount + 3][i + 2] = currentCells[rowCount - 2][i]; 72 | } 73 | } 74 | 75 | #pragma omp parallel for 76 | for (int i = 0; i < rowCount; i++) 77 | { 78 | for (int j = 0; j < columnCount; j++) 79 | { 80 | currentCellsWithBoundary[i + boundarySize][j + boundarySize] = currentCells[i][j]; 81 | } 82 | } 83 | 84 | return currentCellsWithBoundary; 85 | } 86 | 87 | double EulerSolvers::computeMaximumWaveSpeed(vector & currentCells, EulerMaterialParameters materialParameters) 88 | { 89 | double maximumWaveSpeed = 0.0; 90 | long cellCount = currentCells.size(); 91 | 92 | #pragma omp parallel for 93 | for (int i = 0; i < cellCount; i++) 94 | { 95 | double waveSpeed = abs(currentCells[i].getXVelocity()) + abs(currentCells[i].computeSoundSpeed(materialParameters)); 96 | 97 | if (waveSpeed > maximumWaveSpeed) 98 | { 99 | maximumWaveSpeed = waveSpeed; 100 | } 101 | } 102 | 103 | return maximumWaveSpeed; 104 | } 105 | 106 | double EulerSolvers::computeMaximumWaveSpeed2D(vector > & currentCells, EulerMaterialParameters materialParameters) 107 | { 108 | double maximumWaveSpeed = 0.0; 109 | long rowCount = currentCells.size(); 110 | long columnCount = currentCells[0].size(); 111 | 112 | #pragma omp parallel for 113 | for (int i = 0; i < rowCount; i++) 114 | { 115 | for (int j = 0; j < columnCount; j++) 116 | { 117 | double waveSpeed = max(abs(currentCells[i][j].getXVelocity()), abs(currentCells[i][j].getYVelocity()) + 118 | abs(currentCells[i][j].computeSoundSpeed(materialParameters))); 119 | 120 | if (waveSpeed > maximumWaveSpeed) 121 | { 122 | maximumWaveSpeed = waveSpeed; 123 | } 124 | } 125 | } 126 | 127 | return maximumWaveSpeed; 128 | } 129 | 130 | double EulerSolvers::computeStableTimeStep(double timeStep, double currentTime, double finalTime, int currentIteration) 131 | { 132 | double newTimeStep = timeStep; 133 | 134 | if (currentIteration <= 5) 135 | { 136 | newTimeStep *= 0.2; 137 | } 138 | 139 | if ((currentTime + newTimeStep) > finalTime) 140 | { 141 | newTimeStep = finalTime - currentTime; 142 | } 143 | 144 | return newTimeStep; 145 | } 146 | 147 | double EulerSolvers::computeStableTimeStep(vector currentCells, double cellSpacing, double CFLCoefficient, double currentTime, double finalTime, 148 | int currentIteration, EulerMaterialParameters materialParameters) 149 | { 150 | double timeStep = CFLCoefficient * (cellSpacing / computeMaximumWaveSpeed(currentCells, materialParameters)); 151 | 152 | return computeStableTimeStep(timeStep, currentTime, finalTime, currentIteration); 153 | } 154 | 155 | double EulerSolvers::computeStableTimeStep2D(vector > currentCells, double cellSpacing, double CFLCoefficient, double currentTime, 156 | double finalTime, int currentIteration, EulerMaterialParameters materialParameters) 157 | { 158 | double timeStep = CFLCoefficient * (cellSpacing / computeMaximumWaveSpeed2D(currentCells, materialParameters)); 159 | 160 | return computeStableTimeStep(timeStep, currentTime, finalTime, currentIteration); 161 | } 162 | 163 | vector EulerSolvers::computeFractionalEvolutionVector(double stepFraction, vector leftFluxVector, vector rightFluxVector, double cellSpacing, 164 | double timeStep) 165 | { 166 | return VectorAlgebra::multiplyVector(stepFraction * (timeStep / cellSpacing), VectorAlgebra::subtractVectors(leftFluxVector, rightFluxVector)); 167 | } 168 | 169 | vector EulerSolvers::computeEvolutionVector(vector leftFluxVector, vector rightFluxVector, double cellSpacing, double timeStep) 170 | { 171 | return computeFractionalEvolutionVector(0.5, leftFluxVector, rightFluxVector, cellSpacing, timeStep); 172 | } 173 | 174 | EulerStateVector EulerSolvers::evolveStateByHalfTimeStep(vector leftExtrapolatedValue, vector rightExtrapolatedValue, vector evolutionVector, 175 | int side, EulerMaterialParameters materialParameters) 176 | { 177 | EulerStateVector evolvedStateVector; 178 | 179 | if (side == 0) 180 | { 181 | evolvedStateVector.setConservedVariableVector(VectorAlgebra::addVectors(leftExtrapolatedValue, evolutionVector), materialParameters); 182 | } 183 | else 184 | { 185 | evolvedStateVector.setConservedVariableVector(VectorAlgebra::addVectors(rightExtrapolatedValue, evolutionVector), materialParameters); 186 | } 187 | 188 | return evolvedStateVector; 189 | } 190 | 191 | EulerStateVector EulerSolvers::evolveStateByHalfXTimeStep(EulerStateVector leftStateVector, EulerStateVector middleStateVector, EulerStateVector rightStateVector, 192 | double cellSpacing, double timeStep, double bias, int slopeLimiter, int side, 193 | EulerMaterialParameters materialParameters) 194 | { 195 | vector slopeVector = SlopeLimiters::computeSlopeVector(leftStateVector, middleStateVector, rightStateVector, bias, slopeLimiter, materialParameters); 196 | vector leftExtrapolatedValue = VectorAlgebra::subtractVectors(middleStateVector.computeConservedVariableVector(materialParameters), 197 | VectorAlgebra::multiplyVector(0.5, slopeVector)); 198 | vector rightExtrapolatedValue = VectorAlgebra::addVectors(middleStateVector.computeConservedVariableVector(materialParameters), 199 | VectorAlgebra::multiplyVector(0.5, slopeVector)); 200 | 201 | vector leftFluxVector = EulerStateVector::computeXFluxVector(leftExtrapolatedValue, materialParameters); 202 | vector rightFluxVector = EulerStateVector::computeXFluxVector(rightExtrapolatedValue, materialParameters); 203 | vector evolutionVector = computeEvolutionVector(leftFluxVector, rightFluxVector, cellSpacing, timeStep); 204 | 205 | return evolveStateByHalfTimeStep(leftExtrapolatedValue, rightExtrapolatedValue, evolutionVector, side, materialParameters); 206 | } 207 | 208 | EulerStateVector EulerSolvers::evolveStateByHalfYTimeStep(EulerStateVector topStateVector, EulerStateVector middleStateVector, EulerStateVector bottomStateVector, 209 | double cellSpacing, double timeStep, double bias, int slopeLimiter, int side, 210 | EulerMaterialParameters materialParameters) 211 | { 212 | vector slopeVector = SlopeLimiters::computeSlopeVector(topStateVector, middleStateVector, bottomStateVector, bias, slopeLimiter, materialParameters); 213 | vector topExtrapolatedValue = VectorAlgebra::subtractVectors(middleStateVector.computeConservedVariableVector(materialParameters), 214 | VectorAlgebra::multiplyVector(0.5, slopeVector)); 215 | vector bottomExtrapolatedValue = VectorAlgebra::addVectors(middleStateVector.computeConservedVariableVector(materialParameters), 216 | VectorAlgebra::multiplyVector(0.5, slopeVector)); 217 | 218 | vector topFluxVector = EulerStateVector::computeYFluxVector(topExtrapolatedValue, materialParameters); 219 | vector bottomFluxVector = EulerStateVector::computeYFluxVector(bottomExtrapolatedValue, materialParameters); 220 | vector evolutionVector = computeEvolutionVector(topFluxVector, bottomFluxVector, cellSpacing, timeStep); 221 | 222 | return evolveStateByHalfTimeStep(topExtrapolatedValue, bottomExtrapolatedValue, evolutionVector, side, materialParameters); 223 | } 224 | 225 | void EulerSolvers::outputStatus(int currentIteration, double currentTime, double timeStep) 226 | { 227 | cout << "Iteration = " << currentIteration << "; Time = " << currentTime << "; Timestep = " << timeStep << endl; 228 | } 229 | -------------------------------------------------------------------------------- /Solvers/RelativisticEulerSecondOrderSolver.cpp: -------------------------------------------------------------------------------- 1 | #include "RelativisticEulerSecondOrderSolver.hpp" 2 | 3 | vector RelativisticEulerSecondOrderSolver::computeXSLICFlux(RelativisticEulerStateVector leftLeftStateVector, RelativisticEulerStateVector leftStateVector, 4 | RelativisticEulerStateVector rightStateVector, RelativisticEulerStateVector rightRightStateVector, 5 | double cellSpacing, double timeStep, double bias, int slopeLimiter, 6 | EulerMaterialParameters materialParameters) 7 | { 8 | RelativisticEulerStateVector evolvedRightStateVector = RelativisticEulerSolvers::evolveStateByHalfXTimeStep(leftLeftStateVector, leftStateVector, 9 | rightStateVector, cellSpacing, timeStep, bias, 10 | slopeLimiter, 1, materialParameters); 11 | RelativisticEulerStateVector evolvedLeftStateVector = RelativisticEulerSolvers::evolveStateByHalfXTimeStep(leftStateVector, rightStateVector, 12 | rightRightStateVector, cellSpacing, timeStep, bias, 13 | slopeLimiter, 0, materialParameters); 14 | 15 | return RelativisticEulerFirstOrderSolver::computeXFORCEFlux(evolvedRightStateVector, evolvedLeftStateVector, cellSpacing, timeStep, materialParameters); 16 | } 17 | 18 | vector RelativisticEulerSecondOrderSolver::computeYSLICFlux(RelativisticEulerStateVector topTopStateVector, RelativisticEulerStateVector topStateVector, 19 | RelativisticEulerStateVector bottomStateVector, RelativisticEulerStateVector bottomBottomStateVector, 20 | double cellSpacing, double timeStep, double bias, int slopeLimiter, 21 | EulerMaterialParameters materialParameters) 22 | { 23 | RelativisticEulerStateVector evolvedBottomStateVector = RelativisticEulerSolvers::evolveStateByHalfYTimeStep(topTopStateVector, topStateVector, bottomStateVector, 24 | cellSpacing, timeStep, bias, slopeLimiter, 1, 25 | materialParameters); 26 | RelativisticEulerStateVector evolvedTopStateVector = RelativisticEulerSolvers::evolveStateByHalfYTimeStep(topStateVector, bottomStateVector, bottomBottomStateVector, 27 | cellSpacing, timeStep, bias, slopeLimiter, 0, 28 | materialParameters); 29 | 30 | return RelativisticEulerFirstOrderSolver::computeYFORCEFlux(evolvedBottomStateVector, evolvedTopStateVector, cellSpacing, timeStep, materialParameters); 31 | } 32 | 33 | void RelativisticEulerSecondOrderSolver::computeSLICTimeStep(vector & currentCells, double cellSpacing, double timeStep, 34 | double bias, int slopeLimiter, EulerMaterialParameters materialParameters) 35 | { 36 | long cellCount = currentCells.size(); 37 | vector currentCellsWithBoundary = RelativisticEulerSolvers::insertBoundaryCells(currentCells, 2); 38 | 39 | #pragma omp parallel for 40 | for (int i = 0; i < cellCount; i++) 41 | { 42 | vector conservedVariableVector = currentCells[i].computeConservedVariableVector(materialParameters); 43 | 44 | vector leftFluxVector = computeXSLICFlux(currentCellsWithBoundary[i], currentCellsWithBoundary[i + 1], currentCellsWithBoundary[i + 2], 45 | currentCellsWithBoundary[i + 3], cellSpacing, timeStep, bias, slopeLimiter, materialParameters); 46 | vector rightFluxVector = computeXSLICFlux(currentCellsWithBoundary[i + 1], currentCellsWithBoundary[i + 2], currentCellsWithBoundary[i + 3], 47 | currentCellsWithBoundary[i + 4], cellSpacing, timeStep, bias, slopeLimiter, materialParameters); 48 | 49 | currentCells[i].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, leftFluxVector, rightFluxVector, cellSpacing, 50 | timeStep), materialParameters); 51 | } 52 | } 53 | 54 | void RelativisticEulerSecondOrderSolver::computeXSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 55 | double bias, int slopeLimiter, EulerMaterialParameters materialParameters) 56 | { 57 | long rowCount = currentCells.size(); 58 | long columnCount = currentCells[0].size(); 59 | vector > currentCellsWithBoundary = RelativisticEulerSolvers::insertBoundaryCells2D(currentCells, 2); 60 | 61 | #pragma omp parallel for 62 | for (int i = 0; i < rowCount; i++) 63 | { 64 | for (int j = 0; j < columnCount; j++) 65 | { 66 | vector conservedVariableVector = currentCells[i][j].computeConservedVariableVector(materialParameters); 67 | 68 | vector leftFluxVector = computeXSLICFlux(currentCellsWithBoundary[i + 2][j], currentCellsWithBoundary[i + 2][j + 1], 69 | currentCellsWithBoundary[i + 2][j + 2], currentCellsWithBoundary[i + 2][j + 3], cellSpacing, timeStep, 70 | bias, slopeLimiter, materialParameters); 71 | vector rightFluxVector = computeXSLICFlux(currentCellsWithBoundary[i + 2][j + 1], currentCellsWithBoundary[i + 2][j + 2], 72 | currentCellsWithBoundary[i + 2][j + 3], currentCellsWithBoundary[i + 2][j + 4], cellSpacing, timeStep, 73 | bias, slopeLimiter, materialParameters); 74 | 75 | currentCells[i][j].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, leftFluxVector, rightFluxVector, 76 | cellSpacing, timeStep), materialParameters); 77 | } 78 | } 79 | } 80 | 81 | void RelativisticEulerSecondOrderSolver::computeYSLICTimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 82 | double bias, int slopeLimiter, EulerMaterialParameters materialParameters) 83 | { 84 | long rowCount = currentCells.size(); 85 | long columnCount = currentCells[0].size(); 86 | vector > currentCellsWithBoundary = RelativisticEulerSolvers::insertBoundaryCells2D(currentCells, 2); 87 | 88 | #pragma omp parallel for 89 | for (int i = 0; i < rowCount; i++) 90 | { 91 | for (int j = 0; j < columnCount; j++) 92 | { 93 | vector conservedVariableVector = currentCells[i][j].computeConservedVariableVector(materialParameters); 94 | 95 | vector topFluxVector = computeYSLICFlux(currentCellsWithBoundary[i][j + 2], currentCellsWithBoundary[i + 1][j + 2], 96 | currentCellsWithBoundary[i + 2][j + 2], currentCellsWithBoundary[i + 3][j + 2], cellSpacing, timeStep, 97 | bias, slopeLimiter, materialParameters); 98 | vector bottomFluxVector = computeYSLICFlux(currentCellsWithBoundary[i + 1][j + 2], currentCellsWithBoundary[i + 2][j + 2], 99 | currentCellsWithBoundary[i + 3][j + 2], currentCellsWithBoundary[i + 4][j + 2], cellSpacing, timeStep, 100 | bias, slopeLimiter, materialParameters); 101 | 102 | currentCells[i][j].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, topFluxVector, bottomFluxVector, 103 | cellSpacing, timeStep), materialParameters); 104 | } 105 | } 106 | } 107 | 108 | vector RelativisticEulerSecondOrderSolver::solve(vector initialCells, double cellSpacing, 109 | double CFLCoefficient, double finalTime, double bias, int slopeLimiter, 110 | EulerMaterialParameters materialParameters) 111 | { 112 | double currentTime = 0.0; 113 | int currentIteration = 0; 114 | vector currentCells = initialCells; 115 | 116 | while (currentTime < finalTime) 117 | { 118 | double timeStep = RelativisticEulerSolvers::computeStableTimeStep(currentCells, cellSpacing, CFLCoefficient, currentTime, finalTime, currentIteration, 119 | materialParameters); 120 | 121 | computeSLICTimeStep(currentCells, cellSpacing, timeStep, bias, slopeLimiter, materialParameters); 122 | 123 | currentTime += timeStep; 124 | currentIteration += 1; 125 | 126 | EulerSolvers::outputStatus(currentIteration, currentTime, timeStep); 127 | } 128 | 129 | return currentCells; 130 | } 131 | 132 | vector > RelativisticEulerSecondOrderSolver::solve2D(vector > initialCells, double cellSpacing, 133 | double CFLCoefficient, double finalTime, double bias, int slopeLimiter, 134 | EulerMaterialParameters materialParameters) 135 | { 136 | double currentTime = 0.0; 137 | int currentIteration = 0; 138 | vector > currentCells = initialCells; 139 | 140 | while (currentTime < finalTime) 141 | { 142 | double timeStep = RelativisticEulerSolvers::computeStableTimeStep2D(currentCells, cellSpacing, CFLCoefficient, currentTime, finalTime, currentIteration, 143 | materialParameters); 144 | 145 | computeXSLICTimeStep2D(currentCells, cellSpacing, 0.5 * timeStep, bias, slopeLimiter, materialParameters); 146 | computeYSLICTimeStep2D(currentCells, cellSpacing, timeStep, bias, slopeLimiter, materialParameters); 147 | computeXSLICTimeStep2D(currentCells, cellSpacing, 0.5 * timeStep, bias, slopeLimiter, materialParameters); 148 | 149 | currentTime += timeStep; 150 | currentIteration += 1; 151 | 152 | EulerSolvers::outputStatus(currentIteration, currentTime, timeStep); 153 | } 154 | 155 | return currentCells; 156 | } 157 | -------------------------------------------------------------------------------- /Tests/BlackHoleEulerTests.cpp: -------------------------------------------------------------------------------- 1 | #include "BlackHoleEulerTests.hpp" 2 | 3 | void BlackHoleEulerTests::solve1DSphericalAccretionTest(int cellCount, int order, int subcyclingIterations) 4 | { 5 | double cellSpacing = 1.0 / cellCount; 6 | 7 | vector initialCells(cellCount); 8 | EulerMaterialParameters materialParameters(5.0 / 3.0); 9 | BlackHoleSpacetime blackHole(0.05, 0.5, 0.0, 0.0); 10 | 11 | for (int i = 0; i < cellCount; i++) 12 | { 13 | if (i >= (0.1 * cellCount) && i <= (0.9 * cellCount)) 14 | { 15 | initialCells[i] = BlackHoleEulerStateVector(10.0, 0.0, 0.0, 0.0, 0.1); 16 | } 17 | else 18 | { 19 | initialCells[i] = BlackHoleEulerStateVector(0.1, 0.0, 0.0, 0.0, 0.1); 20 | } 21 | } 22 | 23 | if (order == 1) 24 | { 25 | outputSolution(BlackHoleEulerFirstOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.45, subcyclingIterations, materialParameters, blackHole), blackHole); 26 | } 27 | else 28 | { 29 | outputSolution(BlackHoleEulerSecondOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.45, 0.0, 1, subcyclingIterations, materialParameters, blackHole), 30 | blackHole); 31 | } 32 | } 33 | 34 | void BlackHoleEulerTests::solve1DSpinningSphericalAccretionTest(int cellCount, int order, int subcyclingIterations) 35 | { 36 | double cellSpacing = 1.0 / cellCount; 37 | 38 | vector initialCells(cellCount); 39 | EulerMaterialParameters materialParameters(5.0 / 3.0); 40 | BlackHoleSpacetime blackHole(0.1, 0.99, 0.5, 0.0, 0.0); 41 | 42 | for (int i = 0; i < cellCount; i++) 43 | { 44 | if (i >= (0.1 * cellCount) && i <= (0.9 * cellCount)) 45 | { 46 | initialCells[i] = BlackHoleEulerStateVector(10.0, 0.0, 0.0, 0.0, 0.1); 47 | } 48 | else 49 | { 50 | initialCells[i] = BlackHoleEulerStateVector(0.1, 0.0, 0.0, 0.0, 0.1); 51 | } 52 | } 53 | 54 | if (order == 1) 55 | { 56 | outputSolution(BlackHoleEulerFirstOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.45, subcyclingIterations, materialParameters, blackHole), blackHole); 57 | } 58 | else 59 | { 60 | outputSolution(BlackHoleEulerSecondOrderSolver::solve(initialCells, cellSpacing, 0.95, 0.45, 0.0, 1, subcyclingIterations, materialParameters, blackHole), 61 | blackHole); 62 | } 63 | } 64 | 65 | void BlackHoleEulerTests::solve2DSphericalAccretionTest(int cellCount, int order, int subcyclingIterations) 66 | { 67 | double cellSpacing = 1.0 / cellCount; 68 | 69 | vector > initialCells(cellCount, vector(cellCount)); 70 | EulerMaterialParameters materialParameters(5.0 / 3.0); 71 | BlackHoleSpacetime blackHole(0.05, 0.5, 0.5, 0.0); 72 | 73 | for (int i = 0; i < cellCount; i++) 74 | { 75 | for (int j = 0; j < cellCount; j++) 76 | { 77 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount))) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)))) <= 0.4 * cellCount) 78 | { 79 | initialCells[i][j] = BlackHoleEulerStateVector(10.0, 0.0, 0.0, 0.0, 0.1); 80 | } 81 | else 82 | { 83 | initialCells[i][j] = BlackHoleEulerStateVector(0.1, 0.0, 0.0, 0.0, 0.1); 84 | } 85 | } 86 | } 87 | 88 | if (order == 1) 89 | { 90 | outputSolution2D(BlackHoleEulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.45, subcyclingIterations, materialParameters, blackHole), blackHole); 91 | } 92 | else 93 | { 94 | outputSolution2D(BlackHoleEulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.45, 0.0, 1, subcyclingIterations, materialParameters, blackHole), 95 | blackHole); 96 | } 97 | } 98 | 99 | void BlackHoleEulerTests::solve2DSpinningSphericalAccretionTest(int cellCount, int order, int subcyclingIterations) 100 | { 101 | double cellSpacing = 1.0 / cellCount; 102 | 103 | vector > initialCells(cellCount, vector(cellCount)); 104 | EulerMaterialParameters materialParameters(5.0 / 3.0); 105 | BlackHoleSpacetime blackHole(0.1, 0.99, 0.5, 0.5, 0.0); 106 | 107 | for (int i = 0; i < cellCount; i++) 108 | { 109 | for (int j = 0; j < cellCount; j++) 110 | { 111 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount))) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)))) <= 0.4 * cellCount) 112 | { 113 | initialCells[i][j] = BlackHoleEulerStateVector(10.0, 0.0, 0.0, 0.0, 0.1); 114 | } 115 | else 116 | { 117 | initialCells[i][j] = BlackHoleEulerStateVector(0.1, 0.0, 0.0, 0.0, 0.1); 118 | } 119 | } 120 | } 121 | 122 | if (order == 1) 123 | { 124 | outputSolution2D(BlackHoleEulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.45, subcyclingIterations, materialParameters, blackHole), blackHole); 125 | } 126 | else 127 | { 128 | outputSolution2D(BlackHoleEulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.45, 0.0, 1, subcyclingIterations, materialParameters, blackHole), 129 | blackHole); 130 | } 131 | } 132 | 133 | void BlackHoleEulerTests::solve2DSpheroidalAccretionTest(int cellCount, int order, int subcyclingIterations) 134 | { 135 | double cellSpacing = 1.0 / cellCount; 136 | 137 | vector > initialCells(cellCount, vector(cellCount)); 138 | EulerMaterialParameters materialParameters(5.0 / 3.0); 139 | BlackHoleSpacetime blackHole(0.05, 0.5, 0.5, 0.0); 140 | 141 | for (int i = 0; i < cellCount; i++) 142 | { 143 | for (int j = 0; j < cellCount; j++) 144 | { 145 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount)) * 0.8) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)) * 1.2)) <= 0.4 * cellCount) 146 | { 147 | initialCells[i][j] = BlackHoleEulerStateVector(10.0, 0.0, 0.0, 0.0, 0.1); 148 | } 149 | else 150 | { 151 | initialCells[i][j] = BlackHoleEulerStateVector(0.1, 0.0, 0.0, 0.0, 0.1); 152 | } 153 | } 154 | } 155 | 156 | if (order == 1) 157 | { 158 | outputSolution2D(BlackHoleEulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.45, subcyclingIterations, materialParameters, blackHole), blackHole); 159 | } 160 | else 161 | { 162 | outputSolution2D(BlackHoleEulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.45, 0.0, 1, subcyclingIterations, materialParameters, blackHole), 163 | blackHole); 164 | } 165 | } 166 | 167 | void BlackHoleEulerTests::solve2DSpinningSpheroidalAccretionTest(int cellCount, int order, int subcyclingIterations) 168 | { 169 | double cellSpacing = 1.0 / cellCount; 170 | 171 | vector > initialCells(cellCount, vector(cellCount)); 172 | EulerMaterialParameters materialParameters(5.0 / 3.0); 173 | BlackHoleSpacetime blackHole(0.1, 0.99, 0.5, 0.5, 0.0); 174 | 175 | for (int i = 0; i < cellCount; i++) 176 | { 177 | for (int j = 0; j < cellCount; j++) 178 | { 179 | if (sqrt(((i - (0.5 * cellCount)) * (i - (0.5 * cellCount)) * 0.8) + ((j - (0.5 * cellCount)) * (j - (0.5 * cellCount)) * 1.2)) <= 0.4 * cellCount) 180 | { 181 | initialCells[i][j] = BlackHoleEulerStateVector(10.0, 0.0, 0.0, 0.0, 0.1); 182 | } 183 | else 184 | { 185 | initialCells[i][j] = BlackHoleEulerStateVector(0.1, 0.0, 0.0, 0.0, 0.1); 186 | } 187 | } 188 | } 189 | 190 | if (order == 1) 191 | { 192 | outputSolution2D(BlackHoleEulerFirstOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.45, subcyclingIterations, materialParameters, blackHole), blackHole); 193 | } 194 | else 195 | { 196 | outputSolution2D(BlackHoleEulerSecondOrderSolver::solve2D(initialCells, cellSpacing, 0.95, 0.45, 0.0, 1, subcyclingIterations, materialParameters, blackHole), 197 | blackHole); 198 | } 199 | } 200 | 201 | void BlackHoleEulerTests::outputSolution(vector solution, BlackHoleSpacetime blackHole) 202 | { 203 | long cellCount = solution.size(); 204 | double cellSpacing = 1.0 / cellCount; 205 | 206 | ofstream densityFile("/Users/jonathangorard/Documents/Cosmos/density.dat"); 207 | ofstream xVelocityFile("/Users/jonathangorard/Documents/Cosmos/xVelocity.dat"); 208 | ofstream yVelocityFile("/Users/jonathangorard/Documents/Cosmos/yVelocity.dat"); 209 | ofstream zVelocityFile("/Users/jonathangorard/Documents/Cosmos/zVelocity.dat"); 210 | ofstream pressureFile("/Users/jonathangorard/Documents/Cosmos/pressure.dat"); 211 | 212 | for (int i = 0; i < cellCount; i++) 213 | { 214 | if (!blackHole.inExcisionRegion(i * cellSpacing, 0.0, 0.0)) 215 | { 216 | densityFile << (cellSpacing * i) << " " << solution[i].getDensity() << endl; 217 | xVelocityFile << (cellSpacing * i) << " " << solution[i].getXVelocity() << endl; 218 | yVelocityFile << (cellSpacing * i) << " " << solution[i].getYVelocity() << endl; 219 | zVelocityFile << (cellSpacing * i) << " " << solution[i].getZVelocity() << endl; 220 | pressureFile << (cellSpacing * i) << " " << solution[i].getPressure() << endl; 221 | } 222 | else 223 | { 224 | densityFile << (cellSpacing * i) << " " << 0.0 << endl; 225 | xVelocityFile << (cellSpacing * i) << " " << 0.0 << endl; 226 | yVelocityFile << (cellSpacing * i) << " " << 0.0 << endl; 227 | zVelocityFile << (cellSpacing * i) << " " << 0.0 << endl; 228 | pressureFile << (cellSpacing * i) << " " << 0.0 << endl; 229 | } 230 | } 231 | 232 | densityFile.close(); 233 | xVelocityFile.close(); 234 | yVelocityFile.close(); 235 | zVelocityFile.close(); 236 | pressureFile.close(); 237 | } 238 | 239 | void BlackHoleEulerTests::outputSolution2D(vector > solution, BlackHoleSpacetime blackHole) 240 | { 241 | long rowCount = solution.size(); 242 | long columnCount = solution[0].size(); 243 | double rowCellSpacing = 1.0 / rowCount; 244 | double columnCellSpacing = 1.0 / columnCount; 245 | 246 | ofstream densityFile("/Users/jonathangorard/Documents/Cosmos/density.dat"); 247 | ofstream xVelocityFile("/Users/jonathangorard/Documents/Cosmos/xVelocity.dat"); 248 | ofstream yVelocityFile("/Users/jonathangorard/Documents/Cosmos/yVelocity.dat"); 249 | ofstream zVelocityFile("/Users/jonathangorard/Documents/Cosmos/zVelocity.dat"); 250 | ofstream pressureFile("/Users/jonathangorard/Documents/Cosmos/pressure.dat"); 251 | 252 | for (int i = 0; i < rowCount; i++) 253 | { 254 | for (int j = 0; j < columnCount; j++) 255 | { 256 | if (!blackHole.inExcisionRegion(j * columnCellSpacing, i * rowCellSpacing, 0.0)) 257 | { 258 | densityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getDensity() << endl; 259 | xVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getXVelocity() << endl; 260 | yVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getYVelocity() << endl; 261 | zVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getZVelocity() << endl; 262 | pressureFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << solution[i][j].getPressure() << endl; 263 | } 264 | else 265 | { 266 | densityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << 0.0 << endl; 267 | xVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << 0.0 << endl; 268 | yVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << 0.0 << endl; 269 | zVelocityFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << 0.0 << endl; 270 | pressureFile << (rowCellSpacing * i) << " " << (columnCellSpacing * j) << " " << 0.0 << endl; 271 | } 272 | } 273 | 274 | densityFile << endl; 275 | xVelocityFile << endl; 276 | yVelocityFile << endl; 277 | zVelocityFile << endl; 278 | pressureFile << endl; 279 | } 280 | 281 | densityFile.close(); 282 | xVelocityFile.close(); 283 | yVelocityFile.close(); 284 | zVelocityFile.close(); 285 | pressureFile.close(); 286 | } 287 | -------------------------------------------------------------------------------- /Solvers/RelativisticEulerFirstOrderSolver.cpp: -------------------------------------------------------------------------------- 1 | #include "RelativisticEulerFirstOrderSolver.hpp" 2 | 3 | vector RelativisticEulerFirstOrderSolver::computeXLaxFriedrichsFlux(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector rightStateVector, 4 | double cellSpacing, double timeStep, EulerMaterialParameters materialParameters) 5 | { 6 | vector leftConservedVariableVector = leftStateVector.computeConservedVariableVector(materialParameters); 7 | vector rightConservedVariableVector = rightStateVector.computeConservedVariableVector(materialParameters); 8 | 9 | vector leftFluxVector = leftStateVector.computeXFluxVector(materialParameters); 10 | vector rightFluxVector = rightStateVector.computeXFluxVector(materialParameters); 11 | 12 | return EulerFirstOrderSolver::computeLaxFriedrichsFlux(leftConservedVariableVector, rightConservedVariableVector, leftFluxVector, rightFluxVector, 13 | cellSpacing, timeStep); 14 | } 15 | 16 | vector RelativisticEulerFirstOrderSolver::computeXRichtmyerFlux(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector rightStateVector, 17 | double cellSpacing, double timeStep, EulerMaterialParameters materialParameters) 18 | { 19 | vector leftConservedVariableVector = leftStateVector.computeConservedVariableVector(materialParameters); 20 | vector rightConservedVariableVector = rightStateVector.computeConservedVariableVector(materialParameters); 21 | 22 | vector leftFluxVector = leftStateVector.computeXFluxVector(materialParameters); 23 | vector rightFluxVector = rightStateVector.computeXFluxVector(materialParameters); 24 | 25 | vector intermediateStateVector = EulerFirstOrderSolver::computeRichtmyerFlux(leftConservedVariableVector, rightConservedVariableVector, leftFluxVector, 26 | rightFluxVector, cellSpacing, timeStep); 27 | return RelativisticEulerStateVector::computeXFluxVector(intermediateStateVector, materialParameters); 28 | } 29 | 30 | vector RelativisticEulerFirstOrderSolver::computeXFORCEFlux(RelativisticEulerStateVector leftStateVector, RelativisticEulerStateVector rightStateVector, 31 | double cellSpacing, double timeStep, EulerMaterialParameters materialParameters) 32 | { 33 | vector laxFriedrichsFlux = computeXLaxFriedrichsFlux(leftStateVector, rightStateVector, cellSpacing, timeStep, materialParameters); 34 | vector richtmyerFlux = computeXRichtmyerFlux(leftStateVector, rightStateVector, cellSpacing, timeStep, materialParameters); 35 | 36 | return EulerFirstOrderSolver::computeFORCEFlux(laxFriedrichsFlux, richtmyerFlux); 37 | } 38 | 39 | vector RelativisticEulerFirstOrderSolver::computeYLaxFriedrichsFlux(RelativisticEulerStateVector topStateVector, RelativisticEulerStateVector bottomStateVector, 40 | double cellSpacing, double timeStep, EulerMaterialParameters materialParameters) 41 | { 42 | vector topConservedVariableVector = topStateVector.computeConservedVariableVector(materialParameters); 43 | vector bottomConservedVariableVector = bottomStateVector.computeConservedVariableVector(materialParameters); 44 | 45 | vector topFluxVector = topStateVector.computeYFluxVector(materialParameters); 46 | vector bottomFluxVector = bottomStateVector.computeYFluxVector(materialParameters); 47 | 48 | return EulerFirstOrderSolver::computeLaxFriedrichsFlux(topConservedVariableVector, bottomConservedVariableVector, topFluxVector, bottomFluxVector, 49 | cellSpacing, timeStep); 50 | } 51 | 52 | vector RelativisticEulerFirstOrderSolver::computeYRichtmyerFlux(RelativisticEulerStateVector topStateVector, RelativisticEulerStateVector bottomStateVector, 53 | double cellSpacing, double timeStep, EulerMaterialParameters materialParameters) 54 | { 55 | vector topConservedVariableVector = topStateVector.computeConservedVariableVector(materialParameters); 56 | vector bottomConservedVariableVector = bottomStateVector.computeConservedVariableVector(materialParameters); 57 | 58 | vector topFluxVector = topStateVector.computeYFluxVector(materialParameters); 59 | vector bottomFluxVector = bottomStateVector.computeYFluxVector(materialParameters); 60 | 61 | vector intermediateStateVector = EulerFirstOrderSolver::computeRichtmyerFlux(topConservedVariableVector, bottomConservedVariableVector, topFluxVector, 62 | bottomFluxVector, cellSpacing, timeStep); 63 | return RelativisticEulerStateVector::computeYFluxVector(intermediateStateVector, materialParameters); 64 | } 65 | 66 | vector RelativisticEulerFirstOrderSolver::computeYFORCEFlux(RelativisticEulerStateVector topStateVector, RelativisticEulerStateVector bottomStateVector, 67 | double cellSpacing, double timeStep, EulerMaterialParameters materialParameters) 68 | { 69 | vector laxFriedrichsFlux = computeYLaxFriedrichsFlux(topStateVector, bottomStateVector, cellSpacing, timeStep, materialParameters); 70 | vector richtmyerFlux = computeYRichtmyerFlux(topStateVector, bottomStateVector, cellSpacing, timeStep, materialParameters); 71 | 72 | return EulerFirstOrderSolver::computeFORCEFlux(laxFriedrichsFlux, richtmyerFlux); 73 | } 74 | 75 | void RelativisticEulerFirstOrderSolver::computeFORCETimeStep(vector & currentCells, double cellSpacing, double timeStep, 76 | EulerMaterialParameters materialParameters) 77 | { 78 | long cellCount = currentCells.size(); 79 | vector currentCellsWithBoundary = RelativisticEulerSolvers::insertBoundaryCells(currentCells, 1); 80 | 81 | #pragma omp parallel for 82 | for (int i = 0; i < cellCount; i++) 83 | { 84 | vector conservedVariableVector = currentCells[i].computeConservedVariableVector(materialParameters); 85 | 86 | vector leftFluxVector = computeXFORCEFlux(currentCellsWithBoundary[i], currentCellsWithBoundary[i + 1], cellSpacing, timeStep, materialParameters); 87 | vector rightFluxVector = computeXFORCEFlux(currentCellsWithBoundary[i + 1], currentCellsWithBoundary[i + 2], cellSpacing, timeStep, materialParameters); 88 | 89 | currentCells[i].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, leftFluxVector, rightFluxVector, 90 | cellSpacing, timeStep), materialParameters); 91 | } 92 | } 93 | 94 | void RelativisticEulerFirstOrderSolver::computeXFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 95 | EulerMaterialParameters materialParameters) 96 | { 97 | long rowCount = currentCells.size(); 98 | long columnCount = currentCells[0].size(); 99 | vector > currentCellsWithBoundary = RelativisticEulerSolvers::insertBoundaryCells2D(currentCells, 1); 100 | 101 | #pragma omp parallel for 102 | for (int i = 0; i < rowCount; i++) 103 | { 104 | for (int j = 0; j < columnCount; j++) 105 | { 106 | vector conservedVariableVector = currentCells[i][j].computeConservedVariableVector(materialParameters); 107 | 108 | vector leftFluxVector = computeXFORCEFlux(currentCellsWithBoundary[i + 1][j], currentCellsWithBoundary[i + 1][j + 1], cellSpacing, 109 | timeStep, materialParameters); 110 | vector rightFluxVector = computeXFORCEFlux(currentCellsWithBoundary[i + 1][j + 1], currentCellsWithBoundary[i + 1][j + 2], cellSpacing, 111 | timeStep, materialParameters); 112 | 113 | currentCells[i][j].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, leftFluxVector, rightFluxVector, 114 | cellSpacing, timeStep), materialParameters); 115 | } 116 | } 117 | } 118 | 119 | void RelativisticEulerFirstOrderSolver::computeYFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 120 | EulerMaterialParameters materialParameters) 121 | { 122 | long rowCount = currentCells.size(); 123 | long columnCount = currentCells[0].size(); 124 | vector > currentCellsWithBoundary = RelativisticEulerSolvers::insertBoundaryCells2D(currentCells, 1); 125 | 126 | #pragma omp parallel for 127 | for (int i = 0; i < rowCount; i++) 128 | { 129 | for (int j = 0; j < columnCount; j++) 130 | { 131 | vector conservedVariableVector = currentCells[i][j].computeConservedVariableVector(materialParameters); 132 | 133 | vector topFluxVector = computeYFORCEFlux(currentCellsWithBoundary[i][j + 1], currentCellsWithBoundary[i + 1][j + 1], cellSpacing, 134 | timeStep, materialParameters); 135 | vector bottomFluxVector = computeYFORCEFlux(currentCellsWithBoundary[i + 1][j + 1], currentCellsWithBoundary[i + 2][j + 1], cellSpacing, 136 | timeStep, materialParameters); 137 | 138 | currentCells[i][j].setConservedVariableVector(EulerFirstOrderSolver::computeFORCEUpdate(conservedVariableVector, topFluxVector, bottomFluxVector, 139 | cellSpacing, timeStep), materialParameters); 140 | } 141 | } 142 | } 143 | 144 | vector RelativisticEulerFirstOrderSolver::solve(vector initialCells, double cellSpacing, 145 | double CFLCoefficient, double finalTime, EulerMaterialParameters materialParameters) 146 | { 147 | double currentTime = 0.0; 148 | int currentIteration = 0; 149 | vector currentCells = initialCells; 150 | 151 | while (currentTime < finalTime) 152 | { 153 | double timeStep = RelativisticEulerSolvers::computeStableTimeStep(currentCells, cellSpacing, CFLCoefficient, currentTime, finalTime, currentIteration, 154 | materialParameters); 155 | 156 | computeFORCETimeStep(currentCells, cellSpacing, timeStep, materialParameters); 157 | 158 | currentTime += timeStep; 159 | currentIteration += 1; 160 | 161 | EulerSolvers::outputStatus(currentIteration, currentTime, timeStep); 162 | } 163 | 164 | return currentCells; 165 | } 166 | 167 | vector > RelativisticEulerFirstOrderSolver::solve2D(vector > initialCells, 168 | double cellSpacing, double CFLCoefficient, double finalTime, 169 | EulerMaterialParameters materialParameters) 170 | { 171 | double currentTime = 0.0; 172 | int currentIteration = 0; 173 | vector > currentCells = initialCells; 174 | 175 | while (currentTime < finalTime) 176 | { 177 | double timeStep = RelativisticEulerSolvers::computeStableTimeStep2D(currentCells, cellSpacing, CFLCoefficient, currentTime, finalTime, currentIteration, 178 | materialParameters); 179 | 180 | computeXFORCETimeStep2D(currentCells, cellSpacing, timeStep * 0.5, materialParameters); 181 | computeYFORCETimeStep2D(currentCells, cellSpacing, timeStep, materialParameters); 182 | computeXFORCETimeStep2D(currentCells, cellSpacing, timeStep * 0.5, materialParameters); 183 | 184 | currentTime += timeStep; 185 | currentIteration += 1; 186 | 187 | EulerSolvers::outputStatus(currentIteration, currentTime, timeStep); 188 | } 189 | 190 | return currentCells; 191 | } 192 | -------------------------------------------------------------------------------- /Solvers/EulerFirstOrderSolver.cpp: -------------------------------------------------------------------------------- 1 | #include "EulerFirstOrderSolver.hpp" 2 | 3 | vector EulerFirstOrderSolver::computeLaxFriedrichsFlux(vector leftConservedVariableVector, vector rightConservedVariableVector, 4 | vector leftFluxVector, vector rightFluxVector, double cellSpacing, double timeStep) 5 | { 6 | return VectorAlgebra::multiplyVector(0.5, 7 | VectorAlgebra::addVectors(VectorAlgebra::addVectors(leftFluxVector, rightFluxVector), 8 | VectorAlgebra::multiplyVector((cellSpacing / timeStep), 9 | VectorAlgebra::subtractVectors(leftConservedVariableVector, 10 | rightConservedVariableVector)))); 11 | } 12 | 13 | vector EulerFirstOrderSolver::computeRichtmyerFlux(vector leftConservedVariableVector, vector rightConservedVariableVector, 14 | vector leftFluxVector, vector rightFluxVector, double cellSpacing, double timeStep) 15 | { 16 | return VectorAlgebra::multiplyVector(0.5, VectorAlgebra::addVectors(VectorAlgebra::addVectors(leftConservedVariableVector, rightConservedVariableVector), 17 | VectorAlgebra::multiplyVector((timeStep / cellSpacing), 18 | VectorAlgebra::subtractVectors(leftFluxVector, rightFluxVector)))); 19 | } 20 | 21 | vector EulerFirstOrderSolver::computeFORCEFlux(vector laxFriedrichsFlux, vector richtmyerFlux) 22 | { 23 | return VectorAlgebra::multiplyVector(0.5, VectorAlgebra::addVectors(laxFriedrichsFlux, richtmyerFlux)); 24 | } 25 | 26 | vector EulerFirstOrderSolver::computeXLaxFriedrichsFlux(EulerStateVector leftStateVector, EulerStateVector rightStateVector, double cellSpacing, double timeStep, 27 | EulerMaterialParameters materialParameters) 28 | { 29 | vector leftConservedVariableVector = leftStateVector.computeConservedVariableVector(materialParameters); 30 | vector rightConservedVariableVector = rightStateVector.computeConservedVariableVector(materialParameters); 31 | 32 | vector leftFluxVector = leftStateVector.computeXFluxVector(materialParameters); 33 | vector rightFluxVector = rightStateVector.computeXFluxVector(materialParameters); 34 | 35 | return computeLaxFriedrichsFlux(leftConservedVariableVector, rightConservedVariableVector, leftFluxVector, rightFluxVector, cellSpacing, timeStep); 36 | } 37 | 38 | vector EulerFirstOrderSolver::computeXRichtmyerFlux(EulerStateVector leftStateVector, EulerStateVector rightStateVector, double cellSpacing, double timeStep, 39 | EulerMaterialParameters materialParameters) 40 | { 41 | vector leftConservedVariableVector = leftStateVector.computeConservedVariableVector(materialParameters); 42 | vector rightConservedVariableVector = rightStateVector.computeConservedVariableVector(materialParameters); 43 | 44 | vector leftFluxVector = leftStateVector.computeXFluxVector(materialParameters); 45 | vector rightFluxVector = rightStateVector.computeXFluxVector(materialParameters); 46 | 47 | vector intermediateStateVector = computeRichtmyerFlux(leftConservedVariableVector, rightConservedVariableVector, leftFluxVector, rightFluxVector, 48 | cellSpacing, timeStep); 49 | return EulerStateVector::computeXFluxVector(intermediateStateVector, materialParameters); 50 | } 51 | 52 | vector EulerFirstOrderSolver::computeXFORCEFlux(EulerStateVector leftStateVector, EulerStateVector rightStateVector, double cellSpacing, double timeStep, 53 | EulerMaterialParameters materialParameters) 54 | { 55 | vector laxFriedrichsFlux = computeXLaxFriedrichsFlux(leftStateVector, rightStateVector, cellSpacing, timeStep, materialParameters); 56 | vector richtmyerFlux = computeXRichtmyerFlux(leftStateVector, rightStateVector, cellSpacing, timeStep, materialParameters); 57 | 58 | return computeFORCEFlux(laxFriedrichsFlux, richtmyerFlux); 59 | } 60 | 61 | vector EulerFirstOrderSolver::computeYLaxFriedrichsFlux(EulerStateVector topStateVector, EulerStateVector bottomStateVector, double cellSpacing, double timeStep, 62 | EulerMaterialParameters materialParameters) 63 | { 64 | vector topConservedVariableVector = topStateVector.computeConservedVariableVector(materialParameters); 65 | vector bottomConservedVariableVector = bottomStateVector.computeConservedVariableVector(materialParameters); 66 | 67 | vector topFluxVector = topStateVector.computeYFluxVector(materialParameters); 68 | vector bottomFluxVector = bottomStateVector.computeYFluxVector(materialParameters); 69 | 70 | return computeLaxFriedrichsFlux(topConservedVariableVector, bottomConservedVariableVector, topFluxVector, bottomFluxVector, cellSpacing, timeStep); 71 | } 72 | 73 | vector EulerFirstOrderSolver::computeYRichtmyerFlux(EulerStateVector topStateVector, EulerStateVector bottomStateVector, double cellSpacing, double timeStep, 74 | EulerMaterialParameters materialParameters) 75 | { 76 | vector topConservedVariableVector = topStateVector.computeConservedVariableVector(materialParameters); 77 | vector bottomConservedVariableVector = bottomStateVector.computeConservedVariableVector(materialParameters); 78 | 79 | vector topFluxVector = topStateVector.computeYFluxVector(materialParameters); 80 | vector bottomFluxVector = bottomStateVector.computeYFluxVector(materialParameters); 81 | 82 | vector intermediateStateVector = computeRichtmyerFlux(topConservedVariableVector, bottomConservedVariableVector, topFluxVector, bottomFluxVector, 83 | cellSpacing, timeStep); 84 | return EulerStateVector::computeYFluxVector(intermediateStateVector, materialParameters); 85 | } 86 | 87 | vector EulerFirstOrderSolver::computeYFORCEFlux(EulerStateVector topStateVector, EulerStateVector bottomStateVector, double cellSpacing, double timeStep, 88 | EulerMaterialParameters materialParameters) 89 | { 90 | vector laxFriedrichsFlux = computeYLaxFriedrichsFlux(topStateVector, bottomStateVector, cellSpacing, timeStep, materialParameters); 91 | vector richtmyerFlux = computeYRichtmyerFlux(topStateVector, bottomStateVector, cellSpacing, timeStep, materialParameters); 92 | 93 | return computeFORCEFlux(laxFriedrichsFlux, richtmyerFlux); 94 | } 95 | 96 | vector EulerFirstOrderSolver::computeFORCEUpdate(vector conservedVariableVector, vector leftFluxVector, vector rightFluxVector, 97 | double cellSpacing, double timeStep) 98 | { 99 | return VectorAlgebra::addVectors(conservedVariableVector, VectorAlgebra::multiplyVector((timeStep / cellSpacing), 100 | VectorAlgebra::subtractVectors(leftFluxVector, rightFluxVector))); 101 | } 102 | 103 | void EulerFirstOrderSolver::computeFORCETimeStep(vector & currentCells, double cellSpacing, double timeStep, EulerMaterialParameters materialParameters) 104 | { 105 | long cellCount = currentCells.size(); 106 | vector currentCellsWithBoundary = EulerSolvers::insertBoundaryCells(currentCells, 1); 107 | 108 | #pragma omp parallel for 109 | for (int i = 0; i < cellCount; i++) 110 | { 111 | vector conservedVariableVector = currentCells[i].computeConservedVariableVector(materialParameters); 112 | 113 | vector leftFluxVector = computeXFORCEFlux(currentCellsWithBoundary[i], currentCellsWithBoundary[i + 1], cellSpacing, timeStep, materialParameters); 114 | vector rightFluxVector = computeXFORCEFlux(currentCellsWithBoundary[i + 1], currentCellsWithBoundary[i + 2], cellSpacing, timeStep, materialParameters); 115 | 116 | currentCells[i].setConservedVariableVector(computeFORCEUpdate(conservedVariableVector, leftFluxVector, rightFluxVector, cellSpacing, timeStep), 117 | materialParameters); 118 | } 119 | } 120 | 121 | void EulerFirstOrderSolver::computeXFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 122 | EulerMaterialParameters materialParameters) 123 | { 124 | long rowCount = currentCells.size(); 125 | long columnCount = currentCells[0].size(); 126 | vector > currentCellsWithBoundary = EulerSolvers::insertBoundaryCells2D(currentCells, 1); 127 | 128 | #pragma omp parallel for 129 | for (int i = 0; i < rowCount; i++) 130 | { 131 | for (int j = 0; j < columnCount; j++) 132 | { 133 | vector conservedVariableVector = currentCells[i][j].computeConservedVariableVector(materialParameters); 134 | 135 | vector leftFluxVector = computeXFORCEFlux(currentCellsWithBoundary[i + 1][j], currentCellsWithBoundary[i + 1][j + 1], cellSpacing, 136 | timeStep, materialParameters); 137 | vector rightFluxVector = computeXFORCEFlux(currentCellsWithBoundary[i + 1][j + 1], currentCellsWithBoundary[i + 1][j + 2], cellSpacing, 138 | timeStep, materialParameters); 139 | 140 | currentCells[i][j].setConservedVariableVector(computeFORCEUpdate(conservedVariableVector, leftFluxVector, rightFluxVector, cellSpacing, timeStep), 141 | materialParameters); 142 | } 143 | } 144 | } 145 | 146 | void EulerFirstOrderSolver::computeYFORCETimeStep2D(vector > & currentCells, double cellSpacing, double timeStep, 147 | EulerMaterialParameters materialParameters) 148 | { 149 | long rowCount = currentCells.size(); 150 | long columnCount = currentCells[0].size(); 151 | vector > currentCellsWithBoundary = EulerSolvers::insertBoundaryCells2D(currentCells, 1); 152 | 153 | #pragma omp parallel for 154 | for (int i = 0; i < rowCount; i++) 155 | { 156 | for (int j = 0; j < columnCount; j++) 157 | { 158 | vector conservedVariableVector = currentCells[i][j].computeConservedVariableVector(materialParameters); 159 | 160 | vector topFluxVector = computeYFORCEFlux(currentCellsWithBoundary[i][j + 1], currentCellsWithBoundary[i + 1][j + 1], cellSpacing, 161 | timeStep, materialParameters); 162 | vector bottomFluxVector = computeYFORCEFlux(currentCellsWithBoundary[i + 1][j + 1], currentCellsWithBoundary[i + 2][j + 1], cellSpacing, 163 | timeStep, materialParameters); 164 | 165 | currentCells[i][j].setConservedVariableVector(computeFORCEUpdate(conservedVariableVector, topFluxVector, bottomFluxVector, cellSpacing, timeStep), 166 | materialParameters); 167 | } 168 | } 169 | } 170 | 171 | vector EulerFirstOrderSolver::solve(vector initialCells, double cellSpacing, double CFLCoefficient, double finalTime, 172 | EulerMaterialParameters materialParameters) 173 | { 174 | double currentTime = 0.0; 175 | int currentIteration = 0; 176 | vector currentCells = initialCells; 177 | 178 | while (currentTime < finalTime) 179 | { 180 | double timeStep = EulerSolvers::computeStableTimeStep(currentCells, cellSpacing, CFLCoefficient, currentTime, finalTime, currentIteration, materialParameters); 181 | 182 | computeFORCETimeStep(currentCells, cellSpacing, timeStep, materialParameters); 183 | 184 | currentTime += timeStep; 185 | currentIteration += 1; 186 | 187 | EulerSolvers::outputStatus(currentIteration, currentTime, timeStep); 188 | } 189 | 190 | return currentCells; 191 | } 192 | 193 | vector > EulerFirstOrderSolver::solve2D(vector > initialCells, double cellSpacing, double CFLCoefficient, 194 | double finalTime, EulerMaterialParameters materialParameters) 195 | { 196 | double currentTime = 0.0; 197 | int currentIteration = 0; 198 | vector > currentCells = initialCells; 199 | 200 | while (currentTime < finalTime) 201 | { 202 | double timeStep = EulerSolvers::computeStableTimeStep2D(currentCells, cellSpacing, CFLCoefficient, currentTime, finalTime, currentIteration, 203 | materialParameters); 204 | 205 | computeXFORCETimeStep2D(currentCells, cellSpacing, timeStep * 0.5, materialParameters); 206 | computeYFORCETimeStep2D(currentCells, cellSpacing, timeStep, materialParameters); 207 | computeXFORCETimeStep2D(currentCells, cellSpacing, timeStep * 0.5, materialParameters); 208 | 209 | currentTime += timeStep; 210 | currentIteration += 1; 211 | 212 | EulerSolvers::outputStatus(currentIteration, currentTime, timeStep); 213 | } 214 | 215 | return currentCells; 216 | } 217 | --------------------------------------------------------------------------------