From 9d076f6f492c5178859939c97799bd97dcb51cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Gu=C3=A9vremont?= Date: Mon, 5 Aug 2024 17:24:06 -0400 Subject: [PATCH] Refactor calculations and output --- include/solvers/tracer.h | 11 +++++++++-- source/solvers/tracer.cc | 33 +++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/solvers/tracer.h b/include/solvers/tracer.h index b0e39bb2d1..f2a95e0008 100644 --- a/include/solvers/tracer.h +++ b/include/solvers/tracer.h @@ -376,13 +376,20 @@ class Tracer : public AuxiliaryPhysics * @param current_solution_fd current solution for the fluid dynamics, parsed * by postprocess * + * @return values of the tracer flow rate at each boundary + * * @tparam GlobalVectorType The type of the global vector used for the tracer physic */ - template - void + std::vector postprocess_tracer_flow_rate(const GlobalVectorType ¤t_solution_fd); + /** + * @brief Writes the tracer flow rates to an output file + */ + void + write_tracer_flow_rates(const std::vector tracer_flow_rate_vector); + /** * @brief Writes the tracer statistics to an output file */ diff --git a/source/solvers/tracer.cc b/source/solvers/tracer.cc index 03dc888fe9..776ff9cb22 100644 --- a/source/solvers/tracer.cc +++ b/source/solvers/tracer.cc @@ -429,13 +429,6 @@ Tracer::postprocess(bool first_iteration) 0) this->write_tracer_statistics(); } - if (this->simulation_parameters.timer.type == - Parameters::Timer::Type::iteration) - { - announce_string(this->pcout, "Tracer"); - this->computing_timer.print_summary(); - this->computing_timer.reset(); - } // Calculate tracer flow rate at every boundary if (this->simulation_parameters.post_processing.calculate_tracer_flow_rate) @@ -448,16 +441,27 @@ Tracer::postprocess(bool first_iteration) announce_string(this->pcout, "Tracer flow rates"); } + std::vector tracer_flow_rates( + this->simulation_parameters.boundary_conditions.size); if (multiphysics->fluid_dynamics_is_block()) { - postprocess_tracer_flow_rate( + tracer_flow_rates = postprocess_tracer_flow_rate( *multiphysics->get_block_solution(PhysicsID::fluid_dynamics)); } else { - postprocess_tracer_flow_rate( + tracer_flow_rates = postprocess_tracer_flow_rate( *multiphysics->get_solution(PhysicsID::fluid_dynamics)); } + this->write_tracer_flow_rates(tracer_flow_rates); + } + + if (this->simulation_parameters.timer.type == + Parameters::Timer::Type::iteration) + { + announce_string(this->pcout, "Tracer"); + this->computing_timer.print_summary(); + this->computing_timer.reset(); } } @@ -556,7 +560,7 @@ Tracer::calculate_tracer_statistics() template template -void +std::vector Tracer::postprocess_tracer_flow_rate(const VectorType ¤t_solution_fd) { const unsigned int n_q_points_face = this->face_quadrature->size(); @@ -684,6 +688,14 @@ Tracer::postprocess_tracer_flow_rate(const VectorType ¤t_solution_fd) tracer_flow_rate_vector[i_bc] = Utilities::MPI::sum(tracer_flow_rate_vector[i_bc], mpi_communicator); + return tracer_flow_rate_vector; +} + +template +void +Tracer::write_tracer_flow_rates( + const std::vector tracer_flow_rate_vector) +{ // Fill table this->tracer_flow_rate_table.add_value( "time", this->simulation_control->get_current_time()); @@ -712,6 +724,7 @@ Tracer::postprocess_tracer_flow_rate(const VectorType ¤t_solution_fd) << tracer_flow_rate_vector[i_bc] << std::endl; } + auto mpi_communicator = triangulation->get_communicator(); if ((simulation_control->get_step_number() % this->simulation_parameters.post_processing.output_frequency == 0) &&