my_disp_y_worker = Epetra.Vector(my_worker_map) my_force_x_worker = Epetra.Vector(my_worker_map) my_force_y_worker = Epetra.Vector(my_worker_map) #Temporary arrays my_velocity_x = np.zeros_like(my_disp_x) my_velocity_y = np.zeros_like(my_disp_y) my_accel_x = np.zeros_like(my_disp_x) my_accel_y = np.zeros_like(my_disp_y) my_damage = np.zeros_like(my_x) #Initialize output files vector_variables = ['displacement'] scalar_variables = ['damage'] #Instantiate output file object outfile = Ensight('output', vector_variables, scalar_variables, comm, viz_path=VIZ_PATH) #Print the temporary output arrays if rank == 0: print("Output variables requested:\n") for item in vector_variables: print(" " + item) for item in scalar_variables: print(" " + item) print(" ") #Find local nodes where boundary conditions should be applied bc1_local_node_set = boundary_condition_set(BC1_POLYGON,zip(my_x.ravel(),my_y.ravel()),balanced_map) bc2_local_node_set = boundary_condition_set(BC2_POLYGON,zip(my_x.ravel(),my_y.ravel()),balanced_map) #Calculate a stable time step or use the user defined if TIME_STEP == None:
def main(): #Create the PD object i = 0 nodes = 10 problem = PD(nodes, 10.0) problem.nodes_number = nodes pressure_const = problem.pressure_const comm = problem.comm #Define the initial guess field_graph = problem.get_balanced_field_graph() init_vel_guess = Epetra.Vector(problem.get_balanced_field_map()) ux_local_indices = problem.ux_local_indices uy_local_indices = problem.uy_local_indices time_stepping = problem.time_stepping uy_overlap_indices = problem.uy_overlap_indices ux_overlap_indices = problem.ux_overlap_indices #problem.velocity_y_n = problem.vel_overlap[uy_overlap_indices] neighborhood_graph = problem.get_balanced_neighborhood_graph() num_owned = 2.0 * neighborhood_graph.NumMyRows() #neighbors = problem.my_neighbors #node_number = neighbors.shape[0] #neighb_number = neighbors.shape[1] #size_upscaler = (node_number , neighb_number) #problem.up_scaler = np.ones(size_upscaler) horizon = problem.horizon #volumes = problem.my_volumes #size = ref_mag_state.shape #one = np.ones(size) #omega =one #problem.omega = omega #linear = 0 init_guess = problem.init_guess vel_overlap_importer = problem.get_field_overlap_importer() field_overlap_map = problem.get_field_overlap_map() #Initialize and change some NOX settings nl_params = NOX.Epetra.defaultNonlinearParameters(problem.comm, 2) nl_params["Line Search"]["Method"] = "Polynomial" ls_params = nl_params["Linear Solver"] ls_params["Preconditioner Operator"] = "Use Jacobian" ls_params["Preconditioner"] = "New Ifpack" #Establish parameters for ParaView Visualization VIZ_PATH = '/Applications/paraview.app/Contents/MacOS/paraview' vector_variables = ['displacement'] scalar_variables = ['velocity_x', 'velocity_y'] outfile = Ensight('output', vector_variables, scalar_variables, problem.comm, viz_path=VIZ_PATH) problem.velocity_y_n = problem.my_field_overlap[:-1:2] problem.velocity_x_n = problem.my_field_overlap[1::2] problem.current_solution = problem.my_field_overlap end_range = 1000 for i in range(end_range): print(i) problem.jac_comp = True fdc_velocity = NOX.Epetra.FiniteDifferenceColoring( nl_params, problem, init_guess, field_graph, False, False) fdc_velocity.computeJacobian(init_guess) jacobian = fdc_velocity.getUnderlyingMatrix() jacobian.FillComplete() problem.jac_comp = False #Create NOX solver object, solve for velocity_x and velocity_y if i < 1: solver = NOX.Epetra.defaultSolver(init_guess, problem, problem, jacobian, nlParams=nl_params, maxIters=10, wAbsTol=None, wRelTol=None, updateTol=None, absTol=8.0e-7, relTol=None) else: solver = NOX.Epetra.defaultSolver(init_guess, problem, problem, jacobian, nlParams=nl_params, maxIters=100, wAbsTol=None, wRelTol=None, updateTol=None, absTol=1.0e-6, relTol=None) solveStatus = solver.solve() finalGroup = solver.getSolutionGroup() solution = finalGroup.getX() #problem.current_solution = solution #resetting the initial conditions init_vel_guess[ux_local_indices] = solution[ux_local_indices] #start from the initial guess of zero init_vel_guess[uy_local_indices] = solution[uy_local_indices] #velocity_y_n = solution[uy_local_indices] problem.my_field_overlap.Import(solution, vel_overlap_importer, Epetra.Insert) problem.velocity_y_n = problem.my_field_overlap[:-1:2] problem.velocity_x_n = problem.my_field_overlap[1::2] #plotting the results sol_velocity_x = solution[ux_local_indices] #print (uy_local_indices) #ttt.sleep(1) sol_velocity_y = solution[uy_local_indices] velocity_x = problem.velocity_x_n velocity_y = problem.velocity_y_n init_guess = solution x_out = comm.GatherAll(problem.my_x).flatten() y_out = comm.GatherAll(problem.my_y).flatten() v_x = comm.GatherAll(sol_velocity_x).flatten() v_y = comm.GatherAll(sol_velocity_y).flatten() #velocity_total = (v_x **2 + v_y **2 )** 0.5 #v_out = comm.GatherAll(velocity_total).flatten() #if i%100==0: # print ("saving outputs") # if problem.rank==0: # plt.scatter(x_out,y_out,c=v_out) # file_name= "pressure"+"_"+str(i) # plt.savefig(file_name+".png") ################ Write Date to Ensight Outfile ################# time = i * problem.time_stepping outfile.write_geometry_file_time_step(problem.my_x, problem.my_y) outfile.write_vector_variable_time_step( 'displacement', [0.0 * problem.my_x, 0.0 * problem.my_y], time) outfile.write_scalar_variable_time_step('velocity_y', sol_velocity_y, time) outfile.write_scalar_variable_time_step('velocity_x', sol_velocity_x, time) outfile.append_time_step(time) outfile.write_case_file(comm) ################################################################ print("wrote ensight files") outfile.finalize()