Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/meankondo.c')
-rw-r--r--src/meankondo.c301
1 files changed, 301 insertions, 0 deletions
diff --git a/src/meankondo.c b/src/meankondo.c
new file mode 100644
index 0000000..1c976d4
--- /dev/null
+++ b/src/meankondo.c
@@ -0,0 +1,301 @@
+/*
+Copyright 2015 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 simple tool to compute the renormalization group flow for Fermionic hierarchical models
+
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// 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"
+
+// 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();
+// compute flow
+int compute_flow(Str_Array str_args, Meankondo_Options opts);
+// compute the flow equation
+int compute_flow_equation(Polynomial init_poly, Id_Table idtable, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, Grouped_Polynomial* flow_equation);
+
+
+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);
+
+ // 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;
+
+ // loop over arguments
+ for(i=1;i<argc;i++){
+ // flag
+ if(argv[i][0]=='-'){
+ for(ptr=((char*)argv[i])+1;*ptr!='\0';ptr++){
+ switch(*ptr){
+ // threads
+ case 't':
+ flag=CP_FLAG_THREADS;
+ break;
+ // chain
+ case 'C':
+ (*opts).chain=1;
+ break;
+ // print version
+ case 'v':
+ printf("meankondo " VERSION "\n");
+ exit(1);
+ break;
+ default:
+ print_usage_meankondo();
+ exit(-1);
+ break;
+ }
+ }
+ }
+ // threads
+ else if(flag==CP_FLAG_THREADS){
+ sscanf(argv[i],"%d",&((*opts).threads));
+ flag=0;
+ }
+ // read file name from command-line
+ else{
+ file=argv[i];
+ exists_file=1;
+ }
+ }
+
+ read_config_file(str_args, file, 1-exists_file);
+
+ return(0);
+}
+
+// print usage message
+int print_usage_meankondo(){
+ printf("\nusage:\n meankondo [-t threads] [-C] <filename>\n\n");
+ 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;
+ // initial polynomial
+ Polynomial init_poly;
+ // list of rccs
+ Id_Table idtable;
+ // groups of independent fields
+ Groups groups;
+ // flow equation
+ Grouped_Polynomial flow_equation;
+
+
+ // 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 id table
+ 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);
+ }
+
+ // parse symbols
+ arg_index=find_str_arg("symbols", str_args);
+ if(arg_index>=0){
+ parse_input_symbols(str_args.strs[arg_index],&fields);
+ }
+ else{
+ init_Symbols(&(fields.symbols),1);
+ }
+
+ // 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);
+ }
+ 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);
+ }
+ else{
+ init_Identities(&(fields.ids),1);
+ }
+
+ // parse groups
+ arg_index=find_str_arg("groups", str_args);
+ if(arg_index>=0){
+ parse_input_groups(str_args.strs[arg_index],&groups);
+ }
+ else{
+ init_Groups(&groups, 1);
+ }
+
+ // flow equation
+ compute_flow_equation(init_poly, idtable, fields, propagator, groups, opts.threads, &flow_equation);
+ free_Polynomial(init_poly);
+ free_Polynomial_Matrix(propagator);
+ free_Fields_Table(fields);
+ free_Groups(groups);
+
+ // if chain then print config file
+ if(opts.chain==1){
+ for(i=0;i<str_args.length;i++){
+ // check whether to print the str_arg
+ get_str_arg_title(str_args.strs[i], &arg_header);
+ if (\
+ str_cmp(arg_header.str, "symbols")==0 &&\
+ str_cmp(arg_header.str, "groups")==0 &&\
+ str_cmp(arg_header.str, "fields")==0 &&\
+ str_cmp(arg_header.str, "identities")==0 &&\
+ str_cmp(arg_header.str, "propagator")==0 &&\
+ str_cmp(arg_header.str, "input_polynomial")==0 &&\
+ str_cmp(arg_header.str, "id_table")==0 ){
+ printf("%s\n&\n",str_args.strs[i].str);
+ }
+ free_Char_Array(arg_header);
+ }
+ // print flow equation
+ printf("#!flow_equation\n");
+ }
+
+ // print flow equation
+ grouped_polynomial_print(flow_equation,'%','%');
+
+ // free memory
+ free_Id_Table(idtable);
+ free_Grouped_Polynomial(flow_equation);
+ return(0);
+}
+
+
+// compute the flow equation
+int compute_flow_equation(Polynomial init_poly, Id_Table idtable, Fields_Table fields, Polynomial_Matrix propagator, Groups groups, int threads, Grouped_Polynomial* flow_equation){
+ // expectation
+ Polynomial exp_poly;
+
+ polynomial_cpy(init_poly,&exp_poly);
+
+ // average
+ if(threads>1){
+ polynomial_mean_multithread(&exp_poly, fields, propagator, groups, threads);
+ }
+ else{
+ polynomial_mean(&exp_poly, fields, propagator, groups);
+ }
+
+ // grouped representation of expanded_poly
+ group_polynomial(exp_poly,flow_equation,idtable, fields);
+ free_Polynomial(exp_poly);
+
+ return(0);
+}