def test4(self): class OneSettable(object): is_enabled = 0 def is_stopping_condition_enabled(self, sc_type): print sc_type, self.is_enabled return self.is_enabled if sc_type == 0 else 0 def has_stopping_condition(self, sc_type): return 1 if sc_type == 0 else 0 def enable_stopping_condition(self, sc_type): if sc_type == 0: self.is_enabled = 1 def disable_stopping_condition(self, sc_type): if sc_type == 0: self.is_enabled = 0 instance = StoppingConditions(OneSettable()) self.assertTrue(instance.collision_detection.is_supported()) self.assertFalse(instance.collision_detection.is_enabled()) instance.collision_detection.enable() self.assertTrue(instance.collision_detection.is_enabled()) instance.collision_detection.disable() self.assertFalse(instance.collision_detection.is_enabled())
def test7(self): class Collision(object): def is_stopping_condition_enabled(self, sc_type): return 1 if sc_type == 0 else 0 def has_stopping_condition(self, sc_type): return 1 if sc_type == 0 else 0 def is_stopping_condition_set(self, sc_type): return 1 if sc_type == 0 else 0 def get_number_of_stopping_conditions_set(self): return 1 def get_stopping_condition_info(self, indices): return [0],[3] instance = StoppingConditions(Collision()) instance.code.particles = datamodel.Particles(3) instance.code.particles.mass = (1,2,3) | units.kg instance.code.particles.add_function_attribute( "get_stopping_condition_particle_index", lambda particles, indices, sc_type : particles[indices] ) self.assertTrue(instance.collision_detection.is_set()) particles = instance.collision_detection.particles(0) self.assertEquals(len(particles),1) particles = instance.collision_detection.particles(1) self.assertEquals(len(particles),1) particles = instance.collision_detection.particles(2) self.assertEquals(len(particles),1) particles = instance.collision_detection.particles(3) self.assertEquals(len(particles),0)
def __init__(self, mode=MODE_2D, coordinates="cartesian", **options): self.mode = mode self.coordinates = coordinates CommonCode.__init__(self, AdcircInterface(**options), **options) self._nodes = None self._elements = None self._elev_boundary = None self._flow_boundary = None self._parameters = None self.stopping_conditions = StoppingConditions(self)
def test5(self): class OneEnabled(object): def is_stopping_condition_enabled(self, sc_type): return 1 if sc_type == 0 else 0 def has_stopping_condition(self, sc_type): return 1 if sc_type == 0 else 0 instance = StoppingConditions(OneEnabled()) self.assertFalse(instance.escaper_detection.is_supported()) self.assertFalse(instance.escaper_detection.is_enabled()) self.assertRaises(AmuseException, instance.escaper_detection.enable) self.assertRaises(AmuseException, instance.escaper_detection.disable)
def test2(self): class OneEnabled(object): def is_stopping_condition_enabled(self, sc_type): return 1 if sc_type == 0 else 0 def has_stopping_condition(self, sc_type): return 1 if sc_type == 0 else 0 instance = StoppingConditions(OneEnabled()) self.assertTrue(instance.collision_detection.is_supported()) self.assertTrue(instance.collision_detection.is_enabled()) self.assertFalse(instance.escaper_detection.is_supported()) self.assertFalse(instance.escaper_detection.is_enabled()) self.assertFalse(instance.timeout_detection.is_supported()) self.assertFalse(instance.timeout_detection.is_enabled())
def test1(self): class AllEnabled(object): def is_stopping_condition_enabled(self, sc_type): return 1 def has_stopping_condition(self, sc_type): return 1 instance = StoppingConditions(AllEnabled()) self.assertTrue(instance.collision_detection.is_supported()) self.assertTrue(instance.collision_detection.is_enabled()) self.assertTrue(instance.escaper_detection.is_supported()) self.assertTrue(instance.escaper_detection.is_enabled()) self.assertTrue(instance.timeout_detection.is_supported()) self.assertTrue(instance.timeout_detection.is_enabled())
def __init__(self, **options): #print('__init__') self.stopping_conditions = StoppingConditions(self) self.itot = 0 self.ktot = 0 self.latitudes = None self.longitudes = None self.exp_name = 'TEST' CommonCode.__init__(self, OpenIFSInterface(**options), **options) #if workdir is given, assume inputfile, backupfile are relative to workdir #TODO should store the changed file names - they are used in cleanup_code inputfile = OpenIFS.inputfile backupfile = OpenIFS.backupfile if 'workdir' in options: # print('OpenIFS.__init__() : setting workdir.') self.set_workdir(options['workdir']) inputfile = os.path.join(options['workdir'], inputfile) backupfile = os.path.join(options['workdir'], backupfile) if not os.path.exists(inputfile): print('inputfile:' + inputfile) print('cwd:' + os.getcwd()) raise Exception( "File fort.4 not found. Creating an openIFS model from scratch is not supported yet." ) else: os.rename(inputfile, backupfile) self.params = f90nml.read(backupfile) self.patch = { "NAMPAR0": { "NPROC": options.get("number_of_workers", 1) } } restart_steps = options.get("restart_steps", None) if restart_steps: self.patch["NAMRES"] = {"NFRRES": restart_steps} f90nml.patch(backupfile, self.patch, inputfile) print('Done patching openIFS input file', inputfile)
def __init__(self, unit_converter=None, **options): self.stopping_conditions = StoppingConditions(self) GravitationalDynamics.__init__(self, StubInterface(**options), unit_converter, **options)