Exemple #1
0
def test_toepliz_get_submatrix_hy_noteq_hx_and_nx_eq_ny():
    # Mesh hx!=hy, nx=ny
    Mesh = CartesianMesh(1.4, 1.6, 19, 19)
    # old way
    C = load_isotropic_elasticity_matrix(Mesh, Ep)
    # new way
    C_obj = load_isotropic_elasticity_matrix_toepliz(Mesh, Ep)
    slice = np.asarray(range(Mesh.NumberOfElts))
    C_new = C_obj[np.ix_(slice, slice)]
    common_test_for_all_toepliz_tests(C, C_new, expect_simmetric=True)
Exemple #2
0
def test_toepliz_get_submatrix_same_dim():
    Mesh = CartesianMesh(0.45, 0.6, 39, 49)
    # old way
    C = load_isotropic_elasticity_matrix(Mesh, Ep)
    # new way
    C_obj = load_isotropic_elasticity_matrix_toepliz(Mesh, Ep)
    xslice = np.asarray([33, 55, 66])
    yslice = np.asarray([27, 12, 41])
    C_new_sliced = C_obj[np.ix_(xslice, yslice)]
    C_sliced = C[np.ix_(xslice, yslice)]
    common_test_for_all_toepliz_tests(C_sliced,
                                      C_new_sliced,
                                      expect_simmetric=False)
Exemple #3
0
simulProp.set_outputFolder("./Data/star")  # the address of the output folder
simulProp.plotTSJump = 4

# initializing fracture
from fracture_initialization import get_radial_survey_cells
initRad = np.pi
surv_cells, _, inner_cells = get_radial_survey_cells(Mesh, initRad)
surv_cells_dist = np.cos(Mesh.CenterCoor[surv_cells, 0]) + 2.5 - abs(
    Mesh.CenterCoor[surv_cells, 1])
Fr_geometry = Geometry(shape='level set',
                       survey_cells=surv_cells,
                       tip_distances=surv_cells_dist,
                       inner_cells=inner_cells)

from elasticity import load_isotropic_elasticity_matrix
C = load_isotropic_elasticity_matrix(Mesh, Eprime)
init_param = InitializationParameters(Fr_geometry,
                                      regime='static',
                                      net_pressure=1e3,
                                      elasticity_matrix=C)

# creating fracture object
Fr = Fracture(Mesh, init_param, Solid, Fluid, Injection, simulProp)

# create a Controller
controller = Controller(Fr, Solid, Fluid, Injection, simulProp)

# run the simulation
controller.run()

####################
Exemple #4
0
    def run(self):
        """
        This function runs the simulation according to the parameters given in the properties classes. See especially
        the documentation of the :py:class:`properties.SimulationProperties` class to get details of the parameters
        controlling the simulation run.
        """

        # output initial fracture
        if self.sim_prop.saveToDisk:
            # save properties
            if not os.path.exists(self.sim_prop.get_outputFolder()):
                os.makedirs(self.sim_prop.get_outputFolder())

            prop = (self.solid_prop, self.fluid_prop, self.injection_prop,
                    self.sim_prop)
            with open(self.sim_prop.get_outputFolder() + "properties",
                      'wb') as output:
                dill.dump(prop, output, -1)

        if self.sim_prop.plotFigure or self.sim_prop.saveToDisk:
            # save or plot fracture
            self.output(self.fracture)
            self.lastSavedTime = self.fracture.time

        if self.sim_prop.saveToDisk:
            if os.path.exists(self.logAddress + "log.txt"):
                os.remove(self.logAddress + "log.txt")
            with open(self.logAddress + 'log.txt', 'w+') as file:
                file.writelines('log file, simulation run at: ' +
                                strftime("%Y-%m-%d %H:%M:%S", gmtime()) +
                                '\n\n')

        # load elasticity matrix
        if self.C is None:
            print("Making elasticity matrix...")
            if self.sim_prop.symmetric:
                if not self.sim_prop.get_volumeControl():
                    raise ValueError(
                        "Symmetric fracture is only supported for inviscid fluid yet!"
                    )

            if not self.solid_prop.TI_elasticity:
                if self.sim_prop.symmetric:
                    self.C = load_isotropic_elasticity_matrix_symmetric(
                        self.fracture.mesh, self.solid_prop.Eprime)
                else:
                    self.C = load_isotropic_elasticity_matrix(
                        self.fracture.mesh, self.solid_prop.Eprime)
            else:
                C = load_TI_elasticity_matrix(self.fracture.mesh,
                                              self.solid_prop, self.sim_prop)
                # compressing the elasticity matrix for symmetric fracture
                if self.sim_prop.symmetric:
                    self.C = symmetric_elasticity_matrix_from_full(
                        C, self.fracture.mesh)
                else:
                    self.C = C

            print('Done!')

        # # perform first time step with implicit front advancing due to non-availability of velocity
        # if not self.sim_prop.symmetric:
        #     if self.sim_prop.frontAdvancing == "predictor-corrector":
        #         self.sim_prop.frontAdvancing = "implicit"

        print("Starting time = " + repr(self.fracture.time))
        # starting time stepping loop
        while self.fracture.time < 0.999 * self.sim_prop.finalTime and self.TmStpCount < self.sim_prop.maxTimeSteps:

            timeStep = self.get_time_step()

            if self.sim_prop.collectPerfData:
                tmStp_perf = IterationProperties(itr_type="time step")
            else:
                tmStp_perf = None

            # advancing time step
            status, Fr_n_pls1 = self.advance_time_step(self.fracture, self.C,
                                                       timeStep, tmStp_perf)

            if self.sim_prop.collectPerfData:
                tmStp_perf.CpuTime_end = time.time()
                tmStp_perf.status = status == 1
                tmStp_perf.failure_cause = self.errorMessages[status]
                tmStp_perf.time = self.fracture.time
                tmStp_perf.NumbOfElts = len(self.fracture.EltCrack)
                self.perfData.append(tmStp_perf)

            if status == 1:
                # Successful time step
                print("Time step successful!")
                self.delta_w = Fr_n_pls1.w - self.fracture.w
                self.lstTmStp = Fr_n_pls1.time - self.fracture.time
                # output
                if self.sim_prop.plotFigure or self.sim_prop.saveToDisk:
                    if Fr_n_pls1.time > self.lastSavedTime:
                        self.output(Fr_n_pls1)

                # add the advanced fracture to the last five fractures list
                self.fracture = copy.deepcopy(Fr_n_pls1)
                self.fr_queue[self.successfulTimeSteps %
                              5] = copy.deepcopy(Fr_n_pls1)

                if self.fracture.time > self.lastSuccessfulTS:
                    self.lastSuccessfulTS = self.fracture.time
                if self.maxTmStp < self.lstTmStp:
                    self.maxTmStp = self.lstTmStp
                # put check point reattempts to zero if the simulation has advanced past the time where it failed
                if Fr_n_pls1.time > self.lastSuccessfulTS + 2 * self.maxTmStp:
                    self.chkPntReattmpts = 0
                    # set the prefactor to the original value after four time steps (after the 5 time steps back jump)
                    self.sim_prop.tmStpPrefactor = self.tmStpPrefactor_copy
                self.successfulTimeSteps += 1

                # resetting the parameters for closure
                if self.fullyClosed:
                    # set to solve for pressure if the fracture was fully closed in last time step and is open now
                    self.sim_prop.solveDeltaP = False
                else:
                    self.sim_prop.solveDeltaP = self.solveDetlaP_cp
                self.PstvInjJmp = None
                self.fullyClosed = False

                # set front advancing back as set in simulation properties originally if velocity becomes available.
                if np.max(Fr_n_pls1.v) > 0 or not np.isnan(Fr_n_pls1.v).any():
                    self.sim_prop.frontAdvancing = copy.copy(
                        self.frontAdvancing)
                else:
                    self.sim_prop.frontAdvancing = 'implicit'

                if self.TmStpCount == self.sim_prop.maxTimeSteps:
                    print("Max time steps reached!")

            elif status == 12:
                # re-meshing required
                if self.sim_prop.enableRemeshing:
                    self.C *= 1 / self.sim_prop.remeshFactor
                    print("Remeshing...")
                    coarse_mesh = CartesianMesh(
                        self.sim_prop.remeshFactor * self.fracture.mesh.Lx,
                        self.sim_prop.remeshFactor * self.fracture.mesh.Ly,
                        self.fracture.mesh.nx,
                        self.fracture.mesh.ny,
                        symmetric=self.sim_prop.symmetric)
                    self.solid_prop.remesh(coarse_mesh)
                    self.injection_prop.remesh(coarse_mesh, self.fracture.mesh)
                    self.fracture = self.fracture.remesh(
                        self.sim_prop.remeshFactor, self.C, coarse_mesh,
                        self.solid_prop, self.fluid_prop, self.injection_prop,
                        self.sim_prop)
                    # update the saved properties
                    if self.sim_prop.saveToDisk:
                        prop = (self.solid_prop, self.fluid_prop,
                                self.injection_prop, self.sim_prop)
                        with open(
                                self.sim_prop.get_outputFolder() +
                                "properties", 'wb') as output:
                            dill.dump(prop, output, -1)
                    self.remeshings += 1
                    print("Done!")

                    self.write_to_log("\nRemeshed at " +
                                      repr(self.fracture.time))

                else:
                    print("Reached end of the domain. Exiting...")
                    break

            elif status == 14:
                # fracture fully closed
                self.output(Fr_n_pls1)
                if self.PstvInjJmp is None:
                    inp = input(
                        "Fracture is fully closed.\n\nDo you want to jump to"
                        " the time of next positive injection? [y/n]")
                    while inp not in ['y', 'Y', 'n', 'N']:
                        inp = input("Press y or n")

                    if inp is 'y' or inp is 'Y':
                        self.PstvInjJmp = True
                    else:
                        self.PstvInjJmp = False

                if self.PstvInjJmp:
                    self.sim_prop.solveDeltaP = False
                    # index of current time in the time series (first row) of the injection rate array
                    time_larger = np.where(
                        Fr_n_pls1.time <= self.injection_prop.injectionRate[
                            0, :])[0]
                    pos_inj = np.where(
                        self.injection_prop.injectionRate[1, :] > 0)[0]
                    after_time = np.intersect1d(time_larger, pos_inj)
                    if len(after_time) == 0:
                        print("Positive injection not found!")
                        break
                    jump_to = min(self.injection_prop.injectionRate[
                        0, np.intersect1d(time_larger, pos_inj)])
                    Fr_n_pls1.time = jump_to
                elif inp is 'n' or inp is 'N':
                    self.sim_prop.solveDeltaP = True
                self.fullyClosed = True
                self.fracture = copy.deepcopy(Fr_n_pls1)

            else:
                # time step failed
                self.write_to_log("\n" + self.errorMessages[status])
                self.write_to_log("\nTime step failed at = " +
                                  repr(self.fracture.time))
                # check if the queue with last 5 time steps is not empty, or max check points jumps done
                if self.fr_queue[self.successfulTimeSteps % 5] is None or \
                   self.chkPntReattmpts == 4:
                    if self.sim_prop.collectPerfData:
                        if self.sim_prop.saveToDisk:
                            file_address = self.sim_prop.get_outputFolder(
                            ) + "perf_data.dat"
                        else:
                            file_address = "./perf_data.dat"
                        with open(file_address, 'wb') as perf_output:
                            dill.dump(self.perfData, perf_output, -1)

                    self.write_to_log("\n\n---Simulation failed---")

                    raise SystemExit("Simulation failed.")
                else:
                    # decrease time step pre-factor before taking the next fracture in the queue having last
                    # five time steps
                    if isinstance(self.sim_prop.tmStpPrefactor, np.ndarray):
                        indxCurTime = max(
                            np.where(self.fracture.time >=
                                     self.sim_prop.tmStpPrefactor[0, :])[0])
                        self.sim_prop.tmStpPrefactor[1, indxCurTime] *= 0.8
                        current_PreFctr = self.sim_prop.tmStpPrefactor[
                            1, indxCurTime]
                    else:
                        self.sim_prop.tmStpPrefactor *= 0.8
                        current_PreFctr = self.sim_prop.tmStpPrefactor

                    self.chkPntReattmpts += 1
                    self.fracture = copy.deepcopy(
                        self.fr_queue[(self.successfulTimeSteps +
                                       self.chkPntReattmpts) % 5])
                    print(
                        "Time step have failed despite of reattempts with slightly smaller/bigger time steps...\n"
                        "Going " + repr(5 - self.chkPntReattmpts) +
                        " time steps back and re-attempting with the"
                        " time step pre-factor of " + repr(current_PreFctr))
                    self.write_to_log("\nTime step have failed. Going " +
                                      repr(6 - self.chkPntReattmpts) +
                                      " time steps"
                                      " back...\n")
                    self.failedTimeSteps += 1

            self.TmStpCount += 1

        self.write_to_log("\n\n-----Simulation finished------")
        self.write_to_log("\n\nnumber of time steps = " +
                          repr(self.successfulTimeSteps))
        self.write_to_log("\nfailed time steps = " +
                          repr(self.failedTimeSteps))
        self.write_to_log("\nnumber of remeshings = " + repr(self.remeshings))

        plt.show(block=False)
        plt.close('all')

        if self.sim_prop.collectPerfData:
            file_address = self.sim_prop.get_outputFolder() + "perf_data.dat"
            os.makedirs(os.path.dirname(file_address), exist_ok=True)
            with open(file_address, 'wb') as output:
                dill.dump(self.perfData, output, -1)

        print("\nFinal time = " + repr(self.fracture.time))
        print("\n\n-----Simulation finished------")
        print("See log file for details\n\n")