-
Notifications
You must be signed in to change notification settings - Fork 247
Applications as python modules
https://github.com/KratosMultiphysics/Kratos/pull/3217/ enables the applications can be used as python-modules.
This means that the python-scripts in the Applications can now be used e.g. as:
# old:
import KratosMultiphysics
import analysis_stage # this works because the folder "python_scripts" is added to the python_path
# new, pythonic way
from KratosMultiphysics import analysis_stage
from KratosMultiphysics.FluidDynamicsApplication.navier_stokes_solver_vmsmonolithic import NavierStokesSolverMonolithic
The new way is the standard already for new applications created with the Application-Generator. For already existing applications currently both ways are supported, but it is recommended to the developers to use the new way (pythonic way) of importing python-scripts because at some point the old import-mechanism (which adds the python_scripts to the python-path) will be removed eventually, and then all python-files should be using the new way already.
1. Modify the CMakeLists.txt
in your Application (replacing DummyApplication
with the real name of your Application):
Change the location where the DummyApplication.py
is being installed to:
- from:
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/DummyApplication.py" DESTINATION KratosMultiphysics )
- to
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/DummyApplication.py" DESTINATION "KratosMultiphysics/DummyApplication" RENAME "__init__.py")
The DummyApplication.py
should look like this:
# makes KratosMultiphysics backward compatible with python 2.6 and 2.7
from __future__ import print_function, absolute_import, division
# Application dependent names and paths
import KratosMultiphysics as KM
from KratosDummyApplication import *
application = KratosDummyApplication()
application_name = "KratosDummyApplication"
application_folder = "DummyApplication"
KM._ImportApplicationAsModule(application, application_name, application_folder, __path__)
As shown above
previously:
KratosMultiphysics
|-- __init__.py
|-- application_importer.py
|-- kratos_globals.py
|-- ... (other kratos files)
|-- DummyApplication.py
new:
KratosMultiphysics
|-- __init__.py
|-- application_importer.py
|-- kratos_globals.py
|-- ... (other kratos files)
|-- DummyApplication
|-- __init__.py
- 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