next up previous contents index
Next: VI.2 CLA analyses in Up: VI. FeResPost Examples with Previous: VI. FeResPost Examples with   Contents   Index

Subsections


VI.1 COM examples with various languages

In this Chapter one shows examples illustrating the use of the COM component with interpreted or compiled languages. All the examples can work only if the COM component has been properly installed as explained in section IX.A.3.4. Note also, that the examples presented below assume that you have installed version 3.4.0 of the FeResPost COM component. If another version is installed, some lines in the program must be adapted.


VI.1.1 Using COM component with several languages

In this section, one presents an example in which the FeResPost COM component is used to automate CLA analyses with different programming languages. The same calculations are done with different programming languages. This allows the user to identify the similarities and differences of FeResPost COM automation with different programming languages:

Section VI.1.1.5 was added to allow the presentation of an automation program in C. This has not been one yet, however.


VI.1.1.1 Using component with python

The file ``COMEX/EX01/testClaCom.py'' contains the python program lines for automation of CLA calculations with python. One gives below some explanation about how the program works.

First, some python standard packages must be imported to allow the OLE automation to be used in the program. Therefore, the following statements are added at the beginning of the program:

         import sys
         import win32con
         from win32com.client import Dispatch, constants
Then the program defines several methods that are used in the main program: No ``main'' function is defined in the program. Instead, the last lines of the program file contain the instructions that perform the main analysis.

First the component must be accessed and a ClaDb object created and initialized. This is done as follows:

         frpApp = Dispatch("FeResPost_3_4_0.Application")
         db=frpApp.newObject("ClaDb")
         db.readNeutral("test.ndf")
Note that the access to the application requires the full name of the application that includes the version identification. This means that the name will have to be changed if another version of the component is used. The initialization of the ClaDb object involves the reading of ``test.ndf'' neutral data file.

The output of the results is done in a disk file:

         os=file("testClaCom_py.txt","w")
Note that the use of iterators with python is easy. For those who know python, to understand the following lines should not be a problem:
         for lamId in db.iter_laminateId:
            printLamProperties(db,os,lamId)
            for loadId in db.iter_loadId:
               printLoadResponse(db,os,lamId,loadId,0.0,criteria)
One first makes a loop on the laminates and prints their properties. Then, inside the loop on the laminates, a loop on the loads stored in the dataBase is done and the laminate load response is calculated and printed. The criteria that are calculated are: ``TsaiHill'', ``Ilss'' and ``YamadaSun''.

When the program is run, the FeResPost component application window exhibits the number of component objects referenced, and the number of references. You may stop the program at several locations to check this information. (By adding windows message boxes for example.)


VI.1.1.2 Using component with ruby

The file ``COMEX/EX01/testClaCom.rb'' contains the ruby program lines for automation of CLA calculations with ruby. The ruby program is very similar to the python program:

Note that the window created at the end of the program may show that some of the references to COM objects have not been released. Then this is a problem in ``win32ole''extension of ruby, but not in FeResPost COM component.


VI.1.1.3 Using component with VBscript

The file ``COMEX/EX01/testClaCom.vbs'' contains the VBscript program lines for automation of CLA calculations with VBscript. The VBscript version of the example is rather short, and it does not work: there is a problem with the access to elements of 2D matrices. If someone can explain us what is wrong, we would appreciate.

We just show below how the component is accessed, and the ClaDb object initialized:

         set frpApp= CreateObject("FeResPost_3_4_0.Application")
         set db=frpApp.newObject("ClaDb")
         db.readNeutral "test.ndf"


VI.1.1.4 Using component with C++

The example is provided in the following files:

The batch file ``COMEX/EX01/build.bat'' is used to compile the example. The compilation messages should look as follows:
         g++ -c testClaCom.cpp -I"H:\OUTPUTS\COM\include" 
         g++ -c util.cpp 
         g++ -o testClaCom.exe testClaCom.o util.o \
            "H:\OUTPUTS\COM\lib\FeresPost.dll"  -lole32 -loleaut32 \
            -luuid -lstdc++
(You may have to change the compilation commands, options and files access to compile the program on your computer.)

In a C++ program, several headers must first be included in the program to have access to classes, methods and GUIDs declarations and/or definitions:

         #include <Application.hxx>
         #include <Application_i.c>

         #include <ClaDb.hxx>
         #include <ClaLam.hxx>
         #include <ClaMat.hxx>
         #include <ClaLoad.hxx>
         #include <IterX.hxx>
         #include <Iterator.hxx>
(The included files are distributed with the FeResPost COM library in the ``include'' directory.) The access to the component and the initialization is done as follow:
      if (!CoInitialize(0)){
         if ((hr = CoGetClassObject(CLSID_Application, CLSCTX_INPROC_SERVER,
                  0, IID_IClassFactory, (LPVOID *)&classFactory))) {
            MessageBox(0, "Can't get IClassFactory", "CoGetClassObject error", 
                  MB_OK|MB_ICONEXCLAMATION);
            cerr << hr << endl ;
            exit(-1);
         }
         else {
            if ((hr = classFactory->CreateInstance(0, IID_IApplication, 
                     (LPVOID *)&frpApp))) {
               classFactory->Release();
               MessageBox(0, "Can't create IApplication object", 
                     "CreateInstance error",MB_OK|MB_ICONEXCLAMATION);
               return -1;
            }
            else {
               classFactory->Release();
               MessageBox(0, "SUCCESS", "SUCCESS", MB_OK|MB_ICONEXCLAMATION);
            }
         }
      }
       
      frpApp->newObject(BSTR_ClaDb,(IDispatch**)&db);
      string2variant("test.ndf",fileName);
      db->readNeutral(fileName);
As you can see, it is a little more complicated than in ruby or python.

The entire C++ example shows that it is significantly more complicated to use COM component with compiled languages than with interpreted languages that support COM automation. This is related to several factors:

Just to illustrate the points above, one gives below an example of the programming lines necessary to perform the iterations on laminate and load IDs and call the calculation functions:
         VARIANT lamId,loadId;
         IIterator *lamIt,*loadIt;
         IIterX *lamIterX,*loadIterX;
         ULONG pCeltFetched;
         
         ...
         
         db->get_iter_laminateId((IDispatch**)&lamIt);
         lamIt->get_newEnum((IUnknown**)&lamIterX);
         db->get_iter_loadId((IDispatch**)&loadIt);
         loadIt->get_newEnum((IUnknown**)&loadIterX);
         lamIterX->Reset();
         for (lamIterX->Next(1,&lamId,&pCeltFetched);pCeltFetched>0;
               lamIterX->Next(1,&lamId,&pCeltFetched)) {
            printLamProperties(db,os,lamId);
            loadIterX->Reset();
            for (loadIterX->Next(1,&loadId,&pCeltFetched);pCeltFetched>0;
                  loadIterX->Next(1,&loadId,&pCeltFetched)) {
                     printLoadResponse(db,os,lamId,loadId,0.0,criteria);
            }
         }
         lamIterX->Release();
         lamIt->Release();
         loadIterX->Release();
         loadIt->Release();
Actually, the example shows that the component that is being developed is adapted to the use with languages that support the Microsoft IDispatch interface. However, a library adapted to the use with C++ language should also be developed. Consequently we do not advise to use the component from C++ or C language.


VI.1.1.5 Using component with C

No C example is provided. But it is possible to program a C program using FeResPost COM component as well as a C++ program. This requires the same header files as those used in the C++ example. The program will not be significantly different than the C++ one. (Just a bit more complicated actually.)


VI.1.2 Testing the ``NastranDb'' and ``Group'' classes

The three examples described below are provided in directory ``COMEX/EX02''. From now on, the access to the component is done by calling ``getCurrentFrpApp'' method defined in ``Util'' Module. (This reduces the amount of work necessary to update the examples when a new version of FeResPost is published.)

VI.1.2.1 Using iterators and ``NastranDb'' class

The file ``COMEX/EX02/testNastranDb.py'' contains python examples of the use of NastranDb class with the COM component. Each type of test is defined in a devoted python function that is called by the ``main'' program.

The example ``COMEX/EX02/properties.rb'' illustrates the access to FEM definition with ``fillCard'' method.

VI.1.2.2 Writing elements connectivity

The file ``COMEX/EX02/elemConnectivity.rb'' contains the ruby equivalent of the ``testElemConnectivity'' function in ``COMEX/EX04/testNastranDb.py'' example. The operations done in this ruby file correspond to the ones in example ``SMALLEX/EX16/elemConnectivity.rb'' except that the COM component is used instead of the ruby extension. The comparison of the two ruby files shows that the differences correspond to the access to the component, and to the use of iterators.

VI.1.2.3 Manipulation of Groups

The file ``COMEX/EX02/testGroups.py'' contains python examples of Groups manipulation with the COM component. Four functions performing different tests are defined:

The "main" function is defined at the bottom of the example file.


VI.1.3 Translating a few ``SMALLEX'' Result examples

In the following sub-sections, one presents examples devoted to the manipulation of Result objects with FeResPost COM component. All these examples are the translation of examples of the ``SMALLEX'' directory for which the ruby extension was used. As descriptions of these examples with ruby extension are already given in Chapter IV.2, one highlights here only the peculiarities related to the use of the COM component.

Also, several of the ruby examples are translated in python. There, one also presents the peculiarities of the python programming with the COM component.


VI.1.3.1 Printing DataBase lists of Results

This example is stored in file ``COMEX/EX03/printResLists.rb''. It corresponds to the example "SMALLEX/EX04/printResLists.rb" described in section IV.2.4. The differences between the two programs are related to the way FeResPost COM component is accessed, to the access to the objects of different classes, and to the use of iterators. (See corresponding explanations in section IV.2.4.1.)

The same example is also translated in python in file ``COMEX/EX03/printResLists.py''. Here again, for explanations on the access to COM component and the use of iterators, the user is referred to section VI.1.4. One notes however differences in the use of iterators that return several values. The following ruby statements:

      db.iter_resultKey.each do |lcName,scName,tpName|
         tmpRes=db.getResultCopy(lcName,scName,tpName)
         printf("%-20s%-15s%-50s%-10d\n",lcName,scName,tpName,\
                tmpRes.Size)
      end
become in python:
      for tab in db.iter_resultKey:
         lcName=tab[0]
         scName=tab[1]
         tpName=tab[2]
         tmpRes=db.getResultCopy(lcName,scName,tpName)
         stdout.write("%-20s%-15s%-50s%-10d\n"%(lcName,scName,tpName,\
               tmpRes.Size)
(The differences are related to the fact that python has no syntax for iterators that return several values.)


VI.1.3.2 Printing maximum stress

This example is stored in file ``COMEX/EX03/printStressMax.rb''. It corresponds to the example ``SMALLEX/EX05/printStressMax.rb'' described in section IV.2.4.2. This example illustrates the use of operators with COM component. For example, with ruby extension, the intersection of two Groups is calculated with the following statement:

         newGrp = panelGroup * matGrp
With COM component, the same instruction becomes:
         newGrp = panelGroup.opMul(matGrp)
So far, the difference is not very dramatic. However, the translation of expressions involving several dyadic operators can be more difficult. For example, the following expression with ruby extension:
         scalar = Post.sqrt(sXZ*sXZ+sYZ*sYZ)
becomes with COM component:
         scalar = frpApp.sqrt(sXZ.opMul(sXZ).opAdd(sYZ.opMul(sYZ)))
(Note also that the ``sqrt'' method is found in ``frpApp'' Application instead of ``Post'' module.) A python version of the example is also available in file ``COMEX/EX03/printStressMax.py''.


VI.1.3.3 Generating Nastran GRAV cards

This example is stored in file ``COMEX/EX03/makeGravForces.rb''. It corresponds to the example ``SMALLEX/EX06/makeGravForces.rb'' described in section IV.2.5.1. As a Module is defined in this example, one needs to store the application in a ruby global variable. This is done as follows:

         $frpApp = WIN32OLE.new("FeResPost_3_4_0.Application")
Then, in the different methods of the Module, the global variable can be used to access the different methods of the application. For example, objects of the different classes can be created with ``newObject'' method as follows:
         db=$frpApp.newObject("NastranDb")


VI.1.3.4 Printing beam forces

This example is stored in file ``COMEX/EX03/printBeamForces.rb''. It corresponds to the example ``SMALLEX/EX08/printBeamForces.rb'' described in section IV.2.4.4. The example is also defined in the python file ``COMEX/EX03/printBeamForces.py''.

No remark is to be done about these programs, except that the ``UTIL'' modules are used. These are defined in files ``COMEX/Util/util.rb'' and ``COMEX/Util/util.py'' for ruby and python respectively. When the ruby and python versions of the module are compared, one notes a difference in the use of iterators. The brackets are mandatory for iterators methods with arguments are used in python even when no argument is given. This means that the following ruby statement:

      res.iter.each do |key,values|
Becomes in python:
      for tab in res.iter():
         key=tab[0]
         values=tab[1]
(The void brackets in python first statement is related to the fact that the ``iter'' method of ``Result'' class may have up to five arguments.)

Note that the UTIL Modules in COM examples correspond to the UTIL module defined in file ``SMALLEX/UTIL/util.rb'' and described in section IV.2.1.


VI.1.3.5 Printing strain tensor

This example is stored in file ``COMEX/EX03/printStrain.rb''. It corresponds to the example ``SMALLEX/EX08/printStrain.rb'' described in section IV.2.4.4. The example is also defined in the python file ``COMEX/EX03/printStrain.py''. No remark is to be done about this example.


VI.1.3.6 Modification of reference coordinate systems

These examples are stored in files ``COMEX/EX03/modifCS2D.rb'', ``COMEX/EX03/modifCS2Db.rb'', ``COMEX/EX03/modifCS2Dc.rb'' and ``COMEX/EX03/modifCS3D.rb'' respectively. They correspond to the examples of directory ``SMALLEX/EX09'' described in section IV.2.4.5. The example ``COMEX/EX03/modifCS2Db.rb'' is also programmed in python in file ``COMEX/EX03/modifCS2Db.py''. No remark is to be done about these examples.


VI.1.3.7 Calculation of global force and moment

This example is stored in file ``COMEX/EX03/testGlobFM.rb''. It corresponds to the example ``SMALLEX/EX08/testGlobFM.rb'' described in section IV.2.5.3. The example is also defined in the python file ``COMEX/EX03/testGlobFM.py''. No remark is to be done about this example.


VI.1.3.8 Writing GMSH mesh and Results

This example is stored in file ``COMEX/EX03/writeGmsh.rb''. It corresponds to the example ``SMALLEX/EX08/writeGmsh.rb'' described in section IV.2.4.4. The example is also defined in the python file ``COMEX/EX03/writeGmsh.py''. No remark is to be done about this example.


VI.1.3.9 Manipulation of XDB Result files

The examples described in the following sub-sections are devoted to the manipulation of XDB Result files. Only the second example deals with the manipulation of complex Results.

VI.1.3.9.1 Extraction of information from XDB Result file

The first example is stored in file ``COMEX/EX04/printXdbLcScResNames.rb''. It corresponds to the example ``SMALLEX/EX17/printXdbLcScResNames.rb'' described in section IV.2.4.6. The second example is stored in file ``COMEX/EX04/printXdbLcInfos.rb''. It corresponds to the example ``SMALLEX/EX17/printXdbLcInfos.rb'' described in section IV.2.4.6. No remark to be done about these examples.

VI.1.3.9.2 Manipulation of complex Results

This example is stored in file ``COMEX/EX04/manipComplex.rb''. It corresponds to the example ``SMALLEX/EX17/manipComplex.rb'' described in section IV.2.4.6. Some of the methods in ruby extension involve Complex arguments. As complex numbers are not accepted by the COM component, these numbers are replaced by an Array of two real values corresponding to the real and imaginary parts of the complex number respectively. This means that the following statements, valid when FeResPost ruby extension is used:

            Z=Complex.new(3.0,2.0)

            multRI=resRI.clone
            multRI*=Z
become the following statements when the COM component is used:
            Z=Complex.new(3.0,2.0)

            multRI=resRI.makeCopy()
            multRI=multRI.opMul([Z.real,Z.image])


VI.1.4 Using component for CLA analyses

One presents in the following sub-sections various examples of programs in which the COM component is used to perform CLA analyses.

VI.1.4.1 Laminate shear properties and load response

This example is stored in file ``COMEX/EX05/testShear.rb''. It corresponds to the example ``SMALLEX/EX14/testShear.rb'' described in section IV.5.5.

No remark to be done about this example.

VI.1.4.2 Laminate load response with FE Results

This example is stored in file ``COMEX/EX05/testClaFem.rb''. It corresponds to the example ``SMALLEX/EX15/testClaFem.rb'' described in section IV.5.6. Just one remark about this example: the COM methods do not accept the ruby ``Hash'' arguments. Therefore, this argument must be translated into Arrays the elements of which are Arrays of two elements corresponding to the keys and values respectively. In ruby, this operation is done by calling the ``to_a'' method of Hash class. For example, the insertion of allowables in a Laminate is done as follows:

         lam=compDb.getLaminateCopy(6)
         allowables={}
         allowables["sc"]=200.0e6
         allowables["s1c"]=200.0e6
         ...
         allowables["s12"]=100.0e6
         allowables["ilss"]=30.0e6
         lam.insertAllowables(allowables.to_a)
         compDb.insertLaminate(lam)
The example is also translated in python in file ``COMEX/EX05/testClaFem.py''. Then, the ``items'' method of ``map'' class is used to produce an Array suitable for allowables insertion:
         lam=compDb.getLaminateCopy(6)
         allowables={}
         allowables["sc"]=200.0e6
         allowables["s1c"]=200.0e6
         ...
         allowables["s12"]=100.0e6
         allowables["ilss"]=30.0e6
         lam.insertAllowables(allowables.items())
         compDb.insertLaminate(lam)
Note also the use of ``Dispatch'' method in python to retrieve Result objects from an Array like in the following statements:
         for tab in outputs:
            id=tab[0]
            res=Dispatch(tab[1])
            util.printRes(os,id,res)
(We presume that the ``Dispatch'' statement is necessary to convert a VARIANT.)

VI.1.4.3 Laminate failure criteria with FE stresses and strains

This example is stored in file ``COMEX/EX05/testCriteria.rb''. It corresponds to the example ``SMALLEX/EX15/testCriteria.rb'' described in section IV.5.6. No remark is to be done about this example.


VI.1.5 Object-oriented post-processing

In directory ``COMEX/EX07'', one presents the source files of an object-oriented post-processing using the COM component. This is a transposition of the ``PROJECTb'' post-processing described in Chapter IV.4. Modifications in the ruby sources are done to adapt the instructions to the fact that COM component is used instead of ruby extension. Also a few calls to the garbage collector have been added.


VI.1.6 XDB attachment Results access with RUBY and COM

In directory ``COMEX/EX08'', one presents the source files of examples illustrating the access to Results from XDB attached files. The four examples correspond exactly to the ones presented in section IV.2.4.7 for the use of ruby extension. Except for the few first lines, the examples are identical. One does not discuss the programming details here.


VI.1.7 Using COM component with excel

One advantage of programming FeResPost as a COM component, is that this allows to use the component from other applications. For example, FeResPost can be used from Excel provided one accepts to write some programming functions and subroutines in VBA. Several examples illustrate the benefits of using FeResPost from excel:


VI.1.8 An Excel workbook illustrating the use of SQL databases

This example is presented in excel workbook ``blob_test.xls'' in directory ``TESTSAT/COMEX/EX11'' correspond approximately to the ruby examples of section IV.2.6. In this case, one uses the ``SQLite for Excel" extension found on ``http://sqliteforexcel.codeplex.com/''. The corresponding libraries and VBA Module are distributed with the example in sub-directories. Very small modifications have been brought to the VBA code ``SQLite for Excel" to deal with the blobs produced by FeResPost. (See the ``SQLite3'' module in the sources that correspond to the corresponding Module found on ``http://sqliteforexcel.codeplex.com/'' + a few modifications.

Worksheet ``MANIP'' in the workbook corresponds to two VBA macros that perform operations very similar to those of the ruby example of section IV.2.6. These macros and a few more are defined in Module ``FeResPost_Results'' that contains the code for the example.

More information on the use of FeResPost with VBA is given in Chapters VI.2, VI.3 and VI.4. Note also that the installation of ``SQLite for Excel" extension in subdirectories of the example directory is not necessarily a good idea. The extension should be installed in a proper directory if you want to use it for other applications. Then a tuning of some directory names in VBA source code will be necessary.

Note also that COM wrappers of SQLite are also available and may be used with VBA language. (See the following address ``http://www.sqlite.org/cvstrac/wiki?p=SqliteWrappers'' if you are interested.) Of course, the use of databases other than SQLite is also possible (MySQL, PostGreSQL...).


next up previous contents index
Next: VI.2 CLA analyses in Up: VI. FeResPost Examples with Previous: VI. FeResPost Examples with   Contents   Index
FeResPost 2017-05-28