• WSL下安装ubuntu 18.04 +meep进行FDTD仿真计算


    前言

    使用meep进行FDTD开发,开源。这里记录一下自己的安装过程,可以不安装在C盘,有助于后面进行修改。主要是因为我看网上其他人写的就跟一坨屎一样,在那乱写,搞完一堆报错,也没有说明为什么,直接拿meep官方文档翻译一下就成了一篇博客,还说自己是原创,离大普!

    WSL

    关于这个是什么,可以看这个链接:
    链接: WSL
    为什么选择使用WSL去实现meep的仿真环境配置呢,首先是meep是基于linux开发的开源软件,其次呢,使用虚拟机占内存,配置也不简单到哪去。有方便的东西为啥不用,搞那么费事的事情干个锤子。

    安装过程

    打开虚拟环境

    windows下面打开虚拟环境和开发者选项,两个都要!尤其是对全新的电脑,或者重装过系统的电脑。网上一些博客就没有说,导致后面你要是再去安装别的东西,总是报错或者安装不上
    step one:
    在这里插入图片描述
    step two:

    在这里插入图片描述
    接下来:三个都需要勾选上!

    在这里插入图片描述
    打开开发者选项:在设置里面找到隐私和安全性,找到开发者选项,开启开发人员模式
    在这里插入图片描述

    下载Ubuntu并修改安装路径

    打开微软商城,搜索ubuntu,这里选择的版本是ubuntu 18.04 LTS,可以选择更高的20.04
    在这里插入图片描述
    安装完成之后这个就会在C盘,除非你之前就已经修改了微软商城的安装路径
    打开powershell,直接在搜索栏里面搜索就好了
    在这里插入图片描述
    升级WSL1到WSL2,直接是版本2就跳过,在powershell 里面输入下面的命令行

    wsl --set-version Ubuntu-18.04 2
    
    • 1

    等待完成就好了,然后打开ubuntu,设置用户名密码:
    在这里插入图片描述
    这里我直接copy其他的博客的一张图,上面的Enter new UNIX name就是需要输入自己的用户名。输入的密码是看不见的,所以自己得记住。

    修改路径,在powershell里面完成,在完成了自己的命名之后,打开powershell,输入

    wsl -l -v
    
    • 1

    在这里插入图片描述
    此时ubuntu正在运行,需要关闭,输入:

    wsl --shutdown
    
    • 1

    在这里插入图片描述
    之后开始依次在powershell里面输入下面的命令行:

    wsl --export Ubuntu-18.04 D:\ubuntu18.04.tar 
    
    $ 上面是导出子文件到d盘,这个不要输入,这个是我用来解释的,下面的汉字都是用来解释的,不要输入!!!
    
    wsl --unregister Ubuntu-18.04
    
    $注销子系统
    
    wsl --import Ubuntu-18.04 D:\Ubuntu1804 D:\ubuntu18.04.tar 
    
    $重新导入到D盘
    
    ubuntu1804.exe config --default-user rayzs
    
    $ 这里rayzs是我的用户名,改成自己的用户名就好了
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    更改软件源

    ubuntu是一个基于linux的操作系统,上面的默认源是从国外的ip地址,我们可以改成国内的,加快下载的速度。打开ubuntu
    在这里插入图片描述

    点击,这个跳转打开软件源
    在这里插入图片描述
    输入到ubuntu里面,等待就好了,这个我就不贴了,我自己已经配置好了。对了,这个没有办法直接粘贴复制,得自己手动输入,可能是因为linux里面粘贴复制和windows的不一样。

    完成之后再ubuntu里面输入:

    sudo apt-get update
    sudo apt-get upgrade
    
    • 1
    • 2

    就是更新升级一下,不然用不了。
    至此,ubuntu即全部完成了,接下来就是安装meep了

    Meep

    关于meep是什么,请看这个meep
    首先是安装miniconda,安装教程在这:注意都是在ubuntu里面完成的!
    miniconda安装

    开始安装meep,在ubuntu里面输入:

    conda create -n mp -c conda-forge pymeep pymeep-extras
    
    • 1

    等待安装完成,在再次输入:(这里是测试是否安装成功,如果出现了下图所示,就是成功)

    conda activate mp
    
    • 1

    在这里插入图片描述

    VScode远程访问

    至此完成了meep的安装过程,接下来就是使用vscode进行远程访问,使用jupyter notebook也行,个人不喜欢

    打开vscode,在扩展里面找到WSL:
    在这里插入图片描述
    之后 Shift+Ctrl+P 查找 Remote-WSL: New Window 或者 通过 vscode 左下角的按钮 来访问子系统上的开发环境

    在子系统中进行Python开发时也要切换到mp环境,这时候 Shift+Ctrl+P 查找 Python: Select Interpreter

    选择mp环境,即可进行 Meep 程序的开发

    测试程序

    import matplotlib.pyplot as plt
    import meep as mp
    import numpy as np
    from IPython.display import Video
    
    # Set up the bent waveguide in a slightly larger cell:
    cell = mp.Vector3(16,16,0)
    geometry = [mp.Block(mp.Vector3(12,1,mp.inf),
                         center=mp.Vector3(-2.5,-3.5),
                         material=mp.Medium(epsilon=12)),
                mp.Block(mp.Vector3(1,12,mp.inf),
                         center=mp.Vector3(3.5,2),
                         material=mp.Medium(epsilon=12))]
    
    # set up the boundary layer
    pml_layers=[mp.PML(1.0)]
    
    resolution=10 #pixels/um
    
    
    '''
    There are a couple of items to note. First, a point source does not couple very efficiently to the waveguide mode, so we will expand this into a line source,centered at (-7,-3.5), with the same width as the waveguideby adding a size property to the source.
    Second, instead of turning the source on suddently at t=0 which excites many other frequencies because of the discontinuity, we will ramp it on slowly.
    '''
    sources = [mp.Source(mp.ContinuousSource(wavelength=2*(11**0.5),width=20),
                         component=mp.Ez,
                         center=mp.Vector3(-7,-3.5),
                         size=mp.Vector3(0,1))]
    
    sim = mp.Simulation(cell_size=cell,
                        boundary_layers=pml_layers,
                        geometry=geometry,
                        sources=sources,
                        resolution=resolution)
    
    f=plt.figure(dpi=150)
    sim.plot2D(ax=f.gca())
    plt.axis("off")
    plt.show()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    在这里插入图片描述
    如果没有报错就是成功了!各位如果有安装问题请联系我,谢谢!

  • 相关阅读:
    C语言之数组练习题
    Linux 内核参数:percpu_pagelist_fraction
    PHP基础面试题
    某蝶EAS(Enterprise Application Suite)平台myUploadFile接口任意文件上传漏洞复现 CNVD-2023-57598
    TS以及webpack的es module
    轻量级 K8S 环境 安装minikube
    联表更新数据以及You can‘t specify target table ‘xxx‘ for update in FROM clause
    【基于C的排序算法】归并排序
    小菜鸡近期的一些胡思乱想
    【单片机】17-温度传感器DS18B20
  • 原文地址:https://blog.csdn.net/weixin_44449744/article/details/127949957