Commit 37a2ca48 authored by frey_m's avatar frey_m
Browse files

Merge branch '401-closed-orbit-finder-should-not-call-exit' into 'master'

Resolve "Closed Orbit Finder should not call exit()"

Closes #401

See merge request !215
parents 8239ed3d fd714c64
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "Structure/H5PartWrapper.h" #include "Structure/H5PartWrapper.h"
#include "Structure/H5PartWrapperForPC.h" #include "Structure/H5PartWrapperForPC.h"
#include "Utilities/Util.h" #include "Utilities/Util.h"
#include "Utilities/EarlyLeaveException.h"
#include <gsl/gsl_cdf.h> #include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h> #include <gsl/gsl_randist.h>
...@@ -1348,7 +1349,8 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub ...@@ -1348,7 +1349,8 @@ void Distribution::createMatchedGaussDistribution(size_t numberOfParticles, doub
cof_t cof(massIneV*1E-6, Nint, CyclotronElement, false, Nsectors); cof_t cof(massIneV*1E-6, Nint, CyclotronElement, false, Nsectors);
cof.findOrbit(accuracy, maxitCOF, E_m*1E-6, denergy, rguess, true); cof.findOrbit(accuracy, maxitCOF, E_m*1E-6, denergy, rguess, true);
std::exit(0); throw EarlyLeaveException("Distribution::CreateMatchedGaussDistribution()",
"Do only tune calculation.");
} }
bool writeMap = true; bool writeMap = true;
......
...@@ -35,6 +35,7 @@ Inform *gmsg; ...@@ -35,6 +35,7 @@ Inform *gmsg;
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/Options.h" #include "Utilities/Options.h"
#include "Utilities/OpalException.h" #include "Utilities/OpalException.h"
#include "Utilities/EarlyLeaveException.h"
#include "Utilities/Util.h" #include "Utilities/Util.h"
#include "OPALconfig.h" #include "OPALconfig.h"
...@@ -361,13 +362,6 @@ int main(int argc, char *argv[]) { ...@@ -361,13 +362,6 @@ int main(int argc, char *argv[]) {
} }
} }
IpplTimings::stopTimer(mainTimer);
IpplTimings::print();
IpplTimings::print(std::string("timing.dat"),
OpalData::getInstance()->getProblemCharacteristicValues());
if(Ippl::myNode() == 0) { if(Ippl::myNode() == 0) {
std::ifstream errormsg("errormsg.txt"); std::ifstream errormsg("errormsg.txt");
if(errormsg.good()) { if(errormsg.good()) {
...@@ -398,25 +392,8 @@ int main(int argc, char *argv[]) { ...@@ -398,25 +392,8 @@ int main(int argc, char *argv[]) {
errormsg.close(); errormsg.close();
} }
Ippl::Comm->barrier(); } catch(EarlyLeaveException& ex) {
Fieldmap::clearDictionary(); // do nothing here
OpalData::deleteInstance();
delete gmsg;
#ifdef ENABLE_AMR
if ( initAMR ) {
amrex::Finalize(true);
}
#endif
delete ippl;
delete Ippl::Info;
delete Ippl::Warn;
delete Ippl::Error;
delete Ippl::Debug;
return 0;
} catch(OpalException &ex) { } catch(OpalException &ex) {
Inform errorMsg("Error", std::cerr, INFORM_ALL_NODES); Inform errorMsg("Error", std::cerr, INFORM_ALL_NODES);
errorMsg << "\n*** User error detected by function \"" errorMsg << "\n*** User error detected by function \""
...@@ -524,5 +501,30 @@ int main(int argc, char *argv[]) { ...@@ -524,5 +501,30 @@ int main(int argc, char *argv[]) {
MPI_Abort(MPI_COMM_WORLD, -100); MPI_Abort(MPI_COMM_WORLD, -100);
} }
return 1;
IpplTimings::stopTimer(mainTimer);
IpplTimings::print();
IpplTimings::print(std::string("timing.dat"),
OpalData::getInstance()->getProblemCharacteristicValues());
Ippl::Comm->barrier();
Fieldmap::clearDictionary();
OpalData::deleteInstance();
delete gmsg;
#ifdef ENABLE_AMR
if ( initAMR ) {
amrex::Finalize(true);
}
#endif
delete ippl;
delete Ippl::Info;
delete Ippl::Warn;
delete Ippl::Error;
delete Ippl::Debug;
return 0;
} }
\ No newline at end of file
set (_SRCS set (_SRCS
EarlyLeaveException.cpp
OpalException.cpp OpalException.cpp
OpalFilter.cpp OpalFilter.cpp
RegularExpression.cpp RegularExpression.cpp
...@@ -15,6 +16,7 @@ include_directories ( ...@@ -15,6 +16,7 @@ include_directories (
add_opal_sources(${_SRCS}) add_opal_sources(${_SRCS})
set (HDRS set (HDRS
EarlyLeaveException.h
NumToStr.h NumToStr.h
OpalException.h OpalException.h
OpalFilter.h OpalFilter.h
......
//
// Implements the member function of the EarlyLeaveException class.
//
// Copyright (c) 2008-2019
// Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved.
//
// OPAL is licensed under GNU GPL version 3.
//
#include "Utilities/EarlyLeaveException.h"
EarlyLeaveException::EarlyLeaveException(const std::string &meth, const std::string &msg):
ClassicException(meth, msg)
{}
EarlyLeaveException::EarlyLeaveException(const EarlyLeaveException &rhs):
ClassicException(rhs)
{}
EarlyLeaveException::~EarlyLeaveException()
{}
//
// This exception class is used to intentionally exit OPAL even if no
// error occurred. It is used in case of the tune calculation with
// the matched distribution option.
//
// Copyright (c) 2008-2019
// Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved.
//
// OPAL is licensed under GNU GPL version 3.
//
#ifndef OPAL_EARLY_LEAVE_EXCEPTION_H
#define OPAL_EARLY_LEAVE_EXCEPTION_H
#include "Utilities/ClassicException.h"
/*!
This exception class is used to inentionally exit OPAL when no error occurred.
*/
class EarlyLeaveException: public ClassicException {
public:
/** The usual constructor.
* @param[in] meth the name of the method or function detecting the exception
* @param[in] msg the message string identifying the exception
*/
explicit EarlyLeaveException(const std::string &meth, const std::string &msg);
EarlyLeaveException(const EarlyLeaveException &);
virtual ~EarlyLeaveException();
/// Return the message string for the exception.
using ClassicException::what;
/// Return the name of the method or function which detected the exception.
using ClassicException::where;
private:
// Not implemented.
EarlyLeaveException() = delete;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment