示例#1
0
    def test_replace_var(self):
        """Tests whether the replace variable function works.
        """

        # Test par file
        parfile = os.path.join(DATA_DIR, "Par_file")

        # Set new value
        newval = 4

        with tempfile.NamedTemporaryFile(mode='w+t') as tmpfile:
            # Copy parfile content to temporary file.
            print(tmpfile)
            with open(parfile) as PF:
                for line in PF:
                    tmpfile.write(line)

            # Back to start of file
            tmpfile.seek(0)

            # Replace value
            DATAFixer.replace_varval(tmpfile.name, "NCHUNKS", newval)

            # Check if value is
            val = DATAFixer.get_val(tmpfile.name, "NCHUNKS")

            # Check if value has changed
            self.assertTrue(newval == int(val))
示例#2
0
    def test_get_val(self):
        """ Tests static method get_val"""

        # Test par file
        parfile = os.path.join(DATA_DIR, "Par_file")

        # Solution
        original_value = 6

        # Get the value from the file
        val = DATAFixer.get_val(parfile, 'NCHUNKS')

        print(val)
        # Check if values match
        self.assertTrue(original_value == int(val))
def Fix_Specfem():
    """This Function uses the parameters found in
    ::

        GCMT3D/workflow/params/SpecfemParams/SpecfemParams.yml

    and

    ::

        GCMT3D/workflow/params/SpecfemParams/CompilersAndModules.yml

    to fix and recompile the software which is necessary for the simulation
    and inversion of the data.

    Since all data are taken from the parameter files. there are no in- and
    outputs.

    """
    # Define parameter directory
    param_path = os.path.join(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "params")
    specfemspec_path = os.path.join(param_path,
                                    "SpecfemParams/SpecfemParams.yml")
    comp_and_modules_path = os.path.\
        join(param_path, "SpecfemParams/CompilersAndModules.yml")

    # Load parameters
    sf_dict = smart_read_yaml(specfemspec_path, mpi_mode=is_mpi_env())
    cm_dict = smart_read_yaml(comp_and_modules_path, mpi_mode=is_mpi_env())

    # Define the specfemdatafixer
    df = DATAFixer(
        sf_dict["SPECFEM_DIR"],
        NEX_XI=sf_dict["NEX_XI"],
        NEX_ETA=sf_dict["NEX_ETA"],
        NPROC_XI=sf_dict["NPROC_XI"],
        NPROC_ETA=sf_dict["NPROC_ETA"],
        ROTATE_SEISMOGRAMS_RT=sf_dict["ROTATE_SEISMOGRAMS_RT"],
        RECORD_LENGTH=sf_dict["RECORD_LENGTH"],
        MODEL=sf_dict["MODEL"],
        WRITE_SEISMOGRAMS_BY_MASTER=sf_dict["WRITE_SEISMOGRAMS_BY_MASTER"],
        OUTPUT_SEISMOS_ASCII_TEXT=sf_dict["OUTPUT_SEISMOS_ASCII_TEXT"],
        OUTPUT_SEISMOS_SAC_ALPHANUM=sf_dict["OUTPUT_SEISMOS_SAC_ALPHANUM"],
        OUTPUT_SEISMOS_SAC_BINARY=sf_dict["OUTPUT_SEISMOS_SAC_BINARY"],
        OUTPUT_SEISMOS_ASDF=sf_dict["OUTPUT_SEISMOS_ASDF"],
        MOVIE_SURFACE=sf_dict["MOVIE_SURFACE"],
        MOVIE_VOLUME=sf_dict["MOVIE_VOLUME"],
        MOVIE_COARSE=sf_dict["MOVIE_COARSE"],
        GPU_MODE=sf_dict["GPU_MODE"],
        GPU_RUNTIME=sf_dict["GPU_RUNTIME"],
        GPU_PLATFORM=sf_dict["GPU_PLATFORM"],
        GPU_DEVICE=sf_dict["GPU_DEVICE"],
        ADIOS_ENABLED=sf_dict["ADIOS_ENABLED"],
        ADIOS_FOR_FORWARD_ARRAYS=sf_dict["ADIOS_FOR_FORWARD_ARRAYS"],
        ADIOS_FOR_MPI_ARRAYS=sf_dict["ADIOS_FOR_MPI_ARRAYS"],
        ADIOS_FOR_ARRAYS_SOLVER=sf_dict["ADIOS_FOR_ARRAYS_SOLVER"],
        ADIOS_FOR_SOLVER_MESHFILES=sf_dict["ADIOS_FOR_SOLVER_MESHFILES"],
        ADIOS_FOR_AVS_DX=sf_dict["ADIOS_FOR_AVS_DX"],
        ADIOS_FOR_KERNELS=sf_dict["ADIOS_FOR_KERNELS"],
        ADIOS_FOR_MODELS=sf_dict["ADIOS_FOR_MODELS"],
        ADIOS_FOR_UNDO_ATTENUATION=sf_dict["ADIOS_FOR_UNDO_ATTENUATION"],
        modules=cm_dict["modulelist"],
        gpu_module=cm_dict["gpu_module"],
        gpu_version=cm_dict["gpu_version"],
        cc=cm_dict["cc"],
        cpp=cm_dict["cpp"],
        mpicc=cm_dict["mpicc"],
        f90=cm_dict["f90"],
        mpif90=cm_dict["mpif90"],
        nodes=sf_dict["nodes"],
        tasks=sf_dict["tasks"],
        tasks_per_node=sf_dict["tasks_per_node"],
        walltime=sf_dict["walltime"],
        walltime_solver=sf_dict["walltime"],
        memory_req=sf_dict["memory_req"],
        verbose=sf_dict["verbose"])

    # Run `Par_file` fixer.
    df.fix_parfiles()

    # Configure and compile
    df.configure_and_make()

    # Run the mesher to a slurm scheduler.
    df.run_mesher()
def main():
    """This script controlls the compilation and setting up of
    specfem3d_globe.

    Usage:
        In the command line
        ``00_Fix_Specfem_And_Recompile.py``

    It uses the parameter files located in
    ``../params/SpecfemParams/SpecfemParams.yml``
    and ``../params/SpecfemParams/CompAndModules.yaml`` to get all necessary
    parameters.

    """

    # Define parameter directory
    param_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(
        __file__))), "params")
    specfemspec_path = os.path.join(param_path,
                                    "SpecfemParams/SpecfemParams.yml")
    comp_and_modules_path = os.path.join(param_path,
                                    "SpecfemParams/CompilersAndModules.yml")

    # Load parameters
    sf_dict = smart_read_yaml(specfemspec_path, mpi_mode=is_mpi_env())
    cm_dict = smart_read_yaml(comp_and_modules_path, mpi_mode=is_mpi_env())

    # Define the specfemdatafixer
    DF = DATAFixer(sf_dict["SPECFEM_DIR"],
                   NEX_XI=sf_dict["NEX_XI"], NEX_ETA=sf_dict["NEX_ETA"],
                   NPROC_XI=sf_dict["NPROC_XI"], NPROC_ETA=sf_dict["NPROC_ETA"],
                   ROTATE_SEISMOGRAMS_RT=sf_dict["ROTATE_SEISMOGRAMS_RT"],
                   RECORD_LENGTH=sf_dict["RECORD_LENGTH"],
                   MODEL=sf_dict["MODEL"],
                   WRITE_SEISMOGRAMS_BY_MASTER=sf_dict[
                       "WRITE_SEISMOGRAMS_BY_MASTER"],
                   OUTPUT_SEISMOS_ASCII_TEXT=sf_dict[
                       "OUTPUT_SEISMOS_ASCII_TEXT"],
                   OUTPUT_SEISMOS_SAC_ALPHANUM=sf_dict[
                       "OUTPUT_SEISMOS_SAC_ALPHANUM"],
                   OUTPUT_SEISMOS_SAC_BINARY=sf_dict[
                       "OUTPUT_SEISMOS_SAC_BINARY"],
                   OUTPUT_SEISMOS_ASDF=sf_dict["OUTPUT_SEISMOS_ASDF"],
                   MOVIE_SURFACE=sf_dict["MOVIE_SURFACE"],
                   MOVIE_VOLUME=sf_dict["MOVIE_VOLUME"],
                   MOVIE_COARSE=sf_dict["MOVIE_COARSE"],
                   GPU_MODE=sf_dict["GPU_MODE"],
                   GPU_RUNTIME=sf_dict["GPU_RUNTIME"],
                   GPU_PLATFORM=sf_dict["GPU_PLATFORM"],
                   GPU_DEVICE=sf_dict["GPU_DEVICE"],
                   ADIOS_ENABLED=sf_dict["ADIOS_ENABLED"],
                   ADIOS_FOR_FORWARD_ARRAYS=sf_dict["ADIOS_FOR_FORWARD_ARRAYS"],
                   ADIOS_FOR_MPI_ARRAYS=sf_dict["ADIOS_FOR_MPI_ARRAYS"],
                   ADIOS_FOR_ARRAYS_SOLVER=sf_dict["ADIOS_FOR_ARRAYS_SOLVER"],
                   ADIOS_FOR_SOLVER_MESHFILES=sf_dict[
                       "ADIOS_FOR_SOLVER_MESHFILES"],
                   ADIOS_FOR_AVS_DX=sf_dict["ADIOS_FOR_AVS_DX"],
                   ADIOS_FOR_KERNELS=sf_dict["ADIOS_FOR_KERNELS"],
                   ADIOS_FOR_MODELS=sf_dict["ADIOS_FOR_MODELS"],
                   ADIOS_FOR_UNDO_ATTENUATION=sf_dict[
                       "ADIOS_FOR_UNDO_ATTENUATION"],
                   modules=cm_dict["modulelist"],
                   gpu_module=cm_dict["gpu_module"],
                   gpu_version=cm_dict["gpu_version"],
                   cc=cm_dict["cc"],
                   cpp=cm_dict["cpp"],
                   mpicc=cm_dict["mpicc"],
                   f90=cm_dict["f90"],
                   mpif90=cm_dict["mpif90"],
                   nodes=sf_dict["nodes"],
                   tasks=sf_dict["tasks"],
                   tasks_per_node=sf_dict["tasks_per_node"],
                   walltime=sf_dict["walltime"],
                   walltime_solver=sf_dict["walltime_solver"],
                   memory_req=sf_dict["memory_req"],
                   verbose=sf_dict["verbose"])

    # Run `Par_file` fixer.
    DF.fix_parfiles()

    # Configure and compile
    DF.configure_and_make()

    # Run the mesher to a slurm scheduler.
    DF.run_mesher()
示例#5
0
def main():
    # Define parameter directory
    param_path = os.path.join(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "params")
    specfemspec_path = os.path.join(param_path,
                                    "SpecfemParams/SpecfemParams.yml")
    comp_and_modules_path = os.path.join(
        param_path, "SpecfemParams/CompilersAndModules.yml")

    # Load parameters
    sf_dict = smart_read_yaml(specfemspec_path, mpi_mode=is_mpi_env())
    cm_dict = smart_read_yaml(comp_and_modules_path, mpi_mode=is_mpi_env())

    # Define the specfemdatafixer
    DF = DATAFixer(
        sf_dict["SPECFEM_DIR"],
        NEX_XI=sf_dict["NEX_XI"],
        NEX_ETA=sf_dict["NEX_ETA"],
        NPROC_XI=sf_dict["NPROC_XI"],
        NPROC_ETA=sf_dict["NPROC_ETA"],
        ROTATE_SEISMOGRAMS_RT=sf_dict["ROTATE_SEISMOGRAMS_RT"],
        RECORD_LENGTH=sf_dict["RECORD_LENGTH"],
        MODEL=sf_dict["MODEL"],
        WRITE_SEISMOGRAMS_BY_MASTER=sf_dict["WRITE_SEISMOGRAMS_BY_MASTER"],
        OUTPUT_SEISMOS_ASCII_TEXT=sf_dict["OUTPUT_SEISMOS_ASCII_TEXT"],
        OUTPUT_SEISMOS_SAC_ALPHANUM=sf_dict["OUTPUT_SEISMOS_SAC_ALPHANUM"],
        OUTPUT_SEISMOS_SAC_BINARY=sf_dict["OUTPUT_SEISMOS_SAC_BINARY"],
        OUTPUT_SEISMOS_ASDF=sf_dict["OUTPUT_SEISMOS_ASDF"],
        MOVIE_SURFACE=sf_dict["MOVIE_SURFACE"],
        MOVIE_VOLUME=sf_dict["MOVIE_VOLUME"],
        MOVIE_COARSE=sf_dict["MOVIE_COARSE"],
        GPU_MODE=sf_dict["GPU_MODE"],
        GPU_RUNTIME=sf_dict["GPU_RUNTIME"],
        GPU_PLATFORM=sf_dict["GPU_PLATFORM"],
        GPU_DEVICE=sf_dict["GPU_DEVICE"],
        ADIOS_ENABLED=sf_dict["ADIOS_ENABLED"],
        ADIOS_FOR_FORWARD_ARRAYS=sf_dict["ADIOS_FOR_FORWARD_ARRAYS"],
        ADIOS_FOR_MPI_ARRAYS=sf_dict["ADIOS_FOR_MPI_ARRAYS"],
        ADIOS_FOR_ARRAYS_SOLVER=sf_dict["ADIOS_FOR_ARRAYS_SOLVER"],
        ADIOS_FOR_SOLVER_MESHFILES=sf_dict["ADIOS_FOR_SOLVER_MESHFILES"],
        ADIOS_FOR_AVS_DX=sf_dict["ADIOS_FOR_AVS_DX"],
        ADIOS_FOR_KERNELS=sf_dict["ADIOS_FOR_KERNELS"],
        ADIOS_FOR_MODELS=sf_dict["ADIOS_FOR_MODELS"],
        ADIOS_FOR_UNDO_ATTENUATION=sf_dict["ADIOS_FOR_UNDO_ATTENUATION"],
        modules=cm_dict["modulelist"],
        gpu_module=cm_dict["gpu_module"],
        gpu_version=cm_dict["gpu_version"],
        cc=cm_dict["cc"],
        cpp=cm_dict["cpp"],
        mpicc=cm_dict["mpicc"],
        f90=cm_dict["f90"],
        mpif90=cm_dict["mpif90"],
        nodes=sf_dict["nodes"],
        tasks=sf_dict["tasks"],
        tasks_per_node=sf_dict["tasks_per_node"],
        walltime=sf_dict["walltime"],
        walltime_solver=sf_dict["walltime_solver"],
        memory_req=sf_dict["memory_req"],
        verbose=sf_dict["verbose"])

    # Run the mesher to a slurm scheduler.
    DF.run_mesher()