示例#1
0
    def test_oil_in_place_calculation(self):
        seed = 300
        n = 1
        model = Model("Simple Model", 666)

        area = RandomProperty(name="Area", n=n, random_number_function=mock_random)
        porosity = RandomProperty(name="Porosity", n=n, random_number_function=mock_random)
        sw = RandomProperty(name="Sw", n=n, random_number_function=mock_random)

        config = {"Region A": {"Area": {"value": 2.0},
                               "Porosity": {"value": 0.5},
                               "Sw": {"value": 0.1}},
                  "Region B": {"Area": {"value": 1.0},
                               "Porosity": {"value": 0.5},
                               "Sw": {"value": 0.1}}}

        #oil in place region a should be 2.0*0.5*(1-0.1) = 1.0*0.9 = 0.9
        #oil in place region b should be 1.0*0.5*(1-0.1) = 0.5*0.9 = 0.45

        model.add_property(area)
        model.add_property(porosity)
        model.add_property(sw)

        region_a = Region(name="Region A")
        region_b = Region(name="Region B")

        model.add_region(region_a)
        model.add_region(region_b)

        model.add_defined_properties_to_regions()

        model.run(config)

        model.add_regional_property("ooip", OriginalOilInPlace)
        for region_name, region in model.regions.items():
            if region_name is "Region A":
                self.assertAlmostEqual(np.sum(region.properties["ooip"].values), n*0.9, 4)


            else:
                self.assertAlmostEqual(np.sum(region.properties["ooip"].values), n*0.45, 4)
            region.properties["ooip"].calculate_property_statistics()
            self.assertNotEqual(region.properties["ooip"].p10, None)
            self.assertNotEqual(region.properties["ooip"].p50, None)
            self.assertNotEqual(region.properties["ooip"].p90, None)


        ooip = ModelOriginalOilInPlace(model)
        ooip.generate_values()

        self.assertAlmostEqual(np.sum(ooip.values), n*(0.9+0.45), 4)
        ooip.calculate_property_statistics()

        self.assertNotEqual(ooip.p10, None)
        self.assertNotEqual(ooip.p50, None)
        self.assertNotEqual(ooip.p90, None)
示例#2
0
    def test_oil_in_place_calculation(self):
        seed = 300
        n = 1
        model = Model("Simple Model", 666)

        area = RandomProperty(name="Area", n=n, random_number_function=mock_random)
        porosity = RandomProperty(name="Porosity", n=n, random_number_function=mock_random)
        sw = RandomProperty(name="Sw", n=n, random_number_function=mock_random)

        config = {"Region A": {"Area": {"value": 2.0},
                               "Porosity": {"value": 0.5},
                               "Sw": {"value": 0.1}},
                  "Region B": {"Area": {"value": 1.0},
                               "Porosity": {"value": 0.5},
                               "Sw": {"value": 0.1}}}

        #oil in place region a should be 2.0*0.5*(1-0.1) = 1.0*0.9 = 0.9
        #oil in place region b should be 1.0*0.5*(1-0.1) = 0.5*0.9 = 0.45

        model.add_property(area)
        model.add_property(porosity)
        model.add_property(sw)

        region_a = Region(name="Region A")
        region_b = Region(name="Region B")

        model.add_region(region_a)
        model.add_region(region_b)

        model.add_defined_properties_to_regions()

        model.run(config)

        model.add_regional_property("ooip", OriginalOilInPlace)
        for region_name, region in model.regions.iteritems():
            if region_name is "Region A":
                self.assertAlmostEqual(np.sum(region.properties["ooip"].values), n*0.9, 4)


            else:
                self.assertAlmostEqual(np.sum(region.properties["ooip"].values), n*0.45, 4)
            region.properties["ooip"].calculate_property_statistics()
            self.assertNotEqual(region.properties["ooip"].p10, None)
            self.assertNotEqual(region.properties["ooip"].p50, None)
            self.assertNotEqual(region.properties["ooip"].p90, None)


        ooip = ModelOriginalOilInPlace(model)
        ooip.generate_values()

        self.assertAlmostEqual(np.sum(ooip.values), n*(0.9+0.45), 4)
        ooip.calculate_property_statistics()

        self.assertNotEqual(ooip.p10, None)
        self.assertNotEqual(ooip.p50, None)
        self.assertNotEqual(ooip.p90, None)
示例#3
0
    def test_model(self):
        model = Model(self.name, self.seed)
        self.assertEqual(model.seed, self.seed)

        model.seed_generator = MockSeedGenerator(self.seed)
        self.assertEqual(model.name, self.name)
        self.assertEqual(model.seed, self.seed)

        mock_property = MockProperty()

        model.add_property(mock_property)
        self.assertEquals(len(model.properties), 1)
        self.assertRaises(KeyError, model.add_property, mock_property)

        mock_random_property = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed - 1),
                                                  name="MockRandomProperty")
        mock_random_property.name = "MockRandomProperty"

        # assigning the property should reset the seed using the models seed generator
        model.add_property(mock_random_property)

        self.assertEqual(model.properties[mock_random_property.name].seed, self.seed)
        self.assertEqual(len(model.properties), 2)

        mock_region = MockRegion(name="MockRegion")
        mock_region.add_property(MockRandomProperty(seed_generator=MockSeedGenerator(self.seed - 1),
                                                    name="RegionRandomMockProperty"))
        model.add_region(mock_region)
        self.assertEquals(len(model.regions), 1)
        self.assertEqual(model.regions[mock_region.name].properties["RegionRandomMockProperty"].seed, self.seed)
        self.assertRaises(KeyError, model.add_region, mock_region)

        #Test Regional Property Addition
        model.add_regional_property("MockRegionalProperty", RegionalProperty)
        for region_name, region in model.regions.items():
            self.assertEqual(len(region.properties), 2)

        # Test filling a model
        # Reinitialize model to get a clean slate
        model = Model(self.name, self.seed)
        mock_random_property_a = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed),
                                                    name="MockRandomProperty")
        mock_region_a = MockRegion(name="MockRegion")

        model.add_region(mock_region_a)
        model.add_property(mock_random_property_a)

        model.add_defined_properties_to_regions()
        for key, region in model.regions.items():
            self.assertEqual(len(region.properties), 1)

        mock_random_property_b = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed - 1),
                                                    name="MockRandomPropertyB")
        model.add_property(mock_random_property_b)

        for region_name, region in model.regions.items():
            self.assertEqual(len(region.properties), 1)

        mock_region_b = MockRegion(name="MockRegionB")

        model.add_region(mock_region_b)
        model.add_defined_properties_to_regions()
        for region_name_a, region_a in model.regions.items():
            for region_name_b, region_b in model.regions.items():
                for property_name, property in model.properties.items():
                    self.assertNotEqual(model.properties[property_name], region_a.properties[property_name])
                    if region_a is not region_b:
                        self.assertNotEqual(region_a.properties[property_name], region_b.properties[property_name])
            self.assertEqual(len(region_a.properties), 2)



        #Test runnning a model from a configuration dictionary
        config = {"MockRegionA": {"MockRandomPropertyA": {"low": 100.0, "high": 1000.0},
                           "MockRandomPropertyB": {"low": 100.0, "high": 1000.0}}
                 }

        n = 10
        model = Model(self.name, self.seed)
        mock_random_property_a = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed),
                                                    name="MockRandomPropertyA", n=n,
                                                    random_number_function=np.random.uniform)
        mock_random_property_b = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed),
                                                    name="MockRandomPropertyB", n=n,
                                                    random_number_function=np.random.uniform)
        mock_region_a = MockRegion(name="MockRegionA")
        model.add_property(mock_random_property_a)
        model.add_property(mock_random_property_b)
        model.add_region(mock_region_a)
        model.run(config)

        for region_name, region in model.regions.items():
            for property_name, property in region.properties.items():
                self.assertEqual(len(property.values), 10)
示例#4
0
    def test_model(self):
        model = Model(self.name, self.seed)
        self.assertEqual(model.seed, self.seed)

        model.seed_generator = MockSeedGenerator(self.seed)
        self.assertEqual(model.name, self.name)
        self.assertEqual(model.seed, self.seed)

        mock_property = MockProperty()

        model.add_property(mock_property)
        self.assertEquals(len(model.properties), 1)
        self.assertRaises(KeyError, model.add_property, mock_property)

        mock_random_property = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed - 1),
                                                  name="MockRandomProperty")
        mock_random_property.name = "MockRandomProperty"

        # assigning the property should reset the seed using the models seed generator
        model.add_property(mock_random_property)

        self.assertEqual(model.properties[mock_random_property.name].seed, self.seed)
        self.assertEqual(len(model.properties), 2)

        mock_region = MockRegion(name="MockRegion")
        mock_region.add_property(MockRandomProperty(seed_generator=MockSeedGenerator(self.seed - 1),
                                                    name="RegionRandomMockProperty"))
        model.add_region(mock_region)
        self.assertEquals(len(model.regions), 1)
        self.assertEqual(model.regions[mock_region.name].properties["RegionRandomMockProperty"].seed, self.seed)
        self.assertRaises(KeyError, model.add_region, mock_region)

        #Test Regional Property Addition
        model.add_regional_property("MockRegionalProperty", RegionalProperty)
        for region_name, region in model.regions.iteritems():
            self.assertEqual(len(region.properties), 2)

        # Test filling a model
        # Reinitialize model to get a clean slate
        model = Model(self.name, self.seed)
        mock_random_property_a = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed),
                                                    name="MockRandomProperty")
        mock_region_a = MockRegion(name="MockRegion")

        model.add_region(mock_region_a)
        model.add_property(mock_random_property_a)

        model.add_defined_properties_to_regions()
        for key, region in model.regions.iteritems():
            self.assertEqual(len(region.properties), 1)

        mock_random_property_b = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed - 1),
                                                    name="MockRandomPropertyB")
        model.add_property(mock_random_property_b)

        for region_name, region in model.regions.iteritems():
            self.assertEqual(len(region.properties), 1)

        mock_region_b = MockRegion(name="MockRegionB")

        model.add_region(mock_region_b)
        model.add_defined_properties_to_regions()
        for region_name_a, region_a in model.regions.iteritems():
            for region_name_b, region_b in model.regions.iteritems():
                for property_name, property in model.properties.iteritems():
                    self.assertNotEqual(model.properties[property_name], region_a.properties[property_name])
                    if region_a is not region_b:
                        self.assertNotEqual(region_a.properties[property_name], region_b.properties[property_name])
            self.assertEqual(len(region_a.properties), 2)



        #Test runnning a model from a configuration dictionary
        config = {"MockRegionA": {"MockRandomPropertyA": {"low": 100.0, "high": 1000.0},
                           "MockRandomPropertyB": {"low": 100.0, "high": 1000.0}}
                 }

        n = 10
        model = Model(self.name, self.seed)
        mock_random_property_a = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed),
                                                    name="MockRandomPropertyA", n=n,
                                                    random_number_function=np.random.uniform)
        mock_random_property_b = MockRandomProperty(seed_generator=MockSeedGenerator(self.seed),
                                                    name="MockRandomPropertyB", n=n,
                                                    random_number_function=np.random.uniform)
        mock_region_a = MockRegion(name="MockRegionA")
        model.add_property(mock_random_property_a)
        model.add_property(mock_random_property_b)
        model.add_region(mock_region_a)
        model.run(config)

        for region_name, region in model.regions.iteritems():
            for property_name, property in region.properties.iteritems():
                self.assertEqual(len(property.values), 10)