/*
    Copyright 2013 Lumerical Solutions, Inc. All rights reserved.
*/
#include "stepindex.h"
#include <cmath>

/*!
    \class StepIndexMaterialPlugin

*/


const char* StepIndexMaterialPlugin::names[4] = {"delta_eps", "time_start", "time_stop", 0};

void StepIndexMaterialPlugin::initialize(const double** parameters, double dt)
{
    for(int i=0; i<3; i++){
        delta_eps[i] = float(parameters[0][i]);
    }

    time_start = parameters[1][0];
    time_stop = parameters[2][0];
    time_dt = dt;

}

float StepIndexMaterialPlugin::calculate(int axis, float U, float V, float E, float* storage)
{
    storage[0] += time_dt;
    bool change_index = (storage[0] > time_start) && (storage[0] < time_stop);  
    return change_index ? V/(U+delta_eps[axis]) : V/U;
}

float StepIndexMaterialPlugin::calculateEx( float U, float V, float Ex, float* storage )
{
    return calculate(0, U, V, Ex, storage);
}

float StepIndexMaterialPlugin::calculateEy( float U, float V, float Ey, float* storage )
{
    return calculate(1, U, V, Ey, storage);
}

float StepIndexMaterialPlugin::calculateEz( float U, float V, float Ez, float* storage )
{
    return calculate(2, U, V, Ez, storage);
}

MATERIAL_PLUGIN(StepIndexMaterialPlugin);
