Changeset 8469
- Timestamp:
- Jul 19, 2012, 4:17:35 PM (13 years ago)
- Location:
- trunk/anuga_core/source/anuga/operators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/operators/kinematic_viscosity_operator.py
r8456 r8469 13 13 14 14 15 class Kinematic_ Viscosity_Operator(Operator):15 class Kinematic_viscosity_operator(Operator): 16 16 """ 17 17 Class for setting up structures and matrices for kinematic viscosity differential … … 27 27 """ 28 28 29 def __init__(self, domain, diffusivity= None, use_triangle_areas=True, verbose=False):29 def __init__(self, domain, diffusivity='height', use_triangle_areas=True, verbose=False): 30 30 31 31 if verbose: log.critical('Kinematic Viscosity: Beginning Initialisation') … … 51 51 self.diffusivity.set_boundary_values(diffusivity) 52 52 53 if isinstance(diffusivity, str): 54 self.diffusivity = self.domain.get_quantity(diffusivity) 55 53 56 54 57 assert isinstance(self.diffusivity, Quantity) … … 128 131 129 132 # diffusivity 130 h = domain.quantities['height'] 131 132 #d = self.diffusivity 133 d = self.diffusivity 134 135 136 assert num.all(d.centroid_values >= 0.0) 133 137 134 138 #d.set_values(num.where(h.centroid_values<1.0, 0.0, 1.0), location= 'centroids') … … 144 148 145 149 #Update operator using current height 146 self.update_elliptic_matrix( h)147 148 (u, self.u_stats) = self.parabolic_solve(u, u, h, u_out=u, update_matrix=False, output_stats=True)149 150 (v, self.v_stats) = self.parabolic_solve(v, v, h, u_out=v, update_matrix=False, output_stats=True)150 self.update_elliptic_matrix(d) 151 152 (u, self.u_stats) = self.parabolic_solve(u, u, d, u_out=u, update_matrix=False, output_stats=True) 153 154 (v, self.v_stats) = self.parabolic_solve(v, v, d, u_out=v, update_matrix=False, output_stats=True) 151 155 152 156 # Update the conserved quantities … … 155 159 156 160 self.dt = 0.0 157 #print self.timestepping_statistics() 161 162 158 163 159 164 def statistics(self): … … 165 170 def timestepping_statistics(self): 166 171 167 message = ' Kinematic Viscosity Operator: ' 172 from anuga import indent 173 174 message = indent+'Kinematic Viscosity Operator: \n' 168 175 if self.u_stats is not None: 169 message += ' u iterations %.5g, ' % self.u_stats.iter176 message += indent + indent + 'u: ' + self.u_stats.__str__() +'\n' 170 177 171 178 if self.v_stats is not None: 172 message += ' v iterations %.5g, ' % self.v_stats.iter179 message += indent + indent + 'v: ' + self.v_stats.__str__() 173 180 174 181 return message … … 482 489 483 490 def parabolic_solve(self, u_in, b, a = None, u_out = None, update_matrix=True, \ 484 imax=10000, tol=1.0e-8, atol=1.0e-8, 485 iprint=None, output_stats=False): 491 output_stats=False, use_dt_tol=True, iprint=None, imax=10000): 486 492 """ 487 493 Solve for u in the equation … … 505 511 """ 506 512 513 514 if use_dt_tol: 515 tol = min(self.dt,0.01) 516 atol = min(self.dt,0.01) 517 else: 518 tol = 1.0e-5 519 atol = 1.0e-5 520 521 522 523 507 524 if u_out == None: 508 525 u_out = Quantity(self.domain) -
trunk/anuga_core/source/anuga/operators/test_kinematic_viscosity_operator.py
r8162 r8469 564 564 565 565 566 u_out = operator.parabolic_solve(u_in, b, a, iprint=1 )566 u_out = operator.parabolic_solve(u_in, b, a, iprint=1, use_dt_tol=False) 567 567 568 568 assert num.allclose(u_out.centroid_values, U_mod[:n]) … … 671 671 kv.update_elliptic_matrix(h) 672 672 673 kv.parabolic_solve(u, u, h, u_out=u, update_matrix=False, iprint=1) 674 675 kv.parabolic_solve(v, v, h, u_out=v, update_matrix=False, iprint=1) 676 673 kv.parabolic_solve(u, u, h, u_out=u, update_matrix=False, iprint=1, use_dt_tol=False) 674 675 kv.parabolic_solve(v, v, h, u_out=v, update_matrix=False, iprint=1, use_dt_tol=False) 676 677 678 #print u.centroid_values 679 #print u.boundary_values 677 680 assert num.allclose(u.centroid_values, num.ones_like(u.centroid_values), rtol=1.0e-1) 678 681 assert num.allclose(u.boundary_values, num.ones_like(u.boundary_values)) … … 762 765 kv.update_elliptic_matrix(h) 763 766 764 kv.parabolic_solve(u, u, h, u_out=u, update_matrix=False, iprint=1 )765 766 kv.parabolic_solve(v, v, h, u_out=v, update_matrix=False, iprint=1 )767 kv.parabolic_solve(u, u, h, u_out=u, update_matrix=False, iprint=1, use_dt_tol=False) 768 769 kv.parabolic_solve(v, v, h, u_out=v, update_matrix=False, iprint=1, use_dt_tol=False) 767 770 768 771 … … 793 796 assert num.allclose(uh.centroid_values, u.centroid_values*h.centroid_values ) 794 797 assert num.allclose(vh.centroid_values, v.centroid_values*h.centroid_values ) 798 799 def test_kinematic_operator_default(self): 800 801 from anuga import rectangular_cross_domain 802 from anuga import Reflective_boundary 803 804 m1 = 10 805 n1 = 10 806 domain = rectangular_cross_domain(m1,n1) 807 808 domain.set_flow_algorithm('2_0') 809 810 # 811 domain.set_quantity('elevation', expression='x') 812 domain.set_quantity('friction', 0.03) 813 domain.set_quantity('stage',expression='elevation + 2*(x-0.5)') 814 domain.set_quantity('xmomentum', expression='2*x+3*y') 815 domain.set_quantity('ymomentum', expression='5*x+7*y') 816 817 B = Reflective_boundary(domain) 818 domain.set_boundary( {'left': B, 'right': B, 'top': B, 'bottom': B}) 819 820 kv = Kinematic_Viscosity_Operator(domain) 821 822 823 # let's make timestep large so that the final solution will look like 824 #the solution of hte elliptic problem. In this case u -> 1, v -> 2. 825 826 827 for t in domain.evolve(yieldstep = 1.0, finaltime = 10.0): 828 domain.write_time() 829 domain.print_operator_timestepping_statistics() 830 831 # dt = 1000.0 832 # kv.dt = dt 833 # n = kv.n 834 # nt = kv.tot_len 835 # 836 # kv.update_elliptic_matrix(h) 837 # 838 # kv.parabolic_solve(u, u, h, u_out=u, update_matrix=False, iprint=1) 839 # 840 # kv.parabolic_solve(v, v, h, u_out=v, update_matrix=False, iprint=1) 841 # 842 # 843 # #print 'u' 844 # #print u.centroid_values 845 # #print u.boundary_values 846 # 847 # #print num.where(h.centroid_values > 0.0, 1.0, 0.0) 848 # 849 # assert num.allclose(u.centroid_values, num.where(h.centroid_values > 0.0, 1.0, 0.0), rtol=1.0e-1) 850 # assert num.allclose(u.boundary_values, num.ones_like(u.boundary_values)) 851 # 852 # assert num.allclose(v.centroid_values, num.where(h.centroid_values > 0.0, 2.0, 0.0), rtol=1.0e-1) 853 # assert num.allclose(v.boundary_values, 2.0*num.ones_like(v.boundary_values)) 854 # 855 # 856 # domain.update_centroids_of_momentum_from_velocity() 857 # 858 # domain.distribute_to_vertices_and_edges() 859 # 860 # uh = domain.quantities['xmomentum'] 861 # vh = domain.quantities['ymomentum'] 862 # 863 # #print 'uh' 864 # #print uh.centroid_values 865 # #print uh.boundary_values 866 # 867 # assert num.allclose(uh.centroid_values, u.centroid_values*h.centroid_values ) 868 # assert num.allclose(vh.centroid_values, v.centroid_values*h.centroid_values ) 795 869 796 870
Note: See TracChangeset
for help on using the changeset viewer.