/*
 * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg.
 * All rights reserved. This file is part of nusif-solver.
 * Use of this source code is governed by a MIT style
 * license that can be found in the LICENSE file.
 */
#ifndef __PARTICLETRACING_H_
#define __PARTICLETRACING_H_
#include "allocate.h"
#include "parameter.h"

#include "solver.h"
#include <mpi.h>
#include <stdbool.h>

#define NDIMS 2

typedef enum COORD { X = 0, Y, NCOORD } COORD;

typedef struct {
    double x, y;
    bool flag;
} Particle;

typedef struct {
    int numberOfParticles, removedParticles, totalParticles;
    double startTime, injectTimePeriod, writeTimePeriod, lastInjectTime, lastUpdateTime,
        lastWriteTime;

    int estimatedNumParticles;

    double dx, dy, dt;
    Particle* linSpaceLine;
    Particle* particlePool;

    int pointer;

    double imax, jmax, xlength, ylength, imaxLocal, jmaxLocal;

    double x1, y1, x2, y2;

    int size, rank;
    
#ifdef _MPI
    MPI_Datatype mpi_particle;
#endif

    double xLocal, yLocal, xOffset, yOffset, xOffsetEnd, yOffsetEnd;

    double* offset;

} ParticleTracer;

extern void initParticleTracer(ParticleTracer*, Discretization*, Parameter*);
extern void injectParticles(ParticleTracer*, double*);
extern void advanceParticles(ParticleTracer*, double*, double*, double*, Comm*, double);
extern void freeParticles(ParticleTracer*);
extern void writeParticles(ParticleTracer*, Comm*);
extern void printParticleTracerParameters(ParticleTracer*);
extern void printParticles(ParticleTracer*);
extern void trace(ParticleTracer*, Discretization*, double);
extern void compress(ParticleTracer*);
extern void particleRandomizer(ParticleTracer*);

#endif