Changeset 8973
- Timestamp:
- Sep 12, 2013, 3:18:38 PM (12 years ago)
- Location:
- trunk/anuga_core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r8970 r8973 1139 1139 1140 1140 1141 if location == 'centroids': 1142 points = self.domain.centroid_coordinates 1143 else: 1144 points = self.domain.vertex_coordinates 1141 1145 1142 1146 1143 … … 1238 1235 datafile.close() 1239 1236 1240 #print Z.shape, Z 1241 1242 x = num.linspace(xllcorner, xllcorner+cellsize*(nrows-1), nrows) 1243 y = num.linspace(yllcorner, yllcorner+cellsize*(ncols-1), ncols) 1237 #print Z.shape 1238 #print Z 1239 1240 # For raster data we need to a flip and transpose 1241 Z = numpy.flipud(Z) 1242 1243 # Transpose z to have y coordinates along the first axis and x coordinates 1244 # along the second axis 1245 Z = Z.transpose() 1246 1247 x = num.linspace(xllcorner, xllcorner+cellsize*(ncols-1), ncols) 1248 y = num.linspace(yllcorner, yllcorner+cellsize*(nrows-1), nrows) 1249 1250 1251 if location == 'centroids': 1252 points = self.domain.centroid_coordinates 1253 else: 1254 points = self.domain.vertex_coordinates 1255 1256 from anuga.geospatial_data.geospatial_data import Geospatial_data, ensure_absolute 1257 points = ensure_absolute(points, geo_reference=self.domain.geo_reference) 1258 1259 print numpy.max(points[:,0]) 1260 print numpy.min(points[:,0]) 1261 print numpy.max(points[:,1]) 1262 print numpy.min(points[:,1]) 1263 1264 print numpy.max(x) 1265 print numpy.min(x) 1266 print numpy.max(y) 1267 print numpy.min(y) 1268 1244 1269 1245 1270 #print x.shape, x … … 1275 1300 #assert values.shape[0] == N, msg 1276 1301 1277 self.vertex_values[:] = values 1302 #print values.shape 1303 #print self.vertex_values.shape 1304 self.vertex_values[:] = values.reshape((-1,3)) 1278 1305 else: 1279 1306 msg = 'Number of values must match number of indices' … … 1281 1308 1282 1309 # Brute force 1283 self.vertex_values[indices] = values 1310 self.vertex_values[indices] = values.reshape((-1,3)) 1284 1311 1285 1312 def get_extremum_index(self, mode=None, indices=None): -
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r8970 r8973 1388 1388 1389 1389 def test_set_values_from_asc_vertices(self): 1390 1391 quantity= Quantity(self.mesh_onslow)1392 1393 1394 1390 """ Format of asc file 1395 1391 ncols 11 … … 1400 1396 NODATA_value -9999 1401 1397 """ 1402 1403 # UTM round Onslow 1404 1398 1399 #x0 = 314036.58727982 1400 #y0 = 6224951.2960092 1401 x0 = 0.0 1402 y0 = 0.0 1403 1404 a = [0.0, 0.0] 1405 b = [0.0, 2.0] 1406 c = [2.0, 0.0] 1407 d = [0.0, 4.0] 1408 e = [2.0, 2.0] 1409 f = [4.0, 0.0] 1410 1411 points = [a, b, c, d, e, f] 1412 1413 #bac, bce, ecf, dbe 1414 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 1415 1416 mesh4 = Generic_Domain(points, elements) 1417 # geo_reference = Geo_reference(56, x0, y0)) 1418 mesh4.check_integrity() 1419 quantity = Quantity(mesh4) 1405 1420 1406 1421 1407 1422 ncols = 11 # Nx 1408 1423 nrows = 12 # Ny 1409 xllcorner = 2400001410 yllcorner = 76200001411 cellsize = 60001424 xllcorner = x0 1425 yllcorner = y0 1426 cellsize = 1.0 1412 1427 NODATA_value = -9999 1413 1428 … … 1457 1472 1458 1473 # check order of vertices 1459 answer = [ 23298000. , 23358000. , 23118000. ] 1460 answer = [ 23298000. , 23118000. , 23358000 ] 1461 print quantity.vertex_values 1474 1475 answer = [[ 6., 0., 2.], 1476 [ 6., 2., 8.], 1477 [ 8., 2., 4.], 1478 [ 12., 6., 8.]] 1479 #print quantity.vertex_values 1462 1480 assert num.allclose(quantity.vertex_values, answer) 1463 1481 … … 1478 1496 #print quantity.centroid_values 1479 1497 1480 answer = [ 23258000. ] 1498 1499 answer = [ 2.66666667, 5.33333333, 4.66666667, 8.66666667] 1500 1481 1501 assert num.allclose(quantity.centroid_values, answer) 1482 1502 #Cleanup -
trunk/anuga_core/user_manual/anuga_user_manual.tex
r8942 r8973 2732 2732 2733 2733 The \code{Culvert_flow} class takes as input: 2734 \begin{itemize} 2735 \item \code{domain}: a reference to the domain being evolved 2736 \item \code{culvert_description_filename}: 2737 \item \code{culvert_routine}: 2738 \item \code{end_point0}: Coordinates of one opening 2739 \item \code{end_point1}: Coordinates of other opening 2740 \item \code{enquiry_point0}: 2741 \item \code{enquiry_point1}: 2742 \item \code{type}: (default is 'box') 2743 \item \code{width}: 2744 \item \code{height}: 2745 \item \code{length}: 2746 \item \code{number_of_barrels}: Number of identical pipes in the culvert (default is 1) 2747 \item \code{trigger_depth}: (default is 0.01) 2748 \item \code{manning}: Mannings Roughness for Culvert 2749 \item \code{sum_loss}: 2750 \item \code{use_velocity_head}: 2751 \item \code{use_momentum_jet}: 2752 \item \code{label}: Short text naming the culvert 2753 \item \code{description}: Text describing the culvert 2754 \item \code{update_interval}: 2755 \item \code{log_file}: 2756 \item \code{discharge_hydrograph}: 2757 \end{itemize} 2734 2735 \code{domain}: a reference to the domain being evolved 2736 2737 \code{culvert_description_filename}: 2738 2739 \code{culvert_routine}: 2740 2741 \code{end_point0}: Coordinates of one opening 2742 2743 \code{end_point1}: Coordinates of other opening 2744 2745 \code{enquiry_point0}: 2746 2747 \code{enquiry_point1}: 2748 2749 \code{type}: (default is 'box') 2750 2751 \code{width}: 2752 2753 \code{height}: 2754 2755 \code{length}: 2756 2757 \code{number_of_barrels}: Number of identical pipes in the culvert (default is 1) 2758 2759 \code{trigger_depth}: (default is 0.01) 2760 2761 \code{manning}: Mannings Roughness for Culvert 2762 2763 \code{sum_loss}: 2764 2765 \code{use_velocity_head}: 2766 2767 \code{use_momentum_jet}: 2768 2769 \code{label}: Short text naming the culvert 2770 2771 \code{description}: Text describing the culvert 2772 2773 \code{update_interval}: 2774 2775 \code{log_file}: 2776 2777 \code{discharge_hydrograph}: 2778 2758 2779 2759 2780 The user can specify different culvert routines. However, \anuga currently provides only one, namely the … … 2792 2813 2793 2814 2815 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2816 \section{Fractional Step Operators}\index{fractional step operators} 2817 2818 An alternative way to effect the evolution is via fractional step operators. The idea is that at each inner timestep we can use 2819 a fractional step operator to change the centroid values of our conserved quantities, the stage and the xmomentum and the ymomentum. The elevation can also be changed but more care needs to be applied as the \code{elevation} quantity needs to remain continuous. The moral, play with \code{elevation} at your peril. 2820 2821 We are tending to move away from forcing terms and towards fractpional step operators as they are easier to parallelize. 2822 2823 2824 Currently predefined fractional step operators: 2825 2826 2827 \begin{classdesc}{Set_elevation_operator}{domain, 2828 elevation=None, 2829 indices=None, 2830 polygon=None, 2831 center=None, 2832 radius=None, 2833 description = None, 2834 label = None, 2835 logging = False, 2836 verbose = False} 2837 Module: \module{anuga.operators.set_elevation_operator} 2838 2839 Set the elevation in a region (careful to maintain continuitiy of elevation) 2840 2841 2842 \code{domain} is the domain being evolved. 2843 2844 \code{elevation} a function of $t$ or $x,y$ or $x,y,t$ written to take numpy arrays $x$ and $y$. $t$ is a scalar. 2845 2846 \code{indices} is a list of triangle indices where the function \code{elevation} will be applied. 2847 2848 \code{polygon} is a polygon. The function \code{elevation} will be applied to triangles with in the polygon. 2849 2850 \code{center} is the center of a circle where the function \code{elevation} will be applied. (\code{radius} needs to be set). 2851 2852 \code{radius} is the radius of a circle where the function \code{elevation} will be applied. (\code{center} needs to be set). 2853 2854 \code{description} is a description of this operator. 2855 2856 \code{label} is the lable used when reporting on the operator. 2857 2858 \code{logging} is the boolean flag to set logging to a file. 2859 2860 \code{verbose} is the boolean flag to setup extended output from the operator. 2861 2862 Example: 2863 2864 \begin{verbatim} 2865 from anuga.operators.set_elevation_operator import Set_elevation_operator 2866 2867 op0 =Set_elevation_operator(domain, elevation = lambda t : 0.01*t) 2868 \end{verbatim} 2869 would setup an operator which raises the elevation over the whole domain 1 cm per second. 2870 2871 2872 While 2873 \begin{verbatim} 2874 from anuga.operators.set_elevation_operator import Set_elevation_operator 2875 P = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]] 2876 2877 op0 =Set_elevation_operator(domain, elevation = lambda t : 0.01*t, polygon=P) 2878 \end{verbatim} 2879 would setup an operator which raises the elevation over the polygon \code{P} 1 cm per second. 2880 2881 \end{classdesc} 2882 2883 2884 2885 \subsection{User developed fractional step operator} 2886 2887 Suppose we want to add water to our domain at a steady rate. we can create a class based on the \code{Operator} class which has a \code{__call__} function to do the required update to the centroid values of the stage variable. 2888 2889 Here is some code to do this: 2890 \begin{verbatim} 2891 from anuga.operators.base_operator import Operator 2892 2893 class My_operator(Operator): 2894 """ 2895 Add water to the domain at a given rate (m/sec) 2896 """ 2897 2898 def __init__(self, 2899 domain, 2900 rate=0.0, 2901 description = None, 2902 label = None, 2903 logging = False, 2904 verbose = False): 2905 """Initialize the user defined operator 2906 """ 2907 2908 Operator.__init__(self, domain, description, label, logging, verbose) 2909 2910 self.rate = rate 2911 2912 2913 def __call__(self): 2914 """ 2915 Apply rate to all triangles 2916 """ 2917 2918 timestep = self.domain.get_timestep() 2919 2920 self.stage_c[:] = self.stage_c[:] + self.rate*timestep 2921 \end{verbatim} 2922 2923 And then in your script you would asosciated \code{My_operator} with the \code{domain} with a call 2924 \begin{verbatim} 2925 My_operator(domain,rate=1.0) 2926 \end{verbatim} 2927 2928 2929 2930 2931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2794 2932 \section{Evolution}\index{evolution} 2795 2933 \label{sec:evolution}
Note: See TracChangeset
for help on using the changeset viewer.