Tutorial:Editing the main files
From KratosWiki
(Difference between revisions)
(→cpp file: purediffusion_application.cpp) |
(→cpp file: purediffusion_application.cpp) |
||
Line 152: | Line 152: | ||
KratosPureDiffusionApplication::KratosPureDiffusionApplication()''':''' //constructor ''' do not forget to add the ":" ''' | KratosPureDiffusionApplication::KratosPureDiffusionApplication()''':''' //constructor ''' do not forget to add the ":" ''' | ||
− | '''mPoisson2D ( 0, Element::GeometryType::Pointer( new Triangle2D3<Node<3> >( | + | '''mPoisson2D ( 0, Element::GeometryType::Pointer( new Triangle2D3<Node<3> >( Element::GeometryType::PointsArrayType (3) ) ) ),''' |
− | '''mPointSource ( 0, Element::GeometryType::Pointer( new Point2D <Node<3> >( Element::GeometryType::PointsArrayType (1 | + | '''mPointSource ( 0, Element::GeometryType::Pointer( new Point2D <Node<3> >( Element::GeometryType::PointsArrayType (1) ) ) )''' |
{} | {} |
Latest revision as of 07:46, 3 May 2016
As stated in the the begining of the tutorial, our application must contain:
- Elements, which will define the stiffness matrix of our problem (only lefthandside, since there are no thermal loads that affect the whole element) and
- Conditions: Our puntual heat loads (applied nodewisely)
- Note that we'll have to create a new variable POINT_HEAT_SOURCE that is not inside the kratos' kernel. To do so we have to define, create and register it as shown in the files below.
In the main files of our application: purediffusion_application.cpp and purediffusion.h we will have to include the code describing our element and condition and tell Kratos how to use it. The original files created in the previous section require some minor modifications, shown in bold in the code shown below:
header file: purediffusion_application.h
// // Project Name: Kratos // Last Modified by: $Author: $ // Date: $Date: $ // Revision: $Revision: 1.2 $ // // #if !defined(KRATOS_PUREDIFFUSION_APPLICATION_H_INCLUDED ) #define KRATOS_PUREDIFFUSION_APPLICATION_H_INCLUDED // System includes #include <string> #include <iostream> // External includes:none in this case // Project includes #include "includes/define.h" #include "includes/kratos_application.h" #include "includes/variables.h" #include "custom_elements/poisson_2d.h" //including the file for the element #include "includes/condition.h" //we'll also need conditions for the point heat loads #include "custom_conditions/pointsource.h" #include "includes/ublas_interface.h" namespace Kratos { ///@name Kratos Globals ///@{ // Variables definition KRATOS_DEFINE_VARIABLE(double, POINT_HEAT_SOURCE) class KratosPureDiffusionApplication : public KratosApplication { public: /// Pointer definition of KratosPureDiffusionApplication KRATOS_CLASS_POINTER_DEFINITION(KratosPureDiffusionApplication); /// Default constructor. KratosPureDiffusionApplication(); /// Destructor. virtual ~KratosPureDiffusionApplication(){} virtual void Register(); /// Turn back information as a string. virtual std::string Info() const { return "KratosPureDiffusionApplication"; } /// Print information about this object. virtual void PrintInfo(std::ostream& rOStream) const { rOStream << Info(); PrintData(rOStream); } ///// Print object's data. virtual void PrintData(std::ostream& rOStream) const { KRATOS_WATCH("in my application"); KRATOS_WATCH(KratosComponents<VariableData>::GetComponents().size() ); rOStream << "Variables:" << std::endl; KratosComponents<VariableData>().PrintData(rOStream); rOStream << std::endl; rOStream << "Elements:" << std::endl; KratosComponents<Element>().PrintData(rOStream); rOStream << std::endl; rOStream << "Conditions:" << std::endl; KratosComponents<Condition>().PrintData(rOStream); } protected: private: const Poisson2D mPoisson2D; //and here is our element. const PointSource mPointSource; //and our condition /// Assignment operator. KratosPureDiffusionApplication& operator=(KratosPureDiffusionApplication const& rOther); /// Copy constructor. KratosPureDiffusionApplication(KratosPureDiffusionApplication const& rOther); }; // Class KratosPureDiffusionApplication } // namespace Kratos. #endif // KRATOS_PUREDIFFUSION_APPLICATION_H_INCLUDED defined
cpp file: purediffusion_application.cpp
// // Project Name: Kratos // Last Modified by: $Author: $ // Date: $Date: $ // Revision: $Revision: 1.3 $ // // Project includes #include "includes/define.h" #include "geometries/triangle_2d_3.h" //#include "geometries/triangle_3d_3.h" //#include "geometries/tetrahedra_3d_4.h" #include "geometries/point_2d.h" #include "geometries/line_2d.h" #include "purediffusion_application.h" #include "includes/variables.h" namespace Kratos { KRATOS_CREATE_VARIABLE(double, POINT_HEAT_SOURCE) // the other variables needed in this app dont need to be created since they're already included in the kernel ( CONDUCTIVITY and TEMPERATURE) KratosPureDiffusionApplication::KratosPureDiffusionApplication(): //constructor do not forget to add the ":" mPoisson2D ( 0, Element::GeometryType::Pointer( new Triangle2D3<Node<3> >( Element::GeometryType::PointsArrayType (3) ) ) ), mPointSource ( 0, Element::GeometryType::Pointer( new Point2D <Node<3> >( Element::GeometryType::PointsArrayType (1) ) ) ) {} void KratosPureDiffusionApplication::Register() { // calling base class register to register Kratos components KratosApplication::Register(); std::cout << "Initializing KratosPureDiffusionApplication... " << std::endl; KRATOS_REGISTER_VARIABLE( POINT_HEAT_SOURCE ) // Registering elements and conditions here KRATOS_REGISTER_ELEMENT("Poisson2D", mPoisson2D); //and here is our element KRATOS_REGISTER_CONDITION( "PointSource", mPointSource ) //and our condition } } // namespace Kratos.
CMakeLists.txt
Finally, you'll have to add the new sources to the cmake file (only the .cpp are needed)
${CMAKE_CURRENT_SOURCE_DIR}/custom_elements/poisson_2d.cpp ${CMAKE_CURRENT_SOURCE_DIR}/custom_conditions/pointsource.cpp
back to Kratos For Dummies