MarmotUtilitiesCore

class MakeString
#include <MarmotJournal.h>

Utility class for constructing strings with stream-like syntax.

This class allows for easy string construction using the stream insertion operator. It can be used to build complex strings in a readable manner.

Public Functions

inline operator std::string() const

Convert the accumulated stream content to a std::string.

template<class T>
inline MakeString &operator<<(T const &VAR)

Append a value to the internal stream.

Template Parameters:

T – Type of the value to append.

Parameters:

VAR – Value to insert into the stream.

Returns:

Reference to *this for chaining.

Public Members

std::stringstream stream

Internal string stream used for building the output string.

class MarmotJournal
#include <MarmotJournal.h>

Singleton class for managing output messages in the Marmot framework.

This class provides a centralized way to handle warning and notification messages, allowing them to be directed to a specified output stream (e.g., console, file).

Public Functions

MarmotJournal(MarmotJournal const&) = delete
void operator=(MarmotJournal const&) = delete

Public Static Functions

static void setMSGOutputDirection(std::ostream &newOutputStream)

Redirect all subsequent journal output to newOutputStream.

Parameters:

newOutputStream – The output stream that warnings and notifications are written to.

static bool warningToMSG(const std::string &message)

Write a warning message to the journal output stream.

Parameters:

message – The warning text to emit.

Returns:

true after the message has been written.

static bool notificationToMSG(const std::string &message)

Write a notification message to the journal output stream.

Parameters:

message – The notification text to emit.

Returns:

true after the message has been written.

Private Functions

MarmotJournal()

Private Members

std::ostream output

Private Static Functions

static MarmotJournal &getInstance()
class MarmotStateLayoutDynamic

Runtime-defined layout for a flat array of named double state variables.

Variables are registered by name and size via add(), then the layout is locked with finalize(), which assigns contiguous offsets. After finalization the various get* accessors can be used to reach individual variables inside any conforming state vector.

Public Functions

inline void add(std::string name, std::size_t size)

Register a new named state variable.

Must be called before finalize(). Adding a variable with an already-registered name or calling this method after finalize() throws std::runtime_error.

Parameters:
  • name – Unique name for the state variable.

  • size – Number of double values required by the variable.

inline void finalize()

Compute and lock the offsets of all registered variables.

Iterates over the registered variables in registration order, assigns each a contiguous offset, and sets the total size. After this call no further variables may be added. Calling finalize() a second time throws std::runtime_error.

inline const VarInfo &getInfo(const std::string &name) const

Return the VarInfo record for a registered variable.

Parameters:

name – Name of the variable to look up.

Throws:

std::runtime_error – if name is not registered.

Returns:

Const reference to the corresponding VarInfo.

inline std::pair<std::size_t, std::size_t> get(const std::string &name) const

Return the {offset, size} pair for a registered variable.

Parameters:

name – Name of the variable.

Throws:

std::runtime_error – if name is not registered.

Returns:

A pair {offset, size} (both in units of double).

inline double *getPtr(double *base, const std::string &name) const

Return a raw pointer to a variable inside a state vector.

Parameters:
  • base – Pointer to the beginning of the state vector.

  • name – Name of the variable.

Throws:

std::runtime_error – if name is not registered.

Returns:

base + offset for the named variable.

inline std::span<double> getSpan(double *base, const std::string &name) const

Return a std::span<double> view of a variable inside a state vector.

Parameters:
  • base – Pointer to the beginning of the state vector.

  • name – Name of the variable.

Throws:

std::runtime_error – if name is not registered.

Returns:

A span covering [base + offset, base + offset + size).

inline StateView getStateView(double *base, const std::string &name) const

Return a StateView for a variable inside a state vector.

Parameters:
  • base – Pointer to the beginning of the state vector.

  • name – Name of the variable.

Throws:

std::runtime_error – if name is not registered.

Returns:

A StateView with stateLocation = base + offset and stateSize = size.

template<class View, class ...Args>
inline View getAs(double *base, const std::string &name, Args&&... args) const

Map a variable inside a state vector to a typed view via StateMapper.

Delegates to StateMapper<View>::map(base + offset, size, args...). The layout must have been finalized before calling this method.

Template Parameters:
  • View – Target view type (must have a matching StateMapper specialization).

  • Args – Additional constructor arguments forwarded to StateMapper::map.

Parameters:
  • base – Pointer to the beginning of the state vector.

  • name – Name of the variable.

  • args – Extra arguments forwarded to StateMapper::map.

Throws:

std::runtime_error – if the layout is not finalized or name is not registered.

Returns:

The mapped view of the requested variable.

template<class View, class ...Args>
inline View getAs(const double *base, const std::string &name, Args&&... args) const

Const version of getAs.

Template Parameters:
  • View – Target view type (must have a matching StateMapper specialization).

  • Args – Additional constructor arguments forwarded to StateMapper::map.

Parameters:
  • base – Pointer to the beginning of the state vector.

  • name – Name of the variable.

  • args – Extra arguments forwarded to StateMapper::map.

Throws:

std::runtime_error – if the layout is not finalized or name is not registered.

Returns:

The mapped view of the requested variable.

inline int totalSize() const

Return the total size (in units of double) of the state layout. This is the size of the state vector required to hold all registered variables.

inline bool isFinalized() const

Check if the layout has been finalized.

Returns:

true if finalize() has been called, false otherwise.

Private Members

std::vector<VarInfo> variables
std::unordered_map<std::string, std::size_t> name_to_index
bool finalized = false
int total_sz = 0
class SolverConvergenceFailed : public std::runtime_error
#include <MarmotExceptions.h>

Inheritance diagram for Marmot::SolverConvergenceFailed:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Marmot::SolverConvergenceFailed" tooltip="Marmot::SolverConvergenceFailed" fillcolor="#BFBFBF"]
    "2" [label="std::runtime_error" tooltip="std::runtime_error"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Collaboration diagram for Marmot::SolverConvergenceFailed:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Marmot::SolverConvergenceFailed" tooltip="Marmot::SolverConvergenceFailed" fillcolor="#BFBFBF"]
    "2" [label="std::runtime_error" tooltip="std::runtime_error"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Exception thrown when the Newton-Raphson iteration in a material-point solver fails to converge (maximum number of iterations reached or NaN encountered).

Public Functions

inline explicit SolverConvergenceFailed(const std::string &message)

Constructor for SolverConvergenceFailed exception.

Parameters:

message – A descriptive error message explaining the reason for the exception.

class SolverIncrementsExhausted : public std::runtime_error
#include <MarmotExceptions.h>

Inheritance diagram for Marmot::SolverIncrementsExhausted:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Marmot::SolverIncrementsExhausted" tooltip="Marmot::SolverIncrementsExhausted" fillcolor="#BFBFBF"]
    "2" [label="std::runtime_error" tooltip="std::runtime_error"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Collaboration diagram for Marmot::SolverIncrementsExhausted:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Marmot::SolverIncrementsExhausted" tooltip="Marmot::SolverIncrementsExhausted" fillcolor="#BFBFBF"]
    "2" [label="std::runtime_error" tooltip="std::runtime_error"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Exception thrown when the material-point solver exhausts the maximum number of increments without completing the step.

Public Functions

inline explicit SolverIncrementsExhausted(const std::string &message)

Constructor for SolverIncrementsExhausted exception.

Parameters:

message – A descriptive error message explaining the reason for the exception.

class SolverTimestepExhausted : public std::runtime_error
#include <MarmotExceptions.h>

Inheritance diagram for Marmot::SolverTimestepExhausted:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Marmot::SolverTimestepExhausted" tooltip="Marmot::SolverTimestepExhausted" fillcolor="#BFBFBF"]
    "2" [label="std::runtime_error" tooltip="std::runtime_error"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Collaboration diagram for Marmot::SolverTimestepExhausted:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Marmot::SolverTimestepExhausted" tooltip="Marmot::SolverTimestepExhausted" fillcolor="#BFBFBF"]
    "2" [label="std::runtime_error" tooltip="std::runtime_error"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Exception thrown when the material-point solver cannot reduce the time step below the prescribed minimum.

Public Functions

inline explicit SolverTimestepExhausted(const std::string &message)

Constructor for SolverTimestepExhausted exception.

Parameters:

message – A descriptive error message explaining the reason for the exception.

template<class View, int... Args>
struct StateMapper

Template struct to map raw double pointers and sizes to specific views. Specializations of this struct should provide a static map method that takes a double* and a std::size_t size, returning the desired view type.

struct StateView
#include <MarmotUtils.h>

Structure to hold a pointer to the state location and its size.

This structure is used to provide a view of the state variables in a finite element or material, allowing access to the state data without copying it.

Public Members

double *stateLocation

Pointer to the first element of the state variable block.

int stateSize

Number of double values in the state variable block.

class StressUpdateFailed : public std::runtime_error
#include <MarmotExceptions.h>

Inheritance diagram for Marmot::StressUpdateFailed:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Marmot::StressUpdateFailed" tooltip="Marmot::StressUpdateFailed" fillcolor="#BFBFBF"]
    "2" [label="std::runtime_error" tooltip="std::runtime_error"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Collaboration diagram for Marmot::StressUpdateFailed:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="Marmot::StressUpdateFailed" tooltip="Marmot::StressUpdateFailed" fillcolor="#BFBFBF"]
    "2" [label="std::runtime_error" tooltip="std::runtime_error"]
    "1" -> "2" [dir=forward tooltip="public-inheritance"]
}

Exception thrown when a stress update (e.g., return-mapping iteration) fails to converge inside a material model.

Public Functions

inline explicit StressUpdateFailed(const std::string &message)

Constructor for StressUpdateFailed exception.

Parameters:

message – A descriptive error message explaining the reason for the exception.

struct VarInfo

Describes a single named state variable registered in the layout.

Public Members

std::string name

Unique name of the state variable.

std::size_t size

Number of double values occupied by this variable.

std::size_t offset

Byte-offset (in units of double) from the beginning of the state vector.

namespace Marmot
namespace Testing

Functions

bool checkIfEqual(const double a, const double b, const double tol = 1e-15)

Check whether two double values are equal within a tolerance.

Parameters:
  • a – First value.

  • b – Second value.

  • tol – Absolute tolerance (default: 1e-15).

Returns:

true if |a - b| <= tol, false otherwise.

bool checkIfEqual(const autodiff::dual a, const autodiff::dual b, const double tol = 1e-15)

Check whether two autodiff::dual values are equal within a tolerance.

Parameters:
  • a – First dual number.

  • b – Second dual number.

  • tol – Absolute tolerance applied to the real part (default: 1e-15).

Returns:

true if the values compare equal within tol, false otherwise.

bool checkIfEqual(const std::complex<double> a, const std::complex<double> b, const double tol = 1e-15)

Check whether two std::complex<double> values are equal within a tolerance.

Parameters:
  • a – First complex value.

  • b – Second complex value.

  • tol – Absolute tolerance (default: 1e-15).

Returns:

true if both real and imaginary parts are within tol, false otherwise.

std::string getString(const double a)

Convert a double to its string representation.

Parameters:

a – Value to convert.

Returns:

String representation of a.

std::string getString(const autodiff::dual a)

Convert an autodiff::dual to its string representation.

Parameters:

a – Dual number to convert.

Returns:

String representation of a.

template<typename T>
bool checkIfEqual(const Eigen::Matrix<T, -1, -1> &a, const Eigen::Matrix<T, -1, -1> &b, const double tol = 1e-15)

Check whether two dynamic Eigen matrices are element-wise equal within a tolerance.

Prints a hint to stdout identifying the first mismatching entry before returning false.

Template Parameters:

T – Scalar type of the matrices.

Parameters:
  • a – First matrix.

  • b – Second matrix.

  • tol – Absolute tolerance per element (default: 1e-15).

Returns:

true if all elements satisfy |a(i,j) - b(i,j)| <= tol, false otherwise.

template<typename T, long int... Rest>
bool checkIfEqual(const Eigen::TensorFixedSize<T, Eigen::Sizes<Rest...>> &a, const Eigen::TensorFixedSize<T, Eigen::Sizes<Rest...>> &b, const double tol = 1e-15)

Check whether two fixed-size Eigen tensors are element-wise equal within a tolerance.

Prints a hint to stdout identifying the first mismatching entry before returning false.

Template Parameters:
  • T – Scalar type of the tensors.

  • Rest – Compile-time dimension pack.

Parameters:
  • a – First tensor.

  • b – Second tensor.

  • tol – Absolute tolerance per element (default: 1e-15).

Returns:

true if all elements satisfy |a(i) - b(i)| <= tol, false otherwise.

template<typename T, size_t... Rest>
bool checkIfEqual(const Fastor::Tensor<T, Rest...> &a, const Fastor::Tensor<T, Rest...> &b, const double tol = 1e-15)

Check whether two Fastor tensors are element-wise equal within a tolerance.

Prints a hint to stdout identifying the first mismatching entry before returning false.

Template Parameters:
  • T – Scalar type of the tensors.

  • Rest – Compile-time dimension pack.

Parameters:
  • a – First tensor.

  • b – Second tensor.

  • tol – Absolute tolerance per element (default: 1e-15).

Returns:

true if all elements satisfy |a(i) - b(i)| <= tol, false otherwise.

void throwExceptionOnFailure(const bool condition, const std::string &message = "")

Throw a std::runtime_error when condition is false.

Parameters:
  • condition – The condition to check; an exception is thrown when false.

  • message – Optional message included in the exception (default: “”).

void executeTestsAndCollectExceptions(const std::vector<std::function<void()>> &testFunctions)

Execute a list of test functions and collect any exceptions they throw.

Each function in testFunctions is called in order. Exceptions are caught, their messages accumulated, and a single combined exception is re-thrown after all tests have run so that every failure is reported.

Parameters:

testFunctions – Vector of zero-argument callables to execute.

template<int N>
Eigen::Matrix<double, N, 2> fibonacciLatticeHemisphere()

Generate a Fibonacci-lattice sampling of the hemisphere.

Returns N evenly-distributed (φ, θ) angle pairs on the upper hemisphere using the golden-angle Fibonacci lattice.

Template Parameters:

N – Number of sample points.

Returns:

An Nx2 matrix where each row is (phi, theta) in radians.

bool spinTurbokreisel(Marmot::Solvers::MarmotMaterialPointSolverHypoElastic &solver, double stressTol = 1e-15, double stiffnessTol = 1e-15)

Stress/stiffness objectivity test (“spinning top” test) for hypo-elastic materials.

Applies a sequence of large rigid-body rotations to a material point and verifies that the Cauchy stress and algorithmic tangent remain objective to within the specified tolerances.

Parameters:
  • solver – The hypo-elastic material-point solver to test.

  • stressTol – Tolerance for the stress objectivity check (default: 1e-15).

  • stiffnessTol – Tolerance for the stiffness objectivity check (default: 1e-15).

Returns:

true if the solver passes both checks, false otherwise.

namespace std
file MarmotExceptions.h
#include <stdexcept>
#include <string>

Include dependency graph for MarmotExceptions.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotExceptions.h" tooltip="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotExceptions.h" fillcolor="#BFBFBF"]
    "2" [label="stdexcept" tooltip="stdexcept"]
    "3" [label="string" tooltip="string"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
}
file MarmotJournal.h
#include <iostream>
#include <sstream>
#include <string>

Include dependency graph for MarmotJournal.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotJournal.h" tooltip="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotJournal.h" fillcolor="#BFBFBF"]
    "2" [label="iostream" tooltip="iostream"]
    "3" [label="sstream" tooltip="sstream"]
    "4" [label="string" tooltip="string"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
    "1" -> "4" [dir=forward tooltip="include"]
}
file MarmotStateHelpers.h
#include “Fastor/Fastor.h”
#include “Marmot/MarmotUtils.h
#include <Eigen/Dense>
#include <cstddef>
#include <span>
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>

Include dependency graph for MarmotStateHelpers.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotStateHelpers.h" tooltip="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotStateHelpers.h" fillcolor="#BFBFBF"]
    "3" [label="Marmot/MarmotUtils.h" tooltip="Marmot/MarmotUtils.h"]
    "4" [label="Eigen/Dense" tooltip="Eigen/Dense"]
    "2" [label="Fastor/Fastor.h" tooltip="Fastor/Fastor.h"]
    "5" [label="cstddef" tooltip="cstddef"]
    "6" [label="span" tooltip="span"]
    "7" [label="stdexcept" tooltip="stdexcept"]
    "8" [label="string" tooltip="string"]
    "9" [label="unordered_map" tooltip="unordered_map"]
    "10" [label="vector" tooltip="vector"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
    "1" -> "4" [dir=forward tooltip="include"]
    "1" -> "5" [dir=forward tooltip="include"]
    "1" -> "6" [dir=forward tooltip="include"]
    "1" -> "7" [dir=forward tooltip="include"]
    "1" -> "8" [dir=forward tooltip="include"]
    "1" -> "9" [dir=forward tooltip="include"]
    "1" -> "10" [dir=forward tooltip="include"]
}
file MarmotTesting.h
#include “Marmot/MarmotConstants.h”
#include “Marmot/MarmotMaterialHypoElastic.h”
#include “Marmot/MarmotMaterialPointSolverHypoElastic.h”
#include “autodiff/forward/dual/dual.hpp”
#include “unsupported/Eigen/CXX11/Tensor”
#include <Eigen/Core>
#include <Fastor/Fastor.h>
#include <iostream>

Include dependency graph for MarmotTesting.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotTesting.h" tooltip="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotTesting.h" fillcolor="#BFBFBF"]
    "7" [label="Eigen/Core" tooltip="Eigen/Core"]
    "8" [label="Fastor/Fastor.h" tooltip="Fastor/Fastor.h"]
    "2" [label="Marmot/MarmotConstants.h" tooltip="Marmot/MarmotConstants.h"]
    "3" [label="Marmot/MarmotMaterialHypoElastic.h" tooltip="Marmot/MarmotMaterialHypoElastic.h"]
    "4" [label="Marmot/MarmotMaterialPointSolverHypoElastic.h" tooltip="Marmot/MarmotMaterialPointSolverHypoElastic.h"]
    "5" [label="autodiff/forward/dual/dual.hpp" tooltip="autodiff/forward/dual/dual.hpp"]
    "9" [label="iostream" tooltip="iostream"]
    "6" [label="unsupported/Eigen/CXX11/Tensor" tooltip="unsupported/Eigen/CXX11/Tensor"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
    "1" -> "4" [dir=forward tooltip="include"]
    "1" -> "5" [dir=forward tooltip="include"]
    "1" -> "6" [dir=forward tooltip="include"]
    "1" -> "7" [dir=forward tooltip="include"]
    "1" -> "8" [dir=forward tooltip="include"]
    "1" -> "9" [dir=forward tooltip="include"]
}

Lightweight unit-test helpers for Marmot material and numerical routines.

Provides templated equality checks (checkIfEqual) for scalars, Eigen matrices, Eigen tensors and Fastor tensors, as well as higher-level utilities such as throwExceptionOnFailure, the Fibonacci hemisphere sampler fibonacciLatticeHemisphere, and the spinTurbokreisel material-point test.

file MarmotUtils.h

This graph shows which files directly or indirectly include MarmotUtils.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotStateHelpers.h" tooltip="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotStateHelpers.h"]
    "1" [label="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotUtils.h" tooltip="/home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot/MarmotUtils.h" fillcolor="#BFBFBF"]
    "1" -> "2" [dir=back tooltip="include"]
}
dir /home/runner/work/Marmot/Marmot/modules/core
dir /home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include
dir /home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore/include/Marmot
dir /home/runner/work/Marmot/Marmot/modules/core/MarmotUtilitiesCore
dir /home/runner/work/Marmot/Marmot/modules