result = sqa.normalOrder(sqa.multiplyTerms(Op2, Op1)) # Simplify the result for t in result: t.contractDeltaFuncs_new() sqa.removeVirtOps_sf(result) sqa.termChop(result) sqa.combineTerms(result) extendedR=[] for t in result: extendedR += sqa.contractCoreOps_sf(t) for t in extendedR: t.contractDeltaFuncs_new() sqa.termChop(extendedR) sqa.combineTerms(extendedR) result = [] rdmDelta = [deltaC, deltaA, deltaV] for r in extendedR: item1=geraldCode.replaceRepeatIndicesWithDeltas(r, rdmDelta) item2=geraldCode.replaceSingleKdeltaWithDeltas(item1, rdmDelta) result.append(geraldCode.replaceAllKdeltaWithDeltas(item2, rdmDelta)) # Write out the equation for A.p print '//Number of terms : ', nbrEqs print ' FEqInfo EqsRes[%i] = {\n'%(nbrEqs) geraldCode.WriteCodeSimple(result, AllTensors, CommentKey) print '\n };'
def write_tensors_and_equations(Class, result, tensors, commentE3=False, df=False): if 'AAA' in Class or '3' in Class: commentE3 = False names = [tensors[index][0] for index in range(len(tensors))] selectA = [] selectH = [] selectD = [] selection = [] # the residual if "R" in names: selection.append(names.index("R")) # all the amplitudes for i in range(len(tensors)): if tensors[i][3] == "A": selectA.append(i) # the tensors needed by the equations for t in result: for i in t.tensors: try: index = names.index(i.name) except: newlist = [ i.name, i.name[:2], i.name[2:].replace('v', 'e'), 'A' ] selectA.append(len(tensors)) names.append(i.name) index = len(tensors) tensors = tensors + [newlist] if tensors[index][3] == "D": if index not in selectD: selectD.append(index) elif tensors[index][3] == "H" or tensors[index][3] == "I": if index not in selectH: selectH.append(index) elif tensors[index][3] == "A" or tensors[index][3] == "R": if index not in selectA: selectA.append(index) else: print('None of D/H/I/A/R? (in "needed_by_equation")') print(tensors[index]) exit() # all the overlaps S and all the coefficients D for i in range(len(tensors)): if re.search('^S', tensors[i][0]): if i not in selectD: selectD.append(i) if re.search('^D', tensors[i][0]): if i not in selectH: selectH.append(i) # the manual additions addition = manual(Class, df=df) for add in addition: index = names.index(add) if tensors[index][3] == "D": if index not in selectD: selectD.append(index) elif tensors[index][3] == "H": if index not in selectH: selectH.append(index) elif tensors[index][3] == "A": if index not in selectA: selectA.append(index) else: print('None of D/H/A? (in "manual_additions")') print(tensors[index]) exit() # sort by name namesA = [names[i] for i in selectA] namesH = sorted([names[i] for i in selectH], key=lambda s: s.lower()) namesD = sorted([names[i] for i in selectD], key=lambda s: s.lower()) sorted_names = namesA + namesH + namesD selection += [ names.index(name) for name in sorted_names if name is not "E3" and name is not "E4" ] if "E3" in sorted_names: selection += [names.index("E3")] if "E4" in sorted_names: selection += [names.index("E4")] AllTensors = [tensors[index2][0] for index2 in selection] CommentTensors = [tensors[index2][1] for index2 in selection] Domains = [tensors[index2][2] for index2 in selection] Usage = [tensors[index2][3] for index2 in selection] CommentKey = {} for tc in list(zip(AllTensors, CommentTensors)): CommentKey[tc[0]] = tc[1] # Write out the tensors print("namespace " + Class + " {\n") nbrTensors = geraldCode.writeTensors(AllTensors, CommentKey, Domains, Usage, commentE3=commentE3) # Write out the equation for A.p nbrEqs = geraldCode.WriteCodeSimple(result, AllTensors, CommentKey, commentE3=commentE3) return AllTensors, nbrTensors, nbrEqs