13.07.2015 Views

Part II Implementation - FEniCS Project

Part II Implementation - FEniCS Project

Part II Implementation - FEniCS Project

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Susanne Hentschel, Svein Linge, Emil Alf Løvgren and Kent-Andre Mardaldef area(self, i):f = Constant(self.mesh, 1)A = f*ds(i)a = assemble(A, exterior_facet_domains=self.sub_domains)return aObject Functions. Being a subclass of ProblemBase, Problem overrides theobject functions update and functional. The first ensures that all time–dependent variables are updated for the current time step. The latter printsthe maximum values for pressure and velocity. The normal flux through theboundaries is defined in the separate function flux.def update(self, t, u, p):self.g1.t = tself.g2.t = tpassdef functional(self, t, u, p):v_max = u.vector().norm(linf)f0 = self.flux(0,u)f1 = self.flux(1,u)f2 = self.flux(2,u)pressure_at_peak_v = p.vector()[0]print "time ", tprint "max value of u ", v_maxprint "max value of p ", p.vector().norm(linf)print "CFL = ", v_max * self.dt / self.h.min()print "flux through top ", f1print "flux through bottom ", f2# if current velocity is peakif v_max > self.peak_v:self.peak_v = v_maxprint pressure_at_peak_vself.pressure_at_peak_v = pressure_at_peak_vreturn pressure_at_peak_vdef flux(self, i, u):n = FacetNormal(self.mesh)A = dot(u,n)*ds(i)a = assemble(A, exterior_facet_domains=self.sub_domains)return aThe boundaryconditionsare all given asDirichlet conditions, associated withtheir velocity function space and the belonging sub domain. The additional functionsboundary conditions and initial conditions define the respectiveconditions for the problem that are called by the solver. Boundary conditions forvelocity, pressure and psi (???) are collected in the lists bcv, bcp and bcpsi.def boundary_conditions(self, V, Q):# Create no-slip boundary condition for velocityself.g0 = Constant(self.mesh, (0.0, 0.0, 0.0))bc0 = DirichletBC(V, self.g0, self.contour)# create function for inlet and outlet BC229

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!