efield.cuh 1.15 KB
#include "rts/math/complex.h"
#include "rts/visualization/colormap.h"

namespace rts{

/*  This class implements a discrete representation of an electromagnetic field
    in 2D. The majority of this representation is done on the GPU.
*/
template<typename P>
class efield
{
private:

    bool scalar;

    //gpu pointer to the field data
    rts::complex<P>* X;
    rts::complex<P>* Y;
    rts::complex<P>* Z;

    //resolution of the discrete field
    unsigned int R[2];


public:

    efield(unsigned int res0, unsigned int res1, bool _scalar = false)
    {
        //initialize all pointers to NULL
        X = Y = Z = NULL;
        R[0] = res0;
        R[1] = res1;

        //allocate memory on the gpu
        cudaMalloc(&X, sizeof(rts::complex<P>) * R[0] * R[1]);

        if(!scalar)
        {
            cudaMalloc(&Y, sizeof(rts::complex<P>) * R[0] * R[1]);
            cudaMalloc(&Z, sizeof(rts::complex<P>) * R[0] * R[1]);
        }
    }

    //destructor
    ~efield()
    {
        if(X != NULL) cudaFree(X);
        if(Y != NULL) cudaFree(Y);
        if(Z != NULL) cudaFree(Z);
    }

    void render(std::string)
    {

    }


};



}   //end namespace rts