VTK-m  2.0
ComputePotentialBin.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_compute_potential_bin_h
52 #define vtkm_worklet_cosmotools_compute_potential_bin_h
53 
55 
56 namespace vtkm
57 {
58 namespace worklet
59 {
60 namespace cosmotools
61 {
62 
63 // Worklet for computing the potential for a bin in one halo
64 template <typename T>
66 {
67 public:
69 
70  using ControlSignature = void(FieldIn binId, // (input) bin Id
71  WholeArrayIn binCount, // (input) particles per bin
72  WholeArrayIn binX, // (input) x index in bin
73  WholeArrayIn binY, // (input) y index in bin
74  WholeArrayIn binZ, // (input) z index in bin
75  FieldInOut bestPot, // (output) best potential estimate
76  FieldInOut worstPot); // (output) worst potential estimate
77  using ExecutionSignature = void(_1, _2, _3, _4, _5, _6, _7);
78  using InputDomain = _1;
79 
80  vtkm::Id nBins; // Number of bins
81  T mass; // Particle mass
82  T linkLen; // Linking length is side of bin
83 
84  // Constructor
86  ComputePotentialBin(vtkm::Id N, T Mass, T LinkLen)
87  : nBins(N)
88  , mass(Mass)
89  , linkLen(LinkLen)
90  {
91  }
92 
93  template <typename InIdPortalType>
94  VTKM_EXEC void operator()(const vtkm::Id& i,
95  const InIdPortalType& count,
96  const InIdPortalType& binX,
97  const InIdPortalType& binY,
98  const InIdPortalType& binZ,
99  T& bestPotential,
100  T& worstPotential) const
101  {
102  vtkm::Id ibinX = binX.Get(i);
103  vtkm::Id ibinY = binY.Get(i);
104  vtkm::Id ibinZ = binZ.Get(i);
105 
106  for (vtkm::Id j = 0; j < nBins; j++)
107  {
108  vtkm::Id xDelta = vtkm::Abs(ibinX - binX.Get(j));
109  vtkm::Id yDelta = vtkm::Abs(ibinY - binY.Get(j));
110  vtkm::Id zDelta = vtkm::Abs(ibinZ - binZ.Get(j));
111 
112  if ((count.Get(j) != 0) && (xDelta > 1) && (yDelta > 1) && (zDelta > 1))
113  {
114  T xDistNear = static_cast<T>((xDelta - 1)) * linkLen;
115  T yDistNear = static_cast<T>((yDelta - 1)) * linkLen;
116  T zDistNear = static_cast<T>((zDelta - 1)) * linkLen;
117  T xDistFar = static_cast<T>((xDelta + 1)) * linkLen;
118  T yDistFar = static_cast<T>((yDelta + 1)) * linkLen;
119  T zDistFar = static_cast<T>((zDelta + 1)) * linkLen;
120 
121  T rNear =
122  vtkm::Sqrt((xDistNear * xDistNear) + (yDistNear * yDistNear) + (zDistNear * zDistNear));
123  T rFar = vtkm::Sqrt((xDistFar * xDistFar) + (yDistFar * yDistFar) + (zDistFar * zDistFar));
124 
125  if (rFar > 0.00000000001f)
126  {
127  worstPotential -= (static_cast<T>(count.Get(j)) * mass) / rFar;
128  }
129  if (rNear > 0.00000000001f)
130  {
131  bestPotential -= (static_cast<T>(count.Get(j)) * mass) / rNear;
132  }
133  }
134  }
135  }
136 }; // ComputePotentialBin
137 }
138 }
139 }
140 
141 #endif
vtkm::Sqrt
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
vtkm::worklet::cosmotools::ComputePotentialBin::ComputePotentialBin
VTKM_EXEC_CONT ComputePotentialBin(vtkm::Id N, T Mass, T LinkLen)
Definition: ComputePotentialBin.h:86
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
WorkletMapField.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::worklet::cosmotools::ComputePotentialBin::InputDomain
_1 InputDomain
Definition: ComputePotentialBin.h:78
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::cosmotools::ComputePotentialBin::nBins
vtkm::Id nBins
Definition: ComputePotentialBin.h:80
vtkm::worklet::cosmotools::ComputePotentialBin
Definition: ComputePotentialBin.h:65
vtkm::worklet::cosmotools::ComputePotentialBin::linkLen
T linkLen
Definition: ComputePotentialBin.h:82
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::WorkletMapField::FieldInOut
A control signature tag for input-output (in-place) fields.
Definition: WorkletMapField.h:71
vtkm::worklet::cosmotools::ComputePotentialBin::operator()
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
Definition: ComputePotentialBin.h:94
vtkm::worklet::cosmotools::ComputePotentialBin::ControlSignature
void(FieldIn binId, WholeArrayIn binCount, WholeArrayIn binX, WholeArrayIn binY, WholeArrayIn binZ, FieldInOut bestPot, FieldInOut worstPot) ControlSignature
Definition: ComputePotentialBin.h:76
vtkm::worklet::cosmotools::ComputePotentialBin::ExecutionSignature
void(_1, _2, _3, _4, _5, _6, _7) ExecutionSignature
Definition: ComputePotentialBin.h:77
vtkm::worklet::cosmotools::ComputePotentialBin::mass
T mass
Definition: ComputePotentialBin.h:81
vtkm::List
Definition: List.h:34
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38