boundary_marker = False dt = Constant(0) dt.assign(np.min([fenics_dt, precice_dt])) # Define variational problem u = TrialFunction(V) v = TestFunction(V) f = Expression('beta + gamma*x[0]*x[0] - 2*gamma*t - 2*(1-gamma) - 2*alpha', degree=2, alpha=alpha, beta=beta, gamma=gamma, t=0) F = u * v / dt * dx + dot(grad(u), grad(v)) * dx - (u_n / dt + f) * v * dx bcs = [DirichletBC(V, u_D, remaining_boundary)] # Set boundary conditions at coupling interface once wrt to the coupling expression coupling_expression = precice.create_coupling_expression() if problem is ProblemType.DIRICHLET: # modify Dirichlet boundary condition on coupling interface bcs.append(DirichletBC(V, coupling_expression, coupling_boundary)) if problem is ProblemType.NEUMANN: # modify Neumann boundary condition on coupling interface, modify weak form correspondingly if not boundary_marker: # there is only 1 Neumann-BC which is at the coupling boundary -> integration over whole boundary if coupling_expression.is_scalar_valued(): F += v * coupling_expression * dolfin.ds # this term has to be added to weak form to add a Neumann BC (see e.g. p. 83ff Langtangen, Hans Petter, and Anders Logg. "Solving PDEs in Python The FEniCS Tutorial Volume I." (2016).) elif coupling_expression.is_vector_valued(): normal = FacetNormal(mesh) F += -v * dot(normal, coupling_expression) * dolfin.ds else: raise Exception("invalid!") else: # For multiple Neumann BCs integration should only be performed over the respective domain. # TODO: fix the problem here
u = TrialFunction(V) v = TestFunction(V) u_n = Function(V) if args.source: u_ini = Expression("1", degree=1) bc = DirichletBC(V, u_ini, AllBoundary()) elif args.drain: u_ini = Expression("0", degree=1) bc = DirichletBC(V, u_ini, RightBoundary()) u_n = interpolate(u_ini, V) dt = precice.initialize(AllDomain(), read_function_space=V, write_object=u_n) volume_term = precice.create_coupling_expression() f = Function(V) dt_inv = Constant(1 / dt) diffusion_source = 1 diffusion_drain = 1 if args.source: F = dt_inv * (u - u_n) * v * dx - (f - u_ini) * v * dx + diffusion_source * inner(grad(u), grad(v)) * dx elif args.drain: F = dt_inv * (u - u_n) * v * dx - (f - u) * v * dx + diffusion_drain * inner(grad(u), grad(v)) * dx # Time-stepping u_np1 = Function(V) if args.source: