Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
211bb053
Commit
211bb053
authored
10 years ago
by
Henry
Browse files
Options
Downloads
Patches
Plain Diff
Random: clean-up
parent
ec41a4cc
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/OpenFOAM/primitives/random/Random/Random.C
+16
-29
16 additions, 29 deletions
src/OpenFOAM/primitives/random/Random/Random.C
with
16 additions
and
29 deletions
src/OpenFOAM/primitives/random/Random/Random.C
+
16
−
29
View file @
211bb053
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
========= |
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011
-2015
OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation |
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
License
License
...
@@ -28,21 +28,15 @@ License
...
@@ -28,21 +28,15 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace
Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#if INT_MAX != 2147483647
#if INT_MAX != 2147483647
# error "INT_MAX != 2147483647"
# error "INT_MAX != 2147483647"
# error "The random number generator may not work!"
# error "The random number generator may not work!"
#endif
#endif
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Random
::
Random
(
const
label
seed
)
Foam
::
Random
::
Random
(
const
label
seed
)
{
{
if
(
seed
>
1
)
if
(
seed
>
1
)
{
{
...
@@ -57,7 +51,7 @@ Random::Random(const label seed)
...
@@ -57,7 +51,7 @@ Random::Random(const label seed)
}
}
int
Random
::
bit
()
int
Foam
::
Random
::
bit
()
{
{
if
(
osRandomInteger
()
>
INT_MAX
/
2
)
if
(
osRandomInteger
()
>
INT_MAX
/
2
)
{
{
...
@@ -70,13 +64,13 @@ int Random::bit()
...
@@ -70,13 +64,13 @@ int Random::bit()
}
}
scalar
Random
::
scalar01
()
Foam
::
scalar
Foam
::
Random
::
scalar01
()
{
{
return
osRandomDouble
();
return
osRandomDouble
();
}
}
vector
Random
::
vector01
()
Foam
::
vector
Foam
::
Random
::
vector01
()
{
{
vector
rndVec
;
vector
rndVec
;
for
(
direction
cmpt
=
0
;
cmpt
<
vector
::
nComponents
;
cmpt
++
)
for
(
direction
cmpt
=
0
;
cmpt
<
vector
::
nComponents
;
cmpt
++
)
...
@@ -88,7 +82,7 @@ vector Random::vector01()
...
@@ -88,7 +82,7 @@ vector Random::vector01()
}
}
sphericalTensor
Random
::
sphericalTensor01
()
Foam
::
sphericalTensor
Foam
::
Random
::
sphericalTensor01
()
{
{
sphericalTensor
rndTen
;
sphericalTensor
rndTen
;
rndTen
.
ii
()
=
scalar01
();
rndTen
.
ii
()
=
scalar01
();
...
@@ -97,7 +91,7 @@ sphericalTensor Random::sphericalTensor01()
...
@@ -97,7 +91,7 @@ sphericalTensor Random::sphericalTensor01()
}
}
symmTensor
Random
::
symmTensor01
()
Foam
::
symmTensor
Foam
::
Random
::
symmTensor01
()
{
{
symmTensor
rndTen
;
symmTensor
rndTen
;
for
(
direction
cmpt
=
0
;
cmpt
<
symmTensor
::
nComponents
;
cmpt
++
)
for
(
direction
cmpt
=
0
;
cmpt
<
symmTensor
::
nComponents
;
cmpt
++
)
...
@@ -109,7 +103,7 @@ symmTensor Random::symmTensor01()
...
@@ -109,7 +103,7 @@ symmTensor Random::symmTensor01()
}
}
tensor
Random
::
tensor01
()
Foam
::
tensor
Foam
::
Random
::
tensor01
()
{
{
tensor
rndTen
;
tensor
rndTen
;
for
(
direction
cmpt
=
0
;
cmpt
<
tensor
::
nComponents
;
cmpt
++
)
for
(
direction
cmpt
=
0
;
cmpt
<
tensor
::
nComponents
;
cmpt
++
)
...
@@ -121,13 +115,13 @@ tensor Random::tensor01()
...
@@ -121,13 +115,13 @@ tensor Random::tensor01()
}
}
label
Random
::
integer
(
const
label
lower
,
const
label
upper
)
Foam
::
label
Foam
::
Random
::
integer
(
const
label
lower
,
const
label
upper
)
{
{
return
lower
+
(
osRandomInteger
()
%
(
upper
+
1
-
lower
));
return
lower
+
(
osRandomInteger
()
%
(
upper
+
1
-
lower
));
}
}
vector
Random
::
position
(
const
vector
&
start
,
const
vector
&
end
)
Foam
::
vector
Foam
::
Random
::
position
(
const
vector
&
start
,
const
vector
&
end
)
{
{
vector
rndVec
(
start
);
vector
rndVec
(
start
);
...
@@ -141,40 +135,37 @@ vector Random::position(const vector& start, const vector& end)
...
@@ -141,40 +135,37 @@ vector Random::position(const vector& start, const vector& end)
}
}
void
Random
::
randomise
(
scalar
&
s
)
void
Foam
::
Random
::
randomise
(
scalar
&
s
)
{
{
s
=
scalar01
();
s
=
scalar01
();
}
}
void
Random
::
randomise
(
vector
&
v
)
void
Foam
::
Random
::
randomise
(
vector
&
v
)
{
{
v
=
vector01
();
v
=
vector01
();
}
}
void
Random
::
randomise
(
sphericalTensor
&
st
)
void
Foam
::
Random
::
randomise
(
sphericalTensor
&
st
)
{
{
st
=
sphericalTensor01
();
st
=
sphericalTensor01
();
}
}
void
Random
::
randomise
(
symmTensor
&
st
)
void
Foam
::
Random
::
randomise
(
symmTensor
&
st
)
{
{
st
=
symmTensor01
();
st
=
symmTensor01
();
}
}
void
Random
::
randomise
(
tensor
&
t
)
void
Foam
::
Random
::
randomise
(
tensor
&
t
)
{
{
t
=
tensor01
();
t
=
tensor01
();
}
}
// return a normal Gaussian randon number
Foam
::
scalar
Foam
::
Random
::
GaussNormal
()
// with zero mean and unity variance N(0, 1)
scalar
Random
::
GaussNormal
()
{
{
static
int
iset
=
0
;
static
int
iset
=
0
;
static
scalar
gset
;
static
scalar
gset
;
...
@@ -204,8 +195,4 @@ scalar Random::GaussNormal()
...
@@ -204,8 +195,4 @@ scalar Random::GaussNormal()
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
}
// End namespace Foam
// ************************************************************************* //
// ************************************************************************* //
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment