KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
prime_numbers.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 //
13 
14 #if !defined(KRATOS_PRIME_NUMBERS_H_INCLUDED )
15 #define KRATOS_PRIME_NUMBERS_H_INCLUDED
16 
17 
18 
19 // System includes
20 #include <string>
21 #include <iostream>
22 #include <array>
23 
24 // Project includes
25 #include "includes/exception.h"
26 
27 namespace Kratos
28 {
31 
34 
36 
39  {
42 
43  static constexpr std::size_t mNumberOfPreCalculatedPrimes = 100000;
44 
45  static constexpr std::size_t mLargestPreCalculatedPrime = 1299689;
46 
48  public:
51 
55 
58 
60  PrimeNumbers(PrimeNumbers const& rOther) = delete;
61 
63  virtual ~PrimeNumbers(){}
64 
65 
69 
71  PrimeNumbers& operator=(PrimeNumbers const& rOther) = delete;
72 
73  std::size_t operator[](std::size_t Index) {
75  }
76 
80 
81 
85 
86  static std::size_t GetNumberOfPreCalculatedPrimes() {
87  return mNumberOfPreCalculatedPrimes;
88  }
89 
90  static std::size_t LargestPreCalculatedPrime() {
91  return mLargestPreCalculatedPrime;
92  }
93 
94  static std::size_t GetPreCalculatedPrime(std::size_t Index) {
95  KRATOS_DEBUG_ERROR_IF(Index >= mNumberOfPreCalculatedPrimes) << "Index " << Index
96  << " is larger than Number of precalculated primes " << mNumberOfPreCalculatedPrimes << std::endl;
97  return mPrecalculatedPrimes[Index];
98  }
99 
103 
104  static bool IsPrime(std::size_t TheNumber);
105 
106 
110 
111 
113 
114  private:
117 
118  static const std::array<std::size_t, mNumberOfPreCalculatedPrimes> mPrecalculatedPrimes;
119 
123 
124  static std::size_t FindGreaterEqualPrecalculatedPrimeNumber(std::size_t TheNumber);
125 
127 
128  }; // Class PrimeNumbers
129 
131 
133 
134 } // namespace Kratos.
135 
136 #endif // KRATOS_PRIME_NUMBERS_H_INCLUDED defined
Gives a prime number before or after given number.
Definition: prime_numbers.h:39
static bool IsPrime(std::size_t TheNumber)
Definition: prime_numbers.cpp:32
static std::size_t GetNumberOfPreCalculatedPrimes()
Definition: prime_numbers.h:86
PrimeNumbers(PrimeNumbers const &rOther)=delete
Copy constructor.
PrimeNumbers()
Default constructor.
Definition: prime_numbers.h:57
static std::size_t GetPreCalculatedPrime(std::size_t Index)
Definition: prime_numbers.h:94
PrimeNumbers & operator=(PrimeNumbers const &rOther)=delete
Assignment operator.
std::size_t operator[](std::size_t Index)
Definition: prime_numbers.h:73
static std::size_t LargestPreCalculatedPrime()
Definition: prime_numbers.h:90
virtual ~PrimeNumbers()
Destructor.
Definition: prime_numbers.h:63
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
def Index()
Definition: hdf5_io_tools.py:38