Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++17] Check whether the output directory exists. #12080

Merged
merged 1 commit into from
Jul 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions examples/step-70/step-70.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ namespace LA
#endif

#include <cmath>
#include <filesystem>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll be some fun - For libstdc++ we will have to figure out a sane way to decide whether we have to link against libstdc++fs as well or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't -std=c++17 imply that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bangerth gcc version 9 onwards should just require -std=c++17, gcc version 8 and older require manual linking with libstdc++fs. At least if I recall correctly 😸

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember that I had similar issues with gcc8. I solved this by substitution with boost libraries:

#ifdef __cpp_lib_filesystem
#  include <filesystem>
namespace filesystem
{
  using namespace std::filesystem;
}
#else
#  include <boost/filesystem.hpp>
namespace filesystem
{
  using namespace boost::filesystem;
}
#endif

I'm not sure if the __cpp_lib_filesystem flag only exists for gcc.

We could move this code snippet into the std_cxx17 namespace. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we don't include the boost filesystem parts in the bundled/ directory :-( There is also the issue that this is a tutorial and I really didn't want to introduce some complicated workaround in tutorials -- I'd rather just leave things as they are if we can't do it right....

#include <fstream>
#include <iostream>
#include <memory>
Expand Down Expand Up @@ -769,8 +770,11 @@ namespace Step70

// In the constructor, we create the mpi_communicator as well as
// the triangulations and dof_handler for both the fluid and the solid.
// Using the mpi_communicator, both the ConditionalOStream and TimerOutput
// Using the `mpi_communicator`, both the ConditionalOStream and TimerOutput
// object are constructed.
//
// In the constructor, we also check whether the output directory
// specified in the input file exists and, if not, create it.
template <int dim, int spacedim>
StokesImmersedProblem<dim, spacedim>::StokesImmersedProblem(
const StokesImmersedProblemParameters<dim, spacedim> &par)
Expand All @@ -792,7 +796,17 @@ namespace Step70
Triangulation<dim, spacedim>::smoothing_on_coarsening))
, fluid_dh(fluid_tria)
, solid_dh(solid_tria)
{}
{
if (std::filesystem::exists(par.output_directory))
{
Assert(std::filesystem::is_directory(par.output_directory),
ExcMessage("You specified <" + par.output_directory +
"> as the output directory in the input file, "
"but this is not in fact a directory."));
}
else
std::filesystem::create_directory(par.output_directory);
}


// In order to generate the grid, we first try to use the functions in the
Expand Down