Skip to content

Commit

Permalink
Merge branch 'ruff' into 'master'
Browse files Browse the repository at this point in the history
[py] ruff fixes

Closes #3436

See merge request ogs/ogs!4824
  • Loading branch information
endJunction committed Nov 29, 2023
2 parents 9daf641 + 5f6fc12 commit 912f501
Show file tree
Hide file tree
Showing 90 changed files with 3,568 additions and 2,812 deletions.
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
"OGS_INSTALL_DEPENDENCIES": "OFF",
"OGS_USE_PIP": "OFF",
"OGS_USE_MFRONT": "ON",
"DOGS_BUILD_PROCESSES": "SteadyStateDiffusion",
"BUILD_SHARED_LIBS": "ON"
}
}
Expand Down
12 changes: 5 additions & 7 deletions MaterialLib/SolidModels/MFront/Lubby2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import matplotlib.pyplot as plt
import mtest
import numpy as np
import matplotlib.pyplot as plt


GM0 = 9.54e3
KM0 = 2.78e4
Expand Down Expand Up @@ -49,13 +48,12 @@
etaM = etaM0 * np.exp(mvM * sig_eff)


eps_xy = (
lambda t: (
def eps_xy(t):
return (
(1.0 / GM0 + t / etaM) * sig_xy
+ 1.0 / GK * (1.0 - np.exp(-GK / etaK * t)) * sig_xy
)
/ 2.0
)
) / 2.0


s = mtest.MTestCurrentState()
wk = mtest.MTestWorkSpace()
Expand Down
13 changes: 6 additions & 7 deletions MaterialLib/SolidModels/MFront/ModCamClay_ShearTest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import matplotlib.pyplot as plt
import mtest
import numpy as np
import matplotlib.pyplot as plt


# Material constants
E = 150.0e3 # Young's modulus in MPa
Expand Down Expand Up @@ -158,7 +157,7 @@
for k in range(runs):
ax.plot(ltime, results[3][k], label=prelabel + "%.2f" % (valueList[k]))
ax.set_xlabel("$t$ / s")
ax.set_ylabel("$\phi$")
ax.set_ylabel(r"$\phi$")
ax.grid()
ax.legend()
fig.savefig("ModCamClay_ParamStudy_Porosity.pdf")
Expand All @@ -167,8 +166,8 @@
# ax.set_title('Shear stress over shear strain')
for k in range(runs):
ax.plot(results[4][k], results[5][k], label=prelabel + "%.2f" % (valueList[k]))
ax.set_xlabel("$\epsilon_{xy}$")
ax.set_ylabel("$\sigma_{xy}$ / MPa")
ax.set_xlabel(r"$\epsilon_{xy}$")
ax.set_ylabel(r"$\sigma_{xy}$ / MPa")
ax.grid()
ax.legend()
fig.savefig("ModCamClay_ParamStudy_ShearCurves.pdf")
Expand All @@ -179,8 +178,8 @@
ax.plot(
results[4][k], results[7][k] * 100, label=prelabel + "%.2f" % (valueList[k])
)
ax.set_xlabel("$\epsilon_{xy}$")
ax.set_ylabel("${\epsilon}_p^V$ / %")
ax.set_xlabel(r"$\epsilon_{xy}$")
ax.set_ylabel(r"${\epsilon}_p^V$ / %")
ax.grid()
ax.legend()
fig.savefig("ModCamClay_ParamStudy_eplVCurves.pdf")
Expand Down
28 changes: 14 additions & 14 deletions MaterialLib/SolidModels/MFront/ModCamClay_TriaxTest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mtest as mtest
import numpy as np
import matplotlib.pyplot as plt
import mtest
import numpy as np

m = mtest.MTest()
mtest.setVerboseMode(mtest.VerboseLevel.VERBOSE_QUIET)
Expand Down Expand Up @@ -199,7 +199,7 @@
ax.set_title("Numerical solution versus analytical solution (Peric, 2006)")
ax.plot(eQCurve, qCurve / 1e3, "+", markersize=14, markevery=4, label="numerical")
ax.plot(v0xEpsQ / v0, qRangeAna / 1e3, linewidth=2, label="analytical")
ax.set_xlabel("$\epsilon_{q}$")
ax.set_xlabel(r"$\epsilon_{q}$")
ax.set_ylabel("q / kPa")
ax.grid()
ax.legend()
Expand Down Expand Up @@ -238,30 +238,30 @@
ax.legend()

fig, ax = plt.subplots()
ax.plot(ltime, stresses[0][:], label="$\sigma_{rr}$ / MPa")
ax.plot(ltime, stresses[2][:], label="$\sigma_{\phi\phi}$ / MPa")
ax.plot(ltime, stresses[1][:], label="$\sigma_{zz}$ / MPa")
ax.plot(ltime, stresses[3][:], label="$\sigma_{rz}$ / MPa")
ax.plot(ltime, stresses[0][:], label=r"$\sigma_{rr}$ / MPa")
ax.plot(ltime, stresses[2][:], label=r"$\sigma_{\phi\phi}$ / MPa")
ax.plot(ltime, stresses[1][:], label=r"$\sigma_{zz}$ / MPa")
ax.plot(ltime, stresses[3][:], label=r"$\sigma_{rz}$ / MPa")
ax.set_xlabel("$t$ / s")
ax.set_ylabel("stress / MPa")
ax.grid()
ax.legend()

fig, ax = plt.subplots()
ax.plot(ltime, strains[0][:], color="red", label="$\epsilon_{rr}$")
ax.plot(ltime, strains[2][:], "--", color="green", label="$\epsilon_{\phi\phi}$")
ax.plot(ltime, strains[1][:], label="$\epsilon_{zz}$")
ax.plot(ltime, strains[3][:], color="black", label="$\epsilon_{rz}$")
ax.plot(ltime, strains[0][:], color="red", label=r"$\epsilon_{rr}$")
ax.plot(ltime, strains[2][:], "--", color="green", label=r"$\epsilon_{\phi\phi}$")
ax.plot(ltime, strains[1][:], label=r"$\epsilon_{zz}$")
ax.plot(ltime, strains[3][:], color="black", label=r"$\epsilon_{rz}$")
ax.set_xlabel("$t$ / s")
ax.set_ylabel("strain")
ax.grid()
ax.legend(loc="lower left")
fig.savefig("ModCamClay_TriaxStudy_Strains.pdf")

fig, ax = plt.subplots()
ax.plot(ltime, phiCurve - phi0, label="$\phi-\phi_0$")
ax.plot(ltime, eVCurve, label="$\epsilon_{V}$")
ax.plot(ltime, lpCurve, label="$\epsilon_{eq}$")
ax.plot(ltime, phiCurve - phi0, label=r"$\phi-\phi_0$")
ax.plot(ltime, eVCurve, label=r"$\epsilon_{V}$")
ax.plot(ltime, lpCurve, label=r"$\epsilon_{eq}$")
ax.set_xlabel("$t$ / s")
ax.set_ylabel(" ")
ax.grid()
Expand Down
9 changes: 5 additions & 4 deletions MaterialLib/SolidModels/MFront/pi-plane.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from math import pi, cos, sin, sqrt
from tfel.material import projectOnPiPlane
from math import cos, pi, sin

import mtest
from tfel.material import projectOnPiPlane

divisions = 1000
for theta in [
pi * (-1.0 + 2.0 * float(i) / (float(divisions) - 1.0)) for i in range(0, divisions)
pi * (-1.0 + 2.0 * float(i) / (float(divisions) - 1.0)) for i in range(divisions)
]:
# for theta in [-1.3010636242139548]:
em = 5.0e-3
Expand Down Expand Up @@ -35,7 +36,7 @@
m.completeInitialisation()
m.initializeCurrentState(s)
m.initializeWorkSpace(wk)
ltime = [float((tmax / (npas - 1))) * i for i in range(npas)]
ltime = [float(tmax / (npas - 1)) * i for i in range(npas)]
plas = 0
plas_tol = 1e-10
p = s.getInternalStateVariableValue("EquivalentPlasticStrain")
Expand Down
9 changes: 5 additions & 4 deletions MaterialLib/SolidModels/MFront/pi-plane_ortho.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from math import pi, cos, sin, sqrt
from tfel.material import projectOnPiPlane
from math import cos, pi, sin

import mtest
from tfel.material import projectOnPiPlane

divisions = 1000
for theta in [
pi * (-1.0 + 2.0 * float(i) / (float(divisions) - 1.0)) for i in range(0, divisions)
pi * (-1.0 + 2.0 * float(i) / (float(divisions) - 1.0)) for i in range(divisions)
]:
# for theta in [-1.3010636242139548]:
em = 5.0e-3
Expand Down Expand Up @@ -42,7 +43,7 @@
m.completeInitialisation()
m.initializeCurrentState(s)
m.initializeWorkSpace(wk)
ltime = [float((tmax / (npas - 1))) * i for i in range(npas)]
ltime = [float(tmax / (npas - 1)) * i for i in range(npas)]
plas = 0
plas_tol = 1e-10
for i in range(npas - 1):
Expand Down
2 changes: 1 addition & 1 deletion MaterialLib/SolidModels/MFront/three_ax_strain_ortho.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
m.completeInitialisation()
m.initializeCurrentState(s)
m.initializeWorkSpace(wk)
ltime = [float((tmax / (npas - 1))) * i for i in range(npas)]
ltime = [float(tmax / (npas - 1)) * i for i in range(npas)]
for i in range(npas - 1):
m.execute(s, wk, ltime[i], ltime[i + 1])
print(
Expand Down
6 changes: 3 additions & 3 deletions Tests/Data/Elliptic/cube_1x1x1_SteadyStateDiffusion/cube.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from paraview.simple import *
# ruff: noqa
from paraview import coprocessing

from paraview.simple import *

# --------------------------------------------------------------
# Code generated from cpstate.py to create the CoProcessor.
Expand Down Expand Up @@ -94,7 +94,7 @@ def CreatePipeline(self, datadescription):
def RequestDataDescription(datadescription):
"Callback to populate the request for current timestep"
global coprocessor
if datadescription.GetForceOutput() == True:
if datadescription.GetForceOutput() is True:
# We are just going to request all fields and meshes from the simulation
# code/adaptor.
for i in range(datadescription.GetNumberOfInputDescriptions()):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from math import cos, cosh, pi, sin, sinh

import OpenGeoSys
from math import pi, sin, cos, sinh, cosh

a = 2.0 * pi / 3.0


# analytical solution used to set the Dirichlet BCs
def solution(x, y):
return sin(a * x) * sinh(a * y)
Expand All @@ -17,23 +19,26 @@ def grad_solution(x, y):
class BCTop(OpenGeoSys.BoundaryCondition):
def getDirichletBCValue(self, t, coords, node_id, primary_vars):
x, y, z = coords
assert y == 1.0 and z == 0.0
assert y == 1.0
assert z == 0.0
value = solution(x, y)
return (True, value)


class BCLeft(OpenGeoSys.BoundaryCondition):
def getDirichletBCValue(self, t, coords, node_id, primary_vars):
x, y, z = coords
assert x == 0.0 and z == 0.0
assert x == 0.0
assert z == 0.0
value = solution(x, y)
return (True, value)


class BCBottom(OpenGeoSys.BoundaryCondition):
def getDirichletBCValue(self, t, coords, node_id, primary_vars):
x, y, z = coords
assert y == 0.0 and z == 0.0
assert y == 0.0
assert z == 0.0
value = solution(x, y)
return (True, value)

Expand All @@ -42,7 +47,8 @@ def getDirichletBCValue(self, t, coords, node_id, primary_vars):
class BCRight(OpenGeoSys.BoundaryCondition):
def getFlux(self, t, coords, primary_vars):
x, y, z = coords
assert x == 1.0 and z == 0.0
assert x == 1.0
assert z == 0.0
value = grad_solution(x, y)[0]
Jac = [0.0] # value does not depend on primary variable
return (True, value, Jac)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import OpenGeoSys
from math import pi, sin

import OpenGeoSys

a = 2.0 * pi
b = 2.0 * pi

Expand Down
3 changes: 2 additions & 1 deletion Tests/Data/EllipticPETSc/square_1e1_neumann-insitu.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
# paraview version 5.8.0
# --------------------------------------------------------------

from paraview.simple import *
# ruff: noqa
from paraview import coprocessing
from paraview.simple import *

# ----------------------- CoProcessor definition -----------------------

Expand Down
5 changes: 1 addition & 4 deletions Tests/Data/HydroMechanics/GroundEquilibrium/pythonBCsOGS.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
except ModuleNotFoundError:
import OpenGeoSys

import numpy as np

s_a = 365.25 * 24 * 3600 # =31557600 seconds per year

Expand All @@ -31,9 +30,7 @@


def ExternalDisplacement(x, t):
uy = u_max * (t / T) * (x / Lx) ** 2

return uy
return u_max * (t / T) * (x / Lx) ** 2


# Hydraulic BCs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import OpenGeoSys



p_flux_in = 1e-2
p_0 = 1e5


# Source Terms
## Pressure
class BC_p_D(OpenGeoSys.BoundaryCondition):
Expand All @@ -17,5 +16,6 @@ def getFlux(self, t, coords, primary_vars):
Jac = [0.0, 0.0, 0.0]
return (True, p_flux_in, Jac)


bc_p_D = BC_p_D()
bc_p_N = BC_p_N()
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import OpenGeoSys


dirichlet_displacement_top = -0.05
dirichlet_displacement_0 = 0
dirichlet_pressure_0 = 0



# Boundary conditions
## Pressure
class BC_p_D_0(OpenGeoSys.BoundaryCondition):
class BC_p_D_0(OpenGeoSys.BoundaryCondition):
def getDirichletBCValue(self, t, coords, node_id, primary_vars):
return (True, dirichlet_pressure_0)



## Displacement
### Dirichlet
class BC_u_D_0(OpenGeoSys.BoundaryCondition):
class BC_u_D_0(OpenGeoSys.BoundaryCondition):
def getDirichletBCValue(self, t, coords, node_id, primary_vars):
return (True, dirichlet_displacement_0)

class BC_u_D_top(OpenGeoSys.BoundaryCondition):


class BC_u_D_top(OpenGeoSys.BoundaryCondition):
def getDirichletBCValue(self, t, coords, node_id, primary_vars):
return (True, dirichlet_displacement_top)

Expand Down
12 changes: 4 additions & 8 deletions Tests/Data/HydroMechanics/SeabedResponse/Stationary_waves.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,14 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"plt.rc(\"font\", size=8)\n",
"plt.rc(\"axes\", titlesize=10)\n",
"plt.rc(\"axes\", labelsize=10)\n",
"\n",
"import gmsh\n",
"\n",
"import pyvista as pv\n",
"\n",
"pv.set_plot_theme(\"document\")\n",
Expand Down Expand Up @@ -434,7 +432,7 @@
" if y == 0:\n",
" ax[1].legend(loc=\"upper right\")\n",
"\n",
"ax[1].set_ylabel(\"$\\sigma$'/$\\\\alpha\\\\tilde{p}$\")\n",
"ax[1].set_ylabel(\"$\\\\sigma$'/$\\\\alpha\\\\tilde{p}$\")\n",
"\n",
"\n",
"ax[0].set_title(\"Pore pressure over time\")\n",
Expand Down Expand Up @@ -874,8 +872,7 @@
"def read_timestep_mesh(a, time):\n",
" reader = pv.PVDReader(f\"{out_dir}/square_{a}x100.pvd\")\n",
" reader.set_active_time_point(int(time * 4)) # time [s], delta t = 0.25 s\n",
" mesh = reader.read()[0]\n",
" return mesh\n",
" return reader.read()[0]\n",
"\n",
"\n",
"def slice_along_line(mesh, start_point, end_point):\n",
Expand All @@ -887,8 +884,7 @@
" pressure = mesh.point_data[\"pressure_interpolated\"]\n",
" depth = mesh.points[:, 1]\n",
" indices_sorted = np.argsort(depth)\n",
" pressure_sorted = pressure[indices_sorted]\n",
" return pressure_sorted\n",
" return pressure[indices_sorted]\n",
"\n",
"\n",
"def get_stresses_sorted(mesh):\n",
Expand Down
Loading

0 comments on commit 912f501

Please sign in to comment.