How to Add a Custom Utilities File

From KratosWiki
(Difference between revisions)
Jump to: navigation, search
Line 6: Line 6:
 
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.
 
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)
 
(Remember that python language does not allow templates)
 
 
  
  
Line 18: Line 16:
  
 
         ##pure convection  Crank Nicholson tool
 
         ##pure convection  Crank Nicholson tool
        if(self.domain_size == 2):
+
          if(self.domain_size == 2):
 
             self.convection_solver = PureConvectionCrankNUtilities2D();
 
             self.convection_solver = PureConvectionCrankNUtilities2D();
 
         else:
 
         else:
Line 71: Line 69:
  
 
For more information about the overloading problem is recommended to look at http://www.boost.org/doc/libs/1_34_1/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading
 
For more information about the overloading problem is recommended to look at http://www.boost.org/doc/libs/1_34_1/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading
 +
 +
 +
==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.
 +
-  Modify the jamfile of the application inserting the new file to be built:
 +
     
 +
  project MeshingApplication
 +
    :
 +
    source-location
 +
      .
 +
      constitutive_laws
 +
      custom_conditions
 +
      custom_elements
 +
      custom_processes
 +
      custom_python
 +
      custom_strategies
 +
      custom_utilities
 +
     
 +
 +
      ## list of files to be build, including dependencies to other libraries
 +
        import python ;
 +
        python-extension KratosR1MeshingApplication
 +
              : 
 +
              add_custom_utilities_to_python.cpp
 +
-

Revision as of 09:24, 10 June 2008

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)


Contents

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 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 solver-file.py just typing

           # construct system -- could be done once if the mesh does not change
           self.convection_solver.ConstructSystem(self.extrapolation_model_part,DISTANCE,CONVECTION_VELOCITY,MESH_VELOCITY);
           #calculate projections
           self.convection_solver.CalculateProjection(self.extrapolation_model_part,DISTANCE,NODAL_AREA,CONVECTION_VELOCITY,
                           MESH_VELOCITY,TEMP_CONV_PROJ);
           #perform convection step
           self.convection_solver.ConvectScalarVar(self.extrapolation_model_part,self.convection_linear_solver,DISTANCE,
                          CONVECTION_VELOCITY,MESH_VELOCITY,TEMP_CONV_PROJ,self.convection_order);
           #free memory
           self.convection_solver.ClearSystem();


Overloading

For more information about the overloading problem is recommended to look at http://www.boost.org/doc/libs/1_34_1/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading


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. - Modify the jamfile of the application inserting the new file to be built:

  project MeshingApplication
   : 
   source-location
      .
      constitutive_laws
      custom_conditions
      custom_elements
      custom_processes
      custom_python
      custom_strategies
      custom_utilities
      
     ## list of files to be build, including dependencies to other libraries
        import python ;
        python-extension KratosR1MeshingApplication
             :  
             add_custom_utilities_to_python.cpp 	

-

Personal tools
Categories