def __init__(self,rawfield,name): self._name = name self._rawfield = rawfield #learn about degrees of freedom: tmp_dof_maxind_by_name = {} self.dof_names = [] self.dofs = [] dof_maxnames = ocaml.data_doftypes(self._rawfield) for dofname,maxind in dof_maxnames: tmp_dof_maxind_by_name[dofname] = maxind #populate degrees of freedom vecdofs = {} def cb(i, dof_name_stem, site, pos, value): site = tuple(site) dofname, ind = dof_name_stem #have we seen this dof before? if not vecdofs.has_key(dofname): vecdofs[dofname]={} #have we seen this site before? if not vecdofs[dofname].has_key(site): maxind = tmp_dof_maxind_by_name[dofname] data = make_dof_list_structure(maxind,None) dof_id = copy.copy(data) vecdofs[dofname][site] = [data,pos,site,dof_id] if ind==[]: #scalar vecdofs[dofname][site][0] = value vecdofs[dofname][site][3] = i else: vecdofs[dofname][site][0][ind[0]] = value vecdofs[dofname][site][3][ind[0]] = i nfem.field_entry_wise( self._rawfield, cb ) #now sort into neat vectors for dofname,maxind in dof_maxnames: tmp = vecdofs[dofname].values() data = map( lambda a : a[0], tmp) pos = map( lambda a : a[1], tmp) site = map( lambda a : a[2], tmp) dof_id = map( lambda a : a[3], tmp) tmpdof = VectorDOF(dofname,data,pos,site,dof_id,maxind) self.__setattr__(dofname,tmpdof) self.dof_names.append(dofname) self.dofs.append(tmpdof)
def __init__(self, rawfield, name): self._name = name self._rawfield = rawfield #learn about degrees of freedom: tmp_dof_maxind_by_name = {} self.dof_names = [] self.dofs = [] dof_maxnames = ocaml.data_doftypes(self._rawfield) for dofname, maxind in dof_maxnames: tmp_dof_maxind_by_name[dofname] = maxind #populate degrees of freedom vecdofs = {} def cb(i, dof_name_stem, site, pos, value): site = tuple(site) dofname, ind = dof_name_stem #have we seen this dof before? if not vecdofs.has_key(dofname): vecdofs[dofname] = {} #have we seen this site before? if not vecdofs[dofname].has_key(site): maxind = tmp_dof_maxind_by_name[dofname] data = make_dof_list_structure(maxind, None) dof_id = copy.copy(data) vecdofs[dofname][site] = [data, pos, site, dof_id] if ind == []: #scalar vecdofs[dofname][site][0] = value vecdofs[dofname][site][3] = i else: vecdofs[dofname][site][0][ind[0]] = value vecdofs[dofname][site][3][ind[0]] = i nfem.field_entry_wise(self._rawfield, cb) #now sort into neat vectors for dofname, maxind in dof_maxnames: tmp = vecdofs[dofname].values() data = map(lambda a: a[0], tmp) pos = map(lambda a: a[1], tmp) site = map(lambda a: a[2], tmp) dof_id = map(lambda a: a[3], tmp) tmpdof = VectorDOF(dofname, data, pos, site, dof_id, maxind) self.__setattr__(dofname, tmpdof) self.dof_names.append(dofname) self.dofs.append(tmpdof)
def data_doftypes(x): """Given a raw ocaml field, this returns a list of pairs. Each pair contains first the name of the subfield and second the shape information for this subfield.""" result = ocaml.data_doftypes(x) #log.debug("doftypes of XXX is %s" % str(result)) return result
def data_doftypes(x): """Given a raw ocaml field, this returns a list of pairs. Each pair contains first the name of the subfield and second the shape information for this subfield.""" result = ocaml.data_doftypes(x) # log.debug("doftypes of XXX is %s" % str(result)) return result