def _get_explorer_config(self): from ibvpy.api import TLine, BCDof, RTDofGraph c = super(MATS1DPlastic, self)._get_explorer_config() # overload the default configuration c['bcond_list'] = [BCDof(var='u', dof=0, value=2.0, time_function=lambda t: sin(t))] c['rtrace_list'] = [ RTDofGraph(name='strain - stress', var_x='eps_app', idx_x=0, var_y='sig_app', idx_y=0, record_on='update'), RTDofGraph(name='time - plastic_strain', var_x='time', idx_x=0, var_y='eps_p', idx_y=0, record_on='update'), RTDofGraph(name='time - back stress', var_x='time', idx_x=0, var_y='q', idx_y=0, record_on='update'), RTDofGraph(name='time - hardening', var_x='time', idx_x=0, var_y='alpha', idx_y=0, record_on='update') ] c['tline'] = TLine(step=0.3, max=10) return c
def _get_explorer_config(self): from ibvpy.api import TLine, RTDofGraph, BCDof ec = super(MATS1DDamage, self)._get_explorer_config() ec['mats_eval'] = MATS1DDamage(E=1.0, epsilon_0=1.0, epsilon_f=5) ec['bcond_list'] = [ BCDof(var='u', dof=0, value=1.7, time_function=lambda t: (1 + 0.1 * t) * sin(t)) ] ec['tline'] = TLine(step=0.1, max=10) ec['rtrace_list'] = [ RTDofGraph(name='strain - stress', var_x='eps_app', idx_x=0, var_y='sig_app', idx_y=0, record_on='update'), RTDofGraph(name='time - damage', var_x='time', idx_x=0, var_y='omega', idx_y=0, record_on='update') ] return ec
def verify_sig_m_eps(self, ax, **kw): e_phi_data = np.loadtxt(self.phi_file) e_data, phi_data = e_phi_data.T E_c = self.get_E_c() rt = RTDofGraph(name='stress - strain', var_x='eps_app', idx_x=0, var_y='sig_app', idx_y=0, record_on='update') ec = { # overload the default configuration 'bcond_list': [BCDofProportional(max_strain=np.max(e_data), alpha_rad=0.0)], 'rtrace_list': [ rt ], } mats_eval = MATS2DMicroplaneDamage( n_mp=30, E=E_c, nu=0.2, elastic_debug=False, stress_state='plane_stress', symmetrization='sum-type', model_version='compliance', phi_fn=PhiFnGeneral(mfn=MFnLineArray(xdata=e_data, ydata=phi_data)), ) me = MATSExplore(KMAX=300, tolerance=5e-4, # 0.01, RESETMAX=0, dim=MATS2DExplore( mats_eval=mats_eval, explorer_config=ec, ), store_fitted_phi_fn=True, log=False ) #------------------------------------------------------------------ # specify the parameters used within the calibration #------------------------------------------------------------------ # me.n_steps = 200 me.tloop.tline.step = 0.01 me.format_ticks = True me.tloop.eval() rt.redraw() eps_m = rt.trace.xdata sig_m = rt.trace.ydata ax.plot(eps_m, sig_m, **kw)
def verify_sig_m_eps(self, ax, **kw): e_phi_data = np.loadtxt(self.phi_file) e_data, phi_data = e_phi_data.T E_c = self.get_E_c() rt = RTDofGraph(name='stress - strain', var_x='eps_app', idx_x=0, var_y='sig_app', idx_y=0, record_on='update') ec = { # overload the default configuration 'bcond_list': [BCDofProportional(max_strain=np.max(e_data), alpha_rad=0.0)], 'rtrace_list': [rt], } mats_eval = MATS2DMicroplaneDamage( n_mp=30, E=E_c, nu=0.2, elastic_debug=False, stress_state='plane_stress', symmetrization='sum-type', model_version='compliance', phi_fn=PhiFnGeneral( mfn=MFnLineArray(xdata=e_data, ydata=phi_data)), ) me = MATSExplore( KMAX=300, tolerance=5e-4, # 0.01, RESETMAX=0, dim=MATS2DExplore( mats_eval=mats_eval, explorer_config=ec, ), store_fitted_phi_fn=True, log=False) #------------------------------------------------------------------ # specify the parameters used within the calibration #------------------------------------------------------------------ # me.n_steps = 200 me.tloop.tline.step = 0.01 me.format_ticks = True me.tloop.eval() rt.redraw() eps_m = rt.trace.xdata sig_m = rt.trace.ydata ax.plot(eps_m, sig_m, **kw)
def _get_rt_list(self): '''Prepare the list of tracers ''' right_dof = self.fe_grid[-1, -1].dofs[0, 0, 0] eps_app = RTraceDomainListField(name='Strain' , position='int_pnts', var='eps_app', warp=False) damage = RTraceDomainListField(name='Damage' , position='int_pnts', var='omega', warp=False) disp = RTraceDomainListField(name='Displacement' , position='int_pnts', var='u', warp=False) sig_app = RTraceDomainListField(name='Stress' , position='int_pnts', var='sig_app') rt_fu = RTDofGraph(name='Fi,right over u_right (iteration)' , var_y='F_int', idx_y=right_dof, var_x='U_k', idx_x=right_dof) return [ rt_fu, eps_app, damage, sig_app, disp ]
def test_bar1(self): '''Clamped bar loaded at the right end with unit displacement [00]-[01]-[02]-[03]-[04]-[05]-[06]-[07]-[08]-[09]-[10] 'u[0] = 0, u[10] = 1''' self.domain.coord_max = (10, 0, 0) self.domain.shape = (10, ) self.ts.bcond_list = [ BCDof(var='u', dof=0, value=0.), BCDof(var='u', dof=10, value=1.) ] self.ts.rtrace_list = [ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=10, var_x='U_k', idx_x=10) ] u = self.tloop.eval() # expected solution u_ex = array([0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.], dtype=float) difference = sqrt(norm(u - u_ex)) self.assertAlmostEqual(difference, 0) # compare the reaction at the left end F = self.ts.F_int[0] self.assertAlmostEqual(F, -1)
def example_with_new_domain(): from ibvpy.api import \ TStepper as TS, RTDofGraph, RTraceDomainListField, TLoop, \ TLine, BCDof, IBVPSolve as IS, DOTSEval from ibvpy.mats.mats1D.mats1D_elastic.mats1D_elastic import MATS1DElastic fets_eval = FETS1D2L3U(mats_eval=MATS1DElastic(E=10.)) from ibvpy.mesh.fe_grid import FEGrid # Discretization domain = FEGrid(coord_max=(3., ), shape=(3, ), fets_eval=fets_eval) ts = TS(dof_resultants=True, sdomain=domain, # conversion to list (square brackets) is only necessary for slicing of # single dofs, e.g "get_left_dofs()[0,1]" # bcond_list = [ BCDof(var='u', dof = 0, value = 0.) ] + # [ BCDof(var='u', dof = 2, value = 0.001 ) ]+ # [ ) ], bcond_list=[BCDof(var='u', dof=0, value=0.), # BCDof(var='u', dof = 1, link_dofs = [2], link_coeffs = [0.5], # value = 0. ), # BCDof(var='u', dof = 2, link_dofs = [3], link_coeffs = [1.], # value = 0. ), BCDof(var='f', dof=6, value=1, # link_dofs = [2], link_coeffs = [2] )], rtrace_list=[RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=0, var_x='U_k', idx_x=1), RTraceDomainListField(name='Stress', var='sig_app', idx=0), RTraceDomainListField(name='Displacement', var='u', idx=0), RTraceDomainListField(name='N0', var='N_mtx', idx=0, record_on='update') ] ) # Add the time-loop control tloop = TLoop(tstepper=ts, tline=TLine(min=0.0, step=1, max=1.0)) print('---- result ----') print(tloop.eval()) print(ts.F_int) print(ts.rtrace_list[0].trace.ydata) # Put the whole stuff into the simulation-framework to map the # individual pieces of definition into the user interface. # from ibvpy.plugins.ibvpy_app import IBVPyApp app = IBVPyApp(ibv_resource=tloop) app.main()
def example_3d(): from ibvpy.tmodel.mats3D.mats3D_elastic.mats3D_elastic import MATS3DElastic from ibvpy.fets.fets3D.fets3D8h import FETS3D8H fets_eval = FETS3D8H(mats_eval=MATS3DElastic()) fe_domain = FEDomain() fe_level1 = FERefinementGrid(domain=fe_domain, fets_eval=fets_eval) # Discretization fe_domain1 = FEGrid(coord_max=(2., 5., 3.), shape=(2, 3, 2), level=fe_level1, fets_eval=fets_eval) fe_child_domain = FERefinementGrid(parent=fe_domain1, fine_cell_shape=(2, 2, 2)) fe_child_domain.refine_elem((1, 1, 0)) fe_child_domain.refine_elem((0, 1, 0)) fe_child_domain.refine_elem((1, 1, 1)) fe_child_domain.refine_elem((0, 1, 1)) ts = TS( dof_resultants=True, sdomain=fe_domain, bcond_list=[ BCDofGroup(var='f', value=1., dims=[0], get_dof_method=fe_domain1.get_top_dofs), BCDofGroup(var='u', value=0., dims=[0, 1], get_dof_method=fe_domain1.get_bottom_dofs), ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=0, var_x='U_k', idx_x=1), # RTraceDomainListField(name = 'Stress' , # var = 'sig_app', idx = 0, warp = True ), # RTraceDomainField(name = 'Displacement' , # var = 'u', idx = 0), # RTraceDomainField(name = 'N0' , # var = 'N_mtx', idx = 0, # record_on = 'update') ]) # Add the time-loop control tloop = TLoop(tstepper=ts, tline=TLine(min=0.0, step=1, max=1.0)) print(tloop.eval()) from ibvpy.plugins.ibvpy_app import IBVPyApp ibvpy_app = IBVPyApp(ibv_resource=tloop) ibvpy_app.main()
def _get_explorer_config(self): from ibvpy.api import BCDof, TLine, RTDofGraph return {'bcond_list': [BCDof(var='u', dof=0, value=0.01, time_function=lambda t: t)], 'rtrace_list': [RTDofGraph(name='strain - stress', var_x='eps_app', idx_x=0, var_y='sig_app', idx_y=0, record_on='update'), RTDofGraph(name='strain - strain', var_x='eps_app', idx_x=0, var_y='eps_app', idx_y=1, record_on='update'), RTDofGraph(name='stress - stress', var_x='sig_app', idx_x=0, var_y='sig_app', idx_y=1, record_on='update'), RTDofGraph(name='Stress - Strain', var_x='F_int', idx_x=0, var_y='U_k', idx_y=0, record_on='update'), RTDofGraph(name='Strain - Strain', var_x='U_k', idx_x=0, var_y='U_k', idx_y=1, record_on='update'), RTDofGraph(name='Stress - Stress', var_x='F_int', idx_x=0, var_y='F_int', idx_y=1, record_on='update'), RTDofGraph(name='sig1 - eps1', var_x='F_int', idx_x=0, var_y='U_k', idx_y=0, record_on='update'), RTDofGraph(name='sig2 - sig3', var_x='F_int', idx_x=1, var_y='F_int', idx_y=2, record_on='update'), RTDofGraph(name='eps2 - eps3', var_x='U_k', idx_x=1, var_y='U_k', idx_y=2, record_on='update') ], 'tline': TLine(step=0.1, max=1.0) } def _set_explorer_config(self, value): self._explorer_config = value
def _get_explorer_rtrace_list(self): '''Return the list of relevant tracers to be used in mats_explorer. ''' return [ RTDofGraph(name='strain - stress', var_x='eps_app', idx_x=0, var_y='sig_app', idx_y=0, record_on='update') ]
def __demo__(): from ibvpy.api import \ TStepper as TS, RTDofGraph, RTraceDomainListField, TLoop, \ TLine, BCDof from ibvpy.tmodel.mats1D.mats1D_elastic.mats1D_elastic import MATS1DElastic fets_eval = FETS1D2L(mats_eval=MATS1DElastic(E=10.)) from ibvpy.mesh.fe_grid import FEGrid # Discretization domain = FEGrid(coord_max=(3., ), shape=(3, ), fets_eval=fets_eval) ts = TS(dof_resultants=True, sdomain=domain, bcond_list=[ BCDof(var='u', dof=0, value=0.), BCDof( var='f', dof=3, value=1, ) ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=0, var_x='U_k', idx_x=1), RTraceDomainListField(name='Stress', var='sig_app', idx=0), RTraceDomainListField(name='Displacement', var='u', idx=0, warp=True), RTraceDomainListField(name='N0', var='N_mtx', idx=0, record_on='update') ]) # Add the time-loop control tloop = TLoop(tstepper=ts, tline=TLine(min=0.0, step=0.5, max=1.0)) print('---- result ----') print(tloop.eval()) print(ts.F_int) print(ts.rtrace_list[0].trace.ydata) # Put the whole stuff into the simulation-framework to map the # individual pieces of definition into the user interface. # app = IBVPyApp(ibv_resource=tloop) app.main()
def test_bar4(self): '''Clamped bar 3 domains, each with 2 elems (displ at right end) [0]-[1]-[2] [3]-[4]-[5] [6]-[7]-[8] u[0] = 0, u[2] = u[3], u[5] = u[6], u[8] = 1''' self.fe_domain1.set(coord_min=(0, 0, 0), coord_max=(2, 0, 0), shape=(2, )) self.fe_domain2.set(coord_min=(2, 0, 0), coord_max=(4, 0, 0), shape=(2, )) self.fe_domain3.set(coord_min=(4, 0, 0), coord_max=(6, 0, 0), shape=(2, )) self.ts.set( sdomain=[self.fe_domain1, self.fe_domain2, self.fe_domain3], dof_resultants=True, bcond_list=[ BCDof(var='u', dof=0, value=0.), BCDof(var='u', dof=2, link_dofs=[3], link_coeffs=[1.], value=0.), BCDof(var='u', dof=5, link_dofs=[6], link_coeffs=[1.], value=0.), BCDof(var='u', dof=8, value=1) ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=0, var_x='U_k', idx_x=1), ]) # system solver u = self.tloop.eval() # expected solution u_ex = array( [0., 1 / 6., 1 / 3., 1 / 3., 1 / 2., 2 / 3., 2 / 3., 5 / 6., 1.], dtype=float) for u_, u_ex_ in zip(u, u_ex): self.assertAlmostEqual(u_, u_ex_)
def setUp(self): self.fets_eval = FETS1D2L(mats_eval=MATS1DElastic(E=10.)) # Discretization self.fe_domain1 = FEGrid(coord_max=(3., 0., 0.), shape=(3, ), fets_eval=self.fets_eval) self.fe_domain2 = FEGrid(coord_min=(3., 0., 0.), coord_max=(6., 0., 0.), shape=(3, ), fets_eval=self.fets_eval) self.fe_domain3 = FEGrid(coord_min=(3., 0., 0.), coord_max=(6., 0., 0.), shape=(3, ), fets_eval=self.fets_eval) self.ts = TS( dof_resultants=True, sdomain=[self.fe_domain1, self.fe_domain2, self.fe_domain3], bcond_list=[ BCDof(var='u', dof=0, value=0.), BCDof(var='u', dof=4, link_dofs=[3], link_coeffs=[1.], value=0.), BCDof(var='f', dof=7, value=1, link_dofs=[2], link_coeffs=[2]) ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=0, var_x='U_k', idx_x=1), ]) # Add the time-loop control self.tloop = TLoop(tstepper=self.ts, tline=TLine(min=0.0, step=1, max=1.0))
fe_domain = FEDomain(subdomains=[fe_domain1, fe_domain2]) ts = TS(dof_resultants=True, sdomain=fe_domain, bcond_list=[ BCDof(var='u', dof=0, value=0.), BCDof(var='u', dof=5, link_dofs=[16], link_coeffs=[1.], value=0.), BCDof(var='f', dof=21, value=10) ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=0, var_x='U_k', idx_x=1), ]) # Add the time-loop control tloop = TLoop(tstepper=ts, tline=TLine(min=0.0, step=1, max=1.0)) ts.set(sdomain=FEDomain(subdomains=[fe_domain1, fe_domain2])) ts.set(bcond_list=[ BCDof(var='u', dof=0, value=0.), BCDof(var='u', dof=5, link_dofs=[16], link_coeffs=[1.], value=0.), BCDof(var='f', dof=21, value=10) ]) print(tloop.eval())
def combined_fe2D4q_with_fe2D4q8u(): fets_eval_4u_conc = FETS2D4Q(mats_eval=MATS2DElastic(E=28500, nu=0.2)) fets_eval_4u_steel = FETS2D4Q(mats_eval=MATS2DElastic(E=210000, nu=0.25)) fets_eval_8u = FETS2D4Q8U(mats_eval=MATS2DElastic()) # Discretization fe_domain = FEDomain() fe_grid_level1 = FERefinementGrid(name='master grid', fets_eval=fets_eval_4u_conc, domain=fe_domain) fe_grid = FEGrid(level=fe_grid_level1, coord_max=(2., 6., 0.), shape=(11, 30), fets_eval=fets_eval_4u_conc) fe_grid_level2 = FERefinementGrid(name='refinement grid', parent=fe_grid_level1, fets_eval=fets_eval_4u_steel, fine_cell_shape=(1, 1)) # fe_grid_level1[ 5, :5 ].refine_using( fe_grid_level2 ) # 1. first get the slice for the level - distinguish it from the slice at the subgrid # this includes slicing in the subgrids. what if the subgrid does not exist? # # Each subgrid must hold its own slice within the level. The index operator fills # the grid [...] instanciates the whole grid and returns the instance of # FEGridLevelSlice. The expanded subgrid contains its constructor slice. # # 2. If the slice is within an existing slice no change in the FESubgrid is required # only the instance of the slice is returned. The FEGridLevelSlice goes always into # an expanded part of FEGrid. # # 3. If the slice does not fit into any existing slice - all domain with an intersection # of the existing slice must be constructed as well. # # 2. deactivate elements # 3. # BUT how to impose the boundary conditions on the particular refinement? The # slice has an attribute fe_grid_level2.refine_elem((5, 0)) fe_grid_level2.refine_elem((5, 1)) fe_grid_level2.refine_elem((5, 2)) fe_grid_level2.refine_elem((5, 3)) fe_grid_level2.refine_elem((5, 4)) fe_grid_level2.refine_elem((5, 5)) # apply the boundary condition on a subgrid # print(fe_grid_level2.fe_subgrids) fe_first_grid = fe_grid_level2.fe_subgrids[0] ts = TS( dof_resultants=True, sdomain=fe_domain, bcond_list=[ BCSlice(var='f', value=1., dims=[0], slice=fe_grid[:, -1, :, -1]), BCSlice(var='u', value=0., dims=[0, 1], slice=fe_first_grid[:, 0, :, 0]) ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=0, var_x='U_k', idx_x=1), RTraceDomainListField(name='Stress', var='sig_app', idx=0, warp=True), # RTraceDomainField(name = 'Displacement' , # var = 'u', idx = 0), # RTraceDomainField(name = 'N0' , # var = 'N_mtx', idx = 0, # record_on = 'update') ]) # Add the time-loop control tloop = TLoop(tstepper=ts, tline=TLine(min=0.0, step=1, max=1.0)) print(tloop.eval()) from ibvpy.plugins.ibvpy_app import IBVPyApp ibvpy_app = IBVPyApp(ibv_resource=tloop) ibvpy_app.main()
def example_with_new_domain(): from ibvpy.api import \ TStepper as TS, RTDofGraph, RTraceDomainListField, \ RTraceDomainListInteg, TLoop, \ TLine, BCDof, DOTSEval from ibvpy.mats.mats2D.mats2D_elastic.mats2D_elastic import MATS2DElastic from ibvpy.mats.mats2D.mats2D_sdamage.mats2D_sdamage import MATS2DScalarDamage from ibvpy.api import BCDofGroup mats_eval = MATS2DElastic() fets_eval = FETS2D4Q(mats_eval=mats_eval) #fets_eval = FETS2D4Q(mats_eval = MATS2DScalarDamage()) print(fets_eval.vtk_node_cell_data) from ibvpy.mesh.fe_grid import FEGrid from ibvpy.mesh.fe_refinement_grid import FERefinementGrid from ibvpy.mesh.fe_domain import FEDomain from mathkit.mfn import MFnLineArray # Discretization fe_grid = FEGrid(coord_max=(10., 4., 0.), shape=(10, 3), fets_eval=fets_eval) bcg = BCDofGroup(var='u', value=0., dims=[0], get_dof_method=fe_grid.get_left_dofs) bcg.setup(None) print('labels', bcg._get_labels()) print('points', bcg._get_mvpoints()) mf = MFnLineArray( # xdata = arange(10), ydata=np.array([0, 1, 2, 3])) right_dof = 2 tstepper = TS( sdomain=fe_grid, bcond_list=[ BCDofGroup(var='u', value=0., dims=[0, 1], get_dof_method=fe_grid.get_left_dofs), # BCDofGroup( var='u', value = 0., dims = [1], # get_dof_method = fe_grid.get_bottom_dofs ), BCDofGroup(var='u', value=.005, dims=[1], time_function=mf.get_value, get_dof_method=fe_grid.get_right_dofs) ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=right_dof, var_x='U_k', idx_x=right_dof, record_on='update'), RTraceDomainListField(name='Stress', var='sig_app', idx=0, position='int_pnts', record_on='update'), # RTraceDomainListField(name = 'Damage' , # var = 'omega', idx = 0, # # record_on = 'update', # warp = True), RTraceDomainListField(name='Displacement', var='u', idx=0, record_on='update', warp=True), RTraceDomainListField(name='Strain energy', var='strain_energy', idx=0, record_on='update', warp=False), RTraceDomainListInteg(name='Integ strain energy', var='strain_energy', idx=0, record_on='update', warp=False), # RTraceDomainListField(name = 'N0' , # var = 'N_mtx', idx = 0, # record_on = 'update') ]) # Add the time-loop control #global tloop tloop = TLoop(tstepper=tstepper, KMAX=300, tolerance=1e-4, tline=TLine(min=0.0, step=1.0, max=1.0)) #import cProfile #cProfile.run('tloop.eval()', 'tloop_prof' ) # print tloop.eval() #import pstats #p = pstats.Stats('tloop_prof') # p.strip_dirs() # print 'cumulative' # p.sort_stats('cumulative').print_stats(20) # print 'time' # p.sort_stats('time').print_stats(20) tloop.eval() # Put the whole thing into the simulation-framework to map the # individual pieces of definition into the user interface. # from ibvpy.plugins.ibvpy_app import IBVPyApp app = IBVPyApp(ibv_resource=tloop) app.main()
if __name__ == '__main__': # tseval for a material model # # tseval = MATSProxy( mats_eval_type = 'MATS1DElastic' ) tseval = MATSProxy() E_mod_varpar = tseval.varpars['E'] E_mod_varpar.spatial_fn = MFnNDGrid(shape=(10, 10, 1), x_maxs=GridPoint(x=10, y=10)) ts = TS(tse=tseval, bcond_list=[BCDof(var='u', dof=0, value=1.)], rtrace_list=[ RTDofGraph(name='strain 0 - stress 0', var_x='eps_app', idx_x=0, var_y='sig_app', idx_y=0, record_on='update') ]) # Put the time-stepper into the time-loop # tmax = 4.0 # tmax = 0.0006 n_steps = 100 tl = TLoop(tstepper=ts, DT=tmax / n_steps, KMAX=100, RESETMAX=0, tline=TLine(min=0.0, max=tmax))
def eval(self): elem_length = self.length / float(self.shape) flaw_radius = self.flaw_radius mats = MATS1DElasticWithFlaw(E=10., flaw_position=self.flaw_position, flaw_radius=flaw_radius, reduction_factor=self.reduction_factor) #fets_eval = FETS1D2L( mats_eval = mats ) fets_eval = FETS1D2L3U(mats_eval=mats) domain = FEGrid(coord_max=(self.length, 0., 0.), shape=(self.shape, ), fets_eval=fets_eval) avg_processor = RTNonlocalAvg( avg_fn=QuarticAF(radius=self.avg_radius, correction=True)) eps_app = RTraceDomainListField(name='Strain', position='int_pnts', var='eps_app', warp=False) damage = RTraceDomainListField(name='Damage', position='int_pnts', var='omega', warp=False) disp = RTraceDomainListField(name='Displacement', position='int_pnts', var='u', warp=False) sig_app = RTraceDomainListField(name='Stress', position='int_pnts', var='sig_app') right_dof = domain[-1, -1].dofs[0, 0, 0] rt_fu = RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=right_dof, var_x='U_k', idx_x=right_dof) ts = TS( u_processor=avg_processor, dof_resultants=True, sdomain=domain, # conversion to list (square brackets) is only necessary for slicing of # single dofs, e.g "get_left_dofs()[0,1]" # bcond_list = [ BCDof(var='u', dof = 0, value = 0.) ] + # [ BCDof(var='u', dof = 2, value = 0.001 ) ]+ # [ ) ], bcond_list=[ BCDof(var='u', dof=0, value=0.), # BCDof(var='u', dof = 1, link_dofs = [2], link_coeffs = [0.5], # value = 0. ), # BCDof(var='u', dof = 2, link_dofs = [3], link_coeffs = [1.], # value = 0. ), BCDof( var='u', dof=right_dof, value=0.01, ) ], rtrace_list=[ rt_fu, eps_app, # damage, sig_app, disp, ]) # Add the time-loop control tloop = TLoop(tstepper=ts, KMAX=100, tolerance=1e-5, verbose_iteration=False, tline=TLine(min=0.0, step=1.0, max=1.0)) U = tloop.eval() p.subplot(221) rt_fu.refresh() rt_fu.trace.plot(p) eps = eps_app.subfields[0] xdata = eps.vtk_X[:, 0] ydata = eps.field_arr[:, 0, 0] idata = argsort(xdata) p.subplot(222) p.plot(xdata[idata], ydata[idata], 'o-') disp = disp.subfields[0] xdata = disp.vtk_X[:, 0] ydata = disp.field_arr[:, 0] idata = argsort(xdata) p.subplot(223) p.plot(xdata[idata], ydata[idata], 'o-') sig = sig_app.subfields[0] xdata = sig.vtk_X[:, 0] ydata = sig.field_arr[:, 0, 0] idata = argsort(xdata) p.subplot(224) p.plot(xdata[idata], ydata[idata], 'o-')
def app(): avg_radius = 0.03 md = MATS2DScalarDamage( E=20.0e3, nu=0.2, epsilon_0=1.0e-4, epsilon_f=8.0e-4, #epsilon_f = 12.0e-4, #test doubling the e_f stress_state="plane_strain", stiffness="secant", #stiffness = "algorithmic", strain_norm=Rankine()) mdm = MATS2DMicroplaneDamage( E=20.0e3, nu=0.2, #epsilon_f = 12.0e-4, #test doubling the e_f stress_state="plane_strain", model_version='compliance', phi_fn=PhiFnStrainSoftening(G_f=0.0014, f_t=2.0, md=0.0, h=2. * avg_radius)) # mp = MATSProxy( mats_eval = mdm ) # mp.varpars['epsilon_0'].switch = 'varied' # mp.varpars['epsilon_0'].spatial_fn = MFnNDGrid( shape = ( 8, 5, 1 ), # active_dims = ['x', 'y'], # x_mins = GridPoint( x = 0., y = 0. ), # x_maxs = GridPoint( x = length, y = heigth ) ) # mp.varpars['epsilon_0'].spatial_fn.set_values_in_box( 500., [0, 0, 0], [0.2, 0.2, 0.] ) # mp.varpars['epsilon_0'].spatial_fn.set_values_in_box( 500., [0.8, 0, 0], [1., 0.2, 0.] ) # mp.varpars['epsilon_0'].spatial_fn.set_values_in_box( 50., [0., 0.46, 0], [1., 0.5, 0.] ) # me = MATS2DElastic( E = 20.0e3, # nu = 0.2, # stress_state = "plane_strain" ) fets_eval = FETS2D4Q(mats_eval=mdm) #, ngp_r = 3, ngp_s = 3) n_el_x = 20 # 60 # Discretization fe_grid = FEGrid(coord_max=(.6, .15, 0.), shape=(n_el_x, n_el_x / 4), fets_eval=fets_eval) mf = MFnLineArray(xdata=array([0, 1, 2]), ydata=array([0, 3., 3.2])) #averaging function avg_processor = RTNonlocalAvg( avg_fn=QuarticAF(radius=avg_radius, correction=True)) loading_dof = fe_grid[n_el_x / 2, -1, 0, -1].dofs.flatten()[1] print('loading_dof', loading_dof) ts = TS( sdomain=fe_grid, u_processor=avg_processor, bcond_list=[ # constraint for all left dofs in y-direction: BCSlice(var='u', slice=fe_grid[0, 0, 0, 0], dims=[0, 1], value=0.), BCSlice(var='u', slice=fe_grid[-1, 0, -1, 0], dims=[1], value=0.), BCSlice(var='u', slice=fe_grid[n_el_x / 2, -1, 0, -1], dims=[1], time_function=mf.get_value, value=-2.0e-4), ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=loading_dof, var_x='U_k', idx_x=loading_dof, record_on='update'), RTraceDomainListField(name='Deformation', var='eps_app', idx=0, record_on='update'), RTraceDomainListField(name='Deformation', var='sig_app', idx=0, record_on='update'), RTraceDomainListField(name='Displacement', var='u', idx=1, record_on='update', warp=True), RTraceDomainListField(name='fracture_energy', var='fracture_energy', idx=0, record_on='update', warp=True), RTraceDomainListField(name='Damage', var='omega_mtx', idx=0, warp=True, record_on='update'), # RTraceDomainField(name = 'Stress' , # var = 'sig', idx = 0, # record_on = 'update'), # RTraceDomainField(name = 'N0' , # var = 'N_mtx', idx = 0, # record_on = 'update') ]) # Add the time-loop control # tl = TLoop(tstepper=ts, tolerance=5.0e-5, KMAX=200, tline=TLine(min=0.0, step=.1, max=1.0)) tl.eval() # Put the whole stuff into the simulation-framework to map the # individual pieces of definition into the user interface. # from ibvpy.plugins.ibvpy_app import IBVPyApp ibvpy_app = IBVPyApp(ibv_resource=ts) ibvpy_app.main()
'sig_norm': self.get_sig_norm, 'eps_p': self.get_eps_p } if __name__ == '__main__': #------------------------------------------------------------------------- # Example using the mats2d_explore #------------------------------------------------------------------------- from ibvpy.api import RTDofGraph from ibvpy.mats.mats2D.mats2D_explore import MATS2DExplore from .yield_face2D import J2 mats2D_explore = \ MATS2DExplore(mats2D_eval=MATS2DPlastic(yf=J2()), rtrace_list=[RTDofGraph(name='strain 0 - stress 0', var_x='eps_app', idx_x=0, var_y='sig_app', idx_y=0, record_on='update'), RTDofGraph(name='strain 0 - strain 1', var_x='eps_app', idx_x=0, var_y='eps_app', idx_y=1, record_on='update'), RTDofGraph(name='stress 0 - stress 1', var_x='sig_app', idx_x=0, var_y='sig_app', idx_y=1, record_on='update'), RTDofGraph(name='time - sig_norm', var_x='time', idx_x=0, var_y='sig_norm', idx_y=0, record_on='update') ])
def example_2d(): from ibvpy.mats.mats2D.mats2D_elastic.mats2D_elastic import MATS2DElastic from ibvpy.fets.fets2D.fets2D4q import FETS2D4Q fets_eval = FETS2D4Q(mats_eval=MATS2DElastic(E=2.1e5)) # Discretization fe_domain1 = FEGrid(coord_max=(2., 5., 0.), shape=(10, 10), fets_eval=fets_eval) fe_subgrid1 = FERefinementLevel(parent=fe_domain1, fine_cell_shape=(1, 1)) print('children') print(fe_domain1.children) fe_subgrid1.refine_elem((5, 5)) fe_subgrid1.refine_elem((6, 5)) fe_subgrid1.refine_elem((7, 5)) fe_subgrid1.refine_elem((8, 5)) fe_subgrid1.refine_elem((9, 5)) fe_domain = FEDomain(subdomains=[fe_domain1]) ts = TS( dof_resultants=True, sdomain=fe_domain, bcond_list=[ BCDofGroup(var='f', value=0.1, dims=[0], get_dof_method=fe_domain1.get_top_dofs), BCDofGroup(var='u', value=0., dims=[0, 1], get_dof_method=fe_domain1.get_bottom_dofs), ], rtrace_list=[ RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=0, var_x='U_k', idx_x=1), RTraceDomainListField(name='Stress', var='sig_app', idx=0, warp=True), # RTraceDomainField(name = 'Displacement' , # var = 'u', idx = 0), # RTraceDomainField(name = 'N0' , # var = 'N_mtx', idx = 0, # record_on = 'update') ]) # Add the time-loop control tloop = TLoop(tstepper=ts, tline=TLine(min=0.0, step=1, max=1.0)) # print(tloop.eval()) from ibvpy.plugins.ibvpy_app import IBVPyApp ibvpy_app = IBVPyApp(ibv_resource=tloop) ibvpy_app.main()
def example(): from ibvpy.api import \ TStepper as TS, RTDofGraph, RTraceDomainListField, TLoop, \ TLine, IBVPSolve as IS, DOTSEval, BCSlice from ibvpy.mesh.fe_grid import FEGrid from mathkit.mfn import MFnLineArray stiffness_concrete = 34000 * 0.03 * 0.03 A_fiber = 1. E_fiber = 1. stiffness_fiber = E_fiber * A_fiber d = 2 * sqrt(Pi) tau_max = 0.1 * d * Pi G = 100 u_max = 0.023 f_max = 0.2 mats_eval = MATS1D5Bond(mats_phase1=MATS1DElastic(E=stiffness_fiber), mats_phase2=MATS1DElastic(E=0), mats_ifslip=MATS1DPlastic(E=G, sigma_y=tau_max, K_bar=0., H_bar=0.), mats_ifopen=MATS1DElastic(E=0)) fets_eval = FETS1D52L4ULRH(mats_eval=mats_eval) domain = FEGrid(coord_max=(1., 0.2), shape=(16, 1), fets_eval=fets_eval) end_dof = domain[-1, 0, -1, 0].dofs[0, 0, 0] ts = TS(dof_resultants=True, sdomain=domain, # conversion to list (square brackets) is only necessary for slicing of # single dofs, e.g "get_left_dofs()[0,1]" bcond_list=[ BCSlice(var='u', value=0., dims=[0], slice=domain[:, :, :, -1]), BCSlice(var='u', value=0., dims=[1], slice=domain[:, :, :, :]), BCSlice(var='f', value=f_max, dims=[0], slice=domain[-1, 0, -1, 0]) ], rtrace_list=[RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=end_dof, var_x='U_k', idx_x=end_dof), RTraceDomainListField(name='slip', var='slip', idx=0), RTraceDomainListField(name='eps1', var='eps1', idx=0), RTraceDomainListField(name='eps2', var='eps2', idx=0), RTraceDomainListField(name='shear_flow', var='shear_flow', idx=0), RTraceDomainListField(name='sig1', var='sig1', idx=0), RTraceDomainListField(name='sig2', var='sig2', idx=0), RTraceDomainListField(name='Displacement', var='u', idx=0) ]) # Add the time-loop control tloop = TLoop(tstepper=ts, KMAX=30, debug=False, tline=TLine(min=0.0, step=0.1, max=1.0)) print(tloop.eval()) # Put the whole stuff into the simulation-framework to map the # individual pieces of definition into the user interface. # from ibvpy.plugins.ibvpy_app import IBVPyApp app = IBVPyApp(ibv_resource=tloop) app.main()
def simgrid( fets_eval, cube_size, shape, support_slices, support_dirs, loading_slice, load_dir=0, load_max=0.01, n_load_steps=1, vars=[], ivars=[], var_type='u', ): '''Construct an idealization and run simulation with primary variable fixed on support slices and with unit load on loading slices applied in load dir. Return the solution vector and the fields specified in vars. ''' # Discretization domain = FEGrid(coord_max=cube_size, shape=shape, fets_eval=fets_eval) u_max = load_max support_bcond = [ BCSlice(var='u', value=0, dims=support_dir, slice=domain[support_slice]) for support_slice, support_dir in zip(support_slices, support_dirs) ] load_bcond = [ BCSlice(var=var_type, value=u_max, dims=[load_dir], slice=domain[loading_slice]) ] bcond = support_bcond + load_bcond loading_dofs = domain[loading_slice].dofs[:, :, load_dir].flatten() graphs = [ RTDofGraph(name='Force in one node / Displ.', var_y='F_int', idx_x=loading_dof, var_x='U_k', idx_y=loading_dof) for loading_dof in loading_dofs ] rtrace_list = [ RTraceDomainListField( name=var, var=var, warp=True, #position = 'int_pnts', record_on='update') for var in vars ] irtrace_list = [ RTraceDomainListInteg(name='Integ(' + var + ')', var=var, record_on='update') for var in ivars ] ts = TS(sdomain=domain, bcond_list=bcond, rtrace_list=graphs + rtrace_list + irtrace_list) load_step = 1. / float(n_load_steps) # Add the time-loop control tloop = TLoop(tstepper=ts, KMAX=15, RESETMAX=0, tolerance=1e-5, tline=TLine(min=0.0, step=load_step, max=1.0)) u = tloop.eval() fields = [rtrace.subfields[0].field_arr for rtrace in rtrace_list] integs = [rtrace.integ_val for rtrace in irtrace_list] for graph in graphs: graph.redraw() traces = [graph.trace for graph in graphs] xydata = (traces[0].xdata, column_stack([trace.ydata for trace in traces])) return tloop, u, fields, integs, xydata
fets_eval=fets_eval ) ts = TS(sdomain=domain, dof_resultants=True ) tloop = TLoop(tstepper=ts, tline=TLine(min=0.0, step=1, max=1.0)) '''Clamped bar loaded at the right end with unit displacement [00]-[01]-[02]-[03]-[04]-[05]-[06]-[07]-[08]-[09]-[10] 'u[0] = 0, u[10] = 1''' domain.coord_max = (10, 0, 0) domain.shape = (10,) ts.bcond_list = [BCDof(var='u', dof=0, value=0.), BCDof(var='u', dof=10, value=1.)] ts.rtrace_list = [RTDofGraph(name='Fi,right over u_right (iteration)', var_y='F_int', idx_y=10, var_x='U_k', idx_x=10)] u = tloop.eval() # expected solution u_ex = array([0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.], dtype=float) difference = sqrt(norm(u - u_ex)) print('difference') # compare the reaction at the left end F = ts.F_int[0] print(F)
def main(): # Get the default mayavi plugins. plugins = get_plugins() from .rtrace_plugin import RTracePlugin from .rtrace_service import RTraceService # Inject our plugin up front so our perspective becomes the default. #plugins = [ RTracePlugin() ] plugins.insert(0, RTracePlugin()) from .ibvpy_workbench_application import IBVPyWorkbenchApplication # Create an Envisage application. id = 'rtrace_service.rtrace_service' application = IBVPyWorkbenchApplication(id=id, plugins=plugins) rtrace_mgr = RTraceService(rtrace_list=[ RTDofGraph(name='rte 1'), RTDofGraph(name='rte 2'), RTDofGraph(name='rte 3'), RTDofGraph(name='rte 4'), RTDofGraph(name='rte 5'), RTDofGraph(name='rte 6'), RTDofGraph(name='rte 7'), RTDofGraph(name='rte 8'), RTDofGraph(name='rte 8'), RTDofGraph(name='rte 10'), RTDofGraph(name='rte 11'), ]) application.register_service('rtrace_service.RTraceService', rtrace_mgr) setup_logger(logger, 'rtrace.log', mode=logging.ERROR) # Start the application. application.run()