def setup(self): g = CartGrid([5, 5]) g.compute_geometry() perm = PermTensor(g.dim, np.ones(g.num_cells)) bnd = bc.BoundaryCondition(g) flux, bound_flux, _, _ = mpfa.mpfa(g, perm, bnd, inverter="python") return g, perm, bnd, flux, bound_flux
def test_one_cell_a_time_node_keyword(self): # Update one and one cell, and verify that the result is the same as # with a single computation. # The test is similar to what will happen with a memory-constrained # splitting. g = CartGrid([3, 3]) g.compute_geometry() # Assign random permeabilities, for good measure np.random.seed(42) kxx = np.random.random(g.num_cells) kyy = np.random.random(g.num_cells) # Ensure positive definiteness kxy = np.random.random(g.num_cells) * kxx * kyy perm = PermTensor(2, kxx=kxx, kyy=kyy, kxy=kxy) flux = sps.csr_matrix((g.num_faces, g.num_cells)) bound_flux = sps.csr_matrix((g.num_faces, g.num_faces)) faces_covered = np.zeros(g.num_faces, np.bool) bnd = bc.BoundaryCondition(g) cn = g.cell_nodes() for ci in range(g.num_cells): ind = np.zeros(g.num_cells) ind[ci] = 1 nodes = np.squeeze(np.where(cn * ind > 0)) partial_flux, partial_bound, _, _, active_faces = mpfa.mpfa_partial( g, perm, bnd, nodes=nodes, inverter="python") if np.any(faces_covered): partial_flux[faces_covered, :] *= 0 partial_bound[faces_covered, :] *= 0 faces_covered[active_faces] = True flux += partial_flux bound_flux += partial_bound flux_full, bound_flux_full, _, _ = mpfa.mpfa(g, perm, bnd, inverter="python") self.assertTrue((flux_full - flux).max() < 1e-8) self.assertTrue((flux_full - flux).min() > -1e-8) self.assertTrue((bound_flux - bound_flux_full).max() < 1e-8) self.assertTrue((bound_flux - bound_flux_full).min() > -1e-8)