• Using conservative mass transport to determine water origin

    Hello Forum,

    i am facing the following problem. My model domain represents a vertical slice of aquifer which is orientated transverse to a river. The river is represented with a transient hydraulic head boundary. The remaining boundary condition is a recharge value implemented as a constant flux BC on top of the domain. I am investigating the influence of a clogging layer (implemented as a low hydraulic conductive layer next to the river boundary) to the hyporheic zone. The size of the hyporheic zone is defined as 10 % river water content.
    Currently i try to use a non reactive species to show this 10% isoline and thus represent the size of the hyporheic zone. Therefore i add a mass concentration BC to the aquifer - river interface with 1 mg/l and 0 mg/l to the recharge boundary condition. Unfortunately with my setup i am not able to produce a conservative transport. As soon as i assign the dispersivity to 0 the model is no longer transporting mass. I already switched to the divergence form of the transport equation to enable also conductive transport.

    I would be very glad if you could help me. Maybe i am just missing a setting which is important or my attempt is completely wrong and there is a much better solution.

    Thanks in advance
    Ludwig
  • Re: Coupling Feflow and FePest for not assigned Parameters (Manual Coupling of PEST)

    Hello Forum,

    the code i posted is finally working. The problem which caused the error was finally much simpler. My FePest project was connected to another .fem file and also didn't have the plugin attached.

    With the right .fem the callback structure works fine and in combination with the PARDISO solver it is also acceptable fast.

    Best regards
    Ludwig
  • Re: Coupling Feflow and FePest for not assigned Parameters (Manual Coupling of PEST)

    Hello Carlos,

    here the code of the plugin. The code is placed in the callback section of the IFM structure.

    #include "stdifm.h"
    #include "IFM Plug-in1.h"
    #include <ifm/document.h>
    #include <fstream>
    #include <iostream>
    #include <string>

    using namespace std;

    IfmModule g_pMod;  /* Global handle related to this plugin */

    #pragma region IFM_Definitions
    /* --- IFMREG_BEGIN --- */
    /*  -- Do not edit! --  */

    static void PreEnterSimulator (IfmDocument);

    /*
    * Enter a short description between the quotation marks in the following lines:
    */
    static const char szDesc[] =
      "Please, insert a plug-in description here!";

    #ifdef __cplusplus
    extern "C"
    #endif /* __cplusplus */

    IfmResult RegisterModule(IfmModule pMod)
    {
      if (IfmGetFeflowVersion (pMod) < IFM_REQUIRED_VERSION)
        return False;
      g_pMod = pMod;
      IfmRegisterModule (pMod, "SIMULATION", "IFM_PLUG_IN1", "IFM Plug-in1", 0x1000);
      IfmSetDescriptionString (pMod, szDesc);
      IfmSetCopyrightPath (pMod, "IFM Plug-in1.txt");
      IfmSetHtmlPage (pMod, "IFM Plug-in1.htm");
      IfmSetPrimarySource (pMod, "IFM Plug-in1.cpp");
      IfmRegisterProc (pMod, "PreEnterSimulator", 1, (IfmProc)PreEnterSimulator);
      return True;
    }

    static void PreEnterSimulator (IfmDocument pDoc)
    {
      CIfmPlugIn1::FromHandle(pDoc)->PreEnterSimulator (pDoc);
    }

    /* --- IFMREG_END --- */
    #pragma endregion


    ///////////////////////////////////////////////////////////////////////////
    // Implementation of CIfmPlugIn1

    // Constructor
    CIfmPlugIn1::CIfmPlugIn1 (IfmDocument pDoc)
      : m_pDoc(pDoc)
    {
      /*
      * TODO: Add your own code here ...
      */
    }

    // Destructor
    CIfmPlugIn1::~CIfmPlugIn1 ()
    {
      /*
      * TODO: Add your own code here ...
      */
    }

    // Obtaining class instance from document handle
    CIfmPlugIn1* CIfmPlugIn1::FromHandle (IfmDocument pDoc)
    {
      return reinterpret_cast<CIfmPlugIn1*>(IfmDocumentGetUserData(pDoc));
    }

    // Callbacks
    void CIfmPlugIn1::PreEnterSimulator (IfmDocument pDoc)
    // Reading number of Elements
    { int maxElement = IfmGetNumberOfElements(pDoc);
    //Reading the values
    double tab [5]={ 0.000, 0.000, 0.000, 0.000};
    string colA;
    double colB;

    int i=0;
    ifstream inputFile("C:\\PEST\\Basis_225_181_2L_simple_unsat_cal\\ifm.fpi");
    if (inputFile.is_open())
    {
    while ((!inputFile.eof())&&(i<5))
    {

    inputFile>>colA;
    inputFile>>colB;
    tab[i]=colB;
    i++;
    }
    inputFile.close();
    }
    double Value_s_s=tab [0];
    double Value_s_r=tab [1];
    double Value_alpha=tab [2];
    double Value_n=tab [3];
    //Writing values to file
    ofstream myfile;
      myfile.open ("C:\\PEST\\Basis_225_181_2L_simple_unsat_cal\\example.txt");
      myfile << tab[0] << tab[1] << tab[2] << tab[3];
      myfile.close();
    //Assigning the values
    for (int nElement=0;nElement < maxElement;nElement++)
    {
    IfmSetMatUnsatFittingCoefficient(pDoc,nElement,Value_alpha);
    IfmSetMatUnsatFittingExponent(pDoc,nElement,Value_n);
    IfmSetMatUnsatMaximumSaturation(pDoc,nElement,Value_s_s);
    IfmSetMatUnsatResidualSaturation(pDoc,nElement,Value_s_r);
    }
    }


    //Ludwig
  • Re: Coupling Feflow and FePest for not assigned Parameters (Manual Coupling of PEST)

    Hello Carlos,

    i managed to develop the plugin so far (Code coming soon). The problem which remains is that the callback functions are not triggered when PEST is starting the .fem file.
    I tried so far:

    PreSimulation
    PreEnterSimulation
    PreFlowSimulation
    PostLoadDocument

    Is there anything else beside the Callback function, the attaching of the plugin and the activation i have to do so the plugin starts when FePest is using the .fem file?

    Thanks
    Ludwig
  • Coupling Feflow and FePest for not assigned Parameters (Manual Coupling of PEST)

    Hello Forum,

    i would like here to continue on my initial topic of coupling Pest manually with Feflow in case the parameter which need to be calibrated are not available in the current FePest version.

    After helpful contributions by Carlos and Giovanni it turned out that a Plugin development would be taking less time than the setup of all the Pest files.
    The state is that the function of this Plugin is not entirely clear to me. Until now i assume the following way of functionality:

    1. In FePest a #IFM implemented# parameter is assigned and during the run of the check function a additional template file (ifm.tpl) is added to the Pest directory.
    2. The plugin in Feflow is triggered before every simulation run. This is done by the callback function PreFlowSimulation.
    3. The plugin assignes the in the template file stored, estimated parameters (in my case Van Genuchten alpha and n, and the saturation limits s_s and s_r)
    4. After every model call by FePest the parameter is changed for optimization in the ifm.tpl file and Feflow assignes the changed parameters in the .fem file.

    I hope this gives a sufficient summary of the development so far and i hope it is right so far.

    Regards
    Ludwig
  • Re: Manual Coupling of PEST and Feflow

    Of course, i will open a new topic in the FePest forum.
  • Re: Manual Coupling of PEST and Feflow

    Hello Carlos,

    thank you for your answers in the Webinar. I would like to summarize them here so the forum can participate as well.

    FePest is creating a blank parameter in the Pest directory as well as an additional template file. The Feflow plugin needs to extract the parameter which wants to be estimated from this file to the .fem. Than FePest knows the value and can calibrate it. The initial conditions probably need to be defined manually, as well as, the Pest results?

    I have a few more questions to this procedure:

    1. The time when the plugin is launched is defined by the callback function. This would be normally before the simulation starts so the new calibrated.
    2. The template file is updated after every model run by Pest, so it is not sufficient to setup the IFM.tpl once on the beginning manually

    Regards

    Ludwig
  • Re: Manual Coupling of PEST and Feflow

    Hello Carlos,

    i already went through this documentation.

    So far i understand the following workflow:

    1. FePest can access parameters via the #IFM implemented# definition (There i assign a Definition/Name for the parameter which must be the same definition as in the plugin)
    2. The plugin is calling the parameters in Feflow and assigning this identifying Definition/Name to them

    Thereafter, FePest should be able to comunicate with Feflow and adjust the parameters in the Estimation process.

    Am i right with this assumption? If, yes i assume that the plugin has just the function of assigning identifiers.

    //Ludwig
  • Re: Manual Coupling of PEST and Feflow

    Hello,

    I will try to develop the necessary plugin to assign the unsaturated parameters in Feflow. Since I am not used to programming this seems quite challenging. How is the assigning of the already existing parameters done in FePest? Is it a plugin as well? If yes, I would be interested to see how the Code looks like and maybe i could use the biggest part of this.

    Is there any tutorial or help about which callbacks have to be used and which not?

    Thanks for the help

    Ludwig
  • Manual Coupling of PEST and Feflow

    Hello everybody,

    i am currently in the need to use PEST to calibrate hydraulic conductivity and unsaturated Parameters (s_s, s_r and the fitting parameters alpha and n of the Van Genuchten model).

    Since this is not working in FePest without developing a new Plugin i would like to use PEST in the classical way. I found a guide (http://www.feflow.com/uploads/media/pest_feflow.pdf)  which explains the basic steps for creating the input files but it refers to a available .dar file for extracting the results. Can i setup Feflow so that it will always save the .dar file with the new results after each run of the model? Or is there a possibility to extract the results somewhere else.
    In my case it is a 2D, transient model with a simulation time of 110 days.

    If maybe somebody already faced this problem and managed to develop the necessary coupling Plugin i would be glad if i could use it to proceed with my thesis.

    Best Regards
    Ludwig