pol_cli.cpp 1.68 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/**
 * polarisation test
 * @author Tobias Weber <tweber@ill.fr>
 * @date aug-18
 * @license GPLv3, see 'LICENSE' file
 * @desc The present version was forked on 8-Nov-2018 from the privately developed "magtools" project (https://github.com/t-weber/magtools).
 *
 * g++ -std=c++2a -fconcepts -I../.. -o pol_cli pol_cli.cpp
 */

#include <iostream>
Tobias WEBER's avatar
Tobias WEBER committed
12
#include "libs/math_algos.h"
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
using namespace m;
using namespace m_ops;

using t_real = double;
using t_cplx = std::complex<t_real>;
using t_vec = std::vector<t_cplx>;
using t_mat = mat<t_cplx, std::vector>;
using t_matvec = std::vector<t_mat>;


std::istringstream get_istr(std::istream& istr)
{
	std::string _str;
	std::getline(istr, _str);
	return std::istringstream(_str);
}


int main()
{
	constexpr bool bCheck = true;

	t_cplx N(0,0);
	t_vec Mperp = create<t_vec>({0, 0, t_cplx(1,2)});
	t_vec P = create<t_vec>({0, 1, 1});


	std::cout << "N = "; get_istr(std::cin) >> N;
	std::cout << "Mperp = "; std::cin >> Mperp; Mperp.resize(3);
	std::cout << "P = "; std::cin >> P; P.resize(3);

	std::cout << "\n";
	std::cout << "N = " << N << "\n";
	std::cout << "Mperp = " << Mperp << "\n";
	std::cout << "P = " << P << "\n";
	std::cout << std::endl;

	std::cout << "density matrix = " << pol_density_mat<t_vec, t_mat>(P) << "\n";
	std::cout << std::endl;

	auto [I, P_f] = blume_maleev_indir<t_mat, t_vec, t_cplx>(P, Mperp, N);
	std::cout << "I = " << I << "\nP_f = " << P_f << std::endl;

	// double-check results
	if constexpr(bCheck)
	{
		auto [I2, P_f2] = blume_maleev<t_vec, t_cplx>(P, Mperp, N);
		if(!equals(I, I2, 1e-5) || !equals(P_f, P_f2, 1e-5))
		{
			std::cerr << "Mismatch between blume_maleev() and blume_maleev_indir()!" << std::endl;
		}
	}

	return 0;
}