Skip to content

Commit

Permalink
Merge pull request #11637 from KratosMultiphysics/core/timer-ostream
Browse files Browse the repository at this point in the history
[Core][BuiltinTimer] add ostream operator
  • Loading branch information
philbucher authored Sep 30, 2023
2 parents e21baa8 + 34cc873 commit b652b8e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Project includes
#include "utilities/assign_master_slave_constraints_to_neighbours_utility.h"

namespace Kratos
namespace Kratos
{
///@addtogroup Kratos Core
///@{
Expand All @@ -43,8 +43,8 @@ AssignMasterSlaveConstraintsToNeighboursUtility::AssignMasterSlaveConstraintsToN
NodesContainerType::ContainerType& nodes_model_part = rMasterStructureNodes.GetContainer();
mpBins = Kratos::make_unique<NodeBinsType>(nodes_model_part.begin(), nodes_model_part.end());
mMaxNumberOfNodes = rMasterStructureNodes.size();
KRATOS_CATCH("");
}
KRATOS_CATCH("");
}

// Destructor
AssignMasterSlaveConstraintsToNeighboursUtility::~AssignMasterSlaveConstraintsToNeighboursUtility() {}
Expand Down Expand Up @@ -97,7 +97,7 @@ void AssignMasterSlaveConstraintsToNeighboursUtility::GetDofsAndCoordinatesForSl
} else {
std::stringstream variables_str;
variables_str << "[";
for (const auto& variable : rVariableList)
for (const auto& variable : rVariableList)
variables_str << variable.get() << ", ";
variables_str.seekp(-2, std::ios_base::end); // Remove the last ", "
variables_str << "]";
Expand Down Expand Up @@ -206,7 +206,7 @@ void AssignMasterSlaveConstraintsToNeighboursUtility::AssignMasterSlaveConstrain
// Get Dofs and Coordinates for the slave node and the cloud of nodes
GetDofsAndCoordinatesForSlaveNode(p_slave_node, rVariableList, r_slave_dofs, r_slave_coordinates);
GetDofsAndCoordinatesForCloudOfNodes(r_cloud_of_nodes, rVariableList, r_cloud_of_dofs, r_cloud_of_nodes_coordinates);

// Calculate shape functions
RBFShapeFunctionsUtility::CalculateShapeFunctions(r_cloud_of_nodes_coordinates, r_slave_coordinates, r_n_container);

Expand All @@ -232,7 +232,7 @@ void AssignMasterSlaveConstraintsToNeighboursUtility::AssignMasterSlaveConstrain
// Add the constraints to the rComputingModelPart in a single call
rComputingModelPart.AddMasterSlaveConstraints(temp_constraints.begin(), temp_constraints.end());

KRATOS_INFO("AssignMasterSlaveConstraintsToNeighboursUtility") << "Build and Assign Master-Slave Constraints Time: " << build_and_assign_mscs.ElapsedSeconds() << std::endl;
KRATOS_INFO("AssignMasterSlaveConstraintsToNeighboursUtility") << "Build and Assign Master-Slave Constraints Time: " << build_and_assign_mscs << std::endl;
KRATOS_CATCH("");
}
} // namespace Kratos.
Expand Down
34 changes: 27 additions & 7 deletions kratos/utilities/builtin_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: Michael Andre
//
//

#if !defined(KRATOS_BUILTIN_TIMER_H_INCLUDED)
#define KRATOS_BUILTIN_TIMER_H_INCLUDED
#pragma once

// System includes
#include <chrono>
Expand Down Expand Up @@ -58,6 +57,27 @@ class BuiltinTimer

///@} // Kratos Classes

} // namespace Kratos.
/// output stream function
inline std::ostream& operator << (std::ostream& rOStream, const BuiltinTimer& rThis)
{
const double elapsed_secs = rThis.ElapsedSeconds();

int minutes = elapsed_secs / 60;
int hours = minutes / 60;
minutes = minutes % 60;
double seconds = elapsed_secs - hours*3600.0 - minutes*60.0;

if (hours > 0) {
rOStream << hours << " [h] ";
}
if (minutes > 0) {
rOStream << minutes << " [m] ";
// remove decimals if over a minute
seconds = int(seconds);
}
rOStream << seconds << " [s]";
return rOStream;

#endif // KRATOS_BUILTIN_TIMER_H_INCLUDED defined
}

} // namespace Kratos.

0 comments on commit b652b8e

Please sign in to comment.