def run_pde(self): t0 = self.parameter.simulation_start_time # Start time for simulation current_time = t0 # Variable to store the current time t_step = self.parameter.time_step pde_equation = self.pde_equation sol_variable = self.solution_variable if self.parameter.plotting: viewer = Viewer(vars=sol_variable, datamin=0, datamax=1.) viewer.plotMesh() # source_flag = True # currently not implemented while current_time < t0 + self.parameter.simulation_duration: ### This code was to allow boundary flux to change, but non-flux boundaries are not working # if source_flag and current_time > self.parameter.source_end_time: # sol_variable = self.define_solution_variable(sol_variable, boundary_source='no flux') # sol_variable.faceGrad.constrain(0 * self.mesh.faceNormals, self.mesh.exteriorFaces) pde_equation.solve(var=sol_variable, dt=t_step) # solve one time step # Increment time previous_time = current_time current_time += t_step # Check for change in convection data if self.detect_change_in_convection_data(previous_time, current_time): pde_equation = self.define_ode(current_time) # Check if the solution should be saved if self.detect_save_time(previous_time, current_time): self.add_current_state_to_save_file(current_time) if self.parameter.plotting: viewer.plot() # If the final time step goes beyond the duration, do a shorter finishing step. if current_time > t0 + self.parameter.simulation_duration: t_step = current_time - (t0 + self.parameter.simulation_duration) current_time = t0 + self.parameter.simulation_duration # set current time to the final time pde_equation.solve(var=sol_variable, dt=t_step) # solve one time step print('Current time step: {}, finish time: {}'.format(current_time, self.parameter.simulation_duration)) # At completion, save the final state self.add_current_state_to_save_file(current_time) print('PDE solving complete')
#We create a viewer to see the results #.. index:: # module: fipy.viewers if __name__ == '__main__': if doBlob: try: viewer = Viewer(vars=phi, datamin=-1.5, datamax=1.) viewer.plot() raw_input("Irregular circular mesh. Press <return> to proceed..." ) # doctest: +GMSH except: print "Unable to create a viewer for an irregular mesh (try Matplotlib2DViewer or MayaviViewer)" elif doCirc: try: viewer = Viewer(vars=phi, datamin=-1, datamax=1.) viewer.plotMesh() raw_input("Irregular circular mesh. Press <return> to proceed..." ) # doctest: +GMSH except: print "Unable to create a viewer for an irregular mesh (try Matplotlib2DViewer or MayaviViewer)" else: viewer = Viewer(vars=phi, datamin=0., datamax=1.) viewer.plot() #and solve the equation by repeatedly looping in time: if doBlob: timeStepDuration = 10 * 0.9 * 0.05**2 / (2 * D) elif doCirc: timeStepDuration = 10 * 0.9 * cellSize**2 / (2 * D) else: timeStepDuration = 10 * 0.9 * dx**2 / (2 * D)