Commit b14957fb authored by GILLES Sebastien's avatar GILLES Sebastien

#1315 I have added with the writing of a Lua file the possibility to...

#1315 I have added with the writing of a Lua file the possibility to rejuvenate a Lua file and make sure its comments are up-to-date. It remains to be propagated to all the Lua files.
parent 7bc0ddd6
......@@ -1468,6 +1468,8 @@
BECEF92D22DF5D5E00D0DDE7 /* Now.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BECEF92A22DF5D5E00D0DDE7 /* Now.hpp */; };
BECF3E2122E8A39F00FF951A /* LuaFormat.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BECF3E1E22E8A39E00FF951A /* LuaFormat.hpp */; };
BECF3E2222E8A39F00FF951A /* LuaFormat.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BECF3E1F22E8A39F00FF951A /* LuaFormat.hxx */; };
BECF3E4222E98DDB00FF951A /* RewriteInputDataFile.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BECF3E3F22E98DDB00FF951A /* RewriteInputDataFile.hxx */; };
BECF3E4322E98DDB00FF951A /* RewriteInputDataFile.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BECF3E4022E98DDB00FF951A /* RewriteInputDataFile.hpp */; };
BED13353206519C800A3B0AA /* Penalization.hxx in Headers */ = {isa = PBXBuildFile; fileRef = BED13351206519C700A3B0AA /* Penalization.hxx */; };
BED13354206519C800A3B0AA /* Penalization.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BED13352206519C800A3B0AA /* Penalization.hpp */; };
BED793B11D1AD75900492784 /* HyperelasticLaw.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BED793AE1D1AD75900492784 /* HyperelasticLaw.hpp */; };
......@@ -4662,6 +4664,9 @@
BECEF93522DF7B0200D0DDE7 /* demo_result_directory_start_time.lua */ = {isa = PBXFileReference; lastKnownFileType = text; path = demo_result_directory_start_time.lua; sourceTree = "<group>"; };
BECF3E1E22E8A39E00FF951A /* LuaFormat.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LuaFormat.hpp; sourceTree = "<group>"; };
BECF3E1F22E8A39F00FF951A /* LuaFormat.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LuaFormat.hxx; sourceTree = "<group>"; };
BECF3E3022E8D3A400FF951A /* main_update_lua_file.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main_update_lua_file.cpp; sourceTree = "<group>"; };
BECF3E3F22E98DDB00FF951A /* RewriteInputDataFile.hxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = RewriteInputDataFile.hxx; sourceTree = "<group>"; };
BECF3E4022E98DDB00FF951A /* RewriteInputDataFile.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = RewriteInputDataFile.hpp; sourceTree = "<group>"; };
BED13351206519C700A3B0AA /* Penalization.hxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Penalization.hxx; sourceTree = "<group>"; };
BED13352206519C800A3B0AA /* Penalization.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Penalization.hpp; sourceTree = "<group>"; };
BED748E41906734200BAB761 /* main_test_ondomatic_numbering.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main_test_ondomatic_numbering.cpp; sourceTree = "<group>"; };
......@@ -8238,6 +8243,7 @@
BE7ABCE822DCDF0100238C51 /* demo_3d_binary.lua */,
BE7ABCE922DCDF0100238C51 /* demo_2d_binary.lua */,
BE4478861AA740F800665010 /* main.cpp */,
BECF3E3022E8D3A400FF951A /* main_update_lua_file.cpp */,
BE3B35FB1D91792500DB81A3 /* main_ensight_output.cpp */,
BE8E21C8207E9D3000E24E6D /* test_results.cpp */,
BE63B4951A31C20E003A6523 /* InputData.hpp */,
......@@ -9272,6 +9278,8 @@
BEA355D717D0971500FB643B /* LuaFunction.hxx */,
BE353B9822E7527100A06A8F /* Extract.hpp */,
BE353B9722E7527100A06A8F /* Extract.hxx */,
BECF3E4022E98DDB00FF951A /* RewriteInputDataFile.hpp */,
BECF3E3F22E98DDB00FF951A /* RewriteInputDataFile.hxx */,
BE768EBB1B835FFA009B24CB /* Crtp */,
BEB6424B17CF7A08001CEE44 /* Exceptions */,
BE53FC081E0D797500C5D6F5 /* Internal */,
......@@ -11377,6 +11385,7 @@
BE145A0D1E54BC49000A2BF5 /* UnlabeledValueArg.h in Headers */,
BE53FC261E0D81A000C5D6F5 /* Traits.hpp in Headers */,
BE145A071E54BC49000A2BF5 /* MultiSwitchArg.h in Headers */,
BECF3E4322E98DDB00FF951A /* RewriteInputDataFile.hpp in Headers */,
BE90E1D11A2492AA00CCAFDE /* PetscViewer.hpp in Headers */,
BE90E19F1A24929A00CCAFDE /* Op.hpp in Headers */,
BE90E1951A24929A00CCAFDE /* TimeKeep.hpp in Headers */,
......@@ -11469,6 +11478,7 @@
132BD2741C72136D008DDEE7 /* Solver.hpp in Headers */,
BE1798141E316640004326D2 /* Traits.hpp in Headers */,
BE90E1731A24926E00CCAFDE /* String.hxx in Headers */,
BECF3E4222E98DDB00FF951A /* RewriteInputDataFile.hxx in Headers */,
BE145A111E54BC49000A2BF5 /* Visitor.h in Headers */,
BE9512901A8CC3E5009E0082 /* Mutex.hpp in Headers */,
BECDB4BA22C21749009BA8E2 /* PrintTypeName.hxx in Headers */,
......@@ -26,6 +26,11 @@ apply_lto_if_supported(MoReFEM4Elasticity)
morefem_install(MoReFEM4Elasticity MoReFEM4Elasticity_lib)
add_executable(MoReFEM4ElasticityUpdateLuaFile ${CMAKE_CURRENT_LIST_DIR}/main_update_lua_file.cpp)
target_link_libraries(MoReFEM4ElasticityUpdateLuaFile
${MOREFEM_CORE})
add_executable(MoReFEM4ElasticityEnsightOutput ${CMAKE_CURRENT_LIST_DIR}/main_ensight_output.cpp)
target_link_libraries(MoReFEM4ElasticityEnsightOutput
${MOREFEM_POST_PROCESSING})
......
......@@ -25,7 +25,7 @@ int main(int argc, char** argv)
{
//! \copydoc doxygen_hide_model_specific_input_data
using InputData = ElasticityNS::InputData;
using InputData = ElasticityNS::InputData;
try
{
......
//! \file
//
//
// main_update_lua_file.cpp
// MoReFEM
//
// Created by sebastien on 24/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#include "Utilities/Exceptions/PrintAndAbort.hpp"
#include "Utilities/InputData/RewriteInputDataFile.hpp"
#include "Core/MoReFEMData/MoReFEMData.hpp"
#include "ModelInstances/Elasticity/InputData.hpp"
using namespace MoReFEM;
int main(int argc, char** argv)
{
using InputData = ElasticityNS::InputData;
try
{
MoReFEMData<InputData> morefem_data(argc, argv);
RewriteInputDataFile(morefem_data.GetInputData());
}
catch(const std::exception& e)
{
std::ostringstream oconv;
oconv << "Exception caught: " << e.what() << std::endl;
std::cout << oconv.str();
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -26,7 +26,7 @@ int main(int argc, char** argv)
{
//! \copydoc doxygen_hide_model_specific_input_data
using InputData = LightweightDomainListNS::InputData;
using InputData = LightweightDomainListNS::InputData;
try
......
......@@ -330,6 +330,21 @@ namespace MoReFEM
void CreateDefaultInputFile(const std::string& path);
/*!
* \brief Write in a file the content of \a input_data.
*
* \tparam InputDataT The object which holds the information about input data file content.
*
* \param[in] target Path to the file into which the data will be written in the proper format (so it might
* be reused as input for a MoReFEM model). The file must not exist yet but the directory in which it is
* located must already exist.
* \param[in] input_data The data to be written in the file.
*/
template<class InputData>
void Write(const InputData& input_data,
const std::string& target);
} // namespace InputDataNS
......
......@@ -96,7 +96,7 @@ namespace MoReFEM::Utilities::InputDataNS
* \brief Read the number of elements when the object is a vector.
*
* If not a vector, a compilation error will occur as size() method won't be defined.
* \param[in] input_data Object which hols all relevant input data for the model considered.
* \param[in] input_data Object which holds all relevant input data for the model considered.
*
*
* \return Number of elements hold by \a ObjectT.
......
......@@ -19,6 +19,7 @@
# include "Utilities/Miscellaneous.hpp"
# include "Utilities/Containers/Print.hpp"
# include "Utilities/Containers/PrintPolicy/Associative.hpp"
# include "Utilities/Type/PrintTypeName.hpp"
namespace MoReFEM::Internal::PrintPolicyNS
......
......@@ -63,8 +63,13 @@ namespace MoReFEM::Internal::PrintPolicyNS
::MoReFEM::Utilities::PrintPolicyNS::Associative<Utilities::PrintPolicyNS::associative_format::Lua>;
Utilities::PrintContainer<policy>::Do(entry, stream, ", ", '{', '}');
}
else if constexpr (std::is_same<std::nullptr_t, type>()) // might happen: the 'ignore' parameters proceed that way
{
stream << 0;
}
else
{
std::cerr << "Type not handled: " << ::MoReFEM::GetTypeName<type>() << std::endl;
assert(false && "Case not foreseen...");
exit(EXIT_FAILURE);
}
......
//! \file
//
//
// RewriteInputDataFile.hpp
// MoReFEM
//
// Created by sebastien on 25/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_INPUT_DATA_x_REWRITE_INPUT_DATA_FILE_HPP_
# define MOREFEM_x_UTILITIES_x_INPUT_DATA_x_REWRITE_INPUT_DATA_FILE_HPP_
# include <iostream>
# include "Utilities/Filesystem/File.hpp"
# include "Utilities/InputData/Base.hpp"
# include "Utilities/Exceptions/Exception.hpp"
namespace MoReFEM
{
/*!
* \brief Rewrite the input data file that was used to load the input data in the first place.
*
* Doing so might be useful to make sure the comments are up-to-date: if the documentation of the fields has changed
* you will get the latest version this way. It will also trim fields that were in fact not used in the model.
*
* \copydoc
*/
template<class InputDataT>
void RewriteInputDataFile(const InputDataT& input_data);
} // namespace MoReFEM
# include "Utilities/InputData/RewriteInputDataFile.hxx"
#endif // MOREFEM_x_UTILITIES_x_INPUT_DATA_x_REWRITE_INPUT_DATA_FILE_HPP_
//! \file
//
//
// RewriteInputDataFile.hxx
// MoReFEM
//
// Created by sebastien on 25/07/2019.
//Copyright © 2019 Inria. All rights reserved.
//
#ifndef MOREFEM_x_UTILITIES_x_INPUT_DATA_x_REWRITE_INPUT_DATA_FILE_HXX_
# define MOREFEM_x_UTILITIES_x_INPUT_DATA_x_REWRITE_INPUT_DATA_FILE_HXX_
namespace MoReFEM
{
template<class InputDataT>
void RewriteInputDataFile(const InputDataT& input_data)
{
decltype(auto) original_file = input_data.GetInputFile();
decltype(auto) backup_file = original_file + ".bak";
FilesystemNS::File::Copy(original_file,
backup_file,
FilesystemNS::File::fail_if_already_exist::no,
FilesystemNS::File::autocopy::no,
__FILE__, __LINE__);
try
{
FilesystemNS::File::Remove(original_file, __FILE__, __LINE__);
Utilities::InputDataNS::Write(input_data, original_file);
}
catch(const Exception& e)
{
std::cerr << "Exception caught: " << e.what() << std::endl;
std::cerr << "File " << original_file << " will be put back in its original state and exception will be"
" thrown again." << std::endl;
FilesystemNS::File::Copy(backup_file,
original_file,
FilesystemNS::File::fail_if_already_exist::no,
FilesystemNS::File::autocopy::no,
__FILE__, __LINE__);
throw;
}
std::cout << "File " << original_file << " has been updated; a copy of the former version has been made "
"(with an additional .bak extension). Please review it before validating it! " << std::endl;
std::cout << "It is possible that some fields have disappeared: if there was in the data file a field which "
"was not considered at all (i.e. had no match in the InputData tuple) they were in fact unused and were "
"dropped here." << std::endl;
}
} // namespace MoReFEM
#endif // MOREFEM_x_UTILITIES_x_INPUT_DATA_x_REWRITE_INPUT_DATA_FILE_HXX_
......@@ -20,6 +20,8 @@ target_sources(${MOREFEM_UTILITIES}
"${CMAKE_CURRENT_LIST_DIR}/Extract.hxx"
"${CMAKE_CURRENT_LIST_DIR}/LuaFunction.hpp"
"${CMAKE_CURRENT_LIST_DIR}/LuaFunction.hxx"
"${CMAKE_CURRENT_LIST_DIR}/RewriteInputDataFile.hpp"
"${CMAKE_CURRENT_LIST_DIR}/RewriteInputDataFile.hxx"
)
include(${CMAKE_CURRENT_LIST_DIR}/Crtp/SourceList.cmake)
......
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