From fa70e1a1ded232a10eefbd794ba477697b54bc8d Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Sat, 29 Jul 2023 18:09:31 -0700 Subject: [PATCH 1/2] add custom temp and hf to inc ns solver and fix failing test --- SU2_CFD/src/solvers/CIncNSSolver.cpp | 9 +++++++-- TestCases/py_wrapper/custom_heat_flux/run_ad.py | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/SU2_CFD/src/solvers/CIncNSSolver.cpp b/SU2_CFD/src/solvers/CIncNSSolver.cpp index ea9fc7a1bdb..ce1c28fe364 100644 --- a/SU2_CFD/src/solvers/CIncNSSolver.cpp +++ b/SU2_CFD/src/solvers/CIncNSSolver.cpp @@ -336,13 +336,13 @@ void CIncNSSolver::BC_Wall_Generic(const CGeometry *geometry, const CConfig *con const bool implicit = (config->GetKind_TimeIntScheme() == EULER_IMPLICIT); const bool energy = config->GetEnergy_Equation(); + const bool py_custom = config->GetMarker_All_PyCustom(val_marker); /*--- Variables for streamwise periodicity ---*/ const bool streamwise_periodic = (config->GetKind_Streamwise_Periodic() != ENUM_STREAMWISE_PERIODIC::NONE); const bool streamwise_periodic_temperature = config->GetStreamwise_Periodic_Temperature(); su2double Cp, thermal_conductivity, dot_product, scalar_factor; - /*--- Identify the boundary by string name ---*/ const auto Marker_Tag = config->GetMarker_All_TagBound(val_marker); @@ -426,6 +426,9 @@ void CIncNSSolver::BC_Wall_Generic(const CGeometry *geometry, const CConfig *con /*--- Apply a weak boundary condition for the energy equation. Compute the residual due to the prescribed heat flux. ---*/ + if (py_custom) { + Wall_HeatFlux = geometry->GetCustomBoundaryHeatFlux(val_marker, iVertex) / config->GetHeat_Flux_Ref(); + } LinSysRes(iPoint, nDim+1) -= Wall_HeatFlux*Area; /*--- With streamwise periodic flow and heatflux walls an additional term is introduced in the boundary formulation ---*/ @@ -460,7 +463,9 @@ void CIncNSSolver::BC_Wall_Generic(const CGeometry *geometry, const CConfig *con break; case ISOTHERMAL: - + if (py_custom) { + Twall = geometry->GetCustomBoundaryTemperature(val_marker, iVertex) / config->GetTemperature_Ref(); + } const auto Point_Normal = geometry->vertex[val_marker][iVertex]->GetNormal_Neighbor(); /*--- Get coordinates of i & nearest normal and compute distance ---*/ diff --git a/TestCases/py_wrapper/custom_heat_flux/run_ad.py b/TestCases/py_wrapper/custom_heat_flux/run_ad.py index 91695b4e6b2..8a13e067a56 100644 --- a/TestCases/py_wrapper/custom_heat_flux/run_ad.py +++ b/TestCases/py_wrapper/custom_heat_flux/run_ad.py @@ -228,9 +228,9 @@ def main(): comm = MPI.COMM_WORLD rank = comm.Get_rank() - obj_pert_size = RunPrimal(0.100005) + obj_pert_size = RunPrimal(0.10002) obj = RunPrimal(0.1) - sens_size_fd = (obj_pert_size - obj) / 0.000005 + sens_size_fd = (obj_pert_size - obj) / 0.00002 sens_size, sens_temp = RunAdjoint(0.1) @@ -238,7 +238,7 @@ def main(): print(" Finite Differences\tDiscrete Adjoint") print(f"Size {sens_size_fd}\t{sens_size}") - assert abs(sens_size / sens_size_fd - 1) < 1e-4, "Error in geometric derivatives." + assert abs(sens_size / sens_size_fd - 1) < 1e-3, "Error in geometric derivatives." # We expect the final average temperature to be directly proportional to the initial # temperature since the applied heat flux is not a function of temperature. assert abs(sens_temp - 1) < 1e-5, "Error in initial condition derivatives." From f679db17223395c6224bcf20af4e010168840474 Mon Sep 17 00:00:00 2001 From: Pedro Gomes Date: Sat, 29 Jul 2023 19:33:33 -0700 Subject: [PATCH 2/2] fix the python case --- SU2_CFD/src/interfaces/cht/CConjugateHeatInterface.cpp | 2 +- SU2_CFD/src/solvers/CIncNSSolver.cpp | 2 +- TestCases/py_wrapper/custom_heat_flux/run_ad.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SU2_CFD/src/interfaces/cht/CConjugateHeatInterface.cpp b/SU2_CFD/src/interfaces/cht/CConjugateHeatInterface.cpp index a1400ad0799..ea9dd7134f7 100644 --- a/SU2_CFD/src/interfaces/cht/CConjugateHeatInterface.cpp +++ b/SU2_CFD/src/interfaces/cht/CConjugateHeatInterface.cpp @@ -70,7 +70,7 @@ void CConjugateHeatInterface::GetDonor_Variable(CSolver *donor_solution, CGeomet su2double conductivity_over_dist = 0.0; const bool compressible_flow = (donor_config->GetKind_Regime() == ENUM_REGIME::COMPRESSIBLE); - const bool incompressible_flow = (donor_config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE) && + const bool incompressible_flow = (donor_config->GetKind_Regime() == ENUM_REGIME::INCOMPRESSIBLE) && (donor_config->GetEnergy_Equation() || (donor_config->GetKind_FluidModel() == ENUM_FLUIDMODEL::FLUID_FLAMELET)); if (compressible_flow) { diff --git a/SU2_CFD/src/solvers/CIncNSSolver.cpp b/SU2_CFD/src/solvers/CIncNSSolver.cpp index ce1c28fe364..061c8ee02ec 100644 --- a/SU2_CFD/src/solvers/CIncNSSolver.cpp +++ b/SU2_CFD/src/solvers/CIncNSSolver.cpp @@ -219,7 +219,7 @@ void CIncNSSolver::GetStreamwise_Periodic_Properties(const CGeometry *geometry, const su2double FaceArea = GeometryToolbox::Norm(nDim, AreaNormal); - HeatFlow_Local += FaceArea * (-1.0) * Wall_HeatFlux/config->GetHeat_Flux_Ref();; + HeatFlow_Local += FaceArea * (-1.0) * Wall_HeatFlux/config->GetHeat_Flux_Ref(); } // loop Vertices } // loop Heatflux marker } // loop AllMarker diff --git a/TestCases/py_wrapper/custom_heat_flux/run_ad.py b/TestCases/py_wrapper/custom_heat_flux/run_ad.py index 8a13e067a56..8fa54a0a891 100644 --- a/TestCases/py_wrapper/custom_heat_flux/run_ad.py +++ b/TestCases/py_wrapper/custom_heat_flux/run_ad.py @@ -92,7 +92,7 @@ def ApplyHeatFlux(time, driver, marker_ids): for marker_id in marker_ids: if marker_id < 0: continue - hf = (-1, 0)[time > 0.2] + hf = (-1 * 2700 * 870, 0)[time > 0.2] for i_vertex in range(driver.GetNumberMarkerNodes(marker_id)): driver.SetMarkerCustomNormalHeatFlux(marker_id, i_vertex, hf) @@ -228,9 +228,9 @@ def main(): comm = MPI.COMM_WORLD rank = comm.Get_rank() - obj_pert_size = RunPrimal(0.10002) + obj_pert_size = RunPrimal(0.100005) obj = RunPrimal(0.1) - sens_size_fd = (obj_pert_size - obj) / 0.00002 + sens_size_fd = (obj_pert_size - obj) / 0.000005 sens_size, sens_temp = RunAdjoint(0.1) @@ -238,7 +238,7 @@ def main(): print(" Finite Differences\tDiscrete Adjoint") print(f"Size {sens_size_fd}\t{sens_size}") - assert abs(sens_size / sens_size_fd - 1) < 1e-3, "Error in geometric derivatives." + assert abs(sens_size / sens_size_fd - 1) < 1e-4, "Error in geometric derivatives." # We expect the final average temperature to be directly proportional to the initial # temperature since the applied heat flux is not a function of temperature. assert abs(sens_temp - 1) < 1e-5, "Error in initial condition derivatives."