VTK-m  2.0
cosmotools/CosmoTools.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 // Copyright (c) 2016, Los Alamos National Security, LLC
11 // All rights reserved.
12 //
13 // Copyright 2016. Los Alamos National Security, LLC.
14 // This software was produced under U.S. Government contract DE-AC52-06NA25396
15 // for Los Alamos National Laboratory (LANL), which is operated by
16 // Los Alamos National Security, LLC for the U.S. Department of Energy.
17 // The U.S. Government has rights to use, reproduce, and distribute this
18 // software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, LLC
19 // MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE
20 // USE OF THIS SOFTWARE. If software is modified to produce derivative works,
21 // such modified software should be clearly marked, so as not to confuse it
22 // with the version available from LANL.
23 //
24 // Additionally, redistribution and use in source and binary forms, with or
25 // without modification, are permitted provided that the following conditions
26 // are met:
27 //
28 // 1. Redistributions of source code must retain the above copyright notice,
29 // this list of conditions and the following disclaimer.
30 // 2. Redistributions in binary form must reproduce the above copyright notice,
31 // this list of conditions and the following disclaimer in the documentation
32 // and/or other materials provided with the distribution.
33 // 3. Neither the name of Los Alamos National Security, LLC, Los Alamos
34 // National Laboratory, LANL, the U.S. Government, nor the names of its
35 // contributors may be used to endorse or promote products derived from
36 // this software without specific prior written permission.
37 //
38 // THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND
39 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
40 // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS
42 // NATIONAL SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
48 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 //============================================================================
50 
51 #ifndef vtkm_worklet_cosmotools_cosmotools_h
52 #define vtkm_worklet_cosmotools_cosmotools_h
53 
63 
72 
73 #include <vtkm/cont/Algorithm.h>
80 #include <vtkm/cont/Invoker.h>
82 
83 #include <vtkm/BinaryPredicates.h>
84 #include <vtkm/Math.h>
85 
86 #include <algorithm>
87 #include <cmath>
88 #include <cstdlib>
89 #include <iomanip>
90 #include <iostream>
91 
92 namespace
93 {
94 
96 //
97 // Debug prints
98 //
100 template <typename U>
101 void DebugPrint(const char* msg, vtkm::cont::ArrayHandle<U>& array)
102 {
103  vtkm::Id count = 20;
104  count = std::min(count, array.GetNumberOfValues());
105  auto portal = array.ReadPortal();
106  std::cout << std::setw(15) << msg << ": ";
107  for (vtkm::Id i = 0; i < count; i++)
108  std::cout << std::setprecision(3) << std::setw(5) << portal.Get(i) << " ";
109  std::cout << std::endl;
110 }
111 
112 template <typename U>
113 void DebugPrint(const char* msg, vtkm::cont::ArrayHandleReverse<vtkm::cont::ArrayHandle<U>>& array)
114 {
115  vtkm::Id count = 20;
116  count = std::min(count, array.GetNumberOfValues());
117  auto portal = array.ReadPortal();
118  std::cout << std::setw(15) << msg << ": ";
119  for (vtkm::Id i = 0; i < count; i++)
120  std::cout << std::setw(5) << portal.Get(i) << " ";
121  std::cout << std::endl;
122 }
123 }
124 
125 namespace vtkm
126 {
127 namespace worklet
128 {
129 namespace cosmotools
130 {
131 
132 
134 //
135 // Scatter the result of a reduced array
136 //
138 template <typename T>
140 {
141  using ControlSignature = void(FieldIn inIndices, FieldOut outIndices);
142  using ExecutionSignature = void(_1, _2);
144 
145  VTKM_EXEC
146  void operator()(T inputIndex, T& outputIndex) const { outputIndex = inputIndex; }
147 };
148 
150 //
151 // Scale or offset values of an array
152 //
154 template <typename T>
156 {
157  T Scale;
158  T Bias;
159 
160  VTKM_CONT
161  ScaleBiasFunctor(T scale = T(1), T bias = T(0))
162  : Scale(scale)
163  , Bias(bias)
164  {
165  }
166 
168  T operator()(T value) const { return (Scale * value + Bias); }
169 };
170 
171 template <typename T, typename StorageType>
173 {
174 public:
177 
178  // geometry of domain
180  const T particleMass;
182  const T linkLen;
186 
187  // particle locations within domain
192 
193  // cosmo tools constructor for all particles
194  CosmoTools(const vtkm::Id NParticles, // Number of particles
195  const T mass, // Particle mass for potential
196  const vtkm::Id pmin, // Minimum particles per halo
197  const T bb, // Linking length between particles
198  vtkm::cont::ArrayHandle<T, StorageType>& X, // Physical location of each particle
201 
202  // cosmo tools constructor for particles in one halo
203  CosmoTools(const vtkm::Id NParticles, // Number of particles
204  const T mass, // Particle mass for potential
205  vtkm::cont::ArrayHandle<T, StorageType>& X, // Physical location of each particle
209 
210  // Halo finding and center finding on halos
213  vtkm::cont::ArrayHandle<T>& resultPot);
216  vtkm::cont::ArrayHandle<vtkm::Id>& leftNeighbor,
217  vtkm::cont::ArrayHandle<vtkm::Id>& rightNeighbor);
221  vtkm::cont::ArrayHandle<T>& minPotential);
222 
223  // MBP Center finding on single halo using NxN algorithm
224  vtkm::Id MBPCenterFinderNxN(T* nxnPotential);
225 
226  // MBP Center finding on single halo using MxN estimation
227  vtkm::Id MBPCenterFinderMxN(T* mxnPotential);
228 
233  vtkm::cont::ArrayHandle<vtkm::Id>& particleOffset,
239  vtkm::cont::ArrayHandle<T>& minPotential);
240 };
241 
243 //
244 // Constructor for all particles in the system
245 //
247 template <typename T, typename StorageType>
249  const T mass,
250  const vtkm::Id pmin,
251  const T bb,
255  : nParticles(NParticles)
256  , particleMass(mass)
257  , minPartPerHalo(pmin)
258  , linkLen(bb)
259  , xLoc(X)
260  , yLoc(Y)
261  , zLoc(Z)
262 {
263 }
264 
266 //
267 // Constructor for particles in a single halo
268 //
270 template <typename T, typename StorageType>
272  const T mass,
276  : nParticles(NParticles)
277  , particleMass(mass)
278  , minPartPerHalo(10)
279  , linkLen(0.2f)
280  , xLoc(X)
281  , yLoc(Y)
282  , zLoc(Z)
283 {
284 }
285 }
286 }
287 }
288 #endif
vtkm::worklet::cosmotools::CosmoTools::particleMass
const T particleMass
Definition: cosmotools/CosmoTools.h:180
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
vtkm::worklet::cosmotools::CosmoTools::numBinsZ
vtkm::Id numBinsZ
Definition: cosmotools/CosmoTools.h:185
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::cosmotools::CosmoTools::yLoc
LocationType & yLoc
Definition: cosmotools/CosmoTools.h:190
vtkm::worklet::cosmotools::CosmoTools::CosmoTools
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)
Definition: cosmotools/CosmoTools.h:248
ComputePotentialBin.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::worklet::cosmotools::CosmoTools::xLoc
LocationType & xLoc
Definition: cosmotools/CosmoTools.h:189
vtkm::worklet::cosmotools::CosmoTools::nParticles
const vtkm::Id nParticles
Definition: cosmotools/CosmoTools.h:179
ArrayHandleCompositeVector.h
vtkm::worklet::cosmotools::CosmoTools::~CosmoTools
~CosmoTools()
Definition: cosmotools/CosmoTools.h:208
ArrayHandleTransform.h
ComputeNeighborBins.h
SetCandidateParticles.h
ArrayHandleConstant.h
vtkm::worklet::cosmotools::CosmoTools::numBinsX
vtkm::Id numBinsX
Definition: cosmotools/CosmoTools.h:183
Invoker.h
vtkm::worklet::cosmotools::CosmoTools::NUM_NEIGHBORS
const vtkm::Id NUM_NEIGHBORS
Definition: cosmotools/CosmoTools.h:176
vtkm::worklet::cosmotools::CosmoTools::minPartPerHalo
const vtkm::Id minPartPerHalo
Definition: cosmotools/CosmoTools.h:181
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ScatterCounting.h
ComputePotential.h
vtkm::worklet::cosmotools::ScatterWorklet::operator()
VTKM_EXEC void operator()(T inputIndex, T &outputIndex) const
Definition: cosmotools/CosmoTools.h:146
vtkm::worklet::cosmotools::ScatterWorklet
Definition: cosmotools/CosmoTools.h:139
vtkm::worklet::cosmotools::ScaleBiasFunctor::Scale
T Scale
Definition: cosmotools/CosmoTools.h:157
vtkm::worklet::ScatterCounting
A scatter that maps input to some numbers of output.
Definition: ScatterCounting.h:44
ComputePotentialOnCandidates.h
IsStar.h
X
#define X
Definition: ClipTables.h:2430
vtkm::worklet::cosmotools::ScaleBiasFunctor::ScaleBiasFunctor
VTKM_CONT ScaleBiasFunctor(T scale=T(1), T bias=T(0))
Definition: cosmotools/CosmoTools.h:161
Math.h
Algorithm.h
vtkm::worklet::cosmotools::ScatterWorklet::ExecutionSignature
void(_1, _2) ExecutionSignature
Definition: cosmotools/CosmoTools.h:142
GraftParticles.h
ComputePotentialMxN.h
vtkm::worklet::cosmotools::CosmoTools::zLoc
LocationType & zLoc
Definition: cosmotools/CosmoTools.h:191
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
ArrayHandleIndex.h
vtkm::worklet::cosmotools::CosmoTools
Definition: cosmotools/CosmoTools.h:172
MarkActiveNeighbors.h
vtkm::worklet::cosmotools::CosmoTools::numBinsY
vtkm::Id numBinsY
Definition: cosmotools/CosmoTools.h:184
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
ComputePotentialNeighbors.h
ComputeBinIndices.h
ValidHalo.h
vtkm::worklet::cosmotools::CosmoTools::linkLen
const T linkLen
Definition: cosmotools/CosmoTools.h:182
vtkm::cont::Algorithm
Definition: Algorithm.h:385
vtkm::worklet::cosmotools::CosmoTools::BinParticlesAll
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)
Definition: CosmoToolsHaloFinder.h:189
vtkm::worklet::cosmotools::ScaleBiasFunctor
Definition: cosmotools/CosmoTools.h:155
vtkm::worklet::cosmotools::ScaleBiasFunctor::operator()
VTKM_EXEC_CONT T operator()(T value) const
Definition: cosmotools/CosmoTools.h:168
vtkm::worklet::cosmotools::CosmoTools::HaloFinder
void HaloFinder(vtkm::cont::ArrayHandle< vtkm::Id > &resultHaloId, vtkm::cont::ArrayHandle< vtkm::Id > &resultMBP, vtkm::cont::ArrayHandle< T > &resultPot)
Definition: CosmoToolsHaloFinder.h:72
vtkm::cont::ArrayHandle::ReadPortal
VTKM_CONT ReadPortalType ReadPortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:414
ArrayHandleCounting.h
BinaryPredicates.h
ComputeBins.h
vtkm::cont::ArrayHandleReverse
Reverse the order of an array, on demand.
Definition: ArrayHandleReverse.h:147
vtkm::worklet::cosmotools::CosmoTools::MBPCenterFinderMxN
vtkm::Id MBPCenterFinderMxN(T *mxnPotential)
Definition: CosmoToolsCenterFinder.h:73
EqualsMinimumPotential.h
vtkm::worklet::cosmotools::CosmoTools::LocationType
typename vtkm::cont::ArrayHandle< T, StorageType > LocationType
Definition: cosmotools/CosmoTools.h:188
vtkm::worklet::cosmotools::CosmoTools::MBPCenterFindingByKey
void MBPCenterFindingByKey(vtkm::cont::ArrayHandle< vtkm::Id > &keyId, vtkm::cont::ArrayHandle< vtkm::Id > &partId, vtkm::cont::ArrayHandle< T > &minPotential)
Definition: CosmoToolsCenterFinder.h:303
ComputeBinRange.h
ArrayHandleReverse.h
vtkm::worklet::cosmotools::ScaleBiasFunctor::Bias
T Bias
Definition: cosmotools/CosmoTools.h:158
PointerJump.h
vtkm::worklet::cosmotools::CosmoTools::BinParticlesHalo
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)
Definition: CosmoToolsCenterFinder.h:197
vtkm::worklet::cosmotools::CosmoTools::MBPCenterFindingByHalo
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)
Definition: CosmoToolsHaloFinder.h:287
ComputePotentialNxN.h
vtkm::worklet::cosmotools::CosmoTools::MBPCenterFinderNxN
vtkm::Id MBPCenterFinderNxN(T *nxnPotential)
Definition: CosmoToolsCenterFinder.h:381
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
vtkm::worklet::cosmotools::ScatterWorklet::ControlSignature
void(FieldIn inIndices, FieldOut outIndices) ControlSignature
Definition: cosmotools/CosmoTools.h:141