(更新中)gprMax项目代码分解:gprMax.constants.py、gprMax.exceptions

1. 引言#

本文对gprMax项目中的“gprMax.constants.py”、“gprMax.exceptions.py”文件代码进行了逻辑梳理和分解。

2. gprMax.constants.py#

gprMax.constants.py内容主要用于定义一些常量和数据类型。其中的常量cm0e0从scipy库导入的,可详见Constants (scipy.constants) — SciPy v1.10.0 Manual;常量z0是通过简单的平方根运算得到的。数据类型的定义也很直观,均是通过直接赋值的方式指定的。

import numpy as np
from scipy.constants import c
from scipy.constants import mu_0 as m0
from scipy.constants import epsilon_0 as e0

#定义变量z0
# Impedance of free space (Ohms)
z0 = np.sqrt(m0 / e0)

#以下为定义数据类型
# Single precision
# For numpy arrays
floattype = np.float32
complextype = np.complex64

# For C (CUDA) arrays
cudafloattype = 'float'
cudacomplextype = 'pycuda::complex<float>'

# Double precision
# For numpy arrays
# floattype = np.float64
# complextype = np.complex128

# For C (CUDA) arrays
# cudafloattype = 'double'
# cudacomplextype = 'pycuda::complex<double>'

3. gprMax.exceptions.py#

colorama库用于自定义命令行文本显示颜色。Generalerror类和CmdinputErrorl类都继承自ValueError类,GeneralError类用于处理一般错误,CmdinputErrorl用于处理用户输入命令错误

#导入函数库
import sys
from colorama import init
from colorama import Fore

init()

sys.tracebacklimit = None


class GeneralError(ValueError):
	""""此类用于处理一般错误,继承自ValueError。"""
    """Handles general errors. Subclasses the ValueError class."""

    def __init__(self, message, *args):

        self.message = message
        super(GeneralError, self).__init__(message, *args)
        print(Fore.RED)


class CmdInputError(ValueError):
	""""此类用于处理用户输入命令错误,继承自ValueError。"""
    """Handles errors in user specified commands. Subclasses the ValueError class."""

    def __init__(self, message, *args):

        self.message = message
        super(CmdInputError, self).__init__(message, *args)
        print(Fore.RED)

4. 总结#

本文分解了gprMax项目中的gprMax.constants.py、gprMax.exceptions.py文件代码。

Reference#

  1. GitHub - gprMax/gprMax: gprMax is open source software that simulates electromagnetic wave propagation using the Finite-Difference Time-Domain (FDTD) method for numerical modelling of Ground Penetrating Radar (GPR)
  2. SciPy documentation — SciPy v1.10.0 Manual

作者:realxuan

出处:https://www.cnblogs.com/realxuan/p/17644655.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   realXuan  阅读(65)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
more_horiz
keyboard_arrow_up light_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示