Changeset 4883
- Timestamp:
- Dec 11, 2007, 6:48:46 PM (16 years ago)
- Location:
- anuga_core
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/documentation/user_manual/demos/runup.py
r4551 r4883 10 10 #------------------------------------------------------------------------------ 11 11 12 from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular 12 from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross 13 13 from anuga.shallow_water import Domain 14 14 from anuga.shallow_water import Reflective_boundary … … 22 22 #------------------------------------------------------------------------------ 23 23 24 points, vertices, boundary = rectangular (10, 10) # Basic mesh24 points, vertices, boundary = rectangular_cross(10, 10,len1=1.0, len2= 1.0 ) # Basic mesh 25 25 26 26 domain = Domain(points, vertices, boundary) # Create domain … … 37 37 38 38 def topography(x,y): 39 return -x/2 # linear bed slope39 return -x/2 # linear bed slope 40 40 #return x*(-(2.0-x)*.5) # curved bed slope 41 41 … … 54 54 Bd = Dirichlet_boundary([-0.2,0.,0.]) # Constant boundary values 55 55 Bw = Time_boundary(domain=domain, # Time dependent boundary 56 f=lambda t: [(.1*sin(t*2*pi)-0.3) * exp(-t), 0.0, 0.0])56 f=lambda t: [(.1*sin(t*2*pi)-0.3) , 0.0, 0.0]) 57 57 58 58 # Associate boundary tags with boundary objects 59 59 domain.set_boundary({'left': Br, 'right': Bw, 'top': Br, 'bottom': Br}) 60 60 61 #=============================================================================== 62 from anuga.visualiser import RealtimeVisualiser 63 vis = RealtimeVisualiser(domain) 64 vis.render_quantity_height("elevation", zScale=1.0, dynamic=False) 65 vis.render_quantity_height("stage", dynamic=True) 66 vis.colour_height_quantity('stage', (lambda q:q['stage'], -0.5, 0.5)) 67 vis.start() 68 #=============================================================================== 61 69 70 import time 71 t0 = time.time() 62 72 #------------------------------------------------------------------------------ 63 73 # Evolve system through time … … 66 76 for t in domain.evolve(yieldstep = 0.1, finaltime = 10.0): 67 77 domain.write_time() 68 78 vis.update() 69 79 80 vis.evolveFinished() 81 print 'That took %.2f seconds' %(time.time()-t0) 70 82 -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r4872 r4883 1327 1327 def extrapolate_first_order(self): 1328 1328 """Extrapolate conserved quantities from centroid to 1329 vertices for each volume using1329 vertices and edges for each volume using 1330 1330 first order scheme. 1331 1331 """ … … 1333 1333 qc = self.centroid_values 1334 1334 qv = self.vertex_values 1335 qe = self.edge_values 1335 1336 1336 1337 for i in range(3): 1337 1338 qv[:,i] = qc 1339 qe[:,i] = qc 1338 1340 1339 1341 … … 1391 1393 return compute_gradients(self) 1392 1394 1395 1393 1396 def limit(self): 1394 #Call correct module function 1395 #(either from this module or C-extension) 1396 limit(self) 1397 #Call correct module depending on whether 1398 #basing limit calculations on edges or vertices 1399 limit_old(self) 1400 1401 1402 ## def limit_by_vertex(self): 1403 ## #Call correct module function 1404 ## #(either from this module or C-extension) 1405 ## limit_by_vertex() 1406 1407 1408 ## def limit_by_edge(self): 1409 ## #Call correct module function 1410 ## #(either from this module or C-extension) 1411 ## limit_by_edge() 1397 1412 1398 1413 def extrapolate_second_order(self): … … 1400 1415 #(either from this module or C-extension) 1401 1416 extrapolate_second_order(self) 1417 1402 1418 1403 1419 def backup_centroid_values(self): … … 1417 1433 # Underlying C implementations can be accessed 1418 1434 1419 from quantity_ext import average_vertex_values, backup_centroid_values, \ 1420 saxpy_centroid_values 1421 1422 from quantity_ext import compute_gradients, limit,\ 1423 extrapolate_second_order, interpolate_from_vertices_to_edges, update 1435 from quantity_ext import \ 1436 average_vertex_values,\ 1437 backup_centroid_values,\ 1438 saxpy_centroid_values,\ 1439 compute_gradients,\ 1440 limit_old,\ 1441 extrapolate_second_order,\ 1442 interpolate_from_vertices_to_edges,\ 1443 update 1424 1444 else: 1425 1445 msg = 'C implementations could not be accessed by %s.\n ' %__file__ -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity_ext.c
r4769 r4883 98 98 double* vertex_coordinates, 99 99 double* vertex_values, 100 double* edge_values, 100 101 double* a, 101 102 double* b) { … … 125 126 vertex_values[k3+1] = centroid_values[k] + a[k]*(x1-x) + b[k]*(y1-y); 126 127 vertex_values[k3+2] = centroid_values[k] + a[k]*(x2-x) + b[k]*(y2-y); 128 129 130 edge_values[k3+0] = 0.5*(vertex_values[k3 + 1]+vertex_values[k3 + 2]); 131 edge_values[k3+1] = 0.5*(vertex_values[k3 + 2]+vertex_values[k3 + 0]); 132 edge_values[k3+2] = 0.5*(vertex_values[k3 + 0]+vertex_values[k3 + 1]); 127 133 128 134 } … … 595 601 PyObject *quantity, *domain; 596 602 PyArrayObject 597 *centroids, //Coordinates at centroids 598 *centroid_values, //Values at centroids 599 *vertex_coordinates, //Coordinates at vertices 600 *vertex_values, //Values at vertices 601 *number_of_boundaries, //Number of boundaries for each triangle 602 *surrogate_neighbours, //True neighbours or - if one missing - self 603 *a, *b; //Gradients 603 *centroids, //Coordinates at centroids 604 *centroid_values, //Values at centroids 605 *vertex_coordinates, //Coordinates at vertices 606 *vertex_values, //Values at vertices 607 *edge_values, //Values at edges 608 *number_of_boundaries, //Number of boundaries for each triangle 609 *surrogate_neighbours, //True neighbours or - if one missing - self 610 *a, *b; //Gradients 604 611 605 612 //int N, err; … … 622 629 623 630 // Get pertinent variables 624 centroids = get_consecutive_array(domain, "centroid_coordinates"); 625 centroid_values = get_consecutive_array(quantity, "centroid_values"); 626 surrogate_neighbours = get_consecutive_array(domain, "surrogate_neighbours"); 627 number_of_boundaries = get_consecutive_array(domain, "number_of_boundaries"); 628 vertex_coordinates = get_consecutive_array(domain, "vertex_coordinates"); 629 vertex_values = get_consecutive_array(quantity, "vertex_values"); 631 centroids = get_consecutive_array(domain, "centroid_coordinates"); 632 centroid_values = get_consecutive_array(quantity, "centroid_values"); 633 surrogate_neighbours = get_consecutive_array(domain, "surrogate_neighbours"); 634 number_of_boundaries = get_consecutive_array(domain, "number_of_boundaries"); 635 vertex_coordinates = get_consecutive_array(domain, "vertex_coordinates"); 636 vertex_values = get_consecutive_array(quantity, "vertex_values"); 637 edge_values = get_consecutive_array(quantity, "edge_values"); 630 638 631 639 N = centroid_values -> dimensions[0]; … … 665 673 (double*) vertex_coordinates -> data, 666 674 (double*) vertex_values -> data, 675 (double*) edge_values -> data, 667 676 (double*) a -> data, 668 677 (double*) b -> data); … … 684 693 Py_DECREF(vertex_coordinates); 685 694 Py_DECREF(vertex_values); 695 Py_DECREF(edge_values); 686 696 Py_DECREF(a); 687 697 Py_DECREF(b); … … 692 702 693 703 694 PyObject *limit (PyObject *self, PyObject *args) {704 PyObject *limit_old(PyObject *self, PyObject *args) { 695 705 //Limit slopes for each volume to eliminate artificial variance 696 706 //introduced by e.g. second order extrapolator … … 707 717 PyObject *quantity, *domain, *Tmp; 708 718 PyArrayObject 709 710 711 719 *qv, //Conserved quantities at vertices 720 *qc, //Conserved quantities at centroids 721 *neighbours; 712 722 713 723 int k, i, n, N, k3; … … 718 728 if (!PyArg_ParseTuple(args, "O", &quantity)) { 719 729 PyErr_SetString(PyExc_RuntimeError, 720 "quantity_ext.c: limit could not parse input");730 "quantity_ext.c: limit_old could not parse input"); 721 731 return NULL; 722 732 } … … 725 735 if (!domain) { 726 736 PyErr_SetString(PyExc_RuntimeError, 727 "quantity_ext.c: limit could not obtain domain object from quantity");737 "quantity_ext.c: limit_old could not obtain domain object from quantity"); 728 738 729 739 return NULL; … … 737 747 if (!Tmp) { 738 748 PyErr_SetString(PyExc_RuntimeError, 739 "quantity_ext.c: limit could not obtain beta_w object from domain");749 "quantity_ext.c: limit_old could not obtain beta_w object from domain"); 740 750 741 751 return NULL; … … 777 787 778 788 // Call underlying routine 779 _limit (N, beta_w, (double*) qc -> data, (double*) qv -> data, qmin, qmax);789 _limit_old(N, beta_w, (double*) qc -> data, (double*) qv -> data, qmin, qmax); 780 790 781 791 free(qmin); … … 788 798 // Method table for python module 789 799 static struct PyMethodDef MethodTable[] = { 790 {"limit ", limit, METH_VARARGS, "Print out"},800 {"limit_old", limit_old, METH_VARARGS, "Print out"}, 791 801 {"update", update, METH_VARARGS, "Print out"}, 792 802 {"backup_centroid_values", backup_centroid_values, METH_VARARGS, "Print out"}, -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r4779 r4883 107 107 108 108 #print quantity.vertex_values 109 #assert allclose(quantity.vertex_values, [[2., 2., 2.], 110 # [3.+2./3, 6.+2./3, 4.+2./3], 111 # [7.5, 0.5, 1.], 112 # [-5, -2.5, 7.5]]) 113 114 assert allclose(quantity.vertex_values[1,:],[3.+2./3, 6.+2./3, 4.+2./3]) 115 #FIXME: Work out the others 116 109 assert allclose(quantity.vertex_values, [[3.5, -1.0, 3.5], 110 [3.+2./3, 6.+2./3, 4.+2./3], 111 [4.6, 3.4, 1.], 112 [-5.0, 1.0, 4.0]]) 117 113 118 114 #print quantity.edge_values 119 assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5], 120 [5., 5., 5.], 121 [4.5, 4.5, 0.], 122 [3.0, -1.5, -1.5]]) 115 assert allclose(quantity.edge_values, [[1.25, 3.5, 1.25], 116 [5. + 2/3.0, 4.0 + 1.0/6, 5.0 + 1.0/6], 117 [2.2, 2.8, 4.0], 118 [2.5, -0.5, -2.0]]) 119 120 121 #assert allclose(quantity.edge_values, [[2.5, 2.0, 1.5], 122 # [5., 5., 5.], 123 # [4.5, 4.5, 0.], 124 # [3.0, -1.5, -1.5]]) 123 125 124 126 def test_get_extrema_1(self): -
anuga_core/source/anuga/shallow_water/shallow_water_ext.c
r4834 r4883 2416 2416 2417 2417 // Call underlying standard routine 2418 _limit (N, beta_h, (double*) hc -> data, (double*) hvbar -> data, hmin, hmax);2418 _limit_old(N, beta_h, (double*) hc -> data, (double*) hvbar -> data, hmin, hmax); 2419 2419 2420 2420 // // //Py_DECREF(domain); //FIXME: Necessary? -
anuga_core/source/anuga/utilities/util_ext.h
r2508 r4883 132 132 133 133 134 void _limit(int N, double beta, double* qc, double* qv, 134 void _limit_old(int N, double beta, double* qc, double* qv, 135 double* qmin, double* qmax) { 136 137 //N are the number of elements 138 int k, i, k3; 139 double dq, dqa[3], phi, r; 140 141 //printf("INSIDE\n"); 142 for (k=0; k<N; k++) { 143 k3 = k*3; 144 145 //Find the gradient limiter (phi) across vertices 146 phi = 1.0; 147 for (i=0; i<3; i++) { 148 r = 1.0; 149 150 dq = qv[k3+i] - qc[k]; //Delta between vertex and centroid values 151 dqa[i] = dq; //Save dq for use in the next loop 152 153 if (dq > 0.0) r = (qmax[k] - qc[k])/dq; 154 if (dq < 0.0) r = (qmin[k] - qc[k])/dq; 155 156 157 phi = min( min(r*beta, 1.0), phi); 158 } 159 160 //Then update using phi limiter 161 for (i=0; i<3; i++) { 162 qv[k3+i] = qc[k] + phi*dqa[i]; 163 } 164 } 165 } 166 167 168 void _limit_by_edge(int N, double beta, double* qc, double* qv, 169 double* qmin, double* qmax) { 170 171 //N are the number of elements 172 int k, i, k3; 173 double dq, dqa[3], phi, r; 174 175 //printf("INSIDE\n"); 176 for (k=0; k<N; k++) { 177 k3 = k*3; 178 179 //Find the gradient limiter (phi) across vertices 180 phi = 1.0; 181 for (i=0; i<3; i++) { 182 r = 1.0; 183 184 dq = qv[k3+i] - qc[k]; //Delta between vertex and centroid values 185 dqa[i] = dq; //Save dq for use in the next loop 186 187 if (dq > 0.0) r = (qmax[k] - qc[k])/dq; 188 if (dq < 0.0) r = (qmin[k] - qc[k])/dq; 189 190 191 phi = min( min(r*beta, 1.0), phi); 192 } 193 194 //Then update using phi limiter 195 for (i=0; i<3; i++) { 196 qv[k3+i] = qc[k] + phi*dqa[i]; 197 } 198 } 199 } 200 201 void _limit_by_vertex(int N, double beta, double* qc, double* qv, 135 202 double* qmin, double* qmax) { 136 203
Note: See TracChangeset
for help on using the changeset viewer.