2018-04-19 05:09:25 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-04-19 05:09:25 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
2019-04-09 13:52:53 +00:00
|
|
|
#include <vtkm/cont/Initialize.h>
|
|
|
|
|
2018-04-19 05:09:25 +00:00
|
|
|
#include <vtkm/worklet/ParticleAdvection.h>
|
|
|
|
#include <vtkm/worklet/particleadvection/Integrators.h>
|
|
|
|
#include <vtkm/worklet/particleadvection/ParticleAdvectionWorklets.h>
|
|
|
|
#include <vtkm/worklet/particleadvection/TemporalGridEvaluators.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/Timer.h>
|
|
|
|
#include <vtkm/io/reader/BOVDataSetReader.h>
|
|
|
|
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
// The way to verify if the code produces correct streamlines
|
|
|
|
// is to do a visual test by using VisIt/ParaView to visualize
|
|
|
|
// the file written by this method.
|
2018-06-01 14:31:14 +00:00
|
|
|
int renderAndWriteDataSet(const vtkm::cont::DataSet& dataset)
|
2018-04-19 05:09:25 +00:00
|
|
|
{
|
|
|
|
std::cout << "Trying to render the dataset" << std::endl;
|
|
|
|
vtkm::io::writer::VTKDataSetWriter writer("pathlines.vtk");
|
2018-06-01 14:31:14 +00:00
|
|
|
writer.WriteDataSet(dataset);
|
2018-04-19 05:09:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RunTest(vtkm::Id numSteps, vtkm::Float32 stepSize, vtkm::Id advectType)
|
|
|
|
{
|
|
|
|
using FieldType = vtkm::Float32;
|
|
|
|
using FieldHandle = vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>>;
|
|
|
|
|
|
|
|
// These lines read two datasets, which are BOVs.
|
|
|
|
// Currently VTKm does not support providing time series datasets
|
|
|
|
// In the hackiest way possible this pathlines example run using
|
|
|
|
// two time slices. The way to provide more datasets will be explored
|
|
|
|
// as VTKm evolves.
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> fieldArray1;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> fieldArray2;
|
|
|
|
|
|
|
|
vtkm::io::reader::BOVDataSetReader reader1("slice1.bov");
|
|
|
|
vtkm::cont::DataSet ds1 = reader1.ReadDataSet();
|
|
|
|
ds1.GetField(0).GetData().CopyTo(fieldArray1);
|
|
|
|
|
|
|
|
vtkm::io::reader::BOVDataSetReader reader2("slice2.bov");
|
|
|
|
vtkm::cont::DataSet ds2 = reader2.ReadDataSet();
|
|
|
|
ds2.GetField(0).GetData().CopyTo(fieldArray2);
|
|
|
|
|
|
|
|
// The only change in this example and the vanilla particle advection example is
|
|
|
|
// this example makes use of the TemporalGridEvaluator.
|
2018-08-30 23:48:39 +00:00
|
|
|
using GridEvaluator = vtkm::worklet::particleadvection::TemporalGridEvaluator<FieldHandle>;
|
2018-07-08 01:19:39 +00:00
|
|
|
using Integrator = vtkm::worklet::particleadvection::EulerIntegrator<GridEvaluator>;
|
2018-04-19 05:09:25 +00:00
|
|
|
|
|
|
|
GridEvaluator eval(ds1.GetCoordinateSystem(),
|
|
|
|
ds1.GetCellSet(0),
|
|
|
|
fieldArray1,
|
|
|
|
0,
|
|
|
|
ds2.GetCoordinateSystem(),
|
|
|
|
ds2.GetCellSet(0),
|
|
|
|
fieldArray2,
|
|
|
|
10.0);
|
|
|
|
|
|
|
|
Integrator integrator(eval, stepSize);
|
|
|
|
|
|
|
|
// This example does not work on scale, works on basic 11 particles
|
|
|
|
// so the results are more tractible
|
|
|
|
std::vector<vtkm::Vec<FieldType, 3>> seeds;
|
2018-06-01 14:31:14 +00:00
|
|
|
FieldType x = 0, y = 5, z = 0;
|
2018-04-19 05:09:25 +00:00
|
|
|
for (int i = 0; i <= 11; i++)
|
|
|
|
{
|
|
|
|
vtkm::Vec<FieldType, 3> point;
|
|
|
|
point[0] = x;
|
|
|
|
point[1] = y;
|
|
|
|
point[2] = z++;
|
|
|
|
seeds.push_back(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> seedArray;
|
|
|
|
seedArray = vtkm::cont::make_ArrayHandle(seeds);
|
|
|
|
|
|
|
|
if (advectType == 0)
|
|
|
|
{
|
|
|
|
vtkm::worklet::ParticleAdvection particleAdvection;
|
2018-08-30 15:53:18 +00:00
|
|
|
particleAdvection.Run(integrator, seedArray, numSteps);
|
2018-04-19 05:09:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vtkm::worklet::Streamline streamline;
|
2018-08-30 15:53:18 +00:00
|
|
|
vtkm::worklet::StreamlineResult res = streamline.Run(integrator, seedArray, numSteps);
|
2018-04-19 05:09:25 +00:00
|
|
|
vtkm::cont::DataSet outData;
|
|
|
|
vtkm::cont::CoordinateSystem outputCoords("coordinates", res.positions);
|
|
|
|
outData.AddCellSet(res.polyLines);
|
|
|
|
outData.AddCoordinateSystem(outputCoords);
|
|
|
|
renderAndWriteDataSet(outData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2019-04-09 13:52:53 +00:00
|
|
|
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
|
|
|
auto config = vtkm::cont::Initialize(argc, argv, opts);
|
|
|
|
|
|
|
|
std::cout << "TemporalAdvection Example" << std::endl;
|
|
|
|
std::cout << "Parameters are [options] numSteps stepSize advectionType" << std::endl << std::endl;
|
|
|
|
std::cout << "advectionType Particles=0 Streamlines=1" << std::endl;
|
|
|
|
|
2018-04-19 05:09:25 +00:00
|
|
|
vtkm::Id numSteps;
|
|
|
|
vtkm::Float32 stepSize;
|
|
|
|
vtkm::Id advectionType;
|
|
|
|
|
|
|
|
if (argc < 4)
|
|
|
|
{
|
|
|
|
std::cout << "Wrong number of parameters provided" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
numSteps = atoi(argv[1]);
|
2018-06-01 14:31:14 +00:00
|
|
|
stepSize = static_cast<vtkm::Float32>(atof(argv[2]));
|
2018-04-19 05:09:25 +00:00
|
|
|
advectionType = atoi(argv[3]);
|
|
|
|
|
|
|
|
RunTest(numSteps, stepSize, advectionType);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|