/* Copyright 2015-2022 Ian Jauslin Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* meankondo A tool to compute the renormalization group flow for Fermionic hierarchical models */ #include #include // pre-compiler definitions #include "definitions.cpp" // various arrays #include "array.h" // list of fields #include "fields.h" // numbers #include "number.h" // polynomials #include "polynomial.h" // list of rccs #include "idtable.h" // grouped representation of polynomials #include "grouped_polynomial.h" // command line parser #include "cli_parser.h" // parse input file #include "parse_file.h" // means #include "mean.h" // various string operations #include "istring.h" // symbolic trees # include "tree.h" // read cli arguments int read_args_meankondo(int argc,const char* argv[], Str_Array* str_args, Meankondo_Options* opts); // print usage message int print_usage_meankondo(); // check consistency of options int check_meankondo_opts(Meankondo_Options opts); // compute flow int compute_flow(Str_Array str_args, Meankondo_Options opts); // compute average int compute_average(Polynomial init_poly, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, int print_progress, Polynomial* exp_poly); int main (int argc, const char* argv[]){ // string arguments Str_Array str_args; // options Meankondo_Options opts; // read command-line arguments read_args_meankondo(argc,argv,&str_args,&opts); // check command-line arguments check_meankondo_opts(opts); // warning message if representing rational numbers as floats #ifdef RATIONAL_AS_FLOAT fprintf(stderr,"info: representing rational numbers using floats\n"); #endif compute_flow(str_args, opts); //free memory free_Str_Array(str_args); return(0); } // parse command-line arguments #define CP_FLAG_THREADS 1 int read_args_meankondo(int argc,const char* argv[], Str_Array* str_args, Meankondo_Options* opts){ int i; // pointers char* ptr; // file to read the polynomial from in flow mode const char* file=""; // flag that indicates what argument is being read int flag=0; // whether a file was specified on the command-line int exists_file=0; // defaults // single thread (*opts).threads=1; // do not chain (*opts).chain=0; // do not print progress (*opts).print_progress=0; // print the flow equation (*opts).group_poly=1; // loop over arguments for(i=1;i\n\n"); return(0); } // check consistency of options int check_meankondo_opts(Meankondo_Options opts){ if(opts.chain==1 && opts.group_poly==0){ fprintf(stderr,"aborting: the '-C' and '-A' options are incompatible\n"); exit(-1); } return(0); } // compute the renormalization group flow int compute_flow(Str_Array str_args, Meankondo_Options opts){ int i; // index of the entry in the input file int arg_index; // header of the entry Char_Array arg_header; // list of fields Fields_Table fields; // their propagator Polynomial_Matrix propagator; // preprocessor variables Variables variables; // initial polynomial Polynomial init_poly; // list of rccs Id_Table idtable; // groups of independent fields Groups groups; // flow equation Grouped_Polynomial flow_equation; // polynomial produced by the averaging operation Polynomial exp_poly; // parse fields arg_index=find_str_arg("fields", str_args); if(arg_index<0){ fprintf(stderr,"error: no fields entry in the configuration file\n"); exit(-1); } else{ parse_input_fields(str_args.strs[arg_index],&fields); } // parse variables // must precede id_table, virtual_fields, identities and input_polynomial arg_index=find_str_arg("preprocessor_variables", str_args); if(arg_index>=0){ parse_input_variables(str_args.strs[arg_index],&variables); } else{ init_Variables(&variables,1); } // parse id table if(opts.group_poly==1){ arg_index=find_str_arg("id_table", str_args); if(arg_index<0){ fprintf(stderr,"error: no id table entry in the configuration file\n"); exit(-1); } else{ parse_input_id_table(str_args.strs[arg_index],&idtable, fields, variables); } } // parse virtual_fields arg_index=find_str_arg("virtual_fields", str_args); if(arg_index>=0){ parse_input_virtual_fields(str_args.strs[arg_index], &fields, variables); } // parse input polynomial arg_index=find_str_arg("input_polynomial", str_args); if(arg_index>=0){ parse_input_polynomial(str_args.strs[arg_index],&init_poly, fields, variables); } else{ fprintf(stderr,"error: no input polynomial entry in the configuration file\n"); exit(-1); } // propagator arg_index=find_str_arg("propagator", str_args); if(arg_index<0){ fprintf(stderr,"error: no propagator entry in the configuration file\n"); exit(-1); } else{ parse_input_propagator(str_args.strs[arg_index],&propagator, fields); } // parse identities arg_index=find_str_arg("identities", str_args); if(arg_index>=0){ parse_input_identities(str_args.strs[arg_index],&fields, variables); } // parse groups (must come after virtual_fields and propagator) arg_index=find_str_arg("groups", str_args); if(arg_index>=0){ parse_input_groups(str_args.strs[arg_index],&groups, propagator, fields); } else{ init_Groups(&groups, 1); } // compute the average compute_average(init_poly, fields, propagator, groups, opts.threads, opts.print_progress, &exp_poly); free_Polynomial(init_poly); free_Polynomial_Matrix(propagator); free_Groups(groups); // parse postprocessing entry arg_index=find_str_arg("postprocess_operation", str_args); if(arg_index>=0){ add_polynomial_to_variables("OUT", exp_poly, &variables); // parse postprocess entry Polynomial postprocess_operation; parse_input_polynomial(str_args.strs[arg_index], &postprocess_operation, fields, variables); // replace exp_poly free_Polynomial(exp_poly); exp_poly=postprocess_operation; } if(opts.group_poly==1){ // flow equation group_polynomial(exp_poly, &flow_equation, idtable, fields); } // postprocess flow equation arg_index=find_str_arg("postprocess_flow_equation", str_args); if(arg_index>=0){ Polynomial flow_polynomial; // polynomial made of the rcc's multiplied by the corresponding fields (parsed from idtable) idtable_to_polynomial(idtable, &flow_polynomial); // add to variables add_polynomial_to_variables("FLOW", flow_polynomial, &variables); free_Polynomial(flow_polynomial); // parse postprocess entry Polynomial postprocess_polynomial; parse_input_polynomial(str_args.strs[arg_index], &postprocess_polynomial, fields, variables); // convert to flow equation Grouped_Polynomial postprocess_flow_equation; group_polynomial(postprocess_polynomial, &postprocess_flow_equation, idtable, fields); free_Polynomial(postprocess_polynomial); // apply postprocessing to flow equation Grouped_Polynomial new_flow; compose_flow_equations(postprocess_flow_equation, flow_equation, &new_flow); free_Grouped_Polynomial(postprocess_flow_equation); // replace flow_equation free_Grouped_Polynomial(flow_equation); flow_equation=new_flow; } // if chain then print config file if(opts.chain==1){ for(i=0;i=0){ Polynomial rcc_polynomial; // polynomial made of the rcc's multiplied by the corresponding fields (parsed from idtable) idtable_to_polynomial(idtable, &rcc_polynomial); // add to variables add_polynomial_to_variables("RCC", rcc_polynomial, &variables); free_Polynomial(rcc_polynomial); // parse postprocess entry Polynomial numerical_postprocess_operation; parse_input_polynomial(str_args.strs[arg_index], &numerical_postprocess_operation, fields, variables); // convert to flow equation Grouped_Polynomial numerical_postprocess_flow_equation; group_polynomial(numerical_postprocess_operation, &numerical_postprocess_flow_equation, idtable, fields); free_Polynomial(numerical_postprocess_operation); // print postprocessing flow equation printf("\n&\n#!postprocess_operation\n"); grouped_polynomial_print(numerical_postprocess_flow_equation,'%','%'); free_Grouped_Polynomial(numerical_postprocess_flow_equation); } if(opts.group_poly==1){ free_Id_Table(idtable); } free_Fields_Table(fields); free_Variables(variables); return(0); } // compute average int compute_average(Polynomial init_poly, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, int print_progress, Polynomial* exp_poly){ polynomial_cpy(init_poly,exp_poly); // average if(threads>1){ polynomial_mean_multithread(exp_poly, fields, propagator, groups, threads, print_progress); } else{ polynomial_mean(exp_poly, fields, propagator, groups, print_progress); } return(0); }