Example #1
0
 def test_51_execution(self):
     print "\n(5.1) Test execution.\n  ",
     
     capExplicit = "0"
     radEntries = None
     radCoeffRegis = ""
     radCoeffTd = ""
     try:
         self.article.execute()
         
         ## Check mass calculation
         parser = XmlParser()
         data = parser.loadFile(tNodePath % tNetwork)
         ## Open it for reading and save its xml data.
         entries = parser.getElements(data, "node")
 
         ## Loop through each source entry, totaling the mass.
         massSum = 0;
         for entry in entries:                
             ## Create and initialize XmlEntryAnalyzer object.
             mass = parser.getChildText(entry, "mass")
             massSum = massSum + float(mass)
             
             ## Store capacitance of a specific node in question.
             if "GOOD_EXPLICIT_12" == parser.getChildText(entry, "name"):
                 capExplicit = parser.getChildText(entry, "capacitance") 
         
         ## Read radiation data for testing.    
         radData = parser.loadFile(tRadPath % tNetwork)
         radEntries = parser.getElements(radData, "radiation")
         ## Check radiation coefficients.  
         radCoeffTd = parser.getChildText(radEntries[0], "coefficient")
         radCoeffRegis = parser.getChildText(radEntries[1], "coefficient")
                     
     except (Exception), e:
         print e
         self.fail("Uncaught exception during execute().")
Example #2
0
class SymbolLoader():
    ## @brief:
    ## Constructs the SymbolLoader and creates a XmlParser object.
    def __init__(self):
        ## An XmlParser() object for getting data from xml elements.
        self.mParser = XmlParser()

        ## Stores name of current file being parsed.
        self.mCurrentFile = "[mCurrentFile not set]"

    #===============================================================================================
    ## @brief:
    ## Main public function. Creates a dictionary based on symbols defined in the xml file.
    ## @param[in]: symFiles   name of xml-file containing symbols data
    ## @return:    a dictionary with key = symbol, value = resulting numerical value of symbol
    def execute(self, symFiles):

        masterNameList = []
        masterExpList = []

        for file in symFiles:
            ## Read each file.
            [nameList, expList, desList,
             groupList] = self.loadSymbolsFrom(file)

            ## Update master lists
            masterNameList = masterNameList + nameList
            masterExpList = masterExpList + expList

        return self.defineSymbols(masterNameList, masterExpList, locals())

    # ----------------------------------------------------------------------------------------------
    ## @brief:
    ## Private method. Defines a symbol list given an expression list.
    ## @param[in]: symFile       name of xml-file containing symbols data
    ## @param[in]: areDesAndGroupIncluded    a boolean to specify if the group/des tags need to be
    ##                                       read as well (like in the generate_TD_symbols case)
    ## @return:    nameList      list of text under <name> tag in symbols xml
    ## @return:    expList       list of text under <exp> tag in symbols xml
    def loadSymbolsFrom(self, symFile):

        ## Set current file for error reporting purposes.
        self.mCurrentFile = symFile

        ## Try to open the symbol file. Open it for reading and save its xml data.
        symbols = self.mParser.loadFile(symFile)

        ## Initialize lists.
        nameList = []
        expList = []
        desList = []
        groupList = []

        ## Loop over the symbols.
        for symbol in symbols:
            ## Initialize name for error reporting.
            name = "[error reading name]"

            ## Get data.
            try:
                name = self.mParser.getChildText(symbol, "name")
                expElem = self.mParser.getElements(symbol, "exp", True,
                                                   name)[0]
                expText = self.mParser.getText(expElem, name)

                if name in nameList:
                    ## If the symbol is a mass, it can overwrite a previous instance.
                    if 'mass_' == name[:5]:
                        expList[nameList.index(name)] = expText
                        continue
                    else:
                        raise ThermError("Symbol previously defined (%s)." %
                                         name)

                ## Special instructions for capacitance symbols, for mass accounting purposes.
                if 'cap_' == name[:4]:
                    try:
                        ## Read the given mass from the symbols element.
                        specHeatText = self.mParser.getChildText(
                            expElem, "specHeat", name)
                        massText = self.mParser.getChildText(
                            expElem, "mass",
                            name).replace('%Cp', specHeatText)
                        expText = "(%s) * (%s)" % (massText, specHeatText)

                    except (TagNotFound), e:
                        ## Store a "-1" as an indication that no mass data was provided.
                        massText = "-1"

                    ## Append a symbol for the mass.
                    nameList.append(name.replace("cap_", "mass_"))
                    expList.append(massText)

                ## Append name and expression to list.
                nameList.append(name)
                expList.append(expText)

            except (TagNotFound, ThermError), e:
                print e,
                print "Symbol will be ignored (%s)." % name
                continue
Example #3
0
class IcdBuilder:
    ## @brief:
    ## Default constructs the object with default, uninitialized members.
    def __init__(self):
        uninitialized = "[not initialized]"

        ## IcdSettings() object contains specifics used in Thermal Aspect ICD printing.
        ## For example, the IcdBuilder needs to know that:
        ## - On the registry, a capacitance link uses the XML tag <temperature> to describe
        ##    an ICD "READ" exchange.
        ## - The unit for temperature is "K".
        ## - The PTCS member that contains the temperature is
        ##    "therm.mCapacitanceLinks[%s].mTemperature".
        self.mIcdSettings = uninitialized

        ## Name of network using this IcdBuilder() class.
        self.mNetwork = uninitialized

        ## List of Icd Exchange() objects. This list is appended with all the WRITE/READ groups
        ## that are described in the thermal registry files. After all data has been read,
        ## the IcdBuilder loops through each and prints them to the PTCS.txt icd-file.
        self.mListOfExchanges = []

        ## An XmlParser() object for setting data in xml elements.
        self.mParser = XmlParser()

    #===============================================================================================
    ## @brief:
    ## Public function. Initializes the class with data common to all icd actions.
    ## @param[in]: network      string of abbreviated network name, as found in Thermal file names
    ##                                                ex: 'trussMid' -> ThermNodes_trussMid.xml
    ## @param[in]: icdSettings  IcdSettings() obj containing specifics used in Thermal ICD printing
    def initialize(self, network, icdSettings):

        ## Network this IcdBuilder was made for.
        self.mNetwork = network

        ## ICD settings specific to this network
        self.mIcdSettings = icdSettings

    #===============================================================================================
    ## @brief:
    ## Public function, called by IndivNetworkBuilder. This function reads the data in a
    ## ThermRegistryEntryAnalyzer object and from it, creates and initializes IcdExchange objects.
    ## @param[in]: entryObj      An initialized ThermRegistryEntryAnalyzer object
    ## @param[in]: linkType      type of Gunns object, either "potential" or "capacitance"
    ## @param[in]: enumIndex     the number in the PTCS enumeration (its array index in the
    ##                               Gunns thermal link array)
    def extractAndProcessIcd(self, entryObj, linkType, enumIndex):

        ## Get link type, id, and description.
        comments = entryObj.mDescription
        identifier = entryObj.mName
        if "potential" == linkType:
            identifier = "pot_" + identifier

        ## Get icd data contained in entryObj.
        linkElements = self.mParser.getElements(entryObj.mEntry, linkType)
        if len(linkElements) != 1:
            return

        ## Process Icd.
        self.processIcd(linkElements[0], identifier, linkType, enumIndex,
                        comments)

    #===============================================================================================
    ## @brief:
    ## Public function, called by IndivNetworkBuilder. This function reads the data in a
    ## ThermRegistryEntryAnalyzer object and from it, creates and initializes IcdExchange objects.
    ## @param[in]: element       xml-element containing an icd job, whose tag depends on linkType
    ## @param[in]: identifier    string that identifies the particular link, used
    ##                               in the PTCS enumeration
    ## @param[in]: linkType      type of Gunns object, either "potential" or "capacitance"
    ## @param[in]: enumIndex     the number in the PTCS enumeration (its array index in the
    ##                               Gunns thermal link array)
    ## @param[in]: comments      comments describing icd exchange
    def processIcd(self, element, identifier, linkType, enumIndex, comments):

        ## Declare generic data.
        pui = "xxxx"
        subsys = "ptcs"
        type = "double"

        try:
            ## Find the icd category, the tag name under which the icd data is contained
            ## (<temperature>, <heatFlux>, <viewScalar>, etc).
            categoryThatPtcsReads = self.mIcdSettings.mCategoryThatPtcsReads[
                linkType]
            categoryThatPtcsWrites = self.mIcdSettings.mCategoryThatPtcsWrites[
                linkType]

            ## Get icd data.
            otherSubsWrites = self.mParser.getElements(element,
                                                       categoryThatPtcsReads)
            otherSubsReads = self.mParser.getElements(element,
                                                      categoryThatPtcsWrites)

            #.............................
            ## PTCS Writing
            if len(otherSubsReads) > 0:
                ## Create an IcdExchange object and append it to mListOfExchanges.
                self.createIcdExchange(identifier, linkType, enumIndex, categoryThatPtcsWrites, "",\
                                       None, otherSubsReads, pui, subsys, type, comments)
            #.............................
            ## PTCS Reading
            for i in range(0, len(otherSubsWrites)):
                ## Create an IcdExchange object and append it to mListOfExchanges.
                self.createIcdExchange(identifier, linkType, enumIndex, categoryThatPtcsReads, str(i),\
                                       otherSubsWrites[i], None, pui, subsys, type, comments)

        except (ThermError, TagNotFound), e:
            print e,
            print "%s job will not be written on ICD." % identifier