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
9b72c0c3
Commit
9b72c0c3
authored
8 years ago
by
Van Herck, Walter
Browse files
Options
Downloads
Patches
Plain Diff
Fix complex overflows in SpecularMatrix
parent
4d759954
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Core/Algorithms/ScalarSpecularInfoMap.cpp
+0
-4
0 additions, 4 deletions
Core/Algorithms/ScalarSpecularInfoMap.cpp
Core/Algorithms/SpecularMatrix.cpp
+13
-3
13 additions, 3 deletions
Core/Algorithms/SpecularMatrix.cpp
Core/Algorithms/SpecularMatrix.h
+0
-2
0 additions, 2 deletions
Core/Algorithms/SpecularMatrix.h
with
13 additions
and
9 deletions
Core/Algorithms/ScalarSpecularInfoMap.cpp
+
0
−
4
View file @
9b72c0c3
...
@@ -49,9 +49,5 @@ const ScalarRTCoefficients *ScalarSpecularInfoMap::getCoefficients(kvector_t kve
...
@@ -49,9 +49,5 @@ const ScalarRTCoefficients *ScalarSpecularInfoMap::getCoefficients(kvector_t kve
SpecularMatrix
::
MultiLayerCoeff_t
coeffs
;
SpecularMatrix
::
MultiLayerCoeff_t
coeffs
;
SpecularMatrix
::
execute
(
*
mp_multilayer
,
kvec
,
coeffs
);
SpecularMatrix
::
execute
(
*
mp_multilayer
,
kvec
,
coeffs
);
auto
layer_coeffs
=
coeffs
[
m_layer
];
auto
layer_coeffs
=
coeffs
[
m_layer
];
if
(
std
::
isnan
(
layer_coeffs
.
getScalarT
().
real
()))
{
throw
RuntimeErrorException
(
"ScalarSpecularInfoMap::getCoefficients() -> "
"Error! Amplitude is NaN"
);
}
return
new
ScalarRTCoefficients
(
layer_coeffs
);
return
new
ScalarRTCoefficients
(
layer_coeffs
);
}
}
This diff is collapsed.
Click to expand it.
Core/Algorithms/SpecularMatrix.cpp
+
13
−
3
View file @
9b72c0c3
...
@@ -24,6 +24,8 @@ namespace {
...
@@ -24,6 +24,8 @@ namespace {
const
complex_t
imag_unit
=
complex_t
(
0.0
,
1.0
);
const
complex_t
imag_unit
=
complex_t
(
0.0
,
1.0
);
}
}
void
setZeroBelow
(
SpecularMatrix
::
MultiLayerCoeff_t
&
coeff
,
size_t
current_layer
);
// Computes refraction angles and transmission/reflection coefficients
// Computes refraction angles and transmission/reflection coefficients
// for given coherent wave propagation in a multilayer.
// for given coherent wave propagation in a multilayer.
// k : length: wavenumber in vacuum, direction: defined in layer 0
// k : length: wavenumber in vacuum, direction: defined in layer 0
...
@@ -90,7 +92,7 @@ void SpecularMatrix::execute(const MultiLayer& sample, const kvector_t k,
...
@@ -90,7 +92,7 @@ void SpecularMatrix::execute(const MultiLayer& sample, const kvector_t k,
(
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
*
(
lambda_rough
+
lambda_below
)
*
coeff
[
i
+
1
].
t_r
(
1
)
)
/
2.0
/
lambda
*
std
::
exp
(
ikd
*
lambda
);
std
::
exp
(
ikd
*
lambda
);
if
(
std
::
is
nan
(
std
::
abs
(
coeff
[
i
].
t_r
(
0
))))
{
if
(
std
::
is
inf
(
std
::
abs
(
coeff
[
i
].
getScalarT
(
))))
{
coeff
[
i
].
t_r
(
0
)
=
1.0
;
coeff
[
i
].
t_r
(
0
)
=
1.0
;
coeff
[
i
].
t_r
(
1
)
=
0.0
;
coeff
[
i
].
t_r
(
1
)
=
0.0
;
setZeroBelow
(
coeff
,
i
);
setZeroBelow
(
coeff
,
i
);
...
@@ -98,16 +100,24 @@ void SpecularMatrix::execute(const MultiLayer& sample, const kvector_t k,
...
@@ -98,16 +100,24 @@ void SpecularMatrix::execute(const MultiLayer& sample, const kvector_t k,
}
}
// 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
].
getScalarT
();
// This trick is used to avoid overflows in the intermediate steps of
// complex division:
double
tmax
=
std
::
max
(
std
::
abs
(
T0
.
real
()),
std
::
abs
(
T0
.
imag
()));
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
coeff
[
i
].
t_r
(
0
)
/=
tmax
;
coeff
[
i
].
t_r
(
1
)
/=
tmax
;
}
// Now the real normalization to T_0 proceeds
T0
=
coeff
[
0
].
getScalarT
();
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
;
}
}
}
}
void
SpecularMatrix
::
setZeroBelow
(
MultiLayerCoeff_t
&
coeff
,
size_t
current_layer
)
void
setZeroBelow
(
SpecularMatrix
::
MultiLayerCoeff_t
&
coeff
,
size_t
current_layer
)
{
{
size_t
N
=
coeff
.
size
();
size_t
N
=
coeff
.
size
();
for
(
size_t
i
=
current_layer
+
1
;
i
<
N
;
++
i
)
{
for
(
size_t
i
=
current_layer
+
1
;
i
<
N
;
++
i
)
{
coeff
[
i
].
t_r
.
setZero
();
coeff
[
i
].
t_r
.
setZero
();
}
}
}
}
This diff is collapsed.
Click to expand it.
Core/Algorithms/SpecularMatrix.h
+
0
−
2
View file @
9b72c0c3
...
@@ -37,8 +37,6 @@ public:
...
@@ -37,8 +37,6 @@ public:
//! Computes refraction angles and transmission/reflection coefficients
//! Computes refraction angles and transmission/reflection coefficients
//! for given coherent wave propagation in a multilayer.
//! for given coherent wave propagation in a multilayer.
static
void
execute
(
const
MultiLayer
&
sample
,
const
kvector_t
k
,
MultiLayerCoeff_t
&
coeff
);
static
void
execute
(
const
MultiLayer
&
sample
,
const
kvector_t
k
,
MultiLayerCoeff_t
&
coeff
);
private:
void
setZeroBelow
(
MultiLayerCoeff_t
&
coeff
,
size_t
current_layer
);
};
};
#endif
/* SPECULARMATRIX_H_ */
#endif
/* SPECULARMATRIX_H_ */
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