<commit_before>#include "material.h"
#include "simconf.h"

#include "functions.h"

#include <cmath>
#include <iostream>


void materialBase::prepare()
{
  double tt = 0.0;

  // get total stoichiometry
  for( int i = 0; i < element.size(); i++ )
  {
    if( element[i]->t < 0.0 ) element[i]->t = 0.0;
    tt += element[i]->t;
  }

  // normalize relative probabilities to 1
  for( int i = 0; i < element.size(); i++ ) element[i]->t /= tt;

  // average
  am = 0.0;
  az = 0.0;
  for( int i = 0; i < element.size(); i++ )
  {
    am += element[i]->m * element[i]->t;
    az += double( element[i]->z ) * element[i]->t;
  }

  arho = rho * 0.6022 / am; //[TRI00310] atoms/Ang^3
}

// make sure layers are prepare'd first!
void materialBase::average( const ionBase *pka )
{
  mu = pka->m1 / am;

  // universal or firsov screening length
  a = .5292 * .8853 / ( pow( double(pka->z1), 0.23 ) + pow( az, 0.23 ) );
  //a = .5292 * .8853 / pow( pow( double(pka.z1), 0.5 ) + pow( az, 0.5 ), 2.0/3.0 );

  // mean flight path0
  f = a * am / ( az * double(pka->z1) * 14.4 * ( pka->m1 + am ) );
  //eps0 = e0 * f;
  epsdg = simconf->tmin * f * pow( 1.0 + mu, 2.0 ) / ( 4.0 * mu );

  // fd and kd determine how much recoil energy goes into el. loss and vaccancies
  fd = pow( 0.01 * az, -7.0 / 3.0 );
  kd = pow( 0.1334 * az, 2.0 / 3.0 ) / sqrtf( am );

  for( int i = 0; i < element.size(); i++ )
  {
    element[i]->my = pka->m1 / element[i]->m;
    element[i]->ec = 4.0 * element[i]->my / pow( 1.0 + element[i]->my, 2.0 );
    element[i]->ai = .5292 * .8853 / ( pow( double(pka->z1), 0.23 ) + pow( element[i]->m, 0.23 ) );
    //ai = .5292 * .8853 / pow( pow( double(pka.z1), 0.5 ) + pow( element[i].m, 0.5 ), 2.0/3.0 );
    element[i]->fi = element[i]->ai * element[i]->m /
                     ( double(pka->z1) * double(element[i]->z) * 14.4 * ( pka->m1 + element[i]->m ) );
  }

  dirty = false;
}

// make sure layers are prepare'd and averaged first!
double materialBase::getrstop( const ionBase *pka )
{
  double se = 0.0;
  for( int i = 0; i < element.size(); i++ )
    se += rstop( pka, element[i]->z ) * element[i]->t * arho;

  return se;
}
<commit_msg>fix m/z mix-up in screening length calculation (thanks <NAME> for spotting this)<commit_after>#include "material.h"
#include "simconf.h"

#include "functions.h"

#include <cmath>
#include <iostream>


void materialBase::prepare()
{
  double tt = 0.0;

  // get total stoichiometry
  for( int i = 0; i < element.size(); i++ )
  {
    if( element[i]->t < 0.0 ) element[i]->t = 0.0;
    tt += element[i]->t;
  }

  // normalize relative probabilities to 1
  for( int i = 0; i < element.size(); i++ ) element[i]->t /= tt;

  // average
  am = 0.0;
  az = 0.0;
  for( int i = 0; i < element.size(); i++ )
  {
    am += element[i]->m * element[i]->t;
    az += double( element[i]->z ) * element[i]->t;
  }

  arho = rho * 0.6022 / am; //[TRI00310] atoms/Ang^3
}

// make sure layers are prepare'd first!
void materialBase::average( const ionBase *pka )
{
  mu = pka->m1 / am;

  // universal or firsov screening length
  a = .5292 * .8853 / ( pow( double(pka->z1), 0.23 ) + pow( az, 0.23 ) );
  //a = .5292 * .8853 / pow( pow( double(pka.z1), 0.5 ) + pow( az, 0.5 ), 2.0/3.0 );

  // mean flight path0
  f = a * am / ( az * double(pka->z1) * 14.4 * ( pka->m1 + am ) );
  //eps0 = e0 * f;
  epsdg = simconf->tmin * f * pow( 1.0 + mu, 2.0 ) / ( 4.0 * mu );

  // fd and kd determine how much recoil energy goes into el. loss and vaccancies
  fd = pow( 0.01 * az, -7.0 / 3.0 );
  kd = pow( 0.1334 * az, 2.0 / 3.0 ) / sqrtf( am );

  for( int i = 0; i < element.size(); i++ )
  {
    element[i]->my = pka->m1 / element[i]->m;
    element[i]->ec = 4.0 * element[i]->my / pow( 1.0 + element[i]->my, 2.0 );
    element[i]->ai = .5292 * .8853 / ( pow( double(pka->z1), 0.23 ) + pow( element[i]->z, 0.23 ) );
    //ai = .5292 * .8853 / pow( pow( double(pka.z1), 0.5 ) + pow( element[i].z, 0.5 ), 2.0/3.0 );
    element[i]->fi = element[i]->ai * element[i]->m /
                     ( double(pka->z1) * double(element[i]->z) * 14.4 * ( pka->m1 + element[i]->m ) );
  }

  dirty = false;
}

// make sure layers are prepare'd and averaged first!
double materialBase::getrstop( const ionBase *pka )
{
  double se = 0.0;
  for( int i = 0; i < element.size(); i++ )
    se += rstop( pka, element[i]->z ) * element[i]->t * arho;

  return se;
}

{'fraction_non_alphanumeric': 0.21694450787851108, 'fraction_numerical': 0.0621146380452158, 'mean_word_length': 2.3435114503816794, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3039674', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1807, 'n_words': 489}