From 0e01ff6455b6fdff8fa8c7707413fe1742dc2fe9 Mon Sep 17 00:00:00 2001 From: chenyongxin Date: Tue, 14 Apr 2015 08:09:19 +0100 Subject: [PATCH 1/9] New arrangement --- LilyPad/CircleArray.pde | 194 ++++++++++++++++++++++++++++++++++++++++ LilyPad/LilyPad.pde | 28 ++++-- 2 files changed, 213 insertions(+), 9 deletions(-) create mode 100644 LilyPad/CircleArray.pde diff --git a/LilyPad/CircleArray.pde b/LilyPad/CircleArray.pde new file mode 100644 index 0000000..b832e84 --- /dev/null +++ b/LilyPad/CircleArray.pde @@ -0,0 +1,194 @@ +/********************************* + +This class creats a circle array of cylinders. +This is special for bundle case. + +The input arguments are center coordinates X, Y; diameter of each cylinder D; Radius of circle array; division n; window. + +**********************************/ + +class CircleArray extends Body{ + ArrayList circleList = new ArrayList(); //This is a container for all bodies + + float X, Y; //X, Y represent a temporal coordinate of a new body + + + CircleArray(float x, float y, float d, float R, int n, float rad, Window window){ + super(x, y, window); + for ( int i = 1; i <= n; i++ ){ + + //Define each body's center coordinate. + X = x+R*cos(TWO_PI/n*i+rad); + Y = y+R*sin(TWO_PI/n*i+rad); + + circleList.add(new CircleBody(X, Y, d, window)); + } + } + + void display(color C, Window window ){ + for ( CircleBody circle : circleList ){ + circle.display(C, window); + } + + } + + float distance(float x, float y){ + float d = 0; + float dmin = 1E5; + for ( CircleBody circle : circleList ){ + d = circle.distance(x, y); + dmin = min(d, dmin); + } + return dmin; + } + + + + + int distance( int px, int py){ // in pixels + int d = 0; + int dmin = (int)1e3; + for ( CircleBody circle : circleList ){ + d = circle.distance(px, py); + dmin = min(d, dmin); + } + return dmin; + } + + Body closest (float x, float y){ + float dmin = 1e5; + Body body = circleList.get(0); + //CircleBody b; + for (CircleBody circle: circleList){ + if(circle.distance(x, y) < dmin){ + dmin = circle.distance(x, y); + body = circle; + } + } + return body; + } + + + PVector WallNormal(float x, float y){ + Body c = closest(x,y); + return c.WallNormal(x,y); + } + + float velocity( int d, float dt, float x, float y ){ + Body c = closest(x,y); + return c.velocity(d,dt,x,y); + } + + + +} + +class CircleArrangement extends Body { + ArrayList circleArr = new ArrayList(); + + // constructor, ro is density, n is division for the very out layer + // delete density ro, and use number of cylinders to control. + + CircleArrangement(float x, float y, float d, float R, int n, //float ro, + float rad, Window window) { + super(x, y, window); + + // define different layer + // when define each layer depending on density ro, the inner circle + // should be considered in case of conflict + + //float r; // r is interval of radial direction +// r = ro * R; + int N; // N is number of circles in radial direction without central + // circle +// N = (int)(1/ro); +// define N + if (n<6){ + N = 1; + } else if (n<20){ + N = 2; + } else if (n<40){ + N = 3; + } else if (n<65){ + N = 4; + } else if (n<96) { + N = 5; + } else{ + N = 6; + } + + + // new a arraylist to restore the number of maximum cylinders on each ring. + int[] ring = new int[7]; + ring[1] = 6; + ring[2] = 13; + ring[3] = 20; + ring[4] = 25; + ring[5] = 31; + + if (N==1){ + circleArr.add(new CircleArray(x, y, d, R, n-1, rad, window)); + circleArr.add(new CircleArray(x, y, d, 0, 1, rad, window)); + } else{ + int temp; + temp = n-1; + for (int i=1; i Date: Sat, 25 Apr 2015 23:28:20 +0100 Subject: [PATCH 2/9] new window understanding --- LilyPad/LilyPad.pde | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LilyPad/LilyPad.pde b/LilyPad/LilyPad.pde index c332ac6..2992ae2 100644 --- a/LilyPad/LilyPad.pde +++ b/LilyPad/LilyPad.pde @@ -12,9 +12,9 @@ CircleArrangement body; FloodPlot flood; void setup(){ - int n=(int)pow(2,8)+2; // number of grid points - size(1400,1000); // display window size - Window view = new Window(0, 0, n, n); + int n=(int)pow(2,9)+2; // number of grid points + size(1350,900); // display window size + Window view = new Window(3*n/2, n); float D; //Bundle radius float d = 2; //Define each cylinder's diameter From 3ab7e5b074a932fa639d756c7555f7f2c106df46 Mon Sep 17 00:00:00 2001 From: Yongxin Chen Date: Fri, 5 Jun 2015 00:04:31 +0100 Subject: [PATCH 3/9] Circular array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Add CircleArray.pde to set up circular arrangement of cylinders which are similar to Eames’ paper. 2. Create SaveData2.pde which is simplified from SaveData to save Drag/Lift coefficients. --- LilyPad/CircleArray.pde | 139 +++++++++++++++++++++++++--------------- LilyPad/SaveData2.pde | 112 ++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+), 52 deletions(-) create mode 100644 LilyPad/SaveData2.pde diff --git a/LilyPad/CircleArray.pde b/LilyPad/CircleArray.pde index b832e84..2cf83d8 100644 --- a/LilyPad/CircleArray.pde +++ b/LilyPad/CircleArray.pde @@ -1,26 +1,67 @@ /********************************* - -This class creats a circle array of cylinders. +CircleArray class creats a single circle array of cylinders. This is special for bundle case. +The input arguments are center coordinates X, Y; diameter of each cylinder D; +Radius of circle array; division n; Angle of Attack rad; window. + +CircleArrangement class uses CircleArray to setup circular arrangement for many times. +Setup order (logic): single cylinder-->circle array (single ring of cylinders)--> circular arrangement (many rings of cylinders) + +Example code: + + +SaveData2 dat; +CircleArrangement body; +BDIM flow; +FloodPlot flood; + +float DomainRatio = 2; // Domain/DG +int gridScale = 8; // coefficient for number of grid points +int Nc = 39; // circles in bundle +int n = gridScale*(int)pow(2,6)+2; // y-axis number of points +int m = 2*(n-2)+2; // x-axis number of points +float DG = float(n-2)/DomainRatio; // Bundle diameter +float d = DG/21.; // Cylinder's diameter +float R = DG/2; //Bundle radius +float aoa = PI/2; //Angle of Attack +float ReG = 2100; //physical Reynolds number +float Reh = ReG/DG; //grid-based Reynolds number +float dt = 0; +boolean QUICK = true; -The input arguments are center coordinates X, Y; diameter of each cylinder D; Radius of circle array; division n; window. +void setup(){ + size(1200,600); // display window size + Window view = new Window(m,n); + + float x = (float)n/2., y = (float)n/2.; //central position + body = new CircleArrangement(x, y, d, R, Nc, aoa, view); + dat = new SaveData2("saved/N39d12DragAoA90.txt",body); // initialize the output data file with header information + flow = new BDIM(m,n,dt,body,(float)1./Reh,QUICK); + flood = new FloodPlot(view); + flood.range = new Scale(-.75,.75); + flood.setLegend("vorticity"); +} + +void draw(){ + body.update(); + flow.update(body); + flow.update2(); + flood.display(flow.u.vorticity()); + body.display(); + dat.addData(flow.p,"Drag", DG); // "Drag" or "Lift" +} **********************************/ class CircleArray extends Body{ ArrayList circleList = new ArrayList(); //This is a container for all bodies - float X, Y; //X, Y represent a temporal coordinate of a new body - - CircleArray(float x, float y, float d, float R, int n, float rad, Window window){ super(x, y, window); for ( int i = 1; i <= n; i++ ){ - //Define each body's center coordinate. X = x+R*cos(TWO_PI/n*i+rad); Y = y+R*sin(TWO_PI/n*i+rad); - circleList.add(new CircleBody(X, Y, d, window)); } } @@ -28,8 +69,7 @@ class CircleArray extends Body{ void display(color C, Window window ){ for ( CircleBody circle : circleList ){ circle.display(C, window); - } - + } } float distance(float x, float y){ @@ -40,10 +80,7 @@ class CircleArray extends Body{ dmin = min(d, dmin); } return dmin; - } - - - + } int distance( int px, int py){ // in pixels int d = 0; @@ -53,8 +90,8 @@ class CircleArray extends Body{ dmin = min(d, dmin); } return dmin; - } - + } + Body closest (float x, float y){ float dmin = 1e5; Body body = circleList.get(0); @@ -66,8 +103,7 @@ class CircleArray extends Body{ } } return body; - } - + } PVector WallNormal(float x, float y){ Body c = closest(x,y); @@ -78,69 +114,64 @@ class CircleArray extends Body{ Body c = closest(x,y); return c.velocity(d,dt,x,y); } - - - } -class CircleArrangement extends Body { - ArrayList circleArr = new ArrayList(); - // constructor, ro is density, n is division for the very out layer - // delete density ro, and use number of cylinders to control. - + +/*================================================ + CircleArrangement class +================================================*/ + +class CircleArrangement extends Body { + ArrayList circleArr = new ArrayList(); CircleArrangement(float x, float y, float d, float R, int n, //float ro, float rad, Window window) { super(x, y, window); - - // define different layer - // when define each layer depending on density ro, the inner circle - // should be considered in case of conflict - - //float r; // r is interval of radial direction -// r = ro * R; - int N; // N is number of circles in radial direction without central - // circle -// N = (int)(1/ro); -// define N - if (n<6){ + + int N; // N is number of rings + if (n<=7){ N = 1; - } else if (n<20){ + } else if (n<=20){ N = 2; - } else if (n<40){ + } else if (n<=40){ N = 3; - } else if (n<65){ + } else if (n<=65){ N = 4; - } else if (n<96) { + } else if (n<=96) { N = 5; } else{ N = 6; } - - // new a arraylist to restore the number of maximum cylinders on each ring. +// New a arraylist to restore the number of maximum cylinders on each ring. +// This set of numbers is implemented from Eames' paper. int[] ring = new int[7]; ring[1] = 6; ring[2] = 13; ring[3] = 20; ring[4] = 25; ring[5] = 31; - + +// The logic for the arrangement is expect from centric cylinder and most outer ring, +// the middle parts are arranged separately with specific AoA. if (N==1){ - circleArr.add(new CircleArray(x, y, d, R, n-1, rad, window)); - circleArr.add(new CircleArray(x, y, d, 0, 1, rad, window)); + if(n==1){ + circleArr.add(new CircleArray(x, y, d, 0, 1, rad, window)); + } + else{ + circleArr.add(new CircleArray(x, y, d, R, n-1, rad, window)); + circleArr.add(new CircleArray(x, y, d, 0, 1, rad, window)); + } } else{ int temp; temp = n-1; for (int i=1; i coords = new ArrayList(); + PrintWriter output; + int n; + ArrayList bodys = new ArrayList(); + SaveData2(String name, CircleArrangement body){ + output = createWriter(name); + n = 0; + for(CircleArray subcircleArr : body.circleArr){ + for(CircleBody x: subcircleArr.circleList){ + for(PVector xx: x.coords){ + coords.add(xx); + } + bodys.add(x); + n++; + } + } + this.bodys = bodys; + this.n = n; +} + + void saveParam(String name, float value){ + output.println("% " + name + " = " + value + ";"); + } + void saveString(String s){ + output.println(s); + } + + + void addData(Field a, String str, float L){ + //get pressure for every cylinder. + PVector pressure=new PVector(0, 0); + for(CircleBody cb : bodys){ + pressure.add(cb.pressForce(a)); + } + + if(str.equals("Drag")){ + output.println(2*pressure.x/L + " "); + } + else{ + output.println(2*pressure.y/L + " "); + } + } + + // New addData method that restores drag or lift coefficient of each cylinder. + // The 4th argument is just only for distinguishing this function to store single cylinder's information with other functions. e.g. "Single". + // Output file with the format: + /* + cylinder 1's Drag pressure, cylinder 2's Drag pressure, cylinder 3's Drag pressure,..., cylinder n's Drag pressure (first time step) + cylinder 1's Drag pressure, cylinder 2's Drag pressure, cylinder 3's Drag pressure,..., cylinder n's Drag pressure (second time step) + cylinder 1's Drag pressure, cylinder 2's Drag pressure, cylinder 3's Drag pressure,..., cylinder n's Drag pressure (third time step) + */ + void addData(Field a, String str, float L, String str2){ + if(str.equals("Drag")){ + for(CircleBody cb : bodys){ + output.print(2*cb.pressForce(a).x/L+" "); + } + output.println(); + } + else{ + for(CircleBody cb : bodys){ + output.print(2*cb.pressForce(a).y/L+" "); + } + output.println(); + } + } + + void addData(float t, Field a){ + output.print(t + " "); + for(int i=0; i Date: Sun, 7 Jun 2015 00:23:50 +0100 Subject: [PATCH 4/9] New pull-request 1. Revert LilyPad.pde to it's original state. 2. Make the example code more concise. --- LilyPad/CircleArray.pde | 37 ++++++++++++------------------------- LilyPad/LilyPad.pde | 31 +++++++++---------------------- LilyPad/SaveData2.pde | 23 +++++++++++++++++------ 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/LilyPad/CircleArray.pde b/LilyPad/CircleArray.pde index 2cf83d8..788a083 100644 --- a/LilyPad/CircleArray.pde +++ b/LilyPad/CircleArray.pde @@ -1,42 +1,30 @@ /********************************* -CircleArray class creats a single circle array of cylinders. -This is special for bundle case. +CircleArray class creats a single circle ring of cylinders. The input arguments are center coordinates X, Y; diameter of each cylinder D; Radius of circle array; division n; Angle of Attack rad; window. CircleArrangement class uses CircleArray to setup circular arrangement for many times. -Setup order (logic): single cylinder-->circle array (single ring of cylinders)--> circular arrangement (many rings of cylinders) Example code: - SaveData2 dat; CircleArrangement body; BDIM flow; FloodPlot flood; - -float DomainRatio = 2; // Domain/DG -int gridScale = 8; // coefficient for number of grid points -int Nc = 39; // circles in bundle -int n = gridScale*(int)pow(2,6)+2; // y-axis number of points -int m = 2*(n-2)+2; // x-axis number of points -float DG = float(n-2)/DomainRatio; // Bundle diameter -float d = DG/21.; // Cylinder's diameter -float R = DG/2; //Bundle radius -float aoa = PI/2; //Angle of Attack -float ReG = 2100; //physical Reynolds number -float Reh = ReG/DG; //grid-based Reynolds number -float dt = 0; -boolean QUICK = true; +int n=(int)pow(2,6)+2; +float DG = float(n-2)/2; // Bundle diameter +float d = DG/21.; // Cylinder's diameter +float R = DG/2; //Bundle radius +float ReG = 2100; //physical Reynolds number +float Reh = ReG/DG; //grid-based Reynolds number void setup(){ - size(1200,600); // display window size - Window view = new Window(m,n); - + size(600,600); // display window size + Window view = new Window(n,n); float x = (float)n/2., y = (float)n/2.; //central position - body = new CircleArrangement(x, y, d, R, Nc, aoa, view); - dat = new SaveData2("saved/N39d12DragAoA90.txt",body); // initialize the output data file with header information - flow = new BDIM(m,n,dt,body,(float)1./Reh,QUICK); + body = new CircleArrangement(x, y, d, R, 20, PI/2, view); + dat = new SaveData2("saved/N39d12DragAoA90.txt",body); + flow = new BDIM(n,n,0,body,(float)1./Reh,true); flood = new FloodPlot(view); flood.range = new Scale(-.75,.75); flood.setLegend("vorticity"); @@ -50,7 +38,6 @@ void draw(){ body.display(); dat.addData(flow.p,"Drag", DG); // "Drag" or "Lift" } - **********************************/ class CircleArray extends Body{ diff --git a/LilyPad/LilyPad.pde b/LilyPad/LilyPad.pde index 2992ae2..56578f7 100644 --- a/LilyPad/LilyPad.pde +++ b/LilyPad/LilyPad.pde @@ -1,33 +1,23 @@ /********************************************************* Main Window! - Click the "Run" button to Run the simulation. - Change the geometry, flow conditions, numercial parameters visualizations and measurments from this window. - *********************************************************/ BDIM flow; -CircleArrangement body; +CircleBody body; FloodPlot flood; void setup(){ - int n=(int)pow(2,9)+2; // number of grid points - size(1350,900); // display window size - Window view = new Window(3*n/2, n); - - float D; //Bundle radius - float d = 2; //Define each cylinder's diameter - D = d * 21; - float x = n/4, y = n/2; - float aoa = PI/2; //aoa is Angle of Attack - - body = new CircleArrangement(x, y, d, D/2, 95, aoa, view); - -// flow = new BDIM(n,n,1.5,body); // solve for flow using BDIM - flow = new BDIM(n,n,0,body,0.01,true); // QUICK with adaptive dt + int n=(int)pow(2,6)+2; // number of grid points + size(400,400); // display window size + Window view = new Window(n,n); + + body = new CircleBody(n/3,n/2,n/8,view); // define geom + flow = new BDIM(n,n,1.5,body); // solve for flow using BDIM +// flow = new BDIM(n,n,0,body,0.01,true); // QUICK with adaptive dt flood = new FloodPlot(view); - flood.range = new Scale(-1.,1); + flood.range = new Scale(-.75,.75); flood.setLegend("vorticity"); } void draw(){ @@ -40,6 +30,3 @@ void draw(){ void mousePressed(){body.mousePressed();} void mouseReleased(){body.mouseReleased();} - - - diff --git a/LilyPad/SaveData2.pde b/LilyPad/SaveData2.pde index 0d39373..9056fa0 100644 --- a/LilyPad/SaveData2.pde +++ b/LilyPad/SaveData2.pde @@ -4,9 +4,20 @@ Saves data to a text file with customizable header ---- example code fragment: + SaveData2 dat; - dat = new SaveData2("saved/N39d12DragAoA90.txt",body); - dat.addData(flow.p,"Drag", DG); + + void setup(){ + ... + dat = new SaveData2("saved/N39d12DragAoA90.txt",body); + ... + } + + void draw(){ + ... + dat.addData(flow.p,"Drag", DG); + ... + } ----see use in CircleArray.pde ***********************************/ class SaveData2{ @@ -18,11 +29,11 @@ class SaveData2{ output = createWriter(name); n = 0; for(CircleArray subcircleArr : body.circleArr){ - for(CircleBody x: subcircleArr.circleList){ - for(PVector xx: x.coords){ - coords.add(xx); + for(CircleBody circle: subcircleArr.circleList){ + for(PVector xy: circle.coords){ + coords.add(xy); } - bodys.add(x); + bodys.add(circle); n++; } } From b06b59995c6e8a00e79a52b827cddf2038721f33 Mon Sep 17 00:00:00 2001 From: Yongxin Chen Date: Sun, 7 Jun 2015 00:28:27 +0100 Subject: [PATCH 5/9] New pull-request 2 1. Revert LilyPad.pde to it's original state. 2. Make the example code more concise. --- LilyPad/LilyPad.pde | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LilyPad/LilyPad.pde b/LilyPad/LilyPad.pde index 56578f7..c63b305 100644 --- a/LilyPad/LilyPad.pde +++ b/LilyPad/LilyPad.pde @@ -1,7 +1,9 @@ /********************************************************* Main Window! Click the "Run" button to Run the simulation. + Change the geometry, flow conditions, numercial parameters + visualizations and measurments from this window. *********************************************************/ BDIM flow; From e12d314cb5d27b2d153a997f48fefdf125f2c167 Mon Sep 17 00:00:00 2001 From: Yongxin Chen Date: Sun, 7 Jun 2015 00:30:03 +0100 Subject: [PATCH 6/9] New pull-request 3 1. Revert LilyPad.pde to it's original state. 2. Make the example code more concise. --- LilyPad/LilyPad.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LilyPad/LilyPad.pde b/LilyPad/LilyPad.pde index c63b305..6a94868 100644 --- a/LilyPad/LilyPad.pde +++ b/LilyPad/LilyPad.pde @@ -1,9 +1,9 @@ /********************************************************* Main Window! + Click the "Run" button to Run the simulation. Change the geometry, flow conditions, numercial parameters - visualizations and measurments from this window. *********************************************************/ BDIM flow; From ed4c20c717e51fad677b0f923c72a33da388822a Mon Sep 17 00:00:00 2001 From: Yongxin Chen Date: Sun, 7 Jun 2015 00:31:54 +0100 Subject: [PATCH 7/9] New pull-request 4 1. Revert LilyPad.pde to it's original state. 2. Make the example code more concise. --- LilyPad/LilyPad.pde | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LilyPad/LilyPad.pde b/LilyPad/LilyPad.pde index 6a94868..6bec200 100644 --- a/LilyPad/LilyPad.pde +++ b/LilyPad/LilyPad.pde @@ -1,10 +1,11 @@ /********************************************************* Main Window! - + Click the "Run" button to Run the simulation. Change the geometry, flow conditions, numercial parameters visualizations and measurments from this window. + *********************************************************/ BDIM flow; CircleBody body; From c5c58769ca86d93d0d8553b3cf243d5c32840981 Mon Sep 17 00:00:00 2001 From: Yongxin Chen Date: Sun, 7 Jun 2015 00:32:37 +0100 Subject: [PATCH 8/9] New pull-request 5 1. Revert LilyPad.pde to it's original state. 2. Make the example code more concise. --- LilyPad/LilyPad.pde | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LilyPad/LilyPad.pde b/LilyPad/LilyPad.pde index 6bec200..3cad346 100644 --- a/LilyPad/LilyPad.pde +++ b/LilyPad/LilyPad.pde @@ -5,7 +5,7 @@ Click the "Run" button to Run the simulation. Change the geometry, flow conditions, numercial parameters visualizations and measurments from this window. - + *********************************************************/ BDIM flow; CircleBody body; From 25d01de548009eb09dc49b1599a86555225f12ab Mon Sep 17 00:00:00 2001 From: Yongxin Chen Date: Sun, 12 Jul 2015 16:43:48 +0100 Subject: [PATCH 9/9] Circle array test case cleaned up project test case --- LilyPad/CircleArray.pde | 196 ++++++++++++++++++---------------------- LilyPad/SaveData2.pde | 123 ------------------------- 2 files changed, 89 insertions(+), 230 deletions(-) delete mode 100644 LilyPad/SaveData2.pde diff --git a/LilyPad/CircleArray.pde b/LilyPad/CircleArray.pde index 788a083..44d06fb 100644 --- a/LilyPad/CircleArray.pde +++ b/LilyPad/CircleArray.pde @@ -3,11 +3,16 @@ CircleArray class creats a single circle ring of cylinders. The input arguments are center coordinates X, Y; diameter of each cylinder D; Radius of circle array; division n; Angle of Attack rad; window. -CircleArrangement class uses CircleArray to setup circular arrangement for many times. +CircleArrangement class extends CircleArray class to create circle arrangement +for many times. + +SaveDrag class saves drag coefficient by two methods: +1. saves the total drag coefficient; +2. saves each cylinder's drag coefficient. Example code: -SaveData2 dat; +SaveDrag dat; CircleArrangement body; BDIM flow; FloodPlot flood; @@ -23,7 +28,7 @@ void setup(){ Window view = new Window(n,n); float x = (float)n/2., y = (float)n/2.; //central position body = new CircleArrangement(x, y, d, R, 20, PI/2, view); - dat = new SaveData2("saved/N39d12DragAoA90.txt",body); + dat = new SaveDrag("saved/test.txt",body); flow = new BDIM(n,n,0,body,(float)1./Reh,true); flood = new FloodPlot(view); flood.range = new Scale(-.75,.75); @@ -36,21 +41,19 @@ void draw(){ flow.update2(); flood.display(flow.u.vorticity()); body.display(); - dat.addData(flow.p,"Drag", DG); // "Drag" or "Lift" + dat.addDataT(flow.p, DG); } **********************************/ class CircleArray extends Body{ ArrayList circleList = new ArrayList(); //This is a container for all bodies - float X, Y; //X, Y represent a temporal coordinate of a new body - CircleArray(float x, float y, float d, float R, int n, float rad, Window window){ + + CircleArray(float x, float y, Window window){ super(x, y, window); - for ( int i = 1; i <= n; i++ ){ - //Define each body's center coordinate. - X = x+R*cos(TWO_PI/n*i+rad); - Y = y+R*sin(TWO_PI/n*i+rad); - circleList.add(new CircleBody(X, Y, d, window)); - } + } + + void add(float X, float Y, float d){ + circleList.add(new CircleBody(X, Y, d, window)); } void display(color C, Window window ){ @@ -59,60 +62,41 @@ class CircleArray extends Body{ } } - float distance(float x, float y){ - float d = 0; - float dmin = 1E5; - for ( CircleBody circle : circleList ){ - d = circle.distance(x, y); - dmin = min(d, dmin); + Body closest (float x, float y){ + float dmin = 1e5; + Body body = circleList.get(0); + for (CircleBody circle: circleList){ + if(circle.distance(x, y) < dmin){ + dmin = circle.distance(x, y); + body = circle; + } } - return dmin; - } + return body; + } - int distance( int px, int py){ // in pixels - int d = 0; - int dmin = (int)1e3; - for ( CircleBody circle : circleList ){ - d = circle.distance(px, py); - dmin = min(d, dmin); - } - return dmin; - } - - Body closest (float x, float y){ - float dmin = 1e5; - Body body = circleList.get(0); - //CircleBody b; - for (CircleBody circle: circleList){ - if(circle.distance(x, y) < dmin){ - dmin = circle.distance(x, y); - body = circle; - } - } - return body; + float distance(float x, float y){ + Body c = closest(x,y); + return c.distance(x,y); } - PVector WallNormal(float x, float y){ + PVector WallNormal(float x, float y){ Body c = closest(x,y); return c.WallNormal(x,y); } - float velocity( int d, float dt, float x, float y ){ + float velocity( int d, float dt, float x, float y ){ Body c = closest(x,y); return c.velocity(d,dt,x,y); - } + } } - /*================================================ CircleArrangement class ================================================*/ -class CircleArrangement extends Body { - ArrayList circleArr = new ArrayList(); - CircleArrangement(float x, float y, float d, float R, int n, //float ro, - float rad, Window window) { +class CircleArrangement extends CircleArray { + CircleArrangement(float x, float y, float d, float R, int n, float rad, Window window) { super(x, y, window); int N; // N is number of rings @@ -120,7 +104,7 @@ class CircleArrangement extends Body { N = 1; } else if (n<=20){ N = 2; - } else if (n<=40){ + } else if (n<=39){ N = 3; } else if (n<=65){ N = 4; @@ -135,82 +119,80 @@ class CircleArrangement extends Body { int[] ring = new int[7]; ring[1] = 6; ring[2] = 13; - ring[3] = 20; + ring[3] = 19; ring[4] = 25; ring[5] = 31; // The logic for the arrangement is expect from centric cylinder and most outer ring, // the middle parts are arranged separately with specific AoA. if (N==1){ - if(n==1){ - circleArr.add(new CircleArray(x, y, d, 0, 1, rad, window)); - } - else{ - circleArr.add(new CircleArray(x, y, d, R, n-1, rad, window)); - circleArr.add(new CircleArray(x, y, d, 0, 1, rad, window)); + if(n>1){ + ring( x, y, d, R, n-1, rad ); } + ring( x, y, d, 0, 1, rad ); } else{ - int temp; - temp = n-1; - for (int i=1; i bodys = new ArrayList(); + int n; - int distance(int px, int py) { // in pixels - int d = 0; - int dmin = (int) 1e3; - for (CircleArray array : circleArr) { - d = array.distance(px, py); - dmin = min(d, dmin); + SaveDrag(String name, CircleArrangement body){ + output = createWriter(name); + n = 0; + for(CircleBody circle : body.circleList){ + bodys.add(circle); + n++; } - return dmin; + this.bodys = bodys; + this.n = n; } - - Body closest(float x, float y) { - float dmin = 1e5; - CircleArray body = circleArr.get(0); - // CircleBody b; - for (CircleArray array : circleArr) { - if (array.distance(x, y) < dmin) { - dmin = array.distance(x, y); - body = array; + + // add total drag coefficient of array + void addDataT(Field a, float L){ + PVector pressure=new PVector(0, 0); + for(CircleBody circle : bodys){ + pressure.add(circle.pressForce(a)); } - } - return body.closest(x, y); - } - - PVector WallNormal(float x, float y) { - Body c = closest(x, y); - return c.WallNormal(x, y); - } - - float velocity(int d, float dt, float x, float y) { - Body c = closest(x, y); - return c.velocity(d, dt, x, y); + output.println(2*pressure.x/L + " "); + } + // add single drag coefficient of each cylinder of array + void addDataS(Field a, float L){ + for(CircleBody circle : bodys){ + output.print(2*circle.pressForce(a).x/L+" "); + } + output.println(); + } + + void finish(){ + output.flush(); // Writes the remaining data to the file + output.close(); // Finishes the file } + } - diff --git a/LilyPad/SaveData2.pde b/LilyPad/SaveData2.pde deleted file mode 100644 index 9056fa0..0000000 --- a/LilyPad/SaveData2.pde +++ /dev/null @@ -1,123 +0,0 @@ -/********************************** - SaveData2 class - This is a simplified version of SaveData class which is exclusive for circular array of cylinders. - Saves data to a text file with customizable header - ----- example code fragment: - - SaveData2 dat; - - void setup(){ - ... - dat = new SaveData2("saved/N39d12DragAoA90.txt",body); - ... - } - - void draw(){ - ... - dat.addData(flow.p,"Drag", DG); - ... - } -----see use in CircleArray.pde -***********************************/ -class SaveData2{ - ArrayList coords = new ArrayList(); - PrintWriter output; - int n; - ArrayList bodys = new ArrayList(); - SaveData2(String name, CircleArrangement body){ - output = createWriter(name); - n = 0; - for(CircleArray subcircleArr : body.circleArr){ - for(CircleBody circle: subcircleArr.circleList){ - for(PVector xy: circle.coords){ - coords.add(xy); - } - bodys.add(circle); - n++; - } - } - this.bodys = bodys; - this.n = n; -} - - void saveParam(String name, float value){ - output.println("% " + name + " = " + value + ";"); - } - void saveString(String s){ - output.println(s); - } - - - void addData(Field a, String str, float L){ - //get pressure for every cylinder. - PVector pressure=new PVector(0, 0); - for(CircleBody cb : bodys){ - pressure.add(cb.pressForce(a)); - } - - if(str.equals("Drag")){ - output.println(2*pressure.x/L + " "); - } - else{ - output.println(2*pressure.y/L + " "); - } - } - - // New addData method that restores drag or lift coefficient of each cylinder. - // The 4th argument is just only for distinguishing this function to store single cylinder's information with other functions. e.g. "Single". - // Output file with the format: - /* - cylinder 1's Drag pressure, cylinder 2's Drag pressure, cylinder 3's Drag pressure,..., cylinder n's Drag pressure (first time step) - cylinder 1's Drag pressure, cylinder 2's Drag pressure, cylinder 3's Drag pressure,..., cylinder n's Drag pressure (second time step) - cylinder 1's Drag pressure, cylinder 2's Drag pressure, cylinder 3's Drag pressure,..., cylinder n's Drag pressure (third time step) - */ - void addData(Field a, String str, float L, String str2){ - if(str.equals("Drag")){ - for(CircleBody cb : bodys){ - output.print(2*cb.pressForce(a).x/L+" "); - } - output.println(); - } - else{ - for(CircleBody cb : bodys){ - output.print(2*cb.pressForce(a).y/L+" "); - } - output.println(); - } - } - - void addData(float t, Field a){ - output.print(t + " "); - for(int i=0; i