pops-core  0.9
PoPS (Pest or Pathogen Spread) Model Core C++ library
neighbor_kernel.hpp
Go to the documentation of this file.
1 /*
2  * PoPS model - deterministic neighbor dispersal kernel
3  *
4  * Copyright (C) 2020 by the authors.
5  *
6  * Authors: Vaclav Petras (wenzeslaus gmail com)
7  *
8  * The code contained herein is licensed under the GNU General Public
9  * License. You may obtain a copy of the GNU General Public License
10  * Version 2 or later at the following locations:
11  *
12  * http://www.opensource.org/licenses/gpl-license.html
13  * http://www.gnu.org/copyleft/gpl.html
14  */
15 
16 #ifndef POPS_NEIGHBOR_KERNEL_HPP
17 #define POPS_NEIGHBOR_KERNEL_HPP
18 
19 #include "kernel_types.hpp"
20 #include "radial_kernel.hpp"
21 #include "utils.hpp"
22 
23 namespace pops {
24 
36 {
37 protected:
39 
40 public:
53  : direction_(dispersal_direction)
54  {}
55 
61  template<typename Generator>
62  std::tuple<int, int> operator()(Generator& generator, int row, int col)
63  {
64  UNUSED(generator); // Deterministic does not need random numbers.
65  switch (direction_) {
66  case Direction::E:
67  col += 1;
68  break;
69  case Direction::N:
70  row -= 1;
71  break;
72  case Direction::NE:
73  row -= 1;
74  col += 1;
75  break;
76  case Direction::NW:
77  row -= 1;
78  col -= 1;
79  break;
80  case Direction::S:
81  row += 1;
82  break;
83  case Direction::SE:
84  row += 1;
85  col += 1;
86  break;
87  case Direction::SW:
88  row += 1;
89  col -= 1;
90  break;
91  case Direction::W:
92  col -= 1;
93  break;
94  default:
95  throw std::invalid_argument(
96  "NeighborDispersalKernel: Unsupported Direction");
97  }
98  return std::make_tuple(row, col);
99  }
100 
103  static bool supports_kernel(const DispersalKernelType type)
104  {
106  return true;
107  return false;
108  }
109 };
110 
111 } // namespace pops
112 
113 #endif // POPS_NEIGHBOR_KERNEL_HPP
Direction::NW
@ NW
Northwest.
pops::DeterministicNeighborDispersalKernel::DeterministicNeighborDispersalKernel
DeterministicNeighborDispersalKernel(Direction dispersal_direction)
Creates kernel based on the spread direction.
Definition: neighbor_kernel.hpp:52
utils.hpp
pops::DeterministicNeighborDispersalKernel::operator()
std::tuple< int, int > operator()(Generator &generator, int row, int col)
Generates a new position for the spread.
Definition: neighbor_kernel.hpp:62
radial_kernel.hpp
Direction::W
@ W
West.
pops::DispersalKernelType::DeterministicNeighbor
@ DeterministicNeighbor
Deterministic immediate neighbor dispersal kernel.
Direction::SW
@ SW
Southwest.
pops::DispersalKernelType
DispersalKernelType
Type of dispersal kernel.
Definition: kernel_types.hpp:53
UNUSED
#define UNUSED(expr)
Macro to mark unused variables (including parameters) and silence the warning while documenting that ...
Definition: utils.hpp:33
pops::DeterministicNeighborDispersalKernel::supports_kernel
static bool supports_kernel(const DispersalKernelType type)
Returns true if the kernel class support a given kernel type.
Definition: neighbor_kernel.hpp:103
pops
Definition: cauchy_kernel.hpp:25
Direction::E
@ E
East.
Direction::SE
@ SE
Southeast.
pops::DeterministicNeighborDispersalKernel
Dispersal kernel for deterministic spread to a next cell.
Definition: neighbor_kernel.hpp:35
Direction::N
@ N
North.
Direction::NE
@ NE
Northeast.
kernel_types.hpp
Kernel types enum and helper functions.
Direction::S
@ S
South.
pops::DeterministicNeighborDispersalKernel::direction_
Direction direction_
Definition: neighbor_kernel.hpp:38
Direction
Direction
Spread direction.
Definition: utils.hpp:83