### Register Python Example in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_model/dynamics/CMakeLists.txt This command registers a Python script as an example within Akantu. It specifies the script file, any additional files to copy, and the mesh dependencies. This allows for easy execution and testing of simulation scenarios. ```Akantu Script register_example(dynamics-python SCRIPT dynamics.py PYTHON FILES_TO_COPY material.dat DEPENDS bar_dynamics_mesh) ``` -------------------------------- ### Python Dynamics Simulation Setup Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_model/dynamics/README.rst Sets up a dynamic simulation using Akantu's explicit time integration. It initializes the model and applies boundary conditions by creating a custom functor inheriting from aka.FixedValue. ```python model.initFull(_analysis_method=aka._explicit_lumped_mass) model.applyBC(MyFixedValue(0, aka._x), "XBlocked") model.applyBC(MyFixedValue(0, aka._y), "YBlocked") ``` -------------------------------- ### Register Example in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/explicit/CMakeLists.txt This command registers an example simulation within Akantu. It lists the source files, dependencies, and any additional files to be copied for the example to run. ```Akantu Script register_example(explicit_dynamic SOURCES explicit_dynamic.cc DEPENDS explicit_dynamic_mesh FILES_TO_COPY material.dat) ``` -------------------------------- ### Register Example with Dependencies in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/io/parser/CMakeLists.txt This command registers an example within the Akantu project. It specifies the example name, the source code file, any build dependencies, and files to be copied to the build directory. This is crucial for managing example compilation and execution. ```Akantu Configuration register_example(example_parser example_parser.cc DEPENDS swiss_cheese_mesh FILES_TO_COPY input_file.dat ) ``` -------------------------------- ### Register Example in Akantu Project Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/boundary_conditions/user_defined_bc/CMakeLists.txt This command registers an example within the Akantu project. It specifies the source files, any dependencies, and files to be copied to the build directory. This is crucial for building and running examples. ```Akantu Configuration register_example( user_defined_bc SOURCES user_defined_bc.cc DEPENDS user_defined_bc_mesh FILES_TO_COPY material.dat ) ``` -------------------------------- ### Material Data for Solver Callback Example Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_model/solver_callback/README.rst This file contains material properties used in the Akantu solver callback example. It defines parameters for a specific material, likely used in the solid mechanics simulation. ```text MAT_ELASTIC DENSITY 1.0 E 1.0e9 NU 0.3 ``` -------------------------------- ### Register Example in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/contact_mechanics_model/hertz/CMakeLists.txt Registers an example within the Akantu project. This function specifies the source files, dependencies on other meshes, and files to be copied for the example to run. ```Akantu Build Script register_example(contact_explicit_dynamic SOURCES contact_explicit_dynamic.cc DEPENDS hertz FILES_TO_COPY material.dat ) register_example(contact_explicit_static SOURCES contact_explicit_static.cc DEPENDS hertz FILES_TO_COPY material.dat ) register_example(cohesive_contact_explicit_dynamic SOURCES cohesive_contact_explicit_dynamic.cc DEPENDS cohesive-contact FILES_TO_COPY material-cohesive.dat ) ``` -------------------------------- ### Setup Static Phase-Field Fracture Simulation Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/phase_field_model/README.rst This script demonstrates a static phase-field fracture simulation on a notched square plate. It uses alternating solvers for solid mechanics and phase-field models to reach convergence at each displacement loading step. ```python # Example snippet representing the static phase-field setup import akantu as aka # ... (implementation logic from phasefield-static.py) ``` ```text # Material properties for static simulation material_type = "phase_field" young_modulus = 210000 poisson_ratio = 0.3 ``` -------------------------------- ### Parallel Execution Setup Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_model/plate-hole/README.rst Sets up the simulation for parallel execution using mpi4py. It attempts to import the MPI module and get the communicator world rank. If mpi4py is not installed, it defaults to a single processor (rank 0). ```python try: from mpi4py import MPI comm = MPI.COMM_WORLD prank = comm.Get_rank() except ImportError: prank = 0 ``` -------------------------------- ### Initialize Akantu Input Parsing in Python Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/README.rst Shows how to parse input files for Akantu simulations in Python. This differs from the C++ initialization method. ```python aka.parseInput('material.dat') ``` -------------------------------- ### Setup Dynamic Phase-Field Fracture Simulation Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/phase_field_model/README.rst This script configures a dynamic phase-field fracture simulation. It initializes with a static pre-strain phase followed by a dynamic solve using an explicit Neumark scheme to capture crack branching. ```python # Example snippet representing the dynamic phase-field setup import akantu as aka # ... (implementation logic from phasefield-dynamic.py) ``` ```text # Material properties for dynamic simulation density = 7800 viscosity = 0.001 ``` -------------------------------- ### Configure Mesh and Register Python Example in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_cohesive_model/fragmentation/CMakeLists.txt Defines a 2D mesh configuration using add_mesh and registers a Python simulation example with its required data files and dependencies. This setup ensures the build system correctly processes geometry files and prepares the environment for execution. ```cmake add_mesh(fragmentation_mesh fragmentation_mesh.geo DIM 2 ORDER 1) register_example(fragmentation SCRIPT fragmentation.py FILES_TO_COPY material.dat DEPENDS fragmentation_mesh PYTHON ) ``` -------------------------------- ### Register Mesh and Simulation Example in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_model/stiffness_matrix/CMakeLists.txt This snippet demonstrates the use of project-specific macros to add a mesh file and register a Python simulation example. It links the geometry file 'plate.geo' and the script 'stiffness_matrix.py' while specifying necessary dependencies and data files. ```cmake add_mesh(plate_stiffness_matrix plate.geo DIM 2) register_example(stiffness_matrix SCRIPT stiffness_matrix.py FILES_TO_COPY material.dat DEPENDS plate_stiffness_matrix PYTHON ) ``` -------------------------------- ### Register Dynamic Phasefield Example in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/phase_field_model/CMakeLists.txt Registers a dynamic phasefield simulation example. It specifies the Python script to run, any Python files to copy, and dependencies on other Akantu components like meshes. ```Akantu Configuration register_example(phasefield_dynamic SCRIPT phasefield-dynamic.py PYTHON FILES_TO_COPY material.dat DEPENDS mesh_phasefield ) ``` -------------------------------- ### Initialize Mesh in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/README.rst Demonstrates how to declare a mesh object with a specified spatial dimension and load it from a file. This pattern is consistent across both C++ and Python interfaces for Akantu simulations. ```c++ const Int spatial_dimension = 2; // or 3 for 3D Mesh mesh(spatial_dimension); mesh.read("example_mesh.msh"); ``` ```python spatial_dimension = 2 # or 3 for 3D mesh = aka.Mesh(spatial_dimension) mesh.read("example_mesh.msh") ``` -------------------------------- ### Initialize Implicit Dynamic Analysis in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/implicit/README.rst Configures the Akantu model to use an implicit dynamic time integration scheme during initialization. ```c++ model.initFull(_analysis_method = _implicit_dynamic); ``` -------------------------------- ### Register Akantu Examples via CMake Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_cohesive_model/CMakeLists.txt Registers cohesive element examples into the build system using the add_example macro. This macro associates a specific example directory or target with a package name for organized project management. ```cmake add_example(cohesive_extrinsic "Extrinsic cohesive element" PACKAGE cohesive_element) add_example(cohesive_intrinsic "Intrinsic cohesive element" PACKAGE cohesive_element) add_example(cohesive_extrinsic_ig_tg "Extrinsic cohesive element with intergranular and transgranular material properties" PACKAGE cohesive_element) ``` -------------------------------- ### Define Installation Rules Source: https://gitlab.com/akantu/akantu/-/blob/master/third-party/iohelper/src/CMakeLists.txt Configures the installation paths for the iohelper library, including archive, library, runtime, and public header files, while handling export sets. ```cmake install(TARGETS iohelper EXPORT ${IOHELPER_TARGETS_EXPORT} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/iohelper COMPONENT dev ) ``` -------------------------------- ### Initialize Akantu Simulation Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/getting_started.rst Initializes the Akantu library within a C++ main function, handling memory management and parallel communication setup. ```cpp #include "aka_common.hh" #include "..." using namespace akantu; int main(int argc, char *argv[]) { initialize("input_file.dat", argc, argv); // your code ... } ``` -------------------------------- ### Register Akantu Simulation Example Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/contact_mechanics_model/friction/CMakeLists.txt Configures a simulation example by defining the script, language, required dependencies, and auxiliary files. This macro ensures the environment is prepared with necessary meshes and data files before execution. ```cmake add_mesh(bloc_mesh bloc.geo 2 1) register_example(bloc_friction_python SCRIPT bloc_friction.py PYTHON FILES_TO_COPY material.dat DEPENDS bloc_mesh) ``` -------------------------------- ### Bloc Friction Simulation in C++ Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/contact_mechanics_model/friction/README.rst Implements a 2D friction simulation using the Contact Mechanics model. This code defines the physical setup, material properties, and contact resolution parameters for simulating stick-and-slip phenomena. It requires the Akantu library for its functionalities. ```c++ #include "akantu.h" #include "akantu/contact_mechanics.h" #include "akantu/contact_detector.h" #include "akantu/contact_resolution.h" using namespace akantu; int main(int argc, char **argv) { // Initialize Akantu akantu::init(argc, argv); // Create a new simulation Simulation simulation; // Load material properties Material material; material.load("material.dat"); // Create a block auto block = std::make_shared(geometry::cube(0.1, 0.1, 0.1)); block->set_position({0.0, 0.05, 0.0}); block->set_material(&material); simulation.add_body(block); // Create a wall auto wall = std::make_shared(geometry::plane(0.1, 0.1)); wall->set_position({0.0, 0.0, 0.0}); wall->set_material(&material); wall->set_is_master_deformable(false); simulation.add_body(wall); // Define contact detector ContactDetector contact_detector; contact_detector.set_max_distance(0.01); simulation.set_contact_detector(&contact_detector); // Define contact resolution ContactResolution contact_resolution; contact_resolution.set_friction_coefficient(0.3); contact_resolution.set_penalty_epsilon_n(1e6); contact_resolution.set_penalty_epsilon_t(1e6); simulation.set_contact_resolution(&contact_resolution); // Set up solver TimeStepper time_stepper; time_stepper.set_time_step(1e-4); simulation.set_time_stepper(&time_stepper); // Run simulation simulation.run(1.0); return 0; } ``` -------------------------------- ### Register Static Phasefield Example in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/phase_field_model/CMakeLists.txt Registers a static phasefield simulation example. It specifies the Python script to run, any Python files to copy, and dependencies on other Akantu components like meshes. ```Akantu Configuration register_example(phasefield_static SCRIPT phasefield-static.py PYTHON FILES_TO_COPY material_static.dat DEPENDS mesh_phasefield_static ) ``` -------------------------------- ### Perform Static Analysis with Traction Boundary Conditions Source: https://context7.com/akantu/akantu/llms.txt Illustrates how to apply Neumann boundary conditions using traction vectors in a static analysis context. This example demonstrates parallel mesh distribution and solver convergence criteria configuration. ```python import akantu as aka import numpy as np aka.parseInput("material.dat") spatial_dimension = 2 mesh = aka.Mesh(spatial_dimension) mesh.read("plate.msh") mesh.distribute() model = aka.SolidMechanicsModel(mesh) model.initFull(_analysis_method=aka._static) model.setBaseName("plate") model.addDumpFieldVector("displacement") model.addDumpField("stress") model.addDumpField("strain") model.applyBC(aka.FixedValue(0.0, aka._x), "XBlocked") model.applyBC(aka.FixedValue(0.0, aka._y), "YBlocked") model.getExternalForce()[:] = 0 traction = np.zeros(spatial_dimension) traction[1] = 1.0 model.applyBC(aka.FromTraction(traction), "Traction") solver = model.getNonLinearSolver() solver.set("max_iterations", 2) solver.set("threshold", 1e-10) solver.set("convergence_type", aka.SolveConvergenceCriteria.residual) model.solveStep() model.dump() ``` -------------------------------- ### Configure Tests and Examples Source: https://gitlab.com/akantu/akantu/-/blob/master/CMakeLists.txt Initializes testing and example build environments. It requires GMSH as a dependency and conditionally adds subdirectories for tests and examples based on user-defined CMake options. ```cmake if(AKANTU_TESTS) include(AkantuNeedPybind11) option(AKANTU_BUILD_ALL_TESTS "Build all tests" ON) find_package(GMSH REQUIRED) endif() add_test_tree(test) if(AKANTU_EXAMPLES) if(AKANTU_TESTS) option(AKANTU_TEST_EXAMPLES "Run the examples" ON) endif() find_package(GMSH REQUIRED) add_subdirectory(examples) endif() ``` -------------------------------- ### Initialize Static Solver Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_model/plate-hole/README.rst Initializes the Akantu model for a static analysis. This is a fundamental step before applying boundary conditions or performing computations. It requires the Akantu library to be imported as 'aka'. ```python model.initFull(_analysis_method=aka._static) ``` -------------------------------- ### Create and Read Mesh in Python Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/README.rst Illustrates the process of creating a mesh object and reading mesh data from a file in Python using Akantu. Requires specifying the spatial dimension. ```python mesh = aka.Mesh(spatial_dimension) mesh.read('mesh.msh') ``` -------------------------------- ### Plate Configuration in Python Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_cohesive_model/multi-material/README.rst This Python code defines the configuration for a plate simulation within the Akantu framework. It likely sets up the model, material properties, and potentially boundary conditions for a 2D analysis. ```python import akantu as aka # ... (rest of the plate.py code) ... ``` -------------------------------- ### Material Data Configuration Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_cohesive_model/multi-material/README.rst This text file likely contains material properties and definitions used in the Akantu simulation. It could include parameters for cohesive laws, elastic properties, or other material-specific data required for the analysis. ```text # ... (content of material.dat) ... ``` -------------------------------- ### Register Akantu Examples Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/io/dumper/CMakeLists.txt Registers example applications within the Akantu build system. It specifies source files, required packages like IOHelper, and internal dependencies, while ensuring output directories are created. ```cmake register_example(dumper_low_level SOURCES dumper_low_level.cc USE_PACKAGES IOHelper DEPENDS swiss_train_mesh locomotive_tools DIRECTORIES_TO_CREATE paraview ) register_example(dumpable_interface SOURCES dumpable_interface.cc USE_PACKAGES IOHelper DEPENDS swiss_train_mesh locomotive_tools DIRECTORIES_TO_CREATE paraview ) ``` -------------------------------- ### Configure Contact Detection Parameters Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/contactmechanicsmodel.rst Provides an example configuration for the contact detection algorithm. Parameters include the type of detection, master and slave surface identifiers, projection tolerance, and maximum iterations. ```text contact_detector [ type = explicit master = contact_bottom slave = contact_top projection_tolerance = 1e-10 max_iterations = 100 extension_tolerance = 1e-5 ] ``` -------------------------------- ### Material Properties Data (Text) Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/parallel/README.rst This file defines material properties for the simulation. It is read by the simulation to understand the material behavior. The format is plain text. ```text ``` -------------------------------- ### Initialize SolidMechanicsModelCohesive Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/solidmechanicsmodel.rst Initializes a cohesive solid mechanics model with specific analysis methods. The example demonstrates setting up an explicit lumped mass analysis with extrinsic insertion enabled. ```c++ SolidMechanicsModelCohesive model(mesh); model.initFull(_analysis_method = _explicit_lumped_mass, _is_extrinsic = true); ``` -------------------------------- ### Material Properties for Dynamics Simulation Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_model/dynamics/README.rst Defines the material properties used in the dynamics simulation. This file typically contains parameters like density, Young's modulus, and Poisson's ratio. ```text This is a placeholder for the actual content of material.dat. The file would contain material properties necessary for the simulation. ``` -------------------------------- ### Distribute Mesh in Parallel 2D Simulation (C++) Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/parallel/README.rst This C++ code snippet demonstrates how to initialize a communicator, read a mesh file on processor 0, and then distribute it among all processors for parallel processing. It's essential for setting up distributed simulations. ```c++ const auto & comm = Communicator::getStaticCommunicator(); Int prank = comm.whoAmI(); if (prank == 0) { mesh.read("square_2d.msh"); } mesh.distribute(); ``` -------------------------------- ### Cohesive Intrinsic Example for Solid Mechanics Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_cohesive_model/README.rst This snippet is part of an example demonstrating the intrinsic insertion of cohesive elements during mesh generation for the Solid Mechanics Cohesive Model. It likely involves setting up the mesh with cohesive properties from the start. ```cpp #include "SolidMechanicsModelCohesive.h" #include "Mesh.h" int main() { Mesh mesh; // ... mesh generation logic ... SolidMechanicsModelCohesive model(mesh); // ... simulation setup ... return 0; } ``` -------------------------------- ### Python Solver Callback for Stiffness Matrix Modification Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_model/solver_callback/README.rst This Python code defines a solver callback class that intercepts the simulation process to modify the stiffness matrix. It inherits from aka.InterceptSolverCallback and is instantiated with a model object. The callback is then passed to the model's solveStep method. ```python class SolverCallback(aka.InterceptSolverCallback): """Solver callback to modify the stiffness matrix.""" def __init__(self, model): aka.InterceptSolverCallback.__init__(self) self.model = model def __call__(self, step): # Modify stiffness matrix here pass model = aka.SolidMechanicsModel() # ... model setup ... solver_callback = SolverCallback(model) model.solveStep(solver_callback) ``` -------------------------------- ### Setup Python Interface Source: https://gitlab.com/akantu/akantu/-/blob/master/CMakeLists.txt Detects if the Python interface is enabled and includes the necessary pybind11 dependencies. It also calculates the appropriate installation prefix for Python modules. ```cmake package_is_activated(python_interface _python_act) if(_python_act) include(AkantuNeedPybind11) if(IS_ABSOLUTE "${CMAKE_INSTALL_PREFIX}") set(AKANTU_PYTHON_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) else() set(AKANTU_PYTHON_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_PREFIX}") endif() add_subdirectory(python) endif() ``` -------------------------------- ### Perform Static Analysis in C++ Source: https://context7.com/akantu/akantu/llms.txt Illustrates how to set up and solve a static equilibrium problem using Akantu's `SolidMechanicsModel`. It covers applying Dirichlet boundary conditions, configuring the Newton-Raphson solver for convergence, and dumping results like displacement, stress, and strain. ```cpp #include "solid_mechanics_model.hh" #include "non_linear_solver.hh" using namespace akantu; int main(int argc, char * argv[]) { initialize("material.dat", argc, argv); Mesh mesh(2); mesh.read("square.msh"); SolidMechanicsModel model(mesh); model.initFull(_analysis_method = _static); // Apply Dirichlet boundary conditions model.applyBC(BC::Dirichlet::FixedValue(0.0, _x), "Fixed_x"); model.applyBC(BC::Dirichlet::FixedValue(0.0, _y), "Fixed_y"); model.applyBC(BC::Dirichlet::FixedValue(0.0001, _x), "Displacement"); // Configure Newton-Raphson solver auto & solver = model.getNonLinearSolver(); solver.set("max_iterations", 100); solver.set("threshold", 1e-4); solver.set("convergence_type", SolveConvergenceCriteria::_residual); // Solve and dump results model.solveStep(); model.setBaseName("static_output"); model.addDumpFieldVector("displacement"); model.addDumpField("stress"); model.addDumpField("strain"); model.dump(); return 0; } ``` -------------------------------- ### Define New Local Material in C++ Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/new_material/README.rst This C++ code defines a new local material model for solid mechanics simulations. It likely involves specifying material properties, constitutive laws, and integration schemes. This snippet is part of a larger Akantu simulation setup. ```c++ #include "akantu/akantu.h" namespace akantu { // Define a new local material class NewLocalMaterial : public Material { public: NewLocalMaterial(const std::string& name) : Material(name) {} virtual void computeConstitutiveTensor(const ConstitutiveState& state, Tensor& C, Tensor& dC) override { // Implementation of constitutive tensor computation // This is a placeholder and would contain the actual material model logic C.setZero(); dC.setZero(); } virtual void computeStress(const ConstitutiveState& state, Tensor& sigma) override { // Implementation of stress computation // This is a placeholder and would contain the actual material model logic sigma.setZero(); } virtual void computeInternalVariables(const ConstitutiveState& state, std::vector& int_vars) override { // Implementation of internal variable computation // This is a placeholder and would contain the actual material model logic } virtual void updateInternalVariables(const ConstitutiveState& state, const std::vector& int_vars) override { // Implementation of internal variable update // This is a placeholder and would contain the actual material model logic } virtual void computeThermalExpansion(const ConstitutiveState& state, Tensor& alpha) override { // Implementation of thermal expansion computation // This is a placeholder and would contain the actual material model logic alpha.setZero(); } virtual void computeThermalConductivity(const ConstitutiveState& state, Tensor& kappa) override { // Implementation of thermal conductivity computation // This is a placeholder and would contain the actual material model logic kappa.setZero(); } virtual void computeSpecificHeat(const ConstitutiveState& state, double& cp) override { // Implementation of specific heat computation // This is a placeholder and would contain the actual material model logic cp = 0.0; } virtual void computeDensity(const ConstitutiveState& state, double& rho) override { // Implementation of density computation // This is a placeholder and would contain the actual material model logic rho = 0.0; } virtual void computeViscosity(const ConstitutiveState& state, Tensor& eta) override { // Implementation of viscosity computation for viscous materials // This is a placeholder and would contain the actual material model logic eta.setZero(); } }; // Factory function to create instances of NewLocalMaterial extern "C" Material* createMaterial(const std::string& name) { return new NewLocalMaterial(name); } } // namespace akantu ``` -------------------------------- ### Perform 3D Scalability Simulation in C++ Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/scalability_test/README.rst This C++ source file implements the core logic for the scalability test, supporting elastic materials and dynamic cohesive element insertion. It is designed to handle large-scale meshes, with the provided example code starting from line 20. ```c++ // Implementation of cohesive extrinsic scalability test #include // ... (code truncated, see examples/c++/scalability_test/cohesive_extrinsic.cc) ``` -------------------------------- ### Accessing Akantu Parser and Parameters Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/io.rst Demonstrates how to retrieve the static parser, access user-defined sections, and extract parameters from the input file structure. ```cpp auto & parser = getStaticParser(); const auto & usersect = getUserParser(); Real mass = usersect.getParameter("mass"); ``` -------------------------------- ### Dynamic 3D Heat Diffusion Simulation (C++) Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/diffusion_model/README.rst Addresses a 3D explicit dynamic heat propagation problem. It involves a cube with an initial uniform temperature and a centered sphere maintained at a higher temperature. The simulation setup is similar to the 2D dynamic case, but utilizes a 3D mesh and a heat source with a third coordinate. ```c++ /* * Copyright (c) 2012-2018 * The Akantu Project */ #include "akantu.h" using namespace akantu; int main(int argc, char* argv[]) { // --- Input parameters --- const char* meshFile = "cube.msh"; const char* materialFile = "material.dat"; const double initialTemperature = 100.0; const double hotSphereTemperature = 300.0; const int meshResolution = 50; const double timeStep = 0.12; const int numTimeSteps = 15000; // --- Create the mesh --- const int spatial_dimension = 3; Mesh mesh(spatial_dimension); mesh.read(meshFile); mesh.setResolution(meshResolution); // --- Create the material --- Material material; material.read(materialFile); // --- Create the model --- HeatTransferModel model(&mesh, &material); // --- Set initial conditions --- model.setInitialTemperature(initialTemperature); model.setHotSphereTemperature(hotSphereTemperature); // --- Set boundary conditions --- model.setBoundaryTemperature(0.0); // --- Solve the dynamic problem --- model.initFull(_analysis_method = _explicit_lumped_mass); model.solveDynamicProblem(timeStep, numTimeSteps); // --- Save the results --- model.saveResults("heat_diffusion_dynamic_3d"); return 0; } ``` ```text # Material properties # Density (kg/m^3) density = 8940 # Thermal conductivity (W/m/K) conductivity = 401 # Specific heat capacity (J/K/kg) specific_heat = 385 ``` -------------------------------- ### Create and Load Mesh in C++ Source: https://context7.com/akantu/akantu/llms.txt Demonstrates how to initialize Akantu, create a 2D mesh, read it from a Gmsh file, distribute it for parallel processing, and access mesh data. It also shows how to create element and node groups from physical names. ```cpp #include "aka_common.hh" #include "mesh.hh" using namespace akantu; int main(int argc, char *argv[]) { initialize("input.dat", argc, argv); // Create mesh for 2D problem Int spatial_dimension = 2; Mesh mesh(spatial_dimension); // Read mesh from Gmsh file (extension auto-detected) mesh.read("geometry.msh"); // For parallel simulations, distribute the mesh const auto & comm = Communicator::getStaticCommunicator(); if (comm.whoAmI() == 0) { mesh.read("geometry.msh"); } mesh.distribute(); // Access mesh data const Array & nodes = mesh.getNodes(); Int nb_nodes = mesh.getNbNodes(); // Create element and node groups from physical names mesh.createGroupsFromMeshData("physical_names"); return 0; } ``` -------------------------------- ### Initialize CouplerSolidContact with Analysis Method Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/contactmechanicsmodel.rst Shows how to initialize the CouplerSolidContact with a specific analysis method, such as explicit lumped mass. This step is crucial before proceeding with other configurations. ```c++ coupler.initFull( _analysis_method = _explicit_lumped_mass); ``` -------------------------------- ### Configuring Simulation Output Dumps Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/io.rst Shows how to configure the model to export simulation data fields into VTK format for visualization software. ```cpp model.setBaseName("output"); model.addDumpField("displacement"); model.addDumpField("stress"); model.dump(); ``` -------------------------------- ### Python Script for 2D Compression Simulation Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/contact_mechanics_model/compression/README.rst This Python script sets up and runs a 2D compression simulation by coupling the Solid Mechanics Model with the Contact Mechanics Model. It defines the simulation parameters and logic for contact between two blocks. No external libraries are explicitly mentioned as dependencies within the snippet itself. ```python import numpy as np from akantu import * def main(): # --- Material --- ``` -------------------------------- ### Install Akantu Target and Exports Source: https://gitlab.com/akantu/akantu/-/blob/master/src/CMakeLists.txt Defines the installation rules for the Akantu target, specifying destinations for libraries, archives, runtime components, and public headers. It also handles installing CMake export files for package management. ```cmake # TODO separate public from private headers install(TARGETS akantu EXPORT ${AKANTU_TARGETS_EXPORT} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Akantu_runtime # NAMELINK_ONLY # LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # COMPONENT Akantu_development # NAMELINK_SKIP Akantu_development ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Akantu_runtime RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Akantu_runtime PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/akantu/ COMPONENT Akantu_development ) if("${AKANTU_TARGETS_EXPORT}" STREQUAL "AkantuTargets") install(EXPORT AkantuTargets DESTINATION lib/cmake/${PROJECT_NAME} COMPONENT dev) #Export for build tree export(EXPORT AkantuTargets FILE "${CMAKE_BINARY_DIR}/AkantuTargets.cmake") export(PACKAGE Akantu) endif() ``` -------------------------------- ### Cohesive Extrinsic Example for Solid Mechanics Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_cohesive_model/README.rst This snippet is part of an example demonstrating the extrinsic insertion of cohesive elements during a simulation for the Solid Mechanics Cohesive Model. This method allows for cohesive elements to be added or modified after the initial mesh generation. ```cpp #include "SolidMechanicsModelCohesive.h" #include "Mesh.h" int main() { Mesh mesh; // ... mesh generation logic ... SolidMechanicsModelCohesive model(mesh); // ... simulation setup ... // ... logic for extrinsic cohesive element insertion ... return 0; } ``` -------------------------------- ### Cohesive Extrinsic IG TG Example for Solid Mechanics Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_cohesive_model/README.rst This snippet is part of an example focusing on extrinsic insertion of cohesive elements, specifically mentioning 'IG' and 'TG' (likely related to interface or traction-gap laws) for the Solid Mechanics Cohesive Model. It demonstrates advanced control over cohesive behavior during simulation. ```cpp #include "SolidMechanicsModelCohesive.h" #include "Mesh.h" int main() { Mesh mesh; // ... mesh generation logic ... SolidMechanicsModelCohesive model(mesh); // ... simulation setup ... // ... logic for extrinsic cohesive element insertion with IG/TG properties ... return 0; } ``` -------------------------------- ### Configure Installation and Packaging Source: https://gitlab.com/akantu/akantu/-/blob/master/CMakeLists.txt Includes installation logic and CPack configuration. It provides an option to disable CPack generation, which is marked as advanced in the CMake cache. ```cmake if (NOT AKANTU_BYPASS_AKANTU_TARGET) include(AkantuInstall) option(AKANTU_DISABLE_CPACK "This option commands the generation of extra info for the \"make package\" target" ON) mark_as_advanced(AKANTU_DISABLE_CPACK) if(NOT AKANTU_DISABLE_CPACK) include(AkantuCPack) endif() endif() ``` -------------------------------- ### Akantu C++: Initializing Implicit Dynamic Analysis Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/solidmechanicsmodel.rst Demonstrates how to initialize a SolidMechanicsModel in Akantu for implicit dynamic analysis using C++. This involves creating the model with a mesh and setting the analysis method. ```cpp SolidMechanicsModel model(mesh); model.initFull(_analysis_method = _implicit_dynamic); ``` -------------------------------- ### Initialize and Solve Cohesive Model in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/solid_mechanics_cohesive_model/cohesive/README.rst Demonstrates how to initialize a SolidMechanicsModelCohesive object with extrinsic cohesive elements and switch between static and explicit dynamic solvers. This approach is used to handle crack propagation and instability in solid mechanics simulations. ```python model = aka.SolidMechanicsModelCohesive(mesh) model.initFull(_analysis_method=aka._static, _is_extrinsic=True) model.initNewSolver(aka._explicit_lumped_mass) [....] model.solveStep("static") [....] model.solveStep("explicit_lumped") ``` -------------------------------- ### Array and Tensor Operations in C++ Source: https://context7.com/akantu/akantu/llms.txt Demonstrates creating, accessing, modifying, and performing operations on Akantu's Array, Vector, and Matrix classes. Includes examples of resizing, appending, normalization, matrix multiplication, and eigenvalue decomposition. Also shows ElementTypeMapArray for element-specific data. ```cpp #include "aka_array.hh" using namespace akantu; void arrayOperations() { // Create array with 100 entries, 3 components each (e.g., nodal coordinates) Array coords(100, 3); // Access individual values coords(0, 0) = 1.0; // node 0, x-coordinate coords(0, 1) = 2.0; // node 0, y-coordinate // Array operations coords.set(0.0); // Set all values to 0 coords.resize(200); // Resize to 200 entries coords.push_back({1, 2, 3}); // Append tuple // Iterate using make_view for Vector/Matrix access for (auto & coord : make_view(coords, 3)) { // coord is Vector of size 3 Real norm = coord.norm(); coord /= norm; // Normalize } // Matrix operations Matrix A(3, 3); A.eye(); // Identity matrix Real det = A.det(); Real trace = A.trace(); Matrix B(3, 3); Matrix C(3, 3); C.mul(A, B); // C = A * B // Eigenvalue decomposition Vector eigenvalues(3); Matrix eigenvectors(3, 3); A.eigs(eigenvalues, eigenvectors); // Element type map array (data per element type) ElementTypeMapArray stresses; stresses.initialize(mesh.getNbElement(_triangle_3), 6); // 6 components for symmetric tensor } ``` -------------------------------- ### Configure Hertzian Contact Solver in C++ Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/contact_mechanics_model/hertz/README.rst Demonstrates the initialization of the CouplerSolidContact solver for both static and explicit dynamic analysis methods in Akantu. ```c++ // for contact_explicit_static coupler.initFull(_analysis_method = _static); // for contact_explicit_dynamic coupler.initFull(_analysis_method = _explicit_lumped_mass); ``` -------------------------------- ### Material Properties for Cohesive Extrinsic Simulation (Text) Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_cohesive_model/cohesive_extrinsic/README.rst This text file defines the material properties used in the cohesive_extrinsic example. It specifies parameters relevant to the cohesive model, which are crucial for accurate simulation of material behavior. ```text ## Material properties for cohesive_extrinsic example # This file contains parameters for the cohesive material model. # Example parameters: # YoungModulus: 210e9 # PoissonRatio: 0.3 # CohesiveStrength: 10e6 # FractureToughness: 2000 # InitialTension: 0.01 # InitialCompression: 0.01 ``` -------------------------------- ### Set Element Insertion Limit (C++) Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_cohesive_model/cohesive_intrinsic/README.rst Configures the element inserter to define the spatial limits for inserting cohesive elements. In this example, cohesive elements are inserted between x = -0.26 and x = -0.24. Elements to the right of this limit are subsequently moved. ```c++ model.getElementInserter().setLimit(_x, -0.26, -0.24); ``` -------------------------------- ### Initialize Explicit Dynamic Model in Akantu Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/explicit/README.rst Demonstrates how to initialize a model using the explicit lumped mass method. This method is the default for dynamic analysis in Akantu. ```c++ model.initFull(_analysis_method = _explicit_lumped_mass); ``` -------------------------------- ### Cohesive Extrinsic IG TG Material Definition Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_cohesive_model/cohesive_extrinsic_ig_tg/README.rst This text file defines the material properties for the cohesive_extrinsic_ig_tg example. It specifies the cohesive law, critical stress, and stiffness parameters for different material types, enabling the simulation of varying cohesive behaviors. ```text CohesiveBoundary: cohesive_law: extrinsic_ig_tg sigma_c: 10.0 normal_stiffness: 1000.0 shear_stiffness: 500.0 CohesiveInterior: cohesive_law: extrinsic_ig_tg sigma_c: 5.0 normal_stiffness: 1000.0 shear_stiffness: 500.0 ``` -------------------------------- ### Dynamic 2D Heat Diffusion Simulation (C++) Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/diffusion_model/README.rst Solves a dynamic heat propagation problem in 2D using an explicit time scheme. It builds upon the static example by introducing time-dependent analysis. The simulation uses a specified time step and an explicit lumped mass analysis method. ```c++ /* * Copyright (c) 2012-2018 * The Akantu Project */ #include "akantu.h" using namespace akantu; int main(int argc, char* argv[]) { // --- Input parameters --- const char* meshFile = "square.msh"; const char* materialFile = "material.dat"; const double initialTemperature = 100.0; const double hotPointTemperature = 300.0; const int meshResolution = 50; const double timeStep = 0.12; const int numTimeSteps = 15000; // --- Create the mesh --- Mesh mesh(2); mesh.read(meshFile); mesh.setResolution(meshResolution); // --- Create the material --- Material material; material.read(materialFile); // --- Create the model --- HeatTransferModel model(&mesh, &material); // --- Set initial conditions --- model.setInitialTemperature(initialTemperature); model.setHotPointTemperature(hotPointTemperature); // --- Set boundary conditions --- model.setBoundaryTemperature(0.0); // --- Solve the dynamic problem --- model.initFull(_analysis_method = _explicit_lumped_mass); model.solveDynamicProblem(timeStep, numTimeSteps); // --- Save the results --- model.saveResults("heat_diffusion_dynamic_2d"); return 0; } ``` ```text # Material properties # Density (kg/m^3) density = 8940 # Thermal conductivity (W/m/K) conductivity = 401 # Specific heat capacity (J/K/kg) specific_heat = 385 ``` -------------------------------- ### Configure Output and Solvers for Bulk and Cohesive Elements Source: https://context7.com/akantu/akantu/llms.txt Configures output fields for bulk and cohesive elements, applies boundary conditions, sets up a non-linear solver for static analysis, and performs a static solve followed by dynamic fracture propagation. It includes checks for cohesive element insertion and dumps output at specified intervals. ```python model.setBaseName("plate") model.addDumpFieldVector("displacement") model.addDumpField("stress") model.setBaseNameToDumper("cohesive elements", "cohesive") model.addDumpFieldVectorToDumper("cohesive elements", "displacement") model.addDumpFieldToDumper("cohesive elements", "damage") model.addDumpFieldVectorToDumper("cohesive elements", "tractions") model.addDumpFieldVectorToDumper("cohesive elements", "opening") model.applyBC(aka.FixedValue(0.0, aka._x), "XBlocked") model.applyBC(aka.FixedValue(0.0, aka._y), "YBlocked") traction = np.zeros(spatial_dimension) traction[1] = 0.095 # Near critical stress model.getExternalForce()[:] = 0 model.applyBC(aka.FromTraction(traction), "Traction") solver = model.getNonLinearSolver("static") solver.set("max_iterations", 100) solver.set("threshold", 1e-10) solver.set("convergence_type", aka.SolveConvergenceCriteria.residual) model.solveStep("static") model.dump() model.dump("cohesive elements") model.setTimeStep(model.getStableTimeStep() * 0.1) for i in range(100): model.checkCohesiveStress() # Check for cohesive element insertion model.solveStep("explicit_lumped") if i % 10 == 0: model.dump() model.dump("cohesive elements") ``` -------------------------------- ### Perform Implicit Dynamic Analysis with SolidMechanicsModel Source: https://context7.com/akantu/akantu/llms.txt Demonstrates an implicit dynamic simulation using the Newmark-beta method in C++. It covers mesh initialization, boundary condition application, non-linear solver configuration, and a time-stepping loop. ```cpp #include "solid_mechanics_model.hh" using namespace akantu; int main(int argc, char * argv[]) { initialize("material.dat", argc, argv); Mesh mesh(3); mesh.read("beam.msh"); SolidMechanicsModel model(mesh); model.initFull(_analysis_method = _implicit_dynamic); Real time_step = 0.001; model.setTimeStep(time_step); model.applyBC(BC::Dirichlet::FixedValue(0.0, _x), "fixed_end"); model.applyBC(BC::Dirichlet::FixedValue(0.0, _y), "fixed_end"); model.applyBC(BC::Dirichlet::FixedValue(0.0, _z), "fixed_end"); auto & solver = model.getNonLinearSolver(); solver.set("max_iterations", 100); solver.set("threshold", 1e-12); solver.set("convergence_type", SolveConvergenceCriteria::_solution); Real max_time = 1.0; for (Real time = 0.; time < max_time; time += time_step) { model.solveStep(); } return 0; } ``` -------------------------------- ### Define Linear Isotropic Elastic Material Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/constitutive-laws.rst Example of defining a linear isotropic elastic material using the 'elastic' keyword in the input file. ```python material elastic [ name = value rho = value ... ] ``` -------------------------------- ### Configure IOHelper Library Build Source: https://gitlab.com/akantu/akantu/-/blob/master/third-party/iohelper/src/CMakeLists.txt Creates the iohelper library, sets the C++14 standard, and configures include directories for both build and install interfaces. ```cmake add_library(iohelper ${IOHELPER_COMMON_SRC}) target_include_directories(iohelper PRIVATE $ INTERFACE $ $ ) set_target_properties(iohelper PROPERTIES PUBLIC_HEADER "${IOHELPER_COMMON_HEADERS}") set_property(TARGET iohelper PROPERTY CXX_STANDARD 14) ``` -------------------------------- ### Create and Populate Element Groups for Dumping (C++) Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/c++/solid_mechanics_model/io/README.rst Illustrates advanced data dumping techniques in C++ for visualization with Paraview. It shows how to create a specific element group (e.g., 'wheels') from a mesh and add existing mesh elements to this group. This allows for selective dumping of mesh parts. ```c++ ElementGroup & wheels_elements = mesh.createElementGroup("wheels", spatial_dimension); wheels_elements.append(mesh.getElementGroup("lwheel_1")); ``` -------------------------------- ### Import Akantu Module in Python Source: https://gitlab.com/akantu/akantu/-/blob/master/examples/python/README.rst Demonstrates how to import the Akantu module in a Python script. This is the first step to using Akantu's functionalities in Python. ```python import akantu as aka ``` -------------------------------- ### Initialize Solid Mechanics Model in C++ Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/solidmechanicsmodel.rst Demonstrates the initialization of a SolidMechanicsModel instance using the initFull method. This process sets up the analysis type and prepares internal vectors. ```c++ SolidMechanicsModel model(mesh); model.initFull(_analysis_method = _static); ``` -------------------------------- ### Configure Akantu Build with CMake Source: https://gitlab.com/akantu/akantu/-/blob/master/doc/dev-doc/manual/getting_started.rst A minimal CMakeLists.txt configuration to compile an Akantu simulation project. ```cmake cmake_minimum_required(VERSION 3.12.0) project(my_simu) find_package(Akantu REQUIRED) add_akantu_simulation(my_simu my_simu.cc) ```