Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
PDESRandomNumberGeneratorService.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* PDESRandomNumberGeneratorService.cc (C) 2000-2022 */
9/* */
10/* Implementation of an LCG random number generator. */
11/* Inspired by the Quicksilver generator (LLNL) and pages 302-304 */
12/* from the book: */
13/* */
14/* Numerical Recipes in C */
15/* The Art of Scientific Computing */
16/* Second Edition */
17/*---------------------------------------------------------------------------*/
18#ifndef ARCANE_STD_PDESRANDOMNUMBERGENERATORSERVICE_H
19#define ARCANE_STD_PDESRANDOMNUMBERGENERATORSERVICE_H
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23#include "arcane/core/IRandomNumberGenerator.h"
24#include "arcane/std/PDESRandomNumberGenerator_axl.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35class PDESRandomNumberGeneratorService
37{
38 public:
39
40 PDESRandomNumberGeneratorService(const ServiceBuildInfo& sbi)
42 , m_seed(4294967297)
43 {
44 m_with_option = (sbi.creationType() == ST_CaseOption);
45 }
46
47 virtual ~PDESRandomNumberGeneratorService() {};
48
49 public:
50
51 bool initSeed() override;
52 bool initSeed(ByteArrayView seed) override;
53
54 ByteUniqueArray emptySeed() override;
56
57 Integer neededSizeOfSeed() override;
58
59 bool isLeapSeedSupported() override { return true; };
61 ByteUniqueArray generateRandomSeed(ByteArrayView parent_seed, Integer leap = 0) override;
62
63 bool isLeapNumberSupported() override { return true; };
64 Real generateRandomNumber(Integer leap) override;
65 Real generateRandomNumber(ByteArrayView seed, Integer leap = 0) override;
66
67 protected:
68
69 void _breakupUInt64(uint64_t uint64_in, uint32_t* front_bits, uint32_t* back_bits);
70 uint64_t _reconstructUInt64(uint32_t front_bits, uint32_t back_bits);
71 void _psdes(uint32_t* lword, uint32_t* irword);
72 uint64_t _hashState(uint64_t initial_number);
73 Real _ran4(Int64* seed, Integer leap);
74
75 protected:
76
77 Int64 m_seed;
78 const Integer m_size_of_seed = sizeof(Int64);
79 bool m_with_option;
80};
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85ARCANE_REGISTER_SERVICE_PDESRANDOMNUMBERGENERATOR(PDESRandomNumberGenerator, PDESRandomNumberGeneratorService);
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90} // End namespace Arcane
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95#endif
ArcanePDESRandomNumberGeneratorObject(const Arcane::ServiceBuildInfo &sbi)
Constructeur.
ByteConstArrayView viewSeed() override
Method allowing retrieval of a constant view of the current seed.
ByteUniqueArray generateRandomSeed(Integer leap=0) override
Method allowing generation of a "child" seed from a "parent" seed.
uint64_t _hashState(uint64_t initial_number)
Method to generate a new seed using the pseudo-DES algorithm.
Real generateRandomNumber(Integer leap) override
Method allowing generation of a random number using the seed in memory.
Integer neededSizeOfSeed() override
Method allowing knowledge of the seed size required for the implementation.
bool initSeed() override
Method allowing initialization of the service.
bool isLeapNumberSupported() override
Method allowing knowledge if leaps are allowed on the number generator.
void _psdes(uint32_t *lword, uint32_t *irword)
Pseudo-DES algorithm from the book: Numerical Recipes in C The Art of Scientific Computing Second Edi...
uint64_t _reconstructUInt64(uint32_t front_bits, uint32_t back_bits)
Method to combine two uint32s into a uint64.
ByteUniqueArray emptySeed() override
Method allowing retrieval of an empty seed of the correct size.
bool isLeapSeedSupported() override
Method allowing knowledge if leaps are allowed on the seed generator.
void _breakupUInt64(uint64_t uint64_in, uint32_t *front_bits, uint32_t *back_bits)
Method to split a uint64 into two uint32s.
Real _ran4(Int64 *seed, Integer leap)
Method to generate pseudo-random numbers from a seed.
eServiceType creationType() const
Type of service that can be created by this instance.
Structure containing the information to create a service.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
Definition UtilsTypes.h:447
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
@ ST_CaseOption
The service is used at the dataset level.
UniqueArray< Byte > ByteUniqueArray
Dynamic 1D array of characters.
Definition UtilsTypes.h:335
double Real
Type representing a real number.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
Definition UtilsTypes.h:476