Ejemplo n.º 1
0
    def SOF3(self, header=True, dataincommentrow=True):
        """Return a SOF3 string, combining data from the wateroil and
        gasoil objects.

        So - the oil saturation ranges from 0 to 1-swl. The saturation points
        from the WaterOil object is used to generate these
        """
        if self.wateroil is None or self.gasoil is None:
            logger.error("Both WaterOil and GasOil is needed for SOF3")
            return ""
        self.threephaseconsistency()

        # Copy of the wateroil data:
        table = pd.DataFrame(self.wateroil.table[["sw", "krow"]])
        table["so"] = 1 - table["sw"]

        # Copy of the gasoil data:
        gastable = pd.DataFrame(self.gasoil.table[["sg", "krog"]])
        gastable["so"] = 1 - gastable["sg"] - self.wateroil.swl

        # Merge WaterOil and GasOil on oil saturation, interpolate for
        # missing data (potentially different sg- and sw-grids)
        sof3table = (pd.concat(
            [table, gastable],
            sort=True).set_index("so").sort_index().interpolate(
                method="slinear").fillna(method="ffill").fillna(
                    method="bfill").reset_index())
        sof3table["soint"] = list(
            map(int, list(map(round, sof3table["so"] * SWINTEGERS))))
        sof3table.drop_duplicates("soint", inplace=True)

        # The 'so' column has been calculated from floating point numbers
        # and the zero value easily becomes a negative zero, circumvent this:
        zerorow = np.isclose(sof3table["so"], 0.0)
        sof3table.loc[zerorow, "so"] = abs(sof3table.loc[zerorow, "so"])

        string = ""
        if header:
            string += "SOF3\n"
        wo_tag = utils.comment_formatter(self.wateroil.tag)
        go_tag = utils.comment_formatter(self.gasoil.tag)
        if wo_tag != go_tag:
            string += wo_tag
            string += go_tag
        else:
            # Only print once if they are equal
            string += wo_tag
        string += "-- pyscal: " + str(pyscal.__version__) + "\n"
        if dataincommentrow:
            string += self.wateroil.swcomment
            string += self.gasoil.sgcomment
            string += self.wateroil.krowcomment
            string += self.gasoil.krogcomment

        width = 10
        string += ("-- " + "SW".ljust(width - 3) + "KROW".ljust(width) +
                   "KROG".ljust(width) + "\n")
        string += utils.df2str(sof3table[["so", "krow", "krog"]])
        string += "/\n"
        return string
Ejemplo n.º 2
0
 def SWFN(self, header=True, dataincommentrow=True):
     """Return a SWFN keyword with data to Eclipse"""
     if not self.selfcheck(mode="SWFN"):
         # selfcheck will print errors/warnings
         return ""
     string = ""
     if "pc" not in self.table.columns:
         self.table["pc"] = 0
         self.pccomment = "-- Zero capillary pressure\n"
     if header:
         string += "SWFN\n"
     string += utils.comment_formatter(self.tag)
     string += "-- pyscal: " + str(pyscal.__version__) + "\n"
     if dataincommentrow:
         string += self.swcomment
         string += self.krwcomment
         if "krow" in self.table.columns and not self.fast:
             string += "-- krw = krow @ sw=%1.5f\n" % self.crosspoint()
         string += self.pccomment
     width = 10
     string += ("-- " + "SW".ljust(width - 3) + "KRW".ljust(width) +
                "PC".ljust(width) + "\n")
     string += self.table[["sw", "krw", "pc"]].to_csv(sep=" ",
                                                      float_format="%1.7f",
                                                      header=None,
                                                      index=False)
     string += "/\n"  # Empty line at the end
     return string
Ejemplo n.º 3
0
    def SWOF(self, header=True, dataincommentrow=True):
        """
        Produce SWOF input for Eclipse reservoir simulator.

        The columns sw, krw, krow and pc are outputted and
        formatted accordingly.

        Meta-information for the tabulated data are printed
        as Eclipse comments.

        Args:
            header (bool): Indicate whether the SWOF string should
                be emitted. If you have multiple SATNUMs, you should
                set this to True only for the first (or False for all,
                and emit the SWOF yourself). Default True
            dataincommentrow (bool): Wheter metadata should
                be printed. Defualt True
        """
        if not self.fast and not self.selfcheck():
            # selfcheck failed and has issued an error message
            return ""
        string = ""
        if header:
            string += "SWOF\n"
        string += utils.comment_formatter(self.tag)
        string += "-- pyscal: " + str(pyscal.__version__) + "\n"
        if "pc" not in self.table.columns:
            self.table["pc"] = 0
            self.pccomment = "-- Zero capillary pressure\n"
        if dataincommentrow:
            string += self.swcomment
            string += self.krwcomment
            string += self.krowcomment
            if not self.fast:
                string += "-- krw = krow @ sw=%1.5f\n" % self.crosspoint()
            string += self.pccomment
        width = 10
        string += (
            "-- "
            + "SW".ljust(width - 3)
            + "KRW".ljust(width)
            + "KROW".ljust(width)
            + "PC".ljust(width)
            + "\n"
        )
        string += utils.df2str(
            self.table[["sw", "krw", "krow", "pc"]],
            monotone_column="pc",
            monotone_direction="dec",
        )
        string += "/\n"  # Empty line at the end
        return string
Ejemplo n.º 4
0
    def SGOF(self, header=True, dataincommentrow=True):
        """
        Produce SGOF input for Eclipse reservoir simulator.

        The columns sg, krg, krog and pc are outputted and
        formatted accordingly.

        Meta-information for the tabulated data are printed
        as Eclipse comments.

        Args:
            header (bool): Whether the SGOF string should be emitted.
                If you have multiple satnums, you should have True only
                for the first (or False for all, and emit the SGOF yourself).
                Defaults to True.
            dataincommentrow (bool): Whether metadata should be printed,
                defaults to True.
        """
        if not self.fast and not self.selfcheck():
            # selfcheck() will log error/warning messages
            return ""
        string = ""
        if "pc" not in self.table:
            self.table["pc"] = 0
            self.pccomment = "-- Zero capillary pressure\n"
        if header:
            string += "SGOF\n"
        string += utils.comment_formatter(self.tag)
        string += "-- pyscal: " + str(pyscal.__version__) + "\n"
        if dataincommentrow:
            string += self.sgcomment
            string += self.krgcomment
            string += self.krogcomment
            if not self.fast:
                string += "-- krg = krog @ sw=%1.5f\n" % self.crosspoint()
            string += self.pccomment
        width = 10
        string += (
            "-- "
            + "SG".ljust(width - 3)
            + "KRG".ljust(width)
            + "KROG".ljust(width)
            + "PC".ljust(width)
            + "\n"
        )
        string += self.table[["sg", "krg", "krog", "pc"]].to_csv(
            sep=" ", float_format="%1.7f", header=None, index=False
        )
        string += "/\n"
        return string
Ejemplo n.º 5
0
def test_comment_formatter():
    """Test the comment formatter

    This is also tested through hypothesis.text()
    in test_wateroil and test_gasoil, there is it tested
    through the use of tag formatting
    """
    assert utils.comment_formatter(None) == "-- \n"
    assert utils.comment_formatter("\n") == "-- \n"
    assert utils.comment_formatter("\r\n") == "-- \n"
    assert utils.comment_formatter("\r") == "-- \n"
    assert utils.comment_formatter("foo") == "-- foo\n"
    assert utils.comment_formatter("foo", prefix="gaa") == "gaafoo\n"
    assert utils.comment_formatter("foo\nbar") == "-- foo\n-- bar\n"
Ejemplo n.º 6
0
    def SGFN(self, header=True, dataincommentrow=True):
        """
        Produce SGFN input for Eclipse reservoir simulator.

        The columns sg, krg, and pc are outputted and
        formatted accordingly.

        Meta-information for the tabulated data are printed
        as Eclipse comments.

        Args:
            header: boolean for whether the SGOF string should be emitted.
                If you have multiple satnums, you should have True only
                for the first (or False for all, and emit the SGOF yourself).
                Defaults to True.
            dataincommentrow: boolean for wheter metadata should be printed,
                defaults to True.
        """
        string = ""
        if "pc" not in self.table.columns:
            self.table["pc"] = 0
            self.pccomment = "-- Zero capillary pressure\n"
        if header:
            string += "SGFN\n"
        string += utils.comment_formatter(self.tag)
        string += "-- pyscal: " + str(pyscal.__version__) + "\n"
        if dataincommentrow:
            string += self.sgcomment
            string += self.krgcomment
            if "krog" in self.table.columns:
                string += "-- krg = krog @ sw=%1.5f\n" % self.crosspoint()
            string += self.pccomment
        width = 10
        string += ("-- " + "SG".ljust(width - 3) + "KRG".ljust(width) +
                   "PC".ljust(width) + "\n")
        string += utils.df2str(
            self.table[["sg", "krg", "pc"]],
            monotone_column="pc",
            monotone_direction="inc",
        )
        string += "/\n"
        return string