Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new temporal profile tsin2plateau #7

Merged
merged 7 commits into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Profiles/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,17 @@ double Function_TimePolynomial::valueAt(double time) {
}
return r;
}
// Time sin2 profile with a plateau the funtion and the derivative are continuos
double Function_TimeSin2Plateau::valueAt(double time) {
if (time<start) {
return 0.;
} else if ((time < start+slope1)&&(slope1!=0.)) {
return pow( sin(0.5*M_PI*(time-start)/slope1) , 2 );
} else if (time < start+slope1+plateau) {
return 1.;
} else if ((time < start+slope1+plateau+slope2)&&(slope2!=0.)) {
return pow( cos(0.5*M_PI*(time-start-slope1-plateau)/slope2) , 2 );
} else {
return 0.;
}
}
24 changes: 23 additions & 1 deletion src/Profiles/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -809,4 +809,26 @@ class Function_TimePolynomial : public Function
std::vector<double> coeffs;
};

#endif
class Function_TimeSin2Plateau : public Function{
public:
Function_TimeSin2Plateau ( PyObject *py_profile ){
//double duration;
PyTools::getAttr(py_profile, "start", start );
PyTools::getAttr(py_profile, "slope1", slope1 );
PyTools::getAttr(py_profile, "plateau", plateau );
PyTools::getAttr(py_profile, "slope2" , slope2 );
end = start + slope1 + plateau + slope2;
};
Function_TimeSin2Plateau ( Function_TimeSin2Plateau *f ){
start = f->start;
slope1 = f->slope1;
plateau = f->plateau;
slope2 = f->slope2;
end = f->end;
};
double valueAt(double);
private:
double start, slope1, plateau, slope2, end;
};

#endif
144 changes: 76 additions & 68 deletions src/Profiles/Profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,14 @@ Profile::Profile(PyObject* py_profile, unsigned int nvariables, string name, boo
else
ERROR("Profile `"<<name<<"`: tpolynomial() profile is only for time");

} else if( profileName == "tsin2plateau" ){

if( nvariables == 1 )
function = new Function_TimeSin2Plateau(py_profile);
else
ERROR("Profile `"<<name<<"`: tsin2plateau() profile is only for time");
}

}

// Otherwise (if the python profile cannot be hard-coded) ....
Expand Down Expand Up @@ -232,79 +238,81 @@ Profile::Profile(PyObject* py_profile, unsigned int nvariables, string name, boo


// Cloning constructor
Profile::Profile(Profile *p)
{
profileName = p->profileName;
nvariables = p->nvariables ;
info = p->info ;
uses_numpy = p->uses_numpy ;
if( profileName != "" ) {
if( profileName == "constant" ) {
if ( nvariables == 1 )
function = new Function_Constant1D(static_cast<Function_Constant1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Constant2D(static_cast<Function_Constant2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Constant3D(static_cast<Function_Constant3D*>(p->function));
} else if( profileName == "trapezoidal" ){
if ( nvariables == 1 )
function = new Function_Trapezoidal1D(static_cast<Function_Trapezoidal1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Trapezoidal2D(static_cast<Function_Trapezoidal2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Trapezoidal3D(static_cast<Function_Trapezoidal3D*>(p->function));
} else if( profileName == "gaussian" ){
if ( nvariables == 1 )
function = new Function_Gaussian1D(static_cast<Function_Gaussian1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Gaussian2D(static_cast<Function_Gaussian2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Gaussian3D(static_cast<Function_Gaussian3D*>(p->function));
} else if( profileName == "polygonal" ){
if ( nvariables == 1 )
function = new Function_Polygonal1D(static_cast<Function_Polygonal1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Polygonal2D(static_cast<Function_Polygonal2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Polygonal3D(static_cast<Function_Polygonal3D*>(p->function));
} else if( profileName == "cosine" ){
if ( nvariables == 1 )
function = new Function_Cosine1D(static_cast<Function_Cosine1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Cosine2D(static_cast<Function_Cosine2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Cosine3D(static_cast<Function_Cosine3D*>(p->function));
} else if( profileName == "polynomial" ){
if ( nvariables == 1 )
function = new Function_Polynomial1D(static_cast<Function_Polynomial1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Polynomial2D(static_cast<Function_Polynomial2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Polynomial3D(static_cast<Function_Polynomial3D*>(p->function));
} else if( profileName == "tconstant" ){
function = new Function_TimeConstant(static_cast<Function_TimeConstant*>(p->function));
} else if( profileName == "ttrapezoidal" ){
function = new Function_TimeTrapezoidal(static_cast<Function_TimeTrapezoidal*>(p->function));
} else if( profileName == "tgaussian" ){
function = new Function_TimeGaussian(static_cast<Function_TimeGaussian*>(p->function));
} else if( profileName == "tpolygonal" ){
function = new Function_TimePolygonal(static_cast<Function_TimePolygonal*>(p->function));
} else if( profileName == "tcosine" ){
function = new Function_TimeCosine(static_cast<Function_TimeCosine*>(p->function));
} else if( profileName == "tpolynomial" ){
function = new Function_TimePolynomial(static_cast<Function_TimePolynomial*>(p->function));
}
} else {
if ( nvariables == 1 ) function = new Function_Python1D(static_cast<Function_Python1D*>(p->function));
else if ( nvariables == 2 ) function = new Function_Python2D(static_cast<Function_Python2D*>(p->function));
else if ( nvariables == 3 ) function = new Function_Python3D(static_cast<Function_Python3D*>(p->function));
Profile::Profile(Profile *p){
profileName = p->profileName;
nvariables = p->nvariables ;
info = p->info ;
uses_numpy = p->uses_numpy ;
if( profileName != "" ) {
if( profileName == "constant" ) {
if ( nvariables == 1 )
function = new Function_Constant1D(static_cast<Function_Constant1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Constant2D(static_cast<Function_Constant2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Constant3D(static_cast<Function_Constant3D*>(p->function));
} else if( profileName == "trapezoidal" ){
if ( nvariables == 1 )
function = new Function_Trapezoidal1D(static_cast<Function_Trapezoidal1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Trapezoidal2D(static_cast<Function_Trapezoidal2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Trapezoidal3D(static_cast<Function_Trapezoidal3D*>(p->function));
} else if( profileName == "gaussian" ){
if ( nvariables == 1 )
function = new Function_Gaussian1D(static_cast<Function_Gaussian1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Gaussian2D(static_cast<Function_Gaussian2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Gaussian3D(static_cast<Function_Gaussian3D*>(p->function));
} else if( profileName == "polygonal" ){
if ( nvariables == 1 )
function = new Function_Polygonal1D(static_cast<Function_Polygonal1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Polygonal2D(static_cast<Function_Polygonal2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Polygonal3D(static_cast<Function_Polygonal3D*>(p->function));
} else if( profileName == "cosine" ){
if ( nvariables == 1 )
function = new Function_Cosine1D(static_cast<Function_Cosine1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Cosine2D(static_cast<Function_Cosine2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Cosine3D(static_cast<Function_Cosine3D*>(p->function));
} else if( profileName == "polynomial" ){
if ( nvariables == 1 )
function = new Function_Polynomial1D(static_cast<Function_Polynomial1D*>(p->function));
else if( nvariables == 2 )
function = new Function_Polynomial2D(static_cast<Function_Polynomial2D*>(p->function));
else if( nvariables == 3 )
function = new Function_Polynomial3D(static_cast<Function_Polynomial3D*>(p->function));
} else if( profileName == "tconstant" ){
function = new Function_TimeConstant(static_cast<Function_TimeConstant*>(p->function));
} else if( profileName == "ttrapezoidal" ){
function = new Function_TimeTrapezoidal(static_cast<Function_TimeTrapezoidal*>(p->function));
} else if( profileName == "tgaussian" ){
function = new Function_TimeGaussian(static_cast<Function_TimeGaussian*>(p->function));
} else if( profileName == "tpolygonal" ){
function = new Function_TimePolygonal(static_cast<Function_TimePolygonal*>(p->function));
} else if( profileName == "tcosine" ){
function = new Function_TimeCosine(static_cast<Function_TimeCosine*>(p->function));
} else if( profileName == "tpolynomial" ){
function = new Function_TimePolynomial(static_cast<Function_TimePolynomial*>(p->function));
} else if( profileName == "tsin2plateau" ){
function = new Function_TimeSin2Plateau(static_cast<Function_TimeSin2Plateau*>(p->function));
}
}else {
if ( nvariables == 1 ) function = new Function_Python1D(static_cast<Function_Python1D*>(p->function));
else if ( nvariables == 2 ) function = new Function_Python2D(static_cast<Function_Python2D*>(p->function));
else if ( nvariables == 3 ) function = new Function_Python3D(static_cast<Function_Python3D*>(p->function));
}
}



Profile::~Profile()
{
delete function;
delete function;
}


Expand Down
28 changes: 28 additions & 0 deletions src/Python/pyprofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,33 @@ def f(t):
f.coeffs.append( c )
return f

def tsin2plateau(start=0., fwhm=0., plateau=None, slope1=None, slope2=None):
import math
global Main
if len(Main)==0:
raise Exception("tsin2plateau profile has been defined before `Main()`")
if plateau is None: plateau = 0 # default is a simple sin2 profile (could be used for a 2D or 3D laserPulse too)
if slope1 is None: slope1 = fwhm
if slope2 is None: slope2 = slope1
def f(t):
if t < start:
return 0.
elif (t < start+fwhm) and (fwhm!=0.):
return math.pow( math.sin(0.5*math.pi*(t-start)/fwhm) , 2 )
elif t < start+fwhm+plateau:
return 1.
elif t < start+fwhm+plateau+slope2 and (slope2!=0.):
return math.pow( math.cos(0.5*math.pi*(t-start-fwhm-plateau)/slope2) , 2 )
else:
return 0.
f.profileName = "tsin2plateau"
f.start = start
#f.fwhm = fwhm
f.plateau = plateau
f.slope1 = slope1
f.slope2 = slope2
return f


def transformPolarization(polarizationPhi, ellipticity):
import math
Expand Down Expand Up @@ -554,6 +581,7 @@ def phase(y,z):
phase = [ lambda y,z:phase(y,z)-phaseZero+dephasing, lambda y,z:phase(y,z)-phaseZero ],
)


"""
-----------------------------------------------------------------------
BEGINNING OF THE USER NAMELIST
Expand Down