Skip to content

Commit

Permalink
Write solution when time integration fails
Browse files Browse the repository at this point in the history
Up to now, the computed time points had been discarded when the
simulation crashes. The behavior is changed to save what we have
computed up to the point of failure.
  • Loading branch information
sleweke committed Aug 18, 2021
1 parent 83eb8b5 commit 35d7aac
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/cadet-cli/cadet-cli.cpp
Expand Up @@ -189,8 +189,9 @@ class JsonDriverConfigurator
};

template <class DriverConfigurator_t, class Writer_t>
void run(const std::string& inFileName, const std::string& outFileName, bool showProgressBar)
int run(const std::string& inFileName, const std::string& outFileName, bool showProgressBar)
{
int returnCode = 0;
cadet::Driver drv;

{
Expand All @@ -206,7 +207,16 @@ void run(const std::string& inFileName, const std::string& outFileName, bool sho
#endif

drv.simulator()->setNotificationCallback(pb.get());
drv.run();

try
{
drv.run();
}
catch (const cadet::IntegrationException& e)
{
std::cerr << "SOLVER ERROR: " << e.what() << std::endl;
returnCode = 3;
}

Writer_t writer;
if (inFileName == outFileName)
Expand Down Expand Up @@ -250,6 +260,8 @@ void run(const std::string& inFileName, const std::string& outFileName, bool sho
}
std::cout << "\n}" << std::endl;
#endif

return returnCode;
}


Expand Down Expand Up @@ -314,18 +326,19 @@ int main(int argc, char** argv)

const std::string fileExtIn = inFileName.substr(dotPosIn+1);
const std::string fileExtOut = outFileName.substr(dotPosOut+1);
int returnCode = 0;

try
{
if (cadet::util::caseInsensitiveEquals(fileExtIn, "h5"))
{
if (cadet::util::caseInsensitiveEquals(fileExtOut, "h5"))
{
run<FileReaderDriverConfigurator<cadet::io::HDF5Reader>, cadet::io::HDF5Writer>(inFileName, outFileName, showProgressBar);
returnCode = run<FileReaderDriverConfigurator<cadet::io::HDF5Reader>, cadet::io::HDF5Writer>(inFileName, outFileName, showProgressBar);
}
else if (cadet::util::caseInsensitiveEquals(fileExtOut, "xml"))
{
run<FileReaderDriverConfigurator<cadet::io::HDF5Reader>, cadet::io::XMLWriter>(inFileName, outFileName, showProgressBar);
returnCode = run<FileReaderDriverConfigurator<cadet::io::HDF5Reader>, cadet::io::XMLWriter>(inFileName, outFileName, showProgressBar);
}
else
{
Expand All @@ -337,11 +350,11 @@ int main(int argc, char** argv)
{
if (cadet::util::caseInsensitiveEquals(fileExtOut, "xml"))
{
run<FileReaderDriverConfigurator<cadet::io::XMLReader>, cadet::io::XMLWriter>(inFileName, outFileName, showProgressBar);
returnCode = run<FileReaderDriverConfigurator<cadet::io::XMLReader>, cadet::io::XMLWriter>(inFileName, outFileName, showProgressBar);
}
else if (cadet::util::caseInsensitiveEquals(fileExtOut, "h5"))
{
run<FileReaderDriverConfigurator<cadet::io::XMLReader>, cadet::io::HDF5Writer>(inFileName, outFileName, showProgressBar);
returnCode = run<FileReaderDriverConfigurator<cadet::io::XMLReader>, cadet::io::HDF5Writer>(inFileName, outFileName, showProgressBar);
}
else
{
Expand All @@ -353,11 +366,11 @@ int main(int argc, char** argv)
{
if (cadet::util::caseInsensitiveEquals(fileExtOut, "xml"))
{
run<JsonDriverConfigurator, cadet::io::XMLWriter>(inFileName, outFileName, showProgressBar);
returnCode = run<JsonDriverConfigurator, cadet::io::XMLWriter>(inFileName, outFileName, showProgressBar);
}
else if (cadet::util::caseInsensitiveEquals(fileExtOut, "h5"))
{
run<JsonDriverConfigurator, cadet::io::HDF5Writer>(inFileName, outFileName, showProgressBar);
returnCode = run<JsonDriverConfigurator, cadet::io::HDF5Writer>(inFileName, outFileName, showProgressBar);
}
else
{
Expand Down Expand Up @@ -387,5 +400,5 @@ int main(int argc, char** argv)
return 1;
}

return 0;
return returnCode;
}

0 comments on commit 35d7aac

Please sign in to comment.