Ejemplo n.º 1
0
 def run(self):
     n = len(self.points_index)
     comm = MPI.COMM_WORLD
     rank = comm.Get_rank()
     size = comm.Get_size()
     comm.barrier()
     if rank == 0:
         self.generaterundir()
     comm.barrier()
     global_range = range(n)
     local_range = range(rank,n,size)
     for idx, val in enumerate(local_range):
         current_adjoint_rundir = os.path.join(self.solution_dir, "jac_adjoint_%i"%self.points_index[val])
         adturns = AdTurnsRKD(nspec=1, rundir = current_adjoint_rundir)
         if self.DEBUG:
             adturns.set_debug_params()
         else:
             adturns.set_input_params(self.adjoint_params)
         print "Running adjoint for points %i from process %i"%(self.points_index[val], rank)
         adturns.run()
     comm.barrier()
     if rank == 0:
         nj, nk = adturns.get_grid_dimensions()
         nt = nj*nk
         jac_map = np.zeros([n, nt])
         F_map = np.zeros([n])
         for idx, val in enumerate(global_range):
             current_adjoint_rundir = os.path.join(self.solution_dir, "jac_adjoint_%i"%self.points_index[val])
             sensturns = SensTurnsRKD(nspec=1, rundir = current_adjoint_rundir)
             sens = sensturns.get_beta_sensitivity()
             jac_map[idx, :] = np.reshape(sens, [1, nt])
             F_map[idx] = np.loadtxt('fort.747')
         beta_map = np.reshape(sensturns.read_beta("beta.opt"), [nt, 1])
         io.savemat(os.path.join(self.solution_dir, "map.mat"),  {'jac_map':jac_map, 'beta_map':beta_map, 'F_map': F_map, 'nj':nj, 'nk':nk})
Ejemplo n.º 2
0
 def collect_jac(self):
     n = len(self.points_index)
     turns = TurnsRKD(nspec=1, rundir = self.solution_dir)
     nj, nk = turns.get_grid_dimensions()
     nt = nj*nk
     jac_map = np.zeros([n, nt])
     F_map = np.zeros([n])
     
     for idx, point in enumerate(self.points_index):
         print "\r Creating jacobian for point %i"%point,
         current_adjoint_rundir = os.path.join(self.solution_dir, "jac_adjoint_%i"%point)
         sensturns = SensTurnsRKD(nspec=1, rundir = current_adjoint_rundir)
         try:
             sens = sensturns.get_beta_sensitivity()
             jac_map[idx, :] = np.reshape(sens, [1, nt])
             F_map[idx] = np.loadtxt('fort.747')
         except:
             print "NOT FOUND SENS"
     print "\n"
     beta_map = np.reshape(sensturns.read_beta("beta.opt"), [nt, 1])
     io.savemat(os.path.join(self.solution_dir, "map.mat"),  {'jac_map':jac_map, 'beta_map':beta_map, 'F_map': F_map, 'nj':nj, 'nk':nk})