Exemplo n.º 1
0
    def clone(self, newmesh, copy_field, copy_equation, notifications):
        # Create a copy of this subproblem in the given mesh, which is
        # either our mesh or a copy of it.  'notifications' is a set
        # of switchboard messages which will be sent by the calling
        # function when all the cloning is complete.
        subp = self.getObject()
        newsubptype = self.subptype.clone()
        newsubpobj = newsubptype.create()
        # create new subproblem context with a temporary name so that
        # it won't overwrite an old subproblem until we're done with
        # the old one (in case we're recreating an old subproblem, as
        # in the Revert mesh modifier).  It's up to the caller to
        # delete the original subproblems and rename the new ones.
        desiredname = newmesh.path() + ':' + self.name()
        temppath = newmesh.path() + ":" + subproblems.uniqueName(desiredname)
        newsubpctxt = newmesh.newSubProblem(newsubpobj, newsubptype, temppath)
        oldmesh = self.getParent()
        # CSubProblem.set_mesh() must have been called with the new
        # meshctxt *before* this point, or new DoFs and NodalEqns
        # won't be stored in the right object.  Mesh.setFEMesh must be
        # called *before* calling CSubProblem.set_mesh() because it
        # uses Mesh.getObject() to get the FEMesh.  But if we do that,
        # then the field planarities won't be retrieved correctly from
        # the Mesh, because it will use the wrong FEMesh.  Therefore,
        # this routine does not set the planarity at all. Planarity
        # isn't really a subproblem responsibility anyway.
        if copy_field:
            for field in self.all_compound_fields():
                newsubpobj.define_field(field)
                notifications.add(
                    ("field defined", desiredname, field.name(), 1))
                if subp.is_active_field(field):
                    newsubpobj.activate_field(field)
                    notifications.add(("field activated",
                                       desiredname, field.name(), 1))
        if copy_equation:
            for eqn in self.all_equations():
                newsubpobj.activate_equation(eqn)
                notifications.add(
                    ("equation activated", desiredname, eqn.name(), 1))
        if self.solver_mode is not None:
            newsubpctxt.solver_mode = self.solver_mode.clone()
        
        # The times and dof values, etc, will be reset when the fields
        # are initialized, which isn't done here. installedTime,
        # startValues, and endValues don't have to be set here at all.
        newsubpctxt.startTime = 0.0
        newsubpctxt.endTime = None

        newsubpctxt.solveFlag = self.solveFlag
        return newsubpctxt
Exemplo n.º 2
0
    def clone(self, newmesh, copy_field, copy_equation, notifications):
        # Create a copy of this subproblem in the given mesh, which is
        # either our mesh or a copy of it.  'notifications' is a set
        # of switchboard messages which will be sent by the calling
        # function when all the cloning is complete.
        subp = self.getObject()
        newsubptype = self.subptype.clone()
        newsubpobj = newsubptype.create()
        # create new subproblem context with a temporary name so that
        # it won't overwrite an old subproblem until we're done with
        # the old one (in case we're recreating an old subproblem, as
        # in the Revert mesh modifier).  It's up to the caller to
        # delete the original subproblems and rename the new ones.
        desiredname = newmesh.path() + ':' + self.name()
        temppath = newmesh.path() + ":" + subproblems.uniqueName(desiredname)
        newsubpctxt = newmesh.newSubProblem(newsubpobj, newsubptype, temppath)
        oldmesh = self.getParent()
        # CSubProblem.set_mesh() must have been called with the new
        # meshctxt *before* this point, or new DoFs and NodalEqns
        # won't be stored in the right object.  Mesh.setFEMesh must be
        # called *before* calling CSubProblem.set_mesh() because it
        # uses Mesh.getObject() to get the FEMesh.  But if we do that,
        # then the field planarities won't be retrieved correctly from
        # the Mesh, because it will use the wrong FEMesh.  Therefore,
        # this routine does not set the planarity at all. Planarity
        # isn't really a subproblem responsibility anyway.
        if copy_field:
            for field in self.all_compound_fields():
                newsubpobj.define_field(field)
                notifications.add(
                    ("field defined", desiredname, field.name(), 1))
                if subp.is_active_field(field):
                    newsubpobj.activate_field(field)
                    notifications.add(("field activated",
                                       desiredname, field.name(), 1))
        if copy_equation:
            for eqn in self.all_equations():
                newsubpobj.activate_equation(eqn)
                notifications.add(
                    ("equation activated", desiredname, eqn.name(), 1))
        if self.solver_mode is not None:
            newsubpctxt.solver_mode = self.solver_mode.clone()
        
        # The times and dof values, etc, will be reset when the fields
        # are initialized, which isn't done here. installedTime,
        # startValues, and endValues don't have to be set here at all.
        newsubpctxt.startTime = 0.0
        newsubpctxt.endTime = None

        newsubpctxt.solveFlag = self.solveFlag
        return newsubpctxt
Exemplo n.º 3
0
def _edit_subproblem(menuitem, name, subproblem):
##    if parallel_enable.enabled():
##        ## TODO: out of date
##        ipcsubpmenu.Edit(name=name, subproblem=subproblem)
##        return
    oldsubp = ooflib.engine.subproblemcontext.subproblems[name]
    if oldsubp.name() == ooflib.engine.mesh.defaultSubProblemName:
        raise ooferror.ErrUserError("You can't edit the default Subproblem!")
    meshctxt = oldsubp.getParent()
    oldsubp.reserve()
    oldsubp.begin_writing()
    try:
        oldsubpobj = oldsubp.getObject()
        # Save lists of fields, etc, so that they can be restored in
        # the new subproblem.
        oldfields = oldsubp.all_compound_fields() # only CompoundFields
        oldactivefields = [field for field in oldfields
                           if oldsubpobj.is_active_field(field)]
        oldeqns = oldsubp.all_equations()
        oldsubp.destroy()
    finally:
        oldsubp.end_writing()
        oldsubp.cancel_reservation()

    # Create context for new subproblem.
    newsubpobj = subproblem.create()
    newsubp = meshctxt.newSubProblem(newsubpobj, subproblem, name)
    meshctxt.reserve()
    meshctxt.begin_writing()
    # Gather switchboard messages and send them all after the lock has
    # been released.
    notifications = []
    try:
        # Restore field and equation state saved from old subproblem.
        for field in oldfields:
            newsubpobj.define_field(field)
            notifications.append(("field defined", name, field.name(), 1))
        for field in oldactivefields:
            newsubpobj.activate_field(field)
            notifications.append(("field activated", name, field.name(), 1))
        for eqn in oldeqns:
            newsubpobj.activate_equation(eqn)
            notifications.append(("equation activated", name, eqn.name(), 1))
    finally:
        meshctxt.end_writing()
        meshctxt.cancel_reservation()
    newsubp.autoenableBCs()
    for notice in notifications:
        switchboard.notify(*notice)
    newsubp.changed("Subproblem redefined.")
Exemplo n.º 4
0
def _deactivateField(menuitem, subproblem, field):
    deactivation = False
    if parallel_enable.enabled():
        ipcsubpmenu.Field.Deactivate(subproblem=subproblem, field=field)
    else:
        subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
        subpcontext.reserve()
        subpcontext.begin_writing()
        try:
            subp = subpcontext.getObject()
            if subp.is_active_field(field):
                subp.deactivate_field(field)
                deactivation = True
            else:
                reporter.report(
                    "You must define and activate a Field before you can deactivate it."
                )
        finally:
            subpcontext.end_writing()
            subpcontext.cancel_reservation()

        if deactivation:
            subpcontext.autoenableBCs()
            switchboard.notify("field activated", subproblem, field.name(), 0)
            subpcontext.changed("Field deactivated.")
Exemplo n.º 5
0
def _defineField(menuitem, subproblem, field):
    if parallel_enable.enabled():
        ipcsubpmenu.Field.Define(subproblem=subproblem, field=field)
    else:
        # subproblem is a name, not an object
        subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
        subpcontext.reserve()
        subpcontext.begin_writing()
        didsomething = False
        try:
            if not subpcontext.is_defined_field(field):
                subpcontext.getObject().define_field(field)
                meshctxt = subpcontext.getParent()
                initializer = meshctxt.get_initializer(field)
                if initializer:
                    initializer.apply(subpcontext.getParent().getObject(),
                                      field,
                                      singleFieldDef=True)
                meshctxt.update_fields()
                didsomething = True
        finally:
            subpcontext.end_writing()
            subpcontext.cancel_reservation()
        if didsomething:
            subpcontext.autoenableBCs()
            subpcontext.changed("Field defined.")
            switchboard.notify("field defined", subproblem, field.name(), 1)
            switchboard.notify("redraw")
Exemplo n.º 6
0
def _defineField(menuitem, subproblem, field):
    if parallel_enable.enabled():
        ipcsubpmenu.Field.Define(subproblem=subproblem, field=field)
    else:
        # subproblem is a name, not an object
        subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
        subpcontext.reserve()
        subpcontext.begin_writing()
        didsomething = False
        try:
            if not subpcontext.is_defined_field(field):
                subpcontext.getObject().define_field(field)
                meshctxt = subpcontext.getParent()
                initializer = meshctxt.get_initializer(field)
                if initializer:
                    initializer.apply(subpcontext.getParent().getObject(),
                                      field, singleFieldDef=True)
                meshctxt.update_fields()
                didsomething = True
        finally:
            subpcontext.end_writing()
            subpcontext.cancel_reservation()
        if didsomething:
            subpcontext.autoenableBCs()
            subpcontext.changed("Field defined.")
            switchboard.notify("field defined", subproblem, field.name(), 1)
            switchboard.notify("redraw")
Exemplo n.º 7
0
def parallel_copy_subproblem(menuitem, subproblem, mesh, name):
    debug.fmsg()
    sourcectxt = ooflib.engine.subproblemcontext.subproblems[subproblem]
    sourceobj = sourcectxt.getObject()
    # Make a copy of the CSubProblem object, using the clone function
    # (added to the class by registerCClass).
    copyobj = sourceobj.clone()  # new CSubProblem

    sourcectxt.begin_reading()
    try:
        fields = sourcectxt.all_compound_fields()
        activefields = [
            field for field in fields
            if sourcectxt.getObject().is_active_field(field)
        ]
        equations = sourceobj.all_equations()
    finally:
        sourcectxt.end_reading()

    meshctxt = ooflib.engine.mesh.meshes[mesh]
    copyctxt = meshctxt.newSubProblem(copyobj,
                                      mesh + ':' + name)  # new context
    copyname = copyctxt.path()

    # Set Fields and Equations in the copy
    copyctxt.reserve()
    copyctxt.begin_writing()
    notifications = []
    try:
        for field in fields:
            copyobj.define_field(field)
            notifications.append(("field defined", copyname, field.name(), 1))
        for field in activefields:
            copyobj.activate_field(field)
            notifications.append(
                ("field activated", copyname, field.name(), 1))
        for eqn in sourceobj.all_equations():
            copyobj.activate_equation(eqn)
            notifications.append(
                ("equation activated", copyname, eqn.name(), 1))
    finally:
        copyctxt.end_writing()
        copyctxt.cancel_reservation()
    copyctxt.autoenableBCs()

    for notice in notifications:
        switchboard.notify(*notice)
Exemplo n.º 8
0
 def setFieldActiveTip(self, button, field):
     if button.get_active():
         verb = "Deactivate"
     else:
         verb = "Activate"
     tooltips.set_tooltip_text(button,
         "%s the %s field on the subproblem. The solver finds the values of the active fields by solving the active equations."
         % (verb, field.name()))
Exemplo n.º 9
0
 def setFieldDefineTip(self, button, field):
     if button.get_active():
         verb = "Undefine"
     else:
         verb = "Define"
     tooltips.set_tooltip_text(button,
         "%s the %s field on the mesh.  Only defined fields have values."
         % (verb, field.name()))
Exemplo n.º 10
0
 def setFieldActiveTip(self, button, field):
     if button.get_active():
         verb = "Deactivate"
     else:
         verb = "Activate"
     tooltips.set_tooltip_text(
         button,
         "%s the %s field on the subproblem. The solver finds the values of the active fields by solving the active equations."
         % (verb, field.name()))
Exemplo n.º 11
0
 def setFieldInPlaneTip(self, button, field):
     debug.mainthreadTest()
     if button.get_active():
         verb = "Do not constrain"
     else:
         verb = "Constrain"
     tooltips.set_tooltip_text(button,
         "%s the derivatives of the %s field to lie in the x-y plane."
         % (verb, field.name()))
Exemplo n.º 12
0
 def setFieldDefineTip(self, button, field):
     if button.get_active():
         verb = "Undefine"
     else:
         verb = "Define"
     tooltips.set_tooltip_text(
         button,
         "%s the %s field on the mesh.  Only defined fields have values." %
         (verb, field.name()))
Exemplo n.º 13
0
 def setFieldInPlaneTip(self, button, field):
     debug.mainthreadTest()
     if button.get_active():
         verb = "Do not constrain"
     else:
         verb = "Constrain"
     tooltips.set_tooltip_text(
         button,
         "%s the derivatives of the %s field to lie in the x-y plane." %
         (verb, field.name()))
Exemplo n.º 14
0
def _copy_subproblem(menuitem, subproblem, mesh, name):
    if parallel_enable.enabled():
        ipcsubpmenu.Copy(name=name, mesh=mesh, subproblem=subproblem)
        return
    sourcectxt = ooflib.engine.subproblemcontext.subproblems[subproblem]
    sourceobj = sourcectxt.getObject()
    copyobj = sourcectxt.subptype.create() # new CSubProblem

    sourcectxt.begin_reading()
    try:
        fields = sourcectxt.all_compound_fields()
        activefields = [field for field in fields
                        if sourcectxt.getObject().is_active_field(field)]
        equations = sourceobj.all_equations()
    finally:
        sourcectxt.end_reading()

    meshctxt = ooflib.engine.mesh.meshes[mesh]
    copyctxt = meshctxt.newSubProblem(copyobj, sourcectxt.subptype,
                                      mesh+':'+name) # new context
    copyname = copyctxt.path()

    # Set Fields and Equations in the copy
    copyctxt.reserve()
    copyctxt.begin_writing()
    notifications = []
    try:
        for field in fields:
            copyobj.define_field(field)
            notifications.append(("field defined", copyname, field.name(), 1))
        for field in activefields:
            copyobj.activate_field(field)
            notifications.append(("field activated", copyname, field.name(), 1))
        for eqn in sourceobj.all_equations():
            copyobj.activate_equation(eqn)
            notifications.append(("equation activated", copyname, eqn.name(), 1))
    finally:
        copyctxt.end_writing()
        copyctxt.cancel_reservation()
    copyctxt.autoenableBCs()

    for notice in notifications:
        switchboard.notify(*notice)
Exemplo n.º 15
0
def parallel_copy_subproblem(menuitem, subproblem, mesh, name):
    debug.fmsg()
    sourcectxt = ooflib.engine.subproblemcontext.subproblems[subproblem]
    sourceobj = sourcectxt.getObject()
    # Make a copy of the CSubProblem object, using the clone function
    # (added to the class by registerCClass).
    copyobj = sourceobj.clone() # new CSubProblem

    sourcectxt.begin_reading()
    try:
        fields = sourcectxt.all_compound_fields()
        activefields = [field for field in fields
                        if sourcectxt.getObject().is_active_field(field)]
        equations = sourceobj.all_equations()
    finally:
        sourcectxt.end_reading()
    
    meshctxt = ooflib.engine.mesh.meshes[mesh]
    copyctxt = meshctxt.newSubProblem(copyobj, mesh+':'+name) # new context
    copyname = copyctxt.path()

    # Set Fields and Equations in the copy
    copyctxt.reserve()
    copyctxt.begin_writing()
    notifications = []
    try:
        for field in fields:
            copyobj.define_field(field)
            notifications.append(("field defined", copyname, field.name(), 1))
        for field in activefields:
            copyobj.activate_field(field)
            notifications.append(("field activated", copyname, field.name(), 1))
        for eqn in sourceobj.all_equations():
            copyobj.activate_equation(eqn)
            notifications.append(("equation activated", copyname, eqn.name(), 1))
    finally:
        copyctxt.end_writing()
        copyctxt.cancel_reservation()
    copyctxt.autoenableBCs()

    for notice in notifications:
        switchboard.notify(*notice)
Exemplo n.º 16
0
def _meshFields(menuitem, mesh, defined, active, inplane):
    meshctxt = ooflib.engine.mesh.meshes[mesh]
    subpname = meshctxt.get_default_subproblem().path()

    for fname in defined:
        field = getFieldObj(fname)
        meshctxt.get_default_subproblem().getObject().define_field(field)
        switchboard.notify("field defined", subpname, field.name(), 1)

    for fname in active:
        field = getFieldObj(fname)
        meshctxt.get_default_subproblem().getObject().activate_field(field)
        switchboard.notify("field activated", subpname, field.name(), 1)

    for fname in inplane:
        field = getFieldObj(fname)
        meshctxt.set_in_plane_field(field, 1)
        switchboard.notify("field inplane", mesh, field.name(), 1)

    switchboard.notify("mesh changed", meshctxt)
Exemplo n.º 17
0
def _meshFields(menuitem, mesh, defined, active, inplane):
    meshctxt = ooflib.engine.mesh.meshes[mesh]
    subpname = meshctxt.get_default_subproblem().path()

    for fname in defined:
        field = getFieldObj(fname)
        meshctxt.get_default_subproblem().getObject().define_field(field)
        switchboard.notify("field defined", subpname, field.name(), 1)

    for fname in active:
        field = getFieldObj(fname)
        meshctxt.get_default_subproblem().getObject().activate_field(field)
        switchboard.notify("field activated", subpname, field.name(), 1)

    for fname in inplane:
        field = getFieldObj(fname)
        meshctxt.set_in_plane_field(field, 1)
        switchboard.notify("field inplane", mesh, field.name(), 1)

    switchboard.notify("mesh changed", meshctxt)
Exemplo n.º 18
0
def _meshFields(menuitem, mesh, defined, active, inplane):
    meshctxt = ooflib.engine.mesh.meshes[mesh]
    subpname = meshctxt.get_default_subproblem().path()

    for fname in defined:
        field = getFieldObj(fname)
        meshctxt.get_default_subproblem().getObject().define_field(field)
        switchboard.notify("field defined", subpname, field.name(), 1)

    for fname in active:
        field = getFieldObj(fname)
        meshctxt.get_default_subproblem().getObject().activate_field(field)
        switchboard.notify("field activated", subpname, field.name(), 1)

    ## NO need to check for 2D here.  This is old code only for
    ## loading old OOF2 files.
    for fname in inplane:
        field = getFieldObj(fname)
        meshctxt.set_in_plane_field(field, 1)
        switchboard.notify("field inplane", mesh, field.name(), 1)

    switchboard.notify("mesh changed", meshctxt)
Exemplo n.º 19
0
def _subpFields(menuitem, subproblem, defined, active, inplane):
    subpctxt = ooflib.engine.subproblemcontext.subproblems[subproblem]
    meshctxt = subpctxt.getParent()
    meshname = meshctxt.path()
    subpname = subpctxt.path()
    subp = subpctxt.getObject()

    for fname in defined:
        field = getFieldObj(fname)
        subp.define_field(field)
        switchboard.notify("field defined", subpname, field.name(), 1)

    for fname in active:
        field = getFieldObj(fname)
        subp.activate_field(field)
        switchboard.notify("field activated", subpname, field.name(), 1)

    for fname in inplane:
        field = getFieldObj(fname)
        meshctxt.set_in_plane_field(field, 1)
        switchboard.notify("field inplane", meshname, field.name(), 1)

    subpctxt.changed("Fields loaded.")
Exemplo n.º 20
0
def _subpFields(menuitem, subproblem, defined, active, inplane):
    subpctxt = ooflib.engine.subproblemcontext.subproblems[subproblem]
    meshctxt = subpctxt.getParent()
    meshname = meshctxt.path()
    subpname = subpctxt.path()
    subp = subpctxt.getObject()

    for fname in defined:
        field = getFieldObj(fname)
        subp.define_field(field)
        switchboard.notify("field defined", subpname, field.name(), 1)

    for fname in active:
        field = getFieldObj(fname)
        subp.activate_field(field)
        switchboard.notify("field activated", subpname, field.name(), 1)

    for fname in inplane:
        field = getFieldObj(fname)
        meshctxt.set_in_plane_field(field, 1)
        switchboard.notify("field inplane", meshname, field.name(), 1)

    subpctxt.changed("Fields loaded.")
Exemplo n.º 21
0
def parallel_undefineField(menuitem, subproblem, field):
    debug.fmsg()
    subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
    subpcontext.reserve()
    subpcontext.begin_writing()
    try:
        subpcontext.getObject().undefine_field(field)
        subpcontext.getParent().update_fields()
    finally:
        subpcontext.end_writing()
        subpcontext.cancel_reservation()

    subpcontext.autoenableBCs()
    subpcontext.changed()
    switchboard.notify("field defined", subproblem, field.name(), 0)
    switchboard.notify("redraw")
Exemplo n.º 22
0
def parallel_undefineField(menuitem, subproblem, field):
    debug.fmsg()
    subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
    subpcontext.reserve()
    subpcontext.begin_writing()
    try:
        subpcontext.getObject().undefine_field(field)
        subpcontext.getParent().update_fields()
    finally:
        subpcontext.end_writing()
        subpcontext.cancel_reservation()

    subpcontext.autoenableBCs()
    subpcontext.changed()
    switchboard.notify("field defined", subproblem, field.name(), 0)
    switchboard.notify("redraw")
Exemplo n.º 23
0
def parallel_activateField(menuitem, subproblem, field):
    debug.fmsg()
    activation = False
    subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
    subpcontext.reserve()
    subpcontext.begin_writing()
    try:
        subp = subpcontext.getObject()
        if subp.is_defined_field(field):
            subp.activate_field(field)
            activation = True
        else:
            reporter.report(
                "You must define a Field before you can activate it.")
    finally:
        subpcontext.end_writing()
        subpcontext.cancel_reservation()

    if activation:
        subpcontext.autoenableBCs()
        switchboard.notify("field activated", subproblem, field.name(), 1)
        subpcontext.changed()
Exemplo n.º 24
0
def parallel_deactivateField(menuitem, subproblem, field):
    debug.fmsg()
    deactivation = False
    subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
    subpcontext.reserve()
    subpcontext.begin_writing()
    try:
        subp = subpcontext.getObject()
        if subp.is_active_field(field):
            subp.deactivate_field(field)
            deactivation = True
        else:
            reporter.report(
                "You must define and activate a Field before you can deactivate it.")
    finally:
        subpcontext.end_writing()
        subpcontext.cancel_reservation()

    if deactivation:
        subpcontext.autoenableBCs()
        switchboard.notify("field activated", subproblem, field.name(), 0)
        subpcontext.changed()
Exemplo n.º 25
0
def _undefineField(menuitem, subproblem, field):
    if parallel_enable.enabled():
        ipcsubpmenu.Field.Undefine(subproblem=subproblem, field=field)
    else:
        subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
        subpcontext.reserve()
        subpcontext.begin_writing()
        try:
            subpcontext.getObject().undefine_field(field)
            subpcontext.getParent().update_fields()
            # After undefining a Field, the data cache in the mesh has
            # the wrong number of dofs in it.  We could in principle
            # delete the correct dofs from each cache entry, but it
            # might be slow (especially for a disk cache).  The
            # simpler thing to do is to just delete the whole cache.
            subpcontext.getParent().clearDataCache()
        finally:
            subpcontext.end_writing()
            subpcontext.cancel_reservation()

        subpcontext.autoenableBCs()
        subpcontext.changed("Field undefined.")
        switchboard.notify("field defined", subproblem, field.name(), 0)
        switchboard.notify("redraw")
Exemplo n.º 26
0
def _activateField(menuitem, subproblem, field):
    activation = False
    if parallel_enable.enabled():
        ipcsubpmenu.Field.Activate(subproblem=subproblem,field=field)
    else:
        subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
        subpcontext.reserve()
        subpcontext.begin_writing()
        try:
            subp = subpcontext.getObject()
            if subp.is_defined_field(field):
                subp.activate_field(field)
                activation = True
            else:
                reporter.report(
                    "You must define a Field before you can activate it.")
        finally:
            subpcontext.end_writing()
            subpcontext.cancel_reservation()

        if activation:
            subpcontext.autoenableBCs()
            switchboard.notify("field activated", subproblem, field.name(), 1)
            subpcontext.changed("Field activated.")
Exemplo n.º 27
0
def _undefineField(menuitem, subproblem, field):
    if parallel_enable.enabled():
        ipcsubpmenu.Field.Undefine(subproblem=subproblem,field=field)
    else:
        subpcontext = ooflib.engine.subproblemcontext.subproblems[subproblem]
        subpcontext.reserve()
        subpcontext.begin_writing()
        try:
            subpcontext.getObject().undefine_field(field)
            subpcontext.getParent().update_fields()
            # After undefining a Field, the data cache in the mesh has
            # the wrong number of dofs in it.  We could in principle
            # delete the correct dofs from each cache entry, but it
            # might be slow (especially for a disk cache).  The
            # simpler thing to do is to just delete the whole cache.
            subpcontext.getParent().clearDataCache()
        finally:
            subpcontext.end_writing()
            subpcontext.cancel_reservation()

        subpcontext.autoenableBCs()
        subpcontext.changed("Field undefined.")
        switchboard.notify("field defined", subproblem, field.name(), 0)
        switchboard.notify("redraw")
Exemplo n.º 28
0
def _copy_subproblem(menuitem, subproblem, mesh, name):
    if parallel_enable.enabled():
        ipcsubpmenu.Copy(name=name, mesh=mesh, subproblem=subproblem)
        return
    meshctxt = ooflib.engine.mesh.meshes[mesh]
    sourcectxt = ooflib.engine.subproblemcontext.subproblems[subproblem]
    if not sourcectxt.consistency():
        raise ooferror.ErrUserError(
            'Subproblem being copied is not consistent!')
    sourceobj = sourcectxt.getObject()
    #Retrieving the tree of dependencies order for the less dependent subproblem to the most dependent one
    links = []
    sourcectxt.tree(links)
    links_update = []
    #Looping around the path of each subproblem from the ordered list
    for link in links:
        # Retrieve the path, the name and the context of the current subproblem
        subp_path = labeltree.makePath(link)
        subp_name = subp_path[-1]
        subp_ctxt = ooflib.engine.subproblemcontext.subproblems[link]
        create = False  #Should the subproblem be created?
        if subp_ctxt != sourcectxt:
            for subp in meshctxt.subproblems():
                #Check that the subproblem has the same name and subptype
                if subp_name == subp.name():
                    if subp_ctxt.subptype.__class__ == subp.subptype.__class__:
                        create = True
                        links_update.append(subp.path())  #Update with the path
                        break

# If the subproblem does not exist in the target mesh subproblem
# Copy the subproblem and update its dependencies since they might probably have
# different paths if the target mesh is another one.
# Create the subproblem copy all the original subproblem content
# Finally update the dependencies dependents and propagate the consistency.
        if create == False:
            subptype_copy = copy.deepcopy(subp_ctxt.subptype)

            for dependency in subptype_copy.get_dependencies():
                dep_index = links.index(dependency)
                update_path = links_update[dep_index]
                subptype_copy.sync_dependency(dependency, update_path)

            copyobj = subptype_copy.create()  # new CSubProblem
            sourcectxt.begin_reading()
            try:
                fields = sourcectxt.all_compound_fields()
                activefields = [
                    field for field in fields
                    if sourcectxt.getObject().is_active_field(field)
                ]
                equations = sourceobj.all_equations()
            finally:
                sourcectxt.end_reading()
            if subp_ctxt != sourcectxt:
                copyctxt = meshctxt.newSubProblem(copyobj, subptype_copy,
                                                  mesh + ':' +
                                                  subp_name)  # new context
            else:
                copyctxt = meshctxt.newSubProblem(
                    copyobj, subptype_copy, mesh + ':' + name)  # new context
            copyname = copyctxt.path()
            links_update.append(copyname)  #Update with the new path

            # Set Fields and Equations in the copy
            copyctxt.reserve()
            copyctxt.begin_writing()
            notifications = []
            try:
                for field in fields:
                    copyobj.define_field(field)
                    notifications.append(
                        ("field defined", copyname, field.name(), 1))
                for field in activefields:
                    copyobj.activate_field(field)
                    notifications.append(
                        ("field activated", copyname, field.name(), 1))
                for eqn in sourceobj.all_equations():
                    copyobj.activate_equation(eqn)
                    notifications.append(
                        ("equation activated", copyname, eqn.name(), 1))
            finally:
                copyctxt.end_writing()
                copyctxt.cancel_reservation()
            copyctxt.autoenableBCs()

            for notice in notifications:
                switchboard.notify(*notice)

            #Update the dependencies dependents
            for dependency in copyctxt.subptype.get_dependencies():
                dependencysubp = ooflib.engine.subproblemcontext.subproblems[
                    dependency]
                dependencysubp.subptype.remove_dependent(link)
                dependencysubp.subptype.add_dependent(copyname)

            for dep in copyctxt.subptype.get_dependencies():
                ooflib.engine.subproblemcontext.subproblems[
                    dep].update_consistency()

            copyctxt.propagate_consistency([copyname])
Exemplo n.º 29
0
    dfile.endCmd()

    # Create subproblems
    anyfields = False  # used later to decide if field values must be saved
    for subpctxt in meshcontext.subproblems():
        subp = subpctxt.subptype
        subpobj = subpctxt.getObject()
        if subpctxt.name() != ooflib.engine.mesh.defaultSubProblemName:
            dfile.startCmd(subpmenu.New)
            dfile.argument('name', subpctxt.name())
            dfile.argument('subproblem', subp)
            dfile.argument('mesh', meshcontext.path())
            dfile.endCmd()
        # Define and activate Fields on subproblems
        definedfields = [
            field.name() for field in subpctxt.all_compound_fields()
        ]
        activefields = [
            field.name() for field in subpctxt.all_compound_fields()
            if subpobj.is_active_field(field)
        ]
        inplanefields = [
            field.name() for field in subpctxt.all_compound_fields()
            if femesh.in_plane(field)
        ]
        if definedfields:
            anyfields = True
            dfile.startCmd(subpmenu.Fields)
            dfile.argument('subproblem', subpctxt.path())
            dfile.argument('defined', definedfields)
            dfile.argument('active', activefields)
Exemplo n.º 30
0
def _edit_subproblem(menuitem, name, subproblem):
    ##    if parallel_enable.enabled():
    ##        ## TODO MER: out of date
    ##        ipcsubpmenu.Edit(name=name, subproblem=subproblem)
    ##        return
    oldsubp = ooflib.engine.subproblemcontext.subproblems[name]
    if oldsubp.name() == ooflib.engine.mesh.defaultSubProblemName:
        raise ooferror.ErrUserError("You can't edit the default Subproblem!")
    meshctxt = oldsubp.getParent()
    # Get the old dependents and dependencies for updates
    old_dependents = oldsubp.subptype.get_dependents()
    old_dependencies = oldsubp.subptype.get_dependencies()
    old_path = oldsubp.path()

    oldsubp.reserve()
    oldsubp.begin_writing()
    try:
        oldsubpobj = oldsubp.getObject()
        # Save lists of fields, etc, so that they can be restored in
        # the new subproblem.
        oldfields = oldsubp.all_compound_fields()  # only CompoundFields
        oldactivefields = [
            field for field in oldfields if oldsubpobj.is_active_field(field)
        ]
        oldeqns = oldsubp.all_equations()
        oldsubp.clean()
    finally:
        oldsubp.end_writing()
        oldsubp.cancel_reservation()

    # Create the new subproblem object
    newsubpobj = subproblem.create()

    #Remove the path from the dependencies dependents:
    for dependency in old_dependencies:
        if old_path in ooflib.engine.subproblemcontext.subproblems[
                dependency].subptype.get_dependents():
            ooflib.engine.subproblemcontext.subproblems[
                dependency].subptype.remove_dependent(old_path)

    # Create context for new subproblem.
    newsubp = meshctxt.newSubProblem(newsubpobj, subproblem, name)
    meshctxt.reserve()
    meshctxt.begin_writing()
    # Gather switchboard messages and send them all after the lock has
    # been released.
    notifications = []
    try:
        # Restore field and equation state saved from old subproblem.
        for field in oldfields:
            newsubpobj.define_field(field)
            notifications.append(("field defined", name, field.name(), 1))
        for field in oldactivefields:
            newsubpobj.activate_field(field)
            notifications.append(("field activated", name, field.name(), 1))
        for eqn in oldeqns:
            newsubpobj.activate_equation(eqn)
            notifications.append(("equation activated", name, eqn.name(), 1))
    finally:
        meshctxt.end_writing()
        meshctxt.cancel_reservation()
    newsubp.autoenableBCs()

    #Update the dependents with the new object
    for dependent in old_dependents:
        dependentsubp = ooflib.engine.subproblemcontext.subproblems[dependent]
        newsubp.subptype.add_dependent(dependent)
        dependentsubp.reserve()
        dependentsubp.begin_writing()
        try:
            dependentsubp.subptype.update_dependency(dependentsubp.getObject(),
                                                     old_path,
                                                     newsubp.getObject())
        finally:
            dependentsubp.end_writing()
            dependentsubp.cancel_reservation()
    for dep in newsubp.subptype.get_dependencies():
        ooflib.engine.subproblemcontext.subproblems[dep].update_consistency()

    newsubp.propagate_consistency([old_path])

    for notice in notifications:
        switchboard.notify(*notice)
    newsubp.changed("Subproblem redefined.")
Exemplo n.º 31
0
    dfile.argument('skeleton', skelpath)
    dfile.endCmd()

    # Create subproblems
    anyfields = False  # used later to decide if field values must be saved
    for subpctxt in meshcontext.subproblems():
        subp = subpctxt.subptype
        subpobj = subpctxt.getObject()
        if subpctxt.name() != ooflib.engine.mesh.defaultSubProblemName:
            dfile.startCmd(subpmenu.New)
            dfile.argument('name', subpctxt.name())
            dfile.argument('subproblem', subp)
            dfile.argument('mesh', meshcontext.path())
            dfile.endCmd()
        # Define and activate Fields on subproblems
        definedfields = [field.name() for field in
                         subpctxt.all_compound_fields()]
        activefields = [field.name() for field in
                        subpctxt.all_compound_fields()
                        if subpobj.is_active_field(field)]
        inplanefields = [field.name() for field in
                         subpctxt.all_compound_fields()
                         if femesh.in_plane(field)]
        if definedfields:
            anyfields = True
            dfile.startCmd(subpmenu.Fields)
            dfile.argument('subproblem', subpctxt.path())
            dfile.argument('defined', definedfields)
            dfile.argument('active', activefields)
            dfile.argument('inplane', inplanefields)
            dfile.endCmd()
Exemplo n.º 32
0
    dfile.argument('skeleton', skelpath)
    dfile.endCmd()

    # Create subproblems
    anyfields = False  # used later to decide if field values must be saved
    for subpctxt in meshcontext.subproblems():
        subp = subpctxt.subptype
        subpobj = subpctxt.getObject()
        if subpctxt.name() != ooflib.engine.mesh.defaultSubProblemName:
            dfile.startCmd(subpmenu.New)
            dfile.argument('name', subpctxt.name())
            dfile.argument('subproblem', subp)
            dfile.argument('mesh', meshcontext.path())
            dfile.endCmd()
        # Define and activate Fields on subproblems
        definedfields = [field.name() for field in
                         subpctxt.all_compound_fields()]
        activefields = [field.name() for field in
                        subpctxt.all_compound_fields()
                        if subpobj.is_active_field(field)]
        inplanefields = [field.name() for field in
                         subpctxt.all_compound_fields()
                         if femesh.in_plane(field)]
        if definedfields:
            anyfields = True
            dfile.startCmd(subpmenu.Fields)
            dfile.argument('subproblem', subpctxt.path())
            dfile.argument('defined', definedfields)
            dfile.argument('active', activefields)
            dfile.argument('inplane', inplanefields)
            dfile.endCmd()
Exemplo n.º 33
0
def writeMesh(dfile, meshcontext, includeFields=True):
    skelcontext = meshcontext.getParent()
    skelpath = skelcontext.path()
    femesh = meshcontext.femesh()

    # Create mesh.
    dfile.startCmd(meshmenu.New)
    dfile.argument('name', meshcontext.name())
    masterelems = [el.name() for el in meshcontext.elementdict.values()]
    dfile.argument('masterelems', masterelems)
    dfile.argument('skeleton', skelpath)
    dfile.endCmd()

    # Create subproblems
    anyfields = False  # used later to decide if field values must be saved
    for subpctxt in meshcontext.subproblems():
        subp = subpctxt.subptype
        subpobj = subpctxt.getObject()
        if subpctxt.name() != ooflib.engine.mesh.defaultSubProblemName:
            dfile.startCmd(subpmenu.New)
            dfile.argument('name', subpctxt.name())
            dfile.argument('subproblem', subp)
            dfile.argument('mesh', meshcontext.path())
            dfile.endCmd()
        # Define and activate Fields on subproblems
        definedfields = [field.name() for field in
                         subpctxt.all_compound_fields()]
        activefields = [field.name() for field in
                        subpctxt.all_compound_fields()
                        if subpobj.is_active_field(field)]
        if config.dimension == 2:
            inplanefields = [field.name() for field in
                             subpctxt.all_compound_fields()
                             if femesh.in_plane(field)]
        if definedfields:
            anyfields = True
            dfile.startCmd(subpmenu.Fields)
            dfile.argument('subproblem', subpctxt.path())
            dfile.argument('defined', definedfields)
            dfile.argument('active', activefields)
            if config.dimension() == 2:
                dfile.argument('inplane', inplanefields)
            dfile.endCmd()
        # Time derivative fields have a separate menu item to preserve
        # backwards compatibiltiy from the pre-time-dependence days.
        timederivfields = [field.name() for field in
                           subpctxt.all_compound_fields() if
                           subpctxt.is_defined_field(field.time_derivative())]
        if timederivfields:
            dfile.startCmd(subpmenu.Time_Derivative_Fields)
            dfile.argument('subproblem', subpctxt.path())
            dfile.argument('fields', timederivfields)
            dfile.endCmd()

        # Equations
        equations = [eqn.name() for eqn in subpctxt.all_equations()]
        if equations:
            dfile.startCmd(subpmenu.Equations)
            dfile.argument('subproblem', subpctxt.path())
            dfile.argument('equations', equations)
            dfile.endCmd()

        # Solver
        if subpctxt.time_stepper is not None:
            dfile.startCmd(subpmenu.Solver)
            dfile.argument('subproblem', subpctxt.path())
            dfile.argument('solver_mode', subpctxt.solver_mode)
            dfile.endCmd()

    # End loop over subproblems

    # Field initializers
    for field in meshcontext.all_subproblem_fields():
        init = meshcontext.get_initializer(field)
        if init:
            dfile.startCmd(meshmenu.Initialize_Field)
            dfile.argument('mesh', meshcontext.path())
            dfile.argument('field', field)
            dfile.argument('initializer', init)
            dfile.endCmd()

    # Boundary conditions
    bcnames = meshcontext.allBndyCondNames()
    bcnames.sort()
    for bcname in bcnames:
        bc = meshcontext.getBdyCondition(bcname)
        # bc's that are invisible in the gui are generally created by
        # internal processes.  Explicity saving and loading them can
        # lead to conflicts.
        if bc.isVisible():
            dfile.startCmd(meshmenu.Boundary_Condition)
            dfile.argument('mesh', meshcontext.path())
            dfile.argument('bcname', bcname)
            dfile.argument('bc', bc)
            dfile.endCmd()

    # Boundary condition initializers
    bcnames = [bc.name() for bc in meshcontext.initialized_bcs()]
    bcnames.sort()
    for bcname in bcnames:
        dfile.startCmd(meshmenu.Set_BC_Initializer)
        dfile.argument('mesh', meshcontext.path())
        dfile.argument('bc', bcname)
        dfile.argument('initializer', meshcontext.get_bc_initializer(bcname))
        dfile.endCmd()
        
    if anyfields and includeFields:
        # Cached data.  Cached data must be stored before the current
        # data, so that when it's reloaded, the current data isn't
        # overwritten.
        lastcachedtime = None
        for time in meshcontext.cachedTimes():
            meshcontext.restoreCachedData(time)
            writeAndCacheFields(dfile, meshcontext, time)
            meshcontext.releaseCachedData()
            lastcachedtime = time
        meshcontext.restoreLatestData()
        if lastcachedtime != meshcontext.getCurrentTime():
            writeFields(dfile, meshcontext)
        meshcontext.releaseLatestData() # allow overwrites later

    # Time
    dfile.startCmd(meshmenu.Time)
    dfile.argument('mesh', meshcontext.path())
    dfile.argument('time', meshcontext.getCurrentTime())
    dfile.endCmd()

    # Cross sections:
    for csname in meshcontext.cross_sections.all_names(): # already ordered
        cs = meshcontext.cross_sections[csname]
        dfile.startCmd(meshmenu.CrossSection)
        dfile.argument('mesh', meshcontext.path())
        dfile.argument('name', csname)
        dfile.argument('cs', cs)
        dfile.endCmd()

    # Scheduled outputs
    meshcontext.outputSchedule.saveAll(dfile, meshcontext)

    # Status. This should be the last thing written.
    dfile.startCmd(meshmenu.Status)
    dfile.argument('mesh', meshcontext.path())
    if isinstance(meshcontext.status,
                  (meshstatus.Unsolved, meshstatus.Solving)):
        # Since the order in which mesh attributes were written to the
        # data file is somewhat arbitrary, the details of an
        # "Unsolved" status aren't terribly meaningful.  Use generic
        # details.  Also, there's no point in storing a "Solving"
        # status, because it won't be true when the mesh is loaded.
        dfile.argument('status', meshstatus.Unsolved("Newly loaded."))
    else:
        dfile.argument('status', meshcontext.status)
    dfile.endCmd()