suanPan-manual
  • Introduction
  • Basic
    • Obtain Application
    • Configure Application
    • Perform Analysis
    • Model Syntax
    • Model Structure
    • Tweak Performance
    • Compile Application
    • Build Documentation
    • Architecture Design
    • On Clusters
  • Example
    • Developer
      • element template
      • material template
    • Solid
      • wave propagation
    • Geotechnical
      • triaxial compression of sand
      • slope analysis
    • Structural
      • Statics
        • bending of a cantilever beam
        • bifurcation of a cantilever beam
        • double-edge notched specimen
        • lees frame
        • notched beam under cyclic loading
        • rc section analysis
        • truss roof
        • uniform tension of a rubber specimen
        • thin-walled section analysis for frame structures
        • calibration of subloading surface model
      • Dynamics
        • bouncing of a ball
        • mass-spring-dashpot system
        • dynamic analysis of a portal frame
        • elemental damping
        • particle collision
        • response history analysis of an elastic coupled wall
        • multi-support excitation
        • triple pendulum
        • computing response spectrum
        • integrate with python
        • process ground motion
      • Hybrid
        • vibration of a displaced beam
      • Buckling
        • buckling analysis of a cantilever beam
      • Contact
        • contact between beam and block
        • contact in 3d space
      • Optimization
        • evolutionary structural optimization
      • Isogeometric Analysis
        • linear analysis of a single element
    • Miscellaneous
      • batch execution for automation
  • Command Collection
    • Define
      • amplitude
      • bc
      • domain
      • element
      • expression
      • file
      • generate
      • group
      • import
      • initial
      • load
      • material
      • modifier
      • node
      • recorder
      • section
    • Configure
      • analyze
      • converger
      • criterion
      • integrator
      • precheck
      • step
    • Process
      • benchmark
      • clear
      • command
      • enable
      • exit
      • materialtest
      • materialtestbyload
      • sectiontest
      • peek
      • plot
      • protect
      • pwd
      • reset
      • save
      • set
      • upsampling
      • sdof_response
      • response_spectrum
  • Amplitude
    • Amplitude
    • Special
      • NZStrongMotion
    • Universal
      • Combine
      • Constant
      • Decay
      • Linear
      • Modulated
      • Tabular
      • TabularSpline
      • Trig
  • Constraint
    • MPC
    • ParticleCollision
    • RigidWall
    • RestitutionWall
    • FixedLength
    • MaxForce
    • NodeLine
    • NodeFacet
    • Embed2D
    • Embed3D
    • LJPotential2D
    • MaximumGap2D
    • MinimumGap2D
    • MaximumGap3D
    • MinimumGap3D
  • Converger
    • Converger
    • Absolute
      • AbsDisp
      • AbsError
      • AbsIncreDisp
      • AbsIncreAcc
      • AbsIncreEnergy
      • AbsResidual
    • Other
      • FixedNumber
      • Logic
    • Relative
      • RelDisp
      • RelError
      • RelIncreDisp
      • RelIncreAcc
      • RelIncreEnergy
      • RelResidual
  • Criterion
    • Criterion
    • MaxDisplacement
    • MaxHistory
    • MaxResistance
    • MinDisplacement
    • MinResistance
    • StrainEnergyEvolution
  • Element
    • Beam
      • B21
      • B21E
      • B21H
      • B31
      • B31OS
      • EB21
      • EB31OS
      • F21
      • F21H
      • F31
      • NMB21
      • NMB21E
      • NMB31
      • MVLEM
      • Orientation
    • Cube
      • C3D20
      • C3D4
      • C3D8
      • C3D8I
      • CIN3D8
      • DC3D4
      • DC3D8
    • Membrane
      • Couple Stress
      • Phase Field
        • DCP3
        • DCP4
      • Axisymmetric
        • CAX3
        • CAX4
        • CAX8
      • Plane
        • CP3
        • CP4
        • CP4I
        • CP5
        • CP6
        • CP7
        • CP8
      • Mixed
        • PS
        • QE2
      • Drilling
        • Allman
        • GCMQ
        • GQ12
      • Infinite
        • CINP4
      • Geotechnical
        • PCPE4DC
        • PCPE4UC
        • PCPE8DC
        • PCPE8UC
      • Membrane
    • Modifier
      • Modifier
      • ElementalLee
      • ElementalNonviscous
      • LinearViscosity
    • Patch
      • Patch
      • PatchCube
      • PatchQuad
    • Plate
      • DKT3
      • DKT4
      • Mindlin
    • Shell
      • DKTS3
      • DKTS4
      • S4
      • SGCMS
      • ShellBase
    • Special
      • Contact2D
      • Contact3D
      • Damper01
      • Damper02
      • Embedded2D
      • Embedded3D
      • Joint
      • Mass
      • SingleSection
      • Spring01
      • Spring02
      • Tie
      • TranslationConnector
    • Truss
      • T2D2
      • T2D2S
      • T3D2
      • T3D2S
  • Group
    • CustomNodeGroup
    • NodeGroup
    • ElementGroup
    • GroupGroup
  • Integrator
    • Implicit
      • Linear
      • BatheTwoStep
      • GeneralizedAlpha
      • OALTS
      • GSSSS
      • Newmark
        • LeeNewmark
        • LeeElementalNewmark
        • LeeNewmarkFull
        • LeeNewmarkIterative
        • Newmark
        • RayleighNewmark
        • WilsonPenzienNewmark
        • NonviscousNewmark
    • Explicit
      • Tchamwa
      • BatheExplicit
      • GeneralizedAlphaExplicit
  • Material
    • Guide
      • Metal
      • Customisation
    • Material1D
      • Concrete
        • ConcreteCM
        • ConcreteExp
        • ConcreteTsai
        • ConcreteTable
        • ConcreteK4
      • Degradation
        • Degradation
        • CustomStrainDegradation
        • CustomStressDegradation
        • Dhakal
        • TrilinearStrainDegradation
      • Elastic
        • BilinearElastic1D
        • Elastic1D
        • AsymmElastic1D
        • MultilinearElastic1D
        • PolyElastic1D
        • NLE1D01
        • Sinh1D
        • Tanh1D
        • CustomElastic1D
      • Hysteresis
        • AFC
        • AFCN
        • BilinearOO
        • BilinearPO
        • BoucWen
        • BWBN
        • Flag
        • MPF
        • MultilinearOO
        • MultilinearPO
        • RambergOsgood
        • SimpleHysteresis
        • SlipLock
        • SteelBRB
        • Trivial
        • Gap01
      • Viscosity
        • Kelvin
        • Maxwell
        • NonlinearViscosity
        • BilinearViscosity
        • CustomViscosity
        • Viscosity01
        • Viscosity02
        • CoulombFriction
        • Nonviscous01
      • vonMises
        • Subloading1D
        • ArmstrongFrederick1D
        • AFCO1D
        • Bilinear1D
        • BilinearMises1D
        • CustomGurson1D
        • CustomMises1D
        • ExpGurson1D
        • ExpMises1D
        • Mises1D
        • Multilinear1D
        • NonlinearGurson1D
        • VAFCRP1D
    • Material2D
      • AxisymmetricElastic
      • Concrete21
      • Concrete22
      • DuncanSelig
      • Elastic2D
      • Rebar2D
    • Material3D
      • CamClay
        • BilinearCC
        • ExpCC
        • NonlinearCamClay
        • ParabolicCC
      • Concrete
        • CDP
        • CDPM2
        • Rebar3D
        • TableCDP
        • CustomCDP
      • Damage
        • IsotropicDamage
        • LinearDamage
      • DruckerPrager
        • BilinearDP
        • ExpDP
        • CustomDP
        • NonlinearDruckerPrager
      • Elastic
        • BlatzKo
        • IsotropicElastic3D
        • IsotropicNonlinearElastic3D
        • MooneyRivlin
        • NLE3D01
        • OrthotropicElastic3D
        • Yeoh
      • Hoffman
        • BilinearHoffman
        • ExpHoffman
        • CustomHoffman
        • NonlinearHill
        • NonlinearHoffman
        • TimberPD
      • Sand
        • SimpleSand
        • DafalisaManzari
      • vonMises
        • ArmstrongFrederick
        • BilinearJ2
        • BilinearPeric
        • CustomGurson
        • TableGurson
        • CustomJ2
        • ExpGurson
        • ExpJ2
        • MultilinearJ2
        • NonlinearGurson
        • NonlinearJ2
        • NonlinearPeric
        • PolyJ2
        • VAFCRP
        • Subloading
    • MaterialOS
      • ElasticOS
    • Wrapper
      • Axisymmetric
      • Laminated
      • Parallel
      • PlaneStrain
      • PlaneSymmetric
      • PlaneStress
      • Rotation2D
      • Rotation3D
      • Sequential
      • Stacked
      • Uniaxial
      • OS146
      • OS146S
      • Substepping
  • Recorder
    • Recorder
    • OutputType
  • Section
    • Code
      • EU
      • NZ
      • US
    • Section1D
      • Circle1D
      • Fibre1D
      • Rectangle1D
      • TrussSection
    • Section2D
      • Bar2D
      • Box2D
      • Circle2D
      • CircularHollow2D
      • Fibre2D
      • HSection2D
      • ISection2D
      • Rectangle2D
      • TSection2D
    • Section3D
      • Bar3D
      • Box3D
      • Circle3D
      • CircularHollow3D
      • Fibre3D
      • ISection3D
      • Rectangle3D
      • TSection3D
    • SectionOS
      • Cell3DOS
      • Fibre3DOS
    • SectionNM
      • SectionNM
      • NM2D1
      • NM2D2
      • NM2D3
      • NM2D3K
      • NM3D1
      • NM3D2
      • NM3D3
      • NM3D3K
  • Solver
    • BFGS
    • MPDC
    • Newton
    • AICN
    • Ramm
  • Step
    • Overview
    • ArcLength
    • Buckle
    • Dynamic
    • Frequency
    • Optimization
    • Static
  • Developer
    • Prerequisites
    • C Style Interface
      • material
    • CPP Style Interface
      • material
      • element
      • constraint
Powered by GitBook
On this page
Edit on GitHub
  1. Example
  2. Developer

material template

Here we show the build-in material template.

/**
 * @class MaterialExample
 * @brief A MaterialExample material class.
 * @author tlc
 * @date 06/07/2018
 * @version 0.2.0
 * @file MaterialExample.h
 * @addtogroup Material-1D
 * @ingroup Material
 * @{
 */

#ifndef MATERIALEXAMPLE_H
#define MATERIALEXAMPLE_H

#include <Material/Material.h>

/**
 * \brief It is recommended to store data, especially constant data, in a simple
 * structure. The motivation is to obtain a clear interface so that store and recover
 * of objects will be easier.
 */
struct MaterialExampleData {
 const double elastic_modulus; // elastic modulus
 const double yield_stress;    // initial yield stress
 const double hardening_ratio; // hardening ratio
 const double beta;            // isotropic/kinematic hardening factor
 const double plastic_modulus; // plastic modulus
};

class MaterialExample final : MaterialExampleData, public Material {
 double current_back_stress = 0.;
 double current_plastic_strain = 0.;
 double trial_back_stress = 0.;
 double trial_plastic_strain = 0.;
public:
 explicit MaterialExample(unsigned = 0,  // tag
                          double = 2E5,  // elastic modulus
                          double = 400., // initial yield stress
                          double = .05,  // hardening ratio
                          double = 0.,   // isotropic/kinematic hardening factor
                          double = 0.    // density
 );

 void initialize(const shared_ptr<DomainBase>&) override;

 unique_ptr<Material> get_copy() override;

 int update_trial_status(const vec&) override;

 int clear_status() override;
 int commit_status() override;
 int reset_status() override;

 void print() override;
};

#endif
#include "MaterialExample.h"

/**
 * \brief The constructor of material model depends on the specific model to be
 * implemented. But for the base `Material` class, it takes only three input arguments:
 *
 * - Unique Material Tag
 * - Material Type
 * - Density
 *
 * Here we are implementing a uniaxial bilinear hardening model, hence `MaterialType::D1`
 * is passed to the base. The material type will be used to validate with associated
 * elements/sections to ensure the consistency of the sizes of data passed between objects.
 * 
 * \param T Unique Material Tag
 * \param E Elastic Modulus
 * \param Y Yield Stress
 * \param H Hardening Ratio
 * \param B Beta
 * \param R Density
 */
MaterialExample::MaterialExample(const unsigned T, const double E, const double Y, const double H, const double B, const double R)
 : MaterialExampleData{E, Y, H, B, E * H / (1. - H)}
 , Material(T, MaterialType::D1, R) {}

/**
 * \brief Unless the target material model involves other material models to compute
 * responses, in general, it is not necessary to get additional information from
 * other parts of the model.
 *
 * In general cases, history variables shall be initialised and initial stiffness
 * (and initial damping if appropriate) shall be set to proper value.
 *
 * To enable initial values for history variables, build-in `trial_history` and
 * `current_history` shall be used, developers can initialise them via method
 * `initialise_history()` so that initial values set by `initial` command will not be
 * overwritten.
 *
 * In this example, instead of using build-in history variables, we manage history
 * variables, namely back stress and plastic strain, by ourselves.
 * 
 */
void MaterialExample::initialize(const shared_ptr<DomainBase>&) {
 current_back_stress = trial_back_stress = 0.;
 current_plastic_strain = trial_plastic_strain = 0.;

 trial_stiffness = current_stiffness = initial_stiffness = elastic_modulus;
}

/**
 * \brief The `get_copy()` method should always be implemented with `make_unique`.
 * In case the model defines other memory management, developers may need to further
 * provide a copy ctor to make `make_unique` work.
 * 
 * **!!!NEVER DO A MANUAL COPY OF DATA IN THIS METHOD!!!**
 * 
 * \return a copy of material model
 */
unique_ptr<Material> MaterialExample::get_copy() { return make_unique<MaterialExample>(*this); }

/**
 * \brief There are two states we are managing at any time point.
 * The current state is the converged state from the last time substep. Since it is
 * converged, all data shall be valid and accurate.
 * The trial state stores the response computed based on converged state and new trial
 * strain. It may be discarded, committed or overwritten with new trial values.
 *
 * **WE ALWAYS COMPUTE TRIAL STATE BASED ON CURRENT STATE AND NEW TRIAL STRAIN**
 * **NEVER COMPUTE RESPONSE BASED ON ANY INFORMATION FROM UNCONVERGED STATE**
 *
 * Developers who are not familiar with classic plasticity theory may consult textbooks
 * for details.
 * 
 * \param t_strain trial strain
 * \return error flag
 */
int MaterialExample::update_trial_status(const vec& t_strain) {
 trial_strain = t_strain;
 incre_strain = trial_strain - current_strain;

 if(fabs(incre_strain(0)) <= tolerance) return 0;

 trial_back_stress = current_back_stress;
 trial_plastic_strain = current_plastic_strain;
 trial_stiffness = initial_stiffness;

 trial_stress = current_stress + elastic_modulus * incre_strain;

 const auto shifted_stress = trial_stress(0) - current_back_stress;

 const auto yield_func = fabs(shifted_stress) - yield_stress - (1. - beta) * plastic_modulus * current_plastic_strain;

 if(yield_func > 0.) {
  const auto incre_plastic_strain = yield_func / (elastic_modulus + plastic_modulus);
  trial_stress -= suanpan::sign(shifted_stress) * elastic_modulus * incre_plastic_strain;
  trial_stiffness *= hardening_ratio;
  trial_back_stress += suanpan::sign(shifted_stress) * beta * plastic_modulus * incre_plastic_strain;
  trial_plastic_strain += incre_plastic_strain;
 }

 return 0;
}

/**
 * \brief Operations are required to achieve the following objective.
 *
 * current state -> 0
 * trial state -> 0
 * 
 * \return error flag
 */
int MaterialExample::clear_status() {
 current_strain.zeros();
 current_stress.zeros();
 current_stiffness = initial_stiffness;
 current_back_stress = 0.;
 current_plastic_strain = 0.;
 return reset_status();
}

/**
 * \brief Operations are required to achieve the following objective.
 *
 * current state <- trial state
 * 
 * \return error flag
 */
int MaterialExample::commit_status() {
 current_strain = trial_strain;
 current_stress = trial_stress;
 current_stiffness = trial_stiffness;
 current_back_stress = trial_back_stress;
 current_plastic_strain = trial_plastic_strain;
 return 0;
}

/**
 * \brief Operations are required to achieve the following objective.
 *
 * current state -> trial state
 * 
 * \return error flag
 */
int MaterialExample::reset_status() {
 trial_strain = current_strain;
 trial_stress = current_stress;
 trial_stiffness = current_stiffness;
 trial_back_stress = current_back_stress;
 trial_plastic_strain = current_plastic_strain;
 return 0;
}

void MaterialExample::print() {
 suanpan_info("A material example based on uniaxial J2 bilinear mixed hardening model.\n");
 suanpan_info("current strain: %.5E\tcurrent stress: %.5E.\n", current_strain.at(0), current_stress.at(0));
}
Previouselement templateNextSolid

Last updated 3 years ago