diff --git a/3rdParty/WebDemo/LBMDemoCopy.htm b/3rdParty/WebDemo/LBMDemoCopy.htm deleted file mode 100644 index c0a2834eaf2ad463f301bd3593972337219fb813..0000000000000000000000000000000000000000 --- a/3rdParty/WebDemo/LBMDemoCopy.htm +++ /dev/null @@ -1,1364 +0,0 @@ - -<!DOCTYPE HTML> -<!-- - A lattice-Boltzmann fluid simulation in JavaScript, using HTML5 canvas for graphics - - Copyright 2013, Daniel V. Schroeder - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated data and documentation (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is furnished to do - so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - OTHER DEALINGS IN THE SOFTWARE. - - Except as contained in this notice, the name of the author shall not be used in - advertising or otherwise to promote the sale, use or other dealings in this - Software without prior written authorization. - - Credits: - The "wind tunnel" entry/exit conditions are inspired by Graham Pullan's code - (http://www.many-core.group.cam.ac.uk/projects/LBdemo.shtml). Additional inspiration from - Thomas Pohl's applet (http://thomas-pohl.info/work/lba.html). Other portions of code are based - on Wagner (http://www.ndsu.edu/physics/people/faculty/wagner/lattice_boltzmann_codes/) and - Gonsalves (http://www.physics.buffalo.edu/phy411-506-2004/index.html; code adapted from Succi, - http://global.oup.com/academic/product/the-lattice-boltzmann-equation-9780199679249). - - Revision history: - First version, with only start/stop, speed, and viscosity controls, February 2013 - Added resolution control, mouse interaction, plot options, etc., March 2013 - Added sensor, contrast slider, improved tracer placement, Fy period readout, May 2013 - Added option to animate using setTimeout instead of requestAnimationFrame, July 2013 - Added "Flowline" plotting (actually just line segments), August 2013 - - Still to do: - * Fix the apparent bug in the force calculation that gives inconsistent results depending - on initial conditions. Perhaps bounce-backs between adjacent barrier sites don't cancel? - * Grabbing the sensor while "drag fluid" selected causes a momentary drag at previous mouse location. - * Try to pass two-fingered touch events on to the browser, so it's still possible to zoom in and out. - * Work on GUI control layout, especially for smaller screens. - * Treat ends symmetrically when flow speed is zero. - * Try some other visualization techniques. ---> -<html> - -<head> -<title>Fluid Dynamics Simulation</title> -<meta charset="utf-8"> -<meta name="viewport" content="width=620"> -<style> - body {background-color:#ffffff; font-family:Arial, sans-serif; font-size:14px; - text-align:center;} /* gray background, center everything */ - p {margin-left:auto; margin-right:auto; width:600px;} /* keep paragraphs narrow and centered */ - input {font-size:115%;} /* make buttons bigger */ - input[type="range"] {width:90px;} /* make sliders shorter */ - select {font-size:115%;} /* make selectors bigger too */ - li {text-align:left;} -</style> -</head> - -<body> - -<h2>Fluid Dynamics Simulation</h2> - -<p>By <a href="http://physics.weber.edu/schroeder/">Dan Schroeder</a>, -<a href="http://physics.weber.edu">Physics Department</a>, -<a href="http://weber.edu">Weber State University</a></p> - -<canvas id="theCanvas" width="600" height="240">This application runs only in modern -browsers. For best results, use Google Chrome.</canvas> - -<div> - <select id="sizeSelect" onchange="resize()"> - <option value="10">60 x 24</option> - <option value="8">75 x 30</option> - <option value="6">100 x 40</option> - <option value="5">120 x 48</option> - <option value="4">150 x 60</option> - <option value="3">200 x 80</option> - <option value="2">300 x 120</option> - <option value="1">600 x 240</option> - </select> - <input id="resetFluidButton" type="button" onclick="initFluid()" value="Reset fluid"> - <input id="stepButton" type="button" onclick="simulate()" value="Step"> - <input id="startButton" type="button" onclick="startStop()" value="Start"> -</div> -<div> - Flow speed = <span id="speedValue">0.100</span> - <input id="speedSlider" type="range" min="0" max="0.12" step="0.005" value="0.1" onchange="adjustSpeed()"> - Viscosity = <span id="viscValue">0.020</span> - <input id="viscSlider" type="range" min="0.000000001" max="0.02" step="0.000005" value="0.02" onchange="adjustViscosity()"> -</div> -<div style="margin-top:3px"> - <select id="mouseSelect"> - <option value="draw">Draw barriers</option> - <option value="erase">Erase barriers</option> - <option value="push">Drag fluid</option> - </select> - <select id="barrierSelect" onchange="placePresetBarrier()"> - <option>Barrier shapes</option> - </select> - <input id="clearButton" type="button" onclick="clearBarriers()" value="Clear barriers"> -</div> -<div> - <select id="plotSelect" onchange="paintCanvas()"> - <option>Plot density</option> - <option>Plot x velocity</option> - <option>Plot y velocity</option> - <option>Plot speed</option> - <option selected>Plot curl</option> - </select> - Contrast: - <input id="contrastSlider" type="range" min="-10" max="10" step="1" value="0" onchange="paintCanvas()"> -</div> -<div> - Animation speed: - <input id="stepsSlider" type="range" min="1" max="40" step="1" value="20" onchange="resetTimer()"> - Steps per second: <span id="speedReadout">0</span> - <input id="rafCheck" type="checkbox" checked onchange="resetTimer()">Faster? -</div> -<div style="margin-top:4px"> - <!--<input id="pixelCheck" type="checkbox" checked onchange="resetTimer()">Use pixel graphics--> - Show: - <input id="tracerCheck" type="checkbox" onchange="initTracers()">Tracers - <input id="flowlineCheck" type="checkbox" onchange="paintCanvas()">Flowlines - <input id="forceCheck" type="checkbox" onchange="paintCanvas()">Force on barriers - <input id="sensorCheck" type="checkbox" onchange="paintCanvas()">Sensor - <input id="dataCheck" type="checkbox" onchange="showData()">Data -</div> -<div id="dataSection" style="display:none"> - <textarea id="dataArea" rows="8" cols="50" disabled readonly></textarea> - <div> - <input id="dataButton" type="button" value="Start data collection" onclick="startOrStopData()"> - <input id="periodButton" type="button" value="Show F_y period" onclick="showPeriod()"> - <input id="barrierDataButton" type="button" value="Show barrier locations" onclick="showBarrierLocations()"> - <input id="debugButton" type="button" value="Debug" onclick="debug()" style="display:none"> - </div> -</div> -<p style="text-align:left">This is a simulation of a two-dimensional fluid. Initially the fluid -is flowing from left to right, and a linear barrier (shown in black) diverts the fluid and creates -vortices. The colors indicate the curl, or local rotational motion, of the fluid. -Use the controls to adjust the flow speed and viscosity, draw different barriers, drag the -fluid around, plot other quantities besides the curl, show the force exerted by the fluid -on the barriers, and measure the fluid's density and velocity at any point. Enjoy!</p> - -<p style="text-align:left">The simulation uses a fairly simple -<a href="http://en.wikipedia.org/wiki/Lattice_Boltzmann_methods">lattice-Boltzmann algorithm</a>, -which you can see by viewing the JavaScript source code. As of mid-2013, the simulation -runs fastest under Chrome on either MacOS or Windows. Firefox is somewhat slower and Safari slower still, -while Opera and Internet Explorer are much slower. You can adjust the resolution to increase or -decrease the simulation speed.</p> - -<p style="text-align:left">If you don't see the slider controls above, try updating your browser. -As of August 2013, the most recent versions of all major browsers should show the sliders.</p> - -<p style="text-align:left">This HTML5-canvas-JavaScript web app is a work in progress. It still -has a few bugs and awkward features, which I hope to address some day.</p> - -<p style="text-align:left"> - Related materials: -</p> -<div style="margin-left:auto; margin-right:auto; width:600px;"> - <ul> - <li><a href="LatticeBoltzmannDemo.java.txt">A similar simulation in Java</a></li> - <li><a href="LatticeBoltzmannDemo.py.txt">A similar simulation in Python</a></li> - <li><a href="FluidSimulationsForUndergrads.pdf">Poster presentation</a> - given at the AAPT summer meeting, 2013 (pdf, 2.6 MB)</li> - <li><a href="http://physics.weber.edu/schroeder/javacourse/LatticeBoltzmann.pdf">Instructions</a> - for a lattice-Boltzmann project in a computational physics course</li> - <li>A more detailed explanation of the lattice-Boltzmann algorithm (coming soon)</li> - </ul> -</div> - -<script src="barrierdata.js"></script> -<script> - // Global variables: - var mobile = navigator.userAgent.match(/iPhone|iPad|iPod|Android|BlackBerry|Opera Mini|IEMobile/i) - var canvas = document.getElementById('theCanvas'); - var context = canvas.getContext('2d'); - var image = context.createImageData(canvas.width, canvas.height); // for direct pixel manipulation (faster than fillRect) - for (var i=3; i<image.data.length; i+=4) image.data[i] = 255; // set all alpha values to opaque - var sizeSelect = document.getElementById('sizeSelect'); - sizeSelect.selectedIndex = 5; - if (mobile) sizeSelect.selectedIndex = 1; // smaller works better on mobile platforms - var pxPerSquare = Number(sizeSelect.options[sizeSelect.selectedIndex].value); - // width of plotted grid site in pixels - var xdim = canvas.width / pxPerSquare; // grid dimensions for simulation - var ydim = canvas.height / pxPerSquare; - var stepsSlider = document.getElementById('stepsSlider'); - var startButton = document.getElementById('startButton'); - var speedSlider = document.getElementById('speedSlider'); - var speedValue = document.getElementById('speedValue'); - var viscSlider = document.getElementById('viscSlider'); - var viscValue = document.getElementById('viscValue'); - var mouseSelect = document.getElementById('mouseSelect'); - var barrierSelect = document.getElementById('barrierSelect'); - for (var barrierIndex=0; barrierIndex<barrierList.length; barrierIndex++) { - var shape = document.createElement("option"); - shape.text = barrierList[barrierIndex].name; - barrierSelect.add(shape, null); - } - var plotSelect = document.getElementById('plotSelect'); - var contrastSlider = document.getElementById('contrastSlider'); - //var pixelCheck = document.getElementById('pixelCheck'); - var tracerCheck = document.getElementById('tracerCheck'); - var flowlineCheck = document.getElementById('flowlineCheck'); - var forceCheck = document.getElementById('forceCheck'); - var sensorCheck = document.getElementById('sensorCheck'); - var dataCheck = document.getElementById('dataCheck'); - var rafCheck = document.getElementById('rafCheck'); - var speedReadout = document.getElementById('speedReadout'); - var dataSection = document.getElementById('dataSection'); - var dataArea = document.getElementById('dataArea'); - var dataButton = document.getElementById('dataButton'); - var running = false; // will be true when running - var stepCount = 0; - var startTime = 0; - var four9ths = 4.0 / 9.0; // abbreviations - var one9th = 1.0 / 9.0; - var one36th = 1.0 / 36.0; - var barrierCount = 0; - var barrierxSum = 0; - var barrierySum = 0; - var barrierFx = 0.0; // total force on all barrier sites - var barrierFy = 0.0; - var sensorX = xdim / 2; // coordinates of "sensor" to measure local fluid properties - var sensorY = ydim / 2; - var draggingSensor = false; - var mouseIsDown = false; - var mouseX, mouseY; // mouse location in canvas coordinates - var oldMouseX = -1, oldMouseY = -1; // mouse coordinates from previous simulation frame - var collectingData = false; - var time = 0; // time (in simulation step units) since data collection started - var showingPeriod = false; - var lastBarrierFy = 1; // for determining when F_y oscillation begins - var lastFyOscTime = 0; // for calculating F_y oscillation period - - canvas.addEventListener('mousedown', mouseDown, false); - canvas.addEventListener('mousemove', mouseMove, false); - document.body.addEventListener('mouseup', mouseUp, false); // button release could occur outside canvas - canvas.addEventListener('touchstart', mouseDown, false); - canvas.addEventListener('touchmove', mouseMove, false); - document.body.addEventListener('touchend', mouseUp, false); - - // Create the arrays of fluid particle densities, etc. (using 1D arrays for speed): - // To index into these arrays, use x + y*xdim, traversing rows first and then columns. - var n0 = new Array(xdim*ydim); // microscopic densities along each lattice direction - var nN = new Array(xdim*ydim); - var nS = new Array(xdim*ydim); - var nE = new Array(xdim*ydim); - var nW = new Array(xdim*ydim); - var nNE = new Array(xdim*ydim); - var nSE = new Array(xdim*ydim); - var nNW = new Array(xdim*ydim); - var nSW = new Array(xdim*ydim); - var rho = new Array(xdim*ydim); // macroscopic density - var ux = new Array(xdim*ydim); // macroscopic velocity - var uy = new Array(xdim*ydim); - var curl = new Array(xdim*ydim); - var barrier = new Array(xdim * ydim); // boolean array of barrier locations - var odd = 1; - - // Initialize to a steady rightward flow with no barriers: - for (var y=0; y<ydim; y++) { - for (var x=0; x<xdim; x++) { - barrier[x+y*xdim] = false; - } - } - - // Create a simple linear "wall" barrier (intentionally a little offset from center): - var barrierSize = 8; - if (mobile) barrierSize = 4; - for (var y=(ydim/2)-barrierSize; y<=(ydim/2)+barrierSize; y++) { - var x = Math.round(ydim/3); - barrier[x+y*xdim] = true; - } - - // Set up the array of colors for plotting (mimicks matplotlib "jet" colormap): - // (Kludge: Index nColors+1 labels the color used for drawing barriers.) - var nColors = 400; // there are actually nColors+2 colors - var hexColorList = new Array(nColors+2); - var redList = new Array(nColors+2); - var greenList = new Array(nColors+2); - var blueList = new Array(nColors+2); - for (var c=0; c<=nColors; c++) { - var r, g, b; - if (c < nColors/8) { - r = 0; g = 0; b = Math.round(255 * (c + nColors/8) / (nColors/4)); - } else if (c < 3*nColors/8) { - r = 0; g = Math.round(255 * (c - nColors/8) / (nColors/4)); b = 255; - } else if (c < 5*nColors/8) { - r = Math.round(255 * (c - 3*nColors/8) / (nColors/4)); g = 255; b = 255 - r; - } else if (c < 7*nColors/8) { - r = 255; g = Math.round(255 * (7*nColors/8 - c) / (nColors/4)); b = 0; - } else { - r = Math.round(255 * (9*nColors/8 - c) / (nColors/4)); g = 0; b = 0; - } - redList[c] = r; greenList[c] = g; blueList[c] = b; - hexColorList[c] = rgbToHex(r, g, b); - } - redList[nColors+1] = 0; greenList[nColors+1] = 0; blueList[nColors+1] = 0; // barriers are black - hexColorList[nColors+1] = rgbToHex(0, 0, 0); - - // Functions to convert rgb to hex color string (from stackoverflow): - function componentToHex(c) { - var hex = c.toString(16); - return hex.length == 1 ? "0" + hex : hex; - } - function rgbToHex(r, g, b) { - return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b); - } - - // Initialize array of partially transparant blacks, for drawing flow lines: - var transBlackArraySize = 50; - var transBlackArray = new Array(transBlackArraySize); - for (var i=0; i<transBlackArraySize; i++) { - transBlackArray[i] = "rgba(0,0,0," + Number(i/transBlackArraySize).toFixed(2) + ")"; - } - - // Initialize tracers (but don't place them yet): - var nTracers = 144; - var tracerX = new Array(nTracers); - var tracerY = new Array(nTracers); - for (var t=0; t<nTracers; t++) { - tracerX[t] = 0.0; tracerY[t] = 0.0; - } - - initFluid(); // initialize to steady rightward flow - - // Mysterious gymnastics that are apparently useful for better cross-browser animation timing: - window.requestAnimFrame = (function(callback) { - return window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || - function(callback) { - window.setTimeout(callback, 1); // second parameter is time in ms - }; - })(); - - // Simulate function executes a bunch of steps and then schedules another call to itself: - function simulate() { - var stepsPerFrame = Number(stepsSlider.value); // number of simulation steps per animation frame - setBoundaries(); - // Test to see if we're dragging the fluid: - var pushing = false; - var pushX, pushY, pushUX, pushUY; - if (mouseIsDown && mouseSelect.selectedIndex==2) { - if (oldMouseX >= 0) { - var gridLoc = canvasToGrid(mouseX, mouseY); - pushX = gridLoc.x; - pushY = gridLoc.y; - pushUX = (mouseX - oldMouseX) / pxPerSquare / stepsPerFrame; - pushUY = -(mouseY - oldMouseY) / pxPerSquare / stepsPerFrame; // y axis is flipped - if (Math.abs(pushUX) > 0.1) pushUX = 0.1 * Math.abs(pushUX) / pushUX; - if (Math.abs(pushUY) > 0.1) pushUY = 0.1 * Math.abs(pushUY) / pushUY; - pushing = true; - } - oldMouseX = mouseX; oldMouseY = mouseY; - } else { - oldMouseX = -1; oldMouseY = -1; - } - // Execute a bunch of time steps: - for (var step = 0; step < stepsPerFrame; step++) { - setBoundaries(); - collide(); - //stream(); - if (odd == 1) { odd = 0; } - else { odd = 1; } - if (tracerCheck.checked) moveTracers(); - if (pushing) push(pushX, pushY, pushUX, pushUY); - time++; - if (showingPeriod && (barrierFy > 0) && (lastBarrierFy <=0)) { - var thisFyOscTime = time - barrierFy/(barrierFy-lastBarrierFy); // interpolate when Fy changed sign - if (lastFyOscTime > 0) { - var period = thisFyOscTime - lastFyOscTime; - dataArea.innerHTML += Number(period).toFixed(2) + "\n"; - dataArea.scrollTop = dataArea.scrollHeight; - } - lastFyOscTime = thisFyOscTime; - } - lastBarrierFy = barrierFy; - } - paintCanvas(); - if (collectingData) { - writeData(); - if (time >= 10000) startOrStopData(); - } - if (running) { - stepCount += stepsPerFrame; - var elapsedTime = ((new Date()).getTime() - startTime) / 1000; // time in seconds - speedReadout.innerHTML = Number(stepCount/elapsedTime).toFixed(0); - } - var stable = true; - for (var x=0; x<xdim; x++) { - var index = x + (ydim/2)*xdim; // look at middle row only - if (rho[index] <= 0) stable = false; - } - if (!stable) { - window.alert("The simulation has become unstable due to excessive fluid speeds."); - startStop(); - initFluid(); - } - if (running) { - if (rafCheck.checked) { - requestAnimFrame(function() { simulate(); }); // let browser schedule next frame - } else { - window.setTimeout(simulate, 1); // schedule next frame asap (nominally 1 ms but always more) - } - } - } - - // Set the fluid variables at the boundaries, according to the current slider value: - function setBoundaries() { - var u0 = Number(speedSlider.value); - for (var x=0; x<xdim; x++) { - setEquil(x, 0, u0, 0, 1); - setEquil(x, ydim-1, u0, 0, 1); - } - for (var y=1; y<ydim-1; y++) { - setEquil(0, y, u0, 0, 1); - setEquil(xdim-1, y, u0, 0, 1); - } - } - - // Collide particles within each cell (here's the physics!): - function collideOLD() { - var viscosity = Number(viscSlider.value); // kinematic viscosity coefficient in natural units - var omega = 1 / (3*viscosity + 0.5); // reciprocal of relaxation time - for (var y=1; y<ydim-1; y++) { - for (var x=1; x<xdim-1; x++) { - var i = x + y*xdim; // array index for this lattice site - var thisrho = n0[i] + nN[i] + nS[i] + nE[i] + nW[i] + nNW[i] + nNE[i] + nSW[i] + nSE[i]; - rho[i] = thisrho; - var thisux = (nE[i] + nNE[i] + nSE[i] - nW[i] - nNW[i] - nSW[i]) / thisrho; - ux[i] = thisux; - var thisuy = (nN[i] + nNE[i] + nNW[i] - nS[i] - nSE[i] - nSW[i]) / thisrho; - uy[i] = thisuy - var one9thrho = one9th * thisrho; // pre-compute a bunch of stuff for optimization - var one36thrho = one36th * thisrho; - var ux3 = 3 * thisux; - var uy3 = 3 * thisuy; - var ux2 = thisux * thisux; - var uy2 = thisuy * thisuy; - var uxuy2 = 2 * thisux * thisuy; - var u2 = ux2 + uy2; - var u215 = 1.5 * u2; - n0[i] += omega * (four9ths*thisrho * (1 - u215) - n0[i]); - nE[i] += omega * ( one9thrho * (1 + ux3 + 4.5*ux2 - u215) - nE[i]); - nW[i] += omega * ( one9thrho * (1 - ux3 + 4.5*ux2 - u215) - nW[i]); - nN[i] += omega * ( one9thrho * (1 + uy3 + 4.5*uy2 - u215) - nN[i]); - nS[i] += omega * ( one9thrho * (1 - uy3 + 4.5*uy2 - u215) - nS[i]); - nNE[i] += omega * ( one36thrho * (1 + ux3 + uy3 + 4.5*(u2+uxuy2) - u215) - nNE[i]); - nSE[i] += omega * ( one36thrho * (1 + ux3 - uy3 + 4.5*(u2-uxuy2) - u215) - nSE[i]); - nNW[i] += omega * ( one36thrho * (1 - ux3 + uy3 + 4.5*(u2-uxuy2) - u215) - nNW[i]); - nSW[i] += omega * ( one36thrho * (1 - ux3 - uy3 + 4.5*(u2+uxuy2) - u215) - nSW[i]); - } - } - for (var y=1; y<ydim-2; y++) { - nW[xdim-1+y*xdim] = nW[xdim-2+y*xdim]; // at right end, copy left-flowing densities from next row to the left - nNW[xdim-1+y*xdim] = nNW[xdim-2+y*xdim]; - nSW[xdim-1+y*xdim] = nSW[xdim-2+y*xdim]; - } - } - - ///----------------------------Cumulants - function collide() { - var viscosity = Number(viscSlider.value); // kinematic viscosity coefficient in natural units - var omega = 1 / (3 * viscosity + 0.5); // reciprocal of relaxation time - //var om3 = 9.0 * (8.0 - 6.0 * omega + omega * omega) / (36.0 - 18 * omega + 2 * omega * omega); // - var om3 = 3.0 * (omega - 2.0) / (omega - 3.0); - for (var y = 1; y < ydim - 1; y++) { - for (var x = 1; x < xdim - 1; x++) { - if (x > xdim - 5) { omega = 1; } - //if (true) - // {//(!barrier[x+y*xdim]){ - else { omega = 1 / (3 * viscosity + 0.5); } - if (!barrier[x+y*xdim]){ - var i = x + y * xdim; // array index for this lattice site - var ix=(x+1)+ y*xdim; - var iy=x+(y+1)*xdim; - var ixy=(x+1)+(y+1)*xdim; -var maa; -var mab; -var mac; -var mba; -var mbb; -var mbc; -var mca; -var mcb; -var mcc; - - if(odd==1){ - maa = nSW[ixy]; - mab = nW[ix]; - mac = nNW[ix]; - mba = nS[iy]; - mbb = n0[i]; - mbc = nN[i]; - mca = nSE[iy]; - mcb = nE[i]; - mcc = nNE[i]; - } - else - { - maa = nNE[ixy]; - mab = nE[ix]; - mac = nSE[ix]; - mba = nN[iy]; - mbb = n0[i]; - mbc = nS[i]; - mca = nNW[iy]; - mcb = nW[i]; - mcc = nSW[i]; - } - - var thisrho = maa + mab + mac + mba + mbb + mbc + mca + mcb + mcc; - rho[i] = thisrho; - var thisux = (mca+mcb+mcc-maa-mab-mac) / thisrho; - ux[i] = thisux; - var thisuy = (mac+mbc+mcc-maa-mba-mca) / thisrho; - uy[i] = thisuy; - - - - var n1=maa+mab+mac; - var n2=(-1-thisuy)*maa-thisuy*mab+(1-thisuy)*mac; - mac=(-1-thisuy)*(-1-thisuy)*maa+thisuy*thisuy*mab+(1-thisuy)*(1-thisuy)*mac; - maa=n1; - mab=n2; - - - n1=mba+mbb+mbc; - n2=(-1-thisuy)*mba-thisuy*mbb+(1-thisuy)*mbc; - mbc=(-1-thisuy)*(-1-thisuy)*mba+thisuy*thisuy*mbb+(1-thisuy)*(1-thisuy)*mbc; - mba=n1; - mbb=n2; - - - n1=mca+mcb+mcc; - n2=(-1-thisuy)*mca-thisuy*mcb+(1-thisuy)*mcc; - mcc=(-1-thisuy)*(-1-thisuy)*mca+thisuy*thisuy*mcb+(1-thisuy)*(1-thisuy)*mcc; - mca=n1; - mcb=n2; -///// y - n1=maa+mba+mca; - n2=(-1-thisux)*maa-thisux*mba+(1-thisux)*mca; - mca=(-1-thisux)*(-1-thisux)*maa+thisux*thisux*mba+(1-thisux)*(1-thisux)*mca; - maa=n1; - mba=n2; - - n1=mab+mbb+mcb; - n2=(-1-thisux)*mab-thisux*mbb+(1-thisux)*mcb; - mcb=(-1-thisux)*(-1-thisux)*mab+thisux*thisux*mbb+(1-thisux)*(1-thisux)*mcb; - mab=n1; - mbb=n2; - - n1=mac+mbc+mcc; - n2=(-1-thisux)*mac-thisux*mbc+(1-thisux)*mcc; - mcc=(-1-thisux)*(-1-thisux)*mac+thisux*thisux*mbc+(1-thisux)*(1-thisux)*mcc; - mac=n1; - mbc=n2; - // - - //----fast transform - -// var n1 = mcc + maa - mac - mca - thisux * thisuy / thisrho; -// var n2; -// //var pp = 2 * (mca + mac + maa + mcc) + mba + mbc + mab + mcb - (thisux * thisux + thisuy * thisuy) / thisrho; -// var pxx = -mba - mbc + mab + mcb - (thisux * thisux - thisuy * thisuy) / thisrho; -// maa = thisrho; -// mba = 0; -// mab = 0; -// mbb = n1; - - //-----!FastTransform - - //now the collision: - - var pp=mac+mca; - var pxx = mca - mac; - var CUMcc = mcc - (mca * mac + 2 * mbb * mbb) / thisrho; - - //---- - var dxUx = (-0.5 * omega * (2 * mca - mac) - 0.5 * (mca + mac - maa)) / thisrho; - var dyUy = (-0.5 * omega * (2 * mac - mca) - 0.5 * (mca + mac - maa)) / thisrho; - //---- - - // pp = thisrho/3.0*(dxUx*dxUx+dyUy*dyUy)+ 2.0 / 3.0 * thisrho; - // CUMcc = 0.0; - // pxx =thisrho/3.0*(dxUx*dxUx-dyUy*dyUy)*omega-3*thisrho*(1.0-omega*0.5)*(thisux*thisux*dxUx-thisuy*thisuy*dyUy)+ pxx * (1.0 - omega); - var om2=omega;//1.99; -var quadLim = 0.01; //0.001/(0.01+uu+1.0e-9); -var limit1 = om2 + (1.0 - om2) * Math.abs(pp) / (Math.abs(pp) + 0.5); //4 Konstantin - pp=2.0/3.0*thisrho*limit1+(1.0-limit1)*pp; - //pp = 2.0 / 3.0 * thisrho; - pxx = -3*thisrho*(1.0-omega*0.5)*(thisux*thisux*dxUx-thisuy*thisuy*dyUy)+ pxx * (1.0 - omega); - mbb = mbb * (1.0 - omega); - mca = 0.5 * (pp + pxx); - mac = 0.5 * (pp - pxx); - //-----without limiter - // mcb = 0.0; //mcb * (1.0 - om3); - - // mbc = 0.0; //mbc * (1.0 - om3); - //---with limiter - var uu = Math.sqrt(thisux * thisux + thisuy * thisuy); - - var limIT = om3 + (1.0 - om3) * Math.abs(mcb) / (Math.abs(mcb) + quadLim); - mcb = mcb * (1.0 - limIT); - limIT = om3 + (1.0 - om3) * Math.abs(mbc) / (Math.abs(mbc) + quadLim); - mbc = mbc * (1.0 - limIT); - //---!limiter - - mcc = /*CUMcc+ */ (mca * mac + 2 * mbb * mbb) / thisrho; - - - ////x-Richtung - - n1 = (mcc + mac * (-1 + thisux) * thisux + mbc * (-1 + 2 * thisux)) * 0.5; - n2 = mac - mcc - 2 * mbc * thisux - mac * thisux * thisux; - mcc = (mbc + mcc + 2 * mbc * thisux + mac * thisux * (1 + thisux)) * 0.5; - mac = n1; - mbc = n2; - - n1 = (mcb + mab * (-1 + thisux) * thisux + mbb * (-1 + 2 * thisux)) * 0.5; - n2 = mab - mcb - 2 * mbb * thisux - mab * thisux * thisux; - mcb = (mbb + mcb + 2 * mbb * thisux + mab * thisux * (1 + thisux)) * 0.5; - mab = n1; - mbb = n2; - - n1 = (mca + maa * (-1 + thisux) * thisux + mba * (-1 + 2 * thisux)) * 0.5; - n2 = maa - mca - 2 * mba * thisux - maa * thisux * thisux; - mca = (mba + mca + 2 * mba * thisux + maa * thisux * (1 + thisux)) * 0.5; - maa = n1; - mba = n2; - - ////y-Richtung - n1 = (mcc + mca * (-1 + thisuy) * thisuy + mcb * (-1 + 2 * thisuy)) * 0.5; - n2 = mca - mcc - 2 * mcb * thisuy - mca * thisuy * thisuy; - mcc = (mcb + mcc + 2 * mcb * thisuy + mca * thisuy * (1 + thisuy)) * 0.5; - mca = n1; - mcb = n2; - - n1 = (mbc + mba * (-1 + thisuy) * thisuy + mbb * (-1 + 2 * thisuy)) * 0.5; - n2 = mba - mbc - 2 * mbb * thisuy - mba * thisuy * thisuy; - mbc = (mbb + mbc + 2 * mbb * thisuy + mba * thisuy * (1 + thisuy)) * 0.5; - mba = n1; - mbb = n2; - - n1 = (mac + maa * (-1 + thisuy) * thisuy + mab * (-1 + 2 * thisuy)) * 0.5; - n2 = maa - mac - 2 * mab * thisuy - maa * thisuy * thisuy; - mac = (mab + mac + 2 * mab * thisuy + maa * thisuy * (1 + thisuy)) * 0.5; - maa = n1; - mab = n2; - - - if (odd==1){ - n0[i] =mbb; - nW[ix] =mcb; - nE[i] =mab; - nS[iy] =mbc; - nN[i] =mba; - nSW[ixy]=mcc; - nNW[ix]=mca; - nSE[iy]=mac; - nNE[i] = maa; - - } - else{ - n0[i] =mbb; - nE[ix] =mcb; - nW[i] =mab; - nN[iy] =mbc; - nS[i] =mba; - nNE[ixy]=mcc; - nSE[ix]=mca; - nNW[iy]=mac; - nSW[i] = maa; - - } - } - } - } - // if (odd == 0) { - // for (var y = 1; y < ydim - 2; y++) { - // nE[xdim - 1 + y * xdim] = nE[xdim - 2 + y * xdim]; // at right end, copy left-flowing densities from next row to the left - // nNE[xdim - 1 + y * xdim] = nNE[xdim - 2 + y * xdim]; - // nSE[xdim - 1 + y * xdim] = nSE[xdim - 2 + y * xdim]; - - // nW[1+y * xdim] += 0.0001 * 3; - // nWE[1+y * xdim] += 0.0001; - // nWS[1+y * xdim] += 0.0001; - // } - //} - //else { - // for (var y = 1; y < ydim - 2; y++) { - // nW[xdim - 1 + y * xdim] = nW[xdim - 2 + y * xdim]; // at right end, copy left-flowing densities from next row to the left - // nNW[xdim - 1 + y * xdim] = nNW[xdim - 2 + y * xdim]; - // nSW[xdim - 1 + y * xdim] = nSW[xdim - 2 + y * xdim]; - //} - //} - - } - -////------------------------------!Cumulants - - - - // Move particles along their directions of motion: - function stream() { - barrierCount = 0; barrierxSum = 0; barrierySum = 0; - barrierFx = 0.0; barrierFy = 0.0; - for (var y=ydim-2; y>0; y--) { // first start in NW corner... - for (var x=1; x<xdim-1; x++) { - nN[x+y*xdim] = nN[x+(y-1)*xdim]; // move the north-moving particles - nNW[x+y*xdim] = nNW[x+1+(y-1)*xdim]; // and the northwest-moving particles - } - } - for (var y=ydim-2; y>0; y--) { // now start in NE corner... - for (var x=xdim-2; x>0; x--) { - nE[x+y*xdim] = nE[x-1+y*xdim]; // move the east-moving particles - nNE[x+y*xdim] = nNE[x-1+(y-1)*xdim]; // and the northeast-moving particles - } - } - for (var y=1; y<ydim-1; y++) { // now start in SE corner... - for (var x=xdim-2; x>0; x--) { - nS[x+y*xdim] = nS[x+(y+1)*xdim]; // move the south-moving particles - nSE[x+y*xdim] = nSE[x-1+(y+1)*xdim]; // and the southeast-moving particles - } - } - for (var y=1; y<ydim-1; y++) { // now start in the SW corner... - for (var x=1; x<xdim-1; x++) { - nW[x+y*xdim] = nW[x+1+y*xdim]; // move the west-moving particles - nSW[x+y*xdim] = nSW[x+1+(y+1)*xdim]; // and the southwest-moving particles - } - } - for (var y=1; y<ydim-1; y++) { // Now handle bounce-back from barriers - for (var x=1; x<xdim-1; x++) { - if (barrier[x+y*xdim]) { - var index = x + y*xdim; - nE[x+1+y*xdim] = nW[index]; - nW[x-1+y*xdim] = nE[index]; - nN[x+(y+1)*xdim] = nS[index]; - nS[x+(y-1)*xdim] = nN[index]; - nNE[x+1+(y+1)*xdim] = nSW[index]; - nNW[x-1+(y+1)*xdim] = nSE[index]; - nSE[x+1+(y-1)*xdim] = nNW[index]; - nSW[x-1+(y-1)*xdim] = nNE[index]; - // Keep track of stuff needed to plot force vector: - barrierCount++; - barrierxSum += x; - barrierySum += y; - barrierFx += nE[index] + nNE[index] + nSE[index] - nW[index] - nNW[index] - nSW[index]; - barrierFy += nN[index] + nNE[index] + nNW[index] - nS[index] - nSE[index] - nSW[index]; - } - } - } - } - - // Move the tracer particles: - function moveTracers() { - for (var t=0; t<nTracers; t++) { - var roundedX = Math.round(tracerX[t]); - var roundedY = Math.round(tracerY[t]); - var index = roundedX + roundedY*xdim; - tracerX[t] += ux[index]; - tracerY[t] += uy[index]; - if (tracerX[t] > xdim-1) { - tracerX[t] = 0; - tracerY[t] = Math.random() * ydim; - } - } - } - - // "Drag" the fluid in a direction determined by the mouse (or touch) motion: - // (The drag affects a "circle", 5 px in diameter, centered on the given coordinates.) - function push(pushX, pushY, pushUX, pushUY) { - // First make sure we're not too close to edge: - var margin = 3; - if ((pushX > margin) && (pushX < xdim-1-margin) && (pushY > margin) && (pushY < ydim-1-margin)) { - for (var dx=-1; dx<=1; dx++) { - setEquil(pushX+dx, pushY+2, pushUX, pushUY); - setEquil(pushX+dx, pushY-2, pushUX, pushUY); - } - for (var dx=-2; dx<=2; dx++) { - for (var dy=-1; dy<=1; dy++) { - setEquil(pushX+dx, pushY+dy, pushUX, pushUY); - } - } - } - } - - // Set all densities in a cell to their equilibrium values for a given velocity and density: - // (If density is omitted, it's left unchanged.) - function setEquil(x, y, newux, newuy, newrho) { - var i = x + y * xdim; - var ix = (x + 1) + y * xdim; - var iy = x + (y + 1) * xdim; - var ixy = (x + 1) + (y + 1) * xdim; - - if (typeof newrho == 'undefined') { - newrho = rho[i]; - } - var ux3 = 3 * newux; - var uy3 = 3 * newuy; - var ux2 = newux * newux; - var uy2 = newuy * newuy; - var uxuy2 = 2 * newux * newuy; - var u2 = ux2 + uy2; - var u215 = 1.5 * u2; - if (odd == 0) { - n0[i] = four9ths * newrho * (1 - u215); - nW[ix] = one9th * newrho * (1 + ux3 + 4.5 * ux2 - u215); - nE[i] = one9th * newrho * (1 - ux3 + 4.5 * ux2 - u215); - nS[iy] = one9th * newrho * (1 + uy3 + 4.5 * uy2 - u215); - nN[i] = one9th * newrho * (1 - uy3 + 4.5 * uy2 - u215); - nSW[ixy] = one36th * newrho * (1 + ux3 + uy3 + 4.5 * (u2 + uxuy2) - u215); - nNW[ix] = one36th * newrho * (1 + ux3 - uy3 + 4.5 * (u2 - uxuy2) - u215); - nSE[iy] = one36th * newrho * (1 - ux3 + uy3 + 4.5 * (u2 - uxuy2) - u215); - nNE[i] = one36th * newrho * (1 - ux3 - uy3 + 4.5 * (u2 + uxuy2) - u215); - rho[i] = newrho; - ux[i] = newux; - uy[i] = newuy; - } - else { - n0[i] = four9ths * newrho * (1 - u215); - nE[ix] = one9th * newrho * (1 + ux3 + 4.5 * ux2 - u215); - nW[i] = one9th * newrho * (1 - ux3 + 4.5 * ux2 - u215); - nN[iy] = one9th * newrho * (1 + uy3 + 4.5 * uy2 - u215); - nS[i] = one9th * newrho * (1 - uy3 + 4.5 * uy2 - u215); - nNE[ixy] = one36th * newrho * (1 + ux3 + uy3 + 4.5 * (u2 + uxuy2) - u215); - nSE[ix] = one36th * newrho * (1 + ux3 - uy3 + 4.5 * (u2 - uxuy2) - u215); - nNW[iy] = one36th * newrho * (1 - ux3 + uy3 + 4.5 * (u2 - uxuy2) - u215); - nSW[i] = one36th * newrho * (1 - ux3 - uy3 + 4.5 * (u2 + uxuy2) - u215); - rho[i] = newrho; - ux[i] = newux; - uy[i] = newuy; - - } - } - - // Initialize the tracer particles: - function initTracers() { - if (tracerCheck.checked) { - var nRows = Math.ceil(Math.sqrt(nTracers)); - var dx = xdim / nRows; - var dy = ydim / nRows; - var nextX = dx / 2; - var nextY = dy / 2; - for (var t=0; t<nTracers; t++) { - tracerX[t] = nextX; - tracerY[t] = nextY; - nextX += dx; - if (nextX > xdim) { - nextX = dx / 2; - nextY += dy; - } - } - } - paintCanvas(); - } - - // Paint the canvas: - function paintCanvas() { - var cIndex=0; - var contrast = Math.pow(1.2,Number(contrastSlider.value)); - var plotType = plotSelect.selectedIndex; - //var pixelGraphics = pixelCheck.checked; - if (plotType == 4) computeCurl(); - for (var y=0; y<ydim; y++) { - for (var x=0; x<xdim; x++) { - if (barrier[x+y*xdim]) { - cIndex = nColors + 1; // kludge for barrier color which isn't really part of color map - } else { - if (plotType == 0) { - cIndex = Math.round(nColors * ((rho[x+y*xdim]-1)*6*contrast + 0.5)); - } else if (plotType == 1) { - cIndex = Math.round(nColors * (ux[x+y*xdim]*2*contrast + 0.5)); - } else if (plotType == 2) { - cIndex = Math.round(nColors * (uy[x+y*xdim]*2*contrast + 0.5)); - } else if (plotType == 3) { - var speed = Math.sqrt(ux[x+y*xdim]*ux[x+y*xdim] + uy[x+y*xdim]*uy[x+y*xdim]); - cIndex = Math.round(nColors * (speed*4*contrast)); - } else { - cIndex = Math.round(nColors * (curl[x+y*xdim]*5*contrast + 0.5)); - } - if (cIndex < 0) cIndex = 0; - if (cIndex > nColors) cIndex = nColors; - } - //if (pixelGraphics) { - //colorSquare(x, y, cIndex); - colorSquare(x, y, redList[cIndex], greenList[cIndex], blueList[cIndex]); - //} else { - // context.fillStyle = hexColorList[cIndex]; - // context.fillRect(x*pxPerSquare, (ydim-y-1)*pxPerSquare, pxPerSquare, pxPerSquare); - //} - } - } - //if (pixelGraphics) - context.putImageData(image, 0, 0); // blast image to the screen - // Draw tracers, force vector, and/or sensor if appropriate: - if (tracerCheck.checked) drawTracers(); - if (flowlineCheck.checked) drawFlowlines(); - if (forceCheck.checked) drawForceArrow(barrierxSum/barrierCount, barrierySum/barrierCount, barrierFx, barrierFy); - if (sensorCheck.checked) drawSensor(); - } - - // Color a grid square in the image data array, one pixel at a time (rgb each in range 0 to 255): - function colorSquare(x, y, r, g, b) { - //function colorSquare(x, y, cIndex) { // for some strange reason, this version is quite a bit slower on Chrome - //var r = redList[cIndex]; - //var g = greenList[cIndex]; - //var b = blueList[cIndex]; - var flippedy = ydim - y - 1; // put y=0 at the bottom - for (var py=flippedy*pxPerSquare; py<(flippedy+1)*pxPerSquare; py++) { - for (var px=x*pxPerSquare; px<(x+1)*pxPerSquare; px++) { - var index = (px + py*image.width) * 4; - image.data[index+0] = r; - image.data[index+1] = g; - image.data[index+2] = b; - } - } - } - - // Compute the curl (actually times 2) of the macroscopic velocity field, for plotting: - function computeCurl() { - for (var y=1; y<ydim-1; y++) { // interior sites only; leave edges set to zero - for (var x=1; x<xdim-1; x++) { - curl[x+y*xdim] = uy[x+1+y*xdim] - uy[x-1+y*xdim] - ux[x+(y+1)*xdim] + ux[x+(y-1)*xdim]; - } - } - } - - // Draw the tracer particles: - function drawTracers() { - context.fillStyle = "rgb(150,150,150)"; - for (var t=0; t<nTracers; t++) { - var canvasX = (tracerX[t]+0.5) * pxPerSquare; - var canvasY = canvas.height - (tracerY[t]+0.5) * pxPerSquare; - context.fillRect(canvasX-1, canvasY-1, 2, 2); - } - } - - // Draw a grid of short line segments along flow directions: - function drawFlowlines() { - var pxPerFlowline = 10; - if (pxPerSquare == 1) pxPerFlowline = 6; - if (pxPerSquare == 2) pxPerFlowline = 8; - if (pxPerSquare == 5) pxPerFlowline = 12; - if ((pxPerSquare == 6) || (pxPerSquare == 8)) pxPerFlowline = 15; - if (pxPerSquare == 10) pxPerFlowline = 20; - var sitesPerFlowline = pxPerFlowline / pxPerSquare; - var xLines = canvas.width / pxPerFlowline; - var yLines = canvas.height / pxPerFlowline; - for (var yCount=0; yCount<yLines; yCount++) { - for (var xCount=0; xCount<xLines; xCount++) { - var x = Math.round((xCount+0.5) * sitesPerFlowline); - var y = Math.round((yCount+0.5) * sitesPerFlowline); - var thisUx = ux[x+y*xdim]; - var thisUy = uy[x+y*xdim]; - var speed = Math.sqrt(thisUx*thisUx + thisUy*thisUy); - if (speed > 0.0001) { - var px = (xCount+0.5) * pxPerFlowline; - var py = canvas.height - ((yCount+0.5) * pxPerFlowline); - var scale = 0.5 * pxPerFlowline / speed; - context.beginPath(); - context.moveTo(px-thisUx*scale, py+thisUy*scale); - context.lineTo(px+thisUx*scale, py-thisUy*scale); - //context.lineWidth = speed * 5; - var cIndex = Math.round(speed * transBlackArraySize / 0.3); - if (cIndex >= transBlackArraySize) cIndex = transBlackArraySize - 1; - context.strokeStyle = transBlackArray[cIndex]; - //context.strokeStyle = "rgba(0,0,0,0.1)"; - context.stroke(); - } - } - } - } - - // Draw an arrow to represent the total force on the barrier(s): - function drawForceArrow(x, y, Fx, Fy) { - context.fillStyle = "rgba(100,100,100,0.7)"; - context.translate((x + 0.5) * pxPerSquare, canvas.height - (y + 0.5) * pxPerSquare); - var magF = Math.sqrt(Fx*Fx + Fy*Fy); - context.scale(4*magF, 4*magF); - context.rotate(Math.atan2(-Fy, Fx)); - context.beginPath(); - context.moveTo(0, 3); - context.lineTo(100, 3); - context.lineTo(100, 12); - context.lineTo(130, 0); - context.lineTo(100, -12); - context.lineTo(100, -3); - context.lineTo(0, -3); - context.lineTo(0, 3); - context.fill(); - context.setTransform(1, 0, 0, 1, 0, 0); - } - - // Draw the sensor and its associated data display: - function drawSensor() { - var canvasX = (sensorX+0.5) * pxPerSquare; - var canvasY = canvas.height - (sensorY+0.5) * pxPerSquare; - context.fillStyle = "rgba(180,180,180,0.7)"; // first draw gray filled circle - context.beginPath(); - context.arc(canvasX, canvasY, 7, 0, 2*Math.PI); - context.fill(); - context.strokeStyle = "#404040"; // next draw cross-hairs - context.linewidth = 1; - context.beginPath(); - context.moveTo(canvasX, canvasY-10); - context.lineTo(canvasX, canvasY+10); - context.moveTo(canvasX-10, canvasY); - context.lineTo(canvasX+10, canvasY); - context.stroke(); - context.fillStyle = "rgba(255,255,255,0.5)"; // draw rectangle behind text - canvasX += 10; - context.font = "12px Monospace"; - var rectWidth = context.measureText("00000000000").width+6; - var rectHeight = 58; - if (canvasX+rectWidth > canvas.width) canvasX -= (rectWidth+20); - if (canvasY+rectHeight > canvas.height) canvasY = canvas.height - rectHeight; - context.fillRect(canvasX, canvasY, rectWidth, rectHeight); - context.fillStyle = "#000000"; // finally draw the text - canvasX += 3; - canvasY += 12; - var coordinates = " (" + sensorX + "," + sensorY + ")"; - context.fillText(coordinates, canvasX, canvasY); - canvasY += 14; - var rhoSymbol = String.fromCharCode(parseInt('03C1',16)); - var index = sensorX + sensorY * xdim; - context.fillText(" " + rhoSymbol + " = " + Number(rho[index]).toFixed(3), canvasX, canvasY); - canvasY += 14; - var digitString = Number(ux[index]).toFixed(3); - if (ux[index] >= 0) digitString = " " + digitString; - context.fillText("ux = " + digitString, canvasX, canvasY); - canvasY += 14; - digitString = Number(uy[index]).toFixed(3); - if (uy[index] >= 0) digitString = " " + digitString; - context.fillText("uy = " + digitString, canvasX, canvasY); - } - - // Functions to handle mouse/touch interaction: - function mouseDown(e) { - if (sensorCheck.checked) { - var canvasLoc = pageToCanvas(e.pageX, e.pageY); - var gridLoc = canvasToGrid(canvasLoc.x, canvasLoc.y); - var dx = (gridLoc.x - sensorX) * pxPerSquare; - var dy = (gridLoc.y - sensorY) * pxPerSquare; - if (Math.sqrt(dx*dx + dy*dy) <= 8) { - draggingSensor = true; - } - } - mousePressDrag(e); - }; - function mouseMove(e) { - if (mouseIsDown) { - mousePressDrag(e); - } - }; - function mouseUp(e) { - mouseIsDown = false; - draggingSensor = false; - }; - - // Handle mouse press or drag: - function mousePressDrag(e) { - e.preventDefault(); - mouseIsDown = true; - var canvasLoc = pageToCanvas(e.pageX, e.pageY); - if (draggingSensor) { - var gridLoc = canvasToGrid(canvasLoc.x, canvasLoc.y); - sensorX = gridLoc.x; - sensorY = gridLoc.y; - paintCanvas(); - return; - } - if (mouseSelect.selectedIndex == 2) { - mouseX = canvasLoc.x; - mouseY = canvasLoc.y; - return; - } - var gridLoc = canvasToGrid(canvasLoc.x, canvasLoc.y); - if (mouseSelect.selectedIndex == 0) { - addBarrier(gridLoc.x, gridLoc.y); - paintCanvas(); - } else { - removeBarrier(gridLoc.x, gridLoc.y); - } - } - - // Convert page coordinates to canvas coordinates: - function pageToCanvas(pageX, pageY) { - var canvasX = pageX - canvas.offsetLeft; - var canvasY = pageY - canvas.offsetTop; - // this simple subtraction may not work when the canvas is nested in other elements - return { x:canvasX, y:canvasY }; - } - - // Convert canvas coordinates to grid coordinates: - function canvasToGrid(canvasX, canvasY) { - var gridX = Math.floor(canvasX / pxPerSquare); - var gridY = Math.floor((canvas.height - 1 - canvasY) / pxPerSquare); // off by 1? - return { x:gridX, y:gridY }; - } - - // Add a barrier at a given grid coordinate location: - function addBarrier(x, y) { - if ((x > 1) && (x < xdim-2) && (y > 1) && (y < ydim-2)) { - barrier[x+y*xdim] = true; - } - } - - // Remove a barrier at a given grid coordinate location: - function removeBarrier(x, y) { - if (barrier[x+y*xdim]) { - barrier[x+y*xdim] = false; - paintCanvas(); - } - } - - // Clear all barriers: - function clearBarriers() { - for (var x=0; x<xdim; x++) { - for (var y=0; y<ydim; y++) { - barrier[x+y*xdim] = false; - } - } - paintCanvas(); - } - - // Resize the grid: - function resize() { - // First up-sample the macroscopic variables into temporary arrays at max resolution: - var tempRho = new Array(canvas.width*canvas.height); - var tempUx = new Array(canvas.width*canvas.height); - var tempUy = new Array(canvas.width*canvas.height); - var tempBarrier = new Array(canvas.width*canvas.height); - for (var y=0; y<canvas.height; y++) { - for (var x=0; x<canvas.width; x++) { - var tempIndex = x + y*canvas.width; - var xOld = Math.floor(x / pxPerSquare); - var yOld = Math.floor(y / pxPerSquare); - var oldIndex = xOld + yOld*xdim; - tempRho[tempIndex] = rho[oldIndex]; - tempUx[tempIndex] = ux[oldIndex]; - tempUy[tempIndex] = uy[oldIndex]; - tempBarrier[tempIndex] = barrier[oldIndex]; - } - } - // Get new size from GUI selector: - var oldPxPerSquare = pxPerSquare; - pxPerSquare = Number(sizeSelect.options[sizeSelect.selectedIndex].value); - var growRatio = oldPxPerSquare / pxPerSquare; - xdim = canvas.width / pxPerSquare; - ydim = canvas.height / pxPerSquare; - // Create new arrays at the desired resolution: - n0 = new Array(xdim*ydim); - nN = new Array(xdim*ydim); - nS = new Array(xdim*ydim); - nE = new Array(xdim*ydim); - nW = new Array(xdim*ydim); - nNE = new Array(xdim*ydim); - nSE = new Array(xdim*ydim); - nNW = new Array(xdim*ydim); - nSW = new Array(xdim*ydim); - rho = new Array(xdim*ydim); - ux = new Array(xdim*ydim); - uy = new Array(xdim*ydim); - curl = new Array(xdim*ydim); - barrier = new Array(xdim*ydim); - // Down-sample the temporary arrays into the new arrays: - for (var yNew=0; yNew<ydim; yNew++) { - for (var xNew=0; xNew<xdim; xNew++) { - var rhoTotal = 0; - var uxTotal = 0; - var uyTotal = 0; - var barrierTotal = 0; - for (var y=yNew*pxPerSquare; y<(yNew+1)*pxPerSquare; y++) { - for (var x=xNew*pxPerSquare; x<(xNew+1)*pxPerSquare; x++) { - var index = x + y*canvas.width; - rhoTotal += tempRho[index]; - uxTotal += tempUx[index]; - uyTotal += tempUy[index]; - if (tempBarrier[index]) barrierTotal++; - } - } - setEquil(xNew, yNew, uxTotal/(pxPerSquare*pxPerSquare), uyTotal/(pxPerSquare*pxPerSquare), rhoTotal/(pxPerSquare*pxPerSquare)) - curl[xNew+yNew*xdim] = 0.0; - barrier[xNew+yNew*xdim] = (barrierTotal >= pxPerSquare*pxPerSquare/2); - } - } - setBoundaries(); - if (tracerCheck.checked) { - for (var t=0; t<nTracers; t++) { - tracerX[t] *= growRatio; - tracerY[t] *= growRatio; - } - } - sensorX = Math.round(sensorX * growRatio); - sensorY = Math.round(sensorY * growRatio); - //computeCurl(); - paintCanvas(); - resetTimer(); - } - - // Function to initialize or re-initialize the fluid, based on speed slider setting: - function initFluid() { - // Amazingly, if I nest the y loop inside the x loop, Firefox slows down by a factor of 20 - var u0 = Number(speedSlider.value); - for (var y=0; y<ydim; y++) { - for (var x=0; x<xdim; x++) { - setEquil(x, y, u0, 0, 1); - curl[x+y*xdim] = 0.0; - } - } - paintCanvas(); - } - - // Function to start or pause the simulation: - function startStop() { - running = !running; - if (running) { - startButton.value = "Pause"; - resetTimer(); - simulate(); - } else { - startButton.value = " Run "; - } - } - - // Reset the timer that handles performance evaluation: - function resetTimer() { - stepCount = 0; - startTime = (new Date()).getTime(); - } - - // Show value of flow speed setting: - function adjustSpeed() { - speedValue.innerHTML = Number(speedSlider.value).toFixed(3); - } - - // Show value of viscosity: - function adjustViscosity() { - viscValue.innerHTML = Number(viscSlider.value);//.toFixed(6); - } - - // Show or hide the data area: - function showData() { - if (dataCheck.checked) { - dataSection.style.display="block"; - } else { - dataSection.style.display="none"; - } - } - - // Start or stop collecting data: - function startOrStopData() { - collectingData = !collectingData; - if (collectingData) { - time = 0; - dataArea.innerHTML = "Time \tDensity\tVel_x \tVel_y \tForce_x\tForce_y\n"; - writeData(); - dataButton.value = "Stop data collection"; - showingPeriod = false; - periodButton.value = "Show F_y period"; - } else { - dataButton.value = "Start data collection"; - } - } - - // Write one line of data to the data area: - function writeData() { - var timeString = String(time); - while (timeString.length < 5) timeString = "0" + timeString; - sIndex = sensorX + sensorY*xdim; - dataArea.innerHTML += timeString + "\t" + Number(rho[sIndex]).toFixed(4) + "\t" - + Number(ux[sIndex]).toFixed(4) + "\t" + Number(uy[sIndex]).toFixed(4) + "\t" - + Number(barrierFx).toFixed(4) + "\t" + Number(barrierFy).toFixed(4) + "\n"; - dataArea.scrollTop = dataArea.scrollHeight; - } - - // Handle click to "show period" button - function showPeriod() { - showingPeriod = !showingPeriod; - if (showingPeriod) { - time = 0; - lastBarrierFy = 1.0; // arbitrary positive value - lastFyOscTime = -1.0; // arbitrary negative value - dataArea.innerHTML = "Period of F_y oscillation\n"; - periodButton.value = "Stop data"; - collectingData = false; - dataButton.value = "Start data collection"; - } else { - periodButton.value = "Show F_y period"; - } - } - - // Write all the barrier locations to the data area: - function showBarrierLocations() { - dataArea.innerHTML = '{name:"Barrier locations",\n'; - dataArea.innerHTML += 'locations:[\n'; - for (var y=1; y<ydim-1; y++) { - for (var x=1; x<xdim-1; x++) { - if (barrier[x+y*xdim]) dataArea.innerHTML += x + ',' + y + ',\n'; - } - } - dataArea.innerHTML = dataArea.innerHTML.substr(0, dataArea.innerHTML.length-2); // remove final comma - dataArea.innerHTML += '\n]},\n'; - } - - // Place a preset barrier: - function placePresetBarrier() { - var index = barrierSelect.selectedIndex; - if (index == 0) return; - clearBarriers(); - var bCount = barrierList[index-1].locations.length/2; // number of barrier sites - // To decide where to place it, find minimum x and min/max y: - var xMin = barrierList[index-1].locations[0]; - var yMin = barrierList[index-1].locations[1]; - var yMax = yMin; - for (var siteIndex=2; siteIndex<2*bCount; siteIndex+=2) { - if (barrierList[index-1].locations[siteIndex] < xMin) { - xMin = barrierList[index-1].locations[siteIndex]; - } - if (barrierList[index-1].locations[siteIndex+1] < yMin) { - yMin = barrierList[index-1].locations[siteIndex+1]; - } - if (barrierList[index-1].locations[siteIndex+1] > yMax) { - yMax = barrierList[index-1].locations[siteIndex+1]; - } - } - var yAverage = Math.round((yMin+yMax)/2); - // Now place the barriers: - for (var siteIndex=0; siteIndex<2*bCount; siteIndex+=2) { - var x = barrierList[index-1].locations[siteIndex] - xMin + Math.round(ydim/3); - var y = barrierList[index-1].locations[siteIndex+1] - yAverage + Math.round(ydim/2); - addBarrier(x, y); - } - paintCanvas(); - barrierSelect.selectedIndex = 0; // A choice on this menu is a one-time action, not an ongoing setting - } - - // Print debugging data: - function debug() { - dataArea.innerHTML = "Tracer locations:\n"; - for (var t=0; t<nTracers; t++) { - dataArea.innerHTML += tracerX[t] + ", " + tracerY[t] + "\n"; - } - } -</script> - -</body> -</html> \ No newline at end of file diff --git a/3rdParty/WebDemo/barrierdata.js b/3rdParty/WebDemo/barrierdata.js deleted file mode 100644 index c165530d7dbc4b7b07d3e7a3f6703b180c38cbce..0000000000000000000000000000000000000000 --- a/3rdParty/WebDemo/barrierdata.js +++ /dev/null @@ -1,655 +0,0 @@ -var barrierList = [ -{ name: "Short line", - locations: [ -12, 15, -12, 16, -12, 17, -12, 18, -12, 19, -12, 20, -12, 21, -12, 22, -12, 23] -}, -{ name: "Long line", - locations: [ -13, 11, -13, 12, -13, 13, -13, 14, -13, 15, -13, 16, -13, 17, -13, 18, -13, 19, -13, 20, -13, 21, -13, 22, -13, 23, -13, 24, -13, 25, -13, 26, -13, 27, -13, 28 -] -}, -{ name: "Diagonal", - locations: [ -30, 14, -29, 15, -30, 15, -28, 16, -29, 16, -27, 17, -28, 17, -26, 18, -27, 18, -25, 19, -26, 19, -24, 20, -25, 20, -23, 21, -24, 21, -22, 22, -23, 22, -21, 23, -22, 23, -20, 24, -21, 24, -19, 25, -20, 25, -18, 26, -19, 26, -17, 27, -18, 27, -16, 28, -17, 28, -15, 29, -16, 29, -14, 30, -15, 30, -13, 31, -14, 31 -] -}, -{ name: "Shallow diagonal", - locations: [ -47, 18, -48, 18, -49, 18, -50, 18, -44, 19, -45, 19, -46, 19, -47, 19, -41, 20, -42, 20, -43, 20, -44, 20, -38, 21, -39, 21, -40, 21, -41, 21, -35, 22, -36, 22, -37, 22, -38, 22, -32, 23, -33, 23, -34, 23, -35, 23, -29, 24, -30, 24, -31, 24, -32, 24, -26, 25, -27, 25, -28, 25, -29, 25, -23, 26, -24, 26, -25, 26, -26, 26, -20, 27, -21, 27, -22, 27, -23, 27, -17, 28, -18, 28, -19, 28, -20, 28 -] -}, -{ name: "Small circle", - locations: [ -14, 11, -15, 11, -16, 11, -17, 11, -18, 11, -13, 12, -14, 12, -18, 12, -19, 12, -12, 13, -13, 13, -19, 13, -20, 13, -12, 14, -20, 14, -12, 15, -20, 15, -12, 16, -20, 16, -12, 17, -13, 17, -19, 17, -20, 17, -13, 18, -14, 18, -18, 18, -19, 18, -14, 19, -15, 19, -16, 19, -17, 19, -18, 19 -] -}, -{ name: "Large circle", - locations: [ -19, 11, -20, 11, -21, 11, -22, 11, -23, 11, -24, 11, -17, 12, -18, 12, -19, 12, -24, 12, -25, 12, -26, 12, -16, 13, -17, 13, -26, 13, -27, 13, -15, 14, -16, 14, -27, 14, -28, 14, -14, 15, -15, 15, -28, 15, -29, 15, -14, 16, -29, 16, -13, 17, -14, 17, -29, 17, -30, 17, -13, 18, -30, 18, -13, 19, -30, 19, -13, 20, -30, 20, -13, 21, -30, 21, -13, 22, -14, 22, -29, 22, -30, 22, -14, 23, -29, 23, -14, 24, -15, 24, -28, 24, -29, 24, -15, 25, -16, 25, -27, 25, -28, 25, -16, 26, -17, 26, -26, 26, -27, 26, -17, 27, -18, 27, -19, 27, -24, 27, -25, 27, -26, 27, -19, 28, -20, 28, -21, 28, -22, 28, -23, 28, -24, 28 -] -}, -{ name: "Line with spoiler", - locations: [ -16, 20, -16, 21, -16, 22, -16, 23, -16, 24, -17, 24, -18, 24, -19, 24, -20, 24, -21, 24, -22, 24, -23, 24, -24, 24, -25, 24, -26, 24, -27, 24, -28, 24, -29, 24, -30, 24, -31, 24, -32, 24, -33, 24, -34, 24, -35, 24, -36, 24, -37, 24, -38, 24, -39, 24, -40, 24, -41, 24, -42, 24, -43, 24, -44, 24, -45, 24, -46, 24, -47, 24, -48, 24, -49, 24, -50, 24, -16, 25, -16, 26, -16, 27, -16, 28 -] -}, -{ name: "Circle with spoiler", - locations: [ -29, 36, -30, 36, -31, 36, -32, 36, -33, 36, -28, 37, -29, 37, -33, 37, -34, 37, -27, 38, -28, 38, -34, 38, -35, 38, -27, 39, -35, 39, -27, 40, -35, 40, -36, 40, -37, 40, -38, 40, -39, 40, -40, 40, -41, 40, -42, 40, -43, 40, -44, 40, -45, 40, -46, 40, -47, 40, -48, 40, -49, 40, -50, 40, -51, 40, -52, 40, -53, 40, -54, 40, -55, 40, -56, 40, -57, 40, -58, 40, -59, 40, -60, 40, -61, 40, -62, 40, -63, 40, -64, 40, -65, 40, -66, 40, -67, 40, -68, 40, -69, 40, -27, 41, -35, 41, -27, 42, -28, 42, -34, 42, -35, 42, -28, 43, -29, 43, -33, 43, -34, 43, -29, 44, -30, 44, -31, 44, -32, 44, -33, 44 -] -}, -{ name: "Right angle", - locations: [ -27, 36, -28, 36, -29, 36, -30, 36, -31, 36, -32, 36, -33, 36, -34, 36, -35, 36, -36, 36, -37, 36, -38, 36, -39, 36, -40, 36, -41, 36, -42, 36, -43, 36, -44, 36, -45, 36, -46, 36, -47, 36, -48, 36, -49, 36, -50, 36, -51, 36, -52, 36, -53, 36, -54, 36, -55, 36, -56, 36, -57, 36, -58, 36, -59, 36, -60, 36, -61, 36, -62, 36, -63, 36, -64, 36, -65, 36, -66, 36, -67, 36, -68, 36, -69, 36, -70, 36, -71, 36, -72, 36, -73, 36, -74, 36, -75, 36, -76, 36, -77, 36, -78, 36, -79, 36, -27, 37, -27, 38, -27, 39, -27, 40, -27, 41, -27, 42, -27, 43, -27, 44 -] -}, -{ name: "Wedge", - locations: [ -27, 36, -28, 36, -29, 36, -30, 36, -31, 36, -32, 36, -33, 36, -34, 36, -35, 36, -36, 36, -37, 36, -38, 36, -39, 36, -40, 36, -41, 36, -42, 36, -43, 36, -44, 36, -45, 36, -46, 36, -47, 36, -48, 36, -49, 36, -50, 36, -51, 36, -52, 36, -53, 36, -54, 36, -55, 36, -56, 36, -57, 36, -58, 36, -59, 36, -60, 36, -61, 36, -62, 36, -63, 36, -64, 36, -65, 36, -66, 36, -67, 36, -68, 36, -69, 36, -70, 36, -71, 36, -72, 36, -73, 36, -74, 36, -75, 36, -76, 36, -77, 36, -78, 36, -79, 36, -27, 37, -67, 37, -68, 37, -69, 37, -70, 37, -71, 37, -72, 37, -73, 37, -27, 38, -61, 38, -62, 38, -63, 38, -64, 38, -65, 38, -66, 38, -67, 38, -27, 39, -55, 39, -56, 39, -57, 39, -58, 39, -59, 39, -60, 39, -61, 39, -27, 40, -49, 40, -50, 40, -51, 40, -52, 40, -53, 40, -54, 40, -55, 40, -27, 41, -43, 41, -44, 41, -45, 41, -46, 41, -47, 41, -48, 41, -49, 41, -27, 42, -37, 42, -38, 42, -39, 42, -40, 42, -41, 42, -42, 42, -43, 42, -27, 43, -31, 43, -32, 43, -33, 43, -34, 43, -35, 43, -36, 43, -37, 43, -27, 44, -28, 44, -29, 44, -30, 44, -31, 44 -] -}, -{ name: "Airfoil", - locations: [ -17, 16, -18, 16, -19, 16, -20, 16, -21, 16, -22, 16, -23, 16, -24, 16, -25, 16, -26, 16, -27, 16, -28, 16, -29, 16, -30, 16, -31, 16, -32, 16, -33, 16, -34, 16, -35, 16, -36, 16, -37, 16, -38, 16, -39, 16, -40, 16, -41, 16, -42, 16, -43, 16, -44, 16, -45, 16, -46, 16, -47, 16, -48, 16, -49, 16, -50, 16, -51, 16, -52, 16, -53, 16, -54, 16, -55, 16, -56, 16, -57, 16, -58, 16, -59, 16, -60, 16, -61, 16, -62, 16, -63, 16, -64, 16, -65, 16, -66, 16, -67, 16, -68, 16, -14, 17, -15, 17, -16, 17, -17, 17, -56, 17, -57, 17, -58, 17, -59, 17, -60, 17, -61, 17, -62, 17, -13, 18, -14, 18, -50, 18, -51, 18, -52, 18, -53, 18, -54, 18, -55, 18, -56, 18, -13, 19, -44, 19, -45, 19, -46, 19, -47, 19, -48, 19, -49, 19, -50, 19, -13, 20, -38, 20, -39, 20, -40, 20, -41, 20, -42, 20, -43, 20, -44, 20, -13, 21, -14, 21, -32, 21, -33, 21, -34, 21, -35, 21, -36, 21, -37, 21, -38, 21, -14, 22, -15, 22, -26, 22, -27, 22, -28, 22, -29, 22, -30, 22, -31, 22, -32, 22, -15, 23, -16, 23, -17, 23, -18, 23, -21, 23, -22, 23, -23, 23, -24, 23, -25, 23, -26, 23, -18, 24, -19, 24, -20, 24, -21, 24 -] -} -]; \ No newline at end of file diff --git a/Containers/dockerfiles/Ubuntu20_04.Dockerfile b/Containers/Ubuntu20_04.Dockerfile similarity index 100% rename from Containers/dockerfiles/Ubuntu20_04.Dockerfile rename to Containers/Ubuntu20_04.Dockerfile diff --git a/Containers/VirtualFluidsBasicsTest.def b/Containers/VirtualFluidsBasicsTest.def deleted file mode 100644 index 930b93e5e9f71ff9b4b8afcae4c8ea47aeb82522..0000000000000000000000000000000000000000 --- a/Containers/VirtualFluidsBasicsTest.def +++ /dev/null @@ -1,29 +0,0 @@ -BootStrap: docker -From: ubuntu:20.04 - -%files - 3rdParty 3rdParty - apps apps - CMake CMake - Python Python - src src - CMakeLists.txt CMakeLists.txt - cpu.cmake cpu.cmake - gpu.cmake gpu.cmake - setup.py setup.py - pyproject.toml pyproject.toml - -%post - apt-get update && \ - apt-get install -y \ - build-essential \ - cmake=3.16.3-1ubuntu1 \ - openmpi-bin=4.0.3-0ubuntu1 \ - libomp-dev - - mkdir -p build && \ - cmake -DBUILD_VF_CPU=ON -DBUILD_VF_UNIT_TESTS=ON &&\ - make -j4 2>&1 - -%runscript - bin/basicsTest \ No newline at end of file diff --git a/Containers/VirtualFluidsMPICH.def b/Containers/VirtualFluidsMPICH.def deleted file mode 100644 index 72f9ac549bd9d2bd006dafededf7b7b2f74f2600..0000000000000000000000000000000000000000 --- a/Containers/VirtualFluidsMPICH.def +++ /dev/null @@ -1,44 +0,0 @@ -BootStrap: docker -From: ubuntu:20.04 - -%files - 3rdParty 3rdParty - apps apps - CMake CMake - Python Python - src src - CMakeLists.txt CMakeLists.txt - cpu.cmake cpu.cmake - gpu.cmake gpu.cmake - setup.py setup.py - pyproject.toml pyproject.toml - - -%post - export DEBIAN_FRONTEND=noninteractive - apt-get update && \ - apt-get install -y \ - build-essential \ - cmake=3.16.3-1ubuntu1 \ - python3 \ - python3-dev \ - python3-pip \ - mpich \ - libomp-dev - - pip3 install setuptools wheel - - export PYTHONPATH=Python - python3 /setup.py install - -%environment - export PYTHONPATH=/Python - -%runscript - python3 /Python/liddrivencavity/simulation.py - -%appenv poiseuille - export PYTHONPATH=Python - -%apprun poisueille - python3 /Python/poiseuille/poiseuille_hpc.py diff --git a/Containers/VirtualFluidsOpenMPI.def b/Containers/VirtualFluidsOpenMPI.def deleted file mode 100644 index 3903b8769d7e652bbb12add7b815eb35de279d94..0000000000000000000000000000000000000000 --- a/Containers/VirtualFluidsOpenMPI.def +++ /dev/null @@ -1,25 +0,0 @@ -BootStrap: docker -From: irmb/virtualfluids-python-deps - -%files - 3rdParty 3rdParty - apps apps - CMake CMake - Python Python - src src - CMakeLists.txt CMakeLists.txt - cpu.cmake cpu.cmake - gpu.cmake gpu.cmake - setup.py setup.py - pyproject.toml pyproject.toml - - -%post - export PYTHONPATH=Python - python3 /setup.py install - -%environment - export PYTHONPATH=/Python - -%runscript - python3 /Python/liddrivencavity/simulation.py diff --git a/Containers/VirtualFluidsPython.def b/Containers/VirtualFluidsPython.def deleted file mode 100644 index d54066bc634cf25f4340b1e659eae72515467fa8..0000000000000000000000000000000000000000 --- a/Containers/VirtualFluidsPython.def +++ /dev/null @@ -1,33 +0,0 @@ -BootStrap: docker -From: ubuntu:20.04 - -%files - Python Python - dist dist - - -%post - export DEBIAN_FRONTEND=noninteractive - apt-get update && \ - apt-get install -y \ - build-essential \ - cmake=3.16.3-1ubuntu1 \ - python3 \ - python3-dev \ - python3-pip \ - mpich \ - libomp-dev - - pip3 install setuptools wheel $(find dist/*.whl) - -%environment - export PYTHONPATH=/Python - -%runscript - python3 /Python/liddrivencavity/simulation.py - -%appenv poiseuille - export PYTHONPATH=Python - -%apprun poisueille - python3 /Python/poiseuille/poiseuille_hpc.py diff --git a/apps/cpu/MultiphaseDropletTest.zip b/apps/cpu/MultiphaseDropletTest.zip deleted file mode 100644 index 5eb13a6c0bacfbf392deb00c6b388ba282c038e0..0000000000000000000000000000000000000000 Binary files a/apps/cpu/MultiphaseDropletTest.zip and /dev/null differ diff --git a/apps/gpu/HULC/main.cpp b/apps/gpu/HULC/main.cpp deleted file mode 100644 index 80f8ba4c62b3b0af08425f839d0f802a568db034..0000000000000000000000000000000000000000 --- a/apps/gpu/HULC/main.cpp +++ /dev/null @@ -1,411 +0,0 @@ -//#define MPI_LOGGING - - -#include <mpi.h> -#if defined( MPI_LOGGING ) - #include <mpe.h> -#endif - -#include <string> -#include <iostream> - -#include "LBM/Simulation.h" - -#include "Parameter/Parameter.h" -#include "DataStructureInitializer/GridProvider.h" -#include "VirtualFluidsBasics/utilities/input/Input.h" -#include "VirtualFluidsBasics/utilities/StringUtil/StringUtil.h" -#include "grid/GridBuilder/LevelGridBuilder.h" -#include "utilities/transformator/TransformatorImp.h" -#include "io/GridVTKWriter/GridVTKWriter.h" - -#include "io/SimulationFileWriter/SimulationFileWriter.h" -#include "grid/GridBuilder/LevelGridBuilder.h" -#include "grid/GridBuilder/ParallelGridBuilder.h" -#include "geometries/TriangularMesh/TriangularMesh.h" - -#include "grid/GridFactory.h" -#include "grid/GridBuilder/MultipleGridBuilder.h" -#include <grid/GridMocks.h> -#include "grid/GridStrategy/GridStrategyMocks.h" -#include "VirtualFluidsBasics/utilities/logger/Logger.h" -#include "geometries/Conglomerate/Conglomerate.h" -#include "io/STLReaderWriter/STLReader.h" -#include "io/STLReaderWriter/STLWriter.h" -#include "geometries/TriangularMesh/TriangularMeshStrategy.h" -#include "Output/FileWriter.h" - - -#include "Kernel/Utilities/KernelFactory/KernelFactoryImp.h" -#include "PreProcessor/PreProcessorFactory/PreProcessorFactoryImp.h" - - -std::string getGridPath(std::shared_ptr<Parameter> para, std::string Gridpath) -{ - if (para->getNumprocs() == 1) - return Gridpath + "/"; - - return Gridpath + "/" + StringUtil::toString(para->getMyID()) + "/"; -} - -void setParameters(std::shared_ptr<Parameter> para, std::unique_ptr<input::Input> &input) -{ - std::string _path = input->getValue("Path"); - std::string _prefix = input->getValue("Prefix"); - std::string _gridpath = input->getValue("GridPath"); - para->setNumprocs(1); - std::string gridPath = getGridPath(para, _gridpath); - para->setMaxDev(StringUtil::toInt(input->getValue("NumberOfDevices"))); - para->setDevices(StringUtil::toIntVector(input->getValue("Devices"))); - para->setOutputPath(_path); - para->setOutputPrefix(_prefix); - para->setPathAndFilename(_path + "/" + _prefix); - para->setPrintFiles(false); - para->setPrintFiles(StringUtil::toBool(input->getValue("WriteGrid"))); - para->setGeometryValues(StringUtil::toBool(input->getValue("GeometryValues"))); - para->setCalc2ndOrderMoments(StringUtil::toBool(input->getValue("calc2ndOrderMoments"))); - para->setCalc3rdOrderMoments(StringUtil::toBool(input->getValue("calc3rdOrderMoments"))); - para->setCalcHighOrderMoments(StringUtil::toBool(input->getValue("calcHigherOrderMoments"))); - para->setReadGeo(StringUtil::toBool(input->getValue("ReadGeometry"))); - para->setCalcMedian(StringUtil::toBool(input->getValue("calcMedian"))); - para->setConcFile(StringUtil::toBool(input->getValue("UseConcFile"))); - para->setUseMeasurePoints(StringUtil::toBool(input->getValue("UseMeasurePoints"))); - para->setUseWale(StringUtil::toBool(input->getValue("UseWale"))); - para->setSimulatePorousMedia(StringUtil::toBool(input->getValue("SimulatePorousMedia"))); - para->setD3Qxx(StringUtil::toInt(input->getValue("D3Qxx"))); - para->setTimestepEnd(StringUtil::toInt(input->getValue("TimeEnd"))); - para->setTimestepOut(StringUtil::toInt(input->getValue("TimeOut"))); - para->setTimestepStartOut(StringUtil::toInt(input->getValue("TimeStartOut"))); - para->setTimeCalcMedStart(StringUtil::toInt(input->getValue("TimeStartCalcMedian"))); - para->setTimeCalcMedEnd(StringUtil::toInt(input->getValue("TimeEndCalcMedian"))); - para->setPressInID(StringUtil::toInt(input->getValue("PressInID"))); - para->setPressOutID(StringUtil::toInt(input->getValue("PressOutID"))); - para->setPressInZ(StringUtil::toInt(input->getValue("PressInZ"))); - para->setPressOutZ(StringUtil::toInt(input->getValue("PressOutZ"))); - ////////////////////////////////////////////////////////////////////////// - para->setCompOn(StringUtil::toBool(input->getValue("CompOn"))); - para->setDiffOn(StringUtil::toBool(input->getValue("DiffOn"))); - para->setDiffMod(StringUtil::toInt(input->getValue("DiffMod"))); - para->setDiffusivity(StringUtil::toFloat(input->getValue("Diffusivity"))); - para->setTemperatureInit(StringUtil::toFloat(input->getValue("Temp"))); - para->setTemperatureBC(StringUtil::toFloat(input->getValue("TempBC"))); - ////////////////////////////////////////////////////////////////////////// - para->setViscosityLB(StringUtil::toFloat(input->getValue("Viscosity_LB"))); - para->setVelocityLB(StringUtil::toFloat(input->getValue("Velocity_LB"))); - para->setViscosityRatio(StringUtil::toFloat(input->getValue("Viscosity_Ratio_World_to_LB"))); - para->setVelocityRatio(StringUtil::toFloat(input->getValue("Velocity_Ratio_World_to_LB"))); - para->setDensityRatio(StringUtil::toFloat(input->getValue("Density_Ratio_World_to_LB"))); - para->setPressRatio(StringUtil::toFloat(input->getValue("Delta_Press"))); - para->setRealX(StringUtil::toFloat(input->getValue("SliceRealX"))); - para->setRealY(StringUtil::toFloat(input->getValue("SliceRealY"))); - para->setFactorPressBC(StringUtil::toFloat(input->getValue("dfpbc"))); - para->setGeometryFileC(input->getValue("GeometryC")); - para->setGeometryFileM(input->getValue("GeometryM")); - para->setGeometryFileF(input->getValue("GeometryF")); - ////////////////////////////////////////////////////////////////////////// - para->setgeoVec(gridPath + input->getValue("geoVec")); - para->setcoordX(gridPath + input->getValue("coordX")); - para->setcoordY(gridPath + input->getValue("coordY")); - para->setcoordZ(gridPath + input->getValue("coordZ")); - para->setneighborX(gridPath + input->getValue("neighborX")); - para->setneighborY(gridPath + input->getValue("neighborY")); - para->setneighborZ(gridPath + input->getValue("neighborZ")); - para->setscaleCFC(gridPath + input->getValue("scaleCFC")); - para->setscaleCFF(gridPath + input->getValue("scaleCFF")); - para->setscaleFCC(gridPath + input->getValue("scaleFCC")); - para->setscaleFCF(gridPath + input->getValue("scaleFCF")); - para->setscaleOffsetCF(gridPath + input->getValue("scaleOffsetCF")); - para->setscaleOffsetFC(gridPath + input->getValue("scaleOffsetFC")); - para->setgeomBoundaryBcQs(gridPath + input->getValue("geomBoundaryBcQs")); - para->setgeomBoundaryBcValues(gridPath + input->getValue("geomBoundaryBcValues")); - para->setinletBcQs(gridPath + input->getValue("inletBcQs")); - para->setinletBcValues(gridPath + input->getValue("inletBcValues")); - para->setoutletBcQs(gridPath + input->getValue("outletBcQs")); - para->setoutletBcValues(gridPath + input->getValue("outletBcValues")); - para->settopBcQs(gridPath + input->getValue("topBcQs")); - para->settopBcValues(gridPath + input->getValue("topBcValues")); - para->setbottomBcQs(gridPath + input->getValue("bottomBcQs")); - para->setbottomBcValues(gridPath + input->getValue("bottomBcValues")); - para->setfrontBcQs(gridPath + input->getValue("frontBcQs")); - para->setfrontBcValues(gridPath + input->getValue("frontBcValues")); - para->setbackBcQs(gridPath + input->getValue("backBcQs")); - para->setbackBcValues(gridPath + input->getValue("backBcValues")); - para->setnumberNodes(gridPath + input->getValue("numberNodes")); - para->setLBMvsSI(gridPath + input->getValue("LBMvsSI")); - //////////////////////////////gridPath + //////////////////////////////////////////// - para->setmeasurePoints(gridPath + input->getValue("measurePoints")); - para->setpropellerValues(gridPath + input->getValue("propellerValues")); - para->setclockCycleForMP(StringUtil::toFloat(input->getValue("measureClockCycle"))); - para->settimestepForMP(StringUtil::toInt(input->getValue("measureTimestep"))); - para->setcpTop(gridPath + input->getValue("cpTop")); - para->setcpBottom(gridPath + input->getValue("cpBottom")); - para->setcpBottom2(gridPath + input->getValue("cpBottom2")); - para->setConcentration(gridPath + input->getValue("Concentration")); - ////////////////////////////////////////////////////////////////////////// - //Normals - Geometry - para->setgeomBoundaryNormalX(gridPath + input->getValue("geomBoundaryNormalX")); - para->setgeomBoundaryNormalY(gridPath + input->getValue("geomBoundaryNormalY")); - para->setgeomBoundaryNormalZ(gridPath + input->getValue("geomBoundaryNormalZ")); - //Normals - Inlet - para->setInflowBoundaryNormalX(gridPath + input->getValue("inletBoundaryNormalX")); - para->setInflowBoundaryNormalY(gridPath + input->getValue("inletBoundaryNormalY")); - para->setInflowBoundaryNormalZ(gridPath + input->getValue("inletBoundaryNormalZ")); - //Normals - Outlet - para->setOutflowBoundaryNormalX(gridPath + input->getValue("outletBoundaryNormalX")); - para->setOutflowBoundaryNormalY(gridPath + input->getValue("outletBoundaryNormalY")); - para->setOutflowBoundaryNormalZ(gridPath + input->getValue("outletBoundaryNormalZ")); - ////////////////////////////////////////////////////////////////////////// - //Forcing - para->setForcing(StringUtil::toFloat(input->getValue("ForcingX")), StringUtil::toFloat(input->getValue("ForcingY")), StringUtil::toFloat(input->getValue("ForcingZ"))); - ////////////////////////////////////////////////////////////////////////// - //Particles - para->setCalcParticles(StringUtil::toBool(input->getValue("calcParticles"))); - para->setParticleBasicLevel(StringUtil::toInt(input->getValue("baseLevel"))); - para->setParticleInitLevel(StringUtil::toInt(input->getValue("initLevel"))); - para->setNumberOfParticles(StringUtil::toInt(input->getValue("numberOfParticles"))); - para->setneighborWSB(gridPath + input->getValue("neighborWSB")); - para->setStartXHotWall(StringUtil::toDouble(input->getValue("startXHotWall"))); - para->setEndXHotWall(StringUtil::toDouble(input->getValue("endXHotWall"))); - ////////////////////////////////////////////////////////////////////////// - //for Multi GPU - if (para->getNumprocs() > 1) - { - //////////////////////////////////////////////////////////////////////////// - ////1D domain decomposition - //std::vector<std::string> sendProcNeighbors; - //std::vector<std::string> recvProcNeighbors; - //for (int i = 0; i<para->getNumprocs();i++) - //{ - // sendProcNeighbors.push_back(gridPath + StringUtil::toString(i) + "s.dat"); - // recvProcNeighbors.push_back(gridPath + StringUtil::toString(i) + "r.dat"); - //} - //para->setPossNeighborFiles(sendProcNeighbors, "send"); - //para->setPossNeighborFiles(recvProcNeighbors, "recv"); - ////////////////////////////////////////////////////////////////////////// - //3D domain decomposition - std::vector<std::string> sendProcNeighborsX, sendProcNeighborsY, sendProcNeighborsZ; - std::vector<std::string> recvProcNeighborsX, recvProcNeighborsY, recvProcNeighborsZ; - for (int i = 0; i < para->getNumprocs(); i++) - { - sendProcNeighborsX.push_back(gridPath + StringUtil::toString(i) + "Xs.dat"); - sendProcNeighborsY.push_back(gridPath + StringUtil::toString(i) + "Ys.dat"); - sendProcNeighborsZ.push_back(gridPath + StringUtil::toString(i) + "Zs.dat"); - recvProcNeighborsX.push_back(gridPath + StringUtil::toString(i) + "Xr.dat"); - recvProcNeighborsY.push_back(gridPath + StringUtil::toString(i) + "Yr.dat"); - recvProcNeighborsZ.push_back(gridPath + StringUtil::toString(i) + "Zr.dat"); - } - para->setPossNeighborFilesX(sendProcNeighborsX, "send"); - para->setPossNeighborFilesY(sendProcNeighborsY, "send"); - para->setPossNeighborFilesZ(sendProcNeighborsZ, "send"); - para->setPossNeighborFilesX(recvProcNeighborsX, "recv"); - para->setPossNeighborFilesY(recvProcNeighborsY, "recv"); - para->setPossNeighborFilesZ(recvProcNeighborsZ, "recv"); - } - ////////////////////////////////////////////////////////////////////////// - //para->setkFull( input->getValue( "kFull" )); - //para->setgeoFull( input->getValue( "geoFull" )); - //para->setnoSlipBcPos( input->getValue( "noSlipBcPos" )); - //para->setnoSlipBcQs( input->getValue( "noSlipBcQs" )); - //para->setnoSlipBcValues( input->getValue( "noSlipBcValues" )); - //para->setnoSlipBcValue( input->getValue( "noSlipBcValue" )); - //para->setslipBcPos( input->getValue( "slipBcPos" )); - //para->setslipBcQs( input->getValue( "slipBcQs" )); - //para->setslipBcValue( input->getValue( "slipBcValue" )); - //para->setpressBcPos( input->getValue( "pressBcPos" )); - //para->setpressBcQs( input->getValue( "pressBcQs" )); - //para->setpressBcValues( input->getValue( "pressBcValues" )); - //para->setpressBcValue( input->getValue( "pressBcValue" )); - //para->setvelBcQs( input->getValue( "velBcQs" )); - //para->setvelBcValues( input->getValue( "velBcValues" )); - //para->setpropellerCylinder( input->getValue( "propellerCylinder" )); - //para->setpropellerQs( input->getValue( "propellerQs" )); - //para->setwallBcQs( input->getValue( "wallBcQs" )); - //para->setwallBcValues( input->getValue( "wallBcValues" )); - //para->setperiodicBcQs( input->getValue( "periodicBcQs" )); - //para->setperiodicBcValues( input->getValue( "periodicBcValues" )); - //cout << "Try this: " << para->getgeomBoundaryBcValues() << endl; - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //Restart - para->setTimeDoCheckPoint(StringUtil::toInt(input->getValue("TimeDoCheckPoint"))); - para->setTimeDoRestart(StringUtil::toInt(input->getValue("TimeDoRestart"))); - para->setDoCheckPoint(StringUtil::toBool(input->getValue("DoCheckPoint"))); - para->setDoRestart(StringUtil::toBool(input->getValue("DoRestart"))); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/* para->setMaxLevel(StringUtil::toInt(input->getValue("NOGL"))); - para->setGridX(StringUtil::toVector(input->getValue("GridX"))); - para->setGridY(StringUtil::toVector(input->getValue("GridY"))); - para->setGridZ(StringUtil::toVector(input->getValue("GridZ"))); - para->setDistX(StringUtil::toVector(input->getValue("DistX"))); - para->setDistY(StringUtil::toVector(input->getValue("DistY"))); - para->setDistZ(StringUtil::toVector(input->getValue("DistZ"))); */ - - para->setNeedInterface(std::vector<bool>{true, true, true, true, true, true}); - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Kernel - para->setMainKernel(input->getValue("MainKernelName")); - para->setMultiKernelOn(StringUtil::toBool(input->getValue("multiKernelOn"))); - para->setMultiKernelLevel(StringUtil::toIntVector(input->getValue("multiKernelLevel"))); - para->setMultiKernelName(StringUtil::toStringVector(input->getValue("multiKernelName"))); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -} - - - -void multipleLevel(const std::string& configPath) -{ - logging::Logger::setStream(&std::cout); - logging::Logger::setDebugLevel(logging::Logger::INFO_LOW); - logging::Logger::timeStamp(logging::Logger::ENABLE); - - auto gridFactory = SPtr<GridFactory>(new GridFactory()); - gridFactory->setGridStrategy(SPtr<GridStrategy>(new GridCpuStrategy())); - gridFactory->setGrid("grid"); - gridFactory->setTriangularMeshDiscretizationMethod(TriangularMeshDiscretizationMethod::RAYCASTING); - - //auto gridBuilderlevel = LevelGridBuilder::makeShared(Device::CPU, "D3Q27"); - auto gridBuilder = MultipleGridBuilder::makeShared(gridFactory); - - //Conglomerate* conglomerate = new Conglomerate(); - //conglomerate->add(new Cuboid(10, 10, 10, 30, 30, 30)); - //conglomerate->subtract(new Sphere(30, 20, 20, 4)); - //gridBuilder->addGrid(conglomerate, 2); - - -// gridBuilder->addCoarseGrid(0.0, 0.0, 0.0, 14, 10, 20, 0.25); - //TriangularMesh* triangularMesh = TriangularMesh::make("D:/GRIDGENERATION/STL/quadarBinaer.stl", DiscretizationMethod::POINT_IN_OBJECT); - - - gridBuilder->addCoarseGrid(-10, -8, -3, 50, 20, 20, 0.25); - TriangularMesh* triangularMesh = TriangularMesh::make("D:/GRIDGENERATION/STL/input/local_input/bruecke.stl", DiscretizationMethod::RAYCASTING); - - - //TriangleOffsetSurfaceGeneration::createOffsetTriangularMesh(triangularMesh, 5); - - //TriangularMesh* sphere = TriangularMesh::make("D:/GRIDGENERATION/STL/GTI.stl", DiscretizationMethod::RAYCASTING); - //TransformatorImp trans(1.0, Vertex(5.5, 1, 12)); - //trans.transformWorldToGrid(*sphere); - //STLWriter::writeSTL(sphere->triangleVec, "D:/GRIDGENERATION/STL/GTI2.stl", false); - - //gridBuilder->addGrid(new Sphere(20, 20, 20, 8)); - gridBuilder->addGrid(triangularMesh, 2); - - //gridBuilder->addFineGrid(new Cuboid(15, 15, 15, 25, 25, 25), 1); - //gridBuilder->addFineGrid(new Cuboid(17, 17, 17, 23, 23, 23), 2); - - - //gridBuilder->addFineGrid(17.0, 17.0, 17.0, 20.0, 20.0, 20.0, 3); - //gridBuilder->addFineGrid(10.0, 10.0, 10.0, 20.0, 20.0, 20.0, 3); - - - //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_2", 2); - - gridBuilder->buildGrids(); - - gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTestSphere_level_0", 0); - gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTestSphere_level_1", 1); - gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTestSphere_level_2", 2); - - //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTestCuboid_level_0", 0); - //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTestCuboid_level_1", 1); - - //SimulationFileWriter::write("D:/GRIDGENERATION/couplingVF/test/simu/", gridBuilder, FILEFORMAT::ASCII); - - //const uint level = 2; - //gridBuilder->addFineGrid(0.0, 0.0, 0.0, 10.0, 10.0, 10.0, level); - //gridBuilderlevel->setGrids(gridBuilder->getGrids()); - - - //gridBuilder->addGrid(14.4921875, 14.4921875, 14.4921875, 16.5078125, 16.5078125, 16.5078125, 0.015625, "cpu", "D3Q27", false, false, false); - //gridBuilder->addGrid(13.984375, 13.984375, 13.984375, 17.015625, 17.015625, 17.015625, 0.03125, "cpu", "D3Q27", false, false, false); - //gridBuilder->addGrid(13.46875, 13.46875, 13.46875, 17.53125, 17.53125, 17.53125, 0.0625, "cpu", "D3Q27", false, false, false); - //gridBuilder->addGrid(12.4375, 12.4375, 12.4375, 18.5625, 18.5625, 18.5625, 0.125, "gpu", "D3Q27", false, false, false); - //gridBuilder->addGrid(10.375, 10.375, 10.375, 20.625, 20.625, 20.625, 0.25, "gpu", "D3Q27", false, false, false); - //gridBuilder->addGrid(5.25, 5.25, 5.25, 24.75, 24.75, 24.75, 0.5, "gpu", "D3Q27", false, false, false); - //gridBuilder->addGrid(0.0, 0.0, 0.0, 30.0, 30.0, 30.0, 1.0, "gpu", "D3Q27", true, true, true); - - - //gridBuilder->copyDataFromGpu(); - - //gridBuilder->meshGeometry("D:/GRIDGENERATION/STL/circleBinaer.stl", 1); - //gridBuilder->meshGeometry("D:/GRIDGENERATION/STL/circleBinaer.stl", 0); - //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_1", 1); - //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_0", 0); - //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_2", 2); - - SPtr<Parameter> para = Parameter::make(); - SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para, communicator); - //SPtr<GridProvider> gridGenerator = GridProvider::makeGridReader(false, para); - - std::ifstream stream; - stream.open(configPath.c_str(), std::ios::in); - if (stream.fail()) - throw "can not open config file!\n"; - - UPtr<input::Input> input = input::Input::makeInput(stream, "config"); - - setParameters(para, input); - - Simulation sim; - - SPtr<KernelFactory> kernelFactory = KernelFactoryImp::getInstance(); - SPtr<PreProcessorFactory> preProcessorFactory = PreProcessorFactoryImp::getInstance(); - sim.setFactories(kernelFactory, preProcessorFactory); - - SPtr<FileWriter> fileWriter = SPtr<FileWriter>(new FileWriter()); - sim.init(para, gridGenerator, fileWriter); - sim.run(); - sim.free(); -} - - -int main( int argc, char* argv[]) -{ - MPI_Init(&argc, &argv); - std::string str, str2; - if ( argv != NULL ) - { - str = static_cast<std::string>(argv[0]); - if (argc > 1) - { - str2 = static_cast<std::string>(argv[1]); - try - { - multipleLevel(str2); - } - catch (std::exception e) - { - std::cout << e.what() << std::flush; - //MPI_Abort(MPI_COMM_WORLD, -1); - } - } - else - { - std::cout << "Configuration file must be set!: lbmgm <config file>" << std::endl << std::flush; - //MPI_Abort(MPI_COMM_WORLD, -1); - } - } - /* - MPE_Init_log() & MPE_Finish_log() are NOT needed when - liblmpe.a is linked with this program. In that case, - MPI_Init() would have called MPE_Init_log() already. - */ -#if defined( MPI_LOGGING ) - MPE_Init_log(); -#endif - - - -#if defined( MPI_LOGGING ) - if ( argv != NULL ) - MPE_Finish_log( argv[0] ); - if ( str != "" ) - MPE_Finish_log( str.c_str() ); - else - MPE_Finish_log( "TestLog" ); -#endif - - MPI_Finalize(); - return 0; -} diff --git a/apps/gpu/LidDrivenCavity/CMakeLists.txt b/apps/gpu/LidDrivenCavity/CMakeLists.txt deleted file mode 100644 index 108ab3c676e1abf2466f0b7ca61dce2df7eee792..0000000000000000000000000000000000000000 --- a/apps/gpu/LidDrivenCavity/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - - -PROJECT(LidDrivenCavity) - - -vf_add_library(BUILDTYPE binary PRIVATE_LINK basics GridGenerator VirtualFluids_GPU GksMeshAdapter GksGpu FILES LidDrivenCavity.cpp) diff --git a/apps/gpu/LidDrivenCavity/LidDrivenCavity.cpp b/apps/gpu/LidDrivenCavity/LidDrivenCavity.cpp deleted file mode 100644 index 7c1f51f3415e381692f82fcd4822a7b8ca4517f7..0000000000000000000000000000000000000000 --- a/apps/gpu/LidDrivenCavity/LidDrivenCavity.cpp +++ /dev/null @@ -1,370 +0,0 @@ -//======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ -// \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ -// -// This file is part of VirtualFluids. VirtualFluids is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file LidDrivenCavity.cpp -//! \ingroup Applications -//! \author Martin Schoenherr, Stephan Lenz -//======================================================================================= -#define _USE_MATH_DEFINES -#include <math.h> -#include <string> -#include <sstream> -#include <iostream> -#include <stdexcept> -#include <fstream> -#include <exception> -#include <memory> - -////////////////////////////////////////////////////////////////////////// - -#include "Core/DataTypes.h" -#include "PointerDefinitions.h" -#include "Core/LbmOrGks.h" -#include "Core/VectorTypes.h" -#include "Core/Logger/Logger.h" - -////////////////////////////////////////////////////////////////////////// - -#include "GridGenerator/grid/GridBuilder/LevelGridBuilder.h" -#include "GridGenerator/grid/GridBuilder/MultipleGridBuilder.h" -#include "GridGenerator/grid/BoundaryConditions/Side.h" -#include "GridGenerator/grid/GridFactory.h" - -////////////////////////////////////////////////////////////////////////// - -#include "VirtualFluids_GPU/LBM/Simulation.h" -#include "VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h" -#include "VirtualFluids_GPU/DataStructureInitializer/GridProvider.h" -#include "VirtualFluids_GPU/Parameter/Parameter.h" -#include "VirtualFluids_GPU/Output/FileWriter.h" -#include "VirtualFluids_GPU/GPU/CudaMemoryManager.h" -#include "VirtualFluids_GPU/Factories/BoundaryConditionFactory.h" - -////////////////////////////////////////////////////////////////////////// - -#include "GksMeshAdapter/GksMeshAdapter.h" - -#include "GksGpu/DataBase/DataBase.h" -#include "GksGpu/Parameters/Parameters.h" -#include "GksGpu/Initializer/Initializer.h" - -#include "GksGpu/FlowStateData/FlowStateDataConversion.cuh" - -#include "GksGpu/BoundaryConditions/BoundaryCondition.h" -#include "GksGpu/BoundaryConditions/IsothermalWall.h" - -#include "GksGpu/TimeStepping/NestedTimeStep.h" - -#include "GksGpu/Analyzer/CupsAnalyzer.h" -#include "GksGpu/Analyzer/ConvergenceAnalyzer.h" - -#include "GksGpu/CudaUtility/CudaUtility.h" - -#include "GksGpu/Output/VtkWriter.h" - -////////////////////////////////////////////////////////////////////////// - -int main( int argc, char* argv[]) -{ - try - { - ////////////////////////////////////////////////////////////////////////// - // Simulation parameters - ////////////////////////////////////////////////////////////////////////// - std::string path("./output"); - std::string simulationName("LidDrivenCavity"); - - const real L = 1.0; - const real Re = 1000.0; - const real velocity = 1.0; - const real dt = 0.5e-3; - const uint nx = 64; - - const uint timeStepOut = 10000; - const uint timeStepEnd = 250000; - - // switch between LBM and GKS solver here - //LbmOrGks lbmOrGks = GKS; - LbmOrGks lbmOrGks = LBM; - - ////////////////////////////////////////////////////////////////////////// - // setup logger - ////////////////////////////////////////////////////////////////////////// - - logging::Logger::addStream(&std::cout); - logging::Logger::setDebugLevel(logging::Logger::Level::INFO_LOW); - logging::Logger::timeStamp(logging::Logger::ENABLE); - logging::Logger::enablePrintedRankNumbers(logging::Logger::ENABLE); - - ////////////////////////////////////////////////////////////////////////// - // setup gridGenerator - ////////////////////////////////////////////////////////////////////////// - - auto gridFactory = GridFactory::make(); - gridFactory->setGridStrategy(Device::CPU); - auto gridBuilder = MultipleGridBuilder::makeShared(gridFactory); - - ////////////////////////////////////////////////////////////////////////// - // create grid - ////////////////////////////////////////////////////////////////////////// - - real dx = L / real(nx); - - gridBuilder->addCoarseGrid(-0.5 * L, -0.5 * L, -0.5 * L, - 0.5 * L, 0.5 * L, 0.5 * L, dx); - - gridBuilder->setPeriodicBoundaryCondition(false, false, false); - - gridBuilder->buildGrids(lbmOrGks, false); - - ////////////////////////////////////////////////////////////////////////// - // branch between LBM and GKS - ////////////////////////////////////////////////////////////////////////// - - if( lbmOrGks == LBM ) - { - SPtr<Parameter> para = Parameter::make(); - BoundaryConditionFactory bcFactory = BoundaryConditionFactory(); - - ////////////////////////////////////////////////////////////////////////// - // compute parameters in lattice units - ////////////////////////////////////////////////////////////////////////// - - const real velocityLB = velocity * dt / dx; // LB units - - const real vx = velocityLB / sqrt(2.0); // LB units - const real vy = velocityLB / sqrt(2.0); // LB units - - const real viscosityLB = nx * velocityLB / Re; // LB units - - *logging::out << logging::Logger::INFO_HIGH << "velocity [dx/dt] = " << velocityLB << " \n"; - *logging::out << logging::Logger::INFO_HIGH << "viscosity [dx^2/dt] = " << viscosityLB << "\n"; - - ////////////////////////////////////////////////////////////////////////// - // set parameters - ////////////////////////////////////////////////////////////////////////// - - para->setOutputPath( path ); - para->setOutputPrefix( simulationName ); - - para->setPrintFiles(true); - - para->setVelocityLB(velocityLB); - para->setViscosityLB(viscosityLB); - - para->setVelocityRatio(velocity / velocityLB); - - para->setTimestepOut( timeStepOut ); - para->setTimestepEnd( timeStepEnd ); - - ////////////////////////////////////////////////////////////////////////// - // set boundary conditions - ////////////////////////////////////////////////////////////////////////// - - gridBuilder->setNoSlipBoundaryCondition (SideType::PX); - gridBuilder->setNoSlipBoundaryCondition (SideType::MX); - gridBuilder->setNoSlipBoundaryCondition (SideType::PY); - gridBuilder->setNoSlipBoundaryCondition (SideType::MY); - gridBuilder->setVelocityBoundaryCondition(SideType::PZ, vx, vy, 0.0); - gridBuilder->setNoSlipBoundaryCondition (SideType::MZ); - - bcFactory.setNoSlipBoundaryCondition(BoundaryConditionFactory::NoSlipBC::NoSlipBounceBack); - bcFactory.setVelocityBoundaryCondition(BoundaryConditionFactory::VelocityBC::VelocitySimpleBounceBackCompressible); - - ////////////////////////////////////////////////////////////////////////// - // set copy mesh to simulation - ////////////////////////////////////////////////////////////////////////// - - SPtr<CudaMemoryManager> cudaMemoryManager = CudaMemoryManager::make(para); - - SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para, cudaMemoryManager, communicator); - - ////////////////////////////////////////////////////////////////////////// - // run simulation - ////////////////////////////////////////////////////////////////////////// - - Simulation sim; - SPtr<FileWriter> fileWriter = SPtr<FileWriter>(new FileWriter()); - sim.init(para, gridGenerator, fileWriter, cudaMemoryManager); - sim.run(); - sim.free(); - } - else - { - CudaUtility::setCudaDevice(0); - - Parameters parameters; - - ////////////////////////////////////////////////////////////////////////// - // compute remaining parameters - ////////////////////////////////////////////////////////////////////////// - - const real vx = velocity / sqrt(2.0); - const real vy = velocity / sqrt(2.0); - - parameters.K = 2.0; - parameters.Pr = 1.0; - - const real Ma = 0.1; - - real rho = 1.0; - - real cs = velocity / Ma; - real lambda = c1o2 * ( ( parameters.K + 5.0 ) / ( parameters.K + 3.0 ) ) / ( cs * cs ); - - const real mu = velocity * L * rho / Re; - - *logging::out << logging::Logger::INFO_HIGH << "mu = " << mu << " m^2/s\n"; - - *logging::out << logging::Logger::INFO_HIGH << "CFL = " << dt * ( velocity + cs ) / dx << "\n"; - - ////////////////////////////////////////////////////////////////////////// - // set parameters - ////////////////////////////////////////////////////////////////////////// - - parameters.mu = mu; - - parameters.dt = dt; - parameters.dx = dx; - - parameters.lambdaRef = lambda; - - ////////////////////////////////////////////////////////////////////////// - // set copy mesh to simulation - ////////////////////////////////////////////////////////////////////////// - - GksMeshAdapter meshAdapter( gridBuilder ); - - meshAdapter.inputGrid(); - - auto dataBase = std::make_shared<DataBase>( "GPU" ); - - ////////////////////////////////////////////////////////////////////////// - // set boundary conditions - ////////////////////////////////////////////////////////////////////////// - - SPtr<BoundaryCondition> bcLid = std::make_shared<IsothermalWall>( dataBase, Vec3( vx, vy, 0.0 ), lambda, false ); - SPtr<BoundaryCondition> bcWall = std::make_shared<IsothermalWall>( dataBase, Vec3( 0.0, 0.0, 0.0 ), lambda, false ); - - bcLid->findBoundaryCells ( meshAdapter, false, [&](Vec3 center){ return center.z > 0.5 && - center.x > -0.5 && - center.x < 0.5 && - center.y > -0.5 && - center.y < 0.5; } ); - - bcWall->findBoundaryCells( meshAdapter, true, [&](Vec3 center){ return center.x < -0.5 || - center.x > 0.5 || - center.y < -0.5 || - center.y > 0.5 || - center.z < -0.5; } ); - - dataBase->boundaryConditions.push_back( bcLid ); - dataBase->boundaryConditions.push_back( bcWall ); - - ////////////////////////////////////////////////////////////////////////// - // set initial condition and upload mesh and initial condition to GPGPU - ////////////////////////////////////////////////////////////////////////// - - dataBase->setMesh( meshAdapter ); - - Initializer::interpret(dataBase, [&] ( Vec3 cellCenter ) -> ConservedVariables { - - return toConservedVariables( PrimitiveVariables( rho, 0.0, 0.0, 0.0, lambda ), parameters.K ); - }); - - dataBase->copyDataHostToDevice(); - - Initializer::initializeDataUpdate(dataBase); - - VtkWriter::write( dataBase, parameters, path + "/" + simulationName + "_0" ); - - ////////////////////////////////////////////////////////////////////////// - // set analyzers - ////////////////////////////////////////////////////////////////////////// - - CupsAnalyzer cupsAnalyzer( dataBase, false, 60.0, true, 10000 ); - - ConvergenceAnalyzer convergenceAnalyzer( dataBase, 10000 ); - - cupsAnalyzer.start(); - - ////////////////////////////////////////////////////////////////////////// - // run simulation - ////////////////////////////////////////////////////////////////////////// - - for( uint iter = 1; iter <= timeStepEnd; iter++ ) - { - TimeStepping::nestedTimeStep(dataBase, parameters, 0); - - if( iter % timeStepOut == 0 ) - { - dataBase->copyDataDeviceToHost(); - - VtkWriter::write( dataBase, parameters, path + "/" + simulationName + "_" + std::to_string( iter ) ); - } - - int crashCellIndex = dataBase->getCrashCellIndex(); - if( crashCellIndex >= 0 ) - { - *logging::out << logging::Logger::LOGGER_ERROR << "Simulation crashed at CellIndex = " << crashCellIndex << "\n"; - dataBase->copyDataDeviceToHost(); - VtkWriter::write( dataBase, parameters, path + "/" + simulationName + "_" + std::to_string( iter ) ); - - break; - } - - dataBase->getCrashCellIndex(); - - cupsAnalyzer.run( iter, parameters.dt ); - - convergenceAnalyzer.run( iter ); - } - } - } - catch (const std::bad_alloc e) - { - - *logging::out << logging::Logger::LOGGER_ERROR << "Bad Alloc:" << e.what() << "\n"; - } - catch (const std::exception& e) - { - - *logging::out << logging::Logger::LOGGER_ERROR << e.what() << "\n"; - } - catch (std::string& s) - { - - *logging::out << logging::Logger::LOGGER_ERROR << s << "\n"; - } - catch (...) - { - *logging::out << logging::Logger::LOGGER_ERROR << "Unknown exception!\n"; - } - - return 0; -}