void ProblemStructure::initializeVelocityBoundary() { DataWindow<double> uVelocityBoundaryWindow (geometry.getUVelocityBoundaryData(), M, 2); DataWindow<double> vVelocityBoundaryWindow (geometry.getVVelocityBoundaryData(), 2, N); if (boundaryModel == "tauBenchmark") { for (int i = 0; i < M; ++i) for (int j = 0; j < 2; ++j) uVelocityBoundaryWindow (i, j) = cos (j * N * h) * sin ((i + 0.5) * h); for (int i = 0; i < 2; ++i) for (int j = 0; j < N; ++j) vVelocityBoundaryWindow (i, j) = -sin ((j + 0.5) * h) * cos (i * M * h); } else if (boundaryModel == "solCXBenchmark" || boundaryModel == "solKZBenchmark" || boundaryModel == "noFlux") { for (int i = 0; i < M; ++i) for (int j = 0; j < 2; ++j) uVelocityBoundaryWindow (i, j) = 0; for (int i = 0; i < 2; ++i) for (int j = 0; j < N; ++j) vVelocityBoundaryWindow (i, j) = 0; } else { throw std::invalid_argument("<Unexpected boundary model: \"" + boundaryModel + "\" : Shutting down now>"); } #ifdef DEBUG cout << "<Initialized boundary model as: \"" << boundaryModel << "\">" << endl; cout << "<U Velocity Boundary Data>" << endl; uVelocityBoundaryWindow.displayMatrix(); cout << "<V Velocity Boundary Data>" << endl; vVelocityBoundaryWindow.displayMatrix(); #endif }
void ProblemStructure::initializeViscosity() { DataWindow<double> viscosityWindow (geometry.getViscosityData(), M + 1, N + 1); double viscosity; if (viscosityModel == "constant") { if (parser.push ("problemParams")) { if (parser.tryPush ("initialViscosity")) { parser.queryParamDouble ("viscosityScale", viscosity, 1.0); parser.pop(); } else { viscosity = 1.0; } parser.pop(); } for (int i = 0; i < (M + 1); ++i) for (int j = 0; j < (N + 1); ++j) viscosityWindow (i, j) = viscosity; } else if (viscosityModel == "tauBenchmark") { viscosity = 1.0; } else if (viscosityModel == "solCXBenchmark") { for (int i = 0; i < (M + 1); ++i) for (int j = 0; j < (N + 1); ++j) viscosityWindow (i, j) = (j <= N / 2) ? 1.0 : 1.0E06; } else if (viscosityModel == "solKZBenchmark") { for (int i = 0; i < (M + 1); ++i) for (int j = 0; j < (N + 1); ++j) viscosityWindow (i, j) = 1.0 + j * h * 1.0E06; } else { throw std::invalid_argument("Unexpected viscosity model: \"" + viscosityModel + "\" : Shutting down now!"); } #ifdef DEBUG cout << "<Viscosity model initialized as: \"" << viscosityModel << "\">" << endl; cout << "<Viscosity Data>" << endl; viscosityWindow.displayMatrix(); #endif }
void ProblemStructure::initializeTemperature() { DataWindow<double> temperatureWindow (geometry.getTemperatureData(), M, N); double referenceTemperature; double temperatureScale; if (parser.push ("problemParams")) { if (parser.push ("initialTemperatureParams")) { parser.queryParamDouble ("referenceTemperature", referenceTemperature, 273.15); parser.queryParamDouble ("temperatureScale", temperatureScale, 100.0); parser.pop(); } parser.pop(); } if (temperatureModel == "constant") { for (int i = 0; i < M; ++i) for (int j = 0; j < N; ++j) temperatureWindow (i, j) = referenceTemperature; } else if (temperatureModel == "sineWave") { int xModes; int yModes; if (parser.push ("problemParams")) { if (parser.tryPush ("initialTemperatureParams")) { parser.queryParamInt ("xModes", xModes, 2); parser.queryParamInt ("yModes", yModes, 2); parser.pop(); } parser.pop(); } for (int i = 0; i < M; ++i) for (int j = 0; j < N; ++j) temperatureWindow (i, j) = referenceTemperature + sin ((i + 0.5) * h * xModes * pi / xExtent) * sin ((j + 0.5) * h * yModes * pi / yExtent) * temperatureScale; } else if (temperatureModel == "squareWave") { for (int i = 0; i < M; ++i) for (int j = 0; j < N; ++j) { if ((M / 4 < j && j < 3 * M / 4) && (N / 4 < i && i < 3 * N / 4)) temperatureWindow (i, j) = referenceTemperature + temperatureScale; else temperatureWindow (i, j) = referenceTemperature; } } else if (temperatureModel == "circle") { double center_x; double center_y; double radius; if (parser.push ("problemParams")) { if (parser.tryPush ("initialTemperatureParams")) { parser.getParamDouble ("radius", radius); parser.getParamDouble ("xCenter", center_x); parser.getParamDouble ("yCenter", center_y); parser.pop(); } parser.pop(); } for (int i = 0; i < M; ++i) for (int j= 0; j < N; ++j) { if ( std::sqrt(std::pow((i*h+h/2)-(center_y),2.0) + std::pow((j*h+h/2)-(center_x),2.0)) < radius ) temperatureWindow (i, j) = referenceTemperature + temperatureScale; else temperatureWindow (i, j) = referenceTemperature; } } else { throw std::invalid_argument("<Unexpected temperature model: \"" + temperatureModel + "\" : Shutting down now>"); } #ifdef DEBUG cout << "<Initialized temperature model as: \"" << temperatureModel << "\">" << endl; cout << "<Temperature Data>" << endl; temperatureWindow.displayMatrix(); #endif }
// Update the forcing terms // T -> F void ProblemStructure::updateForcingTerms() { DataWindow<double> uForcingWindow (geometry.getUForcingData(), N - 1, M); DataWindow<double> vForcingWindow (geometry.getVForcingData(), N, M - 1); #ifdef DEBUG cout << "<Calculating forcing model using \"" << forcingModel << "\">" << endl; #endif if (forcingModel == "tauBenchmark") { // Benchmark taken from Tau (1991; JCP Vol. 99) for (int i = 0; i < M; ++i) for (int j = 0; j < N - 1; ++j) uForcingWindow (j, i) = 3 * cos ((j + 1) * h) * sin ((i + 0.5) * h); for (int i = 0; i < M - 1; ++i) for (int j = 0; j < N; ++j) vForcingWindow (j, i) = -sin ((j + 0.5) * h) * cos ((i + 1) * h); } else if (forcingModel == "solCXBenchmark" || forcingModel == "solKZBenchmark") { // solCX Benchmark taken from Kronbichler et al. (2011) for (int i = 0; i < M; ++i) for (int j = 0; j < N - 1; ++j) uForcingWindow (j, i) = 0; for (int i = 0; i < M - 1; ++i) for (int j = 0; j < N; ++j) vForcingWindow (j, i) = - sin((i + 0.5) * M_PI * h) * cos ((j + 1) * M_PI * h); } else if (forcingModel == "vorticalFlow") { for (int i = 0; i < M; ++i) for (int j = 0; j < (N - 1); j++) uForcingWindow (j, i) = cos ((j + 1) * h) * sin ((i + 0.5) * h); for (int i = 0; i < (M - 1); ++i) for (int j = 0; j < N; ++j) vForcingWindow (j, i) = -sin ((j + 0.5) * h) * cos ((i + 1) * h); } else if (forcingModel == "buoyancy") { DataWindow<double> temperatureWindow (geometry.getTemperatureData(), N, M); double referenceTemperature; double densityConstant; double thermalExpansion; if (parser.push ("problemParams")) { if (parser.push ("buoyancyModelParams")) { parser.queryParamDouble ("referenceTemperature", referenceTemperature, 273.15); parser.queryParamDouble ("densityConstant", densityConstant, 100.0); parser.queryParamDouble ("thermalExpansion", thermalExpansion, 1.0); parser.pop(); } parser.pop(); } for (int i = 0; i < M; ++i) for (int j = 0; j < (N - 1); ++j) uForcingWindow (j, i) = 0; for (int i = 0; i < (M - 1); ++i) for (int j = 0; j < N; ++j) { vForcingWindow (j, i) = -1 * densityConstant * (1 - thermalExpansion * ((temperatureWindow (j, i) + temperatureWindow (j, i + 1)) / 2 - referenceTemperature)); } } else { cerr << "<Unexpected forcing model: \"" << forcingModel << "\" : Shutting down now>" << endl; exit(-1); } #ifdef DEBUG cout << "<U Forcing Data>" << endl; cout << uForcingWindow.displayMatrix() << endl; cout << "<V Forcing Data>" << endl; cout << vForcingWindow.displayMatrix() << endl << endl; #endif }