Ejemplo n.º 1
0
    def test_Simulation3DCellCentered_Neumann(self, tolerance=0.1):
        simulation = dc.Simulation3DCellCentered(self.mesh,
                                                 survey=self.survey,
                                                 sigma=self.sigma,
                                                 bc_type="Neumann")
        simulation.solver = Solver

        f = simulation.fields(self.sigma)
        eNumeric = utils.mkvc(f[self.survey.source_list, "e"])
        jNumeric = utils.mkvc(f[self.survey.source_list, "j"])
        errE = np.linalg.norm(jNumeric[self.ROIfaceInds] - self.J_analytic[
            self.ROIfaceInds]) / np.linalg.norm(
                self.J_analytic[self.ROIfaceInds])
        errJ = np.linalg.norm(eNumeric[self.ROIfaceInds] - self.E_analytic[
            self.ROIfaceInds]) / np.linalg.norm(
                self.E_analytic[self.ROIfaceInds])
        if errE < tolerance and errJ < tolerance:
            print("\n")
            print("E field error =", errE)
            print("J field error =", errJ)
            passed = True
            print(
                ">> DC analytic test for Simulation3DCellCentered_Neumann passed"
            )
        else:
            print("\n")
            print("E field error =", errE)
            print("J field error =", errJ)
            passed = False
            print(
                ">> DC analytic test for Simulation3DCellCentered_Neumann failed"
            )
        self.assertTrue(passed)
Ejemplo n.º 2
0
    def test_Simulation3DCellCentered_Mixed(self, tolerance=0.05):
        simulation = dc.Simulation3DCellCentered(
            self.mesh,
            survey=self.survey,
            sigma=self.sigma,
            bc_type="Mixed",
            solver=Solver,
        )
        data = simulation.dpred()

        err = np.sqrt((((data - self.data_ana) / self.data_ana)**2).sum() /
                      self.survey.nD)
        if err < tolerance:
            print(err)
            passed = True
            print(">> DC analytic test for Simulation3DCellCentered is passed")
        else:
            print(err)
            passed = False
            print(">> DC analytic test for Simulation3DCellCentered is failed")
        self.assertTrue(passed)
Ejemplo n.º 3
0
    def test_Simulation3DCellCentered_Dirichlet(self, tolerance=0.1):
        simulation = dc.Simulation3DCellCentered(self.mesh,
                                                 survey=self.survey,
                                                 sigma=self.sigma,
                                                 bc_type="Dirichlet")
        simulation.solver = Solver

        #        f = simulation.fields()
        f = simulation.fields(self.sigma)
        eNumeric = utils.mkvc(f[self.survey.source_list, "e"])
        jNumeric = utils.mkvc(f[self.survey.source_list, "j"])
        # also test we can get charge and charge density
        f[:, "charge"]
        f[:, "charge_density"]

        errE = np.linalg.norm(jNumeric[self.ROIfaceInds] - self.J_analytic[
            self.ROIfaceInds]) / np.linalg.norm(
                self.J_analytic[self.ROIfaceInds])
        errJ = np.linalg.norm(eNumeric[self.ROIfaceInds] - self.E_analytic[
            self.ROIfaceInds]) / np.linalg.norm(
                self.E_analytic[self.ROIfaceInds])
        if errE < tolerance and errJ < tolerance:
            print("\n")
            print("E field error =", errE)
            print("J field error =", errJ)
            passed = True
            print(
                ">> DC analytic test for Simulation3DCellCentered_Dirichlet passed"
            )
        else:
            print("\n")
            print("E field error =", errE)
            print("J field error =", errJ)
            passed = False
            print(
                ">> DC analytic test for Simulation3DCellCentered_Dirchlet failed"
            )
        self.assertTrue(passed)
Ejemplo n.º 4
0
    def test_io_rhoa(self):
        # Setup a dipole-dipole Survey

        for survey_type, test_file, rhoa_file in zip(
            ["dipole-dipole", "pole-dipole", "dipole-pole", "pole-pole"],
            [
                "2sph_dipole_dipole.obs",
                "2sph_pole_dipole.obs",
                "2sph_dipole_pole.obs",
                "2sph_pole_pole.obs",
            ],
            [
                "rhoA_GIF_dd.txt",
                "rhoA_GIF_pd.txt",
                "rhoA_GIF_dp.txt",
                "rhoA_GIF_pp.txt",
            ],
        ):
            print("\n Testing {} ... ".format(survey_type))
            survey = utils.gen_DCIPsurvey(
                self.xyz,
                survey_type=survey_type,
                dim=self.mesh.dim,
                a=self.survey_a,
                b=self.survey_b,
                n=self.survey_n,
            )

            self.assertEqual(survey_type, survey.survey_type)

            # Setup Problem with exponential mapping
            expmap = maps.ExpMap(self.mesh)
            problem = dc.Simulation3DCellCentered(
                self.mesh, sigmaMap=expmap, survey=survey, bc_type="Neumann"
            )
            problem.solver = Solver

            # Create synthetic data
            dobs = problem.make_synthetic_data(self.model, relative_error=0.0)
            dobs.eps = 1e-5

            # Testing IO
            surveyfile = os.path.sep.join([self.basePath, test_file])
            utils.writeUBC_DCobs(
                surveyfile, dobs, survey_type=survey_type, dim=3, format_type="GENERAL"
            )
            data2 = utils.readUBC_DC3Dobs(surveyfile)
            self.assertTrue(np.allclose(mkvc(data2), mkvc(dobs)))

            if self.plotIt:
                import matplotlib.pyplot as plt

                # Test Pseudosections plotting
                fig, ax = plt.subplots(1, 1, figsize=(15, 3))
                ax = utils.plot_pseudoSection(
                    survey,
                    ax,
                    survey_type=survey_type,
                    scale="log",
                    clim=None,
                    data_type="appResistivity",
                    pcolorOpts={"cmap": "viridis"},
                    data_location=True,
                )
                plt.show()

            # Test the utils functions electrode_separations,
            # source_receiver_midpoints, geometric_factor,
            # apparent_resistivity all at once
            rhoapp = utils.apparent_resistivity(
                dobs, survey_type=survey_type, space_type="half-space", eps=0.0
            )

            rhoA_GIF_file = os.path.sep.join([self.basePath, rhoa_file])
            rhoA_GIF = np.loadtxt(rhoA_GIF_file)
            passed = np.allclose(rhoapp, rhoA_GIF)
            self.assertTrue(passed)
            print("   ... ok \n".format(survey_type))