-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Revert "Revert "Replay mode for ASTE"" This reverts commit 0b0b832. * Remove test files * Check only init and dt, ignore it and final mesh * Change parsing logic * Start an arbitrary iteration for replay mode * Add start-time to aste-configuration * Change from starttime to startdt and fix logic * Add precice finalize to prevent stall * Change starttime to startdt * Add more guards while parsing ASTE configuration * Improve error handling and error messages for parsing * update error message Co-authored-by: David Schneider <[email protected]> * Change std::throw to print error and exit * Add explanation Co-authored-by: David Schneider <[email protected]>
- Loading branch information
1 parent
6ab9ac1
commit 338d8d7
Showing
15 changed files
with
23,044 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.