Merge topic 'cosmo-tools'
e9f9a3d8 remove setting of DeveiceAdapter from cosmotools worklet cdf84ccb Add sample input 6ca2683f Remove the data file for examples f3766449 Cosmology halo finder Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !919
This commit is contained in:
commit
2052f40719
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(contour_tree)
|
||||
add_subdirectory(cosmotools)
|
||||
add_subdirectory(demo)
|
||||
add_subdirectory(dynamic_dispatcher)
|
||||
add_subdirectory(game_of_life)
|
||||
#add_subdirectory(game_of_life)
|
||||
add_subdirectory(hello_world)
|
||||
add_subdirectory(isosurface)
|
||||
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"
|
@ -24,6 +24,7 @@ set(headers
|
||||
CellDeepCopy.h
|
||||
Clip.h
|
||||
ContourTreeUniform.h
|
||||
CosmoTools.h
|
||||
DispatcherMapField.h
|
||||
DispatcherMapTopology.h
|
||||
DispatcherPointNeighborhood.h
|
||||
@ -70,6 +71,7 @@ set(headers
|
||||
#-----------------------------------------------------------------------------
|
||||
add_subdirectory(internal)
|
||||
add_subdirectory(contourtree)
|
||||
add_subdirectory(cosmotools)
|
||||
add_subdirectory(gradient)
|
||||
add_subdirectory(splatkernels)
|
||||
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
|
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
|
@ -25,6 +25,7 @@ set(unit_tests
|
||||
UnitTestCellGradient.cxx
|
||||
UnitTestClipping.cxx
|
||||
UnitTestContourTreeUniform.cxx
|
||||
UnitTestCosmoTools.cxx
|
||||
UnitTestExternalFaces.cxx
|
||||
UnitTestExtractGeometry.cxx
|
||||
UnitTestExtractPoints.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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user