{"id":1472,"date":"2012-12-11T14:42:44","date_gmt":"2012-12-11T14:42:44","guid":{"rendered":"http:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/?page_id=1472"},"modified":"2012-12-19T01:02:07","modified_gmt":"2012-12-19T01:02:07","slug":"code-2-add-title","status":"publish","type":"page","link":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/code\/code-2-add-title\/","title":{"rendered":"MagmaticContengencies"},"content":{"rendered":"<p>1. Realflow to Rhino exporter<\/p>\n<p>#############################################################################<br \/>\nscript written by Mengna Miao, Carson Russell, Ezio Blasetti, Farzin Lotfijam<br \/>\nscript version Dec. 4, 2012<br \/>\n#############################################################################<\/p>\n<p>#paste it in realflow script deamon &amp; replace the name of the emitter<br \/>\n#export particle information every frame<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: onSimulationBegin<br \/>\n# This function is called by the simulation engine<br \/>\n# when the simulation begins.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def onSimulationBegin():<br \/>\nscene.setGlobalVariableValue(&#8220;ticker&#8221;, 0)<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: onSimulationResume<br \/>\n# This function is called by the simulation engine<br \/>\n# when the simulation resumes.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def onSimulationResume():<br \/>\npass<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: onSimulationStop<br \/>\n# This function is called by the simulation engine<br \/>\n# when the simulation stops.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def onSimulationStop():<br \/>\npass<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: onSimulationFrame<br \/>\n# This function is called by the simulation engine<br \/>\n# when the simulation starts the computation of the.<br \/>\n# next frame.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def onSimulationFrame( frame ):<\/p>\n<p>ticker = scene.getGlobalVariableValue(&#8220;ticker&#8221;)<br \/>\ntickerString = str(ticker)<\/p>\n<p>pl = open(&#8220;\/poslava&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<br \/>\nvl = open(&#8220;\/vellava&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<br \/>\ntl = open(&#8220;\/templava&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<\/p>\n<p>allParticles =lava.getParticles()<br \/>\nfor particle in allParticles :<br \/>\nVel = particle.getVelocity()<br \/>\nPos = particle.getPosition()<\/p>\n<p>xPOS = str(Pos.getX())<br \/>\nyPOS = str(Pos.getY())<br \/>\nzPOS = str(Pos.getZ())<\/p>\n<p>xVEL = str(Vel.getX())<br \/>\nyVEL = str(Vel.getY())<br \/>\nzVEL = str(Vel.getZ())<\/p>\n<p>TEMP = str(particle.getTemperature())<\/p>\n<p>pl.write(xPOS + &#8220;,&#8221; + yPOS + &#8220;,&#8221; + zPOS + &#8220;#&#8221;)<br \/>\nvl.write(xVEL + &#8220;,&#8221; + yVEL + &#8220;,&#8221; + yVEL + &#8220;#&#8221;)<br \/>\ntl.write(TEMP + &#8220;#&#8221;)<\/p>\n<p>######<br \/>\npi = open(&#8220;\/posice&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<br \/>\nvi = open(&#8220;\/velice&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<br \/>\nti = open(&#8220;\/tempice&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<\/p>\n<p>allParticles =solid.getParticles()<br \/>\nfor particle in allParticles :<br \/>\nVel = particle.getVelocity()<br \/>\nPos = particle.getPosition()<\/p>\n<p>xPOS = str(Pos.getX())<br \/>\nyPOS = str(Pos.getY())<br \/>\nzPOS = str(Pos.getZ())<\/p>\n<p>xVEL = str(Vel.getX())<br \/>\nyVEL = str(Vel.getY())<br \/>\nzVEL = str(Vel.getZ())<\/p>\n<p>TEMP = str(particle.getTemperature())<\/p>\n<p>pi.write(xPOS + &#8220;,&#8221; + yPOS + &#8220;,&#8221; + zPOS + &#8220;#&#8221;)<br \/>\nvi.write(xVEL + &#8220;,&#8221; + yVEL + &#8220;,&#8221; + yVEL + &#8220;#&#8221;)<br \/>\nti.write(TEMP + &#8220;#&#8221;)<\/p>\n<p>######<br \/>\npli = open(&#8220;\/posliq&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<br \/>\nvli = open(&#8220;\/velliq&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<br \/>\ntli = open(&#8220;\/templiq&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<\/p>\n<p>allParticles =liquid.getParticles()<br \/>\nfor particle in allParticles :<br \/>\nVel = particle.getVelocity()<br \/>\nPos = particle.getPosition()<\/p>\n<p>xPOS = str(Pos.getX())<br \/>\nyPOS = str(Pos.getY())<br \/>\nzPOS = str(Pos.getZ())<\/p>\n<p>xVEL = str(Vel.getX())<br \/>\nyVEL = str(Vel.getY())<br \/>\nzVEL = str(Vel.getZ())<\/p>\n<p>TEMP = str(particle.getTemperature())<\/p>\n<p>pli.write(xPOS + &#8220;,&#8221; + yPOS + &#8220;,&#8221; + zPOS + &#8220;#&#8221;)<br \/>\nvli.write(xVEL + &#8220;,&#8221; + yVEL + &#8220;,&#8221; + yVEL + &#8220;#&#8221;)<br \/>\ntli.write(TEMP + &#8220;#&#8221;)<\/p>\n<p>######<br \/>\npg = open(&#8220;\/posgas&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<br \/>\nvg = open(&#8220;\/velgas&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<br \/>\ntg = open(&#8220;\/tempgas&#8221; + tickerString + &#8220;.txt&#8221;, &#8216;w&#8217;)<\/p>\n<p>allParticles =gas.getParticles()<br \/>\nfor particle in allParticles :<br \/>\nVel = particle.getVelocity()<br \/>\nPos = particle.getPosition()<\/p>\n<p>xPOS = str(Pos.getX())<br \/>\nyPOS = str(Pos.getY())<br \/>\nzPOS = str(Pos.getZ())<\/p>\n<p>xVEL = str(Vel.getX())<br \/>\nyVEL = str(Vel.getY())<br \/>\nzVEL = str(Vel.getZ())<\/p>\n<p>TEMP = str(particle.getTemperature())<\/p>\n<p>pg.write(xPOS + &#8220;,&#8221; + yPOS + &#8220;,&#8221; + zPOS + &#8220;#&#8221;)<br \/>\nvg.write(xVEL + &#8220;,&#8221; + yVEL + &#8220;,&#8221; + yVEL + &#8220;#&#8221;)<br \/>\ntg.write(TEMP + &#8220;#&#8221;)<\/p>\n<p>ticker+=1<br \/>\nscene.setGlobalVariableValue(&#8220;ticker&#8221;, ticker)<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: applyForceToEmitter<br \/>\n# This function is called by the simulation engine<br \/>\n# when external forces should be applied to the<br \/>\n# particles in the emitter.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def applyForceToEmitter( emitter ):<br \/>\npass<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: applyForceToBody<br \/>\n# This function is called by the simulation engine<br \/>\n# when external forces should be applied to the body.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def applyForceToBody( body ):<br \/>\npass<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: applyForceToMultiBody<br \/>\n# This function is called by the simulation engine<br \/>\n# when external forces should be applied to the body.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def applyForceToMultiBody( multiBody ):<br \/>\npass<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: applyForceToMist<br \/>\n# This function is called by the simulation engine<br \/>\n# when external forces should be applied to the mist.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def applyForceToMist( mist ):<br \/>\npass<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: applyForceToGridFluid<br \/>\n# This function is called by the simulation engine<br \/>\n# when external forces should be applied to the grid fluid.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def applyForceToGridFluid( gridFluid ):<br \/>\npass<\/p>\n<p>#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>\n# Function: removeParticles<br \/>\n# This function is called by the simulation engine<br \/>\n# when it is safe to remove particles.<br \/>\n#&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p>def removeParticles( emitter ):<br \/>\npass<\/p>\n<p>2. Realflow to Rhino importer<\/p>\n<p>#############################################################################<br \/>\nscript written by Mengna Miao, Carson Russell, Ezio Blasetti, Farzin Lotfijam<br \/>\nscript version Dec. 4, 2012<br \/>\n#############################################################################<\/p>\n<p>#paste it in python for Rhino &amp; set your layers, ticker, scale factor(divide)<\/p>\n<p>import rhinoscriptsyntax as rs<\/p>\n<p>#import format: #x,y,z#x,y,z#x,y,z#<\/p>\n<p>ticker=&#8221;38&#8243;<\/p>\n<p>divide=20<\/p>\n<p>#replace file name<br \/>\nfP = open(&#8216;\/poslava&#8217;+ticker+&#8217;.txt&#8217;, &#8216;r&#8217;)<br \/>\nfV = open(&#8216;\/vellava&#8217;+ticker+&#8217;.txt&#8217;, &#8216;r&#8217;)<br \/>\nfT = open(&#8216;\/templava&#8217;+ticker+&#8217;.txt&#8217;, &#8216;r&#8217;)<\/p>\n<p>starts=[]<br \/>\nends=[]<br \/>\n#r=0.01<\/p>\n<p>#read file<br \/>\nfor numberP in fP:<br \/>\nseparateP=numberP.split(&#8220;#&#8221;)<\/p>\n<p>for numberV in fV:<br \/>\nseparateV=numberV.split(&#8220;#&#8221;)<\/p>\n<p>for numberT in fT:<br \/>\nseparateT=numberT.split(&#8220;#&#8221;)<\/p>\n<p>#create points and lines<br \/>\nfor i in range (len(separateP)):<br \/>\nstart=separateP[i]<br \/>\nsphere=rs.AddPoint(start)<br \/>\ntem=float(separateT[i])<br \/>\nend=rs.PointAdd(start,separateV[i])<br \/>\nvector=rs.VectorCreate(end,start)<br \/>\nvector=rs.VectorDivide(vector,divide)<br \/>\nend=rs.VectorAdd(start,vector)<br \/>\nline=rs.AddLine(start,end)<\/p>\n<p>#assign layer (create layers before running)<br \/>\nif tem&gt;1440:<br \/>\nrs.ObjectLayer(line, &#8220;1500-1440&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;1500-1440 p&#8221;)<br \/>\nelif tem1400:<br \/>\nrs.ObjectLayer(line, &#8220;1440-1400&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;1440-1400 p&#8221;)<br \/>\nelif tem1300:<br \/>\nrs.ObjectLayer(line, &#8220;1400-1300&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;1400-1300 p&#8221;)<br \/>\nelif tem1200:<br \/>\nrs.ObjectLayer(line, &#8220;1300-1200&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;1300-1200 p&#8221;)<br \/>\nelif tem1100:<br \/>\nrs.ObjectLayer(line, &#8220;1200-1100&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;1200-1100 p&#8221;)<br \/>\nelif tem1000:<br \/>\nrs.ObjectLayer(line, &#8220;1100-1000&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;1100-1000 p&#8221;)<br \/>\nelif tem900:<br \/>\nrs.ObjectLayer(line, &#8220;1000-900&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;1000-900 p&#8221;)<br \/>\nelif tem800:<br \/>\nrs.ObjectLayer(line, &#8220;900-800&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;900-800 p&#8221;)<br \/>\nelif tem700:<br \/>\nrs.ObjectLayer(line, &#8220;800-700&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;800-700 p&#8221;)<br \/>\nelif tem600:<br \/>\nrs.ObjectLayer(line, &#8220;700-600&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;700-600 p&#8221;)<br \/>\nelif tem500:<br \/>\nrs.ObjectLayer(line, &#8220;600-500&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;600-500 p&#8221;)<br \/>\nelif tem400:<br \/>\nrs.ObjectLayer(line, &#8220;500-400&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;500-400 p&#8221;)<br \/>\nelse:<br \/>\nrs.ObjectLayer(line, &#8220;400&#8221;)<br \/>\nrs.ObjectLayer(sphere, &#8220;400 p&#8221;)<\/p>\n<p>3. Water Spray in Rhino<\/p>\n<p>#############################################################################<br \/>\nscript written by Ezio Blasetti<br \/>\nscript version Dec. 4, 2012<br \/>\n#############################################################################<\/p>\n<p>import rhinoscriptsyntax as rs<\/p>\n<p>def MeshVtxCloseEnoughVtxs(mesh, index, threshold):<br \/>\nreturnlist = []<br \/>\nvtxs = rs.MeshVertices(mesh)<br \/>\nfor i in range(len(vtxs)):<br \/>\nif i!=index:<br \/>\ndist = rs.Distance(vtxs[index],vtxs[i])<br \/>\nif dist &lt;threshold:<br \/>\nreturnlist.append(i)<br \/>\nreturn returnlist<\/p>\n<p>def Main():<br \/>\nstrMesh = rs.GetObject(&#8220;select the mesh to navigate&#8221;,32)<br \/>\nvtxRadious = rs.GetReal(&#8220;please type the radious for the vtx neighborhood&#8221;, 1)<br \/>\narrStrAttr = rs.GetObjects(&#8220;select the attractors&#8221;,1)<br \/>\nattrRadious = rs.GetReal(&#8220;please type the radious for the attractor&#8221;, 9.7)<\/p>\n<p>arrAttr = []<br \/>\nfor i in range(len(arrStrAttr)):<br \/>\narrAttr.append( rs.PointCoordinates(arrStrAttr[i]) )<\/p>\n<p>arrPoints = rs.MeshVertices (strMesh)<\/p>\n<p>for i in range(len(arrPoints)):<br \/>\narrPt0 = arrPoints[i]<br \/>\nindexAttr = rs.PointArrayClosestPoint(arrAttr,arrPt0)<br \/>\narrClosestAttr = arrAttr[indexAttr]<br \/>\ndistfromVtx2ClosestAttr = rs.Distance(arrPt0, arrClosestAttr)<br \/>\nif distfromVtx2ClosestAttr&lt; attrRadious:<br \/>\n#arrneighborsIndex = MeshVtxAdjacentVtxs (strMesh, i)<br \/>\narrneighborsIndex = MeshVtxCloseEnoughVtxs(strMesh, i, vtxRadious)<br \/>\narrNeighbors = []<br \/>\nfor j in range( len(arrneighborsIndex)):<br \/>\narrNeighbors.append( arrPoints[arrneighborsIndex[j]] )<br \/>\nif len(arrNeighbors)&gt;-1 :<br \/>\nindex = rs.PointArrayClosestPoint(arrNeighbors,arrClosestAttr)<br \/>\narrPt1 = arrNeighbors[index]<br \/>\nrs.AddLine(arrPt0,arrPt1)<br \/>\nMain()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Realflow to Rhino exporter ############################################################################# script written by Mengna Miao, Carson Russell, Ezio Blasetti, Farzin Lotfijam script version Dec. 4, 2012 ############################################################################# #paste it in realflow script deamon &amp; replace the name of the emitter #export particle information every frame #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; # Function: onSimulationBegin # This function is called by the simulation engine # [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":9,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-1472","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages\/1472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/comments?post=1472"}],"version-history":[{"count":8,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages\/1472\/revisions"}],"predecessor-version":[{"id":1693,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages\/1472\/revisions\/1693"}],"up":[{"embeddable":true,"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/pages\/9"}],"wp:attachment":[{"href":"https:\/\/www.new-territories.com\/blog\/ncertainties\/col12\/wp-json\/wp\/v2\/media?parent=1472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}