Skip to content

Commit 1d6acbd

Browse files
authored
Test: simplify unitcell ut files (#2015)
* Test: simplify unitcell ut files * remove redundent lines * update unitcell ut * add more tests * add a death test * fix bug --------- Co-authored-by: root <hongriTianqi>
1 parent 5e172f2 commit 1d6acbd

File tree

12 files changed

+4882
-1237
lines changed

12 files changed

+4882
-1237
lines changed

source/module_cell/test/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,25 @@ add_test(NAME cell_parallel_kpoints_test
8181
)
8282

8383
AddTest(
84-
TARGET cell_unitcell_test_f # TEST_F
84+
TARGET cell_unitcell_test
8585
LIBS ${math_libs} base device
86-
SOURCES unitcell_test_f.cpp ../unitcell.cpp ../read_atoms.cpp ../read_cell_pseudopots.cpp ../atom_spec.cpp
86+
SOURCES unitcell_test.cpp ../unitcell.cpp ../read_atoms.cpp ../read_cell_pseudopots.cpp ../atom_spec.cpp
8787
../atom_pseudo.cpp ../pseudo_nc.cpp ../read_pp.cpp ../read_pp_upf201.cpp ../read_pp_upf100.cpp
8888
../read_pp_vwr.cpp ../read_pp_blps.cpp ../../module_io/output.cpp
8989
)
9090

9191
AddTest(
92-
TARGET cell_unitcell_test_p # TEST_P
92+
TARGET cell_unitcell_test_readpp
9393
LIBS ${math_libs} base device
94-
SOURCES unitcell_test_p.cpp ../unitcell.cpp ../read_atoms.cpp ../read_cell_pseudopots.cpp ../atom_spec.cpp
94+
SOURCES unitcell_test_readpp.cpp ../unitcell.cpp ../read_atoms.cpp ../read_cell_pseudopots.cpp ../atom_spec.cpp
9595
../atom_pseudo.cpp ../pseudo_nc.cpp ../read_pp.cpp ../read_pp_upf201.cpp ../read_pp_upf100.cpp
9696
../read_pp_vwr.cpp ../read_pp_blps.cpp ../../module_io/output.cpp
9797
)
9898

9999
AddTest(
100-
TARGET cell_unitcell_test_r # r for reading pp
100+
TARGET cell_unitcell_test_para
101101
LIBS ${math_libs} base device
102-
SOURCES unitcell_test_r.cpp ../unitcell.cpp ../read_atoms.cpp ../read_cell_pseudopots.cpp ../atom_spec.cpp
102+
SOURCES unitcell_test_para.cpp ../unitcell.cpp ../read_atoms.cpp ../read_cell_pseudopots.cpp ../atom_spec.cpp
103103
../atom_pseudo.cpp ../pseudo_nc.cpp ../read_pp.cpp ../read_pp_upf201.cpp ../read_pp_upf100.cpp
104104
../read_pp_vwr.cpp ../read_pp_blps.cpp ../../module_io/output.cpp
105105
)

source/module_cell/test/prepare_unitcell.h

Lines changed: 291 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,48 @@
11
#ifndef PREPARE_UNITCELL_H
22
#define PREPARE_UNITCELL_H
3+
#include<map>
4+
#include<string>
35

46
class UcellTestPrepare
57
{
68
public:
7-
UcellTestPrepare(std::string system_name_in,
8-
std::string latname_in,
9-
int lmaxmax_in,
10-
bool init_vel_in,
11-
bool selective_dynamics_in,
12-
bool relax_new_in,
13-
std::string fixed_axes_in,
14-
double lat0_in,
15-
std::valarray<double> latvec_in,
16-
std::vector<std::string> elements_in,
17-
std::vector<std::string> pp_files_in,
18-
std::vector<std::string> pp_types_in,
19-
std::vector<std::string> orb_files_in,
20-
std::valarray<int> natom_in,
21-
std::vector<double> atomic_mass_in,
22-
std::string coor_type_in,
23-
std::valarray<double> coordinates_in,
24-
std::valarray<double> mbl_in = {0},
25-
std::valarray<double> velocity_in = {0}
26-
):
27-
system_name(system_name_in),
28-
latname(latname_in),
29-
lmaxmax(lmaxmax_in),
30-
init_vel(init_vel_in),
31-
selective_dynamics(selective_dynamics_in),
32-
relax_new(relax_new_in),
33-
fixed_axes(fixed_axes_in),
34-
lat0(lat0_in),
35-
latvec(latvec_in),
36-
elements(elements_in),
37-
pp_files(pp_files_in),
38-
pp_types(pp_types_in),
39-
orb_files(orb_files_in),
40-
natom(natom_in),
41-
atomic_mass(atomic_mass_in),
42-
coor_type(coor_type_in),
43-
coordinates(coordinates_in),
44-
mbl(mbl_in),
45-
velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file()
46-
{}
47-
std::string system_name;
9+
UcellTestPrepare()=default;
10+
UcellTestPrepare(std::string latname_in,
11+
int lmaxmax_in,
12+
bool init_vel_in,
13+
bool selective_dynamics_in,
14+
bool relax_new_in,
15+
std::string fixed_axes_in,
16+
double lat0_in,
17+
std::valarray<double> latvec_in,
18+
std::vector<std::string> elements_in,
19+
std::vector<std::string> pp_files_in,
20+
std::vector<std::string> pp_types_in,
21+
std::vector<std::string> orb_files_in,
22+
std::valarray<int> natom_in,
23+
std::vector<double> atomic_mass_in,
24+
std::string coor_type_in,
25+
std::valarray<double> coordinates_in);
26+
UcellTestPrepare(std::string latname_in,
27+
int lmaxmax_in,
28+
bool init_vel_in,
29+
bool selective_dynamics_in,
30+
bool relax_new_in,
31+
std::string fixed_axes_in,
32+
double lat0_in,
33+
std::valarray<double> latvec_in,
34+
std::vector<std::string> elements_in,
35+
std::vector<std::string> pp_files_in,
36+
std::vector<std::string> pp_types_in,
37+
std::vector<std::string> orb_files_in,
38+
std::valarray<int> natom_in,
39+
std::vector<double> atomic_mass_in,
40+
std::string coor_type_in,
41+
std::valarray<double> coordinates_in,
42+
std::valarray<double> mbl_in,
43+
std::valarray<double> velocity_in);
44+
UcellTestPrepare(const UcellTestPrepare &utp);
45+
4846
std::string latname;
4947
int lmaxmax;
5048
bool init_vel;
@@ -220,4 +218,256 @@ class UcellTestPrepare
220218
}
221219
};
222220

221+
UcellTestPrepare::UcellTestPrepare(std::string latname_in,
222+
int lmaxmax_in,
223+
bool init_vel_in,
224+
bool selective_dynamics_in,
225+
bool relax_new_in,
226+
std::string fixed_axes_in,
227+
double lat0_in,
228+
std::valarray<double> latvec_in,
229+
std::vector<std::string> elements_in,
230+
std::vector<std::string> pp_files_in,
231+
std::vector<std::string> pp_types_in,
232+
std::vector<std::string> orb_files_in,
233+
std::valarray<int> natom_in,
234+
std::vector<double> atomic_mass_in,
235+
std::string coor_type_in,
236+
std::valarray<double> coordinates_in):
237+
latname(latname_in),
238+
lmaxmax(lmaxmax_in),
239+
init_vel(init_vel_in),
240+
selective_dynamics(selective_dynamics_in),
241+
relax_new(relax_new_in),
242+
fixed_axes(fixed_axes_in),
243+
lat0(lat0_in),
244+
latvec(latvec_in),
245+
elements(elements_in),
246+
pp_files(pp_files_in),
247+
pp_types(pp_types_in),
248+
orb_files(orb_files_in),
249+
natom(natom_in),
250+
atomic_mass(atomic_mass_in),
251+
coor_type(coor_type_in),
252+
coordinates(coordinates_in)
253+
{
254+
mbl = {0};
255+
velocity = {0};
256+
}
257+
258+
UcellTestPrepare::UcellTestPrepare(std::string latname_in,
259+
int lmaxmax_in,
260+
bool init_vel_in,
261+
bool selective_dynamics_in,
262+
bool relax_new_in,
263+
std::string fixed_axes_in,
264+
double lat0_in,
265+
std::valarray<double> latvec_in,
266+
std::vector<std::string> elements_in,
267+
std::vector<std::string> pp_files_in,
268+
std::vector<std::string> pp_types_in,
269+
std::vector<std::string> orb_files_in,
270+
std::valarray<int> natom_in,
271+
std::vector<double> atomic_mass_in,
272+
std::string coor_type_in,
273+
std::valarray<double> coordinates_in,
274+
std::valarray<double> mbl_in,
275+
std::valarray<double> velocity_in):
276+
latname(latname_in),
277+
lmaxmax(lmaxmax_in),
278+
init_vel(init_vel_in),
279+
selective_dynamics(selective_dynamics_in),
280+
relax_new(relax_new_in),
281+
fixed_axes(fixed_axes_in),
282+
lat0(lat0_in),
283+
latvec(latvec_in),
284+
elements(elements_in),
285+
pp_files(pp_files_in),
286+
pp_types(pp_types_in),
287+
orb_files(orb_files_in),
288+
natom(natom_in),
289+
atomic_mass(atomic_mass_in),
290+
coor_type(coor_type_in),
291+
coordinates(coordinates_in),
292+
mbl(mbl_in),
293+
velocity(velocity_in) // velocity assume the existence of mbl in print_stru_file()
294+
{}
295+
296+
UcellTestPrepare::UcellTestPrepare(const UcellTestPrepare &utp):
297+
latname(utp.latname),
298+
lmaxmax(utp.lmaxmax),
299+
init_vel(utp.init_vel),
300+
selective_dynamics(utp.selective_dynamics),
301+
relax_new(utp.relax_new),
302+
fixed_axes(utp.fixed_axes),
303+
lat0(utp.lat0),
304+
latvec(utp.latvec),
305+
elements(utp.elements),
306+
pp_files(utp.pp_files),
307+
pp_types(utp.pp_types),
308+
orb_files(utp.orb_files),
309+
natom(utp.natom),
310+
atomic_mass(utp.atomic_mass),
311+
coor_type(utp.coor_type),
312+
coordinates(utp.coordinates),
313+
mbl(utp.mbl),
314+
velocity(utp.velocity) // velocity assume the existence of mbl in print_stru_file()
315+
{}
316+
317+
std::map<std::string,UcellTestPrepare> UcellTestLib
318+
{
319+
{"C1H2-Index", UcellTestPrepare(
320+
"bcc", //latname
321+
2, //lmaxmax
322+
true, //init_vel
323+
true, //selective_dyanmics
324+
true, //relax_new
325+
"volume", //fixed_axes
326+
1.8897261254578281, //lat0
327+
{10.0,0.0,0.0, //latvec
328+
0.0,10.0,0.0,
329+
0.0,0.0,10.0},
330+
{"C","H"}, //elements
331+
{"C.upf","H.upf"}, //upf file
332+
{"upf201","upf201"}, //upf types
333+
{"C.orb","H.orb"}, //orb file
334+
{1,2}, //number of each elements
335+
{12.0,1.0}, //atomic mass
336+
"Direct", //coordination type
337+
{0.1,0.1,0.1, //atomic coordinates
338+
0.15,0.15,0.15,
339+
0.05,0.05,0.05},
340+
{1,1,1, //if atom can move: mbl
341+
0,0,0,
342+
0,0,1},
343+
{0.1,0.1,0.1, //velocity: vel
344+
0.1,0.1,0.1,
345+
0.1,0.1,0.1})},
346+
{"C1H2-Cartesian", UcellTestPrepare(
347+
"bcc", //latname
348+
2, //lmaxmax
349+
true, //init_vel
350+
true, //selective_dyanmics
351+
true, //relax_new
352+
"volume", //fixed_axes
353+
1.8897261254578281, //lat0
354+
{10.0,0.0,0.0, //latvec
355+
0.0,10.0,0.0,
356+
0.0,0.0,10.0},
357+
{"C","H"}, //elements
358+
{"C.upf","H.upf"}, //upf file
359+
{"upf201","upf201"}, //upf types
360+
{"C.orb","H.orb"}, //orb file
361+
{1,2}, //number of each elements
362+
{12.0,1.0}, //atomic mass
363+
"Cartesian", //coordination type
364+
{1,1,1, //atomic coordinates
365+
1.5,1.5,1.5,
366+
0.5,0.5,0.5})},
367+
{"C1H2-CheckDTau", UcellTestPrepare(
368+
"bcc", //latname
369+
2, //lmaxmax
370+
false, //init_vel
371+
false, //selective_dyanmics
372+
true, //relax_new
373+
"volume", //fixed_axes
374+
1.8897261254578281, //lat0
375+
{0.1,0.1,0.1, //latvec
376+
0.15,0.15,0.15,
377+
0.05,0.05,0.05},
378+
{"C","H"}, //elements
379+
{"C.upf","H.upf"}, //upf file
380+
{"upf201","upf201"}, //upf types
381+
{"C.orb","H.orb"}, //orb file
382+
{1,2}, //number of each elements
383+
{12.0,1.0}, //atomic mass
384+
"Direct", //coordination type
385+
{1.6,2.5,3.8, //atomic coordinates
386+
-0.15,1.0,-0.15,
387+
-3.05,-2.8,0.0})},
388+
{"C1H2-CheckTau", UcellTestPrepare(
389+
"bcc", //latname
390+
2, //lmaxmax
391+
false, //init_vel
392+
false, //selective_dyanmics
393+
true, //relax_new
394+
"volume", //fixed_axes
395+
1.8897261254578281, //lat0
396+
{0.1,0.1,0.1, //latvec
397+
0.15,0.15,0.15,
398+
0.05,0.05,0.05},
399+
{"C","H"}, //elements
400+
{"C.upf","H.upf"}, //upf file
401+
{"upf201","upf201"}, //upf types
402+
{"C.orb","H.orb"}, //orb file
403+
{1,2}, //number of each elements
404+
{12.0,1.0}, //atomic mass
405+
"Direct", //coordination type
406+
{0.0,0.0,0.0, //atomic coordinates
407+
0.00001,0.00001,0.00001,
408+
-3.05,-2.8,0.0})},
409+
{"C1H2-SD", UcellTestPrepare(
410+
"bcc", //latname
411+
2, //lmaxmax
412+
false, //init_vel
413+
false, //selective_dyanmics
414+
true, //relax_new
415+
"volume", //fixed_axes
416+
1.8897261254578281, //lat0
417+
{0.1,0.1,0.1, //latvec
418+
0.15,0.15,0.15,
419+
0.05,0.05,0.05},
420+
{"C","H"}, //elements
421+
{"C.upf","H.upf"}, //upf file
422+
{"upf201","upf201"}, //upf types
423+
{"C.orb","H.orb"}, //orb file
424+
{1,2}, //number of each elements
425+
{12.0,1.0}, //atomic mass
426+
"Direct", //coordination type
427+
{0.1,0.1,0.1, //atomic coordinates
428+
0.15,0.15,0.15,
429+
0.05,0.05,0.05})},
430+
{"C1H2-PBA", UcellTestPrepare(
431+
"bcc", //latname
432+
2, //lmaxmax
433+
false, //init_vel
434+
false, //selective_dyanmics
435+
true, //relax_new
436+
"volume", //fixed_axes
437+
1.8897261254578281, //lat0
438+
{0.1,0.1,0.1, //latvec
439+
0.15,0.15,0.15,
440+
0.05,0.05,0.05},
441+
{"C","H"}, //elements
442+
{"C.upf","H.upf"}, //upf file
443+
{"upf201","upf201"}, //upf types
444+
{"C.orb","H.orb"}, //orb file
445+
{1,2}, //number of each elements
446+
{12.0,1.0}, //atomic mass
447+
"Direct", //coordination type
448+
{-0.1,-0.1,-0.1, //atomic coordinates
449+
1.2,1.2,1.2,
450+
-3.05,-2.8,0.0})},
451+
{"C1H2-Read", UcellTestPrepare(
452+
"bcc", //latname
453+
2, //lmaxmax
454+
true, //init_vel
455+
true, //selective_dyanmics
456+
true, //relax_new
457+
"volume", //fixed_axes
458+
1.8897261254578281, //lat0
459+
{10.0,0.0,0.0, //latvec
460+
0.0,10.0,0.0,
461+
0.0,0.0,10.0},
462+
{"C","H"}, //elements
463+
{"C.upf","H.upf"}, //upf file
464+
{"upf201","upf201"}, //upf types
465+
{"C.orb","H.orb"}, //orb file
466+
{1,2}, //number of each elements
467+
{12.0,1.0}, //atomic mass
468+
"Direct", //coordination type
469+
{0.1,0.1,0.1, //atomic coordinates
470+
0.12,0.12,0.12,
471+
0.08,0.08,0.08})}
472+
};
223473
#endif

0 commit comments

Comments
 (0)