- Timestamp:
- Sep 20, 2009, 6:35:14 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/domain.py
r7498 r7519 65 65 boundary=None, 66 66 conserved_quantities=None, 67 evolved_quantities=None, 67 68 other_quantities=None, 68 69 tagged_elements=None, … … 90 91 conserved_quantities: List of quantity names entering the 91 92 conservation equations 93 evolved_quantities: List of all quantities that evolve 92 94 other_quantities: List of other quantity names 93 95 … … 154 156 self.conserved_quantities = conserved_quantities 155 157 158 if evolved_quantities is None: 159 self.evolved_quantities = self.conserved_quantities 160 else: 161 self.evolved_quantities = evolved_quantities 162 156 163 # List of other quantity names 157 164 if other_quantities is None: … … 160 167 self.other_quantities = other_quantities 161 168 169 # Test that conserved_quantities are stored in the first entries of evolved_quantities 170 for i, quantity in enumerate(self.conserved_quantities): 171 msg = 'The conserved quantities must be the first entries of evolved_quantities' 172 assert quantity == self.evolved_quantities[i], msg 173 174 162 175 # Build dictionary of Quantity instances keyed by quantity names 163 176 self.quantities = {} 164 177 165 for name in self. conserved_quantities:178 for name in self.evolved_quantities: 166 179 self.quantities[name] = Quantity(self) 167 180 for name in self.other_quantities: … … 325 338 return self.mesh.get_number_of_nodes(*args, **kwargs) 326 339 340 def get_number_of_triangles(self, *args, **kwargs): 341 return self.mesh.get_number_of_triangles(*args, **kwargs) 342 327 343 def get_normal(self, *args, **kwargs): 328 344 return self.mesh.get_normal(*args, **kwargs) … … 415 431 416 432 return q 433 434 ## 435 # @brief Get evolved quantities for a volume. 436 # @param vol_id ID of the volume we want the conserved quantities for. 437 # @param vertex If specified, use as index for edge values. 438 # @param edge If specified, use as index for edge values. 439 # @return Vector of conserved quantities. 440 # @note If neither 'vertex' or 'edge' specified, use centroid values. 441 # @note If both 'vertex' and 'edge' specified, raise exception. 442 def get_evolved_quantities(self, vol_id, 443 vertex=None, 444 edge=None): 445 """Get evolved quantities at volume vol_id. 446 447 If vertex is specified use it as index for vertex values 448 If edge is specified use it as index for edge values 449 If neither are specified use centroid values 450 If both are specified an exeception is raised 451 452 Return value: Vector of length == number_of_conserved quantities 453 """ 454 455 if not (vertex is None or edge is None): 456 msg = 'Values for both vertex and edge was specified.' 457 msg += 'Only one (or none) is allowed.' 458 raise Exception, msg 459 460 q = num.zeros(len(self.evolved_quantities), num.float) 461 462 for i, name in enumerate(self.evolved_quantities): 463 Q = self.quantities[name] 464 if vertex is not None: 465 q[i] = Q.vertex_values[vol_id, vertex] 466 elif edge is not None: 467 q[i] = Q.edge_values[vol_id, edge] 468 else: 469 q[i] = Q.centroid_values[vol_id] 470 471 return q 472 473 ## 474 # @brief 475 # @param flag 476 def set_CFL(self, cfl=1.0): 477 """Set CFL parameter, warn if greater than 1.0 478 """ 479 if cfl > 1.0: 480 self.CFL = cfl 481 log.warn('Setting CFL > 1.0') 482 483 assert cfl > 0.0 484 self.CFL = cfl 485 486 417 487 418 488 ## … … 876 946 assert quantity in self.quantities, msg 877 947 878 ##assert hasattr(self, 'boundary_objects') 948 949 for i, quantity in enumerate(self.conserved_quantities): 950 msg = 'Conserved quantities must be the first entries of evolved_quantities' 951 assert quantity == self.evolved_quantities[i], msg 952 879 953 880 954 ## … … 1654 1728 1655 1729 ## 1656 # @brief Backup conserved quantities .1730 # @brief Backup conserved quantities 1657 1731 def backup_conserved_quantities(self): 1658 N = len(self) # Number_of_triangles1659 1732 1660 1733 # Backup conserved_quantities centroid values … … 1664 1737 1665 1738 ## 1666 # @brief ??1667 # @param a ??1668 # @param b ??1739 # @brief Combines current C and saved centroid values S as C = aC + bS 1740 # @param a factor in combination 1741 # @param b factor in combination 1669 1742 def saxpy_conserved_quantities(self, a, b): 1670 N = len(self) #number_of_triangles1671 1743 1672 1744 # Backup conserved_quantities centroid values … … 1675 1747 Q.saxpy_centroid_values(a, b) 1676 1748 1749 1750 1751 1752 ## 1753 # @brief Mapping between conserved quantites and evolved quantities 1754 # @param q_cons array of conserved quantity values 1755 # @param q_evolved array of current evolved quantity values 1756 def conserved_to_evolved(self, q_cons, q_evolved): 1757 """Needs to be overridden by Domain subclass 1758 """ 1759 1760 if len(q_cons) == len(q_evolved): 1761 q_evolved[:] = q_cons 1762 else: 1763 msg = 'Method conserved_to_evolved must be overridden by Domain subclass' 1764 raise Exception, msg 1765 1677 1766 ## 1678 1767 # @brief Update boundary values for all conserved quantities. … … 1692 1781 log.critical('WARNING: Ignored boundary segment (None)') 1693 1782 else: 1694 q = B.evaluate(vol_id, edge_id) 1695 1696 for j, name in enumerate(self.conserved_quantities): 1783 q_cons = B.evaluate(vol_id, edge_id) 1784 1785 if len(q_cons) == len(self.evolved_quantities): 1786 # conserved and evolved quantities are the same 1787 q_evol = q_cons 1788 elif len(q_cons) == len(self.conserved_quantities): 1789 # boundary just returns conserved quantities 1790 # Need to calculate all the evolved quantities 1791 # Use default conversion 1792 1793 q_evol = self.get_evolved_quantities(vol_id, edge = edge_id) 1794 1795 self.conserved_to_evolved(q_cons, q_evol) 1796 else: 1797 msg = 'Boundary must return array of either conserved or evolved quantities' 1798 raise Exception, msg 1799 1800 for j, name in enumerate(self.evolved_quantities): 1697 1801 Q = self.quantities[name] 1698 Q.boundary_values[i] = q [j]1802 Q.boundary_values[i] = q_evol[j] 1699 1803 1700 1804 ##
Note: See TracChangeset
for help on using the changeset viewer.