def plot_partitioning(axs, field, cell_tasks, gfd, output_dir, size): """ Plot the partitioning of the domain and field DOFs. """ mesh = field.domain.mesh ax = pc.plot_wireframe(axs[0], mesh.cmesh) coors = field.get_coor() econn = field.econn ax = pd.plot_global_dofs(ax, coors, econn) ax.set_title('global DOFs') ax.figure.savefig(os.path.join(output_dir, 'global_dofs.png'), bbox_inches='tight') ax = pc.plot_wireframe(axs[1], mesh.cmesh) fig = ax.figure coors = field.get_coor() econn = field.econn id_map = gfd.id_map colors = nm.zeros((field.n_nod, 4)) for ir, dof_map in ordered_iteritems(gfd.dof_maps): aux = id_map[dof_map[0]] colors[aux] = [0, 0, float(ir + 1) / size, 0.6] for aux in dof_map[1]: colors[id_map[aux]] = [0, 0, float(ir + 1) / size, 0.9] from sfepy.discrete.fem.utils import prepare_translate aux = prepare_translate(id_map[econn], econn) ax = label_dofs(ax, coors[aux], id_map, colors) mark_subdomains(ax, mesh.cmesh, cell_tasks, size, 0, 0.7) ax.set_title('subdomains of tasks and PETSc DOFs') fig.savefig(os.path.join(output_dir, 'petsc_dofs.png'), bbox_inches='tight') ax.set_title('') axis = ax.axis() for ir, ocells in enumerate(gfd.overlap_cells): aux = nm.zeros_like(cell_tasks) aux[ocells] = 10 aux[gfd.cell_parts[ir]] = 1 ax = fig.add_axes(ax.get_position(), frameon=False, label='aux') mark_subdomains(ax, mesh.cmesh, aux, 11, 1, 0.3, True) ax.axis(axis) ax.set_title('overlap cells on task %d' % ir) fig.savefig(os.path.join(output_dir, 'petsc_overlaps_%02d.png' % ir), bbox_inches='tight') fig.delaxes(ax)
def plot_local_dofs(axs, field, field_i, omega_gi, output_dir, rank): """ Plot the local ang global field DOFs local to the subdomain on the task with the given `rank`. """ mesh = field.domain.mesh ax = pc.plot_wireframe(axs[0], mesh.cmesh) coors = field_i.get_coor() econn = field_i.ap.econn ax = pd.plot_global_dofs(ax, coors, econn) ax.set_title('local DOFs on task %d' % rank) ax.figure.savefig(os.path.join(output_dir, 'local_dofs_%02d.png' % rank)) ax = pc.plot_wireframe(axs[1], mesh.cmesh) coors = field.get_coor() econn = field.get_econn('volume', omega_gi, 0) ax = pd.plot_global_dofs(ax, coors, econn) ax.set_title('global DOFs on task %d' % rank) ax.figure.savefig(os.path.join(output_dir, 'local_global_%02d.png' % rank))
def plot_local_dofs(axs, field, field_i, omega_gi, output_dir, rank): """ Plot the local ang global field DOFs local to the subdomain on the task with the given `rank`. """ mesh = field.domain.mesh ax = pc.plot_wireframe(axs[0], mesh.cmesh) coors = field_i.get_coor() econn = field_i.econn ax = pd.plot_global_dofs(ax, coors, econn) ax.set_title('local DOFs on task %d' % rank) ax.figure.savefig(os.path.join(output_dir, 'local_dofs_%02d.png' % rank), bbox_inches='tight') ax = pc.plot_wireframe(axs[1], mesh.cmesh) coors = field.get_coor() econn = field.get_econn('volume', omega_gi, 0) ax = pd.plot_global_dofs(ax, coors, econn) ax.set_title('global DOFs on task %d' % rank) ax.figure.savefig(os.path.join(output_dir, 'local_global_%02d.png' % rank), bbox_inches='tight')
def main(): parser = OptionParser(usage=usage, version='%prog') options, args = parser.parse_args() if len(args) == 1: filename = args[0] else: parser.print_help(), return mesh = Mesh.from_file(filename) output('Mesh:') output(' dimension: %d, vertices: %d, elements: %d' % (mesh.dim, mesh.n_nod, mesh.n_el)) domain = FEDomain('domain', mesh) output(domain.cmesh) domain.cmesh.cprint(1) dim = domain.cmesh.dim ax = pc.plot_wireframe(None, domain.cmesh) ax = pc.plot_entities(ax, domain.cmesh, 0, 'k') ax = pc.label_global_entities(ax, domain.cmesh, 0, 'k', 12) ax = pc.label_local_entities(ax, domain.cmesh, 0, 'k', 8) ax = pc.plot_entities(ax, domain.cmesh, 1, 'b') ax = pc.label_global_entities(ax, domain.cmesh, 1, 'b', 12) ax = pc.label_local_entities(ax, domain.cmesh, 1, 'b', 8) if dim == 3: ax = pc.plot_entities(ax, domain.cmesh, 2, 'g') ax = pc.label_global_entities(ax, domain.cmesh, 2, 'g', 12) ax = pc.label_local_entities(ax, domain.cmesh, 2, 'g', 8) ax = pc.plot_entities(ax, domain.cmesh, dim, 'r') ax = pc.label_global_entities(ax, domain.cmesh, dim, 'r', 12) pc.plt.show()
def main(): parser = OptionParser(usage=usage, version='%prog') options, args = parser.parse_args() if len(args) == 1: filename = args[0] else: parser.print_help(), return mesh = Mesh.from_file(filename) output('Mesh:') output(' dimension: %d, vertices: %d, elements: %d' % (mesh.dim, mesh.n_nod, mesh.n_el)) domain = FEDomain('domain', mesh) output(domain.cmesh) domain.cmesh.cprint(1) dim = domain.cmesh.dim ax = pc.plot_wireframe(None, domain.cmesh) ax = pc.plot_entities(ax, domain.cmesh, 0, 'k') ax = pc.label_global_entities(ax, domain.cmesh, 0, 'k', 12) ax = pc.label_local_entities(ax, domain.cmesh, 0, 'k', 8) ax = pc.plot_entities(ax, domain.cmesh, 1, 'b') ax = pc.label_global_entities(ax, domain.cmesh, 1, 'b', 12) ax = pc.label_local_entities(ax, domain.cmesh, 1, 'b', 8) if dim == 3: ax = pc.plot_entities(ax, domain.cmesh, 2, 'g') ax = pc.label_global_entities(ax, domain.cmesh, 2, 'g', 12) ax = pc.label_local_entities(ax, domain.cmesh, 2, 'g', 8) ax = pc.plot_entities(ax, domain.cmesh, dim, 'r') ax = pc.label_global_entities(ax, domain.cmesh, dim, 'r', 12) plt.show()
def save_basis_on_mesh(mesh, options, output_dir, lin, permutations=None, suffix=''): if permutations is not None: mesh = mesh.copy() gel = GeometryElement(mesh.descs[0]) perms = gel.get_conn_permutations()[permutations] conn = mesh.cmesh.get_cell_conn() n_el, n_ep = conn.num, gel.n_vertex offsets = nm.arange(n_el) * n_ep conn.indices[:] = conn.indices.take((perms + offsets[:, None]).ravel()) domain = FEDomain('domain', mesh) omega = domain.create_region('Omega', 'all') field = Field.from_args('f', nm.float64, shape=1, region=omega, approx_order=options.max_order, poly_space_base=options.basis) var = FieldVariable('u', 'unknown', field) if options.plot_dofs: import sfepy.postprocess.plot_dofs as pd import sfepy.postprocess.plot_cmesh as pc ax = pc.plot_wireframe(None, mesh.cmesh) ax = pd.plot_global_dofs(ax, field.get_coor(), field.econn) ax = pd.plot_local_dofs(ax, field.get_coor(), field.econn) if options.dofs is not None: ax = pd.plot_nodes(ax, field.get_coor(), field.econn, field.poly_space.nodes, get_dofs(options.dofs, var.n_dof)) pd.plt.show() output('dofs: %d' % var.n_dof) vec = nm.empty(var.n_dof, dtype=var.dtype) n_digit, _format = get_print_info(var.n_dof, fill='0') name_template = os.path.join(output_dir, 'dof_%s%s.vtk' % (_format, suffix)) for ip in get_dofs(options.dofs, var.n_dof): output('dof %d...' % ip) vec.fill(0.0) vec[ip] = 1.0 var.set_data(vec) if options.derivative == 0: out = var.create_output(vec, linearization=lin) else: out = create_expression_output('ev_grad.ie.Elements(u)', 'u', 'f', {'f' : field}, None, Variables([var]), mode='qp', verbose=False, min_level=lin.min_level, max_level=lin.max_level, eps=lin.eps) name = name_template % ip ensure_path(name) out['u'].mesh.write(name, out=out) output('...done (%s)' % name)