Skip to content

Commit

Permalink
Adress PR comments. AverageScalarInTime -> AverageScalar. Null averag…
Browse files Browse the repository at this point in the history
…e heat flux is now outputed before initial_time_for_average_temperature_and_heat_flux
  • Loading branch information
mivaia committed Dec 12, 2024
1 parent c04c32b commit d38e469
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

#---------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions doc/source/parameters/cfd/post_processing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions include/solvers/heat_transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class HeatTransfer : public AuxiliaryPhysics<dim, GlobalVectorType>
if (simulation_parameters.post_processing.calculate_average_temp_and_hf)
{
average_temperature =
std::make_shared<AverageScalarInTime<dim>>(this->dof_handler);
std::make_shared<AverageScalar<dim>>(this->dof_handler);
}
}

Expand Down Expand Up @@ -800,10 +800,10 @@ class HeatTransfer : public AuxiliaryPhysics<dim, GlobalVectorType>
/**
* @brief Compute the average temperature in time.
*/
std::shared_ptr<AverageScalarInTime<dim>> average_temperature;
std::shared_ptr<AverageScalar<dim>> 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;

Expand Down
4 changes: 2 additions & 2 deletions include/solvers/postprocessing_scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ using namespace dealii;
*/

template <int dim>
class AverageScalarInTime
class AverageScalar
{
public:
/**
Expand All @@ -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<dim> &dof_handler);
AverageScalar(const DoFHandler<dim> &dof_handler);


/**
Expand Down
10 changes: 5 additions & 5 deletions source/core/parameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -2079,16 +2079,16 @@ 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");
calculate_flow_rate = prm.get_bool("calculate flow rate");
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");
Expand Down
25 changes: 15 additions & 10 deletions source/solvers/heat_transfer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -788,17 +788,22 @@ HeatTransfer<dim>::attach_solution_to_output(DataOut<dim> &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,
Expand Down
25 changes: 12 additions & 13 deletions source/solvers/postprocessing_scalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include <fstream>

template <int dim>
AverageScalarInTime<dim>::AverageScalarInTime(DoFHandler<dim> &dof_handler)
AverageScalar<dim>::AverageScalar(const DoFHandler<dim> &dof_handler)
: solution_transfer_sum_scalar_dt(dof_handler)
, total_time_for_average(0.0)
, average_calculation(false)
{}

template <int dim>
void
AverageScalarInTime<dim>::calculate_average_scalar(
AverageScalar<dim>::calculate_average_scalar(
const GlobalVectorType &local_evaluation_point,
const Parameters::PostProcessing &post_processing,
const double current_time,
Expand Down Expand Up @@ -52,10 +52,9 @@ AverageScalarInTime<dim>::calculate_average_scalar(

template <int dim>
void
AverageScalarInTime<dim>::initialize_vectors(
const IndexSet &locally_owned_dofs,
const IndexSet &locally_relevant_dofs,
const MPI_Comm &mpi_communicator)
AverageScalar<dim>::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);
Expand All @@ -73,7 +72,7 @@ AverageScalarInTime<dim>::initialize_vectors(

template <int dim>
void
AverageScalarInTime<dim>::update_average_scalar()
AverageScalar<dim>::update_average_scalar()
{
if (total_time_for_average > 1e-16)
{
Expand All @@ -85,7 +84,7 @@ AverageScalarInTime<dim>::update_average_scalar()

template <int dim>
void
AverageScalarInTime<dim>::prepare_for_mesh_adaptation()
AverageScalar<dim>::prepare_for_mesh_adaptation()
{
sum_scalar_dt_with_ghost_cells = sum_scalar_dt;
solution_transfer_sum_scalar_dt.prepare_for_coarsening_and_refinement(
Expand All @@ -94,7 +93,7 @@ AverageScalarInTime<dim>::prepare_for_mesh_adaptation()

template <int dim>
void
AverageScalarInTime<dim>::post_mesh_adaptation()
AverageScalar<dim>::post_mesh_adaptation()
{
solution_transfer_sum_scalar_dt.interpolate(sum_scalar_dt);

Expand All @@ -105,7 +104,7 @@ AverageScalarInTime<dim>::post_mesh_adaptation()

template <int dim>
std::vector<const GlobalVectorType *>
AverageScalarInTime<dim>::save(const std::string &prefix)
AverageScalar<dim>::save(const std::string &prefix)
{
sum_scalar_dt_with_ghost_cells = sum_scalar_dt;

Expand All @@ -124,7 +123,7 @@ AverageScalarInTime<dim>::save(const std::string &prefix)

template <int dim>
std::vector<GlobalVectorType *>
AverageScalarInTime<dim>::read(const std::string &prefix)
AverageScalar<dim>::read(const std::string &prefix)
{
std::vector<GlobalVectorType *> sum_vectors;
sum_vectors.push_back(&sum_scalar_dt_with_ghost_cells);
Expand All @@ -142,5 +141,5 @@ AverageScalarInTime<dim>::read(const std::string &prefix)
return sum_vectors;
}

template class AverageScalarInTime<2>;
template class AverageScalarInTime<3>;
template class AverageScalar<2>;
template class AverageScalar<3>;
4 changes: 2 additions & 2 deletions tests/solvers/average_scalar_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d38e469

Please sign in to comment.