Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ message(" CO_SIM_IO_BUILD_MPI: " ${CO_SIM_IO_BUILD_MPI})
message(" CO_SIM_IO_BUILD_TESTING: " ${CO_SIM_IO_BUILD_TESTING})
message(" CO_SIM_IO_BUILD_C: " ${CO_SIM_IO_BUILD_C})
message(" CO_SIM_IO_BUILD_PYTHON: " ${CO_SIM_IO_BUILD_PYTHON})
# message(" CO_SIM_IO_BUILD_FORTRAN: " ${CO_SIM_IO_BUILD_FORTRAN})
message(" CO_SIM_IO_BUILD_FORTRAN: " ${CO_SIM_IO_BUILD_FORTRAN})
message(" CO_SIM_IO_STRICT_COMPILER: " ${CO_SIM_IO_STRICT_COMPILER})
message("")

Expand Down Expand Up @@ -124,8 +124,7 @@ message("CMAKE_CXX_FLAGS:" ${CMAKE_CXX_FLAGS})
message("CMAKE_C_FLAGS:" ${CMAKE_C_FLAGS})

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# to suppress warning "MACOSX_RPATH is not specified for the following targets"
set(CMAKE_MACOSX_RPATH 0)
cmake_policy(SET CMP0042 NEW)
endif()

# clean the bin directory
Expand Down Expand Up @@ -180,9 +179,14 @@ if (CO_SIM_IO_BUILD_PYTHON)
endif()

if (CO_SIM_IO_BUILD_FORTRAN)
# TODO since fortran relies on C, a check is needed
message( FATAL_ERROR "The CoSimIO is currently not working for Fortran")
add_subdirectory(co_sim_io/fortran)
if (NOT CO_SIM_IO_BUILD_C)
message(FATAL_ERROR "Fortran requires the C interface!")
endif()
include(CMakeAddFortranSubdirectory)
cmake_add_fortran_subdirectory(
co_sim_io/fortran
NO_EXTERNAL_INSTALL
)
endif()

if (CO_SIM_IO_BUILD_TESTING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Kratos CoSimulationApplication
~~~

[![CI](https://github.com/KratosMultiphysics/CoSimIO/actions/workflows/ci.yml/badge.svg?event=schedule)](https://github.com/KratosMultiphysics/CoSimIO/actions/workflows/ci.yml)
<!--- [![CI](https://github.com/KratosMultiphysics/CoSimIO/actions/workflows/ci.yml/badge.svg?event=schedule)](https://github.com/KratosMultiphysics/CoSimIO/actions/workflows/ci.yml)-->
# CoSimIO

The _CoSimIO_ is a small library for interprocess communication in CoSimulation contexts. It is designed for exchanging data between different solvers or other software-tools. For performing coupled simulations it is used in combination with the [_CoSimulationApplication_](https://github.com/KratosMultiphysics/Kratos/tree/master/applications/CoSimulationApplication).\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class CO_SIM_IO_API Communication
Info GetMyInfo() const;
Info GetPartnerInfo() const {return mPartnerInfo;};

fs::path GetTempFileName(
fs::path GetTmpFileName(
const fs::path& rPath,
const bool UseAuxFileForFileAvailability=true) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define CO_SIM_IO_LOCAL_SOCKET_COMMUNICATION_INCLUDED

// System includes
#include <thread>

// Project includes
#include "includes/communication/base_socket_communication.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#define CO_SIM_IO_SOCKET_COMMUNICATION_INCLUDED

// System includes
#include <thread>

// Project includes
#include "includes/communication/base_socket_communication.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,7 @@
#ifndef CO_SIM_IO_FILESYSTEM_INC_INCLUDED
#define CO_SIM_IO_FILESYSTEM_INC_INCLUDED

/* std::filesystem is part of C++17
While we use C++11, the alternative implementation from
"https://github.com/gulrak/filesystem" is used
*/

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include "ghc/filesystem.hpp"
namespace fs = ghc::filesystem;

// use this once moving to C++17
// #include <filesystem>
// namespace fs = std::filesystem;
#include <filesystem>
namespace fs = std::filesystem;

#endif // CO_SIM_IO_FILESYSTEM_INC_INCLUDED
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,35 @@

// Project includes
#include "includes/code_location.hpp"
#include "includes/filesystem_inc.hpp"

namespace CoSimIO {
namespace Internals {

std::string CodeLocation::GetCleanFileName() const
{
return fs::canonical(fs::path(GetFileName())).lexically_relative(fs::absolute(".")).string();
std::string clean_file_name(GetFileName());

// Replace all backslashes with forward slashes
std::size_t start_position = 0;
const std::string from_string = "\\";
const std::string to_string = "/";
while ((start_position = clean_file_name.find(from_string, start_position)) != std::string::npos) {
clean_file_name.replace(start_position, from_string.length(), to_string);
start_position += to_string.length();
}

// Remove the path up to the co_sim_io root folder
std::size_t co_sim_io_root_position = clean_file_name.rfind("/co_sim_io/");
if (co_sim_io_root_position != std::string::npos) {
clean_file_name.erase(0, co_sim_io_root_position+1);
return clean_file_name;
}
if (co_sim_io_root_position != std::string::npos) {
clean_file_name.erase(0, co_sim_io_root_position + 1 );
}

return clean_file_name;
}

} // namespace Interals
} // namespace Internals
} // namespace CoSimIO
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void Communication::PostChecks(const Info& I_Info)
CO_SIM_IO_ERROR_IF_NOT(I_Info.Has("memory_usage_ipc")) << "\"memory_usage_ipc\" must be specified!" << std::endl;
}

fs::path Communication::GetTempFileName(
fs::path Communication::GetTmpFileName(
const fs::path& rPath,
const bool UseAuxFileForFileAvailability) const
{
Expand Down Expand Up @@ -370,7 +370,7 @@ void Communication::MakeFileVisible(
CO_SIM_IO_TRY

if (!UseAuxFileForFileAvailability) {
const fs::path tmp_file_name = GetTempFileName(rPath, UseAuxFileForFileAvailability);
const fs::path tmp_file_name = GetTmpFileName(rPath, UseAuxFileForFileAvailability);
AddFilePermissions(tmp_file_name);
std::error_code ec;
fs::rename(tmp_file_name, rPath, ec);
Expand Down Expand Up @@ -417,9 +417,9 @@ void Communication::SynchronizeAll(const std::string& rTag) const

if (GetIsPrimaryConnection()) {
std::ofstream sync_file;
sync_file.open(GetTempFileName(file_name_primary));
sync_file.open(GetTmpFileName(file_name_primary));
sync_file.close();
CO_SIM_IO_ERROR_IF_NOT(fs::exists(GetTempFileName(file_name_primary))) << "Primary sync file " << file_name_primary << " could not be created!" << std::endl;
CO_SIM_IO_ERROR_IF_NOT(fs::exists(GetTmpFileName(file_name_primary))) << "Primary sync file " << file_name_primary << " could not be created!" << std::endl;
MakeFileVisible(file_name_primary);

WaitForPath(file_name_secondary, true, 2);
Expand All @@ -431,9 +431,9 @@ void Communication::SynchronizeAll(const std::string& rTag) const
RemovePath(file_name_primary);

std::ofstream sync_file;
sync_file.open(GetTempFileName(file_name_secondary));
sync_file.open(GetTmpFileName(file_name_secondary));
sync_file.close();
CO_SIM_IO_ERROR_IF_NOT(fs::exists(GetTempFileName(file_name_secondary))) << "Secondary sync file " << file_name_secondary << " could not be created!" << std::endl;
CO_SIM_IO_ERROR_IF_NOT(fs::exists(GetTmpFileName(file_name_secondary))) << "Secondary sync file " << file_name_secondary << " could not be created!" << std::endl;
MakeFileVisible(file_name_secondary);

WaitUntilFileIsRemoved(file_name_secondary, 2);
Expand Down Expand Up @@ -485,7 +485,7 @@ void Communication::HandShake(const Info& I_Info)
WaitUntilFileIsRemoved(rMyFileName,1); // in case of leftovers

{ // necessary as FileSerializer releases resources on destruction!
FileSerializer serializer_save(GetTempFileName(rMyFileName).string(), mSerializerTraceType);
FileSerializer serializer_save(GetTmpFileName(rMyFileName).string(), mSerializerTraceType);
serializer_save.save("info", GetMyInfo());
}

Expand Down Expand Up @@ -524,7 +524,7 @@ void Communication::HandShake(const Info& I_Info)

auto print_endianness = [](const bool IsBigEndian){return IsBigEndian ? "big endian" : "small endian";};

CO_SIM_IO_INFO_IF("CoSimIO", Utilities::IsBigEndian() != mPartnerInfo.Get<bool>("is_big_endian")) << "WARNING: Parnters have different endianness, check results carefully! It is recommended to use serialized ascii commuication.\n My endianness: " << print_endianness(Utilities::IsBigEndian()) << "\n Partner endianness: " << print_endianness(mPartnerInfo.Get<bool>("is_big_endian")) << std::endl;
CO_SIM_IO_INFO_IF("CoSimIO", Utilities::IsBigEndian() != mPartnerInfo.Get<bool>("is_big_endian")) << "WARNING: Parnters have different endianness, check results carefully! It is recommended to use serialized ascii communication.\n My endianness: " << print_endianness(Utilities::IsBigEndian()) << "\n Partner endianness: " << print_endianness(mPartnerInfo.Get<bool>("is_big_endian")) << std::endl;

// more things can be done in derived class if necessary
DerivedHandShake();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ Info FileCommunication::GenericSendWithFileSerializer(
WaitUntilFileIsRemoved(file_name); // TODO maybe this can be queued somehow ... => then it would not block the sender

const auto start_time(std::chrono::steady_clock::now());
SerializeToFile(GetTempFileName(file_name, mUseAuxFileForFileAvailability), rObj, GetSerializerTraceType());
SerializeToFile(GetTmpFileName(file_name, mUseAuxFileForFileAvailability), rObj, GetSerializerTraceType());

info.Set<std::size_t>("memory_usage_ipc", fs::file_size(GetTempFileName(file_name, mUseAuxFileForFileAvailability)));
info.Set<std::size_t>("memory_usage_ipc", fs::file_size(GetTmpFileName(file_name, mUseAuxFileForFileAvailability)));

MakeFileVisible(file_name, mUseAuxFileForFileAvailability);

Expand Down Expand Up @@ -275,7 +275,7 @@ double FileCommunication::GenericSend(

const auto start_time(std::chrono::steady_clock::now());

std::ofstream output_file(GetTempFileName(file_name, mUseAuxFileForFileAvailability), std::ios::out|std::ios::binary);
std::ofstream output_file(GetTmpFileName(file_name, mUseAuxFileForFileAvailability), std::ios::out|std::ios::binary);
Utilities::CheckStream(output_file, file_name);

output_file.write(reinterpret_cast<const char *>(&size), sizeof(std::size_t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ int GetMajorVersion() {
}

int GetMinorVersion() {
return 2;
return 3;
}

std::string GetPatchVersion() {
return "0";
return "1";
}

} // namespace CoSimIO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)

Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
asio version 1.20.0
Released Saturday, 16 October 2021.
asio version 1.28.0
Released Wednesday, 26 April 2023.

See doc/index.html for API documentation and a tutorial.
Loading