public void MyRunTest(ISF _isf) { Init(_isf, 1024); var compute = fft.LoadJson_Float4ComputeBuffer("test/part.itr01.json"); fft.ExportFloat4(compute, "test/part.itr0.reflect.json"); Texture3D text; var velocity = fft.LoadJson3D_Float4("test/isf.velo.json", out text); var grid_size = isf.GetGridSize(); Debug.Log(grid_size.ToString()); CS.SetVector("grid_size", grid_size); CS.SetInts("grids", isf.GetGrids()); CS.SetFloat("dt", isf.estimate_dt); int kernel = kernelEnumlateParticle[2]; CS.SetTexture(kernel, "Velocity", velocity); CS.SetBuffer(kernel, "ParticlePostion", compute); CS.Dispatch(kernel, 1, 1, 1); fft.ExportFloat4(compute, "test/part.itr1.json"); }
public void GroupInit(ISF _isf) { DataManaging = ManagingMode.Grouped; InitComputeShader(_isf); InitGeometries(); }
public void Init(ISF _isf, int _MaxN = -1, int _CurN = -1) { DataManaging = ManagingMode.CenterPool; if (_MaxN > 0) { MaxN = _MaxN; } if (_CurN > 0) { CurN = _CurN; } InitComputeShader(_isf); int n = MaxN / ChunkSize; for (int i = 0; i < n; ++i) { ParticlePostionList.Add(new ComputeBuffer(ChunkSize, 4 * sizeof(float))); } if (MaxN % ChunkSize != 0) { ParticlePostionList.Add(new ComputeBuffer(ChunkSize, 4 * sizeof(float))); } InitGeometries(); // ParticlePostion = new ComputeBuffer(MaxN, 4 * sizeof(float)); }
public void Initialize(ComputeShader _CS, ISF _isf) { CS = _CS; isf = _isf; kernelCreateNozzleMask = CS.FindKernel("CreateNozzleMask"); kernelNozzleUpdatePsi = CS.FindKernel("NozzleUpdatePsi"); }
public void InitComputeShader(ISF _isf) { isf = _isf; fft = isf.fft; kernelEnumlateParticle[(int)(GPUThreads.T1024 & GPUThreads.T_INDEX)] = CS.FindKernel("EnumlateParticle"); kernelEnumlateParticle[(int)(GPUThreads.T256 & GPUThreads.T_INDEX)] = CS.FindKernel("EnumlateParticle256"); kernelEnumlateParticle[(int)(GPUThreads.T64 & GPUThreads.T_INDEX)] = CS.FindKernel("EnumlateParticle64"); }
/// <summary> /// Removing oldest cache file (file, which last access time is smaller) /// </summary> private bool RemoveOldestCacheFile() { if (_lastAccessTimeDictionary.Count == 0) { return(false); } var oldestCacheFilePath = _lastAccessTimeDictionary.Aggregate((pair1, pair2) => (pair1.Value < pair2.Value)? pair1 : pair2).Key; if (String.IsNullOrEmpty(oldestCacheFilePath)) { return(false); } try { long fileSizeInBytes; using (var file = ISF.OpenFile(oldestCacheFilePath, FileMode.Open, FileAccess.Read)) { fileSizeInBytes = file.Length; } try { ISF.DeleteFile(oldestCacheFilePath); _lastAccessTimeDictionary.Remove(oldestCacheFilePath); CurrentCacheSizeInBytes -= fileSizeInBytes; // Updating current cache size JetImageLoader.Log("[delete] cache file " + oldestCacheFilePath); return(true); } catch { JetImageLoader.Log("[error] can not delete oldest cache file: " + oldestCacheFilePath); } } catch { JetImageLoader.Log("[error] can not get olders cache's file size: " + oldestCacheFilePath); } return(false); }
private async void LoadChapterInst(Chapter C) { BookInstruction BkInst = ( BookInstruction )CurrentBook ?? new BookInstruction(C.Book); XRegistry Settings = SpiderBook.GetSettings(BkInst.ZoneId, BkInst.ZItemId); EpInstruction Inst = new EpInstruction(C, Settings); IEnumerable <ProcConvoy> Convoys = await Inst.Process(); string ChapterText = ""; foreach (ProcConvoy Konvoi in Convoys) { ProcConvoy Convoy = ProcManager.TracePackage( Konvoi , (d, c) => c.Payload is IEnumerable <IStorageFile> || c.Payload is IStorageFile ); if (Convoy == null) { continue; } if (Convoy.Payload is IStorageFile) { ChapterText += await(( IStorageFile )Convoy.Payload).ReadString(); } else if (Convoy.Payload is IEnumerable <IStorageFile> ) { foreach (IStorageFile ISF in ((IEnumerable <IStorageFile>)Convoy.Payload)) { Shared.LoadMessage("MergingContents", ISF.Name); ChapterText += (await ISF.ReadString()) + "\n"; } } } await new ContentParser().ParseAsync(ChapterText, C); OnComplete(C); }
private void BeginCountCurrentCacheSize() { Task.Factory.StartNew(() => { // Pattern to match all innerFiles and innerDirectories inside absoluteDirPath var filesAndDirectoriesPattern = CacheDirectory + @"\*"; string[] cacheFileNames; try { cacheFileNames = ISF.GetFileNames(Path.Combine(CacheDirectory, filesAndDirectoriesPattern)); } catch { return; } long cacheSizeInBytes = 0; foreach (var cacheFileName in cacheFileNames) { var fullCacheFilePath = Path.Combine(CacheDirectory, cacheFileName); try { using (var file = ISF.OpenFile(fullCacheFilePath, FileMode.Open, FileAccess.Read)) { cacheSizeInBytes += file.Length; _lastAccessTimeDictionary.Add(fullCacheFilePath, DateTimeUtil.ConvertDateTimeToMillis(ISF.GetLastAccessTime(fullCacheFilePath).DateTime)); } } catch { JetImageLoader.Log("[error] can not get cache's file size: " + fullCacheFilePath); } } CurrentCacheSizeInBytes += cacheSizeInBytes; // Updating current cache size }); }
static void Main(string[] args) { //PARAMETERS int[] vol_size = { 10, 5, 5 }; // box size int[] vol_res = { 64, 32, 32 }; // volume resolution float hbar = (float)0.1; // Planck constant float dt = 1 / (float)24; // time step int tmax = 85; float[] background_vel = { (float)-0.2, 0, 0 }; float r1 = (float)1.5; float r2 = (float)0.9; float[] n1 = { -1, 0, 0 }; float[] n2 = { -1, 0, 0 }; float[] cen1 = { vol_size[0] / 2f, vol_size[1] / 2f, vol_size[2] / 2f }; float[] cen2 = { vol_size[0] / 2f, vol_size[1] / 2f, vol_size[2] / 2f }; int n_particles = 10000; //INITIALISATION ISF.Init(vol_size, vol_res, hbar, dt); Particles.init(n_particles); //init psi float[] kvec = { background_vel[0] / hbar, background_vel[1] / hbar, background_vel[2] / hbar }; float phase; var tmp1 = new cuFloatComplex[ISF.properties.resx, ISF.properties.resy, ISF.properties.resz]; var tmp2 = new cuFloatComplex[ISF.properties.resx, ISF.properties.resy, ISF.properties.resz]; Complex tmp; for (int i = 0; i < vol_res[0]; i++) { for (int j = 0; j < vol_res[1]; j++) { for (int k = 0; k < vol_res[2]; k++) { phase = kvec[0] * ISF.properties.px[i, j, k] + kvec[1] * ISF.properties.py[i, j, k] + kvec[2] * ISF.properties.pz[i, j, k]; tmp = Complex.Exp(Complex.ImaginaryOne * phase); tmp1[i, j, k] = new cuFloatComplex((float)tmp.Real, (float)tmp.Imaginary); tmp2[i, j, k] = new cuFloatComplex((float)(tmp.Real * 0.01), (float)(tmp.Imaginary * 0.01)); } } } float d = ISF.properties.dx * 5; ISF.add_circle(tmp1, cen1, n1, r1, d); ISF.add_circle(tmp1, cen2, n2, r2, d); ISF.psi1.CopyToDevice(tmp1); ISF.psi2.CopyToDevice(tmp2); ISF.Normalize(); ISF.PressureProject(); //init particles var x = new float[n_particles]; var y = new float[n_particles]; var z = new float[n_particles]; Random rnd = new Random(); for (int i = 0; i < n_particles; i++) { y[i] = (float)(rnd.NextDouble() * 4 + 0.5); z[i] = (float)(rnd.NextDouble() * 4 + 0.5); x[i] = 5; } Particles.add_particles(x, y, z, n_particles); Velocity vel = new Velocity(ISF.properties.resx, ISF.properties.resy, ISF.properties.resz); //MAIN ITERATION Console.Out.WriteLine("Start"); int itermax = (int)Math.Ceiling(tmax / dt); for (int i = 0; i < 100; i++) { //incompressible Schroedinger flow ISF.update_space(); //particle update ISF.update_velocities(vel); Particles.calculate_movement(vel); } float[] xx = Particles.x; float[] yy = Particles.y; float[] zz = Particles.z; for (int i = 0; i < 20; i++) { Console.Out.WriteLine(xx[i] + " " + yy[i] + " " + zz[i]); } }