Пример #1
0
                [28, 'S3',        'S3',      'a',          'D'],
                [29, 'deltac',    'delta',   'cc',         'D'],
                [30, 'deltaa',    'delta',   'aa',         'D'],
                [31, 'deltav',    'delta',   'ee',         'D'],
                ]
AllTensors=    [tensors[index][1] for index in selection]
CommentTensors=[tensors[index][2] for index in selection]
Domains=       [tensors[index][3] for index in selection]
Usage=         [tensors[index][4] for index in selection]
CommentKey = {}
for tc in list(zip(AllTensors, CommentTensors)):
    CommentKey[tc[0]] = tc[1]

# Write out the tensors
print 'namespace NEVPT_'+Class+' {\n'
geraldCode.writeTensors(AllTensors, CommentKey, Domains, Usage)

# Define needed indexes as being core,active,virtual
tag_core    = sqa.options.core_type
tag_active  = sqa.options.active_type
tag_virtual = sqa.options.virtual_type

i  = sqa.index('Ci',  [tag_core],    withC)
j  = sqa.index('Cj',  [tag_core],    withC)
k  = sqa.index('Ck',  [tag_core],    withC)
l  = sqa.index('Cl',  [tag_core],    withC)
p  = sqa.index('Ap',  [tag_active],  withC)
q  = sqa.index('Aq',  [tag_active],  withC)
a  = sqa.index('Va',  [tag_virtual], withC)
b  = sqa.index('Vb',  [tag_virtual], withC)
Пример #2
0
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