### Multi-Stage Simulation Setup Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Developers/Applications/Common_Python_Interface.md Example of setting up and running multiple analysis stages using a common Model object. ```python import KratosMultiphysics # if needed import the apps containing the stage model = KratosMultiphysics.Model() # only ONE for all stages! # reading ProjectParameters # construct all the stages stage_1 = FormFindingStage(model, project_params_formfinding) stage_2 = FSIStage(model, project_params_fsi) stage_3 = FatigueAnalysisStage(model, project_params_fatigue) list_of_stages = [stage_1, stage_2, stage_3] for stage in list_of_stages: stage.Run() ``` -------------------------------- ### MKL Setup Script for Windows Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/LinearSolversApplication/README.md Execute the MKL setup script on Windows before building Kratos to enable MKL functionalities. Adjust the path to your MKL installation if necessary. ```batch call "C:\Program Files (x86)\Intel\oneAPI\mkl\latest\env\vars.bat" intel64 lp64 ``` -------------------------------- ### Example CMake configuration for Ubuntu Trilinos install Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/TrilinosApplication/README.md Provide specific include directory, library directory, and library prefix for Trilinos installed via apt on Ubuntu. ```Shell -DTRILINOS_INCLUDE_DIR="/usr/include/trilinos" -DTRILINOS_LIBRARY_DIR="/usr/lib/x86_64-linux-gnu" -DTRILINOS_LIBRARY_PREFIX="trilinos_" ``` -------------------------------- ### Run Kratos Example Script Source: https://github.com/kratosmultiphysics/kratos/wiki/Getting-Kratos-Binaries-for-Linux Execute a Kratos Python script using the `kratos.sh` launcher. Ensure Kratos is installed and the script is in your PATH. ```bash kratos.sh MainKratos.py ``` -------------------------------- ### Install Boost Libraries with vcpkg Source: https://github.com/kratosmultiphysics/kratos/blob/master/INSTALL.md Installs Boost libraries, including precompiled versions, using vcpkg. This is an example and may require specific package names. ```PowerShell vcpkg install boost ``` -------------------------------- ### Compile and Run gidpost Examples Source: https://github.com/kratosmultiphysics/kratos/blob/master/external_libraries/gidpost/README.md After building the library, navigate to the examples directory and run the provided C and Fortran executables. Use '-help' to see options for the C example. ```shell make cd examples ./testc -help ;# to view format options ./testc -f hdf5 ;# to write a gid post file in hdf5 format ./testf90 ;# fortran 90 example writing hdf5 gid post file ``` -------------------------------- ### Octree Search Example Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/Spatial_Containers/Trees_And_Searches/octree.md Demonstrates the setup and usage of an Octree for spatial searching. It includes preparing point data, defining the Octree, and performing a parallel search within a specified radius. Ensure necessary types like ModelPart, PointObject, and SearchUtilities are available. ```C++ // Defining the point type for the search using NodesContainerType = ModelPart::NodesContainerType; using ResultNodesContainerType = NodesContainerType::ContainerType; using VectorResultNodesContainerType = std::vector; using PointType = PointObject; using PointVector = std::vector; using DistanceType = std::vector; using VectorDistanceType = std::vector; // Defining the PointVector VectorResultNodesContainerType nodes_results; VectorDistanceType result_distance; PointVector points = SearchUtilities::PrepareSearch(rStructureNodes, rInputNodes, nodes_results, result_distance); // Definitions const int allocation_size = 1000; const int bucket_size = 1000; /// Octree definitions using Octree = Tree>>; // Creating the tree Octree octree(points.begin(), points.end(), bucket_size); // Performing search double radius = 1.0; SearchUtilities::ParallelSearch(rInputNodes, radius, octree, nodes_results, result_distance, allocation_size); ``` -------------------------------- ### Python Example: Import Kratos and Create Model Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/Spatial_Containers/Trees_And_Searches/geometrical_objects_bins.md Imports the KratosMultiphysics library and initializes a Kratos Model object. This is a standard setup for Kratos Python scripting. ```python # Importing the Kratos Library import KratosMultiphysics as KM # Create a model model = KM.Model() ``` -------------------------------- ### Example Usage of BinsDynamic Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/Spatial_Containers/Trees_And_Searches/bins_dynamic.md Demonstrates the setup and usage of BinsDynamic for spatial searching. It includes defining point types, preparing search data, creating the BinsDynamic structure, and performing a parallel search within a specified radius. ```C++ // Defining the point type for the search using NodesContainerType = ModelPart::NodesContainerType; using ResultNodesContainerType = NodesContainerType::ContainerType; using VectorResultNodesContainerType = std::vector; using PointType = PointObject; using PointVector = std::vector; using DistanceType = std::vector; using VectorDistanceType = std::vector; // Defining the PointVector VectorResultNodesContainerType nodes_results; VectorDistanceType result_distance; PointVector points = SearchUtilities::PrepareSearch(rStructureNodes, rInputNodes, nodes_results, result_distance); // Definitions const int allocation_size = 1000; /// BinsDynamic definitions using DynamicBins = BinsDynamic<3ul, PointType, PointVector>; // Creating the bins DynamicBins dynamic_bins(points.begin(), points.end()); // Performing search double radius = 1.0; SearchUtilities::ParallelSearch(rInputNodes, radius, dynamic_bins, nodes_results, result_distance, allocation_size); ``` -------------------------------- ### Install MKL on Ubuntu using apt Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/LinearSolversApplication/README.md Install Intel MKL and its dependencies on Ubuntu using apt. This includes updating package lists, installing necessary build tools, adding the Intel repository, and installing the MKL development package. ```bash sudo bash # # If they are not installed, you can install using the following command: sudo apt update sudo apt -y install cmake pkg-config build-essential # use wget to fetch the Intel repository public key wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB # add to your apt sources keyring so that archives signed with this key will be trusted. sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB # remove the public key rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB # Configure apt client to use Intel repository sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main" # Install all MKL related dependencies. You can install full HPC with: sudo apt install intel-hpckit sudo apt install intel-oneapi-mkl-devel # Exit exit ``` -------------------------------- ### Build and Install Kratos Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Users/How_To_Get_Kratos/Compiling-Kratos-with-MPI-support.md Build and install Kratos using CMake, leveraging multiple processor cores for faster compilation. The `--target install` command ensures all necessary components are installed. ```bash cmake --build "${KRATOS_BUILD}" --target install -- -j $(nproc) ``` -------------------------------- ### Install KratosPfemCore and KratosPfemApplication Targets Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/PfemApplication/CMakeLists.txt Installs the compiled KratosPfemCore and KratosPfemApplication libraries into the 'libs' directory of the installation. This makes the compiled binaries available for runtime. ```cmake install(TARGETS KratosPfemCore DESTINATION libs ) install(TARGETS KratosPfemApplication DESTINATION libs ) ``` -------------------------------- ### Install Git on GNU/Linux Source: https://github.com/kratosmultiphysics/kratos/blob/master/INSTALL.md Installs the git version control system on GNU/Linux systems using apt-get. Ensure git is installed before cloning the Kratos repository. ```Shell sudo apt-get install git ``` -------------------------------- ### Install CoSimulationApplication Targets Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/CoSimulationApplication/CMakeLists.txt Installs the KratosCoSimulationCore and KratosCoSimulationApplication libraries to the 'libs' directory. ```cmake install(TARGETS KratosCoSimulationCore DESTINATION libs ) install(TARGETS KratosCoSimulationApplication DESTINATION libs ) ``` -------------------------------- ### Install Trilinos with apt Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/TrilinosApplication/README.md Use this command to install Trilinos development packages on Ubuntu systems. ```Shell sudo apt install trilinos-all-dev ``` -------------------------------- ### Enable Embedded Python Installation Source: https://github.com/kratosmultiphysics/kratos/wiki/Windows-Install Enables the installation of an embedded Python environment for Kratos. This is recommended for a smoother setup. ```bash -DINSTALL_EMBEDDED_PYTHON=ON ^ ``` -------------------------------- ### SetUpSystem Source: https://github.com/kratosmultiphysics/kratos/wiki/pydoc/Classes/KratosMultiphysics.BuilderAndSolver Sets up the linear system. ```APIDOC ## SetUpSystem ### Description Sets up the linear system. ### Parameters - **arg0** (Kratos.ModelPart) - The model part containing the problem. ``` -------------------------------- ### Set PYTHONPATH with GiD Installation on Linux Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Users/Tutorials/Getting_Started.md Example of setting the PYTHONPATH when Kratos is installed as a GiD problem type. The path points to the Kratos execution directory within the GiD installation. ```bash export PYTHONPATH=$HOME/GiDx64/GiD14.0.0/problemtypes/kratos.gid/exec/Kratos ``` -------------------------------- ### Install vedo (older version) Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Users/Crash_Course/Input_Output_and_Visualization/Visualization_In_Real_Time.md Install a specific older version of the vedo module required for this example. This version was previously known as vtkplotter. ```console pip3 install vtkplotter==2020.0.1 ``` -------------------------------- ### Initialize ModelPart and Read Input Source: https://github.com/kratosmultiphysics/kratos/wiki/Python-Script-Tutorial:-ModelPart-Elements-and-Conditions Sets up a Kratos ModelPart, defines nodal solution step variables, and reads model data from a specified file. Ensure the 'path/to/file/example' is a valid path to your input file. ```Python from KratosMultiphysics import * import KratosMultiphysics.FluidDynamicsApplication this_model = Model() fluid_model_part = this_model.CreateModelPart("FluidPart") fluid_model_part.AddNodalSolutionStepVariable(VELOCITY) fluid_model_part.AddNodalSolutionStepVariable(PRESSURE) fluid_model_part.AddNodalSolutionStepVariable(TEMPERATURE) fluid_model_part_io = ModelPartIO("path/to/file/example") fluid_model_part_io.ReadModelPart(fluid_model_part) fluid_model_part.SetBufferSize(3) ``` -------------------------------- ### Install Application Targets Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/GeoMechanicsApplication/CMakeLists.txt Installs the compiled libraries for the GeoMechanics application core, the main application, and test setup utilities. These are placed in the 'libs' directory. ```cmake install(TARGETS KratosGeoMechanicsCore DESTINATION libs ) install(TARGETS KratosGeoMechanicsApplication DESTINATION libs ) install(TARGETS KratosGeoMechanicsTestSetupUtilities DESTINATION libs) ``` -------------------------------- ### Configure Application for Compilation Source: https://github.com/kratosmultiphysics/kratos/wiki/Creating-a-base-application Add the -DMY_EXAMPLE_APPLICATION=ON flag to your configure file to enable compilation of your new application. ```bash -DMY_EXAMPLE_APPLICATION=ON \ ``` -------------------------------- ### Multi-Stage Simulation Setup in Python Source: https://github.com/kratosmultiphysics/kratos/wiki/Common-Python-Interface-of-Applications-for-Users Demonstrates how to set up and run multiple simulation stages sequentially using a shared Kratos Model object. This allows data to be passed between stages. ```python import KratosMultiphysics # if needed import the apps containing the stage model = KratosMultiphysics.Model() # only ONE for all stages! # reading ProjectParameters # construct all the stages stage_1 = FormFindingStage(model, project_params_formfinding) stage_2 = FSIStage(model, project_params_fsi) stage_3 = FatigueAnalysisStage(model, project_params_fatigue) list_of_stages = [stage_1, stage_2, stage_3] for stage in list_of_stages: stage.Run() ``` -------------------------------- ### Python: Example of Creating and Applying MPC Source: https://github.com/kratosmultiphysics/kratos/wiki/[KratosAPI]-MultiPoint-Constraint-(MPC)-interface This Python example demonstrates setting up a ModelPart, adding necessary variables and DoFs, creating a LinearMasterSlaveConstraint between two nodes, applying boundary conditions, and solving the system using a Newton-Raphson strategy. ```python import KratosMultiphysics # Define a Model current_model = KratosMultiphysics.Model() mp = current_model.CreateModelPart("Main") mp.AddNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT) mp.AddNodalSolutionStepVariable(KratosMultiphysics.REACTION) mp.CreateNewNode(1, 0.00000, 0.00000, 0.00000) mp.CreateNewNode(2, 0.00000, 1.00000, 0.00000) KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.DISPLACEMENT_X, KratosMultiphysics.REACTION_X, mp) KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.DISPLACEMENT_Y, KratosMultiphysics.REACTION_Y, mp) KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.DISPLACEMENT_Z, KratosMultiphysics.REACTION_Z, mp) mp.CreateNewMasterSlaveConstraint("LinearMasterSlaveConstraint", 1, mp.Nodes[1], KratosMultiphysics.DISPLACEMENT_X, mp.Nodes[2], KratosMultiphysics.DISPLACEMENT_X, 1.0, 0) # We impose the BC mp.Nodes[1].Fix(KratosMultiphysics.DISPLACEMENT_X) mp.Nodes[1].SetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X, 0.1) #define a minimal newton raphson solver linear_solver = KratosMultiphysics.SkylineLUFactorizationSolver() builder_and_solver = KratosMultiphysics.ResidualBasedBlockBuilderAndSolver(linear_solver) scheme = KratosMultiphysics.ResidualBasedIncrementalUpdateStaticScheme() convergence_criterion = KratosMultiphysics.ResidualCriteria(1e-10, 1e-12) convergence_criterion.SetEchoLevel(0) max_iters = 100 compute_reactions = False reform_step_dofs = True move_mesh_flag = False strategy = KratosMultiphysics.ResidualBasedNewtonRaphsonStrategy( mp, scheme, linear_solver, convergence_criterion, builder_and_solver, max_iters, compute_reactions, reform_step_dofs, move_mesh_flag) strategy.SetEchoLevel(0) strategy.Initialize() strategy.Check() strategy.Solve() print(mp.Nodes[2].GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X)) assert mp.Nodes[2].GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X) == mp.Nodes[1].GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X) ``` -------------------------------- ### KD-Tree Setup and Search in C++ Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/Spatial_Containers/Trees_And_Searches/kd_tree.md Demonstrates the process of preparing points, defining a KD-tree, and performing a parallel radius search. Ensure the necessary types and containers are defined before use. ```C++ // Defining the point type for the search using NodesContainerType = ModelPart::NodesContainerType; using ResultNodesContainerType = NodesContainerType::ContainerType; using VectorResultNodesContainerType = std::vector; using PointType = PointObject; using PointVector = std::vector; using DistanceType = std::vector; using VectorDistanceType = std::vector; // Defining the PointVector VectorResultNodesContainerType nodes_results; VectorDistanceType result_distance; PointVector points = SearchUtilities::PrepareSearch(rStructureNodes, rInputNodes, nodes_results, result_distance); // Definitions const int allocation_size = 1000; const int bucket_size = 1000; /// KDtree definitions using KDTree = Tree>>; // Creating the tree KDTree kd_tree(points.begin(), points.end(), bucket_size); // Performing search double radius = 1.0; SearchUtilities::ParallelSearch(rInputNodes, radius, kd_tree, nodes_results, result_distance, allocation_size); ``` -------------------------------- ### Build GiDPost Library (Linux - GCC) Source: https://github.com/kratosmultiphysics/kratos/blob/master/external_libraries/gidpost/README.md Builds the GiDPost library on Linux using GCC, with options to enable HDF5 support and Fortran examples. Assumes gfortran is installed for Fortran examples. ```shell $ cd .../gidpost $ mkdir build-linux $ cd build-linux $ cmake -DENABLE_HDF5=ON -DENABLE_FORTRAN_EXAMPLES=ON .. ;# gfortran is needed to ENABLE_FORTRAN_EXAMPLES (by default it's off) # more options are: -DENABLE_SHARED_LIBS=ON -DENABLE_EXAMPLES=ON -DENABLE_PARALLEL_EXAMPLE=ON # extra flag -DUSE_PKGCONFIG=false to use pkg-config and pkg_check_modules() instead of cmake's find_package() # by default, if environemt variable VCPKG_ROOT is defined, then USE_PKGCONFIG = true $ make $ cd examples $ ./testc -help ;# to view format options $ ./testc -f hdf5 ;# to write a gid post file in hdf5 format $ ./testf90 ;# fortran 90 example writing hdf5 gid post file ``` -------------------------------- ### SystemVector Construction and Initialization Examples Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Developers/Data_Structures/SystemVector.md Demonstrates various ways to construct and initialize a SystemVector, including default construction, construction with a specified size, setting all elements to a value, initializing from a Kratos Vector, copy construction, and construction using a graph. ```APIDOC ## Construction and Initialization ### Description Examples of creating and initializing `SystemVector` objects. ### Code Examples ```cpp #include "containers/system_vector.h" #include "includes/data_communicator.h" #include "includes/parallel_environment.h" // ... // Default constructor Kratos::SystemVector<> vec1; // Constructor with size (using serial communicator by default) Kratos::SystemVector<> vec2(10); // Creates a vector of size 10 // Initialize all elements to a value vec2.SetValue(5.0); // Constructor from a Kratos Vector Kratos::Vector kratos_vec(5, 1.23); // A standard Kratos Vector Kratos::SystemVector<> vec3(kratos_vec); // Copy constructor Kratos::SystemVector<> vec4(vec2); // Using a graph to define size // Assuming 'graph' is a SparseContiguousRowGraph or SparseGraph object Kratos::SystemVector<> vec_from_graph(graph); ``` ``` -------------------------------- ### Initialize Kratos ModelPart and Load Data Source: https://github.com/kratosmultiphysics/kratos/wiki/ModelPart-entities Import necessary Kratos modules, create a ModelPart, add solution step variables, and read data from a file. Ensure the input file exists. ```python import KratosMultiphysics import KratosMultiphysics.StructuralMechanicsApplication this_model = KratosMultiphysics.Model() structural_model_part = this_model.CreateModelPart("StructuralPart", 3) structural_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT) structural_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.REACTION) structural_model_part_io = KratosMultiphysics.ModelPartIO("KratosWorkshop2019_high_rise_building_CSM") structural_model_part_io.ReadModelPart(structural_model_part) ``` -------------------------------- ### Thrust Interoperation Example Setup Source: https://github.com/kratosmultiphysics/kratos/blob/master/external_libraries/vexcl/examples/CMakeLists.txt This block sets up the 'thrust-sort' executable for CUDA backend. It configures NVCC flags and links the executable against VexCL::CUDA. ```cmake if (VEXCL_BACKEND MATCHES "CUDA") cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS Auto) list(APPEND CUDA_NVCC_FLAGS ${CUDA_ARCH_FLAGS} -Wno-deprecated-gpu-targets -std=c++14 ) cuda_add_executable(thrust-sort thrust-sort.cpp thrust-sort.cu) target_link_libraries(thrust-sort VexCL::CUDA) ``` -------------------------------- ### Setup COMPSs Environment and Download Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Developers/Parallelism/PyCOMPSs.md Configures the Java and Python environment variables for COMPSs and downloads the specified version of the COMPSs framework from GitHub. ```bash # setup COMPSs version and path compss_folder_name="compss" compss_path="$HOME"/"${compss_folder_name}" # setup bash environment grep -v "JAVA_HOME" "$HOME"/.bashrc > "$HOME"/newbashrc echo "export JAVA_HOME=\"/usr/lib/jvm/java-8-openjdk-amd64/\"" >> "$HOME"/newbashrc echo "export PYTHONPATH=$PYTHONPATH:"/opt/COMPSs/Bindings/python/3/"" >> "$HOME"/newbashrc echo "source /etc/profile.d/compss.sh" >> "$HOME"/newbashrc mv "$HOME"/newbashrc "$HOME"/.bashrc export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/" # download COMPSs sudo rm -rf "${compss_path}" cd "$HOME" git clone https://github.com/bsc-wdc/compss.git -b 2.8 "${compss_folder_name}" cd "${compss_path}" ./submodules_get.sh ./submodules_patch.sh cd - ``` -------------------------------- ### Mesh Creation and Solver Setup Source: https://github.com/kratosmultiphysics/kratos/wiki/Kratos-For-Dummies:-Stationary-heat-transfer Initializes the mesh, sets the buffer size for the model part, adds degrees of freedom, and initializes the solver. This is a prerequisite for running the simulation. ```python mesh_name = 0.0 gid_io.InitializeMesh( mesh_name ) gid_io.WriteMesh((model_part).GetMesh()) gid_io.FinalizeMesh() #the buffer size should be set up here after the mesh is read for the first time (this is important for transcient problems, in this static problem =1 is enough) model_part.SetBufferSize(1) # we add the DoFs pure_diffusion_solver.AddDofs() # Initialize the solver pure_diffusion_solver.Initialize() ``` -------------------------------- ### Print Message Once Example in C++ Source: https://github.com/kratosmultiphysics/kratos/wiki/How-to-use-Logger Ensures a message is printed only the first time it is encountered within a loop or repeated calls. Useful for one-time setup notifications. ```cpp for(std::size i = 0; i < 4; i++) { KRATOS_INFO_ONCE("Example") << "Iter: " << i << std::endl; } ``` -------------------------------- ### Test Naming Convention Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Developers/CICD/Unitary_Tests.md Test functions must start with 'test_' to be recognized by the Kratos unittest runner. This example shows the naming convention for test methods. ```python # In order to be recognized automatically, all tests need to have the name "test_" at the beginning of the definition (`test_MembranePatch` and `test_BendingPatch` in this example). ``` -------------------------------- ### Create a basic test suite in C++ Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Developers/CICD/Unitary_Tests.md This is the simplest example of how to create a test suite. It defines a test case and assigns it to a suite. ```C++ #include "testing/testing.h" namespace Kratos { namespace Testing { KRATOS_TEST_CASE_IN_SUITE(TestSuite, KratosCoreFastSuite) { Tester::CreateTestSuite("MyTestSuite") { } } } } ``` -------------------------------- ### Coupling Sequence Setup Example Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Applications/CoSimulation_Application/General/JSON_Structure.md Defines the coupling sequence where the structure solver manages input data from the fluid solver. It specifies data transfer operators and operations. ```json "coupling_sequence": [ { "name": "fluid_solver", "input_data_list" : [], "output_data_list" : [] }, { "name": "structure_solver", "input_data_list": [ { "data" : "structure_solver_load", "from_solver" : "fluid_solver", "from_solver_data" : "fluid_solver_load", "data_transfer_operator" : "Data_Transfer_Operator_A", "data_transfer_operator_options" : ["swap_sign", "use_transpose"], "before_data_transfer_operations" : ["Coupling_Operation_A"], "after_data_transfer_operations" : ["Coupling_Operation_B"] } ], "output_data_list": [ { "data" : "structure_solver_displacement", "to_solver" : "fluid_solver", "to_solver_data" : "fluid_solver_displacement", "data_transfer_operator" : "Data_Transfer_Operator_A" } ] } ], ``` -------------------------------- ### Run Kratos Configuration Script Source: https://github.com/kratosmultiphysics/kratos/wiki/Windows-Install Execute the 'configure' script in a command prompt to set up the Kratos build environment. Verify the output for correct paths and libraries, looking for 'Configuration Done'. ```bash configure ``` -------------------------------- ### Sub-Table Y Example (3-bit lookup) Source: https://github.com/kratosmultiphysics/kratos/blob/master/external_libraries/zlib/doc/algorithm.txt This is a sub-table (Table Y) used when the initial 3-bit lookup indicates a longer code. It uses a 3-bit lookup for symbols starting with '111'. ```text 000: F,2 001: F,2 010: G,2 011: G,2 100: H,2 101: H,2 110: I,3 111: J,3 ``` -------------------------------- ### Simplified Process Implementation Example Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Users/Crash_Course/5_Simulation_Loop.md A simplified Python implementation of a process showing how to get the current time and set a variable's value based on an interval and a lookup table. ```python def ExecuteInitializeSolutionStep(self): current_time = self.model_part.ProcessInfo[KratosMultiphysics.TIME] if self.interval.IsInInterval(current_time): self.value = self.table.GetValue(current_time) self.variable_utils.SetVariable(self.variable, self.value, self.mesh.Nodes) ``` -------------------------------- ### Example Custom Entries Configuration Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/Documentation_Guide/How_Tos/Modify_Navigation_Bars/Custom_entries.md Demonstrates the structure for defining custom navigation bar entries, including string, external, and Kratos example types. ```json "custom_entries": [ "General", "How_to_get_Kratos", "Getting_started", { "type": "external", "title": "Google", "url": "https://www.google.com" }, { "type": "kratos_example", "raw_url": "https://raw.githubusercontent.com/KratosMultiphysics/Examples/master/shape_optimization/use_cases/02_Strain_Energy_Minimization_3D_Shell/README.md", "source_url": "https://github.com/KratosMultiphysics/Examples/tree/master/shape_optimization/use_cases/02_Strain_Energy_Minimization_3D_Shell", "file_name": "Strain_Energy_Minimization_3D_Shell.md" } ] ``` -------------------------------- ### Setup Kratos Testing Engine Source: https://github.com/kratosmultiphysics/kratos/blob/master/kratos/CMakeLists.txt Configures the Kratos testing engine if KRATOS_BUILD_TESTING is enabled. This includes finding GoogleTest, globbing test sources, creating libraries and executables, and installing them. ```cmake if(${KRATOS_BUILD_TESTING} MATCHES ON) include(GoogleTest) file(GLOB_RECURSE KRATOS_TEST_UTILITIES_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_utilities/*.cpp ) file(GLOB_RECURSE KRATOS_TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/cpp_tests/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/testing/*.cpp ) add_library(KratosCoreTestUtilities SHARED ${KRATOS_TEST_UTILITIES_SOURCES}) add_executable(KratosCoreTest ${KRATOS_TEST_SOURCES} ${KRATOS_FUTURE_TEST_SOURCES} ${KRATOS_LEGACY_TEST_SOURCES}) target_link_libraries(KratosCoreTestUtilities KratosCore GTest::gtest GTest::gmock) set_target_properties(KratosCoreTestUtilities PROPERTIES COMPILE_DEFINITIONS "KRATOS_TEST_UTILS=IMPORT,API") target_link_libraries(KratosCoreTest PUBLIC KratosCoreTestUtilities GTest::gmock_main) set_target_properties(KratosCoreTest PROPERTIES COMPILE_DEFINITIONS "KRATOS_TEST_CORE=IMPORT,API") install(TARGETS KratosCoreTestUtilities DESTINATION libs) install(TARGETS KratosCoreTest DESTINATION test) gtest_discover_tests(KratosCoreTest DISCOVERY_MODE PRE_TEST) endif(${KRATOS_BUILD_TESTING} MATCHES ON) ``` -------------------------------- ### Sub-Table X Example (2-bit lookup) Source: https://github.com/kratosmultiphysics/kratos/blob/master/external_libraries/zlib/doc/algorithm.txt This is a sub-table (Table X) used when the initial 3-bit lookup indicates a longer code. It uses a 2-bit lookup for symbols starting with '110'. ```text 00: C,1 01: C,1 10: D,2 11: E,2 ``` -------------------------------- ### Import Kratos, Create ModelPart, and Read Input Source: https://github.com/kratosmultiphysics/kratos/wiki/Python-Script-Tutorial:-Writing-Output-File Initializes Kratos, creates a ModelPart, adds necessary variables, and reads data from an input file. This sets up the ModelPart for further processing or output. ```Python from KratosMultiphysics import * import KratosMultiphysics.FluidDynamicsApplication this_model = Model() fluid_model_part = this_model.CreateModelPart("FluidPart") fluid_model_part.AddNodalSolutionStepVariable(VELOCITY) fluid_model_part.AddNodalSolutionStepVariable(PRESSURE) fluid_model_part_io = ModelPartIO("path/to/file/example") fluid_model_part_io.ReadModelPart(fluid_model_part) ``` -------------------------------- ### InitializeSolutionStep Source: https://github.com/kratosmultiphysics/kratos/wiki/pydoc/Classes/KratosMultiphysics.BuilderAndSolver Initializes the solution step. ```APIDOC ## InitializeSolutionStep ### Description Initializes the solution step. ### Parameters - **arg0** (Kratos.ModelPart) - The model part containing the problem. - **arg1** (Kratos.CompressedMatrix) - The system matrix. - **arg2** (Kratos.Vector) - The solution vector. - **arg3** (Kratos.Vector) - The right-hand side vector. ``` -------------------------------- ### SystemVector Construction and Initialization Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Developers/Data_Structures/SystemVector.md Demonstrates various ways to construct and initialize a SystemVector, including default construction, construction with a specified size, initialization with a value, and construction from existing Kratos Vectors or graphs. It also shows copy construction. ```cpp #include "containers/system_vector.h" #include "includes/data_communicator.h" #include "includes/parallel_environment.h" // ... // Default constructor Kratos::SystemVector<> vec1; // Constructor with size (using serial communicator by default) Kratos::SystemVector<> vec2(10); // Creates a vector of size 10 // Initialize all elements to a value vec2.SetValue(5.0); // Constructor from a Kratos Vector Kratos::Vector kratos_vec(5, 1.23); // A standard Kratos Vector Kratos::SystemVector<> vec3(kratos_vec); // Copy constructor Kratos::SystemVector<> vec4(vec2); // Using a graph to define size // Assuming 'graph' is a SparseContiguousRowGraph or SparseGraph object Kratos::SystemVector<> vec_from_graph(graph); ``` -------------------------------- ### Install Kratos MPI Test Files Source: https://github.com/kratosmultiphysics/kratos/blob/master/kratos/mpi/CMakeLists.txt Conditionally installs Kratos MPI test directories and files if testing files installation is enabled. Excludes source files from the installation. ```cmake if(${INSTALL_TESTING_FILES} MATCHES ON ) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests DESTINATION kratos/mpi PATTERN "*.git" EXCLUDE PATTERN "*.c" EXCLUDE PATTERN "*.h" EXCLUDE PATTERN "*.cpp" EXCLUDE PATTERN "*.hpp" EXCLUDE ) if(${KRATOS_USE_FUTURE} MATCHES ON) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/future/tests DESTINATION kratos/future/mpi PATTERN "*.git" EXCLUDE PATTERN "*.c" EXCLUDE PATTERN "*.h" EXCLUDE PATTERN "*.cpp" EXCLUDE PATTERN "*.hpp" EXCLUDE ) endif(${KRATOS_USE_FUTURE} MATCHES ON) endif(${INSTALL_TESTING_FILES} MATCHES ON ) ``` -------------------------------- ### Install OpenMP headers Source: https://github.com/kratosmultiphysics/kratos/wiki/How-to-run-multiple-cases-in-parallel-using-PyCOMPSs If OpenMP headers are not found after installing libgmp3-dev, install them using the 'libgmp-dev' package. ```sh libgmp-dev ``` -------------------------------- ### Configure Kratos Build Environment Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Users/How_To_Get_Kratos/Compiling-Kratos-with-MPI-support.md Sets up the Kratos build environment by loading necessary modules (Boost, Python, Intel MKL, OpenMPI, GCC) and defining the KRATOS_APPLICATIONS path. ```bash #!/bin/bash # Define application selection function add_app () { export KRATOS_APPLICATIONS="${KRATOS_APPLICATIONS}"$1; } # Load required modules module purge module load boost python git intel/oneapi2021/mkl/2021.1.1 openmpi gcc/10.2.0 ``` -------------------------------- ### BeginAssemble() Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Developers/Data_Structures/DistributedSystemVector.md Prepares the vector for assembly by initializing the exporter and zeroing non-local data contributions. ```APIDOC ## BeginAssemble() ### Description Prepares the vector for assembly. Key actions include: * Initializing the `DistributedVectorExporter` (`mpexporter`) based on the current contents of `mNonLocalData`. The structure of `mNonLocalData` is considered frozen after this call. * Setting all values in `mNonLocalData` to zero, ready to accumulate incoming contributions. ### Method `void BeginAssemble()` ``` -------------------------------- ### Install Automatic Differentiation Directory Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/FluidDynamicsApplication/CMakeLists.txt Installs the 'automatic_differentiation' directory from the application's source into the KratosMultiphysics installation path. ```cmake kratos_python_install_directory(${INSTALL_PYTHON_USING_LINKS} ${CMAKE_CURRENT_SOURCE_DIR}/automatic_differentiation KratosMultiphysics/${CURRENT_DIR_NAME} ) ``` -------------------------------- ### Install massif-visualiser on Debian-based systems Source: https://github.com/kratosmultiphysics/kratos/wiki/Checking-memory-usage-with-Valgrind Install the massif-visualiser tool using apt-get to graphically display Valgrind's Massif output files. ```bash sudo apt-get install massif-visualiser ``` -------------------------------- ### Set Kratos installation prefix Source: https://github.com/kratosmultiphysics/kratos/blob/master/INSTALL.md Defines the installation directory for Kratos. If not set, installation defaults to 'bin/[build_type]'. ```bash -DCMAKE_INSTALL_PREFIX=String ``` -------------------------------- ### Install Pfem Solid Mechanics Application Python Files Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/PfemSolidMechanicsApplication/CMakeLists.txt Installs the main Python application file and the entire python_scripts directory to the Kratos installation path. Uses custom CMake macros for installation. ```cmake # Add to the KratosMultiphisics Python module kratos_python_install(${INSTALL_PYTHON_USING_LINKS} ${CMAKE_CURRENT_SOURCE_DIR}/PfemSolidMechanicsApplication.py KratosMultiphysics/PfemSolidMechanicsApplication/__init__.py ) # Install python files get_filename_component (CURRENT_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) kratos_python_install_directory(${INSTALL_PYTHON_USING_LINKS} ${CMAKE_CURRENT_SOURCE_DIR}/python_scripts KratosMultiphysics/${CURRENT_DIR_NAME} ) ``` -------------------------------- ### Step-based Output Control Example Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Applications/MPM_Application/Output_Processes/mpm_gid_output_process.md Configure the output to be generated at regular intervals based on the number of time steps. This example sets the output to occur every time step. ```json "output_control_type" : "step", "output_interval" : 1, ``` -------------------------------- ### Example Output for GetSolutionStepValue Source: https://github.com/kratosmultiphysics/kratos/blob/master/docs/pages/Kratos/For_Users/Crash_Course/4_Data.md Demonstrates the expected output when retrieving historical pressure values from different time steps. ```Output > 2.0 > 2.0 > 4.0 ``` -------------------------------- ### Install Testing Files Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/DemStructuresCouplingApplication/CMakeLists.txt Installs testing-related files for the DemStructuresCouplingApplication, excluding source files, if testing files installation is enabled. ```cmake if(${INSTALL_TESTING_FILES} MATCHES ON ) get_filename_component (CURRENT_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests DESTINATION applications/${CURRENT_DIR_NAME} PATTERN "*.git" EXCLUDE PATTERN "*.c" EXCLUDE PATTERN "*.h" EXCLUDE PATTERN "*.cpp" EXCLUDE PATTERN "*.hpp" EXCLUDE ) endif(${INSTALL_TESTING_FILES} MATCHES ON) ``` -------------------------------- ### Install PyCOMPSs Dependencies Source: https://github.com/kratosmultiphysics/kratos/wiki/How-to-run-multiple-cases-in-parallel-using-PyCOMPSs Installs necessary system dependencies for PyCOMPSs using apt-get. Ensure these are present before proceeding with installation. ```bash sudo apt-get install -y openjdk-8-jdk graphviz xdg-utils libtool automake build-essential python python-dev libpython2.7 python3 python3-dev libboost-serialization-dev libboost-iostreams-dev libxml2 libxml2-dev csh gfortran libgmp3-dev flex bison texinfo python3-pip libpapi-dev ``` -------------------------------- ### Initialize Kratos Solver and Model Part (.py) Source: https://github.com/kratosmultiphysics/kratos/wiki/Kratos-For-Dummies:-Stationary-heat-transfer Initializes Kratos, imports necessary modules, sets up the domain size, creates a ModelPart, and loads solver settings from a JSON file. This script prepares the environment for solving the problem. ```python from __future__ import print_function, absolute_import, division #makes KratosMultiphysics backward compatible with python 2.6 and 2.7 def Wait(): input("Press Something") #including kratos path import sys from KratosMultiphysics import * #import KratosMultiphysics #we import the KRATOS import KratosMultiphysics.MyLaplacianApplication as Poisson #and now our application. note that we can import as many as we need to solve our specific problem #setting the domain size for the problem to be solved domain_size = 2 # 2D problem #defining a model part model = Model() model_part = model.CreateModelPart("Main"); #we create a model part import KratosMultiphysics.MyLaplacianApplication.pure_diffusion_solver as pure_diffusion_solver #we import the python file that includes the commands that we need parameter_file = open("ProjectParameters.json",'r') # we read the ProjectParameters.json file custom_settings = Parameters(parameter_file.read()) pure_diffusion_solver = pure_diffusion_solver.CreateSolver(model, custom_settings) pure_diffusion_solver.AddVariables() #from the static_poisson_solver.py we call the function Addvariables so that the model part we have just created has the needed variables # (note that our model part does not have nodes or elements yet) ``` -------------------------------- ### Install ZLIB Pkg-config File Source: https://github.com/kratosmultiphysics/kratos/blob/master/external_libraries/zlib/CMakeLists.txt Installs the zlib pkg-config file to the pkgconfig directory. This installation is conditional on SKIP_INSTALL_FILES and SKIP_INSTALL_ALL not being set. ```cmake if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") endif() ``` -------------------------------- ### Configure.sh Example for MinGW Source: https://github.com/kratosmultiphysics/kratos/wiki/Windows-Install-(MinGW) The main configuration script for Kratos compilation on Windows using MinGW. It sets up environment variables, defines applications to compile, and invokes CMake with specific MinGW flags. ```Bash #!/bin/bash # Please do not modify this script # You can use your interpreter of choice (bash, sh, zsh, ...) # For any question please contact with us in: # - https://github.com/KratosMultiphysics/Kratos # Optional parameters: # You can find a list will all the compiation options in INSTALL.md or here: # - https://github.com/KratosMultiphysics/Kratos/wiki/Compilation-options # Function to add apps add_app () { export KRATOS_APPLICATIONS="${KRATOS_APPLICATIONS}$1;" } # Set compiler export CC=${CC:-gcc} export CXX=${CXX:-g++} # Set variables export KRATOS_SOURCE="${KRATOS_SOURCE:-"$( cd "$(dirname "$0")" ; pwd -P )"/..}" export KRATOS_BUILD="${KRATOS_SOURCE}/build" export KRATOS_APP_DIR="${KRATOS_SOURCE}/applications" # export KRATOS_INSTALL_PYTHON_USING_LINKS=ON export KRATOS_SHARED_MEMORY_PARALLELIZATION=${KRATOS_SHARED_MEMORY_PARALLELIZATION:-"OpenMP"} # Set basic configuration export KRATOS_BUILD_TYPE=${KRATOS_BUILD_TYPE:-"Release"} export PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE:-"C:/Windows/py.exe"} # Set applications to compile export KRATOS_APPLICATIONS= add_app ${KRATOS_APP_DIR}/LinearSolversApplication add_app ${KRATOS_APP_DIR}/StructuralMechanicsApplication add_app ${KRATOS_APP_DIR}/FluidDynamicsApplication # Configure cmake .. \ -G "MinGW Makefiles" \ -DWIN32=TRUE \ -DCMAKE_INSTALL_PREFIX="${KRATOS_SOURCE}/bin/${KRATOS_BUILD_TYPE}" \ -DCMAKE_BUILD_TYPE="${KRATOS_BUILD_TYPE}" \ -DCMAKE_EXE_LINKER_FLAGS="-s" \ -DCMAKE_SHARED_LINKER_FLAGS="-s" \ -H"${KRATOS_SOURCE}" \ -B"${KRATOS_BUILD}/${KRATOS_BUILD_TYPE}" \ -DUSE_MPI=OFF \ -DKRATOS_SHARED_MEMORY_PARALLELIZATION="${KRATOS_SHARED_MEMORY_PARALLELIZATION}" \ -DKRATOS_GENERATE_PYTHON_STUBS=ON \ -DUSE_EIGEN_MKL=OFF # Buid cmake --build "${KRATOS_BUILD}/${KRATOS_BUILD_TYPE}" --target install -- -j$(nproc) ``` -------------------------------- ### Install VexCL Library and Headers Source: https://github.com/kratosmultiphysics/kratos/blob/master/external_libraries/vexcl/CMakeLists.txt Installs the VexCL library and its headers to the specified destinations. This ensures that VexCL can be used by other projects after installation. ```cmake install(DIRECTORY vexcl DESTINATION include) install(TARGETS Common EXPORT VexCLTargets) ``` -------------------------------- ### Windows Command Prompt Setup for UCRT64 Source: https://github.com/kratosmultiphysics/kratos/blob/master/INSTALL.md Set up environment variables and perform initial cleanup for building Kratos with UCRT64 on Windows. This script prepares the build environment before executing the configuration script. ```cmd cls @REM Set variables if not defined KRATOS_SOURCE set KRATOS_SOURCE=%~dp0.. if not defined KRATOS_BUILD set KRATOS_BUILD=%KRATOS_SOURCE%/build @REM Set basic configuration if not defined KRATOS_BUILD_TYPE set KRATOS_BUILD_TYPE=Release @REM Decomment the following in case of considering MKL @REM if not defined MKLROOT set MKLROOT=C:\PROGRA~2\Intel\oneAPI\mkl\latest\ @REM rem setting environment variables for using intel MKL @REM call "%MKLROOT%\env\vars.bat" intel64 lp64 :: you may want to decomment this the first time you compile @REM Clean del /F /Q "%KRATOS_BUILD%\%KRATOS_BUILD_TYPE%\cmake_install.cmake" del /F /Q "%KRATOS_BUILD%\%KRATOS_BUILD_TYPE%\CMakeCache.txt" del /F /Q "%KRATOS_BUILD%\%KRATOS_BUILD_TYPE%\CMakeFiles" sh %KRATOS_BUILD%\configure_MINGW_UCRT64.sh ``` -------------------------------- ### Install METIS using Spack Source: https://github.com/kratosmultiphysics/kratos/blob/master/applications/MetisApplication/README.md Installs the parmetis package using Spack. Spack handles the compilation and installation of METIS and its dependencies. ```bash spack install parmetis ``` -------------------------------- ### PythonSolver Settings Example Source: https://github.com/kratosmultiphysics/kratos/wiki/Common-Python-Interface-of-Applications-for-Users Example of settings for the PythonSolver, including echo level and model import configuration. Ensure 'input_type' is set to 'mdpa' or 'rest'. ```json { "echo_level" : 0, "model_import_settings" : { "input_type" : "mdpa" # or "rest" "input_filename" : "input_file_name" } } ```