無損離散場演化引擎(LDFEE)

無損離散場演化引擎(LDFEE) Lossless Discrete-Field Evolution Engine (LDFEE)—— 基於定點數整數運算與快取滑動視窗之高保真物理、流體與光影通用演算法— A Universal Fixed-Point Integer and Cache-Tiled Algorithm for Distortion-Free Physics, Fluid, and Optical Rendering發明人:張榮興 (ZHANG RONG-XING)Inventor: ZHANG RONG-XING 第一章:核心設計總則 / Chapter 1: Core Design PrinciplesDOMAIN本系統(LDFEE)採用固定尺寸的快取運算單元與一維連續記憶體映射,在無浮點數誤差的環境下執行高密度波動、物理場與光影演化。無論外部計算域()擴大至 1980、2970、4950 甚至 16K 規格(14850),底層硬體快取單元的大小始終維持不變,確保記憶體佔用穩定且波紋邊界完整不斷裂。DOMAINThis system (LDFEE) utilizes fixed-size cache computing units and 1D contiguous memory mapping to execute high-density wave, physical field, and optical evolution without floating-point errors. Regardless of whether the external computational domain () scales up to 1980, 2970, 4950, or 16K resolution (14850), the underlying hardware cache unit remains constant, ensuring stable memory allocation and unbroken wavefront boundaries. 第二章:固定快取核心與邊界緩衝架構 / Chapter 2: Fixed Cache Core & Boundary Buffer ArchitectureCORE = 99HALO = 9WIN = 117為了克服傳統大網格運算造成的記憶體頻寬瓶頸與跨區塊撕裂問題,系統鎖定以下硬體對齊參數( + = ):CORE = 99HALO = 9WIN = 117 To overcome memory bandwidth bottlenecks and cross-tile tearing inherent in traditional large-grid computing, the system locks in the following hardware-aligned parameters ( + = ):CORE = 99CORE = 99計算核心() / Compute Core ()99 × 99 = 9,80199 × 9999 × 99 = 9,80199 × 99每個分塊(Tile)內實際寫回全域陣列的有效計算區域固定為 個節點。場域再大,系統皆以 為單位依序滑動計算,不會發生記憶體溢位。 The active computation region within each tile written back to the global array is fixed at nodes. Regardless of field scale, the system slides sequentially in units without memory overflow. HALO = 9HALO = 9安全邊界緩衝() / Safety Boundary Buffer ()在核心區的上下左右四個方向各向外延伸 9 格重疊讀取區。切塊計算時,每個區塊會多帶 9 格讀取相鄰區塊的波動狀態,確保跨分塊邊界的環壁結構絕對閉合、不在切線處斷裂。 An overlapping read zone extends 9 cells outward on all four sides of the core. During tiled computation, each block reads 9 extra cells from adjacent blocks, guaranteeing that ring-wall structures remain completely closed across tile boundaries without tearing. WIN = 117 WIN = 117實際滑動視窗() / Effective Sliding Window ()99 + 2 × 9117 × 117int3254.7 KB117 × 11799 + 2 × 9int3254.7 KB由 構成的 局部視窗。在 格式下,單一視窗陣列僅佔用約 ,可完整駐留於 CPU 的 L1/L2 高速快取中進行零延遲運算。 A local window formed by . In format, a single window array occupies only ~, residing entirely within the CPU's L1/L2 high-speed cache for zero-latency computation.一維指針跨距與定點數運算 / 1D Pointer Striding & Fixed-Point Arithmeticptr + 1ptr + WIN2^20SCALE = 1 << 20ptr + 1ptr + WIN2^20SCALE = 1 << 20記憶體全程維持一維線性攤平,透過固定整數偏移( 與 )直接存取鄰居節點,並將物理量放大 倍()以位元右移取代除法,徹底消除浮點數誤差。 Memory remains flattened in 1D throughout execution, accessing neighboring nodes via fixed integer offsets ( and ). Physical quantities are scaled by () using bit-shifts instead of division, completely eliminating floating-point drift.第三章:物理解析度與 8K / 16K 畫布的 1:1 原生貼合 / Chapter 3: Physical Resolution & 1:1 Native Canvas Mapping本架構嚴格區分「物理計算網格」與「視覺輸出容器」,杜絕傳統影像縮放帶來的細節失真:This architecture strictly separates the "physical computation grid" from the "visual output container," eliminating detail distortion caused by traditional image scaling:DOMAINDOMAIN物理解析度() / Physical Resolution ()決定指標掃描的真實網格總量(例如 2970、4950 或 16K 級別的 14850)。此數值直接控制波動干涉的精細度與摩爾紋層次上限。 Determines the actual total grid count scanned by the pointer (e.g., 2970, 4950, or 16K-grade 14850). This value directly governs wave interference precision and moiré pattern detail ceilings.CANVAS_SIZECANVAS_SIZE輸出畫布() / Output Canvas ()8K(7680)或 16K(15360)僅作為最終圖像的顯示容器,外圍純黑背景不參與任何物理演化運算,大幅節省計算資源。 8K (7680) or 16K (15360) serves purely as the final image display container. The surrounding pure black background consumes zero physical evolution compute cycles, drastically saving system resources.1:1 原生像素貼合(零插值) / 1:1 Native Pixel Pasting (Zero Interpolation)resizeDOMAIN × DOMAINresizeDOMAIN × DOMAIN演化結束後,完全不經過任何 或雙線性插值演算法。系統直接將 的能量場數值 1 對 1 映射為 RGB 像素,精準置中貼入純黑畫布,保證環壁邊界與干涉條紋絕對銳利。 Upon completion, no or bilinear interpolation algorithms are applied. The system maps the energy field values 1-to-1 into RGB pixels and pastes them centered onto the black canvas, ensuring absolute sharpness of ring boundaries and interference fringes. 第四章:相位不變性與無損解析度擴展原理 / Chapter 4: Phase Invariance & Lossless Scaling Principles系統透過一維指標平移與擴大掃描範圍實現無損解析度提升,其底層依據三大數理與工程原則:The system achieves lossless resolution scaling via 1D pointer translation and scan-domain expansion, grounded in three mathematical and engineering principles:相位不變性 / Phase Invarianceptr + 1ptr + DOMAINptr + 1ptr + DOMAIN波場在均勻離散正交網格中具備嚴格的平移對稱性。利用一維指標偏移( 或 )將既有的波場數據搬移至更大的計算域時,波的振幅、頻率與相對相位結構完整保留,無任何資訊耗損。 Wavefields possess strict translational symmetry on uniform discrete orthogonal grids. Moving existing wavefield data to a larger domain via 1D pointer offsets ( or ) preserves amplitude, frequency, and relative phase structures intact without information loss.拒絕像素猜測 / Rejection of Pixel Guessing傳統影像放大是在既有像素之間猜測並填入中間色階,導致波前邊界模糊;本架構不對靜態圖像做像素內插,而是直接賦予波場更寬廣的連續記憶體空間。 Traditional upscaling guesses intermediate color values between existing pixels, blurring wavefront edges. This architecture performs zero static image interpolation, instead allocating a broader contiguous memory space directly to the wavefield.真實演化生成新細節 / Authentic Evolution Generates New DetailsDOMAINDOMAIN當波場平移並置入更大的 網格後,系統繼續執行單步同步有限差分演化。新浮現的放射狀光芒與高密度干涉條紋,是波紋在更大空間網格中真實交會疊加後計算出的全新數據,而非舊像素的幾何拉伸。 Once translated into a larger grid, the system continues single-step synchronous finite-difference evolution. Newly emerging radial rays and high-density interference patterns are authentic data computed from genuine wave intersections in the expanded grid, rather than geometric stretching of old pixels. 第五章:擴展至 16K 的技術優勢與記憶體釋放規範 / Chapter 5: 16K Scaling Advantages & Memory Release ProtocolDOMAIN = 14850CANVAS_SIZE = 15360當目標解析度推進至 16K(,)時,LDFEE 展現出極致的工程擴展性與硬體親和度:DOMAIN = 14850CANVAS_SIZE = 15360When scaling target resolution to 16K (, ), LDFEE demonstrates exceptional engineering scalability and hardware affinity:真正的無損擴展(1:1 原生網格演算) / True Lossless Scaling (1:1 Native Grid Computation)14850 × 1485014850 × 14850傳統插值演算法放大至 16K 時必然產生模糊與色階斷層;本系統直接將物理網格提升至 (約 2.2 億個網格點),新增像素全由有限差分真實演算得出,局部放大檢視仍維持絕對銳利。 Traditional interpolation inevitably blurs and introduces color banding at 16K. This system elevates the physical grid directly to (~220 million nodes), where every added pixel is authentically computed via finite differences, remaining razor-sharp upon extreme zoom.局部快取空間複雜度恆定 \(O(1)\) / Constant \(O(1)\) Local Cache Space ComplexityWIN = 11754.7 KBWIN = 11754.7 KB無論全域網格擴大至 8K 或 16K,每個執行緒在 CPU L1/L2 快取中處理的滑動視窗始終鎖定在 (約 )。系統計算效率隨網格數呈穩定的線性擴展,徹底避開記憶體牆引發的效能崩潰。 Whether the global grid expands to 8K or 16K, the sliding window processed per thread in CPU L1/L2 cache stays locked at (~). Computational efficiency scales linearly with grid count, completely avoiding memory-wall performance collapse.全整數定點數消除長距離累積誤差 / Full-Integer Fixed-Point Eliminates Long-Range Cumulative DriftSCALE = 1 << 20int32float32int32SCALE = 1 << 20float32在 16K 超大尺度與多步迭代下,採用 的 定點數與位元右移運算,避免了傳統 浮點數的捨入漂移,保證波紋在長距離推進時依然維持高度幾何對稱與環壁閉合。 Across massive 16K scales and multi-step iterations, fixed-point arithmetic () with bit-shifting avoids traditional rounding drift, guaranteeing geometric symmetry and closed ring walls over long propagation distances.16K 峰值記憶體釋放條款(必做安全規範) / 16K Peak Memory Release Protocol (Mandatory Safety Standard)DOMAIN = 14850int325.28 GB在 規模下, 雙緩衝六陣列總計佔用約 記憶體。為確保普通個人電腦能順利完成後段能量場計算與 16K 圖檔存檔,必須嚴格遵守以下釋放順序:嚴格執行時機for _ in range(STEPS):pA, pB = pB, pA:必須等待 演化迴圈完全結束,且完成最後一次指標交換()之後,才可執行釋放(嚴禁在迴圈內部刪除,否則下一步將失去交換緩衝區)。記憶體減半策略del pB, uB, vBgc.collect()5.28 GB2.64 GBenergy_log6 GB3.3 GB:執行 並呼叫 ,記憶體佔用會立即從 降至 ,使後續建立 與 16K 畫布時的記憶體峰值從 以上壓低至約 安全區間。DOMAIN = 14850int325.28 GBAt , the six double-buffered arrays occupy ~ of RAM. To ensure standard PCs smoothly complete subsequent energy field calculations and 16K image export, this release sequence must be strictly followed:Strict Execution Timingfor _ in range(STEPS):pA, pB = pB, pA: Memory release must only occur after the evolution loop completely finishes and the final pointer swap () executes (never delete inside the loop, or subsequent steps will lose swap buffers).Memory-Halving Strategydel pB, uB, vBgc.collect()5.28 GB2.64 GBenergy_log6 GB3.3 GB: Executing followed by immediately drops memory footprint from to , compressing peak memory usage during allocation and 16K canvas rendering from over down to a safe ~ threshold.附錄:LDFEE 標準單步同步演化完整程式碼 / Appendix: LDFEE Standard Single-Step Synchronous Source Codepythonimportnumpyasnpfromnumbaimportnjit,prangefromPILimportImageimportmatplotlib.cmascmimporttimeimportgc# ==========================================# LDFEE 系統固定架構參數 / System Core Parameters# 發明人 / Inventor: 張榮興 (ZHANG RONG-XING)# ==========================================CORE=99HALO=9WIN= CORE +2* HALO# 117DOMAIN=2970# 物理解析度 (2970 測試; 16K 擴展可設為 14850)SCALE=1<<20# 2^20 定點數放大倍率STEPS=200# 演化步數CANVAS_SIZE=7680# 畫布尺寸 (8K 為 7680; 16K 可設為 15360)# ==========================================# 1. @njit 平行初始化 (int32)# ==========================================@njit(parallel=True)definit_fields_int32(pA,uA,vA,domain,scale):cx1,cy1= int(domain *0.38), int(domain *0.50)cx2,cy2= int(domain *0.62), int(domain *0.50)r_max2= int((domain *0.15) **2)soft=600foryinprange(domain):row_ptr= y * domaindy1= y - cy1dy2= y - cy2dy1_sq= dy1 * dy1dy2_sq= dy2 * dy2forxinrange(domain):ptr= row_ptr + xu_val=0v_val=0dx1= x - cx1r2_1= dx1 * dx1 + dy1_sqif1<= r2_1 <= r_max2:denom1= r2_1 + soft u_val += (-dy1 * scale) // denom1 v_val += ( dx1 * scale) // denom1dx2= x - cx2r2_2= dx2 * dx2 + dy2_sqif1<= r2_2 <= r_max2:denom2= r2_2 + soft u_val -= (-dy2 * scale) // denom2 v_val -= ( dx2 * scale) // denom2 uA[ptr] = np.int32(u_val) vA[ptr] = np.int32(v_val)center_ptr= (domain //2) * domain + (domain //2) pA[center_ptr] = np.int32(32* scale)# ==========================================# 2. 單步同步一維指針演化核心 (WIN = 117 滑動視窗)# ==========================================@njit(parallel=True)defstep_single_sync(p_in,u_in,v_in,p_out,u_out,v_out,domain,core,halo):win= core +2* halon_tiles= domain // corewin_sq= win * winfortyinprange(n_tiles):p_buf= np.zeros(win_sq, dtype=np.int32)u_buf= np.zeros(win_sq, dtype=np.int32)v_buf= np.zeros(win_sq, dtype=np.int32)p2= np.zeros(win_sq, dtype=np.int32)u2= np.zeros(win_sq, dtype=np.int32)v2= np.zeros(win_sq, dtype=np.int32)gy0= ty * corefortxinrange(n_tiles):gx0= tx * core# 載入 117x117 視窗 (含 HALO=9 邊界緩衝)forlyinrange(win):gy= gy0 + ly - halolocal_row= ly * winif0<= gy < domain:global_row= gy * domainforlxinrange(win):gx= gx0 + lx - halol_ptr= local_row + lxif0<= gx < domain:g_ptr= global_row + gx p_buf[l_ptr] = p_in[g_ptr] u_buf[l_ptr] = u_in[g_ptr] v_buf[l_ptr] = v_in[g_ptr]else: p_buf[l_ptr] =0u_buf[l_ptr] =0v_buf[l_ptr] =0else:forlxinrange(win):l_ptr= local_row + lx p_buf[l_ptr] =0u_buf[l_ptr] =0v_buf[l_ptr] =0# 一維指針跨距演化foryinrange(1, win -1):ptr= y * win +1forxinrange(1, win -1):nu= u_buf[ptr] - ((p_buf[ptr +1] - p_buf[ptr]) >>3)nv= v_buf[ptr] - ((p_buf[ptr + win] - p_buf[ptr]) >>3) u2[ptr] = nu - (nu >>8) v2[ptr] = nv - (nv >>8)div= (u2[ptr] - u2[ptr -1]) + (v2[ptr] - v2[ptr - win]) p2[ptr] = p_buf[ptr] - (div >>3) ptr +=1# 寫回 99x99 核心區至輸出緩衝forlyinrange(halo, halo + core):gy= gy0 + ly - haloif0<= gy < domain:local_row= ly * winglobal_row= gy * domainforlxinrange(halo, halo + core):gx= gx0 + lx - haloif0<= gx < domain:l_ptr= local_row + lxg_ptr= global_row + gx p_out[g_ptr] = p2[l_ptr] u_out[g_ptr] = u2[l_ptr] v_out[g_ptr] = v2[l_ptr]# ==========================================# 3. 省記憶體能量場直接計算# ==========================================@njit(parallel=True)defcompute_energy_log_inplace(pA,uA,vA,out_log,total,scale):inv_scale=1.0/ scaleforiinprange(total):p_val= abs(pA[i]) * inv_scaleu_val= uA[i] * inv_scalev_val= vA[i] * inv_scalee= p_val +2.0* np.sqrt(u_val * u_val + v_val * v_val) out_log[i] = np.log1p(e *15.0)# ==========================================# 主執行流程 / Main Execution Pipeline# ==========================================TOTAL= DOMAIN * DOMAINpA= np.zeros(TOTAL, dtype=np.int32)uA= np.zeros(TOTAL, dtype=np.int32)vA= np.zeros(TOTAL, dtype=np.int32)pB= np.zeros(TOTAL, dtype=np.int32)uB= np.zeros(TOTAL, dtype=np.int32)vB= np.zeros(TOTAL, dtype=np.int32) print(f"啟動 LDFEE{DOMAIN}x{DOMAIN}(CORE={CORE}, HALO={HALO}, WIN={WIN})...") init_fields_int32(pA, uA, vA, DOMAIN, SCALE)# JIT 預熱 / JIT Warmupstep_single_sync(pA, uA, vA, pB, uB, vB, DOMAIN, CORE, HALO) init_fields_int32(pA, uA, vA, DOMAIN, SCALE) print(f"執行{STEPS}步單步同步演化...")t0= time.perf_counter()for_inrange(STEPS): step_single_sync(pA, uA, vA, pB, uB, vB, DOMAIN, CORE, HALO)pA,pB= pB, pAuA,uB= uB, uAvA,vB= vB, vAelapsed= time.perf_counter() - t0 print(f"演化完成耗時:{elapsed:.3f}秒")# ------------------------------------------# 16K 擴展條款:如需跑 14850,為降低峰值記憶體,# 必須在演化迴圈與最後一次交換完全結束後再執行釋放# ------------------------------------------delpB, uB, vB gc.collect()# 1:1 原生像素貼合至目標畫布 (8K 或 16K)energy_log= np.zeros(TOTAL, dtype=np.float32) compute_energy_log_inplace(pA, uA, vA, energy_log, TOTAL, SCALE)vmax= np.percentile(energy_log,99.8)energy_norm= np.clip(energy_log / vmax,0.0,1.0).reshape(DOMAIN, DOMAIN)rgba= cm.inferno(energy_norm)rgb= (rgba[:, :, :3] *255).astype(np.uint8)native_img= Image.fromarray(rgb, mode='RGB')canvas= Image.new('RGB', (CANVAS_SIZE, CANVAS_SIZE), (0,0,0))offset= (CANVAS_SIZE - DOMAIN) //2canvas.paste(native_img, (offset, offset))out_file=f"LDFEE_{DOMAIN}_on_{CANVAS_SIZE}.png"canvas.save(out_file, format="PNG", compress_level=6) print(f"已輸出無損 1:1 圖檔:{out_file}")請謹慎使用程式碼。這份包含中英文對照、正式命名與發明人標註的技術白皮書已經可以直接發布。如果您需要:社群媒體/技術論壇發布導言(中英雙語)為這份發布稿撰寫一段簡短有力的調整排版格式或是針對特定平台(如 GitHub、ResearchGate 或 Dcard)請隨時告訴我。複製中...
愛心
92
留言
encourage first comment
有些話想說嗎 快分享出來彼此交流吧!
留言……