TclMatlabGFunEvaluator.cpp

Go to the documentation of this file.
00001 #include <TclMatlabGFunEvaluator.h>
00002 #include <Vector.h>
00003 #include <GFunEvaluator.h>
00004 #include <ReliabilityDomain.h>
00005 #include <LimitStateFunction.h>
00006 #include <RandomVariablePositioner.h>
00007 #include <ReliabilityDomain.h>
00008 
00009 #include <tcl.h>
00010 #include <string.h>
00011 
00012 #include <fstream.h>
00013 #include <engine.h>
00014 #include <mex.h>
00015 
00016 
00017 
00018 TclMatlabGFunEvaluator::TclMatlabGFunEvaluator(Tcl_Interp *passedTclInterp,
00019                                                                                            ReliabilityDomain *passedReliabilityDomain)
00020 
00021 :GFunEvaluator()
00022 {
00023         theTclInterp                    = passedTclInterp;
00024         theReliabilityDomain    = passedReliabilityDomain;
00025 }
00026 
00027 TclMatlabGFunEvaluator::~TclMatlabGFunEvaluator()
00028 {
00029 }
00030 
00031 
00032 int
00033 TclMatlabGFunEvaluator::evaluate_g(Vector x)
00034 {
00035 
00036         // "Download" limit-state function from reliability domain
00037         int lsf = theReliabilityDomain->getTagOfActiveLimitStateFunction();
00038         LimitStateFunction *theLimitStateFunction = 
00039                 theReliabilityDomain->getLimitStateFunctionPtr(lsf);
00040 
00041         if (lsf == 1) {
00042 
00043                 // Print the realization of x to file called 'realization.txt'
00044                 ofstream outputFile( "realization.txt", ios::out );
00045                 for (int i=0; i<x.Size(); i++) {
00046                         outputFile << x(i) << endl;
00047                 }
00048                 outputFile.close();
00049 
00050 
00051                 // Execute a Tcl file called 'tclgfun.tcl' (remember to "reset" analysis!)
00052                 char theTclCommand[30];
00053                 sprintf(theTclCommand,"source tclgfun.tcl");
00054                 Tcl_Eval( theTclInterp, theTclCommand );
00055 
00056                 
00057                 // Start a Matlab engine
00058                 Engine *ep;
00059                 ep = engOpen("\0");
00060 
00061 
00062                 // Execute a Matlab function called 'matlabgfun'
00063                 char theMatlabCommand[50];
00064                 sprintf(theMatlabCommand,"matlabgfun");
00065                 engEvalString(ep, theMatlabCommand);
00066 
00067 
00068                 // Shut down the Matlab engine
00069                 engClose(ep);
00070 
00071         }
00072         else {
00073                 // Does nothing
00074         }
00075 
00076 
00077         // Read value of limit-state functions from file called 'gfun.txt'
00078         double gvalue;
00079         ifstream inputFile( "gfun.txt", ios::in );
00080 
00081         for (int i=1; i<=lsf; i++) {
00082                 inputFile >> gvalue;
00083         }
00084 
00085 
00086         // Store the value of the g-function
00087         g = gvalue;
00088 
00089         return 0;
00090 }
00091 
00092 
00093 double
00094 TclMatlabGFunEvaluator::get_g()
00095 {
00096         return g;
00097 }

Generated on Mon Oct 23 15:05:25 2006 for OpenSees by doxygen 1.5.0