def __init__(self, skip_assemble=False, skip_poisson=False): """Initializes the solver. Creates the flow variables, assembles the discretized operator matrices and initializes the Poisson solver. """ # read the simulation parameters Parameters() # initialize flow variables self.initialize_variables() print '\n{Assembling matrices}' tic = timer_start() if not skip_assemble: self.assemble_matrices() else: print '--> skipped' timer_stop(tic, info='Assembling matrices') if not skip_poisson: Solver.poisson = Poisson(Solver.p) else: print '--> Poisson skipped'
def solve(self, body=None): # open the file that contains force coefficients if body: outfile = open(Case.path + '/forceCoeffs.dat', ('w' if Parameters.start == 0 else 'a')) # time-integration using Euler method tic = timer_start() while Parameters.ite < Parameters.start + Parameters.nt: Parameters.ite += 1 print '\nIteration %d - Time = %f' \ % (Parameters.ite, Parameters.ite*Parameters.dt) # get intermediate velocity self.intermediate_velocity() # immersed boundary method self.immersed_boundary_method(body) # solve Poisson equation for pressure self.solve_poisson() # update velocity field self.update_velocity() # write variable fields if Parameters.ite % Parameters.write_every == 0: print '\n{Writting results}' if not os.path.isdir(Case.path + '/' + str(Parameters.ite)): os.system('mkdir ' + Case.path + '/' + str(Parameters.ite)) Solver.u.write() Solver.v.write() Solver.p.write() # write force coefficients if body: outfile.write( '%f \t %f \t %f' % (Parameters.ite * Parameters.dt, body.cl, body.cd)) timer_stop(tic, info='DONE') # close the file containing force coefficients if body: outfile.close()
def solve(self, body=None): # open the file that contains force coefficients if body: outfile = open(Case.path+'/forceCoeffs.dat', ('w' if Parameters.start == 0 else 'a')) # time-integration using Euler method tic = timer_start() while Parameters.ite < Parameters.start + Parameters.nt: Parameters.ite += 1 print '\nIteration %d - Time = %f' \ % (Parameters.ite, Parameters.ite*Parameters.dt) # get intermediate velocity self.intermediate_velocity() # immersed boundary method self.immersed_boundary_method(body) # solve Poisson equation for pressure self.solve_poisson() # update velocity field self.update_velocity() # write variable fields if Parameters.ite%Parameters.write_every == 0: print '\n{Writting results}' if not os.path.isdir(Case.path+'/'+str(Parameters.ite)): os.system('mkdir '+Case.path+'/'+str(Parameters.ite)) Solver.u.write() Solver.v.write() Solver.p.write() # write force coefficients if body: outfile.write('%f \t %f \t %f' % (Parameters.ite*Parameters.dt, body.cl, body.cd)) timer_stop(tic, info='DONE') # close the file containing force coefficients if body: outfile.close()