commit a97a6f3ef90bc23dda77ad60991fe53ecd24b2e9
parent 96d13de1d7752eae671890fb650604dcfd827a14
Author: Bakar Chargeishvili <bakar@bcharge.de>
Date:   Wed, 27 Apr 2022 17:59:01 +0200
Major refactoring
Diffstat:
| M | webs.c |  |  | 206 | +++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- | 
1 file changed, 123 insertions(+), 83 deletions(-)
diff --git a/webs.c b/webs.c
@@ -5,17 +5,19 @@
 #include "util.h"
 
 typedef struct {
+	unsigned int legId;
+	unsigned int id;
+} Vertex;
+
+typedef struct {
 	char *name;
 	int init;
 	unsigned int id;
 	int isMassive;
 	int isGluon;
+	Vertex *Vertices;
 } Leg;
 
-typedef struct {
-	unsigned int legId;
-	unsigned int id;
-} Vertex;
 
 typedef struct {
 	Vertex emitter;
@@ -23,20 +25,24 @@ typedef struct {
 } Link;
 
 void
-generate_legs(char **init, size_t n_init, char **fin, size_t n_fin, Leg *Legs)
+generate_legs(char **init, size_t n_init, char **fin, size_t n_fin, size_t nLoops, 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};
+		Vertex *Vertices = (Vertex*)ecalloc(nLoops+1, sizeof(Vertex));
+		Vertices[0] = (Vertex){i,0};
+		Legs[i] = (Leg){init[i], 1, i, 0, isGluon, Vertices};
 	}
 
 	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};
+		Vertex *Vertices = (Vertex *)ecalloc(nLoops+1, sizeof(Vertex));
+		Vertices[0] = (Vertex){n_init+i,0};
+		Legs[n_init+i] = (Leg){init[i], 1, n_init+i, 0, isGluon,Vertices};
 	}
 }
 
@@ -46,7 +52,8 @@ 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};
+			Vertices[j+nLoops*i] = (Vertex){i+1, 1+j};
+			Legs[i].Vertices[j+1] = Vertices[j+nLoops*i];
 		}
 	}
 
@@ -60,77 +67,89 @@ generate_vertices(Leg *Legs, size_t nLegs, int nLoops, Vertex *Vertices)
 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);
+	for (int iVx = 0; iVx < nVx; ++iVx) {
+		Link *Graph = (Link *)ecalloc(nLoops, sizeof(Link));
+		int iEdge = -1;
+		for (int jVx = 0; jVx < nVx; ++jVx) {
+			if (iVx == jVx) {
+				continue;
+			}
+			/* Add a connection */
+			Graph[++iEdge] = (Link){Vertices[iVx], Vertices[jVx]};
+			printf("V%d%d\n", iVx, jVx);
 		}
-		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));
+	/* 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));
 
 }
 
@@ -146,22 +165,43 @@ main(int argc, char *argv[])
 	char *initial[] = {"g","g"};
 	char *final[]   = {"q","qbar", "g"};
 
-	int nLoops = 2;
+	int nLoops = 1;
 
 	size_t nLegs = NELEMS(initial) + NELEMS(final);
 	Leg Legs[nLegs];
-	generate_legs(initial,NELEMS(initial), final, NELEMS(final), Legs);
+	generate_legs(initial,NELEMS(initial), final, NELEMS(final), nLoops, Legs);
 
-	Vertex *Vertices = (Vertex *)ecalloc(nLoops*nLegs, sizeof(Vertex));
+	size_t nVx = nLegs*nLoops;
+	Vertex *Vertices = (Vertex *)ecalloc(nVx, sizeof(Vertex));
 	generate_vertices(Legs, nLegs, nLoops, Vertices);
 
-	printf("%d\n",Vertices[0].legId);
-	printf("%d\n",Vertices[1].legId);
+	for (int i = 0; i < nVx; ++i) {
+		printf("V%d%d\n",Vertices[i].legId,Vertices[i].id);
+	}
 
-	size_t nVx = nLegs*nLoops;
 	int *deletedVertices = (int *)ecalloc(nVx, sizeof(int));
 	Link *Graphs = (Link *)ecalloc(300*nLoops, sizeof(Link));
 
+	Link *Skeleton = (Link *)ecalloc(300*nLoops, sizeof(Link));
+	int iEdge = -1;
+	for (int iLeg = 0; iLeg < nLegs; ++iLeg) {
+		Vertex* LegVertices = Legs[iLeg].Vertices;
+		Skeleton[++iEdge] = (Link){LegVertices[0],LegVertices[1]};
+		for (int iVx = 1; iVx < nLoops; ++iVx) {
+			Skeleton[++iEdge] = (Link){LegVertices[iVx],LegVertices[iVx+1]};
+		}
+		/*printf("Last vx: V%d%d\n", LegVertices[nLoops].legId, LegVertices[nLoops].id);*/
+		Skeleton[++iEdge] = (Link){LegVertices[nLoops], (Vertex){999, 999}};
+	}
+
+	for (int i = 0; i < iEdge; ++i) {
+		printf("Emit V%d%d Absorb V%d%d\n",
+				Skeleton[i].emitter.legId,Skeleton[i].emitter.id, Skeleton[i].absorber.legId,Skeleton[i].absorber.id);
+	}
+
+	printf("Edge count: %d\n", iEdge);
+	return 0;
+
 	generate_loops(Vertices, deletedVertices, Graphs, nVx, nLoops, 0);
 
 	for (int iVx=0; iVx<300; ++iVx) {