How to Add a Custom Utilities File

From KratosWiki
Revision as of 15:58, 20 February 2008 by Antonia (Talk | contribs)
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 solver_file.py

In the solver file (in this case ND_level_set_solver.py inside incompressible_fluid_application/python_scripts/), after having included the entire application

  from KratosR1ConvectionDiffusionApplication import *

we will write:

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


when we want toi call the pure convection solver.

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

I will define these two classes inside the 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