def print_min_max(u, title, color='97', cls=None): """ Print the minimum and maximum values of <u>, a Vector, Function, or array. """ #if cls is not None: # color = cls.color() if isinstance(u, GenericVector): uMin = MPI.min(mpi_comm_world(), u.min()) uMax = MPI.max(mpi_comm_world(), u.max()) s = title + ' <min, max> : <%.3e, %.3e>' % (uMin, uMax) print_text(s, color) elif isinstance(u, ndarray): if u.dtype != float64: u = u.astype(float64) uMin = MPI.min(mpi_comm_world(), u.min()) uMax = MPI.max(mpi_comm_world(), u.max()) s = title + ' <min, max> : <%.3e, %.3e>' % (uMin, uMax) print_text(s, color) elif isinstance(u, Function):# \ # or isinstance(u, dolfin.functions.function.Function): uMin = MPI.min(mpi_comm_world(), u.vector().min()) uMax = MPI.max(mpi_comm_world(), u.vector().max()) s = title + ' <min, max> : <%.3e, %.3e>' % (uMin, uMax) print_text(s, color) elif isinstance(u, int) or isinstance(u, float): s = title + ' : %.3e' % u print_text(s, color) elif isinstance(u, Constant): s = title + ' : %.3e' % u(0) print_text(s, color) else: er = title + ": print_min_max function requires a Vector, Function" \ + ", array, int or float, not %s." % type(u) print_text(er, 'red', 1)
t0 = timer.time() #try: if r["space"] == "mixedspace": problem_mix(**vars()) elif r["space"] == "singlespace": problem_single() else: print("Problem type %s is not implemented, only mixedspace " + "and singlespace are valid options") % r["space"] sys.exit(0) #except Exception as e: # print "Problems for solver", r["name"] # print "Unexpected error:", sys.exc_info()[0] # print e # print "Move on the the next solver" r["number_of_cores"] = MPI.max(mpi_comm_world(), MPI.rank( mpi_comm_world())) + 1 r["solution_time"] = MPI.sum(mpi_comm_world(), timer.time() - t0) / (r["number_of_cores"]) displacement = probe.array() probe.clear() # Store results if MPI.rank(mpi_comm_world()) == 0 and not load: results.append( (displacement[0, :], displacement[1, :], np.array(time))) if not path.exists(r["case_path"]): makedirs(r["case_path"]) results[-1][0].dump(path.join(r["case_path"], "dis_x.np")) results[-1][1].dump(path.join(r["case_path"], "dis_y.np")) results[-1][2].dump(path.join(r["case_path"], "time.np"))