def _gendecls(self):
     self._writeline(indent1 + '#Assumes 0.0 initial value for inputs')
     for k, v in self.components.iteritems():
         for name, nodes in v.iteritems():
             #MDPL - is there any way to get units?
             if k == 'surfaces':
                 for i in ansysinfo.surfaceinputtypes.iterkeys():
                     self._gendecl(k, i, name)
             elif k == 'keypoints':
                 for i in ansysinfo.keypointinputtypes.iterkeys():
                     self._gendecl(k, i, name)
             elif k == 'nodes':
                 for i in ansysinfo.nodeinputtypes.iterkeys():
                     self._gendecl(k, i, name)
             else:
                 print 'ERROR: AnsysWrapperGenerator for ' + name + \
                       ': unknown component type ' + k + ' - IGNORED'
             for otype, ounits in ansysinfo.outputtypes.iteritems():
                 n = ansysinfo._make_name(name, otype)
                 #import pdb; pdb.set_trace()
                 self._writeline(indent1 + n +
                                 ' = List(iotype = "out", desc = "' + otype +
                                 ' on nodes of ' + name + '")')
                 for ctype in ansysinfo.calctypes:
                     s = indent1 + n + '_' + ctype + \
                         ' = Float(0.0, iotype = "out",\n' + \
                         indent2 + 'desc = "' + ctype + ' of ' + otype + \
                         ' on nodes of ' + name + '"'
                     if self.unitsinfo.ok and ounits in self.unitsinfo.info:
                         s = s + ',\n' + indent2 + 'units = "' + \
                             self.unitsinfo.info[ounits] + '"'
                     s = s + ')'
                     self._writeline(s)
 def _gendecl(self, k, i, name):
     s = indent1 + ansysinfo._make_name(name, i) + \
         ' = Float(0.0,' 'iotype = "in",\n' + indent2 + 'desc = " ' + \
         i + ' on ' + k + ' component ' + name + '"'
     if self.unitsinfo.ok and i in self.unitsinfo.info:
         s = s + ',\n' + indent2 + 'units = "' + self.unitsinfo.info[i] + '"'
     s = s + ')'
     self._writeline(s)
 def _gendecl(self, k, i, name, units):
     nm = ansysinfo._make_name(name, i)
     self.input_names.add(nm)
     s = indent1 + nm + ' = Float(0.0,' 'iotype = "in",\n' + indent2 + 'desc = " ' + \
         i + ' on ' + k + ' component ' + name + '"'
     if self.unitsinfo.ok and units in self.unitsinfo.info:
         s = s + ',\n' + indent2 + 'units = "' + self.unitsinfo.info[units] + '"'
     s = s + ')'
     self._writeline(s)
 def _gendecls(self):
     self._writeline(indent1 + '#Assumes 0.0 initial value for inputs')
     for k, v in self.components.iteritems():
         for name, nodes in v.iteritems():
             #TO_CHECK  - is there any way to get units?
             if k == 'surfaces':
                 for i, v in ansysinfo.surfaceinputtypes.iteritems():
                     self._gendecl(k, i, name, v[1])
             elif k == 'keypoints':
                 for i, v in ansysinfo.keypointinputtypes.iteritems():
                     self._gendecl(k, i, name, v[1])
             elif k == 'nodes':
                 for i, v in ansysinfo.nodeinputtypes.iteritems():
                     self._gendecl(k, i, name, v[1])
             else:
                 s = 'AnsysWrapperGenerator for ' + name + ': unknown component type ' + k + ' - IGNORED'
                 print 'WARNING: ' + s
                 self.logger.warning(s)        
             for otype, ounits in ansysinfo.outputtypes.iteritems():
                 n = ansysinfo._make_name(name, otype)
                 self.output_names.add(n)
                 if self.unitsinfo.ok and ounits in self.unitsinfo.info:
                     units_str = ',\n' + indent2 + 'units = "' + self.unitsinfo.info[ounits] + '"'
                 else:
                     units_str = ''
                 self._writeline(indent1 + n +
                                 ' = Array(iotype = "out", dtype = "float",\n' + indent2 + 'desc = "' + otype +
                                 ' on nodes of ' + name + '"' + units_str + ')')
                 for ctype in ansysinfo.calctypes:
                     cname = n + '_' + ctype
                     self.output_names.add(cname)
                     self._writeline(indent1 + cname + ' = Float(0.0, iotype = "out",\n' +
                                     indent2 + 'desc = "' + ctype + ' of ' + otype + ' on nodes of ' + name + '"' + units_str + ')')
     for i, v in ansysinfo.globalinputtypes.iteritems():
         iunits = v[1]
         if self.unitsinfo.ok and iunits in self.unitsinfo.info:
             units_str = 'units = "' + self.unitsinfo.info[iunits] + '"'
         else:
             units_str = ''
         global_name = 'FEA_' + i
         self.input_names.add(global_name)
         initial_name = 'initial_' + global_name
         if i in self.initial_values_dictionary:
             initial_value = self.initial_values_dictionary[i]
         else:
             initial_value = 0.0
             s = 'AnsysWrapperGenerator for ' + name + ': ' + i + ' not in initial_values_dictionary; using 0.0 as initial value'
             print 'WARNING: ' + s
             self.logger.warning(s)
         self._writeline(indent1 + global_name + ' = Float(' + str(initial_value) + ', iotype = "in", ' + units_str + ')') 
         self._writeline(indent1 + initial_name  + ' = ' + str(initial_value))
     #an output for the full name of the python results file
     self._writeline(indent1 + 'Results_File = Str(iotype = "out", desc = "Results file in Python Format")')
Ejemplo n.º 5
0
    def write_input(self, inputs=[]):
        """Write input file self.loadsfile."""
        currdir = os.getcwd()
        input_cmds = []
        try:
            os.chdir(self.runner.workingdir)
            try:
                f = open(self.loadsfile, 'w')
            except IOError as ioe:
                print 'Error opening loadsfile file ' + self.loadsfile
                print sys.exc_info()[0]
                print str(ioe)
                self.ok = False
                return False
            self.logger.info(self.my_name + ' write input: ' + self.loadsfile)
            self.logger.info('-------------------------------------\n')
            #self.logger.debug('nodeinputtypes ' + str(ansysinfo.nodeinputtypes))
            for k, vv in self.components.iteritems():
                #self.logger.debug('component ' + str(k) + ' ' + str(vv.keys()))
                for name, nodes in vv.iteritems():
                    #self.logger.debug(name)
                    if k == 'surfaces':
                        for i, s in ansysinfo.surfaceinputtypes.iteritems():
                            n = ansysinfo._make_name(name, i)
                            v = self.get_attr_value(n)
                            v = self.convert_units(n, v)
                            #self.logger.debug(n + ' = ' + str(v))
                            if v != 0.0: #write new value
                                l = s[0].replace('%N%', name)
                                l1 = l.replace('%V%', str(v))
                                l2 = '!apply ' + i + ' ' + str(v) + ' to ' + \
                                    ' surface component ' + name
                                f.write(l2 + '\n')
                                f.write(l1 + '\n')
                                self.logger.info(l2)
                                self.logger.info(l1)
                                input_cmds.append(l1)
                    elif k == 'keypoints':
                        for i, s in ansysinfo.keypointinputtypes.iteritems():
                            n = ansysinfo._make_name(name, i)
                            v = self.get_attr_value(n)
                            v = self.convert_units(n, v)
                            #self.logger.debug(n + ' = ' + str(v))
                            if v != 0.0: #write new value
                                l = s[0].replace('%N%', name)
                                l1 = l.replace('%V%', str(v))
                                l2 = '!apply ' + i + ' ' + str(v) + ' to ' + \
                                    ' keypoint component ' + name
                                f.write(l2 + '\n')
                                f.write(l1 + '\n')
                                self.logger.info(l2)
                                self.logger.info(l1)
                                input_cmds.append(l1)
                    elif k == 'nodes':
                        #self.logger.debug('node ' + name)
                        #import pdb; pdb.set_trace()
                        for i, s in ansysinfo.nodeinputtypes.iteritems():
                            n = ansysinfo._make_name(name, i)
                            try:
                                v = self.get_attr_value(n)
                                v = self.convert_units(n, v)
                            except:
                                print 'Exception in gettattr ' + n
                                v = 0.0
                            #self.logger.debug(n + ' = ' + str(v))
                            if v != 0.0: #write new value
                                l = s[0].replace('%N%', name)
                                l1 = l.replace('%V%', str(v))
                                l2 = '!apply ' + i + ' ' + str(v) + ' to ' + \
                                    ' node component ' + name
                                f.write(l2 + '\n')
                                f.write(l1 + '\n')
                                self.logger.info(l2)
                                self.logger.info(l1)
                                input_cmds.append(l1)
                    elif k == 'global':
                        for i, s in ansysinfo.globalinputtypes.iteritems():
                            n = ansysinfo._make_name(name, i)
                            v = self.get_attr_value(n)
                            v = self.convert_units(n, v)
                            initial_v = self.get_attr_value('initial_' + n)
                            if v != initial_v: #write new value
                                l = s[0].replace('%N%', name)
                                l1 = l.replace('%V%', str(v))
                                l2 = '!apply ' + i + ' ' + str(v) + ' to ' + \
                                    ' global component ' + name
                                f.write(l2 + '\n')
                                f.write(l1 + '\n')
                                self.logger.info(l2)
                                self.logger.info(l1)
                                input_cmds.append(l1)


                    elif k == 'coordinputtypes':
                        keys = ansysinfo.coordinputtypes.keys()
                        keys.sort()
                        subs = [ansysinfo.coordinputtypes[k] for k in keys]
                        for bnd, vvv in vv.iteritems():
                            for node, defls in vvv.iteritems(): # node is node number, delfs is list [UX, UY, UZ]
                                for defl, sub in zip(defls, subs):
                                    if defl <> 0:
                                        l = sub[0].replace('%N%', str(node))
                                        l1 = l.replace('%V%', str(defl))
                                        l2 = '!apply deflection ' + str(defl) + ' to ' + ' node ' + str(node)  
                                        f.write(l2 + '\n')
                                        f.write(l1 + '\n')
                                        self.logger.info(l2)
                                        self.logger.info(l1)
                                        input_cmds.append(l1)

            # extra_inputs, set elsewhere, get passed through verbatim
            for line in inputs:
                f.write(line)
                input_cmds.append(line)

            self.logger.info('-------------------------------------\n')
            self.logger.info(self.my_name + ' write input done')

        finally:
            f.close()
            os.chdir(currdir)
            return input_cmds