Commit 9e58e61e authored by GILLES Sebastien's avatar GILLES Sebastien

#1480 Many replacements of previous directories by the new object. Doesn't...

#1480 Many replacements of previous directories by the new object. Doesn't quite work currently however (wildcard are not handled properly).
parent 03a7e1cf
......@@ -19,6 +19,28 @@
# include "Core/MoReFEMData/Advanced/ParallelismStrategy.hpp"
// ============================
//! \cond IGNORE_BLOCK_IN_DOXYGEN
// Forward declarations.
// ============================
namespace MoReFEM::Wrappers
{
class Mpi;
} // namespace MoReFEM::Wrappers
// ============================
// End of forward declarations.
//! \endcond IGNORE_BLOCK_IN_DOXYGEN
// ============================
namespace MoReFEM::Internal
{
......@@ -49,7 +71,8 @@ namespace MoReFEM::Internal
* \copydoc doxygen_hide_input_data_arg
*/
template<class InputDataT>
explicit Parallelism(const InputDataT& input_data);
explicit Parallelism(const ::MoReFEM::Wrappers::Mpi& mpi,
const InputDataT& input_data);
//! Destructor.
~Parallelism() = default;
......@@ -69,7 +92,7 @@ namespace MoReFEM::Internal
///@}
//! Get the path of the parallelism directory.
const std::string& GetDirectory() const noexcept;
const FilesystemNS::Directory& GetDirectory() const noexcept;
//! Get the parallelism strategy.
::MoReFEM::Advanced::parallelism_strategy GetParallelismStrategy() const noexcept;
......@@ -81,7 +104,7 @@ namespace MoReFEM::Internal
::MoReFEM::Advanced::parallelism_strategy::none;
//! Path to the parallelism directory.
std::string directory_ = "";
FilesystemNS::Directory::const_unique_ptr directory_ = nullptr;
};
......
......@@ -17,7 +17,8 @@ namespace MoReFEM::Internal
template<class InputDataT>
Parallelism::Parallelism(const InputDataT& input_data)
Parallelism::Parallelism(const ::MoReFEM::Wrappers::Mpi& mpi,
const InputDataT& input_data)
{
namespace ipl = Utilities::InputDataNS;
......@@ -45,24 +46,39 @@ namespace MoReFEM::Internal
case ::MoReFEM::Advanced::parallelism_strategy::parallel:
{
using directory = ::MoReFEM::InputDataNS::Parallelism::Directory;
directory_ = ipl::Extract<directory>::Path(input_data);
std::string path = ipl::Extract<directory>::Path(input_data);
directory_ = std::make_unique<FilesystemNS::Directory>(mpi,
path,
FilesystemNS::behaviour::ask,
__FILE__, __LINE__);
break;
}
case ::MoReFEM::Advanced::parallelism_strategy::parallel_no_write:
break;
case ::MoReFEM::Advanced::parallelism_strategy::run_from_preprocessed:
directory_ = ipl::Extract<Parallelism::Directory>::Folder(input_data);
{
using directory = ::MoReFEM::InputDataNS::Parallelism::Directory;
std::string path = ipl::Extract<directory>::Path(input_data);
directory_ = std::make_unique<FilesystemNS::Directory>(mpi,
path,
FilesystemNS::behaviour::read,
__FILE__, __LINE__);
break;
}
case ::MoReFEM::Advanced::parallelism_strategy::none:
break;
}
}
inline const std::string& Parallelism::GetDirectory() const noexcept
inline const FilesystemNS::Directory& Parallelism::GetDirectory() const noexcept
{
assert(!directory_.empty());
return directory_;
assert(!(!directory_));
return *directory_;
}
......
......@@ -62,7 +62,7 @@ namespace MoReFEM
// 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>(*input_data_);
parallelism_ = std::make_unique<Internal::Parallelism>(mpi, *input_data_);
namespace ipl = Utilities::InputDataNS;
using Result = InputDataNS::Result;
......
......@@ -82,7 +82,7 @@ namespace MoReFEM
}
void GodOfDof::Init1(std::string&& output_directory,
void GodOfDof::Init1(const FilesystemNS::Directory& output_directory,
FEltSpace::vector_unique_ptr&& a_felt_space_list,
std::map<unsigned int, std::vector<unsigned int>>& dof_list_per_felt_space)
{
......@@ -889,14 +889,12 @@ namespace MoReFEM
case Advanced::parallelism_strategy::precompute:
{
const auto parallelism_directory = parallelism.GetDirectory() +
"/Rank_" + std::to_string(mpi.GetRank<int>()) +
"/Mesh_" + std::to_string(mesh.GetUniqueId());
FilesystemNS::Folder::Create(parallelism_directory, __FILE__, __LINE__);
FilesystemNS::Directory mesh_subdir(parallelism.GetDirectory(),
"Mesh_" + std::to_string(mesh.GetUniqueId()),
__FILE__, __LINE__);
Advanced::MeshNS::WritePrepartitionedData partition_data_facility(mesh,
parallelism_directory,
mesh_subdir,
mesh.GetInitialFormat());
break;
......
......@@ -158,7 +158,7 @@ namespace MoReFEM
void Init(const MoReFEMDataT& morefem_data,
FEltSpace::vector_unique_ptr&& felt_space_list,
DoConsiderProcessorWiseLocal2Global do_consider_processor_wise_local_2_global,
std::string&& output_directory);
const FilesystemNS::Directory& output_directory);
//! Get the mesh object.
......@@ -510,7 +510,7 @@ namespace MoReFEM
* \param[in] output_directory Output directory for data specific to the mesh covered by the \a GodOfDof.
*
*/
void Init1(std::string&& output_directory,
void Init1(const FilesystemNS::Directory& output_directory,
FEltSpace::vector_unique_ptr&& felt_space_list,
std::map<unsigned int, std::vector<unsigned int>>& dof_list_per_felt_space);
......
......@@ -25,13 +25,13 @@ namespace MoReFEM
void GodOfDof::Init(const MoReFEMDataT& morefem_data,
FEltSpace::vector_unique_ptr&& a_felt_space_list,
DoConsiderProcessorWiseLocal2Global do_consider_proc_wise_local_2_global,
std::string&& output_directory)
const FilesystemNS::Directory& output_directory)
{
parallelism_ = morefem_data.GetParallelismPtr();
std::map<unsigned int, std::vector<unsigned int>> dof_list_per_felt_space;
Init1(std::move(output_directory),
Init1(output_directory,
std::move(a_felt_space_list),
dof_list_per_felt_space);
......
......@@ -157,10 +157,14 @@ namespace MoReFEM
}
void WriteInterfaceListForEachMesh(const std::map<unsigned int, std::string>& mesh_output_directory_storage)
void WriteInterfaceListForEachMesh(const std::map<unsigned int, ::MoReFEM::FilesystemNS::Directory::const_unique_ptr>&
mesh_output_directory_storage)
{
for (const auto& pair : mesh_output_directory_storage)
{
WriteInterfaceList(pair);
}
}
......
......@@ -18,6 +18,7 @@
# include <set>
# include "Utilities/Singleton/Singleton.hpp"
# include "Utilities/Filesystem/Directory.hpp"
# include "Core/InputData/Instances/Geometry/Mesh.hpp"
......@@ -248,7 +249,8 @@ namespace MoReFEM
* \param[in] mesh_output_directory_storage Key is the unique id of the meshes, value the path to the
* associated output directory, which should already exist.
*/
void WriteInterfaceListForEachMesh(const std::map<unsigned int, std::string>& mesh_output_directory_storage);
void WriteInterfaceListForEachMesh(const std::map<unsigned int, ::MoReFEM::FilesystemNS::Directory::const_unique_ptr>&
mesh_output_directory_storage);
} // namespace MeshNS
......
......@@ -753,19 +753,21 @@ namespace MoReFEM
}
void WriteInterfaceList(const std::pair<unsigned int, std::string>& mesh_infos)
void WriteInterfaceList(const std::pair<const unsigned int, FilesystemNS::Directory::const_unique_ptr>& mesh_infos)
{
std::ofstream out;
decltype(auto) mesh_output_directory = mesh_infos.second;
assert(FilesystemNS::Folder::DoExist(mesh_output_directory) && "Assert because it should be guaranteed by Model");
std::string filename = mesh_output_directory + "/interfaces.hhdata";
const auto& mesh_output_directory_ptr = mesh_infos.second;
assert(!(!mesh_output_directory_ptr));
const auto& mesh_output_directory = *mesh_output_directory_ptr;
std::string filename = mesh_output_directory.AddFile("interfaces.hhdata");
decltype(auto) mesh =
Internal::MeshNS::MeshManager::GetInstance(__FILE__, __LINE__).GetMesh(mesh_infos.first);
FilesystemNS::File::Create(out, filename, __FILE__, __LINE__);
Internal::MeshNS::ComputeInterfaceListInMesh mesh_interface_list(mesh);
......
......@@ -23,6 +23,7 @@
# include "Utilities/UniqueId/UniqueId.hpp"
# include "Utilities/Mpi/Mpi.hpp"
# include "Utilities/Filesystem/Directory.hpp"
# include "ThirdParty/IncludeWithoutWarning/Seldon/Seldon.hpp"
# include "ThirdParty/IncludeWithoutWarning/Petsc/PetscSys.hpp"
......@@ -860,7 +861,7 @@ namespace MoReFEM
*
* A 'interfaces.hhdata' file will be written inside this output directory.
*/
void WriteInterfaceList(const std::pair<unsigned int, std::string>& mesh);
void WriteInterfaceList(const std::pair<const unsigned int, FilesystemNS::Directory::const_unique_ptr>& mesh);
/*!
......
......@@ -48,7 +48,7 @@ namespace MoReFEM
template<class MoReDEMDataT>
void InitGodOfDof(const MoReDEMDataT& morefem_data,
DoConsiderProcessorWiseLocal2Global do_consider_processor_wise_local_2_global,
std::map<unsigned int, std::string>&& output_directory_per_mesh_index);
std::map<unsigned int, FilesystemNS::Directory::const_unique_ptr>&& output_directory_per_mesh_index);
......
......@@ -32,7 +32,7 @@ namespace MoReFEM
void InitEachGodOfDof(const MoReDEMDataT& morefem_data,
std::map<unsigned int, FEltSpace::vector_unique_ptr>& felt_space_list_per_god_of_dof_index,
DoConsiderProcessorWiseLocal2Global do_consider_proc_wise_local_2_global,
std::map<unsigned int, std::string>&& mesh_output_directory_storage)
std::map<unsigned int, FilesystemNS::Directory::const_unique_ptr>&& mesh_output_directory_storage)
{
const auto& god_of_dof_storage = GodOfDofManager::GetInstance(__FILE__, __LINE__).GetStorage();
......@@ -52,11 +52,12 @@ namespace MoReFEM
auto it_output_dir = mesh_output_directory_storage.find(god_of_dof.GetUniqueId());
assert(it_output_dir != mesh_output_directory_storage.cend());
assert(it_output_dir->second != nullptr);
god_of_dof.Init(morefem_data,
std::move(it->second),
do_consider_proc_wise_local_2_global,
std::move(it_output_dir->second));
*(it_output_dir->second));
}
}
......@@ -64,7 +65,7 @@ namespace MoReFEM
template<class MoReDEMDataT>
void InitGodOfDof(const MoReDEMDataT& morefem_data,
DoConsiderProcessorWiseLocal2Global do_consider_proc_wise_local_2_global,
std::map<unsigned int, std::string>&& mesh_output_directory_storage)
std::map<unsigned int, FilesystemNS::Directory::const_unique_ptr>&& mesh_output_directory_storage)
{
std::map<unsigned int, FEltSpace::vector_unique_ptr> felt_space_list_per_god_of_dof_index;
......
......@@ -239,7 +239,7 @@ namespace MoReFEM
* \brief Access to output directory.
*
*/
const std::string& GetOutputDirectory() const noexcept;
const FilesystemNS::Directory& GetOutputDirectory() const noexcept;
//! Setter on do_print_new_time_iteration_banner_.
//! \param[in] do_print True if you want to print the banner.
......@@ -294,14 +294,11 @@ namespace MoReFEM
* \param[in] do_create_output_dir Whether the output directory should be created (if it does already exist,
* the old one is removed and a new one is created).
* Should be 'yes' for model executables, but might be run for Post processing ones.
* \tparam MpiScaleT If MpiScale::processor-wise, return the subdirectory which also specifies the rank (or
* the result directory directly if the model is run sequentially). If MpiScale::program_wise, returns the
* result directory. The latter is expected to be used mostly on the root processor.
*
* \return Key is the unique id of the mesh, value the path to it.
*/
template<MpiScale MpiScaleT>
std::map<unsigned int, std::string> CreateMeshDataDirectory(create_output_dir do_create_output_dir) const;
std::map<unsigned int, FilesystemNS::Directory::const_unique_ptr>
CreateMeshDataDirectory(create_output_dir do_create_output_dir) const;
//! Constant accessor to create_domain_list_for_coords_.
create_domain_list_for_coords GetCreateDomainListForCoords() const noexcept;
......
......@@ -141,7 +141,7 @@ namespace MoReFEM
{
Wrappers::Petsc::PrintMessageOnFirstProcessor("\nIf no exception, all results have been printed in %s.\n",
mpi, __FILE__, __LINE__,
GetOutputDirectory().c_str());
GetOutputDirectory().GetPath().c_str());
Wrappers::Petsc::PrintMessageOnFirstProcessor("\n==============================================================\n",
mpi, __FILE__, __LINE__);
......@@ -212,7 +212,7 @@ namespace MoReFEM
if (is_root_processor)
{
auto mesh_directory_storage = CreateMeshDataDirectory<MpiScale::program_wise>(do_create_output_dir);
auto mesh_directory_storage = CreateMeshDataDirectory(do_create_output_dir);
Internal::MeshNS::WriteInterfaceListForEachMesh(mesh_directory_storage);
}
......@@ -261,7 +261,7 @@ namespace MoReFEM
Internal::ModelNS::InitGodOfDof(morefem_data,
DoConsiderProcessorWiseLocal2GlobalT,
CreateMeshDataDirectory<MpiScale::processor_wise>(do_create_output_dir));
CreateMeshDataDirectory(do_create_output_dir));
// As FiberListManager gets a constructor with arguments, call it explicitly there.
decltype(auto) time_manager = GetTimeManager();
......@@ -482,7 +482,7 @@ namespace MoReFEM
DoConsiderProcessorWiseLocal2Global DoConsiderProcessorWiseLocal2GlobalT,
class TimeManagerPolicyT
>
const std::string& Model<DerivedT, MoReFEMDataT, DoConsiderProcessorWiseLocal2GlobalT, TimeManagerPolicyT>
const FilesystemNS::Directory& Model<DerivedT, MoReFEMDataT, DoConsiderProcessorWiseLocal2GlobalT, TimeManagerPolicyT>
::GetOutputDirectory() const noexcept
{
return GetMoReFEMData().GetResultDirectory();
......@@ -551,11 +551,11 @@ namespace MoReFEM
DoConsiderProcessorWiseLocal2Global DoConsiderProcessorWiseLocal2GlobalT,
class TimeManagerPolicyT
>
template<MpiScale MpiScaleT>
std::map<unsigned int, std::string> Model<DerivedT, MoReFEMDataT, DoConsiderProcessorWiseLocal2GlobalT, TimeManagerPolicyT>
std::map<unsigned int, FilesystemNS::Directory::const_unique_ptr>
Model<DerivedT, MoReFEMDataT, DoConsiderProcessorWiseLocal2GlobalT, TimeManagerPolicyT>
::CreateMeshDataDirectory(create_output_dir do_create_output_dir) const
{
std::map<unsigned int, std::string> ret;
std::map<unsigned int, FilesystemNS::Directory::const_unique_ptr> ret;
decltype(auto) mesh_manager = Internal::MeshNS::MeshManager::GetInstance(__FILE__, __LINE__);
......@@ -563,19 +563,12 @@ namespace MoReFEM
decltype(auto) output_dir = GetOutputDirectory();
for (const auto mesh_id : mesh_id_list)
ret.insert({ mesh_id, output_dir + "/Mesh_" + std::to_string(mesh_id)});
if (do_create_output_dir == create_output_dir::yes)
{
for (const auto& pair : ret)
{
const auto& mesh_directory = pair.second;
auto new_subdir = std::make_unique<FilesystemNS::Directory>(output_dir,
"Mesh_" + std::to_string(mesh_id),
__FILE__, __LINE__);
if (FilesystemNS::Folder::DoExist(mesh_directory))
FilesystemNS::Folder::Remove(mesh_directory, __FILE__, __LINE__);
FilesystemNS::Folder::Create(mesh_directory, __FILE__, __LINE__);
}
ret.insert({ mesh_id, std::move(new_subdir)});
}
return ret;
......
......@@ -46,7 +46,7 @@ namespace MoReFEM
decltype(auto) fluid_god_of_dof = god_of_dof_manager.GetGodOfDof(EnumUnderlyingType(MeshIndex::fluid));
using namespace TestNS::FromVertexMatchingNS;
PostProcessingNS::PostProcessing fluid_post_processing(model.GetOutputDirectory(),
{ EnumUnderlyingType(NumberingSubsetIndex::unknown_on_fluid) },
fluid_god_of_dof.GetMesh());
......
......@@ -30,7 +30,7 @@ namespace MoReFEM
{
using type = NonConformInterpolatorNS::FromVertexMatching;
decltype(auto) morefem_data = parent::GetMoReFEMData();
unknown_solid_2_fluid_ =
std::make_unique<type>(morefem_data.GetInputData(),
EnumUnderlyingType(InitVertexMatchingInterpolator::unknown_on_solid),
......
......@@ -232,23 +232,6 @@ namespace MoReFEM
unsigned int ReadHelperNumber() const;
/*!
* \brief Helper function used to handle a folder path: in case it doesn't exist, it can be
* created or an exception might be thrown (depending on the policy chosen).
*
* \return The requested element in the tuple. This string is afterwards interpreted as a folder;
* \a UnexistentFolderPolicyT policy tells what to do when the folder doesn't exist.
*
*/
template
<
class InputDataT,
UnexistentFolderPolicy UnexistentFolderPolicyT = UnexistentFolderPolicy::create
>
std::string ReadHelperFolder() const;
/*!
* \brief Helper function used to handle a path: it is basically handled as a mere string, except
* that environment variables are replaced on the fly if they respect the format ${...}.
......@@ -257,8 +240,6 @@ namespace MoReFEM
* parameter is), this method might modify the value stored in the tuple. On first call all environment
* variables are replaced, and what is stored afterwards is the result after the substitution.
*
* A specialized version for folder also exist (ReadHelperFolder()).
*
* For instance "${HOME}/Codes/MoReFEM" will be resolved on a Mac in /Users/ *username* /Codes/MoReFEM.
*
* \return The requested element in the tuple.
......
......@@ -119,54 +119,6 @@ namespace MoReFEM
}
template<class DerivedT, class TupleT>
template<class InputDataT, UnexistentFolderPolicy UnexistentFolderPolicyT>
std::string Base<DerivedT, TupleT>::ReadHelperFolder() const
{
std::string folder_name = ReadHelperPath<InputDataT>();
if (folder_name.empty())
{
std::ostringstream oconv;
oconv << "The directory given in field '" << InputDataT::GetIdentifier() << "' is an empty "
"string!";
throw Exception(oconv.str(), __FILE__, __LINE__);
}
if (!FilesystemNS::Folder::DoExist(folder_name))
{
switch(UnexistentFolderPolicyT)
{
case UnexistentFolderPolicy::create:
{
try
{
FilesystemNS::Folder::Create(folder_name, __FILE__, __LINE__);
}
catch(const Exception& )
{
// In parallel, when several ranks share the same filesystem, creation might fail
// due to the folder already existing (because created by another rank since the
// existence test failure above). So if we test it again here and find it already
// exists, we can safely dismiss the exception.
if (!FilesystemNS::Folder::DoExist(folder_name))
throw;
}
break;
}
case UnexistentFolderPolicy::throw_exception:
{
throw ExceptionNS::FolderDoesntExist(folder_name, __FILE__, __LINE__);
}
}
}
return folder_name;
}
template<class DerivedT, class TupleT>
template<class InputDataT>
std::string Base<DerivedT, TupleT>::ReadHelperPath() const
......
......@@ -67,15 +67,6 @@ namespace MoReFEM::Utilities::InputDataNS
};
//! Behaviour when the folder read in the input data file doesn't exist.
enum class UnexistentFolderPolicy
{
create,
throw_exception
};
} // namespace MoReFEM::Utilities::InputDataNS
......
......@@ -80,18 +80,6 @@ namespace MoReFEM::Utilities::InputDataNS
static std::string Path(const InputDataT& input_data);
/*!
* \brief Return a string that stands for a folder; several operations might be attempted if said folder
* doesn't exist.
*
* \param[in] input_data Object which holds all relevant input data for the model considered.
*
* \return Path to the folder hold by \a ObjectT.
*/
template<class InputDataT, UnexistentFolderPolicy UnexistentFolderPolicyT = UnexistentFolderPolicy::create>
static std::string Folder(const InputDataT& input_data);
/*!
* \brief Read the number of elements when the object is a vector.
*
......
......@@ -33,15 +33,6 @@ namespace MoReFEM::Utilities::InputDataNS
}
template<class ObjectT>
template<class InputDataT, UnexistentFolderPolicy UnexistentFolderPolicyT>
std::string Extract<ObjectT>
::Folder(const InputDataT& input_data)
{
return input_data.template ReadHelperFolder<ObjectT, UnexistentFolderPolicyT>();
}
template<class ObjectT>
template<class InputDataT>
unsigned int Extract<ObjectT>::Number(const InputDataT& input_data)
......
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