Arcane  v3.16.8.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
UniformOnSphere.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* UniformOnSphere.h (C) 2000-2025 */
9/* */
10/* Randomiser 'Uniform0nSphere'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_CORE_RANDOM_UNIFORMONSPHERE_H
14#define ARCANE_CORE_RANDOM_UNIFORMONSPHERE_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/FatalErrorException.h"
19#include "arcane/utils/Real3.h"
20
21#include "arcane/core/random/NormalDistribution.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane::random
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32/*
33 * Copyright Jens Maurer 2000-2001
34 * Permission to use, copy, modify, sell, and distribute this software
35 * is hereby granted without fee provided that the above copyright notice
36 * appears in all copies and that both that copyright notice and this
37 * permission notice appear in supporting documentation,
38 *
39 * Jens Maurer makes no representations about the suitability of this
40 * software for any purpose. It is provided "as is" without express or
41 * implied warranty.
42 *
43 * See http://www.boost.org for most recent version including documentation.
44 *
45 * $Id: UniformOnSphere.h 7934 2007-01-16 08:49:47Z grospelx $
46 *
47 * Revision history
48 * 2001-02-18 moved to individual header files
49 */
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
54template<class UniformRandomNumberGenerator>
55class UniformOnSphere
56{
57 public:
58 typedef UniformRandomNumberGenerator base_type;
59 typedef Real3 result_type;
60
61 explicit UniformOnSphere(base_type & rng)
62 : _rng(rng) { }
63
64 typedef typename base_type::result_type base_result;
65 Real3 applyDim3()
66 {
67 Real results[3];
68 Real sqsum = 0;
69 for( Integer i=0; i<3; ++i ){
70 Real val = _rng();
71 val += 1.0e-16;
72 results[i] = val;
73 //cout << " VAL " << i << " =" << val << '\n';
74 sqsum += val * val;
75 }
76 //cout << " SQSUM " << sqsum << '\n';
77 Real inv_sqrt_sqsum = 1. / math::sqrt(sqsum);
78 //cout << " INV_SQSUM " << inv_sqrt_sqsum << '\n';
79 for( Integer i=0; i<3; ++i ){
80 results[i] *= inv_sqrt_sqsum;
81 }
82 return Real3(results[0],results[1],results[2]);
83 }
84 private:
85
87};
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
97#endif
Classe gérant un vecteur de réel de dimension 3.
Definition Real3.h:132
__host__ __device__ double sqrt(double v)
Racine carrée de v.
Definition Math.h:135
Int32 Integer
Type représentant un entier.
double Real
Type représentant un réel.