25#ifndef __TESTING_HPP__
26#define __TESTING_HPP__
43inline int call_test(std::string label__, F&& f__)
50 catch (std::exception
const& e) {
56 msg =
"unknown exception";
59 std::cout << label__ <<
" : Failed" << std::endl;
61 std::cout <<
"exception occured:" << std::endl;
62 std::cout << msg << std::endl;
65 std::cout << label__ <<
" : OK" << std::endl;
71inline int call_test(std::string label__, F&& f__, cmd_args
const& args__)
73 printf(
"running %-30s : ", label__.c_str());
74 int result = f__(args__);
76 printf(
"\x1b[31m" "Failed" "\x1b[0m" "\n");
78 printf(
"\x1b[32m" "OK" "\x1b[0m" "\n");
87 double average()
const
90 for (
size_t i = 0; i < this->size(); i++) {
93 d /=
static_cast<double>(this->size());
99 double avg = average();
101 for (
size_t i = 0; i < this->size(); i++) {
102 variance += std::pow((*
this)[i] - avg, 2);
104 variance /=
static_cast<double>(this->size());
105 return std::sqrt(variance);
111random_symmetric(
int N__,
int bs__,
la::BLACS_grid const& blacs_grid__)
113 PROFILE(
"random_symmetric");
117 for (
int j = 0; j < A.num_cols_local(); j++) {
118 for (
int i = 0; i < A.num_rows_local(); i++) {
119 A(i, j) = random<T>();
123#ifdef SIRIUS_SCALAPACK
126 for (
int i = 0; i < N__; i++) {
127 for (
int j = 0; j < N__; j++) {
128 B(i, j) =
conj(A(j, i));
133 for (
int j = 0; j < A.num_cols_local(); j++) {
134 for (
int i = 0; i < A.num_rows_local(); i++) {
135 A(i, j) = 0.5 * (A(i, j) + B(i, j));
139 for (
int i = 0; i < N__; i++) {
148random_positive_definite(
int N__,
int bs__ = 16, la::BLACS_grid
const *blacs_grid__ =
nullptr)
150 PROFILE(
"random_positive_definite");
152 double p = 1.0 / N__;
153 auto A = (blacs_grid__) ? la::dmatrix<T>(N__, N__, *blacs_grid__, bs__, bs__) : la::dmatrix<T>(N__, N__);
154 auto B = (blacs_grid__) ? la::dmatrix<T>(N__, N__, *blacs_grid__, bs__, bs__) : la::dmatrix<T>(N__, N__);
155 for (
int j = 0; j < A.num_cols_local(); j++) {
156 for (
int i = 0; i < A.num_rows_local(); i++) {
157 A(i, j) = p * random<T>();
162#ifdef SIRIUS_SCALAPACK
163 la::wrap(
la::lib_t::scalapack).gemm(
'C',
'N', N__, N__, N__, &la::constant<T>::one(), A, 0, 0, A, 0, 0,
164 &la::constant<T>::zero(), B, 0, 0);
166 RTE_THROW(
"not compiled with scalapack");
169 la::wrap(
la::lib_t::blas).gemm(
'C',
'N', N__, N__, N__, &la::constant<T>::one(), &A(0, 0), A.ld(),
170 &A(0, 0), A.ld(), &la::constant<T>::zero(), &B(0, 0), B.ld());
173 for (
int i = 0; i < N__; i++) {
181create_simulation_context(nlohmann::json
const& conf__, r3::matrix<double> L__,
int num_atoms__,
182std::vector<r3::vector<double>> coord__,
bool add_vloc__,
bool add_dion__)
184 auto ctx = std::make_unique<sirius::Simulation_context>(conf__);
186 ctx->unit_cell().set_lattice_vectors(L__);
188 auto& atype = ctx->unit_cell().add_atom_type(
"Cu");
190 if (ctx->cfg().parameters().electronic_structure_method() ==
"full_potential_lapwlo") {
196 atype.set_radial_grid(radial_grid_t::lin_exp, 1000, 0.0, 100.0, 6);
198 int icut = atype.radial_grid().index_of(1.0);
199 double rcut = atype.radial_grid(icut);
201 std::vector<double> beta(icut + 1);
202 std::vector<double> beta1(icut + 1);
203 for (
int l = 0; l <= 2; l++) {
204 for (
int i = 0; i <= icut; i++) {
205 double x = atype.radial_grid(i);
206 beta[i] = confined_polynomial(x, rcut, l, l + 1, 0);
207 beta1[i] = confined_polynomial(x, rcut, l, l + 2, 0);
210 atype.add_beta_radial_function(angular_momentum(l), beta);
211 atype.add_beta_radial_function(angular_momentum(l), beta1);
214 std::vector<double> ps_wf(atype.radial_grid().num_points());
215 for (
int l = 0; l <= 2; l++) {
216 for (
int i = 0; i < atype.radial_grid().num_points(); i++) {
217 double x = atype.radial_grid(i);
218 ps_wf[i] = std::exp(-x) * std::pow(x, l);
221 atype.add_ps_atomic_wf(3, angular_momentum(l), ps_wf);
225 std::vector<double> vloc(atype.radial_grid().num_points(), 0);
227 for (
int i = 0; i < atype.radial_grid().num_points(); i++) {
228 double x = atype.radial_grid(i);
229 vloc[i] = -atype.zn() / (std::exp(-x * (x + 1)) + x);
232 atype.local_potential(vloc);
234 int nbf = atype.num_beta_radial_functions();
235 sddk::matrix<double> dion(nbf, nbf);
238 for (
int i = 0; i < nbf; i++) {
242 atype.d_mtrx_ion(dion);
244 std::vector<double> arho(atype.radial_grid().num_points());
245 for (
int i = 0; i < atype.radial_grid().num_points(); i++) {
246 double x = atype.radial_grid(i);
247 arho[i] = 2 * atype.zn() * std::exp(-x * x) * x;
249 atype.ps_total_charge_density(arho);
252 for (
auto v: coord__) {
253 ctx->unit_cell().add_atom(
"Cu", v, {0, 0, 1});
262randomize(wf::Wave_functions<T>& wf__)
264 for (
int i = 0; i < wf__.num_wf().get(); i++) {
265 for (
int s = 0; s < wf__.num_sc().get(); s++) {
266 auto ptr = wf__.at(sddk::memory_t::host, 0, wf::spin_index(s), wf::band_index(i));
267 for (
int j = 0; j < wf__.ld(); j++) {
268 ptr[j] = random<std::complex<double>>();
Contains definition and implementation of cmd_args class.
Contains definition and implementation of distributed matrix class.
Linear algebra interface.
@ scalapack
CPU ScaLAPACK.
Namespace of the SIRIUS library.
auto conj(double x__)
Return complex conjugate of a number. For a real value this is the number itself.
Simple classes and functions to work with vectors and matrices of the R^3 space.
Contains definition and implementation of Simulation_context class.
Contains declaration and implementation of Wave_functions class.