bridge.cpp 2.74 KB
Newer Older
1 2 3 4 5 6 7
#include "bridge.h"

#include "dataadaptor.h"

#ifdef ENABLE_HISTOGRAM
#include "HistogramAnalysisAdaptor.h"
#endif
8 9 10
#ifdef ENABLE_AUTOCORRELATION
#include <AutocorrelationAnalysisAdaptor.h>
#endif
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

#include <vtkDataObject.h>
#include <vtkInsituAnalysisAdaptor.h>
#include <vtkNew.h>
#include <vtkSmartPointer.h>
#include <vector>

namespace bridge
{
static vtkNew<oscillators::DataAdaptor> GlobalDataAdaptor;
typedef std::vector<vtkSmartPointer<vtkInsituAnalysisAdaptor> > GlobalAnalysesType;
static GlobalAnalysesType GlobalAnalyses;
bool ExecuteGlobalAnalyses()
{
  for (auto a : GlobalAnalyses)
    {
    if (!a->Execute(GlobalDataAdaptor.GetPointer()))
      {
      return false;
      }
    }
  return true;
}

//-----------------------------------------------------------------------------
void initialize(MPI_Comm world,
                size_t window,
                size_t nblocks,
                size_t n_local_blocks,
                int domain_shape_x, int domain_shape_y, int domain_shape_z,
                int* gid,
                int* from_x, int* from_y, int* from_z,
                int* to_x,   int* to_y,   int* to_z)
{
  GlobalDataAdaptor->Initialize(nblocks);
  for (size_t cc=0; cc < n_local_blocks; ++cc)
    {
    GlobalDataAdaptor->SetBlockExtent(gid[cc],
      from_x[cc], to_x[cc],
      from_y[cc], to_y[cc],
      from_z[cc], to_z[cc]);
    }
#ifdef ENABLE_HISTOGRAM
  vtkNew<HistogramAnalysisAdaptor> histogram;
  histogram->Initialize(world, 10, vtkDataObject::FIELD_ASSOCIATION_POINTS, "data");
  GlobalAnalyses.push_back(histogram.GetPointer());
#endif
58 59 60 61 62 63 64 65 66 67 68
#ifdef ENABLE_AUTOCORRELATION
  vtkNew<AutocorrelationAnalysisAdaptor> autocorrelation;
  autocorrelation->Initialize(world,
                              window,
                              n_local_blocks,
                              domain_shape_x, domain_shape_y, domain_shape_z,
                              gid,
                              from_x, from_y, from_z,
                              to_x,   to_y,   to_z);
  GlobalAnalyses.push_back(autocorrelation.GetPointer());
#endif
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
}

//-----------------------------------------------------------------------------
void set_data(int gid, float* data)
{
  GlobalDataAdaptor->SetBlockData(gid, data);
}

//-----------------------------------------------------------------------------
void analyze()
{
  ExecuteGlobalAnalyses();
  GlobalDataAdaptor->ReleaseData();
}

//-----------------------------------------------------------------------------
void finalize(size_t k_max, size_t nblocks)
{
87 88 89 90 91 92 93 94 95
#ifdef ENABLE_AUTOCORRELATION
  for (auto a : GlobalAnalyses)
    {
    if (AutocorrelationAnalysisAdaptor* aca = AutocorrelationAnalysisAdaptor::SafeDownCast(a))
      {
      aca->PrintResults(k_max, nblocks);
      }
    }
#endif
96 97 98 99
  GlobalAnalyses.clear();
}

}