Ignore:
Timestamp:
Mar 10, 2014 2:06:56 PM (8 years ago)
Author:
toby
Message:

fix constraints use in sequential refinements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIImapvars.py

    r1160 r1243  
    8585parameter from being varied. Note that all parameters in a constraint relationship
    8686must specified as varied (appear in varyList) or none can be varied. This is
    87 checked in GenerateConstraints (as well as for generated relationships in SetVaryFlags).
     87checked in GenerateConstraints. Likewise, if all parameters in a constraint are
     88not referenced in a refinement, the constraint is ignored, but if some parameters
     89in a constraint group are not referenced in a refinement, but others are this
     90constitutes and error.
    8891
    8992* When a new variable is created, the variable is assigned the name associated
     
    508511    return errmsg,warnmsg
    509512
    510 def GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList):
     513def GenerateConstraints(groups,parmlist,varyList,constrDict,fixedList,parmDict=None):
    511514    '''Takes a list of relationship entries comprising a group of
    512515    constraints and builds the relationship lists and their inverse
     
    545548    # process equivalences: make a list of dependent and independent vars
    546549    #    and check for repeated uses (repetition of a parameter as an
    547     #    independent var is OK)
     550    #    independent var is OK [A=B; A=C], but chaining: [A=B; B=C] is not good)
    548551    indepVarList = []
    549552    depVarList = []
    550553    multdepVarList = []
    551     for varlist,mapvars,multarr,invmultarr in zip(
     554    for varlist,mapvars,multarr,invmultarr in zip(       # process equivalences
    552555        dependentParmList,indParmList,arrayList,invarrayList):
    553         if multarr is None: # do only if an equivalence
     556        if multarr is None: # true only if an equivalence
    554557            zeromult = False
    555558            for mv in mapvars:
     
    563566                    notvaried += mv
    564567                if mv not in indepVarList: indepVarList.append(mv)
     568                if parmDict is not None and mv not in parmDict:
     569                    msg += "\nCannot equivalence to variable "+str(mv)+". Not defined in this refinement"
     570                    continue
    565571                for v,m in zip(varlist,invmultarr):
     572                    if parmDict is not None and v not in parmDict:
     573                        print "Dropping equivalence for variable "+str(v)+". Not defined in this refinement"
     574                        continue
    566575                    if m == 0: zeromult = True
    567576                    if v in varyList:
     
    617626            varied = 0
    618627            notvaried = ''
     628            unused = 0
     629            notused = ''
    619630            for var in constrDict[rel]:
    620631                if var.startswith('_'): continue
     632                if parmDict is not None and var not in parmDict:
     633                    unused += 1
     634                    if notvaried: notused += ', '
     635                    notused += var
    621636                if var in varyList:
    622637                    varied += 1
     
    627642                    msg += '\nError: parameter '+var+" is Fixed and used in a constraint:\n\t"
    628643                    msg += _FormatConstraint(constrDict[rel],fixedList[rel])+"\n"
     644            #if unused > 0:# and unused != len(VarKeys(constrDict[rel])):
     645            if unused > 0 and unused != len(VarKeys(constrDict[rel])):
     646                msg += "\nSome (but not all) variables in constraint are not defined:\n\t"
     647                msg += _FormatConstraint(constrDict[rel],fixedList[rel])
     648                msg += '\nNot used: ' + notused + '\n'
    629649            if varied > 0 and varied != len(VarKeys(constrDict[rel])):
    630650                msg += "\nNot all variables refined in constraint:\n\t"
     
    651671        for rel in group:
    652672            varied = 0
     673            unused = 0
    653674            for var in VarKeys(constrDict[rel]):
     675                if parmDict is not None and var not in parmDict:
     676                    unused += 1                   
    654677                if var not in varsList: varsList.append(var)
    655678                if var in varyList: varied += 1
     
    659682            msg = 'too many relationships'
    660683            break
     684        # Since we checked before, if any variables are unused, then all must be.
     685        # If so, this set of relationships can be ignored
     686        if unused:
     687            if debug: print('Constraint ignored (all variables undefined)')
     688            if debug: print ('    '+_FormatConstraint(constrDict[rel],fixedList[rel]))
     689            continue
    661690        # fill in additional degrees of freedom
    662691        try:
     
    704733                unused = False
    705734                mapvar.append(fixedval)
    706         if unused: continue # skip over constraints that do not have a fixed value or a refined variable
     735        if unused: # skip over constraints that don't matter (w/o fixed value or any refined variables)
     736            if debug: print('Constraint ignored (all variables unrefined)')
     737            if debug: print ('   '+_FormatConstraint(constrDict[rel],fixedList[rel]))
     738            continue
    707739        dependentParmList.append(varlist)
    708740        arrayList.append(constrArr)
Note: See TracChangeset for help on using the changeset viewer.