def report(self, t): (v, b1, u, b2, p) = self.w.split() v.rename("v", "velocity") u.rename("u", "displacement") p.rename("p", "pressure") self.vfile.write(v, t) self.ufile.write(u, t) self.pfile.write(p, t) P = assemble(self.p * ds(_OUTFLOW)) / gW PI = assemble(abs(jump(self.p)) * dS(_FSI)) # Compute drag and lift force = dot(self.S_f, self.n) D_C = -assemble(force[0] * dss(_FLUID_CYLINDER)) L_C = -assemble(force[1] * dss(_FLUID_CYLINDER)) w_ = Function(self.W) Fbc = DirichletBC(self.W.sub(0), Constant((1.0, 0.0)), self.interface, _FSI) Fbc.apply(w_.vector()) D_F = -assemble(action(self.F_fluid, w_)) w_ = Function(self.W) Fbc = DirichletBC(self.W.sub(0), Constant((0.0, 1.0)), self.interface, _FSI) Fbc.apply(w_.vector()) L_F = -assemble(action(self.F_fluid, w_)) w_ = Function(self.W) Fbc = DirichletBC(self.W.sub(0), Constant((1.0, 0.0)), self.interface, _FSI) Fbc.apply(w_.vector()) D_S = assemble(action(self.F_solid, w_)) w_ = Function(self.W) Fbc = DirichletBC(self.W.sub(0), Constant((0.0, 1.0)), self.interface, _FSI) Fbc.apply(w_.vector()) L_S = assemble(action(self.F_solid, w_)) w_ = Function(self.W) Fbc1 = DirichletBC(self.W.sub(0), Constant((1.0, 0.0)), self.interface, _FLUID_CYLINDER) Fbc2 = DirichletBC(self.W.sub(0), Constant((1.0, 0.0)), self.interface, _FSI) Fbc1.apply(w_.vector()) Fbc2.apply(w_.vector()) D_FF = -assemble(action(self.F_fluid, w_)) w_ = Function(self.W) Fbc1 = DirichletBC(self.W.sub(0), Constant((0.0, 1.0)), self.interface, _FLUID_CYLINDER) Fbc2 = DirichletBC(self.W.sub(0), Constant((0.0, 1.0)), self.interface, _FSI) Fbc1.apply(w_.vector()) Fbc2.apply(w_.vector()) L_FF = -assemble(action(self.F_fluid, w_)) # MPI trick to extract displacement values at the end of the beam self.w.set_allow_extrapolation(True) pA_loc = self.p((A.x(), A.y())) pB_loc = self.p((B.x(), B.y())) pB_loc = self.p((B.x(), B.y())) Ax_loc = self.u[0]((A.x(), A.y())) Ay_loc = self.u[1]((A.x(), A.y())) self.w.set_allow_extrapolation(False) pi = 0 if self.bb.compute_first_collision(A) < 4294967295: pi = 1 else: pA_loc = 0.0 Ax_loc = 0.0 Ay_loc = 0.0 pA = MPI.sum(comm, pA_loc) / MPI.sum(comm, pi) Ax = MPI.sum(comm, Ax_loc) / MPI.sum(comm, pi) Ay = MPI.sum(comm, Ay_loc) / MPI.sum(comm, pi) pi = 0 if self.bb.compute_first_collision(B) < 4294967295: pi = 1 else: pB_loc = 0.0 pB = MPI.sum(comm, pB_loc) / MPI.sum(comm, pi) p_diff = pB - pA # wirte computed quantities to a file if my_rank == 0: with open(result + '/data.csv', 'a') as data_file: writer = csv.writer(data_file, delimiter=';', lineterminator='\n') writer.writerow([ t, P, PI, Ax, Ay, p_diff, D_C, D_F, D_S, D_FF, L_C, L_F, L_S, L_FF ])