Commit 2a23636b authored by GILLES Sebastien's avatar GILLES Sebastien

#356 Introduce a new function that handles initialization of time keep.

parent 41148658
......@@ -96,6 +96,8 @@
BE41A8DA1A24AB6B004E4312 /* libSeldon.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE2393191A23978400E24C84 /* libSeldon.a */; };
BE41C7591A41D89C007DFB55 /* libPostProcessing.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE45292A1A41AC3F006A1577 /* libPostProcessing.a */; };
BE4238361A431E8400666812 /* libOps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BE2393141A23977700E24C84 /* libOps.a */; };
BE42A43B1A5D650E00B3FF6B /* InitTimeKeepLog.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE42A4381A5D650E00B3FF6B /* InitTimeKeepLog.hpp */; };
BE42A43C1A5D650E00B3FF6B /* InitTimeKeepLog.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE42A4391A5D650E00B3FF6B /* InitTimeKeepLog.hxx */; };
BE438D881A3EE658004AC229 /* WorkMatrices.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE438D851A3EE658004AC229 /* WorkMatrices.hpp */; };
BE438D891A3EE658004AC229 /* WorkMatrices.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BE438D861A3EE658004AC229 /* WorkMatrices.hxx */; };
BE438D8C1A3EF493004AC229 /* WorkVectors.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BE438D8A1A3EF493004AC229 /* WorkVectors.hpp */; };
......@@ -1091,6 +1093,8 @@
BE41F81219FFEE50009D04E7 /* LocalNode.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LocalNode.hpp; sourceTree = "<group>"; };
BE41F81319FFEE50009D04E7 /* LocalNode.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LocalNode.hxx; sourceTree = "<group>"; };
BE4225F219E41C6F008F6FA5 /* EnumInterface.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = EnumInterface.hxx; sourceTree = "<group>"; };
BE42A4381A5D650E00B3FF6B /* InitTimeKeepLog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = InitTimeKeepLog.hpp; path = src/Core/InitTimeKeepLog.hpp; sourceTree = "<group>"; };
BE42A4391A5D650E00B3FF6B /* InitTimeKeepLog.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = InitTimeKeepLog.hxx; path = src/Core/InitTimeKeepLog.hxx; sourceTree = "<group>"; };
BE438D851A3EE658004AC229 /* WorkMatrices.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = WorkMatrices.hpp; sourceTree = "<group>"; };
BE438D861A3EE658004AC229 /* WorkMatrices.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = WorkMatrices.hxx; sourceTree = "<group>"; };
BE438D8A1A3EF493004AC229 /* WorkVectors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = WorkVectors.hpp; sourceTree = "<group>"; };
......@@ -2425,6 +2429,8 @@
BEA4FC2A18214B6A002B2EA1 /* TransientParameters.cpp */,
BEA4FC2B18214B6A002B2EA1 /* TransientParameters.hpp */,
BEC4383A1834FAC8005B6730 /* TransientParameters.hxx */,
BE42A4381A5D650E00B3FF6B /* InitTimeKeepLog.hpp */,
BE42A4391A5D650E00B3FF6B /* InitTimeKeepLog.hxx */,
BE968B6917AB94A100995748 /* InputParameter */,
BE747A8B17CE40D200E7FDF0 /* main_create_defaut_input_file.cpp */,
);
......@@ -3877,8 +3883,10 @@
BE90DED01A24903700CCAFDE /* Mpi.hpp in Headers */,
BE90DEDC1A24903700CCAFDE /* Petsc.hpp in Headers */,
BE90DEDA1A24903700CCAFDE /* BoundaryCondition.hpp in Headers */,
BE42A43C1A5D650E00B3FF6B /* InitTimeKeepLog.hxx in Headers */,
BE90DEE11A24903700CCAFDE /* Result.hpp in Headers */,
BE90DEE01A24903700CCAFDE /* Force.hpp in Headers */,
BE42A43B1A5D650E00B3FF6B /* InitTimeKeepLog.hpp in Headers */,
BE90DED31A24903700CCAFDE /* InputParameterList.hxx in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
......
......@@ -22,10 +22,10 @@ int main(int argc, char ** argv)
{
Wrappers::Mpi::InitEnvironment(argc, argv);
Wrappers::Mpi::shared_ptr mpi_world_ptr =
std::make_shared<Wrappers::Mpi>(0, Wrappers::MpiNS::Comm::World); // must be called before Petsc RAII
std::make_shared<Wrappers::Mpi>(0, Wrappers::MpiNS::Comm::World); // must be called before Petsc RAII
std::string input_parameter_file =
Utilities::CommandLineOptions::InputParameterFileFromCommandLine(argc, argv, __FILE__, __LINE__);
Utilities::CommandLineOptions::InputParameterFileFromCommandLine(argc, argv, __FILE__, __LINE__);
std::string time_log_filename;
......
//
// InitTimeKeepLog.hpp
// HappyHeart
//
// Created by Sebastien Gilles on 07/01/15.
// Copyright (c) 2015 Inria. All rights reserved.
//
#ifndef __HappyHeart__InitTimeKeepLog__HPP
# define __HappyHeart__InitTimeKeepLog__HPP
# include "ThirdParty/Wrappers/Mpi/Mpi.hpp"
# include "Utilities/TimeKeep/TimeKeep.hpp"
# include "Core/InputParameterList.hpp"
# include "Core/InputParameter/Result.hpp"
namespace HappyHeart
{
/*!
* \brief Init the time keeper and write its logs in the output directory specified in \a input_parameter_data.
*
* This function is to be called early in your main if you want to time keep some information lines.
*
* IMPORTANT: Do not forget the return time in assignation in your main!
*
* \code
* auto time_keep_stream = InitTimeKeepLog(mpi, input_parameter_data); // Correct!
* InitTimeKeepLog(mpi, input_parameter_data); // Incorrect: the stream destructor will be called immediately...
* \endcode
*/
template<class InputParameterDataT>
std::ofstream InitTimeKeepLog(const Wrappers::Mpi& mpi,
const InputParameterDataT& input_parameter_data);
} // namespace HappyHeart
# include "Core/InitTimeKeepLog.hxx"
#endif /* defined(__HappyHeart__InitTimeKeepLog__HPP) */
//
// InitTimeKeepLog.hxx
// HappyHeart
//
// Created by Sebastien Gilles on 07/01/15.
// Copyright (c) 2015 Inria. All rights reserved.
//
#ifndef __HappyHeart__InitTimeKeepLog__HXX
#define __HappyHeart__InitTimeKeepLog__HXX
namespace HappyHeart
{
template<class InputParameterDataT>
std::ofstream InitTimeKeepLog(const Wrappers::Mpi& mpi,
const InputParameterDataT& input_parameter_data)
{
namespace IPL = Utilities::InputParameterListNS;
namespace Result = InputParameter::Result;
auto result_directory = IPL::ExtractValue<Result::OutputDirectory>::FolderValue(input_parameter_data);
std::string time_log_filename;
{
std::ostringstream oconv;
oconv << result_directory << "/time_log." << mpi.template Rank<int>() << ".txt";
time_log_filename = oconv.str();
}
std::ofstream log_time_elapsed(time_log_filename);
TimeKeep::CreateOrGetInstance(log_time_elapsed);
return log_time_elapsed;
}
} // namespace HappyHeart
#endif /* defined(__HappyHeart__InitTimeKeepLog__HXX) */
......@@ -3,6 +3,8 @@
#include "Utilities/TimeKeep/TimeKeep.hpp"
#include "Utilities/CommandLineOptions/CommandLineOptions.hpp"
#include "Core/InitTimeKeepLog.hpp"
#include "Problems/Elasticity/InputParameterList.hpp"
#include "Problems/Elasticity/ElasticityModel.hpp"
......@@ -12,35 +14,28 @@ using namespace HappyHeart;
int main(int argc, char ** argv)
{
Wrappers::Mpi::InitEnvironment(argc, argv);
Wrappers::Mpi::shared_ptr mpi_world_ptr =
std::make_shared<Wrappers::Mpi>(0, Wrappers::MpiNS::Comm::World); // must be called before Petsc RAII
std::string input_parameter_file =
Utilities::CommandLineOptions::InputParameterFileFromCommandLine(argc, argv, __FILE__, __LINE__);
std::string time_log_filename;
{
std::ostringstream oconv;
oconv << "/Volumes/Data/sebastien/HappyHeart/Results/Elasticity/TimeLogs/time_log."
<< mpi_world_ptr->Rank<int>() << ".txt";
time_log_filename = std::move(oconv.str());
}
std::ofstream log_time_elapsed(time_log_filename);
TimeKeep::CreateOrGetInstance(log_time_elapsed);
Wrappers::Petsc::Petsc raii_over_petsc(__FILE__, __LINE__);
try
{
Wrappers::Mpi::InitEnvironment(argc, argv);
Wrappers::Mpi::shared_ptr mpi_world_ptr =
std::make_shared<Wrappers::Mpi>(0, Wrappers::MpiNS::Comm::World); // must be called before Petsc RAII
std::string input_parameter_file =
Utilities::CommandLineOptions::InputParameterFileFromCommandLine(argc, argv, __FILE__, __LINE__);
Wrappers::Petsc::Petsc raii_over_petsc(__FILE__, __LINE__);
ElasticityNS::InputParameterList
input_parameter_data(input_parameter_file, mpi_world_ptr);
auto time_keep_stream = InitTimeKeepLog(*mpi_world_ptr,
input_parameter_data);
ElasticityNS::ElasticityModel model(mpi_world_ptr, input_parameter_data);
model.Run(input_parameter_data);
input_parameter_data.PrintUnused(std::cout);
input_parameter_data.PrintUnused(std::cout);
}
catch(const std::exception& e)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment