示例#1
0
    def readFromStgXML(self, inputFilesList, basePath):
        '''Read in the list of fields that have already been specified to 
         be tested from a set of StGermain input files. Useful when e.g. 
         working with an Analytic Solution plugin.'''
        self.fromXML = True

        # create a flattened file
        absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(
            inputFilesList, basePath)
        ffile = stgxml.createFlattenedXML(absInputFiles)
        xmlDoc = etree.parse(ffile)
        stgRoot = xmlDoc.getroot()
        # Go and grab necessary info from XML file
        fieldTestDataEl = stgxml.getStructNode(stgRoot, self.stgXMLSpecName)
        fieldTestListEl = stgxml.getListNode(fieldTestDataEl,
                                             self.stgXMLSpecFList)

        fieldTestEls = fieldTestListEl.getchildren()
        # As per the current spec, the field names are followed by an index
        # of analytic solution
        ii = 0
        while ii < len(fieldTestEls):
            fieldName = fieldTestEls[ii].text
            self.fields[fieldName] = FieldComparisonOp(fieldName)
            # Skip the index
            ii += 1
            ii += 1
        # NB: not reading in all the other specifying stuff currently. Possibly
        # would be useful to do this in future.
        os.remove(ffile)
    def regenerateFixture(self, jobRunner):
        """Do a run to create the reference solution to use."""
        resParams = ("elementResI", "elementResJ", "elementResK")
        ffile = stgxml.createFlattenedXML(self.inputFiles)
        xmlDoc = etree.parse(ffile)
        stgRoot = xmlDoc.getroot()
        origRes = [0] * 3
        for ii, resParam in enumerate(resParams):
            origRes[ii] = stgxml.getParamValue(stgRoot, resParam, int)
        os.remove(ffile)
        highRes = [int(self.highResRatio * res) for res in origRes]

        print "Running the model to create a high-res reference solution " " after %d steps and with res %g times the original, " " and saving in dir '%s'" % (
            self.runSteps,
            self.highResRatio,
            self.expectedSolnPath,
        )
        mRun = self._createDefaultModelRun(self.testName + "-createReference", self.expectedSolnPath)
        mRun.simParams = SimParams(nsteps=self.runSteps, cpevery=self.runSteps, dumpevery=0)
        for ii, resParam in enumerate(resParams):
            mRun.paramOverrides[resParam] = highRes[ii]
        mRun.cpFields = self.fieldsToTest
        mRun.writeInfoXML()
        mRun.analysisXMLGen()
        result = jobRunner.runModel(mRun)
        # It's conceivable this could be useful, if we store results about
        # e.g. solver solution times etc.
        result.writeRecordXML()
示例#3
0
    def readFromStgXML(self, inputFilesList, basePath):
        '''Read in the list of fields that have already been specified to
         be tested from a set of StGermain input files. Useful when e.g.
         working with an Analytic Solution plugin.'''
        self.fromXML = True

        # create a flattened file
        absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(
            inputFilesList, basePath)
        ffile = stgxml.createFlattenedXML(absInputFiles)
        xmlDoc = etree.parse(ffile)
        stgRoot = xmlDoc.getroot()

        # Go and grab necessary info from XML file
        componentEl = stgxml.getStructNode(stgRoot, self.stgXMLCompListName)
        fieldTestDataEl = stgxml.getStructNode(componentEl,
                                               self.stgXMLCompName)
        fieldTestListEl = stgxml.getListNode(fieldTestDataEl,
                                             self.stgXMLSpecFList)
        fieldTestStructEls = fieldTestListEl.getchildren()
        for fieldStruct in fieldTestStructEls:
            numericField = stgxml.getParamValue(fieldStruct, 'NumericField',
                                                str)
            self.fields[numericField] = FieldComparisonOp(numericField)

        # NB: not reading in all the other specifying stuff currently. Possibly
        # would be useful to do this in future.
        os.remove(ffile)
示例#4
0
    def regenerateFixture(self, jobRunner):
        '''Do a run to create the reference solution to use.'''
        resParams = ("elementResI", "elementResJ", "elementResK")
        ffile = stgxml.createFlattenedXML(self.inputFiles)
        xmlDoc = etree.parse(ffile)
        stgRoot = xmlDoc.getroot()
        origRes = [0] * 3
        for ii, resParam in enumerate(resParams):
            origRes[ii] = stgxml.getParamValue(stgRoot, resParam, int)
        os.remove(ffile)
        highRes = [int(self.highResRatio * res) for res in origRes]

        print "Running the model to create a high-res reference solution "\
            " after %d steps and with res %g times the original, "\
            " and saving in dir '%s'" % \
            (self.runSteps, self.highResRatio, self.expectedSolnPath)
        mRun = self._createDefaultModelRun(self.testName + "-createReference",
                                           self.expectedSolnPath)
        mRun.simParams = SimParams(nsteps=self.runSteps,
                                   cpevery=self.runSteps,
                                   dumpevery=0)
        for ii, resParam in enumerate(resParams):
            mRun.paramOverrides[resParam] = highRes[ii]
        mRun.cpFields = self.fieldsToTest
        mRun.writeInfoXML()
        mRun.analysisXMLGen()
        result = jobRunner.runModel(mRun)
        # It's conceivable this could be useful, if we store results about
        # e.g. solver solution times etc.
        result.writeRecordXML()
    def readFromStgXML(self, inputFilesList, basePath):
        '''Read in the list of fields that have already been specified to 
         be tested from a set of StGermain input files. Useful when e.g. 
         working with an Analytic Solution plugin.'''
        self.fromXML = True

        # create a flattened file
        absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(inputFilesList,
            basePath)
        ffile=stgxml.createFlattenedXML(absInputFiles)
        xmlDoc = etree.parse(ffile)
        stgRoot = xmlDoc.getroot()

        # Go and grab necessary info from XML file
        componentEl = stgxml.getStructNode(stgRoot, self.stgXMLCompListName)
        fieldTestDataEl = stgxml.getStructNode(componentEl, self.stgXMLCompName)
        fieldTestListEl = stgxml.getListNode(fieldTestDataEl, self.stgXMLSpecFList)
        fieldTestStructEls = fieldTestListEl.getchildren()
        for fieldStruct in fieldTestStructEls:
            numericField=stgxml.getParamValue(fieldStruct,'NumericField',str)
            self.fields[numericField]=FieldComparisonOp(numericField)

        # NB: not reading in all the other specifying stuff currently. Possibly
        # would be useful to do this in future.
        os.remove(ffile)
示例#6
0
    def genFlattenedXML(self, cmdLineOverrides=None, flatFilename=None):
        self.analysisXMLGen()
        xmls = self.modelInputFiles + [self.analysisXML]
        overridesStr = getParamOverridesAsStr(self.paramOverrides)
        if cmdLineOverrides != None:
            overridesStr = " ".join([overridesStr, cmdLineOverrides])

        fFilename = stgxml.createFlattenedXML(xmls, overridesStr,
            flatFilename=flatFilename)
        return fFilename
示例#7
0
    def genFlattenedXML(self, cmdLineOverrides=None, flatFilename=None):
        self.analysisXMLGen()
        xmls = self.modelInputFiles + [self.analysisXML]
        overridesStr = getParamOverridesAsStr(self.paramOverrides)
        if cmdLineOverrides != None:
            overridesStr = " ".join([overridesStr, cmdLineOverrides])

        fFilename = stgxml.createFlattenedXML(xmls,
                                              overridesStr,
                                              flatFilename=flatFilename)
        return fFilename
示例#8
0
 def checkStgXMLResultsEnabled(self, inputFilesList, basePath):
     """Checks that the field comparison has the writing of comparison
     info to file enabled (returning Bool)."""
     absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(
         inputFilesList, basePath)
     ffile = stgxml.createFlattenedXML(absInputFiles)
     xmlDoc = etree.parse(ffile)
     stgRoot = xmlDoc.getroot()
     fieldTestDataEl = stgxml.getStructNode(stgRoot, self.stgXMLSpecName)
     appendNode = stgxml.getParamNode(fieldTestDataEl,
                                      "appendToAnalysisFile")
     appendBool = stgxml.strToBool(appendNode.text)
     os.remove(ffile)
     return appendBool
 def checkStgXMLResultsEnabled(self, inputFilesList, basePath):
     """Checks that the field comparison has the writing of comparison
     info to file enabled (returning Bool)."""
     absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(inputFilesList,
         basePath)
     ffile=stgxml.createFlattenedXML(absInputFiles)
     xmlDoc = etree.parse(ffile)
     stgRoot = xmlDoc.getroot()
     fieldTestDataEl = stgxml.getStructNode(stgRoot, self.stgXMLSpecName)
     appendNode = stgxml.getParamNode(fieldTestDataEl,
         "appendToAnalysisFile")
     appendBool = stgxml.strToBool(appendNode.text)
     os.remove(ffile)
     return appendBool
示例#10
0
    def readFromStgXML(self, inputFilesList, basePath, cmdLineOverrides):
        '''Reads all the parameters of this class from a given StGermain 
        set of input files'''
        absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(
            inputFilesList, basePath)
        ffile = stgxml.createFlattenedXML(absInputFiles, cmdLineOverrides)
        xmlDoc = etree.parse(ffile)
        stgRoot = xmlDoc.getroot()
        for param, stgParam in self.stgParamInfos.iteritems():
            # some of these may be none, but is ok since will check below
            val = stgxml.getParamValue(stgRoot, stgParam.stgName,\
                stgParam.pType)
            self.setParam(param, val)

        self.checkValidParams()
        os.remove(ffile)
示例#11
0
    def readFromStgXML(self, inputFilesList, basePath, cmdLineOverrides):
        '''Reads all the parameters of this class from a given StGermain 
        set of input files'''
        absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(
            inputFilesList, basePath)
        ffile=stgxml.createFlattenedXML(absInputFiles, cmdLineOverrides)
        xmlDoc = etree.parse(ffile)
        stgRoot = xmlDoc.getroot()
        for param, stgParam in self.stgParamInfos.iteritems():
            # some of these may be none, but is ok since will check below
            val = stgxml.getParamValue(stgRoot, stgParam.stgName,\
                stgParam.pType)
            self.setParam(param, val)

        self.checkValidParams()
        os.remove(ffile)
def getNumEls(mRun):
    """Calculate the number of elements used by a model run."""
    #TODO: this should be abstracted a service of models perhaps ...
    #res = mRun.getResolution()
    from credo.io import stgxml
    from credo.io import stgpath
    import credo.modelrun as mrun
    from xml.etree import ElementTree as etree
    paramOverridesStr = mrun.getParamOverridesAsStr(mRun.paramOverrides)    
    iFiles = mRun.modelInputFiles
    if mRun.analysisXML is not None: iFiles += [mRun.analysisXML]
    absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(
        iFiles, mRun.basePath)
    ffile = stgxml.createFlattenedXML(absInputFiles, paramOverridesStr)
    xmlDoc = etree.parse(ffile)

    stgRoot = xmlDoc.getroot()
    resX = stgxml.getParamValue(stgRoot, "elementResI", int)
    resY = stgxml.getParamValue(stgRoot, "elementResJ", int)
    resZ = stgxml.getParamValue(stgRoot, "elementResK", int)
    if resZ == 0: resZ = 1  #(Just in case)
    numEls = resX * resY * resZ
    return numEls
示例#13
0
def getNumEls(mRun):
    """Calculate the number of elements used by a model run."""
    #TODO: this should be abstracted a service of models perhaps ...
    #res = mRun.getResolution()
    from credo.io import stgxml
    from credo.io import stgpath
    import credo.modelrun as mrun
    from xml.etree import ElementTree as etree
    paramOverridesStr = mrun.getParamOverridesAsStr(mRun.paramOverrides)
    iFiles = mRun.modelInputFiles
    if mRun.analysisXML is not None: iFiles += [mRun.analysisXML]
    absInputFiles = stgpath.convertLocalXMLFilesToAbsPaths(
        iFiles, mRun.basePath)
    ffile = stgxml.createFlattenedXML(absInputFiles, paramOverridesStr)
    xmlDoc = etree.parse(ffile)

    stgRoot = xmlDoc.getroot()
    resX = stgxml.getParamValue(stgRoot, "elementResI", int)
    resY = stgxml.getParamValue(stgRoot, "elementResJ", int)
    resZ = stgxml.getParamValue(stgRoot, "elementResK", int)
    if resZ == 0: resZ = 1  #(Just in case)
    numEls = resX * resY * resZ
    return numEls