-
Notifications
You must be signed in to change notification settings - Fork 247
Tutorial: Editing the main files
In the main files of our application: my_laplacian_application.h
and my_laplacian_application.cpp
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, which are explained below:
The first lines are just the typical legal issues related to the Kratos license. Just add your name as the main author of this application.
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: HERE_YOUR_NAME
//
In order to avoid class redefinition, you have to define a label for your application definition, as follows:
#pragma once
We will need to add the "include" files, such as the element and condition:
#include "custom_elements/my_laplacian_element.h"
#include "custom_conditions/point_source_condition.h"
The class MyLaplacianApplication
definition comes inside the Kratos namespace. Then, you will need to declare the element and conditions as private member variables:
private:
///@name Static Member Variables
///@{
///@}
///@name Member Variables
///@{
const MyLaplacianElement mMyLaplacianElement;
const PointSourceCondition mPointSourceCondition;
///@}
As specified in the Style Guide, all member variables inside a class are identified by a lower case m at the beginning of the name.
First of all, remember to customize the header and add the include files. The elements initialization will need the geometries headers:
// | / |
// ' / __| _` | __| _ \ __|
// . \ | ( | | ( |\__ `
// _|\_\_| \__,_|\__|\___/ ____/
// Multi-Physics
//
// License: BSD License
// Kratos default license: kratos/license.txt
//
// Main authors: HERE_YOUR_NAME
//
// System includes
// External includes
// Project includes
#include "geometries/triangle_2d_3.h"
#include "geometries/line_2d_2.h"
#include "geometries/point_2d.h"
#include "my_laplacian_application.h"
#include "my_laplacian_application_variables.h"
The implementation file includes the initialization of the element and conditions inside the constructor, and then, registering them:
namespace Kratos {
KratosMyLaplacianApplication::KratosMyLaplacianApplication():
KratosApplication("MyLaplacianApplication"),
mMyLaplacianElement( 0, Element::GeometryType::Pointer( new Triangle2D3<Node>( Element::GeometryType::PointsArrayType (3) ) ) ),
mPointSourceCondition( 0, Element::GeometryType::Pointer( new Point2D <Node>( Element::GeometryType::PointsArrayType (1) ) ) )
{}
void KratosMyLaplacianApplication::Register() {
// calling base class register to register Kratos components
KratosApplication::Register();
std::cout << "Initializing KratosMyLaplacianApplication... " << std::endl;
KRATOS_REGISTER_VARIABLE( POINT_HEAT_SOURCE )
KRATOS_REGISTER_ELEMENT( "MyLaplacianElement", mMyLaplacianElement )
KRATOS_REGISTER_CONDITION( "PointSourceCondition", mPointSourceCondition )
}
} // namespace Kratos.
We only need to create POINT_HEAT_SOURCE
variable since the other variables needed in this app are already included in the kernel (CONDUCTIVITY
and TEMPERATURE
). The application generator has carried out the next tasks:
-
Define the variables in the
application_variables.h
(just remember to customize the header) -
Create the variables in the
application_variables.cpp
-
Register the variables in Kratos in the
application.h
, as we have seen above -
Register the variables in Python in the
custom_python/python_application.cpp
file.
Finally, we will need to add the new sources to the cmake file (only the .cpp are needed).
This is currently done automatically with the commands. Check that you have these lines in your CMakeLists.txt.
## MyLaplacian Core sources
file(GLOB_RECURSE KRATOS_MY_LAPLACIAN_APPLICATION_CORE
${CMAKE_CURRENT_SOURCE_DIR}/my_laplacian_application.cpp
${CMAKE_CURRENT_SOURCE_DIR}/my_laplacian_application_variables.cpp
${CMAKE_CURRENT_SOURCE_DIR}/custom_conditions/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/custom_elements/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/custom_processes/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/custom_utilities/*.cpp
)
- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API