示例#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 = comment_formatter(self.wateroil.tag)
        go_tag = 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 += df2str(sof3table[["so", "krow", "krog"]])
        string += "/\n"
        return string
示例#2
0
    def SGOF(self, header: bool = True, dataincommentrow: bool = True) -> str:
        """
        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: 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: 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.0
            self.pccomment = "-- Zero capillary pressure\n"
        if header:
            string += "SGOF\n"
        string += 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 @ sg=%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 += df2str(
            self.table[["SG", "KRG", "KROG", "PC"]],
            monotonicity={
                "KROG": {
                    "sign": -1,
                    "lower": 0,
                    "upper": 1
                },
                "KRG": {
                    "sign": 1,
                    "lower": 0,
                    "upper": 1
                },
                "PC": {
                    "sign": 1,
                    "allowzero": True
                },
            } if not self.fast else None,
        )
        string += "/\n"
        return string
示例#3
0
    def SLGOF(self, header=True, dataincommentrow=True):
        """Produce SLGOF input for Eclipse reservoir simulator.

        The columns sl (liquid saturation), krg, krog and pc are
        outputted and formatted accordingly.

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

        Args:
            header: boolean for whether the SLGOF 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.
        """
        if not self.selfcheck():
            # Selfcheck will issue error messages.
            return ""
        string = ""
        if "pc" not in self.table:
            self.table["pc"] = 0.0
            self.pccomment = "-- Zero capillary pressure\n"
        if header:
            string += "SLGOF\n"
        string += comment_formatter(self.tag)
        string += "-- pyscal: " + str(pyscal.__version__) + "\n"
        if dataincommentrow:
            string += self.sgcomment
            string += self.krgcomment
            string += self.krogcomment
            string += "-- krg = krog @ sg=%1.5f\n" % self.crosspoint()
            string += self.pccomment
        width = 10
        string += ("-- " + "SL".ljust(width - 3) + "KRG".ljust(width) +
                   "KROG".ljust(width) + "PC".ljust(width) + "\n")
        string += df2str(
            self.slgof_df(),
            monotonocity={
                "krog": {
                    "sign": 1,
                    "lower": 0,
                    "upper": 1
                },
                "krg": {
                    "sign": -1,
                    "lower": 0,
                    "upper": 1
                },
                "pc": {
                    "sign": -1,
                    "allowzero": True
                },
            },
        )
        string += "/\n"
        return string
示例#4
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 += comment_formatter(self.tag)
        string += "-- pyscal: " + str(pyscal.__version__) + "\n"
        if "pc" not in self.table.columns:
            self.table["pc"] = 0.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 += df2str(
            self.table[["sw", "krw", "krow", "pc"]],
            monotonocity={
                "krow": {"sign": -1, "lower": 0, "upper": 1},
                "krw": {"sign": 1, "lower": 0, "upper": 1},
                "pc": {"sign": -1, "allowzero": True},
            }
            if not self.fast
            else None,
        )
        string += "/\n"  # Empty line at the end
        return string
示例#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 comment_formatter(None) == "-- \n"
    assert comment_formatter("\n") == "-- \n"
    assert comment_formatter("\r\n") == "-- \n"
    assert comment_formatter("\r") == "-- \n"
    assert comment_formatter("foo") == "-- foo\n"
    assert comment_formatter("foo", prefix="gaa") == "gaafoo\n"
    assert comment_formatter("foo\nbar") == "-- foo\n-- bar\n"
示例#6
0
    def SGFN(
        self,
        header: bool = True,
        dataincommentrow: bool = True,
        sgcomment: Optional[str] = None,
        crosspointcomment: Optional[str] = None,
    ):
        """
        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 SGFN string should be emitted.
                If you have multiple satnums, you should have True only
                for the first (or False for all, and emit the SGFN yourself).
                Defaults to True.
            dataincommentrow: boolean for wheter metadata should be printed,
                defaults to True.
            sgcomment: Provide the string to include in the comment
                section for describing the saturation endpoints. Used
                by GasWater.
            crosspointcomment: String to be used for crosspoint comment
                string, overrides what this object can provide. Used by GasWater.
                If None, it will be computed, use empty string to avoid.
        """
        if not self.selfcheck(mode="SGFN"):
            # Selfcheck will issue error messages.
            return ""
        string = ""
        if "PC" not in self.table.columns:
            self.table["PC"] = 0.0
            self.pccomment = "-- Zero capillary pressure\n"
        if header:
            string += "SGFN\n"
        string += comment_formatter(self.tag)
        string += "-- pyscal: " + str(pyscal.__version__) + "\n"
        if dataincommentrow:
            if sgcomment is not None:
                string += sgcomment
            else:
                string += self.sgcomment
            string += self.krgcomment
            if crosspointcomment is None:
                if "KROG" in self.table.columns:
                    string += "-- krg = krog @ sg=%1.5f\n" % self.crosspoint()
            else:
                string += crosspointcomment
            string += self.pccomment
        width = 10
        string += ("-- " + "SG".ljust(width - 3) + "KRG".ljust(width) +
                   "PC".ljust(width) + "\n")
        string += df2str(
            self.table[["SG", "KRG", "PC"]],
            monotonicity={
                "KRG": {
                    "sign": 1,
                    "lower": 0,
                    "upper": 1
                },
                "PC": {
                    "sign": 1,
                    "allowzero": True
                },
            } if not self.fast else None,
        )
        string += "/\n"
        return string
示例#7
0
    def SWFN(
        self, header=True, dataincommentrow=True, swcomment=None, crosspointcomment=None
    ):
        """Return a SWFN keyword with data to Eclipse

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

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

        Args:
            header: boolean for whether the SWFN string should be emitted.
                If you have multiple satnums, you should have True only
                for the first (or False for all, and emit the SWFN yourself).
                Defaults to True.
            dataincommentrow: boolean for wheter metadata should be printed,
                defaults to True.
            swcomment (str): String to be used for swcomment, overrides what
                this object can provide. Used by GasWater
            crosspointcomment (str): String to be used for crosspoint comment
                string, overrides what this object can provide. Used by GasWater.
                If None, it will be computed, use empty string to avoid.
        """
        if not self.selfcheck(mode="SWFN"):
            # selfcheck will print errors/warnings
            return ""
        string = ""
        if "pc" not in self.table.columns:
            self.table["pc"] = 0.0
            self.pccomment = "-- Zero capillary pressure\n"
        if header:
            string += "SWFN\n"
        string += comment_formatter(self.tag)
        string += "-- pyscal: " + str(pyscal.__version__) + "\n"
        if dataincommentrow:
            if swcomment is not None:
                string += swcomment
            else:
                string += self.swcomment
            string += self.krwcomment
            if crosspointcomment is None:
                if "krow" in self.table.columns and not self.fast:
                    string += "-- krw = krow @ sw=%1.5f\n" % self.crosspoint()
            else:
                string += crosspointcomment
            string += self.pccomment
        width = 10
        string += (
            "-- "
            + "SW".ljust(width - 3)
            + "KRW".ljust(width)
            + "PC".ljust(width)
            + "\n"
        )
        string += df2str(
            self.table[["sw", "krw", "pc"]],
            monotonocity={
                "krw": {"sign": 1, "lower": 0, "upper": 1},
                "pc": {"sign": -1, "allowzero": True},
            }
            if not self.fast
            else None,
        )
        string += "/\n"  # Empty line at the end
        return string