Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
cmake_minimum_required(VERSION 3.16)
project(MarmotSolverExample LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(Python3 COMPONENTS Interpreter REQUIRED)

execute_process(
COMMAND "${Python3_EXECUTABLE}" -c "import sys; print(sys.prefix, end='')"
OUTPUT_VARIABLE PYTHON_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)

set(MARMOT_ROOT "${PYTHON_PREFIX}")
set(EIGEN_DIR "${PYTHON_PREFIX}/include/eigen3")
set(FASTOR_DIR "${PYTHON_PREFIX}/include/Fastor")

add_executable(solver_example example.cpp)

target_include_directories(solver_example PRIVATE
"${MARMOT_ROOT}/include"
"${EIGEN_DIR}"
"${FASTOR_DIR}"
)

target_link_directories(solver_example PRIVATE "${MARMOT_ROOT}/lib")

target_link_libraries(solver_example PRIVATE Marmot)

target_compile_options(solver_example PRIVATE -Wall -Wextra -fPIC)

set_target_properties(solver_example PROPERTIES
BUILD_RPATH "${MARMOT_ROOT}/lib"
INSTALL_RPATH "${MARMOT_ROOT}/lib"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "Marmot/MarmotFastorTensorBasics.h"
#include "Marmot/MarmotMaterialPointSolverFiniteStrain.h"
// Ensure the registration unit is linked or included if using static registration
// #include "Marmot/MaterialRegistration.cpp"

int main()
{
using namespace Marmot::Solvers;
using namespace Marmot::FastorStandardTensors;

// 1) Define the material model
// Must match the key used in MarmotMaterialFiniteStrainFactory::registerMaterial
std::string materialName = "FINITESTRAINJ2PLASTICITY_SUBSTEPPED";

// Define Properties
// [0]: nSubsteps (Specific to SubsteppingMaterial)
// [1...8]: Standard FiniteStrainJ2Plasticity properties
double properties[] = {
20, // nSubsteps (20 substeps per global increment)
35, // K (Bulk Modulus)
15, // G (Shear Modulus)
0.45, // fy (Initial Yield Stress)
0.75, // fyInf (Saturated Yield Stress)
0.5, // eta (Saturation rate)
0.1, // H (Linear Hardening)
1.0, // implementationType (1 = Full Analytical Return Mapping)
0.0 // density
Comment on lines +16 to +27
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on line 17 states "Standard FiniteStrainJ2Plasticity properties" for indices [1...8], but only 8 properties are defined (indices 1-8), which is correct. However, the comment could be clearer about which property is at which index. Consider adding inline comments for each property value to improve readability and maintainability.

Suggested change
// [0]: nSubsteps (Specific to SubsteppingMaterial)
// [1...8]: Standard FiniteStrainJ2Plasticity properties
double properties[] = {
20, // nSubsteps (20 substeps per global increment)
35, // K (Bulk Modulus)
15, // G (Shear Modulus)
0.45, // fy (Initial Yield Stress)
0.75, // fyInf (Saturated Yield Stress)
0.5, // eta (Saturation rate)
0.1, // H (Linear Hardening)
1.0, // implementationType (1 = Full Analytical Return Mapping)
0.0 // density
// [0]: nSubsteps (specific to SubsteppingMaterial)
// [1-8]: Standard FiniteStrainJ2Plasticity material properties
double properties[] = {
20, // [0] nSubsteps (20 substeps per global increment)
35, // [1] K (Bulk Modulus)
15, // [2] G (Shear Modulus)
0.45, // [3] fy (Initial Yield Stress)
0.75, // [4] fyInf (Saturated Yield Stress)
0.5, // [5] eta (Saturation rate)
0.1, // [6] H (Linear Hardening)
1.0, // [7] implementationType (1 = Full Analytical Return Mapping)
0.0 // [8] density

Copilot uses AI. Check for mistakes.
};
int nProps = 9;

// 2) Configure solver options
// With a consistent analytical tangent from the substepper,
// we expect quadratic convergence (typically < 5 iterations).
MarmotMaterialPointSolverFiniteStrain::SolverOptions options;
options.maxIterations = 15;
options.residualTolerance = 1e-8;
options.correctionTolerance = 1e-8;

// 3) Create solver instance
// The factory will instantiate SubsteppingMaterial, which internally instantiates FiniteStrainJ2Plasticity
MarmotMaterialPointSolverFiniteStrain solver( materialName, properties, nProps, options );

// 5) Define Loading Steps

// --- Step 1: Loading (Uniaxial extension to 10%) ---
MarmotMaterialPointSolverFiniteStrain::Step step1;
step1.timeStart = 0.0;
step1.timeEnd = 1.0;
step1.dTStart = 1e-0; // 10 global increments
step1.dTMin = 1e-1;
step1.dTMax = 0.5;

step1.gradUIncrementTarget = Tensor33d( 0.0 );
step1.stressIncrementTarget = Tensor33d( 0.0 );
step1.isGradUComponentControlled = Tensor33t< bool >( false );
step1.isStressComponentControlled = Tensor33t< bool >( true );

// Control gradU_11 (stretch to 10%)
step1.gradUIncrementTarget( 0, 0 ) = 1;
step1.isGradUComponentControlled( 0, 0 ) = true;
step1.isStressComponentControlled( 0, 0 ) = false;

// Mixed control for lateral contraction (Plane Stress approximation via Solver)
// We keep stress 22 and 33 controlled to 0.0 (default true)

solver.addStep( step1 );

// --- Step 2: Unloading (Return to 0% global strain) ---
// This validates that F_n is correctly updated and stored between steps
MarmotMaterialPointSolverFiniteStrain::Step step2 = step1;
step2.timeStart = 1.0;
step2.timeEnd = 2.0;

// Reverse direction: target increment is -0.10 to go back to 0
step2.gradUIncrementTarget( 0, 0 ) = -1;

solver.addStep( step2 );

// 6) Run the solver
try {
solver.solve();
}
catch ( const std::exception& e ) {
// Catch exceptions thrown by the substepper (e.g., if inner Newton fails)
std::cerr << "\n!!! SOLVER FAILED !!!\nError: " << e.what() << std::endl;
return 1;
}

// 7) Output the results
// The CSV will contain extra columns for the substepper state (Substepping_F_n components)
solver.exportHistoryToCSV( "j2_substepped_results.csv" );

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class MarmotMaterialFiniteStrain {
AlgorithmicModuli< 3 >& tangents,
const Deformation< 3 >&,
const TimeIncrement& ) const = 0;

/**
* @brief Computes the Kirchhoff stress given the deformation, time increment, and eigen deformation.
* @param[inout] response ConstitutiveResponse instance
Expand Down
Loading