Changeset 2450
- Timestamp:
- Feb 27, 2006, 12:23:18 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
documentation/user_manual/anuga_user_manual.tex
r2449 r2450 423 423 momentum quantities assumed to be the second and third conserved 424 424 quantities. 425 425 426 426 \item[Transmissive boundary]Returns same conserved quantities as 427 427 those present in its neighbour volume. 428 428 429 429 \item[Dirichlet boundary]Specifies a fixed value at the 430 430 boundary. … … 458 458 series of steps indicated by the values of \code{yieldstep} and 459 459 \code{finaltime}, which can be altered as required. 460 The value of \code{yieldstep} controls the time interval between successive model outputs. 460 The value of \code{yieldstep} controls the time interval between successive model outputs. 461 461 Behind the scenes more time steps are generally taken. 462 462 … … 489 489 \section{An Example with Real Data} 490 490 491 The following discussion builds on the concepts introduced through \code{bedslope.py} 492 example and introduces a second example, \code{run_sydney_smf.py}, that follows 493 the same basic outline, but incorporates many more 494 complex features. 495 496 The chief difference is that data is taken from a file and represents an actual physical 497 scenario rather than an illustrative example. However a different 498 method is used to create the mesh. Instead of imposing a mesh 499 structure on a rectangular grid, the technique used for this example involves building 500 mesh structures inside polygons. 501 502 In its simplest form, the mesh is created within a single polygon 503 whose vertices are at geographical locations specified by the user. A 504 triangular mesh is created using points inside the polygon selected 505 through a random process, the user specifying the 506 \emph{resolution}---that is, the maximal area of a triangle used for 507 triangulation. 491 The following discussion builds on the concepts introduced through 492 the \code{bedslope.py} example and introduces a second example, 493 \code{run_sydney_smf.py}, that follows the same basic outline, but 494 incorporates many more complex features. 495 496 Here is the code for \code{run_sydney_smf.py}: 497 498 {\scriptsize \begin{verbatim} 499 """Script for running a tsunami 500 inundation scenario for Sydney, NSW, Australia. 501 502 Source data such as elevation and boundary data is assumed to be 503 available in directories specified by project.py The output sww file 504 is stored in project.outputdir 505 506 The scenario is defined by a triangular mesh created from 507 project.polygon, the elevation data and a simulated submarine 508 landslide. 509 510 Ole Nielsen and Duncan Gray, GA - 2005 and Adrian Hitchman and Jane 511 Sexton, GA - 2006 """ 512 513 514 #-------------------------------------------------------------------------------# 515 Import necessary modules 516 #------------------------------------------------------------------------------- 517 518 # Standard modules 519 import os 520 import time 521 522 # Related major packages 523 from pyvolution.shallow_water import 524 Domain, Reflective_boundary 525 from pyvolution.data_manager import 526 convert_dem_from_ascii2netcdf, dem2pts 527 from pyvolution.combine_pts 528 import combine_rectangular_points_files 529 from pyvolution.pmesh2domain 530 import pmesh_to_domain_instance 531 532 # Application specific imports 533 import project # 534 Definition of file names and polygons 535 from smf import slump_tsunami 536 # Function for submarine mudslide 537 538 539 #------------------------------------------------------------------------------- 540 # Preparation of topographic data # 541 # Convert ASC 2 DEM 2 PTS using 542 source data and store result in source data 543 # Do for coarse and fine 544 data 545 546 # Fine pts file to be clipped to area of interest 547 #------------------------------------------------------------------------------- 548 549 # filenames 550 coarsedemname = project.coarsedemname 551 finedemname = 552 project.finedemname meshname = project.meshname+'.msh' 553 554 # coarse data convert_dem_ 555 from_ascii2netcdf(coarsedemname, 556 use_cache=True, verbose=True) dem2pts(coarsedemname, use_cache=True, 557 verbose=True) 558 559 # fine data (clipping the points file to smaller area) 560 convert_dem_from_ascii2netcdf(finedemname, use_cache=True, 561 verbose=True) dem2pts(finedemname, 562 easting_min=project.eastingmin, 563 easting_max=project.eastingmax, 564 northing_min=project.northingmin, 565 northing_max= project.northingmax, 566 use_cache=True, 567 verbose=True) 568 569 570 # combining the coarse and fine data 571 combine_rectangular_points_files(project.finedemname + '.pts', 572 project.coarsedemname + '.pts', 573 project.combineddemname + '.pts') 574 575 576 #------------------------------------------------------------------------------- 577 # Create the triangular mesh based on overall clipping polygon with 578 a tagged # boundary and interior regions defined in project.py along 579 with # resolutions (maximal area of per triangle) for each polygon 580 #------------------------------------------------------------------------------- 581 582 #def get_polygon_from_file(filename): # fid = open(filename) # 583 lines = fid.readlines() # fid.close() 584 585 # polygon = [] # for line in lines[1:]: # fields = 586 line.split(',') # x = float(fields[3]) # y = 587 float(fields[4]) # polygon.append([x, y]) 588 589 # return interior_polygon 590 591 from pmesh.create_mesh import create_mesh_from_regions 592 593 num_polygons = 1 filelist = [] fileext = '.csv' filename = 594 project.polygonptsfile interior_res = 50000 595 596 for p in range(1, num_polygons+1): 597 thefilename = filename + str(p) + fileext 598 interior_polygon = get_polygon_from_file(thefilename) 599 interior_regions.append([interior_polygon, interior_res]) 600 601 # test #interior_regions = [[project.poly1, interior_res], # 602 [project.poly2, interior_res]] # original #interior_regions = 603 [[project.harbour_polygon_2, interior_res], # 604 [project.botanybay_polygon_2, interior_res]] 605 606 #FIXME: Fix caching of this one once the mesh_interface is ready 607 from caching import cache _ = cache(create_mesh_from_regions, 608 project.diffpolygonall, 609 {'boundary_tags': {'bottom': [0], 610 'right1': [1], 'right0': [2], 611 'right2': [3], 'top': [4], 'left1': [5], 612 'left2': [6], 'left3': [7]}, 613 'resolution': 100000, 614 'filename': meshname, 615 'interior_regions': interior_regions, 616 'UTM': True, 617 'refzone': project.refzone}, 618 verbose = True) 619 620 621 #------------------------------------------------------------------------------- 622 # Setup computational domain 623 #------------------------------------------------------------------------------- 624 625 domain = pmesh_to_domain_instance(meshname, Domain, 626 use_cache = True, 627 verbose = True) 628 629 print 'Number of triangles = ', len(domain) print 'The extent is ', 630 domain.get_extent() 631 632 domain.set_name(project.basename) 633 domain.set_datadir(project.outputdir) 634 domain.set_quantities_to_be_stored(['stage', 'xmomentum', 635 'ymomentum']) 636 637 638 #------------------------------------------------------------------------------- 639 # Set up scenario (tsunami_source is a callable object used with 640 set_quantity) 641 #------------------------------------------------------------------------------- 642 643 tsunami_source = slump_tsunami(length=30000.0, 644 depth=400.0, 645 slope=6.0, 646 thickness=176.0, 647 radius=3330, 648 dphi=0.23, 649 x0=project.slump_origin[0], 650 y0=project.slump_origin[1], 651 alpha=0.0, 652 domain=domain) 653 654 655 #------------------------------------------------------------------------------- 656 # Setup initial conditions 657 #------------------------------------------------------------------------------- 658 659 domain.set_quantity('stage', tsunami_source) 660 domain.set_quantity('friction', 0.03) # supplied by Benfield 661 domain.set_quantity('elevation', 662 filename = project.combineddemname + '.pts', 663 use_cache = True, 664 verbose = True) 665 666 667 #------------------------------------------------------------------------------- 668 # Setup boundary conditions (all reflective) 669 #------------------------------------------------------------------------------- 670 671 print 'Available boundary tags', domain.get_boundary_tags() 672 673 Br = Reflective_boundary(domain) domain.set_boundary( {'bottom': Br, 674 'right1': Br, 'right0': Br, 675 'right2': Br, 'top': Br, 'left1': Br, 676 'left2': Br, 'left3': Br} ) 677 678 679 #------------------------------------------------------------------------------- 680 # Evolve system through time 681 #------------------------------------------------------------------------------- 682 683 import time t0 = time.time() 684 685 for t in domain.evolve(yieldstep = 120, finaltime = 18000): 686 domain.write_time() 687 domain.write_boundary_statistics(tags = 'bottom') 688 689 print 'That took %.2f seconds' %(time.time()-t0) 690 691 \end{verbatim}} 692 693 Before discussing the details of this example, let us take a more 694 high-level perspective of the various tasks it undertakes. 695 696 If we compare this example with \code{bedslope.py}, the most 697 noticeable difference is that data is taken from a file. This is to 698 be expected, since the example now represents an actual physical 699 scenario rather than an illustrative example. 700 701 However, another important difference is that this example uses a 702 different method to create the mesh---one more suited to use for a 703 physical scenario. Instead of imposing a mesh structure on a 704 rectangular grid, the technique used for this example involves 705 building mesh structures inside polygons specified by the user. 706 707 In its simplest form, this technique creates the mesh within a 708 single polygon whose vertices are at geographical locations 709 specified by the user. A triangular mesh is created using points 710 inside the polygon selected through a random process, the user 711 specifying the \emph{resolution}---that is, the maximal area of a 712 triangle used for triangulation. 508 713 509 714 Figure XXX shows a simple example, in which the triangulation is … … 523 728 524 729 730 731 732 733 734 525 735 \chapter{\anuga Public Interface} 526 736 527 This chapter lists the functions and classes available at the public interface. 737 This chapter lists the functions and classes available at the public interface. 528 738 529 739 \section{Functions and Classes} … … 531 741 \indexedcodeheader{create_mesh_from_region} 532 742 533 Creates a triangular mesh based on a bounding polygon and 534 a number of internal polygons. For each polygon the user specifies a resolution---that is, the maximal area 535 of triangles in the mesh. The bounding polygon also has symbolic \code{tags} associated with it. 536 537 \textbf{Arguments:} 538 743 Creates a triangular mesh based on a bounding polygon and 744 a number of internal polygons. For each polygon the user specifies a resolution---that is, the maximal area 745 of triangles in the mesh. The bounding polygon also has symbolic \code{tags} associated with it. 746 747 \textbf{Arguments:} 748 539 749 \begin{itemize} 540 750 \item the bounding polygon, %do we need to spell out how a polygon is specified? 541 \item a dictionary of boundary tags, for all segments of the bounding polygon, 751 \item a dictionary of boundary tags, for all segments of the bounding polygon, 542 752 \emph{[not clear what the keys and values of this dictionary are]} 543 753 \item the resolution for the bounding polygon, 544 754 \item (optional) a filename, \emph{[what is the file for?]} 545 \item a list of 2-tuples \code{(polygon, resolution)}, specifying the interior polygons and 755 \item a list of 2-tuples \code{(polygon, resolution)}, specifying the interior polygons and 546 756 their associated resolutions. 547 757 \end{itemize} 548 549 758 759 550 760 \indexedcodeheader{pmesh_to_domain_instance} 551 761 552 Converts a generated mesh file to a domain object. 553 554 \textbf{Arguments:} 555 762 Converts a generated mesh file to a domain object. 763 764 \textbf{Arguments:} 765 556 766 \begin{itemize} 557 767 \item \code{file_name} is the name of the mesh file to convert, including the extension … … 560 770 \item \code{use_cache}: \code{True} means that caching is attempted for the computed domain. 561 771 \end{itemize} 562 563 772 773 564 774 \begin{itemize} 565 775 \item Mesh file name 566 \item Class name, specifying the domain class to be instantiated. 776 \item Class name, specifying the domain class to be instantiated. 567 777 \end{itemize} 568 569 \indexedcodeheader{file_function} %in util.py "High priority" 778 779 \indexedcodeheader{file_function} %in util.py "High priority" 570 780 571 781 Reads the time history of spatial data from NetCDF file and returns a callable object. 572 782 573 783 \textbf{Input variables:} 574 784 575 785 \code{filename} - Name of \code{sww} or \code{tms} file (see 576 786 Section \ref{sec:file formats} on page \pageref{sec:file formats} 577 787 for details about file formats). 578 788 579 789 \begin{quote} 580 790 If the file has extension \code{sww} then it is assumed to be spatio-temporal … … 589 799 \end{quote} 590 800 591 \code{domain} - Associated domain object 801 \code{domain} - Associated domain object 592 802 If domain is specified, model time (\code{domain.starttime}) 593 803 will be checked and possibly modified. 594 804 595 805 \begin{quote} 596 806 All times are assumed to be in UTC. 597 807 598 808 All spatial information is assumed to be in absolute UTM coordinates. 599 809 \end{quote} … … 601 811 \code{quantities} - the name of the quantity to be interpolated or a 602 812 list of quantity names. The resulting function will return 603 a tuple of values -- one for each quantity. 813 a tuple of values -- one for each quantity. 604 814 605 815 \code{interpolation_points} - list of absolute UTM coordinates for points at 606 816 which values are sought 607 817 608 818 \code{use_cache}: \code{True} means that caching of intermediate result of 609 819 \code{Interpolation_function} is attempted 610 820 611 612 % See Interpolation function for further documentation 821 822 % See Interpolation function for further documentation 613 823 \indexedcodeheader{Interpolation_function} 614 824 Creates a callable object \code{f(t, id)} or \code{f(t,x,y)} … … 617 827 618 828 Let $m$ be the number of vertices, $n$ the number of triangles 619 and $p$ the number of time steps. 829 and $p$ the number of time steps. 620 830 621 831 \textbf{Mandatory input:} 622 832 623 833 \begin{tabular}{ll} 624 834 \code{time}: & $p \times 1$ array of monotonously increasing times (Float)\\ 625 835 626 836 \code{quantities}: & Dictionary of arrays or one array (Float). The arrays must \\ 627 837 & have dimensions either $p \times m$ or $m \times 1$. The resulting function \\ … … 629 839 & in the latter case.\\ 630 840 \end{tabular} 631 632 841 842 633 843 \textbf{Optional input:} 634 844 635 845 \begin{tabular}{ll} 636 846 \code{quantity_names}: & List of keys into the quantities dictionary\\ 637 847 638 848 \code{vertex_coordinates}: & $m \times 2$ array of coordinates (Float)\\ 639 849 640 850 \code{triangles}: & $n \times 3$ array of indices into \code{vertex_coordinates} (Int)\\ 641 851 642 852 \code{interpolation_points}: & $N \times 2$ array of coordinates to be interpolated to \\ 643 853 644 854 \code{verbose}: & Level of reporting\\ 645 855 \end{tabular} 646 856 647 857 The quantities returned by the callable object are specified by 648 858 the list quantities which must contain the names of the … … 654 864 quantities are to be computed whenever the object is called. 655 865 If \code{None}, returns average value. 656 657 658 \indexedcodeheader{set_region} ``Low priority. Will be merged into set\_quantity'' 659 866 867 868 \indexedcodeheader{set_region} ``Low priority. Will be merged into set\_quantity'' 869 660 870 \indexedcodeheader{set_quantity} ``Pretty mature'' 661 871 662 872 \indexedcodeheader{set_boundary} ``Pretty mature'' 663 873 664 874 665 875 … … 755 965 \begin{array}{ccr} 756 966 2 & 4 & 4\\ 757 1 & 1 & 1 758 \end{array} 967 1 & 1 & 1 968 \end{array} 759 969 \right] 760 970 \] … … 825 1035 \section{caching} 826 1036 827 The \code{cache} function is used to provide supervised caching of function results. A Python 1037 The \code{cache} function is used to provide supervised caching of function results. A Python 828 1038 function call of the form 829 1039 … … 838 1048 result = cache(func,(arg1,...,argn)) 839 1049 \end{verbatim}} 840 1050 841 1051 which returns the same output but reuses cached 842 1052 results if the function has been computed previously in the same context. 843 1053 \code{result} and the arguments can be simple types, tuples, list, dictionaries or 844 objects, but not unhashable types such as functions or open file objects. 1054 objects, but not unhashable types such as functions or open file objects. 845 1055 The function \code{func} may be a member function of an object or a module. 846 1056 … … 852 1062 If the function definition changes after a result has been cached it will be 853 1063 detected by examining the functions \code{bytecode (co_code, co_consts, 854 func_defualts, co_argcount)} and it will be recomputed. 855 856 Options are set 857 by means of the function \code{set_option(key, value)}, where \code{key} is a key associated with a 858 Python dictionary \code{options} that stores settings such as the name of the directory used, the maximum 1064 func_defualts, co_argcount)} and it will be recomputed. 1065 1066 Options are set 1067 by means of the function \code{set_option(key, value)}, where \code{key} is a key associated with a 1068 Python dictionary \code{options} that stores settings such as the name of the directory used, the maximum 859 1069 number of cached files allowed, and so on. 860 1070 861 1071 The \code{cache} function allows the user also to specify a list of dependent files. If any of these 862 1072 have been changed, the function is recomputed and the results stored again. 863 1073 864 1074 Other features include support for compression and a capability to \ldots 865 1075 866 1076 867 1077 \textbf{USAGE:} 868 1078 869 1079 {\scriptsize \begin{verbatim} 870 1080 result = cache(func, args, kwargs, dependencies, cachedir, verbose, … … 873 1083 874 1084 \textbf{ARGUMENTS:} 875 1085 876 1086 \begin{tabular}{ll} 877 1087 \code{func} & Function object (Required)\\ 878 1088 \code{args} & Arguments to func (Default: ())\\ 879 \code{kwargs} & Keyword arguments to func (Default: {}) \\ 1089 \code{kwargs} & Keyword arguments to func (Default: {}) \\ 880 1090 \code{dependencies} & Filenames that func depends on (Default: \code{None})\\ 881 1091 \code{cachedir} & Directory for cache files (Default: \code{options['cachedir']})\\ … … 885 1095 \code{evaluate} & Flag forced evaluation of func (Default: 0)\\ 886 1096 \code{test} & Flag test for cached results (Default: 0)\\ 887 \code{clear} & Flag delete cached results (Default: 0)\\ 888 \code{return_filename} & Flag return of cache filename (Default: 0)\\ 1097 \code{clear} & Flag delete cached results (Default: 0)\\ 1098 \code{return_filename} & Flag return of cache filename (Default: 0)\\ 889 1099 \end{tabular} 890 1100 891 1101 892 1102 \textbf{LIMITATIONS:} 893 1103 894 1104 \begin{itemize} 895 1105 \item Caching uses the apply function and will work with anything that can be 896 pickled, so any limitation in apply or pickle extends to caching. 897 1106 pickled, so any limitation in apply or pickle extends to caching. 1107 898 1108 \item A function to be cached should not depend on global variables 899 1109 as wrong results may occur if globals are changed after a result has … … 901 1111 \end{itemize} 902 1112 903 1113 904 1114 905 1115 … … 1055 1265 \item \indexedbold{resolution} refers to the maximal area of each triangular cell in the mesh 1056 1266 1057 \item \indexedbold{polygon} A sequence of points in the plane. (Arbitrary polygons can be created 1267 \item \indexedbold{polygon} A sequence of points in the plane. (Arbitrary polygons can be created 1058 1268 in this way ) 1059 ANUGA represents polygons as either a list of 2-tuples, where the latter are either Python tuples 1060 or Python lists of length 2. The unit square, for example, would be represented by the polygon 1061 [ [0,0], [1,0], [1,1], [0,1] ]. Alternatively, polygons can be represented as $N \times 2$ Numeric 1269 ANUGA represents polygons as either a list of 2-tuples, where the latter are either Python tuples 1270 or Python lists of length 2. The unit square, for example, would be represented by the polygon 1271 [ [0,0], [1,0], [1,1], [0,1] ]. Alternatively, polygons can be represented as $N \times 2$ Numeric 1062 1272 arrays, where $N$ is the number of points. 1063 1273
Note: See TracChangeset
for help on using the changeset viewer.