From afe7dbb4e237d8623f6aee4b85f5d6c62e416fb0 Mon Sep 17 00:00:00 2001 From: Bruno Blais Date: Tue, 20 Aug 2024 17:12:12 -0400 Subject: [PATCH] Remove all clang tidy warnings from the core library of Lethe (#1243) Description Since I have deployed the new CI action, we are able to identify many more alerts using clang sanitizer. This PR aims at removing the alerts from the core library of Lethe. We still have warnings when we compile with clang, but this will need an additional CI instance check. Testing All units tests and application tests should pass before this is merged. --- include/core/bdf.h | 10 ++-- include/core/manifolds.h | 12 ++-- include/core/parameters.h | 12 ++-- include/core/parsed_function_custom.h | 6 +- include/core/pvd_handler.h | 6 +- include/core/serial_solid.h | 7 ++- include/core/shape.h | 2 +- include/core/shape_parsing.h | 16 +++--- include/core/simulation_control.h | 29 ++++++---- include/core/solid_base.h | 8 +-- include/core/solutions_output.h | 8 +-- include/core/utilities.h | 14 ++--- source/core/bdf.cc | 16 +++--- source/core/lethe_grid_tools.cc | 8 +-- source/core/manifolds.cc | 16 +++--- source/core/parameters.cc | 20 +++---- source/core/parsed_function_custom.cc | 7 ++- source/core/pvd_handler.cc | 9 ++- source/core/serial_solid.cc | 6 +- source/core/shape.cc | 2 +- source/core/shape_parsing.cc | 56 +++++++++---------- source/core/simulation_control.cc | 24 ++++---- source/core/solid_base.cc | 8 +-- source/core/solutions_output.cc | 40 ++++++------- source/core/utilities.cc | 46 ++++++++------- tests/core/bdf_01.cc | 10 ++-- tests/core/bdf_extrapolation_01.cc | 20 ++++--- .../lethe_grid_tool_mesh_cut_by_flat_2.cc | 11 ++-- .../lethe_grid_tool_mesh_cut_by_flat_3.cc | 13 ++--- tests/core/shape_composites.cc | 10 ++-- tests/core/table_read.cc | 13 ++--- tests/core/vector_problem.cc | 15 ++--- 32 files changed, 242 insertions(+), 238 deletions(-) diff --git a/include/core/bdf.h b/include/core/bdf.h index 10f935761a..e8fb5ff6c3 100644 --- a/include/core/bdf.h +++ b/include/core/bdf.h @@ -50,7 +50,7 @@ using namespace dealii; Vector calculate_bdf_coefficients( const Parameters::SimulationControl::TimeSteppingMethod method, - const std::vector time_steps); + const std::vector &time_steps); /** @@ -78,10 +78,10 @@ calculate_bdf_coefficients( * calculation of BDF coefficients. */ Vector -delta(const unsigned int order, - const unsigned int n, - const unsigned int j, - const Vector times); +delta(const unsigned int order, + const unsigned int n, + const unsigned int j, + const Vector ×); diff --git a/include/core/manifolds.h b/include/core/manifolds.h index beeb57d6d1..fedf3fb701 100644 --- a/include/core/manifolds.h +++ b/include/core/manifolds.h @@ -186,19 +186,19 @@ attach_manifolds_to_triangulation( */ void attach_cad_to_manifold(parallel::DistributedTriangulationBase<2> &triangulation, - std::string cad_name, - unsigned int manifold_id); + const std::string &cad_name, + const unsigned int manifold_id); void attach_cad_to_manifold( parallel::DistributedTriangulationBase<2, 3> &triangulation, - std::string cad_name, - unsigned int manifold_id); + const std::string &cad_name, + const unsigned int manifold_id); void attach_cad_to_manifold(parallel::DistributedTriangulationBase<3> &triangulation, - std::string cad_name, - unsigned int manifold_id); + const std::string &cad_name, + const unsigned int manifold_id); diff --git a/include/core/parameters.h b/include/core/parameters.h index a9423789c4..f9970e66df 100644 --- a/include/core/parameters.h +++ b/include/core/parameters.h @@ -384,12 +384,12 @@ namespace Parameters {} void - declare_parameters(ParameterHandler &prm, - std::string material_prefix, - unsigned int id); + declare_parameters(ParameterHandler &prm, + const std::string &material_prefix, + unsigned int id); void parse_parameters(ParameterHandler &prm, - std::string material_prefix, + const std::string &material_prefix, const unsigned int id, const Dimensionality dimensions); @@ -815,8 +815,8 @@ namespace Parameters // z =2) value of the beam_orientation parameter unsigned int beam_orientation_coordinate; - // beam_direction shows the direction of laser beam (either in positive (1) - // or negative (0) direction + // beam_direction shows the direction of laser beam (either in positive + // (true) or negative (false) direction bool beam_direction; // Based on the laser beam orientation, the integer values of a diff --git a/include/core/parsed_function_custom.h b/include/core/parsed_function_custom.h index b175d0732e..35570b20c8 100644 --- a/include/core/parsed_function_custom.h +++ b/include/core/parsed_function_custom.h @@ -81,9 +81,9 @@ class ParsedFunctionCustom * @param[in] constants_list Constants used by the expressions */ void - initialize(const std::string vnames, - const std::string expression, - const std::string constants_list); + initialize(const std::string &vnames, + const std::string &expression, + const std::string &constants_list); /** * @brief Evaluate all components at the evaluation point diff --git a/include/core/pvd_handler.h b/include/core/pvd_handler.h index 25b8663f22..141caa6aa3 100644 --- a/include/core/pvd_handler.h +++ b/include/core/pvd_handler.h @@ -35,7 +35,7 @@ class PVDHandler * @param filename Name of the file to which the PVDHandler content is save */ void - save(std::string filename); + save(const std::string &filename); /** * @brief read Reads the content of a pvd times_and_names checpoint @@ -43,10 +43,10 @@ class PVDHandler * @param filename Name of the file frin which the PVDHandler content is read */ void - read(std::string filename); + read(const std::string &filename); void - append(double time, std::string pvtu_filename) + append(double time, const std::string &pvtu_filename) { times_and_names.push_back( std::pair(time, pvtu_filename)); diff --git a/include/core/serial_solid.h b/include/core/serial_solid.h index 757c0d7768..27d4f4a6b7 100644 --- a/include/core/serial_solid.h +++ b/include/core/serial_solid.h @@ -201,7 +201,8 @@ class SerialSolid * @param simulation_control The simulation control object */ void - write_output_results(std::shared_ptr simulation_control); + write_output_results( + const std::shared_ptr &simulation_control); /** * @brief read solid base triangulation checkpoint and replaces the @@ -211,7 +212,7 @@ class SerialSolid * */ void - read_checkpoint(std::string prefix_name); + read_checkpoint(const std::string &prefix_name); /** * @brief write solid base triangulation checkpoint @@ -219,7 +220,7 @@ class SerialSolid * @param prefix_name The prefix of the checkpoint of the simulation */ void - write_checkpoint(std::string prefix_name); + write_checkpoint(const std::string &prefix_name); private: diff --git a/include/core/shape.h b/include/core/shape.h index 0a3ba533b3..a71dd71cdb 100644 --- a/include/core/shape.h +++ b/include/core/shape.h @@ -2680,7 +2680,7 @@ class RBFShape : public Shape * @param orientation the orientation of the shape with respect to each main * axis */ - RBFShape(const std::string shape_arguments_str, + RBFShape(const std::string &shape_arguments_str, const Point &position, const Tensor<1, 3> &orientation); diff --git a/include/core/shape_parsing.h b/include/core/shape_parsing.h index 0ae01de080..5fd019726d 100644 --- a/include/core/shape_parsing.h +++ b/include/core/shape_parsing.h @@ -33,8 +33,8 @@ namespace ShapeGenerator */ template std::shared_ptr> - initialize_shape(const std::string type, - const std::string shape_arguments_str, + initialize_shape(const std::string &type, + const std::string &shape_arguments_str, const Point &position, const Tensor<1, 3> &orientation); @@ -47,10 +47,10 @@ namespace ShapeGenerator */ template std::shared_ptr> - initialize_shape_from_vector(const std::string type, - const std::vector shape_arguments, - const Point &position, - const Tensor<1, 3> &orientation); + initialize_shape_from_vector(const std::string &type, + const std::vector &shape_arguments, + const Point &position, + const Tensor<1, 3> &orientation); /** * Initializes the shape from its type and a text file that contains the real @@ -62,8 +62,8 @@ namespace ShapeGenerator */ template std::shared_ptr> - initialize_shape_from_file(const std::string type, - const std::string file_name, + initialize_shape_from_file(const std::string &type, + const std::string &file_name, const Point &position, const Tensor<1, 3> &orientation); } // namespace ShapeGenerator diff --git a/include/core/simulation_control.h b/include/core/simulation_control.h index 757ac99005..08dd840459 100644 --- a/include/core/simulation_control.h +++ b/include/core/simulation_control.h @@ -165,7 +165,7 @@ class SimulationControl * **/ - SimulationControl(const Parameters::SimulationControl param); + SimulationControl(const Parameters::SimulationControl ¶m); /** * @brief Pure virtual function to control the progression of the simulation. @@ -472,23 +472,31 @@ class SimulationControl return bdf_coefs; } - + /** + * @brief Save the simulation control information from the checkpoint file and updates the time step vector, the CFL value, the time and the iteration number. + * + * @param prefix The prefix of the checkpoint of the simulation + */ void - save(std::string filename); + save(const std::string &prefix); /** * @brief Reads the simulation control information from the checkpoint file and updates the time step vector, the CFL value, the time and the iteration number. + * + * @param prefix The prefix of the checkpoint of the simulation */ void - read(std::string filename); + read(const std::string &prefix); /** * @brief Reads and returns the simulation control information from the checkpoint file filename without updating the simulation control information. * + * @param prefix The prefix of the checkpoint of the simulation + * * @return A vector containing the last checkpointed file and time step. */ std::vector - get_checkpointed_simulation_control_info(std::string filename); + get_checkpointed_simulation_control_info(const std::string &prefix); }; @@ -518,7 +526,7 @@ class SimulationControlTransient : public SimulationControl public: - SimulationControlTransient(Parameters::SimulationControl param); + SimulationControlTransient(const Parameters::SimulationControl ¶m); virtual void print_progression(const ConditionalOStream &pcout) override; @@ -543,7 +551,7 @@ class SimulationControlTransient : public SimulationControl class SimulationControlTransientDEM : public SimulationControlTransient { public: - SimulationControlTransientDEM(Parameters::SimulationControl param); + SimulationControlTransientDEM(const Parameters::SimulationControl ¶m); virtual void print_progression(const ConditionalOStream &pcout) override; @@ -571,7 +579,8 @@ class SimulationControlTransientDynamicOutput calculate_time_step() override; public: - SimulationControlTransientDynamicOutput(Parameters::SimulationControl param); + SimulationControlTransientDynamicOutput( + const Parameters::SimulationControl ¶m); /** @@ -585,7 +594,7 @@ class SimulationControlTransientDynamicOutput class SimulationControlSteady : public SimulationControl { public: - SimulationControlSteady(Parameters::SimulationControl param); + SimulationControlSteady(const Parameters::SimulationControl ¶m); virtual void print_progression(const ConditionalOStream &pcout) override; @@ -606,7 +615,7 @@ class SimulationControlSteady : public SimulationControl class SimulationControlAdjointSteady : public SimulationControlTransient { public: - SimulationControlAdjointSteady(Parameters::SimulationControl param); + SimulationControlAdjointSteady(const Parameters::SimulationControl ¶m); virtual void print_progression(const ConditionalOStream &pcout) override; diff --git a/include/core/solid_base.h b/include/core/solid_base.h index 5cd4af9378..5bf12c55ca 100644 --- a/include/core/solid_base.h +++ b/include/core/solid_base.h @@ -101,14 +101,14 @@ class SolidBase * @brief Loads a solid triangulation from a restart file */ void - load_triangulation(const std::string filename_tria); + load_triangulation(const std::string &filename_tria); /** * @brief Loads a particle handler in the fluid triangulation domain that holds the particles of the solid * according to a specific quadrature, and sets up dofs */ void - load_particles(const std::string filename_part); + load_particles(const std::string &filename_part); /** * @return the reference to the std::shared_ptr of a Particles::ParticleHandler that contains the solid particle handler @@ -220,13 +220,13 @@ class SolidBase * @brief read solid base triangulation checkpoint */ void - read_checkpoint(std::string prefix_name); + read_checkpoint(const std::string &prefix_name); /** * @brief write solid base triangulation checkpoint */ void - write_checkpoint(std::string prefix_name); + write_checkpoint(const std::string &prefix_name); private: diff --git a/include/core/solutions_output.h b/include/core/solutions_output.h index 27f5eb6667..ff4e08b93e 100644 --- a/include/core/solutions_output.h +++ b/include/core/solutions_output.h @@ -55,8 +55,8 @@ template void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface &data_out, - const std::string folder, - const std::string file_prefix, + const std::string &folder, + const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, @@ -80,10 +80,10 @@ write_vtu_and_pvd(PVDHandler &pvd_handler, template void write_boundaries_vtu(const DataOutFaces &data_out, - const std::string folder, + const std::string &folder, const double time, const unsigned int iter, const MPI_Comm &mpi_communicator, - const std::string file_prefix = std::string("boundaries"), + const std::string &file_prefix = std::string("boundaries"), const unsigned int digits = 5); #endif diff --git a/include/core/utilities.h b/include/core/utilities.h index f890e9e3e6..1aeeb515b3 100644 --- a/include/core/utilities.h +++ b/include/core/utilities.h @@ -363,9 +363,9 @@ calculate_point_property_cahn_hilliard(const double phase_cahn_hilliard, * @param delimiter The delimiter used to read the table. */ void -fill_table_from_file(TableHandler &table, - const std::string file_name, - const std::string delimiter = " "); +fill_table_from_file(TableHandler &table, + const std::string &file_name, + const std::string &delimiter = " "); /** * @brief function that read a file that was build from a dealii table and fill 2 vectors. @@ -379,8 +379,8 @@ fill_table_from_file(TableHandler &table, */ void fill_vectors_from_file(std::map> &map, - const std::string file_name, - const std::string delimiter = " "); + const std::string &file_name, + const std::string &delimiter = " "); /** * @brief Function that read a file that was build from a dealii table and create a map with the key being the column name and the variable the vectors of data. @@ -393,8 +393,8 @@ fill_vectors_from_file(std::map> &map, void fill_string_vectors_from_file( std::map> &map, - const std::string file_name, - const std::string delimiter = " "); + const std::string &file_name, + const std::string &delimiter = " "); /** * @brief Creates the simulation output folder diff --git a/source/core/bdf.cc b/source/core/bdf.cc index c974e39584..3f55d29a4e 100644 --- a/source/core/bdf.cc +++ b/source/core/bdf.cc @@ -20,10 +20,10 @@ Vector -bdf_coefficients(const unsigned int p, const std::vector dt) +bdf_coefficients(const unsigned int p, const std::vector &time_steps) { // There should be at least p time steps - assert(dt.size() >= p); + assert(time_steps.size() >= p); // Create a time table for the bdf formula Vector times(p + 1); @@ -31,7 +31,7 @@ bdf_coefficients(const unsigned int p, const std::vector dt) { times[i] = 0.; for (unsigned int j = 0; j < i; ++j) - times[i] -= dt[j]; + times[i] -= time_steps[j]; } // The alphas are the bdf coefficients @@ -54,7 +54,7 @@ bdf_coefficients(const unsigned int p, const std::vector dt) Vector calculate_bdf_coefficients( const Parameters::SimulationControl::TimeSteppingMethod method, - const std::vector time_steps) + const std::vector &time_steps) { switch (method) { @@ -74,10 +74,10 @@ calculate_bdf_coefficients( } Vector -delta(const unsigned int p, - const unsigned int n, - const unsigned int j, - const Vector times) +delta(const unsigned int p, + const unsigned int n, + const unsigned int j, + const Vector ×) { if (j == 0) { diff --git a/source/core/lethe_grid_tools.cc b/source/core/lethe_grid_tools.cc index 964849d66f..7a299c480b 100644 --- a/source/core/lethe_grid_tools.cc +++ b/source/core/lethe_grid_tools.cc @@ -913,7 +913,7 @@ LetheGridTools::find_cells_around_flat_cell( std::set::active_cell_iterator>> &vertices_cell_map) { - TriaActiveIterator> starting_cell = + TriaActiveIterator> starting_cell = find_cell_around_point_with_tree(dof_handler, cell->vertex(0)); std::unordered_set::active_cell_iterator, @@ -1257,13 +1257,13 @@ LetheGridTools::find_particle_triangle_projection( vector_to_plane = p_0 - particle_position; // A bool variable for region 0 - bool region_zero = 0; + bool region_zero = false; // Check to see if the particle is located on the correct side (with // respect to the normal vector) of the triangle if (vector_to_plane * unit_normal > 0) { - unit_normal = -1.0 * unit_normal; + unit_normal *= -1.0; } double distance_squared = scalar_product(vector_to_plane, unit_normal); @@ -1349,7 +1349,7 @@ LetheGridTools::find_particle_triangle_projection( if constexpr (dim == 2) unit_normal_3d = tensor_nd_to_3d(unit_normal); - region_zero = 1; + region_zero = true; } } else diff --git a/source/core/manifolds.cc b/source/core/manifolds.cc index a3a61cb3fd..e3434e2310 100644 --- a/source/core/manifolds.cc +++ b/source/core/manifolds.cc @@ -160,16 +160,16 @@ attach_manifolds_to_triangulation( void attach_cad_to_manifold(parallel::DistributedTriangulationBase<2> &, - std::string, - unsigned int) + const std::string &, + const unsigned int) { throw std::runtime_error("IGES manifolds are not supported in 2D"); } void attach_cad_to_manifold(parallel::DistributedTriangulationBase<2, 3> &, - std::string, - unsigned int) + const std::string &, + const unsigned int) { throw std::runtime_error("IGES manifolds are not supported in 2D/3D"); } @@ -177,8 +177,8 @@ attach_cad_to_manifold(parallel::DistributedTriangulationBase<2, 3> &, #ifdef DEAL_II_WITH_OPENCASCADE void attach_cad_to_manifold(parallel::DistributedTriangulationBase<3> &triangulation, - std::string cad_name, - unsigned int manifold_id) + const std::string &cad_name, + const unsigned int manifold_id) { TopoDS_Shape cad_surface = OpenCASCADE::read_IGES(cad_name, 1e-3); @@ -207,8 +207,8 @@ attach_cad_to_manifold(parallel::DistributedTriangulationBase<3> &triangulation, #else void attach_cad_to_manifold(parallel::DistributedTriangulationBase<3> &, - std::string, - unsigned int) + const std::string &, + const unsigned int) { throw std::runtime_error( "IGES manifolds require DEAL_II to be compiled with OPENCASCADE"); diff --git a/source/core/parameters.cc b/source/core/parameters.cc index 8368f6fbc2..2412e0dbe2 100644 --- a/source/core/parameters.cc +++ b/source/core/parameters.cc @@ -973,9 +973,9 @@ namespace Parameters } void - Material::declare_parameters(ParameterHandler &prm, - std::string material_prefix, - unsigned int id) + Material::declare_parameters(ParameterHandler &prm, + const std::string &material_prefix, + unsigned int id) { prm.enter_subsection(material_prefix + " " + Utilities::int_to_string(id, 1)); @@ -1081,7 +1081,7 @@ namespace Parameters void Material::parse_parameters(ParameterHandler &prm, - std::string material_prefix, + const std::string &material_prefix, const unsigned int id, const Parameters::Dimensionality dimensions) { @@ -1671,7 +1671,7 @@ namespace Parameters op = prm.get("beam orientation"); if (op == "x+") { - beam_direction = 1; + beam_direction = true; beam_orientation = BeamOrientation::x_plus; beam_orientation_coordinate = 0; perpendicular_plane_coordinate_one = 1; @@ -1680,7 +1680,7 @@ namespace Parameters } else if (op == "x-") { - beam_direction = 0; + beam_direction = false; beam_orientation = BeamOrientation::x_minus; beam_orientation_coordinate = 0; perpendicular_plane_coordinate_one = 1; @@ -1689,7 +1689,7 @@ namespace Parameters } else if (op == "y+") { - beam_direction = 1; + beam_direction = true; beam_orientation = BeamOrientation::y_plus; perpendicular_plane_coordinate_one = 0; beam_orientation_coordinate = 1; @@ -1698,7 +1698,7 @@ namespace Parameters } else if (op == "y-") { - beam_direction = 0; + beam_direction = false; beam_orientation = BeamOrientation::y_minus; perpendicular_plane_coordinate_one = 0; beam_orientation_coordinate = 1; @@ -1709,7 +1709,7 @@ namespace Parameters { if constexpr (dim == 3) { - beam_direction = 1; + beam_direction = true; beam_orientation = BeamOrientation::z_plus; perpendicular_plane_coordinate_one = 0; perpendicular_plane_coordinate_two = 1; @@ -1722,7 +1722,7 @@ namespace Parameters { if constexpr (dim == 3) { - beam_direction = 0; + beam_direction = false; beam_orientation = BeamOrientation::z_minus; perpendicular_plane_coordinate_one = 0; perpendicular_plane_coordinate_two = 1; diff --git a/source/core/parsed_function_custom.cc b/source/core/parsed_function_custom.cc index 6d2570c00d..830dc75454 100644 --- a/source/core/parsed_function_custom.cc +++ b/source/core/parsed_function_custom.cc @@ -148,9 +148,10 @@ ParsedFunctionCustom::parse_parameters(ParameterHandler &prm) template void -ParsedFunctionCustom::initialize(const std::string vnames, - const std::string expression, - const std::string constants_list) +ParsedFunctionCustom::initialize( + const std::string &vnames, + const std::string &expression, + const std::string &constants_list) { this->vnames = vnames; this->expression = expression; diff --git a/source/core/pvd_handler.cc b/source/core/pvd_handler.cc index f4128982c6..9969850bc0 100644 --- a/source/core/pvd_handler.cc +++ b/source/core/pvd_handler.cc @@ -6,21 +6,20 @@ using namespace dealii; void -PVDHandler::save(std::string prefix) +PVDHandler::save(const std::string &prefix) { std::string filename = prefix + ".pvdhandler"; std::ofstream output(filename.c_str()); output << times_and_names.size() << std::endl; output << "Time File" << std::endl; - for (unsigned int i = 0; i < times_and_names.size(); ++i) + for (const auto &time_name : times_and_names) { - output << times_and_names[i].first << " " << times_and_names[i].second - << std::endl; + output << time_name.first << " " << time_name.second << std::endl; } } void -PVDHandler::read(std::string prefix) +PVDHandler::read(const std::string &prefix) { times_and_names.clear(); std::string filename = prefix + ".pvdhandler"; diff --git a/source/core/serial_solid.cc b/source/core/serial_solid.cc index da749b4a97..ea90160e41 100644 --- a/source/core/serial_solid.cc +++ b/source/core/serial_solid.cc @@ -472,7 +472,7 @@ SerialSolid::move_solid_triangulation_with_displacement() template void SerialSolid::write_output_results( - std::shared_ptr simulation_control) + const std::shared_ptr &simulation_control) { if (!output_bool) return; @@ -541,7 +541,7 @@ SerialSolid::write_output_results( template void -SerialSolid::write_checkpoint(std::string prefix) +SerialSolid::write_checkpoint(const std::string &prefix) { // Checkpoint the DOF Handler { @@ -567,7 +567,7 @@ SerialSolid::write_checkpoint(std::string prefix) template void -SerialSolid::read_checkpoint(std::string prefix) +SerialSolid::read_checkpoint(const std::string &prefix) { // Import dof handler { diff --git a/source/core/shape.cc b/source/core/shape.cc index 33ee45ea9e..10494222dd 100644 --- a/source/core/shape.cc +++ b/source/core/shape.cc @@ -1638,7 +1638,7 @@ CompositeShape::set_layer_thickening(const double layer_thickening) } template -RBFShape::RBFShape(const std::string shape_arguments_str, +RBFShape::RBFShape(const std::string &shape_arguments_str, const Point &position, const Tensor<1, 3> &orientation) : Shape(1, position, orientation) diff --git a/source/core/shape_parsing.cc b/source/core/shape_parsing.cc index 489de687ef..af6c846be4 100644 --- a/source/core/shape_parsing.cc +++ b/source/core/shape_parsing.cc @@ -2,8 +2,8 @@ template std::shared_ptr> -ShapeGenerator::initialize_shape(const std::string type, - const std::string shape_arguments_str, +ShapeGenerator::initialize_shape(const std::string &type, + const std::string &shape_arguments_str, const Point &position, const Tensor<1, 3> &orientation) { @@ -32,10 +32,10 @@ ShapeGenerator::initialize_shape(const std::string type, template std::shared_ptr> ShapeGenerator::initialize_shape_from_vector( - const std::string type, - const std::vector shape_arguments, - const Point &position, - const Tensor<1, 3> &orientation) + const std::string &type, + const std::vector &shape_arguments, + const Point &position, + const Tensor<1, 3> &orientation) { std::shared_ptr> shape; if (type == "sphere") @@ -153,8 +153,8 @@ ShapeGenerator::initialize_shape_from_vector( template std::shared_ptr> -ShapeGenerator::initialize_shape_from_file(const std::string type, - const std::string file_name, +ShapeGenerator::initialize_shape_from_file(const std::string &type, + const std::string &file_name, const Point &position, const Tensor<1, 3> &orientation) { @@ -212,12 +212,10 @@ ShapeGenerator::initialize_shape_from_file(const std::string type, std::vector list_of_words_base = Utilities::split_string_list(line, ";"); std::vector list_of_words_clean; - for (unsigned int j = 0; j < list_of_words_base.size(); ++j) + for (const auto &word : list_of_words_base) { - if (list_of_words_base[j] != "") - { - list_of_words_clean.push_back(list_of_words_base[j]); - } + if (word != "") + list_of_words_clean.emplace_back(word); } if (parsing_shapes) { @@ -313,34 +311,34 @@ ShapeGenerator::initialize_shape_from_file(const std::string type, } template std::shared_ptr> -ShapeGenerator::initialize_shape(const std::string type, - const std::string arguments, +ShapeGenerator::initialize_shape(const std::string &type, + const std::string &arguments, const Point<2> &position, const Tensor<1, 3> &orientation); template std::shared_ptr> -ShapeGenerator::initialize_shape(const std::string type, - const std::string arguments, +ShapeGenerator::initialize_shape(const std::string &type, + const std::string &arguments, const Point<3> &position, const Tensor<1, 3> &orientation); template std::shared_ptr> ShapeGenerator::initialize_shape_from_vector( - const std::string type, - const std::vector shape_arguments, - const Point<2> &position, - const Tensor<1, 3> &orientation); + const std::string &type, + const std::vector &shape_arguments, + const Point<2> &position, + const Tensor<1, 3> &orientation); template std::shared_ptr> ShapeGenerator::initialize_shape_from_vector( - const std::string type, - const std::vector shape_arguments, - const Point<3> &position, - const Tensor<1, 3> &orientation); + const std::string &type, + const std::vector &shape_arguments, + const Point<3> &position, + const Tensor<1, 3> &orientation); template std::shared_ptr> -ShapeGenerator::initialize_shape_from_file(const std::string type, - const std::string file_name, +ShapeGenerator::initialize_shape_from_file(const std::string &type, + const std::string &file_name, const Point<2> &position, const Tensor<1, 3> &orientation); template std::shared_ptr> -ShapeGenerator::initialize_shape_from_file(const std::string type, - const std::string file_name, +ShapeGenerator::initialize_shape_from_file(const std::string &type, + const std::string &file_name, const Point<3> &position, const Tensor<1, 3> &orientation); diff --git a/source/core/simulation_control.cc b/source/core/simulation_control.cc index 22ee3f0a24..facb934bfd 100644 --- a/source/core/simulation_control.cc +++ b/source/core/simulation_control.cc @@ -6,7 +6,7 @@ #include -SimulationControl::SimulationControl(const Parameters::SimulationControl param) +SimulationControl::SimulationControl(const Parameters::SimulationControl ¶m) : method(param.method) , assembly_method(param.method) , current_time(0) @@ -146,7 +146,7 @@ SimulationControl::is_verbose_iteration() } void -SimulationControl::save(std::string prefix) +SimulationControl::save(const std::string &prefix) { std::string filename = prefix + ".simulationcontrol"; std::ofstream output(filename.c_str()); @@ -159,7 +159,7 @@ SimulationControl::save(std::string prefix) } void -SimulationControl::read(std::string prefix) +SimulationControl::read(const std::string &prefix) { std::string filename = prefix + ".simulationcontrol"; std::ifstream input(filename.c_str()); @@ -167,8 +167,8 @@ SimulationControl::read(std::string prefix) std::string buffer; std::getline(input, buffer); - for (unsigned int i = 0; i < time_step_vector.size(); ++i) - input >> buffer >> time_step_vector[i]; + for (auto &time_step_value : time_step_vector) + input >> buffer >> time_step_value; input >> buffer >> CFL; input >> buffer >> current_time; input >> buffer >> iteration_number; @@ -178,7 +178,8 @@ SimulationControl::read(std::string prefix) } std::vector -SimulationControl::get_checkpointed_simulation_control_info(std::string prefix) +SimulationControl::get_checkpointed_simulation_control_info( + const std::string &prefix) { std::string filename = prefix + ".simulationcontrol"; std::ifstream input(filename.c_str()); @@ -210,7 +211,7 @@ SimulationControl::get_checkpointed_simulation_control_info(std::string prefix) } SimulationControlTransient::SimulationControlTransient( - Parameters::SimulationControl param) + const Parameters::SimulationControl ¶m) : SimulationControl(param) , adapt(param.adapt) , adaptative_time_step_scaling(param.adaptative_time_step_scaling) @@ -287,7 +288,7 @@ SimulationControlTransient::calculate_time_step() } SimulationControlTransientDEM::SimulationControlTransientDEM( - Parameters::SimulationControl param) + const Parameters::SimulationControl ¶m) : SimulationControlTransient(param) {} @@ -312,7 +313,8 @@ SimulationControlTransientDEM::print_progression( SimulationControlTransientDynamicOutput:: - SimulationControlTransientDynamicOutput(Parameters::SimulationControl param) + SimulationControlTransientDynamicOutput( + const Parameters::SimulationControl ¶m) : SimulationControlTransient(param) , time_step_forced_output(false) // To be fixed for restarts @@ -367,7 +369,7 @@ SimulationControlTransientDynamicOutput::is_output_iteration() SimulationControlSteady::SimulationControlSteady( - Parameters::SimulationControl param) + const Parameters::SimulationControl ¶m) : SimulationControl(param) {} @@ -438,7 +440,7 @@ SimulationControlAdjointSteady::is_at_end() } SimulationControlAdjointSteady::SimulationControlAdjointSteady( - Parameters::SimulationControl param) + const Parameters::SimulationControl ¶m) : SimulationControlTransient(param) {} diff --git a/source/core/solid_base.cc b/source/core/solid_base.cc index ae36fe8fb1..7aa8e6fc1a 100644 --- a/source/core/solid_base.cc +++ b/source/core/solid_base.cc @@ -276,7 +276,7 @@ SolidBase<3, 3>::translate_grid(const Tensor<1, 3> translation) template void -SolidBase::load_triangulation(const std::string filename_tria) +SolidBase::load_triangulation(const std::string &filename_tria) { // Load solid triangulation from given file // Currently we only load the triangulation without loading the particles, @@ -393,7 +393,7 @@ SolidBase::setup_particles() template void -SolidBase::load_particles(const std::string filename_part) +SolidBase::load_particles(const std::string &filename_part) { // Setup particles handler setup_particles_handler(); @@ -717,7 +717,7 @@ SolidBase::print_particle_positions() template void -SolidBase::write_checkpoint(std::string prefix) +SolidBase::write_checkpoint(const std::string &prefix) { // First, manage the serialization of the particle information. // The particles are attached to the background triangulation and not @@ -754,7 +754,7 @@ SolidBase::write_checkpoint(std::string prefix) template void -SolidBase::read_checkpoint(std::string prefix) +SolidBase::read_checkpoint(const std::string &prefix) { // Setup an un-refined triangulation before loading if we have a fully // distributed triangulation. If we have a fully distributed triangulation, diff --git a/source/core/solutions_output.cc b/source/core/solutions_output.cc index 9bd18eea6c..30458a4653 100644 --- a/source/core/solutions_output.cc +++ b/source/core/solutions_output.cc @@ -16,8 +16,8 @@ template void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface &data_out, - const std::string folder, - const std::string file_prefix, + const std::string &folder, + const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, @@ -73,11 +73,11 @@ write_vtu_and_pvd(PVDHandler &pvd_handler, template void write_boundaries_vtu(const DataOutFaces &data_out_faces, - const std::string folder, + const std::string &folder, const double, const unsigned int iter, const MPI_Comm &mpi_communicator, - const std::string file_prefix, + const std::string &file_prefix, const unsigned int digits) { const int my_id = Utilities::MPI::this_mpi_process(mpi_communicator); @@ -97,8 +97,8 @@ write_boundaries_vtu(const DataOutFaces &data_out_faces, template void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface<1, 2> &data_out, - const std::string folder, - const std::string file_prefix, + const std::string &folder, + const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, @@ -108,8 +108,8 @@ write_vtu_and_pvd(PVDHandler &pvd_handler, template void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface<2, 2> &data_out, - const std::string folder, - const std::string file_prefix, + const std::string &folder, + const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, @@ -119,8 +119,8 @@ write_vtu_and_pvd(PVDHandler &pvd_handler, template void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface<2, 3> &data_out, - const std::string folder, - const std::string file_prefix, + const std::string &folder, + const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, @@ -130,8 +130,8 @@ write_vtu_and_pvd(PVDHandler &pvd_handler, template void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface<3, 3> &data_out, - const std::string folder, - const std::string file_prefix, + const std::string &folder, + const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, @@ -141,8 +141,8 @@ write_vtu_and_pvd(PVDHandler &pvd_handler, template void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface<0, 2> &data_out, - const std::string folder, - const std::string file_prefix, + const std::string &folder, + const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, @@ -152,8 +152,8 @@ write_vtu_and_pvd(PVDHandler &pvd_handler, template void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface<0, 3> &data_out, - const std::string folder, - const std::string file_prefix, + const std::string &folder, + const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, @@ -163,18 +163,18 @@ write_vtu_and_pvd(PVDHandler &pvd_handler, template void write_boundaries_vtu(const DataOutFaces<2> &data_out_faces, - const std::string folder, + const std::string &folder, const double time, const unsigned int iter, const MPI_Comm &mpi_communicator, - const std::string file_prefix, + const std::string &file_prefix, const unsigned int digits); template void write_boundaries_vtu(const DataOutFaces<3> &data_out_faces, - const std::string folder, + const std::string &folder, const double time, const unsigned int iter, const MPI_Comm &mpi_communicator, - const std::string file_prefix, + const std::string &file_prefix, const unsigned int digits); diff --git a/source/core/utilities.cc b/source/core/utilities.cc index e2165c8e22..827d4eb4fd 100644 --- a/source/core/utilities.cc +++ b/source/core/utilities.cc @@ -29,14 +29,14 @@ make_table_scalars_vectors( if (display_scientific_notation) { table.set_scientific(independent_column_name, true); - for (unsigned int d = 0; d < dependent_column_names.size(); ++d) - table.set_scientific(dependent_column_names[d], true); + for (const auto &name : dependent_column_names) + table.set_scientific(name, true); } else { table.set_precision(independent_column_name, display_precision); - for (unsigned int d = 0; d < dependent_column_names.size(); ++d) - table.set_precision(dependent_column_names[d], display_precision); + for (const auto &name : dependent_column_names) + table.set_precision(name, display_precision); } return table; @@ -212,9 +212,9 @@ make_table_tensors_scalars( } void -fill_table_from_file(TableHandler &table, - const std::string file_name, - const std::string delimiter) +fill_table_from_file(TableHandler &table, + const std::string &file_name, + const std::string &delimiter) { table.clear(); std::ifstream myfile(file_name); @@ -231,11 +231,11 @@ fill_table_from_file(TableHandler &table, std::vector list_of_words_base = Utilities::split_string_list(line, delimiter); std::vector list_of_words_clean; - for (unsigned int i = 0; i < list_of_words_base.size(); ++i) + for (const auto &word : list_of_words_base) { - if (list_of_words_base[i] != "") + if (word != "") { - list_of_words_clean.push_back(list_of_words_base[i]); + list_of_words_clean.emplace_back(word); } } // If it's the first line, we only initialize the variable names. @@ -259,8 +259,8 @@ fill_table_from_file(TableHandler &table, void fill_vectors_from_file(std::map> &map, - std::string file, - const std::string delimiter) + const std::string &file, + const std::string &delimiter) { // fill a pair, first being a vector of vector name and the second being the // vector of vector associated with the vector name. @@ -278,11 +278,11 @@ fill_vectors_from_file(std::map> &map, std::vector list_of_words_base = Utilities::split_string_list(line, delimiter); std::vector list_of_words_clean; - for (unsigned int i = 0; i < list_of_words_base.size(); ++i) + for (const auto &word : list_of_words_base) { - if (list_of_words_base[i] != "") + if (word != "") { - list_of_words_clean.push_back(list_of_words_base[i]); + list_of_words_clean.emplace_back(word); } } // check if the line is contained words or numbers. @@ -291,7 +291,7 @@ fill_vectors_from_file(std::map> &map, line_of_data = Utilities::string_to_double(list_of_words_clean); for (unsigned int i = 0; i < line_of_data.size(); ++i) { - map[column_names[i]].push_back(line_of_data[i]); + map[column_names[i]].emplace_back(line_of_data[i]); } } else @@ -313,8 +313,8 @@ fill_vectors_from_file(std::map> &map, void fill_string_vectors_from_file( std::map> &map, - std::string file, - const std::string delimiter) + const std::string &file, + const std::string &delimiter) { std::ifstream myfile(file); AssertThrow(myfile, ExcFileNotOpen(file)); @@ -330,12 +330,10 @@ fill_string_vectors_from_file( std::vector list_of_words_base = Utilities::split_string_list(line, delimiter); std::vector list_of_words_clean; - for (unsigned int i = 0; i < list_of_words_base.size(); ++i) + for (const auto &word : list_of_words_base) { - if (list_of_words_base[i] != "") - { - list_of_words_clean.push_back(list_of_words_base[i]); - } + if (word != "") + list_of_words_clean.emplace_back(word); } // Check if it is the first line. If it is we assume it is the // column name. @@ -344,7 +342,7 @@ fill_string_vectors_from_file( line_of_data = list_of_words_clean; for (unsigned int i = 0; i < line_of_data.size(); ++i) { - map[column_names[i]].push_back(line_of_data[i]); + map[column_names[i]].emplace_back(line_of_data[i]); } } else diff --git a/tests/core/bdf_01.cc b/tests/core/bdf_01.cc index e5b144c89d..6ce7104dc4 100644 --- a/tests/core/bdf_01.cc +++ b/tests/core/bdf_01.cc @@ -20,10 +20,11 @@ test() dt[3] = 0.4; dt[4] = 0.5; deallog << "Time steps "; - for (unsigned int i = 0; i < dt.size(); ++i) + for (const auto &dt_val : dt) { - deallog << dt[i] << " "; + deallog << dt_val << " "; } + deallog << std::endl; Vector order1_coefficients = calculate_bdf_coefficients( @@ -40,10 +41,11 @@ test() Vector order3_coefficients = calculate_bdf_coefficients( Parameters::SimulationControl::TimeSteppingMethod::bdf3, dt); deallog << "Order 3 : "; - for (unsigned int i = 0; i < order3_coefficients.size(); ++i) + for (const auto &coefficient : order3_coefficients) { - deallog << order3_coefficients[i] << " "; + deallog << coefficient << " "; } + deallog << std::endl; } diff --git a/tests/core/bdf_extrapolation_01.cc b/tests/core/bdf_extrapolation_01.cc index 82062cdb09..6b11dd72be 100644 --- a/tests/core/bdf_extrapolation_01.cc +++ b/tests/core/bdf_extrapolation_01.cc @@ -56,10 +56,11 @@ test() deallog << "Order 1: "; - for (unsigned int v = 0; v < out_values.size(); ++v) + for (const auto &val : out_values) { - deallog << out_values[v] << " "; + deallog << val << " "; } + deallog << std::endl; } @@ -71,10 +72,11 @@ test() deallog << "Order 2 constant time steps: "; - for (unsigned int v = 0; v < out_values.size(); ++v) + for (const auto &val : out_values) { - deallog << out_values[v] << " "; + deallog << val << " "; } + deallog << std::endl; } @@ -86,10 +88,11 @@ test() deallog << "Order 2 variable time steps: "; - for (unsigned int v = 0; v < out_values.size(); ++v) + for (const auto &val : out_values) { - deallog << out_values[v] << " "; + deallog << val << " "; } + deallog << std::endl; } @@ -101,10 +104,11 @@ test() deallog << "Order 3 constant time steps: "; - for (unsigned int v = 0; v < out_values.size(); ++v) + for (const auto &val : out_values) { - deallog << out_values[v] << " "; + deallog << val << " "; } + deallog << std::endl; } } diff --git a/tests/core/lethe_grid_tool_mesh_cut_by_flat_2.cc b/tests/core/lethe_grid_tool_mesh_cut_by_flat_2.cc index 84ded63d2d..2e6bb37b63 100644 --- a/tests/core/lethe_grid_tool_mesh_cut_by_flat_2.cc +++ b/tests/core/lethe_grid_tool_mesh_cut_by_flat_2.cc @@ -102,13 +102,12 @@ test() }); Vector subdomain(triangulation.n_active_cells()); - for (unsigned int i = 0; i < cells_cut.size(); ++i) + for (auto &cell : cells_cut) { - cells_cut[i]->set_subdomain_id(1); - subdomain(cells_cut[i]->global_active_cell_index()) = 1; - deallog << "The cell with ID : " - << cells_cut[i]->global_active_cell_index() << " is cut " - << std::endl; + cell->set_subdomain_id(1); + subdomain(cell->global_active_cell_index()) = 1; + deallog << "The cell with ID : " << cell->global_active_cell_index() + << " is cut " << std::endl; } // Printing the final position for all the vertices diff --git a/tests/core/lethe_grid_tool_mesh_cut_by_flat_3.cc b/tests/core/lethe_grid_tool_mesh_cut_by_flat_3.cc index a3fcd88300..e265d4241e 100644 --- a/tests/core/lethe_grid_tool_mesh_cut_by_flat_3.cc +++ b/tests/core/lethe_grid_tool_mesh_cut_by_flat_3.cc @@ -100,14 +100,13 @@ test() }); - for (unsigned int i = 0; i < cells_cut.size(); ++i) + for (auto &cell : cells_cut) { - cells_cut[i]->set_subdomain_id(1); - subdomain(cells_cut[i]->global_active_cell_index()) = - cells_cut[i]->global_active_cell_index(); - deallog << "The cell with ID : " - << cells_cut[i]->global_active_cell_index() << " is cut " - << std::endl; + cell->set_subdomain_id(1); + subdomain(cell->global_active_cell_index()) = + cell->global_active_cell_index(); + deallog << "The cell with ID : " << cell->global_active_cell_index() + << " is cut " << std::endl; } // Printing the final position for all the vertices diff --git a/tests/core/shape_composites.cc b/tests/core/shape_composites.cc index a1892dc8b1..d9ae15295e 100644 --- a/tests/core/shape_composites.cc +++ b/tests/core/shape_composites.cc @@ -30,11 +30,11 @@ test() shapes[1] = rectangle; // Creation of maps of operations - typedef std::map< - unsigned int, - std::tuple::BooleanOperation, unsigned int, unsigned int>> - operation_map; - typedef CompositeShape<3>::BooleanOperation boolean_operation; + using operation_map = std::map::BooleanOperation, + unsigned int, + unsigned int>>; + using boolean_operation = CompositeShape<3>::BooleanOperation; operation_map operation_union; operation_union[2] = std::make_tuple(boolean_operation::Union, 0, 1); diff --git a/tests/core/table_read.cc b/tests/core/table_read.cc index 7161c9696b..aa8886c1e8 100644 --- a/tests/core/table_read.cc +++ b/tests/core/table_read.cc @@ -52,16 +52,11 @@ test() std::map> vectors; fill_vectors_from_file(vectors, table_file_name); - for (std::map>::iterator it = - vectors.begin(); - it != vectors.end(); - ++it) + for (const auto &it : vectors) { - deallog << it->first << std::endl; - for (unsigned int j = 0; j < it->second.size(); ++j) - { - deallog << it->second[j] << std::endl; - } + deallog << it.first << std::endl; + for (const auto &j : it.second) + deallog << j << std::endl; } } diff --git a/tests/core/vector_problem.cc b/tests/core/vector_problem.cc index bcaedee2e3..8574225016 100644 --- a/tests/core/vector_problem.cc +++ b/tests/core/vector_problem.cc @@ -99,14 +99,12 @@ test() for (unsigned int d = 0; d < 3; ++d) { - for (auto j = index_set_velocity[d].begin(); - j != index_set_velocity[d].end(); - j++) + for (const auto &j : index_set_velocity[d]) { - correction_norm += dummy_solution[*j] * dummy_solution[*j]; + correction_norm += dummy_solution[j] * dummy_solution[j]; max_correction = - std::max(max_correction, std::abs(dummy_solution[*j])); + std::max(max_correction, std::abs(dummy_solution[j])); } } @@ -116,12 +114,11 @@ test() correction_norm = 0.0; max_correction = DBL_MIN; - for (auto j = index_set_pressure[3].begin(); j != index_set_pressure[3].end(); - j++) + for (const auto &j : index_set_pressure[3]) { - correction_norm += dummy_solution[*j] * dummy_solution[*j]; + correction_norm += dummy_solution[j] * dummy_solution[j]; - max_correction = std::max(max_correction, std::abs(dummy_solution[*j])); + max_correction = std::max(max_correction, std::abs(dummy_solution[j])); } deallog << "||p||_L2 : " << std::sqrt(correction_norm) << std::endl;