Esempio n. 1
0
 def apply(self, femesh, field, time=None, singleFieldDef=False):
     if singleFieldDef:
         # The purpose of calling node.fieldDefCount is to ensure
         # that we don't set the value of a field that is defined
         # in more than one subproblem when that field gets defined
         # on the second subproblem.  Doing so would wipe out a
         # value that might have been set by the first subproblem.
         fniter = femesh.funcnode_iterator()
         while not fniter.end():
             node = fniter.node()
             if node.fieldDefCount(field) == 1:
                 position = node.position()
                 for i in range(field.ndof()):  # field component
                     field.setvalue(femesh, node, i,
                                    self.func(position, time, i))
             fniter.next()
     else:
         fniter = femesh.funcnode_iterator()
         while not fniter.end():
             node = fniter.node()
             if node.hasField(field):
                 position = node.position()
                 for i in range(field.ndof()):  # field component
                     field.setvalue(femesh, node, i,
                                    self.func(position, time, i))
             fniter.next()
Esempio n. 2
0
 def apply(self, femesh, field, time=None, singleFieldDef=False):
     if singleFieldDef:
         # The purpose of calling node.fieldDefCount is to ensure
         # that we don't set the value of a field that is defined
         # in more than one subproblem when that field gets defined
         # on the second subproblem.  Doing so would wipe out a
         # value that might have been set by the first subproblem.
         fniter = femesh.funcnode_iterator()
         while not fniter.end():
             node = fniter.node()
             if node.fieldDefCount(field)==1:
                 position = node.position()
                 for i in range(field.ndof()): # field component
                     field.setvalue(femesh, node, i,
                                    self.func(position, time, i))
             fniter.next()
     else:
         fniter = femesh.funcnode_iterator()
         while not fniter.end():
             node = fniter.node()
             if node.hasField(field):
                 position = node.position()
                 for i in range(field.ndof()): # field component
                     field.setvalue(femesh, node, i,
                                    self.func(position, time, i))
             fniter.next()
Esempio n. 3
0
def writeFields(dfile, meshcontext):
    # Field values
    # fields = ["Displacement", "Temperature"] : ListOfStrings
    # field_values = [(node_index, fvalue0, fvalue1, fvalue2), ....]
    # : ListOfTuplesOfIntFloats

    # When a Mesh is created from a Skeleton, its nodes are created in
    # some (seemingly) arbitrary order, which depends on the order of
    # the nodes and elements in the Skeleton and on the way in which
    # Skeleton and SkeletonElement conspire to build the Mesh.  The
    # order in which the Field values are saved in the data file
    # depends on the order of the Mesh nodes, which depends on this
    # confusing creation history.  But everything is ok, because
    # Meshes are *always* created from Skeletons, and always created
    # the same way.  As long as the Skeleton in the Mesh file has been
    # saved with its nodes in the right order, the Mesh will be
    # created with its nodes in the right order, and the data file
    # will list the Fields in the right order.

    # Since different Nodes may contain different sets of Fields
    # (being in different sets of SubProblems), we need to list which
    # Fields are defined at each Node.  It's not sufficient to use the
    # SubProblem data for this, because Fields may be defined in more
    # than one SubProblem on a Node.  So we need to save a list of
    # Fields for each Node, but in order to save space in the data
    # file, we first create sets of Nodes that contain the same
    # Fields.  Then the list of Fields just has to be saved once for
    # each set of Nodes.  The Fields defined on a Node are determined
    # by the Node's FieldSet, so we can use the fieldSetID.

    femesh = meshcontext.getObject()
    ids, nodesets = getNodeSets(femesh)
    for fieldsetID in ids:
        nodelist = nodesets[fieldsetID]
        fieldnames = femesh.getFieldSetByID(fieldsetID)
        fieldnames.sort()
        fields = [getFieldObj(name) for name in fieldnames]
        values = []
        for node in nodelist:
            fv = [node.index()]
            for field in fields:
                for i in range(field.ndof()):
                    fv.append(field.value(femesh, node, i))
            values.append(tuple(fv))


## TODO: figure out what's wrong with this version, and if it's faster
## when fixed:
#             values = [
#                 tuple(
#                     [node.index()] + [field.value(femesh, node, i)
#                                       for i in range(field.ndof())
#                                       for field in fields]
#                     )
#                 for node in nodelist]
        dfile.startCmd(meshmenu.Load_Field)
        dfile.argument('mesh', meshcontext.path())
        dfile.argument('fields', fieldnames)
        dfile.argument('field_values', values)
        dfile.endCmd()
Esempio n. 4
0
def writeFields(dfile, meshcontext):
    # Field values
    # fields = ["Displacement", "Temperature"] : ListOfStrings
    # field_values = [(node_index, fvalue0, fvalue1, fvalue2), ....]
    # : ListOfTuplesOfIntFloats

    # When a Mesh is created from a Skeleton, its nodes are created in
    # some (seemingly) arbitrary order, which depends on the order of
    # the nodes and elements in the Skeleton and on the way in which
    # Skeleton and SkeletonElement conspire to build the Mesh.  The
    # order in which the Field values are saved in the data file
    # depends on the order of the Mesh nodes, which depends on this
    # confusing creation history.  But everything is ok, because
    # Meshes are *always* created from Skeletons, and always created
    # the same way.  As long as the Skeleton in the Mesh file has been
    # saved with its nodes in the right order, the Mesh will be
    # created with its nodes in the right order, and the data file
    # will list the Fields in the right order.

    # Since different Nodes may contain different sets of Fields
    # (being in different sets of SubProblems), we need to list which
    # Fields are defined at each Node.  It's not sufficient to use the
    # SubProblem data for this, because Fields may be defined in more
    # than one SubProblem on a Node.  So we need to save a list of
    # Fields for each Node, but in order to save space in the data
    # file, we first create sets of Nodes that contain the same
    # Fields.  Then the list of Fields just has to be saved once for
    # each set of Nodes.  The Fields defined on a Node are determined
    # by the Node's FieldSet, so we can use the fieldSetID.

    femesh = meshcontext.getObject()
    ids, nodesets = getNodeSets(femesh)
    for fieldsetID in ids:
        nodelist= nodesets[fieldsetID]
        fieldnames = femesh.getFieldSetByID(fieldsetID)
        fieldnames.sort()
        fields = [getFieldObj(name) for name in fieldnames]
        values = []
        for node in nodelist:
            fv = [node.index()]
            for field in fields:
                for i in range(field.ndof()):
                    fv.append(field.value(femesh, node, i))
            values.append(tuple(fv))
## TODO: figure out what's wrong with this version, and if it's faster
## when fixed:
#             values = [
#                 tuple(
#                     [node.index()] + [field.value(femesh, node, i)
#                                       for i in range(field.ndof())
#                                       for field in fields]
#                     )
#                 for node in nodelist]
        dfile.startCmd(meshmenu.Load_Field)
        dfile.argument('mesh', meshcontext.path())
        dfile.argument('fields', fieldnames)
        dfile.argument('field_values', values)
        dfile.endCmd()
Esempio n. 5
0
def _loadFieldValues(menuitem, mesh, fields, field_values):
    meshctxt = ooflib.engine.mesh.meshes[mesh]
    femesh = meshctxt.getObject()
    fieldlist = [getFieldObj(fld) for fld in fields]  # get objects from names
    for fv in field_values:
        index = fv[0]
        node = femesh.getNode(index)
        pointer = 1
        for field in fieldlist:
            for i in range(field.ndof()):
                field.setvalue(femesh, node, i, fv[pointer])
                pointer += 1

    # Field values can change the appearance of a newly-loaded mesh.
    switchboard.notify("mesh data changed", meshctxt)
    switchboard.notify("redraw")
Esempio n. 6
0
def _loadFieldValues(menuitem, mesh, fields, field_values):
    meshctxt = ooflib.engine.mesh.meshes[mesh]
    femesh = meshctxt.getObject()
    fieldlist = [getFieldObj(fld) for fld in fields] # get objects from names
    for fv in field_values:
        index = fv[0]
        node = femesh.getNode(index)
        pointer = 1
        for field in fieldlist:
            for i in range(field.ndof()):
                field.setvalue(femesh, node, i, fv[pointer])
                pointer += 1

    # Field values can change the appearance of a newly-loaded mesh.
    switchboard.notify("mesh data changed", meshctxt)
    switchboard.notify("redraw")