Merged nested if conditions, and removed some un-necessary conditional statement in a function.

这个提交包含在:
Sai-Suraj-27
2023-08-03 20:55:14 +05:30
父节点 8e56b47405
当前提交 22ab1ebd44
共有 4 个文件被更改,包括 12 次插入25 次删除

查看文件

@@ -427,19 +427,11 @@ def dispersion_analysis(G):
results["error"] = "user waveform detected."
else:
# User-defined waveform
if waveform.type == "user":
iterations = G.iterations
# Built-in waveform
else:
# Time to analyse waveform - 4*pulse_width as using entire
# time window can result in demanding FFT
waveform.calculate_coefficients()
iterations = round_value(4 * waveform.chi / G.dt)
if iterations > G.iterations:
iterations = G.iterations
# Time to analyse waveform - 4*pulse_width as using entire
# time window can result in demanding FFT
waveform.calculate_coefficients()
iterations = round_value(4 * waveform.chi / G.dt)
iterations = min(iterations, G.iterations)
waveformvalues = np.zeros(G.iterations)
for iteration in range(G.iterations):
waveformvalues[iteration] = waveform.calculate_value(iteration * G.dt, G.dt)

查看文件

@@ -185,8 +185,7 @@ def write_processed_file(processedlines):
f.write(f"{item}")
logger.info(
f"Written input commands, after processing any Python "
+ f"code and include commands, to file: {processedfile}\n"
f"Written input commands, after processing any Python code and include commands, to file: {processedfile}\n"
)

查看文件

@@ -64,9 +64,7 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None:
tmp = tuple(int(x) for x in singlecmds[cmd].split())
if len(tmp) != 1:
logger.exception(
f"{cmd} requires exactly one parameter to specify " + f"the number of CPU OpenMP threads to use"
)
logger.exception(f"{cmd} requires exactly one parameter to specify the number of CPU OpenMP threads to use")
raise ValueError
omp_threads = OMPThreads(n=tmp[0])
@@ -106,7 +104,7 @@ def process_singlecmds(singlecmds):
if len(tmp) != 1:
logger.exception(
f"{cmd} requires exactly one parameter to specify the "
+ f"time window. Either in seconds or number of iterations."
f"time window. Either in seconds or number of iterations."
)
raise ValueError
tmp = tmp[0].lower()

查看文件

@@ -317,9 +317,8 @@ class PeplinskiSoil:
# Check to see if the material already exists before creating a new one
requiredID = "|{:.4f}|".format(float(muiter[0]))
material = next((x for x in G.materials if x.ID == requiredID), None)
if muiter.index == 0:
if material:
self.matID.append(material.numID)
if muiter.index == 0 and material:
self.matID.append(material.numID)
if not material:
m = DispersiveMaterial(len(G.materials), requiredID)
m.type = "debye"
@@ -412,9 +411,8 @@ class RangeMaterial:
# Check to see if the material already exists before creating a new one
requiredID = f"|{float(er):.4f}+{float(se):.4f}+{float(mr):.4f}+{float(sm):.4f}|"
material = next((x for x in G.materials if x.ID == requiredID), None)
if iter == 0:
if material:
self.matID.append(material.numID)
if iter == 0 and material:
self.matID.append(material.numID)
if not material:
m = Material(len(G.materials), requiredID)
m.type = ""