Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
b6ec8212
Commit
b6ec8212
authored
8 years ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
Correct bisection: need to recompute 'good' variant when returning from
'bad' case.
parent
bf20bc14
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Core/Multilayer/SpecularMatrix.cpp
+13
-4
13 additions, 4 deletions
Core/Multilayer/SpecularMatrix.cpp
Tests/UnitTests/Core/Sample/RTTest.h
+1
-1
1 addition, 1 deletion
Tests/UnitTests/Core/Sample/RTTest.h
with
14 additions
and
5 deletions
Core/Multilayer/SpecularMatrix.cpp
+
13
−
4
View file @
b6ec8212
...
@@ -81,16 +81,20 @@ void SpecularMatrix::execute(const MultiLayer& sample, const kvector_t k, MultiL
...
@@ -81,16 +81,20 @@ void SpecularMatrix::execute(const MultiLayer& sample, const kvector_t k, MultiL
setZeroBelow
(
coeff
,
start_layer_index
+
1
);
setZeroBelow
(
coeff
,
start_layer_index
+
1
);
// Normalize to incoming downward travelling amplitude = 1.
// Normalize to incoming downward travelling amplitude = 1.
complex_t
T0
=
coeff
[
0
].
getScalarT
(
);
complex_t
T0
=
coeff
[
0
].
t_r
(
0
);
// This trick is used to avoid overflows in the intermediate steps of
// This trick is used to avoid overflows in the intermediate steps of
// complex division:
// complex division:
double
tmax
=
std
::
max
(
std
::
abs
(
T0
.
real
()),
std
::
abs
(
T0
.
imag
()));
double
tmax
=
std
::
max
(
std
::
abs
(
T0
.
real
()),
std
::
abs
(
T0
.
imag
()));
if
(
std
::
isinf
(
tmax
))
throw
std
::
runtime_error
(
"Unexpected tmax=infty"
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
coeff
[
i
].
t_r
(
0
)
/=
tmax
;
coeff
[
i
].
t_r
(
0
)
/=
tmax
;
coeff
[
i
].
t_r
(
1
)
/=
tmax
;
coeff
[
i
].
t_r
(
1
)
/=
tmax
;
}
}
// Now the real normalization to T_0 proceeds
// Now the real normalization to T_0 proceeds
T0
=
coeff
[
0
].
getScalarT
();
T0
=
coeff
[
0
].
t_r
(
0
);
if
(
std
::
isinf
(
abs
(
T0
)))
throw
std
::
runtime_error
(
"Unexpected tmax=infty"
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
coeff
[
i
].
t_r
=
coeff
[
i
].
t_r
/
T0
;
coeff
[
i
].
t_r
=
coeff
[
i
].
t_r
/
T0
;
}
}
...
@@ -139,7 +143,7 @@ bool calculateUpFromLayer(SpecularMatrix::MultiLayerCoeff_t& coeff, const MultiL
...
@@ -139,7 +143,7 @@ bool calculateUpFromLayer(SpecularMatrix::MultiLayerCoeff_t& coeff, const MultiL
coeff
[
i
].
t_r
(
1
)
=
(
coeff
[
i
].
t_r
(
1
)
=
(
(
lambda_rough
-
lambda_below
)
*
coeff
[
i
+
1
].
t_r
(
0
)
+
(
lambda_rough
-
lambda_below
)
*
coeff
[
i
+
1
].
t_r
(
0
)
+
(
lambda_rough
+
lambda_below
)
*
coeff
[
i
+
1
].
t_r
(
1
)
)
/
2.0
/
lambda
*
exp_fac
;
(
lambda_rough
+
lambda_below
)
*
coeff
[
i
+
1
].
t_r
(
1
)
)
/
2.0
/
lambda
*
exp_fac
;
if
(
std
::
isinf
(
std
::
abs
(
coeff
[
i
].
getScalarT
(
))))
if
(
std
::
isinf
(
abs
(
coeff
[
i
].
t_r
(
0
))))
return
false
;
// overflow => retry calulation starting from a higher layer
return
false
;
// overflow => retry calulation starting from a higher layer
}
}
return
true
;
// no overflow => result is definitive
return
true
;
// no overflow => result is definitive
...
@@ -147,6 +151,7 @@ bool calculateUpFromLayer(SpecularMatrix::MultiLayerCoeff_t& coeff, const MultiL
...
@@ -147,6 +151,7 @@ bool calculateUpFromLayer(SpecularMatrix::MultiLayerCoeff_t& coeff, const MultiL
//! Recursive bisection to determine the number of the deepest layer where RT computation
//! Recursive bisection to determine the number of the deepest layer where RT computation
//! can be started without running into overflow.
//! can be started without running into overflow.
//! Computes coeff, and returns largest possible start layer index.
size_t
bisectRTcomputation
(
size_t
bisectRTcomputation
(
SpecularMatrix
::
MultiLayerCoeff_t
&
coeff
,
const
MultiLayer
&
sample
,
SpecularMatrix
::
MultiLayerCoeff_t
&
coeff
,
const
MultiLayer
&
sample
,
...
@@ -159,8 +164,12 @@ size_t bisectRTcomputation(
...
@@ -159,8 +164,12 @@ size_t bisectRTcomputation(
return
bisectRTcomputation
(
coeff
,
sample
,
kmag
,
l
,
lbad
,
(
l
+
lbad
)
/
2
);
return
bisectRTcomputation
(
coeff
,
sample
,
kmag
,
l
,
lbad
,
(
l
+
lbad
)
/
2
);
}
else
{
}
else
{
// failure => highest valid l must be in lgood..l-1
// failure => highest valid l must be in lgood..l-1
if
(
l
-
1
==
lgood
)
if
(
l
-
1
==
lgood
)
{
if
(
!
calculateUpFromLayer
(
coeff
,
sample
,
kmag
,
l
-
1
))
throw
std
::
runtime_error
(
"Bisection failed: Unexpected non-monotonicity in RT computation"
);
return
l
-
1
;
return
l
-
1
;
}
return
bisectRTcomputation
(
coeff
,
sample
,
kmag
,
lgood
,
l
,
(
lgood
+
l
)
/
2
);
return
bisectRTcomputation
(
coeff
,
sample
,
kmag
,
lgood
,
l
,
(
lgood
+
l
)
/
2
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Tests/UnitTests/Core/Sample/RTTest.h
+
1
−
1
View file @
b6ec8212
...
@@ -72,7 +72,7 @@ TEST_F(RTTest, SplitBilayers)
...
@@ -72,7 +72,7 @@ TEST_F(RTTest, SplitBilayers)
{
{
// With exaggerated values of #layers, layer thickness, and absorption
// With exaggerated values of #layers, layer thickness, and absorption
// so that we also test correct handling of floating-point overflow.
// so that we also test correct handling of floating-point overflow.
const
int
n
=
4
00
;
const
int
n
=
2
00
;
sample1
.
addLayer
(
topLayer
);
sample1
.
addLayer
(
topLayer
);
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
...
...
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