<commit_before>// Field.cpp - implementation of time-varying external field shapes
//
// <NAME> (2015)
// <EMAIL>
//
#include<Field.hpp>

// Abstract class to hold a field calculation
Field::Field( float field )
{
  setH( field );
}
void Field::setH( float field ) { h=field; }
float Field::getH() const { return h; }

// Abstrsct class for periodic time-varying fields
FieldPeriodic::FieldPeriodic( float field, float freq )
        : Field( field )
{
  setF( freq );
}
void FieldPeriodic::setF( float freq ) { f=freq; }
float FieldPeriodic::getF() const { return f; }

// Sine field
FieldACSine::FieldACSine( float field, float freq )
  : FieldPeriodic( field, freq ) {}
float FieldACSine::getField( float t ) const
{
  return getH()*std::sin( 2*M_PI*getF()*t );
}

// Cosine field
FieldACCosine::FieldACCosine( float field, float freq )
  : FieldPeriodic( field, freq ) {}
float FieldACCosine::getField( float t ) const
{
  return getH()*std::cos( 2*M_PI*getF()*t );
}

// Square wave
FieldACSquare::FieldACSquare( float field, float freq )
  : FieldPeriodic( field, freq ) {}
float FieldACSquare::getField( float t ) const
{
  return getH()*( int( t*getF()*2 )%2 ? -1 : 1 );
}

// Ramped square wave
FieldACRamp::FieldACRamp( float field, float freq,
			  float riseTime )
  : FieldPeriodic( field, freq )
{
  setRT( riseTime );
}
float FieldACRamp::getRT() const { return rt; }
void FieldACRamp::setRT( float r )
{
  // rise time must be 0-50%
  if( ( r>0.5 ) or ( r<0.0 ) )
    throw std::invalid_argument("The rise time must be between"
				" 0.0 - 0.5 (proportion of"
				" cyclical period)" );
  // set the rise time
  rt = r;
  // compute the ramping gradient
  float T=1/getF();
  ramp = 2*getH()/( T*rt );
  // compute the max interval
  left=T/2*rt;
  right=T/2*( 1-rt );
}
  
float FieldACRamp::getField( float t ) const
{
  float tcyc = std::fmod( t, 1/( getF() ) );
  float T2 = 1/( 2*getF() );
  return tcyc<left ? getH()*tcyc*ramp :
    tcyc<right ? getH() :
    tcyc<( T2+left ) ? getH()*( 1-ramp*( tcyc-right ) ) :
    tcyc<( T2+right ) ? -getH() :
    getH()*( ramp*( tcyc-T2-right )-1 );
}<commit_msg>Corrected the ramped field calculations<commit_after>// Field.cpp - implementation of time-varying external field shapes
//
// <NAME> (2015)
// <EMAIL>
//
#include<Field.hpp>

// Abstract class to hold a field calculation
Field::Field( float field )
{
  setH( field );
}
void Field::setH( float field ) { h=field; }
float Field::getH() const { return h; }

// Abstrsct class for periodic time-varying fields
FieldPeriodic::FieldPeriodic( float field, float freq )
        : Field( field )
{
  setF( freq );
}
void FieldPeriodic::setF( float freq ) { f=freq; }
float FieldPeriodic::getF() const { return f; }

// Sine field
FieldACSine::FieldACSine( float field, float freq )
  : FieldPeriodic( field, freq ) {}
float FieldACSine::getField( float t ) const
{
  return getH()*std::sin( 2*M_PI*getF()*t );
}

// Cosine field
FieldACCosine::FieldACCosine( float field, float freq )
  : FieldPeriodic( field, freq ) {}
float FieldACCosine::getField( float t ) const
{
  return getH()*std::cos( 2*M_PI*getF()*t );
}

// Square wave
FieldACSquare::FieldACSquare( float field, float freq )
  : FieldPeriodic( field, freq ) {}
float FieldACSquare::getField( float t ) const
{
  return getH()*( int( t*getF()*2 )%2 ? -1 : 1 );
}

// Ramped square wave
FieldACRamp::FieldACRamp( float field, float freq,
			  float riseTime )
  : FieldPeriodic( field, freq )
{
  setRT( riseTime );
}
float FieldACRamp::getRT() const { return rt; }
void FieldACRamp::setRT( float r )
{
  // rise time must be 0-50%
  if( ( r>0.5 ) or ( r<0.0 ) )
    throw std::invalid_argument("The rise time must be between"
				" 0.0 - 0.5 (proportion of"
				" cyclical period)" );
  // set the rise time
  rt = r;
  // compute the ramping gradient
  float T=1/getF();
  ramp = 2*getH()/( T*rt );
  // compute the max interval
  left=T/2*rt;
  right=T/2*( 1-rt );
}
  
float FieldACRamp::getField( float t ) const
{
  float tcyc = std::fmod( t, 1/( getF() ) );
  float T2 = 1/( 2*getF() );
  return tcyc<left ? tcyc*ramp :
    tcyc<right ? getH() :
    tcyc<( T2+left ) ? getH() - ramp*( tcyc-right ) :
    tcyc<( T2+right ) ? -getH() :
    -getH() + ramp*( tcyc-T2-right );
}
{'fraction_non_alphanumeric': 0.16251761390324096, 'fraction_numerical': 0.015969938938468764, 'mean_word_length': 3.4784437434279707, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 11, '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': '2826429', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1601, 'n_words': 437}