Commit 065efd4b authored by GILLES Sebastien's avatar GILLES Sebastien

#1480 Remove a bit of code that harmed hyperelastic case (and which was the...

#1480 Remove a bit of code that harmed hyperelastic case (and which was the reason anyway I took the time to introduce a proper Directory class).
parent 15d4c45d
......@@ -116,51 +116,4 @@ namespace MoReFEM::Internal::MoReFEMDataNS
}
void AskResultDirectoryRemoval(const std::string& directory, overwrite_directory do_overwrite_directory)
{
if (FilesystemNS::Folder::DoExist(directory))
{
switch (do_overwrite_directory)
{
case overwrite_directory::no:
{
std::string answer;
while (answer != "y" && answer != "n")
{
do
{
if (!std::cin)
{
std::cin.clear(); // clear the states of std::cin, putting it back to `goodbit`.
std::cin.ignore(10000, '\n'); // clean-up what might remain in std::cin before using it again.
}
std::cout << "Directory '" << directory << "' already exists. Do you want to remove it? "
"[y/n]" << std::endl;
std::cin >> answer;
} while (!std::cin);
}
if (answer == "n")
{
std::cout << "The program will therefore exit here." << std::endl;
throw ExceptionNS::GracefulExit(__FILE__, __LINE__);
}
break;
}
case overwrite_directory::yes:
{
std::cout << "Removing pre-existing directory " << directory << " before recreating it."
<< std::endl;
}
break;
}
FilesystemNS::Folder::Remove(directory, __FILE__, __LINE__);
}
}
} // namespace MoReFEM::Internal::MoReFEMDataNS
......@@ -121,15 +121,6 @@ namespace MoReFEM::Internal::MoReFEMDataNS
const std::string& input_data_file);
/*!
* \brief If \a directory already exists, ask the user whereas he wants to remove it or stop the program.
*
* \param[in] directory Directory which existence is checked.
* \param[in] do_overwrite_directory If 'yes', the former directory is removed silently.
*/
void AskResultDirectoryRemoval(const std::string& directory, overwrite_directory do_overwrite_directory);
} // namespace MoReFEM::Internal::MoReFEMDataNS
......
......@@ -69,10 +69,13 @@ namespace MoReFEM::Internal
* \brief Constructor.
*
* \copydoc doxygen_hide_input_data_arg
* \param[in] behaviour Behaviour to use when the subdirectory to create already exist. Irrelevant for policies
* that only read existing directories.
*/
template<class InputDataT>
explicit Parallelism(const ::MoReFEM::Wrappers::Mpi& mpi,
const InputDataT& input_data);
const InputDataT& input_data,
::MoReFEM::FilesystemNS::behaviour behaviour);
//! Destructor.
~Parallelism() = default;
......
......@@ -18,7 +18,8 @@ namespace MoReFEM::Internal
template<class InputDataT>
Parallelism::Parallelism(const ::MoReFEM::Wrappers::Mpi& mpi,
const InputDataT& input_data)
const InputDataT& input_data,
::MoReFEM::FilesystemNS::behaviour behaviour)
{
namespace ipl = Utilities::InputDataNS;
......@@ -50,7 +51,7 @@ namespace MoReFEM::Internal
directory_ = std::make_unique<FilesystemNS::Directory>(mpi,
path,
FilesystemNS::behaviour::ask,
behaviour,
__FILE__, __LINE__);
break;
......
......@@ -59,10 +59,7 @@ namespace MoReFEM
mpi,
DoTrackUnusedFieldsT);
// Parallelism is an optional field: it might not be present in the Lua file (for tests for instance it is not
// meaningful).
if constexpr (InputDataT::template Find<InputDataNS::Parallelism>())
parallelism_ = std::make_unique<Internal::Parallelism>(mpi, *input_data_);
namespace ipl = Utilities::InputDataNS;
using Result = InputDataNS::Result;
......@@ -85,39 +82,11 @@ namespace MoReFEM
path,
directory_behaviour,
__FILE__, __LINE__);
}
// We first deal with the data that are written only in the 'main' folder.
if (mpi.IsRootProcessor())
{
if constexpr(ProgramTypeT == program_type::model)
{
// Internal::MoReFEMDataNS::AskResultDirectoryRemoval(result_directory_, do_overwrite_directory);
if constexpr (InputDataT::template Find<InputDataNS::Parallelism>())
Internal::MoReFEMDataNS::AskResultDirectoryRemoval(GetParallelism().GetDirectory(),
do_overwrite_directory);
}
else if constexpr(ProgramTypeT == program_type::test)
{
// if (FilesystemNS::Folder::DoExist(result_directory_))
// {
// std::cout << "Removing pre-existing directory " << result_directory_ << " before "
// "recreating it." << std::endl;
// FilesystemNS::Folder::Remove(result_directory_, __FILE__, __LINE__);
// }
if constexpr (InputDataT::template Find<InputDataNS::Parallelism>())
{
const auto parallelism_directory = GetParallelism().GetDirectory();
if (FilesystemNS::Folder::DoExist(parallelism_directory))
{
std::cout << "Removing pre-existing directory " << parallelism_directory << " before "
"recreating it." << std::endl;
FilesystemNS::Folder::Remove(parallelism_directory, __FILE__, __LINE__);
}
}
}
// Parallelism is an optional field: it might not be present in the Lua file (for tests for instance it is not
// meaningful).
if constexpr (InputDataT::template Find<InputDataNS::Parallelism>())
parallelism_ = std::make_unique<Internal::Parallelism>(mpi, *input_data_, directory_behaviour);
}
mpi.Barrier();
......
......@@ -536,7 +536,7 @@ Parallelism = {
-- If Policy is 'RunFromPreprocessed', path to the directory which contains the pre-processed data.
-- Expected format: "VALUE"
directory = ''
directory = '${MOREFEM_RESULT_DIR}/MidpointHyperelasticity_Parallelism'
} -- Parallelism
......
......@@ -463,7 +463,7 @@ Parallelism = {
-- If Policy is 'RunFromPreprocessed', path to the directory which contains the pre-processed data.
-- Expected format: "VALUE"
directory = ''
directory = '${MOREFEM_RESULT_DIR}/MidpointHyperelasticity_Parallelism/${MOREFEM_START_TIME}'
} -- Parallelism
......
......@@ -24,7 +24,12 @@ int main(int argc, char** argv)
//! \copydoc doxygen_hide_model_specific_input_data
using InputData = MidpointHyperelasticityNS::InputData;
//TODO:
// - Solve the test failure
// - CHeck overwrite option
// - Check ask in parallel
try
{
MoReFEMData<InputData, program_type::model> morefem_data(argc, argv);
......
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