Tutorial:Editing the main files

From KratosWiki
Jump to: navigation, search

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 $


// 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 

	class KratosPureDiffusionApplication : public KratosApplication

		/// Pointer definition of KratosPureDiffusionApplication

		/// Default constructor.

		/// 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();

		///// 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;
			rOStream << std::endl;
			rOStream << "Elements:" << std::endl;
			rOStream << std::endl;
			rOStream << "Conditions:" << std::endl;



 		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.


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
		std::cout << "Initializing KratosPureDiffusionApplication... " << std::endl;


		// 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.


Finally, you'll have to add the new sources to the cmake file (only the .cpp are needed)


back to Kratos For Dummies

Personal tools