[195] | 1 | """Example using the module for solving the advection equation |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | Initial condition is zero, boundary conditions are transmissive everywhere except |
---|
| 5 | for three segments where three different time dependent conditions are applied. |
---|
| 6 | """ |
---|
| 7 | import sys |
---|
| 8 | from os import sep |
---|
| 9 | sys.path.append('..'+sep+'pyvolution') |
---|
| 10 | |
---|
| 11 | from mesh_factory import rectangular |
---|
| 12 | from advection import Domain, Transmissive_boundary, Dirichlet_boundary, Time_boundary |
---|
| 13 | |
---|
| 14 | #Create basic mesh |
---|
| 15 | points, vertices, boundary = rectangular(20, 4) |
---|
| 16 | |
---|
| 17 | #Create advection domain |
---|
| 18 | # - Initial condition is zero by default |
---|
| 19 | domain = Domain(points, vertices, boundary, velocity=[1.0, -0.8]) |
---|
| 20 | #domain.smooth = False |
---|
| 21 | domain.visualise = True |
---|
| 22 | |
---|
| 23 | #Boundaries |
---|
| 24 | T = Transmissive_boundary(domain) |
---|
| 25 | D = Dirichlet_boundary([0.1]) |
---|
| 26 | |
---|
| 27 | from math import sin, pi |
---|
| 28 | T1 = Time_boundary(domain, f=lambda x: [0.2*(sin(2*x*pi)+1)/2]) |
---|
| 29 | T2 = Time_boundary(domain, f=lambda x: [0.2*(sin(4*x*pi)+1)/3]) |
---|
| 30 | T3 = Time_boundary(domain, f=lambda x: [0.2*(sin(6*x*pi)+1)/4]) |
---|
| 31 | |
---|
| 32 | #Modify boundary tags |
---|
| 33 | domain.boundary[(7, 1)] = 't1' |
---|
| 34 | domain.boundary[(5, 2)] = 't2' |
---|
| 35 | domain.boundary[(3, 2)] = 't3' |
---|
| 36 | |
---|
| 37 | domain.set_boundary( {'left': T, 'right': T, 'bottom': T, 'top': T, |
---|
| 38 | 't1': T1, 't2': T2, 't3': T3} ) |
---|
| 39 | domain.check_integrity() |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | ################### |
---|
| 43 | # Evolution |
---|
| 44 | for t in domain.evolve(yieldstep = 0.02, finaltime = None): |
---|
| 45 | domain.write_time() |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | |
---|