Skip to content

Commit ac8b358

Browse files
committed
Merge branch 'input' into develop
2 parents 3c50fbf + 6ccb78a commit ac8b358

14 files changed

+612
-1
lines changed

source/Makefile.Objects

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ read_cell_pseudopots.o\
247247
read_dm.o\
248248
read_txt_tools.o\
249249
read_txt_stru.o\
250+
read_txt_input_value.o\
251+
read_txt_input_list.o\
252+
read_txt_input_process.o\
253+
read_txt_input-general.o\
254+
read_txt_input-pw.o\
250255
write_pot.o\
251256
write_rho.o\
252257
write_rho_cube.o\

source/src_io/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ add_library(
2424
read_dm.cpp
2525
read_rho.cpp
2626
read_txt_tools.cpp
27+
read_txt_input_value.cpp
28+
read_txt_input_list.cpp
29+
read_txt_input_process.cpp
30+
read_txt_input-general.cpp
31+
read_txt_input-pw.cpp
2732
read_txt_stru.cpp
2833
restart.cpp
2934
rwstream.cpp
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-12-13
4+
//=======================
5+
6+
#include "read_txt_input_list.h"
7+
8+
#include "src_io/read_txt_tools.h"
9+
#include <stdexcept>
10+
11+
// for convert
12+
#include "module_base/global_variable.h"
13+
#include "src_pw/global.h"
14+
15+
namespace Read_Txt_Input
16+
{
17+
void Input_List::set_items_general()
18+
{
19+
{
20+
Input_Item item("nspin");
21+
item.default_1(1);
22+
item.annotation = "1: single spin; 2: up and down spin; 4: noncollinear spin";
23+
item.check_transform = [](Input_Item &self)
24+
{
25+
if(!Read_Txt_Tools::in_set(self.values[0].geti(), {1,2,4}))
26+
throw std::invalid_argument("nspin must be 1,2,4");
27+
};
28+
item.convert = [](const Input_Item &self)
29+
{
30+
GlobalV::NSPIN = self.values[0].geti();
31+
};
32+
this->add_item(item);
33+
}
34+
35+
{
36+
Input_Item item("ntype");
37+
item.default_1(0);
38+
item.annotation = "atom species number";
39+
item.check_transform = [](Input_Item &self)
40+
{
41+
if(self.values[0].geti()<=0)
42+
throw std::invalid_argument("ntype must > 0");
43+
};
44+
item.convert = [](const Input_Item &self)
45+
{
46+
GlobalC::ucell.ntype = self.values[0].geti();
47+
};
48+
this->add_item(item);
49+
}
50+
51+
{
52+
Input_Item item("symmetry");
53+
item.default_1(false);
54+
item.annotation = "turn symmetry on or off";
55+
item.check_transform = [](Input_Item &self)
56+
{
57+
if(!Read_Txt_Tools::in_set( self.values[0].gets(), Read_Txt_Tools::Preset::Bool))
58+
throw std::invalid_argument("symmetry must be bool");
59+
};
60+
item.convert = [](const Input_Item &self)
61+
{
62+
ModuleSymmetry::Symmetry::symm_flag = self.values[0].getb();
63+
};
64+
this->add_item(item);
65+
}
66+
}
67+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-12-13
4+
//=======================
5+
6+
#include "read_txt_input_list.h"
7+
8+
#include "module_base/constants.h"
9+
#include <stdexcept>
10+
11+
// for convert
12+
#include "module_base/global_variable.h"
13+
14+
namespace Read_Txt_Input
15+
{
16+
void Input_List::set_items_pw()
17+
{
18+
{
19+
Input_Item item("ecutwfc");
20+
item.default_1(100,"eV");
21+
item.annotation = "energy cutoff for wave functions";
22+
item.check_transform = [](Input_Item &self)
23+
{
24+
if(self.values[1].gets()=="eV"){}
25+
else if(self.values[1].gets()=="Ry")
26+
self.values[0].setd( self.values[0].getd() / ModuleBase::Ry_to_eV );
27+
else
28+
throw std::invalid_argument(self.values[1].gets());
29+
self.values[1].sets("eV");
30+
if(self.values[0].getd()<=0)
31+
throw std::invalid_argument("ecutwfc must > 0");
32+
};
33+
item.convert = [](const Input_Item &self)
34+
{
35+
// ?? GlobalC::pw.set()
36+
};
37+
this->add_item(item);
38+
}
39+
}
40+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-12-13
4+
//=======================
5+
6+
#ifndef READ_TXT_INPUT_ITEM_TEMPLATE_H
7+
#define READ_TXT_INPUT_ITEM_TEMPLATE_H
8+
9+
#include "read_txt_input_item.h"
10+
11+
namespace Read_Txt_Input
12+
{
13+
template<typename T>
14+
void Input_Item::default_1(const T &value)
15+
{
16+
set_value(value);
17+
}
18+
19+
template <typename T_head, typename... T_tail>
20+
void Input_Item::default_1( const T_head &value_head, const T_tail... values_tail)
21+
{
22+
set_value(value_head);
23+
default_1(values_tail...);
24+
}
25+
26+
template<>
27+
void Input_Item::set_value(const bool &b)
28+
{
29+
this->values.push_back({});
30+
this->values.back().setb(b);
31+
}
32+
33+
template<>
34+
void Input_Item::set_value(const int &i)
35+
{
36+
this->values.push_back({});
37+
this->values.back().seti(i);
38+
}
39+
40+
template<>
41+
void Input_Item::set_value(const double &d)
42+
{
43+
this->values.push_back({});
44+
this->values.back().setd(d);
45+
}
46+
47+
template<>
48+
void Input_Item::set_value(const std::string &s)
49+
{
50+
this->values.push_back({});
51+
this->values.back().sets(s);
52+
}
53+
54+
template<>
55+
void Input_Item::set_value(const char*const &s)
56+
{
57+
this->values.push_back({});
58+
this->values.back().sets(std::string(s));
59+
}
60+
}
61+
62+
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-12-13
4+
//=======================
5+
6+
#ifndef READ_TXT_INPUT_ITEM_H
7+
#define READ_TXT_INPUT_ITEM_H
8+
9+
#include "read_txt_input_value.h"
10+
11+
#include <vector>
12+
#include <map>
13+
#include <string>
14+
#include <functional>
15+
16+
#ifdef USE_CEREAL_SERIALIZATION
17+
#include <cereal/access.hpp>
18+
#endif
19+
20+
namespace Read_Txt_Input
21+
{
22+
class Input_Item
23+
{
24+
public:
25+
// call these functions
26+
Input_Item(const std::string &label_in) :label(label_in) {}
27+
template<typename T>
28+
void default_1(const T &value);
29+
template <typename T_head, typename... T_tail>
30+
void default_1( const T_head &value_head, const T_tail... values_tail);
31+
32+
// set these variables and functions
33+
std::string annotation;
34+
std::function<void(Input_Item&)> check_transform
35+
= [](Input_Item&self){};
36+
std::function<void(const std::map<std::string, Input_Item>&)> default2
37+
= [](const std::map<std::string, Input_Item>&list){};
38+
std::function<void(const Input_Item&)> convert
39+
= [](const Input_Item&item){};
40+
41+
std::vector<Input_Value> values;
42+
43+
private:
44+
std::string label;
45+
//int value_read_size = -1;
46+
47+
friend class Input_List;
48+
friend class Input_Process;
49+
50+
template<typename T>
51+
void set_value(const T &value);
52+
53+
#ifdef USE_CEREAL_SERIALIZATION
54+
public:
55+
Input_Item() = default;
56+
private:
57+
friend class cereal::access;
58+
template <class Archive> void serialize( Archive & ar );
59+
#endif
60+
};
61+
}
62+
63+
#include "read_txt_input_item-template.h"
64+
65+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-12-13
4+
//=======================
5+
6+
#include "read_txt_input_list.h"
7+
8+
namespace Read_Txt_Input
9+
{
10+
void Input_List::add_item(const Input_Item &input_item)
11+
{
12+
list.insert(make_pair(input_item.label, input_item));
13+
add_order.push_back(input_item.label);
14+
}
15+
16+
/*
17+
void Input_List::check_value_size(const Input_Item& input_item, const int size)
18+
{
19+
if(input_item.value_read_size==-1)
20+
return;
21+
if(input_item.value_read_size!=size)
22+
throw std::out_of_range(std::to_string(input_item.value_read_size)+std::to_string(size));
23+
}
24+
25+
void Input_List::check_value_size(const Input_Item& input_item, const int size_low, const int size_up)
26+
{
27+
if(input_item.value_read_size==-1)
28+
return;
29+
if(input_item.value_read_size<size_low || input_item.value_read_size>size_up)
30+
throw std::out_of_range(std::to_string(input_item.value_read_size)+std::to_string(size_low)+std::to_string(size_up));
31+
}
32+
*/
33+
34+
void Input_List::set_items()
35+
{
36+
set_items_general();
37+
set_items_pw();
38+
}
39+
40+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-12-13
4+
//=======================
5+
6+
#ifndef READ_TXT_INIPUT_LIST_H
7+
#define READ_TXT_INIPUT_LIST_H
8+
9+
#include "read_txt_input_item.h"
10+
11+
#include <vector>
12+
#include <map>
13+
#include <string>
14+
15+
namespace Read_Txt_Input
16+
{
17+
class Input_List
18+
{
19+
public:
20+
void set_items();
21+
22+
private:
23+
void add_item(const Input_Item &input_item);
24+
//static void check_value_size(const Input_Item& input_item, const int size);
25+
//static void check_value_size(const Input_Item& input_item, const int size_low, const int size_up);
26+
27+
std::map<std::string, Input_Item> list;
28+
std::vector<std::string> add_order;
29+
30+
void set_items_general();
31+
void set_items_pw();
32+
33+
friend class Input_Process;
34+
};
35+
}
36+
37+
#endif

0 commit comments

Comments
 (0)