def from_conf(conf, dpb, apb): opts = conf.options regions = dpb.domain.regions if opts.use_mesh_velocity: import tables as pt fd = pt.open_file(opts.mesh_velocity_filename, mode='r') aux = fd.get_node('/u').read() nu = nm.asarray(aux, dtype=nm.float64) fd.close() else: nu = None sp_boxes = ffd.read_spline_box_hdf5(opts.ffd_spline_data) dsg_vars = ffd.read_dsg_vars_hdf5(opts.ffd_spline_data) dsg_vars.renumber_by_boxes(sp_boxes) dsg_vars.normalize_null_space_base() print dsg_vars.indx.shape print dsg_vars.null_space_b.shape control_region = regions[opts.control_domain] design_region = regions[opts.design_domain] from sfepy.discrete.fem.mesh import Mesh cmm = Mesh.from_region(control_region, dpb.domain.mesh) dmm = Mesh.from_region(design_region, dpb.domain.mesh) cmm.write('control.mesh', io='auto') dmm.write('design.mesh', io='auto') SOFC = ShapeOptimFlowCase obj = SOFC(dpb=dpb, apb=apb, sp_boxes=sp_boxes, dsg_vars=dsg_vars, problem_type=opts.problem, objective_function_type=opts.objective_function, var_map=opts.var_map, nu=nu, use_mesh_velocity=opts.use_mesh_velocity, save_dir=opts.save_dir, save_iter_sols=opts.save_iter_sols, save_control_points=opts.save_control_points, save_dsg_vars=opts.save_dsg_vars, test_terms_if_test=opts.test_terms_if_test) equations = getattr( conf, '_'.join(('equations_sensitivity', opts.problem, opts.objective_function))) obj.obj_fun_term = equations['objective'] obj.sens_terms = equations['sensitivity'] obj.n_var = dsg_vars.val.shape[0] obj.create_evaluables() return obj
def from_conf(conf, dpb, apb): opts = conf.options regions = dpb.domain.regions if opts.use_mesh_velocity: import tables as pt fd = pt.open_file( opts.mesh_velocity_filename, mode = 'r' ) aux = fd.get_node( '/u' ).read() nu = nm.asarray( aux, dtype = nm.float64 ) fd.close() else: nu = None sp_boxes = ffd.read_spline_box_hdf5( opts.ffd_spline_data ) dsg_vars = ffd.read_dsg_vars_hdf5( opts.ffd_spline_data ) dsg_vars.renumber_by_boxes( sp_boxes ) dsg_vars.normalize_null_space_base() print dsg_vars.indx.shape print dsg_vars.null_space_b.shape control_region = regions[opts.control_domain] design_region = regions[opts.design_domain] from sfepy.discrete.fem.mesh import Mesh cmm = Mesh.from_region(control_region, dpb.domain.mesh) dmm = Mesh.from_region(design_region, dpb.domain.mesh) cmm.write( 'control.mesh', io = 'auto' ) dmm.write( 'design.mesh', io = 'auto' ) SOFC = ShapeOptimFlowCase obj = SOFC(dpb=dpb, apb=apb, sp_boxes=sp_boxes, dsg_vars=dsg_vars, problem_type=opts.problem, objective_function_type=opts.objective_function, var_map=opts.var_map, nu=nu, use_mesh_velocity=opts.use_mesh_velocity, save_dir=opts.save_dir, save_iter_sols=opts.save_iter_sols, save_control_points=opts.save_control_points, save_dsg_vars=opts.save_dsg_vars, test_terms_if_test=opts.test_terms_if_test) equations = getattr( conf, '_'.join( ('equations_sensitivity', opts.problem, opts.objective_function) ) ) obj.obj_fun_term = equations['objective'] obj.sens_terms = equations['sensitivity'] obj.n_var = dsg_vars.val.shape[0] obj.create_evaluables() return obj
def save_state( self, filename, state=None, out=None, fill_value=None, post_process_hook=None, linearization=None, file_per_var=False, **kwargs ): """ Parameters ---------- file_per_var : bool or None If True, data of each variable are stored in a separate file. If None, it is set to the application option value. linearization : Struct or None The linearization configuration for higher order approximations. If its kind is 'adaptive', `file_per_var` is assumed True. """ linearization = get_default(linearization, self.linearization) if linearization.kind != "adaptive": file_per_var = get_default(file_per_var, self.file_per_var) else: file_per_var = True extend = not file_per_var if (out is None) and (state is not None): out = state.create_output_dict(fill_value=fill_value, extend=extend, linearization=linearization) if post_process_hook is not None: out = post_process_hook(out, self, state, extend=extend) if linearization.kind == "adaptive": for key, val in out.iteritems(): mesh = val.get("mesh", self.domain.mesh) aux = io.edit_filename(filename, suffix="_" + val.var_name) mesh.write(aux, io="auto", out={key: val}, float_format=self.float_format, **kwargs) if hasattr(val, "levels"): output("max. refinement per group:", val.levels) elif file_per_var: meshes = {} if self.equations is None: varnames = {} for key, val in out.iteritems(): varnames[val.var_name] = 1 varnames = varnames.keys() outvars = self.create_variables(varnames) itervars = outvars.__iter__ else: itervars = self.equations.variables.iter_state for var in itervars(): rname = var.field.region.name if meshes.has_key(rname): mesh = meshes[rname] else: mesh = Mesh.from_region( var.field.region, self.domain.mesh, localize=True, is_surface=var.is_surface ) meshes[rname] = mesh vout = {} for key, val in out.iteritems(): try: if val.var_name == var.name: vout[key] = val except AttributeError: msg = "missing var_name attribute in output!" raise ValueError(msg) aux = io.edit_filename(filename, suffix="_" + var.name) mesh.write(aux, io="auto", out=vout, float_format=self.float_format, **kwargs) else: self.domain.mesh.write(filename, io="auto", out=out, float_format=self.float_format, **kwargs)
def save_state(self, filename, state=None, out=None, fill_value=None, post_process_hook=None, linearization=None, file_per_var=False, **kwargs): """ Parameters ---------- file_per_var : bool or None If True, data of each variable are stored in a separate file. If None, it is set to the application option value. linearization : Struct or None The linearization configuration for higher order approximations. If its kind is 'adaptive', `file_per_var` is assumed True. """ linearization = get_default(linearization, self.linearization) if linearization.kind != 'adaptive': file_per_var = get_default(file_per_var, self.file_per_var) else: file_per_var = True extend = not file_per_var if (out is None) and (state is not None): out = state.create_output_dict(fill_value=fill_value, extend=extend, linearization=linearization) if post_process_hook is not None: out = post_process_hook(out, self, state, extend=extend) if linearization.kind == 'adaptive': for key, val in out.iteritems(): mesh = val.get('mesh', self.domain.mesh) aux = io.edit_filename(filename, suffix='_' + val.var_name) mesh.write(aux, io='auto', out={key : val}, float_format=self.float_format, **kwargs) if hasattr(val, 'levels'): output('max. refinement per group:', val.levels) elif file_per_var: meshes = {} if self.equations is None: varnames = {} for key, val in out.iteritems(): varnames[val.var_name] = 1 varnames = varnames.keys() outvars = self.create_variables(varnames) itervars = outvars.__iter__ else: itervars = self.equations.variables.iter_state for var in itervars(): rname = var.field.region.name if meshes.has_key(rname): mesh = meshes[rname] else: mesh = Mesh.from_region(var.field.region, self.domain.mesh, localize=True, is_surface=var.is_surface) meshes[rname] = mesh vout = {} for key, val in out.iteritems(): try: if val.var_name == var.name: vout[key] = val except AttributeError: msg = 'missing var_name attribute in output!' raise ValueError(msg) aux = io.edit_filename(filename, suffix='_' + var.name) mesh.write(aux, io='auto', out=vout, float_format=self.float_format, **kwargs) else: mesh = out.pop('__mesh__', self.domain.mesh) mesh.write(filename, io='auto', out=out, float_format=self.float_format, **kwargs)