.. math:: D_{ijkl} = \mu (\delta_{ik} \delta_{jl}+\delta_{il} \delta_{jk}) + \lambda \ \delta_{ij} \delta_{kl} \;. """ from __future__ import absolute_import from sfepy.mechanics.matcoefs import stiffness_from_youngpoisson from sfepy.discrete.fem.utils import refine_mesh from sfepy import data_dir # Fix the mesh file name if you run this file outside the SfePy directory. filename_mesh = data_dir + '/meshes/2d/its2D.mesh' refinement_level = 0 filename_mesh = refine_mesh(filename_mesh, refinement_level) output_dir = '.' # set this to a valid directory you have write access to young = 2000.0 # Young's modulus [MPa] poisson = 0.4 # Poisson's ratio options = { 'output_dir' : output_dir, } regions = { 'Omega' : 'all', 'Left' : ('vertices in (x < 0.001)', 'facet'), 'Bottom' : ('vertices in (y < 0.001)', 'facet'), 'Top' : ('vertex 2', 'vertex'),
.. math:: D_{ijkl} = \mu (\delta_{ik} \delta_{jl}+\delta_{il} \delta_{jk}) + \lambda \ \delta_{ij} \delta_{kl} \;. """ from __future__ import absolute_import from sfepy.mechanics.matcoefs import stiffness_from_youngpoisson from sfepy.discrete.fem.utils import refine_mesh from sfepy import data_dir # Fix the mesh file name if you run this file outside the SfePy directory. filename_mesh = '/Users/arafat/Google Drive/MTP/code/sfepy/its2D.mesh' refinement_level = 0 filename_mesh = refine_mesh(filename_mesh, refinement_level) print "asda" output_dir = '/Users/arafat/Google Drive/MTP/code/sfepy' # set this to a valid directory you have write access to young = 2000.0 # Young's modulus [MPa] poisson = 0.4 # Poisson's ratio options = { 'output_dir': output_dir, } regions = { 'Omega': 'all', 'Left': ('vertices in (x < 0.001)', 'facet'), 'Bottom': ('vertices in (y < 0.001)', 'facet'), 'Top': ('vertex 2', 'vertex'),
def main(argv): if argv is None: argv = sys.argv[1:] parser = create_argument_parser() args = parser.parse_args(argv) prefix = "" problem_module_name = args.problem_file.replace(".py", "").strip("\\.") \ .replace("\\", ".").replace("/", ".") if not problem_module_name.startswith(prefix): problem_module_name = prefix + problem_module_name problem_module = importlib.import_module(problem_module_name) mesh = None if args.mesh_file is not None: mesh = str(Path(args.mesh_file)) refines = parse_str2tuple_default(args.refines, (1, 2, 3, 4, 5)) orders = parse_str2tuple_default(args.orders, (0, 1, 2, 3, 4)) if problem_module.dim == 1: sol_fig, axs = plt.subplots(len(orders), len(refines), figsize=(18, 10)) mod = sys.modules[problem_module_name] results = [] for ir, refine in enumerate(refines): if mesh is not None: gen_mesh = refine_mesh(mesh, refine) else: gen_mesh = refine for io, order in enumerate(orders): conf = ProblemConf.from_dict(problem_module.define( filename_mesh=gen_mesh, approx_order=order, adflux=args.adflux, limit=args.limit, cw=args.cw, diffcoef=args.diffcoef, diffscheme=args.diffscheme, cfl=args.cfl, dt=args.dt, ), mod, verbose=args.verbose) conf.options.absolute_mesh_path = True if args.output_dir is None: base_output_folder = Path(outputs_folder) / "conv_tests_out" /\ conf.example_name elif "{}" in args.output_dir: base_output_folder = Path( args.output_dir.format(conf.example_name)) else: base_output_folder = Path(args.output_dir) output_folder = base_output_folder / ("h" + str(refine)) output_folder = output_folder / ("o" + str(order)) configure_output({ 'output_screen': not args.no_output_screen, 'output_log_name': str(output_folder / "last_run.txt") }) output("----------------Running--------------------------") output("{}: {}".format(conf.example_name, time.asctime())) output('refine:', refine, 'order:', order) h, n_cells, pb, vols = create_problem(conf) output_format = pjoin( str(output_folder), "sol-h{:02d}o{:02d}.*.{}".format( n_cells, order, "vtk" if problem_module.dim == 1 else "msh")) output("Output set to {}, clearing.".format(output_format)) clear_folder(output_format, confirm=False, doit=True) ensure_path(output_format) pb, elapsed = run_calc(pb, output_format) output("{}: {}".format(conf.example_name, time.asctime())) output("------------------Finished------------------\n\n") ana_l2, ana_qp, diff_l2, rel_l2, num_qp = compute_erros( conf.sol_fun, pb) n_dof = pb.fields["f"].n_nod result = (h, n_cells, nm.mean(vols), order, n_dof, ana_l2, diff_l2, rel_l2, elapsed, getattr(pb.ts_conf, "cour", nm.NAN), getattr(pb.ts_conf, "dt", nm.NAN), getattr(pb.solver.status.nls_status, "err", nm.NAN), getattr(pb.solver.status.nls_status, "n_iter", nm.NAN)) results.append(result) if problem_module.dim == 1: plot_1D_snr(conf, pb, ana_qp, num_qp, io, order, orders, ir, sol_fig, axs) sol_fig.savefig( base_output_folder / ("err-sol-i20" + build_attrs_string(conf) + ".png"), dpi=100) err_df = create_error_df(conf, pb, results) err_df.to_csv(base_output_folder / "results.csv") err_df.to_csv(base_output_folder.parent / (base_output_folder.name + "_results.csv")) output(err_df) conv_fig = plot_conv_results(base_output_folder, conf, err_df, save=True) conv_fig.savefig(base_output_folder / "results.png", dpi=200) if args.doplot: plt.show()