def _print_eigenvalues_symbolic(self, indent=0): ret_code = symbolic_eigen_decomp % \ (self._sympy_mat_to_numpy_str(self._generator.A), self._sympy_mat_to_numpy_str(self._generator.R), self._sympy_mat_to_numpy_str(self._generator.Rinv), str(self._generator.eig_vals)) return indent_code(ret_code, indent)
def _print_eigenvalues_symbolic (self, indent=0): ret_code = symbolic_eigen_decomp % \ (self._sympy_mat_to_numpy_str(self._generator.A), self._sympy_mat_to_numpy_str(self._generator.R), self._sympy_mat_to_numpy_str(self._generator.Rinv), str(self._generator.eig_vals)) return indent_code(ret_code, indent)
def _print_sizes(self, indent=0): meqn = len(self._generator.conserved.fields()) mwaves = meqn return indent_code( vectorized_shapes % { "meqn": meqn, "mwaves": mwaves }, indent)
def _print_eigenvalues_numerical(self, indent=0): sub_dict = {} for f in self._generator.conserved.fields() + \ self._generator.used_constant_fields(): sub_dict[f] = sp.Symbol(str(f) + "[rp]") A_str = "[%s for i in xrange(nrp)]" % \ self._sympy_mat_to_vectorized_numpy_str( \ self._generator.A.subs(sub_dict)) ret_code = vectorized_numerical_eigen_decomp % A_str return indent_code(ret_code, indent)
def _print_eigenvalues_numerical (self, indent=0): sub_dict = {} for f in self._generator.conserved.fields() + \ self._generator.used_constant_fields(): sub_dict[f] = sp.Symbol(str(f)+"[rp]") A_str = "[%s for i in xrange(nrp)]" % \ self._sympy_mat_to_vectorized_numpy_str( \ self._generator.A.subs(sub_dict)) ret_code = vectorized_numerical_eigen_decomp % A_str return indent_code(ret_code, indent)
def _print_eigenvalues_symbolic (self, indent=0): sub_dict = {} for f in self._generator.conserved.fields() +\ self._generator.used_constant_fields(): sub_dict[f] = sp.Symbol(str(f)+"[rp]") ret_code = vectorized_symbolic_eigen_decomp % \ (self._sympy_mat_to_numpy_str(self._generator.A.subs(sub_dict)), self._sympy_mat_to_numpy_str(self._generator.R.subs(sub_dict)), self._sympy_mat_to_numpy_str(self._generator.Rinv.subs(sub_dict)), str([ev.subs(sub_dict) for ev in self._generator.eig_vals])) return indent_code(ret_code, indent)
def _print_eigenvalues_symbolic(self, indent=0): sub_dict = {} for f in self._generator.conserved.fields() +\ self._generator.used_constant_fields(): sub_dict[f] = sp.Symbol(str(f) + "[rp]") ret_code = vectorized_symbolic_eigen_decomp % \ (self._sympy_mat_to_numpy_str(self._generator.A.subs(sub_dict)), self._sympy_mat_to_numpy_str(self._generator.R.subs(sub_dict)), self._sympy_mat_to_numpy_str(self._generator.Rinv.subs(sub_dict)), str([ev.subs(sub_dict) for ev in self._generator.eig_vals])) return indent_code(ret_code, indent)
def _print_jac_evals (self, indent=0): ret_code = "" if self._generator._is_nonlinear(): if self._generator.jacobian_averaging == "arithmetic": ret_code += "# Evaluate the averages of the conserved "\ "quantities\n" for n, f in enumerate(self._generator._conserved.fields()): ret_code += "%(f)s = (q_l[%(idx)d,:] + q_r[%(idx)d,:])" \ "/2.0\n" % {"f":str(f), "idx":n} else: raise NotImplementedError("Unknown jacobian evaluation: %s" \ % self._generator.jacobian_averaging) return indent_code(ret_code, indent)
def _print_jac_evals(self, indent=0): ret_code = "" if self._generator._is_nonlinear(): if self._generator.jacobian_averaging == "arithmetic": ret_code += "# Evaluate the averages of the conserved "\ "quantities\n" for n, f in enumerate(self._generator._conserved.fields()): ret_code += "%(f)s = (q_l[%(idx)d,:] + q_r[%(idx)d,:])" \ "/2.0\n" % {"f":str(f), "idx":n} else: raise NotImplementedError("Unknown jacobian evaluation: %s" \ % self._generator.jacobian_averaging) return indent_code(ret_code, indent)
def _print_constant_fields (self, indent=0): used_cf = self._generator.used_constant_fields() if len(used_cf) == 0: return "" ret_code = "\n# Evaluating Constant Fields\n" if self._generator.jacobian_averaging == "arithmetic": for n, cf in enumerate(self._generator.constant_fields): if cf in used_cf: ret_code += "%(cf)s = (aux_l[%(n)d,:] + aux_r[%(n)d,:])" \ "/2.0\n" % {"cf":str(cf), "n":n} else: raise NotImplementedError("Unimplemented jacobian averaging: %s" \ % self._generator.jacobian_averaging) return indent_code(ret_code, indent)
def _print_constant_fields(self, indent=0): used_cf = self._generator.used_constant_fields() if len(used_cf) == 0: return "" ret_code = "\n# Evaluating Constant Fields\n" if self._generator.jacobian_averaging == "arithmetic": for n, cf in enumerate(self._generator.constant_fields): if cf in used_cf: ret_code += "%(cf)s = (aux_l[%(n)d,:] + aux_r[%(n)d,:])" \ "/2.0\n" % {"cf":str(cf), "n":n} else: raise NotImplementedError("Unimplemented jacobian averaging: %s" \ % self._generator.jacobian_averaging) return indent_code(ret_code, indent)
def _print_func_decl(self, indent=0): return indent_code(func_decl, indent)
def _print_eigenvalues_numerical (self, indent=0): A_str = self._sympy_mat_to_numpy_str(self._generator.A) ret_code = numerical_eigen_decomp % A_str return indent_code(ret_code, indent)
def _print_kernel(self, indent=0): return indent_code(pointwise_kernel, indent)
def _print_func_return(self, indent=0): return indent_code(func_return, indent)
def _print_header(self, indent=0): return indent_code(file_header, indent)
def _print_eigenvalues_numerical(self, indent=0): A_str = self._sympy_mat_to_numpy_str(self._generator.A) ret_code = numerical_eigen_decomp % A_str return indent_code(ret_code, indent)
def _print_constants(self, indent=0): ret_code = "\n# Evaluating Constants\n" for a in self._generator.used_constants(): ret_code += "%(c)s = aux_global['%(c)s']\n" % {"c": str(a)} return indent_code(ret_code, indent)
def _print_kernel (self, indent=0): return indent_code(pointwise_kernel, indent)
def _print_constants (self, indent=0): ret_code = "\n# Evaluating Constants\n" for a in self._generator.used_constants(): ret_code += "%(c)s = aux_global['%(c)s']\n" % {"c": str(a)} return indent_code(ret_code, indent)
def _print_func_return(self, indent=0): return indent_code(vectorized_func_return, indent)
def _print_sizes (self, indent=0): meqn = len(self._generator.conserved.fields()) mwaves = meqn return indent_code(vectorized_shapes % {"meqn":meqn, "mwaves":mwaves}, indent)
def _print_kernel (self, indent=0): ret_code = vectorized_kernel return indent_code(ret_code, indent)
def _print_kernel(self, indent=0): ret_code = vectorized_kernel return indent_code(ret_code, indent)
def test_indent_code (): code = "python\nrequires\nfour\nspaces" indented_code = " python\n requires\n four\n spaces" assert(indent_code(code, 4) == indented_code) assert(indent_code("",4) == "") assert(indent_code("foobar",0) == "foobar")