doc_mVariable

Documentation

  1. Brief Explanation of Variable
    1. It is generated upon reading XML script files.

    2. This class instances are included in Script::BODY 2. Other comments:

    This class will hold definitions for variables. During initialization, they only contain strings for their function definitions (self.sFunction). Later “self. fSetfFunction” will be called and Variable::_fFunction will contain a real function definition. Variable class can be called, and have caches to store any calculated values.

    I think calling a user-defined class may not be efficient in terms of computation time. We may need to think of a new way to store caches and compute quickly.

  2. List of Member Variables and Methods
    1. How to Create a class instance

      >>> s=Script(sFilePath=".\\script\\Script2.txt")
      >>> v=s.BODY["aa"] 'take the Variable named "aa" as an example
      
    2. Functions
      1. __init__(self,sName=”“,sFunction=”“,sModule=”“,sProduct=”“,sAccumulation=”“)

        >>> v.__dict__
        {'sName': 'aa',
         'sFunction': 'def aa(t):\n\t\t\t\treturn t',
         'sModule': 'oneguy',
         '_fFunction': None,
         'lsFuncArgs': [],
         '_dCache': {},
         'lProduct': ['PROD1'],
         'lAccumulation': ['ACC1'],
         'bRerunEveryTime': False}
        >>> p=Process() #another example showing the situation after running the model
        >>> p.fRunModel()
        >>> vTemp=p.mVarNameSpace.aa
        >>> vTemp.__dict__
        {'sName': 'aa',
         'sFunction': 'def aa(t):\n\t\t\t\treturn t',
         'sModule': 'oneguy',
         '_fFunction': <function var_name_space.aa(t)>,
         'lsFuncArgs': ['t'],
         '_dCache': {(0,): 0,
          (1,): 1,
          (2,): 2,
          (3,): 3,
          ...lots of outputs
          (97,): 97,
          (98,): 98,
          (99,): 99},
         'lProduct': ['PROD1'],
         'lAccumulation': ['ACC1'],
         'bRerunEveryTime': False}
        
      2. fSetfFunction(self,mModule_fFunc,bReInitialize=False)
        >>> import imp
        >>> module = imp.new_module("haha")
        >>> print(v._fFunction)
        None
        >>> v.fSetfFunction(module,False)
        >>> v._fFunction
        <function haha.aa(t)>
        >>> v._fFunction(23)
        23
        
      3. fReInitialize(self)

        TODO: explain this later

      … and other functions

    3. Variables

  3. Related Document

    Sample Code for Script2.txt