def tensor_solver(b4_eqns, aft_eqns, e_knowns=[], levels=-1, num_sols=1, verbose=True, solution_file=None, logic_files=None): """Updater calling tensor solvers.""" if verbose or DEBUG: print "tensor_solver:" print " b4_eqns:", pprint.pformat(b4_eqns, 4, 80) print " aft_eqns:", pprint.pformat(aft_eqns, 4, 80) print " e_knowns:", pprint.pformat(e_knowns, 4, 80) knowns = set(flatten([eqn.atoms() for eqn in b4_eqns])).union(set(e_knowns)) knowns.union(CONSTANTS) eqns = aft_eqns + b4_eqns if verbose or DEBUG or True: print "=" * 80 print "Calling Generator with following:" print "*" * 80 print "Knowns:", pprint.pformat(knowns, 4, 80) print "-" * 80 unknown = set(flatten([eqn.atoms() for eqn in aft_eqns])) - knowns print "Unknowns:", pprint.pformat(unknown, 4, 80) print "-" * 80 print "eqns:", pprint.pformat(eqns, 4, 80) print "=" * 80 multiple_sols = True sub_all = True sol_dicts = all_back_sub(eqns, knowns, levels, multiple_sols, sub_all) #sol_dicts = map(sol_cse, sol_dicts) if solution_file: fp = open(solution_file, 'w') fp.write("%"*80 + \ "\n%% This file was automatically generated by Ignition\n" + \ "%" * 80 + "\n") for n, dict_ord in enumerate(sol_dicts): fp.write("Algorithm %d\n\n" % (n + 1)) fp.write(update_dict_to_latex(*dict_ord)) fp.write("\n\n") if logic_files: print "Writing out logic files to %s_{0--%d}.out" % \ (logic_files, len(sol_dicts)) for n, dict_ord in enumerate(sol_dicts): fp = open("%s_%d.out" % (logic_files, n), 'w') backward_sub(eqns, knowns, dict_ord[1], multiple_sols, sub_all, fp) fp.close() sol_dicts = sol_dicts[:num_sols] return sol_dicts
def _is_nonlinear (self): """Simple check for non-linear fluxes""" for field in self.conserved.fields(): for term in flatten(self.A.tolist()): if field in term: return True return False
def tensor_solver (b4_eqns, aft_eqns, e_knowns=[], levels= -1, num_sols=1, verbose=True, solution_file=None, logic_files=None, allow_recompute=False): """Updater calling tensor solvers.""" if verbose or DEBUG: print "tensor_solver:" print " b4_eqns:", pprint.pformat(b4_eqns, 4, 80) print " aft_eqns:", pprint.pformat(aft_eqns, 4, 80) print " e_knowns:", pprint.pformat(e_knowns, 4, 80) knowns = set(flatten([eqn.atoms() for eqn in b4_eqns])).union(set(e_knowns)) knowns.union(CONSTANTS) eqns = aft_eqns + b4_eqns if verbose or DEBUG or True: print "=" * 80 print "Calling Generator with following:" print "*" * 80 print "Knowns:", pprint.pformat(knowns, 4, 80) print "-" * 80 unknown = set(flatten([eqn.atoms() for eqn in aft_eqns])) - knowns print "Unknowns:", pprint.pformat(unknown, 4, 80) print "-" * 80 print "eqns:", pprint.pformat(eqns, 4, 80) print "=" * 80 multiple_sols = True sub_all = True sol_dicts = all_back_sub(eqns, knowns, levels, multiple_sols, sub_all, allow_recompute) #sol_dicts = map(sol_cse, sol_dicts) if solution_file: fp = open(solution_file, 'w') fp.write("%"*80 + \ "\n%% This file was automatically generated by Ignition\n" + \ "%" * 80 + "\n") for n, dict_ord in enumerate(sol_dicts): fp.write("Algorithm %d\n\n" % (n + 1)) fp.write(update_dict_to_latex(*dict_ord)) fp.write("\n\n") if logic_files: print "Writing out logic files to %s_{0--%d}.out" % \ (logic_files, len(sol_dicts)) for n, dict_ord in enumerate(sol_dicts): fp = open("%s_%d.out" % (logic_files, n), 'w') backward_sub(eqns, knowns, dict_ord[1], multiple_sols, sub_all, fp) fp.close() sol_dicts = sol_dicts[:num_sols] return sol_dicts
def AK_KJ_Rule(A, K, J): [A] = A [K_l, k_m, K_r] = K [[J_tl, _, _], [Tj_ml, _, _], [_, j_bm, J_br]] = J op = (A * K_l - K_l * J_tl - k_m * Tj_ml) if type(op) is matrix: op = op.tolist() if type(op) is list: op = flatten(op) return op, []
def AK_KJ_Rule (A, K, J): [A] = A [K_l, k_m, K_r] = K [[J_tl, _, _], [Tj_ml, _, _], [_, j_bm, J_br]] = J op = (A * K_l - K_l * J_tl - k_m * Tj_ml) if type(op) is matrix: op = op.tolist() if type(op) is list: op = flatten(op) return op, []
def used_constant_fields(self): """Constant Fields used inside jacobian evaluation""" A = self.A atoms = set(flatten([x.atoms() for x in flatten(A.tolist())])) return filter(lambda a: isinstance(a, ConstantField), atoms)