Merged with master.

This commit is contained in:
Petar Hristov 2020-07-27 16:27:14 +01:00
commit ad497e2619
234 changed files with 4172 additions and 2408 deletions

@ -25,10 +25,8 @@ doxygen:
- "cmake -V -P .gitlab/ci/config/gitlab_ci_setup.cmake" - "cmake -V -P .gitlab/ci/config/gitlab_ci_setup.cmake"
- "ctest -VV -S .gitlab/ci/ctest_configure.cmake" - "ctest -VV -S .gitlab/ci/ctest_configure.cmake"
script: script:
- eval `ssh-agent -s`
- ssh-add <(echo "$DOC_API_KEY_BASE64" | base64 --decode)
- doxygen build/docs/doxyfile - doxygen build/docs/doxyfile
- rsync -tv --recursive --delete -e "ssh -o StrictHostKeyChecking=no" build/docs/doxygen/html/ vtkm.documentation - rsync -tv --recursive --delete -e "ssh -i $DOC_KEY_FILE -o StrictHostKeyChecking=no" build/docs/doxygen/html/ kitware@public.kitware.com:vtkm_documentation/
variables: variables:
CMAKE_BUILD_TYPE: Release CMAKE_BUILD_TYPE: Release
VTKM_SETTINGS: "tbb+openmp+mpi+shared+docs" VTKM_SETTINGS: "tbb+openmp+mpi+shared+docs"

@ -97,8 +97,8 @@ void BenchContToExecRead(benchmark::State& state)
state.SetLabel(desc.str()); state.SetLabel(desc.str());
} }
std::vector<ValueType> vec(static_cast<std::size_t>(numValues)); std::vector<ValueType> vec(static_cast<std::size_t>(numValues), 2);
ArrayType array = vtkm::cont::make_ArrayHandle(vec); ArrayType array = vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::On);
vtkm::cont::Invoker invoker{ device }; vtkm::cont::Invoker invoker{ device };
vtkm::cont::Timer timer{ device }; vtkm::cont::Timer timer{ device };
@ -181,8 +181,8 @@ void BenchContToExecReadWrite(benchmark::State& state)
state.SetLabel(desc.str()); state.SetLabel(desc.str());
} }
std::vector<ValueType> vec(static_cast<std::size_t>(numValues)); std::vector<ValueType> vec(static_cast<std::size_t>(numValues), 2);
ArrayType array = vtkm::cont::make_ArrayHandle(vec); ArrayType array = vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::On);
vtkm::cont::Invoker invoker{ device }; vtkm::cont::Invoker invoker{ device };
vtkm::cont::Timer timer{ device }; vtkm::cont::Timer timer{ device };
@ -223,8 +223,8 @@ void BenchRoundTripRead(benchmark::State& state)
state.SetLabel(desc.str()); state.SetLabel(desc.str());
} }
std::vector<ValueType> vec(static_cast<std::size_t>(numValues)); std::vector<ValueType> vec(static_cast<std::size_t>(numValues), 2);
ArrayType array = vtkm::cont::make_ArrayHandle(vec); ArrayType array = vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::On);
vtkm::cont::Invoker invoker{ device }; vtkm::cont::Invoker invoker{ device };
vtkm::cont::Timer timer{ device }; vtkm::cont::Timer timer{ device };
@ -277,7 +277,7 @@ void BenchRoundTripReadWrite(benchmark::State& state)
} }
std::vector<ValueType> vec(static_cast<std::size_t>(numValues)); std::vector<ValueType> vec(static_cast<std::size_t>(numValues));
ArrayType array = vtkm::cont::make_ArrayHandle(vec); ArrayType array = vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::On);
vtkm::cont::Invoker invoker{ device }; vtkm::cont::Invoker invoker{ device };
vtkm::cont::Timer timer{ device }; vtkm::cont::Timer timer{ device };

@ -860,8 +860,12 @@ void InitDataSet(int& argc, char** argv)
if (options[HELP]) if (options[HELP])
{ {
// FIXME: Print google benchmark usage too option::printUsage(std::cout, usage.data());
option::printUsage(std::cerr, usage.data()); // Print google benchmark usage too
const char* helpstr = "--help";
char* tmpargv[] = { argv[0], const_cast<char*>(helpstr), nullptr };
int tmpargc = 2;
VTKM_EXECUTE_BENCHMARKS(tmpargc, tmpargv);
exit(0); exit(0);
} }
@ -1014,16 +1018,12 @@ int main(int argc, char* argv[])
// Parse VTK-m options: // Parse VTK-m options:
Config = vtkm::cont::Initialize(argc, args.data(), opts); Config = vtkm::cont::Initialize(argc, args.data(), opts);
// This occurs when it is help // This opts changes when it is help
if (opts == vtkm::cont::InitializeOptions::None) if (opts != vtkm::cont::InitializeOptions::None)
{
std::cout << Config.Usage << std::endl;
}
else
{ {
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(Config.Device); vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(Config.Device);
InitDataSet(argc, args.data());
} }
InitDataSet(argc, args.data());
const std::string dataSetSummary = []() -> std::string { const std::string dataSetSummary = []() -> std::string {
std::ostringstream out; std::ostringstream out;

@ -0,0 +1,39 @@
# Deprecate ArrayHandleVirtualCoordinates
As we port VTK-m to more types of accelerator architectures, supporting
virtual methods is becoming more problematic. Thus, we are working to back
out of using virtual methods in the execution environment.
One of the most widespread users of virtual methods in the execution
environment is `ArrayHandleVirtual`. As a first step of deprecating this
class, we first deprecate the `ArrayHandleVirtualCoordinates` subclass.
Not surprisingly, `ArrayHandleVirtualCoordinates` is used directly by
`CoordinateSystem`. The biggest change necessary was that the `GetData`
method returned an `ArrayHandleVirtualCoordinates`, which obviously would
not work if that class is deprecated.
An oddness about this return type is that it is quite different from the
superclass's method of the same name. Rather, `Field` returns a
`VariantArrayHandle`. Since this had to be corrected anyway, it was decided
to change `CoordinateSystem`'s `GetData` to also return a
`VariantArrayHandle`, although its typelist is set to just `vtkm::Vec3f`.
To try to still support old code that expects the deprecated behavior of
returning an `ArrayHandleVirtualCoordinates`, `CoordinateSystem::GetData`
actually returns a "hidden" subclass of `VariantArrayHandle` that
automatically converts itself to an `ArrayHandleVirtualCoordinates`. (A
deprecation warning is given if this is done.)
This approach to support deprecated code is not perfect. The returned value
for `CoordinateSystem::GetData` can only be used as an `ArrayHandle` if a
method is directly called on it or if it is cast specifically to
`ArrayHandleVirtualCoordinates` or its superclass. For example, if passing
it to a method argument typed as `vtkm::cont::ArrayHandle<T, S>` where `T`
and `S` are template parameters, then the conversion will fail.
To continue to support ease of use, `CoordinateSystem` now has a method
named `GetDataAsMultiplexer` that returns the data as an
`ArrayHandleMultiplexer`. This can be employed to quickly use the
`CoordinateSystem` as an array without the overhead of a `CastAndCall`.

@ -0,0 +1,120 @@
# Improvements to moving data into ArrayHandle
We have made several improvements to adding data into an `ArrayHandle`.
## Moving data from an `std::vector`
For numerous reasons, it is convenient to define data in a `std::vector`
and then wrap that into an `ArrayHandle`. There are two obvious ways to do
this. First, you could deep copy the data into an `ArrayHandle`, which has
obvious drawbacks. Second, you could take the pointer for the data in the
`std::vector` and use that as user-allocated memory in the `ArrayHandle`
without deep copying it. The problem with this shallow copy is that it is
unsafe. If the `std::vector` goes out of scope (or gets resized), then the
data the `ArrayHandle` is pointing to becomes unallocated, which will lead
to unpredictable behavior.
However, there is a third option. It is often the case that an
`std::vector` is filled and then becomes unused once it is converted to an
`ArrayHandle`. In this case, what we really want is to pass the data off to
the `ArrayHandle` so that the `ArrayHandle` is now managing the data and
not the `std::vector`.
C++11 has a mechanism to do this: move semantics. You can now pass
variables to functions as an "rvalue" (right-hand value). When something is
passed as an rvalue, it can pull state out of that variable and move it
somewhere else. `std::vector` implements this movement so that an rvalue
can be moved to another `std::vector` without actually copying the data.
`make_ArrayHandle` now also takes advantage of this feature to move rvalue
`std::vector`s.
There is a special form of `make_ArrayHandle` named `make_ArrayHandleMove`
that takes an rvalue. There is also a special overload of
`make_ArrayHandle` itself that handles an rvalue `vector`. (However, using
the explicit move version is better if you want to make sure the data is
actually moved.)
So if you create the `std::vector` in the call to `make_ArrayHandle`, then
the data only gets created once.
``` cpp
auto array = vtkm::cont::make_ArrayHandleMove(std::vector<vtkm::Id>{ 2, 6, 1, 7, 4, 3, 9 });
```
Note that there is now a better way to express an initializer list to
`ArrayHandle` documented below. But this form of `ArrayHandleMove` can be
particularly useful for initializing an array to all of a particular value.
For example, an easy way to initialize an array of 1000 elements all to 1
is
``` cpp
auto array = vtkm::cont::make_ArrayHandleMove(std::vector<vtkm::Id>(1000, 1));
```
You can also move the data from an already created `std::vector` by using
the `std::move` function to convert it to an rvalue. When you do this, the
`std::vector` becomes invalid after the call and any use will be undefined.
``` cpp
std::vector<vtkm::Id> vector;
// fill vector
auto array = vtkm::cont::make_ArrayHandleMove(std::move(vector));
```
## Make `ArrayHandle` from initalizer list
A common use case for using `std::vector` (particularly in our unit tests)
is to quickly add an initalizer list into an `ArrayHandle`. Repeating the
example from above:
``` cpp
auto array = vtkm::cont::make_ArrayHandleMove(std::vector<vtkm::Id>{ 2, 6, 1, 7, 4, 3, 9 });
```
However, creating the `std::vector` should be unnecessary. Why not be able
to create the `ArrayHandle` directly from an initializer list? Now you can
by simply passing an initializer list to `make_ArrayHandle`.
``` cpp
auto array = vtkm::cont::make_ArrayHandle({ 2, 6, 1, 7, 4, 3, 9 });
```
There is an issue here. The type here can be a little ambiguous (for
humans). In this case, `array` will be of type
`vtkm::cont::ArrayHandleBasic<int>`, since that is what an integer literal
defaults to. This could be a problem if, for example, you want to use
`array` as an array of `vtkm::Id`, which could be of type `vtkm::Int64`.
This is easily remedied by specifying the desired value type as a template
argument to `make_ArrayHandle`.
``` cpp
auto array = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 2, 6, 1, 7, 4, 3, 9 });
```
## Deprecated `make_ArrayHandle` with default shallow copy
For historical reasons, passing an `std::vector` or a pointer to
`make_ArrayHandle` does a shallow copy (i.e. `CopyFlag` defaults to `Off`).
Although more efficient, this mode is inherintly unsafe, and making it the
default is asking for trouble.
To combat this, calling `make_ArrayHandle` without a copy flag is
deprecated. In this way, if you wish to do the faster but more unsafe
creation of an `ArrayHandle` you should explicitly express that.
This requried quite a few changes through the VTK-m source (particularly in
the tests).
## Similar changes to `Field`
`vtkm::cont::Field` has a `make_Field` helper function that is similar to
`make_ArrayHandle`. It also features the ability to create fields from
`std::vector`s and C arrays. It also likewise had the same unsafe behavior
by default of not copying from the source of the arrays.
That behavior has similarly been depreciated. You now have to specify a
copy flag.
The ability to construct a `Field` from an initializer list of values has
also been added.

@ -22,6 +22,7 @@ if(VTKm_ENABLE_EXAMPLES)
add_subdirectory(game_of_life) add_subdirectory(game_of_life)
add_subdirectory(hello_worklet) add_subdirectory(hello_worklet)
add_subdirectory(histogram) add_subdirectory(histogram)
add_subdirectory(ising)
add_subdirectory(lagrangian) add_subdirectory(lagrangian)
add_subdirectory(mesh_quality) add_subdirectory(mesh_quality)
add_subdirectory(multi_backend) add_subdirectory(multi_backend)

@ -52,11 +52,11 @@ void TestCosmoCenterFinder(const char* fileName)
} }
vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray = vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray =
vtkm::cont::make_ArrayHandle<vtkm::Float32>(xLocation, nParticles); vtkm::cont::make_ArrayHandle<vtkm::Float32>(xLocation, nParticles, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray = vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray =
vtkm::cont::make_ArrayHandle<vtkm::Float32>(yLocation, nParticles); vtkm::cont::make_ArrayHandle<vtkm::Float32>(yLocation, nParticles, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray = vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray =
vtkm::cont::make_ArrayHandle<vtkm::Float32>(zLocation, nParticles); vtkm::cont::make_ArrayHandle<vtkm::Float32>(zLocation, nParticles, vtkm::CopyFlag::Off);
// Output MBP particleId pairs array // Output MBP particleId pairs array
vtkm::Pair<vtkm::Id, vtkm::Float32> nxnResult; vtkm::Pair<vtkm::Id, vtkm::Float32> nxnResult;

@ -53,11 +53,11 @@ void TestCosmoHaloFinder(const char* fileName)
} }
vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray = vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray =
vtkm::cont::make_ArrayHandle<vtkm::Float32>(xLocation, nParticles); vtkm::cont::make_ArrayHandleMove<vtkm::Float32>(xLocation, nParticles);
vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray = vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray =
vtkm::cont::make_ArrayHandle<vtkm::Float32>(yLocation, nParticles); vtkm::cont::make_ArrayHandleMove<vtkm::Float32>(yLocation, nParticles);
vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray = vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray =
vtkm::cont::make_ArrayHandle<vtkm::Float32>(zLocation, nParticles); vtkm::cont::make_ArrayHandleMove<vtkm::Float32>(zLocation, nParticles);
// Output halo id, mbp id and min potential per particle // Output halo id, mbp id and min potential per particle
vtkm::cont::ArrayHandle<vtkm::Id> resultHaloId; vtkm::cont::ArrayHandle<vtkm::Id> resultHaloId;
@ -88,10 +88,6 @@ void TestCosmoHaloFinder(const char* fileName)
xLocArray.ReleaseResources(); xLocArray.ReleaseResources();
yLocArray.ReleaseResources(); yLocArray.ReleaseResources();
zLocArray.ReleaseResources(); zLocArray.ReleaseResources();
delete[] xLocation;
delete[] yLocation;
delete[] zLocation;
} }
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////

@ -17,7 +17,6 @@
#include <iostream> #include <iostream>
#include <random> #include <random>
#include <vtkm/Math.h>
#include <vtkm/cont/ArrayHandle.h> #include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleCounting.h> #include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/DataSetBuilderUniform.h> #include <vtkm/cont/DataSetBuilderUniform.h>
@ -29,10 +28,8 @@
#include <vtkm/filter/FilterDataSet.h> #include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/WorkletPointNeighborhood.h> #include <vtkm/worklet/WorkletPointNeighborhood.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/TryExecute.h> #include <vtkm/cont/TryExecute.h>
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
//Suppress warnings about glut being deprecated on OSX //Suppress warnings about glut being deprecated on OSX
#if (defined(VTKM_GCC) || defined(VTKM_CLANG)) #if (defined(VTKM_GCC) || defined(VTKM_CLANG))

@ -0,0 +1,21 @@
##============================================================================
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
##
## 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.
##============================================================================
cmake_minimum_required(VERSION 3.12...3.15 FATAL_ERROR)
project(IsingModel CXX)
#Find the VTK-m package
find_package(VTKm REQUIRED QUIET)
add_executable(Ising Ising.cxx)
target_link_libraries(Ising PRIVATE vtkm_worklet vtkm_io vtkm_rendering)
vtkm_add_target_information(Ising
DROP_UNUSED_SYMBOLS MODIFY_CUDA_FLAGS
DEVICE_SOURCES Ising.cxx)

122
examples/ising/Ising.cxx Normal file

@ -0,0 +1,122 @@
//
// Created by ollie on 7/8/20.
//
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// 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.
//============================================================================
/// Simulation of ferromagnetism using the Ising Model
/// Reference: Computational Physics 2nd Edition, Nicholas Giordano & Hisao Nakanishi
#include <iomanip>
#include <vtkm/cont/ArrayHandleRandomUniformReal.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderUniform.h>
#include <vtkm/cont/Initialize.h>
#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/MapperRayTracer.h>
#include <vtkm/rendering/Scene.h>
#include <vtkm/rendering/View2D.h>
#include <vtkm/worklet/WorkletCellNeighborhood.h>
struct UpDown
{
VTKM_EXEC_CONT vtkm::Float32 operator()(vtkm::Float32 p) const { return p > 0.5 ? 1.0f : -1.0f; }
};
vtkm::cont::DataSet SpinField(vtkm::Id2 dims)
{
auto result =
vtkm::cont::DataSetBuilderUniform::Create(dims, vtkm::Vec2f{ 0, 0 }, vtkm::Vec2f{ 1, 1 });
vtkm::cont::ArrayHandle<vtkm::Float32> spins;
vtkm::cont::ArrayCopy(
vtkm::cont::make_ArrayHandleTransform(
vtkm::cont::ArrayHandleRandomUniformReal<vtkm::Float32>(result.GetNumberOfCells()), UpDown{}),
spins);
result.AddCellField("spins", spins);
return result;
}
struct UpdateSpins : public vtkm::worklet::WorkletCellNeighborhood
{
using ControlSignature = void(CellSetIn,
FieldInNeighborhood prevspin,
FieldIn prob,
FieldOut spin);
using ExecutionSignature = void(_2, _3, _4);
template <typename NeighIn>
VTKM_EXEC_CONT void operator()(const NeighIn& prevspin,
vtkm::Float32 p,
vtkm::Float32& spin) const
{
// TODO: what is the real value and unit of the change constant J and Boltzmann constant kB?
const vtkm::Float32 J = 1.f;
const vtkm::Float32 kB = 1.f;
// TODO: temperature in Kelvin
const vtkm::Float32 T = 5.f;
const auto mySpin = prevspin.Get(0, 0, 0);
// 1. Calculate the energy of flipping, E_flip
vtkm::Float32 E_flip =
J * mySpin * (prevspin.Get(-1, -1, 0) + prevspin.Get(-1, 0, 0) + prevspin.Get(-1, 1, 0) +
prevspin.Get(0, -1, 0) + prevspin.Get(0, 1, 0) + prevspin.Get(1, -1, 0) +
prevspin.Get(1, 0, 0) + prevspin.Get(1, 1, 0));
if (E_flip <= 0)
{
// 2. If E_flip <= 0, just flip the spin
spin = -1.f * mySpin;
}
else
{
// 3. otherwise, flip the spin if the Boltzmann factor exp(-E_flip/kB*T) is larger than the
// uniform real random number p.
if (p <= vtkm::Exp(-E_flip / (kB * T)))
spin = -1.f * mySpin;
else
spin = mySpin;
}
}
};
int main(int argc, char** argv)
{
auto opts =
vtkm::cont::InitializeOptions::DefaultAnyDevice | vtkm::cont::InitializeOptions::Strict;
vtkm::cont::Initialize(argc, argv, opts);
auto dataSet = SpinField({ 5, 5 });
vtkm::cont::ArrayHandle<vtkm::Float32> spins;
dataSet.GetCellField("spins").GetData().CopyTo(spins);
vtkm::rendering::Scene scene;
vtkm::rendering::Actor actor(dataSet.GetCellSet(),
dataSet.GetCoordinateSystem(),
dataSet.GetCellField("spins"),
vtkm::cont::ColorTable("Cool To Warm"));
scene.AddActor(actor);
vtkm::rendering::CanvasRayTracer canvas(1024, 1024);
vtkm::rendering::MapperRayTracer mapper;
mapper.SetShadingOn(false);
vtkm::rendering::View2D view(scene, mapper, canvas);
view.Paint();
view.SaveAs("spin0.png");
vtkm::cont::Invoker invoker;
for (vtkm::UInt32 i = 1; i < 10; ++i)
{
vtkm::cont::ArrayHandleRandomUniformReal<vtkm::Float32> prob(dataSet.GetNumberOfCells(), { i });
invoker(UpdateSpins{}, dataSet.GetCellSet(), spins, prob, spins);
view.Paint();
view.SaveAs("spin" + std::to_string(i) + ".png");
}
}

@ -42,7 +42,7 @@ vtkm::cont::DataSet make_test3DImageData(vtkm::Id3 dims)
vtkm::cont::ArrayHandle<vtkm::Vec3f> field; vtkm::cont::ArrayHandle<vtkm::Vec3f> field;
vtkm::cont::Invoker invoke; vtkm::cont::Invoker invoke;
invoke(WaveField{}, ds.GetCoordinateSystem(), field); invoke(WaveField{}, ds.GetCoordinateSystem().GetDataAsMultiplexer(), field);
ds.AddPointField("vec_field", field); ds.AddPointField("vec_field", field);
return ds; return ds;

@ -57,11 +57,11 @@ int main(int argc, char** argv)
//create seeds randomly placed withing the bounding box of the data. //create seeds randomly placed withing the bounding box of the data.
vtkm::Bounds bounds = ds.GetCoordinateSystem().GetBounds(); vtkm::Bounds bounds = ds.GetCoordinateSystem().GetBounds();
std::vector<vtkm::Particle> seeds; std::vector<vtkm::Massless> seeds;
for (vtkm::Id i = 0; i < numSeeds; i++) for (vtkm::Id i = 0; i < numSeeds; i++)
{ {
vtkm::Particle p; vtkm::Massless p;
vtkm::FloatDefault rx = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX; vtkm::FloatDefault rx = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX;
vtkm::FloatDefault ry = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX; vtkm::FloatDefault ry = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX;
vtkm::FloatDefault rz = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX; vtkm::FloatDefault rz = (vtkm::FloatDefault)rand() / (vtkm::FloatDefault)RAND_MAX;
@ -71,7 +71,7 @@ int main(int argc, char** argv)
p.ID = i; p.ID = i;
seeds.push_back(p); seeds.push_back(p);
} }
auto seedArray = vtkm::cont::make_ArrayHandle(seeds); auto seedArray = vtkm::cont::make_ArrayHandle(seeds, vtkm::CopyFlag::Off);
//compute streamlines //compute streamlines
vtkm::filter::Streamline streamline; vtkm::filter::Streamline streamline;

@ -75,7 +75,7 @@ int main(int argc, char** argv)
// Use the coordinate system as seeds for performing advection // Use the coordinate system as seeds for performing advection
vtkm::cont::ArrayHandle<vtkm::Vec3f> pts; vtkm::cont::ArrayHandle<vtkm::Vec3f> pts;
vtkm::cont::ArrayCopy(ds1.GetCoordinateSystem().GetData(), pts); vtkm::cont::ArrayCopy(ds1.GetCoordinateSystem().GetData(), pts);
vtkm::cont::ArrayHandle<vtkm::Particle> seeds; vtkm::cont::ArrayHandle<vtkm::Massless> seeds;
vtkm::Id numPts = pts.GetNumberOfValues(); vtkm::Id numPts = pts.GetNumberOfValues();
seeds.Allocate(numPts); seeds.Allocate(numPts);
@ -83,7 +83,7 @@ int main(int argc, char** argv)
auto seedPortal = seeds.WritePortal(); auto seedPortal = seeds.WritePortal();
for (vtkm::Id i = 0; i < numPts; i++) for (vtkm::Id i = 0; i < numPts; i++)
{ {
vtkm::Particle p; vtkm::Massless p;
p.Pos = ptsPortal.Get(i); p.Pos = ptsPortal.Get(i);
p.ID = i; p.ID = i;
seedPortal.Set(i, p); seedPortal.Set(i, p);

@ -11,6 +11,8 @@
#define vtk_m_Particle_h #define vtk_m_Particle_h
#include <vtkm/Bitset.h> #include <vtkm/Bitset.h>
#include <vtkm/VecVariable.h>
#include <vtkm/VectorAnalysis.h>
namespace vtkm namespace vtkm
{ {
@ -68,6 +70,12 @@ public:
VTKM_EXEC_CONT VTKM_EXEC_CONT
Particle() {} Particle() {}
VTKM_EXEC_CONT virtual ~Particle() noexcept
{
// This must not be defaulted, since defaulted virtual destructors are
// troublesome with CUDA __host__ __device__ markup.
}
VTKM_EXEC_CONT VTKM_EXEC_CONT
Particle(const vtkm::Vec3f& p, Particle(const vtkm::Vec3f& p,
const vtkm::Id& id, const vtkm::Id& id,
@ -92,7 +100,20 @@ public:
{ {
} }
vtkm::Particle& operator=(const vtkm::Particle& p) = default; vtkm::Particle& operator=(const vtkm::Particle&) = default;
// The basic particle is only meant to be advected in a velocity
// field. In that case it is safe to assume that the velocity value
// will always be stored in the first location of vectors
VTKM_EXEC_CONT
virtual vtkm::Vec3f Next(const vtkm::VecVariable<vtkm::Vec3f, 2>&, const vtkm::FloatDefault&) = 0;
// The basic particle is only meant to be advected in a velocity
// field. In that case it is safe to assume that the velocity value
// will always be stored in the first location of vectors
VTKM_EXEC_CONT
virtual vtkm::Vec3f Velocity(const vtkm::VecVariable<vtkm::Vec3f, 2>&,
const vtkm::FloatDefault&) = 0;
vtkm::Vec3f Pos; vtkm::Vec3f Pos;
vtkm::Id ID = -1; vtkm::Id ID = -1;
@ -100,6 +121,141 @@ public:
vtkm::ParticleStatus Status; vtkm::ParticleStatus Status;
vtkm::FloatDefault Time = 0; vtkm::FloatDefault Time = 0;
}; };
}
class Massless : public vtkm::Particle
{
public:
VTKM_EXEC_CONT
Massless() {}
VTKM_EXEC_CONT ~Massless() noexcept override
{
// This must not be defaulted, since defaulted virtual destructors are
// troublesome with CUDA __host__ __device__ markup.
}
VTKM_EXEC_CONT
Massless(const vtkm::Vec3f& p,
const vtkm::Id& id,
const vtkm::Id& numSteps = 0,
const vtkm::ParticleStatus& status = vtkm::ParticleStatus(),
const vtkm::FloatDefault& time = 0)
: Particle(p, id, numSteps, status, time)
{
}
/*VTKM_EXEC_CONT
Massless(const vtkm::Massless& p)
: Particle(p)
{
}*/
VTKM_EXEC_CONT
vtkm::Vec3f Next(const vtkm::VecVariable<vtkm::Vec3f, 2>& vectors,
const vtkm::FloatDefault& length) override
{
VTKM_ASSERT(vectors.GetNumberOfComponents() > 0);
return this->Pos + length * vectors[0];
}
VTKM_EXEC_CONT
vtkm::Vec3f Velocity(const vtkm::VecVariable<vtkm::Vec3f, 2>& vectors,
const vtkm::FloatDefault& vtkmNotUsed(length)) override
{
// Velocity is evaluated from the Velocity field
// and is not influenced by the particle
VTKM_ASSERT(vectors.GetNumberOfComponents() > 0);
return vectors[0];
}
};
class Electron : public vtkm::Particle
{
public:
VTKM_EXEC_CONT
Electron() {}
VTKM_EXEC_CONT
Electron(const vtkm::Vec3f& position,
const vtkm::Id& id,
const vtkm::FloatDefault& mass,
const vtkm::FloatDefault& charge,
const vtkm::FloatDefault& weighting,
const vtkm::Vec3f& momentum,
const vtkm::Id& numSteps = 0,
const vtkm::ParticleStatus& status = vtkm::ParticleStatus(),
const vtkm::FloatDefault& time = 0)
: Particle(position, id, numSteps, status, time)
, Mass(mass)
, Charge(charge)
, Weighting(weighting)
, Momentum(momentum)
{
}
VTKM_EXEC_CONT
vtkm::FloatDefault Beta(vtkm::Vec3f momentum) const
{
return static_cast<vtkm::FloatDefault>(vtkm::Magnitude(momentum / this->Mass) /
vtkm::Pow(SPEED_OF_LIGHT, 2));
}
VTKM_EXEC_CONT
vtkm::Vec3f Next(const vtkm::VecVariable<vtkm::Vec3f, 2>& vectors,
const vtkm::FloatDefault& length) override
{
// TODO: implement Lorentz force calculation
return this->Pos + length * this->Velocity(vectors, length);
}
VTKM_EXEC_CONT
vtkm::Vec3f Velocity(const vtkm::VecVariable<vtkm::Vec3f, 2>& vectors,
const vtkm::FloatDefault& length) override
{
VTKM_ASSERT(vectors.GetNumberOfComponents() == 2);
// Suppress unused warning
(void)this->Weighting;
vtkm::Vec3f velocity;
// Particle has a charge and a mass
// Velocity updated using Lorentz force
// Return velocity of the particle
vtkm::Vec3f eField = vectors[0];
vtkm::Vec3f bField = vectors[1];
const vtkm::FloatDefault QoM = this->Charge / this->Mass;
const vtkm::FloatDefault half = 0.5;
const vtkm::Vec3f mom_ = this->Momentum + (half * this->Charge * eField * length);
//TODO : Calculate Gamma
vtkm::Vec3f gamma_reci = vtkm::Sqrt(1 - this->Beta(mom_));
// gamma(mom_, mass) -> needs velocity calculation
const vtkm::Vec3f t = half * QoM * bField * gamma_reci * length;
const vtkm::Vec3f s = 2.0f * t * (1 / 1 + vtkm::Magnitude(t));
const vtkm::Vec3f mom_pr = mom_ + vtkm::Cross(mom_, t);
const vtkm::Vec3f mom_pl = mom_ + vtkm::Cross(mom_pr, s);
const vtkm::Vec3f mom_new = mom_pl + 0.5 * this->Charge * eField * length;
//TODO : this is a const method, figure a better way to update momentum
this->Momentum = mom_new;
velocity = mom_new / this->Mass;
return velocity;
}
private:
vtkm::FloatDefault Mass;
vtkm::FloatDefault Charge;
vtkm::FloatDefault Weighting;
vtkm::Vec3f Momentum;
constexpr static vtkm::FloatDefault SPEED_OF_LIGHT =
static_cast<vtkm::FloatDefault>(2.99792458e8);
};
} //namespace vtkm
#endif // vtk_m_Particle_h #endif // vtk_m_Particle_h

@ -65,11 +65,16 @@ public:
VTKM_EXEC_CONT VTKM_EXEC_CONT
inline const ComponentType& operator[](vtkm::IdComponent index) const inline const ComponentType& operator[](vtkm::IdComponent index) const
{ {
VTKM_ASSERT(index >= 0 && index < this->NumComponents);
return this->Data[index]; return this->Data[index];
} }
VTKM_EXEC_CONT VTKM_EXEC_CONT
inline ComponentType& operator[](vtkm::IdComponent index) { return this->Data[index]; } inline ComponentType& operator[](vtkm::IdComponent index)
{
VTKM_ASSERT(index >= 0 && index < this->NumComponents);
return this->Data[index];
}
VTKM_EXEC_CONT VTKM_EXEC_CONT
void Append(ComponentType value) void Append(ComponentType value)

@ -110,6 +110,39 @@ VTKM_CONT void ArrayCopy(const vtkm::cont::ArrayHandle<InValueType, InStorage>&
// Static dispatch cases 1 & 2 // Static dispatch cases 1 & 2
detail::ArrayCopyImpl(source, destination, JustCopyStorage{}); detail::ArrayCopyImpl(source, destination, JustCopyStorage{});
} }
// Forward declaration
// Cannot include VariantArrayHandle.h here due to circular dependency.
template <typename TypeList>
class VariantArrayHandleBase;
namespace detail
{
struct ArrayCopyFunctor
{
template <typename InValueType, typename InStorage, typename OutValueType, typename OutStorage>
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<InValueType, InStorage>& source,
vtkm::cont::ArrayHandle<OutValueType, OutStorage>& destination) const
{
vtkm::cont::ArrayCopy(source, destination);
}
};
} // namespace detail
/// \brief Deep copies data in a `VariantArrayHandle` to an array of a known type.
///
/// This form of `ArrayCopy` can be used to copy data from an unknown array type to
/// an array of a known type. Note that regardless of the source type, the data will
/// be deep copied.
///
template <typename InTypeList, typename OutValueType, typename OutStorage>
VTKM_CONT void ArrayCopy(const vtkm::cont::VariantArrayHandleBase<InTypeList>& source,
vtkm::cont::ArrayHandle<OutValueType, OutStorage>& destination)
{
source.CastAndCall(detail::ArrayCopyFunctor{}, destination);
}
} }
} // namespace vtkm::cont } // namespace vtkm::cont

@ -958,7 +958,7 @@ public:
/// ///
VTKM_CONT ArrayHandleNewStyle(const std::vector<vtkm::cont::internal::Buffer>& buffers, VTKM_CONT ArrayHandleNewStyle(const std::vector<vtkm::cont::internal::Buffer>& buffers,
const StorageType& storage = StorageType()) const StorageType& storage = StorageType())
: Internals(std::make_shared<InternalsStruct>(&buffers.front(), storage)) : Internals(std::make_shared<InternalsStruct>(buffers.data(), storage))
{ {
VTKM_ASSERT(static_cast<vtkm::IdComponent>(this->Internals->Buffers.size()) == VTKM_ASSERT(static_cast<vtkm::IdComponent>(this->Internals->Buffers.size()) ==
GetNumberOfBuffers()); GetNumberOfBuffers());
@ -1304,7 +1304,7 @@ public:
/// ///
VTKM_CONT vtkm::cont::internal::Buffer* GetBuffers() const VTKM_CONT vtkm::cont::internal::Buffer* GetBuffers() const
{ {
return &this->Internals->Buffers.front(); return this->Internals->Buffers.data();
} }
private: private:
@ -1409,8 +1409,8 @@ VTKM_NEVER_EXPORT VTKM_CONT inline void printSummary_ArrayHandle(
vtkm::Id sz = array.GetNumberOfValues(); vtkm::Id sz = array.GetNumberOfValues();
out << "valueType=" << vtkm::cont::TypeToString<T>() out << "valueType=" << vtkm::cont::TypeToString<T>()
<< " storageType=" << vtkm::cont::TypeToString<StorageT>() << sz << " values occupying " << " storageType=" << vtkm::cont::TypeToString<StorageT>() << " " << sz
<< (static_cast<size_t>(sz) * sizeof(T)) << " bytes ["; << " values occupying " << (static_cast<size_t>(sz) * sizeof(T)) << " bytes [";
PortalType portal = array.ReadPortal(); PortalType portal = array.ReadPortal();
if (full || sz <= 7) if (full || sz <= 7)

@ -175,12 +175,11 @@ public:
{ {
} }
template <typename Deleter>
ArrayHandleBasic( ArrayHandleBasic(
T* array, T* array,
vtkm::Id numberOfValues, vtkm::Id numberOfValues,
vtkm::cont::DeviceAdapterId device, vtkm::cont::DeviceAdapterId device,
Deleter deleter, vtkm::cont::internal::BufferInfo::Deleter deleter,
vtkm::cont::internal::BufferInfo::Reallocater reallocater = internal::InvalidRealloc) vtkm::cont::internal::BufferInfo::Reallocater reallocater = internal::InvalidRealloc)
: Superclass(std::vector<vtkm::cont::internal::Buffer>{ : Superclass(std::vector<vtkm::cont::internal::Buffer>{
vtkm::cont::internal::MakeBuffer(device, vtkm::cont::internal::MakeBuffer(device,
@ -192,6 +191,39 @@ public:
{ {
} }
ArrayHandleBasic(
T* array,
void* container,
vtkm::Id numberOfValues,
vtkm::cont::internal::BufferInfo::Deleter deleter,
vtkm::cont::internal::BufferInfo::Reallocater reallocater = internal::InvalidRealloc)
: Superclass(std::vector<vtkm::cont::internal::Buffer>{
vtkm::cont::internal::MakeBuffer(vtkm::cont::DeviceAdapterTagUndefined{},
array,
container,
internal::detail::NumberOfBytes(numberOfValues, sizeof(T)),
deleter,
reallocater) })
{
}
ArrayHandleBasic(
T* array,
void* container,
vtkm::Id numberOfValues,
vtkm::cont::DeviceAdapterId device,
vtkm::cont::internal::BufferInfo::Deleter deleter,
vtkm::cont::internal::BufferInfo::Reallocater reallocater = internal::InvalidRealloc)
: Superclass(std::vector<vtkm::cont::internal::Buffer>{
vtkm::cont::internal::MakeBuffer(device,
array,
container,
internal::detail::NumberOfBytes(numberOfValues, sizeof(T)),
deleter,
reallocater) })
{
}
/// @{ /// @{
/// \brief Gets raw access to the `ArrayHandle`'s data. /// \brief Gets raw access to the `ArrayHandle`'s data.
/// ///
@ -238,11 +270,85 @@ public:
/// @} /// @}
}; };
namespace internal
{
// Deletes a container object by casting it to a pointer of a given type (the template argument)
// and then using delete[] on the object.
template <typename T>
VTKM_CONT inline void SimpleArrayDeleter(void* container_)
{
T* container = reinterpret_cast<T*>(container_);
delete[] container;
}
// Reallocates a standard C array. Note that the allocation method is different than the default
// host allocation of vtkm::cont::internal::BufferInfo and may be less efficient.
template <typename T>
VTKM_CONT inline void SimpleArrayReallocater(void*& memory,
void*& container,
vtkm::BufferSizeType oldSize,
vtkm::BufferSizeType newSize)
{
VTKM_ASSERT(memory == container);
VTKM_ASSERT(static_cast<std::size_t>(newSize) % sizeof(T) == 0);
// If the new size is not much smaller than the old size, just reuse the buffer (and waste a
// little memory).
if ((newSize > ((3 * oldSize) / 4)) && (newSize <= oldSize))
{
return;
}
void* newBuffer = new T[static_cast<std::size_t>(newSize) / sizeof(T)];
std::memcpy(newBuffer, memory, static_cast<std::size_t>(newSize < oldSize ? newSize : oldSize));
if (memory != nullptr)
{
SimpleArrayDeleter<T>(memory);
}
memory = container = newBuffer;
}
// Deletes a container object by casting it to a pointer of a given type (the template argument)
// and then using delete on the object.
template <typename T>
VTKM_CONT inline void CastDeleter(void* container_)
{
T* container = reinterpret_cast<T*>(container_);
delete container;
}
template <typename T, typename Allocator>
VTKM_CONT inline void StdVectorDeleter(void* container)
{
CastDeleter<std::vector<T, Allocator>>(container);
}
template <typename T, typename Allocator>
VTKM_CONT inline void StdVectorReallocater(void*& memory,
void*& container,
vtkm::BufferSizeType oldSize,
vtkm::BufferSizeType newSize)
{
using vector_type = std::vector<T, Allocator>;
vector_type* vector = reinterpret_cast<vector_type*>(container);
VTKM_ASSERT(vector->empty() || (memory == vector->data()));
VTKM_ASSERT(oldSize == static_cast<vtkm::BufferSizeType>(vector->size()));
vector->resize(static_cast<std::size_t>(newSize));
memory = vector->data();
}
} // namespace internal
/// A convenience function for creating an ArrayHandle from a standard C array. /// A convenience function for creating an ArrayHandle from a standard C array.
/// ///
template <typename T> template <typename T>
VTKM_CONT vtkm::cont::ArrayHandleBasic<T> VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandle(const T* array,
make_ArrayHandle(const T* array, vtkm::Id numberOfValues, vtkm::CopyFlag copy = vtkm::CopyFlag::Off) vtkm::Id numberOfValues,
vtkm::CopyFlag copy)
{ {
if (copy == vtkm::CopyFlag::On) if (copy == vtkm::CopyFlag::On)
{ {
@ -258,16 +364,39 @@ make_ArrayHandle(const T* array, vtkm::Id numberOfValues, vtkm::CopyFlag copy =
} }
} }
template <typename T>
VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_ArrayHandle.")
VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandle(const T* array, vtkm::Id numberOfValues)
{
return make_ArrayHandle(array, numberOfValues, vtkm::CopyFlag::Off);
}
/// A convenience function to move a user-allocated array into an `ArrayHandle`.
/// The provided array pointer will be reset to `nullptr`.
/// If the array was not allocated with the `new[]` operator, then deleter and reallocater
/// functions must be provided.
///
template <typename T>
VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandleMove(
T*& array,
vtkm::Id numberOfValues,
vtkm::cont::internal::BufferInfo::Deleter deleter = internal::SimpleArrayDeleter<T>,
vtkm::cont::internal::BufferInfo::Reallocater reallocater = internal::SimpleArrayReallocater<T>)
{
vtkm::cont::ArrayHandleBasic<T> arrayHandle(array, numberOfValues, deleter, reallocater);
array = nullptr;
return arrayHandle;
}
/// A convenience function for creating an ArrayHandle from an std::vector. /// A convenience function for creating an ArrayHandle from an std::vector.
/// ///
template <typename T, typename Allocator> template <typename T, typename Allocator>
VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandle( VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandle(const std::vector<T, Allocator>& array,
const std::vector<T, Allocator>& array, vtkm::CopyFlag copy)
vtkm::CopyFlag copy = vtkm::CopyFlag::Off)
{ {
if (!array.empty()) if (!array.empty())
{ {
return make_ArrayHandle(&array.front(), static_cast<vtkm::Id>(array.size()), copy); return make_ArrayHandle(array.data(), static_cast<vtkm::Id>(array.size()), copy);
} }
else else
{ {
@ -275,6 +404,42 @@ VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandle(
return vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic>(); return vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic>();
} }
} }
template <typename T, typename Allocator>
VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_ArrayHandle.")
VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandle(const std::vector<T, Allocator>& array)
{
return make_ArrayHandle(array, vtkm::CopyFlag::Off);
}
/// Move an std::vector into an ArrayHandle.
///
template <typename T, typename Allocator>
VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandleMove(std::vector<T, Allocator>&& array)
{
using vector_type = std::vector<T, Allocator>;
vector_type* container = new vector_type(std::move(array));
return vtkm::cont::ArrayHandleBasic<T>(container->data(),
container,
static_cast<vtkm::Id>(container->size()),
internal::StdVectorDeleter<T, Allocator>,
internal::StdVectorReallocater<T, Allocator>);
}
template <typename T, typename Allocator>
VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandle(std::vector<T, Allocator>&& array,
vtkm::CopyFlag vtkmNotUsed(copy))
{
return make_ArrayHandleMove(array);
}
/// Create an ArrayHandle directly from an initializer list of values.
///
template <typename T>
VTKM_CONT vtkm::cont::ArrayHandleBasic<T> make_ArrayHandle(std::initializer_list<T>&& values)
{
return make_ArrayHandle(values.begin(), static_cast<vtkm::Id>(values.size()), vtkm::CopyFlag::On);
}
} }
} // namespace vtkm::cont } // namespace vtkm::cont

@ -63,16 +63,8 @@ vtkm::cont::ArrayHandleExtrudeCoords<T> make_ArrayHandleExtrudeCoords(
vtkm::CopyFlag copy = vtkm::CopyFlag::Off) vtkm::CopyFlag copy = vtkm::CopyFlag::Off)
{ {
using StorageType = vtkm::cont::internal::Storage<vtkm::Vec<T, 3>, internal::StorageTagExtrude>; using StorageType = vtkm::cont::internal::Storage<vtkm::Vec<T, 3>, internal::StorageTagExtrude>;
if (copy == vtkm::CopyFlag::Off) return ArrayHandleExtrudeCoords<T>(
{ StorageType(vtkm::cont::make_ArrayHandle(array, length, copy), numberOfPlanes, cylindrical));
return ArrayHandleExtrudeCoords<T>(StorageType(array, length, numberOfPlanes, cylindrical));
}
else
{
auto storage = StorageType(
vtkm::cont::make_ArrayHandle(array, length, vtkm::CopyFlag::On), numberOfPlanes, cylindrical);
return ArrayHandleExtrudeCoords<T>(storage);
}
} }
template <typename T> template <typename T>
@ -85,7 +77,7 @@ vtkm::cont::ArrayHandleExtrudeCoords<T> make_ArrayHandleExtrudeCoords(
if (!array.empty()) if (!array.empty())
{ {
return make_ArrayHandleExtrudeCoords( return make_ArrayHandleExtrudeCoords(
&array.front(), static_cast<vtkm::Id>(array.size()), numberOfPlanes, cylindrical, copy); array.data(), static_cast<vtkm::Id>(array.size()), numberOfPlanes, cylindrical, copy);
} }
else else
{ {

@ -234,8 +234,8 @@ public:
Storage() = default; Storage() = default;
VTKM_CONT Storage(std::initializer_list<BaseArrayType>&& arrays) VTKM_CONT Storage(std::array<BaseArrayType, NUM_COMPONENTS>&& arrays)
: Arrays{ std::move(arrays) } : Arrays(std::move(arrays))
{ {
VTKM_ASSERT(IsValid()); VTKM_ASSERT(IsValid());
} }
@ -433,11 +433,18 @@ public:
(ArrayHandleSOA<ValueType_>), (ArrayHandleSOA<ValueType_>),
(ArrayHandle<ValueType_, vtkm::cont::StorageTagSOA>)); (ArrayHandle<ValueType_, vtkm::cont::StorageTagSOA>));
ArrayHandleSOA(std::initializer_list<BaseArrayType>&& componentArrays) ArrayHandleSOA(std::array<BaseArrayType, Traits::NUM_COMPONENTS>&& componentArrays)
: Superclass(StorageType(std::move(componentArrays))) : Superclass(StorageType(std::move(componentArrays)))
{ {
} }
ArrayHandleSOA(std::initializer_list<BaseArrayType>&& componentArrays)
{
VTKM_ASSERT(componentArrays.size() == Traits::NUM_COMPONENTS);
std::copy(
componentArrays.begin(), componentArrays.end(), this->GetStorage().GetArrays().begin());
}
ArrayHandleSOA(std::initializer_list<std::vector<ComponentType>>&& componentVectors) ArrayHandleSOA(std::initializer_list<std::vector<ComponentType>>&& componentVectors)
{ {
VTKM_ASSERT(componentVectors.size() == Traits::NUM_COMPONENTS); VTKM_ASSERT(componentVectors.size() == Traits::NUM_COMPONENTS);
@ -456,26 +463,45 @@ public:
template <typename... RemainingVectors> template <typename... RemainingVectors>
ArrayHandleSOA(vtkm::CopyFlag copy, ArrayHandleSOA(vtkm::CopyFlag copy,
const std::vector<ComponentType>& vector0, const std::vector<ComponentType>& vector0,
const RemainingVectors&... componentVectors) RemainingVectors&&... componentVectors)
: Superclass(StorageType(vtkm::cont::make_ArrayHandle(vector0, copy), : Superclass(StorageType(
vtkm::cont::make_ArrayHandle(componentVectors, copy)...)) vtkm::cont::make_ArrayHandle(vector0, copy),
vtkm::cont::make_ArrayHandle(std::forward<RemainingVectors>(componentVectors), copy)...))
{ {
VTKM_STATIC_ASSERT(sizeof...(RemainingVectors) + 1 == Traits::NUM_COMPONENTS); VTKM_STATIC_ASSERT(sizeof...(RemainingVectors) + 1 == Traits::NUM_COMPONENTS);
} }
// This only works if all the templated arguments are of type std::vector<ComponentType>. // This only works if all the templated arguments are of type std::vector<ComponentType>.
template <typename... RemainingVectors> template <typename... RemainingVectors>
ArrayHandleSOA(const std::vector<ComponentType>& vector0, ArrayHandleSOA(vtkm::CopyFlag copy,
const RemainingVectors&... componentVectors) std::vector<ComponentType>&& vector0,
: Superclass(StorageType(vtkm::cont::make_ArrayHandle(vector0), RemainingVectors&&... componentVectors)
vtkm::cont::make_ArrayHandle(componentVectors)...)) : Superclass(StorageType(
vtkm::cont::make_ArrayHandle(std::move(vector0), copy),
vtkm::cont::make_ArrayHandle(std::forward<RemainingVectors>(componentVectors), copy)...))
{
VTKM_STATIC_ASSERT(sizeof...(RemainingVectors) + 1 == Traits::NUM_COMPONENTS);
}
// This only works if all the templated arguments are of type std::vector<ComponentType>.
template <typename... RemainingVectors>
#ifndef VTKM_MSVC
// For some reason, having VTKM_DEPRECATED here is causing a syntax error in some MSVC
// compilers.
VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_ArrayHandle.")
#endif
ArrayHandleSOA(const std::vector<ComponentType>& vector0,
const RemainingVectors&... componentVectors)
: Superclass(
StorageType(vtkm::cont::make_ArrayHandle(vector0, vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(componentVectors, vtkm::CopyFlag::Off)...))
{ {
VTKM_STATIC_ASSERT(sizeof...(RemainingVectors) + 1 == Traits::NUM_COMPONENTS); VTKM_STATIC_ASSERT(sizeof...(RemainingVectors) + 1 == Traits::NUM_COMPONENTS);
} }
ArrayHandleSOA(std::initializer_list<const ComponentType*> componentArrays, ArrayHandleSOA(std::initializer_list<const ComponentType*> componentArrays,
vtkm::Id length, vtkm::Id length,
vtkm::CopyFlag copy = vtkm::CopyFlag::Off) vtkm::CopyFlag copy)
{ {
VTKM_ASSERT(componentArrays.size() == Traits::NUM_COMPONENTS); VTKM_ASSERT(componentArrays.size() == Traits::NUM_COMPONENTS);
vtkm::IdComponent componentIndex = 0; vtkm::IdComponent componentIndex = 0;
@ -487,6 +513,20 @@ public:
} }
} }
VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_ArrayHandle.")
ArrayHandleSOA(std::initializer_list<const ComponentType*> componentArrays, vtkm::Id length)
{
VTKM_ASSERT(componentArrays.size() == Traits::NUM_COMPONENTS);
vtkm::IdComponent componentIndex = 0;
for (auto&& vectorIter = componentArrays.begin(); vectorIter != componentArrays.end();
++vectorIter)
{
this->SetArray(componentIndex,
vtkm::cont::make_ArrayHandle(*vectorIter, length, vtkm::CopyFlag::Off));
++componentIndex;
}
}
// This only works if all the templated arguments are of type std::vector<ComponentType>. // This only works if all the templated arguments are of type std::vector<ComponentType>.
template <typename... RemainingArrays> template <typename... RemainingArrays>
ArrayHandleSOA(vtkm::Id length, ArrayHandleSOA(vtkm::Id length,
@ -501,11 +541,17 @@ public:
// This only works if all the templated arguments are of type std::vector<ComponentType>. // This only works if all the templated arguments are of type std::vector<ComponentType>.
template <typename... RemainingArrays> template <typename... RemainingArrays>
ArrayHandleSOA(vtkm::Id length, #ifndef VTKM_MSVC
const ComponentType* array0, // For some reason, having VTKM_DEPRECATED here is causing a syntax error in some MSVC
const RemainingArrays&... componentArrays) // compilers.
: Superclass(StorageType(vtkm::cont::make_ArrayHandle(array0, length), VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_ArrayHandle.")
vtkm::cont::make_ArrayHandle(componentArrays, length)...)) #endif
ArrayHandleSOA(vtkm::Id length,
const ComponentType* array0,
const RemainingArrays&... componentArrays)
: Superclass(
StorageType(vtkm::cont::make_ArrayHandle(array0, length, vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(componentArrays, length, vtkm::CopyFlag::Off)...))
{ {
VTKM_STATIC_ASSERT(sizeof...(RemainingArrays) + 1 == Traits::NUM_COMPONENTS); VTKM_STATIC_ASSERT(sizeof...(RemainingArrays) + 1 == Traits::NUM_COMPONENTS);
} }
@ -558,34 +604,73 @@ VTKM_CONT
ArrayHandleSOA<vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>> ArrayHandleSOA<vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>>
make_ArrayHandleSOA(vtkm::CopyFlag copy, make_ArrayHandleSOA(vtkm::CopyFlag copy,
const std::vector<ComponentType>& vector0, const std::vector<ComponentType>& vector0,
const RemainingVectors&... componentVectors) RemainingVectors&&... componentVectors)
{ {
return ArrayHandleSOA< // Convert std::vector to ArrayHandle first so that it correctly handles a mix of rvalue args.
vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>>( return { vtkm::cont::make_ArrayHandle(vector0, copy),
vector0, componentVectors..., copy); vtkm::cont::make_ArrayHandle(std::forward<RemainingVectors>(componentVectors),
copy)... };
} }
// This only works if all the templated arguments are of type std::vector<ComponentType>.
template <typename ComponentType, typename... RemainingVectors> template <typename ComponentType, typename... RemainingVectors>
VTKM_CONT VTKM_CONT
ArrayHandleSOA<vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>> ArrayHandleSOA<vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>>
make_ArrayHandleSOA(const std::vector<ComponentType>& vector0, make_ArrayHandleSOA(vtkm::CopyFlag copy,
const RemainingVectors&... componentVectors) std::vector<ComponentType>&& vector0,
RemainingVectors&&... componentVectors)
{
// Convert std::vector to ArrayHandle first so that it correctly handles a mix of rvalue args.
return ArrayHandleSOA<
vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>>(
vtkm::cont::make_ArrayHandle(std::move(vector0), copy),
vtkm::cont::make_ArrayHandle(std::forward<RemainingVectors>(componentVectors), copy)...);
}
template <typename ComponentType, typename... RemainingVectors>
VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_ArrayHandle.")
VTKM_CONT ArrayHandleSOA<
vtkm::Vec<ComponentType,
vtkm::IdComponent(sizeof...(RemainingVectors) +
1)>> make_ArrayHandleSOA(const std::vector<ComponentType>& vector0,
const RemainingVectors&... componentVectors)
{ {
return ArrayHandleSOA< return ArrayHandleSOA<
vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>>( vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>>(
vector0, componentVectors...); vector0, componentVectors...);
} }
// This only works if all the templated arguments are rvalues of std::vector<ComponentType>.
template <typename ComponentType, typename... RemainingVectors>
VTKM_CONT
ArrayHandleSOA<vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingVectors) + 1)>>
make_ArrayHandleSOAMove(std::vector<ComponentType>&& vector0,
RemainingVectors&&... componentVectors)
{
return { vtkm::cont::make_ArrayHandleMove(std::move(vector0)),
vtkm::cont::make_ArrayHandleMove(std::forward<RemainingVectors>(componentVectors))... };
}
template <typename ValueType> template <typename ValueType>
VTKM_CONT ArrayHandleSOA<ValueType> make_ArrayHandleSOA( VTKM_CONT ArrayHandleSOA<ValueType> make_ArrayHandleSOA(
std::initializer_list<const typename vtkm::VecTraits<ValueType>::ComponentType*>&& std::initializer_list<const typename vtkm::VecTraits<ValueType>::ComponentType*>&&
componentVectors, componentVectors,
vtkm::Id length, vtkm::Id length,
vtkm::CopyFlag copy = vtkm::CopyFlag::Off) vtkm::CopyFlag copy)
{ {
return ArrayHandleSOA<ValueType>(std::move(componentVectors), length, copy); return ArrayHandleSOA<ValueType>(std::move(componentVectors), length, copy);
} }
template <typename ValueType>
VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_ArrayHandle.")
VTKM_CONT ArrayHandleSOA<ValueType> make_ArrayHandleSOA(
std::initializer_list<const typename vtkm::VecTraits<ValueType>::ComponentType*>&&
componentVectors,
vtkm::Id length)
{
return vtkm::cont::make_ArrayHandleSOA(std::move(componentVectors), length, vtkm::CopyFlag::Off);
}
// This only works if all the templated arguments are of type std::vector<ComponentType>. // This only works if all the templated arguments are of type std::vector<ComponentType>.
template <typename ComponentType, typename... RemainingArrays> template <typename ComponentType, typename... RemainingArrays>
VTKM_CONT VTKM_CONT
@ -601,11 +686,13 @@ VTKM_CONT
} }
template <typename ComponentType, typename... RemainingArrays> template <typename ComponentType, typename... RemainingArrays>
VTKM_CONT VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_ArrayHandle.")
ArrayHandleSOA<vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingArrays) + 1)>> VTKM_CONT ArrayHandleSOA<
make_ArrayHandleSOA(vtkm::Id length, vtkm::Vec<ComponentType,
const ComponentType* array0, vtkm::IdComponent(sizeof...(RemainingArrays) +
const RemainingArrays*... componentArrays) 1)>> make_ArrayHandleSOA(vtkm::Id length,
const ComponentType* array0,
const RemainingArrays*... componentArrays)
{ {
return ArrayHandleSOA< return ArrayHandleSOA<
vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingArrays) + 1)>>( vtkm::Vec<ComponentType, vtkm::IdComponent(sizeof...(RemainingArrays) + 1)>>(

@ -28,20 +28,24 @@ namespace cont
{ {
/// ArrayHandleVirtualCoordinates is a specialization of ArrayHandle. /// ArrayHandleVirtualCoordinates is a specialization of ArrayHandle.
class VTKM_ALWAYS_EXPORT ArrayHandleVirtualCoordinates final class VTKM_ALWAYS_EXPORT VTKM_DEPRECATED(1.6, "Virtual ArrayHandles are being phased out.")
: public vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f> ArrayHandleVirtualCoordinates final : public vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>
{ {
public: public:
VTKM_ARRAY_HANDLE_SUBCLASS_NT(ArrayHandleVirtualCoordinates, VTKM_ARRAY_HANDLE_SUBCLASS_NT(ArrayHandleVirtualCoordinates,
(vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>)); (vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>));
VTKM_DEPRECATED_SUPPRESS_BEGIN
template <typename T, typename S> template <typename T, typename S>
explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle<T, S>& ah) explicit ArrayHandleVirtualCoordinates(const vtkm::cont::ArrayHandle<T, S>& ah)
: vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>(vtkm::cont::make_ArrayHandleCast<ValueType>(ah)) : vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>(vtkm::cont::make_ArrayHandleCast<ValueType>(ah))
{ {
} }
VTKM_DEPRECATED_SUPPRESS_END
}; };
VTKM_DEPRECATED_SUPPRESS_BEGIN
template <typename Functor, typename... Args> template <typename Functor, typename... Args>
void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates& coords, void CastAndCall(const vtkm::cont::ArrayHandleVirtualCoordinates& coords,
Functor&& f, Functor&& f,
@ -66,6 +70,8 @@ struct SerializableTypeString<vtkm::cont::ArrayHandleVirtualCoordinates>
static VTKM_CONT const std::string Get() { return "AH_VirtualCoordinates"; } static VTKM_CONT const std::string Get() { return "AH_VirtualCoordinates"; }
}; };
VTKM_DEPRECATED_SUPPRESS_END
} // namespace cont } // namespace cont
} // namespace vtkm } // namespace vtkm
@ -75,6 +81,8 @@ struct SerializableTypeString<vtkm::cont::ArrayHandleVirtualCoordinates>
namespace mangled_diy_namespace namespace mangled_diy_namespace
{ {
VTKM_DEPRECATED_SUPPRESS_BEGIN
template <> template <>
struct Serialization<vtkm::cont::ArrayHandleVirtualCoordinates> struct Serialization<vtkm::cont::ArrayHandleVirtualCoordinates>
{ {
@ -173,6 +181,8 @@ public:
} }
}; };
VTKM_DEPRECATED_SUPPRESS_END
} // diy } // diy
/// @endcond SERIALIZATION /// @endcond SERIALIZATION

@ -16,7 +16,7 @@
#include <vtkm/cont/ArrayHandleCartesianProduct.h> #include <vtkm/cont/ArrayHandleCartesianProduct.h>
#include <vtkm/cont/ArrayHandleCompositeVector.h> #include <vtkm/cont/ArrayHandleCompositeVector.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h> #include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h> #include <vtkm/cont/ArrayHandleVirtual.h>
#include <vtkm/cont/DeviceAdapterTag.h> #include <vtkm/cont/DeviceAdapterTag.h>
namespace vtkm namespace vtkm

@ -128,9 +128,9 @@ set(template_sources
CellSetExtrude.hxx CellSetExtrude.hxx
CellSetStructured.hxx CellSetStructured.hxx
ColorTable.hxx ColorTable.hxx
CoordinateSystem.hxx
FieldRangeCompute.hxx FieldRangeCompute.hxx
FieldRangeGlobalCompute.hxx FieldRangeGlobalCompute.hxx
ParticleArrayCopy.hxx
StorageVirtual.hxx StorageVirtual.hxx
VirtualObjectHandle.hxx VirtualObjectHandle.hxx
) )
@ -151,7 +151,6 @@ set(sources
internal/VirtualObjectTransfer.cxx internal/VirtualObjectTransfer.cxx
Initialize.cxx Initialize.cxx
Logging.cxx Logging.cxx
ParticleArrayCopy.cxx
RuntimeDeviceTracker.cxx RuntimeDeviceTracker.cxx
Token.cxx Token.cxx
TryExecute.cxx TryExecute.cxx
@ -185,7 +184,6 @@ set(sources
Field.cxx Field.cxx
FieldRangeCompute.cxx FieldRangeCompute.cxx
FieldRangeGlobalCompute.cxx FieldRangeGlobalCompute.cxx
ParticleArrayCopy.cxx
PartitionedDataSet.cxx PartitionedDataSet.cxx
PointLocator.cxx PointLocator.cxx
PointLocatorUniformGrid.cxx PointLocatorUniformGrid.cxx

@ -234,7 +234,7 @@ void CellLocatorBoundingIntervalHierarchy::Build()
vtkm::cont::DynamicCellSet cellSet = this->GetCellSet(); vtkm::cont::DynamicCellSet cellSet = this->GetCellSet();
vtkm::Id numCells = cellSet.GetNumberOfCells(); vtkm::Id numCells = cellSet.GetNumberOfCells();
vtkm::cont::CoordinateSystem coords = this->GetCoordinates(); vtkm::cont::CoordinateSystem coords = this->GetCoordinates();
vtkm::cont::ArrayHandleVirtualCoordinates points = coords.GetData(); auto points = coords.GetDataAsMultiplexer();
//std::cout << "No of cells: " << numCells << "\n"; //std::cout << "No of cells: " << numCells << "\n";
//std::cout.precision(3); //std::cout.precision(3);
@ -457,7 +457,7 @@ struct CellLocatorBIHPrepareForExecutionFunctor
vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>& bihExec, vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>& bihExec,
const vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode>& nodes, const vtkm::cont::ArrayHandle<vtkm::exec::CellLocatorBoundingIntervalHierarchyNode>& nodes,
const vtkm::cont::ArrayHandle<vtkm::Id>& processedCellIds, const vtkm::cont::ArrayHandle<vtkm::Id>& processedCellIds,
const vtkm::cont::ArrayHandleVirtualCoordinates& coords) const const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coords) const
{ {
using ExecutionType = using ExecutionType =
vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>; vtkm::exec::CellLocatorBoundingIntervalHierarchyExec<DeviceAdapter, CellSetType>;
@ -501,7 +501,7 @@ const vtkm::exec::CellLocator* CellLocatorBoundingIntervalHierarchy::PrepareForE
this->ExecutionObjectHandle, this->ExecutionObjectHandle,
this->Nodes, this->Nodes,
this->ProcessedCellIds, this->ProcessedCellIds,
this->GetCoordinates().GetData()); this->GetCoordinates().GetDataAsMultiplexer());
return this->ExecutionObjectHandle.PrepareForExecution(device, token); return this->ExecutionObjectHandle.PrepareForExecution(device, token);
; ;
} }

@ -94,9 +94,9 @@ private:
using ArrayPortalConst = using ArrayPortalConst =
typename vtkm::cont::ArrayHandle<T>::template ExecutionTypes<DeviceAdapter>::PortalConst; typename vtkm::cont::ArrayHandle<T>::template ExecutionTypes<DeviceAdapter>::PortalConst;
using CoordsPortalType = decltype(vtkm::cont::ArrayHandleVirtualCoordinates{}.PrepareForInput( using CoordsPortalType =
DeviceAdapter{}, typename vtkm::cont::CoordinateSystem::MultiplexerArrayType::ExecutionTypes<
std::declval<vtkm::cont::Token&>())); DeviceAdapter>::PortalConst;
using CellSetP2CExecType = using CellSetP2CExecType =
decltype(std::declval<CellSetType>().PrepareForInput(DeviceAdapter{}, decltype(std::declval<CellSetType>().PrepareForInput(DeviceAdapter{},
@ -150,7 +150,7 @@ public:
vtkm::TopologyElementTagCell{}, vtkm::TopologyElementTagCell{},
vtkm::TopologyElementTagPoint{}, vtkm::TopologyElementTagPoint{},
token)) token))
, Coords(coords.GetData().PrepareForInput(DeviceAdapter{}, token)) , Coords(coords.GetDataAsMultiplexer().PrepareForInput(DeviceAdapter{}, token))
{ {
} }

@ -81,12 +81,10 @@ struct CellLocatorUniformGridPrepareForExecutionFunctor
template <typename DeviceAdapter, typename... Args> template <typename DeviceAdapter, typename... Args>
VTKM_CONT bool operator()(DeviceAdapter, VTKM_CONT bool operator()(DeviceAdapter,
vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>& execLocator, vtkm::cont::VirtualObjectHandle<vtkm::exec::CellLocator>& execLocator,
vtkm::cont::Token& token,
Args&&... args) const Args&&... args) const
{ {
using ExecutionType = vtkm::exec::CellLocatorUniformGrid<DeviceAdapter, dimensions>; using ExecutionType = vtkm::exec::CellLocatorUniformGrid<DeviceAdapter, dimensions>;
ExecutionType* execObject = ExecutionType* execObject = new ExecutionType(std::forward<Args>(args)..., DeviceAdapter());
new ExecutionType(std::forward<Args>(args)..., DeviceAdapter(), token);
execLocator.Reset(execObject); execLocator.Reset(execObject);
return true; return true;
} }
@ -103,26 +101,22 @@ const vtkm::exec::CellLocator* CellLocatorUniformGrid::PrepareForExecution(
success = vtkm::cont::TryExecuteOnDevice(device, success = vtkm::cont::TryExecuteOnDevice(device,
CellLocatorUniformGridPrepareForExecutionFunctor<3>(), CellLocatorUniformGridPrepareForExecutionFunctor<3>(),
this->ExecutionObjectHandle, this->ExecutionObjectHandle,
token,
this->CellDims, this->CellDims,
this->PointDims, this->PointDims,
this->Origin, this->Origin,
this->InvSpacing, this->InvSpacing,
this->MaxPoint, this->MaxPoint);
this->GetCoordinates().GetData());
} }
else else
{ {
success = vtkm::cont::TryExecuteOnDevice(device, success = vtkm::cont::TryExecuteOnDevice(device,
CellLocatorUniformGridPrepareForExecutionFunctor<2>(), CellLocatorUniformGridPrepareForExecutionFunctor<2>(),
this->ExecutionObjectHandle, this->ExecutionObjectHandle,
token,
this->CellDims, this->CellDims,
this->PointDims, this->PointDims,
this->Origin, this->Origin,
this->InvSpacing, this->InvSpacing,
this->MaxPoint, this->MaxPoint);
this->GetCoordinates().GetData());
} }
if (!success) if (!success)
{ {

@ -168,10 +168,23 @@ CellSetExtrude make_CellSetExtrude(const std::vector<vtkm::Int32>& conn,
const std::vector<vtkm::Int32>& nextNode, const std::vector<vtkm::Int32>& nextNode,
bool periodic = true) bool periodic = true)
{ {
return CellSetExtrude{ vtkm::cont::make_ArrayHandle(conn), return CellSetExtrude{ vtkm::cont::make_ArrayHandle(conn, vtkm::CopyFlag::On),
static_cast<vtkm::Int32>(coords.GetNumberOfPointsPerPlane()), static_cast<vtkm::Int32>(coords.GetNumberOfPointsPerPlane()),
coords.GetNumberOfPlanes(), coords.GetNumberOfPlanes(),
vtkm::cont::make_ArrayHandle(nextNode), vtkm::cont::make_ArrayHandle(nextNode, vtkm::CopyFlag::On),
periodic };
}
template <typename T>
CellSetExtrude make_CellSetExtrude(std::vector<vtkm::Int32>&& conn,
const vtkm::cont::ArrayHandleExtrudeCoords<T>& coords,
std::vector<vtkm::Int32>&& nextNode,
bool periodic = true)
{
return CellSetExtrude{ vtkm::cont::make_ArrayHandleMove(std::move(conn)),
static_cast<vtkm::Int32>(coords.GetNumberOfPointsPerPlane()),
coords.GetNumberOfPlanes(),
vtkm::cont::make_ArrayHandleMove(std::move(nextNode)),
periodic }; periodic };
} }
} }

@ -833,15 +833,20 @@ ColorTable::TransferState ColorTable::GetExecutionDataForTransfer() const
if (this->Impl->ColorArraysChanged) if (this->Impl->ColorArraysChanged)
{ {
this->Impl->ColorPosHandle = vtkm::cont::make_ArrayHandle(this->Impl->ColorNodePos); this->Impl->ColorPosHandle =
this->Impl->ColorRGBHandle = vtkm::cont::make_ArrayHandle(this->Impl->ColorRGB); vtkm::cont::make_ArrayHandle(this->Impl->ColorNodePos, vtkm::CopyFlag::Off);
this->Impl->ColorRGBHandle =
vtkm::cont::make_ArrayHandle(this->Impl->ColorRGB, vtkm::CopyFlag::Off);
} }
if (this->Impl->OpacityArraysChanged) if (this->Impl->OpacityArraysChanged)
{ {
this->Impl->OpacityPosHandle = vtkm::cont::make_ArrayHandle(this->Impl->OpacityNodePos); this->Impl->OpacityPosHandle =
this->Impl->OpacityAlphaHandle = vtkm::cont::make_ArrayHandle(this->Impl->OpacityAlpha); vtkm::cont::make_ArrayHandle(this->Impl->OpacityNodePos, vtkm::CopyFlag::Off);
this->Impl->OpacityMidSharpHandle = vtkm::cont::make_ArrayHandle(this->Impl->OpacityMidSharp); this->Impl->OpacityAlphaHandle =
vtkm::cont::make_ArrayHandle(this->Impl->OpacityAlpha, vtkm::CopyFlag::Off);
this->Impl->OpacityMidSharpHandle =
vtkm::cont::make_ArrayHandle(this->Impl->OpacityMidSharp, vtkm::CopyFlag::Off);
} }
TransferState state = { (this->Impl->ColorArraysChanged || this->Impl->OpacityArraysChanged || TransferState state = { (this->Impl->ColorArraysChanged || this->Impl->OpacityArraysChanged ||

@ -10,22 +10,32 @@
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h> #include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/cont/CoordinateSystem.h> #include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/CoordinateSystem.hxx>
namespace vtkm namespace vtkm
{ {
namespace cont namespace cont
{ {
namespace detail
{
VTKM_DEPRECATED_SUPPRESS_BEGIN
vtkm::cont::ArrayHandleVirtualCoordinates CoordDataDepWrapper::ToArray() const
{
return this->Cast<vtkm::cont::ArrayHandleVirtualCoordinates>();
}
VTKM_DEPRECATED_SUPPRESS_END
} // namespace detail
VTKM_CONT CoordinateSystem::CoordinateSystem() VTKM_CONT CoordinateSystem::CoordinateSystem()
: Superclass() : Superclass()
{ {
} }
VTKM_CONT CoordinateSystem::CoordinateSystem( VTKM_CONT CoordinateSystem::CoordinateSystem(std::string name,
std::string name, const vtkm::cont::VariantArrayHandleCommon& data)
const vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>& data) : Superclass(name, Association::POINTS, vtkm::cont::VariantArrayHandle{ data })
: Superclass(name, Association::POINTS, data)
{ {
} }
@ -38,21 +48,19 @@ CoordinateSystem::CoordinateSystem(std::string name,
vtkm::Vec3f spacing) vtkm::Vec3f spacing)
: Superclass(name, : Superclass(name,
Association::POINTS, Association::POINTS,
vtkm::cont::ArrayHandleVirtualCoordinates( vtkm::cont::ArrayHandleUniformPointCoordinates(dimensions, origin, spacing))
vtkm::cont::ArrayHandleUniformPointCoordinates(dimensions, origin, spacing)))
{ {
} }
VTKM_CONT VTKM_CONT vtkm::cont::detail::CoordDataDepWrapper CoordinateSystem::GetData() const
vtkm::cont::ArrayHandleVirtualCoordinates CoordinateSystem::GetData() const
{ {
return this->Superclass::GetData().Cast<vtkm::cont::ArrayHandleVirtualCoordinates>(); return vtkm::cont::detail::CoordDataDepWrapper(this->Superclass::GetData());
} }
VTKM_CONT VTKM_CONT vtkm::cont::CoordinateSystem::MultiplexerArrayType
void CoordinateSystem::SetData(const vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>& newdata) CoordinateSystem::GetDataAsMultiplexer() const
{ {
this->Superclass::SetData(newdata); return this->GetData().AsMultiplexer<MultiplexerArrayType>();
} }
VTKM_CONT VTKM_CONT
@ -103,14 +111,5 @@ template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem(
vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>, vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>,
vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>, vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>,
vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>>::StorageTag>&); vtkm::cont::ArrayHandle<vtkm::Float64, vtkm::cont::StorageTagBasic>>::StorageTag>&);
template VTKM_CONT_EXPORT CoordinateSystem::CoordinateSystem(std::string name,
const vtkm::cont::VariantArrayHandle&);
template VTKM_CONT_EXPORT void CoordinateSystem::SetData(
const vtkm::cont::ArrayHandle<vtkm::Vec<float, 3>>&);
template VTKM_CONT_EXPORT void CoordinateSystem::SetData(
const vtkm::cont::ArrayHandle<vtkm::Vec<double, 3>>&);
template VTKM_CONT_EXPORT void CoordinateSystem::SetData(const vtkm::cont::VariantArrayHandle&);
} }
} // namespace vtkm::cont } // namespace vtkm::cont

@ -11,6 +11,7 @@
#define vtk_m_cont_CoordinateSystem_h #define vtk_m_cont_CoordinateSystem_h
#include <vtkm/Bounds.h> #include <vtkm/Bounds.h>
#include <vtkm/Deprecated.h>
#include <vtkm/cont/ArrayHandleCast.h> #include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h> #include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
@ -21,25 +22,116 @@ namespace vtkm
{ {
namespace cont namespace cont
{ {
namespace detail
{
// CoordinateSystem::GetData used to return an ArrayHandleVirtualCoordinates.
// That behavior is deprecated, and CoordianteSystem::GetData now returns a
// VariantArrayHandle similar (although slightly different than) its superclass.
// This wrapper class supports the old deprecated behavior until it is no longer
// supported. Once the behavior is removed (probably when
// ArrayHandleVirtualCoordinates is removed), then this class should be removed.
class VTKM_ALWAYS_EXPORT CoordDataDepWrapper
: public vtkm::cont::VariantArrayHandleBase<vtkm::TypeListFieldVec3>
{
using Superclass = vtkm::cont::VariantArrayHandleBase<vtkm::TypeListFieldVec3>;
VTKM_DEPRECATED_SUPPRESS_BEGIN
VTKM_CONT_EXPORT VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates ToArray() const;
VTKM_DEPRECATED_SUPPRESS_END
public:
using Superclass::Superclass;
// Make the return also behave as ArrayHandleVirtualCoordiantes
VTKM_DEPRECATED_SUPPRESS_BEGIN
VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
operator vtkm::cont::ArrayHandleVirtualCoordinates() const
{
return this->ToArray();
}
VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
operator vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagVirtual>() const
{
return this->ToArray();
}
using ValueType VTKM_DEPRECATED(1.6,
"CoordinateSystem::GetData() now returns a VariantArrayHandle.") =
vtkm::Vec3f;
VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
ArrayHandleVirtualCoordinates::ReadPortalType ReadPortal() const
{
return this->ToArray().ReadPortal();
}
VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
ArrayHandleVirtualCoordinates::WritePortalType WritePortal() const
{
return this->ToArray().WritePortal();
}
template <typename Device>
VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
typename ArrayHandleVirtualCoordinates::ExecutionTypes<Device>::PortalConst
PrepareForInput(Device device, vtkm::cont::Token& token) const
{
return this->ToArray().PrepareForInput(device, token);
}
template <typename Device>
VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
typename ArrayHandleVirtualCoordinates::ExecutionTypes<Device>::Portal
PrepareForInPlace(Device device, vtkm::cont::Token& token) const
{
return this->ToArray().PrepareForInPlace(device, token);
}
template <typename Device>
VTKM_CONT VTKM_DEPRECATED(1.6, "CoordinateSystem::GetData() now returns a VariantArrayHandle.")
typename ArrayHandleVirtualCoordinates::ExecutionTypes<Device>::Portal
PrepareForOutput(vtkm::Id numberOfValues, Device device, vtkm::cont::Token& token) const
{
return this->ToArray().PrepareForOutput(numberOfValues, device, token);
}
VTKM_DEPRECATED_SUPPRESS_END
};
} // namespace detail
VTKM_DEPRECATED_SUPPRESS_BEGIN
VTKM_CONT VTKM_DEPRECATED(
1.6,
"CoordinateSystem::GetData() now returns a "
"VariantArrayHandle.") inline void printSummary_ArrayHandle(const detail::CoordDataDepWrapper&
array,
std::ostream& out,
bool full = false)
{
vtkm::cont::ArrayHandleVirtualCoordinates coordArray = array;
vtkm::cont::printSummary_ArrayHandle(coordArray, out, full);
}
VTKM_DEPRECATED_SUPPRESS_END
class VTKM_CONT_EXPORT CoordinateSystem : public vtkm::cont::Field class VTKM_CONT_EXPORT CoordinateSystem : public vtkm::cont::Field
{ {
using Superclass = vtkm::cont::Field; using Superclass = vtkm::cont::Field;
using CoordinatesTypeList = vtkm::List<vtkm::cont::ArrayHandleVirtualCoordinates::ValueType>; using CoordinatesTypeList = vtkm::List<vtkm::Vec3f_32, vtkm::Vec3f_64>;
public: public:
VTKM_CONT VTKM_CONT
CoordinateSystem(); CoordinateSystem();
VTKM_CONT CoordinateSystem(std::string name, VTKM_CONT CoordinateSystem(std::string name, const vtkm::cont::VariantArrayHandleCommon& data);
const vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>& data);
template <typename TypeList>
VTKM_CONT CoordinateSystem(std::string name,
const vtkm::cont::VariantArrayHandleBase<TypeList>& data);
template <typename T, typename Storage> template <typename T, typename Storage>
VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle<T, Storage>& data) VTKM_CONT CoordinateSystem(std::string name, const ArrayHandle<T, Storage>& data)
: Superclass(name, Association::POINTS, vtkm::cont::ArrayHandleVirtualCoordinates(data)) : Superclass(name, Association::POINTS, data)
{ {
} }
@ -54,17 +146,54 @@ public:
VTKM_CONT VTKM_CONT
vtkm::Id GetNumberOfPoints() const { return this->GetNumberOfValues(); } vtkm::Id GetNumberOfPoints() const { return this->GetNumberOfValues(); }
VTKM_CONT VTKM_CONT detail::CoordDataDepWrapper GetData() const;
vtkm::cont::ArrayHandleVirtualCoordinates GetData() const;
VTKM_CONT void SetData(const vtkm::cont::ArrayHandleVirtual<vtkm::Vec3f>& newdata); private:
#ifdef VTKM_USE_DOUBLE_PRECISION
using FloatNonDefault = vtkm::Float32;
#else
using FloatNonDefault = vtkm::Float64;
#endif
using Vec3f_nd = vtkm::Vec<FloatNonDefault, 3>;
template <typename T, typename Storage> struct StorageToArrayDefault
VTKM_CONT void SetData(const vtkm::cont::ArrayHandle<T, Storage>& newdata); {
template <typename S>
using IsInvalid = vtkm::cont::internal::IsInvalidArrayHandle<vtkm::Vec3f, S>;
VTKM_CONT template <typename S>
template <typename TypeList> using Transform = vtkm::cont::ArrayHandle<vtkm::Vec3f, S>;
void SetData(const vtkm::cont::VariantArrayHandleBase<TypeList>& newdata); };
struct StorageToArrayNonDefault
{
template <typename S>
using IsInvalid = vtkm::cont::internal::IsInvalidArrayHandle<Vec3f_nd, S>;
template <typename S>
using Transform =
vtkm::cont::ArrayHandleCast<vtkm::Vec3f, vtkm::cont::ArrayHandle<Vec3f_nd, S>>;
};
using ArraysFloatDefault = vtkm::ListTransform<
vtkm::ListRemoveIf<VTKM_DEFAULT_STORAGE_LIST, StorageToArrayDefault::IsInvalid>,
StorageToArrayDefault::Transform>;
using ArraysFloatNonDefault = vtkm::ListTransform<
vtkm::ListRemoveIf<VTKM_DEFAULT_STORAGE_LIST, StorageToArrayNonDefault::IsInvalid>,
StorageToArrayNonDefault::Transform>;
public:
using MultiplexerArrayType = //
vtkm::cont::ArrayHandleMultiplexerFromList<
vtkm::ListAppend<ArraysFloatDefault, ArraysFloatNonDefault>>;
/// \brief Returns the data for the coordinate system as an `ArrayHandleMultiplexer`.
///
/// This array will handle all potential types supported by CoordinateSystem, so all types can be
/// handled with one compile pass. However, using this precludes specialization for special
/// arrays such as `ArrayHandleUniformPointCoordinates` that could have optimized code paths
///
VTKM_CONT MultiplexerArrayType GetDataAsMultiplexer() const;
VTKM_CONT VTKM_CONT
void GetRange(vtkm::Range* range) const void GetRange(vtkm::Range* range) const
@ -138,6 +267,12 @@ struct DynamicTransformTraits<vtkm::cont::CoordinateSystem>
using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall; using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall;
}; };
template <>
struct DynamicTransformTraits<vtkm::cont::detail::CoordDataDepWrapper>
{
using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall;
};
} // namespace internal } // namespace internal
} // namespace cont } // namespace cont
} // namespace vtkm } // namespace vtkm
@ -148,22 +283,32 @@ struct DynamicTransformTraits<vtkm::cont::CoordinateSystem>
namespace mangled_diy_namespace namespace mangled_diy_namespace
{ {
template <>
struct Serialization<vtkm::cont::detail::CoordDataDepWrapper>
: public Serialization<
vtkm::cont::VariantArrayHandleBase<vtkm::List<vtkm::Vec3f_32, vtkm::Vec3f_64>>>
{
};
template <> template <>
struct Serialization<vtkm::cont::CoordinateSystem> struct Serialization<vtkm::cont::CoordinateSystem>
{ {
using CoordinatesTypeList = vtkm::List<vtkm::Vec3f_32, vtkm::Vec3f_64>;
static VTKM_CONT void save(BinaryBuffer& bb, const vtkm::cont::CoordinateSystem& cs) static VTKM_CONT void save(BinaryBuffer& bb, const vtkm::cont::CoordinateSystem& cs)
{ {
vtkmdiy::save(bb, cs.GetName()); vtkmdiy::save(bb, cs.GetName());
vtkmdiy::save(bb, cs.GetData()); vtkmdiy::save(
bb, static_cast<vtkm::cont::VariantArrayHandleBase<CoordinatesTypeList>>(cs.GetData()));
} }
static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::CoordinateSystem& cs) static VTKM_CONT void load(BinaryBuffer& bb, vtkm::cont::CoordinateSystem& cs)
{ {
std::string name; std::string name;
vtkmdiy::load(bb, name); vtkmdiy::load(bb, name);
vtkm::cont::ArrayHandleVirtualCoordinates array; vtkm::cont::VariantArrayHandleBase<CoordinatesTypeList> data;
vtkmdiy::load(bb, array); vtkmdiy::load(bb, data);
cs = vtkm::cont::CoordinateSystem(name, array); cs = vtkm::cont::CoordinateSystem(name, data);
} }
}; };

@ -1,73 +0,0 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// 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.
//============================================================================
#ifndef vtk_m_cont_CoordinateSystem_hxx
#define vtk_m_cont_CoordinateSystem_hxx
#include <vtkm/cont/CoordinateSystem.h>
namespace vtkm
{
namespace cont
{
namespace detail
{
struct MakeArrayHandleVirtualCoordinatesFunctor
{
template <typename StorageTag>
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<vtkm::Vec3f_32, StorageTag>& array,
ArrayHandleVirtualCoordinates& output) const
{
output = vtkm::cont::ArrayHandleVirtualCoordinates(array);
}
template <typename StorageTag>
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<vtkm::Vec3f_64, StorageTag>& array,
ArrayHandleVirtualCoordinates& output) const
{
output = vtkm::cont::ArrayHandleVirtualCoordinates(array);
}
};
template <typename TypeList>
VTKM_CONT vtkm::cont::ArrayHandleVirtualCoordinates MakeArrayHandleVirtualCoordinates(
const vtkm::cont::VariantArrayHandleBase<TypeList>& array)
{
vtkm::cont::ArrayHandleVirtualCoordinates output;
vtkm::cont::CastAndCall(array.ResetTypes(vtkm::TypeListFieldVec3{}),
MakeArrayHandleVirtualCoordinatesFunctor{},
output);
return output;
}
} // namespace detail
template <typename TypeList>
VTKM_CONT CoordinateSystem::CoordinateSystem(
std::string name,
const vtkm::cont::VariantArrayHandleBase<TypeList>& data)
: Superclass(name, Association::POINTS, detail::MakeArrayHandleVirtualCoordinates(data))
{
}
template <typename T, typename Storage>
VTKM_CONT void CoordinateSystem::SetData(const vtkm::cont::ArrayHandle<T, Storage>& newdata)
{
this->SetData(vtkm::cont::ArrayHandleVirtualCoordinates(newdata));
}
template <typename TypeList>
VTKM_CONT void CoordinateSystem::SetData(
const vtkm::cont::VariantArrayHandleBase<TypeList>& newdata)
{
this->SetData(detail::MakeArrayHandleVirtualCoordinates(newdata));
}
}
}
#endif

@ -69,19 +69,29 @@ public:
const std::string& coordsNm = "coords"); const std::string& coordsNm = "coords");
template <typename T> template <typename T>
VTKM_CONT static vtkm::cont::DataSet Create( VTKM_DEPRECATED(1.6,
const vtkm::cont::ArrayHandle<T>& xVals, "Combine point coordinate arrays using most appropriate array (e.g. "
const vtkm::cont::ArrayHandle<T>& yVals, "ArrayHandleCompositeVector, ArrayHandleSOA, ArrayHandleCartesianProduct")
const vtkm::cont::ArrayHandle<T>& zVals, VTKM_CONT static vtkm::cont::DataSet
const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes, Create(const vtkm::cont::ArrayHandle<T>& xVals,
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices, const vtkm::cont::ArrayHandle<T>& yVals,
const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity, const vtkm::cont::ArrayHandle<T>& zVals,
const std::string& coordsNm = "coords") const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
const vtkm::cont::ArrayHandle<vtkm::IdComponent>& numIndices,
const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
const std::string& coordsNm = "coords")
{ {
VTKM_ASSERT(xVals.GetNumberOfValues() == yVals.GetNumberOfValues());
VTKM_ASSERT(xVals.GetNumberOfValues() == zVals.GetNumberOfValues());
auto offsets = vtkm::cont::ConvertNumIndicesToOffsets(numIndices); auto offsets = vtkm::cont::ConvertNumIndicesToOffsets(numIndices);
return DataSetBuilderExplicit::BuildDataSet( return DataSetBuilderExplicit::BuildDataSet(
xVals, yVals, zVals, shapes, offsets, connectivity, coordsNm); vtkm::cont::make_ArrayHandleCompositeVector(xVals, yVals, zVals),
shapes,
offsets,
connectivity,
coordsNm);
} }
template <typename T> template <typename T>
@ -123,15 +133,6 @@ public:
} }
private: private:
template <typename T>
static vtkm::cont::DataSet BuildDataSet(const vtkm::cont::ArrayHandle<T>& X,
const vtkm::cont::ArrayHandle<T>& Y,
const vtkm::cont::ArrayHandle<T>& Z,
const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
const vtkm::cont::ArrayHandle<vtkm::Id>& offsets,
const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
const std::string& coordsNm);
template <typename T> template <typename T>
VTKM_CONT static vtkm::cont::DataSet BuildDataSet( VTKM_CONT static vtkm::cont::DataSet BuildDataSet(
const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords, const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& coords,
@ -161,9 +162,16 @@ inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create(
{ {
VTKM_ASSERT(xVals.size() == yVals.size() && yVals.size() == zVals.size() && xVals.size() > 0); VTKM_ASSERT(xVals.size() == yVals.size() && yVals.size() == zVals.size() && xVals.size() > 0);
auto xArray = vtkm::cont::make_ArrayHandle(xVals, vtkm::CopyFlag::On); vtkm::cont::ArrayHandle<vtkm::Vec3f> coordsArray;
auto yArray = vtkm::cont::make_ArrayHandle(yVals, vtkm::CopyFlag::On); coordsArray.Allocate(static_cast<vtkm::Id>(xVals.size()));
auto zArray = vtkm::cont::make_ArrayHandle(zVals, vtkm::CopyFlag::On); auto coordsPortal = coordsArray.WritePortal();
for (std::size_t index = 0; index < xVals.size(); ++index)
{
coordsPortal.Set(static_cast<vtkm::Id>(index),
vtkm::make_Vec(static_cast<vtkm::FloatDefault>(xVals[index]),
static_cast<vtkm::FloatDefault>(yVals[index]),
static_cast<vtkm::FloatDefault>(zVals[index])));
}
auto shapesArray = vtkm::cont::make_ArrayHandle(shapes, vtkm::CopyFlag::On); auto shapesArray = vtkm::cont::make_ArrayHandle(shapes, vtkm::CopyFlag::On);
auto connArray = vtkm::cont::make_ArrayHandle(connectivity, vtkm::CopyFlag::On); auto connArray = vtkm::cont::make_ArrayHandle(connectivity, vtkm::CopyFlag::On);
@ -172,33 +180,7 @@ inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::Create(
vtkm::cont::make_ArrayHandle(numIndices, vtkm::CopyFlag::Off)); vtkm::cont::make_ArrayHandle(numIndices, vtkm::CopyFlag::Off));
return DataSetBuilderExplicit::BuildDataSet( return DataSetBuilderExplicit::BuildDataSet(
xArray, yArray, zArray, shapesArray, offsetsArray, connArray, coordsNm); coordsArray, shapesArray, offsetsArray, connArray, coordsNm);
}
template <typename T>
inline VTKM_CONT vtkm::cont::DataSet DataSetBuilderExplicit::BuildDataSet(
const vtkm::cont::ArrayHandle<T>& X,
const vtkm::cont::ArrayHandle<T>& Y,
const vtkm::cont::ArrayHandle<T>& Z,
const vtkm::cont::ArrayHandle<vtkm::UInt8>& shapes,
const vtkm::cont::ArrayHandle<vtkm::Id>& offsets,
const vtkm::cont::ArrayHandle<vtkm::Id>& connectivity,
const std::string& coordsNm)
{
VTKM_ASSERT(X.GetNumberOfValues() == Y.GetNumberOfValues() &&
Y.GetNumberOfValues() == Z.GetNumberOfValues() && X.GetNumberOfValues() > 0 &&
shapes.GetNumberOfValues() + 1 == offsets.GetNumberOfValues());
vtkm::cont::DataSet dataSet;
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem(coordsNm, make_ArrayHandleCompositeVector(X, Y, Z)));
vtkm::Id nPts = X.GetNumberOfValues();
vtkm::cont::CellSetExplicit<> cellSet;
cellSet.Fill(nPts, shapes, connectivity, offsets);
dataSet.SetCellSet(cellSet);
return dataSet;
} }
template <typename T> template <typename T>

@ -27,7 +27,8 @@ class VTKM_CONT_EXPORT DataSetBuilderRectilinear
template <typename T, typename U> template <typename T, typename U>
VTKM_CONT static void CopyInto(const std::vector<T>& input, vtkm::cont::ArrayHandle<U>& output) VTKM_CONT static void CopyInto(const std::vector<T>& input, vtkm::cont::ArrayHandle<U>& output)
{ {
DataSetBuilderRectilinear::CopyInto(vtkm::cont::make_ArrayHandle(input), output); DataSetBuilderRectilinear::CopyInto(vtkm::cont::make_ArrayHandle(input, vtkm::CopyFlag::Off),
output);
} }
template <typename T, typename U> template <typename T, typename U>
@ -40,7 +41,8 @@ class VTKM_CONT_EXPORT DataSetBuilderRectilinear
template <typename T, typename U> template <typename T, typename U>
VTKM_CONT static void CopyInto(const T* input, vtkm::Id len, vtkm::cont::ArrayHandle<U>& output) VTKM_CONT static void CopyInto(const T* input, vtkm::Id len, vtkm::cont::ArrayHandle<U>& output)
{ {
DataSetBuilderRectilinear::CopyInto(vtkm::cont::make_ArrayHandle(input, len), output); DataSetBuilderRectilinear::CopyInto(
vtkm::cont::make_ArrayHandle(input, len, vtkm::CopyFlag::Off), output);
} }
public: public:

@ -126,10 +126,10 @@ public:
this->ModifiedFlag = true; this->ModifiedFlag = true;
} }
VTKM_CONT template <typename TypeList>
void SetData(const vtkm::cont::VariantArrayHandle& newdata) VTKM_CONT void SetData(const vtkm::cont::VariantArrayHandleBase<TypeList>& newdata)
{ {
this->Data = newdata; this->Data = vtkm::cont::VariantArrayHandle(newdata);
this->ModifiedFlag = true; this->ModifiedFlag = true;
} }
@ -181,20 +181,61 @@ vtkm::cont::Field make_Field(std::string name,
Field::Association association, Field::Association association,
const T* data, const T* data,
vtkm::Id size, vtkm::Id size,
vtkm::CopyFlag copy = vtkm::CopyFlag::Off) vtkm::CopyFlag copy)
{ {
return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandle(data, size, copy)); return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandle(data, size, copy));
} }
template <typename T>
VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_Field.")
vtkm::cont::Field
make_Field(std::string name, Field::Association association, const T* data, vtkm::Id size)
{
return make_Field(name, association, data, size, vtkm::CopyFlag::Off);
}
template <typename T> template <typename T>
vtkm::cont::Field make_Field(std::string name, vtkm::cont::Field make_Field(std::string name,
Field::Association association, Field::Association association,
const std::vector<T>& data, const std::vector<T>& data,
vtkm::CopyFlag copy = vtkm::CopyFlag::Off) vtkm::CopyFlag copy)
{ {
return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandle(data, copy)); return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandle(data, copy));
} }
template <typename T>
VTKM_DEPRECATED(1.6, "Specify a vtkm::CopyFlag or use a move version of make_Field.")
vtkm::cont::Field
make_Field(std::string name, Field::Association association, const std::vector<T>& data)
{
return make_Field(name, association, data, vtkm::CopyFlag::Off);
}
template <typename T>
vtkm::cont::Field make_FieldMove(std::string name,
Field::Association association,
std::vector<T>&& data)
{
return vtkm::cont::Field(name, association, vtkm::cont::make_ArrayHandleMove(data));
}
template <typename T>
vtkm::cont::Field make_Field(std::string name,
Field::Association association,
std::vector<T>&& data,
vtkm::CopyFlag vtkmNotUsed(copy))
{
return make_FieldMove(name, association, std::move(data));
}
template <typename T>
vtkm::cont::Field make_Field(std::string name,
Field::Association association,
std::initializer_list<T>&& data)
{
return make_FieldMove(name, association, vtkm::cont::make_ArrayHandle(std::move(data)));
}
//@} //@}
/// Convenience function to build point fields from vtkm::cont::ArrayHandle /// Convenience function to build point fields from vtkm::cont::ArrayHandle

@ -10,10 +10,8 @@
#ifndef vtk_m_cont_Invoker_h #ifndef vtk_m_cont_Invoker_h
#define vtk_m_cont_Invoker_h #define vtk_m_cont_Invoker_h
#include <vtkm/worklet/DispatcherMapField.h> #include <vtkm/worklet/internal/MaskBase.h>
#include <vtkm/worklet/DispatcherMapTopology.h> #include <vtkm/worklet/internal/ScatterBase.h>
#include <vtkm/worklet/DispatcherPointNeighborhood.h>
#include <vtkm/worklet/DispatcherReduceByKey.h>
#include <vtkm/cont/TryExecute.h> #include <vtkm/cont/TryExecute.h>

@ -24,9 +24,10 @@ namespace cont
/// Given an \c ArrayHandle of vtkm::Particle, this function copies the /// Given an \c ArrayHandle of vtkm::Particle, this function copies the
/// position field into an \c ArrayHandle of \c Vec3f objects. /// position field into an \c ArrayHandle of \c Vec3f objects.
/// ///
VTKM_CONT_EXPORT
VTKM_CONT void ParticleArrayCopy( template <typename ParticleType>
const vtkm::cont::ArrayHandle<vtkm::Particle, vtkm::cont::StorageTagBasic>& inP, VTKM_ALWAYS_EXPORT inline void ParticleArrayCopy(
const vtkm::cont::ArrayHandle<ParticleType, vtkm::cont::StorageTagBasic>& inP,
vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagBasic>& outPos); vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagBasic>& outPos);
/// \brief Copy all fields in vtkm::Particle to standard types. /// \brief Copy all fields in vtkm::Particle to standard types.
@ -35,9 +36,10 @@ VTKM_CONT void ParticleArrayCopy(
/// position, ID, number of steps, status and time into a separate /// position, ID, number of steps, status and time into a separate
/// \c ArrayHandle. /// \c ArrayHandle.
/// ///
VTKM_CONT_EXPORT
VTKM_CONT void ParticleArrayCopy( template <typename ParticleType>
const vtkm::cont::ArrayHandle<vtkm::Particle, vtkm::cont::StorageTagBasic>& inP, VTKM_ALWAYS_EXPORT inline void ParticleArrayCopy(
const vtkm::cont::ArrayHandle<ParticleType, vtkm::cont::StorageTagBasic>& inP,
vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagBasic>& outPos, vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagBasic>& outPos,
vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic>& outID, vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic>& outID,
vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic>& outSteps, vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic>& outSteps,
@ -46,4 +48,8 @@ VTKM_CONT void ParticleArrayCopy(
} }
} // namespace vtkm::cont } // namespace vtkm::cont
#ifndef vtk_m_cont_ParticleArrayCopy_hxx
#include <vtkm/cont/ParticleArrayCopy.hxx>
#endif //vtk_m_cont_ParticleArrayCopy_hxx
#endif //vtk_m_cont_ParticleArrayCopy_h #endif //vtk_m_cont_ParticleArrayCopy_h

@ -0,0 +1,97 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// 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.
//============================================================================
#ifndef vtk_m_cont_ParticleArrayCopy_hxx
#define vtk_m_cont_ParticleArrayCopy_hxx
#include <vtkm/cont/Invoker.h>
#include <vtkm/cont/ParticleArrayCopy.h>
#include <vtkm/worklet/WorkletMapField.h>
namespace vtkm
{
namespace cont
{
namespace detail
{
struct CopyParticlePositionWorklet : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn inParticle, FieldOut outPos);
VTKM_EXEC void operator()(const vtkm::Particle& inParticle, vtkm::Vec3f& outPos) const
{
outPos = inParticle.Pos;
}
};
struct CopyParticleAllWorklet : public vtkm::worklet::WorkletMapField
{
using ControlSignature = void(FieldIn inParticle,
FieldOut outPos,
FieldOut outID,
FieldOut outSteps,
FieldOut outStatus,
FieldOut outTime);
VTKM_EXEC void operator()(const vtkm::Particle& inParticle,
vtkm::Vec3f& outPos,
vtkm::Id& outID,
vtkm::Id& outSteps,
vtkm::ParticleStatus& outStatus,
vtkm::FloatDefault& outTime) const
{
outPos = inParticle.Pos;
outID = inParticle.ID;
outSteps = inParticle.NumSteps;
outStatus = inParticle.Status;
outTime = inParticle.Time;
}
};
} // namespace detail
template <typename ParticleType>
VTKM_ALWAYS_EXPORT inline void ParticleArrayCopy(
const vtkm::cont::ArrayHandle<ParticleType, vtkm::cont::StorageTagBasic>& inP,
vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagBasic>& outPos)
{
vtkm::cont::Invoker invoke;
detail::CopyParticlePositionWorklet worklet;
invoke(worklet, inP, outPos);
}
/// \brief Copy all fields in vtkm::Particle to standard types.
///
/// Given an \c ArrayHandle of vtkm::Particle, this function copies the
/// position, ID, number of steps, status and time into a separate
/// \c ArrayHandle.
///
template <typename ParticleType>
VTKM_ALWAYS_EXPORT inline void ParticleArrayCopy(
const vtkm::cont::ArrayHandle<ParticleType, vtkm::cont::StorageTagBasic>& inP,
vtkm::cont::ArrayHandle<vtkm::Vec3f, vtkm::cont::StorageTagBasic>& outPos,
vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic>& outID,
vtkm::cont::ArrayHandle<vtkm::Id, vtkm::cont::StorageTagBasic>& outSteps,
vtkm::cont::ArrayHandle<vtkm::ParticleStatus, vtkm::cont::StorageTagBasic>& outStatus,
vtkm::cont::ArrayHandle<vtkm::FloatDefault, vtkm::cont::StorageTagBasic>& outTime)
{
vtkm::cont::Invoker invoke;
detail::CopyParticleAllWorklet worklet;
invoke(worklet, inP, outPos, outID, outSteps, outStatus, outTime);
}
}
} // namespace vtkm::cont
#endif //vtk_m_cont_ParticleArrayCopy_hxx

@ -115,7 +115,7 @@ struct PointLocatorUniformGrid::PrepareExecutionObjectFunctor
rmin, rmin,
rmax, rmax,
self.Dims, self.Dims,
self.GetCoordinates().GetData().PrepareForInput(DeviceAdapter(), token), self.GetCoordinates().GetDataAsMultiplexer().PrepareForInput(DeviceAdapter(), token),
self.PointIds.PrepareForInput(DeviceAdapter(), token), self.PointIds.PrepareForInput(DeviceAdapter(), token),
self.CellLower.PrepareForInput(DeviceAdapter(), token), self.CellLower.PrepareForInput(DeviceAdapter(), token),
self.CellUpper.PrepareForInput(DeviceAdapter(), token)); self.CellUpper.PrepareForInput(DeviceAdapter(), token));

@ -395,15 +395,6 @@ public:
{ {
} }
// Create with externally managed memory
Storage(const BaseT* array, vtkm::Id arrayLength, vtkm::Int32 numberOfPlanes, bool cylindrical)
: Array(vtkm::cont::make_ArrayHandle(array, arrayLength))
, NumberOfPlanes(numberOfPlanes)
, UseCylindrical(cylindrical)
{
VTKM_ASSERT(this->Array.GetNumberOfValues() >= 0);
}
Storage(const HandleType& array, vtkm::Int32 numberOfPlanes, bool cylindrical) Storage(const HandleType& array, vtkm::Int32 numberOfPlanes, bool cylindrical)
: Array(array) : Array(array)
, NumberOfPlanes(numberOfPlanes) , NumberOfPlanes(numberOfPlanes)

@ -84,7 +84,18 @@ public:
template <typename ArrayHandleType> template <typename ArrayHandleType>
VTKM_CONT ArrayHandleType Cast() const VTKM_CONT ArrayHandleType Cast() const
{ {
// MSVC will issue deprecation warnings if this templated method is instantiated with
// a deprecated class here even if the method is called from a section of code where
// deprecation warnings are suppressed. This is annoying behavior since this templated
// method has no control over what class it is used from. To get around it, we have to
// suppress all deprecation warnings here.
#ifdef VTKM_MSVC
VTKM_DEPRECATED_SUPPRESS_BEGIN
#endif
return internal::variant::Cast<ArrayHandleType>(this->ArrayContainer.get()); return internal::variant::Cast<ArrayHandleType>(this->ArrayContainer.get());
#ifdef VTKM_MSVC
VTKM_DEPRECATED_SUPPRESS_END
#endif
} }
/// \brief Call a functor using the underlying array type. /// \brief Call a functor using the underlying array type.
@ -202,7 +213,7 @@ public:
/// \brief Holds an array handle without having to specify template parameters. /// \brief Holds an array handle without having to specify template parameters.
/// ///
/// \c VariantArrayHandle holds an \c ArrayHandle or \c ArrayHandleVirtual /// `VariantArrayHandle` holds an `ArrayHandle`
/// object using runtime polymorphism to manage different value types and /// object using runtime polymorphism to manage different value types and
/// storage rather than compile-time templates. This adds a programming /// storage rather than compile-time templates. This adds a programming
/// convenience that helps avoid a proliferation of templates. It also provides /// convenience that helps avoid a proliferation of templates. It also provides
@ -210,24 +221,23 @@ public:
/// will not be known until runtime. /// will not be known until runtime.
/// ///
/// To interface between the runtime polymorphism and the templated algorithms /// To interface between the runtime polymorphism and the templated algorithms
/// in VTK-m, \c VariantArrayHandle contains a method named \c CastAndCall that /// in VTK-m, `VariantArrayHandle` contains a method named `CastAndCall` that
/// will determine the correct type from some known list of types. It returns /// will determine the correct type from some known list of types.
/// an ArrayHandleVirtual which type erases the storage type by using polymorphism.
/// This mechanism is used internally by VTK-m's worklet invocation /// This mechanism is used internally by VTK-m's worklet invocation
/// mechanism to determine the type when running algorithms. /// mechanism to determine the type when running algorithms.
/// ///
/// By default, \c VariantArrayHandle will assume that the value type in the /// By default, `VariantArrayHandle` will assume that the value type in the
/// array matches one of the types specified by \c VTKM_DEFAULT_TYPE_LIST /// array matches one of the types specified by `VTKM_DEFAULT_TYPE_LIST`
/// This list can be changed by using the \c ResetTypes. It is /// This list can be changed by using the `ResetTypes`. It is
/// worthwhile to match these lists closely to the possible types that might be /// worthwhile to match these lists closely to the possible types that might be
/// used. If a type is missing you will get a runtime error. If there are more /// used. If a type is missing you will get a runtime error. If there are more
/// types than necessary, then the template mechanism will create a lot of /// types than necessary, then the template mechanism will create a lot of
/// object code that is never used, and keep in mind that the number of /// object code that is never used, and keep in mind that the number of
/// combinations grows exponentially when using multiple \c VariantArrayHandle /// combinations grows exponentially when using multiple `VariantArrayHandle`
/// objects. /// objects.
/// ///
/// The actual implementation of \c VariantArrayHandle is in a templated class /// The actual implementation of `VariantArrayHandle` is in a templated class
/// named \c VariantArrayHandleBase, which is templated on the list of /// named `VariantArrayHandleBase`, which is templated on the list of
/// component types. /// component types.
/// ///
template <typename TypeList> template <typename TypeList>
@ -301,16 +311,12 @@ public:
/// `CastAndCall` attempts to cast the held array to a specific value type, /// `CastAndCall` attempts to cast the held array to a specific value type,
/// then call the given functor with the cast array. The types /// then call the given functor with the cast array. The types
/// tried in the cast are those in the lists defined by the TypeList. /// tried in the cast are those in the lists defined by the TypeList.
/// By default \c VariantArrayHandle set this to \c VTKM_DEFAULT_TYPE_LIST. /// By default `VariantArrayHandle` set this to `VTKM_DEFAULT_TYPE_LIST`.
/// ///
/// In addition to the value type, an \c ArrayHandle also requires a storage tag. /// In addition to the value type, an `ArrayHandle` also requires a storage tag.
/// By default, \c CastAndCall attempts to cast the array using the storage tags /// By default, `CastAndCall` attempts to cast the array using the storage tags
/// listed in \c VTKM_DEFAULT_STORAGE_LIST. You can optionally give a custom /// listed in `VTKM_DEFAULT_STORAGE_LIST`. You can optionally give a custom
/// list of storage tags as the second argument. If the storage of the underlying /// list of storage tags as the second argument.
/// array does not match any of the storage tags given, then the array will
/// be cast to an \c ArrayHandleVirtual, which can hold any array given the
/// appropriate value type. To always use \c ArrayHandleVirtual, pass
/// \c vtkm::ListEmpty as thefirst argument.
/// ///
/// As previous stated, if a storage tag list is provided, it is given in the /// As previous stated, if a storage tag list is provided, it is given in the
/// first argument. The functor to call with the cast array is given as the next /// first argument. The functor to call with the cast array is given as the next
@ -318,7 +324,7 @@ public:
/// The remaning arguments, if any, are passed to the functor. /// The remaning arguments, if any, are passed to the functor.
/// ///
/// The functor will be called with the cast array as its first argument. Any /// The functor will be called with the cast array as its first argument. Any
/// remaining arguments are passed from the arguments to \c CastAndCall. /// remaining arguments are passed from the arguments to `CastAndCall`.
/// ///
template <typename FunctorOrStorageList, typename... Args> template <typename FunctorOrStorageList, typename... Args>
VTKM_CONT void CastAndCall(FunctorOrStorageList&& functorOrStorageList, Args&&... args) const VTKM_CONT void CastAndCall(FunctorOrStorageList&& functorOrStorageList, Args&&... args) const
@ -423,35 +429,6 @@ struct VariantArrayHandleTry
} }
}; };
struct VariantArrayHandleTryFallback
{
template <typename T, typename Functor, typename... Args>
void operator()(T,
Functor&& f,
bool& called,
const vtkm::cont::internal::VariantArrayHandleContainerBase& container,
Args&&... args) const
{
if (!called && vtkm::cont::internal::variant::IsValueType<T>(&container))
{
called = true;
const auto* derived =
static_cast<const vtkm::cont::internal::VariantArrayHandleContainer<T>*>(&container);
VTKM_LOG_CAST_SUCC(container, derived);
// If you get a compile error here, it means that you have called CastAndCall for a
// vtkm::cont::VariantArrayHandle and the arguments of the functor do not match those
// being passed. This is often because it is calling the functor with an ArrayHandle
// type that was not expected. Either add overloads to the functor to accept all
// possible array types or constrain the types tried for the CastAndCall. Note that
// the functor will be called with an array of type vtkm::cont::ArrayHandle<T, S>.
// Directly using a subclass of ArrayHandle (e.g. vtkm::cont::ArrayHandleConstant<T>)
// might not work.
f(derived->Array, std::forward<Args>(args)...);
}
}
};
template <typename T> template <typename T>
struct IsUndefinedStorage struct IsUndefinedStorage
{ {
@ -484,16 +461,6 @@ VTKM_CONT void VariantArrayHandleCommon::CastAndCall(Functor&& f, Args&&... args
ref, ref,
std::forward<Args>(args)...); std::forward<Args>(args)...);
if (!called) if (!called)
{
// try to fall back to using ArrayHandleVirtual
vtkm::ListForEach(detail::VariantArrayHandleTryFallback{},
TypeList{},
std::forward<Functor>(f),
called,
ref,
std::forward<Args>(args)...);
}
if (!called)
{ {
// throw an exception // throw an exception
VTKM_LOG_CAST_FAIL(*this, TypeList); VTKM_LOG_CAST_FAIL(*this, TypeList);
@ -660,14 +627,14 @@ struct VariantArrayHandleSerializeFunctor
struct VariantArrayHandleDeserializeFunctor struct VariantArrayHandleDeserializeFunctor
{ {
template <typename T, typename TypeList> template <typename T, typename S, typename TypeList>
void operator()(T, void operator()(vtkm::List<T, S>,
vtkm::cont::VariantArrayHandleBase<TypeList>& dh, vtkm::cont::VariantArrayHandleBase<TypeList>& dh,
const std::string& typeString, const std::string& typeString,
bool& success, bool& success,
BinaryBuffer& bb) const BinaryBuffer& bb) const
{ {
using ArrayHandleType = vtkm::cont::ArrayHandleVirtual<T>; using ArrayHandleType = vtkm::cont::ArrayHandle<T, S>;
if (!success && (typeString == vtkm::cont::SerializableTypeString<ArrayHandleType>::Get())) if (!success && (typeString == vtkm::cont::SerializableTypeString<ArrayHandleType>::Get()))
{ {
@ -690,7 +657,7 @@ private:
public: public:
static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj) static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj)
{ {
obj.CastAndCall(vtkm::ListEmpty(), internal::VariantArrayHandleSerializeFunctor{}, bb); obj.CastAndCall(internal::VariantArrayHandleSerializeFunctor{}, bb);
} }
static VTKM_CONT void load(BinaryBuffer& bb, Type& obj) static VTKM_CONT void load(BinaryBuffer& bb, Type& obj)
@ -699,8 +666,12 @@ public:
vtkmdiy::load(bb, typeString); vtkmdiy::load(bb, typeString);
bool success = false; bool success = false;
vtkm::ListForEach( vtkm::ListForEach(internal::VariantArrayHandleDeserializeFunctor{},
internal::VariantArrayHandleDeserializeFunctor{}, TypeList{}, obj, typeString, success, bb); vtkm::cont::detail::ListDynamicTypes<TypeList, VTKM_DEFAULT_STORAGE_LIST>{},
obj,
typeString,
success,
bb);
if (!success) if (!success)
{ {

@ -51,7 +51,7 @@ struct TryArrayInType
} }
using ArrayHandleType = vtkm::cont::ArrayHandle<T>; using ArrayHandleType = vtkm::cont::ArrayHandle<T>;
ArrayHandleType handle = vtkm::cont::make_ArrayHandle(array, ARRAY_SIZE); ArrayHandleType handle = vtkm::cont::make_ArrayHandle(array, ARRAY_SIZE, vtkm::CopyFlag::Off);
using PortalType = typename ArrayHandleType::template ExecutionTypes<Device>::PortalConst; using PortalType = typename ArrayHandleType::template ExecutionTypes<Device>::PortalConst;

@ -49,7 +49,7 @@ struct TryArrayInOutType
} }
using ArrayHandleType = vtkm::cont::ArrayHandle<T>; using ArrayHandleType = vtkm::cont::ArrayHandle<T>;
ArrayHandleType handle = vtkm::cont::make_ArrayHandle(array, ARRAY_SIZE); ArrayHandleType handle = vtkm::cont::make_ArrayHandle(array, ARRAY_SIZE, vtkm::CopyFlag::Off);
using PortalType = typename ArrayHandleType::template ExecutionTypes<Device>::Portal; using PortalType = typename ArrayHandleType::template ExecutionTypes<Device>::Portal;

@ -43,7 +43,7 @@ VTKM_CONT_EXPORT void ThrowCastAndCallException(
const std::type_info& type) const std::type_info& type)
{ {
std::ostringstream out; std::ostringstream out;
out << "Could not find appropriate cast for array in CastAndCall1.\n" out << "Could not find appropriate cast for array in CastAndCall.\n"
"Array: "; "Array: ";
ref.PrintSummary(out); ref.PrintSummary(out);
out << "TypeList: " << type.name() << "\n"; out << "TypeList: " << type.name() << "\n";

@ -211,6 +211,14 @@ struct VTKM_ALWAYS_EXPORT Caster<T, vtkm::cont::StorageTagVirtual>
} }
}; };
// MSVC will issue deprecation warnings here if this template is instantiated with
// a deprecated class even if the template is used from a section of code where
// deprecation warnings are suppressed. This is annoying behavior since this template
// has no control over what class it is used with. To get around it, we have to
// suppress all deprecation warnings here.
#ifdef VTKM_MSVC
VTKM_DEPRECATED_SUPPRESS_BEGIN
#endif
template <typename ArrayHandleType> template <typename ArrayHandleType>
VTKM_CONT ArrayHandleType Cast(const VariantArrayHandleContainerBase* container) VTKM_CONT ArrayHandleType Cast(const VariantArrayHandleContainerBase* container)
{ //container could be nullptr { //container could be nullptr
@ -220,6 +228,9 @@ VTKM_CONT ArrayHandleType Cast(const VariantArrayHandleContainerBase* container)
auto ret = Caster<Type, Storage>{}(container); auto ret = Caster<Type, Storage>{}(container);
return ArrayHandleType(std::move(ret)); return ArrayHandleType(std::move(ret));
} }
#ifdef VTKM_MSVC
VTKM_DEPRECATED_SUPPRESS_END
#endif
struct ForceCastToVirtual struct ForceCastToVirtual
{ {

@ -48,10 +48,10 @@ void VectorReallocator(void*& memory,
{ {
std::vector<T>* v = reinterpret_cast<std::vector<T>*>(container); std::vector<T>* v = reinterpret_cast<std::vector<T>*>(container);
VTKM_TEST_ASSERT(v->size() == static_cast<std::size_t>(oldSize)); VTKM_TEST_ASSERT(v->size() == static_cast<std::size_t>(oldSize));
VTKM_TEST_ASSERT(memory == &v->front()); VTKM_TEST_ASSERT(v->empty() || (memory == v->data()));
v->resize(static_cast<std::size_t>(newSize)); v->resize(static_cast<std::size_t>(newSize));
memory = &v->front(); memory = v->data();
} }
struct VectorDeleter struct VectorDeleter
{ {
@ -67,7 +67,7 @@ struct VectorDeleter
{ {
if (this->Data) if (this->Data)
{ {
VTKM_TEST_ASSERT(reinterpret_cast<T*>(p) == &this->Data->front()); VTKM_TEST_ASSERT(reinterpret_cast<T*>(p) == this->Data->data());
this->Data.reset(); this->Data.reset();
} }
} }
@ -132,7 +132,7 @@ void DoTest()
std::cout << "Reset with device data" << std::endl; std::cout << "Reset with device data" << std::endl;
std::vector<T> v(ARRAY_SIZE); std::vector<T> v(ARRAY_SIZE);
void* devicePointer = &v.front(); void* devicePointer = v.data();
SetPortal(MakePortal(devicePointer, ARRAY_SIZE)); SetPortal(MakePortal(devicePointer, ARRAY_SIZE));
buffer.Reset(vtkm::cont::internal::BufferInfo(device, buffer.Reset(vtkm::cont::internal::BufferInfo(device,
devicePointer, devicePointer,

@ -90,6 +90,21 @@ static void ComputeChunkSize(const vtkm::Id numVals,
valuesPerChunk = CeilDivide(pagesPerChunk * VTKM_PAGE_SIZE, bytesPerValue); valuesPerChunk = CeilDivide(pagesPerChunk * VTKM_PAGE_SIZE, bytesPerValue);
} }
template <typename T>
struct CleanArrayRefImpl
{
using type = T;
};
template <typename PortalType>
struct CleanArrayRefImpl<vtkm::internal::ArrayPortalValueReference<PortalType>>
{
using type = typename PortalType::ValueType;
};
template <typename T>
using CleanArrayRef = typename CleanArrayRefImpl<T>::type;
template <typename T, typename U> template <typename T, typename U>
static void DoCopy(T src, U dst, vtkm::Id numVals, std::true_type) static void DoCopy(T src, U dst, vtkm::Id numVals, std::true_type)
{ {
@ -103,19 +118,24 @@ static void DoCopy(T src, U dst, vtkm::Id numVals, std::true_type)
template <typename InIterT, typename OutIterT> template <typename InIterT, typename OutIterT>
static void DoCopy(InIterT inIter, OutIterT outIter, vtkm::Id numVals, std::false_type) static void DoCopy(InIterT inIter, OutIterT outIter, vtkm::Id numVals, std::false_type)
{ {
using ValueType = typename std::iterator_traits<OutIterT>::value_type; using InValueType = CleanArrayRef<typename std::iterator_traits<InIterT>::value_type>;
using OutValueType = CleanArrayRef<typename std::iterator_traits<OutIterT>::value_type>;
for (vtkm::Id i = 0; i < numVals; ++i) for (vtkm::Id i = 0; i < numVals; ++i)
{ {
*(outIter++) = static_cast<ValueType>(*(inIter++)); // The conversion to InputType and then OutputType looks weird, but it is necessary.
// *inItr actually returns an ArrayPortalValueReference, which can automatically convert
// itself to InputType but not necessarily OutputType. Thus, we first convert to
// InputType, and then allow the conversion to OutputType.
*(outIter++) = static_cast<OutValueType>(static_cast<InValueType>(*(inIter++)));
} }
} }
template <typename InIterT, typename OutIterT> template <typename InIterT, typename OutIterT>
static void DoCopy(InIterT inIter, OutIterT outIter, vtkm::Id numVals) static void DoCopy(InIterT inIter, OutIterT outIter, vtkm::Id numVals)
{ {
using InValueType = typename std::iterator_traits<InIterT>::value_type; using InValueType = CleanArrayRef<typename std::iterator_traits<InIterT>::value_type>;
using OutValueType = typename std::iterator_traits<OutIterT>::value_type; using OutValueType = CleanArrayRef<typename std::iterator_traits<OutIterT>::value_type>;
DoCopy(inIter, outIter, numVals, std::is_same<InValueType, OutValueType>()); DoCopy(inIter, outIter, numVals, std::is_same<InValueType, OutValueType>());
} }

@ -46,22 +46,32 @@ private:
// template calls std::copy if and only if the types match, otherwise falls // template calls std::copy if and only if the types match, otherwise falls
// back to a iterative casting approach. Since std::copy can only really // back to a iterative casting approach. Since std::copy can only really
// optimize same-type copies, this shouldn't affect performance. // optimize same-type copies, this shouldn't affect performance.
template <typename InIter, typename OutIter> template <typename InPortal, typename OutPortal>
static void DoCopy(InIter src, InIter srcEnd, OutIter dst, std::false_type) static void DoCopy(InPortal src,
OutPortal dst,
std::false_type,
vtkm::Id startIndex,
vtkm::Id numToCopy,
vtkm::Id outIndex)
{ {
using OutputType = typename std::iterator_traits<OutIter>::value_type; using OutputType = typename OutPortal::ValueType;
while (src != srcEnd) for (vtkm::Id index = 0; index < numToCopy; ++index)
{ {
*dst = static_cast<OutputType>(*src); dst.Set(index + startIndex, static_cast<OutputType>(src.Get(index + outIndex)));
++src;
++dst;
} }
} }
template <typename InIter, typename OutIter> template <typename InPortal, typename OutPortal>
static void DoCopy(InIter src, InIter srcEnd, OutIter dst, std::true_type) static void DoCopy(InPortal src,
OutPortal dst,
std::true_type,
vtkm::Id startIndex,
vtkm::Id numToCopy,
vtkm::Id outIndex)
{ {
std::copy(src, srcEnd, dst); std::copy(vtkm::cont::ArrayPortalToIteratorBegin(src) + startIndex,
vtkm::cont::ArrayPortalToIteratorBegin(src) + startIndex + numToCopy,
vtkm::cont::ArrayPortalToIteratorBegin(dst) + outIndex);
} }
public: public:
@ -85,10 +95,7 @@ public:
using InputType = decltype(inputPortal.Get(0)); using InputType = decltype(inputPortal.Get(0));
using OutputType = decltype(outputPortal.Get(0)); using OutputType = decltype(outputPortal.Get(0));
DoCopy(vtkm::cont::ArrayPortalToIteratorBegin(inputPortal), DoCopy(inputPortal, outputPortal, std::is_same<InputType, OutputType>{}, 0, inSize, 0);
vtkm::cont::ArrayPortalToIteratorEnd(inputPortal),
vtkm::cont::ArrayPortalToIteratorBegin(outputPortal),
std::is_same<InputType, OutputType>());
} }
template <typename T, typename U, class CIn, class CStencil, class COut> template <typename T, typename U, class CIn, class CStencil, class COut>
@ -188,16 +195,16 @@ public:
vtkm::cont::Token token; vtkm::cont::Token token;
auto inputPortal = input.PrepareForInput(DeviceAdapterTagSerial(), token); auto inputPortal = input.PrepareForInput(DeviceAdapterTagSerial(), token);
auto outputPortal = output.PrepareForInPlace(DeviceAdapterTagSerial(), token); auto outputPortal = output.PrepareForInPlace(DeviceAdapterTagSerial(), token);
auto inIter = vtkm::cont::ArrayPortalToIteratorBegin(inputPortal);
auto outIter = vtkm::cont::ArrayPortalToIteratorBegin(outputPortal);
using InputType = decltype(inputPortal.Get(0)); using InputType = decltype(inputPortal.Get(0));
using OutputType = decltype(outputPortal.Get(0)); using OutputType = decltype(outputPortal.Get(0));
DoCopy(inIter + inputStartIndex, DoCopy(inputPortal,
inIter + inputStartIndex + numberOfElementsToCopy, outputPortal,
outIter + outputIndex, std::is_same<InputType, OutputType>(),
std::is_same<InputType, OutputType>()); inputStartIndex,
numberOfElementsToCopy,
outputIndex);
return true; return true;
} }

@ -107,10 +107,15 @@ struct CopyBody
template <typename InIter, typename OutIter> template <typename InIter, typename OutIter>
void DoCopy(InIter src, InIter srcEnd, OutIter dst, std::false_type) const void DoCopy(InIter src, InIter srcEnd, OutIter dst, std::false_type) const
{ {
using OutputType = typename std::iterator_traits<OutIter>::value_type; using InputType = typename InputPortalType::ValueType;
using OutputType = typename OutputPortalType::ValueType;
while (src != srcEnd) while (src != srcEnd)
{ {
*dst = static_cast<OutputType>(*src); // The conversion to InputType and then OutputType looks weird, but it is necessary.
// *src actually returns an ArrayPortalValueReference, which can automatically convert
// itself to InputType but not necessarily OutputType. Thus, we first convert to
// InputType, and then allow the conversion to OutputType.
*dst = static_cast<OutputType>(static_cast<InputType>(*src));
++src; ++src;
++dst; ++dst;
} }

@ -364,8 +364,10 @@ inline vtkm::cont::DataSet MakeTestDataSet::Make3DUniformDataSet3(const vtkm::Id
dataSet.AddPointField("pointvar", pointvar); dataSet.AddPointField("pointvar", pointvar);
vtkm::Id numCells = (dims[0] - 1) * (dims[1] - 1) * (dims[2] - 1); vtkm::Id numCells = (dims[0] - 1) * (dims[1] - 1) * (dims[2] - 1);
dataSet.AddCellField( vtkm::cont::ArrayHandle<vtkm::Float64> cellvar;
"cellvar", vtkm::cont::make_ArrayHandleCounting(vtkm::Float64(0), vtkm::Float64(1), numCells)); vtkm::cont::ArrayCopy(
vtkm::cont::make_ArrayHandleCounting(vtkm::Float64(0), vtkm::Float64(1), numCells), cellvar);
dataSet.AddCellField("cellvar", cellvar);
return dataSet; return dataSet;
} }

@ -10,6 +10,9 @@
#ifndef vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h #ifndef vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h
#define vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h #define vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h
// This is testing deprecated functionality. It is left to make sure that old code
// still works, but will be removed if ArrayHandleVirtualCoordinates is removed.
#include <vtkm/cont/ArrayHandleCartesianProduct.h> #include <vtkm/cont/ArrayHandleCartesianProduct.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h> #include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h> #include <vtkm/cont/ArrayHandleVirtualCoordinates.h>
@ -17,6 +20,8 @@
#include <vtkm/worklet/DispatcherMapField.h> #include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h> #include <vtkm/worklet/WorkletMapField.h>
VTKM_DEPRECATED_SUPPRESS_BEGIN
namespace vtkm namespace vtkm
{ {
namespace cont namespace cont
@ -142,5 +147,6 @@ public:
} }
} // vtkm::cont::testing } // vtkm::cont::testing
VTKM_DEPRECATED_SUPPRESS_END
#endif // vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h #endif // vtk_m_cont_testing_TestingArrayHandleVirtualCoordinates_h

@ -177,7 +177,7 @@ private:
arrayHandle.ReleaseResourcesExecution(); arrayHandle.ReleaseResourcesExecution();
arrayHandle = vtkm::cont::ArrayHandle<T>(); arrayHandle = vtkm::cont::ArrayHandle<T>();
arrayHandle.ReleaseResources(); arrayHandle.ReleaseResources();
arrayHandle = vtkm::cont::make_ArrayHandle(std::vector<T>()); arrayHandle = vtkm::cont::make_ArrayHandleMove(std::vector<T>());
arrayHandle.PrepareForInput(DeviceAdapterTag(), token); arrayHandle.PrepareForInput(DeviceAdapterTag(), token);
arrayHandle = vtkm::cont::ArrayHandle<T>(); arrayHandle = vtkm::cont::ArrayHandle<T>();
arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token); arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
@ -361,6 +361,144 @@ private:
} }
}; };
struct VerifyVectorMovedMemory
{
template <typename T>
VTKM_CONT void operator()(T) const
{
std::cout << "Creating moved std::vector memory." << std::endl;
std::vector<T> buffer(ARRAY_SIZE);
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
buffer[static_cast<std::size_t>(index)] = TestValue(index, T());
}
vtkm::cont::ArrayHandle<T> arrayHandle = vtkm::cont::make_ArrayHandleMove(std::move(buffer));
// buffer is now invalid
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE,
"ArrayHandle has wrong number of entries.");
std::cout << "Check array with moved std::vector memory." << std::endl;
array_handle_testing::CheckArray(arrayHandle);
std::cout << "Check out execution array behavior." << std::endl;
{ //as input
vtkm::cont::Token token;
typename vtkm::cont::ArrayHandle<T>::template ExecutionTypes<DeviceAdapterTag>::PortalConst
executionPortal;
executionPortal = arrayHandle.PrepareForInput(DeviceAdapterTag(), token);
token.DetachFromAll();
//use a worklet to verify the input transfer worked properly
vtkm::cont::ArrayHandle<T> result;
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
array_handle_testing::CheckArray(result);
}
std::cout << "Check out inplace." << std::endl;
{ //as inplace
vtkm::cont::Token token;
typename vtkm::cont::ArrayHandle<T>::template ExecutionTypes<DeviceAdapterTag>::Portal
executionPortal;
executionPortal = arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
token.DetachFromAll();
//use a worklet to verify the inplace transfer worked properly
vtkm::cont::ArrayHandle<T> result;
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
array_handle_testing::CheckArray(result);
}
std::cout << "Check out output." << std::endl;
{ //as output with same length as user provided. This should work
//as no new memory needs to be allocated
vtkm::cont::Token token;
arrayHandle.PrepareForOutput(ARRAY_SIZE, DeviceAdapterTag(), token);
token.DetachFromAll();
//we can't verify output contents as those aren't fetched, we
//can just make sure the allocation didn't throw an exception
}
{ //as a vector moved to the ArrayHandle, reallocation should be possible
vtkm::cont::Token token;
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, DeviceAdapterTag(), token);
token.DetachFromAll();
//we can't verify output contents as those aren't fetched, we
//can just make sure the allocation didn't throw an exception
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2);
}
}
};
struct VerifyInitializerList
{
template <typename T>
VTKM_CONT void operator()(T) const
{
std::cout << "Creating array with initializer list memory." << std::endl;
vtkm::cont::ArrayHandle<T> arrayHandle =
vtkm::cont::make_ArrayHandle({ TestValue(0, T()), TestValue(1, T()), TestValue(2, T()) });
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == 3,
"ArrayHandle has wrong number of entries.");
std::cout << "Check array with initializer list memory." << std::endl;
array_handle_testing::CheckArray(arrayHandle);
std::cout << "Check out execution array behavior." << std::endl;
{ //as input
vtkm::cont::Token token;
typename vtkm::cont::ArrayHandle<T>::template ExecutionTypes<DeviceAdapterTag>::PortalConst
executionPortal;
executionPortal = arrayHandle.PrepareForInput(DeviceAdapterTag(), token);
token.DetachFromAll();
//use a worklet to verify the input transfer worked properly
vtkm::cont::ArrayHandle<T> result;
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
array_handle_testing::CheckArray(result);
}
std::cout << "Check out inplace." << std::endl;
{ //as inplace
vtkm::cont::Token token;
typename vtkm::cont::ArrayHandle<T>::template ExecutionTypes<DeviceAdapterTag>::Portal
executionPortal;
executionPortal = arrayHandle.PrepareForInPlace(DeviceAdapterTag(), token);
token.DetachFromAll();
//use a worklet to verify the inplace transfer worked properly
vtkm::cont::ArrayHandle<T> result;
DispatcherPassThrough().Invoke(arrayHandle, WrapPortal(executionPortal), result);
array_handle_testing::CheckArray(result);
}
std::cout << "Check out output." << std::endl;
{ //as output with same length as user provided. This should work
//as no new memory needs to be allocated
vtkm::cont::Token token;
arrayHandle.PrepareForOutput(3, DeviceAdapterTag(), token);
token.DetachFromAll();
//we can't verify output contents as those aren't fetched, we
//can just make sure the allocation didn't throw an exception
}
{ //as a vector moved to the ArrayHandle, reallocation should be possible
vtkm::cont::Token token;
arrayHandle.PrepareForOutput(ARRAY_SIZE * 2, DeviceAdapterTag(), token);
token.DetachFromAll();
//we can't verify output contents as those aren't fetched, we
//can just make sure the allocation didn't throw an exception
VTKM_TEST_ASSERT(arrayHandle.GetNumberOfValues() == ARRAY_SIZE * 2);
}
}
};
struct VerifyVTKMAllocatedHandle struct VerifyVTKMAllocatedHandle
{ {
template <typename T> template <typename T>
@ -497,11 +635,13 @@ private:
{ {
void operator()() const void operator()() const
{ {
vtkm::testing::Testing::TryTypes(VerifyEmptyArrays()); vtkm::testing::Testing::TryTypes(VerifyEmptyArrays{});
vtkm::testing::Testing::TryTypes(VerifyUserOwnedMemory()); vtkm::testing::Testing::TryTypes(VerifyUserOwnedMemory{});
vtkm::testing::Testing::TryTypes(VerifyUserTransferredMemory()); vtkm::testing::Testing::TryTypes(VerifyUserTransferredMemory{});
vtkm::testing::Testing::TryTypes(VerifyVTKMAllocatedHandle()); vtkm::testing::Testing::TryTypes(VerifyVectorMovedMemory{});
vtkm::testing::Testing::TryTypes(VerifyEqualityOperators()); vtkm::testing::Testing::TryTypes(VerifyInitializerList{});
vtkm::testing::Testing::TryTypes(VerifyVTKMAllocatedHandle{});
vtkm::testing::Testing::TryTypes(VerifyEqualityOperators{});
} }
}; };

@ -170,7 +170,8 @@ public:
pointsVec.push_back(point); pointsVec.push_back(point);
} }
vtkm::cont::ArrayHandle<PointType> points = vtkm::cont::make_ArrayHandle(pointsVec); vtkm::cont::ArrayHandle<PointType> points =
vtkm::cont::make_ArrayHandle(pointsVec, vtkm::CopyFlag::Off);
// Initialize locator // Initialize locator
vtkm::cont::CellLocatorRectilinearGrid locator; vtkm::cont::CellLocatorRectilinearGrid locator;

@ -76,10 +76,6 @@ vtkm::cont::DataSet MakeTestDataSet(const vtkm::Vec<vtkm::Id, DIMENSIONS>& dims)
vtkm::Vec<vtkm::FloatDefault, DIMENSIONS>(0.0f), vtkm::Vec<vtkm::FloatDefault, DIMENSIONS>(0.0f),
vtkm::Vec<vtkm::FloatDefault, DIMENSIONS>(1.0f)); vtkm::Vec<vtkm::FloatDefault, DIMENSIONS>(1.0f));
// copy points
vtkm::cont::ArrayHandle<PointType> points;
vtkm::cont::ArrayCopy(uniformDs.GetCoordinateSystem().GetData(), points);
auto uniformCs = auto uniformCs =
uniformDs.GetCellSet().template Cast<vtkm::cont::CellSetStructured<DIMENSIONS>>(); uniformDs.GetCellSet().template Cast<vtkm::cont::CellSetStructured<DIMENSIONS>>();
@ -99,15 +95,21 @@ vtkm::cont::DataSet MakeTestDataSet(const vtkm::Vec<vtkm::Id, DIMENSIONS>& dims)
// Warp the coordinates // Warp the coordinates
std::uniform_real_distribution<vtkm::FloatDefault> warpFactor(-0.10f, 0.10f); std::uniform_real_distribution<vtkm::FloatDefault> warpFactor(-0.10f, 0.10f);
auto pointsPortal = points.WritePortal(); auto inPointsPortal = uniformDs.GetCoordinateSystem()
for (vtkm::Id i = 0; i < pointsPortal.GetNumberOfValues(); ++i) .GetData()
.template Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>()
.ReadPortal();
vtkm::cont::ArrayHandle<PointType> points;
points.Allocate(inPointsPortal.GetNumberOfValues());
auto outPointsPortal = points.WritePortal();
for (vtkm::Id i = 0; i < outPointsPortal.GetNumberOfValues(); ++i)
{ {
PointType warpVec(0); PointType warpVec(0);
for (vtkm::IdComponent c = 0; c < DIMENSIONS; ++c) for (vtkm::IdComponent c = 0; c < DIMENSIONS; ++c)
{ {
warpVec[c] = warpFactor(RandomGenerator); warpVec[c] = warpFactor(RandomGenerator);
} }
pointsPortal.Set(i, pointsPortal.Get(i) + warpVec); outPointsPortal.Set(i, inPointsPortal.Get(i) + warpVec);
} }
// build dataset // build dataset
@ -152,7 +154,8 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds,
vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates> dispatcher( vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates> dispatcher(
ParametricToWorldCoordinates::MakeScatter(cellIds)); ParametricToWorldCoordinates::MakeScatter(cellIds));
dispatcher.Invoke(ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords); dispatcher.Invoke(
ds.GetCellSet(), ds.GetCoordinateSystem().GetDataAsMultiplexer(), pcoords, wcoords);
} }
class FindCellWorklet : public vtkm::worklet::WorkletMapField class FindCellWorklet : public vtkm::worklet::WorkletMapField

@ -145,7 +145,8 @@ public:
pointsVec.push_back(vtkm::make_Vec(0, 4, 4)); pointsVec.push_back(vtkm::make_Vec(0, 4, 4));
pointsVec.push_back(vtkm::make_Vec(4, 0, 4)); pointsVec.push_back(vtkm::make_Vec(4, 0, 4));
vtkm::cont::ArrayHandle<PointType> points = vtkm::cont::make_ArrayHandle(pointsVec); vtkm::cont::ArrayHandle<PointType> points =
vtkm::cont::make_ArrayHandle(pointsVec, vtkm::CopyFlag::Off);
// Query the points using the locators. // Query the points using the locators.
vtkm::cont::ArrayHandle<vtkm::Id> cellIds; vtkm::cont::ArrayHandle<vtkm::Id> cellIds;
vtkm::cont::ArrayHandle<PointType> parametric; vtkm::cont::ArrayHandle<PointType> parametric;

@ -177,9 +177,7 @@ public:
vtkm::cont::ColorTable table(range, rgb1, rgb2, rgbspace); vtkm::cont::ColorTable table(range, rgb1, rgb2, rgbspace);
VTKM_TEST_ASSERT(table.GetClamping() == true, "clamping not setup properly"); VTKM_TEST_ASSERT(table.GetClamping() == true, "clamping not setup properly");
constexpr vtkm::Id nvals = 4; auto field = vtkm::cont::make_ArrayHandle({ -1, 0, 1, 2 });
constexpr int data[nvals] = { -1, 0, 1, 2 };
auto field = vtkm::cont::make_ArrayHandle(data, nvals);
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
const bool ran = table.Map(field, colors); const bool ran = table.Map(field, colors);
@ -202,9 +200,7 @@ public:
table.SetClampingOff(); table.SetClampingOff();
VTKM_TEST_ASSERT(table.GetClamping() == false, "clamping not setup properly"); VTKM_TEST_ASSERT(table.GetClamping() == false, "clamping not setup properly");
constexpr vtkm::Id nvals = 4; auto field = vtkm::cont::make_ArrayHandle({ -2, -1, 2, 3 });
constexpr int data[nvals] = { -2, -1, 2, 3 };
auto field = vtkm::cont::make_ArrayHandle(data, nvals);
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
const bool ran = table.Map(field, colors); const bool ran = table.Map(field, colors);
@ -249,9 +245,7 @@ public:
"rescaled has incorrect number of control points"); "rescaled has incorrect number of control points");
//Verify that the rescaled color table generates correct colors //Verify that the rescaled color table generates correct colors
constexpr vtkm::Id nvals = 6; auto field = vtkm::cont::make_ArrayHandle({ 0, 10, 20, 30, 40, 50 });
constexpr int data[nvals] = { 0, 10, 20, 30, 40, 50 };
auto field = vtkm::cont::make_ArrayHandle(data, nvals);
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
const bool ran = newTable.Map(field, colors); const bool ran = newTable.Map(field, colors);
@ -284,11 +278,8 @@ public:
VTKM_TEST_ASSERT(table.GetNumberOfPoints() == 4, VTKM_TEST_ASSERT(table.GetNumberOfPoints() == 4,
"adding points caused number of control points to be wrong"); "adding points caused number of control points to be wrong");
constexpr vtkm::Id nvals = 3;
constexpr float data[nvals] = { 10.0f, -5.0f, -15.0f };
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle(data, nvals); auto field = vtkm::cont::make_ArrayHandle({ 10.0f, -5.0f, -15.0f });
const bool ran = table.Map(field, colors); const bool ran = table.Map(field, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute"); VTKM_TEST_ASSERT(ran, "color table failed to execute");
@ -322,11 +313,8 @@ public:
VTKM_TEST_ASSERT(opacityData[3] == 0.0, "rescale modified mid/sharp of opacity"); VTKM_TEST_ASSERT(opacityData[3] == 0.0, "rescale modified mid/sharp of opacity");
constexpr vtkm::Id nvals = 6;
constexpr int data[nvals] = { 0, 10, 20, 30, 40, 50 };
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle(data, nvals); auto field = vtkm::cont::make_ArrayHandle({ 0, 10, 20, 30, 40, 50 });
const bool ran = table.Map(field, colors); const bool ran = table.Map(field, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute"); VTKM_TEST_ASSERT(ran, "color table failed to execute");
@ -366,11 +354,8 @@ public:
"removing points didn't update range"); "removing points didn't update range");
table.RescaleToRange(vtkm::Range{ 0.0, 50.0 }); table.RescaleToRange(vtkm::Range{ 0.0, 50.0 });
constexpr vtkm::Id nvals = 6;
constexpr float data[nvals] = { 0.0f, 10.0f, 20.0f, 30.0f, 40.0f, 50.0f };
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle(data, nvals); auto field = vtkm::cont::make_ArrayHandle({ 0.0f, 10.0f, 20.0f, 30.0f, 40.0f, 50.0f });
const bool ran = table.Map(field, colors); const bool ran = table.Map(field, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute"); VTKM_TEST_ASSERT(ran, "color table failed to execute");
@ -424,11 +409,8 @@ public:
"removing points didn't update range"); "removing points didn't update range");
table.RescaleToRange(vtkm::Range{ 0.0, 50.0 }); table.RescaleToRange(vtkm::Range{ 0.0, 50.0 });
constexpr vtkm::Id nvals = 6;
constexpr float data[nvals] = { 0.0f, 10.0f, 20.0f, 30.0f, 40.0f, 50.0f };
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle(data, nvals); auto field = vtkm::cont::make_ArrayHandle({ 0.0f, 10.0f, 20.0f, 30.0f, 40.0f, 50.0f });
const bool ran = table.Map(field, colors); const bool ran = table.Map(field, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute"); VTKM_TEST_ASSERT(ran, "color table failed to execute");
@ -454,9 +436,7 @@ public:
VTKM_TEST_ASSERT((table.GetNumberOfPoints() == 21), VTKM_TEST_ASSERT((table.GetNumberOfPoints() == 21),
"loading linear green table failed with number of control points"); "loading linear green table failed with number of control points");
constexpr vtkm::Id nvals = 3; auto samples = vtkm::cont::make_ArrayHandle({ 0.0, 0.5, 1.0 });
constexpr double data[3] = { 0.0, 0.5, 1.0 };
auto samples = vtkm::cont::make_ArrayHandle(data, nvals);
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
{ {
@ -503,11 +483,8 @@ public:
table.Sample(256, samples); table.Sample(256, samples);
VTKM_TEST_ASSERT((samples.Samples.GetNumberOfValues() == 260), "invalid sample length"); VTKM_TEST_ASSERT((samples.Samples.GetNumberOfValues() == 260), "invalid sample length");
constexpr vtkm::Id nvals = 8;
constexpr int data[nvals] = { -1, 0, 10, 20, 30, 40, 50, 60 };
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors; vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle(data, nvals); auto field = vtkm::cont::make_ArrayHandle({ -1, 0, 10, 20, 30, 40, 50, 60 });
const bool ran = table.Map(field, samples, colors); const bool ran = table.Map(field, samples, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute"); VTKM_TEST_ASSERT(ran, "color table failed to execute");

@ -51,8 +51,8 @@ private:
std::random_device rng; std::random_device rng;
std::mt19937 urng(rng()); std::mt19937 urng(rng());
std::shuffle(data, data + nvals, urng); std::shuffle(data, data + nvals, urng);
auto field = auto field = vtkm::cont::make_Field(
vtkm::cont::make_Field("TestField", vtkm::cont::Field::Association::POINTS, data, nvals); "TestField", vtkm::cont::Field::Association::POINTS, data, nvals, vtkm::CopyFlag::Off);
vtkm::Range result; vtkm::Range result;
field.GetRange(&result); field.GetRange(&result);
@ -78,8 +78,8 @@ private:
fieldData[j][i] = data[j]; fieldData[j][i] = data[j];
} }
} }
auto field = auto field = vtkm::cont::make_Field(
vtkm::cont::make_Field("TestField", vtkm::cont::Field::Association::POINTS, fieldData, nvals); "TestField", vtkm::cont::Field::Association::POINTS, fieldData, nvals, vtkm::CopyFlag::Off);
vtkm::Range result[NumberOfComponents]; vtkm::Range result[NumberOfComponents];
field.GetRange(result, CustomTypeList()); field.GetRange(result, CustomTypeList());

@ -971,7 +971,7 @@ private:
testData[i] = static_cast<vtkm::Id>(OFFSET + (i % 50)); testData[i] = static_cast<vtkm::Id>(OFFSET + (i % 50));
} }
IdArrayHandle input = vtkm::cont::make_ArrayHandle(&(*testData.begin()), ARRAY_SIZE); IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData, vtkm::CopyFlag::Off);
//make a deep copy of input and place it into temp //make a deep copy of input and place it into temp
IdArrayHandle temp; IdArrayHandle temp;
@ -1017,7 +1017,7 @@ private:
randomData[5] = 955; // 3 (lower), 4 (upper) randomData[5] = 955; // 3 (lower), 4 (upper)
//change the control structure under the handle //change the control structure under the handle
input = vtkm::cont::make_ArrayHandle(randomData, RANDOMDATA_SIZE); input = vtkm::cont::make_ArrayHandle(randomData, RANDOMDATA_SIZE, vtkm::CopyFlag::Off);
FloatCastHandle tempCast(temp); FloatCastHandle tempCast(temp);
Algorithm::Copy(input, tempCast); Algorithm::Copy(input, tempCast);
@ -1064,7 +1064,7 @@ private:
testData[i] = static_cast<vtkm::Id>(OFFSET + ((ARRAY_SIZE - i) % 50)); testData[i] = static_cast<vtkm::Id>(OFFSET + ((ARRAY_SIZE - i) % 50));
} }
IdArrayHandle unsorted = vtkm::cont::make_ArrayHandle(testData); IdArrayHandle unsorted = vtkm::cont::make_ArrayHandle(testData, vtkm::CopyFlag::Off);
IdArrayHandle sorted; IdArrayHandle sorted;
Algorithm::Copy(unsorted, sorted); Algorithm::Copy(unsorted, sorted);
@ -1095,7 +1095,7 @@ private:
} }
//sort the users memory in-place //sort the users memory in-place
IdArrayHandle sorted = vtkm::cont::make_ArrayHandle(testData); IdArrayHandle sorted = vtkm::cont::make_ArrayHandle(testData, vtkm::CopyFlag::Off);
Algorithm::Sort(sorted); Algorithm::Sort(sorted);
//copy the sorted array into our own memory, if use the same user ptr //copy the sorted array into our own memory, if use the same user ptr
@ -1136,7 +1136,7 @@ private:
testData[i] = static_cast<vtkm::Id>(OFFSET + ((ARRAY_SIZE - i) % 50)); testData[i] = static_cast<vtkm::Id>(OFFSET + ((ARRAY_SIZE - i) % 50));
} }
IdArrayHandle unsorted = vtkm::cont::make_ArrayHandle(testData); IdArrayHandle unsorted = vtkm::cont::make_ArrayHandle(testData, vtkm::CopyFlag::Off);
IdArrayHandle sorted; IdArrayHandle sorted;
Algorithm::Copy(unsorted, sorted); Algorithm::Copy(unsorted, sorted);
@ -1202,8 +1202,8 @@ private:
testValues[index] = TestValue(i, Vec3()); testValues[index] = TestValue(i, Vec3());
} }
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(testKeys); IdArrayHandle keys = vtkm::cont::make_ArrayHandle(testKeys, vtkm::CopyFlag::Off);
Vec3ArrayHandle values = vtkm::cont::make_ArrayHandle(testValues); Vec3ArrayHandle values = vtkm::cont::make_ArrayHandle(testValues, vtkm::CopyFlag::Off);
Algorithm::SortByKey(keys, values); Algorithm::SortByKey(keys, values);
@ -1261,7 +1261,7 @@ private:
{ {
testData[i] = static_cast<vtkm::Id>(OFFSET + (i % 50)); testData[i] = static_cast<vtkm::Id>(OFFSET + (i % 50));
} }
IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData); IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData, vtkm::CopyFlag::Off);
//make a deep copy of input and place it into temp //make a deep copy of input and place it into temp
IdArrayHandle temp; IdArrayHandle temp;
@ -1297,7 +1297,7 @@ private:
{ {
testData[i] = static_cast<vtkm::Id>(OFFSET + (i % 50)); testData[i] = static_cast<vtkm::Id>(OFFSET + (i % 50));
} }
IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData); IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData, vtkm::CopyFlag::Off);
//make a deep copy of input and place it into temp //make a deep copy of input and place it into temp
IdArrayHandle temp; IdArrayHandle temp;
@ -1408,7 +1408,7 @@ private:
} }
testData[ARRAY_SIZE / 2] = maxValue; testData[ARRAY_SIZE / 2] = maxValue;
IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData); IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData, vtkm::CopyFlag::Off);
vtkm::Id2 range = Algorithm::Reduce(input, vtkm::Id2(0, 0), vtkm::MinAndMax<vtkm::Id>()); vtkm::Id2 range = Algorithm::Reduce(input, vtkm::Id2(0, 0), vtkm::MinAndMax<vtkm::Id>());
VTKM_TEST_ASSERT(maxValue == range[1], "Got bad value from Reduce with comparison object"); VTKM_TEST_ASSERT(maxValue == range[1], "Got bad value from Reduce with comparison object");
@ -1430,27 +1430,24 @@ private:
std::cout << " Reduce bool array with vtkm::LogicalAnd to see if all values are true." std::cout << " Reduce bool array with vtkm::LogicalAnd to see if all values are true."
<< std::endl; << std::endl;
//construct an array of bools and verify that they aren't all true //construct an array of bools and verify that they aren't all true
constexpr vtkm::Id inputLength = 60; auto barray =
constexpr bool inputValues[inputLength] = { vtkm::cont::make_ArrayHandle({ true, true, true, true, true, true, false, true, true, true,
true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true true, true, true, true, true, true, true, true, true, true,
}; true, true, true, true, true, true, true, true, true, true });
auto barray = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
bool all_true = Algorithm::Reduce(barray, true, vtkm::LogicalAnd()); bool all_true = Algorithm::Reduce(barray, true, vtkm::LogicalAnd());
VTKM_TEST_ASSERT(all_true == false, "reduction with vtkm::LogicalAnd should return false"); VTKM_TEST_ASSERT(all_true == false, "reduction with vtkm::LogicalAnd should return false");
std::cout << " Reduce with custom value type and custom comparison operator." << std::endl; std::cout << " Reduce with custom value type and custom comparison operator." << std::endl;
//test with a custom value type with the reduction value being a vtkm::Vec<float,2> //test with a custom value type with the reduction value being a vtkm::Vec<float,2>
constexpr CustomTForReduce inputFValues[inputLength] = { auto farray = vtkm::cont::make_ArrayHandle<CustomTForReduce>(
13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 413.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, { 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 413.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f,
13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f,
13.1f, -2.1f, -11.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -11.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f,
13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -211.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -211.1f, -1.0f,
13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 113.1f, -2.1f, -1.0f 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 13.1f, -2.1f, -1.0f, 113.1f, -2.1f, -1.0f });
};
auto farray = vtkm::cont::make_ArrayHandle(inputFValues, inputLength);
vtkm::Vec2f_32 frange = vtkm::Vec2f_32 frange =
Algorithm::Reduce(farray, vtkm::Vec2f_32(0.0f, 0.0f), CustomMinAndMax<CustomTForReduce>()); Algorithm::Reduce(farray, vtkm::Vec2f_32(0.0f, 0.0f), CustomMinAndMax<CustomTForReduce>());
VTKM_TEST_ASSERT(-211.1f == frange[0], VTKM_TEST_ASSERT(-211.1f == frange[0],
@ -1494,20 +1491,15 @@ private:
{ {
//lastly test with heterogeneous zip values ( vec3, and constant array handle), //lastly test with heterogeneous zip values ( vec3, and constant array handle),
//and a custom reduce binary functor //and a custom reduce binary functor
const vtkm::Id indexLength = 30;
const vtkm::Id valuesLength = 10;
using ValueType = vtkm::Float32; using ValueType = vtkm::Float32;
vtkm::Id indexs[indexLength] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, IdArrayHandle indexHandle =
5, 5, 5, 1, 4, 9, 7, 7, 7, 8, 8, 8, 0, 1, 2 }; vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4,
ValueType values[valuesLength] = { 5, 5, 5, 1, 4, 9, 7, 7, 7, 8, 8, 8, 0, 1, 2 });
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, -2.0f vtkm::cont::ArrayHandle<ValueType> valueHandle = vtkm::cont::make_ArrayHandle(
}; { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, -2.0f });
const ValueType expectedSum = 125;
IdArrayHandle indexHandle = vtkm::cont::make_ArrayHandle(indexs, indexLength); const ValueType expectedSum = 125;
vtkm::cont::ArrayHandle<ValueType> valueHandle =
vtkm::cont::make_ArrayHandle(values, valuesLength);
vtkm::cont::ArrayHandlePermutation<IdArrayHandle, vtkm::cont::ArrayHandle<ValueType>> perm; vtkm::cont::ArrayHandlePermutation<IdArrayHandle, vtkm::cont::ArrayHandle<ValueType>> perm;
perm = vtkm::cont::make_ArrayHandlePermutation(indexHandle, valueHandle); perm = vtkm::cont::make_ArrayHandlePermutation(indexHandle, valueHandle);
@ -1526,15 +1518,14 @@ private:
//first test with very basic integer key / values //first test with very basic integer key / values
{ {
const vtkm::Id inputLength = 12;
const vtkm::Id expectedLength = 6; const vtkm::Id expectedLength = 6;
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 4, 0, 2, 2, 2, 2, -1 }; // in keys
vtkm::Id inputValues[inputLength] = { 13, -2, -1, 1, 1, 0, 3, 1, 2, 3, 4, -42 }; // in values
vtkm::IdComponent expectedKeys[expectedLength] = { 0, 1, 4, 0, 2, -1 }; vtkm::IdComponent expectedKeys[expectedLength] = { 0, 1, 4, 0, 2, -1 };
vtkm::Id expectedValues[expectedLength] = { 10, 2, 0, 3, 10, -42 }; vtkm::Id expectedValues[expectedLength] = { 10, 2, 0, 3, 10, -42 };
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength); IdComponentArrayHandle keys =
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength); vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 4, 0, 2, 2, 2, 2, -1 });
IdArrayHandle values =
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 13, -2, -1, 1, 1, 0, 3, 1, 2, 3, 4, -42 });
IdComponentArrayHandle keysOut; IdComponentArrayHandle keysOut;
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
@ -1560,22 +1551,19 @@ private:
//next test with a single key across the entire set, using vec3 as the //next test with a single key across the entire set, using vec3 as the
//value, using a custom reduce binary functor //value, using a custom reduce binary functor
{ {
const vtkm::Id inputLength = 3; IdArrayHandle keys = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 0, 0 });
vtkm::cont::ArrayHandle<vtkm::Vec3f_64, StorageTag> values =
vtkm::cont::make_ArrayHandle({ vtkm::Vec3f_64(13.1, 13.3, 13.5),
vtkm::Vec3f_64(-2.1, -2.3, -2.5),
vtkm::Vec3f_64(-1.0, -1.0, 1.0) });
const vtkm::Id expectedLength = 1; const vtkm::Id expectedLength = 1;
vtkm::Id inputKeys[inputLength] = { 0, 0, 0 }; // input keys
vtkm::Vec3f_64 inputValues[inputLength];
inputValues[0] = vtkm::make_Vec(13.1, 13.3, 13.5);
inputValues[1] = vtkm::make_Vec(-2.1, -2.3, -2.5);
inputValues[2] = vtkm::make_Vec(-1.0, -1.0, 1.0); // input keys
vtkm::Id expectedKeys[expectedLength] = { 0 }; vtkm::Id expectedKeys[expectedLength] = { 0 };
vtkm::Vec3f_64 expectedValues[expectedLength]; vtkm::Vec3f_64 expectedValues[expectedLength];
expectedValues[0] = vtkm::make_Vec(27.51, 30.59, -33.75); expectedValues[0] = vtkm::make_Vec(27.51, 30.59, -33.75);
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
vtkm::cont::ArrayHandle<vtkm::Vec3f_64, StorageTag> values =
vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle keysOut; IdArrayHandle keysOut;
vtkm::cont::ArrayHandle<vtkm::Vec3f_64, StorageTag> valuesOut; vtkm::cont::ArrayHandle<vtkm::Vec3f_64, StorageTag> valuesOut;
Algorithm::ReduceByKey(keys, values, keysOut, valuesOut, vtkm::Multiply()); Algorithm::ReduceByKey(keys, values, keysOut, valuesOut, vtkm::Multiply());
@ -1603,17 +1591,16 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Reduce By Key with Fancy Arrays" << std::endl; std::cout << "Testing Reduce By Key with Fancy Arrays" << std::endl;
const vtkm::Id inputLength = 12; IdComponentArrayHandle keys =
vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 4, 0, 2, 2, 2, 2, -1 });
IdArrayHandle values =
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 13, -2, -1, 1, 1, 0, 3, 1, 2, 3, 4, -42 });
FloatCastHandle castValues(values);
const vtkm::Id expectedLength = 6; const vtkm::Id expectedLength = 6;
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 4, 0, 2, 2, 2, 2, -1 }; // in keys
vtkm::Id inputValues[inputLength] = { 13, -2, -1, 1, 1, 0, 3, 1, 2, 3, 4, -42 }; // in values
vtkm::IdComponent expectedKeys[expectedLength] = { 0, 1, 4, 0, 2, -1 }; vtkm::IdComponent expectedKeys[expectedLength] = { 0, 1, 4, 0, 2, -1 };
vtkm::Id expectedValues[expectedLength] = { 10, 2, 0, 3, 10, -42 }; vtkm::Id expectedValues[expectedLength] = { 10, 2, 0, 3, 10, -42 };
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
FloatCastHandle castValues(values);
IdComponentArrayHandle keysOut; IdComponentArrayHandle keysOut;
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
FloatCastHandle castValuesOut(valuesOut); FloatCastHandle castValuesOut(valuesOut);
@ -1640,21 +1627,14 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key with 1 elements" << std::endl; std::cout << "Testing Scan Inclusive By Key with 1 elements" << std::endl;
const vtkm::Id inputLength = 1; IdArrayHandle keys = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0 });
vtkm::Id inputKeys[inputLength] = { 0 }; IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 5 });
vtkm::Id inputValues[inputLength] = { 5 };
const vtkm::Id expectedLength = 1;
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
Algorithm::ScanInclusiveByKey(keys, values, valuesOut, vtkm::Add()); Algorithm::ScanInclusiveByKey(keys, values, valuesOut, vtkm::Add());
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength, VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == 1, "Got wrong number of output values");
"Got wrong number of output values");
const vtkm::Id v = valuesOut.ReadPortal().Get(0); const vtkm::Id v = valuesOut.ReadPortal().Get(0);
VTKM_TEST_ASSERT(5 == v, "Incorrect scanned value"); VTKM_TEST_ASSERT(5 == v, "Incorrect scanned value");
} }
@ -1664,16 +1644,12 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key with 2 elements" << std::endl; std::cout << "Testing Scan Exclusive By Key with 2 elements" << std::endl;
const vtkm::Id inputLength = 2; IdArrayHandle keys = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 1 });
vtkm::Id inputKeys[inputLength] = { 0, 1 }; IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1 });
vtkm::Id inputValues[inputLength] = { 1, 1 };
const vtkm::Id expectedLength = 2; const vtkm::Id expectedLength = 2;
vtkm::Id expectedValues[expectedLength] = { 1, 1 }; vtkm::Id expectedValues[expectedLength] = { 1, 1 };
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
Algorithm::ScanInclusiveByKey(keys, values, valuesOut, vtkm::Add()); Algorithm::ScanInclusiveByKey(keys, values, valuesOut, vtkm::Add());
@ -1692,8 +1668,7 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key with " << ARRAY_SIZE << " elements" << std::endl; std::cout << "Testing Scan Inclusive By Key with " << ARRAY_SIZE << " elements" << std::endl;
const vtkm::Id inputLength = ARRAY_SIZE; std::vector<vtkm::Id> inputKeys(ARRAY_SIZE);
std::vector<vtkm::Id> inputKeys(inputLength);
for (vtkm::Id i = 0; i < ARRAY_SIZE; i++) for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
{ {
@ -1702,10 +1677,9 @@ private:
else else
inputKeys[static_cast<std::size_t>(i)] = static_cast<vtkm::Id>(i); inputKeys[static_cast<std::size_t>(i)] = static_cast<vtkm::Id>(i);
} }
std::vector<vtkm::Id> inputValues(inputLength, 1); std::vector<vtkm::Id> inputValues(ARRAY_SIZE, 1);
const vtkm::Id expectedLength = ARRAY_SIZE; std::vector<vtkm::Id> expectedValues(ARRAY_SIZE);
std::vector<vtkm::Id> expectedValues(expectedLength);
for (std::size_t i = 0; i < ARRAY_SIZE; i++) for (std::size_t i = 0; i < ARRAY_SIZE; i++)
{ {
if (i % 100 < 98) if (i % 100 < 98)
@ -1714,17 +1688,17 @@ private:
expectedValues[i] = static_cast<vtkm::Id>(1); expectedValues[i] = static_cast<vtkm::Id>(1);
} }
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys); IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, vtkm::CopyFlag::Off);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues); IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, vtkm::CopyFlag::Off);
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
Algorithm::ScanInclusiveByKey(keys, values, valuesOut, vtkm::Add()); Algorithm::ScanInclusiveByKey(keys, values, valuesOut, vtkm::Add());
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength, VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == ARRAY_SIZE,
"Got wrong number of output values"); "Got wrong number of output values");
auto values_portal = valuesOut.ReadPortal(); auto values_portal = valuesOut.ReadPortal();
for (auto i = 0; i < expectedLength; i++) for (auto i = 0; i < ARRAY_SIZE; i++)
{ {
const vtkm::Id v = values_portal.Get(i); const vtkm::Id v = values_portal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value"); VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
@ -1735,16 +1709,13 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Inclusive By Key" << std::endl; std::cout << "Testing Scan Inclusive By Key" << std::endl;
const vtkm::Id inputLength = 10; IdComponentArrayHandle keys =
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 }; vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
vtkm::Id inputValues[inputLength] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
const vtkm::Id expectedLength = 10; const vtkm::Id expectedLength = 10;
vtkm::Id expectedValues[expectedLength] = { 1, 2, 3, 1, 2, 1, 1, 2, 3, 4 }; vtkm::Id expectedValues[expectedLength] = { 1, 2, 3, 1, 2, 1, 1, 2, 3, 4 };
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
Algorithm::ScanInclusiveByKey(keys, values, valuesOut); Algorithm::ScanInclusiveByKey(keys, values, valuesOut);
@ -1763,16 +1734,13 @@ private:
std::cout << "Testing Scan Inclusive By Key In Place" << std::endl; std::cout << "Testing Scan Inclusive By Key In Place" << std::endl;
const vtkm::Id inputLength = 10; IdComponentArrayHandle keys =
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 }; vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
vtkm::Id inputValues[inputLength] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
const vtkm::Id expectedLength = 10; const vtkm::Id expectedLength = 10;
vtkm::Id expectedValues[expectedLength] = { 1, 2, 3, 1, 2, 1, 1, 2, 3, 4 }; vtkm::Id expectedValues[expectedLength] = { 1, 2, 3, 1, 2, 1, 1, 2, 3, 4 };
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
Algorithm::ScanInclusiveByKey(keys, values, values); Algorithm::ScanInclusiveByKey(keys, values, values);
VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength, VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength,
"Got wrong number of output values"); "Got wrong number of output values");
@ -1789,17 +1757,14 @@ private:
std::cout << "Testing Scan Inclusive By Key In Place with a Fancy Array" << std::endl; std::cout << "Testing Scan Inclusive By Key In Place with a Fancy Array" << std::endl;
const vtkm::Id inputLength = 10; IdComponentArrayHandle keys =
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 }; vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
vtkm::Id inputValues[inputLength] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
FloatCastHandle castValues(values);
const vtkm::Id expectedLength = 10; const vtkm::Id expectedLength = 10;
vtkm::Id expectedValues[expectedLength] = { 1, 2, 3, 1, 2, 1, 1, 2, 3, 4 }; vtkm::Id expectedValues[expectedLength] = { 1, 2, 3, 1, 2, 1, 1, 2, 3, 4 };
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
FloatCastHandle castValues(values);
Algorithm::ScanInclusiveByKey(keys, castValues, castValues); Algorithm::ScanInclusiveByKey(keys, castValues, castValues);
VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength, VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength,
"Got wrong number of output values"); "Got wrong number of output values");
@ -1816,15 +1781,12 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key with 1 elements" << std::endl; std::cout << "Testing Scan Exclusive By Key with 1 elements" << std::endl;
const vtkm::Id inputLength = 1;
vtkm::Id inputKeys[inputLength] = { 0 };
vtkm::Id inputValues[inputLength] = { 0 };
vtkm::Id init = 5; vtkm::Id init = 5;
const vtkm::Id expectedLength = 1; const vtkm::Id expectedLength = 1;
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength); IdArrayHandle keys = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength); IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0 });
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
@ -1841,17 +1803,14 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key with 2 elements" << std::endl; std::cout << "Testing Scan Exclusive By Key with 2 elements" << std::endl;
const vtkm::Id inputLength = 2;
vtkm::Id inputKeys[inputLength] = { 0, 1 };
vtkm::Id inputValues[inputLength] = { 1, 1 };
vtkm::Id init = 5; vtkm::Id init = 5;
IdArrayHandle keys = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 1 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1 });
const vtkm::Id expectedLength = 2; const vtkm::Id expectedLength = 2;
vtkm::Id expectedValues[expectedLength] = { 5, 5 }; vtkm::Id expectedValues[expectedLength] = { 5, 5 };
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
Algorithm::ScanExclusiveByKey(keys, values, valuesOut, init, vtkm::Add()); Algorithm::ScanExclusiveByKey(keys, values, valuesOut, init, vtkm::Add());
@ -1871,8 +1830,7 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key with " << ARRAY_SIZE << " elements" << std::endl; std::cout << "Testing Scan Exclusive By Key with " << ARRAY_SIZE << " elements" << std::endl;
const vtkm::Id inputLength = ARRAY_SIZE; std::vector<vtkm::Id> inputKeys(ARRAY_SIZE);
std::vector<vtkm::Id> inputKeys(inputLength);
for (std::size_t i = 0; i < ARRAY_SIZE; i++) for (std::size_t i = 0; i < ARRAY_SIZE; i++)
{ {
if (i % 100 < 98) if (i % 100 < 98)
@ -1880,11 +1838,10 @@ private:
else else
inputKeys[i] = static_cast<vtkm::Id>(i); inputKeys[i] = static_cast<vtkm::Id>(i);
} }
std::vector<vtkm::Id> inputValues(inputLength, 1); std::vector<vtkm::Id> inputValues(ARRAY_SIZE, 1);
vtkm::Id init = 5; vtkm::Id init = 5;
const vtkm::Id expectedLength = ARRAY_SIZE; std::vector<vtkm::Id> expectedValues(ARRAY_SIZE);
std::vector<vtkm::Id> expectedValues(expectedLength);
for (vtkm::Id i = 0; i < ARRAY_SIZE; i++) for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
{ {
if (i % 100 < 98) if (i % 100 < 98)
@ -1893,17 +1850,17 @@ private:
expectedValues[static_cast<std::size_t>(i)] = init; expectedValues[static_cast<std::size_t>(i)] = init;
} }
IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys); IdArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, vtkm::CopyFlag::Off);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues); IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, vtkm::CopyFlag::Off);
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
Algorithm::ScanExclusiveByKey(keys, values, valuesOut, init, vtkm::Add()); Algorithm::ScanExclusiveByKey(keys, values, valuesOut, init, vtkm::Add());
VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == expectedLength, VTKM_TEST_ASSERT(valuesOut.GetNumberOfValues() == ARRAY_SIZE,
"Got wrong number of output values"); "Got wrong number of output values");
auto valuesPortal = valuesOut.ReadPortal(); auto valuesPortal = valuesOut.ReadPortal();
for (vtkm::Id i = 0; i < expectedLength; i++) for (vtkm::Id i = 0; i < ARRAY_SIZE; i++)
{ {
const vtkm::Id v = valuesPortal.Get(i); const vtkm::Id v = valuesPortal.Get(i);
VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value"); VTKM_TEST_ASSERT(expectedValues[static_cast<std::size_t>(i)] == v, "Incorrect scanned value");
@ -1915,17 +1872,15 @@ private:
std::cout << "-------------------------------------------" << std::endl; std::cout << "-------------------------------------------" << std::endl;
std::cout << "Testing Scan Exclusive By Key" << std::endl; std::cout << "Testing Scan Exclusive By Key" << std::endl;
const vtkm::Id inputLength = 10;
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 };
vtkm::Id inputValues[inputLength] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
vtkm::Id init = 5; vtkm::Id init = 5;
IdComponentArrayHandle keys =
vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
const vtkm::Id expectedLength = 10; const vtkm::Id expectedLength = 10;
vtkm::Id expectedValues[expectedLength] = { 5, 6, 7, 5, 6, 5, 5, 6, 7, 8 }; vtkm::Id expectedValues[expectedLength] = { 5, 6, 7, 5, 6, 5, 5, 6, 7, 8 };
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
IdArrayHandle valuesOut; IdArrayHandle valuesOut;
Algorithm::ScanExclusiveByKey(keys, values, valuesOut, init, vtkm::Add()); Algorithm::ScanExclusiveByKey(keys, values, valuesOut, init, vtkm::Add());
@ -1945,17 +1900,15 @@ private:
std::cout << "Testing Scan Inclusive By Key In Place" << std::endl; std::cout << "Testing Scan Inclusive By Key In Place" << std::endl;
const vtkm::Id inputLength = 10;
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 };
vtkm::Id inputValues[inputLength] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
vtkm::Id init = 5; vtkm::Id init = 5;
IdComponentArrayHandle keys =
vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
const vtkm::Id expectedLength = 10; const vtkm::Id expectedLength = 10;
vtkm::Id expectedValues[expectedLength] = { 5, 6, 7, 5, 6, 5, 5, 6, 7, 8 }; vtkm::Id expectedValues[expectedLength] = { 5, 6, 7, 5, 6, 5, 5, 6, 7, 8 };
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
Algorithm::ScanExclusiveByKey(keys, values, values, init, vtkm::Add()); Algorithm::ScanExclusiveByKey(keys, values, values, init, vtkm::Add());
VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength, VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength,
"Got wrong number of output values"); "Got wrong number of output values");
@ -1972,18 +1925,16 @@ private:
std::cout << "Testing Scan Inclusive By Key In Place with a Fancy Array" << std::endl; std::cout << "Testing Scan Inclusive By Key In Place with a Fancy Array" << std::endl;
const vtkm::Id inputLength = 10;
vtkm::IdComponent inputKeys[inputLength] = { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 };
vtkm::Id inputValues[inputLength] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
vtkm::FloatDefault init = 5; vtkm::FloatDefault init = 5;
IdComponentArrayHandle keys =
vtkm::cont::make_ArrayHandle<vtkm::IdComponent>({ 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
IdArrayHandle values = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
FloatCastHandle castValues(values);
const vtkm::Id expectedLength = 10; const vtkm::Id expectedLength = 10;
vtkm::Id expectedValues[expectedLength] = { 5, 6, 7, 5, 6, 5, 5, 6, 7, 8 }; vtkm::Id expectedValues[expectedLength] = { 5, 6, 7, 5, 6, 5, 5, 6, 7, 8 };
IdComponentArrayHandle keys = vtkm::cont::make_ArrayHandle(inputKeys, inputLength);
IdArrayHandle values = vtkm::cont::make_ArrayHandle(inputValues, inputLength);
FloatCastHandle castValues(values);
Algorithm::ScanExclusiveByKey(keys, castValues, castValues, init, vtkm::Add()); Algorithm::ScanExclusiveByKey(keys, castValues, castValues, init, vtkm::Add());
VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength, VTKM_TEST_ASSERT(values.GetNumberOfValues() == expectedLength,
"Got wrong number of output values"); "Got wrong number of output values");
@ -2049,7 +2000,7 @@ private:
inputValues[mid] = 0.0; inputValues[mid] = 0.0;
vtkm::cont::ArrayHandle<vtkm::Float64> array = vtkm::cont::ArrayHandle<vtkm::Float64> array =
vtkm::cont::make_ArrayHandle(&inputValues[0], ARRAY_SIZE); vtkm::cont::make_ArrayHandle(inputValues, vtkm::CopyFlag::Off);
vtkm::Float64 product = Algorithm::ScanInclusive(array, array, vtkm::Multiply()); vtkm::Float64 product = Algorithm::ScanInclusive(array, array, vtkm::Multiply());
@ -2082,7 +2033,7 @@ private:
{ {
testValues[i] = TestValue(1, Vec3()); testValues[i] = TestValue(1, Vec3());
} }
Vec3ArrayHandle values = vtkm::cont::make_ArrayHandle(testValues); Vec3ArrayHandle values = vtkm::cont::make_ArrayHandle(testValues, vtkm::CopyFlag::Off);
Vec3 sum = Algorithm::ScanInclusive(values, values); Vec3 sum = Algorithm::ScanInclusive(values, values);
std::cout << "Sum that was returned " << sum << std::endl; std::cout << "Sum that was returned " << sum << std::endl;
@ -2194,7 +2145,8 @@ private:
std::size_t mid = ARRAY_SIZE / 2; std::size_t mid = ARRAY_SIZE / 2;
inputValues[mid] = 0.0; inputValues[mid] = 0.0;
vtkm::cont::ArrayHandle<vtkm::Float64> array = vtkm::cont::make_ArrayHandle(inputValues); vtkm::cont::ArrayHandle<vtkm::Float64> array =
vtkm::cont::make_ArrayHandle(inputValues, vtkm::CopyFlag::Off);
vtkm::Float64 initialValue = 2.00; vtkm::Float64 initialValue = 2.00;
vtkm::Float64 product = vtkm::Float64 product =
@ -2231,7 +2183,7 @@ private:
{ {
testValues[i] = TestValue(1, Vec3()); testValues[i] = TestValue(1, Vec3());
} }
Vec3ArrayHandle values = vtkm::cont::make_ArrayHandle(testValues); Vec3ArrayHandle values = vtkm::cont::make_ArrayHandle(testValues, vtkm::CopyFlag::Off);
Vec3 sum = Algorithm::ScanExclusive(values, values); Vec3 sum = Algorithm::ScanExclusive(values, values);
std::cout << "Sum that was returned " << sum << std::endl; std::cout << "Sum that was returned " << sum << std::endl;
@ -2470,7 +2422,7 @@ private:
testData[i] = TestCopy<T>::get(index); testData[i] = TestCopy<T>::get(index);
} }
vtkm::cont::ArrayHandle<T> input = vtkm::cont::make_ArrayHandle(&testData[0], COPY_ARRAY_SIZE); vtkm::cont::ArrayHandle<T> input = vtkm::cont::make_ArrayHandle(testData, vtkm::CopyFlag::Off);
//make a deep copy of input and place it into temp //make a deep copy of input and place it into temp
{ {
@ -2680,7 +2632,7 @@ private:
testData[i] = static_cast<vtkm::Id>(OFFSET + (i % 50)); testData[i] = static_cast<vtkm::Id>(OFFSET + (i % 50));
} }
IdArrayHandle input = vtkm::cont::make_ArrayHandle(testData); IdArrayHandle input = vtkm::cont::make_ArrayHandle<vtkm::Id>(testData, vtkm::CopyFlag::Off);
//make a deep copy of input and place it into temp //make a deep copy of input and place it into temp
vtkm::cont::ArrayHandle<vtkm::Float64> temp; vtkm::cont::ArrayHandle<vtkm::Float64> temp;
@ -2710,10 +2662,8 @@ private:
// a single atomic value. // a single atomic value.
std::cout << "Testing Atomic Add with vtkm::Int32" << std::endl; std::cout << "Testing Atomic Add with vtkm::Int32" << std::endl;
{ {
std::vector<vtkm::Int32> singleElement;
singleElement.push_back(0);
vtkm::cont::ArrayHandle<vtkm::Int32> atomicElement = vtkm::cont::ArrayHandle<vtkm::Int32> atomicElement =
vtkm::cont::make_ArrayHandle(singleElement); vtkm::cont::make_ArrayHandle<vtkm::Int32>({ 0 });
vtkm::cont::AtomicArray<vtkm::Int32> atomic(atomicElement); vtkm::cont::AtomicArray<vtkm::Int32> atomic(atomicElement);
{ {
@ -2727,10 +2677,8 @@ private:
std::cout << "Testing Atomic Add with vtkm::Int64" << std::endl; std::cout << "Testing Atomic Add with vtkm::Int64" << std::endl;
{ {
std::vector<vtkm::Int64> singleElement;
singleElement.push_back(0);
vtkm::cont::ArrayHandle<vtkm::Int64> atomicElement = vtkm::cont::ArrayHandle<vtkm::Int64> atomicElement =
vtkm::cont::make_ArrayHandle(singleElement); vtkm::cont::make_ArrayHandle<vtkm::Int64>({ 0 });
vtkm::cont::AtomicArray<vtkm::Int64> atomic(atomicElement); vtkm::cont::AtomicArray<vtkm::Int64> atomic(atomicElement);
{ {
@ -2744,10 +2692,8 @@ private:
std::cout << "Testing Atomic CAS with vtkm::Int32" << std::endl; std::cout << "Testing Atomic CAS with vtkm::Int32" << std::endl;
{ {
std::vector<vtkm::Int32> singleElement;
singleElement.push_back(0);
vtkm::cont::ArrayHandle<vtkm::Int32> atomicElement = vtkm::cont::ArrayHandle<vtkm::Int32> atomicElement =
vtkm::cont::make_ArrayHandle(singleElement); vtkm::cont::make_ArrayHandle<vtkm::Int32>({ 0 });
vtkm::cont::AtomicArray<vtkm::Int32> atomic(atomicElement); vtkm::cont::AtomicArray<vtkm::Int32> atomic(atomicElement);
{ {
@ -2761,10 +2707,8 @@ private:
std::cout << "Testing Atomic CAS with vtkm::Int64" << std::endl; std::cout << "Testing Atomic CAS with vtkm::Int64" << std::endl;
{ {
std::vector<vtkm::Int64> singleElement;
singleElement.push_back(0);
vtkm::cont::ArrayHandle<vtkm::Int64> atomicElement = vtkm::cont::ArrayHandle<vtkm::Int64> atomicElement =
vtkm::cont::make_ArrayHandle(singleElement); vtkm::cont::make_ArrayHandle<vtkm::Int64>({ 0 });
vtkm::cont::AtomicArray<vtkm::Int64> atomic(atomicElement); vtkm::cont::AtomicArray<vtkm::Int64> atomic(atomicElement);
{ {

@ -359,12 +359,6 @@ private:
vector2.push_back(value[2]); vector2.push_back(value[2]);
} }
{
vtkm::cont::ArrayHandleSOA<Vec3> soaArray = { vector0, vector1, vector2 };
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
CheckPortal(soaArray.ReadPortal());
}
{ {
vtkm::cont::ArrayHandleSOA<Vec3> soaArray = vtkm::cont::ArrayHandleSOA<Vec3> soaArray =
vtkm::cont::make_ArrayHandleSOA<Vec3>({ vector0, vector1, vector2 }); vtkm::cont::make_ArrayHandleSOA<Vec3>({ vector0, vector1, vector2 });
@ -374,21 +368,21 @@ private:
{ {
vtkm::cont::ArrayHandleSOA<Vec3> soaArray = vtkm::cont::ArrayHandleSOA<Vec3> soaArray =
vtkm::cont::make_ArrayHandleSOA(vector0, vector1, vector2); vtkm::cont::make_ArrayHandleSOA(vtkm::CopyFlag::Off, vector0, vector1, vector2);
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE); VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
CheckPortal(soaArray.ReadPortal()); CheckPortal(soaArray.ReadPortal());
} }
{ {
vtkm::cont::ArrayHandleSOA<Vec3> soaArray = vtkm::cont::make_ArrayHandleSOA<Vec3>( vtkm::cont::ArrayHandleSOA<Vec3> soaArray = vtkm::cont::make_ArrayHandleSOA<Vec3>(
{ &vector0.front(), &vector1.front(), &vector2.front() }, ARRAY_SIZE); { vector0.data(), vector1.data(), vector2.data() }, ARRAY_SIZE, vtkm::CopyFlag::Off);
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE); VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
CheckPortal(soaArray.ReadPortal()); CheckPortal(soaArray.ReadPortal());
} }
{ {
vtkm::cont::ArrayHandleSOA<Vec3> soaArray = vtkm::cont::make_ArrayHandleSOA( vtkm::cont::ArrayHandleSOA<Vec3> soaArray = vtkm::cont::make_ArrayHandleSOA(
ARRAY_SIZE, &vector0.front(), &vector1.front(), &vector2.front()); ARRAY_SIZE, vtkm::CopyFlag::Off, vector0.data(), vector1.data(), vector2.data());
VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE); VTKM_TEST_ASSERT(soaArray.GetNumberOfValues() == ARRAY_SIZE);
CheckPortal(soaArray.ReadPortal()); CheckPortal(soaArray.ReadPortal());
} }
@ -436,7 +430,7 @@ private:
const ValueType value = TestValue(13, ValueType()); const ValueType value = TestValue(13, ValueType());
std::vector<ValueType> compositeData(ARRAY_SIZE, value); std::vector<ValueType> compositeData(ARRAY_SIZE, value);
vtkm::cont::ArrayHandle<ValueType> compositeInput = vtkm::cont::ArrayHandle<ValueType> compositeInput =
vtkm::cont::make_ArrayHandle(compositeData); vtkm::cont::make_ArrayHandle(compositeData, vtkm::CopyFlag::Off);
auto composite = auto composite =
vtkm::cont::make_ArrayHandleCompositeVector(compositeInput, compositeInput, compositeInput); vtkm::cont::make_ArrayHandleCompositeVector(compositeInput, compositeInput, compositeInput);
@ -597,7 +591,7 @@ private:
basicVec.push_back(ValueType(static_cast<ComponentType>(i))); basicVec.push_back(ValueType(static_cast<ComponentType>(i)));
basicVec.push_back(ValueType(ComponentType(i))); basicVec.push_back(ValueType(ComponentType(i)));
} }
BasicArrayType basic = vtkm::cont::make_ArrayHandle(basicVec); BasicArrayType basic = vtkm::cont::make_ArrayHandle(basicVec, vtkm::CopyFlag::Off);
// concatenate two arrays together // concatenate two arrays together
ConcatenateType concatenate = vtkm::cont::make_ArrayHandleConcatenate(implicit, basic); ConcatenateType concatenate = vtkm::cont::make_ArrayHandleConcatenate(implicit, basic);
@ -986,14 +980,9 @@ private:
{ {
using ValueType = vtkm::Vec<ComponentType, NUM_COMPONENTS>; using ValueType = vtkm::Vec<ComponentType, NUM_COMPONENTS>;
ComponentType testValues[ARRAY_SIZE * NUM_COMPONENTS]; vtkm::cont::ArrayHandle<ComponentType> baseArray;
baseArray.Allocate(ARRAY_SIZE * NUM_COMPONENTS);
for (vtkm::Id index = 0; index < ARRAY_SIZE * NUM_COMPONENTS; ++index) SetPortal(baseArray.WritePortal());
{
testValues[index] = TestValue(index, ComponentType());
}
vtkm::cont::ArrayHandle<ComponentType> baseArray =
vtkm::cont::make_ArrayHandle(testValues, ARRAY_SIZE * NUM_COMPONENTS);
vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<ComponentType>, NUM_COMPONENTS> vtkm::cont::ArrayHandleGroupVec<vtkm::cont::ArrayHandle<ComponentType>, NUM_COMPONENTS>
groupArray(baseArray); groupArray(baseArray);
@ -1210,9 +1199,10 @@ private:
testKeys[i] = KeyType(static_cast<KeyComponentType>(ARRAY_SIZE - i)); testKeys[i] = KeyType(static_cast<KeyComponentType>(ARRAY_SIZE - i));
testValues[i] = ValueType(static_cast<ValueComponentType>(i)); testValues[i] = ValueType(static_cast<ValueComponentType>(i));
} }
vtkm::cont::ArrayHandle<KeyType> keys = vtkm::cont::make_ArrayHandle(testKeys, ARRAY_SIZE); vtkm::cont::ArrayHandle<KeyType> keys =
vtkm::cont::make_ArrayHandle(testKeys, ARRAY_SIZE, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandle<ValueType> values = vtkm::cont::ArrayHandle<ValueType> values =
vtkm::cont::make_ArrayHandle(testValues, ARRAY_SIZE); vtkm::cont::make_ArrayHandle(testValues, ARRAY_SIZE, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandleZip<vtkm::cont::ArrayHandle<KeyType>, vtkm::cont::ArrayHandleZip<vtkm::cont::ArrayHandle<KeyType>,
vtkm::cont::ArrayHandle<ValueType>> vtkm::cont::ArrayHandle<ValueType>>
@ -1425,7 +1415,7 @@ private:
ValueType(static_cast<ValueComponentType>(i))); ValueType(static_cast<ValueComponentType>(i)));
} }
vtkm::cont::ArrayHandle<PairType> input = vtkm::cont::ArrayHandle<PairType> input =
vtkm::cont::make_ArrayHandle(testKeysAndValues, ARRAY_SIZE); vtkm::cont::make_ArrayHandle(testKeysAndValues, ARRAY_SIZE, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandle<KeyType> result_keys; vtkm::cont::ArrayHandle<KeyType> result_keys;
vtkm::cont::ArrayHandle<ValueType> result_values; vtkm::cont::ArrayHandle<ValueType> result_values;

@ -69,7 +69,7 @@ void EvaluateOnCoordinates(vtkm::cont::CoordinateSystem points,
EvaluateImplicitFunction eval(function.PrepareForExecution(device, token)); EvaluateImplicitFunction eval(function.PrepareForExecution(device, token));
EvalDispatcher dispatcher(eval); EvalDispatcher dispatcher(eval);
dispatcher.SetDevice(DeviceAdapter()); dispatcher.SetDevice(DeviceAdapter());
dispatcher.Invoke(points, values, gradients); dispatcher.Invoke(points.GetDataAsMultiplexer(), values, gradients);
} }
template <typename ItemType, std::size_t N> template <typename ItemType, std::size_t N>

@ -118,7 +118,7 @@ public:
coordi.push_back(vtkm::make_Vec(00.0f, 10.0f, 10.0f)); coordi.push_back(vtkm::make_Vec(00.0f, 10.0f, 10.0f));
coordi.push_back(vtkm::make_Vec(10.0f, 00.0f, 10.0f)); coordi.push_back(vtkm::make_Vec(10.0f, 00.0f, 10.0f));
coordi.push_back(vtkm::make_Vec(10.0f, 10.0f, 10.0f)); coordi.push_back(vtkm::make_Vec(10.0f, 10.0f, 10.0f));
auto coordi_Handle = vtkm::cont::make_ArrayHandle(coordi); auto coordi_Handle = vtkm::cont::make_ArrayHandle(coordi, vtkm::CopyFlag::Off);
vtkm::cont::CoordinateSystem coord("points", coordi_Handle); vtkm::cont::CoordinateSystem coord("points", coordi_Handle);
@ -145,7 +145,7 @@ public:
qcVec.push_back(vtkm::make_Vec(0.01f, 9.99f, 9.99f)); qcVec.push_back(vtkm::make_Vec(0.01f, 9.99f, 9.99f));
qcVec.push_back(vtkm::make_Vec(9.99f, 0.01f, 9.99f)); qcVec.push_back(vtkm::make_Vec(9.99f, 0.01f, 9.99f));
qcVec.push_back(vtkm::make_Vec(9.99f, 9.99f, 9.99f)); qcVec.push_back(vtkm::make_Vec(9.99f, 9.99f, 9.99f));
auto qc_Handle = vtkm::cont::make_ArrayHandle(qcVec); auto qc_Handle = vtkm::cont::make_ArrayHandle(qcVec, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandle<vtkm::Id> nnId_Handle; vtkm::cont::ArrayHandle<vtkm::Id> nnId_Handle;
vtkm::cont::ArrayHandle<vtkm::FloatDefault> nnDis_Handle; vtkm::cont::ArrayHandle<vtkm::FloatDefault> nnDis_Handle;
@ -163,8 +163,7 @@ public:
vtkm::worklet::DispatcherMapField<NearestNeighborSearchBruteForce3DWorklet> nnsbf3DDispatcher( vtkm::worklet::DispatcherMapField<NearestNeighborSearchBruteForce3DWorklet> nnsbf3DDispatcher(
nnsbf3dWorklet); nnsbf3dWorklet);
nnsbf3DDispatcher.SetDevice(DeviceAdapter()); nnsbf3DDispatcher.SetDevice(DeviceAdapter());
nnsbf3DDispatcher.Invoke( nnsbf3DDispatcher.Invoke(qc_Handle, coordi_Handle, bfnnId_Handle, bfnnDis_Handle);
qc_Handle, vtkm::cont::make_ArrayHandle(coordi), bfnnId_Handle, bfnnDis_Handle);
///// verify search result ///// ///// verify search result /////
bool passTest = true; bool passTest = true;

@ -53,8 +53,7 @@ void TryCopy()
} }
{ // ArrayHandle ids { // ArrayHandle ids
const std::vector<vtkm::Id> idsVec{ 3, 8, 7 }; const auto ids = vtkm::cont::make_ArrayHandle<vtkm::Id>({ 3, 8, 7 });
const auto ids = vtkm::cont::make_ArrayHandle(idsVec);
{ // Return vector: { // Return vector:
const std::vector<ValueType> output = vtkm::cont::ArrayGetValues(ids, data); const std::vector<ValueType> output = vtkm::cont::ArrayGetValues(ids, data);
TestValues<ValueType>(output, { 3, 8, 7 }); TestValues<ValueType>(output, { 3, 8, 7 });

@ -83,9 +83,9 @@ void RunTest()
createArr(Y, nY); createArr(Y, nY);
createArr(Z, nZ); createArr(Z, nZ);
ArrayHandleCPBasic(vtkm::cont::make_ArrayHandle(X), ArrayHandleCPBasic(vtkm::cont::make_ArrayHandle(X, vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(Y), vtkm::cont::make_ArrayHandle(Y, vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(Z)); vtkm::cont::make_ArrayHandle(Z, vtkm::CopyFlag::Off));
} }
} }
} }

@ -52,16 +52,7 @@ vtkm::cont::ArrayHandle<ValueType, StorageTag> MakeInputArray(int arrayId)
} }
// Make an array handle that points to this buffer. // Make an array handle that points to this buffer.
using ArrayHandleType = vtkm::cont::ArrayHandle<ValueType, StorageTag>; return vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE, vtkm::CopyFlag::On);
ArrayHandleType bufferHandle = vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE);
// When this function returns, the array is going to go out of scope, which
// will invalidate the array handle we just created. So copy to a new buffer
// that will stick around after we return.
ArrayHandleType copyHandle;
vtkm::cont::ArrayCopy(bufferHandle, copyHandle);
return copyHandle;
} }
template <typename ValueType, typename C> template <typename ValueType, typename C>

@ -54,7 +54,7 @@ void TestConcatenateEmptyArray()
using ArrayConcat = vtkm::cont::ArrayHandleConcatenate<CoeffArrayTypeTmp, CoeffArrayTypeTmp>; using ArrayConcat = vtkm::cont::ArrayHandleConcatenate<CoeffArrayTypeTmp, CoeffArrayTypeTmp>;
using ArrayConcat2 = vtkm::cont::ArrayHandleConcatenate<ArrayConcat, CoeffArrayTypeTmp>; using ArrayConcat2 = vtkm::cont::ArrayHandleConcatenate<ArrayConcat, CoeffArrayTypeTmp>;
CoeffArrayTypeTmp arr1 = vtkm::cont::make_ArrayHandle(vec); CoeffArrayTypeTmp arr1 = vtkm::cont::make_ArrayHandle(vec, vtkm::CopyFlag::Off);
CoeffArrayTypeTmp arr2, arr3; CoeffArrayTypeTmp arr2, arr3;
ArrayConcat arrConc(arr2, arr1); ArrayConcat arrConc(arr2, arr1);

@ -60,8 +60,8 @@ struct Test
} }
// Prepare array handles: // Prepare array handles:
Handle keys = vtkm::cont::make_ArrayHandle(keyData, ARRAY_SIZE); Handle keys = vtkm::cont::make_ArrayHandle(keyData, ARRAY_SIZE, vtkm::CopyFlag::Off);
Handle values = vtkm::cont::make_ArrayHandle(valueData, ARRAY_SIZE); Handle values = vtkm::cont::make_ArrayHandle(valueData, ARRAY_SIZE, vtkm::CopyFlag::Off);
DiscardHandle output_keys; DiscardHandle output_keys;
Handle output_values; Handle output_values;

@ -96,7 +96,7 @@ int TestArrayHandleExtrude()
const int numPlanes = 8; const int numPlanes = 8;
auto coords = vtkm::cont::make_ArrayHandleExtrudeCoords( auto coords = vtkm::cont::make_ArrayHandleExtrudeCoords(
vtkm::cont::make_ArrayHandle(points_rz), numPlanes, false); vtkm::cont::make_ArrayHandle(points_rz, vtkm::CopyFlag::Off), numPlanes, false);
VTKM_TEST_ASSERT(coords.GetNumberOfValues() == VTKM_TEST_ASSERT(coords.GetNumberOfValues() ==
static_cast<vtkm::Id>(((points_rz.size() / 2) * numPlanes)), static_cast<vtkm::Id>(((points_rz.size() / 2) * numPlanes)),

@ -196,14 +196,7 @@ struct PermutationTests
} }
// Create an ArrayHandle from the buffer // Create an ArrayHandle from the buffer
ValueArrayType array = vtkm::cont::make_ArrayHandle(buffer); return vtkm::cont::make_ArrayHandle(buffer, vtkm::CopyFlag::On);
// Copy the array so that the data is not destroyed when we return from
// this method.
ValueArrayType arrayCopy;
Algorithm::Copy(array, arrayCopy);
return arrayCopy;
} }
void operator()() const void operator()() const

@ -15,26 +15,35 @@ void TestArrayHandleRandomUniformBits()
{ {
auto actual0 = vtkm::cont::ArrayHandleRandomUniformBits(10, { 0 }); auto actual0 = vtkm::cont::ArrayHandleRandomUniformBits(10, { 0 });
// result from Random123 sample implementation of philox2x32x10 // result from Random123 sample implementation of philox2x32x10
std::vector<vtkm::UInt64> expected0{ 0x6cd10df2ff1dae59, 0x5f3adb6bdcdce855, 0x3fbb6394049f6998, auto expected0 = vtkm::cont::make_ArrayHandle<vtkm::UInt64>({ 0x6cd10df2ff1dae59,
0xbd592d1202a74512, 0x8a115b62c08084ef, 0x1411803b3bb7eefa, 0x5f3adb6bdcdce855,
0x7d138a2280027d0e, 0x318a7703a1da82c5, 0xdcd79c6998975579, 0x3fbb6394049f6998,
0x6cb1a07c91f81109 }; 0xbd592d1202a74512,
0x8a115b62c08084ef,
0x1411803b3bb7eefa,
0x7d138a2280027d0e,
0x318a7703a1da82c5,
0xdcd79c6998975579,
0x6cb1a07c91f81109 });
auto result = auto result = vtkm::cont::testing::test_equal_ArrayHandles(actual0, expected0);
vtkm::cont::testing::test_equal_ArrayHandles(actual0, vtkm::cont::make_ArrayHandle(expected0));
VTKM_TEST_ASSERT(result, result.GetMergedMessage()); VTKM_TEST_ASSERT(result, result.GetMergedMessage());
// initialize with seed = 100, could be "iteration number" in actual use case. // initialize with seed = 100, could be "iteration number" in actual use case.
auto actual100 = vtkm::cont::ArrayHandleRandomUniformBits(10, { 100 }); auto actual100 = vtkm::cont::ArrayHandleRandomUniformBits(10, { 100 });
// result from Random123 sample implementation of philox2x32x10 // result from Random123 sample implementation of philox2x32x10
std::vector<vtkm::UInt64> expected100{ auto expected100 = vtkm::cont::make_ArrayHandle<vtkm::UInt64>({ 0xbd35360836122ea3,
0xbd35360836122ea3, 0xe033b74acce7aa5f, 0xc0fbb65cba93ecd7, 0xe3fee2812b77e480, 0xe033b74acce7aa5f,
0x92e5c7d563767971, 0xd99e952fb054fc19, 0xb8f2adc12094ad29, 0xb7dcb35fea8c27ac, 0xc0fbb65cba93ecd7,
0x9c7b779e88270c45, 0x7325b123dc32e01d, 0xe3fee2812b77e480,
}; 0x92e5c7d563767971,
auto result100 = vtkm::cont::testing::test_equal_ArrayHandles( 0xd99e952fb054fc19,
actual100, vtkm::cont::make_ArrayHandle(expected100)); 0xb8f2adc12094ad29,
0xb7dcb35fea8c27ac,
0x9c7b779e88270c45,
0x7325b123dc32e01d });
auto result100 = vtkm::cont::testing::test_equal_ArrayHandles(actual100, expected100);
VTKM_TEST_ASSERT(result, result.GetMergedMessage()); VTKM_TEST_ASSERT(result, result.GetMergedMessage());
} }

@ -44,7 +44,7 @@ void TestArrayHandleReverseRead()
void TestArrayHandleReverseWrite() void TestArrayHandleReverseWrite()
{ {
std::vector<vtkm::Id> ids(ARRAY_SIZE, 0); std::vector<vtkm::Id> ids(ARRAY_SIZE, 0);
vtkm::cont::ArrayHandle<vtkm::Id> handle = vtkm::cont::make_ArrayHandle(ids); vtkm::cont::ArrayHandle<vtkm::Id> handle = vtkm::cont::make_ArrayHandle(ids, vtkm::CopyFlag::Off);
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> reverse = vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> reverse =
vtkm::cont::make_ArrayHandleReverse(handle); vtkm::cont::make_ArrayHandleReverse(handle);
@ -63,10 +63,10 @@ void TestArrayHandleReverseWrite()
void TestArrayHandleReverseScanInclusiveByKey() void TestArrayHandleReverseScanInclusiveByKey()
{ {
vtkm::Id ids[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; vtkm::cont::ArrayHandle<vtkm::Id> values =
vtkm::Id seg[] = { 0, 0, 0, 0, 1, 1, 2, 3, 3, 4 }; vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
vtkm::cont::ArrayHandle<vtkm::Id> values = vtkm::cont::make_ArrayHandle(ids, 10); vtkm::cont::ArrayHandle<vtkm::Id> keys =
vtkm::cont::ArrayHandle<vtkm::Id> keys = vtkm::cont::make_ArrayHandle(seg, 10); vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 0, 0, 0, 1, 1, 2, 3, 3, 4 });
vtkm::cont::ArrayHandle<vtkm::Id> output; vtkm::cont::ArrayHandle<vtkm::Id> output;
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> reversed = vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> reversed =
@ -75,9 +75,9 @@ void TestArrayHandleReverseScanInclusiveByKey()
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<vtkm::cont::DeviceAdapterTagSerial>; using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<vtkm::cont::DeviceAdapterTagSerial>;
Algorithm::ScanInclusiveByKey(keys, values, reversed); Algorithm::ScanInclusiveByKey(keys, values, reversed);
vtkm::Id expected[] = { 0, 1, 3, 6, 4, 9, 6, 7, 15, 9 };
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> expected_reversed = vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> expected_reversed =
vtkm::cont::make_ArrayHandleReverse(vtkm::cont::make_ArrayHandle(expected, 10)); vtkm::cont::make_ArrayHandleReverse(
vtkm::cont::make_ArrayHandle<vtkm::Id>({ 0, 1, 3, 6, 4, 9, 6, 7, 15, 9 }));
auto outputPortal = output.ReadPortal(); auto outputPortal = output.ReadPortal();
auto reversePortal = expected_reversed.ReadPortal(); auto reversePortal = expected_reversed.ReadPortal();
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)

@ -156,7 +156,8 @@ struct TemplatedTests
T* end = begin + ARRAY_SIZE; T* end = begin + ARRAY_SIZE;
const T* cbegin = begin; const T* cbegin = begin;
const T* cend = end; const T* cend = end;
vtkm::cont::ArrayHandle<T> arrayHandle = vtkm::cont::make_ArrayHandle(begin, ARRAY_SIZE); vtkm::cont::ArrayHandle<T> arrayHandle =
vtkm::cont::make_ArrayHandle(begin, ARRAY_SIZE, vtkm::CopyFlag::Off);
std::cout std::cout
<< " Testing ArrayPortalToIterators(ArrayPortalFromIterators) gets back simple iterator." << " Testing ArrayPortalToIterators(ArrayPortalFromIterators) gets back simple iterator."

@ -61,7 +61,7 @@ vtkm::cont::DataSet MakeTestDataSetRectilinear()
vtkm::cont::DataSet MakeTestDataSetCurvilinear() vtkm::cont::DataSet MakeTestDataSetCurvilinear()
{ {
auto recti = MakeTestDataSetRectilinear(); auto recti = MakeTestDataSetRectilinear();
auto coords = recti.GetCoordinateSystem().GetData(); auto coords = recti.GetCoordinateSystem().GetDataAsMultiplexer();
vtkm::cont::ArrayHandle<PointType> sheared; vtkm::cont::ArrayHandle<PointType> sheared;
sheared.Allocate(coords.GetNumberOfValues()); sheared.Allocate(coords.GetNumberOfValues());
@ -140,7 +140,8 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds,
vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates> dispatcher( vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates> dispatcher(
ParametricToWorldCoordinates::MakeScatter(cellIds)); ParametricToWorldCoordinates::MakeScatter(cellIds));
dispatcher.Invoke(ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords); dispatcher.Invoke(
ds.GetCellSet(), ds.GetCoordinateSystem().GetDataAsMultiplexer(), pcoords, wcoords);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

@ -45,10 +45,11 @@ vtkm::Id ArrayLength(const T (&)[Length])
vtkm::cont::CellSetExplicit<> MakeTestCellSet1() vtkm::cont::CellSetExplicit<> MakeTestCellSet1()
{ {
vtkm::cont::CellSetExplicit<> cs; vtkm::cont::CellSetExplicit<> cs;
cs.Fill(numberOfPoints, cs.Fill(
vtkm::cont::make_ArrayHandle(g_shapes, ArrayLength(g_shapes)), numberOfPoints,
vtkm::cont::make_ArrayHandle(g_connectivity, ArrayLength(g_connectivity)), vtkm::cont::make_ArrayHandle(g_shapes, ArrayLength(g_shapes), vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(g_offsets, ArrayLength(g_offsets))); vtkm::cont::make_ArrayHandle(g_connectivity, ArrayLength(g_connectivity), vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(g_offsets, ArrayLength(g_offsets), vtkm::CopyFlag::Off));
return cs; return cs;
} }
@ -57,9 +58,10 @@ vtkm::cont::CellSetExplicit<> MakeTestCellSet2()
{ {
vtkm::cont::CellSetExplicit<> cs; vtkm::cont::CellSetExplicit<> cs;
cs.Fill(numberOfPoints, cs.Fill(numberOfPoints,
vtkm::cont::make_ArrayHandle(g_shapes2, ArrayLength(g_shapes2)), vtkm::cont::make_ArrayHandle(g_shapes2, ArrayLength(g_shapes2), vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(g_connectivity2, ArrayLength(g_connectivity2)), vtkm::cont::make_ArrayHandle(
vtkm::cont::make_ArrayHandle(g_offsets2, ArrayLength(g_offsets2))); g_connectivity2, ArrayLength(g_connectivity2), vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(g_offsets2, ArrayLength(g_offsets2), vtkm::CopyFlag::Off));
return cs; return cs;
} }

@ -129,14 +129,14 @@ int TestCellSetExtrude()
// verify that a constant value point field can be accessed // verify that a constant value point field can be accessed
std::vector<float> pvalues(static_cast<size_t>(coords.GetNumberOfValues()), 42.0f); std::vector<float> pvalues(static_cast<size_t>(coords.GetNumberOfValues()), 42.0f);
vtkm::cont::Field pfield( vtkm::cont::Field pfield = vtkm::cont::make_Field(
"pfield", vtkm::cont::Field::Association::POINTS, vtkm::cont::make_ArrayHandle(pvalues)); "pfield", vtkm::cont::Field::Association::POINTS, pvalues, vtkm::CopyFlag::Off);
dataset.AddField(pfield); dataset.AddField(pfield);
// verify that a constant cell value can be accessed // verify that a constant cell value can be accessed
std::vector<float> cvalues(static_cast<size_t>(cells.GetNumberOfCells()), 42.0f); std::vector<float> cvalues(static_cast<size_t>(cells.GetNumberOfCells()), 42.0f);
vtkm::cont::Field cfield = vtkm::cont::Field cfield = vtkm::cont::make_Field(
vtkm::cont::make_FieldCell("cfield", vtkm::cont::make_ArrayHandle(cvalues)); "cfield", vtkm::cont::Field::Association::CELL_SET, cvalues, vtkm::CopyFlag::Off);
dataset.AddField(cfield); dataset.AddField(cfield);
vtkm::filter::PointAverage avg; vtkm::filter::PointAverage avg;

@ -83,9 +83,7 @@ std::vector<T> createVec(std::size_t n, const T* data)
template <typename T> template <typename T>
vtkm::cont::ArrayHandle<T> createAH(std::size_t n, const T* data) vtkm::cont::ArrayHandle<T> createAH(std::size_t n, const T* data)
{ {
vtkm::cont::ArrayHandle<T> arr; return vtkm::cont::make_ArrayHandle(data, static_cast<vtkm::Id>(n), vtkm::CopyFlag::On);
DFA::Copy(vtkm::cont::make_ArrayHandle(data, static_cast<vtkm::Id>(n)), arr);
return arr;
} }
template <typename T> template <typename T>
@ -105,6 +103,9 @@ vtkm::cont::DataSet CreateDataSetArr(bool useSeparatedCoords,
{ {
std::vector<T> xvals(numPoints), yvals(numPoints), zvals(numPoints); std::vector<T> xvals(numPoints), yvals(numPoints), zvals(numPoints);
std::vector<T> varP(numPoints), varC(numCells); std::vector<T> varP(numPoints), varC(numCells);
std::vector<vtkm::UInt8> shapevals(numCells);
std::vector<vtkm::IdComponent> indicesvals(numCells);
std::vector<vtkm::Id> connvals(numConn);
for (std::size_t i = 0; i < numPoints; i++, f++) for (std::size_t i = 0; i < numPoints; i++, f++)
{ {
xvals[i] = coords[i * 3 + 0]; xvals[i] = coords[i * 3 + 0];
@ -116,15 +117,17 @@ vtkm::cont::DataSet CreateDataSetArr(bool useSeparatedCoords,
for (std::size_t i = 0; i < numCells; i++, f++) for (std::size_t i = 0; i < numCells; i++, f++)
{ {
varC[i] = static_cast<T>(f * 1.1f); varC[i] = static_cast<T>(f * 1.1f);
shapevals[i] = shape[i];
indicesvals[i] = indices[i];
} }
vtkm::cont::ArrayHandle<T> X, Y, Z, P, C; for (std::size_t i = 0; i < numConn; i++)
DFA::Copy(vtkm::cont::make_ArrayHandle(xvals), X); {
DFA::Copy(vtkm::cont::make_ArrayHandle(yvals), Y); connvals[i] = conn[i];
DFA::Copy(vtkm::cont::make_ArrayHandle(zvals), Z); }
DFA::Copy(vtkm::cont::make_ArrayHandle(varP), P); dataSet = dsb.Create(xvals, yvals, zvals, shapevals, indicesvals, connvals);
DFA::Copy(vtkm::cont::make_ArrayHandle(varC), C);
dataSet = dsb.Create( vtkm::cont::ArrayHandle<T> P = vtkm::cont::make_ArrayHandle(varP, vtkm::CopyFlag::On);
X, Y, Z, createAH(numCells, shape), createAH(numCells, indices), createAH(numConn, conn)); vtkm::cont::ArrayHandle<T> C = vtkm::cont::make_ArrayHandle(varC, vtkm::CopyFlag::On);
dataSet.AddPointField("pointvar", P); dataSet.AddPointField("pointvar", P);
dataSet.AddCellField("cellvar", C); dataSet.AddCellField("cellvar", C);
return dataSet; return dataSet;
@ -145,8 +148,8 @@ vtkm::cont::DataSet CreateDataSetArr(bool useSeparatedCoords,
{ {
varC[i][0] = static_cast<T>(f * 1.1f); varC[i][0] = static_cast<T>(f * 1.1f);
} }
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> pts; vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> pts =
DFA::Copy(vtkm::cont::make_ArrayHandle(tmp), pts); vtkm::cont::make_ArrayHandle(tmp, vtkm::CopyFlag::On);
dataSet = dsb.Create( dataSet = dsb.Create(
pts, createAH(numCells, shape), createAH(numCells, indices), createAH(numConn, conn)); pts, createAH(numCells, shape), createAH(numCells, indices), createAH(numConn, conn));
dataSet.AddPointField("pointvar", varP); dataSet.AddPointField("pointvar", varP);
@ -229,7 +232,6 @@ vtkm::cont::DataSet CreateDataSetVec(bool useSeparatedCoords,
void TestDataSetBuilderExplicit() void TestDataSetBuilderExplicit()
{ {
vtkm::cont::DataSetBuilderExplicit dsb;
vtkm::cont::DataSet ds; vtkm::cont::DataSet ds;
vtkm::Bounds bounds; vtkm::Bounds bounds;

@ -121,7 +121,6 @@ void RectilinearTests()
const vtkm::Id NUM_FILL_METHODS = 5; const vtkm::Id NUM_FILL_METHODS = 5;
vtkm::cont::DataSetBuilderRectilinear dataSetBuilder; vtkm::cont::DataSetBuilderRectilinear dataSetBuilder;
vtkm::cont::DataSet dataSet;
std::uniform_int_distribution<vtkm::Id> randomDim(1, MAX_DIM_SIZE); std::uniform_int_distribution<vtkm::Id> randomDim(1, MAX_DIM_SIZE);
std::uniform_int_distribution<vtkm::IdComponent> randomFill(0, NUM_FILL_METHODS - 1); std::uniform_int_distribution<vtkm::IdComponent> randomFill(0, NUM_FILL_METHODS - 1);
@ -130,6 +129,8 @@ void RectilinearTests()
{ {
std::cout << "Trial " << trial << std::endl; std::cout << "Trial " << trial << std::endl;
vtkm::cont::DataSet dataSet;
vtkm::Id3 dimensions( vtkm::Id3 dimensions(
randomDim(g_RandomGenerator), randomDim(g_RandomGenerator), randomDim(g_RandomGenerator)); randomDim(g_RandomGenerator), randomDim(g_RandomGenerator), randomDim(g_RandomGenerator));
std::cout << "Dimensions: " << dimensions << std::endl; std::cout << "Dimensions: " << dimensions << std::endl;
@ -210,16 +211,17 @@ void RectilinearTests()
std::cout << " Create with C array" << std::endl; std::cout << " Create with C array" << std::endl;
dataSet = dataSetBuilder.Create( dataSet = dataSetBuilder.Create(
dimensions[0], dimensions[1], &xCoordinates.front(), &yCoordinates.front()); dimensions[0], dimensions[1], xCoordinates.data(), yCoordinates.data());
dataSet.AddPointField("pointvar", &varP2D.front(), numPoints); dataSet.AddPointField("pointvar", varP2D.data(), numPoints);
dataSet.AddCellField("cellvar", &varC2D.front(), numCells); dataSet.AddCellField("cellvar", varC2D.data(), numCells);
ValidateDataSet(dataSet, ndims, numPoints, numCells, bounds); ValidateDataSet(dataSet, ndims, numPoints, numCells, bounds);
std::cout << " Create with ArrayHandle" << std::endl; std::cout << " Create with ArrayHandle" << std::endl;
dataSet = dataSetBuilder.Create(vtkm::cont::make_ArrayHandle(xCoordinates), dataSet =
vtkm::cont::make_ArrayHandle(yCoordinates)); dataSetBuilder.Create(vtkm::cont::make_ArrayHandle(xCoordinates, vtkm::CopyFlag::Off),
dataSet.AddPointField("pointvar", vtkm::cont::make_ArrayHandle(varP2D)); vtkm::cont::make_ArrayHandle(yCoordinates, vtkm::CopyFlag::Off));
dataSet.AddCellField("cellvar", vtkm::cont::make_ArrayHandle(varC2D)); dataSet.AddPointField("pointvar", vtkm::cont::make_ArrayHandle(varP2D, vtkm::CopyFlag::Off));
dataSet.AddCellField("cellvar", vtkm::cont::make_ArrayHandle(varC2D, vtkm::CopyFlag::Off));
ValidateDataSet(dataSet, ndims, numPoints, numCells, bounds); ValidateDataSet(dataSet, ndims, numPoints, numCells, bounds);
} }
@ -256,19 +258,20 @@ void RectilinearTests()
dataSet = dataSetBuilder.Create(dimensions[0], dataSet = dataSetBuilder.Create(dimensions[0],
dimensions[1], dimensions[1],
dimensions[2], dimensions[2],
&xCoordinates.front(), xCoordinates.data(),
&yCoordinates.front(), yCoordinates.data(),
&zCoordinates.front()); zCoordinates.data());
dataSet.AddPointField("pointvar", vtkm::cont::make_ArrayHandle(varP3D)); dataSet.AddPointField("pointvar", vtkm::cont::make_ArrayHandle(varP3D, vtkm::CopyFlag::Off));
dataSet.AddCellField("cellvar", vtkm::cont::make_ArrayHandle(varC3D)); dataSet.AddCellField("cellvar", vtkm::cont::make_ArrayHandle(varC3D, vtkm::CopyFlag::Off));
ValidateDataSet(dataSet, ndims, numPoints, numCells, bounds); ValidateDataSet(dataSet, ndims, numPoints, numCells, bounds);
std::cout << " Create with ArrayHandle" << std::endl; std::cout << " Create with ArrayHandle" << std::endl;
dataSet = dataSetBuilder.Create(vtkm::cont::make_ArrayHandle(xCoordinates), dataSet =
vtkm::cont::make_ArrayHandle(yCoordinates), dataSetBuilder.Create(vtkm::cont::make_ArrayHandle(xCoordinates, vtkm::CopyFlag::Off),
vtkm::cont::make_ArrayHandle(zCoordinates)); vtkm::cont::make_ArrayHandle(yCoordinates, vtkm::CopyFlag::Off),
dataSet.AddPointField("pointvar", vtkm::cont::make_ArrayHandle(varP3D)); vtkm::cont::make_ArrayHandle(zCoordinates, vtkm::CopyFlag::Off));
dataSet.AddCellField("cellvar", vtkm::cont::make_ArrayHandle(varC3D)); dataSet.AddPointField("pointvar", vtkm::cont::make_ArrayHandle(varP3D, vtkm::CopyFlag::Off));
dataSet.AddCellField("cellvar", vtkm::cont::make_ArrayHandle(varC3D, vtkm::CopyFlag::Off));
ValidateDataSet(dataSet, ndims, numPoints, numCells, bounds); ValidateDataSet(dataSet, ndims, numPoints, numCells, bounds);
} }
} }

@ -86,12 +86,9 @@ void TestDataSet_Explicit()
vtkm::cont::DataSet dataSet = make_SingleTypeDataSet(); vtkm::cont::DataSet dataSet = make_SingleTypeDataSet();
std::vector<vtkm::Id> validIds; //iterate the 2nd cell 4 times
validIds.push_back(1); //iterate the 2nd cell 4 times vtkm::cont::ArrayHandle<vtkm::Id> validCellIds =
validIds.push_back(1); vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1 });
validIds.push_back(1);
validIds.push_back(1);
vtkm::cont::ArrayHandle<vtkm::Id> validCellIds = vtkm::cont::make_ArrayHandle(validIds);
//get the cellset single type from the dataset //get the cellset single type from the dataset
vtkm::cont::CellSetSingleType<> cellSet; vtkm::cont::CellSetSingleType<> cellSet;
@ -125,12 +122,9 @@ void TestDataSet_Structured2D()
vtkm::cont::testing::MakeTestDataSet testDataSet; vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make2DUniformDataSet0(); vtkm::cont::DataSet dataSet = testDataSet.Make2DUniformDataSet0();
std::vector<vtkm::Id> validIds; //iterate the 2nd cell 4 times
validIds.push_back(1); //iterate the 2nd cell 4 times vtkm::cont::ArrayHandle<vtkm::Id> validCellIds =
validIds.push_back(1); vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1 });
validIds.push_back(1);
validIds.push_back(1);
vtkm::cont::ArrayHandle<vtkm::Id> validCellIds = vtkm::cont::make_ArrayHandle(validIds);
vtkm::cont::CellSetStructured<2> cellSet; vtkm::cont::CellSetStructured<2> cellSet;
dataSet.GetCellSet().CopyTo(cellSet); dataSet.GetCellSet().CopyTo(cellSet);
@ -161,12 +155,9 @@ void TestDataSet_Structured3D()
vtkm::cont::testing::MakeTestDataSet testDataSet; vtkm::cont::testing::MakeTestDataSet testDataSet;
vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0(); vtkm::cont::DataSet dataSet = testDataSet.Make3DUniformDataSet0();
std::vector<vtkm::Id> validIds; //iterate the 2nd cell 4 times
validIds.push_back(1); //iterate the 2nd cell 4 times vtkm::cont::ArrayHandle<vtkm::Id> validCellIds =
validIds.push_back(1); vtkm::cont::make_ArrayHandle<vtkm::Id>({ 1, 1, 1, 1 });
validIds.push_back(1);
validIds.push_back(1);
vtkm::cont::ArrayHandle<vtkm::Id> validCellIds = vtkm::cont::make_ArrayHandle(validIds);
vtkm::cont::CellSetStructured<3> cellSet; vtkm::cont::CellSetStructured<3> cellSet;
dataSet.GetCellSet().CopyTo(cellSet); dataSet.GetCellSet().CopyTo(cellSet);

@ -141,7 +141,9 @@ void TestContDataTypesHaveMoveSemantics()
is_noexcept_movable<vtkm::cont::DataSet>(); is_noexcept_movable<vtkm::cont::DataSet>();
is_noexcept_movable<vtkm::cont::Field>(); is_noexcept_movable<vtkm::cont::Field>();
is_noexcept_movable<vtkm::cont::CoordinateSystem>(); is_noexcept_movable<vtkm::cont::CoordinateSystem>();
VTKM_DEPRECATED_SUPPRESS_BEGIN
is_noexcept_movable<vtkm::cont::ArrayHandleVirtualCoordinates>(); is_noexcept_movable<vtkm::cont::ArrayHandleVirtualCoordinates>();
VTKM_DEPRECATED_SUPPRESS_END
//verify the CellSetStructured, and CellSetExplicit //verify the CellSetStructured, and CellSetExplicit
//have efficient storage in containers such as std::vector //have efficient storage in containers such as std::vector

@ -19,25 +19,25 @@ void TestParticleArrayCopy()
vtkm::FloatDefault x0(-1), x1(1); vtkm::FloatDefault x0(-1), x1(1);
std::uniform_real_distribution<vtkm::FloatDefault> dist(x0, x1); std::uniform_real_distribution<vtkm::FloatDefault> dist(x0, x1);
std::vector<vtkm::Particle> particles; std::vector<vtkm::Massless> particles;
vtkm::Id N = 17; vtkm::Id N = 17;
for (vtkm::Id i = 0; i < N; i++) for (vtkm::Id i = 0; i < N; i++)
{ {
auto x = dist(generator); auto x = dist(generator);
auto y = dist(generator); auto y = dist(generator);
auto z = dist(generator); auto z = dist(generator);
particles.push_back(vtkm::Particle(vtkm::Vec3f(x, y, z), i)); particles.push_back(vtkm::Massless(vtkm::Vec3f(x, y, z), i));
} }
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
auto particleAH = vtkm::cont::make_ArrayHandle(particles); auto particleAH = vtkm::cont::make_ArrayHandle(particles, vtkm::CopyFlag::Off);
//Test copy position only //Test copy position only
if (i == 0) if (i == 0)
{ {
vtkm::cont::ArrayHandle<vtkm::Vec3f> pos; vtkm::cont::ArrayHandle<vtkm::Vec3f> pos;
vtkm::cont::ParticleArrayCopy(particleAH, pos); vtkm::cont::ParticleArrayCopy<vtkm::Massless>(particleAH, pos);
auto pPortal = particleAH.ReadPortal(); auto pPortal = particleAH.ReadPortal();
for (vtkm::Id j = 0; j < N; j++) for (vtkm::Id j = 0; j < N; j++)
@ -54,7 +54,7 @@ void TestParticleArrayCopy()
vtkm::cont::ArrayHandle<vtkm::ParticleStatus> status; vtkm::cont::ArrayHandle<vtkm::ParticleStatus> status;
vtkm::cont::ArrayHandle<vtkm::FloatDefault> ptime; vtkm::cont::ArrayHandle<vtkm::FloatDefault> ptime;
vtkm::cont::ParticleArrayCopy(particleAH, pos, ids, steps, status, ptime); vtkm::cont::ParticleArrayCopy<vtkm::Massless>(particleAH, pos, ids, steps, status, ptime);
auto pPortal = particleAH.ReadPortal(); auto pPortal = particleAH.ReadPortal();
for (vtkm::Id j = 0; j < N; j++) for (vtkm::Id j = 0; j < N; j++)

@ -132,30 +132,6 @@ struct TestArrayHandleCast
} }
}; };
struct TestArrayHandleCompositeVector
{
template <typename T>
void operator()(T) const
{
auto array = vtkm::cont::make_ArrayHandleCompositeVector(RandomArrayHandle<T>::Make(ArraySize),
RandomArrayHandle<T>::Make(ArraySize));
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
}
};
struct TestArrayHandleConcatenate
{
template <typename T>
void operator()(T) const
{
auto array = vtkm::cont::make_ArrayHandleConcatenate(RandomArrayHandle<T>::Make(ArraySize),
RandomArrayHandle<T>::Make(ArraySize));
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
}
};
struct TestArrayHandleConstant struct TestArrayHandleConstant
{ {
template <typename T> template <typename T>
@ -181,19 +157,6 @@ struct TestArrayHandleCounting
} }
}; };
struct TestArrayHandleExtractComponent
{
template <typename T>
void operator()(T) const
{
auto numComps = vtkm::VecTraits<T>::NUM_COMPONENTS;
auto array = vtkm::cont::make_ArrayHandleExtractComponent(
RandomArrayHandle<T>::Make(ArraySize), RandomValue<vtkm::IdComponent>::Make(0, numComps - 1));
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
}
};
struct TestArrayHandleGroupVec struct TestArrayHandleGroupVec
{ {
template <typename T> template <typename T>
@ -243,8 +206,8 @@ struct TestArrayHandleGroupVecVariable
return offset; return offset;
}); });
auto array = vtkm::cont::make_ArrayHandleGroupVecVariable(RandomArrayHandle<T>::Make(size), auto array = vtkm::cont::make_ArrayHandleGroupVecVariable(
vtkm::cont::make_ArrayHandle(comps)); RandomArrayHandle<T>::Make(size), vtkm::cont::make_ArrayHandle(comps, vtkm::CopyFlag::On));
RunTest(array); RunTest(array);
// cannot make a VariantArrayHandle containing ArrayHandleGroupVecVariable // cannot make a VariantArrayHandle containing ArrayHandleGroupVecVariable
@ -253,37 +216,6 @@ struct TestArrayHandleGroupVecVariable
} }
}; };
struct TestArrayHandleImplicit
{
template <typename T>
struct ImplicitFunctor
{
ImplicitFunctor() = default;
explicit ImplicitFunctor(const T& factor)
: Factor(factor)
{
}
VTKM_EXEC_CONT T operator()(vtkm::Id index) const
{
return static_cast<T>(this->Factor *
static_cast<typename vtkm::VecTraits<T>::ComponentType>(index));
}
T Factor;
};
template <typename T>
void operator()(T) const
{
ImplicitFunctor<T> functor(RandomValue<T>::Make(2, 9));
auto array = vtkm::cont::make_ArrayHandleImplicit(functor, ArraySize);
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
}
};
void TestArrayHandleIndex() void TestArrayHandleIndex()
{ {
auto size = RandomValue<vtkm::Id>::Make(2, 10); auto size = RandomValue<vtkm::Id>::Make(2, 10);
@ -321,86 +253,6 @@ struct TestArrayHandleReverse
} }
}; };
struct TestArrayHandleSwizzle
{
template <typename T>
void operator()(T) const
{
static const vtkm::IdComponent2 map2s[6] = { { 0, 1 }, { 0, 2 }, { 1, 0 },
{ 1, 2 }, { 2, 0 }, { 2, 1 } };
static const vtkm::IdComponent3 map3s[6] = { { 0, 1, 2 }, { 0, 2, 1 }, { 1, 0, 2 },
{ 1, 2, 0 }, { 2, 0, 1 }, { 2, 1, 0 } };
auto numOutComps = RandomValue<vtkm::IdComponent>::Make(2, 3);
switch (numOutComps)
{
case 2:
{
auto array = make_ArrayHandleSwizzle(RandomArrayHandle<vtkm::Vec<T, 3>>::Make(ArraySize),
map2s[RandomValue<int>::Make(0, 5)]);
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
break;
}
case 3:
default:
{
auto array = make_ArrayHandleSwizzle(RandomArrayHandle<vtkm::Vec<T, 3>>::Make(ArraySize),
map3s[RandomValue<int>::Make(0, 5)]);
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
break;
}
}
}
};
struct TestArrayHandleTransform
{
struct TransformFunctor
{
template <typename T>
VTKM_EXEC_CONT T operator()(const T& in) const
{
return static_cast<T>(in * T{ 2 });
}
};
struct InverseTransformFunctor
{
template <typename T>
VTKM_EXEC_CONT T operator()(const T& in) const
{
return static_cast<T>(in / T{ 2 });
}
};
template <typename T>
void TestType1() const
{
auto array = vtkm::cont::make_ArrayHandleTransform(RandomArrayHandle<T>::Make(ArraySize),
TransformFunctor{});
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
}
template <typename T>
void TestType2() const
{
auto array = vtkm::cont::make_ArrayHandleTransform(
RandomArrayHandle<T>::Make(ArraySize), TransformFunctor{}, InverseTransformFunctor{});
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
}
template <typename T>
void operator()(T) const
{
this->TestType1<T>();
this->TestType2<T>();
}
};
vtkm::cont::ArrayHandleUniformPointCoordinates MakeRandomArrayHandleUniformPointCoordinates() vtkm::cont::ArrayHandleUniformPointCoordinates MakeRandomArrayHandleUniformPointCoordinates()
{ {
@ -417,46 +269,6 @@ void TestArrayHandleUniformPointCoordinates()
RunTest(MakeTestVariantArrayHandle(array)); RunTest(MakeTestVariantArrayHandle(array));
} }
void TestArrayHandleVirtualCoordinates()
{
int type = RandomValue<int>::Make(0, 2);
vtkm::cont::ArrayHandleVirtualCoordinates array;
switch (type)
{
case 0:
array =
vtkm::cont::ArrayHandleVirtualCoordinates(MakeRandomArrayHandleUniformPointCoordinates());
break;
case 1:
array =
vtkm::cont::ArrayHandleVirtualCoordinates(vtkm::cont::make_ArrayHandleCartesianProduct(
RandomArrayHandle<vtkm::FloatDefault>::Make(ArraySize),
RandomArrayHandle<vtkm::FloatDefault>::Make(ArraySize),
RandomArrayHandle<vtkm::FloatDefault>::Make(ArraySize)));
break;
default:
array =
vtkm::cont::ArrayHandleVirtualCoordinates(RandomArrayHandle<vtkm::Vec3f>::Make(ArraySize));
break;
}
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
}
struct TestArrayHandleZip
{
template <typename T>
void operator()(T) const
{
auto array = vtkm::cont::make_ArrayHandleZip(RandomArrayHandle<T>::Make(ArraySize),
vtkm::cont::ArrayHandleIndex(ArraySize));
RunTest(array);
RunTest(MakeTestVariantArrayHandle(array));
}
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void TestArrayHandleSerialization() void TestArrayHandleSerialization()
@ -464,62 +276,81 @@ void TestArrayHandleSerialization()
std::cout << "Testing ArrayHandleBasic\n"; std::cout << "Testing ArrayHandleBasic\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleBasic(), TestTypesList()); vtkm::testing::Testing::TryTypes(TestArrayHandleBasic(), TestTypesList());
std::cout << "Testing ArrayHandleSOA\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagSOA>::value)
vtkm::testing::Testing::TryTypes(TestArrayHandleSOA(), TestTypesList()); {
std::cout << "Testing ArrayHandleSOA\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleSOA(), TestTypesList());
}
std::cout << "Testing ArrayHandleCartesianProduct\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
vtkm::testing::Testing::TryTypes(TestArrayHandleCartesianProduct(), TestTypesList()); vtkm::cont::StorageTagCartesianProduct<vtkm::cont::StorageTagBasic,
vtkm::cont::StorageTagBasic,
vtkm::cont::StorageTagBasic>>::value)
{
std::cout << "Testing ArrayHandleCartesianProduct\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleCartesianProduct(), TestTypesList());
}
std::cout << "Testing TestArrayHandleCast\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
vtkm::testing::Testing::TryTypes(TestArrayHandleCast(), TestTypesList()); vtkm::cont::StorageTagCast<vtkm::Int8, vtkm::cont::StorageTagBasic>>::value)
{
std::cout << "Testing TestArrayHandleCast\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleCast(), TestTypesList());
}
std::cout << "Testing ArrayHandleCompositeVector\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagConstant>::value)
vtkm::testing::Testing::TryTypes(TestArrayHandleCompositeVector(), TestTypesList()); {
std::cout << "Testing ArrayHandleConstant\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleConstant(), TestTypesList());
}
std::cout << "Testing ArrayHandleConcatenate\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagCounting>::value)
vtkm::testing::Testing::TryTypes(TestArrayHandleConcatenate(), TestTypesList()); {
std::cout << "Testing ArrayHandleCounting\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleCounting(), TestTypesList());
}
std::cout << "Testing ArrayHandleConstant\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
vtkm::testing::Testing::TryTypes(TestArrayHandleConstant(), TestTypesList()); vtkm::cont::StorageTagGroupVec<vtkm::cont::StorageTagBasic, 3>>::value)
{
std::cout << "Testing ArrayHandleGroupVec\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVec(), TestTypesList());
}
std::cout << "Testing ArrayHandleCounting\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
vtkm::testing::Testing::TryTypes(TestArrayHandleCounting(), TestTypesList()); vtkm::cont::StorageTagGroupVecVariable<vtkm::cont::StorageTagBasic,
vtkm::cont::StorageTagBasic>>::value)
{
std::cout << "Testing ArrayHandleGroupVecVariable\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVecVariable(), TestTypesList());
}
std::cout << "Testing ArrayHandleExtractComponent\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagIndex>::value)
vtkm::testing::Testing::TryTypes(TestArrayHandleExtractComponent(), TestTypesList()); {
std::cout << "Testing ArrayHandleIndex\n";
TestArrayHandleIndex();
}
std::cout << "Testing ArrayHandleGroupVec\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVec(), TestTypesList()); vtkm::cont::StorageTagPermutation<vtkm::cont::StorageTagBasic,
vtkm::cont::StorageTagBasic>>::value)
{
std::cout << "Testing ArrayHandlePermutation\n";
vtkm::testing::Testing::TryTypes(TestArrayHandlePermutation(), TestTypesList());
}
std::cout << "Testing ArrayHandleGroupVecVariable\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST,
vtkm::testing::Testing::TryTypes(TestArrayHandleGroupVecVariable(), TestTypesList()); vtkm::cont::StorageTagReverse<vtkm::cont::StorageTagBasic>>::value)
{
std::cout << "Testing ArrayHandleReverse\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleReverse(), TestTypesList());
}
std::cout << "Testing ArrayHandleImplicit\n"; if (vtkm::ListHas<VTKM_DEFAULT_STORAGE_LIST, vtkm::cont::StorageTagUniformPoints>::value)
vtkm::testing::Testing::TryTypes(TestArrayHandleImplicit(), TestTypesList()); {
std::cout << "Testing ArrayHandleUniformPointCoordinates\n";
std::cout << "Testing ArrayHandleIndex\n"; TestArrayHandleUniformPointCoordinates();
TestArrayHandleIndex(); }
std::cout << "Testing ArrayHandlePermutation\n";
vtkm::testing::Testing::TryTypes(TestArrayHandlePermutation(), TestTypesList());
std::cout << "Testing ArrayHandleReverse\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleReverse(), TestTypesList());
std::cout << "Testing ArrayHandleSwizzle\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleSwizzle(), TestTypesList());
std::cout << "Testing ArrayHandleTransform\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleTransform(), TestTypesList());
std::cout << "Testing ArrayHandleUniformPointCoordinates\n";
TestArrayHandleUniformPointCoordinates();
std::cout << "Testing ArrayHandleVirtualCoordinates\n";
TestArrayHandleVirtualCoordinates();
std::cout << "Testing ArrayHandleZip\n";
vtkm::testing::Testing::TryTypes(TestArrayHandleZip(), TestTypesList());
} }
} // anonymous namespace } // anonymous namespace
@ -540,37 +371,3 @@ int UnitTestSerializationArrayHandle(int argc, char* argv[])
return vtkm::cont::testing::Testing::Run(TestArrayHandleSerialization, argc, argv); return vtkm::cont::testing::Testing::Run(TestArrayHandleSerialization, argc, argv);
} }
//-----------------------------------------------------------------------------
namespace vtkm
{
namespace cont
{
template <typename T>
struct SerializableTypeString<TestArrayHandleImplicit::ImplicitFunctor<T>>
{
static VTKM_CONT const std::string& Get()
{
static std::string name =
"TestArrayHandleImplicit::ImplicitFunctor<" + SerializableTypeString<T>::Get() + ">";
return name;
}
};
template <>
struct SerializableTypeString<TestArrayHandleTransform::TransformFunctor>
{
static VTKM_CONT const std::string Get() { return "TestArrayHandleTransform::TransformFunctor"; }
};
template <>
struct SerializableTypeString<TestArrayHandleTransform::InverseTransformFunctor>
{
static VTKM_CONT const std::string Get()
{
return "TestArrayHandleTransform::InverseTransformFunctor";
}
};
}
} // vtkm::cont

@ -34,20 +34,40 @@
#include <type_traits> #include <type_traits>
#include <typeinfo> #include <typeinfo>
namespace
{
// Make an "unusual" type to use in the test. This is simply a type that
// is sure not to be declared elsewhere.
struct UnusualType
{
using T = vtkm::Id;
T X;
UnusualType() = default;
UnusualType(T x)
: X(x)
{
}
UnusualType& operator=(T x)
{
this->X = x;
return *this;
}
operator T() const { return this->X; }
};
} // anonymous namespace
namespace vtkm namespace vtkm
{ {
// VariantArrayHandle requires its value type to have a defined VecTraits // VariantArrayHandle requires its value type to have a defined VecTraits
// class. One of the tests is to use an "unusual" array of std::string // class. One of the tests is to use an "unusual" array.
// (which is pretty pointless but might tease out some assumptions).
// Make an implementation here. Because I am lazy, this is only a partial // Make an implementation here. Because I am lazy, this is only a partial
// implementation. // implementation.
template <> template <>
struct VecTraits<std::string> struct VecTraits<UnusualType> : VecTraits<UnusualType::T>
{ {
using IsSizeStatic = vtkm::VecTraitsTagSizeStatic;
static constexpr vtkm::IdComponent NUM_COMPONENTS = 1;
using HasMultipleComponents = vtkm::VecTraitsTagSingleComponent;
}; };
} // namespace vtkm } // namespace vtkm
@ -57,34 +77,6 @@ namespace
const vtkm::Id ARRAY_SIZE = 10; const vtkm::Id ARRAY_SIZE = 10;
using TypeListString = vtkm::List<std::string>;
template <typename T>
struct UnusualPortal
{
using ValueType = T;
VTKM_EXEC_CONT
vtkm::Id GetNumberOfValues() const { return ARRAY_SIZE; }
VTKM_EXEC_CONT
ValueType Get(vtkm::Id index) const { return TestValue(index, ValueType()); }
};
template <typename T>
class ArrayHandleWithUnusualStorage
: public vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagImplicit<UnusualPortal<T>>>
{
using Superclass = vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagImplicit<UnusualPortal<T>>>;
public:
VTKM_CONT
ArrayHandleWithUnusualStorage()
: Superclass(typename Superclass::ReadPortalType())
{
}
};
template <typename T> template <typename T>
struct TestValueFunctor struct TestValueFunctor
{ {
@ -93,54 +85,48 @@ struct TestValueFunctor
struct CheckFunctor struct CheckFunctor
{ {
template <typename T, typename S>
static void CheckArray(const vtkm::cont::ArrayHandle<T, S>& array)
{
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size.");
CheckPortal(array.ReadPortal());
}
template <typename S>
static void CheckArray(const vtkm::cont::ArrayHandle<UnusualType, S>& array)
{
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size.");
auto portal = array.ReadPortal();
for (vtkm::Id index = 0; index < array.GetNumberOfValues(); ++index)
{
VTKM_TEST_ASSERT(portal.Get(index) == TestValue(index, UnusualType::T{}));
}
}
template <typename T> template <typename T>
void operator()(const vtkm::cont::ArrayHandle<T>& array, void operator()(const vtkm::cont::ArrayHandle<T>& array,
bool& calledBasic, bool& calledBasic,
bool& vtkmNotUsed(calledUnusual),
bool& vtkmNotUsed(calledVirtual)) const bool& vtkmNotUsed(calledVirtual)) const
{ {
calledBasic = true; calledBasic = true;
std::cout << " Checking for basic array type: " << typeid(T).name() << std::endl; std::cout << " Checking for basic array type: " << typeid(T).name() << std::endl;
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size."); CheckArray(array);
auto portal = array.ReadPortal();
CheckPortal(portal);
}
template <typename T>
void operator()(
const vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagImplicit<UnusualPortal<T>>>& array,
bool& vtkmNotUsed(calledBasic),
bool& calledUnusual,
bool& vtkmNotUsed(calledVirtual)) const
{
calledUnusual = true;
std::cout << " Checking for unusual array type: " << typeid(T).name() << std::endl;
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size.");
auto portal = array.ReadPortal();
CheckPortal(portal);
} }
template <typename T> template <typename T>
void operator()(const vtkm::cont::ArrayHandleVirtual<T>& array, void operator()(const vtkm::cont::ArrayHandleVirtual<T>& array,
bool& vtkmNotUsed(calledBasic), bool& vtkmNotUsed(calledBasic),
bool& vtkmNotUsed(calledUnusual),
bool& calledVirtual) const bool& calledVirtual) const
{ {
calledVirtual = true; calledVirtual = true;
std::cout << " Checking for virtual array type: " << typeid(T).name() << std::endl; std::cout << " Checking for virtual array type: " << typeid(T).name() << std::endl;
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE, "Unexpected array size."); CheckArray(array);
auto portal = array.ReadPortal();
CheckPortal(portal);
} }
template <typename T, typename S> template <typename T, typename S>
void operator()(const vtkm::cont::ArrayHandle<T, S>&, bool&, bool&, bool&) const void operator()(const vtkm::cont::ArrayHandle<T, S>&, bool&, bool&) const
{ {
VTKM_TEST_FAIL("Array resolved to unexpected type."); VTKM_TEST_FAIL("Array resolved to unexpected type.");
} }
@ -161,87 +147,76 @@ void BasicArrayVariantChecks(const vtkm::cont::VariantArrayHandleBase<TypeList>&
template <typename TypeList> template <typename TypeList>
void CheckArrayVariant(const vtkm::cont::VariantArrayHandleBase<TypeList>& array, void CheckArrayVariant(const vtkm::cont::VariantArrayHandleBase<TypeList>& array,
vtkm::IdComponent numComponents, vtkm::IdComponent numComponents,
bool isBasicArray, bool isBasicArray)
bool isUnusualArray)
{ {
BasicArrayVariantChecks(array, numComponents); BasicArrayVariantChecks(array, numComponents);
std::cout << " CastAndCall with default storage" << std::endl; std::cout << " CastAndCall with default storage" << std::endl;
bool calledBasic = false; bool calledBasic = false;
bool calledUnusual = false;
bool calledVirtual = false; bool calledVirtual = false;
CastAndCall(array, CheckFunctor(), calledBasic, calledUnusual, calledVirtual); CastAndCall(array, CheckFunctor(), calledBasic, calledVirtual);
VTKM_TEST_ASSERT( VTKM_TEST_ASSERT(
calledBasic || calledUnusual || calledVirtual, calledBasic || calledVirtual,
"The functor was never called (and apparently a bad value exception not thrown)."); "The functor was never called (and apparently a bad value exception not thrown).");
if (isBasicArray) if (isBasicArray)
{ {
VTKM_TEST_ASSERT(calledBasic, "The functor was never called with the basic array fast path"); VTKM_TEST_ASSERT(calledBasic, "The functor was never called with the basic array fast path");
VTKM_TEST_ASSERT(!calledUnusual, "The functor was somehow called with the unusual fast path");
VTKM_TEST_ASSERT(!calledVirtual, "The functor was somehow called with the virtual path"); VTKM_TEST_ASSERT(!calledVirtual, "The functor was somehow called with the virtual path");
} }
else else
{ {
VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage."); VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage.");
VTKM_TEST_ASSERT(!calledUnusual, "The array somehow got cast to an unusual storage.");
} }
std::cout << " CastAndCall with no storage" << std::endl; // Work around apparent bug in some versions of GCC that give a warning about
calledBasic = false; // StorageVirtualImpl<>::GetNumberOfValues() being "declared 'static' but never defined"
calledUnusual = false; // (even though nothing about this method is declared static). See the following
calledVirtual = false; // stackoverflow discussion for more details:
array.CastAndCall(vtkm::ListEmpty(), CheckFunctor(), calledBasic, calledUnusual, calledVirtual); //
VTKM_TEST_ASSERT( // https://stackoverflow.com/questions/56615695/how-to-fix-declared-static-but-never-defined-on-member-function
calledBasic || calledUnusual || calledVirtual, #if !defined(VTKM_GCC) || (__GNUC__ >= 9)
"The functor was never called (and apparently a bad value exception not thrown).");
VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage.");
VTKM_TEST_ASSERT(!calledUnusual, "The array somehow got cast to an unusual storage.");
std::cout << " CastAndCall with extra storage" << std::endl; std::cout << " CastAndCall with extra storage" << std::endl;
calledBasic = false; calledBasic = false;
calledUnusual = false;
calledVirtual = false; calledVirtual = false;
array.CastAndCall(vtkm::List<vtkm::cont::StorageTagBasic, array.CastAndCall(vtkm::List<vtkm::cont::StorageTagBasic, vtkm::cont::StorageTagConstant>{},
ArrayHandleWithUnusualStorage<vtkm::Id>::StorageTag,
ArrayHandleWithUnusualStorage<std::string>::StorageTag>(),
CheckFunctor(), CheckFunctor(),
calledBasic, calledBasic,
calledUnusual,
calledVirtual); calledVirtual);
VTKM_TEST_ASSERT( VTKM_TEST_ASSERT(
calledBasic || calledUnusual || calledVirtual, calledBasic || calledVirtual,
"The functor was never called (and apparently a bad value exception not thrown)."); "The functor was never called (and apparently a bad value exception not thrown).");
if (isBasicArray) if (isBasicArray)
{ {
VTKM_TEST_ASSERT(calledBasic, "The functor was never called with the basic array fast path"); VTKM_TEST_ASSERT(calledBasic, "The functor was never called with the basic array fast path");
VTKM_TEST_ASSERT(!calledUnusual, "The functor was somehow called with the unusual fast path");
VTKM_TEST_ASSERT(!calledVirtual, "The functor was somehow called with the virtual path");
}
else if (isUnusualArray)
{
VTKM_TEST_ASSERT(calledUnusual, "The functor was never called with the unusual fast path");
VTKM_TEST_ASSERT(!calledBasic, "The functor was somehow called with the basic fast path");
VTKM_TEST_ASSERT(!calledVirtual, "The functor was somehow called with the virtual path"); VTKM_TEST_ASSERT(!calledVirtual, "The functor was somehow called with the virtual path");
} }
else else
{ {
VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage."); VTKM_TEST_ASSERT(!calledBasic, "The array somehow got cast to a basic storage.");
VTKM_TEST_ASSERT(!calledUnusual, "The array somehow got cast to an unusual storage.");
} }
#endif
} }
template <typename T> template <typename T>
vtkm::cont::VariantArrayHandle CreateArrayVariant(T) vtkm::cont::VariantArrayHandle CreateArrayVariant(T)
{ {
// Declared static to prevent going out of scope. vtkm::cont::ArrayHandle<T> array;
static T buffer[ARRAY_SIZE]; array.Allocate(ARRAY_SIZE);
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++) SetPortal(array.WritePortal());
{ return vtkm::cont::VariantArrayHandle(array);
buffer[index] = TestValue(index, T()); }
}
return vtkm::cont::VariantArrayHandle(vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE)); vtkm::cont::VariantArrayHandle CreateArrayVariant(UnusualType)
{
vtkm::cont::ArrayHandle<UnusualType> array;
array.Allocate(ARRAY_SIZE);
auto portal = array.WritePortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
{
portal.Set(index, TestValue(index, UnusualType::T{}));
}
return vtkm::cont::VariantArrayHandle(array);
} }
template <typename ArrayHandleType> template <typename ArrayHandleType>
@ -250,7 +225,7 @@ void CheckCastToArrayHandle(const ArrayHandleType& array)
VTKM_IS_ARRAY_HANDLE(ArrayHandleType); VTKM_IS_ARRAY_HANDLE(ArrayHandleType);
vtkm::cont::VariantArrayHandle arrayVariant = array; vtkm::cont::VariantArrayHandle arrayVariant = array;
VTKM_TEST_ASSERT(!arrayVariant.IsType<vtkm::cont::ArrayHandle<std::string>>(), VTKM_TEST_ASSERT(!arrayVariant.IsType<vtkm::cont::ArrayHandle<UnusualType>>(),
"Dynamic array reporting is wrong type."); "Dynamic array reporting is wrong type.");
ArrayHandleType castArray1; ArrayHandleType castArray1;
@ -345,7 +320,7 @@ template <typename T, typename ArrayVariantType>
void TryNewInstance(T, ArrayVariantType originalArray) void TryNewInstance(T, ArrayVariantType originalArray)
{ {
// This check should already have been performed by caller, but just in case. // This check should already have been performed by caller, but just in case.
CheckArrayVariant(originalArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true, false); CheckArrayVariant(originalArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true);
std::cout << "Create new instance of array." << std::endl; std::cout << "Create new instance of array." << std::endl;
ArrayVariantType newArray = originalArray.NewInstance(); ArrayVariantType newArray = originalArray.NewInstance();
@ -361,7 +336,7 @@ void TryNewInstance(T, ArrayVariantType originalArray)
{ {
staticArray.WritePortal().Set(index, TestValue(index + 100, T())); staticArray.WritePortal().Set(index, TestValue(index + 100, T()));
} }
CheckArrayVariant(originalArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true, false); CheckArrayVariant(originalArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true);
std::cout << "Set the new static array to expected values and make sure the new" << std::endl std::cout << "Set the new static array to expected values and make sure the new" << std::endl
<< "dynamic array points to the same new values." << std::endl; << "dynamic array points to the same new values." << std::endl;
@ -369,7 +344,7 @@ void TryNewInstance(T, ArrayVariantType originalArray)
{ {
staticArray.WritePortal().Set(index, TestValue(index, T())); staticArray.WritePortal().Set(index, TestValue(index, T()));
} }
CheckArrayVariant(newArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true, false); CheckArrayVariant(newArray, vtkm::VecTraits<T>::NUM_COMPONENTS, true);
} }
template <typename T, typename ArrayVariantType> template <typename T, typename ArrayVariantType>
@ -429,7 +404,7 @@ void TryDefaultType(T)
{ {
vtkm::cont::VariantArrayHandle array = CreateArrayVariant(T()); vtkm::cont::VariantArrayHandle array = CreateArrayVariant(T());
CheckArrayVariant(array, vtkm::VecTraits<T>::NUM_COMPONENTS, true, false); CheckArrayVariant(array, vtkm::VecTraits<T>::NUM_COMPONENTS, true);
TryNewInstance(T(), array); TryNewInstance(T(), array);
@ -444,7 +419,7 @@ struct TryBasicVTKmType
vtkm::cont::VariantArrayHandle array = CreateArrayVariant(T()); vtkm::cont::VariantArrayHandle array = CreateArrayVariant(T());
CheckArrayVariant( CheckArrayVariant(
array.ResetTypes(vtkm::TypeListAll()), vtkm::VecTraits<T>::NUM_COMPONENTS, true, false); array.ResetTypes(vtkm::TypeListAll()), vtkm::VecTraits<T>::NUM_COMPONENTS, true);
TryNewInstance(T(), array.ResetTypes(vtkm::TypeListAll())); TryNewInstance(T(), array.ResetTypes(vtkm::TypeListAll()));
} }
@ -453,60 +428,20 @@ struct TryBasicVTKmType
void TryUnusualType() void TryUnusualType()
{ {
// A string is an unlikely type to be declared elsewhere in VTK-m. // A string is an unlikely type to be declared elsewhere in VTK-m.
vtkm::cont::VariantArrayHandle array = CreateArrayVariant(std::string()); vtkm::cont::VariantArrayHandle array = CreateArrayVariant(UnusualType{});
try try
{ {
CheckArrayVariant(array, 1, true, false); CheckArrayVariant(array, 1, true);
VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized type."); VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized type.");
} }
catch (vtkm::cont::ErrorBadValue&) catch (vtkm::cont::ErrorBadValue&)
{ {
std::cout << " Caught exception for unrecognized type." << std::endl; std::cout << " Caught exception for unrecognized type." << std::endl;
} }
CheckArrayVariant(array.ResetTypes(vtkm::List<UnusualType>()), 1, true);
CheckArrayVariant(array.ResetTypes(TypeListString()), 1, true, false);
std::cout << " Found type when type list was reset." << std::endl; std::cout << " Found type when type list was reset." << std::endl;
} }
void TryUnusualStorage()
{
vtkm::cont::VariantArrayHandle array = ArrayHandleWithUnusualStorage<vtkm::Id>();
try
{
CheckArrayVariant(array, 1, false, true);
}
catch (...)
{
VTKM_TEST_FAIL("CastAndCall with Variant failed to handle unusual storage.");
}
}
void TryUnusualTypeAndStorage()
{
vtkm::cont::VariantArrayHandle array = ArrayHandleWithUnusualStorage<std::string>();
try
{
CheckArrayVariant(array, 1, false, true);
VTKM_TEST_FAIL("CastAndCall failed to error for unrecognized type/storage.");
}
catch (vtkm::cont::ErrorBadValue&)
{
std::cout << " Caught exception for unrecognized type/storage." << std::endl;
}
try
{
CheckArrayVariant(array.ResetTypes(TypeListString()), 1, false, true);
}
catch (...)
{
VTKM_TEST_FAIL("CastAndCall with Variant failed to handle unusual storage.");
}
}
template <typename ArrayHandleType> template <typename ArrayHandleType>
void TryCastToArrayHandle(const ArrayHandleType& array) void TryCastToArrayHandle(const ArrayHandleType& array)
{ {
@ -523,7 +458,8 @@ void TryCastToArrayHandle()
buffer[index] = TestValue(index, vtkm::Id()); buffer[index] = TestValue(index, vtkm::Id());
} }
vtkm::cont::ArrayHandle<vtkm::Id> array = vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE); vtkm::cont::ArrayHandle<vtkm::Id> array =
vtkm::cont::make_ArrayHandle(buffer, ARRAY_SIZE, vtkm::CopyFlag::On);
TryCastToArrayHandle(array); TryCastToArrayHandle(array);
std::cout << " Cast array handle." << std::endl; std::cout << " Cast array handle." << std::endl;
@ -586,12 +522,6 @@ void TestVariantArrayHandle()
std::cout << "Try unusual type." << std::endl; std::cout << "Try unusual type." << std::endl;
TryUnusualType(); TryUnusualType();
std::cout << "Try unusual storage." << std::endl;
TryUnusualStorage();
std::cout << "Try unusual type in unusual storage." << std::endl;
TryUnusualTypeAndStorage();
std::cout << "Try CastToArrayHandle" << std::endl; std::cout << "Try CastToArrayHandle" << std::endl;
TryCastToArrayHandle(); TryCastToArrayHandle();
} }

@ -13,7 +13,7 @@
#include <vtkm/TopologyElementTag.h> #include <vtkm/TopologyElementTag.h>
#include <vtkm/VecFromPortalPermute.h> #include <vtkm/VecFromPortalPermute.h>
#include <vtkm/cont/ArrayHandle.h> #include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleVirtualCoordinates.h> #include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/exec/CellInside.h> #include <vtkm/exec/CellInside.h>
#include <vtkm/exec/CellLocator.h> #include <vtkm/exec/CellLocator.h>
#include <vtkm/exec/ParametricCoordinates.h> #include <vtkm/exec/ParametricCoordinates.h>
@ -74,12 +74,13 @@ public:
CellLocatorBoundingIntervalHierarchyExec() {} CellLocatorBoundingIntervalHierarchyExec() {}
VTKM_CONT VTKM_CONT
CellLocatorBoundingIntervalHierarchyExec(const NodeArrayHandle& nodes, CellLocatorBoundingIntervalHierarchyExec(
const CellIdArrayHandle& cellIds, const NodeArrayHandle& nodes,
const CellSetType& cellSet, const CellIdArrayHandle& cellIds,
const vtkm::cont::ArrayHandleVirtualCoordinates& coords, const CellSetType& cellSet,
DeviceAdapter, const vtkm::cont::CoordinateSystem::MultiplexerArrayType& coords,
vtkm::cont::Token& token) DeviceAdapter,
vtkm::cont::Token& token)
: Nodes(nodes.PrepareForInput(DeviceAdapter(), token)) : Nodes(nodes.PrepareForInput(DeviceAdapter(), token))
, CellIds(cellIds.PrepareForInput(DeviceAdapter(), token)) , CellIds(cellIds.PrepareForInput(DeviceAdapter(), token))
, CellSet(cellSet.PrepareForInput(DeviceAdapter(), VisitType(), IncidentType(), token)) , CellSet(cellSet.PrepareForInput(DeviceAdapter(), VisitType(), IncidentType(), token))
@ -277,8 +278,9 @@ private:
using CellSetPortal = typename CellSetType::template ExecutionTypes<DeviceAdapter, using CellSetPortal = typename CellSetType::template ExecutionTypes<DeviceAdapter,
VisitType, VisitType,
IncidentType>::ExecObjectType; IncidentType>::ExecObjectType;
using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes< using CoordsPortal =
DeviceAdapter>::PortalConst; typename vtkm::cont::CoordinateSystem::MultiplexerArrayType::template ExecutionTypes<
DeviceAdapter>::PortalConst;
NodePortal Nodes; NodePortal Nodes;
CellIdPortal CellIds; CellIdPortal CellIds;

@ -34,8 +34,6 @@ private:
using VisitType = vtkm::TopologyElementTagCell; using VisitType = vtkm::TopologyElementTagCell;
using IncidentType = vtkm::TopologyElementTagPoint; using IncidentType = vtkm::TopologyElementTagPoint;
using CellSetPortal = vtkm::exec::ConnectivityStructured<VisitType, IncidentType, dimensions>; using CellSetPortal = vtkm::exec::ConnectivityStructured<VisitType, IncidentType, dimensions>;
using CoordsPortal = typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes<
DeviceAdapter>::PortalConst;
public: public:
VTKM_CONT VTKM_CONT
@ -44,15 +42,12 @@ public:
const vtkm::Vec3f origin, const vtkm::Vec3f origin,
const vtkm::Vec3f invSpacing, const vtkm::Vec3f invSpacing,
const vtkm::Vec3f maxPoint, const vtkm::Vec3f maxPoint,
const vtkm::cont::ArrayHandleVirtualCoordinates& coords, DeviceAdapter)
DeviceAdapter,
vtkm::cont::Token& token)
: CellDims(cellDims) : CellDims(cellDims)
, PointDims(pointDims) , PointDims(pointDims)
, Origin(origin) , Origin(origin)
, InvSpacing(invSpacing) , InvSpacing(invSpacing)
, MaxPoint(maxPoint) , MaxPoint(maxPoint)
, Coords(coords.PrepareForInput(DeviceAdapter(), token))
{ {
} }
@ -120,7 +115,6 @@ private:
vtkm::Vec3f Origin; vtkm::Vec3f Origin;
vtkm::Vec3f InvSpacing; vtkm::Vec3f InvSpacing;
vtkm::Vec3f MaxPoint; vtkm::Vec3f MaxPoint;
CoordsPortal Coords;
}; };
} }
} }

@ -115,6 +115,12 @@ public:
return this->Internals.GetPointDimensions(); return this->Internals.GetPointDimensions();
} }
VTKM_EXEC_CONT
vtkm::Vec<vtkm::Id, Dimension> GetCellDimensions() const
{
return this->Internals.GetCellDimensions();
}
VTKM_EXEC_CONT VTKM_EXEC_CONT
SchedulingRangeType GetGlobalPointIndexStart() const SchedulingRangeType GetGlobalPointIndexStart() const
{ {

@ -27,7 +27,7 @@ namespace exec
/// be returned determined by the boundary behavior. A \c BoundaryState object can be used to /// be returned determined by the boundary behavior. A \c BoundaryState object can be used to
/// determine if the neighborhood extends beyond the boundary of the mesh. /// determine if the neighborhood extends beyond the boundary of the mesh.
/// ///
/// This class is typically constructued using the \c FieldInNeighborhood tag in an /// This class is typically constructed using the \c FieldInNeighborhood tag in an
/// \c ExecutionSignature. There is little reason to construct this in user code. /// \c ExecutionSignature. There is little reason to construct this in user code.
/// ///
/// \c FieldNeighborhood is templated on the array portal from which field values are retrieved. /// \c FieldNeighborhood is templated on the array portal from which field values are retrieved.

@ -10,6 +10,7 @@
#ifndef vtk_m_exec_PointLocatorUniformGrid_h #ifndef vtk_m_exec_PointLocatorUniformGrid_h
#define vtk_m_exec_PointLocatorUniformGrid_h #define vtk_m_exec_PointLocatorUniformGrid_h
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/DeviceAdapter.h> #include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h> #include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/worklet/DispatcherMapField.h> #include <vtkm/worklet/DispatcherMapField.h>
@ -29,7 +30,7 @@ class VTKM_ALWAYS_EXPORT PointLocatorUniformGrid final : public vtkm::exec::Poin
{ {
public: public:
using CoordPortalType = using CoordPortalType =
typename vtkm::cont::ArrayHandleVirtualCoordinates::template ExecutionTypes< typename vtkm::cont::CoordinateSystem::MultiplexerArrayType::template ExecutionTypes<
DeviceAdapter>::PortalConst; DeviceAdapter>::PortalConst;
using IdPortalType = using IdPortalType =
typename vtkm::cont::ArrayHandle<vtkm::Id>::template ExecutionTypes<DeviceAdapter>::PortalConst; typename vtkm::cont::ArrayHandle<vtkm::Id>::template ExecutionTypes<DeviceAdapter>::PortalConst;

@ -33,6 +33,8 @@ set(headers
ThreadIndicesBasic.h ThreadIndicesBasic.h
ThreadIndicesBasic3D.h ThreadIndicesBasic3D.h
ThreadIndicesExtrude.h ThreadIndicesExtrude.h
ThreadIndicesNeighborhood.h
ThreadIndicesCellNeighborhood.h
ThreadIndicesPointNeighborhood.h ThreadIndicesPointNeighborhood.h
ThreadIndicesReduceByKey.h ThreadIndicesReduceByKey.h
ThreadIndicesTopologyMap.h ThreadIndicesTopologyMap.h

@ -0,0 +1,90 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// 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.
//============================================================================
#ifndef vtk_m_exec_arg_ThreadIndicesCellNeighborhood_h
#define vtk_m_exec_arg_ThreadIndicesCellNeighborhood_h
#include <vtkm/exec/BoundaryState.h>
#include <vtkm/exec/ConnectivityStructured.h>
#include <vtkm/exec/arg/ThreadIndicesBasic.h>
#include <vtkm/exec/arg/ThreadIndicesNeighborhood.h>
#include <vtkm/exec/arg/ThreadIndicesTopologyMap.h> //for Deflate and Inflate
#include <vtkm/Math.h>
namespace vtkm
{
namespace exec
{
namespace arg
{
/// \brief Container for thread information in a WorkletCellNeighborhood.
///
///
class ThreadIndicesCellNeighborhood : public vtkm::exec::arg::ThreadIndicesNeighborhood
{
using Superclass = vtkm::exec::arg::ThreadIndicesNeighborhood;
public:
template <vtkm::IdComponent Dimension>
VTKM_EXEC ThreadIndicesCellNeighborhood(
const vtkm::Id3& threadIndex3D,
vtkm::Id threadIndex1D,
const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
Dimension>& connectivity)
: Superclass(
threadIndex1D,
vtkm::exec::BoundaryState{ threadIndex3D, detail::To3D(connectivity.GetCellDimensions()) })
{
}
template <vtkm::IdComponent Dimension>
VTKM_EXEC ThreadIndicesCellNeighborhood(
const vtkm::Id3& threadIndex3D,
vtkm::Id threadIndex1D,
vtkm::Id inputIndex,
vtkm::IdComponent visitIndex,
vtkm::Id outputIndex,
const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
Dimension>& connectivity)
: Superclass(
threadIndex1D,
inputIndex,
visitIndex,
outputIndex,
vtkm::exec::BoundaryState{ threadIndex3D, detail::To3D(connectivity.GetCellDimensions()) })
{
}
template <vtkm::IdComponent Dimension>
VTKM_EXEC ThreadIndicesCellNeighborhood(
vtkm::Id threadIndex,
vtkm::Id inputIndex,
vtkm::IdComponent visitIndex,
vtkm::Id outputIndex,
const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell,
Dimension>& connectivity)
: Superclass(
threadIndex,
inputIndex,
visitIndex,
outputIndex,
vtkm::exec::BoundaryState{ detail::To3D(connectivity.FlatToLogicalToIndex(inputIndex)),
detail::To3D(connectivity.GetCellDimensions()) })
{
}
};
}
}
} // namespace vtkm::exec::arg
#endif //vtk_m_exec_arg_ThreadIndicesCellNeighborhood_h

@ -0,0 +1,115 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// 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.
//============================================================================
#ifndef vtk_m_exec_arg_ThreadIndicesNeighborhood_h
#define vtk_m_exec_arg_ThreadIndicesNeighborhood_h
#include <vtkm/exec/BoundaryState.h>
#include <vtkm/exec/ConnectivityStructured.h>
#include <vtkm/exec/arg/ThreadIndicesBasic.h>
#include <vtkm/exec/arg/ThreadIndicesTopologyMap.h> //for Deflate and Inflate
#include <vtkm/Math.h>
namespace vtkm
{
namespace exec
{
namespace arg
{
namespace detail
{
/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros.
///
inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Id3 index)
{
return index;
}
/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros.
/// \overload
inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Id2 index)
{
return vtkm::Id3(index[0], index[1], 1);
}
/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros.
/// \overload
inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Vec<vtkm::Id, 1> index)
{
return vtkm::Id3(index[0], 1, 1);
}
/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros.
/// \overload
inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Id index)
{
return vtkm::Id3(index, 1, 1);
}
}
class ThreadIndicesNeighborhood
{
public:
VTKM_EXEC ThreadIndicesNeighborhood(vtkm::Id threadIndex1D,
const vtkm::exec::BoundaryState& state)
: State(state)
, ThreadIndex(threadIndex1D)
, InputIndex(threadIndex1D)
, OutputIndex(threadIndex1D)
, VisitIndex(0)
{
}
VTKM_EXEC ThreadIndicesNeighborhood(vtkm::Id threadIndex1D,
vtkm::Id inputIndex,
vtkm::IdComponent visitIndex,
vtkm::Id outputIndex,
const vtkm::exec::BoundaryState& state)
: State(state)
, ThreadIndex(threadIndex1D)
, InputIndex(inputIndex)
, OutputIndex(outputIndex)
, VisitIndex(visitIndex)
{
}
VTKM_EXEC
const vtkm::exec::BoundaryState& GetBoundaryState() const { return this->State; }
VTKM_EXEC
vtkm::Id GetThreadIndex() const { return this->ThreadIndex; }
VTKM_EXEC
vtkm::Id GetInputIndex() const { return this->InputIndex; }
VTKM_EXEC
vtkm::Id3 GetInputIndex3D() const { return this->State.IJK; }
VTKM_EXEC
vtkm::Id GetOutputIndex() const { return this->OutputIndex; }
VTKM_EXEC
vtkm::IdComponent GetVisitIndex() const { return this->VisitIndex; }
private:
vtkm::exec::BoundaryState State;
vtkm::Id ThreadIndex;
vtkm::Id InputIndex;
vtkm::Id OutputIndex;
vtkm::IdComponent VisitIndex;
};
}
}
} // namespace vtkm::exec::arg
#endif //vtk_m_exec_arg_ThreadIndicesNeighborhood_h

@ -10,12 +10,7 @@
#ifndef vtk_m_exec_arg_ThreadIndicesPointNeighborhood_h #ifndef vtk_m_exec_arg_ThreadIndicesPointNeighborhood_h
#define vtk_m_exec_arg_ThreadIndicesPointNeighborhood_h #define vtk_m_exec_arg_ThreadIndicesPointNeighborhood_h
#include <vtkm/exec/BoundaryState.h> #include <vtkm/exec/arg/ThreadIndicesNeighborhood.h>
#include <vtkm/exec/ConnectivityStructured.h>
#include <vtkm/exec/arg/ThreadIndicesBasic.h>
#include <vtkm/exec/arg/ThreadIndicesTopologyMap.h> //for Deflate and Inflate
#include <vtkm/Math.h>
namespace vtkm namespace vtkm
{ {
@ -23,43 +18,12 @@ namespace exec
{ {
namespace arg namespace arg
{ {
namespace detail
{
/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros.
///
inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Id3 index)
{
return index;
}
/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros.
/// \overload
inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Id2 index)
{
return vtkm::Id3(index[0], index[1], 1);
}
/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros.
/// \overload
inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Vec<vtkm::Id, 1> index)
{
return vtkm::Id3(index[0], 1, 1);
}
/// Given a \c Vec of (semi) arbitrary size, inflate it to a vtkm::Id3 by padding with zeros.
/// \overload
inline VTKM_EXEC vtkm::Id3 To3D(vtkm::Id index)
{
return vtkm::Id3(index, 1, 1);
}
}
/// \brief Container for thread information in a WorkletPointNeighborhood. /// \brief Container for thread information in a WorkletPointNeighborhood.
/// ///
/// ///
class ThreadIndicesPointNeighborhood class ThreadIndicesPointNeighborhood : public vtkm::exec::arg::ThreadIndicesNeighborhood
{ {
using Superclass = vtkm::exec::arg::ThreadIndicesNeighborhood;
public: public:
template <vtkm::IdComponent Dimension> template <vtkm::IdComponent Dimension>
@ -69,11 +33,9 @@ public:
const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint, const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell, vtkm::TopologyElementTagCell,
Dimension>& connectivity) Dimension>& connectivity)
: State(threadIndex3D, detail::To3D(connectivity.GetPointDimensions())) : Superclass(
, ThreadIndex(threadIndex1D) threadIndex1D,
, InputIndex(threadIndex1D) vtkm::exec::BoundaryState{ threadIndex3D, detail::To3D(connectivity.GetPointDimensions()) })
, OutputIndex(threadIndex1D)
, VisitIndex(0)
{ {
} }
@ -87,11 +49,12 @@ public:
const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint, const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell, vtkm::TopologyElementTagCell,
Dimension>& connectivity) Dimension>& connectivity)
: State(threadIndex3D, detail::To3D(connectivity.GetPointDimensions())) : Superclass(
, ThreadIndex(threadIndex1D) threadIndex1D,
, InputIndex(inputIndex) inputIndex,
, OutputIndex(outputIndex) visitIndex,
, VisitIndex(visitIndex) outputIndex,
vtkm::exec::BoundaryState{ threadIndex3D, detail::To3D(connectivity.GetPointDimensions()) })
{ {
} }
@ -104,42 +67,17 @@ public:
const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint, const vtkm::exec::ConnectivityStructured<vtkm::TopologyElementTagPoint,
vtkm::TopologyElementTagCell, vtkm::TopologyElementTagCell,
Dimension>& connectivity) Dimension>& connectivity)
: State(detail::To3D(connectivity.FlatToLogicalToIndex(inputIndex)), : Superclass(
detail::To3D(connectivity.GetPointDimensions())) threadIndex,
, ThreadIndex(threadIndex) inputIndex,
, InputIndex(inputIndex) visitIndex,
, OutputIndex(outputIndex) outputIndex,
, VisitIndex(visitIndex) vtkm::exec::BoundaryState{ detail::To3D(connectivity.FlatToLogicalToIndex(inputIndex)),
detail::To3D(connectivity.GetPointDimensions()) })
{ {
} }
VTKM_EXEC
const vtkm::exec::BoundaryState& GetBoundaryState() const { return this->State; }
VTKM_EXEC
vtkm::Id GetThreadIndex() const { return this->ThreadIndex; }
VTKM_EXEC
vtkm::Id GetInputIndex() const { return this->InputIndex; }
VTKM_EXEC
vtkm::Id3 GetInputIndex3D() const { return this->State.IJK; }
VTKM_EXEC
vtkm::Id GetOutputIndex() const { return this->OutputIndex; }
VTKM_EXEC
vtkm::IdComponent GetVisitIndex() const { return this->VisitIndex; }
private:
vtkm::exec::BoundaryState State;
vtkm::Id ThreadIndex;
vtkm::Id InputIndex;
vtkm::Id OutputIndex;
vtkm::IdComponent VisitIndex;
}; };
} } // arg
} } // exec
} // namespace vtkm::exec::arg } // vtkm
#endif //vtk_m_exec_arg_ThreadIndicesPointNeighborhood_h #endif //vtk_m_exec_arg_ThreadIndicesPointNeighborhood_h

@ -35,7 +35,7 @@ public:
VTKM_CONT VTKM_CONT
CellMeasures(); CellMeasures();
/// Set/Get the name of the cell measure field. If empty, "measure" is used. /// Set/Get the name of the cell measure field. If not set, "measure" is used.
void SetCellMeasureName(const std::string& name) { this->SetOutputFieldName(name); } void SetCellMeasureName(const std::string& name) { this->SetOutputFieldName(name); }
const std::string& GetCellMeasureName() const { return this->GetOutputFieldName(); } const std::string& GetCellMeasureName() const { return this->GetOutputFieldName(); }

@ -25,6 +25,7 @@ inline VTKM_CONT CellMeasures<IntegrationType>::CellMeasures()
: vtkm::filter::FilterCell<CellMeasures<IntegrationType>>() : vtkm::filter::FilterCell<CellMeasures<IntegrationType>>()
{ {
this->SetUseCoordinateSystemAsField(true); this->SetUseCoordinateSystemAsField(true);
this->SetCellMeasureName("measure");
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

@ -108,6 +108,8 @@ VTKM_FILTER_EXPORT_EXECUTE_METHOD(ClipWithField);
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#ifndef vtk_m_filter_ClipWithField_hxx
#include <vtkm/filter/ClipWithField.hxx> #include <vtkm/filter/ClipWithField.hxx>
#endif
#endif // vtk_m_filter_ClipWithField_h #endif // vtk_m_filter_ClipWithField_h

@ -11,6 +11,8 @@
#ifndef vtk_m_filter_ClipWithField_hxx #ifndef vtk_m_filter_ClipWithField_hxx
#define vtk_m_filter_ClipWithField_hxx #define vtk_m_filter_ClipWithField_hxx
#include <vtkm/filter/ClipWithField.h>
#include <vtkm/cont/ArrayHandlePermutation.h> #include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h> #include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/CoordinateSystem.h> #include <vtkm/cont/CoordinateSystem.h>
@ -21,6 +23,26 @@ namespace vtkm
{ {
namespace filter namespace filter
{ {
namespace detail
{
struct ClipWithFieldProcessCoords
{
template <typename T, typename Storage>
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, Storage>& inCoords,
const std::string& coordsName,
const vtkm::worklet::Clip& worklet,
vtkm::cont::DataSet& output) const
{
vtkm::cont::ArrayHandle<T> outArray = worklet.ProcessPointField(inCoords);
vtkm::cont::CoordinateSystem outCoords(coordsName, outArray);
output.AddCoordinateSystem(outCoords);
}
};
} // namespace detail
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute( inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute(
@ -37,9 +59,6 @@ inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute(
//get the cells and coordinates of the dataset //get the cells and coordinates of the dataset
const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(); const vtkm::cont::DynamicCellSet& cells = input.GetCellSet();
const vtkm::cont::CoordinateSystem& inputCoords =
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
vtkm::cont::CellSetExplicit<> outputCellSet = this->Worklet.Run( vtkm::cont::CellSetExplicit<> outputCellSet = this->Worklet.Run(
vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), field, this->ClipValue, this->Invert); vtkm::filter::ApplyPolicyCellSet(cells, policy, *this), field, this->ClipValue, this->Invert);
@ -48,9 +67,14 @@ inline VTKM_CONT vtkm::cont::DataSet ClipWithField::DoExecute(
output.SetCellSet(outputCellSet); output.SetCellSet(outputCellSet);
// Compute the new boundary points and add them to the output: // Compute the new boundary points and add them to the output:
auto outputCoordsArray = this->Worklet.ProcessPointField(inputCoords.GetData()); for (vtkm::IdComponent coordSystemId = 0; coordSystemId < input.GetNumberOfCoordinateSystems();
vtkm::cont::CoordinateSystem outputCoords(inputCoords.GetName(), outputCoordsArray); ++coordSystemId)
output.AddCoordinateSystem(outputCoords); {
vtkm::cont::CoordinateSystem coords = input.GetCoordinateSystem(coordSystemId);
coords.GetData().CastAndCall(
detail::ClipWithFieldProcessCoords{}, coords.GetName(), this->Worklet, output);
}
return output; return output;
} }
} }

@ -105,6 +105,8 @@ VTKM_FILTER_EXPORT_EXECUTE_METHOD(ClipWithImplicitFunction);
} }
} // namespace vtkm::filter } // namespace vtkm::filter
#ifndef vtk_m_filter_ClipWithImplicitFunction_hxx
#include <vtkm/filter/ClipWithImplicitFunction.hxx> #include <vtkm/filter/ClipWithImplicitFunction.hxx>
#endif
#endif // vtk_m_filter_ClipWithImplicitFunction_h #endif // vtk_m_filter_ClipWithImplicitFunction_h

@ -11,6 +11,8 @@
#ifndef vtk_m_filter_ClipWithImplicitFunction_hxx #ifndef vtk_m_filter_ClipWithImplicitFunction_hxx
#define vtk_m_filter_ClipWithImplicitFunction_hxx #define vtk_m_filter_ClipWithImplicitFunction_hxx
#include <vtkm/filter/ClipWithImplicitFunction.h>
#include <vtkm/cont/ArrayHandlePermutation.h> #include <vtkm/cont/ArrayHandlePermutation.h>
#include <vtkm/cont/CellSetPermutation.h> #include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/DynamicCellSet.h> #include <vtkm/cont/DynamicCellSet.h>
@ -19,6 +21,26 @@ namespace vtkm
{ {
namespace filter namespace filter
{ {
namespace detail
{
struct ClipWithImplicitFunctionProcessCoords
{
template <typename T, typename Storage>
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, Storage>& inCoords,
const std::string& coordsName,
const vtkm::worklet::Clip& worklet,
vtkm::cont::DataSet& output) const
{
vtkm::cont::ArrayHandle<T> outArray = worklet.ProcessPointField(inCoords);
vtkm::cont::CoordinateSystem outCoords(coordsName, outArray);
output.AddCoordinateSystem(outCoords);
}
};
} // namespace detail
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename DerivedPolicy> template <typename DerivedPolicy>
inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute( inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute(
@ -37,14 +59,18 @@ inline vtkm::cont::DataSet ClipWithImplicitFunction::DoExecute(
inputCoords, inputCoords,
this->Invert); this->Invert);
// compute output coordinates
auto outputCoordsArray = this->Worklet.ProcessPointField(inputCoords.GetData());
vtkm::cont::CoordinateSystem outputCoords(inputCoords.GetName(), outputCoordsArray);
//create the output data //create the output data
vtkm::cont::DataSet output; vtkm::cont::DataSet output;
output.SetCellSet(outputCellSet); output.SetCellSet(outputCellSet);
output.AddCoordinateSystem(outputCoords);
// compute output coordinates
for (vtkm::IdComponent coordSystemId = 0; coordSystemId < input.GetNumberOfCoordinateSystems();
++coordSystemId)
{
vtkm::cont::CoordinateSystem coords = input.GetCoordinateSystem(coordSystemId);
coords.GetData().CastAndCall(
detail::ClipWithImplicitFunctionProcessCoords{}, coords.GetName(), this->Worklet, output);
}
return output; return output;
} }

@ -12,6 +12,7 @@
#define vtk_m_filter_ImageMedian_hxx #define vtk_m_filter_ImageMedian_hxx
#include <vtkm/Swap.h> #include <vtkm/Swap.h>
#include <vtkm/worklet/WorkletPointNeighborhood.h>
namespace vtkm namespace vtkm
{ {

@ -23,6 +23,7 @@
#include <vtkm/cont/ErrorFilterExecution.h> #include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/worklet/ParticleAdvection.h> #include <vtkm/worklet/ParticleAdvection.h>
#include <vtkm/worklet/WorkletMapField.h> #include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/particleadvection/Field.h>
#include <vtkm/worklet/particleadvection/GridEvaluators.h> #include <vtkm/worklet/particleadvection/GridEvaluators.h>
#include <vtkm/worklet/particleadvection/Integrators.h> #include <vtkm/worklet/particleadvection/Integrators.h>
#include <vtkm/worklet/particleadvection/Particles.h> #include <vtkm/worklet/particleadvection/Particles.h>
@ -32,8 +33,8 @@
#include <string.h> #include <string.h>
static vtkm::Id cycle = 0; static vtkm::Id cycle = 0;
static vtkm::cont::ArrayHandle<vtkm::Particle> BasisParticles; static vtkm::cont::ArrayHandle<vtkm::Massless> BasisParticles;
static vtkm::cont::ArrayHandle<vtkm::Particle> BasisParticlesOriginal; static vtkm::cont::ArrayHandle<vtkm::Massless> BasisParticlesOriginal;
static vtkm::cont::ArrayHandle<vtkm::Id> BasisParticlesValidity; static vtkm::cont::ArrayHandle<vtkm::Id> BasisParticlesValidity;
namespace namespace
@ -51,7 +52,7 @@ public:
} }
template <typename ValidityType> template <typename ValidityType>
VTKM_EXEC void operator()(const vtkm::Particle& end_point, ValidityType& res) const VTKM_EXEC void operator()(const vtkm::Massless& end_point, ValidityType& res) const
{ {
vtkm::Id steps = end_point.NumSteps; vtkm::Id steps = end_point.NumSteps;
if (steps > 0 && res == 1) if (steps > 0 && res == 1)
@ -83,8 +84,8 @@ public:
using InputDomain = _1; using InputDomain = _1;
template <typename DisplacementType> template <typename DisplacementType>
VTKM_EXEC void operator()(const vtkm::Particle& end_point, VTKM_EXEC void operator()(const vtkm::Massless& end_point,
const vtkm::Particle& start_point, const vtkm::Massless& start_point,
DisplacementType& res) const DisplacementType& res) const
{ {
res[0] = end_point.Pos[0] - start_point.Pos[0]; res[0] = end_point.Pos[0] - start_point.Pos[0];
@ -193,7 +194,7 @@ inline void Lagrangian::InitializeSeedPositions(const vtkm::cont::DataSet& input
{ {
vtkm::FloatDefault xi = static_cast<vtkm::FloatDefault>(x * x_spacing); vtkm::FloatDefault xi = static_cast<vtkm::FloatDefault>(x * x_spacing);
portal1.Set(id, portal1.Set(id,
vtkm::Particle(Vec3f(static_cast<vtkm::FloatDefault>(bounds.X.Min) + xi, vtkm::Massless(Vec3f(static_cast<vtkm::FloatDefault>(bounds.X.Min) + xi,
static_cast<vtkm::FloatDefault>(bounds.Y.Min) + yi, static_cast<vtkm::FloatDefault>(bounds.Y.Min) + yi,
static_cast<vtkm::FloatDefault>(bounds.Z.Min) + zi), static_cast<vtkm::FloatDefault>(bounds.Z.Min) + zi),
id)); id));
@ -264,7 +265,7 @@ inline VTKM_CONT vtkm::cont::DataSet Lagrangian::DoExecute(
throw vtkm::cont::ErrorFilterExecution( throw vtkm::cont::ErrorFilterExecution(
"Write frequency can not be 0. Use SetWriteFrequency()."); "Write frequency can not be 0. Use SetWriteFrequency().");
} }
vtkm::cont::ArrayHandle<vtkm::Particle> basisParticleArray; vtkm::cont::ArrayHandle<vtkm::Massless> basisParticleArray;
vtkm::cont::ArrayCopy(BasisParticles, basisParticleArray); vtkm::cont::ArrayCopy(BasisParticles, basisParticleArray);
cycle += 1; cycle += 1;
@ -274,12 +275,14 @@ inline VTKM_CONT vtkm::cont::DataSet Lagrangian::DoExecute(
vtkm::Bounds bounds = input.GetCoordinateSystem().GetBounds(); vtkm::Bounds bounds = input.GetCoordinateSystem().GetBounds();
using FieldHandle = vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>; using FieldHandle = vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>;
using GridEvalType = vtkm::worklet::particleadvection::GridEvaluator<FieldHandle>; using FieldType = vtkm::worklet::particleadvection::VelocityField<FieldHandle>;
using GridEvalType = vtkm::worklet::particleadvection::GridEvaluator<FieldType>;
using RK4Type = vtkm::worklet::particleadvection::RK4Integrator<GridEvalType>; using RK4Type = vtkm::worklet::particleadvection::RK4Integrator<GridEvalType>;
vtkm::worklet::ParticleAdvection particleadvection; vtkm::worklet::ParticleAdvection particleadvection;
vtkm::worklet::ParticleAdvectionResult res; vtkm::worklet::ParticleAdvectionResult<vtkm::Massless> res;
GridEvalType gridEval(coords, cells, field); FieldType velocities(field);
GridEvalType gridEval(coords, cells, velocities);
RK4Type rk4(gridEval, static_cast<vtkm::Float32>(this->stepSize)); RK4Type rk4(gridEval, static_cast<vtkm::Float32>(this->stepSize));
res = particleadvection.Run(rk4, basisParticleArray, 1); // Taking a single step res = particleadvection.Run(rk4, basisParticleArray, 1); // Taking a single step

@ -14,6 +14,7 @@
#include <vtkm/cont/ArrayHandleIndex.h> #include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/ErrorFilterExecution.h> #include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/cont/Invoker.h> #include <vtkm/cont/Invoker.h>
#include <vtkm/worklet/particleadvection/Field.h>
#include <vtkm/worklet/particleadvection/GridEvaluators.h> #include <vtkm/worklet/particleadvection/GridEvaluators.h>
#include <vtkm/worklet/particleadvection/Integrators.h> #include <vtkm/worklet/particleadvection/Integrators.h>
#include <vtkm/worklet/particleadvection/Particles.h> #include <vtkm/worklet/particleadvection/Particles.h>
@ -34,12 +35,28 @@ public:
using ExecutionSignature = void(_1, _2); using ExecutionSignature = void(_1, _2);
using InputDomain = _1; using InputDomain = _1;
VTKM_EXEC void operator()(const vtkm::Particle& particle, vtkm::Vec3f& pt) const VTKM_EXEC void operator()(const vtkm::Massless& particle, vtkm::Vec3f& pt) const
{ {
pt = particle.Pos; pt = particle.Pos;
} }
}; };
class MakeParticles : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn seed, FieldOut particle);
using ExecutionSignature = void(WorkIndex, _1, _2);
using InputDomain = _1;
VTKM_EXEC void operator()(const vtkm::Id index,
const vtkm::Vec3f& seed,
vtkm::Massless& particle) const
{
particle.ID = index;
particle.Pos = seed;
}
};
} //detail } //detail
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -66,7 +83,8 @@ inline VTKM_CONT vtkm::cont::DataSet LagrangianStructures::DoExecute(
using Structured3DType = vtkm::cont::CellSetStructured<3>; using Structured3DType = vtkm::cont::CellSetStructured<3>;
using FieldHandle = vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>; using FieldHandle = vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>;
using GridEvaluator = vtkm::worklet::particleadvection::GridEvaluator<FieldHandle>; using FieldType = vtkm::worklet::particleadvection::VelocityField<FieldHandle>;
using GridEvaluator = vtkm::worklet::particleadvection::GridEvaluator<FieldType>;
using Integrator = vtkm::worklet::particleadvection::RK4Integrator<GridEvaluator>; using Integrator = vtkm::worklet::particleadvection::RK4Integrator<GridEvaluator>;
vtkm::FloatDefault stepSize = this->GetStepSize(); vtkm::FloatDefault stepSize = this->GetStepSize();
@ -115,15 +133,16 @@ inline VTKM_CONT vtkm::cont::DataSet LagrangianStructures::DoExecute(
} }
else else
{ {
GridEvaluator evaluator(input.GetCoordinateSystem(), input.GetCellSet(), field); vtkm::cont::Invoker invoke;
FieldType velocities(field);
GridEvaluator evaluator(input.GetCoordinateSystem(), input.GetCellSet(), velocities);
Integrator integrator(evaluator, stepSize); Integrator integrator(evaluator, stepSize);
vtkm::worklet::ParticleAdvection particles; vtkm::worklet::ParticleAdvection particles;
vtkm::worklet::ParticleAdvectionResult advectionResult; vtkm::worklet::ParticleAdvectionResult<vtkm::Massless> advectionResult;
vtkm::cont::ArrayHandle<vtkm::Vec3f> advectionPoints; vtkm::cont::ArrayHandle<vtkm::Massless> advectionPoints;
vtkm::cont::ArrayCopy(lcsInputPoints, advectionPoints); invoke(detail::MakeParticles{}, lcsInputPoints, advectionPoints);
advectionResult = particles.Run(integrator, advectionPoints, numberOfSteps); advectionResult = particles.Run(integrator, advectionPoints, numberOfSteps);
vtkm::cont::Invoker invoke;
invoke(detail::ExtractParticlePosition{}, advectionResult.Particles, lcsOutputPoints); invoke(detail::ExtractParticlePosition{}, advectionResult.Particles, lcsOutputPoints);
} }
// FTLE output field // FTLE output field

@ -39,7 +39,7 @@ public:
void SetNumberOfSteps(vtkm::Id n) { this->NumberOfSteps = n; } void SetNumberOfSteps(vtkm::Id n) { this->NumberOfSteps = n; }
VTKM_CONT VTKM_CONT
void SetSeeds(vtkm::cont::ArrayHandle<vtkm::Particle>& seeds); void SetSeeds(vtkm::cont::ArrayHandle<vtkm::Massless>& seeds);
template <typename T, typename StorageType, typename DerivedPolicy> template <typename T, typename StorageType, typename DerivedPolicy>
VTKM_CONT vtkm::cont::DataSet DoExecute( VTKM_CONT vtkm::cont::DataSet DoExecute(
@ -56,7 +56,7 @@ public:
private: private:
vtkm::Id NumberOfSteps; vtkm::Id NumberOfSteps;
vtkm::FloatDefault StepSize; vtkm::FloatDefault StepSize;
vtkm::cont::ArrayHandle<vtkm::Particle> Seeds; vtkm::cont::ArrayHandle<vtkm::Massless> Seeds;
vtkm::worklet::ParticleAdvection Worklet; vtkm::worklet::ParticleAdvection Worklet;
}; };
} }

Some files were not shown because too many files have changed in this diff Show More