The update to version 1.5 is rather substantial, and introduces some minor backward-incompatibilities: * The header "#!symbols" has been replaced by "#!virtual_fields" * Multiplying polynomials using the '*' symbol is no longer supported (or, rather, the symbolic capabilities of meankondo were enhanced, and the syntax has been changed). * 'meantools exp' has been removed (its functionality is now handled by other means) * 'meantoolds derive' has been replaced by 'meantools differentiate' * The symbolic capabilities were enhanced: polynomials can now be multiplied, added, exponentiated, and their logarithms can be taken directly in the configuration file. * The flow equation can now be processed after being computed using the various "#!postprocess_*" entries. * Deprecated kondo_preprocess. * Compute the mean using an LU decomposition if possible. * More detailed checks for syntax errors in configuration file. * Check that different '#!group' entries are indeed uncorrelated. * New flags in meankondo: '-p' and '-A'. * New tool: meantools expand. * Improve conversion to LaTeX using meantools-convert * Assign terms randomly to different threads. * Multiple bug fixes
276 lines
6.6 KiB
C
276 lines
6.6 KiB
C
/*
|
|
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.
|
|
*/
|
|
|
|
/*
|
|
numkondo
|
|
|
|
Compute the flow of a flow equation numerically
|
|
|
|
*/
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
// pre-compiler definitions
|
|
#include "definitions.cpp"
|
|
|
|
// rccs
|
|
#include "rcc.h"
|
|
#include "rcc_mpfr.h"
|
|
// grouped representation of polynomials
|
|
#include "grouped_polynomial.h"
|
|
// command line parser
|
|
#include "cli_parser.h"
|
|
// parse input file
|
|
#include "parse_file.h"
|
|
// numerical flow
|
|
#include "flow.h"
|
|
#include "flow_mpfr.h"
|
|
// arrays
|
|
#include "array.h"
|
|
|
|
// read cli arguments
|
|
int read_args_numkondo(int argc,const char* argv[], Str_Array* str_args, Numkondo_Options* opts);
|
|
// print usage message
|
|
int print_usage_numkondo();
|
|
// compute flow
|
|
int numflow(Str_Array str_args, Numkondo_Options opts);
|
|
|
|
|
|
int main (int argc, const char* argv[]){
|
|
// string arguments
|
|
Str_Array str_args;
|
|
// options
|
|
Numkondo_Options opts;
|
|
|
|
// read command-line arguments
|
|
read_args_numkondo(argc,argv,&str_args,&opts);
|
|
|
|
numflow(str_args, opts);
|
|
|
|
//free memory
|
|
free_Str_Array(str_args);
|
|
return(0);
|
|
}
|
|
|
|
|
|
// parse command-line arguments
|
|
#define CP_FLAG_NITER 1
|
|
#define CP_FLAG_RCCS 2
|
|
#define CP_FLAG_MPFR_PREC 3
|
|
#define CP_FLAG_MPFR_EXP 4
|
|
int read_args_numkondo(int argc,const char* argv[], Str_Array* str_args, Numkondo_Options* opts){
|
|
int i;
|
|
// temporary long int
|
|
long int tmp_lint;
|
|
// 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
|
|
// display entire flow
|
|
(*opts).display_mode=DISPLAY_NUMERICAL;
|
|
// default niter
|
|
(*opts).niter=100;
|
|
// mark rccstring so that it can be recognized whether it has been set or not
|
|
(*opts).eval_rccstring.length=-1;
|
|
// no mpfr
|
|
(*opts).mpfr_prec=0;
|
|
(*opts).mpfr_emax=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){
|
|
// final step: display the final step of the integration with maximal precision
|
|
case 'F':
|
|
(*opts).display_mode=DISPLAY_FINAL;
|
|
break;
|
|
// niter
|
|
case 'N':
|
|
flag=CP_FLAG_NITER;
|
|
break;
|
|
// initial condition
|
|
case 'I':
|
|
flag=CP_FLAG_RCCS;
|
|
break;
|
|
// mpfr precision
|
|
case 'P':
|
|
flag=CP_FLAG_MPFR_PREC;
|
|
break;
|
|
// mpfr emax
|
|
case 'E':
|
|
flag=CP_FLAG_MPFR_EXP;
|
|
break;
|
|
// print version
|
|
case 'v':
|
|
printf("numkondo " VERSION "\n");
|
|
exit(1);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
// if the niter flag is up
|
|
else if (flag==CP_FLAG_NITER){
|
|
// read niter
|
|
sscanf(argv[i],"%d",&((*opts).niter));
|
|
// reset flag
|
|
flag=0;
|
|
}
|
|
// init condition
|
|
else if(flag==CP_FLAG_RCCS){
|
|
str_to_char_array((char*)argv[i], &((*opts).eval_rccstring));
|
|
flag=0;
|
|
}
|
|
// mpfr precision
|
|
else if(flag==CP_FLAG_MPFR_PREC){
|
|
sscanf(argv[i],"%ld",&tmp_lint);
|
|
(*opts).mpfr_prec=(mpfr_prec_t)tmp_lint;
|
|
flag=0;
|
|
}
|
|
// mpfr emax
|
|
else if(flag==CP_FLAG_MPFR_EXP){
|
|
sscanf(argv[i],"%ld",&tmp_lint);
|
|
(*opts).mpfr_emax=(mpfr_exp_t)tmp_lint;
|
|
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_numkondo(){
|
|
printf("\nusage:\n numkondo [-F] [-N niter] [-I initial_condition] [-P precision] [-E exponent_range] <filename>\n\n");
|
|
return(0);
|
|
}
|
|
|
|
|
|
// numerical computation of the flow
|
|
int numflow(Str_Array str_args, Numkondo_Options opts){
|
|
// index of the entry in the input file
|
|
int arg_index;
|
|
// list of rccs
|
|
Labels labels;
|
|
// initial condition
|
|
RCC init_cd;
|
|
RCC_mpfr init_cd_mpfr;
|
|
// flow equation
|
|
Grouped_Polynomial flow_equation;
|
|
// whether or not to use mpfr floats
|
|
int mpfr_flag=0;
|
|
// postprocess flow equation
|
|
Grouped_Polynomial postprocess_flow_equation;
|
|
|
|
// set mpfr defaults
|
|
if(opts.mpfr_prec!=0){
|
|
mpfr_set_default_prec(opts.mpfr_prec);
|
|
mpfr_flag=1;
|
|
}
|
|
if(opts.mpfr_emax!=0){
|
|
mpfr_set_emax(opts.mpfr_emax);
|
|
mpfr_flag=1;
|
|
}
|
|
|
|
|
|
// parse labels
|
|
arg_index=find_str_arg("labels", str_args);
|
|
if(arg_index<0){
|
|
fprintf(stderr,"error: no labels entry in the configuration file\n");
|
|
exit(-1);
|
|
}
|
|
else{
|
|
parse_labels(str_args.strs[arg_index], &labels);
|
|
}
|
|
|
|
// parse flow equation
|
|
arg_index=find_str_arg("flow_equation", str_args);
|
|
if(arg_index<0){
|
|
fprintf(stderr,"error: no flow equation entry in the configuration file\n");
|
|
exit(-1);
|
|
}
|
|
else{
|
|
char_array_to_Grouped_Polynomial(str_args.strs[arg_index], &flow_equation);
|
|
}
|
|
|
|
// parse postprocess operation
|
|
arg_index=find_str_arg("postprocess_operation", str_args);
|
|
if(arg_index>=0){
|
|
char_array_to_Grouped_Polynomial(str_args.strs[arg_index], &postprocess_flow_equation);
|
|
}
|
|
else{
|
|
init_Grouped_Polynomial(&postprocess_flow_equation,1);
|
|
}
|
|
|
|
|
|
// initial conditions
|
|
// check they were not specified on the command line
|
|
if(opts.eval_rccstring.length==-1){
|
|
arg_index=find_str_arg("initial_condition", str_args);
|
|
if(arg_index<0){
|
|
fprintf(stderr,"error: no initial condition in the configuration file or on the command line\n");
|
|
exit(-1);
|
|
}
|
|
else{
|
|
char_array_cpy(str_args.strs[arg_index],&(opts.eval_rccstring));
|
|
}
|
|
}
|
|
// initialize the rccs
|
|
if(mpfr_flag==0){
|
|
prepare_init(flow_equation.indices,flow_equation.length,&init_cd);
|
|
}
|
|
else{
|
|
prepare_init_mpfr(flow_equation.indices,flow_equation.length,&init_cd_mpfr);
|
|
}
|
|
|
|
// read rccs from string
|
|
if(opts.eval_rccstring.length!=-1){
|
|
parse_init_cd(opts.eval_rccstring, &init_cd, &init_cd_mpfr, mpfr_flag);
|
|
free_Char_Array(opts.eval_rccstring);
|
|
}
|
|
|
|
if(mpfr_flag==0){
|
|
numerical_flow(flow_equation, init_cd, postprocess_flow_equation, labels, opts.niter, opts.display_mode);
|
|
free_RCC(init_cd);
|
|
}
|
|
else{
|
|
numerical_flow_mpfr(flow_equation, init_cd_mpfr, postprocess_flow_equation, labels, opts.niter, opts.display_mode);
|
|
free_RCC_mpfr(init_cd_mpfr);
|
|
}
|
|
|
|
|
|
// free memory
|
|
free_Labels(labels);
|
|
free_Grouped_Polynomial(postprocess_flow_equation);
|
|
free_Grouped_Polynomial(flow_equation);
|
|
return(0);
|
|
}
|