mesh = BoxMesh(60, 80, 80, 3.0, 4.0, 4.0) # If using a PML, then the z coordinates needs to be negative, # and on the -x and -y sides of the domain, the PML region must have negative coordinates. mesh.coordinates.dat.data[:, 0] -= 3.0 mesh.coordinates.dat.data[:, 1] -= 1.0 mesh.coordinates.dat.data[:, 2] -= 1.0 comm = spyro.utils.mpi_init(model) element = spyro.domains.space.FE_method( mesh, model["opts"]["method"], model["opts"]["degree"] ) V = FunctionSpace(mesh, element) if comm.comm.rank == 0: print("There are " + str(V.dim()) + " degrees of freedom", flush=True) sources = spyro.Sources(model, mesh, V, comm).create() receivers = spyro.Receivers(model, mesh, V, comm).create() vp = Function(V, name="velocity").assign(1.5) t1 = time.time() p_field, p_at_recv = spyro.solvers.Leapfrog( model, mesh, comm, vp, sources, receivers,
def run(steady=False): """ solve CdT/dt = S + div(k*grad(T)) => C*v*(dT/dt)/k*dx - S*v/k*dx + grad(v)*grad(T)*dx = v*dot(grad(T), n)*ds """ steps = 250 dt = 1e-10 timescale = (0, steps * dt) if steady: print('Running steady state.') else: print(f'Running with time step {dt:.2g}s on time interval: ' f'{timescale[0]:.2g}s - {timescale[1]:.2g}s') dt_invc = Constant(1 / dt) extent = [40e-6, 40e-6, 40e-6] mesh = BoxMesh(20, 20, 20, *extent) V = FunctionSpace(mesh, 'CG', 1) print(V.dim()) T = Function(V) # temperature at time i+1 (electron for now) T_ = Function(V) # temperature at time i v = TestFunction(V) # test function S = create_S(mesh, V, extent) C = create_heat_capacity(mesh, V, extent) k = create_conductivity(mesh, V, T) set_initial_value(mesh, T_, extent) # Mass matrix section M = C * T * dt_invc * v * dx M_ = C * T_ * dt_invc * v * dx # Stiffness matrix section A = k * dot(grad(T), grad(v)) * dx # function section f = S * v * dx # boundaries bcs, R, b = create_dirichlet_bounds(mesh, V, T, v, k, g=100, boundary=[1, 2, 3, 4, 5, 6]) # bcs += create_dirichlet_bounds(mesh, V, T, v, k, 500, [6])[0] # bcs, R, b = create_robin_bounds(mesh, T, v, k, 1e8/(100), 1e8) if steady: steps = 1 a = A + R L = f + b else: a = M + A + R L = M_ + f + b prob = NonlinearVariationalProblem(a - L, T, bcs=bcs) solver = NonlinearVariationalSolver(prob, solver_parameters=SOLVE_PARAMS) T.assign(T_) timestamp = datetime.now().strftime("%d-%b-%Y-%H-%M-%S") outfile = File(f'{timestamp}/first_output.pvd') outfile.write(T_, target_degree=1, target_continuity=H1) last_perc = 0 for i in range(steps): solver.solve() perc = int(100 * (i + 1) / steps) if perc > last_perc: print(f'{perc}%') last_perc = perc T_.assign(T) outfile.write(T_, target_degree=1, target_continuity=H1)