How to Add a Custom Utilities File

From KratosWiki
(Difference between revisions)
Jump to: navigation, search
Line 24: Line 24:
  
  
when we want toi call the pure convection solver.
+
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?
 
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?
Line 53: Line 53:
 
         ;
 
         ;
  
Bythese way also the functions Contructsystem, CalculateProjection, ConvectScalarVar and ClearSystem can be called from the test example python file.
+
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();

Revision as of 16:05, 20 February 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)



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();
Personal tools
Categories