Posted Tue, 08 May 2018 21:02:47 GMT by Joaquin Cortinez SN
Hi all,

I have a model with a layer with inactive elements, which I need to activate at a given moment of the simulation, is it possible to modify the initial conditions of the activated elements (Pressure or Head)? Currently the activated elements are saturated, and I need asignate a certain head, close to the bottom elevation of this layer.

Thanks
Posted Wed, 09 May 2018 10:29:56 GMT by Björn Kaiser
The recent implementation of the GUI (Graphical User Interface) does not allow you to initialize the process variables when activating the elements. In contrast, the FEFLOW API (Application Programmers Interfaces) enables you to use initialize the system. At the moment, C/C++ and Python is supported. Is programming / scripting an option for you?
Posted Wed, 09 May 2018 13:57:57 GMT by Joaquin Cortinez SN
Hi Björn, I have no problems to program in python or C, if you can help me with the functions of the API that could be useful to me, it would be very helpful, since it would be the first time I would do it.

thanks
Posted Fri, 11 May 2018 15:51:33 GMT by Björn Kaiser
Great! I will prepare a snippet illustrating the workflow.
Posted Tue, 15 May 2018 14:01:07 GMT by Joaquin Cortinez SN
Thank for the help Björn

regards
Posted Wed, 16 May 2018 19:29:02 GMT by Björn Kaiser
Please find a tiny code snippet below, which illustrates the workflow. The workflow is based on a Python script. The scripts loads the FEFLOW kernel externally.

The snippet does the following:

1. Get the element members of the selection with the name “sheet_piles_elements”
2. Start a simulation
3. Deactivate the elements of the selection “sheet_piles_elements” after 200 d
4. Re-activate the elements of the same selection after 300 d and initialize corresponding nodal heads with a value of 10 m. Nodes which has been previously completely surrounded by inactive elements are considered only. I detected these nodes based on selections, but you could also check whether or not a nodal head values correspond to nan (not a number).

Please note that the tiny snippet has not been carefully tested (e.g. 3D, unsaturated flow etc). Accordingly, I cannot provide any warranty that the script works correctly. Instead, the script is simple starting point into inactive elements using the FEFLOW API.

[font=courier][color=blue]
import sys, os

sys.path.append('C:\\Program Files\\DHI\\2017\\FEFLOW 7.1\\bin64')
import ifm
from ifm import Enum


try:

    def onTimeStepConstraint(doc, tNow, dT):

        timeIntervals = [100., 200., 300.]
        for i in range(0, len(timeIntervals) - 1):
            if timeIntervals[i] < tNow < timeIntervals[i + 1]:
                if tNow + dT > timeIntervals[i + 1]:
                    dT = timeIntervals[i + 1] - tNow

        if tNow == deactivation_time:
            print "Elements will be deactivated at t = ", tNow

            for inactive_element in inactive_elements_list:
                doc.setMatElementActive(inactive_element, inactive_element_state)

        if tNow == activation_time:
            print "Elements will be activated at t = ", tNow
            for inactive_element in inactive_elements_list:
                doc.setMatElementActive(inactive_element, active_element_state)

            for inactive_node in inactive_node_list_reduced:
                doc.setPredictorHeadTimeValue(inactive_node, initializing_value)
                doc.setResultsFlowHeadValue(inactive_node, initializing_value)

        return dT

    cwd = os.getcwd()

    FEM_FILE_in = cwd + "\\..\\femdata\\barrier_in.fem"
    FEM_FILE_out = cwd + "\\..\\femdata\\barrier_out.fem"
    DAC_FILE_out = cwd + "\\..\\results\\barrier.dac"

    # Time to deactivate elements
    deactivation_time = 200
    # Time to activate elements and process variable initialization
    activation_time = 300

    inactive_elements_list = []
    inactive_node_list = []
    connected_node_list = []
    inactive_node_list_reduced = []
    sel_type_element = 1  # element=0
    sel_type_node = 0  # nodal=0
    inactive_element_state = 0 # inactive = 0
    active_element_state = 1 # active = 1
    initializing_value = 10

    # Load FEFLOW document
    doc=ifm.loadDocument(FEM_FILE_in)


    # Prepare selections
    element_selection_id = doc.findSelection(sel_type_element, "sheet_piles_elements")
    doc.createSelection(sel_type_node, "sheet_piles_nodes")
    node_selection_id = doc.findSelection(sel_type_node, "sheet_piles_nodes")

    nElements = doc.getNumberOfElements()
    nNodes = doc.getNumberOfNodes()

    # Get inactive element list
    for element_id in range(nElements):
        if doc.selectionItemIsSet(sel_type_element, element_selection_id, element_id) == 1:
            inactive_elements_list.append(element_id)


    for inactive_element in inactive_elements_list:

        # Nodes connected to elements
        for ElementNode in range(0, doc.getNumberOfElementNodes(inactive_element)):
            ElementNode_id = doc.getNode(inactive_element, ElementNode)

            # Elements connected to node
            inactive_NodeElements_list = [ElementNode_id, doc.getNumberOfNodeElements(ElementNode_id)]
            for NodeElement in range(0, doc.getNumberOfNodeElements(ElementNode_id)):
                NodeElement_id = doc.getElement(ElementNode_id, NodeElement)

                if doc.selectionItemIsSet(sel_type_element, element_selection_id, NodeElement_id) == 1:
                    inactive_NodeElements_list.append(1)

            connected_node_list.append(inactive_NodeElements_list)

    # Make nodal selection for initialization of process variable head
    for node_incident_list in connected_node_list:
        if node_incident_list[1] == node_incident_list.count(1):
            doc.setSelectionItem(sel_type_node, node_selection_id, node_incident_list[0])
            inactive_node_list.append(node_incident_list[0])

    # Remove doubles
    for inactive_node in inactive_node_list:
        if inactive_node not in inactive_node_list_reduced:
            inactive_node_list_reduced.append(inactive_node)

    # Enable parameter recording in output dac-file for inactive elements (pseudo material)
    doc.enableParamRecording(Enum.P_INACTIVE_ELE)

    doc.saveDocument(FEM_FILE_out)
    doc.startSimulator(DAC_FILE_out)
    doc.stopSimulator()

except Exception as err:
print >> sys.stderr, err
exit(-1);
[/color][/font]


Posted Thu, 17 May 2018 12:36:38 GMT by Joaquin Cortinez SN
thanks for the code Björn, I can post here some feedback of the implementation once i finish my model

regards
Posted Fri, 25 May 2018 15:18:38 GMT by Björn Kaiser
Great, thanks.

You must be signed in to post in this forum.