Merge branch 'master' of https://gitlab.kitware.com/vtk/vtk-m into fix_advection_error
This commit is contained in:
commit
7ce3d72dd1
3
data/sample.cosmotools
Normal file
3
data/sample.cosmotools
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:9dc63465d864ec7a4546f1d006ca0153a5bb4c78fd4a42d16ad1177dabc70d75
|
||||||
|
size 80263
|
@ -25,9 +25,10 @@ set(CMAKE_PREFIX_PATH ${VTKm_BINARY_DIR}/${VTKm_INSTALL_CONFIG_DIR})
|
|||||||
|
|
||||||
add_subdirectory(clipping)
|
add_subdirectory(clipping)
|
||||||
add_subdirectory(contour_tree)
|
add_subdirectory(contour_tree)
|
||||||
|
add_subdirectory(cosmotools)
|
||||||
add_subdirectory(demo)
|
add_subdirectory(demo)
|
||||||
add_subdirectory(dynamic_dispatcher)
|
add_subdirectory(dynamic_dispatcher)
|
||||||
add_subdirectory(game_of_life)
|
#add_subdirectory(game_of_life)
|
||||||
add_subdirectory(hello_world)
|
add_subdirectory(hello_world)
|
||||||
add_subdirectory(isosurface)
|
add_subdirectory(isosurface)
|
||||||
add_subdirectory(multi_backend)
|
add_subdirectory(multi_backend)
|
||||||
|
62
examples/cosmotools/CMakeLists.txt
Normal file
62
examples/cosmotools/CMakeLists.txt
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
##=============================================================================
|
||||||
|
##
|
||||||
|
## 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.
|
||||||
|
##
|
||||||
|
## Copyright 2015 Sandia Corporation.
|
||||||
|
## Copyright 2015 UT-Battelle, LLC.
|
||||||
|
## Copyright 2015 Los Alamos National Security.
|
||||||
|
##
|
||||||
|
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
## the U.S. Government retains certain rights in this software.
|
||||||
|
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
## Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
## this software.
|
||||||
|
##
|
||||||
|
##=============================================================================
|
||||||
|
#Find the VTK-m package
|
||||||
|
find_package(VTKm REQUIRED QUIET
|
||||||
|
OPTIONAL_COMPONENTS Serial CUDA TBB
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(CosmoCenterFinder_SERIAL CosmoCenterFinder.cxx)
|
||||||
|
target_include_directories(CosmoCenterFinder_SERIAL PRIVATE ${VTKm_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(CosmoCenterFinder_SERIAL PRIVATE ${VTKm_LIBRARIES})
|
||||||
|
target_compile_options(CosmoCenterFinder_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS})
|
||||||
|
|
||||||
|
add_executable(CosmoHaloFinder_SERIAL CosmoHaloFinder.cxx)
|
||||||
|
target_include_directories(CosmoHaloFinder_SERIAL PRIVATE ${VTKm_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(CosmoHaloFinder_SERIAL PRIVATE ${VTKm_LIBRARIES})
|
||||||
|
target_compile_options(CosmoHaloFinder_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS})
|
||||||
|
|
||||||
|
if(VTKm_CUDA_FOUND)
|
||||||
|
# Cuda compiles do not respect target_include_directories
|
||||||
|
cuda_include_directories(${VTKm_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
cuda_add_executable(CosmoCenterFinder_CUDA CosmoCenterFinder.cu)
|
||||||
|
target_include_directories(CosmoCenterFinder_CUDA PRIVATE ${VTKm_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(CosmoCenterFinder_CUDA PRIVATE ${VTKm_LIBRARIES})
|
||||||
|
target_compile_options(CosmoCenterFinder_CUDA PRIVATE ${VTKm_COMPILE_OPTIONS})
|
||||||
|
|
||||||
|
cuda_add_executable(CosmoHaloFinder_CUDA CosmoHaloFinder.cu)
|
||||||
|
target_include_directories(CosmoHaloFinder_CUDA PRIVATE ${VTKm_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(CosmoHaloFinder_CUDA PRIVATE ${VTKm_LIBRARIES})
|
||||||
|
target_compile_options(CosmoHaloFinder_CUDA PRIVATE ${VTKm_COMPILE_OPTIONS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(VTKm_TBB_FOUND)
|
||||||
|
add_executable(CosmoCenterFinder_TBB CosmoCenterFinderTBB.cxx)
|
||||||
|
target_include_directories(CosmoCenterFinder_TBB PRIVATE ${VTKm_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(CosmoCenterFinder_TBB PRIVATE ${VTKm_LIBRARIES})
|
||||||
|
target_compile_options(CosmoCenterFinder_TBB PRIVATE PRIVATE ${VTKm_COMPILE_OPTIONS})
|
||||||
|
|
||||||
|
add_executable(CosmoHaloFinder_TBB CosmoHaloFinderTBB.cxx)
|
||||||
|
target_include_directories(CosmoHaloFinder_TBB PRIVATE ${VTKm_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(CosmoHaloFinder_TBB PRIVATE ${VTKm_LIBRARIES})
|
||||||
|
target_compile_options(CosmoHaloFinder_TBB PRIVATE PRIVATE ${VTKm_COMPILE_OPTIONS})
|
||||||
|
endif()
|
23
examples/cosmotools/CosmoCenterFinder.cu
Normal file
23
examples/cosmotools/CosmoCenterFinder.cu
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_CUDA
|
||||||
|
|
||||||
|
#include "CosmoCenterFinder.cxx"
|
138
examples/cosmotools/CosmoCenterFinder.cxx
Normal file
138
examples/cosmotools/CosmoCenterFinder.cxx
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
#include <vtkm/cont/ArrayHandleCast.h>
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||||
|
#include <vtkm/cont/Timer.h>
|
||||||
|
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||||
|
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||||
|
|
||||||
|
#include <vtkm/worklet/CosmoTools.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
typedef vtkm::Vec<vtkm::Float32, 3> FloatVec3;
|
||||||
|
|
||||||
|
void TestCosmoCenterFinder(const char* fileName)
|
||||||
|
{
|
||||||
|
std::cout << std::endl
|
||||||
|
<< "Testing Cosmology MBP Center Finder Filter on one halo " << fileName << std::endl;
|
||||||
|
|
||||||
|
// Open the file for reading
|
||||||
|
std::ifstream inFile(fileName);
|
||||||
|
if (inFile.fail())
|
||||||
|
{
|
||||||
|
std::cout << "File does not exist " << fileName << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read in number of particles and locations
|
||||||
|
int nParticles;
|
||||||
|
inFile >> nParticles;
|
||||||
|
|
||||||
|
float* xLocation = new float[nParticles];
|
||||||
|
float* yLocation = new float[nParticles];
|
||||||
|
float* zLocation = new float[nParticles];
|
||||||
|
std::cout << "Running MBP on " << nParticles << std::endl;
|
||||||
|
|
||||||
|
for (vtkm::Id p = 0; p < nParticles; p++)
|
||||||
|
{
|
||||||
|
inFile >> xLocation[p] >> yLocation[p] >> zLocation[p];
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray =
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Float32>(xLocation, nParticles);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray =
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Float32>(yLocation, nParticles);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray =
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Float32>(zLocation, nParticles);
|
||||||
|
|
||||||
|
// Output MBP particleId pairs array
|
||||||
|
vtkm::Pair<vtkm::Id, vtkm::Float32> nxnResult;
|
||||||
|
vtkm::Pair<vtkm::Id, vtkm::Float32> mxnResult;
|
||||||
|
|
||||||
|
vtkm::cont::Timer<DeviceAdapter> total;
|
||||||
|
vtkm::cont::Timer<DeviceAdapter> timer;
|
||||||
|
|
||||||
|
// Create the worklet and run it
|
||||||
|
vtkm::Float32 particleMass = 1.08413e+09f;
|
||||||
|
|
||||||
|
vtkm::worklet::CosmoTools cosmoTools;
|
||||||
|
cosmoTools.RunMBPCenterFinderNxN(
|
||||||
|
xLocArray, yLocArray, zLocArray, nParticles, particleMass, nxnResult, DeviceAdapter());
|
||||||
|
vtkm::Float64 nxnTime = timer.GetElapsedTime();
|
||||||
|
|
||||||
|
std::cout << "**** NxN MPB = " << nxnResult.first << " potential = " << nxnResult.second
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "**** Time for NxN: " << nxnTime << std::endl;
|
||||||
|
|
||||||
|
timer.Reset();
|
||||||
|
cosmoTools.RunMBPCenterFinderMxN(
|
||||||
|
xLocArray, yLocArray, zLocArray, nParticles, particleMass, mxnResult, DeviceAdapter());
|
||||||
|
vtkm::Float64 estTime = timer.GetElapsedTime();
|
||||||
|
|
||||||
|
std::cout << "**** MxN MPB = " << mxnResult.first << " potential = " << mxnResult.second
|
||||||
|
<< std::endl;
|
||||||
|
std::cout << "**** Time for MxN: " << estTime << std::endl;
|
||||||
|
|
||||||
|
if (nxnResult.first == mxnResult.first)
|
||||||
|
std::cout << "FOUND CORRECT PARTICLE " << mxnResult.first << " with potential "
|
||||||
|
<< nxnResult.second << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "ERROR DID NOT FIND SAME PARTICLE" << std::endl;
|
||||||
|
|
||||||
|
xLocArray.ReleaseResources();
|
||||||
|
yLocArray.ReleaseResources();
|
||||||
|
zLocArray.ReleaseResources();
|
||||||
|
|
||||||
|
delete[] xLocation;
|
||||||
|
delete[] yLocation;
|
||||||
|
delete[] zLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Form of the input file in ASCII
|
||||||
|
// Line 1: number of particles in the file
|
||||||
|
// Line 2+: (float) xLoc (float) yLoc (float) zLoc
|
||||||
|
//
|
||||||
|
// CosmoCenterFinder data.cosmotools
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
std::cout << "Usage: " << std::endl << "$ " << argv[0] << " <input_file>" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Device Adapter Name: " << vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
TestCosmoCenterFinder(argv[1]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
23
examples/cosmotools/CosmoCenterFinderTBB.cxx
Normal file
23
examples/cosmotools/CosmoCenterFinderTBB.cxx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_TBB
|
||||||
|
|
||||||
|
#include "CosmoCenterFinder.cxx"
|
23
examples/cosmotools/CosmoHaloFinder.cu
Normal file
23
examples/cosmotools/CosmoHaloFinder.cu
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_CUDA
|
||||||
|
|
||||||
|
#include "CosmoHaloFinder.cxx"
|
132
examples/cosmotools/CosmoHaloFinder.cxx
Normal file
132
examples/cosmotools/CosmoHaloFinder.cxx
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
#include <vtkm/cont/ArrayHandleCast.h>
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||||
|
#include <vtkm/cont/Timer.h>
|
||||||
|
#include <vtkm/io/reader/VTKDataSetReader.h>
|
||||||
|
#include <vtkm/io/writer/VTKDataSetWriter.h>
|
||||||
|
|
||||||
|
#include <vtkm/worklet/CosmoTools.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
typedef vtkm::Vec<vtkm::Float32, 3> FloatVec3;
|
||||||
|
|
||||||
|
void TestCosmoHaloFinder(const char* fileName)
|
||||||
|
{
|
||||||
|
std::cout << std::endl
|
||||||
|
<< "Testing Cosmology Halo Finder and MBP Center Finder " << fileName << std::endl;
|
||||||
|
|
||||||
|
// Open the file for reading
|
||||||
|
std::ifstream inFile(fileName);
|
||||||
|
if (inFile.fail())
|
||||||
|
{
|
||||||
|
std::cout << "File does not exist " << fileName << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read in number of particles and locations
|
||||||
|
int nParticles;
|
||||||
|
inFile >> nParticles;
|
||||||
|
|
||||||
|
float* xLocation = new float[nParticles];
|
||||||
|
float* yLocation = new float[nParticles];
|
||||||
|
float* zLocation = new float[nParticles];
|
||||||
|
std::cout << "Running Halo Finder on " << nParticles << std::endl;
|
||||||
|
|
||||||
|
for (vtkm::Id p = 0; p < nParticles; p++)
|
||||||
|
{
|
||||||
|
inFile >> xLocation[p] >> yLocation[p] >> zLocation[p];
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray =
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Float32>(xLocation, nParticles);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray =
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Float32>(yLocation, nParticles);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray =
|
||||||
|
vtkm::cont::make_ArrayHandle<vtkm::Float32>(zLocation, nParticles);
|
||||||
|
|
||||||
|
// Output halo id, mbp id and min potential per particle
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> resultHaloId;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> resultMBP;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> resultPot;
|
||||||
|
|
||||||
|
vtkm::cont::Timer<DeviceAdapter> total;
|
||||||
|
vtkm::cont::Timer<DeviceAdapter> timer;
|
||||||
|
|
||||||
|
// Create the worklet and run it
|
||||||
|
vtkm::Id minHaloSize = 20;
|
||||||
|
vtkm::Float32 linkingLength = 0.2f;
|
||||||
|
vtkm::Float32 particleMass = 1.08413e+09f;
|
||||||
|
|
||||||
|
vtkm::worklet::CosmoTools cosmoTools;
|
||||||
|
cosmoTools.RunHaloFinder(xLocArray,
|
||||||
|
yLocArray,
|
||||||
|
zLocArray,
|
||||||
|
nParticles,
|
||||||
|
particleMass,
|
||||||
|
minHaloSize,
|
||||||
|
linkingLength,
|
||||||
|
resultHaloId,
|
||||||
|
resultMBP,
|
||||||
|
resultPot,
|
||||||
|
DeviceAdapter());
|
||||||
|
vtkm::Float64 haloTime = timer.GetElapsedTime();
|
||||||
|
std::cout << "**** Time for HaloFinder: " << haloTime << std::endl;
|
||||||
|
|
||||||
|
xLocArray.ReleaseResources();
|
||||||
|
yLocArray.ReleaseResources();
|
||||||
|
zLocArray.ReleaseResources();
|
||||||
|
|
||||||
|
delete[] xLocation;
|
||||||
|
delete[] yLocation;
|
||||||
|
delete[] zLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Form of the input file in ASCII
|
||||||
|
// Line 1: number of particles in the file
|
||||||
|
// Line 2+: (float) xLoc (float) yLoc (float) zLoc
|
||||||
|
//
|
||||||
|
// CosmoHaloFinder data.cosmotools
|
||||||
|
//
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
if (argc < 2)
|
||||||
|
{
|
||||||
|
std::cout << "Usage: " << std::endl << "$ " << argv[0] << " <input_file>" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Device Adapter Name: " << vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
TestCosmoHaloFinder(argv[1]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
23
examples/cosmotools/CosmoHaloFinderTBB.cxx
Normal file
23
examples/cosmotools/CosmoHaloFinderTBB.cxx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_TBB
|
||||||
|
|
||||||
|
#include "CosmoHaloFinder.cxx"
|
@ -60,8 +60,6 @@ void RunTest(const std::string& fname,
|
|||||||
vtkm::Float32 stepSize,
|
vtkm::Float32 stepSize,
|
||||||
vtkm::Id numThreads,
|
vtkm::Id numThreads,
|
||||||
vtkm::Id advectType,
|
vtkm::Id advectType,
|
||||||
vtkm::Id stepsPerRound,
|
|
||||||
vtkm::Id particlesPerRound,
|
|
||||||
vtkm::Id seeding)
|
vtkm::Id seeding)
|
||||||
{
|
{
|
||||||
using DeviceAdapter = VTKM_DEFAULT_DEVICE_ADAPTER_TAG;
|
using DeviceAdapter = VTKM_DEFAULT_DEVICE_ADAPTER_TAG;
|
||||||
@ -170,8 +168,7 @@ void RunTest(const std::string& fname,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
vtkm::worklet::Streamline streamline;
|
vtkm::worklet::Streamline streamline;
|
||||||
streamline.Run(
|
streamline.Run(rk4, seedArray, fieldArray, numSteps, DeviceAdapter());
|
||||||
rk4, seedArray, fieldArray, numSteps, stepsPerRound, particlesPerRound, DeviceAdapter());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto t1 = std::chrono::high_resolution_clock::now() - t0;
|
auto t1 = std::chrono::high_resolution_clock::now() - t0;
|
||||||
@ -317,14 +314,6 @@ int main(int argc, char** argv)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
RunTest(dataFile,
|
RunTest(dataFile, numSeeds, numSteps, stepSize, numThreads, advectType, seeding);
|
||||||
numSeeds,
|
|
||||||
numSteps,
|
|
||||||
stepSize,
|
|
||||||
numThreads,
|
|
||||||
advectType,
|
|
||||||
stepsPerRound,
|
|
||||||
particlesPerRound,
|
|
||||||
seeding);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <vtkm/cont/ArrayPortal.h>
|
#include <vtkm/cont/ArrayPortal.h>
|
||||||
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||||
#include <vtkm/cont/ErrorBadValue.h>
|
#include <vtkm/cont/ErrorBadValue.h>
|
||||||
|
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
||||||
#include <vtkm/cont/TryExecute.h>
|
#include <vtkm/cont/TryExecute.h>
|
||||||
|
|
||||||
#include <vtkm/Assert.h>
|
#include <vtkm/Assert.h>
|
||||||
@ -438,6 +439,76 @@ make_ArrayHandleGroupVecVariable(const SourceArrayHandleType& sourceArray,
|
|||||||
sourceArray, offsetsArray);
|
sourceArray, offsetsArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \c ConvertNumComponentsToOffsets takes an array of Vec sizes (i.e. the number of components in
|
||||||
|
/// each Vec) and returns an array of offsets to a packed array of such Vecs. The resulting array
|
||||||
|
/// can be used with \c ArrayHandleGroupVecVariable.
|
||||||
|
///
|
||||||
|
/// The first parameter is always the input array that specifies the number of components in each
|
||||||
|
/// group Vec.
|
||||||
|
///
|
||||||
|
/// The next parameter is the output \c ArrayHandle, which must have a value type of \c vtkm::Id.
|
||||||
|
/// If the output \c ArrayHandle is not given, it is returned.
|
||||||
|
///
|
||||||
|
/// The next optional parameter is a reference to a \c vtkm::Id and is filled with the expected
|
||||||
|
/// size of the source values array.
|
||||||
|
///
|
||||||
|
/// The final optional parameter is either a device adapter tag or a \c RuntimeDeviceTracker. If a
|
||||||
|
/// device is not specified, then devices specified by the global \c RuntimeDeviceTracker are used.
|
||||||
|
///
|
||||||
|
template <typename NumComponentsArrayType, typename OffsetsStorage, typename Device>
|
||||||
|
VTKM_CONT void ConvertNumComponentsToOffsets(
|
||||||
|
const NumComponentsArrayType& numComponentsArray,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorage>& offsetsArray,
|
||||||
|
vtkm::Id& sourceArraySize,
|
||||||
|
Device)
|
||||||
|
{
|
||||||
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
|
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||||
|
|
||||||
|
sourceArraySize = vtkm::cont::DeviceAdapterAlgorithm<Device>::ScanExclusive(
|
||||||
|
vtkm::cont::make_ArrayHandleCast<vtkm::Id>(numComponentsArray), offsetsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename NumComponentsArrayType, typename OffsetsStorage, typename Device>
|
||||||
|
VTKM_CONT void ConvertNumComponentsToOffsets(
|
||||||
|
const NumComponentsArrayType& numComponentsArray,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorage>& offsetsArray,
|
||||||
|
Device)
|
||||||
|
{
|
||||||
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
|
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||||
|
|
||||||
|
vtkm::Id dummy;
|
||||||
|
vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, offsetsArray, dummy, Device());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename NumComponentsArrayType, typename Device>
|
||||||
|
VTKM_CONT vtkm::cont::ArrayHandle<vtkm::Id> ConvertNumComponentsToOffsets(
|
||||||
|
const NumComponentsArrayType& numComponentsArray,
|
||||||
|
vtkm::Id& sourceArraySize,
|
||||||
|
Device)
|
||||||
|
{
|
||||||
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
|
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> offsetsArray;
|
||||||
|
vtkm::cont::ConvertNumComponentsToOffsets(
|
||||||
|
numComponentsArray, offsetsArray, sourceArraySize, Device());
|
||||||
|
return offsetsArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename NumComponentsArrayType, typename Device>
|
||||||
|
VTKM_CONT vtkm::cont::ArrayHandle<vtkm::Id> ConvertNumComponentsToOffsets(
|
||||||
|
const NumComponentsArrayType& numComponentsArray,
|
||||||
|
Device)
|
||||||
|
{
|
||||||
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
|
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||||
|
|
||||||
|
vtkm::Id dummy;
|
||||||
|
return vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, dummy, Device());
|
||||||
|
}
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -458,8 +529,8 @@ struct ConvertNumComponentsToOffsetsFunctor
|
|||||||
template <typename Device>
|
template <typename Device>
|
||||||
VTKM_CONT bool operator()(Device)
|
VTKM_CONT bool operator()(Device)
|
||||||
{
|
{
|
||||||
this->SourceArraySize = vtkm::cont::DeviceAdapterAlgorithm<Device>::ScanExclusive(
|
vtkm::cont::ConvertNumComponentsToOffsets(
|
||||||
this->NumComponentsArray, this->OffsetsArray);
|
this->NumComponentsArray, this->OffsetsArray, this->SourceArraySize, Device());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -468,14 +539,15 @@ struct ConvertNumComponentsToOffsetsFunctor
|
|||||||
template <typename NumComponentsArrayType, typename OffsetsArrayType>
|
template <typename NumComponentsArrayType, typename OffsetsArrayType>
|
||||||
VTKM_CONT void DoConvertNumComponentsToOffsets(const NumComponentsArrayType& numComponentsArray,
|
VTKM_CONT void DoConvertNumComponentsToOffsets(const NumComponentsArrayType& numComponentsArray,
|
||||||
OffsetsArrayType& offsetsArray,
|
OffsetsArrayType& offsetsArray,
|
||||||
vtkm::Id& sourceArraySize)
|
vtkm::Id& sourceArraySize,
|
||||||
|
vtkm::cont::RuntimeDeviceTracker tracker)
|
||||||
{
|
{
|
||||||
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
VTKM_IS_ARRAY_HANDLE(OffsetsArrayType);
|
VTKM_IS_ARRAY_HANDLE(OffsetsArrayType);
|
||||||
|
|
||||||
detail::ConvertNumComponentsToOffsetsFunctor<NumComponentsArrayType, OffsetsArrayType> functor(
|
detail::ConvertNumComponentsToOffsetsFunctor<NumComponentsArrayType, OffsetsArrayType> functor(
|
||||||
numComponentsArray);
|
numComponentsArray);
|
||||||
bool success = vtkm::cont::TryExecute(functor);
|
bool success = vtkm::cont::TryExecute(functor, tracker);
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
@ -489,50 +561,54 @@ VTKM_CONT void DoConvertNumComponentsToOffsets(const NumComponentsArrayType& num
|
|||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
/// \c ConvertNumComponentsToOffsets takes an array of Vec sizes (i.e. the
|
|
||||||
/// number of components in each Vec) and returns an array of offsets to a
|
|
||||||
/// packed array of such Vecs. The resulting array can be used with
|
|
||||||
/// \c ArrayHandleGroupVecVariable.
|
|
||||||
///
|
|
||||||
/// If an optional second parameter is given, the expected size of the source
|
|
||||||
/// values array is returned in it.
|
|
||||||
///
|
|
||||||
template <typename NumComponentsArrayType, typename OffsetsStorage>
|
template <typename NumComponentsArrayType, typename OffsetsStorage>
|
||||||
VTKM_CONT void ConvertNumComponentsToOffsets(
|
VTKM_CONT void ConvertNumComponentsToOffsets(
|
||||||
const NumComponentsArrayType& numComponentsArray,
|
const NumComponentsArrayType& numComponentsArray,
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorage>& offsetsArray,
|
vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorage>& offsetsArray,
|
||||||
vtkm::Id& sourceArraySize)
|
vtkm::Id& sourceArraySize,
|
||||||
|
vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker())
|
||||||
{
|
{
|
||||||
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
|
|
||||||
detail::DoConvertNumComponentsToOffsets(
|
detail::DoConvertNumComponentsToOffsets(
|
||||||
vtkm::cont::make_ArrayHandleCast<vtkm::Id>(numComponentsArray), offsetsArray, sourceArraySize);
|
numComponentsArray, offsetsArray, sourceArraySize, tracker);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename NumComponentsArrayType, typename OffsetsStorage>
|
template <typename NumComponentsArrayType, typename OffsetsStorage>
|
||||||
VTKM_CONT void ConvertNumComponentsToOffsets(
|
VTKM_CONT void ConvertNumComponentsToOffsets(
|
||||||
const NumComponentsArrayType& numComponentsArray,
|
const NumComponentsArrayType& numComponentsArray,
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorage>& offsetsArray)
|
vtkm::cont::ArrayHandle<vtkm::Id, OffsetsStorage>& offsetsArray,
|
||||||
|
vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker())
|
||||||
{
|
{
|
||||||
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
|
|
||||||
vtkm::Id dummy;
|
vtkm::Id dummy;
|
||||||
vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, offsetsArray, dummy);
|
vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, offsetsArray, dummy, tracker);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename NumComponentsArrayType>
|
template <typename NumComponentsArrayType>
|
||||||
VTKM_CONT vtkm::cont::ArrayHandle<vtkm::Id> ConvertNumComponentsToOffsets(
|
VTKM_CONT vtkm::cont::ArrayHandle<vtkm::Id> ConvertNumComponentsToOffsets(
|
||||||
const NumComponentsArrayType& numComponentsArray,
|
const NumComponentsArrayType& numComponentsArray,
|
||||||
vtkm::Id& sourceArraySize)
|
vtkm::Id& sourceArraySize,
|
||||||
|
vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker())
|
||||||
{
|
{
|
||||||
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
|
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id> offsetsArray;
|
vtkm::cont::ArrayHandle<vtkm::Id> offsetsArray;
|
||||||
vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, offsetsArray, sourceArraySize);
|
vtkm::cont::ConvertNumComponentsToOffsets(
|
||||||
|
numComponentsArray, offsetsArray, sourceArraySize, tracker);
|
||||||
return offsetsArray;
|
return offsetsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename NumComponentsArrayType>
|
template <typename NumComponentsArrayType>
|
||||||
VTKM_CONT vtkm::cont::ArrayHandle<vtkm::Id> ConvertNumComponentsToOffsets(
|
VTKM_CONT vtkm::cont::ArrayHandle<vtkm::Id> ConvertNumComponentsToOffsets(
|
||||||
const NumComponentsArrayType& numComponentsArray)
|
const NumComponentsArrayType& numComponentsArray,
|
||||||
|
vtkm::cont::RuntimeDeviceTracker tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker())
|
||||||
{
|
{
|
||||||
|
VTKM_IS_ARRAY_HANDLE(NumComponentsArrayType);
|
||||||
|
|
||||||
vtkm::Id dummy;
|
vtkm::Id dummy;
|
||||||
return vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, dummy);
|
return vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, dummy, tracker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace vtkm::cont
|
} // namespace vtkm::cont
|
||||||
|
@ -122,6 +122,8 @@ public:
|
|||||||
template <vtkm::IdComponent ItemTupleLength>
|
template <vtkm::IdComponent ItemTupleLength>
|
||||||
VTKM_CONT void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id, ItemTupleLength>& ids) const;
|
VTKM_CONT void GetIndices(vtkm::Id index, vtkm::Vec<vtkm::Id, ItemTupleLength>& ids) const;
|
||||||
|
|
||||||
|
VTKM_CONT void GetIndices(vtkm::Id index, vtkm::cont::ArrayHandle<vtkm::Id>& ids) const;
|
||||||
|
|
||||||
/// First method to add cells -- one at a time.
|
/// First method to add cells -- one at a time.
|
||||||
VTKM_CONT void PrepareToAddCells(vtkm::Id numCells, vtkm::Id connectivityMaxLen);
|
VTKM_CONT void PrepareToAddCells(vtkm::Id numCells, vtkm::Id connectivityMaxLen);
|
||||||
|
|
||||||
|
@ -216,6 +216,25 @@ CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ShapeStorageTag,
|
||||||
|
typename NumIndicesStorageTag,
|
||||||
|
typename ConnectivityStorageTag,
|
||||||
|
typename OffsetsStorageTag>
|
||||||
|
VTKM_CONT void
|
||||||
|
CellSetExplicit<ShapeStorageTag, NumIndicesStorageTag, ConnectivityStorageTag, OffsetsStorageTag>::
|
||||||
|
GetIndices(vtkm::Id index, vtkm::cont::ArrayHandle<vtkm::Id>& ids) const
|
||||||
|
{
|
||||||
|
this->PointToCell.BuildIndexOffsets(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
vtkm::IdComponent numIndices = this->GetNumberOfPointsInCell(index);
|
||||||
|
ids.Allocate(numIndices);
|
||||||
|
vtkm::Id start = this->PointToCell.IndexOffsets.GetPortalConstControl().Get(index);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>::PortalControl idPortal = ids.GetPortalControl();
|
||||||
|
auto PtCellPortal = this->PointToCell.Connectivity.GetPortalConstControl();
|
||||||
|
|
||||||
|
for (vtkm::IdComponent i = 0; i < numIndices && i < numIndices; i++)
|
||||||
|
idPortal.Set(i, PtCellPortal.Get(start + i));
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
template <typename ShapeStorageTag,
|
template <typename ShapeStorageTag,
|
||||||
|
@ -696,8 +696,8 @@ private:
|
|||||||
vtkm::Id sourceArraySize;
|
vtkm::Id sourceArraySize;
|
||||||
|
|
||||||
vtkm::cont::ArrayHandleCounting<vtkm::IdComponent> numComponentsArray(1, 1, ARRAY_SIZE);
|
vtkm::cont::ArrayHandleCounting<vtkm::IdComponent> numComponentsArray(1, 1, ARRAY_SIZE);
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id> offsetsArray =
|
vtkm::cont::ArrayHandle<vtkm::Id> offsetsArray = vtkm::cont::ConvertNumComponentsToOffsets(
|
||||||
vtkm::cont::ConvertNumComponentsToOffsets(numComponentsArray, sourceArraySize);
|
numComponentsArray, sourceArraySize, DeviceAdapterTag());
|
||||||
|
|
||||||
vtkm::cont::ArrayHandle<ComponentType> sourceArray;
|
vtkm::cont::ArrayHandle<ComponentType> sourceArray;
|
||||||
sourceArray.Allocate(sourceArraySize);
|
sourceArray.Allocate(sourceArraySize);
|
||||||
|
@ -40,6 +40,8 @@ set(headers
|
|||||||
MarchingCubes.h
|
MarchingCubes.h
|
||||||
Mask.h
|
Mask.h
|
||||||
MaskPoints.h
|
MaskPoints.h
|
||||||
|
NDEntropy.h
|
||||||
|
NDHistogram.h
|
||||||
PointAverage.h
|
PointAverage.h
|
||||||
PointElevation.h
|
PointElevation.h
|
||||||
PolicyBase.h
|
PolicyBase.h
|
||||||
@ -74,6 +76,8 @@ set(header_template_sources
|
|||||||
MarchingCubes.hxx
|
MarchingCubes.hxx
|
||||||
Mask.hxx
|
Mask.hxx
|
||||||
MaskPoints.hxx
|
MaskPoints.hxx
|
||||||
|
NDEntropy.hxx
|
||||||
|
NDHistogram.hxx
|
||||||
PointAverage.hxx
|
PointAverage.hxx
|
||||||
PointElevation.hxx
|
PointElevation.hxx
|
||||||
SurfaceNormals.hxx
|
SurfaceNormals.hxx
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
~FilterCell();
|
~FilterCell();
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
void SetActiveCellSet(vtkm::Id index) { this->CellSetIndex = index; }
|
void SetActiveCellSetIndex(vtkm::Id index) { this->CellSetIndex = index; }
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
vtkm::Id GetActiveCellSetIndex() const { return this->CellSetIndex; }
|
vtkm::Id GetActiveCellSetIndex() const { return this->CellSetIndex; }
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
~FilterDataSet();
|
~FilterDataSet();
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
void SetActiveCellSet(vtkm::Id index) { this->CellSetIndex = index; }
|
void SetActiveCellSetIndex(vtkm::Id index) { this->CellSetIndex = index; }
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
vtkm::Id GetActiveCellSetIndex() const { return this->CellSetIndex; }
|
vtkm::Id GetActiveCellSetIndex() const { return this->CellSetIndex; }
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
~FilterDataSetWithField();
|
~FilterDataSetWithField();
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
void SetActiveCellSet(vtkm::Id index) { this->CellSetIndex = index; }
|
void SetActiveCellSetIndex(vtkm::Id index) { this->CellSetIndex = index; }
|
||||||
|
|
||||||
VTKM_CONT
|
VTKM_CONT
|
||||||
vtkm::Id GetActiveCellSetIndex() const { return this->CellSetIndex; }
|
vtkm::Id GetActiveCellSetIndex() const { return this->CellSetIndex; }
|
||||||
|
66
vtkm/filter/NDEntropy.h
Normal file
66
vtkm/filter/NDEntropy.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2016 Sandia Corporation.
|
||||||
|
// Copyright 2016 UT-Battelle, LLC.
|
||||||
|
// Copyright 2016 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
#ifndef vtk_m_filter_NDEntropy_h
|
||||||
|
#define vtk_m_filter_NDEntropy_h
|
||||||
|
|
||||||
|
#include <vtkm/filter/FilterDataSet.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace filter
|
||||||
|
{
|
||||||
|
/// \brief Clean a mesh to an unstructured grid
|
||||||
|
///
|
||||||
|
/// This filter takes a data set and essentially copies it into a new data set.
|
||||||
|
/// The newly constructed data set will have the same cells as the input and
|
||||||
|
/// the topology will be stored in a \c CellSetExplicit<>. The filter will also
|
||||||
|
/// optionally remove all unused points.
|
||||||
|
///
|
||||||
|
/// Note that the result of \c CleanGrid is not necessarily smaller than the
|
||||||
|
/// input. For example, "cleaning" a data set with a \c CellSetStructured
|
||||||
|
/// topology will actually result in a much larger data set.
|
||||||
|
///
|
||||||
|
/// \todo Add a feature to merge points that are coincident or within a
|
||||||
|
/// tolerance.
|
||||||
|
///
|
||||||
|
class NDEntropy : public vtkm::filter::FilterDataSet<NDEntropy>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VTKM_CONT
|
||||||
|
NDEntropy();
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
void AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins);
|
||||||
|
|
||||||
|
template <typename Policy, typename Device>
|
||||||
|
VTKM_CONT vtkm::filter::Result DoExecute(const vtkm::cont::DataSet& inData,
|
||||||
|
vtkm::filter::PolicyBase<Policy> policy,
|
||||||
|
Device);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<vtkm::Id> NumOfBins;
|
||||||
|
std::vector<std::string> FieldNames;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace vtkm::filter
|
||||||
|
|
||||||
|
#include <vtkm/filter/NDEntropy.hxx>
|
||||||
|
|
||||||
|
#endif //vtk_m_filter_NDEntropy_h
|
70
vtkm/filter/NDEntropy.hxx
Normal file
70
vtkm/filter/NDEntropy.hxx
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2016 Sandia Corporation.
|
||||||
|
// Copyright 2016 UT-Battelle, LLC.
|
||||||
|
// Copyright 2016 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/worklet/NDimsEntropy.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace filter
|
||||||
|
{
|
||||||
|
|
||||||
|
inline VTKM_CONT NDEntropy::NDEntropy()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void NDEntropy::AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins)
|
||||||
|
{
|
||||||
|
this->FieldNames.push_back(fieldName);
|
||||||
|
this->NumOfBins.push_back(numOfBins);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Policy, typename Device>
|
||||||
|
inline VTKM_CONT vtkm::filter::Result NDEntropy::DoExecute(
|
||||||
|
const vtkm::cont::DataSet& inData,
|
||||||
|
vtkm::filter::PolicyBase<Policy> vtkmNotUsed(policy),
|
||||||
|
Device device)
|
||||||
|
{
|
||||||
|
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||||
|
|
||||||
|
vtkm::worklet::NDimsEntropy ndEntropy;
|
||||||
|
ndEntropy.SetNumOfDataPoints(inData.GetField(0).GetData().GetNumberOfValues(), device);
|
||||||
|
|
||||||
|
// Add field one by one
|
||||||
|
// (By using AddFieldAndBin(), the length of FieldNames and NumOfBins must be the same)
|
||||||
|
for (size_t i = 0; i < FieldNames.size(); i++)
|
||||||
|
{
|
||||||
|
ndEntropy.AddField(inData.GetField(FieldNames[i]).GetData(), NumOfBins[i], device);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run worklet to calculate multi-variate entropy
|
||||||
|
vtkm::Float64 entropy = ndEntropy.Run(device);
|
||||||
|
|
||||||
|
vtkm::cont::DataSet outputData;
|
||||||
|
std::vector<vtkm::Float64> entropyHandle;
|
||||||
|
entropyHandle.push_back(entropy);
|
||||||
|
outputData.AddField(vtkm::cont::Field("Entropy", vtkm::cont::Field::ASSOC_POINTS, entropyHandle));
|
||||||
|
|
||||||
|
//return outputData;
|
||||||
|
return vtkm::filter::Result(outputData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
vtkm/filter/NDHistogram.h
Normal file
78
vtkm/filter/NDHistogram.h
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2016 Sandia Corporation.
|
||||||
|
// Copyright 2016 UT-Battelle, LLC.
|
||||||
|
// Copyright 2016 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
#ifndef vtk_m_filter_NDHistogram_h
|
||||||
|
#define vtk_m_filter_NDHistogram_h
|
||||||
|
|
||||||
|
#include <vtkm/filter/FilterDataSet.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace filter
|
||||||
|
{
|
||||||
|
/// \brief Clean a mesh to an unstructured grid
|
||||||
|
///
|
||||||
|
/// This filter takes a data set and essentially copies it into a new data set.
|
||||||
|
/// The newly constructed data set will have the same cells as the input and
|
||||||
|
/// the topology will be stored in a \c CellSetExplicit<>. The filter will also
|
||||||
|
/// optionally remove all unused points.
|
||||||
|
///
|
||||||
|
/// Note that the result of \c CleanGrid is not necessarily smaller than the
|
||||||
|
/// input. For example, "cleaning" a data set with a \c CellSetStructured
|
||||||
|
/// topology will actually result in a much larger data set.
|
||||||
|
///
|
||||||
|
/// \todo Add a feature to merge points that are coincident or within a
|
||||||
|
/// tolerance.
|
||||||
|
///
|
||||||
|
class NDHistogram : public vtkm::filter::FilterDataSet<NDHistogram>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VTKM_CONT
|
||||||
|
NDHistogram();
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
void AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins);
|
||||||
|
|
||||||
|
template <typename Policy, typename Device>
|
||||||
|
VTKM_CONT vtkm::filter::Result DoExecute(const vtkm::cont::DataSet& inData,
|
||||||
|
vtkm::filter::PolicyBase<Policy> policy,
|
||||||
|
Device);
|
||||||
|
|
||||||
|
// This index is the field position in FieldNames
|
||||||
|
// (or the input _fieldName string vector of SetFields() Function)
|
||||||
|
VTKM_CONT
|
||||||
|
vtkm::Float64 GetBinDelta(size_t fieldIdx);
|
||||||
|
|
||||||
|
// This index is the field position in FieldNames
|
||||||
|
// (or the input _fieldName string vector of SetFields() Function)
|
||||||
|
VTKM_CONT
|
||||||
|
vtkm::Range GetDataRange(size_t fieldIdx);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<vtkm::Id> NumOfBins;
|
||||||
|
std::vector<std::string> FieldNames;
|
||||||
|
std::vector<vtkm::Float64> BinDeltas;
|
||||||
|
std::vector<vtkm::Range> DataRanges; //Min Max of the field
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace vtkm::filter
|
||||||
|
|
||||||
|
#include <vtkm/filter/NDHistogram.hxx>
|
||||||
|
|
||||||
|
#endif //vtk_m_filter_NDHistogram_h
|
91
vtkm/filter/NDHistogram.hxx
Normal file
91
vtkm/filter/NDHistogram.hxx
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2016 Sandia Corporation.
|
||||||
|
// Copyright 2016 UT-Battelle, LLC.
|
||||||
|
// Copyright 2016 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/worklet/NDimsHistogram.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace filter
|
||||||
|
{
|
||||||
|
|
||||||
|
inline VTKM_CONT NDHistogram::NDHistogram()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void NDHistogram::AddFieldAndBin(const std::string& fieldName, vtkm::Id numOfBins)
|
||||||
|
{
|
||||||
|
this->FieldNames.push_back(fieldName);
|
||||||
|
this->NumOfBins.push_back(numOfBins);
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkm::Float64 NDHistogram::GetBinDelta(size_t fieldIdx)
|
||||||
|
{
|
||||||
|
return BinDeltas[fieldIdx];
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkm::Range NDHistogram::GetDataRange(size_t fieldIdx)
|
||||||
|
{
|
||||||
|
return DataRanges[fieldIdx];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Policy, typename Device>
|
||||||
|
inline VTKM_CONT vtkm::filter::Result NDHistogram::DoExecute(
|
||||||
|
const vtkm::cont::DataSet& inData,
|
||||||
|
vtkm::filter::PolicyBase<Policy> vtkmNotUsed(policy),
|
||||||
|
Device device)
|
||||||
|
{
|
||||||
|
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
||||||
|
|
||||||
|
vtkm::worklet::NDimsHistogram ndHistogram;
|
||||||
|
|
||||||
|
// Set the number of data points
|
||||||
|
ndHistogram.SetNumOfDataPoints(inData.GetField(0).GetData().GetNumberOfValues(), device);
|
||||||
|
|
||||||
|
// Add field one by one
|
||||||
|
// (By using AddFieldAndBin(), the length of FieldNames and NumOfBins must be the same)
|
||||||
|
for (size_t i = 0; i < FieldNames.size(); i++)
|
||||||
|
{
|
||||||
|
vtkm::Range rangeField;
|
||||||
|
vtkm::Float64 deltaField;
|
||||||
|
ndHistogram.AddField(
|
||||||
|
inData.GetField(FieldNames[i]).GetData(), NumOfBins[i], rangeField, deltaField, device);
|
||||||
|
DataRanges.push_back(rangeField);
|
||||||
|
BinDeltas.push_back(deltaField);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>> binIds;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> freqs;
|
||||||
|
ndHistogram.Run(binIds, freqs, device);
|
||||||
|
|
||||||
|
vtkm::cont::DataSet outputData;
|
||||||
|
for (size_t i = 0; i < binIds.size(); i++)
|
||||||
|
{
|
||||||
|
outputData.AddField(
|
||||||
|
vtkm::cont::Field(FieldNames[i], vtkm::cont::Field::ASSOC_POINTS, binIds[i]));
|
||||||
|
}
|
||||||
|
outputData.AddField(vtkm::cont::Field("Frequency", vtkm::cont::Field::ASSOC_POINTS, freqs));
|
||||||
|
|
||||||
|
//return outputData;
|
||||||
|
return vtkm::filter::Result(outputData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -36,6 +36,8 @@ set(unit_tests
|
|||||||
UnitTestMaskFilter.cxx
|
UnitTestMaskFilter.cxx
|
||||||
UnitTestMaskPointsFilter.cxx
|
UnitTestMaskPointsFilter.cxx
|
||||||
UnitTestMultiBlockFilters.cxx
|
UnitTestMultiBlockFilters.cxx
|
||||||
|
UnitTestNDEntropyFilter.cxx
|
||||||
|
UnitTestNDHistogramFilter.cxx
|
||||||
UnitTestPointAverageFilter.cxx
|
UnitTestPointAverageFilter.cxx
|
||||||
UnitTestPointElevationFilter.cxx
|
UnitTestPointElevationFilter.cxx
|
||||||
UnitTestSurfaceNormalsFilter.cxx
|
UnitTestSurfaceNormalsFilter.cxx
|
||||||
|
212
vtkm/filter/testing/UnitTestNDEntropyFilter.cxx
Normal file
212
vtkm/filter/testing/UnitTestNDEntropyFilter.cxx
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2016 Sandia Corporation.
|
||||||
|
// Copyright 2016 UT-Battelle, LLC.
|
||||||
|
// Copyright 2016 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vtkm/filter/NDEntropy.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||||
|
#include <vtkm/cont/testing/Testing.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// Make testing dataset with three fields(variables), each one has 1000 values
|
||||||
|
vtkm::cont::DataSet MakeTestDataSet()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet dataSet;
|
||||||
|
|
||||||
|
const int xVerts = 20;
|
||||||
|
const int yVerts = 50;
|
||||||
|
const int nVerts = xVerts * yVerts;
|
||||||
|
|
||||||
|
vtkm::Float32 fieldA[nVerts] = {
|
||||||
|
8, 10, 9, 8, 14, 11, 12, 9, 19, 7, 8, 11, 7, 10, 11, 11, 11, 6, 8, 8, 7, 15, 9, 7,
|
||||||
|
8, 10, 9, 10, 10, 12, 7, 6, 14, 10, 14, 10, 7, 11, 13, 9, 13, 11, 10, 10, 12, 12, 7, 12,
|
||||||
|
10, 11, 12, 8, 13, 9, 5, 12, 11, 9, 5, 9, 12, 9, 6, 10, 11, 9, 9, 11, 9, 7, 7, 18,
|
||||||
|
16, 13, 12, 8, 10, 11, 9, 8, 17, 3, 15, 15, 9, 10, 10, 8, 10, 9, 7, 9, 8, 10, 13, 9,
|
||||||
|
7, 11, 7, 10, 13, 10, 11, 9, 10, 7, 10, 6, 12, 6, 9, 7, 6, 12, 12, 9, 12, 12, 11, 6,
|
||||||
|
1, 12, 8, 13, 14, 8, 8, 10, 7, 7, 6, 7, 5, 11, 6, 11, 13, 8, 13, 5, 9, 12, 7, 11,
|
||||||
|
10, 15, 11, 9, 7, 12, 15, 7, 8, 7, 12, 8, 21, 16, 13, 11, 10, 14, 12, 11, 12, 14, 7, 11,
|
||||||
|
7, 12, 16, 8, 10, 8, 9, 7, 8, 7, 13, 13, 11, 15, 7, 7, 6, 11, 7, 12, 12, 13, 14, 11,
|
||||||
|
13, 11, 11, 9, 15, 8, 6, 11, 12, 10, 11, 7, 6, 14, 11, 10, 12, 5, 8, 9, 11, 15, 11, 10,
|
||||||
|
17, 14, 9, 10, 10, 12, 11, 13, 13, 12, 11, 7, 8, 10, 7, 11, 10, 5, 8, 10, 13, 13, 12, 6,
|
||||||
|
10, 7, 13, 8, 11, 7, 10, 7, 8, 7, 14, 16, 9, 11, 8, 11, 9, 15, 11, 10, 10, 12, 7, 7,
|
||||||
|
11, 7, 5, 17, 9, 11, 11, 11, 10, 17, 10, 15, 7, 11, 12, 16, 9, 8, 11, 14, 9, 22, 8, 8,
|
||||||
|
8, 13, 12, 12, 1, 14, 15, 6, 15, 8, 11, 16, 14, 8, 6, 9, 8, 9, 9, 10, 8, 6, 13, 8,
|
||||||
|
6, 12, 11, 12, 13, 8, 6, 6, 5, 6, 10, 9, 11, 12, 14, 12, 10, 11, 10, 10, 8, 13, 8, 11,
|
||||||
|
7, 13, 13, 12, 12, 13, 15, 4, 9, 16, 7, 9, 8, 10, 6, 9, 11, 12, 6, 7, 14, 6, 4, 15,
|
||||||
|
5, 18, 9, 9, 11, 12, 9, 5, 6, 7, 15, 6, 11, 14, 8, 12, 6, 9, 5, 9, 14, 9, 12, 6,
|
||||||
|
9, 14, 11, 12, 12, 13, 15, 9, 8, 7, 13, 12, 7, 13, 6, 9, 10, 10, 10, 9, 11, 5, 9, 13,
|
||||||
|
16, 9, 10, 8, 9, 6, 13, 12, 8, 12, 9, 12, 17, 8, 11, 10, 8, 7, 11, 7, 13, 13, 10, 14,
|
||||||
|
11, 9, 6, 6, 14, 16, 5, 9, 13, 11, 12, 7, 4, 6, 9, 11, 11, 10, 12, 9, 7, 13, 8, 8,
|
||||||
|
12, 5, 10, 7, 11, 11, 10, 10, 14, 6, 8, 8, 3, 12, 16, 11, 11, 7, 6, 12, 11, 5, 9, 12,
|
||||||
|
9, 13, 7, 8, 9, 9, 12, 7, 9, 8, 12, 11, 6, 10, 6, 7, 6, 11, 10, 8, 9, 8, 4, 19,
|
||||||
|
12, 6, 10, 9, 6, 12, 9, 14, 7, 8, 11, 7, 7, 12, 13, 9, 13, 12, 8, 6, 10, 17, 19, 10,
|
||||||
|
10, 13, 5, 11, 8, 10, 8, 16, 12, 6, 6, 7, 10, 9, 12, 8, 5, 10, 7, 18, 9, 12, 10, 4,
|
||||||
|
9, 9, 15, 15, 6, 7, 7, 11, 12, 4, 8, 18, 5, 12, 12, 11, 10, 14, 9, 9, 10, 8, 10, 8,
|
||||||
|
10, 9, 9, 4, 10, 12, 5, 13, 6, 9, 7, 5, 12, 8, 11, 10, 9, 17, 9, 9, 8, 11, 18, 11,
|
||||||
|
10, 9, 4, 13, 10, 15, 5, 10, 9, 7, 7, 8, 10, 6, 6, 19, 10, 16, 7, 7, 9, 10, 10, 13,
|
||||||
|
10, 10, 14, 13, 12, 8, 7, 13, 12, 11, 13, 12, 9, 8, 6, 8, 10, 3, 8, 8, 12, 12, 13, 13,
|
||||||
|
10, 5, 10, 7, 13, 7, 9, 5, 13, 7, 10, 8, 13, 11, 17, 9, 6, 14, 10, 10, 13, 9, 15, 8,
|
||||||
|
15, 9, 12, 11, 12, 8, 3, 9, 8, 10, 12, 8, 14, 13, 12, 11, 12, 9, 18, 10, 13, 7, 4, 4,
|
||||||
|
11, 8, 3, 7, 9, 10, 12, 7, 11, 21, 9, 7, 8, 9, 10, 10, 11, 9, 15, 13, 21, 12, 8, 11,
|
||||||
|
9, 10, 11, 9, 17, 8, 9, 8, 14, 6, 13, 9, 8, 11, 12, 12, 12, 11, 6, 13, 7, 9, 11, 15,
|
||||||
|
17, 17, 11, 10, 7, 8, 11, 8, 6, 9, 13, 7, 9, 6, 5, 10, 7, 16, 16, 9, 7, 6, 14, 8,
|
||||||
|
13, 16, 7, 7, 10, 11, 6, 10, 9, 9, 8, 14, 11, 9, 11, 9, 10, 11, 9, 8, 14, 11, 7, 12,
|
||||||
|
11, 8, 9, 9, 10, 11, 11, 10, 9, 6, 6, 11, 16, 10, 7, 6, 6, 13, 18, 8, 12, 11, 14, 13,
|
||||||
|
8, 8, 10, 17, 17, 6, 6, 10, 18, 5, 8, 11, 6, 6, 14, 10, 9, 6, 11, 6, 13, 12, 10, 6,
|
||||||
|
9, 9, 9, 13, 7, 17, 10, 14, 10, 9, 10, 10, 11, 10, 11, 15, 13, 6, 12, 19, 10, 12, 12, 15,
|
||||||
|
13, 10, 10, 13, 11, 13, 13, 17, 6, 5, 6, 7, 6, 9, 13, 11, 8, 12, 9, 6, 10, 16, 11, 12,
|
||||||
|
5, 12, 14, 13, 13, 16, 11, 6, 12, 12, 15, 8, 7, 11, 8, 5, 10, 8, 9, 11, 9, 12, 10, 5,
|
||||||
|
12, 11, 9, 6, 14, 12, 10, 11, 9, 6, 7, 12, 8, 12, 8, 15, 9, 8, 7, 9, 3, 6, 14, 7,
|
||||||
|
8, 11, 9, 10, 12, 9, 10, 9, 8, 6, 12, 11, 6, 8, 9, 8, 15, 11, 7, 18, 12, 11, 10, 13,
|
||||||
|
11, 11, 10, 7, 9, 8, 8, 11, 11, 13, 6, 12, 13, 16, 11, 11, 5, 12, 14, 15, 9, 14, 15, 6,
|
||||||
|
8, 7, 6, 8, 9, 19, 7, 12, 11, 8, 14, 12, 10, 9, 3, 7
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::Float32 fieldB[nVerts] = {
|
||||||
|
24, 19, 28, 19, 25, 28, 25, 22, 27, 26, 35, 26, 30, 28, 24, 23, 21, 31, 20, 11, 21, 22, 14, 25,
|
||||||
|
20, 24, 24, 21, 24, 29, 26, 21, 32, 29, 23, 28, 31, 25, 23, 30, 18, 24, 22, 25, 33, 24, 22, 23,
|
||||||
|
21, 17, 20, 28, 30, 18, 20, 32, 25, 24, 32, 15, 27, 24, 27, 19, 30, 27, 17, 24, 29, 23, 22, 19,
|
||||||
|
24, 19, 28, 24, 25, 24, 25, 30, 24, 31, 30, 27, 25, 25, 25, 15, 29, 23, 29, 29, 21, 25, 35, 24,
|
||||||
|
28, 10, 31, 23, 22, 22, 22, 33, 29, 27, 18, 27, 27, 24, 20, 20, 21, 29, 23, 31, 23, 23, 22, 23,
|
||||||
|
30, 27, 28, 31, 16, 29, 25, 19, 33, 28, 25, 24, 15, 27, 37, 29, 15, 19, 14, 19, 24, 23, 30, 29,
|
||||||
|
35, 22, 19, 26, 26, 14, 24, 30, 32, 23, 30, 29, 26, 27, 25, 23, 17, 26, 32, 29, 20, 17, 21, 23,
|
||||||
|
22, 20, 36, 12, 26, 23, 15, 29, 24, 22, 26, 33, 24, 23, 20, 26, 22, 17, 26, 26, 34, 22, 26, 17,
|
||||||
|
23, 18, 29, 27, 21, 29, 28, 29, 24, 25, 28, 19, 18, 21, 23, 23, 27, 25, 24, 25, 24, 25, 21, 25,
|
||||||
|
21, 27, 23, 20, 29, 15, 28, 30, 24, 27, 17, 23, 16, 21, 25, 17, 27, 28, 21, 13, 19, 27, 16, 30,
|
||||||
|
31, 25, 30, 17, 17, 25, 26, 22, 21, 17, 24, 17, 25, 22, 27, 14, 27, 24, 27, 25, 26, 31, 21, 23,
|
||||||
|
30, 30, 22, 19, 23, 22, 23, 25, 24, 25, 24, 28, 26, 30, 18, 25, 30, 37, 27, 34, 28, 34, 25, 10,
|
||||||
|
25, 22, 35, 30, 24, 32, 24, 34, 19, 29, 26, 16, 27, 17, 26, 23, 27, 25, 26, 21, 31, 21, 28, 15,
|
||||||
|
32, 24, 23, 23, 18, 15, 22, 25, 16, 25, 31, 26, 25, 28, 24, 26, 23, 25, 33, 20, 27, 28, 24, 29,
|
||||||
|
32, 20, 24, 20, 19, 32, 24, 6, 24, 21, 26, 18, 15, 30, 19, 26, 22, 30, 35, 23, 22, 30, 20, 22,
|
||||||
|
18, 30, 28, 25, 16, 25, 27, 30, 18, 24, 30, 28, 20, 19, 20, 28, 21, 24, 15, 33, 20, 18, 20, 36,
|
||||||
|
30, 26, 25, 18, 28, 27, 31, 31, 15, 26, 16, 22, 27, 14, 17, 27, 27, 22, 32, 30, 22, 34, 22, 25,
|
||||||
|
20, 22, 26, 29, 28, 33, 18, 23, 20, 20, 27, 24, 28, 21, 25, 27, 25, 19, 19, 25, 19, 32, 29, 27,
|
||||||
|
23, 21, 28, 33, 23, 23, 28, 26, 31, 19, 21, 29, 21, 27, 23, 32, 24, 26, 21, 28, 28, 24, 17, 31,
|
||||||
|
27, 21, 19, 32, 28, 23, 30, 23, 29, 15, 26, 26, 15, 20, 25, 26, 27, 31, 21, 23, 23, 33, 28, 19,
|
||||||
|
23, 22, 22, 25, 27, 17, 23, 17, 25, 28, 26, 30, 32, 31, 19, 25, 25, 19, 23, 29, 27, 23, 34, 22,
|
||||||
|
13, 21, 32, 10, 20, 33, 21, 17, 29, 31, 14, 24, 23, 19, 19, 22, 17, 26, 37, 26, 22, 26, 38, 29,
|
||||||
|
29, 27, 30, 20, 31, 14, 32, 32, 24, 23, 23, 18, 21, 31, 24, 20, 28, 15, 21, 25, 25, 20, 30, 25,
|
||||||
|
22, 21, 21, 25, 24, 25, 18, 23, 28, 30, 20, 27, 27, 19, 10, 32, 24, 20, 29, 26, 25, 20, 25, 29,
|
||||||
|
28, 24, 32, 26, 22, 19, 23, 27, 27, 29, 20, 25, 21, 30, 28, 31, 24, 19, 23, 19, 19, 18, 30, 18,
|
||||||
|
16, 24, 20, 20, 30, 25, 29, 25, 31, 21, 28, 31, 24, 26, 27, 21, 24, 23, 26, 18, 32, 26, 28, 26,
|
||||||
|
24, 26, 29, 30, 22, 20, 24, 28, 25, 29, 20, 21, 22, 15, 30, 27, 33, 26, 22, 32, 30, 31, 20, 19,
|
||||||
|
24, 26, 27, 31, 17, 17, 33, 27, 16, 27, 27, 22, 27, 19, 24, 21, 17, 24, 28, 23, 26, 24, 19, 26,
|
||||||
|
20, 24, 22, 19, 22, 21, 21, 28, 29, 39, 19, 16, 25, 29, 31, 22, 22, 29, 26, 22, 22, 22, 26, 23,
|
||||||
|
23, 23, 30, 25, 25, 25, 27, 29, 18, 33, 21, 12, 22, 29, 12, 20, 35, 22, 34, 28, 18, 29, 21, 20,
|
||||||
|
24, 33, 24, 26, 23, 34, 31, 25, 31, 22, 35, 21, 20, 29, 27, 22, 30, 22, 27, 23, 22, 32, 16, 19,
|
||||||
|
27, 22, 24, 27, 21, 33, 25, 25, 19, 28, 20, 27, 21, 25, 28, 20, 27, 22, 21, 20, 26, 30, 33, 23,
|
||||||
|
20, 24, 17, 23, 28, 35, 14, 23, 22, 28, 28, 26, 25, 18, 20, 28, 28, 22, 13, 24, 22, 20, 30, 26,
|
||||||
|
26, 18, 22, 20, 23, 24, 20, 27, 34, 28, 18, 24, 34, 33, 25, 33, 37, 21, 20, 31, 19, 23, 29, 22,
|
||||||
|
21, 24, 19, 27, 19, 32, 25, 23, 33, 26, 33, 27, 29, 30, 19, 22, 30, 19, 18, 24, 25, 17, 31, 19,
|
||||||
|
31, 26, 22, 23, 28, 28, 25, 24, 19, 19, 27, 28, 23, 21, 29, 26, 31, 22, 22, 25, 16, 29, 21, 22,
|
||||||
|
23, 25, 22, 21, 22, 19, 27, 26, 28, 30, 22, 21, 24, 22, 23, 26, 28, 22, 18, 25, 23, 27, 31, 19,
|
||||||
|
15, 29, 20, 19, 27, 25, 21, 29, 22, 24, 25, 17, 36, 29, 22, 22, 24, 28, 27, 22, 26, 31, 29, 31,
|
||||||
|
18, 25, 23, 16, 37, 27, 21, 31, 25, 24, 20, 23, 28, 33, 24, 21, 26, 20, 18, 31, 20, 24, 23, 19,
|
||||||
|
27, 17, 23, 23, 20, 26, 28, 23, 26, 31, 25, 31, 19, 32, 26, 18, 19, 29, 20, 21, 15, 25, 27, 29,
|
||||||
|
22, 22, 22, 26, 23, 22, 23, 29, 28, 20, 21, 22, 20, 22, 27, 25, 23, 32, 23, 20, 31, 20, 27, 26,
|
||||||
|
34, 20, 22, 36, 21, 29, 25, 20, 21, 22, 29, 29, 25, 22, 24, 22
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::Float32 fieldC[nVerts] = {
|
||||||
|
3, 1, 4, 6, 5, 4, 8, 7, 2, 9, 2, 0, 0, 4, 3, 2, 5, 2, 3, 6, 3, 8, 3, 4,
|
||||||
|
3, 3, 2, 7, 2, 10, 9, 6, 1, 1, 4, 7, 3, 3, 1, 4, 4, 3, 9, 4, 4, 7, 3, 2,
|
||||||
|
4, 7, 3, 3, 2, 10, 1, 6, 2, 2, 3, 8, 3, 3, 6, 9, 4, 1, 4, 3, 16, 7, 0, 1,
|
||||||
|
8, 7, 13, 3, 5, 0, 3, 8, 10, 3, 5, 5, 1, 5, 2, 1, 3, 2, 5, 3, 4, 3, 3, 3,
|
||||||
|
3, 1, 13, 2, 3, 1, 2, 7, 3, 4, 1, 2, 5, 4, 4, 4, 2, 6, 3, 2, 7, 8, 1, 3,
|
||||||
|
4, 1, 2, 0, 1, 6, 1, 8, 8, 1, 1, 4, 2, 1, 4, 3, 5, 4, 6, 4, 2, 3, 8, 8,
|
||||||
|
3, 3, 3, 4, 5, 8, 8, 16, 7, 12, 4, 3, 14, 8, 3, 12, 5, 0, 5, 3, 5, 2, 9, 2,
|
||||||
|
9, 4, 1, 0, 0, 4, 4, 6, 3, 4, 11, 2, 4, 7, 4, 2, 1, 9, 4, 3, 2, 5, 1, 5,
|
||||||
|
3, 8, 2, 8, 1, 8, 0, 4, 1, 3, 2, 1, 2, 3, 2, 1, 8, 5, 4, 1, 9, 9, 1, 3,
|
||||||
|
5, 0, 1, 6, 10, 8, 3, 12, 3, 4, 4, 7, 1, 3, 6, 4, 4, 6, 1, 4, 7, 5, 6, 11,
|
||||||
|
6, 5, 2, 7, 2, 5, 3, 5, 6, 3, 6, 2, 1, 10, 8, 3, 7, 0, 2, 6, 9, 3, 11, 3,
|
||||||
|
2, 5, 1, 4, 6, 10, 9, 1, 4, 3, 7, 12, 3, 10, 0, 2, 11, 2, 1, 0, 4, 1, 2, 16,
|
||||||
|
5, 17, 7, 8, 2, 10, 10, 3, 1, 3, 2, 2, 4, 8, 4, 3, 2, 4, 4, 6, 8, 6, 2, 3,
|
||||||
|
2, 4, 2, 4, 7, 10, 5, 3, 5, 2, 4, 6, 9, 3, 1, 1, 1, 1, 4, 2, 2, 7, 4, 9,
|
||||||
|
2, 3, 5, 6, 2, 5, 1, 6, 5, 7, 8, 3, 7, 2, 2, 8, 6, 2, 10, 2, 1, 4, 5, 1,
|
||||||
|
1, 1, 5, 6, 1, 1, 4, 5, 4, 2, 4, 3, 2, 7, 19, 4, 7, 2, 7, 5, 2, 5, 3, 8,
|
||||||
|
4, 6, 7, 2, 0, 0, 2, 12, 6, 2, 2, 3, 5, 9, 4, 9, 2, 2, 7, 8, 3, 3, 10, 6,
|
||||||
|
3, 2, 1, 6, 2, 4, 6, 3, 5, 8, 2, 3, 6, 14, 0, 3, 6, 5, 2, 7, 0, 3, 8, 5,
|
||||||
|
3, 2, 2, 5, 1, 3, 12, 11, 16, 2, 1, 3, 7, 3, 1, 6, 4, 3, 12, 5, 1, 3, 1, 4,
|
||||||
|
9, 1, 3, 3, 4, 4, 6, 7, 7, 5, 2, 4, 2, 3, 2, 2, 6, 4, 2, 2, 3, 5, 1, 4,
|
||||||
|
9, 1, 0, 7, 6, 4, 3, 3, 7, 3, 3, 6, 2, 7, 9, 3, 1, 16, 5, 4, 3, 6, 3, 2,
|
||||||
|
5, 2, 2, 4, 3, 1, 3, 3, 6, 3, 5, 9, 1, 10, 1, 7, 2, 2, 6, 7, 3, 5, 3, 7,
|
||||||
|
2, 2, 2, 2, 6, 4, 3, 2, 5, 5, 3, 15, 4, 2, 7, 7, 4, 3, 3, 5, 1, 2, 9, 0,
|
||||||
|
5, 7, 12, 2, 4, 8, 5, 7, 8, 3, 2, 2, 18, 1, 7, 2, 2, 1, 3, 3, 3, 7, 1, 9,
|
||||||
|
8, 4, 3, 7, 6, 4, 5, 2, 0, 5, 1, 5, 10, 4, 2, 8, 2, 2, 0, 5, 6, 4, 5, 0,
|
||||||
|
1, 5, 11, 3, 3, 4, 4, 2, 3, 5, 1, 6, 5, 7, 2, 2, 5, 7, 4, 8, 4, 1, 1, 7,
|
||||||
|
2, 3, 9, 6, 13, 1, 5, 4, 6, 2, 4, 11, 2, 5, 5, 1, 4, 1, 4, 7, 1, 5, 8, 3,
|
||||||
|
1, 10, 9, 13, 1, 7, 2, 9, 4, 3, 3, 10, 12, 2, 0, 4, 6, 5, 5, 1, 4, 7, 2, 12,
|
||||||
|
7, 6, 5, 0, 6, 4, 4, 12, 1, 3, 10, 1, 9, 2, 2, 2, 1, 5, 5, 6, 9, 6, 4, 1,
|
||||||
|
11, 6, 9, 3, 2, 7, 1, 7, 4, 3, 0, 3, 1, 12, 17, 2, 1, 6, 4, 4, 2, 1, 5, 5,
|
||||||
|
3, 2, 2, 4, 6, 5, 4, 6, 11, 3, 12, 6, 3, 6, 3, 0, 6, 3, 7, 4, 8, 5, 14, 5,
|
||||||
|
1, 9, 4, 6, 5, 3, 9, 3, 1, 1, 0, 3, 7, 3, 5, 1, 6, 2, 2, 6, 2, 12, 1, 0,
|
||||||
|
6, 3, 3, 5, 4, 7, 2, 2, 15, 7, 3, 10, 4, 2, 6, 3, 4, 8, 3, 1, 5, 5, 5, 4,
|
||||||
|
3, 7, 3, 4, 5, 5, 2, 4, 2, 5, 1, 12, 5, 6, 3, 2, 8, 5, 2, 3, 11, 11, 6, 5,
|
||||||
|
0, 3, 3, 9, 4, 2, 11, 1, 5, 3, 5, 6, 3, 6, 4, 2, 4, 10, 11, 3, 3, 4, 1, 1,
|
||||||
|
1, 3, 5, 5, 1, 1, 4, 1, 5, 1, 6, 8, 6, 4, 6, 7, 6, 3, 5, 3, 6, 6, 6, 4,
|
||||||
|
0, 6, 3, 1, 2, 4, 2, 6, 1, 1, 1, 2, 2, 4, 7, 2, 6, 2, 5, 7, 6, 4, 6, 3,
|
||||||
|
1, 4, 5, 1, 4, 6, 2, 3, 0, 6, 11, 2, 9, 2, 6, 4, 5, 6, 2, 19, 2, 10, 4, 2,
|
||||||
|
3, 3, 11, 7, 3, 3, 1, 5, 3, 6, 4, 3, 0, 6, 6, 6, 4, 2, 5, 2, 2, 2, 6, 10,
|
||||||
|
4, 9, 3, 7, 7, 0, 6, 8, 5, 2, 3, 2, 3, 3, 3, 1, 6, 1, 8, 2, 5, 3, 6, 11,
|
||||||
|
5, 7, 2, 6, 7, 3, 4, 1, 0, 5, 8, 3, 2, 9, 3, 1, 2, 3, 3, 9, 5, 6, 5, 1,
|
||||||
|
4, 5, 6, 7, 6, 1, 5, 1, 6, 6, 2, 6, 7, 2, 4, 6
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleUniformPointCoordinates coordinates(vtkm::Id3(xVerts, yVerts, 1));
|
||||||
|
dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coordinates));
|
||||||
|
|
||||||
|
// Set point scalars
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldA", vtkm::cont::Field::ASSOC_POINTS, fieldA, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldB", vtkm::cont::Field::ASSOC_POINTS, fieldB, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldC", vtkm::cont::Field::ASSOC_POINTS, fieldC, nVerts));
|
||||||
|
|
||||||
|
return dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunTest()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet ds = MakeTestDataSet();
|
||||||
|
|
||||||
|
vtkm::filter::NDEntropy ndEntropyFilter;
|
||||||
|
|
||||||
|
ndEntropyFilter.AddFieldAndBin("fieldA", 10);
|
||||||
|
ndEntropyFilter.AddFieldAndBin("fieldB", 10);
|
||||||
|
ndEntropyFilter.AddFieldAndBin("fieldC", 10);
|
||||||
|
|
||||||
|
//Entropy is just a single number
|
||||||
|
//It is stored in "Entropy" (type vtkm::Float64) field in the return dataset
|
||||||
|
//The field has only one element, the entropy
|
||||||
|
vtkm::filter::Result resultData = ndEntropyFilter.Execute(ds);
|
||||||
|
vtkm::cont::DataSet& outputData = resultData.GetDataSet();
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float64> entropyHandle;
|
||||||
|
outputData.GetField("Entropy").GetData().CopyTo(entropyHandle);
|
||||||
|
vtkm::Float64 e = entropyHandle.GetPortalControl().Get(0);
|
||||||
|
|
||||||
|
VTKM_TEST_ASSERT(fabs(e - 7.457857) < 0.001,
|
||||||
|
"N-Dimentional entropy filter calculation is incorrect");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
int UnitTestNDEntropyFilter(int, char* [])
|
||||||
|
{
|
||||||
|
return vtkm::cont::testing::Testing::Run(RunTest);
|
||||||
|
}
|
129
vtkm/filter/testing/UnitTestNDHistogramFilter.cxx
Normal file
129
vtkm/filter/testing/UnitTestNDHistogramFilter.cxx
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2016 Sandia Corporation.
|
||||||
|
// Copyright 2016 UT-Battelle, LLC.
|
||||||
|
// Copyright 2016 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vtkm/filter/NDHistogram.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
||||||
|
#include <vtkm/cont/testing/Testing.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
vtkm::cont::DataSet MakeTestDataSet()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet dataSet;
|
||||||
|
|
||||||
|
const int nVerts = 100;
|
||||||
|
|
||||||
|
vtkm::Float32 fieldA[nVerts] = { 8, 10, 9, 8, 14, 11, 12, 9, 19, 7, 8, 11, 7, 10, 11,
|
||||||
|
11, 11, 6, 8, 8, 7, 15, 9, 7, 8, 10, 9, 10, 10, 12,
|
||||||
|
7, 6, 14, 10, 14, 10, 7, 11, 13, 9, 13, 11, 10, 10, 12,
|
||||||
|
12, 7, 12, 10, 11, 12, 8, 13, 9, 5, 12, 11, 9, 5, 9,
|
||||||
|
12, 9, 6, 10, 11, 9, 9, 11, 9, 7, 7, 18, 16, 13, 12,
|
||||||
|
8, 10, 11, 9, 8, 17, 3, 15, 15, 9, 10, 10, 8, 10, 9,
|
||||||
|
7, 9, 8, 10, 13, 9, 7, 11, 7, 10 };
|
||||||
|
|
||||||
|
vtkm::Float32 fieldB[nVerts] = { 24, 19, 28, 19, 25, 28, 25, 22, 27, 26, 35, 26, 30, 28, 24,
|
||||||
|
23, 21, 31, 20, 11, 21, 22, 14, 25, 20, 24, 24, 21, 24, 29,
|
||||||
|
26, 21, 32, 29, 23, 28, 31, 25, 23, 30, 18, 24, 22, 25, 33,
|
||||||
|
24, 22, 23, 21, 17, 20, 28, 30, 18, 20, 32, 25, 24, 32, 15,
|
||||||
|
27, 24, 27, 19, 30, 27, 17, 24, 29, 23, 22, 19, 24, 19, 28,
|
||||||
|
24, 25, 24, 25, 30, 24, 31, 30, 27, 25, 25, 25, 15, 29, 23,
|
||||||
|
29, 29, 21, 25, 35, 24, 28, 10, 31, 23 };
|
||||||
|
|
||||||
|
vtkm::Float32 fieldC[nVerts] = {
|
||||||
|
3, 1, 4, 6, 5, 4, 8, 7, 2, 9, 2, 0, 0, 4, 3, 2, 5, 2, 3, 6, 3, 8, 3, 4, 3,
|
||||||
|
3, 2, 7, 2, 10, 9, 6, 1, 1, 4, 7, 3, 3, 1, 4, 4, 3, 9, 4, 4, 7, 3, 2, 4, 7,
|
||||||
|
3, 3, 2, 10, 1, 6, 2, 2, 3, 8, 3, 3, 6, 9, 4, 1, 4, 3, 16, 7, 0, 1, 8, 7, 13,
|
||||||
|
3, 5, 0, 3, 8, 10, 3, 5, 5, 1, 5, 2, 1, 3, 2, 5, 3, 4, 3, 3, 3, 3, 1, 13, 2
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set point scalars
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldA", vtkm::cont::Field::ASSOC_POINTS, fieldA, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldB", vtkm::cont::Field::ASSOC_POINTS, fieldB, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldC", vtkm::cont::Field::ASSOC_POINTS, fieldC, nVerts));
|
||||||
|
|
||||||
|
return dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RunTest()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet ds = MakeTestDataSet();
|
||||||
|
|
||||||
|
vtkm::filter::NDHistogram ndHistFilter;
|
||||||
|
|
||||||
|
ndHistFilter.AddFieldAndBin("fieldA", 4);
|
||||||
|
ndHistFilter.AddFieldAndBin("fieldB", 4);
|
||||||
|
ndHistFilter.AddFieldAndBin("fieldC", 4);
|
||||||
|
|
||||||
|
//The return data set contains fieldNames.size() + 1 fields
|
||||||
|
//The first "fieldNames.size()"" fields are the binId arrays for inputs field
|
||||||
|
//And their order and field names are the same as the order and name in fieldNames
|
||||||
|
//The name of last fields in the dataset is "Frequency"
|
||||||
|
//This field contains the all freqncys of the N-Dims histogram
|
||||||
|
//The result histogram is stored in sparse representation
|
||||||
|
//(Do not store and return zero frequency bins)
|
||||||
|
//All fields in return dataset must have the same length
|
||||||
|
//So, e.g. (FieldA[i], FieldB[i], FieldC[i], Frequency[i] ) is a bin in the histogram
|
||||||
|
//First three numbers are binID for FieldA, FieldB, FieldC
|
||||||
|
//Frequency[i] is frequency for this bin
|
||||||
|
vtkm::filter::Result resultData = ndHistFilter.Execute(ds);
|
||||||
|
vtkm::cont::DataSet& outputData = resultData.GetDataSet();
|
||||||
|
|
||||||
|
// Ground truth ND histogram
|
||||||
|
vtkm::Id gtNonSparseBins = 33;
|
||||||
|
vtkm::Id gtIdx0[33] = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3 };
|
||||||
|
vtkm::Id gtIdx1[33] = { 1, 1, 2, 3, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3,
|
||||||
|
0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2, 2, 3 };
|
||||||
|
vtkm::Id gtIdx2[33] = { 0, 1, 1, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 3,
|
||||||
|
0, 0, 1, 0, 1, 2, 3, 0, 1, 2, 0, 2, 0, 1, 2, 1 };
|
||||||
|
vtkm::Id gtFreq[33] = { 1, 1, 1, 3, 2, 1, 1, 6, 6, 3, 17, 8, 2, 6, 2, 1, 2,
|
||||||
|
1, 1, 4, 11, 4, 1, 1, 3, 3, 1, 1, 1, 1, 1, 2, 1 };
|
||||||
|
|
||||||
|
// Check result
|
||||||
|
vtkm::Id nonSparseBins = outputData.GetField(0).GetData().GetNumberOfValues();
|
||||||
|
VTKM_TEST_ASSERT(nonSparseBins == gtNonSparseBins, "Incorrect ND-histogram Filter results");
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> binId0;
|
||||||
|
outputData.GetField("fieldA").GetData().CopyTo(binId0);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> binId1;
|
||||||
|
outputData.GetField("fieldB").GetData().CopyTo(binId1);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> binId2;
|
||||||
|
outputData.GetField("fieldC").GetData().CopyTo(binId2);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> freqs;
|
||||||
|
outputData.GetField("Frequency").GetData().CopyTo(freqs);
|
||||||
|
for (int i = 0; i < nonSparseBins; i++)
|
||||||
|
{
|
||||||
|
vtkm::Id idx0 = binId0.GetPortalControl().Get(i);
|
||||||
|
vtkm::Id idx1 = binId1.GetPortalControl().Get(i);
|
||||||
|
vtkm::Id idx2 = binId2.GetPortalControl().Get(i);
|
||||||
|
vtkm::Id f = freqs.GetPortalControl().Get(i);
|
||||||
|
VTKM_TEST_ASSERT(idx0 == gtIdx0[i] && idx1 == gtIdx1[i] && idx2 == gtIdx2[i] && f == gtFreq[i],
|
||||||
|
"Incorrect ND-histogram Filter results");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
int UnitTestNDHistogramFilter(int, char* [])
|
||||||
|
{
|
||||||
|
return vtkm::cont::testing::Testing::Run(RunTest);
|
||||||
|
}
|
@ -187,14 +187,14 @@ private:
|
|||||||
|
|
||||||
out << "CELLS " << nCells << " " << conn_length << std::endl;
|
out << "CELLS " << nCells << " " << conn_length << std::endl;
|
||||||
|
|
||||||
vtkm::Vec<vtkm::Id, 8> ids;
|
|
||||||
for (vtkm::Id i = 0; i < nCells; ++i)
|
for (vtkm::Id i = 0; i < nCells; ++i)
|
||||||
{
|
{
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> ids;
|
||||||
vtkm::Id nids = cellSet.GetNumberOfPointsInCell(i);
|
vtkm::Id nids = cellSet.GetNumberOfPointsInCell(i);
|
||||||
cellSet.GetIndices(i, ids);
|
cellSet.GetIndices(i, ids);
|
||||||
out << nids;
|
out << nids;
|
||||||
for (int j = 0; j < nids; ++j)
|
for (int j = 0; j < nids; ++j)
|
||||||
out << " " << ids[j];
|
out << " " << ids.GetPortalControl().Get(j);
|
||||||
out << std::endl;
|
out << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ set(headers
|
|||||||
CellDeepCopy.h
|
CellDeepCopy.h
|
||||||
Clip.h
|
Clip.h
|
||||||
ContourTreeUniform.h
|
ContourTreeUniform.h
|
||||||
|
CosmoTools.h
|
||||||
DispatcherMapField.h
|
DispatcherMapField.h
|
||||||
DispatcherMapTopology.h
|
DispatcherMapTopology.h
|
||||||
DispatcherPointNeighborhood.h
|
DispatcherPointNeighborhood.h
|
||||||
@ -45,6 +46,9 @@ set(headers
|
|||||||
MarchingCubesDataTables.h
|
MarchingCubesDataTables.h
|
||||||
Mask.h
|
Mask.h
|
||||||
MaskPoints.h
|
MaskPoints.h
|
||||||
|
NDimsEntropy.h
|
||||||
|
NDimsHistogram.h
|
||||||
|
NDimsHistMarginalization.h
|
||||||
ParticleAdvection.h
|
ParticleAdvection.h
|
||||||
PointAverage.h
|
PointAverage.h
|
||||||
PointElevation.h
|
PointElevation.h
|
||||||
@ -70,6 +74,7 @@ set(headers
|
|||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
add_subdirectory(internal)
|
add_subdirectory(internal)
|
||||||
add_subdirectory(contourtree)
|
add_subdirectory(contourtree)
|
||||||
|
add_subdirectory(cosmotools)
|
||||||
add_subdirectory(gradient)
|
add_subdirectory(gradient)
|
||||||
add_subdirectory(splatkernels)
|
add_subdirectory(splatkernels)
|
||||||
add_subdirectory(spatialstructure)
|
add_subdirectory(spatialstructure)
|
||||||
|
149
vtkm/worklet/CosmoTools.h
Normal file
149
vtkm/worklet/CosmoTools.h
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtk_m_worklet_CosmoTools_h
|
||||||
|
#define vtk_m_worklet_CosmoTools_h
|
||||||
|
|
||||||
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
|
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||||
|
#include <vtkm/cont/Field.h>
|
||||||
|
|
||||||
|
#include <vtkm/worklet/cosmotools/CosmoTools.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/CosmoToolsCenterFinder.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/CosmoToolsHaloFinder.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
|
||||||
|
class CosmoTools
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Run the halo finder and then the NxN MBP center finder
|
||||||
|
template <typename FieldType, typename StorageType, typename DeviceAdapter>
|
||||||
|
void RunHaloFinder(vtkm::cont::ArrayHandle<FieldType, StorageType>& xLocation,
|
||||||
|
vtkm::cont::ArrayHandle<FieldType, StorageType>& yLocation,
|
||||||
|
vtkm::cont::ArrayHandle<FieldType, StorageType>& zLocation,
|
||||||
|
const vtkm::Id nParticles,
|
||||||
|
const FieldType particleMass,
|
||||||
|
const vtkm::Id minHaloSize,
|
||||||
|
const FieldType linkingLen,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& resultHaloId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& resultMBP,
|
||||||
|
vtkm::cont::ArrayHandle<FieldType>& resultPot,
|
||||||
|
const DeviceAdapter&)
|
||||||
|
{
|
||||||
|
// Constructor gets particle locations, particle mass and min halo size
|
||||||
|
cosmotools::CosmoTools<FieldType, StorageType, DeviceAdapter> cosmo(
|
||||||
|
nParticles, particleMass, minHaloSize, linkingLen, xLocation, yLocation, zLocation);
|
||||||
|
|
||||||
|
// Find the halos within the particles and the MBP center of each halo
|
||||||
|
cosmo.HaloFinder(resultHaloId, resultMBP, resultPot);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run MBP on a single halo of particles using the N^2 algorithm
|
||||||
|
template <typename FieldType, typename StorageType, typename DeviceAdapter>
|
||||||
|
void RunMBPCenterFinderNxN(vtkm::cont::ArrayHandle<FieldType, StorageType> xLocation,
|
||||||
|
vtkm::cont::ArrayHandle<FieldType, StorageType> yLocation,
|
||||||
|
vtkm::cont::ArrayHandle<FieldType, StorageType> zLocation,
|
||||||
|
const vtkm::Id nParticles,
|
||||||
|
const FieldType particleMass,
|
||||||
|
vtkm::Pair<vtkm::Id, FieldType>& nxnResult,
|
||||||
|
const DeviceAdapter&)
|
||||||
|
{
|
||||||
|
// Constructor gets particle locations and particle mass
|
||||||
|
cosmotools::CosmoTools<FieldType, StorageType, DeviceAdapter> cosmo(
|
||||||
|
nParticles, particleMass, xLocation, yLocation, zLocation);
|
||||||
|
|
||||||
|
// Most Bound Particle N x N algorithm
|
||||||
|
FieldType nxnPotential;
|
||||||
|
vtkm::Id nxnMBP = cosmo.MBPCenterFinderNxN(&nxnPotential);
|
||||||
|
|
||||||
|
nxnResult.first = nxnMBP;
|
||||||
|
nxnResult.second = nxnPotential;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run MBP on a single halo of particles using MxN estimation algorithm
|
||||||
|
template <typename FieldType, typename StorageType, typename DeviceAdapter>
|
||||||
|
void RunMBPCenterFinderMxN(vtkm::cont::ArrayHandle<FieldType, StorageType> xLocation,
|
||||||
|
vtkm::cont::ArrayHandle<FieldType, StorageType> yLocation,
|
||||||
|
vtkm::cont::ArrayHandle<FieldType, StorageType> zLocation,
|
||||||
|
const vtkm::Id nParticles,
|
||||||
|
const FieldType particleMass,
|
||||||
|
vtkm::Pair<vtkm::Id, FieldType>& mxnResult,
|
||||||
|
const DeviceAdapter&)
|
||||||
|
{
|
||||||
|
// Constructor gets particle locations and particle mass
|
||||||
|
cosmotools::CosmoTools<FieldType, StorageType, DeviceAdapter> cosmo(
|
||||||
|
nParticles, particleMass, xLocation, yLocation, zLocation);
|
||||||
|
|
||||||
|
// Most Bound Particle M x N algorithm with binning estimates
|
||||||
|
FieldType mxnPotential;
|
||||||
|
vtkm::Id mxnMBP = cosmo.MBPCenterFinderMxN(&mxnPotential);
|
||||||
|
|
||||||
|
mxnResult.first = mxnMBP;
|
||||||
|
mxnResult.second = mxnPotential;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace vtkm::worklet
|
||||||
|
|
||||||
|
#endif // vtk_m_worklet_CosmoTools_h
|
103
vtkm/worklet/NDimsEntropy.h
Normal file
103
vtkm/worklet/NDimsEntropy.h
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtk_m_worklet_NDimsEntropy_h
|
||||||
|
#define vtk_m_worklet_NDimsEntropy_h
|
||||||
|
|
||||||
|
#include <vtkm/Math.h>
|
||||||
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||||
|
#include <vtkm/cont/DeviceAdapter.h>
|
||||||
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
|
#include <vtkm/worklet/NDimsHistogram.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
#include <vtkm/worklet/histogram/ComputeNDEntropy.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/Field.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
|
||||||
|
class NDimsEntropy
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename DeviceAdapter>
|
||||||
|
void SetNumOfDataPoints(vtkm::Id _numDataPoints, DeviceAdapter device)
|
||||||
|
{
|
||||||
|
NumDataPoints = _numDataPoints;
|
||||||
|
NdHistogram.SetNumOfDataPoints(_numDataPoints, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a field and the bin for this field
|
||||||
|
// Return: rangeOfRange is min max value of this array
|
||||||
|
// binDelta is delta of a bin
|
||||||
|
template <typename HandleType, typename DeviceAdapter>
|
||||||
|
void AddField(const HandleType& fieldArray, vtkm::Id numberOfBins, DeviceAdapter device)
|
||||||
|
{
|
||||||
|
vtkm::Range range;
|
||||||
|
vtkm::Float64 delta;
|
||||||
|
|
||||||
|
NdHistogram.AddField(fieldArray, numberOfBins, range, delta, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the entropy computation filter given
|
||||||
|
// fields and number of bins of each fields
|
||||||
|
// Returns:
|
||||||
|
// Entropy (log2) of the field of the data
|
||||||
|
template <typename DeviceAdapter>
|
||||||
|
vtkm::Float64 Run(DeviceAdapter device)
|
||||||
|
{
|
||||||
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithms;
|
||||||
|
|
||||||
|
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>> binIds;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> freqs;
|
||||||
|
NdHistogram.Run(binIds, freqs, device);
|
||||||
|
|
||||||
|
///// calculate sum of frequency of the histogram /////
|
||||||
|
vtkm::Id initFreqSumValue = 0;
|
||||||
|
vtkm::Id freqSum = DeviceAlgorithms::Reduce(freqs, initFreqSumValue, vtkm::Sum());
|
||||||
|
|
||||||
|
///// calculate information content of each bin using self-define worklet /////
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float64> informationContent;
|
||||||
|
vtkm::worklet::histogram::SetBinInformationContent binWorklet(
|
||||||
|
static_cast<vtkm::Float64>(freqSum));
|
||||||
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::histogram::SetBinInformationContent,
|
||||||
|
DeviceAdapter>
|
||||||
|
setBinInformationContentDispatcher(binWorklet);
|
||||||
|
setBinInformationContentDispatcher.Invoke(freqs, informationContent);
|
||||||
|
|
||||||
|
///// calculate entropy by summing up information conetent of all bins /////
|
||||||
|
vtkm::Float64 initEntropyValue = 0;
|
||||||
|
vtkm::Float64 entropy =
|
||||||
|
DeviceAlgorithms::Reduce(informationContent, initEntropyValue, vtkm::Sum());
|
||||||
|
|
||||||
|
return entropy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
vtkm::worklet::NDimsHistogram NdHistogram;
|
||||||
|
vtkm::Id NumDataPoints;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace vtkm::worklet
|
||||||
|
|
||||||
|
#endif // vtk_m_worklet_NDimsEntropy_h
|
219
vtkm/worklet/NDimsHistMarginalization.h
Normal file
219
vtkm/worklet/NDimsHistMarginalization.h
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtk_m_worklet_NDimsHistMarginalization_h
|
||||||
|
#define vtk_m_worklet_NDimsHistMarginalization_h
|
||||||
|
|
||||||
|
#include <vtkm/Math.h>
|
||||||
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/cont/DeviceAdapter.h>
|
||||||
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
#include <vtkm/worklet/histogram/ComputeNDHistogram.h>
|
||||||
|
#include <vtkm/worklet/histogram/ComputeNDHistogram.h>
|
||||||
|
#include <vtkm/worklet/histogram/ComputeNDHistogram.h>
|
||||||
|
#include <vtkm/worklet/histogram/MarginalizeNDHistogram.h>
|
||||||
|
#include <vtkm/worklet/histogram/MarginalizeNDHistogram.h>
|
||||||
|
#include <vtkm/worklet/histogram/MarginalizeNDHistogram.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/Field.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
class NDimsHistMarginalization
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Execute the histogram (conditional) marginalization,
|
||||||
|
// given the multi-variable histogram(binId, freqIn)
|
||||||
|
// , marginalVariable and marginal condition
|
||||||
|
// Input arguments:
|
||||||
|
// binId, freqsIn: input ND-histogram in the fashion of sparse representation
|
||||||
|
// (definition of binId and frqIn please refer to NDimsHistogram.h),
|
||||||
|
// (binId.size() is the number of variables)
|
||||||
|
// numberOfBins: number of bins of each variable (length of numberOfBins must be the same as binId.size() )
|
||||||
|
// marginalVariables: length is the same as number of variables.
|
||||||
|
// 1 indicates marginal variable, otherwise 0.
|
||||||
|
// conditionFunc: The Condition function for non-marginal variable.
|
||||||
|
// This func takes two arguments (vtkm::Id var, vtkm::Id binId) and return bool
|
||||||
|
// var is index of variable and binId is bin index in the varaiable var
|
||||||
|
// return true indicates considering this bin into final marginal histogram
|
||||||
|
// more details can refer to example in UnitTestNDimsHistMarginalization.cxx
|
||||||
|
// marginalBinId, marginalFreqs: return marginalized histogram in the fashion of sparse representation
|
||||||
|
// the definition is the same as (binId and freqsIn)
|
||||||
|
template <typename BinaryCompare, typename DeviceAdapter>
|
||||||
|
void Run(const std::vector<vtkm::cont::ArrayHandle<vtkm::Id>>& binId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& freqsIn,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& numberOfBins,
|
||||||
|
vtkm::cont::ArrayHandle<bool>& marginalVariables,
|
||||||
|
BinaryCompare conditionFunc,
|
||||||
|
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>>& marginalBinId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& marginalFreqs,
|
||||||
|
DeviceAdapter vtkmNotUsed(device))
|
||||||
|
{
|
||||||
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithms;
|
||||||
|
|
||||||
|
//total variables
|
||||||
|
vtkm::Id numOfVariable = static_cast<vtkm::Id>(binId.size());
|
||||||
|
|
||||||
|
const vtkm::Id numberOfValues = freqsIn.GetPortalConstControl().GetNumberOfValues();
|
||||||
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> constant0Array(0, numberOfValues);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> bin1DIndex;
|
||||||
|
DeviceAlgorithms::Copy(constant0Array, bin1DIndex);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> freqs;
|
||||||
|
DeviceAlgorithms::Copy(freqsIn, freqs);
|
||||||
|
vtkm::Id numMarginalVariables = 0; //count num of marginal variables
|
||||||
|
for (vtkm::Id i = 0; i < numOfVariable; i++)
|
||||||
|
{
|
||||||
|
if (marginalVariables.GetPortalConstControl().Get(i) == true)
|
||||||
|
{
|
||||||
|
// Worklet to calculate 1D index for marginal variables
|
||||||
|
numMarginalVariables++;
|
||||||
|
const vtkm::Id nFieldBins = numberOfBins.GetPortalControl().Get(i);
|
||||||
|
vtkm::worklet::histogram::To1DIndex binWorklet(nFieldBins);
|
||||||
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::histogram::To1DIndex, DeviceAdapter>
|
||||||
|
to1DIndexDispatcher(binWorklet);
|
||||||
|
size_t vecIndex = static_cast<size_t>(i);
|
||||||
|
to1DIndexDispatcher.Invoke(binId[vecIndex], bin1DIndex, bin1DIndex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ //non-marginal variable
|
||||||
|
// Worklet to set the frequency of entities which does not meet the condition
|
||||||
|
// to 0 on non-marginal variables
|
||||||
|
vtkm::worklet::histogram::ConditionalFreq<BinaryCompare> conditionalFreqWorklet{
|
||||||
|
conditionFunc
|
||||||
|
};
|
||||||
|
conditionalFreqWorklet.setVar(i);
|
||||||
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::histogram::ConditionalFreq<BinaryCompare>,
|
||||||
|
DeviceAdapter>
|
||||||
|
cfDispatcher(conditionalFreqWorklet);
|
||||||
|
size_t vecIndex = static_cast<size_t>(i);
|
||||||
|
cfDispatcher.Invoke(binId[vecIndex], freqs, freqs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Sort the freq array for counting by key(1DIndex)
|
||||||
|
DeviceAlgorithms::SortByKey(bin1DIndex, freqs);
|
||||||
|
|
||||||
|
// Add frequency within same 1d index bin (this get a nonSparse representation)
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> nonSparseMarginalFreqs;
|
||||||
|
DeviceAlgorithms::ReduceByKey(
|
||||||
|
bin1DIndex, freqs, bin1DIndex, nonSparseMarginalFreqs, vtkm::Add());
|
||||||
|
|
||||||
|
// Convert to sparse representation(remove all zero freqncy entities)
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> sparseMarginal1DBinId;
|
||||||
|
DeviceAlgorithms::CopyIf(bin1DIndex, nonSparseMarginalFreqs, sparseMarginal1DBinId);
|
||||||
|
DeviceAlgorithms::CopyIf(nonSparseMarginalFreqs, nonSparseMarginalFreqs, marginalFreqs);
|
||||||
|
|
||||||
|
//convert back to multi variate binId
|
||||||
|
marginalBinId.resize(static_cast<size_t>(numMarginalVariables));
|
||||||
|
vtkm::Id marginalVarIdx = numMarginalVariables - 1;
|
||||||
|
for (vtkm::Id i = numOfVariable - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (marginalVariables.GetPortalConstControl().Get(i) == true)
|
||||||
|
{
|
||||||
|
const vtkm::Id nFieldBins = numberOfBins.GetPortalControl().Get(i);
|
||||||
|
vtkm::worklet::histogram::ConvertHistBinToND binWorklet(nFieldBins);
|
||||||
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::histogram::ConvertHistBinToND,
|
||||||
|
DeviceAdapter>
|
||||||
|
ConvertHistBinToNDDispatcher(binWorklet);
|
||||||
|
size_t vecIndex = static_cast<size_t>(marginalVarIdx);
|
||||||
|
ConvertHistBinToNDDispatcher.Invoke(
|
||||||
|
sparseMarginal1DBinId, sparseMarginal1DBinId, marginalBinId[vecIndex]);
|
||||||
|
marginalVarIdx--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} //Run()
|
||||||
|
|
||||||
|
// Execute the histogram marginalization WITHOUT CONDITION,
|
||||||
|
// Please refer to the other Run() functions for the definition of input arguments.
|
||||||
|
template <typename DeviceAdapter>
|
||||||
|
void Run(const std::vector<vtkm::cont::ArrayHandle<vtkm::Id>>& binId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& freqsIn,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& numberOfBins,
|
||||||
|
vtkm::cont::ArrayHandle<bool>& marginalVariables,
|
||||||
|
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>>& marginalBinId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& marginalFreqs,
|
||||||
|
DeviceAdapter vtkmNotUsed(device))
|
||||||
|
{
|
||||||
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithms;
|
||||||
|
|
||||||
|
//total variables
|
||||||
|
vtkm::Id numOfVariable = static_cast<vtkm::Id>(binId.size());
|
||||||
|
|
||||||
|
const vtkm::Id numberOfValues = freqsIn.GetPortalConstControl().GetNumberOfValues();
|
||||||
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> constant0Array(0, numberOfValues);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> bin1DIndex;
|
||||||
|
DeviceAlgorithms::Copy(constant0Array, bin1DIndex);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> freqs;
|
||||||
|
DeviceAlgorithms::Copy(freqsIn, freqs);
|
||||||
|
vtkm::Id numMarginalVariables = 0; //count num of marginal varaibles
|
||||||
|
for (vtkm::Id i = 0; i < numOfVariable; i++)
|
||||||
|
{
|
||||||
|
if (marginalVariables.GetPortalConstControl().Get(i) == true)
|
||||||
|
{
|
||||||
|
// Worklet to calculate 1D index for marginal variables
|
||||||
|
numMarginalVariables++;
|
||||||
|
const vtkm::Id nFieldBins = numberOfBins.GetPortalControl().Get(i);
|
||||||
|
vtkm::worklet::histogram::To1DIndex binWorklet(nFieldBins);
|
||||||
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::histogram::To1DIndex, DeviceAdapter>
|
||||||
|
to1DIndexDispatcher(binWorklet);
|
||||||
|
size_t vecIndex = static_cast<size_t>(i);
|
||||||
|
to1DIndexDispatcher.Invoke(binId[vecIndex], bin1DIndex, bin1DIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the freq array for counting by key (1DIndex)
|
||||||
|
DeviceAlgorithms::SortByKey(bin1DIndex, freqs);
|
||||||
|
|
||||||
|
// Add frequency within same 1d index bin
|
||||||
|
DeviceAlgorithms::ReduceByKey(bin1DIndex, freqs, bin1DIndex, marginalFreqs, vtkm::Add());
|
||||||
|
|
||||||
|
//convert back to multi variate binId
|
||||||
|
marginalBinId.resize(static_cast<size_t>(numMarginalVariables));
|
||||||
|
vtkm::Id marginalVarIdx = numMarginalVariables - 1;
|
||||||
|
for (vtkm::Id i = numOfVariable - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (marginalVariables.GetPortalConstControl().Get(i) == true)
|
||||||
|
{
|
||||||
|
const vtkm::Id nFieldBins = numberOfBins.GetPortalControl().Get(i);
|
||||||
|
vtkm::worklet::histogram::ConvertHistBinToND binWorklet(nFieldBins);
|
||||||
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::histogram::ConvertHistBinToND,
|
||||||
|
DeviceAdapter>
|
||||||
|
ConvertHistBinToNDDispatcher(binWorklet);
|
||||||
|
size_t vecIndex = static_cast<size_t>(marginalVarIdx);
|
||||||
|
ConvertHistBinToNDDispatcher.Invoke(bin1DIndex, bin1DIndex, marginalBinId[vecIndex]);
|
||||||
|
marginalVarIdx--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} //Run()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace vtkm::worklet
|
||||||
|
|
||||||
|
#endif // vtk_m_worklet_NDimsHistMarginalization_h
|
127
vtkm/worklet/NDimsHistogram.h
Normal file
127
vtkm/worklet/NDimsHistogram.h
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtk_m_worklet_NDimsHistogram_h
|
||||||
|
#define vtk_m_worklet_NDimsHistogram_h
|
||||||
|
|
||||||
|
#include <vtkm/Math.h>
|
||||||
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/cont/DeviceAdapter.h>
|
||||||
|
#include <vtkm/cont/ErrorBadValue.h>
|
||||||
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
#include <vtkm/worklet/histogram/ComputeNDHistogram.h>
|
||||||
|
#include <vtkm/worklet/histogram/ComputeNDHistogram.h>
|
||||||
|
#include <vtkm/worklet/histogram/ComputeNDHistogram.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/Field.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
|
||||||
|
class NDimsHistogram
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <typename DeviceAdapter>
|
||||||
|
void SetNumOfDataPoints(vtkm::Id _numDataPoints, DeviceAdapter vtkmNotUsed(device))
|
||||||
|
{
|
||||||
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithms;
|
||||||
|
|
||||||
|
NumDataPoints = _numDataPoints;
|
||||||
|
|
||||||
|
// Initialize bin1DIndex array
|
||||||
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> constant0Array(0, NumDataPoints);
|
||||||
|
DeviceAlgorithms::Copy(constant0Array, Bin1DIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a field and the bin number for this field
|
||||||
|
// Return: rangeOfRange is min max value of this array
|
||||||
|
// binDelta is delta of a bin
|
||||||
|
template <typename HandleType, typename DeviceAdapter>
|
||||||
|
void AddField(const HandleType& fieldArray,
|
||||||
|
vtkm::Id numberOfBins,
|
||||||
|
vtkm::Range& rangeOfValues,
|
||||||
|
vtkm::Float64& binDelta,
|
||||||
|
DeviceAdapter vtkmNotUsed(device))
|
||||||
|
{
|
||||||
|
NumberOfBins.push_back(numberOfBins);
|
||||||
|
|
||||||
|
if (fieldArray.GetNumberOfValues() != NumDataPoints)
|
||||||
|
{
|
||||||
|
throw vtkm::cont::ErrorBadValue("Array lengths does not match");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CastAndCall(fieldArray.ResetTypeList(vtkm::TypeListTagScalarAll()),
|
||||||
|
vtkm::worklet::histogram::ComputeBins<DeviceAdapter>(
|
||||||
|
Bin1DIndex, numberOfBins, rangeOfValues, binDelta));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute N-Dim histogram worklet to get N-Dims histogram from input fields
|
||||||
|
// Input arguments:
|
||||||
|
// binId: returned bin id of NDims-histogram, binId has n arrays, if length of fieldName is n
|
||||||
|
// freqs: returned frequncy(count) array
|
||||||
|
// Note: the ND-histogram is returned in the fashion of sparse representation.
|
||||||
|
// (no zero freqncy in freqs array)
|
||||||
|
// the length of all arrays in binId and freqs array must be the same
|
||||||
|
// if the length of fieldNames is n (compute a n-dimensional hisotgram)
|
||||||
|
// freqs[i] is the freqncy of the bin with bin Ids{ binId[0][i], binId[1][i], ... binId[n-1][i] }
|
||||||
|
template <typename DeviceAdapter>
|
||||||
|
void Run(std::vector<vtkm::cont::ArrayHandle<vtkm::Id>>& binId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& freqs,
|
||||||
|
DeviceAdapter vtkmNotUsed(device))
|
||||||
|
{
|
||||||
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithms;
|
||||||
|
|
||||||
|
binId.resize(NumberOfBins.size());
|
||||||
|
|
||||||
|
// Sort the resulting bin(1D) array for counting
|
||||||
|
DeviceAlgorithms::Sort(Bin1DIndex);
|
||||||
|
|
||||||
|
// Count frequency of each bin
|
||||||
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> constArray(1, NumDataPoints);
|
||||||
|
DeviceAlgorithms::ReduceByKey(Bin1DIndex, constArray, Bin1DIndex, freqs, vtkm::Add());
|
||||||
|
|
||||||
|
//convert back to multi variate binId
|
||||||
|
for (vtkm::Id i = static_cast<vtkm::Id>(NumberOfBins.size()) - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
const vtkm::Id nFieldBins = NumberOfBins[static_cast<size_t>(i)];
|
||||||
|
vtkm::worklet::histogram::ConvertHistBinToND binWorklet(nFieldBins);
|
||||||
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::histogram::ConvertHistBinToND, DeviceAdapter>
|
||||||
|
ConvertHistBinToNDDispatcher(binWorklet);
|
||||||
|
size_t vectorId = static_cast<size_t>(i);
|
||||||
|
ConvertHistBinToNDDispatcher.Invoke(Bin1DIndex, Bin1DIndex, binId[vectorId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<vtkm::Id> NumberOfBins;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> Bin1DIndex;
|
||||||
|
vtkm::Id NumDataPoints;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace vtkm::worklet
|
||||||
|
|
||||||
|
#endif // vtk_m_worklet_NDimsHistogram_h
|
@ -124,6 +124,34 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename FieldType>
|
||||||
|
struct StreamlineResult
|
||||||
|
{
|
||||||
|
StreamlineResult()
|
||||||
|
: positions()
|
||||||
|
, polyLines()
|
||||||
|
, status()
|
||||||
|
, stepsTaken()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamlineResult(const vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>>& pos,
|
||||||
|
const vtkm::cont::CellSetExplicit<>& lines,
|
||||||
|
const vtkm::cont::ArrayHandle<vtkm::Id>& stat,
|
||||||
|
const vtkm::cont::ArrayHandle<vtkm::Id>& steps)
|
||||||
|
: positions(pos)
|
||||||
|
, polyLines(lines)
|
||||||
|
, status(stat)
|
||||||
|
, stepsTaken(steps)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> positions;
|
||||||
|
vtkm::cont::CellSetExplicit<> polyLines;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> status;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> stepsTaken;
|
||||||
|
};
|
||||||
|
|
||||||
class Streamline
|
class Streamline
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -132,20 +160,37 @@ public:
|
|||||||
template <typename IntegratorType,
|
template <typename IntegratorType,
|
||||||
typename FieldType,
|
typename FieldType,
|
||||||
typename PointStorage,
|
typename PointStorage,
|
||||||
typename FieldStorage,
|
|
||||||
typename DeviceAdapter>
|
typename DeviceAdapter>
|
||||||
void Run(const IntegratorType& it,
|
StreamlineResult<FieldType> Run(
|
||||||
const vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>, PointStorage>& pts,
|
const IntegratorType& it,
|
||||||
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>, FieldStorage> fieldArray,
|
const vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>, PointStorage>& seedArray,
|
||||||
const vtkm::Id& nSteps,
|
const vtkm::Id& nSteps,
|
||||||
const vtkm::Id& stepsPerRound,
|
const DeviceAdapter&)
|
||||||
const vtkm::Id& particlesPerRound,
|
|
||||||
const DeviceAdapter&)
|
|
||||||
{
|
{
|
||||||
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
|
||||||
vtkm::worklet::particleadvection::StreamlineWorklet<IntegratorType, FieldType, DeviceAdapter>
|
vtkm::worklet::particleadvection::StreamlineWorklet<IntegratorType, FieldType, DeviceAdapter>
|
||||||
worklet;
|
worklet;
|
||||||
|
|
||||||
worklet.Run(it, pts, fieldArray, nSteps, stepsPerRound, particlesPerRound);
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>, PointStorage> positions;
|
||||||
|
vtkm::cont::CellSetExplicit<> polyLines;
|
||||||
|
|
||||||
|
//Allocate status and steps arrays.
|
||||||
|
vtkm::Id numSeeds = seedArray.GetNumberOfValues();
|
||||||
|
vtkm::Id val = vtkm::worklet::particleadvection::ParticleStatus::STATUS_OK;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> status, steps;
|
||||||
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> ok(val, numSeeds);
|
||||||
|
status.Allocate(numSeeds);
|
||||||
|
|
||||||
|
DeviceAlgorithm::Copy(ok, status);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> zero(0, numSeeds);
|
||||||
|
steps.Allocate(numSeeds);
|
||||||
|
DeviceAlgorithm::Copy(zero, steps);
|
||||||
|
|
||||||
|
worklet.Run(it, seedArray, nSteps, positions, polyLines, status, steps);
|
||||||
|
|
||||||
|
StreamlineResult<FieldType> res(positions, polyLines, status, steps);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
45
vtkm/worklet/cosmotools/CMakeLists.txt
Normal file
45
vtkm/worklet/cosmotools/CMakeLists.txt
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
##============================================================================
|
||||||
|
## 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.
|
||||||
|
##
|
||||||
|
## Copyright 2016 Sandia Corporation.
|
||||||
|
## Copyright 2016 UT-Battelle, LLC.
|
||||||
|
## Copyright 2016 Los Alamos National Security.
|
||||||
|
##
|
||||||
|
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
## the U.S. Government retains certain rights in this software.
|
||||||
|
##
|
||||||
|
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
## Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
## this software.
|
||||||
|
##============================================================================
|
||||||
|
|
||||||
|
set(headers
|
||||||
|
CosmoTools.h
|
||||||
|
CosmoToolsCenterFinder.h
|
||||||
|
CosmoToolsHaloFinder.h
|
||||||
|
ComputeBins.h
|
||||||
|
ComputeBinIndices.h
|
||||||
|
ComputeBinRange.h
|
||||||
|
ComputeNeighborBins.h
|
||||||
|
ComputePotential.h
|
||||||
|
ComputePotentialBin.h
|
||||||
|
ComputePotentialNeighbors.h
|
||||||
|
ComputePotentialNxN.h
|
||||||
|
ComputePotentialMxN.h
|
||||||
|
ComputePotentialOnCandidates.h
|
||||||
|
EqualsMinimumPotential.h
|
||||||
|
GraftParticles.h
|
||||||
|
IsStar.h
|
||||||
|
MarkActiveNeighbors.h
|
||||||
|
PointerJump.h
|
||||||
|
SetCandidateParticles.h
|
||||||
|
ValidHalo.h
|
||||||
|
)
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
vtkm_declare_headers(${headers})
|
109
vtkm/worklet/cosmotools/ComputeBinIndices.h
Normal file
109
vtkm/worklet/cosmotools/ComputeBinIndices.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_bin_indices_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_bin_indices_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet to compute the x,y,z index for every bin
|
||||||
|
template <typename T>
|
||||||
|
class ComputeBinIndices : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> binId, // (input) bin Id
|
||||||
|
FieldOut<IdType> binX, // (output) bin indices
|
||||||
|
FieldOut<IdType> binY,
|
||||||
|
FieldOut<IdType> binZ);
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3, _4);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id numBinsX, numBinsY, numBinsZ; // Number of bins each dimension
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputeBinIndices(vtkm::Id NX, vtkm::Id NY, vtkm::Id NZ)
|
||||||
|
: numBinsX(NX)
|
||||||
|
, numBinsY(NY)
|
||||||
|
, numBinsZ(NZ)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
void operator()(const vtkm::Id& bin, vtkm::Id& xbin, vtkm::Id& ybin, vtkm::Id& zbin) const
|
||||||
|
{
|
||||||
|
xbin = bin % numBinsX;
|
||||||
|
ybin = (bin / numBinsX) % numBinsY;
|
||||||
|
zbin = bin / (numBinsX * numBinsY);
|
||||||
|
}
|
||||||
|
}; // ComputeBinIndices
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
111
vtkm/worklet/cosmotools/ComputeBinRange.h
Normal file
111
vtkm/worklet/cosmotools/ComputeBinRange.h
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_bin_range_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_bin_range_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the range of bins for any particle
|
||||||
|
// In 3D there will be 9 "left" neighbors which start 3 consecutive bins = 27
|
||||||
|
class ComputeBinRange : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> leftNeighbor, // (input) left neighbor id
|
||||||
|
FieldOut<IdType> rightNeighbor); // (output) right neighbor id
|
||||||
|
typedef _2 ExecutionSignature(_1);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id xNum;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputeBinRange(vtkm::Id XNum)
|
||||||
|
: xNum(XNum)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
vtkm::Id operator()(const vtkm::Id& leftNeighbor) const
|
||||||
|
{
|
||||||
|
vtkm::Id rightNeighbor = leftNeighbor;
|
||||||
|
const vtkm::Id xbin = leftNeighbor % xNum;
|
||||||
|
if (xbin == xNum - 1)
|
||||||
|
;
|
||||||
|
else if (xbin == xNum - 2)
|
||||||
|
rightNeighbor += 1;
|
||||||
|
else
|
||||||
|
rightNeighbor += 2;
|
||||||
|
return rightNeighbor;
|
||||||
|
}
|
||||||
|
}; // ComputeBinRange
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
146
vtkm/worklet/cosmotools/ComputeBins.h
Normal file
146
vtkm/worklet/cosmotools/ComputeBins.h
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_bins__h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_bins__h
|
||||||
|
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the bin id for every particle in domain
|
||||||
|
template <typename T>
|
||||||
|
class ComputeBins : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(FieldIn<TagType> xLoc, // (input) x location in halo
|
||||||
|
FieldIn<TagType> yLoc, // (input) y location in halo
|
||||||
|
FieldIn<TagType> zLoc, // (input) z location in halo
|
||||||
|
FieldOut<IdType> binId); // (output) bin Id
|
||||||
|
typedef _4 ExecutionSignature(_1, _2, _3);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
T xMin, xMax, yMin, yMax, zMin, zMax;
|
||||||
|
vtkm::Id xNum, yNum, zNum;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputeBins(T XMin,
|
||||||
|
T XMax,
|
||||||
|
T YMin,
|
||||||
|
T YMax,
|
||||||
|
T ZMin,
|
||||||
|
T ZMax,
|
||||||
|
vtkm::Id XNum,
|
||||||
|
vtkm::Id YNum,
|
||||||
|
vtkm::Id ZNum)
|
||||||
|
: xMin(XMin)
|
||||||
|
, xMax(XMax)
|
||||||
|
, yMin(YMin)
|
||||||
|
, yMax(YMax)
|
||||||
|
, zMin(ZMin)
|
||||||
|
, zMax(ZMax)
|
||||||
|
, xNum(XNum)
|
||||||
|
, yNum(YNum)
|
||||||
|
, zNum(ZNum)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
vtkm::Id operator()(const T& xLoc, const T& yLoc, const T& zLoc) const
|
||||||
|
{
|
||||||
|
vtkm::Id xbin = 0;
|
||||||
|
if (xNum > 1)
|
||||||
|
{
|
||||||
|
xbin = static_cast<vtkm::Id>((static_cast<T>(xNum) * (xLoc - xMin)) / (xMax - xMin));
|
||||||
|
if (xbin >= xNum)
|
||||||
|
xbin = xNum - 1;
|
||||||
|
}
|
||||||
|
vtkm::Id ybin = 0;
|
||||||
|
if (yNum > 1)
|
||||||
|
{
|
||||||
|
ybin = static_cast<vtkm::Id>((static_cast<T>(yNum) * (yLoc - yMin)) / (yMax - yMin));
|
||||||
|
if (ybin >= yNum)
|
||||||
|
ybin = yNum - 1;
|
||||||
|
}
|
||||||
|
vtkm::Id zbin = 0;
|
||||||
|
if (zNum > 1)
|
||||||
|
{
|
||||||
|
zbin = static_cast<vtkm::Id>((static_cast<T>(zNum) * (zLoc - zMin)) / (zMax - zMin));
|
||||||
|
if (zbin >= zNum)
|
||||||
|
zbin = zNum - 1;
|
||||||
|
}
|
||||||
|
return (xbin + ybin * xNum + zbin * xNum * yNum);
|
||||||
|
}
|
||||||
|
}; // ComputeBins
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
132
vtkm/worklet/cosmotools/ComputeNeighborBins.h
Normal file
132
vtkm/worklet/cosmotools/ComputeNeighborBins.h
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_neighbor_bins_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_neighbor_bins_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the left neighbor bin id for every particle in domain
|
||||||
|
// In 3D there will be 9 "left" neighbors which start 3 consecutive bins = 27
|
||||||
|
class ComputeNeighborBins : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> partIndx,
|
||||||
|
FieldIn<IdType> binId, // (input) bin Id
|
||||||
|
WholeArrayOut<IdType> leftNeighbor); // (output) neighbor Id
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id xNum, yNum, zNum;
|
||||||
|
vtkm::Id NUM_NEIGHBORS;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputeNeighborBins(vtkm::Id XNum, vtkm::Id YNum, vtkm::Id ZNum, vtkm::Id NumNeighbors)
|
||||||
|
: xNum(XNum)
|
||||||
|
, yNum(YNum)
|
||||||
|
, zNum(ZNum)
|
||||||
|
, NUM_NEIGHBORS(NumNeighbors)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename OutFieldPortalType>
|
||||||
|
VTKM_EXEC void operator()(const vtkm::Id& i,
|
||||||
|
const vtkm::Id& binId,
|
||||||
|
OutFieldPortalType& leftNeighbor) const
|
||||||
|
{
|
||||||
|
const vtkm::Id xbin = binId % xNum;
|
||||||
|
const vtkm::Id ybin = (binId / xNum) % yNum;
|
||||||
|
const vtkm::Id zbin = binId / (xNum * yNum);
|
||||||
|
|
||||||
|
vtkm::Id cnt = 0;
|
||||||
|
for (vtkm::Id z = zbin - 1; z <= zbin + 1; z++)
|
||||||
|
{
|
||||||
|
for (vtkm::Id y = ybin - 1; y <= ybin + 1; y++)
|
||||||
|
{
|
||||||
|
if ((y >= 0) && (y < yNum) && (z >= 0) && (z < zNum))
|
||||||
|
{
|
||||||
|
if (xbin - 1 >= 0)
|
||||||
|
leftNeighbor.Set((NUM_NEIGHBORS * i + cnt), (xbin - 1) + y * xNum + z * xNum * yNum);
|
||||||
|
else
|
||||||
|
leftNeighbor.Set((NUM_NEIGHBORS * i + cnt), xbin + y * xNum + z * xNum * yNum);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
leftNeighbor.Set((NUM_NEIGHBORS * i + cnt), -1);
|
||||||
|
}
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}; // ComputeNeighborBins
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
136
vtkm/worklet/cosmotools/ComputePotential.h
Normal file
136
vtkm/worklet/cosmotools/ComputePotential.h
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_potential_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_potential_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the potential for a particle
|
||||||
|
template <typename T>
|
||||||
|
class ComputePotential : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(
|
||||||
|
FieldIn<IdType> index, // (input) particle Id
|
||||||
|
WholeArrayIn<IdType> partId, // (input) first particle in halo
|
||||||
|
WholeArrayIn<TagType> xLoc, // (input) x location in domain
|
||||||
|
WholeArrayIn<TagType> yLoc, // (input) y location in domain
|
||||||
|
WholeArrayIn<TagType> zLoc, // (input) z location in domain
|
||||||
|
WholeArrayIn<IdType> firstParticleId, // (input) first particle in halo
|
||||||
|
WholeArrayIn<IdType> lastParticleId, // (input) last particle in halo
|
||||||
|
FieldOut<TagType> potential); // (output) bin ID
|
||||||
|
typedef _8 ExecutionSignature(_1, _2, _3, _4, _5, _6, _7);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
T mass;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputePotential(T Mass)
|
||||||
|
: mass(Mass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InFieldPortalType, typename InIdPortalType, typename PermutePortalType>
|
||||||
|
VTKM_EXEC T operator()(const vtkm::Id& i,
|
||||||
|
const InIdPortalType& partId,
|
||||||
|
const InFieldPortalType& xLoc,
|
||||||
|
const InFieldPortalType& yLoc,
|
||||||
|
const InFieldPortalType& zLoc,
|
||||||
|
const InIdPortalType& firstParticleId,
|
||||||
|
const PermutePortalType& lastParticleId) const
|
||||||
|
{
|
||||||
|
// Worklet index is into array of particle ids sorted by bin
|
||||||
|
// Current particle and other particles retrieved from partId array
|
||||||
|
vtkm::Id iId = partId.Get(i);
|
||||||
|
T potential = 0.0f;
|
||||||
|
|
||||||
|
// first and last particle are arranged by sorted bin id so they match index and not the partId
|
||||||
|
for (vtkm::Id j = firstParticleId.Get(i); j <= lastParticleId.Get(i); j++)
|
||||||
|
{
|
||||||
|
vtkm::Id jId = partId.Get(j);
|
||||||
|
T xDist = xLoc.Get(iId) - xLoc.Get(jId);
|
||||||
|
T yDist = yLoc.Get(iId) - yLoc.Get(jId);
|
||||||
|
T zDist = zLoc.Get(iId) - zLoc.Get(jId);
|
||||||
|
T r = vtkm::Sqrt((xDist * xDist) + (yDist * yDist) + (zDist * zDist));
|
||||||
|
if ((i != j) && (fabs(r) > 0.00000000001f))
|
||||||
|
potential -= mass / r;
|
||||||
|
}
|
||||||
|
return potential;
|
||||||
|
}
|
||||||
|
}; // ComputePotential
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
154
vtkm/worklet/cosmotools/ComputePotentialBin.h
Normal file
154
vtkm/worklet/cosmotools/ComputePotentialBin.h
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_potential_bin_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_potential_bin_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the potential for a bin in one halo
|
||||||
|
template <typename T>
|
||||||
|
class ComputePotentialBin : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> binId, // (input) bin Id
|
||||||
|
WholeArrayIn<IdType> binCount, // (input) particles per bin
|
||||||
|
WholeArrayIn<IdType> binX, // (input) x index in bin
|
||||||
|
WholeArrayIn<IdType> binY, // (input) y index in bin
|
||||||
|
WholeArrayIn<IdType> binZ, // (input) z index in bin
|
||||||
|
FieldInOut<TagType> bestPot, // (output) best potential estimate
|
||||||
|
FieldInOut<TagType> worstPot); // (output) worst potential estimate
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6, _7);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id nBins; // Number of bins
|
||||||
|
T mass; // Particle mass
|
||||||
|
T linkLen; // Linking length is side of bin
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputePotentialBin(vtkm::Id N, T Mass, T LinkLen)
|
||||||
|
: nBins(N)
|
||||||
|
, mass(Mass)
|
||||||
|
, linkLen(LinkLen)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InIdPortalType>
|
||||||
|
VTKM_EXEC void operator()(const vtkm::Id& i,
|
||||||
|
const InIdPortalType& count,
|
||||||
|
const InIdPortalType& binX,
|
||||||
|
const InIdPortalType& binY,
|
||||||
|
const InIdPortalType& binZ,
|
||||||
|
T& bestPotential,
|
||||||
|
T& worstPotential) const
|
||||||
|
{
|
||||||
|
vtkm::Id ibinX = binX.Get(i);
|
||||||
|
vtkm::Id ibinY = binY.Get(i);
|
||||||
|
vtkm::Id ibinZ = binZ.Get(i);
|
||||||
|
|
||||||
|
for (vtkm::Id j = 0; j < nBins; j++)
|
||||||
|
{
|
||||||
|
vtkm::Id xDelta = vtkm::Abs(ibinX - binX.Get(j));
|
||||||
|
vtkm::Id yDelta = vtkm::Abs(ibinY - binY.Get(j));
|
||||||
|
vtkm::Id zDelta = vtkm::Abs(ibinZ - binZ.Get(j));
|
||||||
|
|
||||||
|
if ((count.Get(j) != 0) && (xDelta > 1) && (yDelta > 1) && (zDelta > 1))
|
||||||
|
{
|
||||||
|
T xDistNear = static_cast<T>((xDelta - 1)) * linkLen;
|
||||||
|
T yDistNear = static_cast<T>((yDelta - 1)) * linkLen;
|
||||||
|
T zDistNear = static_cast<T>((zDelta - 1)) * linkLen;
|
||||||
|
T xDistFar = static_cast<T>((xDelta + 1)) * linkLen;
|
||||||
|
T yDistFar = static_cast<T>((yDelta + 1)) * linkLen;
|
||||||
|
T zDistFar = static_cast<T>((zDelta + 1)) * linkLen;
|
||||||
|
|
||||||
|
T rNear =
|
||||||
|
vtkm::Sqrt((xDistNear * xDistNear) + (yDistNear * yDistNear) + (zDistNear * zDistNear));
|
||||||
|
T rFar = vtkm::Sqrt((xDistFar * xDistFar) + (yDistFar * yDistFar) + (zDistFar * zDistFar));
|
||||||
|
|
||||||
|
if (rFar > 0.00000000001f)
|
||||||
|
{
|
||||||
|
worstPotential -= (static_cast<T>(count.Get(j)) * mass) / rFar;
|
||||||
|
}
|
||||||
|
if (rNear > 0.00000000001f)
|
||||||
|
{
|
||||||
|
bestPotential -= (static_cast<T>(count.Get(j)) * mass) / rNear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}; // ComputePotentialBin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
130
vtkm/worklet/cosmotools/ComputePotentialMxN.h
Normal file
130
vtkm/worklet/cosmotools/ComputePotentialMxN.h
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_potential_mxn_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_potential_mxn_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the exact potential for all particles in range vs all particles in system
|
||||||
|
template <typename T>
|
||||||
|
class ComputePotentialMxN : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> index, // (input) index into particles for one bin
|
||||||
|
WholeArrayIn<IdType> partId, // (input) original particle id
|
||||||
|
WholeArrayIn<TagType> xLoc, // (input) x location in domain
|
||||||
|
WholeArrayIn<TagType> yLoc, // (input) y location in domain
|
||||||
|
WholeArrayIn<TagType> zLoc, // (input) z location in domain
|
||||||
|
FieldOut<TagType> potential); // (output) bin ID
|
||||||
|
typedef _6 ExecutionSignature(_1, _2, _3, _4, _5);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id nParticles; // Number of particles in halo
|
||||||
|
T mass; // Particle mass
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputePotentialMxN(vtkm::Id N, T Mass)
|
||||||
|
: nParticles(N)
|
||||||
|
, mass(Mass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InIdPortalType, typename InFieldPortalType>
|
||||||
|
VTKM_EXEC T operator()(const vtkm::Id& i,
|
||||||
|
const InIdPortalType& partId,
|
||||||
|
const InFieldPortalType& xLoc,
|
||||||
|
const InFieldPortalType& yLoc,
|
||||||
|
const InFieldPortalType& zLoc) const
|
||||||
|
{
|
||||||
|
T potential = 0.0f;
|
||||||
|
vtkm::Id iPartId = partId.Get(i);
|
||||||
|
for (vtkm::Id j = 0; j < nParticles; j++)
|
||||||
|
{
|
||||||
|
T xDist = xLoc.Get(iPartId) - xLoc.Get(j);
|
||||||
|
T yDist = yLoc.Get(iPartId) - yLoc.Get(j);
|
||||||
|
T zDist = zLoc.Get(iPartId) - zLoc.Get(j);
|
||||||
|
T r = sqrt((xDist * xDist) + (yDist * yDist) + (zDist * zDist));
|
||||||
|
if (fabs(r) > 0.00000000001f)
|
||||||
|
{
|
||||||
|
potential -= mass / r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return potential;
|
||||||
|
}
|
||||||
|
}; // ComputePotentialMxN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
162
vtkm/worklet/cosmotools/ComputePotentialNeighbors.h
Normal file
162
vtkm/worklet/cosmotools/ComputePotentialNeighbors.h
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_potential_neighbors_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_potential_neighbors_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the potential for a particle using 27 neighbor bins
|
||||||
|
template <typename T>
|
||||||
|
class ComputePotentialNeighbors : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(
|
||||||
|
FieldIn<IdType> index, // (input) particle Id
|
||||||
|
WholeArrayIn<IdType> binId, // (input) bin id for this particle
|
||||||
|
WholeArrayIn<IdType> partId, // (input) first particle in halo
|
||||||
|
WholeArrayIn<TagType> xLoc, // (input) x location in domain
|
||||||
|
WholeArrayIn<TagType> yLoc, // (input) y location in domain
|
||||||
|
WholeArrayIn<TagType> zLoc, // (input) z location in domain
|
||||||
|
WholeArrayIn<IdType> firstParticleId, // (input) first particle in halo
|
||||||
|
WholeArrayIn<IdType> lastParticleId, // (input) last particle in halo
|
||||||
|
FieldOut<TagType> potential); // (output) bin ID
|
||||||
|
typedef _9 ExecutionSignature(_1, _2, _3, _4, _5, _6, _7, _8);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id xNum, yNum, zNum;
|
||||||
|
vtkm::Id NUM_NEIGHBORS;
|
||||||
|
T mass;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputePotentialNeighbors(const vtkm::Id XNum,
|
||||||
|
const vtkm::Id YNum,
|
||||||
|
const vtkm::Id ZNum,
|
||||||
|
const vtkm::Id NumNeighbors,
|
||||||
|
T Mass)
|
||||||
|
: xNum(XNum)
|
||||||
|
, yNum(YNum)
|
||||||
|
, zNum(ZNum)
|
||||||
|
, NUM_NEIGHBORS(NumNeighbors)
|
||||||
|
, mass(Mass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InFieldPortalType, typename InIdPortalType, typename InVectorPortalType>
|
||||||
|
VTKM_EXEC T operator()(const vtkm::Id& i,
|
||||||
|
const InIdPortalType& binId,
|
||||||
|
const InIdPortalType& partId,
|
||||||
|
const InFieldPortalType& xLoc,
|
||||||
|
const InFieldPortalType& yLoc,
|
||||||
|
const InFieldPortalType& zLoc,
|
||||||
|
const InVectorPortalType& firstParticleId,
|
||||||
|
const InVectorPortalType& lastParticleId) const
|
||||||
|
{
|
||||||
|
vtkm::Id iId = partId.Get(i);
|
||||||
|
vtkm::Id ibin = binId.Get(i);
|
||||||
|
|
||||||
|
const vtkm::Id yVal = (ibin / xNum) % yNum;
|
||||||
|
const vtkm::Id zVal = ibin / (xNum * yNum);
|
||||||
|
vtkm::Id cnt = 0;
|
||||||
|
T potential = 0.0f;
|
||||||
|
|
||||||
|
// Iterate on the 9 sets of neighbor particles
|
||||||
|
for (vtkm::Id z = zVal - 1; z <= zVal + 1; z++)
|
||||||
|
{
|
||||||
|
for (vtkm::Id y = yVal - 1; y <= yVal + 1; y++)
|
||||||
|
{
|
||||||
|
vtkm::Id firstBinId = NUM_NEIGHBORS * i + cnt;
|
||||||
|
vtkm::Id startParticle = firstParticleId.Get(firstBinId);
|
||||||
|
vtkm::Id endParticle = lastParticleId.Get(firstBinId);
|
||||||
|
|
||||||
|
for (vtkm::Id j = startParticle; j < endParticle; j++)
|
||||||
|
{
|
||||||
|
vtkm::Id jId = partId.Get(j);
|
||||||
|
T xDist = xLoc.Get(iId) - xLoc.Get(jId);
|
||||||
|
T yDist = yLoc.Get(iId) - yLoc.Get(jId);
|
||||||
|
T zDist = zLoc.Get(iId) - zLoc.Get(jId);
|
||||||
|
T r = vtkm::Sqrt((xDist * xDist) + (yDist * yDist) + (zDist * zDist));
|
||||||
|
if ((i != j) && (fabs(r) > 0.00000000001f))
|
||||||
|
potential -= mass / r;
|
||||||
|
}
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return potential;
|
||||||
|
}
|
||||||
|
}; // ComputePotentialNeighbors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
127
vtkm/worklet/cosmotools/ComputePotentialNxN.h
Normal file
127
vtkm/worklet/cosmotools/ComputePotentialNxN.h
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_potential_nxn_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_potential_nxn_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the potential for a particle in one halo
|
||||||
|
template <typename T>
|
||||||
|
class ComputePotentialNxN : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> partId, // (input) particle Id
|
||||||
|
WholeArrayIn<TagType> xLoc, // (input) x location in domain
|
||||||
|
WholeArrayIn<TagType> yLoc, // (input) y location in domain
|
||||||
|
WholeArrayIn<TagType> zLoc, // (input) z location in domain
|
||||||
|
FieldOut<TagType> potential); // (output) bin ID
|
||||||
|
typedef _5 ExecutionSignature(_1, _2, _3, _4);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id nParticles; // Number of particles in halo
|
||||||
|
T mass; // Particle mass
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputePotentialNxN(vtkm::Id N, T Mass)
|
||||||
|
: nParticles(N)
|
||||||
|
, mass(Mass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InFieldPortalType>
|
||||||
|
VTKM_EXEC T operator()(const vtkm::Id& i,
|
||||||
|
const InFieldPortalType& xLoc,
|
||||||
|
const InFieldPortalType& yLoc,
|
||||||
|
const InFieldPortalType& zLoc) const
|
||||||
|
{
|
||||||
|
T potential = 0.0f;
|
||||||
|
for (vtkm::Id j = 0; j < nParticles; j++)
|
||||||
|
{
|
||||||
|
T xDist = xLoc.Get(i) - xLoc.Get(j);
|
||||||
|
T yDist = yLoc.Get(i) - yLoc.Get(j);
|
||||||
|
T zDist = zLoc.Get(i) - zLoc.Get(j);
|
||||||
|
T r = vtkm::Sqrt((xDist * xDist) + (yDist * yDist) + (zDist * zDist));
|
||||||
|
if ((i != j) && (fabs(r) > 0.00000000001f))
|
||||||
|
{
|
||||||
|
potential -= mass / r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return potential;
|
||||||
|
}
|
||||||
|
}; // ComputePotentialNxN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
127
vtkm/worklet/cosmotools/ComputePotentialOnCandidates.h
Normal file
127
vtkm/worklet/cosmotools/ComputePotentialOnCandidates.h
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_compute_potential_on_candidates_h
|
||||||
|
#define vtkm_worklet_cosmotools_compute_potential_on_candidates_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the potential for a candidate particle
|
||||||
|
template <typename T>
|
||||||
|
class ComputePotentialOnCandidates : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> partId, // (input) particle is part of M
|
||||||
|
WholeArrayIn<TagType> xLoc, // (input) x location in domain
|
||||||
|
WholeArrayIn<TagType> yLoc, // (input) y location in domain
|
||||||
|
WholeArrayIn<TagType> zLoc, // (input) z location in domain
|
||||||
|
FieldOut<TagType> potential); // (output) bin ID
|
||||||
|
typedef _5 ExecutionSignature(_1, _2, _3, _4);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id nParticles; // Number of particles in halo
|
||||||
|
T mass; // Particle mass
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ComputePotentialOnCandidates(vtkm::Id N, T Mass)
|
||||||
|
: nParticles(N)
|
||||||
|
, mass(Mass)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InFieldPortalType>
|
||||||
|
VTKM_EXEC T operator()(const vtkm::Id& i,
|
||||||
|
const InFieldPortalType& xLoc,
|
||||||
|
const InFieldPortalType& yLoc,
|
||||||
|
const InFieldPortalType& zLoc) const
|
||||||
|
{
|
||||||
|
T potential = 0.0f;
|
||||||
|
for (vtkm::Id j = 0; j < nParticles; j++)
|
||||||
|
{
|
||||||
|
T xDist = xLoc.Get(i) - xLoc.Get(j);
|
||||||
|
T yDist = yLoc.Get(i) - yLoc.Get(j);
|
||||||
|
T zDist = zLoc.Get(i) - zLoc.Get(j);
|
||||||
|
T r = vtkm::Sqrt((xDist * xDist) + (yDist * yDist) + (zDist * zDist));
|
||||||
|
if ((i != j) && (fabs(r) > 0.00000000001f))
|
||||||
|
{
|
||||||
|
potential -= mass / r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return potential;
|
||||||
|
}
|
||||||
|
}; // ComputePotentialOnCandidates
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
308
vtkm/worklet/cosmotools/CosmoTools.h
Normal file
308
vtkm/worklet/cosmotools/CosmoTools.h
Normal file
@ -0,0 +1,308 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_cosmotools_h
|
||||||
|
#define vtkm_worklet_cosmotools_cosmotools_h
|
||||||
|
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputeBinIndices.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputeBinRange.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputeBins.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputeNeighborBins.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/GraftParticles.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/IsStar.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/MarkActiveNeighbors.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/PointerJump.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ValidHalo.h>
|
||||||
|
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputePotential.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputePotentialBin.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputePotentialMxN.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputePotentialNeighbors.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputePotentialNxN.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/ComputePotentialOnCandidates.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/EqualsMinimumPotential.h>
|
||||||
|
#include <vtkm/worklet/cosmotools/SetCandidateParticles.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/ArrayHandleCompositeVector.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleConstant.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleReverse.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleTransform.h>
|
||||||
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
|
#include <vtkm/worklet/ScatterCounting.h>
|
||||||
|
|
||||||
|
#include <vtkm/BinaryPredicates.h>
|
||||||
|
#include <vtkm/Math.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
//#define DEBUG_PRINT 1
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Debug prints
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename U>
|
||||||
|
void DebugPrint(const char* msg, vtkm::cont::ArrayHandle<U>& array)
|
||||||
|
{
|
||||||
|
vtkm::Id count = 20;
|
||||||
|
count = std::min(count, array.GetNumberOfValues());
|
||||||
|
std::cout << std::setw(15) << msg << ": ";
|
||||||
|
for (vtkm::Id i = 0; i < count; i++)
|
||||||
|
std::cout << std::setprecision(3) << std::setw(5) << array.GetPortalConstControl().Get(i)
|
||||||
|
<< " ";
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U>
|
||||||
|
void DebugPrint(const char* msg, vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<U>>& array)
|
||||||
|
{
|
||||||
|
vtkm::Id count = 20;
|
||||||
|
count = std::min(count, array.GetNumberOfValues());
|
||||||
|
std::cout << std::setw(15) << msg << ": ";
|
||||||
|
for (vtkm::Id i = 0; i < count; i++)
|
||||||
|
std::cout << std::setw(5) << array.GetPortalConstControl().Get(i) << " ";
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Scatter the result of a reduced array
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
struct ScatterWorklet : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
typedef void ControlSignature(FieldIn<> inIndices, FieldOut<> outIndices);
|
||||||
|
typedef void ExecutionSignature(_1, _2);
|
||||||
|
using ScatterType = vtkm::worklet::ScatterCounting;
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
ScatterType GetScatter() const { return this->Scatter; }
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
ScatterWorklet(const vtkm::worklet::ScatterCounting& scatter)
|
||||||
|
: Scatter(scatter)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
void operator()(T inputIndex, T& outputIndex) const { outputIndex = inputIndex; }
|
||||||
|
private:
|
||||||
|
ScatterType Scatter;
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Scale or offset values of an array
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
struct ScaleBiasFunctor
|
||||||
|
{
|
||||||
|
T Scale;
|
||||||
|
T Bias;
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
ScaleBiasFunctor(T scale = T(1), T bias = T(0))
|
||||||
|
: Scale(scale)
|
||||||
|
, Bias(bias)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
T operator()(T value) const { return (Scale * value + Bias); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
class CosmoTools
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using DeviceAlgorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
|
||||||
|
const vtkm::Id NUM_NEIGHBORS = 9;
|
||||||
|
|
||||||
|
// geometry of domain
|
||||||
|
const vtkm::Id nParticles;
|
||||||
|
const T particleMass;
|
||||||
|
const vtkm::Id minPartPerHalo;
|
||||||
|
const T linkLen;
|
||||||
|
vtkm::Id numBinsX;
|
||||||
|
vtkm::Id numBinsY;
|
||||||
|
vtkm::Id numBinsZ;
|
||||||
|
|
||||||
|
// particle locations within domain
|
||||||
|
using LocationType = typename vtkm::cont::ArrayHandle<T, StorageType>;
|
||||||
|
LocationType& xLoc;
|
||||||
|
LocationType& yLoc;
|
||||||
|
LocationType& zLoc;
|
||||||
|
|
||||||
|
// cosmo tools constructor for all particles
|
||||||
|
CosmoTools(const vtkm::Id NParticles, // Number of particles
|
||||||
|
const T mass, // Particle mass for potential
|
||||||
|
const vtkm::Id pmin, // Minimum particles per halo
|
||||||
|
const T bb, // Linking length between particles
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& X, // Physical location of each particle
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& Y,
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& Z);
|
||||||
|
|
||||||
|
// cosmo tools constructor for particles in one halo
|
||||||
|
CosmoTools(const vtkm::Id NParticles, // Number of particles
|
||||||
|
const T mass, // Particle mass for potential
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& X, // Physical location of each particle
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& Y,
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& Z);
|
||||||
|
~CosmoTools() {}
|
||||||
|
|
||||||
|
// Halo finding and center finding on halos
|
||||||
|
void HaloFinder(vtkm::cont::ArrayHandle<vtkm::Id>& resultHaloId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& resultMBP,
|
||||||
|
vtkm::cont::ArrayHandle<T>& resultPot);
|
||||||
|
void BinParticlesAll(vtkm::cont::ArrayHandle<vtkm::Id>& partId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& leftNeighbor,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& rightNeighbor);
|
||||||
|
void MBPCenterFindingByHalo(vtkm::cont::ArrayHandle<vtkm::Id>& partId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& haloId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& mbpId,
|
||||||
|
vtkm::cont::ArrayHandle<T>& minPotential);
|
||||||
|
|
||||||
|
// MBP Center finding on single halo using NxN algorithm
|
||||||
|
vtkm::Id MBPCenterFinderNxN(T* nxnPotential);
|
||||||
|
|
||||||
|
// MBP Center finding on single halo using MxN estimation
|
||||||
|
vtkm::Id MBPCenterFinderMxN(T* mxnPotential);
|
||||||
|
|
||||||
|
void BinParticlesHalo(vtkm::cont::ArrayHandle<vtkm::Id>& partId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& uniqueBins,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& partPerBin,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& particleOffset,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binX,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binY,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binZ);
|
||||||
|
void MBPCenterFindingByKey(vtkm::cont::ArrayHandle<vtkm::Id>& keyId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& partId,
|
||||||
|
vtkm::cont::ArrayHandle<T>& minPotential);
|
||||||
|
};
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Constructor for all particles in the system
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
CosmoTools<T, StorageType, DeviceAdapter>::CosmoTools(const vtkm::Id NParticles,
|
||||||
|
const T mass,
|
||||||
|
const vtkm::Id pmin,
|
||||||
|
const T bb,
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& X,
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& Y,
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& Z)
|
||||||
|
: nParticles(NParticles)
|
||||||
|
, particleMass(mass)
|
||||||
|
, minPartPerHalo(pmin)
|
||||||
|
, linkLen(bb)
|
||||||
|
, xLoc(X)
|
||||||
|
, yLoc(Y)
|
||||||
|
, zLoc(Z)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Constructor for particles in a single halo
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
CosmoTools<T, StorageType, DeviceAdapter>::CosmoTools(const vtkm::Id NParticles,
|
||||||
|
const T mass,
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& X,
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& Y,
|
||||||
|
vtkm::cont::ArrayHandle<T, StorageType>& Z)
|
||||||
|
: nParticles(NParticles)
|
||||||
|
, particleMass(mass)
|
||||||
|
, minPartPerHalo(10)
|
||||||
|
, linkLen(0.2f)
|
||||||
|
, xLoc(X)
|
||||||
|
, yLoc(Y)
|
||||||
|
, zLoc(Z)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
435
vtkm/worklet/cosmotools/CosmoToolsCenterFinder.h
Normal file
435
vtkm/worklet/cosmotools/CosmoToolsCenterFinder.h
Normal file
@ -0,0 +1,435 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_cosmotools_centerfinder_h
|
||||||
|
#define vtkm_worklet_cosmotools_cosmotools_centerfinder_h
|
||||||
|
|
||||||
|
#include <vtkm/worklet/cosmotools/CosmoTools.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Center finder for particles in FOF halo using estimations but with exact final answer
|
||||||
|
// MBP (Most Bound Particle) is particle with the minimum potential energy
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
vtkm::Id CosmoTools<T, StorageType, DeviceAdapter>::MBPCenterFinderMxN(T* mxnPotential)
|
||||||
|
{
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> partId;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> binId;
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> uniqueBins;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> partPerBin;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> particleOffset;
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> binX;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> binY;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> binZ;
|
||||||
|
|
||||||
|
// Bin all particles in the halo into bins of size linking length
|
||||||
|
BinParticlesHalo(partId, binId, uniqueBins, partPerBin, particleOffset, binX, binY, binZ);
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("uniqueBins", uniqueBins);
|
||||||
|
DebugPrint("partPerBin", partPerBin);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Compute the estimated potential per bin using 27 contiguous bins
|
||||||
|
vtkm::cont::ArrayHandle<T> partPotential;
|
||||||
|
MBPCenterFindingByKey(binId, partId, partPotential);
|
||||||
|
|
||||||
|
// Reduce by key to get the estimated minimum potential per bin within 27 neighbors
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> tempId;
|
||||||
|
vtkm::cont::ArrayHandle<T> minPotential;
|
||||||
|
DeviceAlgorithm::ReduceByKey(binId, partPotential, tempId, minPotential, vtkm::Minimum());
|
||||||
|
|
||||||
|
// Reduce by key to get the estimated maximum potential per bin within 27 neighbors
|
||||||
|
vtkm::cont::ArrayHandle<T> maxPotential;
|
||||||
|
DeviceAlgorithm::ReduceByKey(binId, partPotential, tempId, maxPotential, vtkm::Maximum());
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("minPotential", minPotential);
|
||||||
|
DebugPrint("maxPotential", maxPotential);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Compute potentials estimate for a bin using all other bins
|
||||||
|
// Particles in the other bins are located at the closest point to this bin
|
||||||
|
vtkm::cont::ArrayHandleIndex uniqueIndex(uniqueBins.GetNumberOfValues());
|
||||||
|
vtkm::cont::ArrayHandle<T> bestEstPotential;
|
||||||
|
vtkm::cont::ArrayHandle<T> worstEstPotential;
|
||||||
|
|
||||||
|
// Initialize each bin potential with the nxn for that bin
|
||||||
|
DeviceAlgorithm::Copy(minPotential, bestEstPotential);
|
||||||
|
DeviceAlgorithm::Copy(maxPotential, worstEstPotential);
|
||||||
|
|
||||||
|
// Estimate only across the uniqueBins that contain particles
|
||||||
|
ComputePotentialBin<T> computePotentialBin(uniqueBins.GetNumberOfValues(), particleMass, linkLen);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputePotentialBin<T>> computePotentialBinDispatcher(
|
||||||
|
computePotentialBin);
|
||||||
|
|
||||||
|
computePotentialBinDispatcher.Invoke(uniqueIndex, // input
|
||||||
|
partPerBin, // input (whole array)
|
||||||
|
binX, // input (whole array)
|
||||||
|
binY, // input (whole array)
|
||||||
|
binZ, // input (whole array)
|
||||||
|
bestEstPotential, // input/output
|
||||||
|
worstEstPotential); // input/output
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("bestEstPotential", bestEstPotential);
|
||||||
|
DebugPrint("worstEstPotential", worstEstPotential);
|
||||||
|
std::cout << "Number of bestEstPotential " << bestEstPotential.GetNumberOfValues() << std::endl;
|
||||||
|
std::cout << "Number of worstEstPotential " << worstEstPotential.GetNumberOfValues() << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Sort everything by the best estimated potential per bin
|
||||||
|
vtkm::cont::ArrayHandle<T> tempBest;
|
||||||
|
DeviceAlgorithm::Copy(bestEstPotential, tempBest);
|
||||||
|
DeviceAlgorithm::SortByKey(tempBest, worstEstPotential);
|
||||||
|
|
||||||
|
// Use the worst estimate for the first selected bin to compare to best of all others
|
||||||
|
// Any bin that passes is a candidate for having the MBP
|
||||||
|
T cutoffPotential = worstEstPotential.GetPortalControl().Get(0);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> candidate;
|
||||||
|
DeviceAlgorithm::Copy(vtkm::cont::ArrayHandleConstant<vtkm::Id>(0, nParticles), candidate);
|
||||||
|
|
||||||
|
SetCandidateParticles<T> setCandidateParticles(cutoffPotential);
|
||||||
|
vtkm::worklet::DispatcherMapField<SetCandidateParticles<T>> setCandidateParticlesDispatcher(
|
||||||
|
setCandidateParticles);
|
||||||
|
setCandidateParticlesDispatcher.Invoke(bestEstPotential, // input
|
||||||
|
particleOffset, // input
|
||||||
|
partPerBin, // input
|
||||||
|
candidate); // output (whole array)
|
||||||
|
|
||||||
|
// Copy the M candidate particles to a new array
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> mparticles;
|
||||||
|
DeviceAlgorithm::CopyIf(partId, candidate, mparticles);
|
||||||
|
|
||||||
|
// Compute potentials only on the candidate particles
|
||||||
|
vtkm::cont::ArrayHandle<T> mpotential;
|
||||||
|
ComputePotentialOnCandidates<T> computePotentialOnCandidates(nParticles, particleMass);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputePotentialOnCandidates<T>>
|
||||||
|
computePotentialOnCandidatesDispatcher(computePotentialOnCandidates);
|
||||||
|
|
||||||
|
computePotentialOnCandidatesDispatcher.Invoke(mparticles,
|
||||||
|
xLoc, // input (whole array)
|
||||||
|
yLoc, // input (whole array)
|
||||||
|
zLoc, // input (whole array)
|
||||||
|
mpotential); // output
|
||||||
|
|
||||||
|
// Of the M candidate particles which has the minimum potential
|
||||||
|
DeviceAlgorithm::SortByKey(mpotential, mparticles);
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("mparticles", mparticles);
|
||||||
|
DebugPrint("mpotential", mpotential);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Return the found MBP particle and its potential
|
||||||
|
vtkm::Id mxnMBP = mparticles.GetPortalControl().Get(0);
|
||||||
|
*mxnPotential = mpotential.GetPortalControl().Get(0);
|
||||||
|
|
||||||
|
return mxnMBP;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Bin particles in one halo for quick MBP finding
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
void CosmoTools<T, StorageType, DeviceAdapter>::BinParticlesHalo(
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& partId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& uniqueBins,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& partPerBin,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& particleOffset,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binX,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binY,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binZ)
|
||||||
|
{
|
||||||
|
// Compute number of bins and ranges for each bin
|
||||||
|
vtkm::Vec<T, 2> xRange(xLoc.GetPortalConstControl().Get(0));
|
||||||
|
vtkm::Vec<T, 2> yRange(yLoc.GetPortalConstControl().Get(0));
|
||||||
|
vtkm::Vec<T, 2> zRange(zLoc.GetPortalConstControl().Get(0));
|
||||||
|
xRange = DeviceAlgorithm::Reduce(xLoc, xRange, vtkm::MinAndMax<T>());
|
||||||
|
T minX = xRange[0];
|
||||||
|
T maxX = xRange[1];
|
||||||
|
yRange = DeviceAlgorithm::Reduce(yLoc, yRange, vtkm::MinAndMax<T>());
|
||||||
|
T minY = yRange[0];
|
||||||
|
T maxY = yRange[1];
|
||||||
|
zRange = DeviceAlgorithm::Reduce(zLoc, zRange, vtkm::MinAndMax<T>());
|
||||||
|
T minZ = zRange[0];
|
||||||
|
T maxZ = zRange[1];
|
||||||
|
|
||||||
|
numBinsX = static_cast<vtkm::Id>(vtkm::Floor((maxX - minX) / linkLen));
|
||||||
|
numBinsY = static_cast<vtkm::Id>(vtkm::Floor((maxY - minY) / linkLen));
|
||||||
|
numBinsZ = static_cast<vtkm::Id>(vtkm::Floor((maxZ - minZ) / linkLen));
|
||||||
|
|
||||||
|
vtkm::Id maxBins = 1048576;
|
||||||
|
numBinsX = std::min(maxBins, numBinsX);
|
||||||
|
numBinsY = std::min(maxBins, numBinsY);
|
||||||
|
numBinsZ = std::min(maxBins, numBinsZ);
|
||||||
|
|
||||||
|
vtkm::Id minBins = 1;
|
||||||
|
numBinsX = std::max(minBins, numBinsX);
|
||||||
|
numBinsY = std::max(minBins, numBinsY);
|
||||||
|
numBinsZ = std::max(minBins, numBinsZ);
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
std::cout << std::endl
|
||||||
|
<< "** BinParticlesHalo (" << numBinsX << ", " << numBinsY << ", " << numBinsZ << ") ("
|
||||||
|
<< minX << ", " << minY << ", " << minZ << ") (" << maxX << ", " << maxY << ", " << maxZ
|
||||||
|
<< ")" << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Compute which bin each particle is in
|
||||||
|
ComputeBins<T> computeBins(minX,
|
||||||
|
maxX, // Physical range on domain
|
||||||
|
minY,
|
||||||
|
maxY,
|
||||||
|
minZ,
|
||||||
|
maxZ,
|
||||||
|
numBinsX,
|
||||||
|
numBinsY,
|
||||||
|
numBinsZ); // Size of superimposed mesh
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputeBins<T>> computeBinsDispatcher(computeBins);
|
||||||
|
computeBinsDispatcher.Invoke(xLoc, // input
|
||||||
|
yLoc, // input
|
||||||
|
zLoc, // input
|
||||||
|
binId); // output
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleIndex indexArray(nParticles);
|
||||||
|
DeviceAlgorithm::Copy(indexArray, partId);
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("xLoc", xLoc);
|
||||||
|
DebugPrint("yLoc", yLoc);
|
||||||
|
DebugPrint("zLoc", zLoc);
|
||||||
|
DebugPrint("partId", partId);
|
||||||
|
DebugPrint("binId", binId);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Sort the particles by bin
|
||||||
|
DeviceAlgorithm::SortByKey(binId, partId);
|
||||||
|
|
||||||
|
// Count the number of particles per bin
|
||||||
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> constArray(1, nParticles);
|
||||||
|
DeviceAlgorithm::ReduceByKey(binId, constArray, uniqueBins, partPerBin, vtkm::Add());
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("sorted binId", binId);
|
||||||
|
DebugPrint("sorted partId", partId);
|
||||||
|
DebugPrint("uniqueBins", uniqueBins);
|
||||||
|
DebugPrint("partPerBin", partPerBin);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Calculate the bin indices
|
||||||
|
vtkm::cont::ArrayHandleIndex uniqueIndex(uniqueBins.GetNumberOfValues());
|
||||||
|
ComputeBinIndices<T> computeBinIndices(numBinsX, numBinsY, numBinsZ);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputeBinIndices<T>> computeBinIndicesDispatcher(
|
||||||
|
computeBinIndices);
|
||||||
|
|
||||||
|
computeBinIndicesDispatcher.Invoke(uniqueBins, // input
|
||||||
|
binX, // input
|
||||||
|
binY, // input
|
||||||
|
binZ); // input
|
||||||
|
|
||||||
|
DeviceAlgorithm::ScanExclusive(partPerBin, particleOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Center finder for all particles given location, particle id and key id
|
||||||
|
// Assumed that key and particles are already sorted
|
||||||
|
// MBP (Most Bound Particle) is particle with the minimum potential energy
|
||||||
|
// Method uses ScanInclusiveByKey() and ArrayHandleReverse
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
void CosmoTools<T, StorageType, DeviceAdapter>::MBPCenterFindingByKey(
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& keyId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& partId,
|
||||||
|
vtkm::cont::ArrayHandle<T>& minPotential)
|
||||||
|
{
|
||||||
|
// Compute starting and ending indices of each key (bin or halo)
|
||||||
|
vtkm::cont::ArrayHandleIndex indexArray(nParticles);
|
||||||
|
vtkm::cont::ArrayHandle<T> potential;
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> keyReverse(keyId);
|
||||||
|
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<T>> minPotReverse(minPotential);
|
||||||
|
|
||||||
|
// Compute indices of all left neighbor bins per bin not per particle
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> leftNeighbor;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> rightNeighbor;
|
||||||
|
leftNeighbor.Allocate(NUM_NEIGHBORS * nParticles);
|
||||||
|
rightNeighbor.Allocate(NUM_NEIGHBORS * nParticles);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleIndex countArray(nParticles);
|
||||||
|
ComputeNeighborBins computeNeighborBins(numBinsX, numBinsY, numBinsZ, NUM_NEIGHBORS);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputeNeighborBins> computeNeighborBinsDispatcher(
|
||||||
|
computeNeighborBins);
|
||||||
|
computeNeighborBinsDispatcher.Invoke(countArray, keyId, leftNeighbor);
|
||||||
|
|
||||||
|
// Compute indices of all right neighbor bins
|
||||||
|
ComputeBinRange computeBinRange(numBinsX);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputeBinRange> computeBinRangeDispatcher(computeBinRange);
|
||||||
|
computeBinRangeDispatcher.Invoke(leftNeighbor, rightNeighbor);
|
||||||
|
|
||||||
|
// Convert bin range to particle range within the bins
|
||||||
|
DeviceAlgorithm::LowerBounds(keyId, leftNeighbor, leftNeighbor);
|
||||||
|
DeviceAlgorithm::UpperBounds(keyId, rightNeighbor, rightNeighbor);
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("leftNeighbor", leftNeighbor);
|
||||||
|
DebugPrint("rightNeighbor", rightNeighbor);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Initialize halo id of each particle to itself
|
||||||
|
// Compute potentials on particles in 27 neighbors to find minimum
|
||||||
|
ComputePotentialNeighbors<T> computePotentialNeighbors(
|
||||||
|
numBinsX, numBinsY, numBinsZ, NUM_NEIGHBORS, particleMass);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputePotentialNeighbors<T>>
|
||||||
|
computePotentialNeighborsDispatcher(computePotentialNeighbors);
|
||||||
|
|
||||||
|
computePotentialNeighborsDispatcher.Invoke(indexArray,
|
||||||
|
keyId, // input (whole array)
|
||||||
|
partId, // input (whole array)
|
||||||
|
xLoc, // input (whole array)
|
||||||
|
yLoc, // input (whole array)
|
||||||
|
zLoc, // input (whole array)
|
||||||
|
leftNeighbor, // input (whole array)
|
||||||
|
rightNeighbor, // input (whole array)
|
||||||
|
potential); // output
|
||||||
|
|
||||||
|
// Find minimum potential for all particles in a halo
|
||||||
|
DeviceAlgorithm::ScanInclusiveByKey(keyId, potential, minPotential, vtkm::Minimum());
|
||||||
|
DeviceAlgorithm::ScanInclusiveByKey(keyReverse, minPotReverse, minPotReverse, vtkm::Minimum());
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("potential", potential);
|
||||||
|
DebugPrint("minPotential", minPotential);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Find the particle id matching the minimum potential
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> centerId;
|
||||||
|
EqualsMinimumPotential<T> equalsMinimumPotential;
|
||||||
|
vtkm::worklet::DispatcherMapField<EqualsMinimumPotential<T>> equalsMinimumPotentialDispatcher(
|
||||||
|
equalsMinimumPotential);
|
||||||
|
|
||||||
|
equalsMinimumPotentialDispatcher.Invoke(partId, potential, minPotential, centerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Center finder for particles in a single halo given location and particle id
|
||||||
|
// MBP (Most Bound Particle) is particle with the minimum potential energy
|
||||||
|
// Method uses ScanInclusiveByKey() and ArrayHandleReverse
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
vtkm::Id CosmoTools<T, StorageType, DeviceAdapter>::MBPCenterFinderNxN(T* nxnPotential)
|
||||||
|
{
|
||||||
|
vtkm::cont::ArrayHandle<T> potential;
|
||||||
|
vtkm::cont::ArrayHandle<T> minPotential;
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<T>> minPotReverse(minPotential);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleIndex particleIndex(nParticles);
|
||||||
|
|
||||||
|
// Compute potentials (Worklet)
|
||||||
|
ComputePotentialNxN<T> computePotentialHalo(nParticles, particleMass);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputePotentialNxN<T>> computePotentialHaloDispatcher(
|
||||||
|
computePotentialHalo);
|
||||||
|
|
||||||
|
computePotentialHaloDispatcher.Invoke(particleIndex, // input
|
||||||
|
xLoc, // input (whole array)
|
||||||
|
yLoc, // input (whole array)
|
||||||
|
zLoc, // input (whole array)
|
||||||
|
potential); // output
|
||||||
|
|
||||||
|
// Find minimum potential for all particles in a halo
|
||||||
|
DeviceAlgorithm::ScanInclusive(potential, minPotential, vtkm::Minimum());
|
||||||
|
DeviceAlgorithm::ScanInclusive(minPotReverse, minPotReverse, vtkm::Minimum());
|
||||||
|
|
||||||
|
// Find the particle id matching the minimum potential
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> centerId;
|
||||||
|
EqualsMinimumPotential<T> equalsMinimumPotential;
|
||||||
|
vtkm::worklet::DispatcherMapField<EqualsMinimumPotential<T>> equalsMinimumPotentialDispatcher(
|
||||||
|
equalsMinimumPotential);
|
||||||
|
|
||||||
|
equalsMinimumPotentialDispatcher.Invoke(particleIndex, potential, minPotential, centerId);
|
||||||
|
|
||||||
|
// Fill out entire array with center index
|
||||||
|
vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<vtkm::Id>> centerIdReverse(centerId);
|
||||||
|
DeviceAlgorithm::ScanInclusive(centerId, centerId, vtkm::Maximum());
|
||||||
|
DeviceAlgorithm::ScanInclusive(centerIdReverse, centerIdReverse, vtkm::Maximum());
|
||||||
|
|
||||||
|
vtkm::Id nxnMBP = centerId.GetPortalConstControl().Get(0);
|
||||||
|
*nxnPotential = potential.GetPortalConstControl().Get(nxnMBP);
|
||||||
|
|
||||||
|
return nxnMBP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
417
vtkm/worklet/cosmotools/CosmoToolsHaloFinder.h
Normal file
417
vtkm/worklet/cosmotools/CosmoToolsHaloFinder.h
Normal file
@ -0,0 +1,417 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_cosmotools_halofinder_h
|
||||||
|
#define vtkm_worklet_cosmotools_cosmotools_halofinder_h
|
||||||
|
|
||||||
|
#include <vtkm/worklet/cosmotools/CosmoTools.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Halo finder for all particles in domain
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
void CosmoTools<T, StorageType, DeviceAdapter>::HaloFinder(
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& resultHaloId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& resultMBP,
|
||||||
|
vtkm::cont::ArrayHandle<T>& resultPot)
|
||||||
|
{
|
||||||
|
// Package locations for worklets
|
||||||
|
using CompositeLocationType =
|
||||||
|
typename vtkm::cont::ArrayHandleCompositeVectorType<LocationType,
|
||||||
|
LocationType,
|
||||||
|
LocationType>::type;
|
||||||
|
CompositeLocationType location;
|
||||||
|
location = make_ArrayHandleCompositeVector(xLoc, 0, yLoc, 0, zLoc, 0);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> leftNeighbor; // lower particle id to check for linking length
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> rightNeighbor; // upper particle id to check for linking length
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::UInt32>
|
||||||
|
activeMask; // mask per particle indicating active neighbor bins
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> partId; // index into all particles
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> binId; // bin id for each particle in each FOF halo
|
||||||
|
|
||||||
|
leftNeighbor.Allocate(NUM_NEIGHBORS * nParticles);
|
||||||
|
rightNeighbor.Allocate(NUM_NEIGHBORS * nParticles);
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleConstant<bool> trueArray(true, nParticles);
|
||||||
|
vtkm::cont::ArrayHandleIndex indexArray(nParticles);
|
||||||
|
|
||||||
|
// Bin all particles in domain into bins of size linking length
|
||||||
|
BinParticlesAll(partId, binId, leftNeighbor, rightNeighbor);
|
||||||
|
|
||||||
|
// Mark active neighbor bins, meaning at least one particle in the bin
|
||||||
|
// is within linking length of the given particle indicated by mask
|
||||||
|
MarkActiveNeighbors<T> markActiveNeighbors(numBinsX, numBinsY, numBinsZ, NUM_NEIGHBORS, linkLen);
|
||||||
|
vtkm::worklet::DispatcherMapField<MarkActiveNeighbors<T>> markActiveNeighborsDispatcher(
|
||||||
|
markActiveNeighbors);
|
||||||
|
markActiveNeighborsDispatcher.Invoke(
|
||||||
|
indexArray, // (input) index into all particles
|
||||||
|
partId, // (input) particle id sorted by bin
|
||||||
|
binId, // (input) bin id sorted
|
||||||
|
partId, // (input) particle id (whole array)
|
||||||
|
location, // (input) location on original particle order
|
||||||
|
leftNeighbor, // (input) first partId for neighbor vector
|
||||||
|
rightNeighbor, // (input) last partId for neighbor vector
|
||||||
|
activeMask); // (output) mask per particle indicating valid neighbors
|
||||||
|
|
||||||
|
// Initialize halo id of each particle to itself
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> haloIdCurrent;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> haloIdLast;
|
||||||
|
DeviceAlgorithm::Copy(indexArray, haloIdCurrent);
|
||||||
|
DeviceAlgorithm::Copy(indexArray, haloIdLast);
|
||||||
|
|
||||||
|
// rooted star is nchecked each iteration for all particles being rooted in a halo
|
||||||
|
vtkm::cont::ArrayHandle<bool> rootedStar;
|
||||||
|
|
||||||
|
// Iterate over particles graft together to form halos
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// Connect each particle to another close particle to build halos
|
||||||
|
GraftParticles<T> graftParticles(numBinsX, numBinsY, numBinsZ, NUM_NEIGHBORS, linkLen);
|
||||||
|
vtkm::worklet::DispatcherMapField<GraftParticles<T>> graftParticlesDispatcher(graftParticles);
|
||||||
|
|
||||||
|
graftParticlesDispatcher.Invoke(indexArray, // (input) index into particles
|
||||||
|
partId, // (input) particle id sorted by bin
|
||||||
|
binId, // (input) bin id sorted by bin
|
||||||
|
activeMask, // (input) flag indicates if neighor range is used
|
||||||
|
partId, // (input) particle id (whole array)
|
||||||
|
location, // (input) location on original particle order
|
||||||
|
leftNeighbor, // (input) first partId for neighbor
|
||||||
|
rightNeighbor, // (input) last partId for neighbor
|
||||||
|
haloIdCurrent); // (output)
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("haloIdCurrent", haloIdCurrent);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Reininitialize rootedStar for each pass
|
||||||
|
DeviceAlgorithm::Copy(trueArray, rootedStar);
|
||||||
|
|
||||||
|
// By comparing the haloIds from the last pass and this one
|
||||||
|
// determine if any particles are still migrating to halos
|
||||||
|
IsStar isStar;
|
||||||
|
vtkm::worklet::DispatcherMapField<IsStar> isStarDispatcher(isStar);
|
||||||
|
isStarDispatcher.Invoke(indexArray,
|
||||||
|
haloIdCurrent, // input (whole array)
|
||||||
|
haloIdLast, // input (whole array)
|
||||||
|
rootedStar); // output (whole array)
|
||||||
|
|
||||||
|
// If all vertices are in rooted stars, algorithm is complete
|
||||||
|
bool allStars = DeviceAlgorithm::Reduce(rootedStar, true, vtkm::BitwiseAnd());
|
||||||
|
if (allStars)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// Otherwise copy current halo ids to last pass halo ids
|
||||||
|
{
|
||||||
|
PointerJump pointerJump;
|
||||||
|
vtkm::worklet::DispatcherMapField<PointerJump> pointerJumpDispatcher(pointerJump);
|
||||||
|
pointerJumpDispatcher.Invoke(indexArray, haloIdCurrent); // input (whole array)
|
||||||
|
DeviceAlgorithm::Copy(haloIdCurrent, haloIdLast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Index into final halo id is the original particle ordering
|
||||||
|
// not the particles sorted by bin
|
||||||
|
DeviceAlgorithm::Copy(indexArray, partId);
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("FINAL haloId", haloIdCurrent);
|
||||||
|
DebugPrint("FINAL partId", partId);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Call center finding on all halos using method with ReduceByKey and Scatter
|
||||||
|
DeviceAlgorithm::Copy(haloIdCurrent, resultHaloId);
|
||||||
|
MBPCenterFindingByHalo(partId, resultHaloId, resultMBP, resultPot);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Bin all particles in the system for halo finding
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
void CosmoTools<T, StorageType, DeviceAdapter>::BinParticlesAll(
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& partId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& binId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& leftNeighbor,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& rightNeighbor)
|
||||||
|
{
|
||||||
|
// Compute number of bins and ranges for each bin
|
||||||
|
vtkm::Vec<T, 2> result;
|
||||||
|
vtkm::Vec<T, 2> xInit(xLoc.GetPortalConstControl().Get(0));
|
||||||
|
vtkm::Vec<T, 2> yInit(yLoc.GetPortalConstControl().Get(0));
|
||||||
|
vtkm::Vec<T, 2> zInit(zLoc.GetPortalConstControl().Get(0));
|
||||||
|
result = DeviceAlgorithm::Reduce(xLoc, xInit, vtkm::MinAndMax<T>());
|
||||||
|
T minX = result[0];
|
||||||
|
T maxX = result[1];
|
||||||
|
result = DeviceAlgorithm::Reduce(yLoc, yInit, vtkm::MinAndMax<T>());
|
||||||
|
T minY = result[0];
|
||||||
|
T maxY = result[1];
|
||||||
|
result = DeviceAlgorithm::Reduce(zLoc, zInit, vtkm::MinAndMax<T>());
|
||||||
|
T minZ = result[0];
|
||||||
|
T maxZ = result[1];
|
||||||
|
|
||||||
|
vtkm::Id maxBins = 1048576;
|
||||||
|
vtkm::Id minBins = 1;
|
||||||
|
|
||||||
|
numBinsX = static_cast<vtkm::Id>(vtkm::Floor((maxX - minX) / linkLen));
|
||||||
|
numBinsY = static_cast<vtkm::Id>(vtkm::Floor((maxY - minY) / linkLen));
|
||||||
|
numBinsZ = static_cast<vtkm::Id>(vtkm::Floor((maxZ - minZ) / linkLen));
|
||||||
|
|
||||||
|
numBinsX = std::min(maxBins, numBinsX);
|
||||||
|
numBinsY = std::min(maxBins, numBinsY);
|
||||||
|
numBinsZ = std::min(maxBins, numBinsZ);
|
||||||
|
|
||||||
|
numBinsX = std::max(minBins, numBinsX);
|
||||||
|
numBinsY = std::max(minBins, numBinsY);
|
||||||
|
numBinsZ = std::max(minBins, numBinsZ);
|
||||||
|
|
||||||
|
// Compute which bin each particle is in
|
||||||
|
ComputeBins<T> computeBins(minX,
|
||||||
|
maxX, // Physical range on domain
|
||||||
|
minY,
|
||||||
|
maxY,
|
||||||
|
minZ,
|
||||||
|
maxZ,
|
||||||
|
numBinsX,
|
||||||
|
numBinsY,
|
||||||
|
numBinsZ); // Size of superimposed mesh
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputeBins<T>> computeBinsDispatcher(computeBins);
|
||||||
|
computeBinsDispatcher.Invoke(xLoc, // input
|
||||||
|
yLoc, // input
|
||||||
|
zLoc, // input
|
||||||
|
binId); // output
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleIndex indexArray(nParticles);
|
||||||
|
DeviceAlgorithm::Copy(indexArray, partId);
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
std::cout << std::endl
|
||||||
|
<< "** BinParticlesAll (" << numBinsX << ", " << numBinsY << ", " << numBinsZ << ")"
|
||||||
|
<< std::endl;
|
||||||
|
DebugPrint("xLoc", xLoc);
|
||||||
|
DebugPrint("yLoc", yLoc);
|
||||||
|
DebugPrint("zLoc", zLoc);
|
||||||
|
DebugPrint("partId", partId);
|
||||||
|
DebugPrint("binId", binId);
|
||||||
|
std::cout << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Sort the particles by bin (remember that xLoc and yLoc are not sorted)
|
||||||
|
DeviceAlgorithm::SortByKey(binId, partId);
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("partId", partId);
|
||||||
|
DebugPrint("binId", binId);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Compute indices of all left neighbor bins
|
||||||
|
vtkm::cont::ArrayHandleIndex countArray(nParticles);
|
||||||
|
ComputeNeighborBins computeNeighborBins(numBinsX, numBinsY, numBinsZ, NUM_NEIGHBORS);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputeNeighborBins> computeNeighborBinsDispatcher(
|
||||||
|
computeNeighborBins);
|
||||||
|
computeNeighborBinsDispatcher.Invoke(countArray, binId, leftNeighbor);
|
||||||
|
|
||||||
|
// Compute indices of all right neighbor bins
|
||||||
|
ComputeBinRange computeBinRange(numBinsX);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputeBinRange> computeBinRangeDispatcher(computeBinRange);
|
||||||
|
computeBinRangeDispatcher.Invoke(leftNeighbor, rightNeighbor);
|
||||||
|
|
||||||
|
// Convert bin range to particle range within the bins
|
||||||
|
DeviceAlgorithm::LowerBounds(binId, leftNeighbor, leftNeighbor);
|
||||||
|
DeviceAlgorithm::UpperBounds(binId, rightNeighbor, rightNeighbor);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Center finder for all particles given location, particle id and halo id
|
||||||
|
// MBP (Most Bound Particle) is particle with the minimum potential energy
|
||||||
|
// Method uses ReduceByKey() and Scatter()
|
||||||
|
//
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
template <typename T, typename StorageType, typename DeviceAdapter>
|
||||||
|
void CosmoTools<T, StorageType, DeviceAdapter>::MBPCenterFindingByHalo(
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& partId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& haloId,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& mbpId,
|
||||||
|
vtkm::cont::ArrayHandle<T>& minPotential)
|
||||||
|
{
|
||||||
|
// Sort particles into groups according to halo id using an index into WholeArrays
|
||||||
|
DeviceAlgorithm::SortByKey(haloId, partId);
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("Sorted haloId", haloId);
|
||||||
|
DebugPrint("Sorted partId", partId);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Find the particle in each halo with the lowest potential
|
||||||
|
// Compute starting and ending indices of each halo
|
||||||
|
vtkm::cont::ArrayHandleConstant<vtkm::Id> constArray(1, nParticles);
|
||||||
|
vtkm::cont::ArrayHandleIndex indexArray(nParticles);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> uniqueHaloIds;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> particlesPerHalo;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> minParticle;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> maxParticle;
|
||||||
|
vtkm::cont::ArrayHandle<T> potential;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> tempI;
|
||||||
|
vtkm::cont::ArrayHandle<T> tempT;
|
||||||
|
|
||||||
|
// Halo ids have been sorted, reduce to find the number of particles per halo
|
||||||
|
DeviceAlgorithm::ReduceByKey(haloId, constArray, uniqueHaloIds, particlesPerHalo, vtkm::Add());
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("uniqueHaloId", uniqueHaloIds);
|
||||||
|
DebugPrint("partPerHalo", particlesPerHalo);
|
||||||
|
std::cout << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Setup the ScatterCounting worklets needed to expand the ReduceByKeyResults
|
||||||
|
vtkm::worklet::ScatterCounting scatter(particlesPerHalo, DeviceAdapter());
|
||||||
|
ScatterWorklet<vtkm::Id> scatterWorkletId(scatter);
|
||||||
|
ScatterWorklet<T> scatterWorklet(scatter);
|
||||||
|
vtkm::worklet::DispatcherMapField<ScatterWorklet<vtkm::Id>> scatterWorkletIdDispatcher(
|
||||||
|
scatterWorkletId);
|
||||||
|
vtkm::worklet::DispatcherMapField<ScatterWorklet<T>> scatterWorkletDispatcher(scatterWorklet);
|
||||||
|
|
||||||
|
// Calculate the minimum particle index per halo id and scatter
|
||||||
|
DeviceAlgorithm::ScanExclusive(particlesPerHalo, tempI);
|
||||||
|
scatterWorkletIdDispatcher.Invoke(tempI, minParticle);
|
||||||
|
|
||||||
|
// Calculate the maximum particle index per halo id and scatter
|
||||||
|
DeviceAlgorithm::ScanInclusive(particlesPerHalo, tempI);
|
||||||
|
scatterWorkletIdDispatcher.Invoke(tempI, maxParticle);
|
||||||
|
|
||||||
|
using IdArrayType = vtkm::cont::ArrayHandle<vtkm::Id>;
|
||||||
|
vtkm::cont::ArrayHandleTransform<IdArrayType, ScaleBiasFunctor<vtkm::Id>> scaleBias =
|
||||||
|
vtkm::cont::make_ArrayHandleTransform<IdArrayType>(maxParticle,
|
||||||
|
ScaleBiasFunctor<vtkm::Id>(1, -1));
|
||||||
|
|
||||||
|
DeviceAlgorithm::Copy(scaleBias, maxParticle);
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("minParticle", minParticle);
|
||||||
|
DebugPrint("maxParticle", maxParticle);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Compute potentials
|
||||||
|
ComputePotential<T> computePotential(particleMass);
|
||||||
|
vtkm::worklet::DispatcherMapField<ComputePotential<T>> computePotentialDispatcher(
|
||||||
|
computePotential);
|
||||||
|
|
||||||
|
computePotentialDispatcher.Invoke(indexArray,
|
||||||
|
partId, // input (whole array)
|
||||||
|
xLoc, // input (whole array)
|
||||||
|
yLoc, // input (whole array)
|
||||||
|
zLoc, // input (whole array)
|
||||||
|
minParticle, // input (whole array)
|
||||||
|
maxParticle, // input (whole array)
|
||||||
|
potential); // output
|
||||||
|
|
||||||
|
// Find minimum potential for all particles in a halo and scatter
|
||||||
|
DeviceAlgorithm::ReduceByKey(haloId, potential, uniqueHaloIds, tempT, vtkm::Minimum());
|
||||||
|
scatterWorkletDispatcher.Invoke(tempT, minPotential);
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
DebugPrint("potential", potential);
|
||||||
|
DebugPrint("minPotential", minPotential);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Find the particle id matching the minimum potential (Worklet)
|
||||||
|
EqualsMinimumPotential<T> equalsMinimumPotential;
|
||||||
|
vtkm::worklet::DispatcherMapField<EqualsMinimumPotential<T>> equalsMinimumPotentialDispatcher(
|
||||||
|
equalsMinimumPotential);
|
||||||
|
|
||||||
|
equalsMinimumPotentialDispatcher.Invoke(partId, potential, minPotential, mbpId);
|
||||||
|
|
||||||
|
// Fill out entire array with center index, another reduce and scatter
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> minIndx;
|
||||||
|
minIndx.Allocate(nParticles);
|
||||||
|
DeviceAlgorithm::ReduceByKey(haloId, mbpId, uniqueHaloIds, minIndx, vtkm::Maximum());
|
||||||
|
scatterWorkletIdDispatcher.Invoke(minIndx, mbpId);
|
||||||
|
|
||||||
|
// Resort particle ids and mbpId to starting order
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> savePartId;
|
||||||
|
DeviceAlgorithm::Copy(partId, savePartId);
|
||||||
|
|
||||||
|
DeviceAlgorithm::SortByKey(partId, haloId);
|
||||||
|
DeviceAlgorithm::Copy(savePartId, partId);
|
||||||
|
DeviceAlgorithm::SortByKey(partId, mbpId);
|
||||||
|
DeviceAlgorithm::Copy(savePartId, partId);
|
||||||
|
DeviceAlgorithm::SortByKey(partId, minPotential);
|
||||||
|
|
||||||
|
#ifdef DEBUG_PRINT
|
||||||
|
std::cout << std::endl;
|
||||||
|
DebugPrint("partId", partId);
|
||||||
|
DebugPrint("xLoc", xLoc);
|
||||||
|
DebugPrint("yLoc", yLoc);
|
||||||
|
DebugPrint("haloId", haloId);
|
||||||
|
DebugPrint("mbpId", mbpId);
|
||||||
|
DebugPrint("minPotential", minPotential);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
109
vtkm/worklet/cosmotools/EqualsMinimumPotential.h
Normal file
109
vtkm/worklet/cosmotools/EqualsMinimumPotential.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_equals_minimum_potential_h
|
||||||
|
#define vtkm_worklet_cosmotools_equals_minimum_potential_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for computing the potential for a particle
|
||||||
|
template <typename T>
|
||||||
|
class EqualsMinimumPotential : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> partId, // (input) particle Id
|
||||||
|
FieldIn<TagType> potential1, // (input) particle potential
|
||||||
|
FieldIn<TagType> potential2, // (input) minimum potential
|
||||||
|
FieldOut<IdType> minParticleIndx); // (output) particle Id of min
|
||||||
|
typedef _4 ExecutionSignature(_1, _2, _3);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
EqualsMinimumPotential() {}
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
vtkm::Id operator()(const vtkm::Id& partId, const T& potential1, const T& potential2) const
|
||||||
|
{
|
||||||
|
vtkm::Id minParticleIndx = 0;
|
||||||
|
if (fabs(potential1 - potential2) < 0.000000000001)
|
||||||
|
{
|
||||||
|
minParticleIndx = partId;
|
||||||
|
}
|
||||||
|
return minParticleIndx;
|
||||||
|
}
|
||||||
|
}; // EqualsMinimumPotential
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
173
vtkm/worklet/cosmotools/GraftParticles.h
Normal file
173
vtkm/worklet/cosmotools/GraftParticles.h
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_graft_particle_h
|
||||||
|
#define vtkm_worklet_cosmotools_graft_particle_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet to graft particles together to form halos
|
||||||
|
template <typename T>
|
||||||
|
class GraftParticles : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(
|
||||||
|
FieldIn<IdType> index, // (input) index into particles
|
||||||
|
FieldIn<IdType> partId, // (input) particle id sorted by bin
|
||||||
|
FieldIn<IdType> binId, // (input) bin id sorted by bin
|
||||||
|
FieldIn<vtkm::UInt32> activeFlag, // (input) flag indicates which of neighbor ranges are used
|
||||||
|
WholeArrayIn<IdType> partIdArray, // (input) particle id sorted by bin entire array
|
||||||
|
WholeArrayIn<TagType> location, // (input) location of particles
|
||||||
|
WholeArrayIn<IdType> firstParticleId, // (input) first particle index vector
|
||||||
|
WholeArrayIn<IdType> lastParticleId, // (input) last particle index vector
|
||||||
|
WholeArrayOut<IdType> haloId);
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3, _4, _5, _6, _7, _8, _9);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id xNum, yNum, zNum;
|
||||||
|
vtkm::Id NUM_NEIGHBORS;
|
||||||
|
T linkLenSq;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
GraftParticles(const vtkm::Id XNum,
|
||||||
|
const vtkm::Id YNum,
|
||||||
|
const vtkm::Id ZNum,
|
||||||
|
const vtkm::Id NumNeighbors,
|
||||||
|
const T LinkLen)
|
||||||
|
: xNum(XNum)
|
||||||
|
, yNum(YNum)
|
||||||
|
, zNum(ZNum)
|
||||||
|
, NUM_NEIGHBORS(NumNeighbors)
|
||||||
|
, linkLenSq(LinkLen * LinkLen)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InIdPortalType,
|
||||||
|
typename InFieldPortalType,
|
||||||
|
typename InVectorPortalType,
|
||||||
|
typename OutPortalType>
|
||||||
|
VTKM_EXEC void operator()(const vtkm::Id& i,
|
||||||
|
const vtkm::Id& iPartId,
|
||||||
|
const vtkm::Id& iBinId,
|
||||||
|
const vtkm::UInt32& activeFlag,
|
||||||
|
const InIdPortalType& partIdArray,
|
||||||
|
const InFieldPortalType& location,
|
||||||
|
const InVectorPortalType& firstParticleId,
|
||||||
|
const InVectorPortalType& lastParticleId,
|
||||||
|
OutPortalType& haloId) const
|
||||||
|
{
|
||||||
|
const vtkm::Id yVal = (iBinId / xNum) % yNum;
|
||||||
|
const vtkm::Id zVal = iBinId / (xNum * yNum);
|
||||||
|
vtkm::UInt32 flag = activeFlag;
|
||||||
|
vtkm::Id cnt = 0;
|
||||||
|
|
||||||
|
// Iterate on both sides of the bin this particle is in
|
||||||
|
for (vtkm::Id z = zVal - 1; z <= zVal + 1; z++)
|
||||||
|
{
|
||||||
|
for (vtkm::Id y = yVal - 1; y <= yVal + 1; y++)
|
||||||
|
{
|
||||||
|
if (flag & 0x1)
|
||||||
|
{
|
||||||
|
vtkm::Id firstBinId = NUM_NEIGHBORS * i + cnt;
|
||||||
|
vtkm::Id startParticle = firstParticleId.Get(firstBinId);
|
||||||
|
vtkm::Id endParticle = lastParticleId.Get(firstBinId);
|
||||||
|
|
||||||
|
for (vtkm::Id j = startParticle; j < endParticle; j++)
|
||||||
|
{
|
||||||
|
vtkm::Id jPartId = partIdArray.Get(j);
|
||||||
|
vtkm::Vec<T, 3> iloc = location.Get(iPartId);
|
||||||
|
vtkm::Vec<T, 3> jloc = location.Get(jPartId);
|
||||||
|
T xDist = iloc[0] - jloc[0];
|
||||||
|
T yDist = iloc[1] - jloc[1];
|
||||||
|
T zDist = iloc[2] - jloc[2];
|
||||||
|
if ((xDist * xDist + yDist * yDist + zDist * zDist) <= linkLenSq)
|
||||||
|
{
|
||||||
|
if ((haloId.Get(iPartId) == haloId.Get(haloId.Get(iPartId))) &&
|
||||||
|
(haloId.Get(jPartId) < haloId.Get(iPartId)))
|
||||||
|
{
|
||||||
|
haloId.Set(haloId.Get(iPartId), haloId.Get(jPartId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flag = flag >> 1;
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}; // GraftParticles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
109
vtkm/worklet/cosmotools/IsStar.h
Normal file
109
vtkm/worklet/cosmotools/IsStar.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_is_star_h
|
||||||
|
#define vtkm_worklet_cosmotools_is_star_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Examine halo ids from current pass and last pass to see if particles
|
||||||
|
// are rooted in an existing halo
|
||||||
|
class IsStar : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> index,
|
||||||
|
WholeArrayInOut<IdType> haloIdCurrent,
|
||||||
|
WholeArrayInOut<IdType> haloIdLast,
|
||||||
|
WholeArrayInOut<bool> rootedStar);
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3, _4);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
IsStar() {}
|
||||||
|
|
||||||
|
template <typename InPortalType, typename InPortalType2>
|
||||||
|
VTKM_EXEC void operator()(const vtkm::Id& i,
|
||||||
|
const InPortalType& haloIdCurrent,
|
||||||
|
const InPortalType& haloIdLast,
|
||||||
|
InPortalType2& rootedStar) const
|
||||||
|
{
|
||||||
|
vtkm::Id dValue = haloIdLast.Get(i);
|
||||||
|
vtkm::Id ddValue = haloIdCurrent.Get(dValue);
|
||||||
|
if (dValue != ddValue)
|
||||||
|
{
|
||||||
|
rootedStar.Set(dValue, false);
|
||||||
|
rootedStar.Set(ddValue, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}; // IsStar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
171
vtkm/worklet/cosmotools/MarkActiveNeighbors.h
Normal file
171
vtkm/worklet/cosmotools/MarkActiveNeighbors.h
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_mark_active_neighbors_h
|
||||||
|
#define vtkm_worklet_cosmotools_mark_active_neighbors_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet for particles to indicate which neighbors are active
|
||||||
|
// because at least one particle in that bin is within linking length
|
||||||
|
template <typename T>
|
||||||
|
class MarkActiveNeighbors : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(
|
||||||
|
FieldIn<IdType> index, // (input) particle index
|
||||||
|
FieldIn<IdType> partId, // (input) particle id sorted
|
||||||
|
FieldIn<IdType> binId, // (input) bin Id per particle
|
||||||
|
WholeArrayIn<IdType> partIdArray, // (input) sequence imposed on sorted particle Ids
|
||||||
|
WholeArrayIn<TagType> location, // (input) location of particles
|
||||||
|
WholeArrayIn<IdType> firstPartId, // (input) vector of first particle indices
|
||||||
|
WholeArrayIn<IdType> lastPartId, // (input) vector of last particle indices
|
||||||
|
FieldOut<vtkm::UInt32> flag); // (output) active bin neighbors mask
|
||||||
|
typedef _8 ExecutionSignature(_1, _2, _3, _4, _5, _6, _7);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id xNum, yNum, zNum;
|
||||||
|
vtkm::Id NUM_NEIGHBORS;
|
||||||
|
T linkLenSq;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
MarkActiveNeighbors(const vtkm::Id XNum,
|
||||||
|
const vtkm::Id YNum,
|
||||||
|
const vtkm::Id ZNum,
|
||||||
|
const vtkm::Id NumNeighbors,
|
||||||
|
const T LinkLen)
|
||||||
|
: xNum(XNum)
|
||||||
|
, yNum(YNum)
|
||||||
|
, zNum(ZNum)
|
||||||
|
, NUM_NEIGHBORS(NumNeighbors)
|
||||||
|
, linkLenSq(LinkLen * LinkLen)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InIdPortalType, typename InFieldPortalType, typename InVectorPortalType>
|
||||||
|
VTKM_EXEC vtkm::UInt32 operator()(const vtkm::Id& i,
|
||||||
|
const vtkm::Id& iPartId,
|
||||||
|
const vtkm::Id& iBinId,
|
||||||
|
const InIdPortalType& partIdArray,
|
||||||
|
const InFieldPortalType& location,
|
||||||
|
const InVectorPortalType& firstPartId,
|
||||||
|
const InVectorPortalType& lastPartId) const
|
||||||
|
{
|
||||||
|
const vtkm::Id ybin = (iBinId / xNum) % yNum;
|
||||||
|
const vtkm::Id zbin = iBinId / (xNum * yNum);
|
||||||
|
vtkm::UInt32 activeFlag = 0;
|
||||||
|
vtkm::UInt32 bcnt = 1;
|
||||||
|
vtkm::Id cnt = 0;
|
||||||
|
|
||||||
|
// Examine all neighbor bins surrounding this particle
|
||||||
|
for (vtkm::Id z = zbin - 1; z <= zbin + 1; z++)
|
||||||
|
{
|
||||||
|
for (vtkm::Id y = ybin - 1; y <= ybin + 1; y++)
|
||||||
|
{
|
||||||
|
if ((y >= 0) && (y < yNum) && (z >= 0) && (z < zNum))
|
||||||
|
{
|
||||||
|
vtkm::Id pos = NUM_NEIGHBORS * i + cnt;
|
||||||
|
vtkm::Id startParticle = firstPartId.Get(pos);
|
||||||
|
vtkm::Id endParticle = lastPartId.Get(pos);
|
||||||
|
|
||||||
|
// If the bin has any particles, check to see if any of those
|
||||||
|
// are within the linking length from this particle
|
||||||
|
for (vtkm::Id j = startParticle; j < endParticle; j++)
|
||||||
|
{
|
||||||
|
vtkm::Id jPartId = partIdArray.Get(j);
|
||||||
|
vtkm::Vec<T, 3> iloc = location.Get(iPartId);
|
||||||
|
vtkm::Vec<T, 3> jloc = location.Get(jPartId);
|
||||||
|
T xDist = iloc[0] - jloc[0];
|
||||||
|
T yDist = iloc[1] - jloc[1];
|
||||||
|
T zDist = iloc[2] - jloc[2];
|
||||||
|
|
||||||
|
// Found a particle within linking length so this bin is active
|
||||||
|
if ((xDist * xDist + yDist * yDist + zDist * zDist) <= linkLenSq)
|
||||||
|
{
|
||||||
|
activeFlag = activeFlag | bcnt;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bcnt = bcnt << 1;
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return activeFlag;
|
||||||
|
}
|
||||||
|
}; // MarkActiveNeighbors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
97
vtkm/worklet/cosmotools/PointerJump.h
Normal file
97
vtkm/worklet/cosmotools/PointerJump.h
Normal file
@ -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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_pointer_jump_h
|
||||||
|
#define vtkm_worklet_cosmotools_pointer_jump_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Jump to next pointer in array
|
||||||
|
class PointerJump : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> index, WholeArrayInOut<IdType> D);
|
||||||
|
typedef void ExecutionSignature(_1, _2);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
PointerJump() {}
|
||||||
|
|
||||||
|
template <typename InPortalType>
|
||||||
|
VTKM_EXEC void operator()(const vtkm::Id& index, InPortalType& D) const
|
||||||
|
{
|
||||||
|
vtkm::Id dValue = D.Get(index);
|
||||||
|
D.Set(index, D.Get(dValue));
|
||||||
|
}
|
||||||
|
}; // PointerJump
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
116
vtkm/worklet/cosmotools/SetCandidateParticles.h
Normal file
116
vtkm/worklet/cosmotools/SetCandidateParticles.h
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_set_candidate_particles_h
|
||||||
|
#define vtkm_worklet_cosmotools_set_candidate_particles_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Worklet to examine each bin against a cutoff and mark its particles as candidates
|
||||||
|
template <typename T>
|
||||||
|
class SetCandidateParticles : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct TagType : vtkm::ListTagBase<T>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void ControlSignature(FieldIn<TagType> bestPot, // (input) bin's best potential
|
||||||
|
FieldIn<IdType> partOffset, // (input) offset to first particle
|
||||||
|
FieldIn<IdType> partCount, // (input) count of particles in bin
|
||||||
|
WholeArrayOut<IdType> candidate); // (input) z location in bin
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3, _4);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
T cutoffPotential; // Lowest potential for a candidate bin
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
SetCandidateParticles(T Cutoff)
|
||||||
|
: cutoffPotential(Cutoff)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename OutPortalType>
|
||||||
|
VTKM_EXEC void operator()(const T& bestPot,
|
||||||
|
const vtkm::Id& offset,
|
||||||
|
const vtkm::Id& count,
|
||||||
|
const OutPortalType& candidate) const
|
||||||
|
{
|
||||||
|
if (bestPot <= cutoffPotential)
|
||||||
|
{
|
||||||
|
for (vtkm::Id part = offset; part < offset + count; part++)
|
||||||
|
candidate.Set(part, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}; // SetCandidateParticles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
112
vtkm/worklet/cosmotools/ValidHalo.h
Normal file
112
vtkm/worklet/cosmotools/ValidHalo.h
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
// Copyright (c) 2016, Los Alamos National Security, LLC
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Copyright 2016. Los Alamos National Security, LLC.
|
||||||
|
// This software was produced under U.S. Government contract DE-AC52-06NA25396
|
||||||
|
// for Los Alamos National Laboratory (LANL), which is operated by
|
||||||
|
// Los Alamos National Security, LLC for the U.S. Department of Energy.
|
||||||
|
// The U.S. Government has rights to use, reproduce, and distribute this
|
||||||
|
// software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
|
||||||
|
// MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
|
||||||
|
// USE OF THIS SOFTWARE. If software is modified to produce derivative works,
|
||||||
|
// such modified software should be clearly marked, so as not to confuse it
|
||||||
|
// with the version available from LANL.
|
||||||
|
//
|
||||||
|
// Additionally, redistribution and use in source and binary forms, with or
|
||||||
|
// without modification, are permitted provided that the following conditions
|
||||||
|
// are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer.
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
|
// and/or other materials provided with the distribution.
|
||||||
|
// 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
|
||||||
|
// National Laboratory, LANL, the U.S. Government, nor the names of its
|
||||||
|
// contributors may be used to endorse or promote products derived from
|
||||||
|
// this software without specific prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
|
||||||
|
// CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
|
||||||
|
// NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtkm_worklet_cosmotools_valid_halo_h
|
||||||
|
#define vtkm_worklet_cosmotools_valid_halo_h
|
||||||
|
|
||||||
|
#include <vtkm/exec/ExecutionWholeArray.h>
|
||||||
|
#include <vtkm/worklet/WorkletMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace cosmotools
|
||||||
|
{
|
||||||
|
|
||||||
|
// Return 1 for every unique halo meeting minimum size
|
||||||
|
class ValidHalo : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<IdType> index,
|
||||||
|
FieldIn<IdType> partPerHalo,
|
||||||
|
WholeArrayIn<IdType> haloId,
|
||||||
|
FieldOut<IdType> isValidHalo);
|
||||||
|
typedef _4 ExecutionSignature(_1, _2, _3);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id pmin;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
VTKM_EXEC_CONT
|
||||||
|
ValidHalo(vtkm::Id minimumHalo)
|
||||||
|
: pmin(minimumHalo)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename InPortalType>
|
||||||
|
VTKM_EXEC vtkm::Id operator()(const vtkm::Id& i,
|
||||||
|
const vtkm::Id& partPerHalo,
|
||||||
|
const InPortalType& haloId) const
|
||||||
|
{
|
||||||
|
// Boundary condition
|
||||||
|
if ((i == 0) && (partPerHalo >= pmin))
|
||||||
|
return 1;
|
||||||
|
// Return valid if it is the first particle in halo of correct size
|
||||||
|
if ((haloId.Get(i) != haloId.Get(i - 1)) && (partPerHalo >= pmin))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}; // ValidHalo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
27
vtkm/worklet/histogram/CMakeLists.txt
Normal file
27
vtkm/worklet/histogram/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
##============================================================================
|
||||||
|
## 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.
|
||||||
|
##
|
||||||
|
## Copyright 2014 Sandia Corporation.
|
||||||
|
## Copyright 2014 UT-Battelle, LLC.
|
||||||
|
## Copyright 2014 Los Alamos National Security.
|
||||||
|
##
|
||||||
|
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
## the U.S. Government retains certain rights in this software.
|
||||||
|
##
|
||||||
|
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
## Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
## this software.
|
||||||
|
##============================================================================
|
||||||
|
|
||||||
|
set(headers
|
||||||
|
ComputeNDEntropy.h
|
||||||
|
ComputeNDHistogram.h
|
||||||
|
MarginalizeNDHistogram.h
|
||||||
|
)
|
||||||
|
|
||||||
|
vtkm_declare_headers(${headers})
|
61
vtkm/worklet/histogram/ComputeNDEntropy.h
Normal file
61
vtkm/worklet/histogram/ComputeNDEntropy.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtk_m_worklet_ComputeNDEntropy_h
|
||||||
|
#define vtk_m_worklet_ComputeNDEntropy_h
|
||||||
|
|
||||||
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace histogram
|
||||||
|
{
|
||||||
|
// For each bin, calculate its information content (log2)
|
||||||
|
class SetBinInformationContent : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<> freq, FieldOut<> informationContent);
|
||||||
|
typedef void ExecutionSignature(_1, _2);
|
||||||
|
|
||||||
|
vtkm::Float64 FreqSum;
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
SetBinInformationContent(vtkm::Float64 _freqSum)
|
||||||
|
: FreqSum(_freqSum)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename FreqType>
|
||||||
|
VTKM_EXEC void operator()(const FreqType& freq, vtkm::Float64& informationContent) const
|
||||||
|
{
|
||||||
|
vtkm::Float64 p = ((vtkm::Float64)freq) / FreqSum;
|
||||||
|
if (p > 0)
|
||||||
|
informationContent = -1 * p * vtkm::Log2(p);
|
||||||
|
else
|
||||||
|
informationContent = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace vtkm::worklet
|
||||||
|
|
||||||
|
#endif // vtk_m_worklet_ComputeNDEntropy_h
|
157
vtkm/worklet/histogram/ComputeNDHistogram.h
Normal file
157
vtkm/worklet/histogram/ComputeNDHistogram.h
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtk_m_worklet_ComputeNDHistogram_h
|
||||||
|
#define vtk_m_worklet_ComputeNDHistogram_h
|
||||||
|
|
||||||
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace histogram
|
||||||
|
{
|
||||||
|
// GCC creates false positive warnings for signed/unsigned char* operations.
|
||||||
|
// This occurs because the values are implicitly casted up to int's for the
|
||||||
|
// operation, and than casted back down to char's when return.
|
||||||
|
// This causes a false positive warning, even when the values is within
|
||||||
|
// the value types range
|
||||||
|
#if defined(VTKM_GCC)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wconversion"
|
||||||
|
#endif // gcc
|
||||||
|
template <typename T>
|
||||||
|
T compute_delta(T fieldMinValue, T fieldMaxValue, vtkm::Id num)
|
||||||
|
{
|
||||||
|
typedef vtkm::VecTraits<T> VecType;
|
||||||
|
const T fieldRange = fieldMaxValue - fieldMinValue;
|
||||||
|
return fieldRange / static_cast<typename VecType::ComponentType>(num);
|
||||||
|
}
|
||||||
|
#if defined(VTKM_GCC)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif // gcc
|
||||||
|
|
||||||
|
// For each value set the bin it should be in
|
||||||
|
template <typename FieldType>
|
||||||
|
class SetHistogramBin : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<> value, FieldIn<> binIndexIn, FieldOut<> binIndexOut);
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id numberOfBins;
|
||||||
|
vtkm::Float64 minValue;
|
||||||
|
vtkm::Float64 delta;
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
SetHistogramBin(vtkm::Id numberOfBins0, vtkm::Float64 minValue0, vtkm::Float64 delta0)
|
||||||
|
: numberOfBins(numberOfBins0)
|
||||||
|
, minValue(minValue0)
|
||||||
|
, delta(delta0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
void operator()(const FieldType& value, const vtkm::Id& binIndexIn, vtkm::Id& binIndexOut) const
|
||||||
|
{
|
||||||
|
vtkm::Id localBinIdx = static_cast<vtkm::Id>((value - minValue) / delta);
|
||||||
|
if (localBinIdx < 0)
|
||||||
|
localBinIdx = 0;
|
||||||
|
else if (localBinIdx >= numberOfBins)
|
||||||
|
localBinIdx = numberOfBins - 1;
|
||||||
|
|
||||||
|
binIndexOut = binIndexIn * numberOfBins + localBinIdx;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename DeviceAdapter>
|
||||||
|
class ComputeBins
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VTKM_CONT
|
||||||
|
ComputeBins(vtkm::cont::ArrayHandle<vtkm::Id>& _bin1DIdx,
|
||||||
|
vtkm::Id& _numOfBins,
|
||||||
|
vtkm::Range& _minMax,
|
||||||
|
vtkm::Float64& _binDelta)
|
||||||
|
: Bin1DIdx(_bin1DIdx)
|
||||||
|
, NumOfBins(_numOfBins)
|
||||||
|
, MinMax(_minMax)
|
||||||
|
, BinDelta(_binDelta)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename Storage>
|
||||||
|
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle<T, Storage>& field) const
|
||||||
|
{
|
||||||
|
typedef vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> Algorithm;
|
||||||
|
|
||||||
|
const vtkm::Vec<T, 2> initValue(field.GetPortalConstControl().Get(0));
|
||||||
|
vtkm::Vec<T, 2> minMax = Algorithm::Reduce(field, initValue, vtkm::MinAndMax<T>());
|
||||||
|
MinMax.Min = static_cast<vtkm::Float64>(minMax[0]);
|
||||||
|
MinMax.Max = static_cast<vtkm::Float64>(minMax[1]);
|
||||||
|
BinDelta = compute_delta(MinMax.Min, MinMax.Max, NumOfBins);
|
||||||
|
|
||||||
|
SetHistogramBin<T> binWorklet(NumOfBins, MinMax.Min, BinDelta);
|
||||||
|
vtkm::worklet::DispatcherMapField<vtkm::worklet::histogram::SetHistogramBin<T>, DeviceAdapter>
|
||||||
|
setHistogramBinDispatcher(binWorklet);
|
||||||
|
setHistogramBinDispatcher.Invoke(field, Bin1DIdx, Bin1DIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& Bin1DIdx;
|
||||||
|
vtkm::Id& NumOfBins;
|
||||||
|
vtkm::Range& MinMax;
|
||||||
|
vtkm::Float64& BinDelta;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert N-dims bin index into 1D index
|
||||||
|
class ConvertHistBinToND : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<> bin1DIndexIn,
|
||||||
|
FieldOut<> bin1DIndexOut,
|
||||||
|
FieldOut<> oneVariableIndexOut);
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id numberOfBins;
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
ConvertHistBinToND(vtkm::Id numberOfBins0)
|
||||||
|
: numberOfBins(numberOfBins0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
void operator()(const vtkm::Id& bin1DIndexIn,
|
||||||
|
vtkm::Id& bin1DIndexOut,
|
||||||
|
vtkm::Id& oneVariableIndexOut) const
|
||||||
|
{
|
||||||
|
oneVariableIndexOut = bin1DIndexIn % numberOfBins;
|
||||||
|
bin1DIndexOut = (bin1DIndexIn - oneVariableIndexOut) / numberOfBins;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace vtkm::worklet
|
||||||
|
|
||||||
|
#endif // vtk_m_worklet_ComputeNDHistogram_h
|
88
vtkm/worklet/histogram/MarginalizeNDHistogram.h
Normal file
88
vtkm/worklet/histogram/MarginalizeNDHistogram.h
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#ifndef vtk_m_worklet_MarginalizeNDHistogram_h
|
||||||
|
#define vtk_m_worklet_MarginalizeNDHistogram_h
|
||||||
|
|
||||||
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
|
|
||||||
|
namespace vtkm
|
||||||
|
{
|
||||||
|
namespace worklet
|
||||||
|
{
|
||||||
|
namespace histogram
|
||||||
|
{
|
||||||
|
// Set freq of the entity, which does not meet the condition, to 0
|
||||||
|
template <class BinaryCompare>
|
||||||
|
class ConditionalFreq : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VTKM_CONT
|
||||||
|
ConditionalFreq(BinaryCompare _bop)
|
||||||
|
: bop(_bop)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
void setVar(vtkm::Id _var) { var = _var; }
|
||||||
|
|
||||||
|
BinaryCompare bop;
|
||||||
|
vtkm::Id var;
|
||||||
|
|
||||||
|
typedef void ControlSignature(FieldIn<>, FieldIn<>, FieldOut<>);
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3);
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
void operator()(const vtkm::Id& binIdIn, const vtkm::Id& freqIn, vtkm::Id& freqOut) const
|
||||||
|
{
|
||||||
|
if (bop(var, binIdIn))
|
||||||
|
freqOut = freqIn;
|
||||||
|
else
|
||||||
|
freqOut = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert multiple indices to 1D index
|
||||||
|
class To1DIndex : public vtkm::worklet::WorkletMapField
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef void ControlSignature(FieldIn<> bin, FieldIn<> binIndexIn, FieldOut<> binIndexOut);
|
||||||
|
typedef void ExecutionSignature(_1, _2, _3);
|
||||||
|
typedef _1 InputDomain;
|
||||||
|
|
||||||
|
vtkm::Id numberOfBins;
|
||||||
|
|
||||||
|
VTKM_CONT
|
||||||
|
To1DIndex(vtkm::Id numberOfBins0)
|
||||||
|
: numberOfBins(numberOfBins0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VTKM_EXEC
|
||||||
|
void operator()(const vtkm::Id& bin, const vtkm::Id& binIndexIn, vtkm::Id& binIndexOut) const
|
||||||
|
{
|
||||||
|
binIndexOut = binIndexIn * numberOfBins + bin;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace vtkm::worklet
|
||||||
|
|
||||||
|
#endif // vtk_m_worklet_MarginalizeNDHistogram_h
|
@ -23,9 +23,9 @@
|
|||||||
|
|
||||||
#include <vtkm/Types.h>
|
#include <vtkm/Types.h>
|
||||||
#include <vtkm/cont/ArrayHandle.h>
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleCast.h>
|
||||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||||
#include <vtkm/cont/DataSet.h>
|
#include <vtkm/cont/CellSetExplicit.h>
|
||||||
#include <vtkm/cont/Field.h>
|
|
||||||
#include <vtkm/exec/ExecutionObjectBase.h>
|
#include <vtkm/exec/ExecutionObjectBase.h>
|
||||||
|
|
||||||
#include <vtkm/worklet/DispatcherMapField.h>
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
@ -86,6 +86,7 @@ template <typename IntegratorType, typename FieldType, typename DeviceAdapterTag
|
|||||||
class ParticleAdvectionWorklet
|
class ParticleAdvectionWorklet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag> DeviceAlgorithm;
|
||||||
typedef vtkm::worklet::particleadvection::ParticleAdvectWorklet<IntegratorType,
|
typedef vtkm::worklet::particleadvection::ParticleAdvectWorklet<IntegratorType,
|
||||||
FieldType,
|
FieldType,
|
||||||
DeviceAdapterTag>
|
DeviceAdapterTag>
|
||||||
@ -130,7 +131,6 @@ private:
|
|||||||
|
|
||||||
IntegratorType integrator;
|
IntegratorType integrator;
|
||||||
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> seedArray;
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> seedArray;
|
||||||
vtkm::cont::DataSet ds;
|
|
||||||
vtkm::Id maxSteps;
|
vtkm::Id maxSteps;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -140,6 +140,7 @@ class StreamlineWorklet
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> FieldHandle;
|
typedef vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> FieldHandle;
|
||||||
|
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag> DeviceAlgorithm;
|
||||||
typedef typename FieldHandle::template ExecutionTypes<DeviceAdapterTag>::PortalConst
|
typedef typename FieldHandle::template ExecutionTypes<DeviceAdapterTag>::PortalConst
|
||||||
FieldPortalConstType;
|
FieldPortalConstType;
|
||||||
typedef vtkm::worklet::particleadvection::ParticleAdvectWorklet<IntegratorType,
|
typedef vtkm::worklet::particleadvection::ParticleAdvectWorklet<IntegratorType,
|
||||||
@ -152,144 +153,82 @@ public:
|
|||||||
template <typename PointStorage, typename FieldStorage>
|
template <typename PointStorage, typename FieldStorage>
|
||||||
void Run(const IntegratorType& it,
|
void Run(const IntegratorType& it,
|
||||||
const vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>, PointStorage>& pts,
|
const vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>, PointStorage>& pts,
|
||||||
const vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>, FieldStorage> fieldArray,
|
|
||||||
const vtkm::Id& nSteps,
|
const vtkm::Id& nSteps,
|
||||||
const vtkm::Id stepsPerRound = -1,
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>, PointStorage>& positions,
|
||||||
const vtkm::Id& particlesPerRound = -1)
|
vtkm::cont::CellSetExplicit<>& polyLines,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id, FieldStorage>& statusArray,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id, FieldStorage>& stepsTaken)
|
||||||
{
|
{
|
||||||
integrator = it;
|
integrator = it;
|
||||||
seedArray = pts;
|
seedArray = pts;
|
||||||
maxSteps = nSteps;
|
maxSteps = nSteps;
|
||||||
StepsPerRound = stepsPerRound;
|
|
||||||
ParticlesPerRound = particlesPerRound;
|
run(positions, polyLines, statusArray, stepsTaken);
|
||||||
field = fieldArray.PrepareForInput(DeviceAdapterTag());
|
|
||||||
run(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~StreamlineWorklet() {}
|
~StreamlineWorklet() {}
|
||||||
|
|
||||||
|
struct IsOne
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
VTKM_EXEC_CONT bool operator()(const T& x) const
|
||||||
|
{
|
||||||
|
return x == T(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void run(bool dumpOutput = false)
|
void run(vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>>& positions,
|
||||||
|
vtkm::cont::CellSetExplicit<>& polyLines,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& status,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& stepsTaken)
|
||||||
{
|
{
|
||||||
typedef typename vtkm::worklet::DispatcherMapField<ParticleAdvectWorkletType>
|
typedef typename vtkm::worklet::DispatcherMapField<ParticleAdvectWorkletType>
|
||||||
ParticleWorkletDispatchType;
|
ParticleWorkletDispatchType;
|
||||||
typedef vtkm::worklet::particleadvection::StateRecordingParticles<FieldType, DeviceAdapterTag>
|
typedef vtkm::worklet::particleadvection::StateRecordingParticles<FieldType, DeviceAdapterTag>
|
||||||
StreamlineType;
|
StreamlineType;
|
||||||
typedef vtkm::worklet::particleadvection::StateRecordingParticlesRound<FieldType,
|
|
||||||
DeviceAdapterTag>
|
|
||||||
StreamlineRoundType;
|
|
||||||
|
|
||||||
vtkm::Id totNumSeeds = static_cast<vtkm::Id>(seedArray.GetNumberOfValues());
|
vtkm::Id numSeeds = static_cast<vtkm::Id>(seedArray.GetNumberOfValues());
|
||||||
bool NeedParticleRounds = false;
|
|
||||||
if (!(ParticlesPerRound == -1 || ParticlesPerRound > totNumSeeds))
|
|
||||||
NeedParticleRounds = true;
|
|
||||||
|
|
||||||
ParticleAdvectWorkletType particleWorklet(integrator);
|
ParticleAdvectWorkletType particleWorklet(integrator);
|
||||||
ParticleWorkletDispatchType particleWorkletDispatch(particleWorklet);
|
ParticleWorkletDispatchType particleWorkletDispatch(particleWorklet);
|
||||||
|
|
||||||
//Brute force method, or rounds.
|
vtkm::cont::ArrayHandleIndex idxArray(numSeeds);
|
||||||
if (StepsPerRound == -1)
|
|
||||||
{
|
|
||||||
bool particlesDone = false;
|
|
||||||
vtkm::Id particleOffset = 0;
|
|
||||||
|
|
||||||
while (!particlesDone)
|
vtkm::cont::ArrayHandle<vtkm::Id> validPoint;
|
||||||
{
|
std::vector<vtkm::Id> vpa(static_cast<std::size_t>(numSeeds * maxSteps), 0);
|
||||||
vtkm::Id num = totNumSeeds - particleOffset;
|
validPoint = vtkm::cont::make_ArrayHandle(vpa);
|
||||||
if (num <= 0)
|
|
||||||
break;
|
|
||||||
if (NeedParticleRounds && num > ParticlesPerRound)
|
|
||||||
num = ParticlesPerRound;
|
|
||||||
|
|
||||||
std::vector<vtkm::Id> steps((size_t)num, 0), status((size_t)num, ParticleStatus::STATUS_OK);
|
//Compact history into positions.
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id> stepArray = vtkm::cont::make_ArrayHandle(&steps[0], num);
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> history;
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id> statusArray =
|
StreamlineType streamlines(seedArray, history, stepsTaken, status, validPoint, maxSteps);
|
||||||
vtkm::cont::make_ArrayHandle(&status[0], num);
|
|
||||||
vtkm::cont::ArrayHandleIndex idxArray(num);
|
|
||||||
|
|
||||||
StreamlineType streamlines(seedArray, stepArray, statusArray, maxSteps);
|
particleWorkletDispatch.Invoke(idxArray, streamlines);
|
||||||
particleWorkletDispatch.Invoke(idxArray, streamlines);
|
DeviceAlgorithm::CopyIf(history, validPoint, positions, IsOne());
|
||||||
|
|
||||||
if (dumpOutput)
|
//Create cells.
|
||||||
{
|
vtkm::cont::ArrayHandle<vtkm::Id> cellIndex;
|
||||||
for (vtkm::Id i = 0; i < num; i++)
|
vtkm::Id connectivityLen = DeviceAlgorithm::ScanExclusive(stepsTaken, cellIndex);
|
||||||
{
|
|
||||||
vtkm::Id ns = streamlines.GetStep(i);
|
|
||||||
for (vtkm::Id j = 0; j < ns; j++)
|
|
||||||
{
|
|
||||||
vtkm::Vec<FieldType, 3> p = streamlines.GetHistory(i, j);
|
|
||||||
std::cout << p[0] << " " << p[1] << " " << p[2] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
particleOffset += ParticlesPerRound;
|
vtkm::cont::ArrayHandleCounting<vtkm::Id> connCount(0, 1, connectivityLen);
|
||||||
if (!NeedParticleRounds)
|
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
|
||||||
particlesDone = true;
|
DeviceAlgorithm::Copy(connCount, connectivity);
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bool particlesDone = false;
|
|
||||||
vtkm::Id particleOffset = 0;
|
|
||||||
|
|
||||||
while (!particlesDone)
|
vtkm::cont::ArrayHandle<vtkm::UInt8> cellTypes;
|
||||||
{
|
cellTypes.Allocate(numSeeds);
|
||||||
vtkm::Id num = totNumSeeds - particleOffset;
|
vtkm::cont::ArrayHandleConstant<vtkm::UInt8> polyLineShape(vtkm::CELL_SHAPE_LINE, numSeeds);
|
||||||
if (num <= 0)
|
DeviceAlgorithm::Copy(polyLineShape, cellTypes);
|
||||||
break;
|
|
||||||
if (NeedParticleRounds && num > ParticlesPerRound)
|
|
||||||
num = ParticlesPerRound;
|
|
||||||
|
|
||||||
std::vector<vtkm::Id> steps((size_t)num, 0), status((size_t)num, ParticleStatus::STATUS_OK);
|
vtkm::cont::ArrayHandle<vtkm::IdComponent> cellCounts;
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id> stepArray = vtkm::cont::make_ArrayHandle(&steps[0], num);
|
DeviceAlgorithm::Copy(vtkm::cont::make_ArrayHandleCast(stepsTaken, vtkm::IdComponent()),
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id> statusArray =
|
cellCounts);
|
||||||
vtkm::cont::make_ArrayHandle(&status[0], num);
|
|
||||||
vtkm::cont::ArrayHandleIndex idxArray(num);
|
|
||||||
|
|
||||||
vtkm::Id numSteps = 0, stepOffset = 0;
|
polyLines.Fill(positions.GetNumberOfValues(), cellTypes, cellCounts, connectivity);
|
||||||
bool stepsDone = false;
|
|
||||||
while (!stepsDone)
|
|
||||||
{
|
|
||||||
numSteps += StepsPerRound;
|
|
||||||
if (numSteps >= maxSteps)
|
|
||||||
{
|
|
||||||
numSteps = maxSteps;
|
|
||||||
stepsDone = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
StreamlineRoundType streamlines(
|
|
||||||
seedArray, stepArray, statusArray, numSteps, StepsPerRound, stepOffset, maxSteps);
|
|
||||||
particleWorkletDispatch.Invoke(idxArray, streamlines);
|
|
||||||
|
|
||||||
auto historyPortal = streamlines.HistoryArray.GetPortalConstControl();
|
|
||||||
if (dumpOutput)
|
|
||||||
{
|
|
||||||
for (vtkm::Id i = 0; i < num; i++)
|
|
||||||
{
|
|
||||||
vtkm::Id ns = streamlines.GetStep(i);
|
|
||||||
for (vtkm::Id j = stepOffset; j < ns; j++)
|
|
||||||
{
|
|
||||||
vtkm::Vec<FieldType, 3> p = historyPortal.Get(i * StepsPerRound + (j - stepOffset));
|
|
||||||
std::cout << p[0] << " " << p[1] << " " << p[2] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stepOffset += StepsPerRound;
|
|
||||||
}
|
|
||||||
particleOffset += ParticlesPerRound;
|
|
||||||
if (!NeedParticleRounds)
|
|
||||||
particlesDone = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IntegratorType integrator;
|
IntegratorType integrator;
|
||||||
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> seedArray;
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> seedArray;
|
||||||
vtkm::cont::DataSet ds;
|
|
||||||
vtkm::Id maxSteps;
|
vtkm::Id maxSteps;
|
||||||
vtkm::Id StepsPerRound, ParticlesPerRound;
|
|
||||||
FieldPortalConstType field;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,6 +211,8 @@ private:
|
|||||||
typedef
|
typedef
|
||||||
typename vtkm::cont::ArrayHandle<vtkm::Id>::template ExecutionTypes<DeviceAdapterTag>::Portal
|
typename vtkm::cont::ArrayHandle<vtkm::Id>::template ExecutionTypes<DeviceAdapterTag>::Portal
|
||||||
IdPortal;
|
IdPortal;
|
||||||
|
typedef typename vtkm::cont::ArrayHandle<vtkm::IdComponent>::template ExecutionTypes<
|
||||||
|
DeviceAdapterTag>::Portal IdComponentPortal;
|
||||||
typedef typename vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>::template ExecutionTypes<
|
typedef typename vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>::template ExecutionTypes<
|
||||||
DeviceAdapterTag>::Portal PosPortal;
|
DeviceAdapterTag>::Portal PosPortal;
|
||||||
|
|
||||||
@ -218,16 +220,18 @@ public:
|
|||||||
VTKM_EXEC_CONT
|
VTKM_EXEC_CONT
|
||||||
StateRecordingParticles(const StateRecordingParticles& s)
|
StateRecordingParticles(const StateRecordingParticles& s)
|
||||||
: Particles<T, DeviceAdapterTag>(s.Pos, s.Steps, s.Status, s.MaxSteps)
|
: Particles<T, DeviceAdapterTag>(s.Pos, s.Steps, s.Status, s.MaxSteps)
|
||||||
, HistSize(s.HistSize)
|
, ValidPoint(s.ValidPoint)
|
||||||
, History(s.History)
|
, History(s.History)
|
||||||
|
, HistSize(s.HistSize)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
VTKM_EXEC_CONT
|
||||||
StateRecordingParticles()
|
StateRecordingParticles()
|
||||||
: Particles<T, DeviceAdapterTag>()
|
: Particles<T, DeviceAdapterTag>()
|
||||||
, HistSize(-1)
|
, ValidPoint()
|
||||||
, History()
|
, History()
|
||||||
|
, HistSize(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,32 +239,39 @@ public:
|
|||||||
StateRecordingParticles(const PosPortal& _pos,
|
StateRecordingParticles(const PosPortal& _pos,
|
||||||
const IdPortal& _steps,
|
const IdPortal& _steps,
|
||||||
const IdPortal& _status,
|
const IdPortal& _status,
|
||||||
|
const IdPortal& _validPoint,
|
||||||
const vtkm::Id& _maxSteps)
|
const vtkm::Id& _maxSteps)
|
||||||
: Particles<T, DeviceAdapterTag>(_pos, _steps, _status, _maxSteps)
|
: Particles<T, DeviceAdapterTag>(_pos, _steps, _status, _maxSteps)
|
||||||
, HistSize()
|
, ValidPoint(_validPoint)
|
||||||
, History()
|
, History()
|
||||||
|
, HistSize()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
VTKM_EXEC_CONT
|
||||||
StateRecordingParticles(vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& posArray,
|
StateRecordingParticles(vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& posArray,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& historyArray,
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id>& stepsArray,
|
vtkm::cont::ArrayHandle<vtkm::Id>& stepsArray,
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id>& statusArray,
|
vtkm::cont::ArrayHandle<vtkm::Id>& statusArray,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& validPointArray,
|
||||||
const vtkm::Id& _maxSteps)
|
const vtkm::Id& _maxSteps)
|
||||||
{
|
{
|
||||||
this->Pos = posArray.PrepareForInPlace(DeviceAdapterTag());
|
this->Pos = posArray.PrepareForInPlace(DeviceAdapterTag());
|
||||||
this->Steps = stepsArray.PrepareForInPlace(DeviceAdapterTag());
|
this->Steps = stepsArray.PrepareForInPlace(DeviceAdapterTag());
|
||||||
this->Status = statusArray.PrepareForInPlace(DeviceAdapterTag());
|
this->Status = statusArray.PrepareForInPlace(DeviceAdapterTag());
|
||||||
|
this->ValidPoint = validPointArray.PrepareForInPlace(DeviceAdapterTag());
|
||||||
this->MaxSteps = _maxSteps;
|
this->MaxSteps = _maxSteps;
|
||||||
HistSize = _maxSteps;
|
HistSize = _maxSteps;
|
||||||
NumPos = posArray.GetNumberOfValues();
|
vtkm::Id NumPos = posArray.GetNumberOfValues();
|
||||||
History = HistoryArray.PrepareForOutput(NumPos * HistSize, DeviceAdapterTag());
|
History = historyArray.PrepareForOutput(NumPos * HistSize, DeviceAdapterTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
VTKM_EXEC_CONT
|
||||||
StateRecordingParticles(vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& posArray,
|
StateRecordingParticles(vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& posArray,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& historyArray,
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id>& stepsArray,
|
vtkm::cont::ArrayHandle<vtkm::Id>& stepsArray,
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id>& statusArray,
|
vtkm::cont::ArrayHandle<vtkm::Id>& statusArray,
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id>& validPointArray,
|
||||||
const vtkm::Id& _maxSteps,
|
const vtkm::Id& _maxSteps,
|
||||||
vtkm::Id& _histSize)
|
vtkm::Id& _histSize)
|
||||||
: HistSize(_histSize)
|
: HistSize(_histSize)
|
||||||
@ -268,10 +279,11 @@ public:
|
|||||||
this->Pos = posArray.PrepareForInPlace(DeviceAdapterTag());
|
this->Pos = posArray.PrepareForInPlace(DeviceAdapterTag());
|
||||||
this->Steps = stepsArray.PrepareForInPlace(DeviceAdapterTag());
|
this->Steps = stepsArray.PrepareForInPlace(DeviceAdapterTag());
|
||||||
this->Status = statusArray.PrepareForInPlace(DeviceAdapterTag());
|
this->Status = statusArray.PrepareForInPlace(DeviceAdapterTag());
|
||||||
|
this->ValidPoint = validPointArray.PrepareForInPlace(DeviceAdapterTag());
|
||||||
this->MaxSteps = _maxSteps;
|
this->MaxSteps = _maxSteps;
|
||||||
HistSize = _histSize;
|
HistSize = _histSize;
|
||||||
NumPos = posArray.GetNumberOfValues();
|
vtkm::Id NumPos = posArray.GetNumberOfValues();
|
||||||
History = HistoryArray.PrepareForOutput(NumPos * HistSize, DeviceAdapterTag());
|
History = historyArray.PrepareForOutput(NumPos * HistSize, DeviceAdapterTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
VTKM_EXEC_CONT
|
||||||
@ -281,7 +293,8 @@ public:
|
|||||||
return;
|
return;
|
||||||
vtkm::Id nSteps = this->Steps.Get(idx);
|
vtkm::Id nSteps = this->Steps.Get(idx);
|
||||||
vtkm::Id loc = idx * HistSize + nSteps;
|
vtkm::Id loc = idx * HistSize + nSteps;
|
||||||
History.Set(loc, pt);
|
this->History.Set(loc, pt);
|
||||||
|
this->ValidPoint.Set(loc, 1);
|
||||||
nSteps = nSteps + 1;
|
nSteps = nSteps + 1;
|
||||||
this->Steps.Set(idx, nSteps);
|
this->Steps.Set(idx, nSteps);
|
||||||
if (nSteps == this->MaxSteps)
|
if (nSteps == this->MaxSteps)
|
||||||
@ -297,122 +310,14 @@ public:
|
|||||||
bool Done(const vtkm::Id& idx) { return !this->Integrateable(idx); }
|
bool Done(const vtkm::Id& idx) { return !this->Integrateable(idx); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vtkm::Id NumPos, HistSize;
|
IdPortal ValidPoint;
|
||||||
PosPortal History;
|
PosPortal History;
|
||||||
|
vtkm::Id HistSize;
|
||||||
public:
|
|
||||||
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> HistoryArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T, typename DeviceAdapterTag>
|
|
||||||
class StateRecordingParticlesRound : public Particles<T, DeviceAdapterTag>
|
|
||||||
{
|
|
||||||
|
|
||||||
private:
|
|
||||||
typedef
|
|
||||||
typename vtkm::cont::ArrayHandle<vtkm::Id>::template ExecutionTypes<DeviceAdapterTag>::Portal
|
|
||||||
IdPortal;
|
|
||||||
typedef typename vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>::template ExecutionTypes<
|
|
||||||
DeviceAdapterTag>::Portal PosPortal;
|
|
||||||
|
|
||||||
public:
|
|
||||||
VTKM_EXEC_CONT
|
|
||||||
StateRecordingParticlesRound(const StateRecordingParticlesRound& s)
|
|
||||||
: Particles<T, DeviceAdapterTag>(s.Pos, s.Steps, s.Status, s.MaxSteps)
|
|
||||||
, NumPos(s.NumPos)
|
|
||||||
, HistSize(s.HistSize)
|
|
||||||
, Offset(s.Offset)
|
|
||||||
, TotalMaxSteps(s.TotalMaxSteps)
|
|
||||||
, History(s.History)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
|
||||||
StateRecordingParticlesRound()
|
|
||||||
: Particles<T, DeviceAdapterTag>()
|
|
||||||
, HistSize(-1)
|
|
||||||
, Offset(0)
|
|
||||||
, TotalMaxSteps(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
|
||||||
StateRecordingParticlesRound(const PosPortal& _pos,
|
|
||||||
const IdPortal& _steps,
|
|
||||||
const IdPortal& _status,
|
|
||||||
const vtkm::Id& _maxSteps,
|
|
||||||
const vtkm::Id& _histSize,
|
|
||||||
const vtkm::Id& _offset,
|
|
||||||
const vtkm::Id& _totalMaxSteps)
|
|
||||||
: Particles<T, DeviceAdapterTag>(_pos, _steps, _status, _maxSteps)
|
|
||||||
, HistSize(_histSize)
|
|
||||||
, Offset(_offset)
|
|
||||||
, TotalMaxSteps(_totalMaxSteps)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
|
||||||
StateRecordingParticlesRound(vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>>& posArray,
|
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id>& stepsArray,
|
|
||||||
vtkm::cont::ArrayHandle<vtkm::Id>& statusArray,
|
|
||||||
const vtkm::Id& _maxSteps,
|
|
||||||
const vtkm::Id& _histSize,
|
|
||||||
const vtkm::Id& _offset,
|
|
||||||
const vtkm::Id& _totalMaxSteps)
|
|
||||||
: HistSize(_histSize)
|
|
||||||
, Offset(_offset)
|
|
||||||
, TotalMaxSteps(_totalMaxSteps)
|
|
||||||
{
|
|
||||||
this->Pos = posArray.PrepareForInPlace(DeviceAdapterTag());
|
|
||||||
this->Steps = stepsArray.PrepareForInPlace(DeviceAdapterTag());
|
|
||||||
this->Status = statusArray.PrepareForInPlace(DeviceAdapterTag());
|
|
||||||
this->MaxSteps = _maxSteps;
|
|
||||||
NumPos = posArray.GetNumberOfValues();
|
|
||||||
History = HistoryArray.PrepareForOutput(NumPos * HistSize, DeviceAdapterTag());
|
|
||||||
}
|
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
|
||||||
void TakeStep(const vtkm::Id& idx, const vtkm::Vec<T, 3>& pt, ParticleStatus status)
|
|
||||||
{
|
|
||||||
if (status != ParticleStatus::STATUS_OK)
|
|
||||||
return;
|
|
||||||
vtkm::Id nSteps = this->Steps.Get(idx);
|
|
||||||
vtkm::Id loc = idx * HistSize + (nSteps - Offset);
|
|
||||||
History.Set(loc, pt);
|
|
||||||
nSteps = nSteps + 1;
|
|
||||||
this->Steps.Set(idx, nSteps);
|
|
||||||
if (nSteps == TotalMaxSteps)
|
|
||||||
this->SetTerminated(idx);
|
|
||||||
this->Pos.Set(idx, pt);
|
|
||||||
}
|
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
|
||||||
bool Done(const vtkm::Id& idx)
|
|
||||||
{
|
|
||||||
vtkm::Id nSteps = this->Steps.Get(idx);
|
|
||||||
return (nSteps - Offset == HistSize) || !this->Integrateable(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
VTKM_EXEC_CONT
|
|
||||||
vtkm::Vec<T, 3> GetHistory(const vtkm::Id& idx, const vtkm::Id& step) const
|
|
||||||
{
|
|
||||||
return History.Get(idx * HistSize + step);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
vtkm::Id NumPos, HistSize, Offset, TotalMaxSteps;
|
|
||||||
PosPortal History;
|
|
||||||
|
|
||||||
public:
|
|
||||||
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>> HistoryArray;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace particleadvection
|
} //namespace particleadvection
|
||||||
} //namespace worklet
|
} //namespace worklet
|
||||||
} //namespace vtkm
|
} //namespace vtkm
|
||||||
|
|
||||||
|
|
||||||
#endif // vtk_m_worklet_particleadvection_Particles_h
|
#endif // vtk_m_worklet_particleadvection_Particles_h
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
@ -25,6 +25,7 @@ set(unit_tests
|
|||||||
UnitTestCellGradient.cxx
|
UnitTestCellGradient.cxx
|
||||||
UnitTestClipping.cxx
|
UnitTestClipping.cxx
|
||||||
UnitTestContourTreeUniform.cxx
|
UnitTestContourTreeUniform.cxx
|
||||||
|
UnitTestCosmoTools.cxx
|
||||||
UnitTestExternalFaces.cxx
|
UnitTestExternalFaces.cxx
|
||||||
UnitTestExtractGeometry.cxx
|
UnitTestExtractGeometry.cxx
|
||||||
UnitTestExtractPoints.cxx
|
UnitTestExtractPoints.cxx
|
||||||
@ -37,6 +38,9 @@ set(unit_tests
|
|||||||
UnitTestMarchingCubes.cxx
|
UnitTestMarchingCubes.cxx
|
||||||
UnitTestMask.cxx
|
UnitTestMask.cxx
|
||||||
UnitTestMaskPoints.cxx
|
UnitTestMaskPoints.cxx
|
||||||
|
UnitTestNDimsEntropy.cxx
|
||||||
|
UnitTestNDimsHistogram.cxx
|
||||||
|
UnitTestNDimsHistMarginalization.cxx
|
||||||
UnitTestParticleAdvection.cxx
|
UnitTestParticleAdvection.cxx
|
||||||
UnitTestPointElevation.cxx
|
UnitTestPointElevation.cxx
|
||||||
UnitTestPointGradient.cxx
|
UnitTestPointGradient.cxx
|
||||||
|
356
vtkm/worklet/testing/UnitTestCosmoTools.cxx
Normal file
356
vtkm/worklet/testing/UnitTestCosmoTools.cxx
Normal file
@ -0,0 +1,356 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vtkm/worklet/CosmoTools.h>
|
||||||
|
#include <vtkm/worklet/DispatcherMapField.h>
|
||||||
|
|
||||||
|
#include <vtkm/Pair.h>
|
||||||
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleIndex.h>
|
||||||
|
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
|
||||||
|
#include <vtkm/cont/CellSetExplicit.h>
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/cont/DataSetBuilderExplicit.h>
|
||||||
|
#include <vtkm/cont/DataSetFieldAdd.h>
|
||||||
|
#include <vtkm/cont/testing/Testing.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
template <typename T, typename Storage>
|
||||||
|
bool TestArrayHandle(const vtkm::cont::ArrayHandle<T, Storage>& ah,
|
||||||
|
const vtkm::cont::ArrayHandle<T, Storage>& expected,
|
||||||
|
vtkm::Id size)
|
||||||
|
{
|
||||||
|
if (size != ah.GetNumberOfValues())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (vtkm::Id i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
|
if (ah.GetPortalConstControl().Get(i) != expected.GetPortalConstControl().Get(i))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test 2D explicit dataset of particles
|
||||||
|
//
|
||||||
|
vtkm::cont::DataSet MakeCosmo_2DDataSet_0()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet dataSet;
|
||||||
|
vtkm::cont::DataSetBuilderExplicit dsb;
|
||||||
|
vtkm::cont::DataSetFieldAdd dsf;
|
||||||
|
|
||||||
|
// Coordinates
|
||||||
|
const int nVerts = 17;
|
||||||
|
const int nCells = 17;
|
||||||
|
using CoordType = vtkm::Vec<vtkm::Float32, 3>;
|
||||||
|
std::vector<CoordType> coords(nVerts);
|
||||||
|
|
||||||
|
coords[0] = CoordType(1, 1, 0);
|
||||||
|
coords[1] = CoordType(1, 2, 0);
|
||||||
|
coords[2] = CoordType(2, 6, 0);
|
||||||
|
coords[3] = CoordType(1, 3, 0);
|
||||||
|
coords[4] = CoordType(3, 5, 0);
|
||||||
|
coords[5] = CoordType(1, 4, 0);
|
||||||
|
coords[6] = CoordType(1, 5, 0);
|
||||||
|
coords[7] = CoordType(3, 6, 0);
|
||||||
|
coords[8] = CoordType(2, 3, 0);
|
||||||
|
coords[9] = CoordType(3, 3, 0);
|
||||||
|
coords[10] = CoordType(4, 3, 0);
|
||||||
|
coords[11] = CoordType(3, 7, 0);
|
||||||
|
coords[12] = CoordType(5, 2, 0);
|
||||||
|
coords[13] = CoordType(5, 3, 0);
|
||||||
|
coords[14] = CoordType(4, 6, 0);
|
||||||
|
coords[15] = CoordType(5, 4, 0);
|
||||||
|
coords[16] = CoordType(6, 3, 0);
|
||||||
|
|
||||||
|
// Connectivity
|
||||||
|
std::vector<vtkm::UInt8> shapes;
|
||||||
|
std::vector<vtkm::IdComponent> numindices;
|
||||||
|
std::vector<vtkm::Id> conn;
|
||||||
|
|
||||||
|
for (vtkm::Id pt = 0; pt < nCells; pt++)
|
||||||
|
{
|
||||||
|
shapes.push_back(vtkm::CELL_SHAPE_VERTEX);
|
||||||
|
numindices.push_back(1);
|
||||||
|
conn.push_back(pt);
|
||||||
|
}
|
||||||
|
dataSet = dsb.Create(coords, shapes, numindices, conn, "coordinates", "cells");
|
||||||
|
|
||||||
|
// Field data
|
||||||
|
vtkm::Float32 xLocation[nCells] = { 1, 1, 2, 1, 3, 1, 1, 3, 2, 3, 4, 3, 5, 5, 4, 5, 6 };
|
||||||
|
vtkm::Float32 yLocation[nCells] = { 1, 2, 6, 3, 5, 4, 5, 6, 3, 3, 3, 7, 2, 3, 6, 4, 3 };
|
||||||
|
vtkm::Float32 zLocation[nCells] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
vtkm::Id haloId[nCells] = { 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0, 0 };
|
||||||
|
vtkm::Id mbp[nCells] = { 8, 8, 7, 8, 7, 8, 8, 7, 8, 8, 8, 7, 8, 8, 7, 8, 8 };
|
||||||
|
|
||||||
|
dsf.AddCellField(dataSet, "xLocation", xLocation, nCells);
|
||||||
|
dsf.AddCellField(dataSet, "yLocation", yLocation, nCells);
|
||||||
|
dsf.AddCellField(dataSet, "zLocation", zLocation, nCells);
|
||||||
|
dsf.AddCellField(dataSet, "haloId", haloId, nCells);
|
||||||
|
dsf.AddCellField(dataSet, "mbp", mbp, nCells);
|
||||||
|
return dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Test 3D explicit dataset of particles
|
||||||
|
//
|
||||||
|
vtkm::cont::DataSet MakeCosmo_3DDataSet_0()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet dataSet;
|
||||||
|
vtkm::cont::DataSetBuilderExplicit dsb;
|
||||||
|
vtkm::cont::DataSetFieldAdd dsf;
|
||||||
|
|
||||||
|
// Coordinates
|
||||||
|
const int nVerts = 14;
|
||||||
|
const int nCells = 14;
|
||||||
|
typedef vtkm::Vec<vtkm::Float32, 3> CoordType;
|
||||||
|
std::vector<CoordType> coords(nVerts);
|
||||||
|
|
||||||
|
coords[0] = CoordType(20.8125f, 10.8864f, 0.309784f);
|
||||||
|
coords[1] = CoordType(29.6871f, 15.4445f, 1.55953f);
|
||||||
|
coords[2] = CoordType(29.724f, 15.4766f, 1.51077f);
|
||||||
|
coords[3] = CoordType(29.6783f, 15.4766f, 1.5324f);
|
||||||
|
coords[4] = CoordType(29.7051f, 15.5052f, 1.52008f);
|
||||||
|
coords[5] = CoordType(20.8172f, 10.8534f, 0.23461f);
|
||||||
|
coords[6] = CoordType(20.8665f, 10.8679f, 0.254398f);
|
||||||
|
coords[7] = CoordType(20.8271f, 10.8677f, 0.234255f);
|
||||||
|
coords[8] = CoordType(20.8592f, 10.9505f, 0.248716f);
|
||||||
|
coords[9] = CoordType(20.819f, 10.8949f, 0.304834f);
|
||||||
|
coords[10] = CoordType(29.708f, 15.4251f, 1.53951f);
|
||||||
|
coords[11] = CoordType(20.8829f, 10.9144f, 0.261517f);
|
||||||
|
coords[12] = CoordType(20.8379f, 10.877f, 0.27677f);
|
||||||
|
coords[13] = CoordType(29.7278f, 15.5267f, 1.50798f);
|
||||||
|
|
||||||
|
// Connectivity
|
||||||
|
std::vector<vtkm::UInt8> shapes;
|
||||||
|
std::vector<vtkm::IdComponent> numindices;
|
||||||
|
std::vector<vtkm::Id> conn;
|
||||||
|
|
||||||
|
for (vtkm::Id pt = 0; pt < nCells; pt++)
|
||||||
|
{
|
||||||
|
shapes.push_back(vtkm::CELL_SHAPE_VERTEX);
|
||||||
|
numindices.push_back(1);
|
||||||
|
conn.push_back(pt);
|
||||||
|
}
|
||||||
|
dataSet = dsb.Create(coords, shapes, numindices, conn, "coordinates", "cells");
|
||||||
|
|
||||||
|
// Field data
|
||||||
|
vtkm::Float32 xLocation[nCells] = { 20.8125f, 29.6871f, 29.724f, 29.6783f, 29.7051f,
|
||||||
|
20.8172f, 20.8665f, 20.8271f, 20.8592f, 20.819f,
|
||||||
|
29.708f, 20.8829f, 20.8379f, 29.7278f };
|
||||||
|
vtkm::Float32 yLocation[nCells] = { 10.8864f, 15.4445f, 15.4766f, 15.4766f, 15.5052f,
|
||||||
|
10.8534f, 10.8679f, 10.8677f, 10.9505f, 10.8949f,
|
||||||
|
15.4251f, 10.9144f, 10.877f, 15.5267f };
|
||||||
|
vtkm::Float32 zLocation[nCells] = { 0.309784f, 1.55953f, 1.51077f, 1.5324f, 1.52008f,
|
||||||
|
0.23461f, 0.254398f, 0.234255f, 0.248716f, 0.304834f,
|
||||||
|
1.53951f, 0.261517f, 0.27677f, 1.50798f };
|
||||||
|
|
||||||
|
vtkm::Id haloId[nCells] = { 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1 };
|
||||||
|
vtkm::Id mbp[nCells] = { 9, 4, 4, 4, 4, 9, 9, 9, 9, 9, 4, 9, 9, 4 };
|
||||||
|
|
||||||
|
dsf.AddCellField(dataSet, "xLocation", xLocation, nCells);
|
||||||
|
dsf.AddCellField(dataSet, "yLocation", yLocation, nCells);
|
||||||
|
dsf.AddCellField(dataSet, "zLocation", zLocation, nCells);
|
||||||
|
dsf.AddCellField(dataSet, "haloId", haloId, nCells);
|
||||||
|
dsf.AddCellField(dataSet, "mbp", mbp, nCells);
|
||||||
|
return dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Create an explicit 2D particle set and find halos and minimum potential particle of each halo
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void TestCosmo_2DHaloFind()
|
||||||
|
{
|
||||||
|
std::cout << "Testing Halo Finder 2D" << std::endl;
|
||||||
|
|
||||||
|
// Create the input 2D particle dataset
|
||||||
|
vtkm::cont::DataSet dataSet = MakeCosmo_2DDataSet_0();
|
||||||
|
vtkm::Id nCells = dataSet.GetCellSet(0).GetNumberOfCells();
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> haloIdArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> mbpArray;
|
||||||
|
|
||||||
|
dataSet.GetField("xLocation").GetData().CopyTo(xLocArray);
|
||||||
|
dataSet.GetField("yLocation").GetData().CopyTo(yLocArray);
|
||||||
|
dataSet.GetField("zLocation").GetData().CopyTo(zLocArray);
|
||||||
|
dataSet.GetField("haloId").GetData().CopyTo(haloIdArray);
|
||||||
|
dataSet.GetField("mbp").GetData().CopyTo(mbpArray);
|
||||||
|
|
||||||
|
// Output haloId, MBP, potential per particle
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> resultHaloId;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> resultMBP;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> resultPot;
|
||||||
|
|
||||||
|
// Create the worklet and run it
|
||||||
|
vtkm::Id minHaloSize = 3;
|
||||||
|
vtkm::Float32 linkingLength = 1.0f;
|
||||||
|
vtkm::Float32 particleMass = 1.0f;
|
||||||
|
|
||||||
|
vtkm::worklet::CosmoTools cosmoTools;
|
||||||
|
cosmoTools.RunHaloFinder(xLocArray,
|
||||||
|
yLocArray,
|
||||||
|
zLocArray,
|
||||||
|
nCells,
|
||||||
|
particleMass,
|
||||||
|
minHaloSize,
|
||||||
|
linkingLength,
|
||||||
|
resultHaloId,
|
||||||
|
resultMBP,
|
||||||
|
resultPot,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
VTKM_TEST_ASSERT(TestArrayHandle(haloIdArray, resultHaloId, nCells), "Incorrect Halo Ids");
|
||||||
|
VTKM_TEST_ASSERT(TestArrayHandle(mbpArray, resultMBP, nCells), "Incorrect MBP Ids");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Create an explicit 3D particle set and find halos and minimum potential particle of each halo
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void TestCosmo_3DHaloFind()
|
||||||
|
{
|
||||||
|
std::cout << "Testing Halo Finder 3D" << std::endl;
|
||||||
|
|
||||||
|
// Create the input 3D particle dataset
|
||||||
|
vtkm::cont::DataSet dataSet = MakeCosmo_3DDataSet_0();
|
||||||
|
vtkm::Id nCells = dataSet.GetCellSet(0).GetNumberOfCells();
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> haloIdArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> mbpArray;
|
||||||
|
|
||||||
|
dataSet.GetField("xLocation").GetData().CopyTo(xLocArray);
|
||||||
|
dataSet.GetField("yLocation").GetData().CopyTo(yLocArray);
|
||||||
|
dataSet.GetField("zLocation").GetData().CopyTo(zLocArray);
|
||||||
|
dataSet.GetField("haloId").GetData().CopyTo(haloIdArray);
|
||||||
|
dataSet.GetField("mbp").GetData().CopyTo(mbpArray);
|
||||||
|
|
||||||
|
// Output haloId, MBP, potential per particle
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> resultHaloId;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> resultMBP;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> resultPot;
|
||||||
|
|
||||||
|
// Create the worklet and run it
|
||||||
|
vtkm::Id minHaloSize = 3;
|
||||||
|
vtkm::Float32 linkingLength = 0.2f;
|
||||||
|
vtkm::Float32 particleMass = 1.0f;
|
||||||
|
|
||||||
|
vtkm::worklet::CosmoTools cosmoTools;
|
||||||
|
cosmoTools.RunHaloFinder(xLocArray,
|
||||||
|
yLocArray,
|
||||||
|
zLocArray,
|
||||||
|
nCells,
|
||||||
|
particleMass,
|
||||||
|
minHaloSize,
|
||||||
|
linkingLength,
|
||||||
|
resultHaloId,
|
||||||
|
resultMBP,
|
||||||
|
resultPot,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
VTKM_TEST_ASSERT(TestArrayHandle(haloIdArray, resultHaloId, nCells), "Incorrect Halo Ids");
|
||||||
|
VTKM_TEST_ASSERT(TestArrayHandle(mbpArray, resultMBP, nCells), "Incorrect MBP Ids");
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Create an explicit 3D particle set and find halos and minimum potential particle of each halo
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void TestCosmo_3DCenterFind()
|
||||||
|
{
|
||||||
|
std::cout << "Testing Center Finder 3D" << std::endl;
|
||||||
|
|
||||||
|
// Create the input 3D particle dataset
|
||||||
|
vtkm::cont::DataSet dataSet = MakeCosmo_3DDataSet_0();
|
||||||
|
vtkm::Id nCells = dataSet.GetCellSet(0).GetNumberOfCells();
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> xLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> yLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float32> zLocArray;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> haloIdArray;
|
||||||
|
dataSet.GetField("xLocation").GetData().CopyTo(xLocArray);
|
||||||
|
dataSet.GetField("yLocation").GetData().CopyTo(yLocArray);
|
||||||
|
dataSet.GetField("zLocation").GetData().CopyTo(zLocArray);
|
||||||
|
|
||||||
|
// Output haloId MBP particleId pairs array
|
||||||
|
vtkm::Pair<vtkm::Id, vtkm::Float32> nxnResult;
|
||||||
|
vtkm::Pair<vtkm::Id, vtkm::Float32> mxnResult;
|
||||||
|
|
||||||
|
// Create the worklet and run it
|
||||||
|
vtkm::Float32 particleMass = 1.0f;
|
||||||
|
|
||||||
|
vtkm::worklet::CosmoTools cosmoTools;
|
||||||
|
cosmoTools.RunMBPCenterFinderNxN(xLocArray,
|
||||||
|
yLocArray,
|
||||||
|
zLocArray,
|
||||||
|
nCells,
|
||||||
|
particleMass,
|
||||||
|
nxnResult,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
cosmoTools.RunMBPCenterFinderMxN(xLocArray,
|
||||||
|
yLocArray,
|
||||||
|
zLocArray,
|
||||||
|
nCells,
|
||||||
|
particleMass,
|
||||||
|
mxnResult,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
VTKM_TEST_ASSERT(test_equal(nxnResult.first, mxnResult.first),
|
||||||
|
"NxN and MxN got different results");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCosmoTools()
|
||||||
|
{
|
||||||
|
TestCosmo_2DHaloFind();
|
||||||
|
TestCosmo_3DHaloFind();
|
||||||
|
|
||||||
|
TestCosmo_3DCenterFind();
|
||||||
|
}
|
||||||
|
|
||||||
|
int UnitTestCosmoTools(int, char* [])
|
||||||
|
{
|
||||||
|
return vtkm::cont::testing::Testing::Run(TestCosmoTools);
|
||||||
|
}
|
213
vtkm/worklet/testing/UnitTestNDimsEntropy.cxx
Normal file
213
vtkm/worklet/testing/UnitTestNDimsEntropy.cxx
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vtkm/worklet/NDimsEntropy.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/cont/testing/Testing.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// Make testing dataset with three fields(variables), each one has 1000 values
|
||||||
|
vtkm::cont::DataSet MakeTestDataSet()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet dataSet;
|
||||||
|
|
||||||
|
const int xVerts = 20;
|
||||||
|
const int yVerts = 50;
|
||||||
|
const int nVerts = xVerts * yVerts;
|
||||||
|
|
||||||
|
vtkm::Float32 fieldA[nVerts] = {
|
||||||
|
8, 10, 9, 8, 14, 11, 12, 9, 19, 7, 8, 11, 7, 10, 11, 11, 11, 6, 8, 8, 7, 15, 9, 7,
|
||||||
|
8, 10, 9, 10, 10, 12, 7, 6, 14, 10, 14, 10, 7, 11, 13, 9, 13, 11, 10, 10, 12, 12, 7, 12,
|
||||||
|
10, 11, 12, 8, 13, 9, 5, 12, 11, 9, 5, 9, 12, 9, 6, 10, 11, 9, 9, 11, 9, 7, 7, 18,
|
||||||
|
16, 13, 12, 8, 10, 11, 9, 8, 17, 3, 15, 15, 9, 10, 10, 8, 10, 9, 7, 9, 8, 10, 13, 9,
|
||||||
|
7, 11, 7, 10, 13, 10, 11, 9, 10, 7, 10, 6, 12, 6, 9, 7, 6, 12, 12, 9, 12, 12, 11, 6,
|
||||||
|
1, 12, 8, 13, 14, 8, 8, 10, 7, 7, 6, 7, 5, 11, 6, 11, 13, 8, 13, 5, 9, 12, 7, 11,
|
||||||
|
10, 15, 11, 9, 7, 12, 15, 7, 8, 7, 12, 8, 21, 16, 13, 11, 10, 14, 12, 11, 12, 14, 7, 11,
|
||||||
|
7, 12, 16, 8, 10, 8, 9, 7, 8, 7, 13, 13, 11, 15, 7, 7, 6, 11, 7, 12, 12, 13, 14, 11,
|
||||||
|
13, 11, 11, 9, 15, 8, 6, 11, 12, 10, 11, 7, 6, 14, 11, 10, 12, 5, 8, 9, 11, 15, 11, 10,
|
||||||
|
17, 14, 9, 10, 10, 12, 11, 13, 13, 12, 11, 7, 8, 10, 7, 11, 10, 5, 8, 10, 13, 13, 12, 6,
|
||||||
|
10, 7, 13, 8, 11, 7, 10, 7, 8, 7, 14, 16, 9, 11, 8, 11, 9, 15, 11, 10, 10, 12, 7, 7,
|
||||||
|
11, 7, 5, 17, 9, 11, 11, 11, 10, 17, 10, 15, 7, 11, 12, 16, 9, 8, 11, 14, 9, 22, 8, 8,
|
||||||
|
8, 13, 12, 12, 1, 14, 15, 6, 15, 8, 11, 16, 14, 8, 6, 9, 8, 9, 9, 10, 8, 6, 13, 8,
|
||||||
|
6, 12, 11, 12, 13, 8, 6, 6, 5, 6, 10, 9, 11, 12, 14, 12, 10, 11, 10, 10, 8, 13, 8, 11,
|
||||||
|
7, 13, 13, 12, 12, 13, 15, 4, 9, 16, 7, 9, 8, 10, 6, 9, 11, 12, 6, 7, 14, 6, 4, 15,
|
||||||
|
5, 18, 9, 9, 11, 12, 9, 5, 6, 7, 15, 6, 11, 14, 8, 12, 6, 9, 5, 9, 14, 9, 12, 6,
|
||||||
|
9, 14, 11, 12, 12, 13, 15, 9, 8, 7, 13, 12, 7, 13, 6, 9, 10, 10, 10, 9, 11, 5, 9, 13,
|
||||||
|
16, 9, 10, 8, 9, 6, 13, 12, 8, 12, 9, 12, 17, 8, 11, 10, 8, 7, 11, 7, 13, 13, 10, 14,
|
||||||
|
11, 9, 6, 6, 14, 16, 5, 9, 13, 11, 12, 7, 4, 6, 9, 11, 11, 10, 12, 9, 7, 13, 8, 8,
|
||||||
|
12, 5, 10, 7, 11, 11, 10, 10, 14, 6, 8, 8, 3, 12, 16, 11, 11, 7, 6, 12, 11, 5, 9, 12,
|
||||||
|
9, 13, 7, 8, 9, 9, 12, 7, 9, 8, 12, 11, 6, 10, 6, 7, 6, 11, 10, 8, 9, 8, 4, 19,
|
||||||
|
12, 6, 10, 9, 6, 12, 9, 14, 7, 8, 11, 7, 7, 12, 13, 9, 13, 12, 8, 6, 10, 17, 19, 10,
|
||||||
|
10, 13, 5, 11, 8, 10, 8, 16, 12, 6, 6, 7, 10, 9, 12, 8, 5, 10, 7, 18, 9, 12, 10, 4,
|
||||||
|
9, 9, 15, 15, 6, 7, 7, 11, 12, 4, 8, 18, 5, 12, 12, 11, 10, 14, 9, 9, 10, 8, 10, 8,
|
||||||
|
10, 9, 9, 4, 10, 12, 5, 13, 6, 9, 7, 5, 12, 8, 11, 10, 9, 17, 9, 9, 8, 11, 18, 11,
|
||||||
|
10, 9, 4, 13, 10, 15, 5, 10, 9, 7, 7, 8, 10, 6, 6, 19, 10, 16, 7, 7, 9, 10, 10, 13,
|
||||||
|
10, 10, 14, 13, 12, 8, 7, 13, 12, 11, 13, 12, 9, 8, 6, 8, 10, 3, 8, 8, 12, 12, 13, 13,
|
||||||
|
10, 5, 10, 7, 13, 7, 9, 5, 13, 7, 10, 8, 13, 11, 17, 9, 6, 14, 10, 10, 13, 9, 15, 8,
|
||||||
|
15, 9, 12, 11, 12, 8, 3, 9, 8, 10, 12, 8, 14, 13, 12, 11, 12, 9, 18, 10, 13, 7, 4, 4,
|
||||||
|
11, 8, 3, 7, 9, 10, 12, 7, 11, 21, 9, 7, 8, 9, 10, 10, 11, 9, 15, 13, 21, 12, 8, 11,
|
||||||
|
9, 10, 11, 9, 17, 8, 9, 8, 14, 6, 13, 9, 8, 11, 12, 12, 12, 11, 6, 13, 7, 9, 11, 15,
|
||||||
|
17, 17, 11, 10, 7, 8, 11, 8, 6, 9, 13, 7, 9, 6, 5, 10, 7, 16, 16, 9, 7, 6, 14, 8,
|
||||||
|
13, 16, 7, 7, 10, 11, 6, 10, 9, 9, 8, 14, 11, 9, 11, 9, 10, 11, 9, 8, 14, 11, 7, 12,
|
||||||
|
11, 8, 9, 9, 10, 11, 11, 10, 9, 6, 6, 11, 16, 10, 7, 6, 6, 13, 18, 8, 12, 11, 14, 13,
|
||||||
|
8, 8, 10, 17, 17, 6, 6, 10, 18, 5, 8, 11, 6, 6, 14, 10, 9, 6, 11, 6, 13, 12, 10, 6,
|
||||||
|
9, 9, 9, 13, 7, 17, 10, 14, 10, 9, 10, 10, 11, 10, 11, 15, 13, 6, 12, 19, 10, 12, 12, 15,
|
||||||
|
13, 10, 10, 13, 11, 13, 13, 17, 6, 5, 6, 7, 6, 9, 13, 11, 8, 12, 9, 6, 10, 16, 11, 12,
|
||||||
|
5, 12, 14, 13, 13, 16, 11, 6, 12, 12, 15, 8, 7, 11, 8, 5, 10, 8, 9, 11, 9, 12, 10, 5,
|
||||||
|
12, 11, 9, 6, 14, 12, 10, 11, 9, 6, 7, 12, 8, 12, 8, 15, 9, 8, 7, 9, 3, 6, 14, 7,
|
||||||
|
8, 11, 9, 10, 12, 9, 10, 9, 8, 6, 12, 11, 6, 8, 9, 8, 15, 11, 7, 18, 12, 11, 10, 13,
|
||||||
|
11, 11, 10, 7, 9, 8, 8, 11, 11, 13, 6, 12, 13, 16, 11, 11, 5, 12, 14, 15, 9, 14, 15, 6,
|
||||||
|
8, 7, 6, 8, 9, 19, 7, 12, 11, 8, 14, 12, 10, 9, 3, 7
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::Float32 fieldB[nVerts] = {
|
||||||
|
24, 19, 28, 19, 25, 28, 25, 22, 27, 26, 35, 26, 30, 28, 24, 23, 21, 31, 20, 11, 21, 22, 14, 25,
|
||||||
|
20, 24, 24, 21, 24, 29, 26, 21, 32, 29, 23, 28, 31, 25, 23, 30, 18, 24, 22, 25, 33, 24, 22, 23,
|
||||||
|
21, 17, 20, 28, 30, 18, 20, 32, 25, 24, 32, 15, 27, 24, 27, 19, 30, 27, 17, 24, 29, 23, 22, 19,
|
||||||
|
24, 19, 28, 24, 25, 24, 25, 30, 24, 31, 30, 27, 25, 25, 25, 15, 29, 23, 29, 29, 21, 25, 35, 24,
|
||||||
|
28, 10, 31, 23, 22, 22, 22, 33, 29, 27, 18, 27, 27, 24, 20, 20, 21, 29, 23, 31, 23, 23, 22, 23,
|
||||||
|
30, 27, 28, 31, 16, 29, 25, 19, 33, 28, 25, 24, 15, 27, 37, 29, 15, 19, 14, 19, 24, 23, 30, 29,
|
||||||
|
35, 22, 19, 26, 26, 14, 24, 30, 32, 23, 30, 29, 26, 27, 25, 23, 17, 26, 32, 29, 20, 17, 21, 23,
|
||||||
|
22, 20, 36, 12, 26, 23, 15, 29, 24, 22, 26, 33, 24, 23, 20, 26, 22, 17, 26, 26, 34, 22, 26, 17,
|
||||||
|
23, 18, 29, 27, 21, 29, 28, 29, 24, 25, 28, 19, 18, 21, 23, 23, 27, 25, 24, 25, 24, 25, 21, 25,
|
||||||
|
21, 27, 23, 20, 29, 15, 28, 30, 24, 27, 17, 23, 16, 21, 25, 17, 27, 28, 21, 13, 19, 27, 16, 30,
|
||||||
|
31, 25, 30, 17, 17, 25, 26, 22, 21, 17, 24, 17, 25, 22, 27, 14, 27, 24, 27, 25, 26, 31, 21, 23,
|
||||||
|
30, 30, 22, 19, 23, 22, 23, 25, 24, 25, 24, 28, 26, 30, 18, 25, 30, 37, 27, 34, 28, 34, 25, 10,
|
||||||
|
25, 22, 35, 30, 24, 32, 24, 34, 19, 29, 26, 16, 27, 17, 26, 23, 27, 25, 26, 21, 31, 21, 28, 15,
|
||||||
|
32, 24, 23, 23, 18, 15, 22, 25, 16, 25, 31, 26, 25, 28, 24, 26, 23, 25, 33, 20, 27, 28, 24, 29,
|
||||||
|
32, 20, 24, 20, 19, 32, 24, 6, 24, 21, 26, 18, 15, 30, 19, 26, 22, 30, 35, 23, 22, 30, 20, 22,
|
||||||
|
18, 30, 28, 25, 16, 25, 27, 30, 18, 24, 30, 28, 20, 19, 20, 28, 21, 24, 15, 33, 20, 18, 20, 36,
|
||||||
|
30, 26, 25, 18, 28, 27, 31, 31, 15, 26, 16, 22, 27, 14, 17, 27, 27, 22, 32, 30, 22, 34, 22, 25,
|
||||||
|
20, 22, 26, 29, 28, 33, 18, 23, 20, 20, 27, 24, 28, 21, 25, 27, 25, 19, 19, 25, 19, 32, 29, 27,
|
||||||
|
23, 21, 28, 33, 23, 23, 28, 26, 31, 19, 21, 29, 21, 27, 23, 32, 24, 26, 21, 28, 28, 24, 17, 31,
|
||||||
|
27, 21, 19, 32, 28, 23, 30, 23, 29, 15, 26, 26, 15, 20, 25, 26, 27, 31, 21, 23, 23, 33, 28, 19,
|
||||||
|
23, 22, 22, 25, 27, 17, 23, 17, 25, 28, 26, 30, 32, 31, 19, 25, 25, 19, 23, 29, 27, 23, 34, 22,
|
||||||
|
13, 21, 32, 10, 20, 33, 21, 17, 29, 31, 14, 24, 23, 19, 19, 22, 17, 26, 37, 26, 22, 26, 38, 29,
|
||||||
|
29, 27, 30, 20, 31, 14, 32, 32, 24, 23, 23, 18, 21, 31, 24, 20, 28, 15, 21, 25, 25, 20, 30, 25,
|
||||||
|
22, 21, 21, 25, 24, 25, 18, 23, 28, 30, 20, 27, 27, 19, 10, 32, 24, 20, 29, 26, 25, 20, 25, 29,
|
||||||
|
28, 24, 32, 26, 22, 19, 23, 27, 27, 29, 20, 25, 21, 30, 28, 31, 24, 19, 23, 19, 19, 18, 30, 18,
|
||||||
|
16, 24, 20, 20, 30, 25, 29, 25, 31, 21, 28, 31, 24, 26, 27, 21, 24, 23, 26, 18, 32, 26, 28, 26,
|
||||||
|
24, 26, 29, 30, 22, 20, 24, 28, 25, 29, 20, 21, 22, 15, 30, 27, 33, 26, 22, 32, 30, 31, 20, 19,
|
||||||
|
24, 26, 27, 31, 17, 17, 33, 27, 16, 27, 27, 22, 27, 19, 24, 21, 17, 24, 28, 23, 26, 24, 19, 26,
|
||||||
|
20, 24, 22, 19, 22, 21, 21, 28, 29, 39, 19, 16, 25, 29, 31, 22, 22, 29, 26, 22, 22, 22, 26, 23,
|
||||||
|
23, 23, 30, 25, 25, 25, 27, 29, 18, 33, 21, 12, 22, 29, 12, 20, 35, 22, 34, 28, 18, 29, 21, 20,
|
||||||
|
24, 33, 24, 26, 23, 34, 31, 25, 31, 22, 35, 21, 20, 29, 27, 22, 30, 22, 27, 23, 22, 32, 16, 19,
|
||||||
|
27, 22, 24, 27, 21, 33, 25, 25, 19, 28, 20, 27, 21, 25, 28, 20, 27, 22, 21, 20, 26, 30, 33, 23,
|
||||||
|
20, 24, 17, 23, 28, 35, 14, 23, 22, 28, 28, 26, 25, 18, 20, 28, 28, 22, 13, 24, 22, 20, 30, 26,
|
||||||
|
26, 18, 22, 20, 23, 24, 20, 27, 34, 28, 18, 24, 34, 33, 25, 33, 37, 21, 20, 31, 19, 23, 29, 22,
|
||||||
|
21, 24, 19, 27, 19, 32, 25, 23, 33, 26, 33, 27, 29, 30, 19, 22, 30, 19, 18, 24, 25, 17, 31, 19,
|
||||||
|
31, 26, 22, 23, 28, 28, 25, 24, 19, 19, 27, 28, 23, 21, 29, 26, 31, 22, 22, 25, 16, 29, 21, 22,
|
||||||
|
23, 25, 22, 21, 22, 19, 27, 26, 28, 30, 22, 21, 24, 22, 23, 26, 28, 22, 18, 25, 23, 27, 31, 19,
|
||||||
|
15, 29, 20, 19, 27, 25, 21, 29, 22, 24, 25, 17, 36, 29, 22, 22, 24, 28, 27, 22, 26, 31, 29, 31,
|
||||||
|
18, 25, 23, 16, 37, 27, 21, 31, 25, 24, 20, 23, 28, 33, 24, 21, 26, 20, 18, 31, 20, 24, 23, 19,
|
||||||
|
27, 17, 23, 23, 20, 26, 28, 23, 26, 31, 25, 31, 19, 32, 26, 18, 19, 29, 20, 21, 15, 25, 27, 29,
|
||||||
|
22, 22, 22, 26, 23, 22, 23, 29, 28, 20, 21, 22, 20, 22, 27, 25, 23, 32, 23, 20, 31, 20, 27, 26,
|
||||||
|
34, 20, 22, 36, 21, 29, 25, 20, 21, 22, 29, 29, 25, 22, 24, 22
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::Float32 fieldC[nVerts] = {
|
||||||
|
3, 1, 4, 6, 5, 4, 8, 7, 2, 9, 2, 0, 0, 4, 3, 2, 5, 2, 3, 6, 3, 8, 3, 4,
|
||||||
|
3, 3, 2, 7, 2, 10, 9, 6, 1, 1, 4, 7, 3, 3, 1, 4, 4, 3, 9, 4, 4, 7, 3, 2,
|
||||||
|
4, 7, 3, 3, 2, 10, 1, 6, 2, 2, 3, 8, 3, 3, 6, 9, 4, 1, 4, 3, 16, 7, 0, 1,
|
||||||
|
8, 7, 13, 3, 5, 0, 3, 8, 10, 3, 5, 5, 1, 5, 2, 1, 3, 2, 5, 3, 4, 3, 3, 3,
|
||||||
|
3, 1, 13, 2, 3, 1, 2, 7, 3, 4, 1, 2, 5, 4, 4, 4, 2, 6, 3, 2, 7, 8, 1, 3,
|
||||||
|
4, 1, 2, 0, 1, 6, 1, 8, 8, 1, 1, 4, 2, 1, 4, 3, 5, 4, 6, 4, 2, 3, 8, 8,
|
||||||
|
3, 3, 3, 4, 5, 8, 8, 16, 7, 12, 4, 3, 14, 8, 3, 12, 5, 0, 5, 3, 5, 2, 9, 2,
|
||||||
|
9, 4, 1, 0, 0, 4, 4, 6, 3, 4, 11, 2, 4, 7, 4, 2, 1, 9, 4, 3, 2, 5, 1, 5,
|
||||||
|
3, 8, 2, 8, 1, 8, 0, 4, 1, 3, 2, 1, 2, 3, 2, 1, 8, 5, 4, 1, 9, 9, 1, 3,
|
||||||
|
5, 0, 1, 6, 10, 8, 3, 12, 3, 4, 4, 7, 1, 3, 6, 4, 4, 6, 1, 4, 7, 5, 6, 11,
|
||||||
|
6, 5, 2, 7, 2, 5, 3, 5, 6, 3, 6, 2, 1, 10, 8, 3, 7, 0, 2, 6, 9, 3, 11, 3,
|
||||||
|
2, 5, 1, 4, 6, 10, 9, 1, 4, 3, 7, 12, 3, 10, 0, 2, 11, 2, 1, 0, 4, 1, 2, 16,
|
||||||
|
5, 17, 7, 8, 2, 10, 10, 3, 1, 3, 2, 2, 4, 8, 4, 3, 2, 4, 4, 6, 8, 6, 2, 3,
|
||||||
|
2, 4, 2, 4, 7, 10, 5, 3, 5, 2, 4, 6, 9, 3, 1, 1, 1, 1, 4, 2, 2, 7, 4, 9,
|
||||||
|
2, 3, 5, 6, 2, 5, 1, 6, 5, 7, 8, 3, 7, 2, 2, 8, 6, 2, 10, 2, 1, 4, 5, 1,
|
||||||
|
1, 1, 5, 6, 1, 1, 4, 5, 4, 2, 4, 3, 2, 7, 19, 4, 7, 2, 7, 5, 2, 5, 3, 8,
|
||||||
|
4, 6, 7, 2, 0, 0, 2, 12, 6, 2, 2, 3, 5, 9, 4, 9, 2, 2, 7, 8, 3, 3, 10, 6,
|
||||||
|
3, 2, 1, 6, 2, 4, 6, 3, 5, 8, 2, 3, 6, 14, 0, 3, 6, 5, 2, 7, 0, 3, 8, 5,
|
||||||
|
3, 2, 2, 5, 1, 3, 12, 11, 16, 2, 1, 3, 7, 3, 1, 6, 4, 3, 12, 5, 1, 3, 1, 4,
|
||||||
|
9, 1, 3, 3, 4, 4, 6, 7, 7, 5, 2, 4, 2, 3, 2, 2, 6, 4, 2, 2, 3, 5, 1, 4,
|
||||||
|
9, 1, 0, 7, 6, 4, 3, 3, 7, 3, 3, 6, 2, 7, 9, 3, 1, 16, 5, 4, 3, 6, 3, 2,
|
||||||
|
5, 2, 2, 4, 3, 1, 3, 3, 6, 3, 5, 9, 1, 10, 1, 7, 2, 2, 6, 7, 3, 5, 3, 7,
|
||||||
|
2, 2, 2, 2, 6, 4, 3, 2, 5, 5, 3, 15, 4, 2, 7, 7, 4, 3, 3, 5, 1, 2, 9, 0,
|
||||||
|
5, 7, 12, 2, 4, 8, 5, 7, 8, 3, 2, 2, 18, 1, 7, 2, 2, 1, 3, 3, 3, 7, 1, 9,
|
||||||
|
8, 4, 3, 7, 6, 4, 5, 2, 0, 5, 1, 5, 10, 4, 2, 8, 2, 2, 0, 5, 6, 4, 5, 0,
|
||||||
|
1, 5, 11, 3, 3, 4, 4, 2, 3, 5, 1, 6, 5, 7, 2, 2, 5, 7, 4, 8, 4, 1, 1, 7,
|
||||||
|
2, 3, 9, 6, 13, 1, 5, 4, 6, 2, 4, 11, 2, 5, 5, 1, 4, 1, 4, 7, 1, 5, 8, 3,
|
||||||
|
1, 10, 9, 13, 1, 7, 2, 9, 4, 3, 3, 10, 12, 2, 0, 4, 6, 5, 5, 1, 4, 7, 2, 12,
|
||||||
|
7, 6, 5, 0, 6, 4, 4, 12, 1, 3, 10, 1, 9, 2, 2, 2, 1, 5, 5, 6, 9, 6, 4, 1,
|
||||||
|
11, 6, 9, 3, 2, 7, 1, 7, 4, 3, 0, 3, 1, 12, 17, 2, 1, 6, 4, 4, 2, 1, 5, 5,
|
||||||
|
3, 2, 2, 4, 6, 5, 4, 6, 11, 3, 12, 6, 3, 6, 3, 0, 6, 3, 7, 4, 8, 5, 14, 5,
|
||||||
|
1, 9, 4, 6, 5, 3, 9, 3, 1, 1, 0, 3, 7, 3, 5, 1, 6, 2, 2, 6, 2, 12, 1, 0,
|
||||||
|
6, 3, 3, 5, 4, 7, 2, 2, 15, 7, 3, 10, 4, 2, 6, 3, 4, 8, 3, 1, 5, 5, 5, 4,
|
||||||
|
3, 7, 3, 4, 5, 5, 2, 4, 2, 5, 1, 12, 5, 6, 3, 2, 8, 5, 2, 3, 11, 11, 6, 5,
|
||||||
|
0, 3, 3, 9, 4, 2, 11, 1, 5, 3, 5, 6, 3, 6, 4, 2, 4, 10, 11, 3, 3, 4, 1, 1,
|
||||||
|
1, 3, 5, 5, 1, 1, 4, 1, 5, 1, 6, 8, 6, 4, 6, 7, 6, 3, 5, 3, 6, 6, 6, 4,
|
||||||
|
0, 6, 3, 1, 2, 4, 2, 6, 1, 1, 1, 2, 2, 4, 7, 2, 6, 2, 5, 7, 6, 4, 6, 3,
|
||||||
|
1, 4, 5, 1, 4, 6, 2, 3, 0, 6, 11, 2, 9, 2, 6, 4, 5, 6, 2, 19, 2, 10, 4, 2,
|
||||||
|
3, 3, 11, 7, 3, 3, 1, 5, 3, 6, 4, 3, 0, 6, 6, 6, 4, 2, 5, 2, 2, 2, 6, 10,
|
||||||
|
4, 9, 3, 7, 7, 0, 6, 8, 5, 2, 3, 2, 3, 3, 3, 1, 6, 1, 8, 2, 5, 3, 6, 11,
|
||||||
|
5, 7, 2, 6, 7, 3, 4, 1, 0, 5, 8, 3, 2, 9, 3, 1, 2, 3, 3, 9, 5, 6, 5, 1,
|
||||||
|
4, 5, 6, 7, 6, 1, 5, 1, 6, 6, 2, 6, 7, 2, 4, 6
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleUniformPointCoordinates coordinates(vtkm::Id3(xVerts, yVerts, 1));
|
||||||
|
dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coordinates));
|
||||||
|
|
||||||
|
// Set point scalars
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldA", vtkm::cont::Field::ASSOC_POINTS, fieldA, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldB", vtkm::cont::Field::ASSOC_POINTS, fieldB, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldC", vtkm::cont::Field::ASSOC_POINTS, fieldC, nVerts));
|
||||||
|
|
||||||
|
return dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create a dataset with known point data
|
||||||
|
// Extract the three field
|
||||||
|
// Run NDimsEntropy to calculate the entropy
|
||||||
|
//
|
||||||
|
void TestNDimsEntropy()
|
||||||
|
{
|
||||||
|
// Data attached is the poisson distribution
|
||||||
|
vtkm::cont::DataSet ds = MakeTestDataSet();
|
||||||
|
|
||||||
|
vtkm::worklet::NDimsEntropy ndEntropy;
|
||||||
|
ndEntropy.SetNumOfDataPoints(ds.GetField(0).GetData().GetNumberOfValues(),
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// Add field one by one
|
||||||
|
ndEntropy.AddField(ds.GetField("fieldA").GetData(), 10, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
ndEntropy.AddField(ds.GetField("fieldB").GetData(), 10, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
ndEntropy.AddField(ds.GetField("fieldC").GetData(), 10, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// Run worklet to calculate multi-variate entropy
|
||||||
|
vtkm::Float64 entropy = ndEntropy.Run(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
VTKM_TEST_ASSERT(fabs(entropy - 7.457857) < 0.001,
|
||||||
|
"N-Dimentional entropy calculation is incorrect");
|
||||||
|
} // TestNDimsEntropy
|
||||||
|
}
|
||||||
|
|
||||||
|
int UnitTestNDimsEntropy(int, char* [])
|
||||||
|
{
|
||||||
|
return vtkm::cont::testing::Testing::Run(TestNDimsEntropy);
|
||||||
|
}
|
317
vtkm/worklet/testing/UnitTestNDimsHistMarginalization.cxx
Normal file
317
vtkm/worklet/testing/UnitTestNDimsHistMarginalization.cxx
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vtkm/worklet/NDimsHistMarginalization.h>
|
||||||
|
#include <vtkm/worklet/NDimsHistogram.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
|
||||||
|
#include <vtkm/cont/testing/Testing.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// Make testing dataset with three fields(variables), each one has 1000 values
|
||||||
|
vtkm::cont::DataSet MakeTestDataSet()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet dataSet;
|
||||||
|
|
||||||
|
const int xVerts = 20;
|
||||||
|
const int yVerts = 50;
|
||||||
|
const int nVerts = xVerts * yVerts;
|
||||||
|
|
||||||
|
vtkm::Float32 fieldA[nVerts] = {
|
||||||
|
8, 10, 9, 8, 14, 11, 12, 9, 19, 7, 8, 11, 7, 10, 11, 11, 11, 6, 8, 8, 7, 15, 9, 7,
|
||||||
|
8, 10, 9, 10, 10, 12, 7, 6, 14, 10, 14, 10, 7, 11, 13, 9, 13, 11, 10, 10, 12, 12, 7, 12,
|
||||||
|
10, 11, 12, 8, 13, 9, 5, 12, 11, 9, 5, 9, 12, 9, 6, 10, 11, 9, 9, 11, 9, 7, 7, 18,
|
||||||
|
16, 13, 12, 8, 10, 11, 9, 8, 17, 3, 15, 15, 9, 10, 10, 8, 10, 9, 7, 9, 8, 10, 13, 9,
|
||||||
|
7, 11, 7, 10, 13, 10, 11, 9, 10, 7, 10, 6, 12, 6, 9, 7, 6, 12, 12, 9, 12, 12, 11, 6,
|
||||||
|
1, 12, 8, 13, 14, 8, 8, 10, 7, 7, 6, 7, 5, 11, 6, 11, 13, 8, 13, 5, 9, 12, 7, 11,
|
||||||
|
10, 15, 11, 9, 7, 12, 15, 7, 8, 7, 12, 8, 21, 16, 13, 11, 10, 14, 12, 11, 12, 14, 7, 11,
|
||||||
|
7, 12, 16, 8, 10, 8, 9, 7, 8, 7, 13, 13, 11, 15, 7, 7, 6, 11, 7, 12, 12, 13, 14, 11,
|
||||||
|
13, 11, 11, 9, 15, 8, 6, 11, 12, 10, 11, 7, 6, 14, 11, 10, 12, 5, 8, 9, 11, 15, 11, 10,
|
||||||
|
17, 14, 9, 10, 10, 12, 11, 13, 13, 12, 11, 7, 8, 10, 7, 11, 10, 5, 8, 10, 13, 13, 12, 6,
|
||||||
|
10, 7, 13, 8, 11, 7, 10, 7, 8, 7, 14, 16, 9, 11, 8, 11, 9, 15, 11, 10, 10, 12, 7, 7,
|
||||||
|
11, 7, 5, 17, 9, 11, 11, 11, 10, 17, 10, 15, 7, 11, 12, 16, 9, 8, 11, 14, 9, 22, 8, 8,
|
||||||
|
8, 13, 12, 12, 1, 14, 15, 6, 15, 8, 11, 16, 14, 8, 6, 9, 8, 9, 9, 10, 8, 6, 13, 8,
|
||||||
|
6, 12, 11, 12, 13, 8, 6, 6, 5, 6, 10, 9, 11, 12, 14, 12, 10, 11, 10, 10, 8, 13, 8, 11,
|
||||||
|
7, 13, 13, 12, 12, 13, 15, 4, 9, 16, 7, 9, 8, 10, 6, 9, 11, 12, 6, 7, 14, 6, 4, 15,
|
||||||
|
5, 18, 9, 9, 11, 12, 9, 5, 6, 7, 15, 6, 11, 14, 8, 12, 6, 9, 5, 9, 14, 9, 12, 6,
|
||||||
|
9, 14, 11, 12, 12, 13, 15, 9, 8, 7, 13, 12, 7, 13, 6, 9, 10, 10, 10, 9, 11, 5, 9, 13,
|
||||||
|
16, 9, 10, 8, 9, 6, 13, 12, 8, 12, 9, 12, 17, 8, 11, 10, 8, 7, 11, 7, 13, 13, 10, 14,
|
||||||
|
11, 9, 6, 6, 14, 16, 5, 9, 13, 11, 12, 7, 4, 6, 9, 11, 11, 10, 12, 9, 7, 13, 8, 8,
|
||||||
|
12, 5, 10, 7, 11, 11, 10, 10, 14, 6, 8, 8, 3, 12, 16, 11, 11, 7, 6, 12, 11, 5, 9, 12,
|
||||||
|
9, 13, 7, 8, 9, 9, 12, 7, 9, 8, 12, 11, 6, 10, 6, 7, 6, 11, 10, 8, 9, 8, 4, 19,
|
||||||
|
12, 6, 10, 9, 6, 12, 9, 14, 7, 8, 11, 7, 7, 12, 13, 9, 13, 12, 8, 6, 10, 17, 19, 10,
|
||||||
|
10, 13, 5, 11, 8, 10, 8, 16, 12, 6, 6, 7, 10, 9, 12, 8, 5, 10, 7, 18, 9, 12, 10, 4,
|
||||||
|
9, 9, 15, 15, 6, 7, 7, 11, 12, 4, 8, 18, 5, 12, 12, 11, 10, 14, 9, 9, 10, 8, 10, 8,
|
||||||
|
10, 9, 9, 4, 10, 12, 5, 13, 6, 9, 7, 5, 12, 8, 11, 10, 9, 17, 9, 9, 8, 11, 18, 11,
|
||||||
|
10, 9, 4, 13, 10, 15, 5, 10, 9, 7, 7, 8, 10, 6, 6, 19, 10, 16, 7, 7, 9, 10, 10, 13,
|
||||||
|
10, 10, 14, 13, 12, 8, 7, 13, 12, 11, 13, 12, 9, 8, 6, 8, 10, 3, 8, 8, 12, 12, 13, 13,
|
||||||
|
10, 5, 10, 7, 13, 7, 9, 5, 13, 7, 10, 8, 13, 11, 17, 9, 6, 14, 10, 10, 13, 9, 15, 8,
|
||||||
|
15, 9, 12, 11, 12, 8, 3, 9, 8, 10, 12, 8, 14, 13, 12, 11, 12, 9, 18, 10, 13, 7, 4, 4,
|
||||||
|
11, 8, 3, 7, 9, 10, 12, 7, 11, 21, 9, 7, 8, 9, 10, 10, 11, 9, 15, 13, 21, 12, 8, 11,
|
||||||
|
9, 10, 11, 9, 17, 8, 9, 8, 14, 6, 13, 9, 8, 11, 12, 12, 12, 11, 6, 13, 7, 9, 11, 15,
|
||||||
|
17, 17, 11, 10, 7, 8, 11, 8, 6, 9, 13, 7, 9, 6, 5, 10, 7, 16, 16, 9, 7, 6, 14, 8,
|
||||||
|
13, 16, 7, 7, 10, 11, 6, 10, 9, 9, 8, 14, 11, 9, 11, 9, 10, 11, 9, 8, 14, 11, 7, 12,
|
||||||
|
11, 8, 9, 9, 10, 11, 11, 10, 9, 6, 6, 11, 16, 10, 7, 6, 6, 13, 18, 8, 12, 11, 14, 13,
|
||||||
|
8, 8, 10, 17, 17, 6, 6, 10, 18, 5, 8, 11, 6, 6, 14, 10, 9, 6, 11, 6, 13, 12, 10, 6,
|
||||||
|
9, 9, 9, 13, 7, 17, 10, 14, 10, 9, 10, 10, 11, 10, 11, 15, 13, 6, 12, 19, 10, 12, 12, 15,
|
||||||
|
13, 10, 10, 13, 11, 13, 13, 17, 6, 5, 6, 7, 6, 9, 13, 11, 8, 12, 9, 6, 10, 16, 11, 12,
|
||||||
|
5, 12, 14, 13, 13, 16, 11, 6, 12, 12, 15, 8, 7, 11, 8, 5, 10, 8, 9, 11, 9, 12, 10, 5,
|
||||||
|
12, 11, 9, 6, 14, 12, 10, 11, 9, 6, 7, 12, 8, 12, 8, 15, 9, 8, 7, 9, 3, 6, 14, 7,
|
||||||
|
8, 11, 9, 10, 12, 9, 10, 9, 8, 6, 12, 11, 6, 8, 9, 8, 15, 11, 7, 18, 12, 11, 10, 13,
|
||||||
|
11, 11, 10, 7, 9, 8, 8, 11, 11, 13, 6, 12, 13, 16, 11, 11, 5, 12, 14, 15, 9, 14, 15, 6,
|
||||||
|
8, 7, 6, 8, 9, 19, 7, 12, 11, 8, 14, 12, 10, 9, 3, 7
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::Float32 fieldB[nVerts] = {
|
||||||
|
24, 19, 28, 19, 25, 28, 25, 22, 27, 26, 35, 26, 30, 28, 24, 23, 21, 31, 20, 11, 21, 22, 14, 25,
|
||||||
|
20, 24, 24, 21, 24, 29, 26, 21, 32, 29, 23, 28, 31, 25, 23, 30, 18, 24, 22, 25, 33, 24, 22, 23,
|
||||||
|
21, 17, 20, 28, 30, 18, 20, 32, 25, 24, 32, 15, 27, 24, 27, 19, 30, 27, 17, 24, 29, 23, 22, 19,
|
||||||
|
24, 19, 28, 24, 25, 24, 25, 30, 24, 31, 30, 27, 25, 25, 25, 15, 29, 23, 29, 29, 21, 25, 35, 24,
|
||||||
|
28, 10, 31, 23, 22, 22, 22, 33, 29, 27, 18, 27, 27, 24, 20, 20, 21, 29, 23, 31, 23, 23, 22, 23,
|
||||||
|
30, 27, 28, 31, 16, 29, 25, 19, 33, 28, 25, 24, 15, 27, 37, 29, 15, 19, 14, 19, 24, 23, 30, 29,
|
||||||
|
35, 22, 19, 26, 26, 14, 24, 30, 32, 23, 30, 29, 26, 27, 25, 23, 17, 26, 32, 29, 20, 17, 21, 23,
|
||||||
|
22, 20, 36, 12, 26, 23, 15, 29, 24, 22, 26, 33, 24, 23, 20, 26, 22, 17, 26, 26, 34, 22, 26, 17,
|
||||||
|
23, 18, 29, 27, 21, 29, 28, 29, 24, 25, 28, 19, 18, 21, 23, 23, 27, 25, 24, 25, 24, 25, 21, 25,
|
||||||
|
21, 27, 23, 20, 29, 15, 28, 30, 24, 27, 17, 23, 16, 21, 25, 17, 27, 28, 21, 13, 19, 27, 16, 30,
|
||||||
|
31, 25, 30, 17, 17, 25, 26, 22, 21, 17, 24, 17, 25, 22, 27, 14, 27, 24, 27, 25, 26, 31, 21, 23,
|
||||||
|
30, 30, 22, 19, 23, 22, 23, 25, 24, 25, 24, 28, 26, 30, 18, 25, 30, 37, 27, 34, 28, 34, 25, 10,
|
||||||
|
25, 22, 35, 30, 24, 32, 24, 34, 19, 29, 26, 16, 27, 17, 26, 23, 27, 25, 26, 21, 31, 21, 28, 15,
|
||||||
|
32, 24, 23, 23, 18, 15, 22, 25, 16, 25, 31, 26, 25, 28, 24, 26, 23, 25, 33, 20, 27, 28, 24, 29,
|
||||||
|
32, 20, 24, 20, 19, 32, 24, 6, 24, 21, 26, 18, 15, 30, 19, 26, 22, 30, 35, 23, 22, 30, 20, 22,
|
||||||
|
18, 30, 28, 25, 16, 25, 27, 30, 18, 24, 30, 28, 20, 19, 20, 28, 21, 24, 15, 33, 20, 18, 20, 36,
|
||||||
|
30, 26, 25, 18, 28, 27, 31, 31, 15, 26, 16, 22, 27, 14, 17, 27, 27, 22, 32, 30, 22, 34, 22, 25,
|
||||||
|
20, 22, 26, 29, 28, 33, 18, 23, 20, 20, 27, 24, 28, 21, 25, 27, 25, 19, 19, 25, 19, 32, 29, 27,
|
||||||
|
23, 21, 28, 33, 23, 23, 28, 26, 31, 19, 21, 29, 21, 27, 23, 32, 24, 26, 21, 28, 28, 24, 17, 31,
|
||||||
|
27, 21, 19, 32, 28, 23, 30, 23, 29, 15, 26, 26, 15, 20, 25, 26, 27, 31, 21, 23, 23, 33, 28, 19,
|
||||||
|
23, 22, 22, 25, 27, 17, 23, 17, 25, 28, 26, 30, 32, 31, 19, 25, 25, 19, 23, 29, 27, 23, 34, 22,
|
||||||
|
13, 21, 32, 10, 20, 33, 21, 17, 29, 31, 14, 24, 23, 19, 19, 22, 17, 26, 37, 26, 22, 26, 38, 29,
|
||||||
|
29, 27, 30, 20, 31, 14, 32, 32, 24, 23, 23, 18, 21, 31, 24, 20, 28, 15, 21, 25, 25, 20, 30, 25,
|
||||||
|
22, 21, 21, 25, 24, 25, 18, 23, 28, 30, 20, 27, 27, 19, 10, 32, 24, 20, 29, 26, 25, 20, 25, 29,
|
||||||
|
28, 24, 32, 26, 22, 19, 23, 27, 27, 29, 20, 25, 21, 30, 28, 31, 24, 19, 23, 19, 19, 18, 30, 18,
|
||||||
|
16, 24, 20, 20, 30, 25, 29, 25, 31, 21, 28, 31, 24, 26, 27, 21, 24, 23, 26, 18, 32, 26, 28, 26,
|
||||||
|
24, 26, 29, 30, 22, 20, 24, 28, 25, 29, 20, 21, 22, 15, 30, 27, 33, 26, 22, 32, 30, 31, 20, 19,
|
||||||
|
24, 26, 27, 31, 17, 17, 33, 27, 16, 27, 27, 22, 27, 19, 24, 21, 17, 24, 28, 23, 26, 24, 19, 26,
|
||||||
|
20, 24, 22, 19, 22, 21, 21, 28, 29, 39, 19, 16, 25, 29, 31, 22, 22, 29, 26, 22, 22, 22, 26, 23,
|
||||||
|
23, 23, 30, 25, 25, 25, 27, 29, 18, 33, 21, 12, 22, 29, 12, 20, 35, 22, 34, 28, 18, 29, 21, 20,
|
||||||
|
24, 33, 24, 26, 23, 34, 31, 25, 31, 22, 35, 21, 20, 29, 27, 22, 30, 22, 27, 23, 22, 32, 16, 19,
|
||||||
|
27, 22, 24, 27, 21, 33, 25, 25, 19, 28, 20, 27, 21, 25, 28, 20, 27, 22, 21, 20, 26, 30, 33, 23,
|
||||||
|
20, 24, 17, 23, 28, 35, 14, 23, 22, 28, 28, 26, 25, 18, 20, 28, 28, 22, 13, 24, 22, 20, 30, 26,
|
||||||
|
26, 18, 22, 20, 23, 24, 20, 27, 34, 28, 18, 24, 34, 33, 25, 33, 37, 21, 20, 31, 19, 23, 29, 22,
|
||||||
|
21, 24, 19, 27, 19, 32, 25, 23, 33, 26, 33, 27, 29, 30, 19, 22, 30, 19, 18, 24, 25, 17, 31, 19,
|
||||||
|
31, 26, 22, 23, 28, 28, 25, 24, 19, 19, 27, 28, 23, 21, 29, 26, 31, 22, 22, 25, 16, 29, 21, 22,
|
||||||
|
23, 25, 22, 21, 22, 19, 27, 26, 28, 30, 22, 21, 24, 22, 23, 26, 28, 22, 18, 25, 23, 27, 31, 19,
|
||||||
|
15, 29, 20, 19, 27, 25, 21, 29, 22, 24, 25, 17, 36, 29, 22, 22, 24, 28, 27, 22, 26, 31, 29, 31,
|
||||||
|
18, 25, 23, 16, 37, 27, 21, 31, 25, 24, 20, 23, 28, 33, 24, 21, 26, 20, 18, 31, 20, 24, 23, 19,
|
||||||
|
27, 17, 23, 23, 20, 26, 28, 23, 26, 31, 25, 31, 19, 32, 26, 18, 19, 29, 20, 21, 15, 25, 27, 29,
|
||||||
|
22, 22, 22, 26, 23, 22, 23, 29, 28, 20, 21, 22, 20, 22, 27, 25, 23, 32, 23, 20, 31, 20, 27, 26,
|
||||||
|
34, 20, 22, 36, 21, 29, 25, 20, 21, 22, 29, 29, 25, 22, 24, 22
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::Float32 fieldC[nVerts] = {
|
||||||
|
3, 1, 4, 6, 5, 4, 8, 7, 2, 9, 2, 0, 0, 4, 3, 2, 5, 2, 3, 6, 3, 8, 3, 4,
|
||||||
|
3, 3, 2, 7, 2, 10, 9, 6, 1, 1, 4, 7, 3, 3, 1, 4, 4, 3, 9, 4, 4, 7, 3, 2,
|
||||||
|
4, 7, 3, 3, 2, 10, 1, 6, 2, 2, 3, 8, 3, 3, 6, 9, 4, 1, 4, 3, 16, 7, 0, 1,
|
||||||
|
8, 7, 13, 3, 5, 0, 3, 8, 10, 3, 5, 5, 1, 5, 2, 1, 3, 2, 5, 3, 4, 3, 3, 3,
|
||||||
|
3, 1, 13, 2, 3, 1, 2, 7, 3, 4, 1, 2, 5, 4, 4, 4, 2, 6, 3, 2, 7, 8, 1, 3,
|
||||||
|
4, 1, 2, 0, 1, 6, 1, 8, 8, 1, 1, 4, 2, 1, 4, 3, 5, 4, 6, 4, 2, 3, 8, 8,
|
||||||
|
3, 3, 3, 4, 5, 8, 8, 16, 7, 12, 4, 3, 14, 8, 3, 12, 5, 0, 5, 3, 5, 2, 9, 2,
|
||||||
|
9, 4, 1, 0, 0, 4, 4, 6, 3, 4, 11, 2, 4, 7, 4, 2, 1, 9, 4, 3, 2, 5, 1, 5,
|
||||||
|
3, 8, 2, 8, 1, 8, 0, 4, 1, 3, 2, 1, 2, 3, 2, 1, 8, 5, 4, 1, 9, 9, 1, 3,
|
||||||
|
5, 0, 1, 6, 10, 8, 3, 12, 3, 4, 4, 7, 1, 3, 6, 4, 4, 6, 1, 4, 7, 5, 6, 11,
|
||||||
|
6, 5, 2, 7, 2, 5, 3, 5, 6, 3, 6, 2, 1, 10, 8, 3, 7, 0, 2, 6, 9, 3, 11, 3,
|
||||||
|
2, 5, 1, 4, 6, 10, 9, 1, 4, 3, 7, 12, 3, 10, 0, 2, 11, 2, 1, 0, 4, 1, 2, 16,
|
||||||
|
5, 17, 7, 8, 2, 10, 10, 3, 1, 3, 2, 2, 4, 8, 4, 3, 2, 4, 4, 6, 8, 6, 2, 3,
|
||||||
|
2, 4, 2, 4, 7, 10, 5, 3, 5, 2, 4, 6, 9, 3, 1, 1, 1, 1, 4, 2, 2, 7, 4, 9,
|
||||||
|
2, 3, 5, 6, 2, 5, 1, 6, 5, 7, 8, 3, 7, 2, 2, 8, 6, 2, 10, 2, 1, 4, 5, 1,
|
||||||
|
1, 1, 5, 6, 1, 1, 4, 5, 4, 2, 4, 3, 2, 7, 19, 4, 7, 2, 7, 5, 2, 5, 3, 8,
|
||||||
|
4, 6, 7, 2, 0, 0, 2, 12, 6, 2, 2, 3, 5, 9, 4, 9, 2, 2, 7, 8, 3, 3, 10, 6,
|
||||||
|
3, 2, 1, 6, 2, 4, 6, 3, 5, 8, 2, 3, 6, 14, 0, 3, 6, 5, 2, 7, 0, 3, 8, 5,
|
||||||
|
3, 2, 2, 5, 1, 3, 12, 11, 16, 2, 1, 3, 7, 3, 1, 6, 4, 3, 12, 5, 1, 3, 1, 4,
|
||||||
|
9, 1, 3, 3, 4, 4, 6, 7, 7, 5, 2, 4, 2, 3, 2, 2, 6, 4, 2, 2, 3, 5, 1, 4,
|
||||||
|
9, 1, 0, 7, 6, 4, 3, 3, 7, 3, 3, 6, 2, 7, 9, 3, 1, 16, 5, 4, 3, 6, 3, 2,
|
||||||
|
5, 2, 2, 4, 3, 1, 3, 3, 6, 3, 5, 9, 1, 10, 1, 7, 2, 2, 6, 7, 3, 5, 3, 7,
|
||||||
|
2, 2, 2, 2, 6, 4, 3, 2, 5, 5, 3, 15, 4, 2, 7, 7, 4, 3, 3, 5, 1, 2, 9, 0,
|
||||||
|
5, 7, 12, 2, 4, 8, 5, 7, 8, 3, 2, 2, 18, 1, 7, 2, 2, 1, 3, 3, 3, 7, 1, 9,
|
||||||
|
8, 4, 3, 7, 6, 4, 5, 2, 0, 5, 1, 5, 10, 4, 2, 8, 2, 2, 0, 5, 6, 4, 5, 0,
|
||||||
|
1, 5, 11, 3, 3, 4, 4, 2, 3, 5, 1, 6, 5, 7, 2, 2, 5, 7, 4, 8, 4, 1, 1, 7,
|
||||||
|
2, 3, 9, 6, 13, 1, 5, 4, 6, 2, 4, 11, 2, 5, 5, 1, 4, 1, 4, 7, 1, 5, 8, 3,
|
||||||
|
1, 10, 9, 13, 1, 7, 2, 9, 4, 3, 3, 10, 12, 2, 0, 4, 6, 5, 5, 1, 4, 7, 2, 12,
|
||||||
|
7, 6, 5, 0, 6, 4, 4, 12, 1, 3, 10, 1, 9, 2, 2, 2, 1, 5, 5, 6, 9, 6, 4, 1,
|
||||||
|
11, 6, 9, 3, 2, 7, 1, 7, 4, 3, 0, 3, 1, 12, 17, 2, 1, 6, 4, 4, 2, 1, 5, 5,
|
||||||
|
3, 2, 2, 4, 6, 5, 4, 6, 11, 3, 12, 6, 3, 6, 3, 0, 6, 3, 7, 4, 8, 5, 14, 5,
|
||||||
|
1, 9, 4, 6, 5, 3, 9, 3, 1, 1, 0, 3, 7, 3, 5, 1, 6, 2, 2, 6, 2, 12, 1, 0,
|
||||||
|
6, 3, 3, 5, 4, 7, 2, 2, 15, 7, 3, 10, 4, 2, 6, 3, 4, 8, 3, 1, 5, 5, 5, 4,
|
||||||
|
3, 7, 3, 4, 5, 5, 2, 4, 2, 5, 1, 12, 5, 6, 3, 2, 8, 5, 2, 3, 11, 11, 6, 5,
|
||||||
|
0, 3, 3, 9, 4, 2, 11, 1, 5, 3, 5, 6, 3, 6, 4, 2, 4, 10, 11, 3, 3, 4, 1, 1,
|
||||||
|
1, 3, 5, 5, 1, 1, 4, 1, 5, 1, 6, 8, 6, 4, 6, 7, 6, 3, 5, 3, 6, 6, 6, 4,
|
||||||
|
0, 6, 3, 1, 2, 4, 2, 6, 1, 1, 1, 2, 2, 4, 7, 2, 6, 2, 5, 7, 6, 4, 6, 3,
|
||||||
|
1, 4, 5, 1, 4, 6, 2, 3, 0, 6, 11, 2, 9, 2, 6, 4, 5, 6, 2, 19, 2, 10, 4, 2,
|
||||||
|
3, 3, 11, 7, 3, 3, 1, 5, 3, 6, 4, 3, 0, 6, 6, 6, 4, 2, 5, 2, 2, 2, 6, 10,
|
||||||
|
4, 9, 3, 7, 7, 0, 6, 8, 5, 2, 3, 2, 3, 3, 3, 1, 6, 1, 8, 2, 5, 3, 6, 11,
|
||||||
|
5, 7, 2, 6, 7, 3, 4, 1, 0, 5, 8, 3, 2, 9, 3, 1, 2, 3, 3, 9, 5, 6, 5, 1,
|
||||||
|
4, 5, 6, 7, 6, 1, 5, 1, 6, 6, 2, 6, 7, 2, 4, 6
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkm::cont::ArrayHandleUniformPointCoordinates coordinates(vtkm::Id3(xVerts, yVerts, 1));
|
||||||
|
dataSet.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", coordinates));
|
||||||
|
|
||||||
|
// Set point scalars
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldA", vtkm::cont::Field::ASSOC_POINTS, fieldA, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldB", vtkm::cont::Field::ASSOC_POINTS, fieldB, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldC", vtkm::cont::Field::ASSOC_POINTS, fieldC, nVerts));
|
||||||
|
|
||||||
|
return dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Condition function for non-marginal variable
|
||||||
|
// var is index of variable (data array)
|
||||||
|
// binId is bin index
|
||||||
|
// return true indicates considering this bin into final
|
||||||
|
// marginal histogram
|
||||||
|
// In this example, we have three variable var0, var1, var2
|
||||||
|
// the condition is P(Var0, Var2 | 1<Var1<4)
|
||||||
|
// because var0 and var2 are the marginal varaible, we do not care the case var==0 or var==2
|
||||||
|
// it supposes that we do not have input as var ==0 or 2
|
||||||
|
struct VariableCondition
|
||||||
|
{
|
||||||
|
VTKM_EXEC
|
||||||
|
bool operator()(vtkm::Id var, vtkm::Id binId) const
|
||||||
|
{
|
||||||
|
if (var == 1)
|
||||||
|
{
|
||||||
|
if (1 < binId && binId < 4)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Create a dataset with known point data and cell data (statistical distributions)
|
||||||
|
// Extract arrays of point and cell fields
|
||||||
|
// Create output structure to hold histogram bins
|
||||||
|
// Run FieldHistogram filter
|
||||||
|
//
|
||||||
|
void TestNDimsHistMarginalization()
|
||||||
|
{
|
||||||
|
// Setup and calculate a ND-histogram without marginalization first
|
||||||
|
// Create the output bin array
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Range> range;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Float64> delta;
|
||||||
|
|
||||||
|
// Data attached is the poisson distribution
|
||||||
|
vtkm::cont::DataSet ds = MakeTestDataSet();
|
||||||
|
|
||||||
|
// Compute Nd histogram first
|
||||||
|
vtkm::worklet::NDimsHistogram ndHistogram;
|
||||||
|
|
||||||
|
// Set the number of data points
|
||||||
|
ndHistogram.SetNumOfDataPoints(ds.GetField(0).GetData().GetNumberOfValues(),
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// Add field one by one
|
||||||
|
vtkm::Range rangeFieldA;
|
||||||
|
vtkm::Float64 deltaFieldA;
|
||||||
|
ndHistogram.AddField(ds.GetField("fieldA").GetData(),
|
||||||
|
10,
|
||||||
|
rangeFieldA,
|
||||||
|
deltaFieldA,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
vtkm::Range rangeFieldB;
|
||||||
|
vtkm::Float64 deltaFieldB;
|
||||||
|
ndHistogram.AddField(ds.GetField("fieldB").GetData(),
|
||||||
|
10,
|
||||||
|
rangeFieldB,
|
||||||
|
deltaFieldB,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
vtkm::Range rangeFieldC;
|
||||||
|
vtkm::Float64 deltaFieldC;
|
||||||
|
ndHistogram.AddField(ds.GetField("fieldC").GetData(),
|
||||||
|
10,
|
||||||
|
rangeFieldC,
|
||||||
|
deltaFieldC,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// the return binIds and freqs is sparse distribution representation
|
||||||
|
// (we do not keep the 0 frequency entities)
|
||||||
|
// e.g. we have three variable(data arrays) in this example
|
||||||
|
// binIds[0, 1, 2][j] is a combination of bin ID of three variable,
|
||||||
|
// freqs[j] is the freqncy of this bin IDs combination
|
||||||
|
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>> binIds;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> freqs;
|
||||||
|
ndHistogram.Run(binIds, freqs, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// setup for histogram marginalization
|
||||||
|
// use a bool array to indicate the marginal variable (true -> marginal variable)
|
||||||
|
// the length of this array has to be equal to number of input variables
|
||||||
|
bool marginalVariableAry[3] = { true, false, true };
|
||||||
|
vtkm::cont::ArrayHandle<bool> marginalVariable =
|
||||||
|
vtkm::cont::make_ArrayHandle(marginalVariableAry, 3);
|
||||||
|
|
||||||
|
std::vector<vtkm::Id> numberOfBinsVec(3, 10);
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> numberOfBins = vtkm::cont::make_ArrayHandle(numberOfBinsVec);
|
||||||
|
|
||||||
|
// calculate marginal histogram by the setup (return sparse represetnation)
|
||||||
|
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>> marginalBinIds;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> marginalFreqs;
|
||||||
|
vtkm::worklet::NDimsHistMarginalization ndHistMarginalization;
|
||||||
|
ndHistMarginalization.Run(binIds,
|
||||||
|
freqs,
|
||||||
|
numberOfBins,
|
||||||
|
marginalVariable,
|
||||||
|
VariableCondition(),
|
||||||
|
marginalBinIds,
|
||||||
|
marginalFreqs,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// Ground truth ND histogram
|
||||||
|
vtkm::Id gtNonSparseBins = 40;
|
||||||
|
vtkm::Id gtIdx0[40] = { 0, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4,
|
||||||
|
4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 8, 9 };
|
||||||
|
vtkm::Id gtIdx1[40] = { 1, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 7, 0, 1, 2, 3, 4, 5, 0, 1,
|
||||||
|
2, 3, 4, 5, 7, 8, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 1, 2, 0, 1 };
|
||||||
|
vtkm::Id gtFreq[40] = { 1, 2, 1, 2, 1, 4, 7, 6, 3, 2, 2, 1, 6, 6, 8, 6, 2, 2, 6, 9,
|
||||||
|
10, 2, 5, 1, 1, 1, 6, 7, 9, 6, 3, 3, 2, 3, 2, 2, 3, 2, 1, 1 };
|
||||||
|
|
||||||
|
// Check result
|
||||||
|
vtkm::Id nonSparseBins = marginalBinIds[0].GetPortalControl().GetNumberOfValues();
|
||||||
|
VTKM_TEST_ASSERT(nonSparseBins == gtNonSparseBins,
|
||||||
|
"Incorrect ND-histogram marginalization results");
|
||||||
|
|
||||||
|
for (int i = 0; i < nonSparseBins; i++)
|
||||||
|
{
|
||||||
|
vtkm::Id idx0 = marginalBinIds[0].GetPortalControl().Get(i);
|
||||||
|
vtkm::Id idx1 = marginalBinIds[1].GetPortalControl().Get(i);
|
||||||
|
vtkm::Id f = marginalFreqs.GetPortalControl().Get(i);
|
||||||
|
VTKM_TEST_ASSERT(idx0 == gtIdx0[i] && idx1 == gtIdx1[i] && f == gtFreq[i],
|
||||||
|
"Incorrect ND-histogram marginalization results");
|
||||||
|
}
|
||||||
|
} // TestNDimsHistMarginalization
|
||||||
|
}
|
||||||
|
|
||||||
|
int UnitTestNDimsHistMarginalization(int, char* [])
|
||||||
|
{
|
||||||
|
return vtkm::cont::testing::Testing::Run(TestNDimsHistMarginalization);
|
||||||
|
}
|
141
vtkm/worklet/testing/UnitTestNDimsHistogram.cxx
Normal file
141
vtkm/worklet/testing/UnitTestNDimsHistogram.cxx
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
//============================================================================
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Copyright 2014 Sandia Corporation.
|
||||||
|
// Copyright 2014 UT-Battelle, LLC.
|
||||||
|
// Copyright 2014 Los Alamos National Security.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||||
|
// the U.S. Government retains certain rights in this software.
|
||||||
|
//
|
||||||
|
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||||
|
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||||
|
// this software.
|
||||||
|
//============================================================================
|
||||||
|
|
||||||
|
#include <vtkm/worklet/NDimsHistogram.h>
|
||||||
|
|
||||||
|
#include <vtkm/cont/DataSet.h>
|
||||||
|
#include <vtkm/cont/testing/Testing.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// Make testing dataset with three fields(variables), each one has 100 values
|
||||||
|
vtkm::cont::DataSet MakeTestDataSet()
|
||||||
|
{
|
||||||
|
vtkm::cont::DataSet dataSet;
|
||||||
|
|
||||||
|
const int nVerts = 100;
|
||||||
|
|
||||||
|
vtkm::Float32 fieldA[nVerts] = { 8, 10, 9, 8, 14, 11, 12, 9, 19, 7, 8, 11, 7, 10, 11,
|
||||||
|
11, 11, 6, 8, 8, 7, 15, 9, 7, 8, 10, 9, 10, 10, 12,
|
||||||
|
7, 6, 14, 10, 14, 10, 7, 11, 13, 9, 13, 11, 10, 10, 12,
|
||||||
|
12, 7, 12, 10, 11, 12, 8, 13, 9, 5, 12, 11, 9, 5, 9,
|
||||||
|
12, 9, 6, 10, 11, 9, 9, 11, 9, 7, 7, 18, 16, 13, 12,
|
||||||
|
8, 10, 11, 9, 8, 17, 3, 15, 15, 9, 10, 10, 8, 10, 9,
|
||||||
|
7, 9, 8, 10, 13, 9, 7, 11, 7, 10 };
|
||||||
|
|
||||||
|
vtkm::Float32 fieldB[nVerts] = { 24, 19, 28, 19, 25, 28, 25, 22, 27, 26, 35, 26, 30, 28, 24,
|
||||||
|
23, 21, 31, 20, 11, 21, 22, 14, 25, 20, 24, 24, 21, 24, 29,
|
||||||
|
26, 21, 32, 29, 23, 28, 31, 25, 23, 30, 18, 24, 22, 25, 33,
|
||||||
|
24, 22, 23, 21, 17, 20, 28, 30, 18, 20, 32, 25, 24, 32, 15,
|
||||||
|
27, 24, 27, 19, 30, 27, 17, 24, 29, 23, 22, 19, 24, 19, 28,
|
||||||
|
24, 25, 24, 25, 30, 24, 31, 30, 27, 25, 25, 25, 15, 29, 23,
|
||||||
|
29, 29, 21, 25, 35, 24, 28, 10, 31, 23 };
|
||||||
|
|
||||||
|
vtkm::Float32 fieldC[nVerts] = {
|
||||||
|
3, 1, 4, 6, 5, 4, 8, 7, 2, 9, 2, 0, 0, 4, 3, 2, 5, 2, 3, 6, 3, 8, 3, 4, 3,
|
||||||
|
3, 2, 7, 2, 10, 9, 6, 1, 1, 4, 7, 3, 3, 1, 4, 4, 3, 9, 4, 4, 7, 3, 2, 4, 7,
|
||||||
|
3, 3, 2, 10, 1, 6, 2, 2, 3, 8, 3, 3, 6, 9, 4, 1, 4, 3, 16, 7, 0, 1, 8, 7, 13,
|
||||||
|
3, 5, 0, 3, 8, 10, 3, 5, 5, 1, 5, 2, 1, 3, 2, 5, 3, 4, 3, 3, 3, 3, 1, 13, 2
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set point scalars
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldA", vtkm::cont::Field::ASSOC_POINTS, fieldA, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldB", vtkm::cont::Field::ASSOC_POINTS, fieldB, nVerts));
|
||||||
|
dataSet.AddField(vtkm::cont::Field("fieldC", vtkm::cont::Field::ASSOC_POINTS, fieldC, nVerts));
|
||||||
|
|
||||||
|
return dataSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestNDimsHistogram()
|
||||||
|
{
|
||||||
|
// Create a dataset
|
||||||
|
vtkm::cont::DataSet ds = MakeTestDataSet();
|
||||||
|
|
||||||
|
vtkm::worklet::NDimsHistogram ndHistogram;
|
||||||
|
|
||||||
|
// Set the number of data points
|
||||||
|
ndHistogram.SetNumOfDataPoints(ds.GetField(0).GetData().GetNumberOfValues(),
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// Add field one by one
|
||||||
|
vtkm::Range rangeFieldA;
|
||||||
|
vtkm::Float64 deltaFieldA;
|
||||||
|
ndHistogram.AddField(ds.GetField("fieldA").GetData(),
|
||||||
|
4,
|
||||||
|
rangeFieldA,
|
||||||
|
deltaFieldA,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
vtkm::Range rangeFieldB;
|
||||||
|
vtkm::Float64 deltaFieldB;
|
||||||
|
ndHistogram.AddField(ds.GetField("fieldB").GetData(),
|
||||||
|
4,
|
||||||
|
rangeFieldB,
|
||||||
|
deltaFieldB,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
vtkm::Range rangeFieldC;
|
||||||
|
vtkm::Float64 deltaFieldC;
|
||||||
|
ndHistogram.AddField(ds.GetField("fieldC").GetData(),
|
||||||
|
4,
|
||||||
|
rangeFieldC,
|
||||||
|
deltaFieldC,
|
||||||
|
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// the return binIds and freqs is sparse distribution representation
|
||||||
|
// (we do not keep the 0 frequency entities)
|
||||||
|
// e.g. we have three variable(data arrays) in this example
|
||||||
|
// binIds[0, 1, 2][j] is a combination of bin ID of three variable,
|
||||||
|
// freqs[j] is the freqncy of this bin IDs combination
|
||||||
|
std::vector<vtkm::cont::ArrayHandle<vtkm::Id>> binIds;
|
||||||
|
vtkm::cont::ArrayHandle<vtkm::Id> freqs;
|
||||||
|
ndHistogram.Run(binIds, freqs, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
||||||
|
|
||||||
|
// Ground truth ND histogram
|
||||||
|
vtkm::Id gtNonSparseBins = 33;
|
||||||
|
vtkm::Id gtIdx0[33] = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
|
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3 };
|
||||||
|
vtkm::Id gtIdx1[33] = { 1, 1, 2, 3, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3,
|
||||||
|
0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 1, 1, 2, 2, 2, 3 };
|
||||||
|
vtkm::Id gtIdx2[33] = { 0, 1, 1, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 3,
|
||||||
|
0, 0, 1, 0, 1, 2, 3, 0, 1, 2, 0, 2, 0, 1, 2, 1 };
|
||||||
|
vtkm::Id gtFreq[33] = { 1, 1, 1, 3, 2, 1, 1, 6, 6, 3, 17, 8, 2, 6, 2, 1, 2,
|
||||||
|
1, 1, 4, 11, 4, 1, 1, 3, 3, 1, 1, 1, 1, 1, 2, 1 };
|
||||||
|
|
||||||
|
// Check result
|
||||||
|
vtkm::Id nonSparseBins = binIds[0].GetPortalControl().GetNumberOfValues();
|
||||||
|
VTKM_TEST_ASSERT(nonSparseBins == gtNonSparseBins, "Incorrect ND-histogram results");
|
||||||
|
|
||||||
|
for (int i = 0; i < nonSparseBins; i++)
|
||||||
|
{
|
||||||
|
vtkm::Id idx0 = binIds[0].GetPortalControl().Get(i);
|
||||||
|
vtkm::Id idx1 = binIds[1].GetPortalControl().Get(i);
|
||||||
|
vtkm::Id idx2 = binIds[2].GetPortalControl().Get(i);
|
||||||
|
vtkm::Id f = freqs.GetPortalControl().Get(i);
|
||||||
|
VTKM_TEST_ASSERT(idx0 == gtIdx0[i] && idx1 == gtIdx1[i] && idx2 == gtIdx2[i] && f == gtFreq[i],
|
||||||
|
"Incorrect ND-histogram results");
|
||||||
|
}
|
||||||
|
} // TestNDHistogram
|
||||||
|
}
|
||||||
|
|
||||||
|
int UnitTestNDimsHistogram(int, char* [])
|
||||||
|
{
|
||||||
|
return vtkm::cont::testing::Testing::Run(TestNDimsHistogram);
|
||||||
|
}
|
@ -18,6 +18,7 @@
|
|||||||
// this software.
|
// this software.
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
|
#include <typeinfo>
|
||||||
#include <vtkm/cont/ArrayHandle.h>
|
#include <vtkm/cont/ArrayHandle.h>
|
||||||
#include <vtkm/cont/DataSet.h>
|
#include <vtkm/cont/DataSet.h>
|
||||||
#include <vtkm/cont/DataSetBuilderRectilinear.h>
|
#include <vtkm/cont/DataSetBuilderRectilinear.h>
|
||||||
@ -30,9 +31,6 @@
|
|||||||
#include <vtkm/worklet/particleadvection/Integrators.h>
|
#include <vtkm/worklet/particleadvection/Integrators.h>
|
||||||
#include <vtkm/worklet/particleadvection/Particles.h>
|
#include <vtkm/worklet/particleadvection/Particles.h>
|
||||||
|
|
||||||
|
|
||||||
#include <typeinfo>
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -418,7 +416,7 @@ void TestParticleWorklets()
|
|||||||
typedef vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> FieldHandle;
|
typedef vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> FieldHandle;
|
||||||
typedef FieldHandle::template ExecutionTypes<DeviceAdapter>::PortalConst FieldPortalConstType;
|
typedef FieldHandle::template ExecutionTypes<DeviceAdapter>::PortalConst FieldPortalConstType;
|
||||||
|
|
||||||
FieldType stepSize = 0.01f;
|
FieldType stepSize = 0.05f;
|
||||||
|
|
||||||
vtkm::cont::DataSetBuilderUniform dataSetBuilder;
|
vtkm::cont::DataSetBuilderUniform dataSetBuilder;
|
||||||
|
|
||||||
@ -448,19 +446,45 @@ void TestParticleWorklets()
|
|||||||
RGEvalType eval(ds.GetCoordinateSystem(), ds.GetCellSet(0), fieldArray);
|
RGEvalType eval(ds.GetCoordinateSystem(), ds.GetCellSet(0), fieldArray);
|
||||||
RK4RGType rk4(eval, stepSize);
|
RK4RGType rk4(eval, stepSize);
|
||||||
|
|
||||||
std::vector<vtkm::Vec<FieldType, 3>> pts;
|
for (int i = 0; i < 2; i++)
|
||||||
pts.push_back(vtkm::Vec<FieldType, 3>(1, 1, 1));
|
{
|
||||||
pts.push_back(vtkm::Vec<FieldType, 3>(2, 2, 2));
|
std::vector<vtkm::Vec<FieldType, 3>> pts;
|
||||||
pts.push_back(vtkm::Vec<FieldType, 3>(3, 3, 3));
|
pts.push_back(vtkm::Vec<FieldType, 3>(1, 1, 1));
|
||||||
|
pts.push_back(vtkm::Vec<FieldType, 3>(2, 2, 2));
|
||||||
|
pts.push_back(vtkm::Vec<FieldType, 3>(3, 3, 3));
|
||||||
|
|
||||||
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> seeds;
|
vtkm::Id maxSteps = 100;
|
||||||
seeds = vtkm::cont::make_ArrayHandle(pts);
|
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> seeds;
|
||||||
|
seeds = vtkm::cont::make_ArrayHandle(pts);
|
||||||
|
|
||||||
vtkm::worklet::ParticleAdvection particleAdvection;
|
if (i == 0)
|
||||||
vtkm::worklet::ParticleAdvectionResult<FieldType> res;
|
{
|
||||||
res = particleAdvection.Run(rk4, seeds, 1000, DeviceAdapter());
|
vtkm::worklet::ParticleAdvection particleAdvection;
|
||||||
VTKM_TEST_ASSERT(res.positions.GetNumberOfValues() == seeds.GetNumberOfValues(),
|
vtkm::worklet::ParticleAdvectionResult<FieldType> res;
|
||||||
"Number of output particles does not match input.");
|
res = particleAdvection.Run(rk4, seeds, maxSteps, DeviceAdapter());
|
||||||
|
VTKM_TEST_ASSERT(res.positions.GetNumberOfValues() == seeds.GetNumberOfValues(),
|
||||||
|
"Number of output particles does not match input.");
|
||||||
|
}
|
||||||
|
else if (i == 1)
|
||||||
|
{
|
||||||
|
vtkm::worklet::Streamline streamline;
|
||||||
|
vtkm::worklet::StreamlineResult<FieldType> res;
|
||||||
|
res = streamline.Run(rk4, seeds, maxSteps, DeviceAdapter());
|
||||||
|
|
||||||
|
//Make sure we have the right number of streamlines.
|
||||||
|
VTKM_TEST_ASSERT(res.polyLines.GetNumberOfCells() == seeds.GetNumberOfValues(),
|
||||||
|
"Number of output streamlines does not match input.");
|
||||||
|
|
||||||
|
//Make sure we have the right number of samples in each streamline.
|
||||||
|
vtkm::Id nSeeds = static_cast<vtkm::Id>(pts.size());
|
||||||
|
for (vtkm::Id j = 0; j < nSeeds; j++)
|
||||||
|
{
|
||||||
|
vtkm::Id numPoints = static_cast<vtkm::Id>(res.polyLines.GetNumberOfPointsInCell(j));
|
||||||
|
vtkm::Id numSteps = res.stepsTaken.GetPortalConstControl().Get(j);
|
||||||
|
VTKM_TEST_ASSERT(numPoints == numSteps, "Invalid number of points in streamline.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestParticleAdvection()
|
void TestParticleAdvection()
|
||||||
|
Loading…
Reference in New Issue
Block a user