def createConstraints(self): # First order smoothness matrix self._Ctmp = pg.RSparseMapMatrix() if self.corr_l is None: pg.info("Using smoothing with zWeight = %.2f." % self.zWeight) rm = self.RST.fop.regionManager() rm.fillConstraints(self._Ctmp) # Set zWeight rm.setZWeight(self.zWeight) self.cWeight = pg.RVector() rm.fillConstraintsWeight(self.cWeight) self._CW = pg.LMultRMatrix(self._Ctmp, self.cWeight) else: pg.info("Using geostatistical constraints with " + str(self.corr_l)) # Geostatistical constraints by Jordi et al., GJI, 2018 CM = pg.utils.geostatistics.covarianceMatrix(self.mesh, I=self.corr_l) self._Ctmp = pg.matrix.Cm05Matrix(CM) self._CW = self._Ctmp # Putting together in block matrix self._C = pg.RBlockMatrix() cid = self._C.addMatrix(self._CW) self._C.addMatrixEntry(cid, 0, 0) self._C.addMatrixEntry(cid, self._Ctmp.rows(), self.cellCount) self._C.addMatrixEntry(cid, self._Ctmp.rows() * 2, self.cellCount * 2) self._C.addMatrixEntry(cid, self._Ctmp.rows() * 3, self.cellCount * 3) self.setConstraints(self._C) # Identity matrix for interparameter regularization self._I = pg.IdentityMatrix(self.cellCount) self._G = pg.RBlockMatrix() iid = self._G.addMatrix(self._I) self._G.addMatrixEntry(iid, 0, 0) self._G.addMatrixEntry(iid, 0, self.cellCount) self._G.addMatrixEntry(iid, 0, self.cellCount * 2) self._G.addMatrixEntry(iid, 0, self.cellCount * 3) self.fix_val_matrices = {} # Optionally fix phases to starting model globally or in selected cells phases = ["water", "ice", "air", "rock matrix"] for i, phase in enumerate( [self.fix_water, self.fix_ice, self.fix_air, self.fix_poro]): name = phases[i] vec = pg.RVector(self.cellCount) if phase is True: pg.info("Fixing %s content globally." % name) vec += 1.0 elif hasattr(phase, "__len__"): pg.info("Fixing %s content at selected cells." % name) phase = np.asarray(phase, dtype="int") vec[phase] = 1.0 self.fix_val_matrices[name] = pg.matrix.DiagonalMatrix(vec) self._G.addMatrix(self.fix_val_matrices[name], self._G.rows(), self.cellCount * i)
def __init__(self, mesh, data, verbose): super().__init__(mesh, data, verbose) self.setComplex(True) self._J = pg.RBlockMatrix() self.setJacobian(self._J) self._C = pg.RBlockMatrix() self.setConstraints(self._C) self.matrixHeap = []
def __init__(self, data, nlay=2, verbose=False): """Parameters: FDEM data class and number of layers.""" super(FDEM2dFOP, self).__init__(verbose) self.nlay = nlay self.header = {} self.pos, self.z, self.topo = None, None, None self.FOP = data.FOP(nlay) self.nx = len(data.x) self.nf = len(data.freq()) npar = 2 * nlay - 1 self.mesh1d = pg.createMesh1D(self.nx, npar) self.mesh_ = pg.createMesh1D(self.nx, 2 * nlay - 1) self.setMesh(self.mesh_) # self.J = NDMatrix(self.nx, self.nf*2, npar) self.J = pg.RBlockMatrix() self.FOP1d = [] for i in range(self.nx): self.FOP1d.append( pg.FDEM1dModelling(nlay, data.freq(), data.coilSpacing, -data.height)) n = self.J.addMatrix(self.FOP1d[-1].jacobian()) self.J.addMatrixEntry(n, self.nf * 2 * i, npar * i) self.J.recalcMatrixSize() print(self.J.rows(), self.J.cols())
def initJacobian(self): """TODO.""" self.jac = pg.RBlockMatrix() nData = 0 for fi in self.fops: self.jac.addMatrix(fi.jacobian(), nData, 0) nData += fi.data().size() # update total vector length self.setJacobian(self.jac)
def __init__(self, data, nlay=2, verbose=False, f=None, r=None): """Parameters: FDEM data class and number of layers.""" super(FDEMLCIFOP, self).__init__(verbose) self.nlay = nlay self.FOP = data.FOP(nlay) self.nx = len(data.x) self.nf = len(data.freq()) self.np = 2 * nlay - 1 self.mesh2d = pg.createMesh2D(self.np, self.nx) self.mesh2d.rotate(pg.RVector3(0, 0, -np.pi / 2)) self.setMesh(self.mesh2d) self.J = pg.RBlockMatrix() self.FOP1d = [] for i in range(self.nx): self.FOP1d.append(HEMmodelling(nlay, data.z[i], f, r)) n = self.J.addMatrix(self.FOP1d[-1].jacobian()) self.J.addMatrixEntry(n, self.nf * 2 * i, self.np * i) self.setJacobian(self.J)
def __init__(self, data, nlay=2, verbose=False): """Parameters: FDEM data class and number of layers.""" super(FDEM2dFOP, self).__init__(verbose) self.nlay = nlay self.FOP = data.FOP(nlay) self.nx = len(data.x) self.nf = len(data.freq()) npar = 2 * nlay - 1 self.mesh2d = pg.Mesh() self.mesh2d.create2DGrid(range(npar + 1), range(self.nx + 1)) self.setMesh(self.mesh2d) self.J = pg.RBlockMatrix() self.FOP1d = [] for i in range(self.nx): self.FOP1d.append(HEMmodelling(nlay, data.z[i])) n = self.J.addMatrix(self.FOP1d[-1].jacobian()) self.J.addMatrixEntry(n, self.nf * 2 * i, npar * i) self.J.recalcMatrixSize() print(self.J.rows(), self.J.cols()) self.setJacobian(self.J)
def __init__(self, profile, nlay=2, verbose=False): """Parameters: FDEM data class and number of layers""" super(MRSLCI, self).__init__(verbose) self.nlay = nlay self.nx = len(profile) self.np = 3 * nlay - 1 # self.mesh2d = pg.createMesh2D(npar, self.nx) # self.mesh2d = pg.createMesh2D(self.nx, self.np) self.mesh2d = pg.createMesh2D(range(self.np + 1), range(self.nx + 1)) self.mesh2d.rotate(pg.RVector3(0, 0, -np.pi / 2)) self.setMesh(self.mesh2d) self.J = pg.RBlockMatrix() self.FOP1d = [] ipos = 0 for i, mrs in enumerate(profile): mrs.createFOP(nlay, verbose=False) self.FOP1d.append(mrs.f) n = self.J.addMatrix(self.FOP1d[-1].jacobian()) self.J.addMatrixEntry(n, ipos, self.np * i) ipos += len(mrs.data) self.J.recalcMatrixSize() print(self.J.rows(), self.J.cols()) self.setJacobian(self.J)