Source

active-particles / src / enzo / ActiveParticle_SampleParticle.C

Full commit
/***********************************************************************
/
/  AN EXAMPLE ACTIVE PARTICLE TYPE
/
/  written by: Matthew Turk
/  date:       May, 2011
/
/  PURPOSE:
/
************************************************************************/

#include <string.h>
#include <map>
#include <iostream>
#include <stdexcept>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include "ErrorExceptions.h"
#include "macros_and_parameters.h"
#include "typedefs.h"
#include "global_data.h"
#include "Fluxes.h"
#include "GridList.h"
#include "ExternalBoundary.h"
#include "Grid.h"
#include "Hierarchy.h"
#include "TopGridData.h"
#include "EventHooks.h"
#include "ActiveParticle.h"

/* We need to make sure that we can operate on the grid, so this dance is
 * necessary to make sure that grid is 'friend' to this particle type. */

class ActiveParticleType_SampleParticle;
class SampleParticleBufferHandler;

class SampleParticleGrid : private grid {
  friend class ActiveParticleType_SampleParticle;
};

/* Note that we only refer to SampleParticleGrid here. 
 * Given a grid object, we static case to get this:
 *
 *    SampleParticleGrid *thisgrid =
 *      static_cast<SampleParticleGrid *>(thisgrid_orig); */

class ActiveParticleType_SampleParticle : public ActiveParticleType
{
public:
  static int EvaluateFormation(grid *thisgrid_orig, ActiveParticleFormationData &data);
  static void DescribeSupplementalData(ActiveParticleFormationDataFlags &flags);
  static int WriteToOutput(ActiveParticleType *these_particles, int n, int GridRank, hid_t group_id);
  static int ReadFromOutput(ActiveParticleType **particles_to_read, int *n, int GridRank, hid_t group_id);
  static ParticleBufferHandler *AllocateBuffers(int NumberOfParticles);
  static int EvaluateFeedback(grid *thisgrid_orig, ActiveParticleFormationData &data);
  static int InitializeParticleType(void);
  
  ENABLED_PARTICLE_ID_ACCESSOR
};

int ActiveParticleType_SampleParticle::InitializeParticleType(void)
{
  return SUCCESS;
}

int ActiveParticleType_SampleParticle::EvaluateFormation(grid *thisgrid_orig, ActiveParticleFormationData &data)
{
  SampleParticleGrid *thisgrid =
    static_cast<SampleParticleGrid *>(thisgrid_orig);
  fprintf(stderr, "Checking formation of sample particles.\n");
  return 0;
}

int ActiveParticleType_SampleParticle::EvaluateFeedback
(grid *thisgrid_orig, ActiveParticleFormationData &data)
{
  return SUCCESS;
}

void ActiveParticleType_SampleParticle::DescribeSupplementalData(ActiveParticleFormationDataFlags &flags)
{
  flags.DarkMatterDensity = true;
}

int ActiveParticleType_SampleParticle::WriteToOutput(ActiveParticleType *these_particles, int n, int GridRank, hid_t group_id)
{
  ActiveParticleType_SampleParticle *ParticlesToWrite = static_cast<ActiveParticleType_SampleParticle *>(these_particles);
  return SUCCESS;
}

int ActiveParticleType_SampleParticle::ReadFromOutput(ActiveParticleType **particles_to_read, int *n, int GridRank, hid_t group_id)
{

  return SUCCESS;
}

class SampleParticleBufferHandler : public ParticleBufferHandler
{
  public:
    SampleParticleBufferHandler(int NumberOfParticles) { }
};

ParticleBufferHandler *ActiveParticleType_SampleParticle::AllocateBuffers(int NumberOfParticles)
{
    SampleParticleBufferHandler *handler = new SampleParticleBufferHandler(NumberOfParticles);
    return handler;
}


namespace {
  ActiveParticleType_info *SampleParticleInfo = 
    register_ptype <ActiveParticleType_SampleParticle> ("SampleParticle");
}