How to Add a Custom Utilities File

From KratosWiki
Revision as of 15:39, 20 February 2008 by Antonia (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Once a <custom_utilities>.h is written surely a new class has just been created. For instance if we look to the custom_utilities folder of the convection_diffusion_application we can see that the pure_convection_CrankN_tools.h is present.

Inside this file the problem of pure convection is treated and a Crank Nicolson scheme is used for the time integration.

We want that the python file we will have in the test example will be able to read the pure_convection_CrankN_tools.h both in 2d and 3d. (Remember that python language does not allow templates)



Modifying the python test example file

In the test example file, after having included the entire application, we will write:

       ##pure convection  Crank Nicholson tool
       if(self.domain_size == 2):
           self.convection_solver = PureConvectionCrankNUtilities2D();
       else:
           self.convection_solver = PureConvectionCrankNUtilities3D();

But where do I have to define these two classes just to make python able to recognize the location it has to look at?

Inside the application principal folder there is a folder custom_python where we can find a file add_custom_utilities_to_pyhton.h and add_custom_utilities_to_python.cpp.

Modifying add_custom_utilities_to_python.cpp file

Inside the file add_custom_utilities_to_python.cpp we will include the custom-utilities file:

   // Project includes
   #include "custom_utilities/pure_convection_CrankN_tools.h"
and we will add something like:
        class_< PureConvectionCrankNUtilities< 2, SparseSpaceType, LinearSolverType >,  boost::noncopyable >	
        ("PureConvectionCrankNUtilities2D", init< >() ) 
             .def("ConstructSystem",&PureConvectionCrankNUtilities< 2, SparseSpaceType, LinearSolverType >::ConstructSystem)
             .def("CalculateProjection",&PureConvectionCrankNUtilities< 2, SparseSpaceType, LinearSolverType >::CalculateProjection)
             .def("ConvectScalarVar",&PureConvectionCrankNUtilities< 2, SparseSpaceType, LinearSolverType >::ConvectScalarVar)         
             .def("ClearSystem",&PureConvectionCrankNUtilities< 2, SparseSpaceType, LinearSolverType >::ClearSystem)
        ;
        class_< PureConvectionCrankNUtilities< 3, SparseSpaceType, LinearSolverType >,  boost::noncopyable >	
        ("PureConvectionCrankNUtilities3D", init< >() )
               .def("ConstructSystem",&PureConvectionCrankNUtilities< 3, SparseSpaceType, LinearSolverType >::ConstructSystem)
               .def("CalculateProjection",&PureConvectionCrankNUtilities< 3, SparseSpaceType, LinearSolverType >::CalculateProjection)
               .def("ConvectScalarVar",&PureConvectionCrankNUtilities< 3, SparseSpaceType, LinearSolverType >::ConvectScalarVar)
               .def("ClearSystem",&PureConvectionCrankNUtilities< 3, SparseSpaceType, LinearSolverType >::ClearSystem)
        ;

Bythese way also the functions Contructsystem, CalculateProjection, ConvectScalarVar and ClearSystem can be called from the test example python file.

Personal tools
Categories