Skip to content

Commit 4fcb6ed

Browse files
authored
Merge pull request #107 from PeizeLin/develop
The old and new programmes of reading INPUT coexist now.
2 parents bf2f9d1 + 3dc7853 commit 4fcb6ed

File tree

10 files changed

+64
-33
lines changed

10 files changed

+64
-33
lines changed

source/driver.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
#include "src_io/print_info.h"
1313
#include "module_base/timer.h"
1414

15+
#include "src_io/read_txt_input_list.h"
16+
#include "src_io/read_txt_input_process.h"
17+
1518
Driver::Driver(){}
1619

1720

@@ -77,6 +80,11 @@ void Driver::reading(void)
7780
INPUT.Print( ss1.str() );
7881
//ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running,"READING CARDS");
7982

83+
Read_Txt_Input::Input_List input_list;
84+
input_list.set_items();
85+
Read_Txt_Input::Input_Process input_process(input_list);
86+
input_process.read_and_convert(GlobalV::global_in_card);
87+
8088
ModuleBase::timer::tick("Driver","reading");
8189
return;
8290
}

source/input.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ void Input::Default(void)
219219
//----------------------------------------------------------
220220
// iteration
221221
//----------------------------------------------------------
222-
dr2 = 1.0e-9;
223222
niter = 40;
224223
this->nstep = 0;
225224
out_stru = 0;
@@ -944,10 +943,6 @@ bool Input::Read(const std::string &fn)
944943
//----------------------------------------------------------
945944
// iteration
946945
//----------------------------------------------------------
947-
else if (strcmp("dr2", word) == 0)
948-
{
949-
read_value(ifs, dr2);
950-
}
951946
else if (strcmp("niter", word) == 0)
952947
{
953948
read_value(ifs, niter);
@@ -1860,7 +1855,8 @@ bool Input::Read(const std::string &fn)
18601855
//xiaohui add 2015-09-15
18611856
if(word[0] != '#' && word[0] != '/')
18621857
{
1863-
input_error = 1;
1858+
// Peize Lin delete 2022.01.06 temporarily
1859+
//input_error = 1;
18641860
std::cout<<" THE PARAMETER NAME '" << word << "' IS NOT USED!" << std::endl;
18651861
}
18661862
// mohan screen this 2012-06-30
@@ -2312,7 +2308,6 @@ void Input::Bcast()
23122308
Parallel_Common::bcast_int( test_force );
23132309
Parallel_Common::bcast_int( test_stress );
23142310

2315-
Parallel_Common::bcast_double( dr2 );
23162311
Parallel_Common::bcast_int( niter );
23172312
Parallel_Common::bcast_int( this->nstep );
23182313
Parallel_Common::bcast_int( out_stru ); //mohan add 2012-03-23

source/input.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ class Input
179179
//==========================================================
180180
// iteration
181181
//==========================================================
182-
double dr2; // \sum |rhog_out - rhog_in |^2
183182
int niter; // number of max elec iter
184183
int nstep; // number of max ionic iter
185184
int out_stru; // outut stru file each ion step

source/input_conv.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ void Input_Conv::Convert(void)
193193
GlobalV::TEST_FORCE = INPUT.test_force;
194194
GlobalV::TEST_STRESS = INPUT.test_stress;
195195

196-
//----------------------------------------------------------
197-
// iteration (1/3)
198-
//----------------------------------------------------------
199-
GlobalV::DRHO2 = INPUT.dr2;
200-
201196
//----------------------------------------------------------
202197
// wavefunction / charge / potential / (2/4)
203198
//----------------------------------------------------------

source/src_io/read_txt_input-general.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace Read_Txt_Input
1818
{
1919
this->output_labels.push_back("Parameters (1.General)");
2020

21-
{
21+
/*{ // LDA ; LSDA ; non-linear spin
2222
Input_Item item("nspin");
2323
item.default_1(1);
2424
item.annotation = "1: single spin; 2: up and down spin; 4: noncollinear spin";
@@ -32,9 +32,9 @@ namespace Read_Txt_Input
3232
GlobalV::NSPIN = self.values[0].geti();
3333
};
3434
this->add_item(item);
35-
}
35+
}*/
3636

37-
{
37+
/*{ // number of atom types
3838
Input_Item item("ntype");
3939
item.default_1(0);
4040
item.annotation = "atom species number";
@@ -48,9 +48,9 @@ namespace Read_Txt_Input
4848
GlobalC::ucell.ntype = self.values[0].geti();
4949
};
5050
this->add_item(item);
51-
}
51+
}*/
5252

53-
{
53+
/*{ // turn on symmetry or not
5454
Input_Item item("symmetry");
5555
item.default_1(false);
5656
item.annotation = "turn symmetry on or off";
@@ -59,6 +59,6 @@ namespace Read_Txt_Input
5959
ModuleSymmetry::Symmetry::symm_flag = self.values[0].getb();
6060
};
6161
this->add_item(item);
62-
}
62+
}*/
6363
}
6464
}

source/src_io/read_txt_input-pw.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Read_Txt_Input
1717
{
1818
this->output_labels.push_back("Parameters (2.Pw)");
1919

20-
{
20+
/*{
2121
Input_Item item("ecutwfc");
2222
item.default_1(100.0,"Ry");
2323
item.check_values_size(1,2);
@@ -39,6 +39,22 @@ namespace Read_Txt_Input
3939
// ?? GlobalC::pw.set()
4040
};
4141
this->add_item(item);
42+
}*/
43+
44+
{ // \sum |rhog_out - rhog_in |^2
45+
Input_Item item("dr2");
46+
item.default_1(1.0e-9);
47+
item.annotation = "charge density error";
48+
item.check_transform = [](Input_Item &self)
49+
{
50+
if(self.values[0].getd()<=0)
51+
throw std::invalid_argument("dr2 must > 0");
52+
};
53+
item.convert = [](const Input_Item &self)
54+
{
55+
GlobalV::DRHO2 = self.values[0].getd();
56+
};
57+
this->add_item(item);
4258
}
4359
}
4460
}

source/src_io/read_txt_input-spectrum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Read_Txt_Input
1313
{
1414
this->output_labels.push_back("Parameters (15.Spectrum)");
1515

16-
{
16+
/*{
1717
Input_Item item("ocp_set");
1818
item.annotation = "set occupation number";
1919
item.check_values_size(0, std::numeric_limits<int>::max());
@@ -22,6 +22,6 @@ namespace Read_Txt_Input
2222
// ...
2323
};
2424
this->add_item(item);
25-
}
25+
}*/
2626
}
2727
}

source/src_io/read_txt_input_list.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
//=======================
55

66
#include "read_txt_input_list.h"
7+
#include "module_base/tool_title.h"
78

89
namespace Read_Txt_Input
910
{
1011
void Input_List::add_item(const Input_Item &input_item)
1112
{
12-
list.insert(make_pair(input_item.label, input_item));
13-
output_labels.push_back(input_item.label);
13+
this->list.insert(make_pair(input_item.label, input_item));
14+
this->output_labels.push_back(input_item.label);
1415
}
1516

1617
/*
@@ -33,9 +34,10 @@ namespace Read_Txt_Input
3334

3435
void Input_List::set_items()
3536
{
36-
set_items_general();
37-
set_items_pw();
38-
set_items_spectrum();
37+
ModuleBase::TITLE("Input_List","set_items");
38+
this->set_items_general();
39+
this->set_items_pw();
40+
this->set_items_spectrum();
3941
}
4042

4143
}

source/src_io/read_txt_input_process.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "src_io/read_txt_tools.h"
99
#include "module_base/global_variable.h"
10+
#include "module_base/tool_title.h"
1011

1112
#ifdef USE_CEREAL_SERIALIZATION
1213
#include "src_lcao/serialization_cereal.h"
@@ -16,26 +17,36 @@ namespace Read_Txt_Input
1617
{
1718
void Input_Process::read_and_convert(const std::string &file_name)
1819
{
20+
ModuleBase::TITLE("Input_Process","read_and_convert");
1921
if(GlobalV::MY_RANK==0)
2022
{
2123
this->read(file_name);
2224
this->check_transform();
2325
this->default_2();
24-
this->out(GlobalV::global_out_dir + file_name);
26+
// Peize Lin delete 2022.01.06 temporarily
27+
//this->out(GlobalV::global_out_dir + file_name);
2528
}
2629
this->bcast();
30+
// Peize Lin add 2022.01.06 temporarily
31+
this->out(GlobalV::global_out_dir + file_name + "-new-"+std::to_string(GlobalV::MY_RANK));
2732
this->convert();
2833
}
2934

3035
void Input_Process::read(const std::string &file_name)
3136
{
37+
ModuleBase::TITLE("Input_Process","read");
3238
const std::map<std::string, std::vector<std::string>> inputs_read
3339
= Read_Txt_Tools::read_file_to_map(file_name, {"#","\\"}, true);
3440
for(const auto & input_read : inputs_read)
3541
{
3642
const auto item_ptr = this->input.list.find(input_read.first);
3743
if(item_ptr==this->input.list.end())
38-
throw std::out_of_range("input_read.first");
44+
{
45+
// Peize Lin delete interrupt 2022.01.06 temporarily
46+
//throw std::out_of_range("input_read.first");
47+
GlobalV::ofs_warning<<" INPUT-new '" << input_read.first << "' IS NOT USED!" << std::endl;
48+
continue;
49+
}
3950
Read_Txt_Input::Input_Item &item = item_ptr->second;
4051

4152
item.values_size_read = input_read.second.size();
@@ -52,6 +63,7 @@ namespace Read_Txt_Input
5263

5364
void Input_Process::check_transform()
5465
{
66+
ModuleBase::TITLE("Input_Process","check_transform");
5567
for(auto &tmp : this->input.list)
5668
{
5769
Read_Txt_Input::Input_Item &item = tmp.second;
@@ -81,13 +93,15 @@ namespace Read_Txt_Input
8193

8294
void Input_Process::default_2()
8395
{
96+
ModuleBase::TITLE("Input_Process","default_2");
8497
for(auto &item : this->input.list)
8598
item.second.default_2(item.second, this->input.list);
8699
this->default_2_global(this->input.list);
87100
}
88101

89102
void Input_Process::out(const std::string &file_name) const
90103
{
104+
ModuleBase::TITLE("Input_Process","out");
91105
std::ofstream ofs(file_name);
92106
for(const std::string &label : this->input.output_labels)
93107
{
@@ -105,9 +119,9 @@ namespace Read_Txt_Input
105119
if(item.values_type[i]=="s")
106120
ofs<<item.values[i].gets()<<" ";
107121
else if(item.values_type[i]=="d")
108-
ofs<<std::to_string(item.values[i].getd())<<" ";
122+
ofs<<item.values[i].getd()<<" ";
109123
else if(item.values_type[i]=="i")
110-
ofs<<std::to_string(item.values[i].geti())<<" ";
124+
ofs<<item.values[i].geti()<<" ";
111125
else if(item.values_type[i]=="b")
112126
{
113127
if(item.values[i].getb())
@@ -125,15 +139,18 @@ namespace Read_Txt_Input
125139

126140
void Input_Process::bcast()
127141
{
142+
ModuleBase::TITLE("Input_Process","bcast");
128143
#ifdef USE_CEREAL_SERIALIZATION
129-
ModuleBase::bcast_data_cereal(this->input.list, MPI_COMM_WORLD, 0);
144+
for(auto &item : this->input.list)
145+
ModuleBase::bcast_data_cereal(item.second, MPI_COMM_WORLD, 0);
130146
#else
131147
#error Input_Process::bcast() needs cereal
132148
#endif
133149
}
134150

135151
void Input_Process::convert()
136152
{
153+
ModuleBase::TITLE("Input_Process","convert");
137154
for(auto &item : this->input.list)
138155
item.second.convert(item.second);
139156
this->convert_global(this->input.list);

source/src_io/write_input.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ void Input::Print(const std::string &fn)const
5252
ModuleBase::GlobalFunc::OUTP(ofs,"diago_david_ndim",diago_david_ndim,"max dimension for davidson");
5353
}
5454
ModuleBase::GlobalFunc::OUTP(ofs,"ethr",ethr,"threshold for eigenvalues is cg electron iterations");
55-
ModuleBase::GlobalFunc::OUTP(ofs,"dr2",dr2,"charge density error");
5655
ModuleBase::GlobalFunc::OUTP(ofs,"start_wfc",start_wfc,"start wave functions are from 'atomic' or 'file'");
5756
ModuleBase::GlobalFunc::OUTP(ofs,"start_charge",start_pot,"start charge is from 'atomic' or file");
5857
ModuleBase::GlobalFunc::OUTP(ofs,"charge_extrap",charge_extrap,"atomic; first-order; second-order; dm:coefficients of SIA");

0 commit comments

Comments
 (0)