SAnsell / CombLayer

MCNP(X) project builder using C++
GNU General Public License v3.0
14 stars 13 forks source link

Syntax error in GaussBeamSource.cxx #138

Open blahoslav opened 2 years ago

blahoslav commented 2 years ago

Hello, I think that I have spotted a syntax error in one of the latest commits in System/source/GaussBeamSource.cxx

There is missing code between GaussBeamSource::writePHITS and GaussBeamSource::writeFLUKA methods leading to the syntax error when building CombLayer.

The code for these methods is now:

void
GaussBeamSource::writePHITS(std::ostream& OX) const
  /*!
    Write out as a PHITS source system
    This is an approximate gaussian sauce b
    base no 100 x / 100 z units  
    - Rotation done by transform
    \param OX :: Output stream
  */
{
  ELog::RegMethod RegA("GaussBeamSource","writePHITS");

  const long int nStep(20);

  SourceBase::writePHITS(OX);
  // PHITS are z axis sources

  // Construct a transform to build the source

  const double xStep=3.0*xWidth/static_cast<double>(nStep);
  const double zStep=3.0*zWidth/static_cast<double>(nStep);

  const double xSigma = sqrt(8.0*std::log(2.0)) * xWidth;
  const double zSigma = sqrt(8.0*std::log(2.0)) * zWidth;

  // y is implicitly zero  
  for(long int i=-nStep;i<nStep;i++)
    for(long int j=-nStep;j<nStep;j++)
      {
    const double x= static_cast<double>(i)*xStep;
    const double z= static_cast<double>(j)*zStep;

GaussBeamSource::writeFLUKA(std::ostream& OX) const
  /*!
    Write out as a FLUKA source system
    \param OX :: Output stream
  */
{
  ELog::RegMethod RegA("GaussBeamSource","writeFLUKA");

  const flukaGenParticle& PC=flukaGenParticle::Instance();
  masterWrite& MW=masterWrite::Instance();

  // can be two for an energy range
  if (Energy.size()!=1)
    throw ColErr::SizeError<size_t>
      (Energy.size(),1,"Energy only single point supported");

  std::ostringstream cx;
  // energy : energy divirgence : angle spread [mrad]
  // radius : innerRadius : -1 t o means radius
  cx<<"BEAM "<<-0.001*Energy.front()<<" 0.0 "<<M_PI*angleSpread/0.180
    <<" "<<-xWidth<<" "<<-zWidth<<" -1.0 ";
  cx<<StrFunc::toUpperString(PC.nameToFLUKA(particleType));
  StrFunc::writeFLUKA(cx.str(),OX);
  cx.str("");

  cx<<"BEAMAXES "<<MW.Num(X)<<" "<<MW.Num(Y);
  StrFunc::writeFLUKA(cx.str(),OX);
  cx.str("");
  cx<<"BEAMPOS "<<Origin;
  StrFunc::writeFLUKA(cx.str(),OX);
  cx.str("");

  return;
}

I suggest to modify the methods to :

void
GaussBeamSource::writePHITS(std::ostream& OX) const
  /*!
    Write out as a PHITS source system
    This is an approximate gaussian sauce b
    base no 100 x / 100 z units  
    - Rotation done by transform
    \param OX :: Output stream
  */
{
  ELog::RegMethod RegA("GaussBeamSource","writePHITS");

  const long int nStep(20);

  SourceBase::writePHITS(OX);
  // PHITS are z axis sources

  // Construct a transform to build the source

  const double xStep=3.0*xWidth/static_cast<double>(nStep);
  const double zStep=3.0*zWidth/static_cast<double>(nStep);

  const double xSigma = sqrt(8.0*std::log(2.0)) * xWidth;
  const double zSigma = sqrt(8.0*std::log(2.0)) * zWidth;

  // y is implicitly zero  
  for(long int i=-nStep;i<nStep;i++)
    for(long int j=-nStep;j<nStep;j++)
      {
    const double x= static_cast<double>(i)*xStep;
    const double z= static_cast<double>(j)*zStep;
      }
  return;
}
void
GaussBeamSource::writeFLUKA(std::ostream& OX) const
  /*!
    Write out as a FLUKA source system
    \param OX :: Output stream
  */
{
  ELog::RegMethod RegA("GaussBeamSource","writeFLUKA");

  const flukaGenParticle& PC=flukaGenParticle::Instance();
  masterWrite& MW=masterWrite::Instance();

  // can be two for an energy range
  if (Energy.size()!=1)
    throw ColErr::SizeError<size_t>
      (Energy.size(),1,"Energy only single point supported");

  std::ostringstream cx;
  // energy : energy divirgence : angle spread [mrad]
  // radius : innerRadius : -1 t o means radius
  cx<<"BEAM "<<-0.001*Energy.front()<<" 0.0 "<<M_PI*angleSpread/0.180
    <<" "<<-xWidth<<" "<<-zWidth<<" -1.0 ";
  cx<<StrFunc::toUpperString(PC.nameToFLUKA(particleType));
  StrFunc::writeFLUKA(cx.str(),OX);
  cx.str("");

  cx<<"BEAMAXES "<<MW.Num(X)<<" "<<MW.Num(Y);
  StrFunc::writeFLUKA(cx.str(),OX);
  cx.str("");
  cx<<"BEAMPOS "<<Origin;
  StrFunc::writeFLUKA(cx.str(),OX);
  cx.str("");
  return;
}

Thank you very much for your help.

SAnsell commented 2 years ago

Very sorry -- that was my fault . I have fixed this -- it got deleted by mistake