File: test-coskron.c

package info (click to toggle)
xraylib 4.0.0%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 46,936 kB
  • sloc: ansic: 16,103; f90: 8,746; java: 6,766; python: 1,497; cpp: 1,305; pascal: 1,139; makefile: 809; ruby: 622; php: 594; perl: 573; cs: 193; sh: 125
file content (108 lines) | stat: -rw-r--r-- 4,672 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Copyright (c) 2018, Tom Schoonjans
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY Tom Schoonjans ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Tom Schoonjans BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#include "xraylib.h"
#include "xraylib-error-private.h"
#ifdef NDEBUG
  #undef NDEBUG
#endif
#include <assert.h>
#include <string.h>
#include <math.h>

int main(int argc, char **argv) {
	xrl_error *error = NULL;
	double coskron, sum;

	/* good values */
	coskron = CosKronTransProb(92, FL13_TRANS, &error);
	assert(error == NULL);
	assert(fabs(coskron - 0.620) < 1E-6);

	coskron = CosKronTransProb(75, FL12_TRANS, &error);
	assert(error == NULL);
	assert(fabs(coskron - 1.6E-1) < 1E-6);

	coskron = CosKronTransProb(86, FM45_TRANS, &error);
	assert(error == NULL);
	assert(fabs(coskron - 6E-2) < 1E-6);


	/* bad values */
	/* no data for Z < 12 */
	coskron = CosKronTransProb(11, FL12_TRANS, &error);
	assert(error != NULL);
	assert(coskron == 0.0);
	assert(error->code == XRL_ERROR_INVALID_ARGUMENT );
	assert(strcmp(error->message, INVALID_CK) == 0);
	xrl_clear_error(&error);

	/* apparently we have data for Z = 109... */
	coskron = CosKronTransProb(109, FM45_TRANS, &error);
	assert(error == NULL);
	assert(fabs(coskron - 1.02E-1) < 1E-6);

	/* ... but not for Z = 110+ */
	coskron = CosKronTransProb(110, FL12_TRANS, &error);
	assert(error != NULL);
	assert(coskron == 0.0);
	assert(error->code == XRL_ERROR_INVALID_ARGUMENT );
	assert(strcmp(error->message, INVALID_CK) == 0);
	xrl_clear_error(&error);

	/* let's try going out of range with Z */
	coskron = CosKronTransProb(0, FL12_TRANS, &error);
	assert(error != NULL);
	assert(coskron == 0.0);
	assert(error->code == XRL_ERROR_INVALID_ARGUMENT );
	assert(strcmp(error->message, Z_OUT_OF_RANGE) == 0);
	xrl_clear_error(&error);

	coskron = CosKronTransProb(ZMAX + 1, FL12_TRANS, &error);
	assert(error != NULL);
	assert(coskron == 0.0);
	assert(error->code == XRL_ERROR_INVALID_ARGUMENT );
	assert(strcmp(error->message, Z_OUT_OF_RANGE) == 0);
	xrl_clear_error(&error);

	/* now some non-existent Coster-Kronig transitions */
	coskron = CosKronTransProb(26, 0, &error);
	assert(error != NULL);
	assert(coskron == 0.0);
	assert(error->code == XRL_ERROR_INVALID_ARGUMENT );
	assert(strcmp(error->message, UNKNOWN_CK) == 0);
	xrl_clear_error(&error);

	coskron = CosKronTransProb(92, FM45_TRANS, &error);
	assert(error == NULL);
	assert(coskron > 0.0);
	coskron = CosKronTransProb(92, FM45_TRANS + 1, &error);
	assert(error != NULL);
	assert(coskron == 0.0);
	assert(error->code == XRL_ERROR_INVALID_ARGUMENT );
	assert(strcmp(error->message, UNKNOWN_CK) == 0);
	xrl_clear_error(&error);
	
	/* now some internal consistency checks */
	sum = FluorYield(92, L1_SHELL, NULL) + AugerYield(92, L1_SHELL, NULL) + CosKronTransProb(92, FL12_TRANS, NULL) + CosKronTransProb(92, FL13_TRANS, NULL) + CosKronTransProb(92, FLP13_TRANS, NULL);
	assert(fabs(sum - 1.0) < 1E-6);
	sum = FluorYield(92, L2_SHELL, NULL) + AugerYield(92, L2_SHELL, NULL) + CosKronTransProb(92, FL23_TRANS, NULL);
	assert(fabs(sum - 1.0) < 1E-6);
	sum = FluorYield(92, M4_SHELL, NULL) + AugerYield(92, M4_SHELL, NULL) + CosKronTransProb(92, FM45_TRANS, NULL);
	assert(fabs(sum - 1.0) < 1E-6);
	sum = FluorYield(92, M2_SHELL, NULL) + AugerYield(92, M2_SHELL, NULL) + CosKronTransProb(92, FM23_TRANS, NULL) + CosKronTransProb(92, FM24_TRANS, NULL) + CosKronTransProb(92, FM25_TRANS, NULL);
	assert(fabs(sum - 1.0) < 1E-6);
	

	return 0;
}