Esempio n. 1
0
    def initialize(self, id, atLeastOneActiveEntry, action, icdElement):

        ## Create an XmlParser.
        parser = XmlParser()

        ## Comment out if not ready.
        if 'true' != icdElement.get(
                "isReadyForIcd") or False == atLeastOneActiveEntry:
            self.mCommentChar = "#"

        ## Initialize job data.
        self.mAction = action
        self.mRate = parser.getChildText(icdElement, "rate", id)
        self.mSimObject = parser.getChildText(icdElement, "simObject", id)
        self.mSimVarName = parser.getChildText(icdElement, "simVarName",
                                               id).replace("%s", id)
Esempio n. 2
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().")
Esempio n. 3
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
Esempio n. 4
0
class XmlEntryAnalyzer:
    ## @brief:
    ## Default constructs the object with default, uninitialized members.
    def __init__(self):
        uninitialized = "[not initialized]"

        ## An XmlParser() object for getting data from xml elements.
        self.mParser = XmlParser()
        ## An xml entry from a registry file. This object is only associated with a single entry.
        self.mEntry = uninitialized
        ## A dictionary with the definitions of symbols used in the registries
        self.mSymMap = uninitialized
        ## Name of the Thermal Gunns link, as read from the registry entry.
        self.mName = uninitialized
        ## The link's number in the network's array. Initialized to an invalid value of -1.
        self.mEnumIndex = -1
        ## The link's description
        self.mDescription = uninitialized
        ## Initialization flag.
        self.mIsInitialized = False

    #===============================================================================================
    ## @brief:
    ## Constructs the class using two arguments.
    ## @param[in]: entry    ElementTree xml-element of data from Thermal, Htr, or Panel registry
    ## @param[in]: symMap   dictionary with the definitions of symbols used in the registries
    def initialize(self, entry, symMap={}):

        ## An xml entry from a registry file. This object is only associated with a single entry.
        self.mEntry = entry
        ## A dictionary with the definitions of symbols used in the registries
        self.mSymMap = symMap
        ## Name of the Thermal Gunns node/link, as read from the registry entry.
        self.mName = entry.get("name")

        ## The node entry must have a name. Raise exception if otherwise.
        if None == self.mName:
            raise ThermError("Must have a name attribute.")

        ## The link's description as read from registry entry.
        try:
            self.mDescription = self.mParser.getChildText(entry, "des")
        except TagNotFound:
            self.mDescription = ""

    #===============================================================================================
    ## @brief:
    ## Evaluate an expression value based on symbols defined in mSymMap.
    ## @param[in]: expr    a mathematical expression that may contain symbols defined in mSymMap
    ## @param[in]: info    optional string used in error reporting
    ## @return:    the evaluated expression in numerical form
    def getValidatedValue(self, expr, info=''):
        try:
            value = eval(expr, globals(), self.mSymMap)
        except (NameError, SyntaxError), e:
            print e,
            raise ThermError("Invalid value: %s (%s)." % (expr, info))

        ## Do not accept negative values.
        if value < 0:
            raise ThermError("Cannot accept a negative. %s = %f" %
                             (expr, value))

        return value