Commit 1147eb79 authored by adelmann's avatar adelmann 🎗
Browse files

Merge branch 'master' of gitlab.psi.ch:OPAL/src

parents 00c6d113 2c7e95d6
......@@ -65,7 +65,7 @@ set (BOOSTROOT $ENV{BOOST_DIR})
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package (Boost 1.54.0 REQUIRED COMPONENTS filesystem system iostreams regex)
find_package (Boost 1.55.0 REQUIRED COMPONENTS filesystem system iostreams regex)
if (Boost_INCLUDE_DIRS)
message (STATUS "Found boost include dir: ${Boost_INCLUDE_DIR}")
message (STATUS "Found boost library dir: ${Boost_LIBRARY_DIR}")
......@@ -249,4 +249,4 @@ install (
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
RENAME ${PROJECT_NAME}Config.cmake
)
)
\ No newline at end of file
......@@ -52,7 +52,7 @@ set (BOOSTROOT $ENV{BOOST_DIR})
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package (Boost 1.54.0 REQUIRED COMPONENTS regex filesystem system)
find_package (Boost 1.55.0 REQUIRED COMPONENTS regex filesystem system)
if (Boost_INCLUDE_DIRS)
message (STATUS "Found boost include dir: ${Boost_INCLUDE_DIR}")
message (STATUS "Found boost library dir: ${Boost_LIBRARY_DIR}")
......
......@@ -49,7 +49,7 @@ set(Boost_USE_STATIC_LIBS ON)
set(BOOST_NO_SYSTEM_PATHS TRUE)
set(BOOST_INCLUDEDIR $ENV{BOOST_HOME})
set(BOOST_LIBRARYDIR $ENV{BOOST_HOME}}/lib)
find_package (Boost 1.54.0 REQUIRED chrono filesystem regex serialization system iostreams)
find_package (Boost 1.55.0 REQUIRED chrono filesystem regex serialization system iostreams)
if (Boost_INCLUDE_DIRS)
message (STATUS "Boost include dirs: ${Boost_INCLUDE_DIRS}")
include_directories (${Boost_INCLUDE_DIRS})
......@@ -138,4 +138,4 @@ if (DOXYGEN_FOUND)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
endif(DOXYGEN_FOUND)
\ No newline at end of file
......@@ -23,9 +23,8 @@
#include "boost/smart_ptr.hpp"
#include "boost/algorithm/string.hpp"
#ifdef BOOST_FILESYSTEM
#include "boost/filesystem/operations.hpp"
#endif
#include "boost/filesystem.hpp"
#include "boost/filesystem/operations.hpp"
// access to OPAL lib
#include "opal.h"
......@@ -41,12 +40,15 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
, constraints_(constraints)
, comm_(comm)
{
namespace fs = boost::filesystem;
if(getenv("SIMTMPDIR") == NULL) {
std::cout << "Environment variable SIMTMPDIR not defined!"
<< std::endl;
simTmpDir_ = getenv("PWD");
} else
simTmpDir_ = getenv("SIMTMPDIR");
simulationName_ = name;
// prepare design variables given by the optimizer for generating the
......@@ -64,7 +66,7 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
userVariables_.insert(
std::pair<std::string, std::string>(parameter.first, value.str()));
}
/*
This is a copy from Comm/Splitter/ManyMasterSplit.h
in order to calculate the leader which is the unique ID in case
......@@ -78,7 +80,7 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
unsigned num_coworkers_worker_ = 0;
num_coworkers_worker_ = args->getArg<size_t>("num-coworkers");
unsigned group_start = 0;
unsigned worker_group = ((my_rank % world_size) - 2) / num_coworkers_worker_;
......@@ -91,8 +93,8 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
std::string hash = HashNameGenerator::generate(dict);
std::ostringstream tmp;
tmp.precision(15);
tmp << simTmpDir_ << "/" << hash << "_" << leader_;
tmp << simTmpDir_ << "/" << hash << "_" << leader_;
simulationDirName_ = tmp.str();
......@@ -104,6 +106,12 @@ OpalSimulation::OpalSimulation(Expressions::Named_t objectives,
std::string tmplFile = tmplDir + "/" + simulationName_ + ".tmpl";
// data file is assumed to be located in the root directory
std::string dataFile = simulationName_ + ".data";
if (!fs::exists(dataFile))
throw OptPilotException("OpalSimulation::OpalSimulation", "The data file '" + dataFile + "' doesn't exist");
if (!fs::exists(tmplFile))
throw OptPilotException("OpalSimulation::OpalSimulation", "The template file '" + tmplFile + "' doesn't exit");
gs_.reset(new GenerateOpalSimulation(tmplFile, dataFile, userVariables_));
}
......@@ -147,7 +155,7 @@ void OpalSimulation::setupSimulation() {
"Environment variable FIELDMAPS not defined!");
}
std::string fieldmapPath = getenv("FIELDMAPS");
struct dirent **files;
int count = scandir(fieldmapPath.c_str(), &files, 0, alphasort);
......@@ -201,7 +209,7 @@ void OpalSimulation::restoreOut() {
void OpalSimulation::run() {
// make sure input file is not already existing
MPI_Barrier(comm_);
if( hasResultsAvailable() ) return;
......@@ -411,7 +419,7 @@ bool OpalSimulation::getVariableDictionary(variableDictionary_t& dictionary,
} catch(OptPilotException &e) {
std::cout << "Exception while parsing SDDS file: "
<< e.what() << std::endl;
//XXX: in this case we mark the bunch as invalid since
// broken stat files can crash opt (why do they
// exist?)
......@@ -422,7 +430,7 @@ bool OpalSimulation::getVariableDictionary(variableDictionary_t& dictionary,
// get all the required variable values from the stat file
for(std::string req_var : req_vars) {
if(dictionary.count(req_var) != 0) continue;
try {
double value = 0.0;
sddsr->getValue(-1 /*atTime*/, req_var, value);
......@@ -458,4 +466,4 @@ void OpalSimulation::cleanUp() {
}
#endif
}
}
\ No newline at end of file
......@@ -313,6 +313,7 @@ void Bend::initialise(PartBunchBase<double, 3> *bunch,
endField_m -= elementEdge_m;
elementEdge_m = 0.0;
setupFringeWidths();
msg << level2
<< "======================================================================\n"
<< "======================================================================\n"
......@@ -339,6 +340,7 @@ void Bend::adjustFringeFields(double ratio) {
delta = std::abs(exitParameter2_m - exitParameter3_m);
exitParameter3_m = exitParameter2_m + delta * ratio;
setupFringeWidths();
}
double Bend::calculateBendAngle() {
......@@ -1081,6 +1083,7 @@ void Bend::readFieldMap(Inform &msg) {
fieldmap_m->get1DProfile1ExitParam(exitParameter1_m,
exitParameter2_m,
exitParameter3_m);
setGapFromFieldMap();
fieldmap_m->get1DProfile1EngeCoeffs(engeCoeffsEntry_m,
engeCoeffsExit_m);
......@@ -1209,6 +1212,8 @@ void Bend::setEngeOriginDelta(double delta) {
exitParameter1_m = -delta - std::abs(exitParameter1_m - exitParameter2_m);
exitParameter3_m = -delta + std::abs(exitParameter2_m - exitParameter3_m);
exitParameter2_m = -delta;
setupFringeWidths();
}
void Bend::setFieldCalcParam() {
......@@ -1503,11 +1508,11 @@ std::vector<Vector_t> Bend::getOutline() const {
Vector_t rotationCenter = Vector_t(-designRadius_m * cosEntranceAngle_m, 0.0, designRadius_m * sinEntranceAngle_m);
unsigned int numSteps = 2;
outline.push_back(Vector_t(-aperture_m.second[0], 0.0, 0.0));
outline.push_back(Vector_t(-aperture_m.second[0] + entranceParameter1_m * tanEntranceAngle_m, 0.0, entranceParameter1_m));
outline.push_back(Vector_t(-0.5 * widthEntranceFringe_m, 0.0, 0.0));
outline.push_back(Vector_t(-0.5 * widthEntranceFringe_m + entranceParameter1_m * tanEntranceAngle_m, 0.0, entranceParameter1_m));
outline.push_back(Vector_t(entranceParameter1_m * tanEntranceAngle_m, 0.0, entranceParameter1_m));
outline.push_back(Vector_t(aperture_m.second[0] + entranceParameter1_m * tanEntranceAngle_m, 0.0, entranceParameter1_m));
outline.push_back(Vector_t(aperture_m.second[0], 0.0, 0.0));
outline.push_back(Vector_t(0.5 * widthEntranceFringe_m + entranceParameter1_m * tanEntranceAngle_m, 0.0, entranceParameter1_m));
outline.push_back(Vector_t(0.5 * widthEntranceFringe_m, 0.0, 0.0));
{
double tau1, tau2;
......@@ -1544,11 +1549,11 @@ std::vector<Vector_t> Bend::getOutline() const {
outline.push_back(upperCornerAtExit);
}
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(aperture_m.second[0], 0.0, 0.0)));
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(aperture_m.second[0] - exitParameter3_m * tanExitAngle_m, 0.0, exitParameter3_m)));
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(0.5 * widthExitFringe_m, 0.0, 0.0)));
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(0.5 * widthExitFringe_m - exitParameter3_m * tanExitAngle_m, 0.0, exitParameter3_m)));
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(-exitParameter3_m * tanExitAngle_m, 0.0, exitParameter3_m)));
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(-aperture_m.second[0] - exitParameter3_m * tanExitAngle_m, 0.0, exitParameter3_m)));
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(-aperture_m.second[0], 0.0, 0.0)));
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(-0.5 * widthExitFringe_m - exitParameter3_m * tanExitAngle_m, 0.0, exitParameter3_m)));
outline.push_back(getBeginToEnd_local().transformFrom(Vector_t(-0.5 * widthExitFringe_m, 0.0, 0.0)));
{
double tau1, tau2;
......@@ -1782,4 +1787,10 @@ bool Bend::isInside(const Vector_t &R) const {
}
return (std::abs(R(1)) < 0.5 * gap_m && inMagnetCentralRegion(R));
}
void Bend::setupFringeWidths()
{
widthEntranceFringe_m = 2 * std::min(entranceParameter3_m - entranceParameter1_m, aperture_m.second[0]) + aperture_m.second[0];
widthExitFringe_m = 2 * std::min(exitParameter3_m - exitParameter1_m, aperture_m.second[0]) + aperture_m.second[0];
}
\ No newline at end of file
......@@ -158,6 +158,7 @@ private:
double deltaX);
Vector_t calcExitFringeField(const Vector_t &R,
double deltaX);
void setupFringeWidths();
bool calculateMapField(const Vector_t &R,
Vector_t &B);
void calculateRefTrajectory(double &angleX,
......@@ -215,6 +216,9 @@ private:
double startField_m; /// Start of magnet field map in s coordinates (m).
double endField_m; /// End of magnet field map in s coordinates (m).
double widthEntranceFringe_m;
double widthExitFringe_m;
/*
* Flag to reinitialize the bend the first time the magnet
* is called. This redefines the design energy of the bend
......
......@@ -839,13 +839,14 @@ void MeshGenerator::write(const std::string &fname) {
out << "parser = argparse.ArgumentParser()\n";
out << "parser.add_argument('--export-vtk', action='store_true')\n";
out << "parser.add_argument('--export-web', action='store_true')\n";
out << "parser.add_argument('--background', nargs=3, type=float)\n";
out << "parser.add_argument('--project-to-plane', action='store_true')\n";
out << "parser.add_argument('--normal', nargs=3, type=float)\n";
out << "parser.add_argument('--background', nargs=3, type=float)\n";
out << "args = parser.parse_args()\n\n";
out << "if (args.export_vtk):\n";
out << indent << "exportVTK()\n\n";
out << indent << "exportVTK()\n";
out << indent << "sys.exit()\n\n";
out << "if (args.export_web):\n";
out << indent << "bgcolor = []\n";
......@@ -857,11 +858,17 @@ void MeshGenerator::write(const std::string &fname) {
out << indent << indent << indent << indent << "break\n";
out << indent << indent << "if (validBackground):\n";
out << indent << indent << indent << "bgcolor = args.background\n";
out << indent << "exportWeb(bgcolor)\n\n";
out << indent << "exportWeb(bgcolor)\n";
out << indent << "sys.exit()\n\n";
out << "if (args.project_to_plane):\n";
out << indent << "projectToPlane(args.project_to_plane)";
out << indent << "normal = [0.0, 1.0, 0.0]\n";
out << indent << "if (args.normal):\n";
out << indent << indent << "normal = args.normal\n";
out << indent << "projectToPlane(normal)\n";
out << indent << "sys.exit()\n\n";
out << "parser.print_help()\n";
}
MeshData MeshGenerator::getCylinder(double length,
......
......@@ -172,10 +172,11 @@ void TrackRun::execute() {
errorMsg << it->second << endl;
}
}
errorMsg << "\nMake sure you do understand these changes and adjust your input file \n"
<< "accordingly. Then add\n"
<< "OPTION, VERSION = " << currentVersion << ";\n"
<< "to your input file. " << endl;
errorMsg << "\n"
<< "* Make sure you do understand these changes and adjust your input file \n"
<< "* accordingly. Then add\n"
<< "* OPTION, VERSION = " << currentVersion << ";\n"
<< "* to your input file. " << endl;
errorMsg << "\n****************************************************************************\n" << endl;
throw OpalException("TrackRun::execute", "Version mismatch");
}
......@@ -930,4 +931,4 @@ double TrackRun::setDistributionParallelT(Beam *beam) {
// Return charge per macroparticle.
return beam->getCharge() * beam->getCurrent() / (beam->getFrequency()*1.0e6) / numberOfParticles;
}
}
\ No newline at end of file
......@@ -11,6 +11,9 @@ namespace Versions {
"* The normalization of the 2-dimensional field maps has changed.\n"
" Instead of normalizing with the overall maximum value of longitudinal\n"
" component Opal now uses the maximum value on axis.\n"
"\n"
"* The parser has been modified to check the type of all variables. All real \n"
" variables have to be prefixed with the keyword REAL.\n"
});
changes.insert({109,
......@@ -23,17 +26,15 @@ namespace Versions {
"\n"
"* OPAL-T: The design energy of dipoles is now expected to be in MeV instead\n"
" of eV.\n"
"\n"
"* OPAL-T: The attribute 'ROTATION' of RBEND and SBEND have been replaced\n"
" by 'PSI'. Can be applyied to all elements to rotate them.\n"
"\n"
" The attribute DISTRIBUTION of the command DISTRIBUTION has been renamed to\n"
" TYPE.\n"
"\n"
" The parser has been modified to check the type of all variables. All real \n"
" variables have to be prefixed with the keyword REAL.\n"
"* The attribute DISTRIBUTION of the command DISTRIBUTION has been renamed to\n"
" TYPE.\n"
"\n"
" The string indicating the orientation (sofar always XYZ) of 3D fieldmaps has\n"
" been dropped.\n"
"* The string indicating the orientation (sofar always XYZ) of 3D fieldmaps has\n"
" been dropped.\n"
});
}
}
\ 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