[{"data":1,"prerenderedAt":372},["ShallowReactive",2],{"content-query-8gtEPt3wIJ":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"category":13,"body":14,"_type":366,"_id":367,"_source":368,"_file":369,"_stem":370,"_extension":371},"/technology-blogs/en/2716","en",false,"","Idea Sharing: AD_FDTD, MindSpore-Based Device-to-Device Differential Electromagnetic Solver","MindSpore and Huawei Noah's Ark Laboratory have jointly built a device-to-device differential electromagnetic solver of finite-difference time-domain (FDTD).","2023-02-02","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/f4c8e92dac5048c8bed22a149a61da71.png","technology-blogs","Practices",{"type":15,"children":16,"toc":363},"root",[17,25,35,40,45,50,58,63,71,76,83,88,101,109,114,127,138,146,151,156,161,168,175,180,185,195,200,208,213,221,226,233,241,246,253,258,263,270,278,290,295,302,307,312,320,327,335,340,348,353,358],{"type":18,"tag":19,"props":20,"children":22},"element","h1",{"id":21},"idea-sharing-ad_fdtd-mindspore-based-device-to-device-differential-electromagnetic-solver",[23],{"type":24,"value":8},"text",{"type":18,"tag":26,"props":27,"children":28},"p",{},[29],{"type":18,"tag":30,"props":31,"children":32},"strong",{},[33],{"type":24,"value":34},"Background",{"type":18,"tag":26,"props":36,"children":37},{},[38],{"type":24,"value":39},"MindSpore and Huawei Noah's Ark Laboratory have jointly built a device-to-device differential electromagnetic solver of finite-difference time-domain (FDTD), whose performance has been verified in products such as patch antennas, patch filters, and 2D inverse electromagnetic scattering.",{"type":18,"tag":26,"props":41,"children":42},{},[43],{"type":24,"value":44},"Proposed by K.S.Yee in 1966, FDTD performs discrete and iterative calculation on the E-field and H-field of an electromagnetic field by alternative sampling in space and time. After more than five decades of development, FDTD has become a well-established numerical method. It is widely used in various scenarios, including the analysis of radiation antennas, research on microwave devices and waveguide structures, cross-sectional calculation of scattering and radar, analysis of periodic structures, electronics packaging, and propagation and scattering of nuclear electromagnetic pulses. Nonetheless, traditional numerical methods still face challenges like low computation efficiency and complex computation process, especially in inverse electromagnetic waves.",{"type":18,"tag":26,"props":46,"children":47},{},[48],{"type":24,"value":49},"With the development of AI technologies, AI converged computing (integration of AI and traditional numerical methods) is expected to solve the preceding problems. With this context, we've constructed a device-to-device differential electromagnetic solver AD_FDTD based on MindSpore. This solver is able to rewrite an FDTD forward solution process using MindSpore's neural network operators. It can also optimize medium parameters for inverse electromagnetic waves using MindSpore's automatic differentiation capability. In the future, it is anticipated that some complex solution processes in FDTD will be replaced by AI agent models. Device-to-device differential electromagnetic solvers provide more exploration and development possibilities for electromagnetic technologies.",{"type":18,"tag":26,"props":51,"children":52},{},[53],{"type":18,"tag":30,"props":54,"children":55},{},[56],{"type":24,"value":57},"1. Principle of Differential FDTD Solver",{"type":18,"tag":26,"props":59,"children":60},{},[61],{"type":24,"value":62},"The time-domain Maxwell equations can be presented in the following formats:",{"type":18,"tag":26,"props":64,"children":65},{},[66],{"type":18,"tag":67,"props":68,"children":70},"img",{"alt":7,"src":69},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/f1d6fe8057e34692a045d9e84e38e545.png",[],{"type":18,"tag":26,"props":72,"children":73},{},[74],{"type":24,"value":75},"Numerical solution requires us to discretize the equations by processing partial time derivatives first. FDTD alternately updates electric fields and magnetic fields in a leapfrog manner, which generates the following time-stepping formats:",{"type":18,"tag":26,"props":77,"children":78},{},[79],{"type":18,"tag":67,"props":80,"children":82},{"alt":7,"src":81},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/19b3a02d4b0f43c2a164aff29a3160b5.png",[],{"type":18,"tag":26,"props":84,"children":85},{},[86],{"type":24,"value":87},"A process of updating electromagnetic fields according to the foregoing formulas can be seen as a recurrent neural network (RNN).",{"type":18,"tag":26,"props":89,"children":90},{},[91,95,97],{"type":18,"tag":67,"props":92,"children":94},{"alt":7,"src":93},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/200be4d5f2504ed7aadda83c06aebfbf.png",[],{"type":24,"value":96}," ",{"type":18,"tag":67,"props":98,"children":100},{"alt":7,"src":99},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/be27a42f42ef400594a380de2a7467ea.png",[],{"type":18,"tag":26,"props":102,"children":103},{},[104],{"type":18,"tag":30,"props":105,"children":106},{},[107],{"type":24,"value":108},"2. Application Cases",{"type":18,"tag":26,"props":110,"children":111},{},[112],{"type":24,"value":113},"This part describes features and usage of the solver through cases of forward simulation and reverse optimization.",{"type":18,"tag":26,"props":115,"children":116},{},[117,119],{"type":24,"value":118},"Case: ",{"type":18,"tag":120,"props":121,"children":125},"a",{"href":122,"rel":123},"https://www.mindspore.cn/mindelec/docs/en/master/AD_FDTD.html",[124],"nofollow",[126],{"type":24,"value":122},{"type":18,"tag":26,"props":128,"children":129},{},[130,132],{"type":24,"value":131},"Code: ",{"type":18,"tag":120,"props":133,"children":136},{"href":134,"rel":135},"https://gitee.com/mindspore/mindscience/tree/master/MindElec/examples/AD_FDTD",[124],[137],{"type":24,"value":134},{"type":18,"tag":26,"props":139,"children":140},{},[141],{"type":18,"tag":30,"props":142,"children":143},{},[144],{"type":24,"value":145},"2.1 Forward Simulation: S-parameter Simulation of a Patch Antenna",{"type":18,"tag":26,"props":147,"children":148},{},[149],{"type":24,"value":150},"Electromagnetic simulation is widely used in the product design processes of antennas, chips, and mobile phones. The goal is to obtain the transmission characteristics (such as scattering parameters and electromagnetic fields) of the target to be simulated. The scattering parameters (S-parameters) are network parameters based on the input wave and the reflected wave, and are used to analyze microwave circuits.",{"type":18,"tag":26,"props":152,"children":153},{},[154],{"type":24,"value":155},"By using APIs provided by the code package, you can establish the S-parameter simulation process as follows.",{"type":18,"tag":26,"props":157,"children":158},{},[159],{"type":24,"value":160},"Import related dependencies:",{"type":18,"tag":26,"props":162,"children":163},{},[164],{"type":18,"tag":67,"props":165,"children":167},{"alt":7,"src":166},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/3fab9efa2bf14f93bd743f8f8a79b54e.png",[],{"type":18,"tag":26,"props":169,"children":170},{},[171],{"type":18,"tag":67,"props":172,"children":174},{"alt":7,"src":173},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/86a6b309606049a2833b1a03f5105f06.png",[],{"type":18,"tag":26,"props":176,"children":177},{},[178],{"type":24,"value":179},"Define the antenna structure using APIs provided by the code packaged based on the antenna design diagram:",{"type":18,"tag":26,"props":181,"children":182},{},[183],{"type":24,"value":184},"Patch antenna:",{"type":18,"tag":186,"props":187,"children":189},"pre",{"code":188},"1    def get_invert_f_antenna(air_buffers, npml):\n2        \"\"\" Get grid for IFA. \"\"\"\n3        # Define FDTD grid\n4        cell_lengths = (0.262e-3, 0.4e-3, 0.4e-3)\n5        obj_lengths = (0.787e-3, 40e-3, 40e-3)\n6        cell_numbers = (\n7            2 * npml + 2 * air_buffers[0] + int(obj_lengths[0] / cell_lengths[0]),\n8            2 * npml + 2 * air_buffers[1] + int(obj_lengths[1] / cell_lengths[1]),\n9            2 * npml + 2 * air_buffers[2] + int(obj_lengths[2] / cell_lengths[2]),\n10        )\n11        grid = GridHelper(cell_numbers, cell_lengths, origin=(\n12            npml + air_buffers[0] + int(obj_lengths[0] / cell_lengths[0]),\n13            npml + air_buffers[1],\n14            npml + air_buffers[2],\n15        ))\n16        # Define antenna\n17        grid[-3:0, 0:100, 0:100] = UniformBrick(epsr=2.2)\n18        grid[0, 0:71, 60:66] = PECPlate('x')\n19        grid[0, 40:71, 75:81] = PECPlate('x')\n20        grid[0, 65:71, 21:81] = PECPlate('x')\n21        grid[0, 52:58, 40:81] = PECPlate('x')\n22        grid[-3:0, 40, 75:81] = PECPlate('y')\n23        grid[-3, 0:40, 0:100] = PECPlate('x')\n24        # Define sources\n25        grid[-3:0, 0, 60:66] = VoltageSource(amplitude=1., r=50., polarization='xp')\n26        # Define monitors\n27        grid[-3:0, 0, 61:66] = VoltageMonitor('xp')\n28        grid[-1, 0, 60:66] = CurrentMonitor('xp')\n29        return grid\n",[190],{"type":18,"tag":191,"props":192,"children":193},"code",{"__ignoreMap":7},[194],{"type":24,"value":188},{"type":18,"tag":26,"props":196,"children":197},{},[198],{"type":24,"value":199},"Patch filter:",{"type":18,"tag":186,"props":201,"children":203},{"code":202},"1    def get_microstrip_filter(air_buffers, npml):\n2        \"\"\" microstrip filter \"\"\"\n3        # Define FDTD grid\n4        cell_lengths = (0.4064e-3, 0.4233e-3, 0.265e-3)\n5        obj_lengths = (50 * cell_lengths[0],\n6                       46 * cell_lengths[1],\n7                       3 * cell_lengths[2])\n8        cell_numbers = (\n9            2 * npml + 2 * air_buffers[0] + int(obj_lengths[0] / cell_lengths[0]),\n10            2 * npml + 2 * air_buffers[1] + int(obj_lengths[1] / cell_lengths[1]),\n11            2 * npml + 2 * air_buffers[2] + int(obj_lengths[2] / cell_lengths[2]),\n12        )\n13        grid = GridHelper(cell_numbers, cell_lengths, origin=(\n14            npml + air_buffers[0],\n15            npml + air_buffers[1],\n16            npml + air_buffers[2],\n17        ))\n18        # Define antenna\n19        grid[0:50, 0:46, 0:3] = UniformBrick(epsr=2.2)\n20        grid[14:20, 0:20, 3] = PECPlate('z')\n21        grid[30:36, 26:46, 3] = PECPlate('z')\n22        grid[0:50, 20:26, 3] = PECPlate('z')\n23        grid[0:50, 0:46, 0] = PECPlate('z')\n24        # Define sources\n25        grid[14:20, 0, 0:3] = VoltageSource(1., 50., 'zp')\n26        # Define load\n27        grid[30:36, 46, 0:3] = Resistor(50., 'z')\n28        # Define monitors\n29        grid[14:20, 10, 0:3] = VoltageMonitor('zp')\n30        grid[14:20, 10, 3] = CurrentMonitor('yp')\n31        grid[30:36, 36, 0:3] = VoltageMonitor('zp')\n32        grid[30:36, 36, 3] = CurrentMonitor('yn')\n33        return grid\n",[204],{"type":18,"tag":191,"props":205,"children":206},{"__ignoreMap":7},[207],{"type":24,"value":202},{"type":18,"tag":26,"props":209,"children":210},{},[211],{"type":24,"value":212},"Define an S-parameter solver based on differential FDTD and find the solution:",{"type":18,"tag":186,"props":214,"children":216},{"code":215},"1        # define fdtd network\n2        fdtd_net = full3d.ADFDTD(grid_helper.cell_numbers, grid_helper.cell_lengths,\n3                                    nt, dt, ns, antenna, cpml)\n4        # define solver\n5        solver = SParameterSolver(fdtd_net)\n6        # solve\n7        outputs = solver.solve(waveform_t)\n",[217],{"type":18,"tag":191,"props":218,"children":219},{"__ignoreMap":7},[220],{"type":24,"value":215},{"type":18,"tag":26,"props":222,"children":223},{},[224],{"type":24,"value":225},"The comparison of the S-parameter calculated by differential FDTD between the referenced paper[1] indicates that the accuracy of calculation results produced by differential FDTD is equivalent to those of traditional numerical algorithms.",{"type":18,"tag":26,"props":227,"children":228},{},[229],{"type":18,"tag":67,"props":230,"children":232},{"alt":7,"src":231},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/d00e6bb86cd840b5922353e235004cbb.png",[],{"type":18,"tag":26,"props":234,"children":235},{},[236],{"type":18,"tag":30,"props":237,"children":238},{},[239],{"type":24,"value":240},"2.2 Reverse Optimization: Solving Electromagnetic Inverse Scattering",{"type":18,"tag":26,"props":242,"children":243},{},[244],{"type":24,"value":245},"This case describes how to use MindSpore's automatic differential capability to reconstruct a dielectric based on the time-domain signals received by the receive antenna using the differential FDTD method. This case solves the electromagnetic inverse scattering in two-dimensional mode[3].",{"type":18,"tag":26,"props":247,"children":248},{},[249],{"type":18,"tag":67,"props":250,"children":252},{"alt":7,"src":251},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/c274eae050944f31afddd81a07fdfa3f.png",[],{"type":18,"tag":26,"props":254,"children":255},{},[256],{"type":24,"value":257},"The entire simulation area is divided into 100 x 100 grids, and the 40 x 40 grids (blue square) are used as the optimization area. Four excitation sources (red triangles) and eight observation points (green dots) are set outside the optimization area. The inversion targets are two dielectrics with relative dielectric constant being 4.",{"type":18,"tag":26,"props":259,"children":260},{},[261],{"type":24,"value":262},"By using APIs provided by the code package, you can establish a complete optimization process for electromagnetic inverse scattering as follows.",{"type":18,"tag":26,"props":264,"children":265},{},[266],{"type":18,"tag":67,"props":267,"children":269},{"alt":7,"src":268},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/2d48ce5101944227915a9b392a17f7a6.png",[],{"type":18,"tag":186,"props":271,"children":273},{"code":272},"1    class InverseDomain(BaseTopologyDesigner):\n2        def generate_object(self, rho):\n3            \"\"\"Generate material tensors.\n4            \"\"\"\n5            # generate background material tensors\n6            epsr = self.background_epsr * self.grid\n7            sige = self.background_sige * self.grid\n8            epsr[30:70, 30:70] = self.background_epsr + elu(rho, alpha=1e-2)\n9            return epsr, sige\n10    \n11        def update_sources(self, *args):\n12            \"\"\"Set locations of sources.\n13            \"\"\"\n14            sources, _, waveform, _ = args\n15            jz = sources[0]\n16            jz[0, :, 20, 50] = waveform\n17            jz[1, :, 50, 20] = waveform\n18            jz[2, :, 80, 50] = waveform\n19            jz[3, :, 50, 80] = waveform\n20            return jz\n21    \n22        def get_outputs_at_each_step(self, *args):\n23            \"\"\"Compute output each step.\n24            \"\"\"\n25            ez, _, _ = args[0]\n26            rx = [\n27                ez[:, 0, 25, 25],\n28                ez[:, 0, 25, 50],\n29                ez[:, 0, 25, 75],\n30                ez[:, 0, 50, 25],\n31                ez[:, 0, 50, 75],\n32                ez[:, 0, 75, 25],\n33                ez[:, 0, 75, 50],\n34                ez[:, 0, 75, 75],\n35            ]\n36            return vstack(rx)\n",[274],{"type":18,"tag":191,"props":275,"children":276},{"__ignoreMap":7},[277],{"type":24,"value":272},{"type":18,"tag":26,"props":279,"children":280},{},[281,283,288],{"type":24,"value":282},"The ",{"type":18,"tag":30,"props":284,"children":285},{},[286],{"type":24,"value":287},"elu",{"type":24,"value":289}," activation function is used to guarantee that no unphysical dielectric constant will appear during the solution.",{"type":18,"tag":26,"props":291,"children":292},{},[293],{"type":24,"value":294},"Define a differential FDTD network. As mentioned before, a process of solving the time-domain Maxwell equations by FDTD can be seen as an RNN. In this case, the update process of each field in an FDTD solving process of the 2D TM mode is as follows.",{"type":18,"tag":26,"props":296,"children":297},{},[298],{"type":18,"tag":67,"props":299,"children":301},{"alt":7,"src":300},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/9fc57bf330554777954a606bacd57e00.png",[],{"type":18,"tag":26,"props":303,"children":304},{},[305],{"type":24,"value":306},"The preceding update process has been implemented in the code. You can directly invoke related APIs to define a differential FDTD network.",{"type":18,"tag":26,"props":308,"children":309},{},[310],{"type":24,"value":311},"Define the loss function and optimizer for training and evaluation:",{"type":18,"tag":186,"props":313,"children":315},{"code":314},"1    # define fdtd network\n2    fdtd_net = transverse_magnetic.ADFDTD(\n3        cell_numbers, cell_lengths, nt, dt, ns,\n4        inverse_domain, cpml, rho_init)\n5    # define solver for inverse problem\n6    epochs = options.epochs\n7    lr = options.lr\n8    loss_fn = nn.MSELoss(reduction='sum')\n9    optimizer = nn.Adam(fdtd_net.trainable_params(), learning_rate=lr)\n10   solver = EMInverseSolver(fdtd_net, loss_fn, optimizer)\n11   # solve\n12   solver.solve(epochs, waveform_t, field_labels)\n",[316],{"type":18,"tag":191,"props":317,"children":318},{"__ignoreMap":7},[319],{"type":24,"value":314},{"type":18,"tag":26,"props":321,"children":322},{},[323],{"type":18,"tag":67,"props":324,"children":326},{"alt":7,"src":325},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2023/08/28/96460dd9771d4ac59017af403e953c99.png",[],{"type":18,"tag":26,"props":328,"children":329},{},[330],{"type":18,"tag":30,"props":331,"children":332},{},[333],{"type":24,"value":334},"3. Summary",{"type":18,"tag":26,"props":336,"children":337},{},[338],{"type":24,"value":339},"This MindSpore-based device-to-device electromagnetic solver of differential FDTD is capable of implementing differentiable solutions for electromagnetic simulation. Its effectiveness has been successfully demonstrated in scenarios such as patch antennas, patch filters, and 2D electromagnetic inverse scattering. In the case of the patch antenna and patch filter, the simulation accuracy of S-parameter is equivalent to that produced by traditional numerical methods. In the case of 2D electromagnetic inverse scattering, the structural similarity (SSIM) of dielectric parameters obtained through inversion reaches 96%. Enterprises and research institutes are welcomed to participate in our open source community to continuously evolve differential FDTD electromagnetic solvers and jointly explore the future of AI-driven electromagnetism.",{"type":18,"tag":26,"props":341,"children":342},{},[343],{"type":18,"tag":30,"props":344,"children":345},{},[346],{"type":24,"value":347},"References",{"type":18,"tag":26,"props":349,"children":350},{},[351],{"type":24,"value":352},"[1] L. Guo, et al., Electromagnetic Modeling Using an FDTD-Equivalent Recurrent Convolution Neural Network: Accurate Computing on a Deep Learning Framework [J], IEEE Antennas and Propagation Magazine, 2021.",{"type":18,"tag":26,"props":354,"children":355},{},[356],{"type":24,"value":357},"[2] A. Z. Elsherbeni and V. Demir, The Finite-Difference Time-Domain Method for Electromagnetics with MATLAB Simulations [M], 2ed, 2016.",{"type":18,"tag":26,"props":359,"children":360},{},[361],{"type":24,"value":362},"[3] P. Zhang, et al., A Maxwell's Equations Based Deep Learning Method for Time Domain Electromagnetic Simulations [J], IEEE Journal on Multiscale and Multiphysics Computational Techniques, vol. 6, pp. 35-40, 2021.",{"title":7,"searchDepth":364,"depth":364,"links":365},4,[],"markdown","content:technology-blogs:en:2716.md","content","technology-blogs/en/2716.md","technology-blogs/en/2716","md",1776506106998]