From d38e46916e704b71eef968240b60801b29fcdbee Mon Sep 17 00:00:00 2001 From: Mikael Vaillant Date: Thu, 12 Dec 2024 16:45:00 -0500 Subject: [PATCH] Adress PR comments. AverageScalarInTime -> AverageScalar. Null average heat flux is now outputed before initial_time_for_average_temperature_and_heat_flux --- .../heat_transfer_average_temperature.prm | 2 +- doc/source/parameters/cfd/post_processing.rst | 6 ++--- include/solvers/heat_transfer.h | 6 ++--- include/solvers/postprocessing_scalar.h | 4 +-- source/core/parameters.cc | 10 ++++---- source/solvers/heat_transfer.cc | 25 +++++++++++-------- source/solvers/postprocessing_scalar.cc | 25 +++++++++---------- tests/solvers/average_scalar_01.cc | 4 +-- 8 files changed, 43 insertions(+), 39 deletions(-) diff --git a/applications_tests/lethe-fluid/heat_transfer_average_temperature.prm b/applications_tests/lethe-fluid/heat_transfer_average_temperature.prm index d120231acd..47a19882b9 100644 --- a/applications_tests/lethe-fluid/heat_transfer_average_temperature.prm +++ b/applications_tests/lethe-fluid/heat_transfer_average_temperature.prm @@ -151,7 +151,7 @@ end #--------------------------------------------------- subsection post-processing - set calculate average temperature and average heat flux = true + set calculate average temperature and heat flux = true end #--------------------------------------------------- diff --git a/doc/source/parameters/cfd/post_processing.rst b/doc/source/parameters/cfd/post_processing.rst index 7af9e0233c..ea7cf37c48 100644 --- a/doc/source/parameters/cfd/post_processing.rst +++ b/doc/source/parameters/cfd/post_processing.rst @@ -22,8 +22,8 @@ This subsection controls the post-processing other than the forces and torque on set initial time for average velocity = 0.0 # Average temperature calculation - set calculate average temperature and average heat flux = false - set initial time for average temperature and average heat flux = 0.0 + set calculate average temperature and heat flux = false + set initial time for average temperature and heat flux = 0.0 # Pressure drop calculation set calculate pressure drop = false @@ -110,7 +110,7 @@ This subsection controls the post-processing other than the forces and torque on * ``calculate average velocities``: controls if calculation of time-averaged velocities is enabled. * ``initial time for average velocity``: initial time used for the average velocities calculations. -* ``calculate average temperature and average heat flux``: controls if calculation of time-averaged temperature and time-averaged heat flux is enabled. +* ``calculate average temperature and heat flux``: controls if calculation of time-averaged temperature and time-averaged heat flux is enabled. * ``initial time for average temperature``: initial time used for the average temperature calculations. * ``calculate pressure drop``: controls if calculation of the pressure drop from the inlet boundary to the outlet boundary is enabled. diff --git a/include/solvers/heat_transfer.h b/include/solvers/heat_transfer.h index 39f8f02bd6..6783580703 100644 --- a/include/solvers/heat_transfer.h +++ b/include/solvers/heat_transfer.h @@ -134,7 +134,7 @@ class HeatTransfer : public AuxiliaryPhysics if (simulation_parameters.post_processing.calculate_average_temp_and_hf) { average_temperature = - std::make_shared>(this->dof_handler); + std::make_shared>(this->dof_handler); } } @@ -800,10 +800,10 @@ class HeatTransfer : public AuxiliaryPhysics /** * @brief Compute the average temperature in time. */ - std::shared_ptr> average_temperature; + std::shared_ptr> average_temperature; /** - * @brief Locally owned average temperature calculated using the AverageScalarInTime object. + * @brief Locally owned average temperature calculated using the AverageScalar object. */ GlobalVectorType average_temperature_to_output; diff --git a/include/solvers/postprocessing_scalar.h b/include/solvers/postprocessing_scalar.h index fe36b6c984..8fa66dff32 100644 --- a/include/solvers/postprocessing_scalar.h +++ b/include/solvers/postprocessing_scalar.h @@ -29,7 +29,7 @@ using namespace dealii; */ template -class AverageScalarInTime +class AverageScalar { public: /** @@ -38,7 +38,7 @@ class AverageScalarInTime * @param[in] dof_handler Used to initialize the solution transfer objects. * The solution transfer object is later used for mesh adaptation. */ - AverageScalarInTime(DoFHandler &dof_handler); + AverageScalar(const DoFHandler &dof_handler); /** diff --git a/source/core/parameters.cc b/source/core/parameters.cc index 5e6de8aa26..c7e9344c21 100644 --- a/source/core/parameters.cc +++ b/source/core/parameters.cc @@ -1844,7 +1844,7 @@ namespace Parameters "Enable calculation of average velocities."); prm.declare_entry( - "calculate average temperature and average heat flux", + "calculate average temperature and heat flux", "false", Patterns::Bool(), "Enable calculation of time average temperature and time average heat flux"); @@ -1883,7 +1883,7 @@ namespace Parameters "Initial time to start calculations for average velocities"); prm.declare_entry( - "initial time for average temperature and average heat flux", + "initial time for average temperature and heat flux", "0.0", Patterns::Double(), "Initial time to start calculations for average temperature"); @@ -2079,7 +2079,7 @@ namespace Parameters calculate_average_velocities = prm.get_bool("calculate average velocities"); calculate_average_temp_and_hf = - prm.get_bool("calculate average temperature and average heat flux"); + prm.get_bool("calculate average temperature and heat flux"); calculate_pressure_drop = prm.get_bool("calculate pressure drop"); inlet_boundary_id = prm.get_integer("inlet boundary id"); outlet_boundary_id = prm.get_integer("outlet boundary id"); @@ -2087,8 +2087,8 @@ namespace Parameters calculate_tracer_flow_rate = prm.get_bool("calculate tracer flow rate"); initial_time_for_average_velocities = prm.get_double("initial time for average velocity"); - initial_time_for_average_temp_and_hf = prm.get_double( - "initial time for average temperature and average heat flux"); + initial_time_for_average_temp_and_hf = + prm.get_double("initial time for average temperature and heat flux"); kinetic_energy_output_name = prm.get("kinetic energy name"); pressure_drop_output_name = prm.get("pressure drop name"); flow_rate_output_name = prm.get("flow rate name"); diff --git a/source/solvers/heat_transfer.cc b/source/solvers/heat_transfer.cc index 9c639174d0..ba3172f02f 100644 --- a/source/solvers/heat_transfer.cc +++ b/source/solvers/heat_transfer.cc @@ -788,17 +788,22 @@ HeatTransfer::attach_solution_to_output(DataOut &data_out) } // Ouput the time average temperature and time average heat flux - if (simulation_parameters.post_processing.calculate_average_temp_and_hf && - this->simulation_control->get_current_time() > - simulation_parameters.post_processing - .initial_time_for_average_temp_and_hf - - 1e-6 * simulation_control->get_time_step()) + if (simulation_parameters.post_processing.calculate_average_temp_and_hf) { - this->average_temperature->calculate_average_scalar( - this->present_solution, - this->simulation_parameters.post_processing, - simulation_control->get_current_time(), - simulation_control->get_time_step()); + // Start calculating after the initial time for the average temperature + // and average heat flux + if (this->simulation_control->get_current_time() > + simulation_parameters.post_processing + .initial_time_for_average_temp_and_hf - + 1e-6 * simulation_control->get_time_step()) + { + this->average_temperature->calculate_average_scalar( + this->present_solution, + this->simulation_parameters.post_processing, + simulation_control->get_current_time(), + simulation_control->get_time_step()); + } + this->average_temperature_to_output = this->average_temperature->get_average_scalar(); data_out.add_data_vector(dof_handler, diff --git a/source/solvers/postprocessing_scalar.cc b/source/solvers/postprocessing_scalar.cc index 8e22f2303d..850e7e26a4 100644 --- a/source/solvers/postprocessing_scalar.cc +++ b/source/solvers/postprocessing_scalar.cc @@ -8,7 +8,7 @@ #include template -AverageScalarInTime::AverageScalarInTime(DoFHandler &dof_handler) +AverageScalar::AverageScalar(const DoFHandler &dof_handler) : solution_transfer_sum_scalar_dt(dof_handler) , total_time_for_average(0.0) , average_calculation(false) @@ -16,7 +16,7 @@ AverageScalarInTime::AverageScalarInTime(DoFHandler &dof_handler) template void -AverageScalarInTime::calculate_average_scalar( +AverageScalar::calculate_average_scalar( const GlobalVectorType &local_evaluation_point, const Parameters::PostProcessing &post_processing, const double current_time, @@ -52,10 +52,9 @@ AverageScalarInTime::calculate_average_scalar( template void -AverageScalarInTime::initialize_vectors( - const IndexSet &locally_owned_dofs, - const IndexSet &locally_relevant_dofs, - const MPI_Comm &mpi_communicator) +AverageScalar::initialize_vectors(const IndexSet &locally_owned_dofs, + const IndexSet &locally_relevant_dofs, + const MPI_Comm &mpi_communicator) { // Reinitialisation of the average scalars to get the right length. scalar_dt.reinit(locally_owned_dofs, mpi_communicator); @@ -73,7 +72,7 @@ AverageScalarInTime::initialize_vectors( template void -AverageScalarInTime::update_average_scalar() +AverageScalar::update_average_scalar() { if (total_time_for_average > 1e-16) { @@ -85,7 +84,7 @@ AverageScalarInTime::update_average_scalar() template void -AverageScalarInTime::prepare_for_mesh_adaptation() +AverageScalar::prepare_for_mesh_adaptation() { sum_scalar_dt_with_ghost_cells = sum_scalar_dt; solution_transfer_sum_scalar_dt.prepare_for_coarsening_and_refinement( @@ -94,7 +93,7 @@ AverageScalarInTime::prepare_for_mesh_adaptation() template void -AverageScalarInTime::post_mesh_adaptation() +AverageScalar::post_mesh_adaptation() { solution_transfer_sum_scalar_dt.interpolate(sum_scalar_dt); @@ -105,7 +104,7 @@ AverageScalarInTime::post_mesh_adaptation() template std::vector -AverageScalarInTime::save(const std::string &prefix) +AverageScalar::save(const std::string &prefix) { sum_scalar_dt_with_ghost_cells = sum_scalar_dt; @@ -124,7 +123,7 @@ AverageScalarInTime::save(const std::string &prefix) template std::vector -AverageScalarInTime::read(const std::string &prefix) +AverageScalar::read(const std::string &prefix) { std::vector sum_vectors; sum_vectors.push_back(&sum_scalar_dt_with_ghost_cells); @@ -142,5 +141,5 @@ AverageScalarInTime::read(const std::string &prefix) return sum_vectors; } -template class AverageScalarInTime<2>; -template class AverageScalarInTime<3>; +template class AverageScalar<2>; +template class AverageScalar<3>; diff --git a/tests/solvers/average_scalar_01.cc b/tests/solvers/average_scalar_01.cc index c39fcd4235..f96437af8d 100644 --- a/tests/solvers/average_scalar_01.cc +++ b/tests/solvers/average_scalar_01.cc @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later /** - * @brief This test checks the AverageScalarInTime class in postprocessing_scalar.cc. It does so by averaging a solution in time. + * @brief This test checks the AverageScalar class in postprocessing_scalar.cc. It does so by averaging a solution in time. */ // Deal.II includes @@ -63,7 +63,7 @@ test() GridGenerator::hyper_cube(tria, -1, 1); DoFHandler<3> dof_handler(tria); - AverageScalarInTime<3> average(dof_handler); + AverageScalar<3> average(dof_handler); GlobalVectorType solution(locally_owned_dofs, mpi_communicator); solution(0) = 0.0;