def getFoldedPosition(self, pos, imageBox=None): if not (pmi._PMIComm and pmi._PMIComm.isActive()) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup() or pmi.isController: if imageBox is None: return self.cxxclass.getFoldedPosition(self, toReal3DFromVector(pos)) else: return self.cxxclass.getFoldedPosition( self, toReal3DFromVector(pos), toInt3DFromVector(imageBox))
def scaleVolume(self, *args): if pmi.workerIsActive(): if len(args) == 1: arg0 = args[0] if isinstance(arg0, Real3D): #print arg0," is a Real3D object" self.cxxclass.scaleVolume( arg0 ) elif hasattr(arg0, '__iter__'): if len(arg0) == 3: #print args, " has iterator and length 3" self.cxxclass.scaleVolume(self, toReal3DFromVector(arg0) ) elif len(arg0) == 1: #print args, " has iterator and length 1" self.cxxclass.scaleVolume(self, toReal3DFromVector(arg0[0], arg0[0], arg0[0]) ) else: print args, " is invalid" else: #print args, " is scalar" self.cxxclass.scaleVolume(self, toReal3DFromVector( [arg0, arg0, arg0] ) ) elif len(args) == 3: #print args, " is 3 numbers" self.cxxclass.scaleVolume(self, toReal3DFromVector(*args) ) else: print args, " is invalid"
def scaleVolume(self, *args): if pmi.workerIsActive(): if len(args) == 1: arg0 = args[0] if isinstance(arg0, Real3D): #print arg0," is a Real3D object" self.cxxclass.scaleVolume( arg0 ) elif hasattr(arg0, '__iter__'): if len(arg0) == 3: #print args, " has iterator and length 3" self.cxxclass.scaleVolume(self, toReal3DFromVector(arg0) ) elif len(arg0) == 1: #print args, " has iterator and length 1" self.cxxclass.scaleVolume(self, toReal3DFromVector(arg0[0], arg0[0], arg0[0]) ) else: print(args, " is invalid") else: #print args, " is scalar" self.cxxclass.scaleVolume(self, toReal3DFromVector( [arg0, arg0, arg0] ) ) elif len(args) == 3: #print args, " is 3 numbers" self.cxxclass.scaleVolume(self, toReal3DFromVector(*args) ) else: print(args, " is invalid")
def computeForce(self, *args): if not (pmi._PMIComm and pmi._PMIComm.isActive()) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): if len(args) == 1: arg0 = args[0] if isinstance(arg0, float) or isinstance(arg0, int): newargs = [arg0, 0, 0] return self.cxxclass.computeForce(self, toReal3DFromVector(*newargs))[0] return self.cxxclass.computeForce(self, toReal3DFromVector(*args))
def getFoldedPosition(self, pos, imageBox=None): if not (pmi._PMIComm and pmi._PMIComm.isActive() ) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup( ) or pmi.isController: if imageBox is None: return self.cxxclass.getFoldedPosition(self, toReal3DFromVector(pos)) else: return self.cxxclass.getFoldedPosition( self, toReal3DFromVector(pos), toInt3DFromVector(imageBox))
def computeForce(self, *args): if not (pmi._PMIComm and pmi._PMIComm.isActive() ) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): if len(args) == 1: arg0 = args[0] if isinstance(arg0, float) or isinstance(arg0, int): newargs = [arg0, 0, 0] return self.cxxclass.computeForce( self, toReal3DFromVector(*newargs))[0] return self.cxxclass.computeForce(self, toReal3DFromVector(*args))
def computeForce(self, *args): if not (pmi._PMIComm and pmi._PMIComm.isActive()) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): if len(args) == 1: # in case theta is passed arg0 = args[0] if isinstance(arg0, float) or isinstance(arg0, int): return self.cxxclass.computeForce(self, arg0) return self.cxxclass.computeForce(self, toReal3DFromVector(*args))
def addParticlesArray(self, particleList, *properties): if not (pmi._PMIComm and pmi._PMIComm.isActive() ) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): index_id = -1 index_posx = -1 ### Real3D index_posy = -1 index_posz = -1 index_modeposx = -1 ### Real3D index_modeposy = -1 index_modeposz = -1 index_vx = -1 ### Real3D index_vy = -1 index_vz = -1 index_modemomx = -1 ### Real3D index_modemomy = -1 index_modemomz = -1 index_fx = -1 ### Real3D index_fy = -1 index_fz = -1 index_fmx = -1 ### Real3D index_fmy = -1 index_fmz = -1 index_q = -1 index_radius = -1 index_fradius = -1 index_vradius = -1 index_type = -1 index_mass = -1 index_varmass = -1 index_adrAT = -1 # adress AT particle if 1 index_lambda_adr = -1 index_lambda_adrd = -1 index_state = -1 index_pib = -1 last_pos = toReal3DFromVector([-99, -99, -99]) if properties == None: # default properties = (id, pos) index_id = 0 index_posx = 1 index_posy = 2 index_posz = 3 nindex = 4 else: for nindex, val in enumerate(properties): if val.lower() == "id": index_id = nindex elif val.lower() == "posx": index_posx = nindex elif val.lower() == "posy": index_posy = nindex elif val.lower() == "posz": index_posz = nindex elif val.lower() == "modeposx": index_modeposx = nindex elif val.lower() == "modeposy": index_modeposy = nindex elif val.lower() == "modeposz": index_modeposz = nindex elif val.lower() == "type": index_type = nindex elif val.lower() == "mass": index_mass = nindex elif val.lower() == "varmass": index_varmass = nindex elif val.lower() == "vx": index_vx = nindex elif val.lower() == "vy": index_vy = nindex elif val.lower() == "vz": index_vz = nindex elif val.lower() == "modemomx": index_modemomx = nindex elif val.lower() == "modemomy": index_modemomy = nindex elif val.lower() == "modemomz": index_modemomz = nindex elif val.lower() == "fx": index_fx = nindex elif val.lower() == "fy": index_fy = nindex elif val.lower() == "fz": index_fz = nindex elif val.lower() == "fmx": index_fmx = nindex elif val.lower() == "fmy": index_fmy = nindex elif val.lower() == "fmz": index_fmz = nindex elif val.lower() == "q": index_q = nindex elif val.lower() == "radius": index_radius = nindex elif val.lower() == "fradius": index_fradius = nindex elif val.lower() == "vradius": index_vradius = nindex elif val.lower() == "adrat": index_adrAT = nindex elif val.lower() == "lambda_adr": index_lambda_adr = nindex elif val.lower() == "lambda_adrd": index_lambda_adrd = nindex elif val.lower() == "state": index_state = nindex elif val.lower() == "pib": index_pib = nindex else: raise SyntaxError("unknown particle property: %s" % val) assert index_id >= 0, "particle property id is mandatory" assert index_posx >= 0, "particle property posx is mandatory" assert index_posy >= 0, "particle property posy is mandatory" assert index_posz >= 0, "particle property posz is mandatory" def check3DProperty(prop, ix, iy, iz): assert ((ix>=0)==(iy>=0) and (iy>=0)==(iz>=0)), \ "Missing at least one of the 3d coordinates of property \"{}\"".format(prop) check3DProperty("pos", index_posx, index_posy, index_posz) check3DProperty("v", index_vx, index_vy, index_vz) check3DProperty("f", index_fx, index_fy, index_fz) check3DProperty("fm", index_fmx, index_fmy, index_fmz) check3DProperty("modepos", index_modeposx, index_modeposy, index_modeposz) check3DProperty("modemom", index_modemomx, index_modemomy, index_modemomz) indices = np.array([ index_id, index_posx, index_posy, index_posz, index_modeposx, index_modeposy, index_modeposz, index_vx, index_vy, index_vz, index_modemomx, index_modemomy, index_modemomz, index_fx, index_fy, index_fz, index_fmx, index_fmy, index_fmz, index_q, index_radius, index_fradius, index_vradius, index_type, index_mass, index_varmass, index_adrAT, index_lambda_adr, index_lambda_adrd, index_state, index_pib ], dtype=np.int32) self.cxxclass.addParticlesFromArray(self, particleList, indices)
def addParticles(self, particleList, *properties): if not (pmi._PMIComm and pmi._PMIComm.isActive() ) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): index_id = -1 index_pos = -1 index_modepos = -1 index_v = -1 index_modemom = -1 index_f = -1 index_fm = -1 index_q = -1 index_radius = -1 index_fradius = -1 index_vradius = -1 index_type = -1 index_mass = -1 index_varmass = -1 index_adrAT = -1 # adress AT particle if 1 index_lambda_adr = -1 index_lambda_adrd = -1 index_state = -1 index_pib = -1 last_pos = toReal3DFromVector([-99, -99, -99]) if properties == None: # default properities = (id, pos) index_id = 0 index_pos = 1 nindex = 2 else: nindex = 0 for val in properties: if val.lower() == "id": index_id = nindex elif val.lower() == "pos": index_pos = nindex elif val.lower() == "modepos": index_modepos = nindex elif val.lower() == "type": index_type = nindex elif val.lower() == "mass": index_mass = nindex elif val.lower() == "varmass": index_varmass = nindex elif val.lower() == "v": index_v = nindex elif val.lower() == "modemom": index_modemom = nindex elif val.lower() == "f": index_f = nindex elif val.lower() == "fm": index_fm = nindex elif val.lower() == "q": index_q = nindex elif val.lower() == "radius": index_radius = nindex elif val.lower() == "fradius": index_fradius = nindex elif val.lower() == "vradius": index_vradius = nindex elif val.lower() == "adrat": index_adrAT = nindex elif val.lower() == "lambda_adr": index_lambda_adr = nindex elif val.lower() == "lambda_adrd": index_lambda_adrd = nindex elif val.lower() == "state": index_state = nindex elif val.lower() == "pib": index_pib = nindex else: raise SyntaxError("unknown particle property: %s" % val) nindex += 1 if index_id < 0: raise Exception("particle property id is mandatory") if index_pos < 0: raise Exception("particle property pos is mandatory") # we should check at the begin whether all the particles do not exist. doWeAddParticles = True for particle in particleList: pid = particle[index_id] if self.particleExists(pid): doWeAddParticles = False print("WARNING: Particle ", pid, " already exists") if not doWeAddParticles: print( 'WARNING: Some particles already exist. The list of particles was not added.' ) return for particle in particleList: # verify that each particle has enough entries, avoids index errors if len(particle) != nindex: raise SyntaxError( "particle has %d entries, but %d expected" % (len(particle), nindex)) id = particle[index_id] pos = particle[index_pos] if index_adrAT >= 0: if particle[index_adrAT] == 0: storedParticle = self.cxxclass.addParticle( self, id, pos, True) last_pos = pos else: storedParticle = self.cxxclass.addAdrATParticle( self, id, pos, last_pos) else: #print "%d: addParticle %d, last_pos=pos %f, %f, %f"%(pmi._MPIcomm.rank,id,pos[0], pos[1], pos[2]) storedParticle = self.cxxclass.addParticle( self, id, pos, True) if storedParticle is not None: self.logger.debug("Processor %d stores particle id = %d" % (pmi.rank, id)) self.logger.debug( "particle property indexes: id=%i pos=%i type=%i mass=%i v=%i f=%i q=%i radius=%i lambda_adr=%i lambda_adrd=%i state=%i" % (index_id, index_pos, index_type, index_mass, index_v, index_f, index_q, index_radius, index_lambda_adr, index_lambda_adrd, index_state)) # only the owner processor writes other properties if index_v >= 0: storedParticle.v = particle[index_v] if index_modepos >= 0: storedParticle.modepos = particle[index_modepos] if index_modemom >= 0: storedParticle.modemom = particle[index_modemom] if index_f >= 0: storedParticle.f = particle[index_f] if index_fm >= 0: storedParticle.fm = particle[index_fm] if index_q >= 0: storedParticle.q = particle[index_q] if index_radius >= 0: storedParticle.radius = particle[index_radius] if index_fradius >= 0: storedParticle.fradius = particle[index_fradius] if index_vradius >= 0: storedParticle.vradius = particle[index_vradius] if index_type >= 0: storedParticle.type = particle[index_type] if index_pib >= 0: storedParticle.pib = particle[index_pib] if index_mass >= 0: storedParticle.mass = particle[index_mass] if index_varmass >= 0: storedParticle.varmass = particle[index_varmass] if index_lambda_adr >= 0: storedParticle.lambda_adr = particle[index_lambda_adr] if index_lambda_adrd >= 0: storedParticle.lambda_adrd = particle[ index_lambda_adrd] if index_state >= 0: storedParticle.state = particle[index_state]
def addAdrATParticle(self, pid, *args): if not (pmi._PMIComm and pmi._PMIComm.isActive() ) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): self.cxxclass.addAdrATParticle(self, pid, toReal3DFromVector(*args))
def f(self, val): self.__getTmp().f = toReal3DFromVector(val)
def pos(self, val): self.__getTmp().pos = toReal3DFromVector(val)
def v(self, val): self.__getTmp().v = toReal3DFromVector(val)
def pos(self, val): self.__getTmp().pos = toReal3DFromVector(val) @property
def addParticles(self, particleList, *properties): if not (pmi._PMIComm and pmi._PMIComm.isActive()) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): index_id = -1 index_pos = -1 index_v = -1 index_f = -1 index_q = -1 index_radius = -1 index_fradius = -1 index_vradius = -1 index_type = -1 index_mass = -1 index_adrAT = -1 # adress AT particle if 1 index_lambda_adr = -1 index_lambda_adrd = -1 index_state = -1 last_pos = toReal3DFromVector([-99,-99,-99]) if properties == None: # default properities = (id, pos) index_id = 0 index_pos = 1 nindex = 2 else: nindex = 0 for val in properties: if val.lower() == "id": index_id = nindex elif val.lower() == "pos": index_pos = nindex elif val.lower() == "type": index_type = nindex elif val.lower() == "mass": index_mass = nindex elif val.lower() == "v": index_v = nindex elif val.lower() == "f": index_f = nindex elif val.lower() == "q": index_q = nindex elif val.lower() == "radius": index_radius = nindex elif val.lower() == "fradius": index_fradius = nindex elif val.lower() == "vradius": index_vradius = nindex elif val.lower() == "adrat": index_adrAT = nindex elif val.lower() == "lambda_adr": index_lambda_adr = nindex elif val.lower() == "lambda_adrd": index_lambda_adrd = nindex elif val.lower() == "state": index_state = nindex else: raise SyntaxError("unknown particle property: %s"%val) nindex += 1 if index_id < 0 : raise "particle property id is mandatory" if index_pos < 0 : raise "particle property pos is mandatory" # we should check at the begin whether all the particles do not exist. doWeAddParticles = True for particle in particleList: pid = particle[index_id] if( self.particleExists(pid) ): doWeAddParticles = False print "WARNING: Particle ", pid, " already exists" if(not doWeAddParticles): print 'WARNING: Some particles already exist. The list of particles was not added.' return for particle in particleList: # verify that each particle has enough entries, avoids index errors if len(particle) != nindex: raise SyntaxError("particle has %d entries, but %d expected"%(len(particle), nindex)) id = particle[index_id] pos = particle[index_pos] if index_adrAT >= 0: if particle[index_adrAT] == 0: #print "%d: addParticle %d, last_pos=pos %f, %f, %f"%(pmi._MPIcomm.rank,id,pos[0], pos[1], pos[2]) storedParticle = self.cxxclass.addParticle(self, id, pos) last_pos = pos else: #print "%d: addAdrATparticle %d, pos %f, %f, %f, last_pos %f, %f, %f"%(pmi._MPIcomm.rank,id,pos[0],pos[1],pos[2],last_pos[0], last_pos[1], last_pos[2]) storedParticle = self.cxxclass.addAdrATParticle(self, id, pos, last_pos) else: #print "%d: addParticle %d, last_pos=pos %f, %f, %f"%(pmi._MPIcomm.rank,id,pos[0], pos[1], pos[2]) storedParticle = self.cxxclass.addParticle(self, id, pos) if storedParticle != None: self.logger.debug("Processor %d stores particle id = %d"%(pmi.rank, id)) self.logger.debug("particle property indexes: id=%i pos=%i type=%i mass=%i v=%i f=%i q=%i radius=%i lambda_adr=%i lambda_adrd=%i state=%i"%(index_id,index_pos,index_type,index_mass,index_v,index_f,index_q,index_radius,index_lambda_adr,index_lambda_adrd,index_state)) # only the owner processor writes other properties if index_v >= 0: storedParticle.v = particle[index_v] if index_f >= 0: storedParticle.f = particle[index_f] if index_q >= 0: storedParticle.q = particle[index_q] if index_radius >= 0: storedParticle.radius = particle[index_radius] if index_fradius >= 0: storedParticle.fradius = particle[index_fradius] if index_vradius >= 0: storedParticle.vradius = particle[index_vradius] if index_type >= 0: storedParticle.type = particle[index_type] if index_mass >= 0: storedParticle.mass = particle[index_mass] if index_lambda_adr >= 0: storedParticle.lambda_adr = particle[index_lambda_adr] if index_lambda_adrd >= 0: storedParticle.lambda_adrd = particle[index_lambda_adrd] if index_state >= 0: storedParticle.state = particle[index_state]
def f(self, val): self.__getTmp().f = toReal3DFromVector(val) @property
def getMinimumImageVector(self, pos1, pos2): if not (pmi._PMIComm and pmi._PMIComm.isActive() ) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup( ) or pmi.isController: return self.cxxclass.getMinimumImageVector( self, toReal3DFromVector(pos1), toReal3DFromVector(pos2))
def getMinimumImageVector(self, pos1, pos2): if not (pmi._PMIComm and pmi._PMIComm.isActive()) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup() or pmi.isController: return self.cxxclass.getMinimumImageVector( self, toReal3DFromVector(pos1), toReal3DFromVector(pos2))
def modemom(self, val): self.__getTmp().modemom = toReal3DFromVector(val)
def computeForce(self, position, bc): if not (pmi._PMIComm and pmi._PMIComm.isActive()) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): return self.cxxclass.computeForce(self, toReal3DFromVector(position), bc)
def computeForce(self, position, bc): if not (pmi._PMIComm and pmi._PMIComm.isActive() ) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): return self.cxxclass.computeForce(self, toReal3DFromVector(position), bc)
def addAdrATParticle(self, pid, *args): if not (pmi._PMIComm and pmi._PMIComm.isActive()) or pmi._MPIcomm.rank in pmi._PMIComm.getMPIcpugroup(): self.cxxclass.addAdrATParticle( self, pid, toReal3DFromVector(*args) )