Skip to content

Commit

Permalink
Enable user choice of post processing directory (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchdf authored Jun 24, 2024
1 parent de0f7c6 commit b35b859
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 57 deletions.
4 changes: 3 additions & 1 deletion amr-wind/immersed_boundary/IB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "amr-wind/CFDSim.H"
#include "amr-wind/core/FieldRepo.H"
#include "amr-wind/core/MultiParser.H"
#include "amr-wind/utilities/IOManager.H"
#include "amr-wind/utilities/io_utils.H"

#include <algorithm>
Expand Down Expand Up @@ -118,7 +119,8 @@ void IB::compute_forces()

void IB::prepare_outputs()
{
const std::string out_dir_prefix = "post_processing/immersed_boundary";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string out_dir_prefix = post_dir + "/immersed_boundary";
const std::string sname =
amrex::Concatenate(out_dir_prefix, m_sim.time().time_index());
if (!amrex::UtilCreateDirectory(sname, 0755)) {
Expand Down
6 changes: 4 additions & 2 deletions amr-wind/ocean_waves/OceanWaves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "amr-wind/core/FieldRepo.H"
#include "amr-wind/core/MultiParser.H"
#include "amr-wind/physics/multiphase/MultiPhase.H"
#include "amr-wind/utilities/IOManager.H"

#include <algorithm>

Expand Down Expand Up @@ -92,7 +93,8 @@ void OceanWaves::relaxation_zones()

void OceanWaves::prepare_outputs()
{
const std::string out_dir_prefix = "post_processing/ocean_waves";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string out_dir_prefix = post_dir + "/ocean_waves";
const std::string sname =
amrex::Concatenate(out_dir_prefix, m_sim.time().time_index());
if (!amrex::UtilCreateDirectory(sname, 0755)) {
Expand All @@ -102,4 +104,4 @@ void OceanWaves::prepare_outputs()
m_owm->prepare_outputs(sname);
}

} // namespace amr_wind::ocean_waves
} // namespace amr_wind::ocean_waves
12 changes: 12 additions & 0 deletions amr-wind/utilities/IOManager.H
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public:
return m_chk_fields;
}

//! Name of the post processing directory
const std::string& post_processing_directory()
{
if (!amrex::UtilCreateDirectory(m_post_dir, 0755)) {
amrex::CreateDirectoryFailed(m_post_dir);
}
return m_post_dir;
}

private:
void write_header(
const std::string& /*chkname*/,
Expand Down Expand Up @@ -130,6 +139,9 @@ private:
//! Prefix used for the restart file directories
std::string m_chk_prefix{"chk"};

//! Name for the post_processing directory
std::string m_post_dir{"post_processing"};

//! Restart file name
std::string m_restart_file;

Expand Down
1 change: 1 addition & 0 deletions amr-wind/utilities/IOManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void IOManager::initialize_io()
pp.query("output_default_variables", m_output_default_vars);
pp.query("plot_file", m_plt_prefix);
pp.query("check_file", m_chk_prefix);
pp.query("post_processing_directory", m_post_dir);
pp.query("restart_file", m_restart_file);
pp.query("allow_missing_restart_fields", m_allow_missing_restart_fields);
#ifdef AMR_WIND_USE_HDF5
Expand Down
5 changes: 1 addition & 4 deletions amr-wind/utilities/sampling/Enstrophy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,10 @@ void Enstrophy::prepare_ascii_file()
{
BL_PROFILE("amr-wind::Enstrophy::prepare_ascii_file");

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate(m_label, m_sim.time().time_index());

if (!amrex::UtilCreateDirectory(post_dir, 0755)) {
amrex::CreateDirectoryFailed(post_dir);
}
m_out_fname = post_dir + "/" + sname + ".txt";

if (amrex::ParallelDescriptor::IOProcessor()) {
Expand Down
5 changes: 1 addition & 4 deletions amr-wind/utilities/sampling/FieldNorms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,10 @@ void FieldNorms::prepare_ascii_file()
{
BL_PROFILE("amr-wind::FieldNorms::prepare_ascii_file");

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate(m_label, m_sim.time().time_index());

if (!amrex::UtilCreateDirectory(post_dir, 0755)) {
amrex::CreateDirectoryFailed(post_dir);
}
m_out_fname = post_dir + "/" + sname + ".txt";

if (amrex::ParallelDescriptor::IOProcessor()) {
Expand Down
12 changes: 4 additions & 8 deletions amr-wind/utilities/sampling/FreeSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <utility>
#include "amr-wind/utilities/ncutils/nc_interface.H"
#include "amr-wind/equation_systems/vof/volume_fractions.H"
#include "amr-wind/utilities/IOManager.H"

#include "AMReX_ParmParse.H"

Expand Down Expand Up @@ -682,13 +683,10 @@ void FreeSurface::write_ascii()
<< "WARNING: FreeSurface: ASCII output will impact performance"
<< std::endl;

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate(m_label, m_sim.time().time_index());

if (!amrex::UtilCreateDirectory(post_dir, 0755)) {
amrex::CreateDirectoryFailed(post_dir);
}
const std::string fname = post_dir + "/" + sname + ".txt";

if (amrex::ParallelDescriptor::IOProcessor()) {
Expand Down Expand Up @@ -751,12 +749,10 @@ void FreeSurface::prepare_netcdf_file()
{
#ifdef AMR_WIND_USE_NETCDF

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate(m_label, m_sim.time().time_index());
if (!amrex::UtilCreateDirectory(post_dir, 0755)) {
amrex::CreateDirectoryFailed(post_dir);
}

m_ncfile_name = post_dir + "/" + sname + ".nc";

// Only I/O processor handles NetCDF generation
Expand Down
5 changes: 1 addition & 4 deletions amr-wind/utilities/sampling/KineticEnergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,10 @@ void KineticEnergy::prepare_ascii_file()
{
BL_PROFILE("amr-wind::KineticEnergy::prepare_ascii_file");

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate(m_label, m_sim.time().time_index());

if (!amrex::UtilCreateDirectory(post_dir, 0755)) {
amrex::CreateDirectoryFailed(post_dir);
}
m_out_fname = post_dir + "/" + sname + ".txt";

if (amrex::ParallelDescriptor::IOProcessor()) {
Expand Down
14 changes: 5 additions & 9 deletions amr-wind/utilities/sampling/Sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "amr-wind/utilities/sampling/Sampling.H"
#include "amr-wind/utilities/io_utils.H"
#include "amr-wind/utilities/ncutils/nc_interface.H"
#include "amr-wind/utilities/IOManager.H"

#include "AMReX_ParmParse.H"

Expand Down Expand Up @@ -302,7 +303,7 @@ void Sampling::impl_write_native()
{
BL_PROFILE("amr-wind::Sampling::write_native");

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sampling_name =
amrex::Concatenate(m_label, m_sim.time().time_index());
const std::string name(post_dir + "/" + sampling_name);
Expand All @@ -323,13 +324,10 @@ void Sampling::write_ascii()
<< "WARNING: Sampling: ASCII output will negatively impact performance"
<< std::endl;

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate(m_label, m_sim.time().time_index());

if (!amrex::UtilCreateDirectory(post_dir, 0755)) {
amrex::CreateDirectoryFailed(post_dir);
}
const std::string fname = post_dir + "/" + sname + ".txt";
m_scontainer->WriteAsciiFile(fname);
}
Expand All @@ -338,12 +336,10 @@ void Sampling::prepare_netcdf_file()
{
#ifdef AMR_WIND_USE_NETCDF

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate(m_label, m_sim.time().time_index());
if (!amrex::UtilCreateDirectory(post_dir, 0755)) {
amrex::CreateDirectoryFailed(post_dir);
}

m_ncfile_name = post_dir + "/" + sname + ".nc";

// Only I/O processor handles NetCDF generation
Expand Down
5 changes: 1 addition & 4 deletions amr-wind/utilities/sampling/WaveEnergy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,10 @@ void WaveEnergy::prepare_ascii_file()
{
BL_PROFILE("amr-wind::WaveEnergy::prepare_ascii_file");

const std::string post_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate(m_label, m_sim.time().time_index());

if (!amrex::UtilCreateDirectory(post_dir, 0755)) {
amrex::CreateDirectoryFailed(post_dir);
}
m_out_fname = post_dir + "/" + sname + ".txt";

if (amrex::ParallelDescriptor::IOProcessor()) {
Expand Down
35 changes: 15 additions & 20 deletions amr-wind/wind_energy/ABLStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,34 +296,34 @@ void ABLStats::write_ascii()
{
BL_PROFILE("amr-wind::ABLStats::write_ascii");

const std::string stat_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const auto& time = m_sim.time();
m_pa_vel.output_line_average_ascii(
stat_dir + "/plane_average_velocity.txt", time.time_index(),
post_dir + "/plane_average_velocity.txt", time.time_index(),
time.current_time());
m_pa_temp.output_line_average_ascii(
stat_dir + "/plane_average_temperature.txt", time.time_index(),
post_dir + "/plane_average_temperature.txt", time.time_index(),
time.current_time());
m_pa_vel_fine.output_line_average_ascii(
stat_dir + "/plane_average_velocity_fine.txt", time.time_index(),
post_dir + "/plane_average_velocity_fine.txt", time.time_index(),
time.current_time());
m_pa_temp_fine.output_line_average_ascii(
stat_dir + "/plane_average_temperature_fine.txt", time.time_index(),
post_dir + "/plane_average_temperature_fine.txt", time.time_index(),
time.current_time());
m_pa_mueff.output_line_average_ascii(
stat_dir + "/plane_average_velocity_mueff.txt", time.time_index(),
post_dir + "/plane_average_velocity_mueff.txt", time.time_index(),
time.current_time());
m_pa_tt.output_line_average_ascii(
stat_dir + "/second_moment_temperature_temperature.txt",
post_dir + "/second_moment_temperature_temperature.txt",
time.time_index(), time.current_time());
m_pa_tu.output_line_average_ascii(
stat_dir + "/second_moment_temperature_velocity.txt", time.time_index(),
post_dir + "/second_moment_temperature_velocity.txt", time.time_index(),
time.current_time());
m_pa_uu.output_line_average_ascii(
stat_dir + "/second_moment_velocity_velocity.txt", time.time_index(),
post_dir + "/second_moment_velocity_velocity.txt", time.time_index(),
time.current_time());
m_pa_uuu.output_line_average_ascii(
stat_dir + "/third_moment_velocity_velocity_velocity.txt",
post_dir + "/third_moment_velocity_velocity_velocity.txt",
time.time_index(), time.current_time());

// Only I/O processor handles this file I/O
Expand Down Expand Up @@ -372,14 +372,11 @@ void ABLStats::prepare_ascii_file()
return;
}

const std::string stat_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate("abl_statistics", m_sim.time().time_index());

if (!amrex::UtilCreateDirectory(stat_dir, 0755)) {
amrex::CreateDirectoryFailed(stat_dir);
}
m_ascii_file_name = stat_dir + "/" + sname + ".txt";
m_ascii_file_name = post_dir + "/" + sname + ".txt";

std::ofstream outfile;
outfile.open(m_ascii_file_name.c_str(), std::ios_base::out);
Expand All @@ -393,13 +390,11 @@ void ABLStats::prepare_netcdf_file()
{
#ifdef AMR_WIND_USE_NETCDF

const std::string stat_dir = "post_processing";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string sname =
amrex::Concatenate("abl_statistics", m_sim.time().time_index());
if (!amrex::UtilCreateDirectory(stat_dir, 0755)) {
amrex::CreateDirectoryFailed(stat_dir);
}
m_ncfile_name = stat_dir + "/" + sname + ".nc";

m_ncfile_name = post_dir + "/" + sname + ".nc";

// Only I/O processor handles NetCDF generation
if (!amrex::ParallelDescriptor::IOProcessor()) {
Expand Down
4 changes: 3 additions & 1 deletion amr-wind/wind_energy/actuator/Actuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "amr-wind/CFDSim.H"
#include "amr-wind/core/FieldRepo.H"
#include "amr-wind/utilities/io_utils.H"
#include "amr-wind/utilities/IOManager.H"

#include <algorithm>
#include <memory>
Expand Down Expand Up @@ -258,7 +259,8 @@ void Actuator::compute_source_term()

void Actuator::prepare_outputs()
{
const std::string out_dir_prefix = "post_processing/actuator";
const std::string post_dir = m_sim.io_manager().post_processing_directory();
const std::string out_dir_prefix = post_dir + "/actuator";
const std::string sname =
amrex::Concatenate(out_dir_prefix, m_sim.time().time_index());
if (!amrex::UtilCreateDirectory(sname, 0755)) {
Expand Down
6 changes: 6 additions & 0 deletions docs/sphinx/user/inputs_io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ controls when these files are output.

If a string is present `amr-wind` will restart using the specified file in the string. This is the only argument addressing "input" of data to the simulation instead of "output".

.. input_param:: io.post_processing_directory

**type:** String, optional, default = "post_processing"

Name of the directory that will contain post processing output (e.g., sampling).

.. input_param:: io.output_default_variables

**type:** Boolean, optional, default = true
Expand Down

0 comments on commit b35b859

Please sign in to comment.