def __enter__(self): if self.killmentat: PROCNAME = "mentatOGL.exe" for proc in psutil.process_iter(): # check whether the process name matches if proc.name() == PROCNAME: proc.kill() if self.startmentat: # connect to mentat #if self.background: # CREATE_NO_WINDOW = 0x08000000 # si = subprocess.STARTUPINFO() # si.dwFlags |= subprocess.STARTF_USESHOWWINDOW #else: # CREATE_NO_WINDOW = 0 # si = None subprocess.Popen(r' '.join(self.callmentat), stdout=subprocess.PIPE, stderr=subprocess.PIPE) #, #startupinfo = si) #creationflags=CREATE_NO_WINDOW) #, stdout=subprocess.PIPE #out,err = p.communicate() while True: try: pm.py_connect("127.0.0.1", 40007) # test connection pm.py_send("test connection") break except: time.sleep(0.25) self.connection = True elif not self.startmentat and not self.connection: pm.py_connect("127.0.0.1", 40007) self.connection = True return self
# --- loop over input files ------------------------------------------------------------------------ if filenames == []: filenames = [None] for name in filenames: print(scriptName+': '+name) geom = damask.Grid.load(StringIO(''.join(sys.stdin.read())) if name is None else name) material = geom.material.flatten(order='F') cmds = [\ init(), mesh(geom.cells,geom.size), materials(), geometry(), initial_conditions(material), '*identify_sets', '*show_model', '*redraw', '*draw_automatic', ] outputLocals = {} if options.port: py_mentat.py_connect('',options.port) output(cmds,outputLocals,'Mentat') py_mentat.py_disconnect() else: with sys.stdout if name is None else open(os.path.splitext(name)[0]+'.proc','w') as f: output(cmds,outputLocals,f)
theMap = damask.Colormap() if options.inverse: theMap = theMap.invert() if options.palettef: print theMap.export(format='raw',steps=options.colorcount) elif options.palette: for theColor in theMap.export(format='list',steps=options.colorcount): print '\t'.join(map(lambda x: str(int(255*x)),theColor)) else: # connect to Mentat and change colorMap sys.path.append(damask.solver.Marc().libraryPath()) try: import py_mentat print 'waiting to connect...' py_mentat.py_connect('',options.port) print 'connected...' mentat = True except: sys.stderr.write('warning: no valid Mentat release found\n') mentat = False outputLocals = {} cmds = colorMap(theMap.export(format='list',steps=options.colorcount),options.baseIdx) if mentat: output(['*show_table']+cmds+['*show_model *redraw'],outputLocals,'Mentat') py_mentat.py_disconnect() if options.verbose: output(cmds,outputLocals,'Stdout')
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((HOST, PORT)) s.listen() while True: print('waiting for connection...') conn, addr = s.accept() with conn: print('New Connection\nConnected by', addr) obj_recv = bytearray() data = conn.recv(64) obj_length = int(data[:HEADERSIZE].decode('utf-8')) obj_recv.extend(data[HEADERSIZE:]) while len(obj_recv) < obj_length: data = conn.recv(64) obj_recv.extend(data) task = pickle.loads(obj_recv) task.execute(py_mentat, py_post, conn) print('Client disconnected') if __name__ == '__main__': port = input('enter Mentat port') py_mentat.py_connect('', int(port)) main() py_mentat.py_disconnect()
def __enter__(self): # connect to mentat pm.py_connect("127.0.0.1", 40007) return self
n_id = py_mentat.py_get_int("scalar_max_node()") value = py_mentat.py_get_float('scalar_1({})'.format(n_id)) if value: print('the result is ', value) else: print('no value') def main(): shell = [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0), (8, 0), (9, 0), (10, 0), (11, 0), (12, 0), (13, 0), (14, 0), (14, 1), (14, 2), (14, 3), (13, 3), (12, 3), (11, 3), (10, 3), (9, 3), (8, 3), (7, 3), (6, 3), (5, 3), (4, 3), (3, 3), (3, 4), (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), (3, 10), (3, 11), (3, 12), (3, 13), (3, 14), (2, 14), (1, 14), (0, 14), (0, 13), (0, 12), (0, 11), (0, 10), (0, 9), (0, 8), (0, 7), (0, 6), (0, 5), (0, 4), (0, 3), (0, 2), (0, 1)] fixed_displacements = [(False, False) ] * 39 + [(True, True)] * 4 + [(False, False)] * 13 forces = [(False, False)] * 17 + [(0, -100)] + [(False, False)] * 38 read_in(shell, fixed_displacements, forces) post_processing() if __name__ == '__main__': py_mentat.py_connect("", 40007) main() py_mentat.py_disconnect()
prob = [0.5, 0.1, 0.5] point = [1, 2, 2] # Prepare the unit parameters temp = classes.template(case, x_e, y_e, e_s, b, classes.mold_star_15, n_steps, table_name, d_mag, p_mag) # Create the template create.temp_create(temp) # Check if the analysis method is the Monte Carlo method if a_meth == "m": analyse.monte_carlo(temp, g_meth) # Check if the analysis method is the Genetic Algorithm method elif a_meth == "g": gen_alg.g_a(temp, gen, prob, point, g_meth) # View the boundary conditions of the template inspect.view_bc() return if __name__ == "__main__": py_connect("", 40007) main() py_disconnect