Beispiel #1
0
 def __init__(self, name, inputs=None, outputs=None, internals=None,
              auto_dep=None):
     ModelObj.__init__(self, name)
     self.inputs = inputs
     self.outputs = outputs
     self.internals = internals
     self.auto_dep = auto_dep if auto_dep != None else True
Beispiel #2
0
 def __init__(self,
              name,
              inputs=None,
              outputs=None,
              internals=None,
              auto_dep=None):
     ModelObj.__init__(self, name)
     self.inputs = inputs
     self.outputs = outputs
     self.internals = internals
     self.auto_dep = auto_dep if auto_dep != None else True
Beispiel #3
0
    def vivify(self, model):
        ModelObj.vivify(self, model)

        vols = model.mesh.regionvolumes
        if self.subfields == False:
            self.volumes = {self.name: sum(vols[1:])}

        else:
            if self.subfields == True:
                self.subfields = model.regions.all_entity_names

            # Calculate the volume per subfield as the sum of the volumes
            # where the subfield is defined
            self.volumes = volumes = {}
            for subfield in self.subfields:
                volumes["%s_%s" % (self.name, subfield)] = reduce(
                    lambda v, region_idx: v + vols[region_idx], model.regions.regions_by_entity[subfield], 0.0
                )
Beispiel #4
0
    def vivify(self, model):
        ModelObj.vivify(self, model)

        vols = model.mesh.regionvolumes
        if self.subfields == False:
            self.volumes = {self.name: sum(vols[1:])}

        else:
            if self.subfields == True:
                self.subfields = model.regions.all_entity_names

            # Calculate the volume per subfield as the sum of the volumes
            # where the subfield is defined
            self.volumes = volumes = {}
            for subfield in self.subfields:
                volumes["%s_%s" % (self.name, subfield)] = \
                  reduce(lambda v, region_idx: v + vols[region_idx],
                         model.regions.regions_by_entity[subfield], 0.0)
Beispiel #5
0
    def __init__(self, name, x, dxdt,
                 eq_for_jacobian=None, time_unit=None,
                 derivatives=None,
                 pc_rtol=1e-2, pc_atol=1e-7, pc_dtol=None, pc_maxits=1000000,
                 rtol=1e-5, atol=1e-5, initial_time=0.0,
                 max_order=2, krylov_max=300,
                 jacobi_prealloc_diagonal=75,
                 jacobi_prealloc_off_diagonal=45):
        ModelObj.__init__(self, name)

        if (eq_for_jacobian != None
            and not isinstance(eq_for_jacobian, Equation)):
            raise ValueError("The optional argument eq_for_jacobian should be"
                             "set to an instance of the Equation class.")

        if isinstance(x, str):
            x = [x]

        if isinstance(dxdt, str):
            dxdt = [dxdt]

        if len(x) != len(dxdt):
            raise ValueError("x and dxdt should be lists with the same number "
                             "of entries.")

        self.derivatives = derivatives
        self.time_unit = time_unit
        self.x = x
        self.dxdt = dxdt
        self.eq_for_jacobian = eq_for_jacobian
        self.rtol = rtol
        self.atol = atol
        self.pc_rtol = pc_rtol
        self.pc_atol = pc_atol
        self.pc_dtol = pc_dtol
        self.pc_maxits = pc_maxits
        self.initial_time = initial_time
        self.max_order = max_order
        self.krylov_max = krylov_max
        self.jacobi_prealloc_diagonal = jacobi_prealloc_diagonal
        self.jacobi_prealloc_off_diagonal = jacobi_prealloc_off_diagonal
        self.initialised = False
        self.need_reinitialise = True
Beispiel #6
0
    def __init__(self, name, shape=[], value=None, unit=None, subfields=False):
        """Define a new quantity:
        name:  name of the quantity (should be different for each quantity)
        shape: shape. Examples: [] for scalars, [3] 3-component vectors, etc
        value: initial value of the quantity. An initial value should be
               provided only if the quantity is primary.
        unit:  the unit used for the quantity. Values will be stored in terms
               of unit. For example, if unit=100 and you set the Quantity
               to 200, then - internally - 2 will be used.
        subfields:
               For each region specifies which subfield of the Quantity are
               present in it. Example: [["s1", "s2"], ["s1"], []] means
               that the field has two subfields "s1" and "s2" in the region
               with index 0, only "s1" in region with index 2, and is not
               defined in region 3. If subfield is set to False, then the
               field doesn't have any subfields. If it is set to True than
               it gets all the default subfields of the model.
        """
        ModelObj.__init__(self, name)
        self.shape = shape  # Shape of the field
        self.value = None  # Value (instance of Value class)
        self.unit = unit  # Unit
        self.subfields = subfields
        if subfields not in [True, False]:
            raise NotImplementedError(
                "User defined subfield allocations are "
                "not permitted, yet. Use only "
                "subfields=False or subfields=True "
                "when instantiating a new Quantity."
            )
        self.def_on_mat = subfields

        self.regions = None  # self.regions[sf_name] is the list of regions
        # indices where the subfield sf_name is defined
        self.volumes = None  # self.volumes[sf_name] is the sum of volumes
        # of all the regions self.regions[sf_name].

        self.is_primary = True  # unused at the moment

        self.set_value(value)
Beispiel #7
0
    def __init__(self, name, shape=[], value=None, unit=None, subfields=False):
        """Define a new quantity:
        name:  name of the quantity (should be different for each quantity)
        shape: shape. Examples: [] for scalars, [3] 3-component vectors, etc
        value: initial value of the quantity. An initial value should be
               provided only if the quantity is primary.
        unit:  the unit used for the quantity. Values will be stored in terms
               of unit. For example, if unit=100 and you set the Quantity
               to 200, then - internally - 2 will be used.
        subfields:
               For each region specifies which subfield of the Quantity are
               present in it. Example: [["s1", "s2"], ["s1"], []] means
               that the field has two subfields "s1" and "s2" in the region
               with index 0, only "s1" in region with index 2, and is not
               defined in region 3. If subfield is set to False, then the
               field doesn't have any subfields. If it is set to True than
               it gets all the default subfields of the model.
        """
        ModelObj.__init__(self, name)
        self.shape = shape  # Shape of the field
        self.value = None  # Value (instance of Value class)
        self.unit = unit  # Unit
        self.subfields = subfields
        if subfields not in [True, False]:
            raise NotImplementedError("User defined subfield allocations are "
                                      "not permitted, yet. Use only "
                                      "subfields=False or subfields=True "
                                      "when instantiating a new Quantity.")
        self.def_on_mat = subfields

        self.regions = None  # self.regions[sf_name] is the list of regions
        # indices where the subfield sf_name is defined
        self.volumes = None  # self.volumes[sf_name] is the sum of volumes
        # of all the regions self.regions[sf_name].

        self.is_primary = True  # unused at the moment

        self.set_value(value)