Exemplo n.º 1
0
def integBulkBc(rad, field, ri, ro, lambdai, lambdao, normed=False):
    """
    This function evaluates the radial integral of the input array field
    in the boundary layer and in the bulk separately.

    :param rad: radius
    :type rad: numpy.ndarray
    :param field: the input radial profile
    :type field: numpy.ndarray
    :param ri: the inner core radius
    :type ri: float
    :param ro: the outer core radius
    :type ro: float
    :param lambdai: thickness of the inner boundary layer
    :type lambdai: float
    :param lambdao: thickness of the outer boundary layer
    :type lambdao: float
    :param normed: when set to True, the outputs are normalised by the volumes
                   of the boundary layers and the fluid bulk, respectively. In
                   that case, the outputs are volume-averaged quantities.
    :type normed: bool
    :returns: two floats that contains the boundary layer and the bulk
              integrations (integBc, integBulk)
    :rtype: list
    """
    # Dissipation in the boundary layers
    field2 = field.copy()
    mask = (rad<=ro-lambdao) * (rad>=ri+lambdai)
    field2[mask] = 0.
    integBc = intcheb(field2, len(field2)-1, ri, ro)

    if normed:
        volBc1 = 4./3.*N.pi*(ro**3-(ro-lambdao)**3)
        volBc2 = 4./3.*N.pi*((ri+lambdai)**3-(ri)**3)
        volBc = volBc1+volBc2
        integBc = integBc/volBc

    # Dissipation in the bulk
    field2 = field.copy()
    mask = (rad>ro-lambdao)
    field2[mask] = 0.
    mask = (rad<ri+lambdai)
    field2[mask] = 0.
    integBulk = intcheb(field2, len(field2)-1, ri, ro)

    if normed:
        volBulk = 4./3.*N.pi*((ro-lambdao)**3-(ri+lambdai)**3)
        integBulk = integBulk/volBulk

    return integBc, integBulk
Exemplo n.º 2
0
def integBotTop(rad, field, ri, ro, lambdai, lambdao, normed=False):
    """
    This function evaluates the radial integral of the input array field
    in the bottom and top boundary layers separately.

    :param rad: radius
    :type rad: numpy.ndarray
    :param field: the input radial profile
    :type field: numpy.ndarray
    :param ri: the inner core radius
    :type ri: float
    :param ro: the outer core radius
    :type ro: float
    :param lambdai: thickness of the inner boundary layer
    :type lambdai: float
    :param lambdao: thickness of the outer boundary layer
    :type lambdao: float
    :param normed: when set to True, the outputs are normalised by the volumes
                   of the boundary layers. In that case, the outputs are 
                   volume-averaged quantities.
    :type normed: bool
    :returns: two floats that contains the bottom and top boundary layers
              integrations (integBot, integTop)
    :rtype: list
    """
    field2 = field.copy()
    mask = (rad<=ro-lambdao)
    field2[mask] = 0.
    integTop = intcheb(field2, len(field2)-1, ri, ro)
    field2 = field.copy()
    mask = (rad>=ri+lambdai)
    field2[mask] = 0.
    integBot = intcheb(field2, len(field2)-1, ri, ro)

    if normed:
        volBc1 = 4./3.*N.pi*(ro**3-(ro-lambdao)**3)
        volBc2 = 4./3.*N.pi*((ri+lambdai)**3-(ri)**3)
        integTop /= volBc1
        integBot /= volBc2

    return integBot, integTop
Exemplo n.º 3
0
    def __init__(self, iplot=False, quiet=False):
        """
        :param iplot: display the result when set to True (default False)
        :type iplot: bool
        :param quiet: less verbose when set to True (default is False)
        :type quiet: bool
        """
        if os.path.exists('tInitAvg'):
            file = open('tInitAvg', 'r')
            tstart = float(file.readline())
            file.close()
            logFiles = scanDir('log.*')
            tags = []
            for lg in logFiles:
                nml = MagicSetup(quiet=True, nml=lg)
                if nml.start_time >  tstart:
                    if os.path.exists('bLayersR.%s' % nml.tag):
                        tags.append(nml.tag)
            if len(tags) > 0:
                print(tags)
            else:
                tags = None
            MagicSetup.__init__(self, quiet=True, nml=logFiles[-1])

            a = AvgField()
            self.nuss = a.nuss
            self.reynolds = a.reynolds
        else:
            logFiles = scanDir('log.*')
            MagicSetup.__init__(self, quiet=True, nml=logFiles[-1])
            tags = None
            self.nuss = 1.
            self.reynolds = 1.
        par = MagicRadial(field='bLayersR', iplot=False, tags=tags)
        self.varS = N.sqrt(N.abs(par.varS))
        self.ss = par.entropy

        if os.path.exists('tInitAvg'):
            logFiles = scanDir('log.*', tfix=1409827718.0)
            # Workaround for code mistake before this time
            tfix = 1409827718.0
            tagsFix = []
            for lg in logFiles:
                nml = MagicSetup(quiet=True, nml=lg)
                if nml.start_time >  tstart:
                    if os.path.exists('bLayersR.%s' % nml.tag):
                        tagsFix.append(nml.tag)
            if len(tagsFix) > 0:
                print('Fix temp. tags', tagsFix)
                parFix = MagicRadial(field='bLayersR', iplot=False, tags=tagsFix)
                self.varS = N.sqrt(N.abs(parFix.varS))
                self.ss = parFix.entropy

            self.tags = tagsFix
        self.uh = par.uh
        self.duh = par.duhdr
        self.rad = par.radius
        self.ro = self.rad[0]
        self.ri = self.rad[-1]

        self.reh = 4.*N.pi*intcheb(self.rad**2*self.uh, len(self.rad)-1, 
                        self.ri, self.ro)/(4./3.*N.pi*(self.ro**3-self.ri**3))

        # Thermal dissipation boundary layer
        if hasattr(par, 'dissS'):
            self.dissS = par.dissS
            self.epsT = -4.*N.pi*intcheb(self.rad**2*self.dissS, len(self.rad)-1, 
                                         self.ro, self.ri)
            self.epsTR = 4.*N.pi*self.rad**2*self.dissS
            ind = getMaxima(-abs(self.epsTR-self.epsT))

            try:
                self.dissTopS = self.ro-self.rad[ind[0]]
                self.dissBotS = self.rad[ind[-1]]-self.ri
                self.dissEpsTbl, self.dissEpsTbulk = integBulkBc(self.rad, self.epsTR, 
                             self.ri, self.ro, self.dissBotS, self.dissTopS)
            except IndexError:
                self.dissTopS = self.ro
                self.dissBotS = self.ri
                self.dissEpsTbl, self.dissEpsTbulk = 0., 0.


            print('thDiss bl, bulk',  self.dissEpsTbl/self.epsT, self.dissEpsTbulk/self.epsT)
        # First way of defining the thermal boundary layers: with var(S)
        #rThLayer = getMaxima(self.rad, self.varS)
        ind = argrelextrema(self.varS, N.greater)[0]
        if len(ind) != 0:
            self.bcTopVarS = self.ro-self.rad[ind[0]]
            self.bcBotVarS = self.rad[ind[-1]]-self.ri
        else:
            self.bcTopVarS = 1.
            self.bcBotVarS = 1.
        if hasattr(self, 'epsT'):
            self.varSEpsTbl, self.varSEpsTbulk = integBulkBc(self.rad, self.epsTR, 
                         self.ri, self.ro, self.bcBotVarS, self.bcTopVarS)
            print('var(S) bl, bulk', self.varSEpsTbl/self.epsT, self.varSEpsTbulk/self.epsT)

        # Second way of defining the thermal boundary layers: intersection of the slopes
        d1 = matder(len(self.rad)-1, self.ro, self.ri)
        self.ttm = 3.*intcheb(self.ss*self.rad**2, len(self.rad)-1, self.ri, self.ro) \
                   /(self.ro**3-self.ri**3)
        dsdr = N.dot(d1, self.ss)
        self.beta = dsdr[len(dsdr)/2]
        print('beta', self.beta)
        self.slopeTop = dsdr[2]*(self.rad-self.ro)+self.ss[0]
        self.slopeBot = dsdr[-1]*(self.rad-self.ri)+self.ss[-1]

        self.dtdrm = dsdr[len(self.ss)/2]
        self.slopeMid = self.dtdrm*(self.rad-(self.ri+self.ro)/2.)+self.ss[len(self.ss)/2]

        #self.bcTopSlope = -(self.ttm-self.ss[0])/dsdr[2]
        self.bcTopSlope = (self.ss[len(self.ss)/2]-self.ss[0])/(self.dtdrm-dsdr[2])
        #self.bcBotSlope = (self.ttm-self.ss[-1])/(dsdr[-1])
        self.bcBotSlope = -(self.ss[len(self.ss)/2]-self.ss[-1])/(self.dtdrm-dsdr[-1])

        # 2nd round with a more accurate slope
        bSlope = dsdr[self.rad <= self.ri+self.bcBotSlope/4.].mean()
        tSlope = dsdr[self.rad >= self.ro-self.bcTopSlope/4.].mean()
        self.slopeBot = bSlope*(self.rad-self.ri)+self.ss[-1]
        self.slopeTop = tSlope*(self.rad-self.ro)+self.ss[0]
        #self.bcTopSlope = -(self.ttm-self.ss[0])/tSlope
        self.bcTopSlope = (self.ss[len(self.ss)/2]-self.ss[0])/(self.dtdrm-tSlope)
        #self.bcBotSlope = (self.ttm-self.ss[-1])/bSlope
        self.bcBotSlope = -(self.ss[len(self.ss)/2]-self.ss[-1])/(self.dtdrm-bSlope)


        if hasattr(self, 'epsT'):
            self.slopeEpsTbl, self.slopeEpsTbulk = integBulkBc(self.rad, self.epsTR, 
                         self.ri, self.ro, self.bcBotSlope, self.bcTopSlope)

            print('slopes bl, bulk', self.slopeEpsTbl/self.epsT, self.slopeEpsTbulk/self.epsT)
            
        pow = MagicRadial(field='powerR', iplot=False, tags=tags)
        self.vi = pow.viscDiss
        self.buo = pow.buoPower


        self.epsV = -intcheb(self.vi, len(self.rad)-1, self.ro, self.ri)
        ind = getMaxima(-abs(self.vi-self.epsV))
        if len(ind) > 2:
            for i in ind:
                if self.vi[i-1]-self.epsV > 0 and self.vi[i+1]-self.epsV < 0:
                    self.dissTopV = self.ro-self.rad[i]
                elif self.vi[i-1]-self.epsV < 0 and self.vi[i+1]-self.epsV > 0:
                    self.dissBotV = self.rad[i]-self.ri
        else:
            self.dissTopV = self.ro-self.rad[ind[0]]
            self.dissBotV = self.rad[ind[-1]]-self.ri
        self.dissEpsVbl, self.dissEpsVbulk = integBulkBc(self.rad, self.vi, 
                         self.ri, self.ro, self.dissBotV, self.dissTopV)
        print('visc Diss bl, bulk', self.dissEpsVbl/self.epsV, self.dissEpsVbulk/self.epsV)

        # First way of defining the viscous boundary layers: with duhdr
        #rViscousLayer = getMaxima(self.rad, self.duh)
        if self.kbotv == 1 and self.ktopv == 1:
            ind = argrelextrema(self.duh, N.greater)[0]
            if len(ind) == 0:
                self.bcTopduh = 1.
                self.bcBotduh = 1.
            else:
                if ind[0] < 4:
                    self.bcTopduh = self.ro-self.rad[ind[1]]
                else:
                    self.bcTopduh = self.ro-self.rad[ind[0]]
                if len(self.rad)-ind[-1] < 4:
                    self.bcBotduh = self.rad[ind[-2]]-self.ri
                else:
                    self.bcBotduh = self.rad[ind[-1]]-self.ri
            self.slopeTopU = 0.
            self.slopeBotU = 0.
            self.uhTopSlope = 0.
            self.uhBotSlope = 0.
            self.slopeEpsUbl = 0.
            self.slopeEpsUbulk = 0.
            self.uhBot = 0.
            self.uhTop = 0.
        else:
            ind = argrelextrema(self.uh, N.greater)[0]
            if len(ind) == 1:
                ind = argrelextrema(self.uh, N.greater_equal)[0]
            if len(ind) == 0:
                self.bcTopduh = 1.
                self.bcBotduh = 1.
            else:
                if ind[0] < 4:
                    self.bcTopduh = self.ro-self.rad[ind[1]]
                else:
                    self.bcTopduh = self.ro-self.rad[ind[0]]
                if len(self.rad)-ind[-1] < 4:
                    self.bcBotduh = self.rad[ind[-2]]-self.ri
                else:
                    self.bcBotduh = self.rad[ind[-1]]-self.ri

            self.uhTop = self.uh[self.rad==self.ro-self.bcTopduh][0]
            self.uhBot = self.uh[self.rad==self.ri+self.bcBotduh][0]

            self.bcBotduh, self.bcTopduh, self.uhBot, self.uhTop =      \
                        getAccuratePeaks(self.rad, self.uh, self.uhTop, \
                                         self.uhBot, self.ri, self.ro)

            duhdr = N.dot(d1, self.uh)

            #1st round
            mask = (self.rad>=self.ro-self.bcTopduh/4)*(self.rad<self.ro)
            slopeT = duhdr[mask].mean()
            mask = (self.rad<=self.ri+self.bcBotduh/4)*(self.rad>self.ri)
            slopeB = duhdr[mask].mean()
            self.slopeTopU = slopeT*(self.rad-self.ro)+self.uh[0]
            self.slopeBotU = slopeB*(self.rad-self.ri)+self.uh[-1]
            self.uhTopSlope = -self.uhTop/slopeT
            self.uhBotSlope = self.uhBot/slopeB

            #2nd round
            mask = (self.rad>=self.ro-self.uhTopSlope/4.)*(self.rad<self.ro)
            slopeT = duhdr[mask].mean()
            mask = (self.rad<=self.ri+self.uhBotSlope/4)*(self.rad>self.ri)
            slopeB = duhdr[mask].mean()
            self.uhTopSlope = -self.uhTop/slopeT
            self.uhBotSlope = self.uhBot/slopeB

            self.slopeEpsUbl, self.slopeEpsUbulk = integBulkBc(self.rad, self.vi, 
                         self.ri, self.ro, self.uhBotSlope, self.uhTopSlope)

        self.uhEpsVbl, self.uhEpsVbulk = integBulkBc(self.rad, self.vi, 
                         self.ri, self.ro, self.bcBotduh, self.bcTopduh)
        print('uh bl, bulk', self.uhEpsVbl/self.epsV, self.uhEpsVbulk/self.epsV)

        # Convective Rol in the thermal boundary Layer
        par = MagicRadial(field='parR', iplot=False, tags=tags)
        kin = MagicRadial(field='eKinR', iplot=False, tags=tags)
        ekinNas = kin.ekin_pol+kin.ekin_tor-kin.ekin_pol_axi-kin.ekin_tor_axi
        ReR = N.sqrt(2.*abs(ekinNas)/par.radius**2/(4.*N.pi))
        RolC = ReR*par.ek/par.dlVc

        self.dl = par.dlVc
        y = RolC[par.radius >= self.ro-self.bcTopSlope]
        x = par.radius[par.radius >= self.ro-self.bcTopSlope]
        self.rolTop = simps(3.*y*x**2, x)/(self.ro**3-(self.ro-self.bcTopSlope)**3)

        self.rolbl, self.rolbulk = integBulkBc(self.rad, 4.*N.pi*RolC*self.rad**2, 
                                     self.ri, self.ro, self.bcBotSlope, self.bcTopSlope,
                                     normed=True)

        self.rebl, self.rebulk = integBulkBc(self.rad, 4.*N.pi*ReR*self.rad**2, 
                                     self.ri, self.ro, self.bcBotduh, self.bcTopduh,
                                     normed=True)

        self.lengthbl, self.lengthbulk = integBulkBc(self.rad, par.dlVc, 
                                     self.ri, self.ro, self.bcBotSlope, self.bcTopSlope,
                                     normed=True)

        self.rehbl, self.rehbulk = integBulkBc(self.rad, self.uh*4.*N.pi*self.rad**2, 
                                     self.ri, self.ro, self.bcBotduh, self.bcTopduh,
                                     normed=True)

        y = RolC[par.radius <= self.ri+self.bcBotSlope]
        x = par.radius[par.radius <= self.ri+self.bcBotSlope]
        self.rolBot = simps(3.*y*x**2, x)/((self.ri+self.bcBotSlope)**3-self.ri**3)
        print('reynols bc, reynolds bulk', self.rebl, self.rebulk)
        print('reh bc, reh bulk', self.rehbl, self.rehbulk)
        print('rolbc, rolbulk, roltop, rolbot', self.rolbl, self.rolbulk, self.rolBot, self.rolTop)

        par.dlVc[0] = 0.
        par.dlVc[-1] = 0.
        self.lBot, self.lTop = integBotTop(self.rad, 4.*N.pi*self.rad**2*par.dlVc, 
                         self.ri, self.ro, self.bcBotSlope, self.bcTopSlope, normed=True)

        uhbm, utbm = integBotTop(self.rad, 4.*N.pi*self.uh, 
                         self.ri, self.ro, self.bcBotSlope, self.bcTopSlope, normed=True)

        if iplot:
            self.plot()

        if not quiet:
            print(self)