コード例 #1
0
ファイル: plot.py プロジェクト: kurhar/femagtools
def felosses(losses, coeffs, title='', log=True):
    """plot iron losses with steinmetz or jordan approximation
    Args:
      losses: dict with f, B, pfe values
      coeffs: list with steinmetz (cw, alpha, beta) or
              jordan (cw, alpha, ch, beta, gamma) coeffs
      title: title string
      log: log scale for x and y axes if True"""
    import femagtools.losscoeffs as lc
    ax = pl.gca()

    fo = losses['fo']
    Bo = losses['Bo']
    B = pl.np.linspace(0.9*np.min(losses['B']),
                       1.1*0.9*np.max(losses['B']))
                                  
    for i, f in enumerate(losses['f']):
        pfe = [p for p in np.array(losses['pfe']).T[i] if p]
        if f > 0:
            if len(coeffs) == 5:
                ax.plot(B, lc.pfe_jordan(f, B, *coeffs, fo=fo, Bo=Bo))
            elif len(coeffs) == 3:
                ax.plot(B, lc.pfe_steinmetz(f, B, *coeffs, fo=fo, Bo=Bo))
        pl.plot(losses['B'][:len(pfe)], pfe,
                marker='o', label="{} Hz".format(f))

    ax.set_title("Fe Losses/(W/kg) " + title)
    if log:
        ax.set_yscale('log')
        ax.set_xscale('log')
    ax.set_xlabel("Induction [T]")
    #pl.ylabel("Pfe [W/kg]")
    ax.legend()
    ax.grid(True)
コード例 #2
0
    def writeBinaryFile(self, fillfac=None):
        curve = self._prepare(fillfac)
        # write line, version_mc_curve
        self.writeBlock(self.version_mc_curve)

        # write line, text '    *** File with magnetic curve ***    '
        self.writeBlock('    *** File with magnetic curve ***    ')

        # write line, mc1_title
        self.writeBlock(self.mc1_title.ljust(40)[:40])
        # write line, mc1_ni(1),mc1_mi(1),mc1_type,mc1_recalc,mc1_db2(1)
        self.writeBlock([
            int(self.mc1_ni[0]),
            int(self.mc1_mi[0]),
            int(self.mc1_type),
            int(self.mc1_recalc), self.mc1_db2[0]
        ])

        # write line, mc1_remz, mc1_bsat, mc1_bref, mc1_fillfac
        if self.version_mc_curve == self.ACT_VERSION_MC_CURVE:
            self.writeBlock([
                float(self.mc1_remz),
                float(self.mc1_bsat),
                float(self.mc1_bref),
                float(self.mc1_fillfac)
            ])
        if self.mc1_type == DEMCRV_BR:
            self.mc1_remz = self.mc1_angle[self.mc1_curves - 1]
        if self.version_mc_curve == self.ORIENTED_VERSION_MC_CURVE or \
           self.version_mc_curve == self.PARAMETER_PM_CURVE:
            logging.debug("write mc1_curves %d", self.mc1_curves)
            self.writeBlock([
                float(self.mc1_remz),
                float(self.mc1_bsat),
                float(self.mc1_bref),
                float(self.mc1_fillfac), self.mc1_curves
            ])

        if self.mc1_type == DEMCRV_BR:
            self.mc1_angle[self.mc1_curves - 1] = self.mc1_remz

        # data
        for K in range(0, self.mc1_curves):
            logger.debug(" K %d  Bi, Hi %d", K, len(curve[K].get('bi', [])))
            # hi, bi
            lb = curve[K].get('bi', [])
            lh = curve[K].get('hi', [])
            self.writeBlock(
                zip(*[[
                    float(lb[j]) if j < len(lb) else 0.
                    for j in range(self.MC1_NIMAX)
                ],
                      [
                          float(lh[j]) if j < len(lh) else 0.
                          for j in range(self.MC1_NIMAX)
                      ]]))

            # bi2, nuer
            lb = curve[K]['bi2']
            ln = curve[K]['nuer']
            self.writeBlock(
                zip(*[[
                    float(lb[j]) if j < len(lb) else 0.
                    for j in range(self.MC1_NIMAX)
                ],
                      [
                          float(ln[j]) if j < len(ln) else 0.
                          for j in range(self.MC1_NIMAX)
                      ]]))

            # a, b, c, d
            la = curve[K].get('a', [0.] * self.MC1_NIMAX)
            lb = curve[K].get('b', [0.] * self.MC1_NIMAX)
            self.writeBlock(
                zip(*[[
                    float(la[j]) if j < len(la) else 0.
                    for j in range(self.MC1_NIMAX)
                ],
                      [
                          float(lb[j]) if j < len(lb) else 0.
                          for j in range(self.MC1_NIMAX)
                      ], [0.] * 50, [0.] * 50]))

            #
            if self.version_mc_curve == self.ORIENTED_VERSION_MC_CURVE or \
               self.version_mc_curve == self.PARAMETER_PM_CURVE:
                self.writeBlock([self.mc1_angle[K], self.mc1_db2[K]])

        self.writeBlock([
            float(self.mc1_base_frequency),
            float(self.mc1_base_induction),
            float(self.mc1_ch_factor),
            float(self.mc1_cw_factor),
            float(self.mc1_ch_freq_factor),
            float(self.mc1_cw_freq_factor),
            float(self.mc1_induction_factor),
            float(self.mc1_fe_spez_weigth),
            float(self.mc1_fe_sat_magnetization)
        ])

        if not hasattr(self, 'losses') or not self.losses:
            return

        try:
            nfreq = len([1 for x in self.losses['f'] if x > 0])
            nind = len(self.losses['B'])
            self.writeBlock([nfreq, nind])
            self.writeBlock(self.losses['B'] + [0.0] * (M_LOSS_INDUCT - nind))
            cw = self.losses['cw']
            alpha = self.losses['cw_freq']
            beta = self.losses['b_coeff']

            for f, p in zip(self.losses['f'], self.losses['pfe']):
                if f != None:
                    pl = [
                        px if px != None else lc.pfe_steinmetz(
                            f, b, cw, alpha, beta, self.losses['fo'],
                            self.losses['Bo'])
                        for px, b in zip(p, self.losses['B'])
                    ]
                    self.writeBlock(pl + [0.0] * (M_LOSS_INDUCT - len(pl)))
                    self.writeBlock(f)
            for m in range(M_LOSS_FREQ - len(self.losses['pfe'])):
                self.writeBlock([0.0] * M_LOSS_INDUCT)
                self.writeBlock(0.0)

            self.writeBlock([
                self.losses['cw'], self.losses['cw_freq'],
                self.losses['b_coeff'], self.losses['fo'], self.losses['Bo']
            ])
            self.writeBlock([1])
            logger.info('Losses n freq %d n ind %d', nfreq, nind)
        except Exception as e:
            logger.error(e, exc_info=True)