コード例 #1
0
def _copy_column_coeffs(alphas, betas, coeff_vec, num_poly_terms, num_channels,
                        num_coeffs, j):
    for ci in range(num_coeffs):
        ti = ci - 1
        for i in range(num_channels):
            if ci == 0:
                if i == j:
                    alphas[ci][i, j] = 1.0
            else:
                alphas[ci][i, j] = nw.complex(
                    coeff_vec[_alpha_index(num_poly_terms, i, ti), 0])
                betas[ci][i, j] = nw.complex(
                    coeff_vec[_beta_index(num_poly_terms, num_channels, i, ti),
                              0])
コード例 #2
0
 def get_matrix(self):
     mlist = []
     for m in range(self.size):
         rlist = []
         for n in range(self.size):
             rlist.append(nw.complex(self[m][n]))
         mlist.append(rlist)
     return nw.matrix(mlist)
コード例 #3
0
ファイル: __init__.py プロジェクト: petersbingham/reskit
 def _load_roots(self, Npts, ris):
     if self.archive_root is not None:
         root_path = self._find_compatible_root_dir(Npts, ris)
         if root_path is not None:
             try:
                 with th.fropen(root_path) as f:
                     fndStart = False
                     roots = []
                     for l in f:
                         if not fndStart:
                             if "---" in l:
                                 fndStart = True
                             continue
                         elif "complete" not in l:
                             roots.append(nw.complex(l.split()[0]))
                     if "complete" not in l:
                         self.log.write_err("Incomplete root file")
                         return None
                     self.log.write_msg("Roots loaded from: " + root_path)
                     return roots
             except Exception as inst:
                 self.log.write_err(str(inst))
                 raise
     return None
コード例 #4
0
ファイル: __init__.py プロジェクト: petersbingham/reskit
    def find_stable_Smat_poles(self, cfins_or_roots):
        """
        Finds the S-matrix poles by identifying stable roots. The input can be
        either a list of roots or the Fin themselves. There are additional
        advanced parameters supplied via the Tool yaml file.

        Parameters
        ----------
        cfins_or_roots : list of either cFinMatSympypolyk or list of floats
            As returned from either get_elastic_Fins or find_Fin_roots.

        Returns
        -------
        pole_dat : list of lists.
            List of poles and their calculated quality indicators.
        amalg_pole_dat : list of lists.
            List of poles that had been combined according to the amalgamation
            threshold specified in the paramFile.
        """
        try:
            param_str = str(map(lambda x: x.fitInfo[0], cfins_or_roots))
        except AttributeError:
            param_str = str(cfins_or_roots.n_list)

        self.log.write_call("find_stable_Smat_poles(" + param_str + ")")
        if len(cfins_or_roots) > 0:
            try:
                cfins_or_roots.n_list  # Test for the parameter type.
                all_roots = cfins_or_roots
            except AttributeError:
                all_roots = self.find_Fin_roots(cfins_or_roots, True)
            if len(all_roots) > 0:
                with th.fropen(self.param_file_path) as f:
                    config = yaml.load(f.read())
                    p = config["find_stable_Smat_poles"]
                    self.log.write_parameters(p)
                    if "root_filt" in p:
                        pp = p["root_filt"]
                        all_roots = self._filterRoots(all_roots,
                                                      nw.complex(pp["point"]),
                                                      nw.complex(pp["atol"]))
                    pp = p["stelempy"]
                    # Default to precision limit of input data:
                    end_rtol = pow(10, -nw.dps)
                    try:
                        end_rtol = float(pp["end_rtol"])
                    except TypeError:
                        pass

                    ztol = float(pp["ztol"])
                    ratcmp = sp.num.RationalCompare1(ztol=ztol)
                    poleData = sp.calculate_convergence_groups_range(
                        all_roots, ratcmp, float(pp["start_rtol"]), end_rtol,
                        int(pp["cfsteps"]))
                    self.log.write_msg("Convergence groups calculated")
                    self._save_pole_data(all_roots.n_list, poleData,
                                         all_roots.asymcalc, p)

                    amalg_ratcmp = None
                    amalg_rtol = float(pp["amalg_rtol"])
                    if amalg_rtol != 0.:
                        amalg_ratcmp = sp.num.RationalCompare1(
                            amalg_rtol, ztol)
                    pole_dat = sp.calculate_QIs_from_range(
                        poleData, amalg_ratcmp)
                    self.log.write_msg("QIs calculated")
                    self._save_QI_data(all_roots.n_list, pole_dat,
                                       all_roots.asymcalc)
                    self.log.write_call_end("find_stable_Smat_poles")
                    return pole_dat
        self.log.write_call_end("find_stable_Smat_poles")
        return None, None
コード例 #5
0
 def _get_formatted_str(self, value, is_complex):
     if is_complex:
         return nw.num_str(nw.complex(value), self.precision)
     else:
         return nw.num_str_real(nw.complex(value), self.precision)
コード例 #6
0
 def _is_complex(self):
     for m in range(0, self.size):
         for n in range(0, self.size):
             if abs(float(nw.complex(self[m][n]).imag)) > self.min:
                 return True
     return False
コード例 #7
0
 def fk(self, ene): #free k
     k = nw.sqrt(self.get_ene_conv()*ene)
     return nw.complex(k)
コード例 #8
0
 def ke(self, k):
     ene = (1.0/self.get_ene_conv())*k**2
     return nw.complex(ene)