def test_material_functions(self): from sfepy.fem import Material problem = self.problem conf = problem.conf ts = problem.get_default_ts(step=0) conf_mat1 = conf.get_item_by_name('materials', 'mf1') mat1 = Material.from_conf(conf_mat1, problem.functions) mat1.time_update(ts, None, mode='normal', problem=problem) coors = problem.domain.get_mesh_coors() assert_(nm.all(coors[:,0] == mat1.get_data(None, None, 'x_0'))) conf_mat2 = conf.get_item_by_name('materials', 'mf2') mat2 = Material.from_conf(conf_mat2, problem.functions) mat2.time_update(ts, None, mode='normal', problem=problem) assert_(nm.all(coors[:,1] == mat2.get_data(None, None, 'x_1'))) materials = problem.get_materials() materials.time_update(ts, problem.equations, mode='normal', problem=problem) mat3 = materials['mf3'] key = mat3.get_keys(region_name='Omega')[0] assert_(nm.all(mat3.get_data(key, 0, 'a') == 10.0)) assert_(nm.all(mat3.get_data(key, 0, 'b') == 2.0)) assert_(mat3.get_data(None, None, 'c') == 'ahoj') return True
def test_material_functions(self): from sfepy.fem import Material problem = self.problem conf = problem.conf ts = problem.get_default_ts(step=0) conf_mat1 = conf.get_item_by_name('materials', 'mf1') mat1 = Material.from_conf(conf_mat1, problem.functions) mat1.time_update(ts, None, mode='normal', problem=problem) coors = problem.domain.get_mesh_coors() assert_(nm.all(coors[:, 0] == mat1.get_data(None, None, 'x_0'))) conf_mat2 = conf.get_item_by_name('materials', 'mf2') mat2 = Material.from_conf(conf_mat2, problem.functions) mat2.time_update(ts, None, mode='normal', problem=problem) assert_(nm.all(coors[:, 1] == mat2.get_data(None, None, 'x_1'))) materials = problem.get_materials() materials.time_update(ts, problem.equations, mode='normal', problem=problem) mat3 = materials['mf3'] key = mat3.get_keys(region_name='Omega')[0] assert_(nm.all(mat3.get_data(key, 0, 'a') == 10.0)) assert_(nm.all(mat3.get_data(key, 0, 'b') == 2.0)) assert_(mat3.get_data(None, None, 'c') == 'ahoj') return True
def test_boundary_fluxes( self ): import os.path as op from sfepy.linalg import rotation_matrix2d from sfepy.fem.evaluate import BasicEvaluator from sfepy.fem import Material problem = self.problem angles = [0, 30, 45] region_names = ['Left', 'Right', 'Gamma'] values = [5.0, -5.0, 0.0] variables = problem.get_variables() get_state = variables.get_state_part_view state = self.state.copy(deep=True) problem.time_update(ebcs={}, epbcs={}) # problem.save_ebc( 'aux.vtk' ) state.apply_ebc() ev = BasicEvaluator( problem ) aux = ev.eval_residual(state()) field = variables['t'].field conf_m = problem.conf.get_item_by_name('materials', 'm') m = Material.from_conf(conf_m, problem.functions) name = op.join( self.options.out_dir, op.split( problem.domain.mesh.name )[1] + '_%02d.mesh' ) orig_coors = problem.get_mesh_coors().copy() ok = True for ia, angle in enumerate( angles ): self.report( '%d: mesh rotation %d degrees' % (ia, angle) ) problem.domain.mesh.transform_coors( rotation_matrix2d( angle ), ref_coors = orig_coors ) problem.set_mesh_coors(problem.domain.mesh.coors, update_fields=True) problem.domain.mesh.write( name % angle, io = 'auto' ) for ii, region_name in enumerate( region_names ): flux_term = 'd_surface_flux.i2.%s( m.K, t )' % region_name val1 = problem.evaluate(flux_term, t=variables['t'], m=m) rvec = get_state( aux, 't', True ) reg = problem.domain.regions[region_name] nods = field.get_dofs_in_region(reg, merge=True) val2 = rvec[nods].sum() # Assume 1 dof per node. ok = ok and ((abs( val1 - values[ii] ) < 1e-10) and (abs( val2 - values[ii] ) < 1e-10)) self.report( ' %d. %s: %e == %e == %e'\ % (ii, region_name, val1, val2, values[ii]) ) # Restore original coordinates. problem.domain.mesh.transform_coors(rotation_matrix2d(0), ref_coors=orig_coors) problem.set_mesh_coors(problem.domain.mesh.coors, update_fields=True) return ok
def test_boundary_fluxes(self): import os.path as op from sfepy.linalg import rotation_matrix2d from sfepy.fem.evaluate import BasicEvaluator from sfepy.fem import Material problem = self.problem angles = [0, 30, 45] region_names = ['Left', 'Right', 'Gamma'] values = [5.0, -5.0, 0.0] variables = problem.get_variables() get_state = variables.get_state_part_view state = self.state.copy(deep=True) problem.time_update(ebcs={}, epbcs={}) # problem.save_ebc( 'aux.vtk' ) state.apply_ebc() ev = BasicEvaluator(problem) aux = ev.eval_residual(state()) field = variables['t'].field conf_m = problem.conf.get_item_by_name('materials', 'm') m = Material.from_conf(conf_m, problem.functions) name = op.join(self.options.out_dir, op.split(problem.domain.mesh.name)[1] + '_%02d.mesh') orig_coors = problem.get_mesh_coors().copy() ok = True for ia, angle in enumerate(angles): self.report('%d: mesh rotation %d degrees' % (ia, angle)) problem.domain.mesh.transform_coors(rotation_matrix2d(angle), ref_coors=orig_coors) problem.set_mesh_coors(problem.domain.mesh.coors, update_fields=True) problem.domain.mesh.write(name % angle, io='auto') for ii, region_name in enumerate(region_names): flux_term = 'd_surface_flux.i2.%s( m.K, t )' % region_name val1 = problem.evaluate(flux_term, t=variables['t'], m=m) rvec = get_state(aux, 't', True) reg = problem.domain.regions[region_name] nods = field.get_dofs_in_region(reg, merge=True) val2 = rvec[nods].sum() # Assume 1 dof per node. ok = ok and ((abs(val1 - values[ii]) < 1e-10) and (abs(val2 - values[ii]) < 1e-10)) self.report( ' %d. %s: %e == %e == %e'\ % (ii, region_name, val1, val2, values[ii]) ) # Restore original coordinates. problem.domain.mesh.transform_coors(rotation_matrix2d(0), ref_coors=orig_coors) problem.set_mesh_coors(problem.domain.mesh.coors, update_fields=True) return ok
def test_boundary_fluxes(self): from sfepy.fem.evaluate import BasicEvaluator from sfepy.fem import Material problem = self.problem region_names = ['Gamma'] variables = problem.get_variables() get_state = variables.get_state_part_view state = self.state.copy(deep=True) problem.time_update(ebcs={}, epbcs={}) ## problem.save_ebc( 'aux.vtk' ) state.apply_ebc() ev = BasicEvaluator(problem) aux = ev.eval_residual(state()) field = variables['t'].field conf_m = problem.conf.get_item_by_name('materials', 'm') m = Material.from_conf(conf_m, problem.functions) ok = True for ii, region_name in enumerate(region_names): flux_term = 'd_surface_flux.1.%s( m.K, t )' % region_name val1 = problem.evaluate(flux_term, t=variables['t'], m=m) rvec = get_state(aux, 't', True) reg = problem.domain.regions[region_name] nods = field.get_dofs_in_region(reg, merge=True) val2 = rvec[nods].sum() # Assume 1 dof per node. eps = 1e-2 ok = ok and ((abs(val1 - val2) < eps)) self.report( '%d. %s: |%e - %e| = %e < %.2e'\ % (ii, region_name, val1, val2, abs( val1 - val2 ), eps) ) return ok
def test_boundary_fluxes( self ): from sfepy.fem.evaluate import BasicEvaluator from sfepy.fem import Material problem = self.problem region_names = ['Gamma'] variables = problem.get_variables() get_state = variables.get_state_part_view state = self.state.copy(deep=True) problem.time_update(ebcs={}, epbcs={}) ## problem.save_ebc( 'aux.vtk' ) state.apply_ebc() ev = BasicEvaluator( problem ) aux = ev.eval_residual(state()) field = variables['t'].field conf_m = problem.conf.get_item_by_name('materials', 'm') m = Material.from_conf(conf_m, problem.functions) ok = True for ii, region_name in enumerate( region_names ): flux_term = 'd_surface_flux.1.%s( m.K, t )' % region_name val1 = problem.evaluate(flux_term, t=variables['t'], m=m) rvec = get_state( aux, 't', True ) reg = problem.domain.regions[region_name] nods = field.get_dofs_in_region(reg, merge=True) val2 = rvec[nods].sum() # Assume 1 dof per node. eps = 1e-2 ok = ok and ((abs( val1 - val2 ) < eps)) self.report( '%d. %s: |%e - %e| = %e < %.2e'\ % (ii, region_name, val1, val2, abs( val1 - val2 ), eps) ) return ok