你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 23:14:03 +08:00
Made rounding function more generic.
这个提交包含在:
@@ -17,13 +17,14 @@
|
|||||||
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
|
# along with gprMax. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
|
import decimal as d
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from psutil import virtual_memory
|
from psutil import virtual_memory
|
||||||
|
|
||||||
from gprMax.constants import c, floattype
|
from gprMax.constants import c, floattype
|
||||||
from gprMax.exceptions import CmdInputError
|
from gprMax.exceptions import CmdInputError
|
||||||
from gprMax.pml import PML, CFS
|
from gprMax.pml import PML, CFS
|
||||||
from gprMax.utilities import roundvalue, rounddownmax, human_size
|
from gprMax.utilities import roundvalue, human_size
|
||||||
from gprMax.waveforms import Waveform
|
from gprMax.waveforms import Waveform
|
||||||
|
|
||||||
|
|
||||||
@@ -146,7 +147,7 @@ def process_singlecmds(singlecmds, multicmds, G):
|
|||||||
G.dt = 1 / (c * np.sqrt((1 / G.dx) * (1 / G.dx) + (1 / G.dy) * (1 / G.dy) + (1 / G.dz) * (1 / G.dz)))
|
G.dt = 1 / (c * np.sqrt((1 / G.dx) * (1 / G.dx) + (1 / G.dy) * (1 / G.dy) + (1 / G.dz) * (1 / G.dz)))
|
||||||
|
|
||||||
# Round down time step to nearest float with precision one less than hardware maximum. Avoids inadvertently exceeding the CFL due to binary representation of floating point number.
|
# Round down time step to nearest float with precision one less than hardware maximum. Avoids inadvertently exceeding the CFL due to binary representation of floating point number.
|
||||||
G.dt = rounddownmax(G.dt)
|
G.dt = roundvalue(G.dt, decimalplaces=d.getcontext().prec - 1)
|
||||||
|
|
||||||
if G.messages:
|
if G.messages:
|
||||||
print('Time step: {:.3e} secs'.format(G.dt))
|
print('Time step: {:.3e} secs'.format(G.dt))
|
||||||
|
@@ -79,34 +79,27 @@ def update_progress(progress):
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
def roundvalue(value):
|
def roundvalue(value, decimalplaces=0):
|
||||||
"""Rounds to nearest integer (half values are rounded downwards).
|
"""Rounding function.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
value (float): Number to round.
|
value (float): Number to round.
|
||||||
|
decimalplaces (int): Number of decimal places of float to represent rounded value.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Rounded value (int).
|
rounded (int/float): Rounded value.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return int(d.Decimal(value).quantize(d.Decimal('1'),rounding=d.ROUND_HALF_DOWN))
|
# Rounds to nearest integer (half values are rounded downwards)
|
||||||
|
if decimalplaces == 0:
|
||||||
|
rounded = int(d.Decimal(value).quantize(d.Decimal('1'),rounding=d.ROUND_HALF_DOWN))
|
||||||
def rounddownmax(value):
|
|
||||||
"""Rounds down to nearest float with precision one less than hardware maximum.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
value (float): Number to round.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Rounded value (float).
|
|
||||||
"""
|
|
||||||
|
|
||||||
decimalplaces = d.getcontext().prec
|
# Rounds down to nearest float represented by number of decimal places
|
||||||
decimalplaces -= 1
|
else:
|
||||||
precision = '1.{places}'.format(places='0' * decimalplaces)
|
precision = '1.{places}'.format(places='0' * decimalplaces)
|
||||||
|
rounded = float(d.Decimal(value).quantize(d.Decimal(precision),rounding=d.ROUND_FLOOR))
|
||||||
return float(d.Decimal(value).quantize(d.Decimal(precision),rounding=d.ROUND_FLOOR))
|
|
||||||
|
return rounded
|
||||||
|
|
||||||
|
|
||||||
def human_size(size, a_kilobyte_is_1024_bytes=True):
|
def human_size(size, a_kilobyte_is_1024_bytes=True):
|
||||||
|
在新工单中引用
屏蔽一个用户