WilsonWebs - An automated tool for n-Loop Wilson web generation

git clone git://git.bcharge.de/WilsonWebs.git

About | Log | Files | Refs | License

commit 0a16ed9629969d838b22a0eb9e89630cf7140f81
parent b1fc91dd6271e484ccf8caf41d3abb9cc92e98e8
Author: Bakar Chargeishvili <bakar@bcharge.de>
Date:   Wed, 16 Feb 2022 16:59:13 +0100

Initial import

Diffstat:
A.gitignore | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
ALICENSE | 29+++++++++++++++++++++++++++++
AMakefile | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Aconfig.def.h | 1+
Aconfig.mk | 25+++++++++++++++++++++++++
Autil.c | 30++++++++++++++++++++++++++++++
Autil.h | 14++++++++++++++
Awebs.c | 178+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 383 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,55 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# Main binary of this project +WilsonWebs diff --git a/LICENSE b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2021, Bakar Chargeishvili +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile @@ -0,0 +1,51 @@ +# WilsonWebs - Generate n-Loop Wilson webs +# See LICENSE file for copyright and license details. + +include config.mk + +SRC = webs.c util.c +OBJ = ${SRC:.c=.o} + +all: options webs + +options: + @echo WilsonWebs build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "CC = ${CC}" + +.c.o: + ${CC} -c ${CFLAGS} $< + +${OBJ}: config.mk + +config.h: + cp config.def.h $@ + +webs: ${OBJ} + ${CC} -o WilsonWebs ${OBJ} ${LDFLAGS} + +clean: + rm -f WilsonWebs ${OBJ} + +dist: clean + mkdir -p WilsonWebs-${VERSION} + cp -R LICENSE Makefile README config.def.h config.mk\ + WilsonWebs.1 WilsonWebs.h util.h ${SRC} WilsonWebs-${VERSION} + tar -cf WilsonWebs-${VERSION}.tar WilsonWebs-${VERSION} + gzip WilsonWebs-${VERSION}.tar + rm -rf WilsonWebs-${VERSION} + +install: all + mkdir -p ${DESTDIR}${PREFIX}/bin + cp -f WilsonWebs ${DESTDIR}${PREFIX}/bin + chmod 755 ${DESTDIR}${PREFIX}/bin/WilsonWebs + mkdir -p ${DESTDIR}${MANPREFIX}/man1 + sed "s/VERSION/${VERSION}/g" < WilsonWebs.1 > ${DESTDIR}${MANPREFIX}/man1/WilsonWebs.1 + chmod 644 ${DESTDIR}${MANPREFIX}/man1/WilsonWebs.1 + +uninstall: + rm -f ${DESTDIR}${PREFIX}/bin/WilsonWebs\ + ${DESTDIR}${MANPREFIX}/man1/WilsonWebs.1 + +.PHONY: all options clean dist install uninstall diff --git a/config.def.h b/config.def.h @@ -0,0 +1 @@ +/* See LICENSE file for copyright and license details. */ diff --git a/config.mk b/config.mk @@ -0,0 +1,25 @@ +# WilsonWebs version +VERSION = 0.1 + +# Customize below to fit your system + +# paths +PREFIX = /usr/local +MANPREFIX = ${PREFIX}/share/man + +# includes and libs +INCS = +LIBS = + +# flags +CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=2 -DVERSION=\"${VERSION}\" +#CFLAGS = -g -std=c99 -pedantic -Wall -O0 ${INCS} ${CPPFLAGS} +CFLAGS = -std=c99 -pedantic -Wall -Wno-deprecated-declarations -Os ${INCS} ${CPPFLAGS} +LDFLAGS = ${LIBS} + +# Solaris +#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" +#LDFLAGS = ${LIBS} + +# compiler and linker +CC = cc diff --git a/util.c b/util.c @@ -0,0 +1,30 @@ +/* See LICENSE file for copyright and license details. */ +#include "util.h" + +void* ecalloc(size_t nmemb, size_t size) +{ + void *p; + + if (!(p = calloc(nmemb, size))) + die("calloc:"); + return p; +} + +void die(const char *fmt, ...) { + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } else { + fputc('\n', stderr); + } + + exit(1); +} + + diff --git a/util.h b/util.h @@ -0,0 +1,14 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdlib.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define MAX(A, B) ((A) > (B) ? (A) : (B)) +#define MIN(A, B) ((A) < (B) ? (A) : (B)) +#define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) +#define NELEMS(A) (sizeof(A) / sizeof((A)[0])) + +void die(const char *fmt, ...); +void *ecalloc(size_t nmemb, size_t size); diff --git a/webs.c b/webs.c @@ -0,0 +1,178 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdio.h> +#include <string.h> + +#include "util.h" + +typedef struct { + char *name; + int init; + unsigned int id; + int isMassive; + int isGluon; +} Leg; + +typedef struct { + unsigned int legId; + unsigned int id; +} Vertex; + +typedef struct { + Vertex emitter; + Vertex absorber; +} Link; + +void +generate_legs(char **init, size_t n_init, char **fin, size_t n_fin, Leg *Legs) +{ + for (int i=0; i<n_init; ++i) { + int isGluon = 0; + if (!strcmp("g", init[i])) + isGluon = 1; + Legs[i] = (Leg){init[i], 1, i, 0, isGluon}; + } + + for (int i=0; i<n_fin; ++i) { + int isGluon = 0; + if (!strcmp("g", fin[i])) + isGluon = 1; + Legs[n_init+i] = (Leg){init[i], 1, n_init+i, 0, isGluon}; + } +} + +void +generate_vertices(Leg *Legs, size_t nLegs, int nLoops, Vertex *Vertices) +{ + for (int i=0; i<nLegs; ++i) { + for (int j=0; j<nLoops; ++j) { + /* TODO: Don't forget to add vertices for self-energies later */ + Vertices[j+nLoops*i] = (Vertex){i, j+nLoops*i}; + } + } + + /* + for (int i = 0; i < nLegs*nLoops; ++i) { + printf("test %d\n", Vertices[i].legId); + } + */ +} + +void +generate_loops(Vertex *Vertices, int *deletedVertices, Link *Graphs, size_t nVx, int nLoops, int nGenLoops) +{ + /* Find the first non-deleted vertex */ + int mVx = -1; + for (int iVx=0; iVx<nVx; ++iVx) { + if (!deletedVertices[iVx]) { + mVx = iVx; + break; + } + } + printf("mVx %d\n", mVx); + + Vertex *AllPossConns = (Vertex *)ecalloc(nVx, sizeof(Vertex)); + size_t nConns = 0; + for (int iVx=mVx; iVx<nVx; ++iVx) { + if (!deletedVertices[iVx] && Vertices[iVx].legId != Vertices[mVx].legId) { + AllPossConns[nConns++] = Vertices[iVx]; + } + } + + if (nConns == 0 || mVx == -1) { + free(deletedVertices); + printf("End rec"); + return; + } + + /* We build the connections here */ + static int iGraph = 0; + for (int iVx = 0; iVx < nConns; ++iVx) { + if (!nGenLoops) + printf("yess"); + Graphs[iGraph*nLoops+nGenLoops] = (Link){Vertices[mVx], AllPossConns[iVx]}; + printf("V%d%d - V%d%d\n", Vertices[mVx].legId, Vertices[mVx].id, AllPossConns[iVx].legId, AllPossConns[iVx].id); + /* Gluon connection introduces new vertices. + * Gluon legId = (emitter legId + 100) + */ + + /* + for (int i = 0; i < nLoops-nGenLoops; ++i) { + AllPossConns[i] = (Vertex){Vertices[mVx].legId+100,i} + } + */ + + deletedVertices[mVx] = 1; + deletedVertices[AllPossConns[iVx].id] = 1; + nGenLoops++; + if(nGenLoops < nLoops) { + int *deletedCopy = (int *)ecalloc(nVx, sizeof(int)); + deletedCopy[mVx] = 1; + deletedCopy[AllPossConns[iVx].id] = 1; + generate_loops(Vertices, deletedCopy, Graphs, nVx, nLoops, nGenLoops); + } + else if (nGenLoops == nLoops) { + iGraph++; + } + nGenLoops--; + } + free(AllPossConns); + + /* + for (int iVx=mVx+1; iVx<nVx; ++iVx) + deletedVertices[iVx] = 0; + */ + /* + printf("%d\n", nConns); + printf("%d\n", deletedVertices[mVx-1]); + printf("%d\n", deletedVertices[mVx]); + printf("%d\n", deletedVertices[mVx+1]); + */ + + generate_loops(Vertices, deletedVertices, Graphs, nVx, nLoops, nGenLoops); + + //memmove(&AllPossVertices[0], &Vertices[1], (n_vx - 1) * sizeof(Vertex)); + +} + + +int +main(int argc, char *argv[]) +{ + if (argc == 2 && !strcmp("-v", argv[1])) + die("WilsonWebs-"VERSION); + else if (argc != 1) + die("usage: webs [-v]"); + + char *initial[] = {"g","g"}; + char *final[] = {"q","qbar", "g"}; + + int nLoops = 2; + + size_t nLegs = NELEMS(initial) + NELEMS(final); + Leg Legs[nLegs]; + generate_legs(initial,NELEMS(initial), final, NELEMS(final), Legs); + + Vertex *Vertices = (Vertex *)ecalloc(nLoops*nLegs, sizeof(Vertex)); + generate_vertices(Legs, nLegs, nLoops, Vertices); + + printf("%d\n",Vertices[0].legId); + printf("%d\n",Vertices[1].legId); + + size_t nVx = nLegs*nLoops; + int *deletedVertices = (int *)ecalloc(nVx, sizeof(int)); + Link *Graphs = (Link *)ecalloc(300*nLoops, sizeof(Link)); + + generate_loops(Vertices, deletedVertices, Graphs, nVx, nLoops, 0); + + for (int iVx=0; iVx<300; ++iVx) { + printf("Graph ID: %d\n",iVx); + for (int i=0; i<nLoops; ++i) { + printf("V%d%d-V%d%d\n",Graphs[iVx*nLoops+i].emitter.legId, Graphs[iVx*nLoops+i].emitter.id, Graphs[iVx*nLoops+i].absorber.legId, Graphs[iVx*nLoops+i].absorber.id); + } + } + + //draw(Legs, Connections); + + + return 0; +}