Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dotest(MYSOLVER, multi=False, A=None, **solverOpts):
if A is None:
h1 = np.ones(10)*100.
h2 = np.ones(10)*100.
h3 = np.ones(10)*100.
h = [h1,h2,h3]
M = TensorMesh(h)
D = M.faceDiv
G = -M.faceDiv.T
Msig = M.getFaceInnerProduct()
A = D*Msig*G
A[-1,-1] *= 1/M.vol[-1] # remove the constant null space from the matrix
else:
M = Mesh.TensorMesh([A.shape[0]])
Ainv = MYSOLVER(A, **solverOpts)
if multi:
e = np.ones(M.nC)
else:
e = np.ones((M.nC, numRHS))
rhs = A * e
x = Ainv * rhs
'tol': tol,
'maxit': maxit,
'nu_init': nu_init,
'nu_pre': nu_pre,
'nu_coarse': nu_coarse,
'nu_post': nu_post,
'clevel': clevel,
},
'result': efield.field,
'hresult': hfield.field,
}
# # # # # # # # # # 3. TensorMesh check # # # # # # # # # #
# Create an advanced grid with discretize.
grid = TensorMesh(
[[(10, 10, -1.1), (10, 20, 1), (10, 10, 1.1)],
[(33, 20, 1), (33, 10, 1.5)],
[20]],
x0='CN0')
# List of all attributes in emg3d-grid.
all_attr = [
'hx', 'hy', 'hz', 'vectorNx', 'vectorNy', 'vectorNz', 'vectorCCx', 'nE',
'vectorCCy', 'vectorCCz', 'nEx', 'nEy', 'nEz', 'nCx', 'nCy', 'nCz', 'vnC',
'nNx', 'nNy', 'nNz', 'vnN', 'vnEx', 'vnEy', 'vnEz', 'vnE', 'nC', 'nN', 'x0'
]
mesh = {'attr': all_attr}
for attr in all_attr:
mesh[attr] = getattr(grid, attr)
def genTopography(mesh, zmin, zmax, seed=None, its=100, anisotropy=None):
if mesh.dim == 3:
mesh2D = discretize.TensorMesh(
[mesh.hx, mesh.hy], x0=[mesh.x0[0], mesh.x0[1]]
)
out = ModelBuilder.randomModel(
mesh.vnC[:2], bounds=[zmin, zmax], its=its,
seed=seed, anisotropy=anisotropy
)
return out, mesh2D
elif mesh.dim == 2:
mesh1D = discretize.TensorMesh([mesh.hx], x0=[mesh.x0[0]])
out = ModelBuilder.randomModel(
mesh.vnC[:1], bounds=[zmin, zmax], its=its,
seed=seed, anisotropy=anisotropy
)
return out, mesh1D
else:
raise Exception("Only works for 2D and 3D models")
ax.set_xlim(xlim)
ax.set_ylim(zlim)
###############################################################################
# Waveform for the Long On-Time Simulation
# ----------------------------------------
#
# Here, we define our time-steps for the simulation where we will use a
# waveform with a long on-time to reach a steady-state magnetic field and
# define a quarter-sine ramp-on waveform as our transmitter waveform
ramp = [
(1e-5, 20), (1e-4, 20), (3e-4, 20), (1e-3, 20), (3e-3, 20), (1e-2, 20),
(3e-2, 20), (1e-1, 20), (3e-1, 20), (1, 50)
]
time_mesh = discretize.TensorMesh([ramp])
# define an off time past when we will simulate to keep the transmitter on
offTime = 100
quarter_sine = TDEM.Src.QuarterSineRampOnWaveform(
ramp_on=np.r_[0., 3], ramp_off= offTime - np.r_[1., 0]
)
# evaluate the waveform at each time in the simulation
quarter_sine_plt = [quarter_sine.eval(t) for t in time_mesh.gridN]
fig, ax = plt.subplots(1, 1, figsize=(6, 4))
ax.plot(time_mesh.gridN, quarter_sine_plt)
ax.plot(time_mesh.gridN, np.zeros(time_mesh.nN), 'k|', markersize=2)
ax.set_title('quarter sine waveform')
###############################################################################
]
y0 = ylocs.min()-dy/2.
y0_mesh = -(
(dy * pad_rate_y ** (np.arange(npad_y)+1)).sum()
+ dy*3 - y0
)
h = [hx, hy, hz]
x0_for_mesh = [x0_mesh, y0_mesh, z0_mesh]
self.xyzlim = np.vstack((
np.r_[x0, x0+lineLength],
np.r_[ymin-dy*3, ymax+dy*3],
np.r_[zmax-corezlength, zmax]
))
fill_value = np.nan
mesh = Mesh.TensorMesh(h, x0=x0_for_mesh)
actind = Utils.surface2ind_topo(mesh, locs, method=method, fill_value=fill_value)
else:
raise NotImplementedError()
return mesh, actind
def time_mesh(self):
if getattr(self, '_time_mesh', None) is None:
self._time_mesh = TensorMesh([self.time_steps], x0=[self.t0])
return self._time_mesh
def time_mesh(self):
if getattr(self, '_time_mesh', None) is None:
self._time_mesh = discretize.TensorMesh(
[self.time_steps], x0=[self.t0]
)
return self._time_mesh
data_object = data.Data(survey, dobs=dobs, noise_floor=uncertainties)
#############################################
# Defining a Tensor Mesh
# ----------------------
#
# Here, we create the tensor mesh that will be used to invert TMI data.
# If desired, we could define an OcTree mesh.
#
dh = 5.
hx = [(dh, 5, -1.3), (dh, 40), (dh, 5, 1.3)]
hy = [(dh, 5, -1.3), (dh, 40), (dh, 5, 1.3)]
hz = [(dh, 5, -1.3), (dh, 15)]
mesh = TensorMesh([hx, hy, hz], 'CCN')
########################################################
# Starting/Reference Model and Mapping on Tensor Mesh
# ---------------------------------------------------
#
# Here, we would create starting and/or reference models for the inversion as
# well as the mapping from the model space to the active cells. Starting and
# reference models can be a constant background value or contain a-priori
# structures. Here, the background is 1e-4 SI.
#
# Define background susceptibility model in SI
background_susceptibility = 1e-4
# Find the indecies of the active cells in forward model (ones below surface)
ind_active = surface2ind_topo(mesh, xyz_topo)