コード例 #1
0
ファイル: visual.py プロジェクト: anyint/nmag-src
def _field2meshdata(nr_points_in_mesh, field, name, dim):
    log.debug("Converting %d-dimensional field %s into mesh-data list" %
              (dim, name))
    log.debug("Creating Matrix with size=(%d,%d)" % (nr_points_in_mesh, dim))

    data = numerix.zeros((nr_points_in_mesh, dim), 'f')

    def cb(i, dofname_index, site, pos, value):

        if len(site) > 1:
            log.critical(
                "Problem -- Have only tested this for 1st order basis functions. Gut feeling is that we only want to export first order data to visualisation but this needs further thought. Order appears to be %d"
                % (len(site)))
            raise NotImplementedError, "This has only been implemented for first order meshes"

        dofname, index = dofname_index
        if dofname == name:
            if dim == 1:
                data[site[0]][0] = value
            elif dim in [2, 3]:
                data[site[0], index[0]] = value
            else:
                log.critical(
                    "Problem -- data seems not 1, not 2d, not3d. What's up? dim=%d"
                    % dim)
                raise NfemUserError, "Shouldn't happen (4d-data?5d-data?...)"
        else:
            pass

    nfem.field_entry_wise(field, cb)

    return data.tolist()
コード例 #2
0
ファイル: visual.py プロジェクト: fangohr/nmag-src
def _field2meshdata(nr_points_in_mesh,field,name,dim):
    log.debug("Converting %d-dimensional field %s into mesh-data list" % (dim,name))
    log.debug("Creating Matrix with size=(%d,%d)" % (nr_points_in_mesh,dim))
    
    data = numerix.zeros((nr_points_in_mesh,dim),'f') 
    
    def cb(i,dofname_index,site,pos,value):

        if len(site) > 1:
            log.critical("Problem -- Have only tested this for 1st order basis functions. Gut feeling is that we only want to export first order data to visualisation but this needs further thought. Order appears to be %d" % (len(site)))
            raise NotImplementedError,"This has only been implemented for first order meshes"
        
        dofname,index = dofname_index
        if dofname == name:
            if dim==1:
                data[site[0]][0] = value
            elif dim in [2,3]:
                data[site[0],index[0]] = value
            else:
                log.critical("Problem -- data seems not 1, not 2d, not3d. What's up? dim=%d" % dim)
                raise NfemUserError,"Shouldn't happen (4d-data?5d-data?...)"
        else:
            pass
            
    nfem.field_entry_wise(field,cb)

    return data.tolist()
コード例 #3
0
ファイル: save_field.py プロジェクト: fangohr/nmag-src
def field_dim(field):
    global dim
    dim = -1

    def callback(i, dof_name_stem, site, pos, value):
        global dim
        dim = len(pos)

    nfem.field_entry_wise(field, callback)
    return dim
コード例 #4
0
ファイル: fields.py プロジェクト: fangohr/nmag-src
    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)
コード例 #5
0
    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)
コード例 #6
0
ファイル: exchange-spring.py プロジェクト: Venkat004/nmag-doc
    if dir == 0:
        return 0.0
    elif dir == 1:
        return math.sin(2.0 * math.pi * coords[0] / 8.0)
    else:
        return math.cos(2.0 * math.pi * coords[0] / 8.0)


mag.set_magnetization(initial_M)


def debugprint(n, stem, site, pos, val):
    print "N=", n, " name=", stem, " site=", site, " pos=", pos, " value=", val


nfem.field_entry_wise(mag.default_simulation_context.field_m, debugprint)

print mag.probe([0.1])
print mag.probe([0.2])
print mag.probe([0.3])
print mag.probe([0.4])

mag.advance_time([0.0, 0.0, 0.0], time=0.001)

import nfem.visual

nfem.visual.fields2vtkfile([mag.default_simulation_context.field_M],
                           'data%05d.vtk' % 0,
                           mesh=mag.default_simulation_context.mesh)

for i in range(1, 40):
コード例 #7
0
ファイル: exchange-spring.py プロジェクト: fangohr/nmag-doc
def initial_M(dof_name,coords):
    print "DDD initial_M(dof_name=\"",dof_name,"\",coords=",coords,")\n"
    dir=dof_name[1][0]
    if dir==0:
        return 0.0
    elif dir==1:
        return math.sin(2.0*math.pi*coords[0]/8.0)
    else:
        return math.cos(2.0*math.pi*coords[0]/8.0)

mag.set_magnetization(initial_M)

def debugprint(n,stem,site,pos,val):
    print "N=",n," name=",stem," site=",site," pos=",pos," value=",val

nfem.field_entry_wise(mag.default_simulation_context.field_m,debugprint)

print mag.probe([0.1])
print mag.probe([0.2])
print mag.probe([0.3])
print mag.probe([0.4])

mag.advance_time([0.0,0.0,0.0],time=0.001)



import nfem.visual

nfem.visual.fields2vtkfile([mag.default_simulation_context.field_M],'data%05d.vtk' % 0,mesh=mag.default_simulation_context.mesh)