Commit 4ce8d1c1 authored by frey_m's avatar frey_m

modified: src/Distribution/ClosedOrbitFinder.h

modified:   src/Distribution/Distribution.cpp
modified:   src/Distribution/SigmaGenerator.h
deleted:    src/Distribution/error.h
deleted:    src/Distribution/physical_error.h

Matthias: Removal of unnessecary functions in matched distribution. Using OpalExceptions instead of standard exceptions.
parent 6e820be9
......@@ -19,11 +19,14 @@
#include <functional>
#include <limits>
#include <numeric>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include "Utilities/OpalOptions.h"
#include "Utilities/Options.h"
#include "Utilities/OpalException.h"
// #include "physics.h"
#include "MagneticField.h" // ONLY FOR STAND-ALONE PROGRAM
......@@ -282,12 +285,21 @@ ClosedOrbitFinder<Value_type, Size_type, Stepper>::ClosedOrbitFinder(value_type
vertOscDone_m(false), fieldmap_m(fieldmap), domain_m(domain), stepper_m(), rguess_m(rguess)
{
// if (Emin_m > Emax_m || E_m < Emin_m || E > Emax_m)
// throw std::domain_error("Error in ClosedOrbitFinder: Emin <= E <= Emax and Emin < Emax");
if ( Emin_m > Emax_m )
throw OpalException("ClosedOrbitFinder::ClosedOrbitFinder()",
"Incorrect cyclotron energy (MeV) bounds: Maximum cyclotron energy smaller than minimum cyclotron energy.");
// if ( E_m < Emin_m )
// throw OpalException("ClosedOrbitFinder::ClosedOrbitFinder()",
// "Kinetic energy (" + std::to_string(E_m) + " MeV) smaller than minimum cyclotron energy (" + std::to_string(Emin_m) + " MeV)");
if ( E_m > Emax_m )
throw OpalException("ClosedOrbitFinder::ClosedOrbitFinder()",
"Kinetic energy (" + std::to_string(E_m) + " MeV) bigger than maximum cyclotron energy (" + std::to_string(Emax_m) + " MeV)");
// velocity: beta = v/c = sqrt(1-1/(gamma*gamma))
if (gamma_m == 0)
throw std::invalid_argument("Error in ClosedOrbitFinder: Relativistic factor equal zero.");
throw OpalException("ClosedOrbitFinder::ClosedOrbitFinder()", "Relativistic factor equal zero.");
// if domain_m = true --> integrate over a single sector
if (domain_m) {
......@@ -498,7 +510,7 @@ bool ClosedOrbitFinder<Value_type, Size_type, Stepper>::findOrbit(value_type acc
{
pr2 = y[1] * y[1];
if (p2 < pr2)
throw std::domain_error("Error in ClosedOrbitFinder::findOrbit: p_{r} > p^{2} (defined in Gordon paper)");
throw OpalException("ClosedOrbitFinder::findOrbit()", "p_{r}^2 > p^{2} (defined in Gordon paper) --> Square root of negative number.");
// Gordon, formula (5c)
ptheta = std::sqrt(p2 - pr2);
......@@ -795,8 +807,8 @@ void ClosedOrbitFinder<Value_type, Size_type, Stepper>::computeVerticalOscillati
{
pr2 = y[1] * y[1];
if (p2 < pr2) {
throw std::domain_error("Error in ClosedOrbitFinder::computeVerticalOscillations: p_{r} > p^{2}"
"(defined in Gordon paper)");
throw OpalException("ClosedOrbitFinder::computeVerticalOscillations()",
"p_{r}^2 > p^{2} (defined in Gordon paper) --> Square root of negative number.");
}
// Gordon, formula (5c)
......
......@@ -1374,8 +1374,13 @@ void Distribution::CreateMatchedGaussDistribution(size_t numberOfParticles, doub
}
for (unsigned int i = 0; i < 3; ++ i) {
if ( sigma(2 * i, 2 * i) < 0 || sigma(2 * i + 1, 2 * i + 1) < 0 )
throw OpalException("Distribution::CreateMatchedGaussDistribution()", "Negative value on the diagonal of the sigma matrix.");
sigmaR_m[i] = std::sqrt(sigma(2 * i, 2 * i));
sigmaP_m[i] = std::sqrt(sigma(2 * i + 1, 2 * i + 1));
}
if (inputMoUnits_m == InputMomentumUnitsT::EV) {
......@@ -1396,6 +1401,11 @@ void Distribution::CreateMatchedGaussDistribution(size_t numberOfParticles, doub
}
else {
*gmsg << "* Not converged for " << E_m*1E-6 << " MeV" << endl;
if (siggen)
delete siggen;
throw OpalException("Distribution::CreateMatchedGaussDistribution", "didn't find any matched distribution.");
}
if (siggen)
......
......@@ -25,7 +25,6 @@
#include <list>
#include <numeric>
#include <sstream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
......@@ -739,7 +738,7 @@ void SigmaGenerator<Value_type, Size_type>::initialize(value_type nuz, value_typ
} else if (alpha >= 0) {
sig = sig0 * (1 + alpha * (0.25 - 0.03125 * alpha));
} else {
throw std::range_error("Error in SigmaGenerator::initialize: Alpha value out of range.");
throw OpalException("SigmaGenerator::initialize()", "Negative alpha value: " + std::to_string(alpha) + " < 0");
}
// K = Kx = Ky = Kz
......@@ -752,19 +751,19 @@ void SigmaGenerator<Value_type, Size_type>::initialize(value_type nuz, value_typ
// b must be positive, otherwise no real-valued frequency
if (b < 0)
throw std::domain_error("Error in SigmaGenerator::initialize: b < 0");
throw OpalException("SigmaGenerator::initialize()", "Negative value --> No real-valued frequency.");
value_type tmp = a * a - b; // [tmp] = 1/m^{4}
if (tmp < 0)
throw std::invalid_argument("Error in SigmaGenerator::initialize: a^{2} - b < 0");
throw OpalException("SigmaGenerator::initialize()", "Square root of negative number.");
tmp = std::sqrt(tmp); // [tmp] = 1/m^{2}
if (a < tmp)
throw std::invalid_argument("Error in SigmaGenerator::initialize: Square root of negative number.");
throw OpalException("Error in SigmaGenerator::initialize()", "Square root of negative number.");
if (h * h * nuz * nuz <= K)
throw std::invalid_argument("Error in SigmaGenerator::initialize: h^{2} * nu_{z}^{2} <= K (Square root of negative number)");
throw OpalException("SigmaGenerator::initialize()", "h^{2} * nu_{z}^{2} <= K (i.e. square root of negative number)");
value_type Omega = std::sqrt(a + tmp); // formula (22), [Omega] = 1/m
value_type omega = std::sqrt(a - tmp); // formula (22), [omega] = 1/m
......
#ifndef ERROR_H
#define ERROR_H
#include <cstdlib>
#include <iostream>
#include <string>
/// This class writes error messages to the terminal and stops execution
/*!
* It serves as a base class for further extensions.
*/
class Error
{
public:
/// Writes an error message to the terminal
/*!
* @param sender specifying the class where the error happened
* @param error describing the error that occurred
*/
void static message(std::string sender, std::string error) {
std::cerr << "ERROR in " << sender << ": " << error << std::endl;
std::exit(EXIT_FAILURE);
}
/// Range-access error message
static std::string range;
/// Undefined quantities
static std::string notdefined;
/// Impossible operation
static std::string invalid;
/// Wrong dimension
static std::string dim;
/// Wrong size
static std::string size;
};
std::string Error::range = "VALUE OUT OF RANGE";
std::string Error::notdefined = "VALUE NOT DEFINED";
std::string Error::invalid = "INVALID OPERATION";
std::string Error::dim = "INVALID DIMENSION";
std::string Error::size = "INVALID SIZE";
#endif
\ No newline at end of file
#ifndef PHYSICAL_ERROR_H
#define PHYSICAL_ERROR_H
#include "error.h"
/// This class writes unphysical errors to the terminal and stops execution.
/*!
* It inherits from the base class Error.
*/
class PhysicalError : public Error
{
public:
/// No stationary distribution can be found due to instability of system
static std::string match;
/// Unphysical value
static std::string negative;
/// Undefined value
static std::string undefined;
/// Unstable solution
static std::string unstable;
/// Imaginary solution
static std::string imag;
};
std::string PhysicalError::match = "MATCHING NOT POSSIBLE";
std::string PhysicalError::negative = "NEGATIVE VALUE";
std::string PhysicalError::undefined = "UNDEFINED PHYSICAL VALUE";
std::string PhysicalError::unstable = "NOT STABLE SOLUTION";
std::string PhysicalError::imag = "IMAGINARY VALUE";
#endif
\ No newline at end of file
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