def test_neumann_bc(self): """ we set neumann right cond and check that this is indeed the case""" for met, smet, inner in [('FVM', 'cvode', 'False'), ('FVM', 'cvode_step', 'False'), # ('SIMPLE', 'standard', 'False'), ('FVM', 'odew', 'False'), ('FVM', 'odew_step', 'False'), ]: neumannleft = 1. neumannright = 1.5 inifile = INI_FIBER % { 'intdif': inner, 'method': "'%s'" % met, 'submethod': "'%s'" % smet, 'boundtype': "'flux'", 'boundary_fib_right': '%f' % neumannright, 'tf': '0.', 'evapsatc': "'lambda T: 1.'", 'evaptf': '0.', 'evapmin': '0.', 'outc' : "'lambda t: 0.'", } cfg = FiberConfigManager.get_instance('fiber.ini', realdatastr=inifile) # as we start with an init condition that does not satisfy the # bc, we need a longer time before we satisfy bc somewhat cfg.set('time.time_period', 400.) # we also check left boundary cfg.set('boundary.boundary_fib_left', neumannleft) model = FiberModel(cfg) #pass further execution to the model model.run_init() model.solve_init() if met == 'SIMPLE': startmass = model.simple_sol[0] else: startmass = model.calc_mass(model.initial_c1) model.solve() if met == 'SIMPLE': endmass = model.simple_sol[-1] raise NotImplementedError else: endmass = model.calc_mass(model.conc1[-1]) leftderiv = (model.conc1[-1][1] - model.conc1[-1][0])/((model.delta_r[0]+model.delta_r[1])/2) rightderiv = (model.conc1[-1][-1] - model.conc1[-1][-2])/((model.delta_r[-1]+model.delta_r[-2])/2) #print model.conc1 #print model.conc1[-1] #print rightderiv, neumann ok = allclose([neumannright, neumannleft], [rightderiv, leftderiv], atol=1e-1, rtol=1e-1) #print 'Info: start mass %f, end mass %f' % (startmass, endmass) assert ok, 'Info: neuman cond %s, deriv %s for %s' % \ (str([neumannright, neumannleft]), str([rightderiv, leftderiv]), smet) print 'Info: neuman cond %s, deriv %s for %s' % \ (str([neumannright, neumannleft]), str([rightderiv, leftderiv]), smet) FiberConfigManager.delete('fiber.ini') del model del cfg
def test_zero_flux(self): """ we set zero flux cond and check that mass is conserved""" for met, smet, inner in [('FVM', 'cvode', 'False'), ('FVM', 'cvode_step', 'False'), ('SIMPLE', 'standard', 'False'), ('FVM', 'odew', 'False'), ('FVM', 'odew_step', 'False'), ('FVM', 'cvode', 'True'), ('FVM', 'cvode_step', 'True'), ('SIMPLE', 'standard', 'True'), ('FVM', 'odew', 'True'), ('FVM', 'odew_step', 'True') ]: inifile = INI_FIBER % { 'intdif': inner, 'method': "'%s'" % met, 'submethod': "'%s'" % smet, 'boundtype': "'flux'", 'boundary_fib_right': '0.', 'tf': '0.', 'evapsatc': "'lambda T: 1.'", 'evaptf': '0.', 'evapmin': '0.', 'outc' : "'lambda t: 0.'", } cfg = FiberConfigManager.get_instance('fiber.ini', realdatastr=inifile) model = FiberModel(cfg) #pass further execution to the model model.run_init() model.solve_init() if met == 'SIMPLE': startmass = model.simple_sol[0] else: startmass = model.calc_mass(model.initial_c1) model.solve() if met == 'SIMPLE': endmass = model.simple_sol[-1] else: endmass = model.calc_mass(model.conc1[-1]) ok = allclose([startmass], [endmass], atol=1e-7, rtol=1e-4) #print 'Info: start mass %f, end mass %f' % (startmass, endmass) assert ok, 'Info: start mass %f, end mass %f for %s' % (startmass, endmass, smet) FiberConfigManager.delete('fiber.ini') del model del cfg
pylab.plot(draw_real, poly_polyester(draw_real), '--') pylab.xlim(0., 1.05) pylab.ylim(0., 0.8) pylab.subplot(122) pylab.plot(zone_position_real, ratio_cotton, '*') pylab.plot(draw_real, poly_cotton(draw_real), '-') pylab.xlim(0., 1.05) pylab.ylim(0., 0.8) pylab.axis() pylab.show() raw_input("check the figure") #set up a yarn computation from fiber.config import FiberConfigManager from yarn.config import YarnConfigManager from lib.utils.utils import set_outputdir cfgf1 = FiberConfigManager.get_instance('tmpfiber1.ini', realdatastr=ini_fiber1) cfgf2 = FiberConfigManager.get_instance('tmpfiber2.ini', realdatastr=ini_fiber2) #cfgf3 = FiberConfigManager.get_instance('tmpfiber3.ini', realdatastr=ini_fiber3) cfg = YarnConfigManager.get_instance('tmpyarn.ini', realdatastr=ini_yarn) #create outputdir if not existing if not os.path.isdir('temp'): os.mkdir('temp') set_outputdir('temp') #create 10 2D grids for statistics from yarn2d.yarn2dgrid import Yarn2dGrid grid = Yarn2dGrid(cfg) ouroptions = { 'x_central' : grid.x_central, 'y_central' : grid.y_central, 'number_fiber' : grid.number_fiber, 'number_fiber_blend' : grid.number_fiber_blend,