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

Replay mode for ASTE #100

Merged
merged 17 commits into from
Apr 21, 2022
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ message (STATUS "VTK_VERSION: ${VTK_VERSION}")
find_package(METIS)
if (METIS_FOUND)
add_library(metisAPI SHARED src/metisAPI.cpp)
include_directories(${METIS_INCLUDE_DIRS})
target_link_libraries(metisAPI ${METIS_LIBRARIES})
target_include_directories(metisAPI PRIVATE ${METIS_INCLUDE_DIR})
endif()

find_package(MPI REQUIRED)

add_executable(preciceMap src/preciceMap.cpp src/common.cpp src/easylogging++.cc src/mesh.cpp)
add_executable(preciceMap src/preciceMap.cpp src/common.cpp src/easylogging++.cc src/mesh.cpp src/configreader.cpp src/modes.cpp src/utilities.cpp)
target_include_directories(preciceMap PRIVATE src)
target_link_libraries(preciceMap
precice::precice
Expand Down Expand Up @@ -67,7 +68,6 @@ target_link_libraries(testing
${VTK_LIBRARIES}
)


if (VTK_VERSION VERSION_LESS "8.90.0")
# old system
include(${VTK_USE_FILE})
Expand Down
File renamed without changes.
23 changes: 14 additions & 9 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,24 @@ OptionMap getOptions(int argc, char *argv[])
namespace po = boost::program_options;

po::options_description desc("ASTE: Artificial solver emulation tool");
desc.add_options()("help,h", "Print this help message")(
desc.add_options()("help,h", "Print this help message")("aste-config", po::value<std::string>(), "ASTE Configration file for replay mode")(
"precice-config,c",
po::value<std::string>()->default_value("precice-config.xml"),
"preCICE configuratio file")(
"participant,p",
po::value<std::string>()->required(),
po::value<std::string>(),
"Participant Name")(
"data", po::value<std::string>()->required(),
"data", po::value<std::string>(),
"Name of Data Array to be Mapped")(
"mesh", po::value<string>()->required(),
"mesh", po::value<std::string>(),
"Mesh prefix (i.e. mesh name without the format extension such as '.vtk' or '.vtu'). "
"Example: solution.vtk has the prefix 'solution'. "
"preciceMap will look for timeseries as well as distributed meshes (e.g. from preCICE exports) "
"automatically and load them if required.")(
"output", po::value<string>()->default_value("output"),
"output", po::value<std::string>(),
"Output file name.")(
"vector", po::bool_switch(),
"Distinguish between vector valued data and scalar data")(
"verbose,v", po::bool_switch(),
"Enable verbose output"); // not explicitely used, handled by easylogging
"Distinguish between vector valued data and scalar data")("verbose,v", po::bool_switch(), "Enable verbose output"); // not explicitely used, handled by easylogging

po::variables_map vm;

Expand All @@ -45,9 +43,16 @@ OptionMap getOptions(int argc, char *argv[])
// Needs to be called before we look for participants
po::notify(vm);

if (vm["participant"].as<string>() != "A" &&
if (!vm.count("aste-config") && vm["participant"].as<string>() != "A" &&
vm["participant"].as<string>() != "B")
throw runtime_error("Invalid participant, must be either 'A' or 'B'");

if (!(vm.count("participant") || vm.count("data") || vm.count("mesh") || vm.count("output") || vm.count("vector")) && vm.count("aste-config"))
throw runtime_error("Replay mode can only be combined with logging options");

if ((vm.count("aste-config") == 0) && not(vm.count("participant") && vm.count("data") && vm.count("mesh")))
throw runtime_error("One of the following arguments is missing \"--participant\" \"--data\" \"--mesh\"");

} catch (const std::exception &e) {
LOG(ERROR) << "ERROR: " << e.what() << "\n";
LOG(ERROR) << desc << std::endl;
Expand Down
106 changes: 106 additions & 0 deletions src/configreader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "configreader.hpp"
#include <fstream>
#include <iostream>
#include <mpi.h>
namespace aste {
void asteConfig::load(const std::string &asteConfigFile)
{

std::ifstream ifs(asteConfigFile);
json config = json::parse(ifs);

try {
preciceConfigFilename = config["precice-config"].get<std::string>();
} catch (nlohmann::detail::parse_error) {
std::cerr << "Error while parsing ASTE configuration file \"precice-config\" is missing\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
} catch (nlohmann::detail::type_error) {
std::cerr << "Error while parsing ASTE configuration file \"precice-config\" is missing\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

try {
participantName = config["participant"].get<std::string>();
} catch (nlohmann::detail::parse_error) {
std::cerr << "Error while parsing ASTE configuration file \"participant\" is missing\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
} catch (nlohmann::detail::type_error) {
std::cerr << "Error while parsing ASTE configuration file \"participant\" is missing\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

try {
startdt = config["startdt"].get<int>();
} catch (nlohmann::detail::type_error) {
try {
startdt = std::stoi(config["startdt"].get<std::string>());
} catch (nlohmann::detail::type_error) {
std::cerr << "Error while parsing ASTE configuration file \"startdt\" is missing or has a wrong type, it must be an integer or integer convertable string.\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
} catch (std::invalid_argument) {
std::cerr << "Error while parsing startdt from ASTE configuration file it must be an integer or integer convertable string.\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}
}

if (startdt < 1) {
throw std::runtime_error("Start dt cannot be smaller than 1, please check your ASTE configuration file.");
}

const int numInterfaces = config["meshes"].size();

if (numInterfaces == 0) {
std::cerr << "ASTE configuration should contain at least 1 mesh. Please check your ASTE configuration file.\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

for (auto i = 0; i < numInterfaces; i++) {
asteInterface interface;
try {
interface.meshName = config["meshes"][i]["mesh"].get<std::string>();
} catch (nlohmann::detail::parse_error) {
std::cerr << "Error while parsing ASTE configuration file \"mesh\" is missing\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
} catch (nlohmann::detail::type_error) {
std::cerr << "Error while parsing ASTE configuration file \"mesh\" is missing or not a string\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

try {
interface.meshFilePrefix = config["meshes"][i]["meshfileprefix"];
} catch (nlohmann::detail::parse_error) {
std::cerr << "Error while parsing ASTE configuration file \"meshfileprefix\" is missing\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
} catch (nlohmann::detail::type_error) {
std::cerr << "Error while parsing ASTE configuration file \"meshfileprefix\" is missing or not a string\n";
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

const auto readScalarSize = config["meshes"][i]["read-data"]["scalar"].size();
const auto readVectorSize = config["meshes"][i]["read-data"]["vector"].size();
const auto writeScalarSize = config["meshes"][i]["write-data"]["scalar"].size();
const auto writeVectorSize = config["meshes"][i]["write-data"]["vector"].size();

for (auto k = 0; k < readScalarSize; k++) {
const auto scalarName = config["meshes"][i]["read-data"]["scalar"][k];
interface.readScalarNames.push_back(scalarName);
}
for (auto k = 0; k < readVectorSize; k++) {
const auto vectorName = config["meshes"][i]["read-data"]["vector"][k];
interface.readVectorNames.push_back(vectorName);
}
for (auto k = 0; k < writeScalarSize; k++) {
const auto scalarName = config["meshes"][i]["write-data"]["scalar"][k];
interface.writeScalarNames.push_back(scalarName);
}
for (auto k = 0; k < writeVectorSize; k++) {
const auto vectorName = config["meshes"][i]["write-data"]["vector"][k];
interface.writeVectorNames.push_back(vectorName);
}
asteInterfaces.push_back(interface);
}

return;
};

} // namespace aste
47 changes: 47 additions & 0 deletions src/configreader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <iostream>
#include <json.hpp>
#include <string>
#include <vector>
#include "mesh.hpp"
#include "precice/SolverInterface.hpp"

using json = nlohmann::json;

namespace aste {
/**
* @brief ASTE Interface is used for store meshes and related data about a mesh.
*
*/
struct asteInterface {
std::string meshName; // Meshname in preCICE config
std::string meshFilePrefix; // Meshfile (.vtk/vtu) prefix
std::vector<std::string> writeVectorNames; // Datanames of write type vectors
std::vector<std::string> readVectorNames; // Datanames of read type vectors
std::vector<std::string> writeScalarNames; // Datanames of write type scalars
std::vector<std::string> readScalarNames; // Datanames of read type scalars
std::vector<MeshName> meshes; // A list of meshfiles
int meshID; // MeshID of this mesh in preCICE
Mesh mesh; // Mesh data structure in ASTE
};

/**
* @brief ASTE Configration class which contain current configuration for ASTE
*
*/
class asteConfig {
public:
/**
* @brief Parser for ASTE config file
*
* @param asteConfigFile
*/
void load(const std::string &asteConfigFile);
std::string preciceConfigFilename; // preCICE config file
std::vector<asteInterface> asteInterfaces; // Vector of ASTE interfaces(meshes)
std::string participantName; // The name of participant in preCICE config
int startdt;
};

} // namespace aste
Loading