Commit aaa50e79 authored by kraus's avatar kraus

possibly fixing some memory leaks (thats what valgrind thinks anyway)

parent c6362dcc
......@@ -349,8 +349,8 @@ classic/5.0/src/Fields/FM3DDynamic.cpp -text
classic/5.0/src/Fields/FM3DDynamic.hh -text
classic/5.0/src/Fields/FM3DH5Block.cpp -text
classic/5.0/src/Fields/FM3DH5Block.hh -text
classic/5.0/src/Fields/FM3DH5Block_nonescale.cpp -text
classic/5.0/src/Fields/FM3DH5Block_nonescale.hh -text
classic/5.0/src/Fields/FM3DH5Block_nonscale.cpp -text
classic/5.0/src/Fields/FM3DH5Block_nonscale.hh -text
classic/5.0/src/Fields/FM3DMagnetoStaticH5Block.cpp -text
classic/5.0/src/Fields/FM3DMagnetoStaticH5Block.hh -text
classic/5.0/src/Fields/FMDummy.cpp -text
......
......@@ -54,13 +54,12 @@ VariableRFCavity& VariableRFCavity::operator=(const VariableRFCavity& rhs) {
setAmplitudeModel(NULL);
setFrequencyModel(NULL);
if (rhs._phase_td != NULL)
setPhaseModel(rhs._phase_td->clone());
setPhaseModel(std::shared_ptr<AbstractTimeDependence>(rhs._phase_td->clone()));
if (rhs._amplitude_td != NULL) {
AbstractTimeDependence* new_amp = rhs._amplitude_td->clone();
setAmplitudeModel(new_amp);
setAmplitudeModel(std::shared_ptr<AbstractTimeDependence>(rhs._amplitude_td->clone()));
}
if (rhs._frequency_td != NULL)
setFrequencyModel(rhs._frequency_td->clone());
setFrequencyModel(std::shared_ptr<AbstractTimeDependence>(rhs._frequency_td->clone()));
phaseName_m = rhs.phaseName_m;
amplitudeName_m = rhs.amplitudeName_m;
frequencyName_m = rhs.frequencyName_m;
......@@ -71,19 +70,19 @@ VariableRFCavity& VariableRFCavity::operator=(const VariableRFCavity& rhs) {
}
VariableRFCavity::~VariableRFCavity() {
if (_phase_td != NULL)
delete _phase_td;
if (_amplitude_td != NULL)
delete _amplitude_td;
if (_frequency_td != NULL)
delete _frequency_td;
// if (_phase_td != NULL)
// delete _phase_td;
// if (_amplitude_td != NULL)
// delete _amplitude_td;
// if (_frequency_td != NULL)
// delete _frequency_td;
}
void VariableRFCavity::initNull() {
_length = 0.;
_phase_td = NULL;
_amplitude_td = NULL;
_frequency_td = NULL;
// _phase_td = NULL;
// _amplitude_td = NULL;
// _frequency_td = NULL;
phaseName_m = "";
amplitudeName_m = "";
frequencyName_m = "";
......@@ -92,33 +91,33 @@ void VariableRFCavity::initNull() {
RefPartBunch_m = NULL;
}
AbstractTimeDependence* VariableRFCavity::getAmplitudeModel() const {
std::shared_ptr<AbstractTimeDependence> VariableRFCavity::getAmplitudeModel() const {
return _amplitude_td;
}
AbstractTimeDependence* VariableRFCavity::getPhaseModel() const {
std::shared_ptr<AbstractTimeDependence> VariableRFCavity::getPhaseModel() const {
return _phase_td;
}
AbstractTimeDependence* VariableRFCavity::getFrequencyModel() const {
std::shared_ptr<AbstractTimeDependence> VariableRFCavity::getFrequencyModel() const {
return _frequency_td;
}
void VariableRFCavity::setAmplitudeModel(AbstractTimeDependence* amplitude_td) {
if (_amplitude_td != NULL && amplitude_td != _amplitude_td)
delete _amplitude_td;
void VariableRFCavity::setAmplitudeModel(std::shared_ptr<AbstractTimeDependence> amplitude_td) {
// if (_amplitude_td != NULL && amplitude_td != _amplitude_td)
// delete _amplitude_td;
_amplitude_td = amplitude_td;
}
void VariableRFCavity::setPhaseModel(AbstractTimeDependence* phase_td) {
if (_phase_td != NULL && phase_td != _phase_td)
delete _phase_td;
void VariableRFCavity::setPhaseModel(std::shared_ptr<AbstractTimeDependence> phase_td) {
// if (_phase_td != NULL && phase_td != _phase_td)
// delete _phase_td;
_phase_td = phase_td;
}
void VariableRFCavity::setFrequencyModel(AbstractTimeDependence* frequency_td) {
if (_frequency_td != NULL && frequency_td != _frequency_td)
delete _frequency_td;
void VariableRFCavity::setFrequencyModel(std::shared_ptr<AbstractTimeDependence> frequency_td) {
// if (_frequency_td != NULL && frequency_td != _frequency_td)
// delete _frequency_td;
_frequency_td = frequency_td;
}
......@@ -198,15 +197,15 @@ ElementBase* VariableRFCavity::clone() const {
void VariableRFCavity::accept(BeamlineVisitor& visitor) const {
VariableRFCavity* cavity = const_cast<VariableRFCavity*>(this);
AbstractTimeDependence* phaseTD =
std::shared_ptr<AbstractTimeDependence> phaseTD =
AbstractTimeDependence::getTimeDependence(phaseName_m);
cavity->setPhaseModel(phaseTD->clone());
AbstractTimeDependence* frequencyTD =
cavity->setPhaseModel(std::shared_ptr<AbstractTimeDependence>(phaseTD->clone()));
std::shared_ptr<AbstractTimeDependence> frequencyTD =
AbstractTimeDependence::getTimeDependence(frequencyName_m);
cavity->setFrequencyModel(frequencyTD->clone());
AbstractTimeDependence* amplitudeTD =
cavity->setFrequencyModel(std::shared_ptr<AbstractTimeDependence>(frequencyTD->clone()));
std::shared_ptr<AbstractTimeDependence> amplitudeTD =
AbstractTimeDependence::getTimeDependence(amplitudeName_m);
cavity->setAmplitudeModel(amplitudeTD->clone());
cavity->setAmplitudeModel(std::shared_ptr<AbstractTimeDependence>(amplitudeTD->clone()));
visitor.visitVariableRFCavity(*this);
if (halfHeight_m < 1e-9 || halfWidth_m < 1e-9)
......
/*
/*
* Copyright (c) 2014, Chris Rogers
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STFC nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* 3. Neither the name of STFC nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
......@@ -37,7 +37,7 @@ class Fieldmap;
/** Class VariableRFCavity
*
* Generates a field like
* Generates a field like
* E = E0(x, y, z)*a(t)*sin{f(t)*t-q(t)}
* B = B0(x, y, z)*a(t)*cos{f(t)*t-q(t)}
* where E0, B0 are user defined field maps, a(t), f(t), q(t) are time
......@@ -73,17 +73,17 @@ class VariableRFCavity: public Component {
virtual double getHeight() const {return halfHeight_m*2;}
virtual double getWidth() const {return halfWidth_m*2;}
virtual void setHeight(double fullHeight) {halfHeight_m = fullHeight/2;}
virtual void setHeight(double fullHeight) {halfHeight_m = fullHeight/2;}
virtual void setWidth(double fullWidth) {halfWidth_m = fullWidth/2;}
virtual AbstractTimeDependence* getAmplitudeModel() const;
virtual AbstractTimeDependence* getPhaseModel() const;
virtual AbstractTimeDependence* getFrequencyModel() const;
virtual std::shared_ptr<AbstractTimeDependence> getAmplitudeModel() const;
virtual std::shared_ptr<AbstractTimeDependence> getPhaseModel() const;
virtual std::shared_ptr<AbstractTimeDependence> getFrequencyModel() const;
virtual void setAmplitudeModel(AbstractTimeDependence* time_dep);
virtual void setPhaseModel(AbstractTimeDependence* time_dep);
virtual void setFrequencyModel(AbstractTimeDependence* time_dep);
virtual void setAmplitudeModel(std::shared_ptr<AbstractTimeDependence> time_dep);
virtual void setPhaseModel(std::shared_ptr<AbstractTimeDependence> time_dep);
virtual void setFrequencyModel(std::shared_ptr<AbstractTimeDependence> time_dep);
virtual void setAmplitudeName(std::string amplitude)
{ amplitudeName_m = amplitude; }
......@@ -103,9 +103,9 @@ class VariableRFCavity: public Component {
/// Not implemented
virtual const EMField &getField() const;
protected:
AbstractTimeDependence* _phase_td;
AbstractTimeDependence* _amplitude_td;
AbstractTimeDependence* _frequency_td;
std::shared_ptr<AbstractTimeDependence> _phase_td;
std::shared_ptr<AbstractTimeDependence> _amplitude_td;
std::shared_ptr<AbstractTimeDependence> _frequency_td;
std::string phaseName_m;
std::string amplitudeName_m;
std::string frequencyName_m;
......
......@@ -3,10 +3,10 @@
#include <sstream>
std::map<std::string, AbstractTimeDependence*> AbstractTimeDependence::td_map =
std::map<std::string, AbstractTimeDependence*>();
std::map<std::string, std::shared_ptr<AbstractTimeDependence> > AbstractTimeDependence::td_map =
std::map<std::string, std::shared_ptr<AbstractTimeDependence> >();
AbstractTimeDependence* AbstractTimeDependence::getTimeDependence(std::string name) {
std::shared_ptr<AbstractTimeDependence> AbstractTimeDependence::getTimeDependence(std::string name) {
if (td_map.find(name) != td_map.end()) {
return td_map[name];
} else {
......@@ -16,15 +16,15 @@ AbstractTimeDependence* AbstractTimeDependence::getTimeDependence(std::string na
}
void AbstractTimeDependence::setTimeDependence(std::string name,
AbstractTimeDependence* time_dep) {
if (td_map.find(name) != td_map.end()) {
delete td_map[name];
}
std::shared_ptr<AbstractTimeDependence> time_dep) {
// if (td_map.find(name) != td_map.end()) {
// delete td_map[name];
// }
td_map[name] = time_dep;
}
std::string AbstractTimeDependence::getName(AbstractTimeDependence* time_dep) {
typedef std::map<std::string, AbstractTimeDependence*>::iterator iter;
std::string AbstractTimeDependence::getName(std::shared_ptr<AbstractTimeDependence> time_dep) {
typedef std::map<std::string, std::shared_ptr<AbstractTimeDependence> >::iterator iter;
for (iter i = td_map.begin(); i != td_map.end(); ++i) {
if (i->second == time_dep)
return i->first;
......
......@@ -3,6 +3,7 @@
#include <string>
#include <map>
#include <memory>
/** Time dependence abstraction for field parameters that vary slowly with time
*/
......@@ -13,16 +14,16 @@ class AbstractTimeDependence {
virtual AbstractTimeDependence* clone() = 0;
virtual double getValue(double time) = 0;
static AbstractTimeDependence* getTimeDependence(std::string name);
static std::shared_ptr<AbstractTimeDependence> getTimeDependence(std::string name);
static void setTimeDependence(std::string name,
AbstractTimeDependence* time_dep);
std::shared_ptr<AbstractTimeDependence> time_dep);
/** Reverse the mapping - slow
*/
static std::string getName(AbstractTimeDependence* time_dep);
static std::string getName(std::shared_ptr<AbstractTimeDependence> time_dep);
private:
static std::map<std::string, AbstractTimeDependence*> td_map;
static std::map<std::string, std::shared_ptr<AbstractTimeDependence> > td_map;
};
#endif
......@@ -12,7 +12,7 @@ set (_SRCS
StaticMagneticField.cpp
Fieldmap.cpp
FM3DH5Block.cpp
FM3DH5Block_nonescale.cpp
FM3DH5Block_nonscale.cpp
FM3DMagnetoStaticH5Block.cpp
FM3DDynamic.cpp
FM2DElectroStatic.cpp
......
#include "Fields/FM3DH5Block_nonescale.hh"
#include "Fields/FM3DH5Block_nonscale.hh"
#include "Fields/Fieldmap.icc"
#include "H5hut.h"
#include "Physics/Physics.h"
......@@ -11,7 +11,7 @@ extern Inform *gmsg;
using namespace std;
using Physics::mu_0;
FM3DH5Block_nonescale::FM3DH5Block_nonescale(std::string aFilename):
FM3DH5Block_nonscale::FM3DH5Block_nonscale(std::string aFilename):
Fieldmap(aFilename) {
Inform msg("FM3DH5 ");
h5_err_t h5err;
......@@ -72,11 +72,11 @@ FM3DH5Block_nonescale::FM3DH5Block_nonescale(std::string aFilename):
}
FM3DH5Block_nonescale::~FM3DH5Block_nonescale() {
FM3DH5Block_nonscale::~FM3DH5Block_nonscale() {
}
void FM3DH5Block_nonescale::readMap() {
void FM3DH5Block_nonscale::readMap() {
if(FieldstrengthEz_m.empty()) {
Inform msg("FM3DH5_NS ");
h5_file_t *file = H5OpenFile(Filename_m.c_str(), H5_O_RDONLY, Ippl::getComm());
......@@ -179,7 +179,7 @@ void FM3DH5Block_nonescale::readMap() {
}
}
void FM3DH5Block_nonescale::freeMap() {
void FM3DH5Block_nonscale::freeMap() {
if(!FieldstrengthEz_m.empty()) {
Inform msg("FM3DH5_NS ");
FieldstrengthEx_m.clear();
......@@ -194,7 +194,7 @@ void FM3DH5Block_nonescale::freeMap() {
}
}
bool FM3DH5Block_nonescale::getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const {
bool FM3DH5Block_nonscale::getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const {
const int index_x = static_cast<int>(floor((R(0) - xbegin_m) / hx_m));
const double lever_x = (R(0) - xbegin_m) / hx_m - index_x;
......@@ -276,33 +276,33 @@ bool FM3DH5Block_nonescale::getFieldstrength(const Vector_t &R, Vector_t &E, Vec
return false;
}
bool FM3DH5Block_nonescale::getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const {
bool FM3DH5Block_nonscale::getFieldDerivative(const Vector_t &R, Vector_t &E, Vector_t &B, const DiffDirection &dir) const {
return false;
}
void FM3DH5Block_nonescale::getFieldDimensions(double &zBegin, double &zEnd, double &rBegin, double &rEnd) const {
void FM3DH5Block_nonscale::getFieldDimensions(double &zBegin, double &zEnd, double &rBegin, double &rEnd) const {
zBegin = zbegin_m;
zEnd = zend_m;
rBegin = xbegin_m;
rEnd = xend_m;
}
void FM3DH5Block_nonescale::getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const {}
void FM3DH5Block_nonscale::getFieldDimensions(double &xIni, double &xFinal, double &yIni, double &yFinal, double &zIni, double &zFinal) const {}
void FM3DH5Block_nonescale::swap() { }
void FM3DH5Block_nonscale::swap() { }
void FM3DH5Block_nonescale::getInfo(Inform *msg) {
void FM3DH5Block_nonscale::getInfo(Inform *msg) {
(*msg) << Filename_m << " (3D dynamic); zini= " << zbegin_m << " m; zfinal= " << zend_m << " m;" << endl;
}
double FM3DH5Block_nonescale::getFrequency() const {
double FM3DH5Block_nonscale::getFrequency() const {
return frequency_m;
}
void FM3DH5Block_nonescale::setFrequency(double freq) {
void FM3DH5Block_nonscale::setFrequency(double freq) {
frequency_m = freq;
}
void FM3DH5Block_nonescale::getOnaxisEz(vector<pair<double, double> > & F) {
void FM3DH5Block_nonscale::getOnaxisEz(vector<pair<double, double> > & F) {
double Ez_max = 0.0, dz = (zend_m - zbegin_m) / (num_gridpz_m - 1);
const int index_x = -static_cast<int>(floor(xbegin_m / hx_m));
const double lever_x = -xbegin_m / hx_m - index_x;
......
#ifndef CLASSIC_FIELDMAP3DH5BLOCK_nonescale_HH
#define CLASSIC_FIELDMAP3DH5BLOCK_nonescale_HH
#ifndef CLASSIC_FIELDMAP3DH5BLOCK_nonscale_HH
#define CLASSIC_FIELDMAP3DH5BLOCK_nonscale_HH
#include "Fields/Fieldmap.hh"
#include "hdf5.h"
#include "H5hut.h"
class FM3DH5Block_nonescale: public Fieldmap {
class FM3DH5Block_nonscale: public Fieldmap {
public:
virtual bool getFieldstrength(const Vector_t &R, Vector_t &E, Vector_t &B) const;
......@@ -19,8 +19,8 @@ public:
virtual void getOnaxisEz(std::vector<std::pair<double, double> > & F);
private:
FM3DH5Block_nonescale(std::string aFilename);
~FM3DH5Block_nonescale();
FM3DH5Block_nonscale(std::string aFilename);
~FM3DH5Block_nonscale();
virtual void readMap();
virtual void freeMap();
......
#include "Fields/Fieldmap.hh"
#include "Fields/FM3DDynamic.hh"
#include "Fields/FM3DH5Block.hh"
#include "Fields/FM3DH5Block_nonescale.hh"
#include "Fields/FM3DH5Block_nonscale.hh"
#include "Fields/FM3DMagnetoStaticH5Block.hh"
#include "Fields/FM2DDynamic.hh"
#include "Fields/FM2DDynamic_cspline.hh"
......@@ -139,7 +139,7 @@ Fieldmap *Fieldmap::getFieldmap(std::string Filename, bool fast) {
break;
case T3DDynamicH5Block:
if(fast) {
position = FieldmapDictionary.insert(std::pair<std::string, FieldmapDescription>(Filename, FieldmapDescription(T3DDynamic, new FM3DH5Block_nonescale(Filename))));
position = FieldmapDictionary.insert(std::pair<std::string, FieldmapDescription>(Filename, FieldmapDescription(T3DDynamic, new FM3DH5Block_nonscale(Filename))));
} else {
position = FieldmapDictionary.insert(std::pair<std::string, FieldmapDescription>(Filename, FieldmapDescription(T3DDynamic, new FM3DH5Block(Filename))));
}
......@@ -186,6 +186,15 @@ void Fieldmap::deleteFieldmap(std::string Filename) {
}
}
void Fieldmap::clearDictionary() {
std::map<std::string, FieldmapDescription>::iterator it = FieldmapDictionary.begin();
for (;it != FieldmapDictionary.end(); ++ it) {
delete it->second.Map;
it->second.Map = NULL;
}
FieldmapDictionary.clear();
}
MapType Fieldmap::readHeader(std::string Filename) {
char magicnumber[5] = " ";
std::string buffer;
......
......@@ -60,6 +60,7 @@ public:
static Fieldmap *getFieldmap(std::string Filename, bool fast = false);
static std::vector<std::string> getListFieldmapNames();
static void deleteFieldmap(std::string Filename);
static void clearDictionary();
static MapType readHeader(std::string Filename);
static void readMap(std::string Filename);
static void freeMap(std::string Filename);
......
......@@ -60,13 +60,13 @@ void ParallelSliceTracker::updateRFElement(std::string elName, double maxPhi) {
for (FieldList::iterator fit = cl.begin(); fit != cl.end(); ++fit) {
if ((*fit).getElement()->getName() == elName) {
if ((*fit).getElement()->getType() == "TravelingWave") {
phi = static_cast<TravelingWave *>((*fit).getElement())->getPhasem();
phi = static_cast<TravelingWave *>((*fit).getElement().get())->getPhasem();
phi += maxPhi;
static_cast<TravelingWave *>((*fit).getElement())->setPhasem(phi);
static_cast<TravelingWave *>((*fit).getElement().get())->setPhasem(phi);
} else {
phi = static_cast<RFCavity *>((*fit).getElement())->getPhasem();
phi = static_cast<RFCavity *>((*fit).getElement().get())->getPhasem();
phi += maxPhi;
static_cast<RFCavity *>((*fit).getElement())->setPhasem(phi);
static_cast<RFCavity *>((*fit).getElement().get())->setPhasem(phi);
}
}
}
......@@ -92,15 +92,15 @@ void ParallelSliceTracker::updateAllRFElements() {
for (FieldList::iterator it = cl.begin(); it != cl.end(); ++it) {
if ((*it).getElement()->getType() == "TravelingWave") {
const double apphi = getCavityPhase(cavities_m, (*it).getElement()->getName());
static_cast<TravelingWave *>((*it).getElement())->updatePhasem(apphi);
const double freq = static_cast<TravelingWave *>((*it).getElement())->getFrequencym();
static_cast<TravelingWave *>((*it).getElement().get())->updatePhasem(apphi);
const double freq = static_cast<TravelingWave *>((*it).getElement().get())->getFrequencym();
msg << (*it).getElement()->getName()
<< ": phi= phi_nom + phi_maxE + global phase shift= " << (apphi*RADDEG)-(phiShift*freq*RADDEG) << " degree, "
<< "(global phase shift= " << -phiShift *freq *RADDEG << " degree) \n";
} else {
const double apphi = getCavityPhase(cavities_m, (*it).getElement()->getName());
static_cast<RFCavity *>((*it).getElement())->updatePhasem(apphi+phiShift);
const double freq = static_cast<RFCavity *>((*it).getElement())->getFrequencym();
static_cast<RFCavity *>((*it).getElement().get())->updatePhasem(apphi+phiShift);
const double freq = static_cast<RFCavity *>((*it).getElement().get())->getFrequencym();
msg << (*it).getElement()->getName()
<< ": phi= phi_nom + phi_maxE + global phase shift= " << (apphi*RADDEG)-(phiShift*freq*RADDEG) << " degree, "
<< "(global phase shift= " << -phiShift *freq *RADDEG << "(degree) \n";
......@@ -116,9 +116,9 @@ double ParallelSliceTracker::getCavityPhase(FieldList cav, std::string name) {
for (FieldList::iterator fit = cav.begin(); fit != cav.end(); ++fit) {
if ((*fit).getElement()->getName() == name) {
if ((*fit).getElement()->getType() == "TravelingWave")
phi = static_cast<TravelingWave *>((*fit).getElement())->getPhasem();
phi = static_cast<TravelingWave *>((*fit).getElement().get())->getPhasem();
else
phi = static_cast<RFCavity *>((*fit).getElement())->getPhasem();
phi = static_cast<RFCavity *>((*fit).getElement().get())->getPhasem();
}
}
return phi;
......
......@@ -732,7 +732,7 @@ void ParallelTTracker::checkCavity(double s, Component *& comp, double & cavity_
for(FieldList::iterator fit = cavities_m.begin(); fit != cavities_m.end(); ++ fit) {
if((fit != currently_ap_cavity_m)
&& ((*fit).getStart() <= s) && (s <= (*fit).getEnd())) {
comp = (*fit).getElement();
comp = (*fit).getElement().get();
cavity_start_pos = (*fit).getStart();
currently_ap_cavity_m = fit;
return;
......@@ -790,9 +790,9 @@ void ParallelTTracker::showCavities(Inform &msg) {
<< " from " << (*fit).getStart() << " to "
<< (*fit).getEnd() << " (m) phi=";
if((*fit).getElement()->getType() == "TravelingWave")
msg << static_cast<TravelingWave *>((*fit).getElement())->getPhasem() / Physics::pi * 180.0 << endl;
msg << static_cast<TravelingWave *>((*fit).getElement().get())->getPhasem() / Physics::pi * 180.0 << endl;
else
msg << static_cast<RFCavity *>((*fit).getElement())->getPhasem() / Physics::pi * 180.0 << endl;
msg << static_cast<RFCavity *>((*fit).getElement().get())->getPhasem() / Physics::pi * 180.0 << endl;
}
msg << endl << endl;
}
......@@ -808,13 +808,13 @@ void ParallelTTracker::updateRFElement(std::string elName, double maxPhi) {
for(FieldList::iterator fit = cavities_m.begin(); fit != cavities_m.end(); ++ fit) {
if((*fit).getElement()->getName() == elName) {
if((*fit).getElement()->getType() == "TravelingWave") {
phi = static_cast<TravelingWave *>((*fit).getElement())->getPhasem();
phi = static_cast<TravelingWave *>((*fit).getElement().get())->getPhasem();
phi += maxPhi;
static_cast<TravelingWave *>((*fit).getElement())->updatePhasem(phi);
static_cast<TravelingWave *>((*fit).getElement().get())->updatePhasem(phi);
} else {
phi = static_cast<RFCavity *>((*fit).getElement())->getPhasem();
phi = static_cast<RFCavity *>((*fit).getElement().get())->getPhasem();
phi += maxPhi;
static_cast<RFCavity *>((*fit).getElement())->updatePhasem(phi);
static_cast<RFCavity *>((*fit).getElement().get())->updatePhasem(phi);
}
}
}
......@@ -836,21 +836,21 @@ void ParallelTTracker::updateAllRFElements(double phiShift) {
if(fit != cavities_m.begin())
msg << "\n";
if((*fit).getElement()->getType() == "TravelingWave") {
freq = static_cast<TravelingWave *>((*fit).getElement())->getFrequencym();
phi = static_cast<TravelingWave *>((*fit).getElement())->getPhasem();
freq = static_cast<TravelingWave *>((*fit).getElement().get())->getFrequencym();
phi = static_cast<TravelingWave *>((*fit).getElement().get())->getPhasem();
msg << (*fit).getElement()->getName()
<< ": phi= phi_nom + phi_maxE + global phase shift= " << (phi*RADDEG)-(phiShift*freq*RADDEG) << " degree, "
<< "(global phase shift= " << -phiShift *freq *RADDEG << " degree)\n";
phi -= (phiShift * freq);
static_cast<TravelingWave *>((*fit).getElement())->updatePhasem(phi);
static_cast<TravelingWave *>((*fit).getElement().get())->updatePhasem(phi);
} else {
freq = static_cast<RFCavity *>((*fit).getElement())->getFrequencym();
phi = static_cast<RFCavity *>((*fit).getElement())->getPhasem();
freq = static_cast<RFCavity *>((*fit).getElement().get())->getFrequencym();
phi = static_cast<RFCavity *>((*fit).getElement().get())->getPhasem();
msg << (*fit).getElement()->getName()
<< ": phi= phi_nom + phi_maxE + global phase shift= " << (phi*RADDEG)-(phiShift*freq*RADDEG) << " degree, "
<< "global phase shift= " << -phiShift *freq *RADDEG << " degree\n";
phi -= (phiShift * freq);
static_cast<RFCavity *>((*fit).getElement())->updatePhasem(phi);
static_cast<RFCavity *>((*fit).getElement().get())->updatePhasem(phi);
}
}
msg << "-------------------------------------------------------------------------------------\n"
......@@ -880,7 +880,7 @@ FieldList ParallelTTracker::executeAutoPhaseForSliceTracker() {
<< "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
<< "\033[0m"
<< endl;
static_cast<Monitor *>(it->getElement())->moveBy(-zend - 0.001);
static_cast<Monitor *>(it->getElement().get())->moveBy(-zend - 0.001);
itsOpalBeamline_m.removeElement(it->getElement()->getName());
}
}
......@@ -940,6 +940,8 @@ FieldList ParallelTTracker::executeAutoPhaseForSliceTracker() {
putMessage(*mess, (*it).second);
}
Ippl::Comm->broadcast_all(mess, tag);
delete mess;
} else {
// receive max phases and names and update the structures
int nData = 0;
......@@ -953,6 +955,8 @@ FieldList ParallelTTracker::executeAutoPhaseForSliceTracker() {
updateRFElement(elName, maxPhi);
OpalData::getInstance()->setMaxPhase(elName, maxPhi);
}
delete mess;
}
if(Ippl::myNode() == 0)
......@@ -1673,7 +1677,7 @@ void ParallelTTracker::handleOverlappingMonitors() {
<< "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"
<< "\033[0m"
<< endl;
static_cast<Monitor *>(it->getElement())->moveBy(-zend - 0.001);
static_cast<Monitor *>(it->getElement().get())->moveBy(-zend - 0.001);
itsOpalBeamline_m.removeElement(it->getElement()->getName());
}
}
......@@ -1737,6 +1741,8 @@ void ParallelTTracker::doAutoPhasing() {
Ippl::Comm->broadcast_all(mess, tag);
itsBunch->destroy(1, 0);
delete mess;
} else {
// receive max phases and names and update the structure
itsBunch->update();
......@@ -1752,6 +1758,8 @@ void ParallelTTracker::doAutoPhasing() {
updateRFElement(elName, maxPhi);
OpalData::getInstance()->setMaxPhase(elName, maxPhi);
}
delete mess;
}
itsBunch->update();
itsBunch->pop();
......@@ -2302,19 +2310,19 @@ void ParallelTTracker::computeExternalFields() {
* If the CSR is turned on for a dipole, save its pointer to the CSRWakeFunction
* and reuse it in the following drift.*/
// xpang: start
const ElementBase* element = itsOpalBeamline_m.getWakeFunctionOwner(wfSection);
std::shared_ptr<const ElementBase> element = itsOpalBeamline_m.getWakeFunctionOwner(wfSection);
if(dynamic_cast<CSRWakeFunction*>(wf))
{
if(dynamic_cast<const RBend*>(element) || dynamic_cast<const SBend*>(element))
wakeFunction_m = wf;
if(dynamic_cast<const Drift*>(element))
wf = wakeFunction_m;
if(dynamic_cast<const RBend*>(element.get()) || dynamic_cast<const SBend*>(element.get()))
wakeFunction_m = wf;
if(dynamic_cast<const Drift*>(element.get()))
wf = wakeFunction_m;
}
// xpang: end
if(!wakeStatus_m) {
msg << "============== START WAKE CALCULATION =============" << endl;
const ElementBase* element = itsOpalBeamline_m.getWakeFunctionOwner(wfSection);
wf->initialize