Posted Fri, 09 Nov 2012 00:03:35 GMT by Konrad Miotlinski
I am setting up a transient solute transport model. For selected time steps I want to export SorbedMass (Total and for selected elements) in the file to use it by PEST for the parameter optimisation exercise. Hence the structure of the IFM module looks as follows:

1. At the start of simulation user-defined times need to be imported.
2. After mass transport step FEFLOW calculates "Sorbed Mass" in the whole model and in selected elements.
3. At the end of simulation (or maybe earlier), the calculated masses need to be exported to the text file (only for the user-defined times).

It is probably quite easy, but I have problems with steps 1 and 3. Can anyone show me the commands or alternatively send me a similar benchmark file? That would be much appreciated.

Cheers,
Konrad
Posted Tue, 13 Nov 2012 10:50:16 GMT by Denim Umeshkumar Anajwala
Hi Konrad,

1. There's two options for this: Either the Plug-in reads a text file, or you let the user define a time series, e.g., with a specific name that you can identify via IFM. To be sure that FEFLOW calculates a result for these time stages, you have to apply the callback OnTimeStepConstraint. If the proposed time step would jump over one of the pre-defined time stages, you shorten the time step inside the callback to a value so that the next time stage in the list is exactly met.

3. Here's some simple example code to export water contents to a file (in C++ syntax):
  [font=courier]  ofstream outfile_stream;
    outfile_stream.open(m_out_file_path);
    outfile_stream << fixed << setw(12) << "x" << " ";
    outfile_stream << fixed << setw(12) << "y" << " ";
    outfile_stream << fixed << setw(12) << "z" << " ";
    outfile_stream << scientific << setw(20) << "wc" <<endl;
    double tNow = IfmGetAbsoluteSimulationTime(m_pDoc);
    outfile_stream << "time = " << fixed << setw(12) << tNow << " [d]" << endl;
    for (int i=0;i<m_nn;i++){
      double x = IfmGetX(m_pDoc, i);
      double y = IfmGetY(m_pDoc, i);
      double z = IfmGetZ(m_pDoc, i);
      double wc = IfmGetResultsFlowMoistureContentValue(m_pDoc, i);

      outfile_stream << fixed << setw(12) << x << " ";
      outfile_stream << fixed << setw(12) << y << " ";
      outfile_stream << fixed << setw(12) << z << " ";
      outfile_stream << scientific << setw(20) << wc <<endl;
    }
    outfile_stream.close();[/font]

The file is in this example selected in the OnEditDocument callback (i.e., when the user hits the Edit button in the Plug-ins Panel):

[font=courier]void exportwatercontent::OnEditDocument(void){
const char* temp_path;
temp_path = IfmGetProblemPath(m_pDoc);
m_out_file_path = IfmGetFileDirectory(m_pDoc, temp_path);
// Select output file
static IfmFileSelectionInfo info_outfile = {
  "ExportWaterContent: Select output file",
  NULL,
  "*.dat",
  "Text files (*.dat)|*.dat|All files (*.*)|*.*",
  0,
  NULL
};
info_outfile.initialDirectory = m_out_file_path;
int b = IfmFileSelection (m_pDoc, &m_out_file_path, False, &info_outfile, NULL);
}[/font]

Hope this helps a bit!
Good luck!
Peter
Posted Wed, 21 Nov 2012 05:27:17 GMT by Konrad Miotlinski
Hi Peter,

Thanks for that. I have successully programmed step 3, but I still have problems with step 1. I believe that the OnTimeStepConstraint callback would be the most suitable, as strict output times from the model are required (to compare the results with observations for these time).

Any example of coding 'OnTimeStepConstraint' would be much appreciated.

Regards,
Konrad
Posted Thu, 22 Nov 2012 11:19:19 GMT by Denim Umeshkumar Anajwala
Here you go (I simplified a bit...):
[font=courier]
IfmBool CSomething::OnTimeStepConstraint (double tNow, double* dtProposed)
{
if (((*dtProposed>t2min-tNow))&&((t2min-tNow)!=0.)){
*dtProposed=t2min-tNow;
}
  return true;
}
[/font]

You must be signed in to post in this forum.