LandauGinzburg
Loading...
Searching...
No Matches
field_conf.cpp
Go to the documentation of this file.
1
9#include "field_nicolai.hpp"
10
18const double SOL_ID_MAXVAL = 1.0e-11;
25const double MAX_NRERR = 1.0e-14;
33const double NR_INTERRUPTION = 1.0e9;
34
52typedef struct {
53 int Li;
54 int num_f;
56 int testmode;
57 int num_nrsolutions;
58 int num_nicolai;
59 int num_initialnic;
60 int num_loop;
61 int num_power;
62 int num_coupling;
63 VectorXi k;
64 VectorXd lambda;
66
67static lg_params_t params;
68
75void NicolaiConf (const lg_params_t lp) {
76 try {
77 if (lp.Li % 2 != 0)
78 throw "ERROR<NicolaiConf> Box size is not EVEN.";
79
80 if (lp.spt==SuperPotentialType::AlgebraA) {
81 if (lp.num_f != 1)
82 throw "ERROR<NicolaiConf> SuperPotentialType::AlgebraA: number of fields should be 1.";
83 if (lp.k.size() != 1)
84 throw "ERROR<NicolaiConf> SuperPotentialType::AlgebraA: number of powers should be 1.";
85 if (lp.lambda.size() != 1)
86 throw "ERROR<NicolaiConf> SuperPotentialType::AlgebraA: number of couplings should be 1.";
87 }
88 else if (lp.spt==SuperPotentialType::AlgebraD) {
89 if (lp.num_f != 2)
90 throw "ERROR<NicolaiConf> SuperPotentialType::AlgebraD: number of fields should be 2.";
91 if (lp.k.size() != 1)
92 throw "ERROR<NicolaiConf> SuperPotentialType::AlgebraD: number of powers should be 1.";
93 if (lp.lambda.size() != 2)
94 throw "ERROR<NicolaiConf> SuperPotentialType::AlgebraD: number of couplings should be 2.";
95 }
96 else if (lp.spt==SuperPotentialType::AlgebraE) {
97 if (lp.num_f != 2)
98 throw "ERROR<NicolaiConf> SuperPotentialType::AlgebraE: number of fields should be 2.";
99 if (lp.lambda.size() != 2)
100 throw "ERROR<NicolaiConf> SuperPotentialType::AlgebraE: number of couplings should be 2.";
101 }
102 else {
103 if (lp.num_f < 1)
104 throw "ERROR<NicolaiConf> Number of fields should be positive.";
105 if (lp.k.size() == 0)
106 throw "ERROR<NicolaiConf> No values in powers.";
107 if (lp.lambda.size() == 0)
108 throw "ERROR<NicolaiConf> No values in couplings";
109 }
110
111 cerr << endl << "Calc start ..." << endl;
112 //--Start parallel computing (openmp)--//
113 #pragma omp parallel for
114 for (int in = lp.num_initialnic; in < lp.num_initialnic + lp.num_nicolai; ++in) {
115 NicolaiSol nic(lp.Li, lp.num_f, in);
116 double dmp = nic.nr_method(lp.k, lp.lambda, lp.num_nrsolutions, lp.num_loop, lp.spt);
117
118 int num_sol = nic.num_sol();
119 VectorXi signs(num_sol);
120 for (int i = 0; i < num_sol; ++i) {signs(i) = nic.sign_det(i);}
121 if (SuperPotentialType_StdNumSol(lp.k, lp.spt) != num_sol) {
122 cerr << "lm" << lp.lambda.transpose() << " k" << lp.k.transpose() << " L" << lp.Li << " n" << in
123 << " " << "num_sol: " << num_sol << endl;
124 }
125 for (int i = 0; i < num_sol; ++i) {
126 if (signs(i) == -1) {
127 cerr << "lm" << lp.lambda.transpose() << " k" << lp.k.transpose() << " L" << lp.Li << " n" << in
128 << "_" << i << " " << "sign: -1" << endl;
129 }
130 }
131
132 nic.nic_output(lp.k, lp.lambda, lp.num_nrsolutions, signs, dmp, nic.max_err(), lp.spt);
133 nic.phi_output(in, signs);
134 } //--End parallel computing (openmp)--//
135 cerr << "Calc end ..." << endl << endl;
136 return;
137 } catch (const char *str) {cerr << str << endl; return;}
138}
139
150void Test_SignDet (const int Li, const int num_f, const int loop) {
151 cout << "Box size : " << Li << endl
152 << "Number of fields: " << num_f << endl
153 << "Number of loop : " << loop << endl << endl;
154 int count = 0;
155 int which_fast = 0;
156 VectorXd times = VectorXd::Zero(loop);
157 for (int i = 0; i < loop; ++i) {
159
160 clock_t start1 = clock();
161 int sign = pt.sign_det();
162 clock_t end1 = clock();
163 double t1 = (end1 - start1);
164
165 clock_t start2 = clock();
166 int sign2 = pt.sign_det4multifield();
167 clock_t end2 = clock();
168 double t2 = (end2 - start2);
169
170 if (t1 > t2) ++which_fast;
171 times(i) = t1 / t2;
172 if (sign != sign2) {cout << i << ": Noooooooo!!!!!!! ("
173 << sign << ", " << sign2 << ")" << endl;}
174 if (sign == -1) {
175 ++count; cout << " #" << i << ": sign_modf is negative" << endl;
176 }
177 if (sign2 == -1) {
178 cout << " #" << i << ": sign_naive is negative" << endl;
179 }
180 }
181 cout << endl
182 << "Positive, Negative :" << loop - count << ", " << count << endl
183 << endl
184 << "Which is fast? modf:" << loop - which_fast
185 << ", naive:" << which_fast << endl
186 << endl
187 << "Ratio of time (modf/naive): "
188 << " Average : "
189 << times.mean() << endl
190 << " Minimum, Maximum: "
191 << times.minCoeff() << ", " << times.maxCoeff() << endl;
192 return;
193}
194
195
199static int get_val(FILE* fp, const char *str, const char* fmt, void* val){
200 char c[128];
201 if(1!=fscanf(fp,"%s",c)) {
202 fprintf(stderr,"Error reading input file at %s\n",str);
203 exit(1);
204 }
205 if(strcmp(str,c)!=0) {
206 fprintf(stderr,"Error reading input file expected %s found %s\n",str,c);
207 exit(1);
208 }
209 if(1!=fscanf(fp,fmt,val)) {
210 fprintf(stderr,"Error reading input file at %s\n",str);
211 fprintf(stderr,"Cannot read value format %s\n",fmt);
212 exit(1);
213 }
214 return 0;
215}
216
220static int read_input(char *input) {
221 FILE* fp;
222 fp=fopen(input,"r");
223 if (fp==NULL) {
224 fprintf(stderr,"Cannot open input file %s\n",input);
225 exit(1);
226 }
227 int spt;
228 get_val(fp, "Li", "%i",&(params.Li));
229 get_val(fp, "num_f", "%i",&params.num_f);
230 get_val(fp, "potentialtype", "%i",&spt);
231 if (spt==0)
232 params.spt = SuperPotentialType::AlgebraA;
233 else if (spt==1)
234 params.spt = SuperPotentialType::AlgebraD;
235 else if (spt==2)
236 params.spt = SuperPotentialType::AlgebraE;
237 else if (spt==3)
238 params.spt = SuperPotentialType::Custom;
239 get_val(fp, "testmode", "%i",&params.testmode);
240 get_val(fp, "num_nrsolutions", "%i",&params.num_nrsolutions);
241 get_val(fp, "num_nicolai", "%i",&params.num_nicolai);
242 get_val(fp, "num_initialnic", "%i",&params.num_initialnic);
243 get_val(fp, "num_loop", "%i",&params.num_loop);
244 get_val(fp, "num_power", "%i",&params.num_power);
245 params.k = VectorXi::Zero(params.num_power);
246 for (int i = 0; i<params.num_power; ++i) {
247 get_val(fp, "k", "%i",&params.k(i));
248 }
249 get_val(fp, "num_coupling", "%i",&params.num_coupling);
250 params.lambda = VectorXd::Zero(params.num_coupling);
251 for (int i = 0; i<params.num_coupling; ++i) {
252 get_val(fp, "lambda", "%lf",&params.lambda(i));
253 }
254 cerr << "Superpotential Type : ";
255 if (params.spt==SuperPotentialType::AlgebraA)
256 cerr << "Algebra A" << endl;
257 else if (params.spt==SuperPotentialType::AlgebraD)
258 cerr << "Algebra D" << endl;
259 else if (params.spt==SuperPotentialType::AlgebraE)
260 cerr << "Algebra E" << endl;
261 else if (params.spt==SuperPotentialType::Custom)
262 cerr << "Custom type" << endl;
263 cerr << "Physical Box Size : " << params.Li << endl
264 << "Power in SuperPotential: " << params.k.transpose() << endl
265 << "Coupling : " << params.lambda.transpose() << endl << endl
266 << "Configuration Number : " << params.num_initialnic << "~" << params.num_initialnic + params.num_nicolai << endl
267 << "Number of Loop : " << params.num_loop << endl;
268 return 0;
269}
270
275int main (int argc, char*argv[]) {
276 cout << endl << "main start ..." << endl;
277 clock_t start = clock();
278
279 // int Li = 16;
280 // int num_f = 3;
281 // int loop = 100;
282 // Test_SignDet(Li, num_f, loop);
283
284 if (argc != 2) {
285 fprintf(stderr,"Number of arguments not correct\n");
286 fprintf(stderr,"Usage: %s <infile> \n",argv[0]);
287 exit(1);
288 }
289
290 read_input(argv[1]);
291
292 if (params.testmode==1) {
293 NicolaiSol nic(params.Li, params.num_f, 0);
294 nic.test_nr_method(params.k,params.lambda,params.num_loop,params.num_nrsolutions,params.spt);
295 }
296 else
297 NicolaiConf(params);
298
299 clock_t end = clock();
300 cerr << (double)(end - start) / CLOCKS_PER_SEC << "sec" << endl;
301 cout << "main end ..." << endl;
302}
303
void nic_output(const VectorXi k, const VectorXd lambda, const int num_nrsol, const VectorXi signs, const int dmp, const double max_err, const SuperPotentialType spt) const
Output to file.
Execute the Newton–Raphson method; Combine solutions; Obtain sign det for each Scalar.
int num_sol() const
Number of solutions.
void phi_output(const int in, const VectorXi signs) const
Output to file.
void test_nr_method(const VectorXi k, const VectorXd lambda, const int LOOP, const int TRIAL, const SuperPotentialType t=SuperPotentialType::AlgebraA)
Observe the numerical convergence of NR method for each system.
int sign_det(const int n) const
Sign determinant (Jacobian)
double max_err() const
Maximum error of NR method.
double nr_method(const VectorXi k, const VectorXd lambda, const int num_nrsol, const int LOOP, const SuperPotentialType t=SuperPotentialType::AlgebraA)
Newton–Raphson method.
Compute Jacobian and its sign determinant.
int sign_det(const int debug=0) const
Sign determinant with a fast algorithm (num_f < 4)
int sign_det4multifield(const int debug=0) const
Sign determinant for mutli-superfield.
const double SOL_ID_MAXVAL
Identification of scalar solutions.
int main(int argc, char *argv[])
Main function.
const double NR_INTERRUPTION
Interruption of NR iteration.
void NicolaiConf(const lg_params_t lp)
Solve a Landau–Ginzburg model by NR method; Parallel computing with openmp.
const double MAX_NRERR
Max error of NR iteration.
void Test_SignDet(const int Li, const int num_f, const int loop)
Test program: computation of sign_det() in Potential; Compare signs and times, which are computed by ...
int SuperPotentialType_StdNumSol(const VectorXi k, const SuperPotentialType t)
Standard number of solutions for each SuperPotentialType.
Definition of the classes associated with Nicolai map.
SuperPotentialType
Types of superpotentials.
Structure lg_params_t.