コード例 #1
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)
コード例 #2
0
    def test_default_mechanics_dictionary(self):
        """ Test the default mechanics dictionary.

        Check that the correct parameters are present, and sample some of the values
        and check that they are correct.
        """
        dictionary = dicts.mechanics_dictionary(self.g)
        # Check that all parameters have been added.
        p_list = [
            "source",
            "time_step",
            "fourth_order_tensor",
            "bc",
            "bc_values",
            "slip_distance",
        ]
        [self.assertIn(parameter, dictionary) for parameter in p_list]
        # Check some of the values:
        zeros = np.zeros(self.g.num_faces * self.g.dim)
        self.assertTrue(np.all(np.isclose(dictionary["slip_distance"], zeros)))
        self.assertEqual(dictionary["bc"].bc_type, "vectorial")