/*
    Copyright 2012 Lumerical Solutions, Inc. All rights reserved.
*/
#include "chi3.h"
#include <cmath>

/*!
    \class Chi3MaterialPlugin

    \brief An example implementation of a chi3 non-linear material through the material plugin interface
*/

const char* Chi3MaterialPlugin::names[4] = {"\xcf\x87 1", "\xcf\x87 2", "\xcf\x87 3", 0};


void Chi3MaterialPlugin::initialize(const double** parameters, double dt)
{
    for(int i=0; i<3; i++){
        chi1[i] = float(parameters[0][i]);
        chi2[i] = float(parameters[1][i]);
        chi3[i] = float(parameters[2][i]);
    }
}

float Chi3MaterialPlugin::calculate(int axis, float U, float V, float E, float* storage)
{
    return V/(U+chi1[axis]+chi2[axis]*E+chi3[axis]*E*E);
}

float Chi3MaterialPlugin::calculateEx( float U, float V, float Ex, float* storage )
{
    return calculate(0, U, V, Ex, storage);
}

float Chi3MaterialPlugin::calculateEy( float U, float V, float Ey, float* storage )
{
    return calculate(1, U, V, Ey, storage);
}

float Chi3MaterialPlugin::calculateEz( float U, float V, float Ez, float* storage )
{
    return calculate(2, U, V, Ez, storage);
}

MATERIAL_PLUGIN(Chi3MaterialPlugin);

