/* * full_tpc.java */ import com.comsol.model.*; import com.comsol.model.util.*; import java.io.*; import java.util.Arrays; import java.util.List; import java.util.ArrayList; import java.util.Vector; import java.util.Stack; import java.text.*; /** Model exported on Nov 10 2012, 19:51 by COMSOL 4.1.0.88. */ public class full_tpc_interactive { public static void main(String[] args) { int deformcath=1; int single_force=0; double force = 0.3;//[N] double forceStop =0.3; double forceStep =0.3; int single_degree=0; double degree =-0.3; double DegStop =0.3; double DegStep =0.1; int single=1; int shortci=4; //4 in reality int shortco=3; //3 in reality double Els; double ElsStart=-200; double ElsEnd=-200; double ElsStep=-1; double Ed=-312.9; double dLs=4.7; double dLsStart=4.7; double dLsStop=5.0; double dLsStep=0.1; Integer nofStr=10;//479; //485; double strShifti=0; double strShifto=0; String name; Els=ElsStart; if (single==0) while(dLs<=dLsStop){ while(Els>=ElsEnd) { name="_86ar85"; run(Ed,Els,shortci,shortco,name,dLs,nofStr,-3458.6,-3528.6,-25940,strShifti,strShifto,0,0,0); // Drift=86%, GEM=85% Els+=ElsStep; } dLs+=dLsStep; Els=ElsStart; } else { //Els=-200.; Els=-341; //Ed=-309.6; //dLs=3.5; dLs=4.7; //nofStr=20; System.out.println("****************SINGLE*********************"); name="perfect_"; //run(Ed,Els,shortci,shortco,name,dLs,nofStr,0,0,0,0,0,0,0,0); name="bending_"; run(Ed,Els,shortci,shortco,name,dLs,nofStr,0,0,0,0,0,1,2,0); name=""; String name2; name2=name+"86ar85_"; //run(Ed,Els,shortci,shortco,name2,dLs,nofStr,-3458.6,-3528.6,-25940,strShifti,strShifto,0,0); // Drift=86%, GEM=85% //name2=name+"86ar84_"; //run(Ed,Els,shortci,shortco,name2,dLs,nofStr,-3417.97,-3487.97,-25898.9); //Drift=86%, GEM=84% //name2=name+"65ar81_"; //run(Ed,Els,shortci,shortco,name2,dLs,nofStr,-3295.88,-3365.73,-20306,0,0); //Drift=65%, GEM=81% (actually 80.6) Pion Beamtime //name2=name+"65ar80_"; //run(Ed,Els,shortci,shortco,name2,dLs,nofStr,-3255.2,-3325.05,-20265,0,0); //Drift=65%, GEM=80% (actually 79.6) Pion Beamtime /* for(int scale=60; scale<=90; scale+=2) { name2=name+Integer.toString(scale)+"ar85_"; //System.out.println(name2); //System.out.println(-30162*(double)(scale/100.)); run(Ed,Els,shortci,shortco,name2,dLs,nofStr,-3255.2,-3325.05,-30162*(double)(scale/100.),0,0); } */ } } public static Model run(double E1, double E2, Integer _shorti,Integer _shorto, String addon, double dLsG1, Integer nofStrips, double V1, double V2, double V3, double shi, double sho, int deformcath, double force, double degree) { // Integer nofStrips=10;//479; //Double dLsG1=0.47; String fieldf; //Settings Deformcath double step=0.1;//[mm] double length=105.0;//[mm] int corr=1050; double high=1.0;//[mm] double width=100.0;//[mm] double AreaMoment=high*Math.pow(width,3)*1/12 ; double Emod=36.0;//[MPa] Vector rValues = new Vector(); Vector zValues = new Vector(); Double zCathode=0.25+0.001+dLsG1+(nofStrips*1.5); Double zCathodedef=0.25+0.001+dLsG1+(nofStrips*1.5)+1; Integer stud=0; int dbgplots=1; Integer grid=1; double Edrift=E1; double Els=E2; double Vd=Edrift*(nofStrips*0.15); if (V3!=0) Vd=V3; //3.5 mm ls gem distance to strips double Vls=Els*(dLsG1/10.); if (V2!=0) Vls=V2; double Vgem=0; System.out.println("*******************************************"); System.out.println("now doing: Els="+Double.toString(Els)); System.out.println("Ed="+Double.toString(Edrift)); System.out.println("dLs="+Double.toString(dLsG1)); System.out.println("Inner/Outer Shorts:"+Integer.toString(_shorti)+"/"+Integer.toString(_shorto)); System.out.println("Inner/Outer Shift:"+Double.toString(shi)+"/"+Double.toString(sho)); System.out.println("NUmber of Strips="+Integer.toString(nofStrips)); System.out.println("Force"+Double.toString(force)); System.out.println("*******************************************"); if (V1!=0) { Vgem=V1; Edrift=(Vd-Vgem)/(nofStrips*0.15+dLsG1/10.); Els=(Vls-Vgem)/(dLsG1/10.); System.out.println("************CHANGED FIELDS*****************"); System.out.println("Els="+Double.toString(Els)); System.out.println("Ed="+Double.toString(Edrift)); System.out.println("*******************************************"); } Integer shortsi=_shorti; Integer shortso=_shorto; double Vstepi=(Vd-Vls)/((double)nofStrips-((double)shortsi/2.)); double Vstepo=(Vd-Vls)/((double)nofStrips-((double)shortso/2.)); //System.out.println(((double)nofStrips-((double)shorts/2.))); // int srow[][]=new int[][]{{1944,1,2428},{3890,1,4374},{4375,3,5827},{6319,3,7771}}; System.out.println("Vstepi:"+Double.toString(Vstepi)); System.out.println("Vstepo:"+Double.toString(Vstepo)); int srow[][]=new int[][]{{1944,1,2428}, {3890,1,4374}, {4375,3,5827}, {6319,3,7771}}; srow[0][0]=4*nofStrips+4; srow[0][1]=1; srow[0][2]=srow[0][0]+nofStrips-1; srow[1][0]=srow[0][2]+3*(nofStrips-1)+4; srow[1][1]=1; srow[1][2]=srow[1][0]+nofStrips-1; if (deformcath==1) { System.out.println("big offset"); srow[2][0]=srow[1][2]+1050+11; } else { System.out.println("no offset"); srow[2][0]=srow[1][2]+11; } srow[2][1]=3; srow[2][2]=srow[2][0]+3*(nofStrips-1); srow[3][0]=srow[2][2]+nofStrips+3; srow[3][1]=3; srow[3][2]=srow[3][0]+3*(nofStrips-1); int srow2[][]=new int[][]{{1944,1,2428}, {3890,1,4374}, {4375,3,5827}, {6319,3,7771}}; srow2[0][0]=3; srow2[0][1]=4; srow2[0][2]=srow2[0][0]+4*(nofStrips-1); srow2[1][0]=srow2[0][2]+1*(nofStrips-1)+6; srow2[1][1]=3; srow2[1][2]=srow2[1][0]+3*(nofStrips-1); if (deformcath==1) { System.out.println("big offset"); srow2[2][0]=srow2[1][2]+1050+13+4*nofStrips; System.out.println("*******"+Double.toString(srow2[2][0])); } else { System.out.println("no offset"); srow2[2][0]=srow2[1][2]+13+4*nofStrips; } srow2[2][1]=1; srow2[2][2]=srow2[2][0]+(nofStrips-1); srow2[3][0]=srow2[2][2]+3*nofStrips+2; srow2[3][1]=2; srow2[3][2]=srow2[3][0]+2*(nofStrips-1); int ngems; int[] ndriftDef=new int[1050]; int value; int stop; int stop2; if (degree != 0.){ value = srow[1][2]+4; stop = srow[1][2]+4; ngems=srow[1][2]+2; } else{ value = srow[1][2]+5; stop = srow[1][2]+5; ngems=srow[1][2]+3; } for (int i= 0; i < 1050; i++) { ndriftDef[i]=value; if (value == stop){ if (degree != 0.){ value+=5; } else{ value+=2; } } if ((degree!=0.) && (value == srow[1][2]+528)){ value+=2; } value+=1; } int ndrift=srow[1][2]+5; Model model = ModelUtil.create("Model"); // model.modelPath("E:/last_strip_studies"); String CathodeBending = "(Bforce*Clength^3)/(6*Emod*AreaMoment)*( (( x -CmaxR)/Clength)^3-3*(( x -CmaxR)/Clength)^2)+Cz"; model.param().set("Els" , Double.toString(Els) +" [V/cm]"); model.param().set("Edrift" , Double.toString(Edrift) +" [V/cm]"); model.param().set("dLsG1" , Double.toString(dLsG1) +" [mm]"); model.param().set("Vls" , Double.toString(Vls) +" [V]"); model.param().set("Vd" , Double.toString(Vd) +" [V]"); model.param().set("Vg" , Double.toString(Vgem) +" [V]"); model.param().set("shortsi", Integer.toString(shortsi)); model.param().set("shortso", Integer.toString(shortso)); model.param().set("Vstepi","(Vd-Vls)/(nofStrips-shortsi)"); model.param().set("Vstepo","(Vd-Vls)/(nofStrips-shortso)"); model.param().set("Bforce", Double.toString(force)+" [N]"); model.param().set("Emod", Double.toString(Emod)+" [MPa]"); model.param().set("AreaMoment",Double.toString(AreaMoment)+" [mm^4]"); model.param().set("nofStrips",Integer.toString(nofStrips)); model.param().set("Cz","0.25[mm]+0.001[mm]+dLsG1+(nofStrips*1.5[mm])"); model.param().set("Clength", "105[mm]"); model.param().set("CmaxR", "155[mm]"); model.param().set("CminZ", CathodeBending.replace(" x "," 50[mm]")); model.param().set("shi",Double.toString(shi)); model.param().set("sho",Double.toString(sho)); model.modelNode().create("mod1"); model.func().create("an1", "Analytic"); model.func("an1") .set("expr", CathodeBending); model.func("an1").set("argunit", "m"); model.func("an1").set("plotargs", new String[][]{{"x", "50[mm]", "155[mm]"}}); System.out.println("starting Geometry"); model.geom().create("geom1", 2); model.geom("geom1").axisymmetric(true); model.geom("geom1").lengthUnit("mm"); model.geom("geom1").feature().create("r1", "Rectangle"); //gem if (deformcath==1) { model.geom("geom1").feature().create("Cathode_p1", "BezierPolygon");//deform cathode } else { model.geom("geom1").feature().create("Cathode", "Rectangle"); //cathode } model.geom("geom1").feature().create("r3", "Rectangle"); //volume //gem model.geom("geom1").feature("r1").set("size", new String[]{"105", "1-1e-3"}); model.geom("geom1").feature("r1").set("pos", new String[]{"102.5", "-0.5"}); model.geom("geom1").feature("r1").set("base", "center"); model.geom("geom1").feature("r1").set("rot", degree); //selection Anode String selnameAnod="sel_Anod"; double theta = Math.toRadians(degree); double xminA=102.4; double xmaxA=102.6; double yminA=-0.1; double ymaxA=0.1; //cathode double xminB=50; double xmaxB=155; double yminB; double ymaxB; if (deformcath==1) //calculate the values of the bending curve { String[][] CathodePoints=new String[2][4]; CathodePoints[0][0]="50"; CathodePoints[1][0]=CathodeBending.replace(" x "," 50[mm] "); CathodePoints[0][1]="50"; CathodePoints[1][1]="Cz+1[mm]"; CathodePoints[0][2]="155"; CathodePoints[1][2]="Cz+1[mm]"; CathodePoints[0][3]="155"; CathodePoints[1][3]=CathodeBending.replace(" x "," 155[mm] "); model.geom("geom1").feature("Cathode_p1") .set("p",CathodePoints); model.geom("geom1").feature("Cathode_p1") .set("w", new String[]{"1", "1", "1", "1", "1", "1"}); model.geom("geom1").feature("Cathode_p1").set("type", "open"); model.geom("geom1").feature("Cathode_p1") .set("degree", new String[]{"1", "1", "1"}); model.geom("geom1").feature().create("Cathode_p2", "ParametricCurve"); model.geom("geom1").feature("Cathode_p2").set("parmin", "50"); model.geom("geom1").feature("Cathode_p2").set("parmax", "155"); model.geom("geom1").feature("Cathode_p2").set("pos", new String[]{"0", "0"}); model.geom("geom1").feature("Cathode_p2") .set("coord", new String[]{"s", CathodeBending.replace(" x "," s ")}); model.geom("geom1").feature().create("Cathode", "ConvertToSolid"); model.geom("geom1").feature("Cathode").selection("input") .set(new String[]{"Cathode_p1", "Cathode_p2"}); ymaxB=zCathode; model.param().set("shi","-(Cz-CminZ)"); shi=(force*Math.pow(length,3))/(6*Emod*AreaMoment) * (Math.pow((50)/length,3)-3*(Math.pow((50)/length,2)))+zCathode;//move the inner strips } else { model.geom("geom1").feature("Cathode").set("pos", new String[]{"50", Double.toString(zCathode)}); model.geom("geom1").feature("Cathode").set("size", new String[]{"105", "1"}); yminB=zCathode-0.1; ymaxB=zCathode+0.1; } //Bending selection String selnameBend="sel_bendCathode"; model.geom("geom1").feature().create(selnameBend,"BoxSelection"); model.geom("geom1").feature(selnameBend).name(selnameBend); model.geom("geom1").feature(selnameBend).set("entitydim", "1"); model.geom("geom1").feature(selnameBend).set("inputent", "all"); model.geom("geom1").feature(selnameBend).set("condition", "intersects"); model.geom("geom1").feature(selnameBend).set("groupcontang", "off"); model.geom("geom1").feature(selnameBend).set("xmin", Double.toString(xminB)); model.geom("geom1").feature(selnameBend).set("xmax", Double.toString(xmaxB)); model.geom("geom1").feature(selnameBend).set("ymin", "CminZ"); model.geom("geom1").feature(selnameBend).set("ymax", "Cz"); model.geom("geom1").feature(selnameBend).set("groupcontang", "off"); //model.geom("geom1").run(selnameBend); String fieldf_old="full_field_"+Double.toString(Els)+"_"+Double.toString(Edrift)+"_"+Integer.toString(_shorti)+"s"+Integer.toString(_shorto)+"_"+Double.toString(dLsG1)+"_"+Double.toString(shi)+"sh"+Double.toString(sho)+"_"+Double.toString(force)+"_"+Double.toString(degree)+"_"+addon; fieldf=String.format("full_field_%.2f_%.2f_%ds%d_%.3f_%.3fsh%.3f_%.4f_%s",Els,Edrift,_shorti,_shorto,dLsG1,shi,sho,force,addon); String outpath="/data/fopiroot_data/field_sim/"; System.out.println("Checking Fieldfile: "+outpath+fieldf+".txt"); if ( new File(outpath+"/"+fieldf+".txt").isFile() ) { System.out.println("Field already calculated. skipping"); return model; } if ( new File(outpath+"/"+fieldf_old+".txt").isFile() ) { System.out.println("Field already calculated. Skipping"); return model; } if (new File(outpath+"/"+fieldf+".run").isFile()) { System.out.println("Field is calculated at the moment"); return model; } File runfile=new File(outpath+"/"+fieldf+".run"); try { runfile.createNewFile(); } catch (IOException e) { System.err.println("Error opening lockfile" + e.getMessage()); return model; } //volume Double zVolume=zCathode+2.; model.geom("geom1").feature("r3").set("pos", new String[]{"50-25e-3-2e-3-3e-3 - 1e-3", "-1"}); model.geom("geom1").feature("r3").set("size", new String[]{"105+25e-3+2e-3+2e-3+25e-3+6e-3 + 2e-3","Cz+2[mm]"}); //strips Double zS1=dLsG1+0.75; model.geom("geom1").feature().create("r4", "Rectangle");//outer striprows model.geom("geom1").feature().create("r5", "Rectangle");//inner striprows model.geom("geom1").feature("r4").set("pos", new String[]{"50 - 3e-3", "dLsG1"}); model.geom("geom1").feature("r4").set("size", new String[]{"2e-3", "1"}); model.geom("geom1").feature("r5").set("pos", new String[]{"50 - 25e-3 - 2e-3 - 3e-3", "dLsG1+0.75"}); model.geom("geom1").feature("r5").set("size", new String[]{"2e-3", "1"}); model.geom("geom1").feature().create("arr1", "Array"); model.geom("geom1").feature().create("arr2", "Array"); model.geom("geom1").feature("arr1").set("size", new String[]{"1", "nofStrips"}); model.geom("geom1").feature("arr1").set("displ", new String[]{"0", "1.5"}); model.geom("geom1").feature("arr1").selection("input").set(new String[]{"r4"}); model.geom("geom1").feature("arr2").set("size", new String[]{"1", "nofStrips"}); model.geom("geom1").feature("arr2").set("displ", new String[]{"0", "1.5"}); model.geom("geom1").feature("arr2").selection("input").set(new String[]{"r5"}); model.geom("geom1").feature().create("strip_insulator","Rectangle"); model.geom("geom1").feature("strip_insulator").set("pos", new String[]{"50 - 25e-3 - 2e-3 - 1e-3","dLsG1"}); model.geom("geom1").feature("strip_insulator").set("size",new String[]{"25e-3","Cz+1[mm]-dLsG1-1e-3"}); model.geom("geom1").feature().create("mir1", "Mirror"); model.geom("geom1").feature("mir1").set("keep", true); model.geom("geom1").feature("mir1").set("pos", new String[]{"102.5", "0"}); model.geom("geom1").feature("mir1").selection("input").set(new String[]{"arr1","arr2","strip_insulator"}); model.geom("geom1").feature().create("mov1","Move"); model.geom("geom1").feature("mov1").selection("input").set(new String[]{"mir1"}); model.geom("geom1").feature("mov1").set("disply","sho"); model.geom("geom1").feature().create("mov2","Move"); model.geom("geom1").feature("mov2").selection("input").set(new String[]{"arr1","arr2","strip_insulator"}); model.geom("geom1").feature("mov2").set("disply","shi"); double stamp=System.currentTimeMillis(); model.geom("geom1").run(); System.out.println("Run Geometry needed: "+Double.toString((System.currentTimeMillis()-stamp)/1000)+" s"); int scounter=0; double xmin=0; double xmax=0; double ymin=0; double ymax=0; String shift=""; for (int row=0;row<4;row++) { System.out.println("adding selections to row: "+Integer.toString(row)); scounter=1; ymin=-1e-3; ymax=1+1e-3; if (row==0 | row==1) { //2 + first row + kapton scounter=2+nofStrips+1; //1e-3 is box offset to make sure other partis are inside xmin=50-3e-3 -1e-3; xmax=50-1e-3 +1e-3; //ymin+=shi; //ymax+=shi; shift="shi"; if (row==0) { //starts at 2 (1=air) scounter=2; //kapton thickness, other striprow thicknes + box offset xmin+=-25e-3 - 2e-3 - 1e-3; xmax+=-25e-3 + 1e-3; ymin+=0.75; ymax+=0.75; } } if (row==2 | row==3) { //2 + first row + kapton + second row + anode + cathode scounter=2 + nofStrips + 1 + nofStrips + 1 + 1; xmin=155; xmax=155+3e-3 +1e-3; //ymin+=sho; //ymax+=sho; shift="sho"; if(row==3) { //2 + first row + kapton + second row + anode + cathode + third row + kapton scounter=2 + nofStrips + 1 + nofStrips + 1 + 1 + nofStrips + 1; xmin+=25e-3 + 2e-3; xmax+=25e-3 + 2e-3; ymin+=0.75; ymax+=0.75; } } for (int st=0;st<=nofStrips-1;st++) { System.out.print("At strip "+Integer.toString(st)+" of "+Integer.toString(nofStrips-1)+"\r"); if (st>0) { ymin+=1.5; ymax+=1.5; } String sname="r" +Integer.toString(row)+"s"+Integer.toString(st); String selname="sel_"+sname; model.selection().create(selname,"Explicit"); model.selection(selname).geom("geom1", 2, 1, new String[]{"exterior"}); model.selection(selname).name(selname); model.selection(selname).set(new int[]{scounter}); scounter++; } System.out.println(""); } System.out.println("Run Geometry and Selections needed: "+Double.toString((System.currentTimeMillis()-stamp)/1000)+" s"); System.out.println("adding materials"); model.material().create("mat1"); model.material("mat1").name("Copper"); model.material("mat1").set("family", "copper"); model.material("mat1").propertyGroup("def").set("relpermeability", "1"); model.material("mat1").propertyGroup("def") .set("electricconductivity", "5.998e7[S/m]"); model.material("mat1").propertyGroup("def") .set("thermalexpansioncoefficient", "17e-6[1/K]"); model.material("mat1").propertyGroup("def") .set("heatcapacity", "385[J/(kg*K)]"); model.material("mat1").propertyGroup("def").set("relpermittivity", "1"); model.material("mat1").propertyGroup("def") .set("density", "8700[kg/m^3]"); model.material("mat1").propertyGroup("def") .set("thermalconductivity", "400[W/(m*K)]"); model.material("mat1").propertyGroup() .create("Enu", "Elastizit\u00e4tsmodul und Poissonzahl"); model.material("mat1").propertyGroup("Enu").set("poissonsratio", "0.35"); model.material("mat1").propertyGroup("Enu") .set("youngsmodulus", "110e9[Pa]"); model.material("mat1").propertyGroup() .create("linzRes", "Linearisierter spezifischer Widerstand"); model.material("mat1").propertyGroup("linzRes") .set("alpha", "0.0039[1/K]"); model.material("mat1").propertyGroup("linzRes") .set("rho0", "1.72e-8[ohm*m]"); model.material("mat1").propertyGroup("linzRes").set("Tref", "298[K]"); model.material("mat1").set("family", "copper"); model.material().create("mat2"); model.material("mat2").name("Air"); model.material("mat2").set("family", "air"); model.material("mat2").propertyGroup("def").set("relpermeability", "1"); model.material("mat2").propertyGroup("def").set("relpermittivity", "1"); model.material("mat2").propertyGroup("def") .set("dynamicviscosity", "eta(T[1/K])[Pa*s]"); model.material("mat2").propertyGroup("def") .set("ratioofspecificheat", "1.4"); model.material("mat2").propertyGroup("def") .set("electricconductivity", "0[S/m]"); model.material("mat2").propertyGroup("def") .set("heatcapacity", "Cp(T[1/K])[J/(kg*K)]"); model.material("mat2").propertyGroup("def") .set("density", "rho(pA[1/Pa],T[1/K])[kg/m^3]"); model.material("mat2").propertyGroup("def") .set("thermalconductivity", "k(T[1/K])[W/(m*K)]"); model.material("mat2").propertyGroup("def") .set("soundspeed", "cs(T[1/K])[m/s]"); model.material("mat2").propertyGroup("def").func() .create("eta", "Piecewise"); model.material("mat2").propertyGroup("def").func("eta") .set("funcname", "eta"); model.material("mat2").propertyGroup("def").func("eta").set("arg", "T"); model.material("mat2").propertyGroup("def").func("eta") .set("extrap", "constant"); model.material("mat2").propertyGroup("def").func("eta") .set("pieces", new String[][]{{"200.0", "1600.0", "-8.38278E-7+8.35717342E-8*T^1-7.69429583E-11*T^2+4.6437266E-14*T^3-1.06585607E-17*T^4"}}); model.material("mat2").propertyGroup("def").func() .create("Cp", "Piecewise"); model.material("mat2").propertyGroup("def").func("Cp") .set("funcname", "Cp"); model.material("mat2").propertyGroup("def").func("Cp").set("arg", "T"); model.material("mat2").propertyGroup("def").func("Cp") .set("extrap", "constant"); model.material("mat2").propertyGroup("def").func("Cp") .set("pieces", new String[][]{{"200.0", "1600.0", "1047.63657-0.372589265*T^1+9.45304214E-4*T^2-6.02409443E-7*T^3+1.2858961E-10*T^4"}}); model.material("mat2").propertyGroup("def").func() .create("rho", "Analytic"); model.material("mat2").propertyGroup("def").func("rho") .set("funcname", "rho"); model.material("mat2").propertyGroup("def").func("rho") .set("args", new String[]{"pA", "T"}); model.material("mat2").propertyGroup("def").func("rho") .set("expr", "pA*0.02897/8.314/T"); model.material("mat2").propertyGroup("def").func("rho") .set("dermethod", "manual"); model.material("mat2").propertyGroup("def").func("rho") .set("argders", new String[][]{{"pA", "d(pA*0.02897/8.314/T,pA)"}, {"T", "d(pA*0.02897/8.314/T,T)"}}); model.material("mat2").propertyGroup("def").func() .create("k", "Piecewise"); model.material("mat2").propertyGroup("def").func("k") .set("funcname", "k"); model.material("mat2").propertyGroup("def").func("k").set("arg", "T"); model.material("mat2").propertyGroup("def").func("k") .set("extrap", "constant"); model.material("mat2").propertyGroup("def").func("k") .set("pieces", new String[][]{{"200.0", "1600.0", "-0.00227583562+1.15480022E-4*T^1-7.90252856E-8*T^2+4.11702505E-11*T^3-7.43864331E-15*T^4"}}); model.material("mat2").propertyGroup("def").func() .create("cs", "Analytic"); model.material("mat2").propertyGroup("def").func("cs") .set("funcname", "cs"); model.material("mat2").propertyGroup("def").func("cs") .set("args", new String[]{"T"}); model.material("mat2").propertyGroup("def").func("cs") .set("expr", "sqrt(1.4*287*T)"); model.material("mat2").propertyGroup("def").func("cs") .set("dermethod", "manual"); model.material("mat2").propertyGroup("def").func("cs") .set("argders", new String[][]{{"T", "d(sqrt(1.4*287*T),T)"}}); model.material("mat2").propertyGroup("def").addInput("temperature"); model.material("mat2").propertyGroup("def").addInput("pressure"); model.material("mat2").set("family", "air"); model.material().create("mat3"); model.material("mat3").propertyGroup("def").func() .create("k", "Piecewise"); model.material("mat3").propertyGroup("def").func() .create("C", "Piecewise"); model.material("mat3").propertyGroup("def").func() .create("rho", "Piecewise"); model.material("mat3").name("Polyimide tape (Kapton HN) [solid]"); model.material("mat3").propertyGroup("def").func("k") .set("pieces", new String[][]{{"5.0", "140.0", "-0.001372384+0.005601653*T^1+2.082966E-6*T^2-5.05445E-9*T^3"}, {"140.0", "300.0", "-0.007707532+0.005769136*T^1+5.622796E-7*T^2-4.329984E-10*T^3"}}); model.material("mat3").propertyGroup("def").func("k").set("arg", "T"); model.material("mat3").propertyGroup("def").func("C") .set("pieces", new String[][]{{"4.0", "30.0", "2.809666-1.394349*T^1+0.2106639*T^2+0.004752016*T^3-3.279998E-4*T^4+4.282249E-6*T^5"}, {"30.0", "300.0", "-86.86946+7.816917*T^1-0.03664788*T^2+9.9128E-5*T^3-1.08441E-7*T^4"}}); model.material("mat3").propertyGroup("def").func("C").set("arg", "T"); model.material("mat3").propertyGroup("def").func("rho") .set("pieces", new String[][]{{"293.0", "303.0", "1420.0"}}); model.material("mat3").propertyGroup("def").func("rho").set("arg", "T"); model.material("mat3").propertyGroup("def") .set("thermalconductivity", new String[]{"k(T[1/K])[W/(m*K)]", "0", "0", "0", "k(T[1/K])[W/(m*K)]", "0", "0", "0", "k(T[1/K])[W/(m*K)]"}); model.material("mat3").propertyGroup("def") .set("heatcapacity", "C(T[1/K])[J/(kg*K)]"); model.material("mat3").propertyGroup("def") .set("density", "rho(T[1/K])[kg/m^3]"); model.material("mat3").propertyGroup("def") .set("relpermittivity", new String[]{"3.83", "0", "0", "0", "3.83", "0", "0", "0", "3.83"}); model.material("mat3").propertyGroup("def").addInput("temperature"); model.material("mat1").selection().all(); model.material().move("mat2", 1); model.material("mat2").selection().set(new int[]{1}); stamp=System.currentTimeMillis(); System.out.println("adding physics"); model.physics().create("es", "Electrostatics", "geom1"); scounter=0; double pot=0; double Vstep; xmin=0; xmax=0; ymin=0; ymax=0; //set potentials of field strips stamp=System.currentTimeMillis(); for (int row=0;row<4;row++){ scounter=0; System.out.println("adding potential to row: "+Integer.toString(row)); int[] strip = new int[4]; strip[0]=srow[row][0]; strip[1]=srow2[row][0]; ymin=dLsG1-1e-3; ymax=dLsG1+1+1e-3; if (row==0 | row==1) { strip[2]=strip[1]+1; //1e-3 is box offset to make sure other partis are inside xmin=50-3e-3 -1e-3; xmax=50-1e-3 +1e-3; ymin+=shi; ymax+=shi; if (row==0) { //kapton thickness, other striprow thicknes + box offset xmin+=-25e-3-2e-3 -1e-3; xmax+=-25e-3 +1e-3; ymin+=0.75; ymax+=0.75; } } if (row==2 | row==3) { xmin=155; xmax=155+3e-3 +1e-3; ymin+=sho; ymax+=sho; strip[2]=strip[0]+1; if(row==3) { xmin+=25e-3+2e-3; xmax+=25e-3+2e-3; ymin+=0.75; ymax+=0.75; } } if (row==0) {strip[3]=strip[2]+2;} else {strip[3]=strip[2]+1;} for (int st=0;st<=nofStrips-1;st++) { System.out.print("At strip "+Integer.toString(st)+" of "+Integer.toString(nofStrips-1)+"\r"); if (st>0) { ymin+=1.5; ymax+=1.5; } String sname="r" +Integer.toString(row)+"s"+Integer.toString(scounter); String selname="sel_"+sname; model.physics("es").feature().create(sname, "ElectricPotential", 1); model.physics("es").feature(sname).selection().named(selname); //model.physics("es").feature(sname).selection().set(strip); model.physics("es").feature(sname).name(sname); String potS=""; String VstepS=""; if (row==0|row==1) { Vstep=Vstepi; VstepS="Vstepi"; } else { Vstep=Vstepo; VstepS="Vstepo"; } if (row==0 | row==3) { pot=Vls+Vstep/2.+Vstep*scounter; potS="Vls+"+VstepS+"/2.+"+VstepS+"*"+Integer.toString(scounter); } else { pot=Vls+Vstep*scounter; potS="Vls+"+VstepS+"*"+Integer.toString(scounter); } /* if (pot<=Vd) { pot=Vd; potS="Vd"; } */ model.physics("es").feature(sname). set("V0", "("+potS+")*( ("+potS+")>Vd)+Vd*(("+potS+")<=Vd) "); scounter++; strip[0]+=srow[row][1]; strip[1]+=srow2[row][1]; if (row==0 | row==1) {strip[2]=strip[1]+1;} if (row==2 | row==3) {strip[2]=strip[0]+1;} if (row==0) {strip[3]=strip[2]+2;} else {strip[3]=strip[2]+1;} } System.out.println(""); } System.out.println("Adding Physics needed: "+Double.toString((System.currentTimeMillis()-stamp)/1000)+" s"); //set potential of drift System.out.println("Adding drift potential"); model.physics("es").feature().create("Vdrift", "ElectricPotential", 1); model.physics("es").feature("Vdrift").selection().named("geom1_"+selnameBend); model.physics("es").feature("Vdrift").name("Vdrift"); model.physics("es").feature("Vdrift").set("V0", "Vd"); //set gem potential System.out.println("adding gem potential"); model.physics("es").feature().create("Vgem", "ElectricPotential", 1); model.physics("es").feature("Vgem").selection().named("geom1_"+selnameAnod); model.physics("es").feature("Vgem").name("Vgem"); model.physics("es").feature("Vgem").set("V0", "Vg"); System.out.println("adding mesh"); model.mesh().create("mesh1", "geom1"); model.mesh("mesh1").feature().create("ftri1", "FreeTri"); model.mesh("mesh1").feature("size").set("hauto", 4); //model.mesh("mesh1").feature("size").set("hauto", "9"); model.mesh("mesh1").feature("size").set("hmax", "100"); model.mesh("mesh1").feature("size").set("hmin", "15"); //model.mesh("mesh1").feature("size").set("hmax", "30"); //model.mesh("mesh1").feature("size").set("hmin", "0.1"); model.mesh("mesh1").feature("size").set("hcurve", "1"); model.mesh("mesh1").feature("size").set("hgrad", "1.2"); model.mesh("mesh1").feature("size").set("hnarrow", "0.05"); //model.mesh("mesh1").feature("size").set("hgrad", "2"); //model.mesh("mesh1").feature("size").set("hnarrow", "0.005"); model.mesh("mesh1").feature("ftri1").set("xscale", "10"); model.mesh("mesh1").feature("ftri1").set("yscale", "10"); System.out.println("adding study"); model.study().create("std1"); model.study("std1").feature().create("stat", "Stationary"); if (stud==1) { System.out.println("start meshing"); model.mesh("mesh1").run(); System.out.println("start study"); model.study("std1").run(); System.out.println("creating solution"); model.sol("sol1").study("std1"); model.sol("sol1").attach("std1"); System.out.println("Creating fieldmatrix"); if (grid==2) { // File file=new File("/nfs/hicran/project/panda/SIM/bergerm/"+fieldf+".txt"); File file=new File(outpath+fieldf+".txt"); try { // File file; // file=new File("/nfs/hicran/project/panda/SIM/bergerm/"+fieldf+".txt"); FileWriter writer=new FileWriter(file,true); // BufferedWriter writer = new BufferedWriter(fstream); Double x; Double y; model.result().dataset().create("cpt2", "CutPoint2D"); model.result().numerical().create("Er","EvalPoint"); model.result().numerical().create("Ez","EvalPoint"); model.result().numerical().create("V","EvalPoint"); for(x=50.;x<=155.;x++) { for(y=0.;y<=3.5+nofStrips*1.5;y++) { model.result().dataset("cpt2").set("pointy", Double.toString(x)); model.result().dataset("cpt2").set("pointx", Double.toString(y)); model.result().numerical("Er").set("data","cpt2"); model.result().numerical("Er").set("expr","es.Er"); model.result().numerical("Er").set("unit","V/cm"); model.result().numerical("Er").run(); model.result().numerical("Ez").set("data","cpt2"); model.result().numerical("Ez").set("expr","es.Ez"); model.result().numerical("Ez").set("unit","V/cm"); model.result().numerical("Ez").run(); model.result().numerical("V").set("data","cpt2"); model.result().numerical("V").set("expr","V"); model.result().numerical("V").set("unit","V"); model.result().numerical("V").run(); Double resultEr; Double resultEz; Double resultV; System.out.println(Arrays.deepToString(model.result().numerical("Er").getReal())); resultEr=model.result().numerical("Er").getReal()[0][0]; resultEz=model.result().numerical("Ez").getReal()[0][0]; resultV=model.result().numerical("V").getReal()[0][0]; writer.write(Double.toString(x)+" "); writer.write(Double.toString(y)+" "); writer.write(Double.toString(resultEr)+" "); writer.write(Double.toString(resultEz)+" "); writer.write(Double.toString(resultV)); writer.write(System.getProperty("line.separator")); writer.flush(); System.out.println(Double.toString(x)+" "+Double.toString(y)+" "+Double.toString(resultEr)+" "+Double.toString(resultEz)); } } writer.close();}catch(IOException e){e.printStackTrace();System.err.println("hhh");} } if (grid==1) { model.result().dataset().create("cpt1", "CutPoint2D"); model.result().dataset("cpt1").set("method", "grid"); model.result().dataset("cpt1").set("gridx", "range(50,0.5,155)"); model.result().dataset("cpt1").set("gridy", "range(0,0.5,dLsG1+nofStrips*1.5)"); model.result().dataset("cpt1").run(); System.out.println("adding result"); model.result().dataset("cpt1").run(); model.result().export().create("data1", "Data"); model.result().export("data1").set("data", "cpt1"); model.result().export("data1").setIndex("expr", "es.Er", 0); model.result().export("data1").setIndex("expr", "es.Ez", 1); model.result().export("data1").setIndex("expr", "V", 2); model.result().export("data1").setIndex("unit", "V/cm", 0); model.result().export("data1").setIndex("unit", "V/cm", 1); model.result().export("data1").setIndex("unit", "V", 2); model.result().export("data1") .set("filename", outpath+"/"+fieldf+".txt"); System.out.println("exporting result to "+outpath+"/"+fieldf+".txt"); model.result().export("data1").run(); } } if (dbgplots==1 && stud==1) { model.view().create("view4", "geom1"); model.view("view4").name("close to strips inner"); System.out.println("creating cutlines"); model.result().dataset().create("cln1", "CutLine2D"); model.result().dataset().create("cln2", "CutLine2D"); model.result().dataset().create("cln3", "CutLine2D"); model.result().dataset().create("cln4", "CutLine2D"); model.result().dataset("cln1").name("left"); model.result().dataset("cln1") .set("genpoints", new String[][]{{"50-12.5e-3", "0"}, {"50-12.5e-3", "1000"}}); model.result().dataset("cln1").set("genparadist", "range(0,-0.5,-20)"); model.result().dataset("cln1").set("genparaactive", "on"); model.result().dataset("cln2").name("right"); model.result().dataset("cln2") .set("genpoints", new String[][]{{"155+12.5e-3", "0"}, {"155+12.5e-3", "1000"}}); model.result().dataset("cln3") .set("genpoints", new String[][]{{"0", "10"}, {"250", "10"}}); model.result().dataset("cln4").name("Last Strip"); model.result().dataset("cln4") .set("genpoints", new String[][]{{"49", "dLsG1+0.5"}, {"156", "dLsG1+0.5"}}); model.result().create("pg1", 2); model.result("pg1").set("data", "dset1"); model.result("pg1").feature().create("surf1", "Surface"); model.result("pg1").feature("surf1").set("expr", "V"); model.result("pg1").feature("surf1").set("descr", "Electric potential"); model.result("pg1").set("windowtitle", "Graphics"); model.result("pg1").feature().create("con1", "Contour"); model.result("pg1").feature("con1").set("levelmethod", "number"); model.result("pg1").feature("con1").set("number", "80"); model.result("pg1").feature("con1").set("colorlegend", "off"); model.result("pg1").set("windowtitle", "Graphics"); model.result("pg1").feature("con1").set("colorlegend", "off"); model.result("pg1").feature("con1").set("coloring", "uniform"); model.result("pg1").feature("con1").set("color", "black"); model.result("pg1").name("Potential"); model.result("pg1").run(); System.out.println("creating plotgroup2d Er"); model.result().create("pg2", "PlotGroup2D"); model.result("pg2").feature().create("surf1", "Surface"); model.result("pg2").feature("surf1").set("expr", "es.Er"); model.result("pg2").feature("surf1").set("unit", "V/cm"); model.result("pg2").feature("surf1").set("rangecoloractive", "on"); model.result("pg2").feature("surf1").set("rangecolormin", "-30"); model.result("pg2").feature("surf1").set("rangecolormax", "30"); model.result("pg2").name("Radial Field"); model.result("pg2").run(); System.out.println("creating plotgroup2d Ez"); model.result().create("pg3", "PlotGroup2D"); model.result("pg3").feature().create("surf1", "Surface"); model.result("pg3").feature("surf1").set("expr", "es.Ez"); model.result("pg3").feature("surf1").set("unit", "V/cm"); model.result("pg3").feature("surf1").set("rangecoloractive", "on"); model.result("pg3").feature("surf1").set("rangecolormin", "300"); model.result("pg3").feature("surf1").set("rangecolormax", "400"); model.result("pg3").name("Drift Field"); model.result("pg3").run(); System.out.println("creating plotgroup1d V"); model.result().create("pg4", "PlotGroup1D"); model.result("pg4").feature().create("lngr1", "LineGraph"); model.result("pg4").feature().create("lngr2", "LineGraph"); model.result("pg4").set("title", "Line Graph: Electric potential (V) Line Graph: Electric potential (V) "); model.result("pg4").set("xlabel", "Arc length"); model.result("pg4").set("ylabel", "Electric potential (V)"); model.result("pg4").set("titleactive", false); model.result("pg4").set("xlabelactive", false); model.result("pg4").set("ylabelactive", false); model.result("pg4").feature("lngr1").set("data", "cln1"); model.result("pg4").feature("lngr1").set("legend", true); model.result("pg4").feature("lngr2").set("data", "cln2"); model.result("pg4").feature("lngr2").set("legend", true); model.result("pg4").name("Potential along strips"); System.out.println("creating plotgroup1d V2"); model.result().create("pg5", "PlotGroup1D"); model.result("pg5").feature().create("lngr1", "LineGraph"); model.result("pg5").set("data", "cln3"); model.result("pg5").set("title", "Line Graph: Electric potential (V) "); model.result("pg5").set("xlabel", "Arc length"); model.result("pg5").set("ylabel", "Electric potential (V)"); model.result("pg5").set("titleactive", false); model.result("pg5").set("xlabelactive", false); model.result("pg5").set("ylabelactive", false); model.result("pg5").set("axislimits", "on"); model.result("pg5").set("xmin", "40"); model.result("pg5").set("xmax", "60"); model.result("pg5").set("ymin", "-308.8"); model.result("pg5").set("ymax", "-308.4"); System.out.println("creating plotgroup1d V3"); model.result().create("pg6", "PlotGroup1D"); model.result("pg6").feature().create("lngr1", "LineGraph"); model.result("pg6").set("data", "cln3"); model.result("pg6") .set("title", "Line Graph: Electric field, z component (V/m) "); model.result("pg6").set("xlabel", "Arc length"); model.result("pg6").set("ylabel", "Electric field, z component (V/m)"); model.result("pg6").set("axislimits", "on"); model.result("pg6").set("xmin", "40"); model.result("pg6").set("xmax", "60"); model.result("pg6").set("ymin", "3.085e4"); model.result("pg6").set("ymax", "3.09e4"); model.result("pg6").set("titleactive", false); model.result("pg6").set("xlabelactive", false); model.result("pg6").set("ylabelactive", false); model.result("pg6").feature("lngr1").set("expr", "es.Ez"); model.result("pg6").feature("lngr1").set("unit", "V/m"); model.result("pg6").feature("lngr1") .set("descr", "Electric field, z component"); System.out.println("creating paper plots"); model.result().create("pg8", "PlotGroup1D"); model.result("pg8").feature().create("lngr1", "LineGraph"); model.result("pg8").feature().create("lngr2", "LineGraph"); model.result("pg8").name("Paper stuff"); model.result("pg8").set("xlabel", "Bogenl\u00e4nge"); model.result("pg8") .set("ylabel", "Elektrisches Feld, r-Komponente (V/m)"); model.result("pg8").set("ylabelactive", false); model.result("pg8").set("xlabelactive", false); model.result("pg8").feature("lngr1").name("Er"); model.result("pg8").feature("lngr1").set("data", "cln1"); model.result("pg8").feature("lngr1") .set("descr", "Elektrisches Feld, r-Komponente"); model.result("pg8").feature("lngr1").set("unit", "V/m"); model.result("pg8").feature("lngr1").set("legend", true); model.result("pg8").feature("lngr1").set("expr", "es.Er"); model.result("pg8").feature("lngr2").name("Drift diff"); model.result("pg8").feature("lngr2").set("data", "cln1"); model.result("pg8").feature("lngr2") .set("descr", "(es.Ez-309.6[V/m])/309.6[V/m]"); model.result("pg8").feature("lngr2").set("unit", "1"); model.result("pg8").feature("lngr2").set("legend", true); model.result("pg8").feature("lngr2") .set("expr", "(es.Ez-309.6[V/m])/309.6[V/m]"); model.result().create("pg9", "PlotGroup1D"); model.result("pg9").feature().create("lngr1", "LineGraph"); model.result("pg9").name("Er along last strip"); model.result("pg9").set("data", "cln4"); model.result("pg9").set("xlabel", "Arc length"); model.result("pg9").set("ylabel", "Electric field, r component (V/cm)"); model.result("pg9").set("ylabelactive", false); model.result("pg9").set("xlabelactive", false); model.result("pg9").feature("lngr1") .set("descr", "Electric field, r component"); model.result("pg9").feature("lngr1").set("unit", "V/cm"); model.result("pg9").feature("lngr1").set("resolution", "fine"); model.result("pg9").feature("lngr1").set("expr", "es.Er"); model.result().create("pg10", "PlotGroup1D"); model.result("pg10").feature().create("lngr1", "LineGraph"); model.result("pg10").name("Ez along last strip"); model.result("pg10").set("xlabel", "Arc length"); model.result("pg10").set("ylabel", "Electric field, z component (V/cm)"); model.result("pg10").set("ylabelactive", false); model.result("pg10").set("xlabelactive", false); model.result("pg10").feature("lngr1").set("data", "cln4"); model.result("pg10").feature("lngr1") .set("descr", "Electric field, z component"); model.result("pg10").feature("lngr1").set("unit", "V/cm"); model.result("pg10").feature("lngr1").set("expr", "es.Ez"); model.result().export().create("plot2", "Plot"); model.result().export("plot2").name("Erlines"); model.result().export("plot2") .set("filename", outpath+"/fieldlines_"+fieldf+"_Er_lines.txt"); model.result().export("plot2").set("plotgroup", "pg8"); model.result().export().create("plot3", "Plot"); model.result().export("plot3").name("Ez_diff"); model.result().export("plot3") .set("filename", outpath+"/fieldlines_"+fieldf+"_Ezdiff_lines.txt"); model.result().export("plot3").set("plotgroup", "pg8"); model.result().export("plot3").set("plot", "lngr2"); model.result().export("plot2").run(); model.result().export("plot3").run(); model.result().export().create("img1", "Image2D"); model.result().export("img1").set("unit", "px"); model.result().export("img1").set("height", "2400"); model.result().export("img1").set("width", "1600"); model.result().export("img1").set("lockratio", "off"); model.result().export("img1").set("resolution", "600"); model.result().export("img1").set("size", "manual"); model.result().export("img1").set("antialias", "on"); model.result().export("img1").set("title", "on"); model.result().export("img1").set("legend", "on"); model.result().export("img1").set("logo", "on"); model.result().export("img1").set("options", "off"); model.result().export("img1").set("fontsize", "9"); model.result().export("img1").set("customcolor", new double[]{1, 1, 1}); model.result().export("img1").set("background", "color"); model.result().export("img1").set("qualitylevel", "92"); model.result().export("img1").set("qualityactive", "off"); model.result().export("img1").set("imagetype", "png"); model.result().export("img1").set("axes", "on"); } runfile.delete(); return model; } }