def test_createNewDataDoc(self):
     xmlDoc, root = stgxml.createNewStgDataDoc()
     stgxml.writeParam(root, "testParam", 45)
     stgxml.writeStgDataDocToFile(xmlDoc, "output/testCreate.xml")
     xmlDocRead = etree.parse("output/testCreate.xml")
     rootRead = xmlDocRead.getroot()
     testParamNode = stgxml.getParamNode(rootRead, "testParam")
Exemplo n.º 2
0
 def test_createNewDataDoc(self):
     xmlDoc, root = stgxml.createNewStgDataDoc()
     stgxml.writeParam(root, "testParam", 45)
     stgxml.writeStgDataDocToFile(xmlDoc, "output/testCreate.xml")
     xmlDocRead = etree.parse("output/testCreate.xml")
     rootRead = xmlDocRead.getroot()
     testParamNode = stgxml.getParamNode(rootRead, "testParam")
Exemplo n.º 3
0
 def writeStgDataXML(self, xmlNode):
     '''Writes the parameters of this class as parameters in a StGermain
      XML file'''
     for paramName, stgParam in self.stgParamInfos.iteritems():
         val = self.getParam(paramName)
         if val is not None:
             stgxml.writeParam(xmlNode, stgParam.stgName, val,\
                 mt='replace')
Exemplo n.º 4
0
 def writeStgDataXML(self, xmlNode):
     '''Writes the parameters of this class as parameters in a StGermain
      XML file'''
     for paramName, stgParam in self.stgParamInfos.iteritems():
         val = self.getParam(paramName)
         if val is not None:
             stgxml.writeParam(xmlNode, stgParam.stgName, val,\
                 mt='replace')
Exemplo n.º 5
0
    def analysisXMLGen(self, filename=None):
        """Generates an XML file, in StGermainData XML format, to over-ride
        necessary parameters of the model as specified on this ModelRun
        instance. Returns the name of the just-written XML file.

        Overrides can have the following main sources:

        * Over-ridden simulation parameters that have been specified
          as members of the ModelRun itself, such as cpReadPath, and cpFields;
        * Over-ridden simulation parameters on this ModelRun's SimParams
          attribute (if it exists);  
        * Requested analysis operations that've been added to the ModelRun,
          as specified in the self.analysisOps member list.

        .. note::
           Remember that as well as those overrides written to this XML,
           the user can over-ride particular parameters in the ModelRun via the
           command line by setting the self.paramOverrides member dictionary.
        """
        xmlDoc, root = stgxml.createNewStgDataDoc()
        # Write key entries:
        stgxml.writeParam(root, 'outputPath', self.outputPath, mt='replace')
        if self.cpReadPath:
            stgxml.writeParam(root,
                              'checkpointReadPath',
                              self.cpReadPath,
                              mt='replace')
        if self.simParams:
            self.simParams.writeStgDataXML(root)
        for analysisName, analysisOp in self.analysisOps.iteritems():
            analysisOp.writeStgDataXML(root)

        # This is so we can checkpoint fields list: defined in FieldVariable.c
        if len(self.cpFields):
            # Have used the Merge mergeType, because the solvers for the
            # models in use may have a minimum set of fields to checkpoint.
            stgxml.writeParamList(root,
                                  'FieldVariablesToCheckpoint',
                                  self.cpFields,
                                  mt='merge')

        if filename is None:
            #By default, store this file in the output path.
            absOutputPath = os.path.join(self.basePath, self.outputPath)
            if not os.path.exists(absOutputPath):
                os.makedirs(absOutputPath)
            filename = os.path.join(absOutputPath,
                                    CREDO_ANALYSIS_RECORD_FILENAME)
        stgxml.writeStgDataDocToFile(xmlDoc, filename)
        self.analysisXML = filename
        return filename
Exemplo n.º 6
0
    def analysisXMLGen(self, filename=None):
        """Generates an XML file, in StGermainData XML format, to over-ride
        necessary parameters of the model as specified on this ModelRun
        instance. Returns the name of the just-written XML file.

        Overrides can have the following main sources:

        * Over-ridden simulation parameters that have been specified
          as members of the ModelRun itself, such as cpReadPath, and cpFields;
        * Over-ridden simulation parameters on this ModelRun's SimParams
          attribute (if it exists);  
        * Requested analysis operations that've been added to the ModelRun,
          as specified in the self.analysisOps member list.

        .. note::
           Remember that as well as those overrides written to this XML,
           the user can over-ride particular parameters in the ModelRun via the
           command line by setting the self.paramOverrides member dictionary.
        """ 
        xmlDoc, root = stgxml.createNewStgDataDoc()
        # Write key entries:
        stgxml.writeParam(root, 'outputPath', self.outputPath, mt='replace')
        if self.cpReadPath:
            stgxml.writeParam(root, 'checkpointReadPath', self.cpReadPath,
                mt='replace')
        if self.simParams:
            self.simParams.writeStgDataXML(root)
        for analysisName, analysisOp in self.analysisOps.iteritems():
            analysisOp.writeStgDataXML(root)

        # This is so we can checkpoint fields list: defined in FieldVariable.c
        if len(self.cpFields):
            # Have used the Merge mergeType, because the solvers for the
            # models in use may have a minimum set of fields to checkpoint.
            stgxml.writeParamList(root, 'FieldVariablesToCheckpoint',
                self.cpFields, mt='merge')

        if filename is None:
            #By default, store this file in the output path.
            absOutputPath = os.path.join(self.basePath, self.outputPath)
            if not os.path.exists(absOutputPath):
                os.makedirs(absOutputPath)
            filename = os.path.join(absOutputPath,
                CREDO_ANALYSIS_RECORD_FILENAME)
        stgxml.writeStgDataDocToFile(xmlDoc, filename)
        self.analysisXML = filename
        return filename
Exemplo n.º 7
0
    def writeStgDataXML(self, rootNode):
        '''Writes the necessary StGermain XML to enable these specified
         fields to be compared.'''

        # If there are no fields to test, no need to write StGermain XML
        if len(self.fields) == 0: return
        compElt = stgxml.writeMergeComponentStruct(rootNode)

        if self.fromXML:
            fieldTestElt = stgxml.writeComponent(compElt,
                                                 self.stgXMLCompName,
                                                 self.stgXMLCompType,
                                                 mt="merge")
            stgxml.writeParam(fieldTestElt,
                              'appendToAnalysisFile',
                              'True',
                              mt="replace")
        else:
            for field in self.fields:
                analyticFieldElt = stgxml.writeComponent(
                    compElt, 'Analytic' + field, self.stgXMLAnalyticFieldType)
                for param in self.stgXMLAnalyticFieldParams:
                    stgxml.writeParam(
                        analyticFieldElt, param,
                        self.stgXMLAnalyticFieldMappings[field][param])

                analyticFieldMagElt = stgxml.writeComponent(
                    compElt, 'Analytic' + field + '-Mag', 'OperatorFeVariable')
                for param in self.stgXMLAnalyticFieldMagParams:
                    stgxml.writeParam(
                        analyticFieldMagElt, param,
                        self.stgXMLAnalyticFieldMagMappings[field][param])

                errorFieldElt = stgxml.writeComponent(
                    compElt, 'Error' + field, self.stgXMLErrorFieldType)
                for param in self.stgXMLErrorFieldParams:
                    stgxml.writeParam(
                        errorFieldElt, param,
                        self.stgXMLErrorFieldMappings[field][param])

                errorFieldMagElt = stgxml.writeComponent(
                    compElt, 'Error' + field + '-Mag', 'OperatorFeVariable')
                for param in self.stgXMLErrorFieldMagMappings[field]:
                    stgxml.writeParam(
                        errorFieldMagElt, param,
                        self.stgXMLErrorFieldMagMappings[field][param])

            fieldTestElt = stgxml.writeComponent(compElt, self.stgXMLCompName,
                                                 self.stgXMLCompType)

            if self.useReference or self.useHighResReference:
                stgxml.writeParamSet(
                    fieldTestElt, {
                        'referenceSolutionFilePath':
                        self.referencePath,
                        'useReferenceSolutionFromFile':
                        self.useReference,
                        'useHighResReferenceSolutionFromFile':
                        self.useHighResReference
                    })
                stgxml.writeParamList(fieldTestElt, self.stgXMLSpecRList,
                                      list(self.fields.keys()))

            # Create main struct list for the "FieldMappings
            fieldMappingElt = stgxml.writeStructList(fieldTestElt,
                                                     self.stgXMLSpecFList)

            # For each field, create the actual field mapping
            for field in self.fields:
                fieldMappingChildElt = stgxml.writeStruct(fieldMappingElt)
                stgxml.writeParamSet(
                    fieldMappingChildElt, {
                        'NumericField': field,
                        'AnalyticField': 'Analytic' + field,
                        'AnalyticMagnitudeField': 'Analytic' + field + '-Mag',
                        'ErrorField': 'Error' + field,
                        'ErrorMagnitudeField': 'Error' + field + '-Mag'
                    })

            stgxml.writeParamSet(
                fieldTestElt, {
                    'IntegrationSwarm': 'gaussSwarm',
                    'ConstantMesh': 'constantMesh',
                    'testTimestep': self.testTimestep,
                    'ElementMesh': 'linearMesh',
                    'normaliseByAnalyticSolution': 'True',
                    'context': 'context',
                    'appendToAnalysisFile': 'True'
                })
Exemplo n.º 8
0
    def writeStgDataXML(self, rootNode):
        '''Writes the necessary StGermain XML to enable these specified
         fields to be compared.'''

        # If there are no fields to test, no need to write StGermain XML
        if len(self.fields) == 0: return

        if self.fromXML:
            # In this case, just make sure the printing of comparison info
            #  enabled.
            pluginDataElt = etree.SubElement(rootNode,
                                             stgxml.STG_STRUCT_TAG,
                                             name=self.stgXMLSpecName,
                                             mergeType="merge")
            stgxml.writeParam(pluginDataElt,
                              'appendToAnalysisFile',
                              'True',
                              mt="replace")
        else:
            # Append the component to component list
            compElt = stgxml.writeMergeComponent(rootNode, self.stgXMLCompName,
                                                 self.stgXMLCompType)
            # Create the plugin data
            pluginDataElt = etree.SubElement(rootNode,
                                             stgxml.STG_STRUCT_TAG,
                                             name=self.stgXMLSpecName,
                                             mergeType="replace")
            xmlFieldTestsList = self.fields.keys()
            # This is necessary due to format of this list in FieldTest plugin:
            # <FieldName> <# of analytic func> - both as straight params
            ii = 0
            for index in range(1, len(self.fields) * 2, 2):
                xmlFieldTestsList.insert(index, str(ii))
                ii += 1

            if self.useReference or self.useHighResReference:
                stgxml.writeParamSet(
                    pluginDataElt, {
                        'referenceSolutionFilePath':
                        self.referencePath,
                        'useReferenceSolutionFromFile':
                        self.useReference,
                        'useHighResReferenceSolutionFromFile':
                        self.useHighResReference
                    })
                stgxml.writeParamList(pluginDataElt, self.stgXMLSpecRList,
                                      self.fields.keys())

            # Current plugin seems to require using a numeric fields list
            # For both analytic and ref solns.
            stgxml.writeParamList(pluginDataElt, self.stgXMLSpecFList,
                                  xmlFieldTestsList)

            stgxml.writeParamSet(
                pluginDataElt, {
                    'IntegrationSwarm': 'gaussSwarm',
                    'ConstantMesh': 'constantMesh',
                    'testTimestep': self.testTimestep,
                    'ElementMesh': 'linearMesh',
                    'normaliseByAnalyticSolution': 'True',
                    'context': 'context',
                    'appendToAnalysisFile': 'True'
                })
Exemplo n.º 9
0
    def writeStgDataXML(self, rootNode):
        '''Writes the necessary StGermain XML to enable these specified
         fields to be compared.'''

        # If there are no fields to test, no need to write StGermain XML
        if len(self.fields) == 0: return
        compElt = stgxml.writeMergeComponentStruct(rootNode)

        if self.fromXML:
            fieldTestElt = stgxml.writeComponent(compElt, self.stgXMLCompName,
                self.stgXMLCompType, mt="merge")
            stgxml.writeParam(fieldTestElt, 'appendToAnalysisFile', 'True',
                mt="replace")
        else:
            for field in self.fields:
                analyticFieldElt = stgxml.writeComponent(compElt, 'Analytic'+field,
                    self.stgXMLAnalyticFieldType)
                for param in self.stgXMLAnalyticFieldParams:
                    stgxml.writeParam(analyticFieldElt, param, self.stgXMLAnalyticFieldMappings[field][param]) 

                analyticFieldMagElt = stgxml.writeComponent(compElt, 'Analytic'+field+'-Mag',
                    'OperatorFeVariable')
                for param in self.stgXMLAnalyticFieldMagParams:
                    stgxml.writeParam(analyticFieldMagElt, param, self.stgXMLAnalyticFieldMagMappings[field][param])

                errorFieldElt = stgxml.writeComponent(compElt, 'Error'+field,
                    self.stgXMLErrorFieldType)
                for param in self.stgXMLErrorFieldParams:
                    stgxml.writeParam(errorFieldElt, param, self.stgXMLErrorFieldMappings[field][param])

                errorFieldMagElt = stgxml.writeComponent(compElt, 'Error'+field+'-Mag',
                    'OperatorFeVariable')
                for param in self.stgXMLErrorFieldMagMappings[field]:
                    stgxml.writeParam(errorFieldMagElt, param, self.stgXMLErrorFieldMagMappings[field][param])

            fieldTestElt = stgxml.writeComponent(compElt, self.stgXMLCompName,
                self.stgXMLCompType)

            if self.useReference or self.useHighResReference:
                stgxml.writeParamSet(fieldTestElt, {
                    'referenceSolutionFilePath':self.referencePath,
                    'useReferenceSolutionFromFile':self.useReference,
                    'useHighResReferenceSolutionFromFile':self.useHighResReference })
                stgxml.writeParamList(fieldTestElt, self.stgXMLSpecRList,
                    self.fields.keys())
        
            # Create main struct list for the "FieldMappings
            fieldMappingElt = stgxml.writeStructList(fieldTestElt, self.stgXMLSpecFList)

            # For each field, create the actual field mapping
            for field in self.fields:
                fieldMappingChildElt = stgxml.writeStruct(fieldMappingElt)
                stgxml.writeParamSet(fieldMappingChildElt, {
                    'NumericField':field,
                    'AnalyticField':'Analytic'+field,
                    'AnalyticMagnitudeField':'Analytic'+field+'-Mag',
                    'ErrorField':'Error'+field,
                    'ErrorMagnitudeField':'Error'+field+'-Mag'})

            stgxml.writeParamSet(fieldTestElt, {
                'IntegrationSwarm':'gaussSwarm',
                'ConstantMesh':'constantMesh',
                'testTimestep':self.testTimestep,
                'ElementMesh':'linearMesh',
                'normaliseByAnalyticSolution':'True',
                'context':'context',
                'appendToAnalysisFile':'True'})