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 <cstdlib>
|
2019-08-26 20:51:07 +00:00
|
|
|
#include <string>
|
2018-04-19 05:09:25 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2022-08-01 12:00:46 +00:00
|
|
|
#include <vtkm/Particle.h>
|
|
|
|
//#include <vtkm/cont/Algorithm.h>
|
2022-07-28 17:28:09 +00:00
|
|
|
#include <vtkm/cont/ArrayCopy.h>
|
2019-08-26 20:51:07 +00:00
|
|
|
#include <vtkm/cont/DataSet.h>
|
|
|
|
#include <vtkm/cont/Initialize.h>
|
2022-08-01 12:00:46 +00:00
|
|
|
//#include <vtkm/cont/Timer.h>
|
2018-04-19 05:09:25 +00:00
|
|
|
|
2022-07-25 14:01:13 +00:00
|
|
|
#include <vtkm/filter/flow/Pathline.h>
|
2018-04-19 05:09:25 +00:00
|
|
|
|
2020-04-30 12:12:04 +00:00
|
|
|
#include <vtkm/io/VTKDataSetReader.h>
|
|
|
|
#include <vtkm/io/VTKDataSetWriter.h>
|
2018-04-19 05:09:25 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2019-09-04 16:09:36 +00:00
|
|
|
// Sample data to use this example can be found in the data directory of the
|
|
|
|
// VTK-m repo in the location temporal_datasets.
|
|
|
|
// These example with these datasets can be used for this example as :
|
|
|
|
// ./Temporal_Advection DoubleGyre_0.vtk 0.0 DoubleGyre_5.vtk 5.0
|
|
|
|
// velocity 500 0.025 pathlines.vtk
|
2019-09-09 21:35:10 +00:00
|
|
|
if (argc < 8)
|
2018-04-19 05:09:25 +00:00
|
|
|
{
|
2020-05-05 14:23:16 +00:00
|
|
|
std::cout
|
|
|
|
<< "Usage:\n"
|
|
|
|
<< "./Temporal_Advection slice1 time1 slice2 time2 field num_steps step_size output\n"
|
|
|
|
<< "\tslice1 : Time slice 1, sample data in vtk-m/data/data/rectilinear/Double_Gyre0.vtk\n"
|
|
|
|
<< "\ttime1 : simulation time for slice 1, for sample data use 0.0\n"
|
|
|
|
<< "\tslice2 : Time slice 2, sample data in vtk-m/data/data/rectilinear/Double_Gyre5.vtk\n"
|
|
|
|
<< "\ttime2 : simulation time for slice 2, for sample data use 5.0\n"
|
|
|
|
<< "\tfield : active velocity field in the data set, for sample data use 'velocity'\n"
|
|
|
|
<< "\tnum_steps : maximum number of steps for advection, for sample data use 500\n"
|
|
|
|
<< "\tstep_size : the size of a single step during advection, for sample data use 0.025\n"
|
|
|
|
<< "\toutput : the name of the output file" << std::endl;
|
|
|
|
std::cout << "Example:\n";
|
|
|
|
std::cout << "./Temporal_Advection ~/vtk-m/data/data/rectilinear/DoubleGyre_0.vtk 0.0 "
|
|
|
|
"~/vtk-m/data/data/rectilinear/DoubleGyre_5.vtk 5.0 velocity 500 0.025 "
|
|
|
|
"pathlines.vtk\n";
|
2018-04-19 05:09:25 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-09-04 16:09:36 +00:00
|
|
|
std::string fieldName, datasetName1, datasetName2, outputName;
|
2019-08-26 20:51:07 +00:00
|
|
|
vtkm::FloatDefault time1, time2;
|
2018-04-19 05:09:25 +00:00
|
|
|
|
2019-08-26 20:51:07 +00:00
|
|
|
vtkm::Id numSteps;
|
|
|
|
vtkm::Float32 stepSize;
|
2018-04-19 05:09:25 +00:00
|
|
|
|
2019-08-26 20:51:07 +00:00
|
|
|
datasetName1 = std::string(argv[1]);
|
2019-09-09 21:35:10 +00:00
|
|
|
time1 = static_cast<vtkm::FloatDefault>(atof(argv[2]));
|
2019-08-26 20:51:07 +00:00
|
|
|
datasetName2 = std::string(argv[3]);
|
2019-09-09 21:35:10 +00:00
|
|
|
time2 = static_cast<vtkm::FloatDefault>(atof(argv[4]));
|
|
|
|
fieldName = std::string(argv[5]);
|
|
|
|
numSteps = atoi(argv[6]);
|
|
|
|
stepSize = static_cast<vtkm::Float32>(atof(argv[7]));
|
|
|
|
outputName = std::string(argv[8]);
|
2019-08-26 20:51:07 +00:00
|
|
|
|
2020-04-30 12:12:04 +00:00
|
|
|
vtkm::io::VTKDataSetReader reader1(datasetName1);
|
2019-08-26 20:51:07 +00:00
|
|
|
vtkm::cont::DataSet ds1 = reader1.ReadDataSet();
|
|
|
|
|
2020-04-30 12:12:04 +00:00
|
|
|
vtkm::io::VTKDataSetReader reader2(datasetName2);
|
2019-08-26 20:51:07 +00:00
|
|
|
vtkm::cont::DataSet ds2 = reader2.ReadDataSet();
|
|
|
|
|
|
|
|
// Use the coordinate system as seeds for performing advection
|
2019-12-19 14:56:05 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Vec3f> pts;
|
|
|
|
vtkm::cont::ArrayCopy(ds1.GetCoordinateSystem().GetData(), pts);
|
2020-08-26 13:36:09 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Particle> seeds;
|
2019-12-19 14:56:05 +00:00
|
|
|
|
|
|
|
vtkm::Id numPts = pts.GetNumberOfValues();
|
|
|
|
seeds.Allocate(numPts);
|
2020-01-28 19:14:32 +00:00
|
|
|
auto ptsPortal = pts.ReadPortal();
|
2020-05-05 14:23:16 +00:00
|
|
|
auto seedPortal = seeds.WritePortal();
|
2019-12-19 14:56:05 +00:00
|
|
|
for (vtkm::Id i = 0; i < numPts; i++)
|
|
|
|
{
|
2020-08-26 13:36:09 +00:00
|
|
|
vtkm::Particle p;
|
2022-12-13 18:10:13 +00:00
|
|
|
p.SetPosition(ptsPortal.Get(i));
|
|
|
|
p.SetID(i);
|
2019-12-19 14:56:05 +00:00
|
|
|
seedPortal.Set(i, p);
|
|
|
|
}
|
2019-08-26 20:51:07 +00:00
|
|
|
|
|
|
|
// Instantiate the filter by providing necessary parameters.
|
|
|
|
// Necessary parameters are :
|
2022-07-25 14:01:13 +00:00
|
|
|
vtkm::filter::flow::Pathline pathlineFilter;
|
2019-09-09 21:35:10 +00:00
|
|
|
pathlineFilter.SetActiveField(fieldName);
|
2019-08-26 20:51:07 +00:00
|
|
|
// 1. The current and next time slice. The current time slice is passed
|
|
|
|
// through the parameter to the Execute method.
|
|
|
|
pathlineFilter.SetNextDataSet(ds2);
|
|
|
|
// 2. The current and next times, these times will be used to interpolate
|
|
|
|
// the velocities for particle positions in space and time.
|
2019-09-11 22:45:38 +00:00
|
|
|
pathlineFilter.SetPreviousTime(time1);
|
2019-08-26 20:51:07 +00:00
|
|
|
pathlineFilter.SetNextTime(time2);
|
|
|
|
// 3. Maximum number of steps the particle is allowed to take until termination.
|
|
|
|
pathlineFilter.SetNumberOfSteps(numSteps);
|
|
|
|
// 4. Length for each step.
|
|
|
|
pathlineFilter.SetStepSize(stepSize);
|
|
|
|
// 5. Seeds for advection.
|
|
|
|
pathlineFilter.SetSeeds(seeds);
|
|
|
|
|
|
|
|
vtkm::cont::DataSet output = pathlineFilter.Execute(ds1);
|
|
|
|
|
|
|
|
// 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.
|
2020-04-30 12:12:04 +00:00
|
|
|
vtkm::io::VTKDataSetWriter writer(outputName);
|
2019-08-26 20:51:07 +00:00
|
|
|
writer.WriteDataSet(output);
|
2018-04-19 05:09:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|