Commit 088896bc authored by GILLES Sebastien's avatar GILLES Sebastien

#1458 GodOfDof: avoid creating needless strings in GetOutputDirectoryForNumberingSubset() method.

parent 217807cb
......@@ -97,7 +97,9 @@ namespace MoReFEM
const auto& felt_space_list = GetFEltSpaceList();
ComputeNumberingSubsetList();
SetOutputDirectoryPerNumberingSubset();
const auto& mpi = GetMpi();
const auto rank = mpi.GetRank<unsigned int>();
......@@ -882,26 +884,18 @@ namespace MoReFEM
}
std::string GodOfDof::GetOutputDirectoryForNumberingSubset(const NumberingSubset& numbering_subset) const
const std::string& GodOfDof::GetOutputDirectoryForNumberingSubset(const NumberingSubset& numbering_subset) const
{
#ifndef NDEBUG
{
decltype(auto) numbering_subset_list = GetNumberingSubsetList();
const auto numbering_subset_id = numbering_subset.GetUniqueId();
const auto end = numbering_subset_list.cend();
assert(std::find_if(numbering_subset_list.cbegin(),
end,
[numbering_subset_id](const auto& test)
{
assert(!(!test));
return test->GetUniqueId() == numbering_subset_id;
}) != end);
}
#endif // NDEBUG
std::string ret(GetOutputDirectory());
ret += "/NumberingSubset_" + std::to_string(numbering_subset.GetUniqueId());
return ret;
const auto id = numbering_subset.GetUniqueId();
decltype(auto) output_directory_per_numbering_subset = GetOutputDirectoryPerNumberingSubset();
const auto it = output_directory_per_numbering_subset.find(id);
assert(it != output_directory_per_numbering_subset.cend() &&
"All relevant numbering subsets should have been loaded into the map.");
return it->second;
}
......@@ -1312,6 +1306,31 @@ namespace MoReFEM
}
void GodOfDof::SetOutputDirectoryPerNumberingSubset()
{
decltype(auto) numbering_subset_list = GetNumberingSubsetList();
std::ostringstream oconv;
output_directory_per_numbering_subset_.max_load_factor(Utilities::DefaultMaxLoadFactor());
for (const auto& numbering_subset_ptr : numbering_subset_list)
{
assert(!(!numbering_subset_ptr));
const auto& numbering_subset = *numbering_subset_ptr;
const auto numbering_subset_id = numbering_subset.GetUniqueId();
oconv.str("");
oconv << GetOutputDirectory() << "/NumberingSubset_" << numbering_subset_id;
auto check = output_directory_per_numbering_subset_.insert(std::make_pair(numbering_subset_id, oconv.str()));
assert(check.second);
}
}
} // namespace MoReFEM
......
......@@ -320,7 +320,7 @@ namespace MoReFEM
*
* \return Name of the subfolder related to a given numbering subset.
*/
std::string GetOutputDirectoryForNumberingSubset(const NumberingSubset& numbering_subset) const;
const std::string& GetOutputDirectoryForNumberingSubset(const NumberingSubset& numbering_subset) const;
//! Get the path of the time iteration file.
......@@ -547,7 +547,15 @@ namespace MoReFEM
*/
DoConsiderProcessorWiseLocal2Global GetDoConsiderProcessorWiseLocal2Global() const;
private:
private:
//! Set the values of \a output_directory_per_numbering_subset_.
void SetOutputDirectoryPerNumberingSubset();
//! For each \a NumberingSubset id, keep the associated output directory path.
const std::unordered_map<unsigned int, std::string>& GetOutputDirectoryPerNumberingSubset() const noexcept;
private:
//! List of all finite element spaces related to the mesh covered by GodOfDof.
FEltSpace::vector_unique_ptr felt_space_list_;
......@@ -594,6 +602,9 @@ namespace MoReFEM
//! Path of the file listing the time iterations and the related files.
std::string time_iteration_file_;
//! For each \a NumberingSubset id, keep the associated output directory path.
std::unordered_map<unsigned int, std::string> output_directory_per_numbering_subset_;
# ifndef NDEBUG
/*!
* \brief Whether Init() has already been called or not.
......
......@@ -245,6 +245,13 @@ namespace MoReFEM
}
inline const std::unordered_map<unsigned int, std::string>& GodOfDof
::GetOutputDirectoryPerNumberingSubset() const noexcept
{
return output_directory_per_numbering_subset_;
}
} // namespace MoReFEM
......
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