示例#1
0
 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
示例#2
0
 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