EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
/Users/marc/Developer/EGSnrc/HEN_HOUSE/user_codes/egs_brachy/egs_brachy/egs_sobol.cpp
Go to the documentation of this file.
1/*
2###############################################################################
3#
4# EGSnrc egs++ envelope geometry headers
5# Copyright (C) 2015 National Research Council Canada
6#
7# This file is part of EGSnrc.
8#
9# EGSnrc is free software: you can redistribute it and/or modify it under
10# the terms of the GNU Affero General Public License as published by the
11# Free Software Foundation, either version 3 of the License, or (at your
12# option) any later version.
13#
14# EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17# more details.
18#
19# You should have received a copy of the GNU Affero General Public License
20# along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21#
22###############################################################################
23#
24# Author: Randle Taylor (randle.taylor@gmail.com) on behalf of
25# the Carleton Laboratory for Radiotherapy Physics
26#
27# Contributors:
28#
29###############################################################################
30*/
31
38#include "egs_sobol.h"
39
41 if (copy) {
42 copy->setState(this);
43 }
44 else {
45 copy = new EGS_Sobol(*this);
46 }
47 copy->copy = 0;
48}
49
51 if (copy) {
53 }
54}
55
56EGS_RandomGenerator *EGS_Sobol::getCopy() {
59 return c;
60}
61
62void EGS_Sobol::setState(EGS_RandomGenerator *r) {
63
64 EGS_Sobol *r1 = dynamic_cast<EGS_Sobol *>(r);
65 if (!r1) {
66 egsFatal("EGS_Sobol::setState: attampt to set my state by a non EGS_Sobol RNG!\n");
67 }
68
69 cur_seed = r1->cur_seed;
70 dim = r1->dim;
71 np = dim;
72}
73
74bool EGS_Sobol::storePrivateState(ostream &data) {
75
76 if (!egsStoreI64(data, count)) {
77 return false;
78 }
79
80 if (!egsStoreI64(data, cur_seed)) {
81 return false;
82 }
83
84 data << dim << "\n";
85
86 return data.good();
87}
88
89bool EGS_Sobol::setPrivateState(istream &data) {
90
91 if (!egsGetI64(data, count)) {
92 return false;
93 }
94
95 if (!egsGetI64(data, cur_seed)) {
96 return false;
97 }
98
99 int dimension;
100 data >> dimension;
101
102 setState(dimension, cur_seed);
103
104 return data.good();
105}
106
107
109 egsInformation("Random number generator:\n"
110 "============================================\n");
111 egsInformation(" type = Sobol\n");
112 egsInformation(" dimensions = %d\n", dim);
113 egsInformation(" initial seed = %lld\n", init_seed);
114 egsInformation(" current seed = %lld\n", cur_seed);
115 egsInformation(" numbers used so far = %lld\n", count);
116}
117
118void EGS_Sobol::setState(int dimension, EGS_I64 seed) {
119
120 cur_seed = seed;
121
122 if (dimension < 0 || dimension > 3) {
123 dim = 3;
124 }
125 else {
126 dim = dimension;
127 }
128}
129
130void EGS_Sobol::fillArray(int n, EGS_Float *array) {
131 // note cur_seed gets updated each call to i8_sobol
132 sobol::i8_sobol(dim, &cur_seed, array);
133 count += dim; // we generate dim number every call
134}
135
EGS_RandomGenerator wrapper for Sobol library.
Definition egs_sobol.h:71
void saveState()
Definition egs_sobol.cpp:40
bool setPrivateState(istream &data)
Definition egs_sobol.cpp:89
void describeRNG() const
Output information about this RNG using egsInformation()
void fillArray(int n, EGS_Float *array)
Fill the array pointed to by array with random numbers.
EGS_RandomGenerator * getCopy()
Definition egs_sobol.cpp:56
void setState(EGS_RandomGenerator *r)
Definition egs_sobol.cpp:62
EGS_I64 cur_seed
initial seed for random number generator
Definition egs_sobol.h:157
void resetState()
Definition egs_sobol.cpp:50
EGS_Sobol * copy
current seed being used for random number generator (required to reinitialize
Definition egs_sobol.h:159
bool storePrivateState(ostream &data)
Definition egs_sobol.cpp:74
EGS_I64 init_seed
Definition egs_sobol.h:156
Header file for EGS_Sobol (EGS_RandomGenerator wrapper for Sobol QRNG)
void i8_sobol(int dim_num, long long int *seed, double quasi[])
Definition sobol.cpp:14163