Skip to content

Commit

Permalink
Minor fixes for sim. of exp.
Browse files Browse the repository at this point in the history
  • Loading branch information
ochubar committed Oct 1, 2024
1 parent 76558ac commit 29a133e
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 76 deletions.
4 changes: 3 additions & 1 deletion cpp/src/clients/python/srwlpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5067,7 +5067,9 @@ static PyObject* srwlpy_ResizeElecFieldMesh(PyObject *self, PyObject *args)
//oFunc = PyObject_GetAttrString(oWfr, "allocate");
//END OCTEST

double arPar[] = {0.,1.}; int nPar = 2; double *pPar = arPar; //[0] with or without FFT, [1]==1 means treatment of quadratic term is allowed
//double arPar[] = {0.,1.}; int nPar = 2; double *pPar = arPar; //[0] with or without FFT, [1]==1 means treatment of quadratic term is allowed
//OC22092024
double arPar[] = { 0.,1.,1.}; int nPar = 3; double *pPar = arPar; //[0] means with (1) or without (0) FFT, [1] means treatment of quadratic term is allowed (1) or not (0), [2] means correction of Re and Im parts of the E-field based on intensity is allowed (1) or not (0)
CopyPyListElemsToNumArray(oPar, 'd', pPar, nPar);

ProcRes(srwlResizeElecFieldMesh(&wfr, &newMesh, arPar));
Expand Down
46 changes: 42 additions & 4 deletions cpp/src/core/sroptel2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ int srTGenOptElem::PropagateRadiationMeth_0(srTSRWRadStructAccessData* pRadAcces
pRadDataSingleE->xStep = pRadAccessData->xStep;
pRadDataSingleE->zStart = pRadAccessData->zStart;
pRadDataSingleE->zStep = pRadAccessData->zStep;

pRadDataSingleE->xWfrMin = pRadAccessData->xWfrMin; //HG23072024 (fix of a crash at propagation "from waist")
pRadDataSingleE->xWfrMax = pRadAccessData->xWfrMax;
pRadDataSingleE->zWfrMin = pRadAccessData->zWfrMin;
pRadDataSingleE->zWfrMax = pRadAccessData->zWfrMax;
}
if(pPrevRadDataSingleE != 0)
{
Expand All @@ -121,17 +126,36 @@ int srTGenOptElem::PropagateRadiationMeth_0(srTSRWRadStructAccessData* pRadAcces

if(pRadDataSingleE != pRadAccessData)
{
if(result = UpdateGenRadStructSliceConstE_Meth_0(pRadDataSingleE, ie, pRadAccessData)) return result;
if(ie > 0) //OC23072024
{
srTSRWRadStructAccessData &prevRadDataSingleE = vRadSlices[ie - 1];
if(!gridParamWereModifInSlices)
{
if((pRadDataSingleE->nx != prevRadDataSingleE.nx) || (pRadDataSingleE->xStart != prevRadDataSingleE.xStart) || (pRadDataSingleE->xStep != prevRadDataSingleE.xStep)) gridParamWereModifInSlices = true;
}
if(!gridParamWereModifInSlices)
{
if((pRadDataSingleE->nz != prevRadDataSingleE.nz) || (pRadDataSingleE->zStart != prevRadDataSingleE.zStart) || (pRadDataSingleE->zStep != prevRadDataSingleE.zStep)) gridParamWereModifInSlices = true;
}
}

//if(result = UpdateGenRadStructSliceConstE_Meth_0(pRadDataSingleE, ie, pRadAccessData)) return result;
//HG23072024 (fix of a crash at propagation "from waist"):
//OC: does "ie < (neOrig - 1)" cast to 0 or 1 only (never 2)?
if(result = UpdateGenRadStructSliceConstE_Meth_0(pRadDataSingleE, ie, pRadAccessData, ie < (neOrig - 1))) return result; //Updating slice data is required even if it is re-interpolated later

//if(result = UpdateGenRadStructSliceConstE_Meth_0(pRadDataSingleE, ie, pRadAccessData, ie < (neOrig - 1))) return result;
//the above doesn't change the transverse grid parameters in *pRadAccessData

//vRadSlices.push_back(*pRadDataSingleE); //this automatically calls destructor, which can eventually delete "emulated" structs!
//srTSRWRadStructAccessData copyRadDataSingleE(*pRadDataSingleE); //this doesn't assume to copy pBaseRadX, pBaseRadZ
srTSRWRadStructAccessData copyRadDataSingleE(*pRadDataSingleE, false); //OC290813 fixing memory leak(?) //this doesn't assume to copy pBaseRadX, pBaseRadZ
copyRadDataSingleE.pBaseRadX = copyRadDataSingleE.pBaseRadZ = 0; copyRadDataSingleE.BaseRadWasEmulated = false;
vRadSlices.push_back(copyRadDataSingleE);

if((pRadDataSingleE->nx != pRadAccessData->nx) || (pRadDataSingleE->xStart != pRadAccessData->xStart) || (pRadDataSingleE->xStep != pRadAccessData->xStep)) gridParamWereModifInSlices = true;
if((pRadDataSingleE->nz != pRadAccessData->nz) || (pRadDataSingleE->zStart != pRadAccessData->zStart) || (pRadDataSingleE->zStep != pRadAccessData->zStep)) gridParamWereModifInSlices = true;

//OC23072024 (commented-out)
//if((pRadDataSingleE->nx != pRadAccessData->nx) || (pRadDataSingleE->xStart != pRadAccessData->xStart) || (pRadDataSingleE->xStep != pRadAccessData->xStep)) gridParamWereModifInSlices = true;
//if((pRadDataSingleE->nz != pRadAccessData->nz) || (pRadDataSingleE->zStart != pRadAccessData->zStart) || (pRadDataSingleE->zStep != pRadAccessData->zStep)) gridParamWereModifInSlices = true;
}
}

Expand All @@ -143,6 +167,20 @@ int srTGenOptElem::PropagateRadiationMeth_0(srTSRWRadStructAccessData* pRadAcces
{//to test!
if(result = ReInterpolateWfrDataOnNewTransvMesh(vRadSlices, pRadDataSingleE, pRadAccessData)) return result;
}
else
{//OC23072024
if((pRadDataSingleE != 0) && (pRadDataSingleE != pRadAccessData))
{
pRadAccessData->xStart = pRadDataSingleE->xStart;
pRadAccessData->xStep = pRadDataSingleE->xStep;
pRadAccessData->zStart = pRadDataSingleE->zStart;
pRadAccessData->zStep = pRadDataSingleE->zStep;
pRadAccessData->xWfrMin = pRadDataSingleE->xWfrMin;
pRadAccessData->xWfrMax = pRadDataSingleE->xWfrMax;
pRadAccessData->zWfrMin = pRadDataSingleE->zWfrMin;
pRadAccessData->zWfrMax = pRadDataSingleE->zWfrMax;
}
}

if((pRadDataSingleE != 0) && (pRadDataSingleE != pRadAccessData)) delete pRadDataSingleE;
if((pPrevRadDataSingleE != 0) && (pPrevRadDataSingleE != pRadAccessData)) delete pPrevRadDataSingleE;
Expand Down
5 changes: 4 additions & 1 deletion cpp/src/core/sroptelm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3068,7 +3068,10 @@ int srTGenOptElem::RadResizeCore(srTSRWRadStructAccessData& OldRadAccessData, sr
//srwlPrintTime(":RadResizeCore: init variables 1",&start);

//if((!RadResizeStruct.DoNotTreatSpherTerm) && WaveFrontTermCanBeTreated(OldRadAccessData))
if((!RadResizeStruct.doNotTreatSpherTerm()) && WaveFrontTermCanBeTreated(OldRadAccessData)) //OC090311
//if((!RadResizeStruct.doNotTreatSpherTerm()) && WaveFrontTermCanBeTreated(OldRadAccessData)) //OC090311
//***************
if((!RadResizeStruct.doNotTreatSpherTerm()) && WaveFrontTermCanBeTreated(OldRadAccessData) && (OldRadAccessData.Pres < 1)) //OCTEST06262024 (to test resize in ang. repres.)
//***************
{
//Added by SY (for profiling?) at parallelizing SRW via OpenMP:
//srwlPrintTime(":RadResizeCore: doNotTreatSpherTerm+WaveFrontTermCanBeTreated",&start);
Expand Down
75 changes: 69 additions & 6 deletions cpp/src/core/srradstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4655,6 +4655,13 @@ void srTSRWRadStructAccessData::ResizeCoreXZ(SRWLRadMesh& oldMesh, float* pOldRa
//bool OrigWfrQuadTermCanBeTreatedAtResizeX = OldRadAccessData.WfrQuadTermCanBeTreatedAtResizeX;
//bool OrigWfrQuadTermCanBeTreatedAtResizeZ = OldRadAccessData.WfrQuadTermCanBeTreatedAtResizeZ;

//OC22092024
bool allowReAndImCorrFromI = true;
if(arPar != 0)
{
if(arPar[2] == 0.) allowReAndImCorrFromI = false;
}

if(allowTreatQuadPhaseTerm && QuadPhaseTermCanBeTreated())
{
//NewRadAccessData.WfrQuadTermCanBeTreatedAtResizeX = OldRadAccessData.WfrQuadTermCanBeTreatedAtResizeX;
Expand Down Expand Up @@ -4834,7 +4841,8 @@ void srTSRWRadStructAccessData::ResizeCoreXZ(SRWLRadMesh& oldMesh, float* pOldRa
srTGenOptElem::InterpolFI(InterpolAux02I, xRel, zRel, BufFI, 0);
}
(*BufFI) *= AuxFI->fNorm;
srTGenOptElem::ImproveReAndIm(BufF, BufFI);
//srTGenOptElem::ImproveReAndIm(BufF, BufFI);
if(allowReAndImCorrFromI) srTGenOptElem::ImproveReAndIm(BufF, BufFI); //OC22092024
//if(FieldShouldBeZeroed) { *BufF = 0.; *(BufF+1) = 0.; } //OC17102021 (commented-out, since this case is treated before these interpolations)
*pEX_New = *BufF;
*(pEX_New+1) = *(BufF+1);
Expand All @@ -4844,23 +4852,54 @@ void srTSRWRadStructAccessData::ResizeCoreXZ(SRWLRadMesh& oldMesh, float* pOldRa
if(UseLowOrderInterp_PolCompZ)
{
srTGenOptElem::InterpolF_LowOrder(InterpolAux02, xRel, zRel, BufF, 2);
srTGenOptElem::InterpolFI_LowOrder(InterpolAux02I, xRel, zRel, BufFI, 1);
//srTGenOptElem::InterpolFI_LowOrder(InterpolAux02I, xRel, zRel, BufFI, 1);
if(allowReAndImCorrFromI) srTGenOptElem::InterpolFI_LowOrder(InterpolAux02I, xRel, zRel, BufFI, 1); //OC22092024
}
else
{
srTGenOptElem::InterpolF(InterpolAux02, xRel, zRel, BufF, 2);
srTGenOptElem::InterpolFI(InterpolAux02I, xRel, zRel, BufFI, 1);
//srTGenOptElem::InterpolFI(InterpolAux02I, xRel, zRel, BufFI, 1);
if(allowReAndImCorrFromI) srTGenOptElem::InterpolFI(InterpolAux02I, xRel, zRel, BufFI, 1); //OC22092024
}
(*(BufFI+1)) *= (AuxFI+1)->fNorm;
srTGenOptElem::ImproveReAndIm(BufF+2, BufFI+1);
//srTGenOptElem::ImproveReAndIm(BufF+2, BufFI+1);
if(allowReAndImCorrFromI) srTGenOptElem::ImproveReAndIm(BufF+2, BufFI+1); //OC22092024
//if(FieldShouldBeZeroed) { *(BufF+2) = 0.; *(BufF+3) = 0.; } //OC17102021 (commented-out, since this case is treated before these interpolations)
*pEZ_New = *(BufF+2);
*(pEZ_New+1) = *(BufF+3);
}
}
}
}
if(WaveFrontTermWasTreated) TreatQuadPhaseTerm('a', polComp);
//if(WaveFrontTermWasTreated) TreatQuadPhaseTerm('a', polComp);
//OC21092024
if(WaveFrontTermWasTreated)
{//Treatment of the Quad. Phase Term has to be done on NEW data!
//Setting temporarily all required member variables in this

//float *pBaseRadX, *pBaseRadZ;
//waveHndl wRad, wRadX, wRadZ;
//int hStateRadX, hStateRadZ;
//double eStep, eStart, xStep, xStart, zStep, zStart;
//long ne, nx, nz;

pBaseRadX = pNewRadX;
pBaseRadZ = pNewRadZ;
xStep= xStepNew; xStart = xStartNew;
zStep= zStepNew; zStart = zStartNew;
nx = nxNew;
nz = nzNew;

TreatQuadPhaseTerm('a', polComp);

//Setting back the member variables to their original values
pBaseRadX = pOldRadX;
pBaseRadZ = pOldRadZ;
xStep = xStepOld; xStart = xStartOld;
zStep = zStepOld; zStart = zStartOld;
nx = oldMesh.nx;
nz = oldMesh.ny;
}
}

//*************************************************************************
Expand Down Expand Up @@ -5085,7 +5124,31 @@ void srTSRWRadStructAccessData::ResizeCoreE(SRWLRadMesh& oldMesh, float* pOldRad
}
}
}
if(WaveFrontTermWasTreated) TreatQuadPhaseTerm('r', polComp);
//if(WaveFrontTermWasTreated) TreatQuadPhaseTerm('r', polComp);
//OC22092024
if(WaveFrontTermWasTreated)
{//Treatment of the Quad. Phase Term has to be done on NEW data!
//Setting temporarily all required member variables in this

//float *pBaseRadX, *pBaseRadZ;
//waveHndl wRad, wRadX, wRadZ;
//int hStateRadX, hStateRadZ;
//double eStep, eStart, xStep, xStart, zStep, zStart;
//long ne, nx, nz;

pBaseRadX = pNewRadX;
pBaseRadZ = pNewRadZ;
eStep= eStepNew; eStart = eStartNew;
ne = neNew;

TreatQuadPhaseTerm('a', polComp);

//Setting back the member variables to their original values
pBaseRadX = pOldRadX;
pBaseRadZ = pOldRadZ;
eStep = eStepOld; eStart = eStartOld;
ne = oldMesh.ne;
}
}

//*************************************************************************
Expand Down
7 changes: 5 additions & 2 deletions cpp/src/core/srradstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,11 @@ class srTSRWRadStructAccessData : public CGenObject {
char AnglesXAreSmall = (xMagn < CritRatTransvLong*(::fabs(RobsX)));
char AnglesZAreSmall = (zMagn < CritRatTransvLong*(::fabs(RobsZ)));

WfrQuadTermCanBeTreatedAtResizeX = (AnglesXAreSmall && RobsXErrIsSmall);
WfrQuadTermCanBeTreatedAtResizeZ = (AnglesZAreSmall && RobsZErrIsSmall);
//WfrQuadTermCanBeTreatedAtResizeX = (AnglesXAreSmall && RobsXErrIsSmall);
//WfrQuadTermCanBeTreatedAtResizeZ = (AnglesZAreSmall && RobsZErrIsSmall);
//OCTEST20092024 (trying to drop he small angle requirement - perhaps it's not really necessary, consider spherical wave e.g.)
WfrQuadTermCanBeTreatedAtResizeX = (RobsXErrIsSmall);
WfrQuadTermCanBeTreatedAtResizeZ = (RobsZErrIsSmall);

return (WfrQuadTermCanBeTreatedAtResizeX || WfrQuadTermCanBeTreatedAtResizeZ);
}
Expand Down
Loading

0 comments on commit 29a133e

Please sign in to comment.