def evaluate(self, annotate=True): """ Computes the functional value by running the forward model. """ log(INFO, 'Start evaluation of j') timer = Timer("j evaluation") farm = self.solver.problem.parameters.tidal_farm # Configure dolfin-adjoint adj_reset() parameters["adjoint"]["record_all"] = True # Solve the shallow water system and integrate the functional of # interest. final_only = (not self.solver.problem._is_transient or self._problem_params.functional_final_time_only) self.time_integrator = TimeIntegrator(self.solver.problem, self._functional, final_only) for sol in self.solver.solve(annotate=annotate): self.time_integrator.add(sol["time"], sol["state"], sol["tf"], sol["is_final"]) j = self.time_integrator.integrate() timer.stop() log(INFO, 'Runtime: %f s.' % timer.elapsed()[0]) log(INFO, 'j = %e.' % float(j)) return j
print("l2 error " + str(l2_error)) # Store in error error table num_cells_t = mesh.num_entities_global(2) num_particles = len(x) try: area_error_half = np.float64((area_half - area_0)) except BaseException: area_error_half = float("NaN") l2_error_half = float("NaN") area_error_end = np.float64((area_end - area_0)) with open(output_table, "a") as write_file: write_file.write( "%-12.5g %-15d %-20d %-10.2e %-20.3g %-20.2e %-20.3g %-20.3g \n" % ( float(dt), int(num_cells_t), int(num_particles), float(l2_error_half), np.float64(area_error_half), float(l2_error), np.float64(area_error_end), np.float(timer.elapsed()[0]), )) time_table = timings(TimingClear.keep, [TimingType.wall]) with open(outdir + "timings" + str(nx) + ".log", "w") as out: out.write(time_table.str(True))
t = 0. area_0 = assemble(psi_h * dx) timer = Timer() timer.start() outfile.write(psi_h, t) while step < num_steps: step += 1 t += float(dt) if comm.Get_rank() == 0: print("Step " + str(step)) AD.do_sweep() ap.do_step(float(dt)) AD.do_sweep_failsafe(4) lstsq_psi.project(psi_h.cpp_object(), lb, ub) if step % store_step == 0: outfile.write(psi_h, t) timer.stop() area_end = assemble(psi_h * dx) if comm.Get_rank() == 0: print('Num cells ' + str(mesh.num_entities_global(2))) print('Num particles ' + str(len(x))) print('Elapsed time ' + str(timer.elapsed()[0])) print('Area error ' + str(abs(area_end - area_0)))
ap.do_step(float(dt)) lstsq_psi.project(psi_h, lb, ub) psi_h_min = min(psi_h_min, psi_h.vector().min()) psi_h_max = max(psi_h_max, psi_h.vector().max()) if comm.rank == 0: print("Min max phi {} {}".format(psi_h_min, psi_h_max)) if step % store_step == 0: outfile.write_checkpoint(psi_h, function_name="psi", time_step=t, append=True) # Dump particles to file p.dump2file(mesh, fname_list, property_list, "ab") timer.stop() area_end = assemble(psi_h * dx) num_part = p.number_of_particles() l2_error = np.sqrt(abs(assemble((psi_h0 - psi_h) * (psi_h0 - psi_h) * dx))) if comm.Get_rank() == 0: print("Num cells " + str(mesh.num_entities_global(2))) print("Num particles " + str(num_part)) print("Elapsed time " + str(timer.elapsed()[0])) print("Area error " + str(abs(area_end - area_0))) print("Error " + str(l2_error)) print("Min max phi {} {}".format(psi_h_min, psi_h_max)) outfile.close()