示例#1
0
    def test_default_transport_dictionary(self):
        """ Test the default transport dictionary.

        Check that the correct parameters are present, and sample some of the values
        and check that they are correct.
        """
        # The default darcy_flux needs face normals:
        self.g.compute_geometry()
        dictionary = dicts.transport_dictionary(self.g)
        # Check that all parameters have been added.
        p_list = [
            "source",
            "time_step",
            "second_order_tensor",
            "bc",
            "bc_values",
            "darcy_flux",
            "mass_weight",
        ]
        [self.assertIn(parameter, dictionary) for parameter in p_list]
        # Check some of the values:
        unitary_parameters = ["mass_weight"]
        ones = np.ones(self.g.num_cells)
        for parameter in unitary_parameters:
            self.assertTrue(np.all(np.isclose(dictionary[parameter], ones)))
        zeros = np.zeros(self.g.num_faces)
        self.assertTrue(np.all(np.isclose(dictionary["darcy_flux"], zeros)))
示例#2
0
def initialize_default_data(g,
                            data,
                            parameter_type,
                            specified_parameters=None,
                            keyword=None):
    """Initialize a data dictionary for a single keyword.

    The initialization consists of adding a parameter dictionary and initializing a
    matrix dictionary in the proper fields of data. Default data are added for a certain
    set of "basic" parameters, depending on the type chosen.

    Args:
        g: Grid object with computed geometry.
        data: Outer data dictionary, to which the parameters will be added.
        parameter_type: Which type of parameters to use for the default assignment.
            Must be one of the following:
                "flow", "transport" and "mechanics".
        specified_parameters: A dictionary with specified parameters, overriding the
            @pp.time_logger(sections=module_sections)
            default values. Defualts to an empty dictionary (only default values).
        keyword: String to identify the parameters. Defaults to the parameter type.

     Returns:
        data: The filled dictionary.

    Raises:
        KeyError if an unknown parameter type is passed.
    """
    if not specified_parameters:
        specified_parameters = {}
    if not keyword:
        keyword = parameter_type
    if parameter_type == "flow":
        d = dicts.flow_dictionary(g, specified_parameters)
    elif parameter_type == "transport":
        d = dicts.transport_dictionary(g, specified_parameters)
    elif parameter_type == "mechanics":
        d = dicts.mechanics_dictionary(g, specified_parameters)
    else:
        raise KeyError(
            'Default dictionaries only exist for the parameter types "flow", '
            + '"transport" and "mechanics", not for ' + parameter_type + ".")
    return initialize_data(g, data, keyword, d)