mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Merge topic 'fix_temporal_example'
9b78276ca Updating usage statement for temporal advection example 8e27562ce Adding information about sample datasets in example fd23bb3c7 Update attributes to include all files in data to lfs 01d735e1a Merge branch 'master' of gitlab.kitware.com:vtk/vtk-m into fix_temporal_example d9b038fdd Updating method name in unit test b7191e257 Fixing temporal advection example Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Kenneth Moreland <kmorel@sandia.gov> Merge-request: !1814
This commit is contained in:
commit
9e38f02546
4
.gitattributes
vendored
4
.gitattributes
vendored
@ -6,8 +6,8 @@
|
||||
*.hxx our-c-style
|
||||
*.cu our-c-style
|
||||
|
||||
data/* filter=lfs diff=lfs merge=lfs -text
|
||||
/**/data/* filter=lfs diff=lfs merge=lfs -text
|
||||
data/** filter=lfs diff=lfs merge=lfs -text
|
||||
/**/data/** filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
*.cmake whitespace=tab-in-indent
|
||||
*.md whitespace=tab-in-indent conflict-marker-size=79 -whitespace
|
||||
|
3
data/temporal_datasets/DoubleGyre_0.vtk
Normal file
3
data/temporal_datasets/DoubleGyre_0.vtk
Normal file
@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6969444d4082055c2334a834f025cf8490bd6d43bb2965b3e0859740e0b73767
|
||||
size 7670
|
3
data/temporal_datasets/DoubleGyre_5.vtk
Normal file
3
data/temporal_datasets/DoubleGyre_5.vtk
Normal file
@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b7a6f69e78910d828523fa3c05b787f1d6d89ec6049d2279758b3b032177fda5
|
||||
size 7703
|
@ -8,127 +8,95 @@
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
|
||||
#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 <string>
|
||||
#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.
|
||||
int renderAndWriteDataSet(const vtkm::cont::DataSet& dataset)
|
||||
{
|
||||
std::cout << "Trying to render the dataset" << std::endl;
|
||||
vtkm::io::writer::VTKDataSetWriter writer("pathlines.vtk");
|
||||
writer.WriteDataSet(dataset);
|
||||
return 0;
|
||||
}
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/Initialize.h>
|
||||
#include <vtkm/cont/Timer.h>
|
||||
|
||||
#include <vtkm/filter/Pathline.h>
|
||||
|
||||
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.
|
||||
using GridEvaluator = vtkm::worklet::particleadvection::TemporalGridEvaluator<FieldHandle>;
|
||||
using Integrator = vtkm::worklet::particleadvection::EulerIntegrator<GridEvaluator>;
|
||||
|
||||
GridEvaluator eval(ds1.GetCoordinateSystem(),
|
||||
ds1.GetCellSet(),
|
||||
fieldArray1,
|
||||
0,
|
||||
ds2.GetCoordinateSystem(),
|
||||
ds2.GetCellSet(),
|
||||
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;
|
||||
FieldType x = 0, y = 5, z = 0;
|
||||
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;
|
||||
particleAdvection.Run(integrator, seedArray, numSteps);
|
||||
}
|
||||
else
|
||||
{
|
||||
vtkm::worklet::Streamline streamline;
|
||||
vtkm::worklet::StreamlineResult res = streamline.Run(integrator, seedArray, numSteps);
|
||||
vtkm::cont::DataSet outData;
|
||||
vtkm::cont::CoordinateSystem outputCoords("coordinates", res.positions);
|
||||
outData.SetCellSet(res.polyLines);
|
||||
outData.AddCoordinateSystem(outputCoords);
|
||||
renderAndWriteDataSet(outData);
|
||||
}
|
||||
}
|
||||
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
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;
|
||||
// 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
|
||||
std::cout
|
||||
<< "Parameters : [options] slice1 time1 slice2 time2 field num_steps step_size output\n"
|
||||
<< "slice1 : Time slice 1, sample data in vtk-m/data/temporal_datasets/Double_Gyre0.vtk\n"
|
||||
<< "time1 : simulation time for slice 1, for sample data use 0.0\n"
|
||||
<< "slice2 : Time slice 2, sample data in vtk-m/data/temporal_datasets/Double_Gyre5.vtk\n"
|
||||
<< "time2 : simulation time for slice 2, for sample data use 5.0\n"
|
||||
<< "field : active velocity field in the data set, for sample data use 'velocity'\n"
|
||||
<< "num_steps : maximum number of steps for advection, for sample data use 500\n"
|
||||
<< "step_size : the size of a single step during advection, for sample data use 0.025\n"
|
||||
<< "output : the name of the output file" << std::endl;
|
||||
|
||||
vtkm::Id numSteps;
|
||||
vtkm::Float32 stepSize;
|
||||
vtkm::Id advectionType;
|
||||
|
||||
if (argc < 4)
|
||||
if (argc < 8)
|
||||
{
|
||||
std::cout << "Wrong number of parameters provided" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
numSteps = atoi(argv[1]);
|
||||
stepSize = static_cast<vtkm::Float32>(atof(argv[2]));
|
||||
advectionType = atoi(argv[3]);
|
||||
std::string fieldName, datasetName1, datasetName2, outputName;
|
||||
vtkm::FloatDefault time1, time2;
|
||||
|
||||
RunTest(numSteps, stepSize, advectionType);
|
||||
vtkm::Id numSteps;
|
||||
vtkm::Float32 stepSize;
|
||||
|
||||
datasetName1 = std::string(argv[1]);
|
||||
time1 = static_cast<vtkm::FloatDefault>(atof(argv[2]));
|
||||
datasetName2 = std::string(argv[3]);
|
||||
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]);
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader1(datasetName1);
|
||||
vtkm::cont::DataSet ds1 = reader1.ReadDataSet();
|
||||
|
||||
vtkm::io::reader::VTKDataSetReader reader2(datasetName2);
|
||||
vtkm::cont::DataSet ds2 = reader2.ReadDataSet();
|
||||
|
||||
// Use the coordinate system as seeds for performing advection
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec3f> seeds;
|
||||
vtkm::cont::ArrayCopy(ds1.GetCoordinateSystem().GetData(), seeds);
|
||||
|
||||
// Instantiate the filter by providing necessary parameters.
|
||||
// Necessary parameters are :
|
||||
vtkm::filter::Pathline pathlineFilter;
|
||||
pathlineFilter.SetActiveField(fieldName);
|
||||
// 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.
|
||||
pathlineFilter.SetCurrentTime(time1);
|
||||
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.
|
||||
vtkm::io::writer::VTKDataSetWriter writer(outputName);
|
||||
writer.WriteDataSet(output);
|
||||
return 0;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
Pathline();
|
||||
|
||||
VTKM_CONT
|
||||
void SetPreviousTime(vtkm::worklet::particleadvection::ScalarType t) { this->PreviousTime = t; }
|
||||
void SetCurrentTime(vtkm::worklet::particleadvection::ScalarType t) { this->CurrentTime = t; }
|
||||
VTKM_CONT
|
||||
void SetNextTime(vtkm::worklet::particleadvection::ScalarType t) { this->NextTime = t; }
|
||||
|
||||
@ -67,7 +67,7 @@ public:
|
||||
private:
|
||||
vtkm::worklet::Streamline Worklet;
|
||||
vtkm::worklet::particleadvection::ScalarType StepSize;
|
||||
vtkm::worklet::particleadvection::ScalarType PreviousTime;
|
||||
vtkm::worklet::particleadvection::ScalarType CurrentTime;
|
||||
vtkm::worklet::particleadvection::ScalarType NextTime;
|
||||
vtkm::cont::DataSet NextDataSet;
|
||||
vtkm::Id NumberOfSteps;
|
||||
|
@ -68,7 +68,7 @@ inline VTKM_CONT vtkm::cont::DataSet Pathline::DoExecute(
|
||||
using RK4Type = vtkm::worklet::particleadvection::RK4Integrator<GridEvalType>;
|
||||
|
||||
GridEvalType eval(
|
||||
coords, cells, field, this->PreviousTime, coords2, cells2, field2, this->NextTime);
|
||||
coords, cells, field, this->CurrentTime, coords2, cells2, field2, this->NextTime);
|
||||
RK4Type rk4(eval, static_cast<vtkm::worklet::particleadvection::ScalarType>(this->StepSize));
|
||||
|
||||
vtkm::worklet::Streamline streamline;
|
||||
|
@ -86,7 +86,7 @@ void TestPathline()
|
||||
|
||||
vtkm::filter::Pathline pathline;
|
||||
|
||||
pathline.SetPreviousTime(0.0f);
|
||||
pathline.SetCurrentTime(0.0f);
|
||||
pathline.SetNextTime(1.0f);
|
||||
pathline.SetNextDataSet(ds2);
|
||||
pathline.SetStepSize(0.05f);
|
||||
|
Loading…
Reference in New Issue
Block a user