Пример #1
0
def runElementCycle(initParam,elements=['C','Ca','Mg','Si','S','Ti','Ni0','Fe0'],samples=10,scaling='lin'):
    #initParam.autoRelAbund='O'
    intervals,initParam=initElementCycle(initParam,elements,samples,scaling)
    #print "Dumping initial run in initElemCycle.pkl"
    #pickle.dump(elementMG,file('initElemCycle.pkl','w'))
    bounds=initialize.getElementsBounds(initParam.comp)
    intervalHistory={'Si':[],'S':[],'Mg':[],'C':[]}
    i=1
    while True:
        converged=[]
        for element in ['Si','S','Mg','C']:
            if scaling=='log':
                elementRange=np.logspace(*np.log10(intervals[element]),**dict(num=samples))
            elif scaling=='lin':
                elementRange=np.linspace(*intervals[element],**dict(num=samples))
            
            elementMG=launcherSteps.launchElementCycle({element:elementRange},initParam=initParam)
            plot.plotElementModelGrid(element,elementMG[0],suffix=str(i))    
            intervals[element],finished=dalekSteps.getNextElementParams(element,elementMG[0],initParam,bounds[element])
            converged.append(finished)
            intervalHistory[element].append(intervals[element])
            print "New Interval for %s: %s "%(element,intervals[element])
            initParam[element]=np.mean(intervals[element])
            bounds=initialize.getElementsBounds(initParam.comp)
            intervals=dalekSteps.checkElementBounds(intervals,bounds)
        print "Convergence status %s"%converged
        if all(converged): break
        print "Looking for stop.txt in %s"%os.getcwd()
        if os.path.exists('stop.txt'): break
        i+=1
    return intervalHistory
Пример #2
0
def initElementCycle(initParam,elements,samples,scaling):
    bounds=initialize.getElementsBounds(initParam.comp)
    divIntervals={'Si':[5e-3,5],
                'S':[1e-3,1],
                'Ca':[0.5e-3,0.5],
                'Mg':[0.5e-3,2],
                'C':[0.5e-3,0.5],
                'Fe0':[1e-3,1]}
    
    intervals=copy.deepcopy(bounds)
    initParam.lockIGE=False
    initParam.lockIGEwNi=False
    initParam.lockIGEwoNi=True
    ranges={}
    #intervalHistory={}
    for element in intervals.keys():
        if scaling=='log':
            ranges[element]=np.logspace(*np.log10(intervals[element]),**dict(num=samples))
            
        elif scaling=='lin':
            ranges[element]=np.linspace(*intervals[element],**dict(num=samples))
        else:
            raise Exception('Unknown scaling option %s. Please use lin or log.'%scaling)
    finished=False
    for element in ['Si','S','Mg','C']:
        if scaling=='log':
            elementRange=np.logspace(*np.log10(intervals[element]),**dict(num=samples))
        elif scaling=='lin':
            elementRange=np.linspace(*intervals[element],**dict(num=samples))
        
        elementMG=launcherSteps.launchElementCycle({element:elementRange},initParam=initParam)
        plot.plotElementModelGrid(element,elementMG[0])    
        newInterval,finished=dalekSteps.getNextElementParams(element,elementMG[0],initParam,bounds[element])
        if not finished: intervals[element]=newInterval
        print "New Interval for %s: %s "%(element,intervals[element])
        initParam[element]=np.mean(intervals[element])
        bounds=initialize.getElementsBounds(initParam.comp)
        intervals=dalekSteps.checkElementBounds(intervals,bounds)
        #pdb.set_trace()
    #allMG=launcherSteps.launchElementCycle(ranges,initParam=initParam)
    #elementMG=dict(zip(ranges.keys(),allMG[:-1]))%debug
    #curParamMG=allMG[-1]
    
    return intervals,initParam