Cleanup of some subgrid functions and comments

这个提交包含在:
Craig Warren
2022-11-09 15:14:39 +00:00
父节点 ad8e9fd12b
当前提交 305596ec0e
共有 6 个文件被更改,包括 16 次插入187 次删除

查看文件

@@ -23,7 +23,7 @@ from ..grid import FDTDGrid
logger = logging.getLogger(__name__)
class SubGridBase(FDTDGrid):
class SubGridBaseGrid(FDTDGrid):
def __init__(self, *args, **kwargs):
super().__init__()
@@ -62,12 +62,4 @@ class SubGridBase(FDTDGrid):
self.n_boundary_cells_y = d_to_pml + self.pmlthickness['y0']
self.n_boundary_cells_z = d_to_pml + self.pmlthickness['z0']
self.interpolation = kwargs['interpolation']
def main_grid_index_to_subgrid_index(self, i, j, k):
"""Calculate local subgrid index from global main grid index."""
logger.debug('SubGridBase has no i0, j0, k0 members.')
i_s = self.n_boundary_cells_x + (i - self.i0) * self.ratio
j_s = self.n_boundary_cells_y + (j - self.j0) * self.ratio
k_s = self.n_boundary_cells_z + (k - self.k0) * self.ratio
return (i_s, j_s, k_s)
self.interpolation = kwargs['interpolation']

查看文件

@@ -1,133 +0,0 @@
# Copyright (C) 2015-2022: The University of Edinburgh, United Kingdom
# Authors: Craig Warren, Antonis Giannopoulos, and John Hartley
#
# This file is part of gprMax.
#
# gprMax is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# gprMax is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
import logging
from ..receivers import Rx
logger = logging.getLogger(__name__)
class ReferenceRx(Rx):
"""Receiver that mimicks a receiver in coarse grid.
We often want to compare an output in a fine reference solution with a
the solution in the coarse grid of a subgridded solution. This receiver
moves the output points in the fine grid such that they are in the same
position as the coarse grid.
"""
logger.debug('ReferenceRx has no offset member.')
def get_field(self, str_id, field):
"""Field value at the equivalent coarse yee cell.
Args:
str_id: string of 'Ex' etc...
field: nparray of grid.Ez
Returns:
e: float of field value.
"""
d = {
'Ex': self.get_Ex_from_field,
'Ey': self.get_Ey_from_field,
'Ez': self.get_Ez_from_field,
'Hx': self.get_Hx_from_field,
'Hy': self.get_Hy_from_field,
'Hz': self.get_Hz_from_field
}
e = d[str_id](field)
return e
def get_Ex_from_field(self, Ex):
"""Ex field value from the equivalent coarse yee cell.
Args:
Ex: nparray of Ex field.
Returns:
e: float of Ex field value.
"""
# offset = ratio // 2
e = Ex[self.xcoord + self.offset, self.ycoord, self.zcoord]
return e
def get_Ey_from_field(self, Ey):
"""Ey field value from the equivalent coarse yee cell.
Args:
Ey: nparray of Ey field.
Returns:
e: float of Ey field value.
"""
e = Ey[self.xcoord, self.ycoord + self.offset, self.zcoord]
return e
def get_Ez_from_field(self, Ez):
"""Ez field value from the equivalent coarse yee cell.
Args:
Ez: nparray of Ez field.
Returns:
e: float of Ez field value.
"""
e = Ez[self.xcoord, self.ycoord, self.zcoord + self.offset]
return e
def get_Hx_from_field(self, Hx):
"""Hx field value from the equivalent coarse yee cell.
Args:
Hx: nparray of Hx field.
Returns:
e: float of Hx field value.
"""
e = Hx[self.xcoord, self.ycoord + self.offset, self.zcoord + self.offset]
return e
def get_Hy_from_field(self, Hy):
"""Hy field value from the equivalent coarse yee cell.
Args:
Hy: nparray of Hy field.
Returns:
e: float of Hy field value.
"""
e = Hy[self.xcoord + self.offset, self.ycoord, self.zcoord + self.offset]
return e
def get_Hz_from_field(self, Hz):
"""Hz field value from the equivalent coarse yee cell.
Args:
Hz: nparray of Hz field.
Returns:
e: float of Hz field value.
"""
e = Hz[self.xcoord + self.offset, self.ycoord + self.offset, self.zcoord]
return e

查看文件

@@ -19,15 +19,16 @@
import logging
import gprMax.config as config
from ..cython.fields_updates_hsg import (cython_update_electric_os,
cython_update_is,
cython_update_magnetic_os)
from .base import SubGridBase
from .grid import SubGridBaseGrid
logger = logging.getLogger(__name__)
class SubGridHSG(SubGridBase):
class SubGridHSG(SubGridBaseGrid):
gridtype = '3DSUBGRID'
@@ -83,9 +84,7 @@ class SubGridHSG(SubGridBase):
cython_update_is(self.nwx, self.nwy, self.nwz, self.updatecoeffsE, self.ID, self.n_boundary_cells, 0, self.nwx + 1, self.nwz, self.nwy, 3, self.Ez, precursors.hx_front, precursors.hx_back, self.IDlookup['Ez'], 1, -1, 2, config.get_model_config().ompthreads)
def update_electric_os(self, main_grid):
"""
"""
""""""
i_l = self.i0 - self.is_os_sep
i_u = self.i1 + self.is_os_sep
j_l = self.j0 - self.is_os_sep
@@ -112,9 +111,7 @@ class SubGridHSG(SubGridBase):
cython_update_electric_os(main_grid.updatecoeffsE, main_grid.ID, 1, i_l, i_u + 1, j_l, j_u, k_l, k_u, self.nwz, main_grid.IDlookup['Ey'], main_grid.Ey, self.Hx, 3, 1, -1, 0, self.ratio, self.is_os_sep, self.n_boundary_cells, config.get_model_config().ompthreads)
def update_magnetic_os(self, main_grid):
"""
"""
""""""
i_l = self.i0 - self.is_os_sep
i_u = self.i1 + self.is_os_sep
j_l = self.j0 - self.is_os_sep

查看文件

@@ -47,7 +47,7 @@ def create_updates(G):
class SubgridUpdates(CPUUpdates):
"""Update functions for the Sub gridding simulation."""
"""Updates for subgrids."""
def __init__(self, G, updaters):
super().__init__(G)
@@ -93,23 +93,19 @@ class SubgridUpdater(CPUUpdates):
sub_grid = self.grid
precursors = self.precursors
# copy the main grid electric fields at the IS position
# Copy the main grid electric fields at the IS position
precursors.update_electric()
upper_m = int(sub_grid.ratio / 2 - 0.5)
for m in range(1, upper_m + 1):
self.store_outputs()
self.update_electric_a()
self.update_electric_pml()
precursors.interpolate_magnetic_in_time(int(m + sub_grid.ratio / 2 - 0.5))
sub_grid.update_electric_is(precursors)
self.update_electric_sources()
# second dispersive update
self.update_electric_b()
# STD update, interpolate inc. field in time, apply correction
self.update_magnetic()
self.update_magnetic_pml()
precursors.interpolate_electric_in_time(m)
@@ -134,23 +130,20 @@ class SubgridUpdater(CPUUpdates):
sub_grid = self.grid
precursors = self.precursors
# Copy the main grid magnetic fields at the IS position
precursors.update_magnetic()
upper_m = int(sub_grid.ratio / 2 - 0.5)
for m in range(1, upper_m + 1):
self.update_magnetic()
self.update_magnetic_pml()
precursors.interpolate_electric_in_time(int(m + sub_grid.ratio / 2 - 0.5))
sub_grid.update_magnetic_is(precursors)
self.update_magnetic_sources()
self.store_outputs()
self.update_electric_a()
self.update_electric_pml()
precursors.interpolate_magnetic_in_time(m)
sub_grid.update_electric_is(precursors)
self.update_electric_sources()

查看文件

@@ -22,8 +22,7 @@ from copy import copy
import numpy as np
from ..cmds_geometry.cmds_geometry import UserObjectGeometry
from ..cmds_multiuse import Rx, UserObjectMulti
from .multi import ReferenceRx as ReferenceRxUser
from ..cmds_multiuse import UserObjectMulti
from .subgrid_hsg import SubGridHSG as SubGridHSGUser
logger = logging.getLogger(__name__)
@@ -57,7 +56,7 @@ class SubGridBase(UserObjectMulti):
def set_main_grid_indices(self, sg, grid, uip, p1, p2):
"""Sets subgrid indices related to main grid placement."""
# location of the IS
# Location of the IS
sg.i0, sg.j0, sg.k0 = p1
sg.i1, sg.j1, sg.k1 = p2
@@ -192,22 +191,3 @@ class SubGridHSG(SubGridBase):
sg = SubGridHSGUser(**self.kwargs)
self.setup(sg, grid, uip)
return sg
class ReferenceRx(Rx):
"""ReferenceRx User Object."""
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.hash = '#rx_reference'
self.constructor = ReferenceRxUser
def create(self, grid, uip):
r = super().create(grid, uip)
try:
ratio = self.kwargs['ratio']
r.ratio = ratio
r.offset = ratio // 2
except KeyError:
logger.exception(self.__str__() + ' has an no ratio parameter')
raise

查看文件

@@ -40,8 +40,8 @@ def create_user_input_points(grid, user_obj):
"""Returns a point checker class based on the grid supplied."""
if isinstance(grid, SubGridBase):
# Local object configuration trumps. User can turn of autotranslate for
# specfic objects.
# Local object configuration trumps. User can turn off autotranslate for
# specific objects.
if not user_obj.autotranslate and config.sim_config.args.autotranslate:
return MainGridUserInput(grid)
@@ -89,7 +89,7 @@ class UserInput:
return self.discretise_point(p) * self.grid.dl
def descretised_to_continuous(self, p):
"""Returns a point given as indices to a continous point in the real space."""
"""Returns a point given as indices to a continuous point in the real space."""
return p * self.grid.dl
@@ -146,7 +146,7 @@ class MainGridUserInput(UserInput):
class SubgridUserInput(MainGridUserInput):
"""Handles (x, y, z) points supplied by the user in the sub grid.
"""Handles (x, y, z) points supplied by the user in the subgrid.
This class autotranslates points from main grid to subgrid equivalent
(within IS). Useful if material traverse is not required.
"""