diff --git a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp index acfefc1c84d876efc184487febc0cf46d435be68..de71ebd4842f9b27203a50a0e432a60834d23fc2 100644 --- a/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp +++ b/Applications/Utils/ModelPreparation/PartitionMesh/NodeWiseMeshPartitioner.cpp @@ -475,13 +475,25 @@ void writePropertiesBinary(const std::string& file_name_base, auto const file_name_infix = toString(mesh_item_type); - std::ofstream out = BaseLib::createBinaryFile( - file_name_base + "_partitioned_" + file_name_infix + "_properties_cfg" + - std::to_string(partitions.size()) + ".bin"); + auto const file_name_cfg = file_name_base + "_partitioned_" + + file_name_infix + "_properties_cfg" + + std::to_string(partitions.size()) + ".bin"; + std::ofstream out(file_name_cfg, std::ios::binary); + if (!out) + { + OGS_FATAL("Could not open file '%s' for output.", + file_name_cfg.c_str()); + } - std::ofstream out_val = BaseLib::createBinaryFile( - file_name_base + "_partitioned_" + file_name_infix + "_properties_val" + - std::to_string(partitions.size()) + ".bin"); + auto const file_name_val = file_name_base + "_partitioned_" + + file_name_infix + "_properties_val" + + std::to_string(partitions.size()) + ".bin"; + std::ofstream out_val(file_name_val, std::ios::binary); + if (!out_val) + { + OGS_FATAL("Could not open file '%s' for output.", + file_name_val.c_str()); + } std::size_t const number_of_properties(property_names.size()); BaseLib::writeValueBinary(out, number_of_properties); @@ -570,9 +582,14 @@ std::tuple<std::vector<long>, std::vector<long>> writeConfigDataBinary( const std::string& file_name_base, std::vector<Partition> const& partitions) { - std::ofstream of_bin_cfg = - BaseLib::createBinaryFile(file_name_base + "_partitioned_msh_cfg" + - std::to_string(partitions.size()) + ".bin"); + auto const file_name_cfg = file_name_base + "_partitioned_msh_cfg" + + std::to_string(partitions.size()) + ".bin"; + std::ofstream of_bin_cfg(file_name_cfg, std::ios::binary); + if (!of_bin_cfg) + { + OGS_FATAL("Could not open file '%s' for output.", + file_name_cfg.c_str()); + } std::vector<long> num_elem_integers; num_elem_integers.reserve(partitions.size()); @@ -648,10 +665,23 @@ void writeElementsBinary(std::string const& file_name_base, { const std::string npartitions_str = std::to_string(partitions.size()); - std::ofstream element_info_os = BaseLib::createBinaryFile( - file_name_base + "_partitioned_msh_ele" + npartitions_str + ".bin"); - std::ofstream ghost_element_info_os = BaseLib::createBinaryFile( - file_name_base + "_partitioned_msh_ele_g" + npartitions_str + ".bin"); + auto const file_name_ele = + file_name_base + "_partitioned_msh_ele" + npartitions_str + ".bin"; + std::ofstream element_info_os(file_name_ele, std::ios::binary); + if (!element_info_os) + { + OGS_FATAL("Could not open file '%s' for output.", + file_name_ele.c_str()); + } + + auto const file_name_ele_g = + file_name_base + "_partitioned_msh_ele_g" + npartitions_str + ".bin"; + std::ofstream ghost_element_info_os(file_name_ele_g, std::ios::binary); + if (!ghost_element_info_os) + { + OGS_FATAL("Could not open file '%s' for output.", + file_name_ele_g.c_str()); + } for (std::size_t i = 0; i < partitions.size(); i++) { @@ -703,9 +733,13 @@ void writeNodesBinary(const std::string& file_name_base, std::vector<Partition> const& partitions, std::vector<std::size_t> const& global_node_ids) { - std::ofstream os = - BaseLib::createBinaryFile(file_name_base + "_partitioned_msh_nod" + - std::to_string(partitions.size()) + ".bin"); + auto const file_name = file_name_base + "_partitioned_msh_nod" + + std::to_string(partitions.size()) + ".bin"; + std::ofstream os(file_name, std::ios::binary); + if (!os) + { + OGS_FATAL("Could not open file '%s' for output.", file_name.c_str()); + } for (const auto& partition : partitions) { diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index b9c4eb15ada69c52d3774b93b629282041e96de6..7a50c5e6cc0b999f6d54e20097009ff1dd1497e2 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -57,16 +57,6 @@ void truncateFile( std::string const& filename) ofs.close(); } -std::ofstream createBinaryFile(std::string const& file_name) -{ - std::ofstream os(file_name, std::ios::binary); - if (!os) - { - OGS_FATAL("Could not open file '%s' for output.", file_name.c_str()); - } - return os; -} - namespace { diff --git a/BaseLib/FileTools.h b/BaseLib/FileTools.h index c74ed9b90f96030ff6add5e590517c93c36b9d4f..b3a2c9ec0d0e83bcc79a623e0c7bb078b11a476c 100644 --- a/BaseLib/FileTools.h +++ b/BaseLib/FileTools.h @@ -97,13 +97,6 @@ std::vector<T> readBinaryArray(std::string const& filename, std::size_t const n) return std::vector<T>(); } -/** - * Create a binary file for output. - * - * Wrapper around the std::ofstream constructor with error checking. - */ -std::ofstream createBinaryFile(std::string const& file_name); - /** * \brief truncate a file *