Beispiel #1
0
def add_conductance(G, kind, invivo, edges=None):
    """Adds conductance values to the edges of the graph (consult the relevant
    functions in the physiology module for more information.
    INPUT: G: Vascular graph in iGraph format.
           kind: The vessel kind. This can be either 'a' for artery or 'v' for
                 vein.
           invivo: Boolean, whether the physiological blood characteristics 
                   are calculated using the invivo (=True) or invitro (=False)
                   equations
           edges: (Optional.) The indices of the edges to be given a 
                  conductance value. If no indices are supplied, all edges are 
                  considered.
    """
    P = Physiology(G['defaultUnits'])
    if edges is None:
        edgelist = G.es
    else:
        edgelist = G.es(edges)
    #for e in edgelist:
    #print('')
    #print(e['diameter'])
    #print(e['length'])
    #print(P.dynamic_blood_viscosity(e['diameter'],invivo,kind))
    G.es(edgelist.indices)['conductance'] = \
                                   [P.conductance(e['diameter'],e['length'],
                                       P.dynamic_blood_viscosity(e['diameter'],
                                                                 invivo,kind))
                                    for e in edgelist]
Beispiel #2
0
def add_pBCs(G, kind, vertices):
    """Adds pressure boundary conditions to the vascular graph. Pressure values
    are taken from literature (see function 'blood_pressure').
    The pressure boundary vertices recieve a kind tag of either 'a' or 'v' 
    to classify them as arteries or veins respectively.
    INPUT: G: Vascular graph in iGraph format.
           kind: The vertex kind. This can be either 'a' for arterial or 'v' 
                 for venous.
           vertices: The indices of the vertices for which the pressure 
                     boundary conditions are to be set.
    OUTPUT: G is modified in place.
    """

    P = Physiology(G['defaultUnits'])

    for vertex in vertices:
        diameter = max(
            [G.es[x]['diameter'] for x in G.adjacent(vertex, 'all')])
        G.vs[vertex]['pBC'] = P.blood_pressure(diameter, kind)
        G.vs[vertex]['kind'] = kind
Beispiel #3
0
    def __init__(self, G, withRBC = 0, invivo = 0, dMin_empirical = 3.5, htdMax_empirical = 0.6, verbose = True,
            diameterOverTime=[],**kwargs):
        """
        Computes the flow and pressure field of a vascular graph without RBC tracking.
        It can be chosen between pure plasma flow, constant hematocrit or a given htt/htd
        distribution.
        The pressure boundary conditions (pBC) should be given in mmHG and pressure will be output in mmHg

        INPUT: G: Vascular graph in iGraph format.(the pBC should be given in mmHg)
               invivo: boolean if the invivo or invitro empirical functions are used (default = 0)
               withRBC: = 0: no RBCs, pure plasma Flow (default)
                        0 < withRBC < 1 & 'htt' not in edgeAttributes: the given value is assigned as htt to all edges.
                        0 < withRBC < 1 & 'htt' in edgeAttributes: the given value is assigned as htt to all edges where htt = None.
                        NOTE: Htd will be computed from htt and used to compute the resistance.
                            If htd is already in the edge attributes, it will be overwritten.
                dMin_empiricial: lower limit for the diameter that is used to compute nurel (effective viscosity). The aim of the limit
                        is to avoid using the empirical equations in a range where no data exists (default = 3.5).
                htdMax_empirical: upper limit for htd that is used to compute nurel (effective viscosity). The aim of the limit
                        is to avoid using the empirical equations in a range where no data exists (default = 0.6). Maximum has to be 1.
                verbose: Bool if WARNINGS and setup information (INFO) is printed
                diameterOverTime: list of the diameterChanges over time. The length of the list is the number of time steps with diameter change.
                    each diameter change should be provided as a tuple, e.g. two diameterChanges at the same time, a single diameter change afterwards.
                    [[[edgeIndex1, edgeIndex1],[newDiameter1, newDiameter2]],[[edgeIndex3], [newDiameter3]]]
        OUTPUT: None, the edge properties htt is assgined and the function update is executed (see description for more details)
        """
        self._G = G
        nVertices = G.vcount()
        self._b = np.zeros(nVertices)            
        self._A = lil_matrix((nVertices,nVertices),dtype=float)
        self._eps = np.finfo(float).eps
        self._P = Physiology(G['defaultUnits'])
        self._muPlasma = self._P.dynamic_plasma_viscosity()
        self._withRBC = withRBC
        self._invivo = invivo
        self._verbose = verbose
        self._dMin_empirical = dMin_empirical
        self._htdMax_empirical = htdMax_empirical
        self._diameterOverTime = diameterOverTime
        self._timeSteps = len(diameterOverTime)
        self._scalingFactor = vgm.units.scaling_factor_du('mmHg',G['defaultUnits'])

        if self._verbose:
            print('INFO: The limits for the compuation of the effective viscosity are set to')
            print('Minimum diameter %.2f' %self._dMin_empirical)
            print('Maximum discharge %.2f' %self._htdMax_empirical)

        if self._withRBC != 0:
            if self._withRBC < 1.:
                if 'htt' not in G.es.attribute_names():
                    G.es['htt']=[self._withRBC]*G.ecount()
                else:
                    httNone = G.es(htt_eq=None).indices
                    if len(httNone) > 0:
                        G.es[httNone]['htt']=[self._withRBC]*len(httNone)
                    else:
                        if self._verbose:
                            print('WARNING: htt is already an edge attribute. \n Existing values are not overwritten!'+\
                                    '\n If new values should be assigned htt has to be deleted beforehand!')
            else:
                print('ERROR: 0 < withRBC < 1')

        if 'rBC' not in G.vs.attribute_names():
            G.vs['rBC'] = [None]*G.vcount()

        if 'pBC' not in G.vs.attribute_names():
            G.vs['pBC'] = [None]*G.vcount()

        #Convert 'pBC' ['mmHG'] to default Units
        for v in G.vs(pBC_ne=None):
            v['pBC']=v['pBC']*self._scalingFactor

        if len(G.vs(pBC_ne=None)) > 0:
            if self._verbose:
                print('INFO: Pressure boundary conditions changed from mmHg --> default Units')

        self.update()
Beispiel #4
0
    def __init__(self,
                 G,
                 invivo=True,
                 assert_pBCs=True,
                 resetHtd=True,
                 **kwargs):
        """Initializes a LinearSystemPries instance.
        INPUT: G: Vascular graph in iGraph format.
               invivo: Boolean, whether the physiological blood characteristics 
                       are calculated using the invivo (=True) or invitro (=False)
                       equations
               assert_pBCs: (Optional, default=True.) Boolean whether or not to
                            check components for correct pressure boundary
                            conditions.
               resetHtd: (Optional, default=True.) Boolean whether or not to
                         reset the discharge hematocrit of the VascularGraph at
                         initialization. It may be useful to preserve the
                         original htd-distribution, if only a minor change from
                         the current state is to be expected (faster to obtain
                         the solution).
	       **kwargs:
		    httBC: tube hematocrit boundary condition at inflow (edge)
		    htdBC: discharge hematocrit boundary condition at inflow (vertex)
                    plasmaType: if it is not given, the default value is used. option two: --> francesco: plasma value of francescos simulations
                    species: what type of animal we are dealing with --> relevant for the rbc volume that is used, default is rat
		    
        OUTPUT: None
        """
        self._G = G
        self._invivo = invivo
        self._P = Physiology(G['defaultUnits'])
        self._eps = 1e-7  #finfo(float).eps * 1e4
        htt2htd = self._P.tube_to_discharge_hematocrit

        if kwargs.has_key('httBC'):
            for vi in G['av']:
                for ei in G.adjacent(vi):
                    G.es[ei]['httBC'] = kwargs['httBC']
                    htdBC = htt2htd(kwargs['httBC'], G.es[ei]['diameter'],
                                    invivo)
                G.vs[vi]['htdBC'] = htdBC
        if kwargs.has_key('htdBC'):
            for vi in G['av']:
                G.vs[vi]['htdBC'] = kwargs['htdBC']

        if kwargs.has_key('plasmaType'):
            self._plasmaType = kwargs['plasmaType']
        else:
            self._plasmaType = 'default'

        if kwargs.has_key('species'):
            self._species = kwargs['species']
        else:
            self._species = 'rat'

        # Discharge hematocrit boundary conditions:
        if not 'htdBC' in G.vs.attribute_names():
            for vi in G['av']:
                htdlist = []
                for ei in G.adjacent(vi):
                    if 'httBC' in G.es.attribute_names():
                        if G.es[ei]['httBC'] != None:
                            htdBC = htt2htd(G.es[ei]['httBC'],
                                            G.es[ei]['diameter'], invivo)
                            G.vs[vi]['htdBC'] = htdBC
                        else:
                            for ei in G.adjacent(vi):
                                htdlist.append(
                                    self._P.discharge_hematocrit(
                                        G.es[ei]['diameter'], 'a'))
                                G.vs[vi]['htdBC'] = np.mean(htdlist)
                    else:
                        for ei in G.adjacent(vi):
                            htdlist.append(
                                self._P.discharge_hematocrit(
                                    G.es[ei]['diameter'], 'a'))
                            G.vs[vi]['htdBC'] = np.mean(htdlist)

        #Convert 'pBC' ['mmHg'] to default Units
        for v in G.vs:
            if v['pBC'] != None:
                v['pBC'] = v['pBC'] * vgm.units.scaling_factor_du(
                    'mmHg', G['defaultUnits'])

        # Initial RBC flow, hematocrit, conductance, pressure and flow:
        G.vs['pressure'] = [0.0 for v in G.vs]
        G.es['rbcFlow'] = [0.0 for e in G.es]
        if resetHtd:
            G.es['htd'] = [0.0 for e in G.es]
        if not G.vs[0].attributes().has_key('pBC'):
            G.vs[0]['pBC'] = None
        if not G.vs[0].attributes().has_key('rBC'):
            G.vs[0]['rBC'] = None
        nVertices = G.vcount()
        self._b = zeros(nVertices)
        self._A = lil_matrix((nVertices, nVertices), dtype=float)
        self._update_conductance_and_LS(G, assert_pBCs)
        self._linear_analysis('iterative2')
        self._rheological_analysis(None, True, 1.0)
        self._linear_analysis('iterative2')
Beispiel #5
0
    def __init__(self,
                 G,
                 withRBC=0,
                 invivo=0,
                 dMin_empirical=3.5,
                 htdMax_empirical=0.6,
                 verbose=True,
                 **kwargs):
        """
        Computes the flow and pressure field of a vascular graph without RBC tracking.
        It can be chosen between pure plasma flow, constant hematocrit or a given htt/htd
        distribution.
        The pressure boundary conditions (pBC) should be given in mmHG and pressure will be output in mmHg

        INPUT: G: Vascular graph in iGraph format.(the pBC should be given in mmHg)
               invivo: boolean if the invivo or invitro empirical functions are used (default = 0)
               withRBC: = 0: no RBCs, pure plasma Flow (default)
                        0 < withRBC < 1 & 'htt' not in edgeAttributes: the given value is assigned as htt to all edges.
                        0 < withRBC < 1 & 'htt' in edgeAttributes: the given value is assigned as htt to all edges where htt = None.
                        NOTE: If htd is not in the edge attributes, Htd will be computed from htt and used to compute the resistance.
                        If htd is already in the edge attributes, it won't be recomputed but the current htd values will be used.
                dMin_empiricial: lower limit for the diameter that is used to compute nurel (effective viscosity). The aim of the limit
                        is to avoid using the empirical equations in a range where no data exists (default = 3.5).
                htdMax_empirical: upper limit for htd that is used to compute nurel (effective viscosity). The aim of the limit
                        is to avoid using the empirical equations in a range where no data exists (default = 0.6). Maximum has to be 1.
                verbose: Bool if WARNINGS and setup information is printed
        OUTPUT: None, the edge properties htt is assgined and the function update is executed (see description for more details)
        """
        self._G = G
        self._eps = np.finfo(float).eps
        self._P = Physiology(G['defaultUnits'])
        self._muPlasma = self._P.dynamic_plasma_viscosity()
        self._withRBC = withRBC
        self._invivo = invivo
        self._verbose = verbose
        self._dMin_empirical = dMin_empirical
        self._htdMax_empirical = htdMax_empirical

        if self._verbose:
            print(
                'INFO: The limits for the compuation of the effective viscosity are set to'
            )
            print('Minimum diameter %.2f' % self._dMin_empirical)
            print('Maximum discharge %.2f' % self._htdMax_empirical)

        if self._withRBC != 0:
            if self._withRBC < 1.:
                if 'htt' not in G.es.attribute_names():
                    G.es['htt'] = [self._withRBC] * G.ecount()
                else:
                    httNone = G.es(htt_eq=None).indices
                    if len(httNone) > 0:
                        G.es[httNone]['htt'] = [self._withRBC] * len(httNone)
                    else:
                        if self._verbose:
                            print('WARNING: htt is already an edge attribute. \n Existing values are not overwritten!'+\
                                    '\n If new values should be assigned htt has to be deleted beforehand!')
            else:
                print('ERROR: 0 < withRBC < 1')

        if 'rBC' not in G.vs.attribute_names():
            G.vs['rBC'] = [None] * G.vcount()

        if 'pBC' not in G.vs.attribute_names():
            G.vs['pBC'] = [None] * G.vcount()

        self.update()