How to Add a Custom Utilities File

From KratosWiki
(Difference between revisions)
Jump to: navigation, search
Line 83: Line 83:
   #include "custom_python/add_custom_utilities_to_python.h"
   #include "custom_python/add_custom_utilities_to_python.h"
-  Modify the '''''jamfile''''' of the application inserting the new folder '''custom_utilities''' :
-  Modify the '''''CMakeLists.txt''''' of the application inserting the new folder '''custom_utilities''' :
   project MeshingApplication
and the new file to be built:     
and the new file to be built:     

Revision as of 09:53, 3 May 2012

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

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

  from KratosMultiphysics.ConvectionDiffusionApplication import *

we will write:

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

when we want to 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)

Doing that,the functions Contructsystem, CalculateProjection, ConvectScalarVar and ClearSystem can be called from the just typing

           # construct system -- could be done once if the mesh does not change
           #calculate projections
           #perform convection step
           #free memory


For more information about the overloading problem is recommended to look at

Adding a new folder custom_utilities

If the folder custom_utilities has to be created ex novo and you want to insert a new custom utilities file remember to:

- Create the add_custom_utilities_to_python.h and the add_custom_utilities_to_python.cpp into the custom_python folder of the application. In these two files the interface between python and kratos is created for the functions and classes of the new custom_utilities file. Remember to insert the new custom_utilities file in the add_custom_utilities_to_python.cpp:

    #include "custom_utilities/new_custom_utilities_file.h"


  #include "custom_python/add_custom_utilities_to_python.h"

- Modify the CMakeLists.txt of the application inserting the new folder custom_utilities :


and the new file to be built:

     ## list of files to be build, including dependencies to other libraries
        import python ;
        python-extension KratosR1MeshingApplication

- Inside the custom_python folder, don't forget to add the add_custom_utilities_to_python.cpp into the kratos_..._python_application.cpp

 #include "custom_python/add_custom_utilities_to_python.cpp"

- The same operation has to be done in the application_name

Personal tools