keyword
stringclasses
7 values
repo_name
stringlengths
8
98
file_path
stringlengths
4
244
file_extension
stringclasses
29 values
file_size
int64
0
84.1M
line_count
int64
0
1.6M
content
stringlengths
1
84.1M
language
stringclasses
14 values
3D
febiosoftware/FEBio
FEBioMech/FEEdgeToSurfaceSlidingContact.h
.h
4,330
149
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FESurfaceConstraint.h> #include <FECore/FEEdge.h> #include "FEContactSurface.h" #include <set> //======================================================================================= class FEE2SSlidingContactPoint : public FELineMaterialPoint { public: double m_gap = 0.0; double m_Ln = 0.0; //!< Lagrange multipliers for contact pressure double m_Lm = 0.0; //!< Lagrange multipliers for contact pressure vec3d m_nu; //!< secondary surface normal at primary surface node vec2d m_rs; //!< natural coordinates of primary surface projection on secondary surface element FESurfaceElement* m_pme = nullptr; void Serialize(DumpStream& ar) override { FELineMaterialPoint::Serialize(ar); ar & m_gap & m_Ln & m_Lm & m_nu & m_rs; } void Init() override { FELineMaterialPoint::Init(); m_gap = 0.0; m_Ln = 0.0; m_Lm = 0.0; m_nu = vec3d(0, 0, 0); m_rs = vec2d(0, 0); m_pme = nullptr; } }; //======================================================================================= class FEEdgeToSurfaceSlidingContactSurface : public FEContactSurface { public: FEEdgeToSurfaceSlidingContactSurface(FEModel* fem); void Update(); }; //======================================================================================= class FEEdgeToSurfaceSlidingContactEdge : public FEEdge { public: FEEdgeToSurfaceSlidingContactEdge(FEModel* fem); FEMaterialPoint* CreateMaterialPoint() override; bool Init() override; void Update(); bool Create(FESegmentSet& eset) override; void UnpackLM(FELineElement& el, vector<int>& lm); void Serialize(DumpStream& ar); public: int m_dofX = -1; int m_dofY = -1; int m_dofZ = -1; vector<FEE2SSlidingContactPoint> m_points; //!< sliding contact surface data }; //======================================================================================= class FEEdgeToSurfaceSlidingContact : public FESurfaceConstraint { public: FEEdgeToSurfaceSlidingContact(FEModel* fem); public: //! return the surface FESurface* GetSurface() override; // Build the matrix profile void BuildMatrixProfile(FEGlobalMatrix& M) override; // update void Update() override; // init bool Init() override; // serialization void Serialize(DumpStream& ar) override; public: // The LoadVector function evaluates the "forces" that contribute to the residual of the system void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; // Evaluates the contriubtion to the stiffness matrix void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; protected: void ProjectSurface(bool bupseg, bool bmove = false); void ContactNodalForce(int m, FESurfaceElement& mel, vector<double>& fe); void ContactNodalStiffness(int m, FESurfaceElement& mel, matrix& ke); protected: FEEdgeToSurfaceSlidingContactEdge m_edge; FEEdgeToSurfaceSlidingContactSurface m_surf; protected: double m_atol; double m_eps; int m_naugmin; int m_naugmax; double m_stol; int m_nsegup; double m_sradius; bool m_bfirst; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FERigidSphericalJoint.h
.h
4,764
125
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECore/vec3d.h" #include "FERigidConnector.h" #include "febiomech_api.h" //----------------------------------------------------------------------------- //! The FERigidSphericalJoint class implements a rigid spherical joint that //! functions under static and dynamic conditions. This joint allows the //! user to connect two rigid bodies at a point in space. class FEBIOMECH_API FERigidSphericalJoint : public FERigidConnector { public: //! constructor FERigidSphericalJoint(FEModel* pfem); //! destructor virtual ~FERigidSphericalJoint() {} //! initialization bool Init() override; //! calculates the joint forces void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! calculates the joint stiffness void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! calculate Lagrangian augmentation bool Augment(int naug, const FETimeInfo& tp) override; //! serialize data to archive void Serialize(DumpStream& ar) override; //! update state void Update() override; //! Reset data void Reset() override; //! evaluate relative translation vec3d RelativeTranslation(const bool global = false) override; //! evaluate relative rotation vec3d RelativeRotation(const bool global = false) override; //! initial position vec3d InitialPosition() const; //! current position vec3d Position() const; private: // lag. mult. methods int InitEquations(int neq) override; void BuildMatrixProfile(FEGlobalMatrix& M) override; void UnpackLM(vector<int>& lm); void PrepStep(); void Update(const std::vector<double>& Ui, const std::vector<double>& ui) override; void UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) override; public: // parameters int m_laugon; //!< enforcement method double m_atol; //! augmented Lagrangian tolerance double m_gtol; //! augmented Lagrangian gap tolerance double m_qtol; //! augmented Lagrangian angular gap tolerance double m_eps; //! penalty factor for constraining force double m_ups; //! penalty factor for constraining moment vec3d m_q0; //! initial position of joint int m_naugmin; //! minimum number of augmentations int m_naugmax; //! maximum number of augmentations bool m_bq; //! flag for prescribing rotation double m_qpx; //! prescribed rotation x-component double m_qpy; //! prescribed rotation y-component double m_qpz; //! prescribed rotation z-component double m_Mpx; //! prescribed moment along x double m_Mpy; //! prescribed moment along y double m_Mpz; //! prescribed moment along z bool m_bautopen; //!< auto-penalty for gap and ang tolerance protected: vec3d m_qa0; //! initial relative position vector of joint w.r.t. A vec3d m_qb0; //! initial relative position vector of joint w.r.t. B vec3d m_e0[3]; //! initial joint basis vec3d m_ea0[3]; //! initial joint basis w.r.t. A vec3d m_eb0[3]; //! initial joint basis w.r.t. B vec3d m_L; //! Lagrange multiplier for constraining force vec3d m_U; //! Lagrange multiplier for constraining moment vec3d m_Fp; vector<int> m_LM; // Lagrange multiplier equation numbers DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEReactivePlasticDamageMaterialPoint.h
.h
4,008
80
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2019 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEDamageMaterialPoint.h" #include "FEReactivePlasticDamage.h" #include <vector> class FEReactivePlasticDamage; //----------------------------------------------------------------------------- // Define a material point that stores the damage and plasticity variables. class FEReactivePlasticDamageMaterialPoint : public FEDamageMaterialPoint { public: //! constructor FEReactivePlasticDamageMaterialPoint(FEMaterialPointData *pt, FEReactivePlasticDamage* pmat) : FEDamageMaterialPoint(pt) { m_pMat = pmat; } FEMaterialPointData* Copy() override; //! Initialize material point data void Init() override; //! Update material point data void Update(const FETimeInfo& timeInfo) override; //! Serialize data to archive void Serialize(DumpStream& ar) override; //! Evaluate net mass fraction of yielded bonds double YieldedBonds() const override; // evaluate net mass fraction of intact bonds double IntactBonds() const override; public: vector<mat3d> m_Fusi; //!< inverse of plastic deformation gradient at previous yield vector<mat3d> m_Fvsi; //!< trial value of plastic deformation gradient at current yield vector<double> m_Kv; //!< value of yield measure at current yield vector<double> m_Ku; //!< value of yield measure at previous yield vector<double> m_gp; //!< current value of octahedral plastic shear strain vector<double> m_gpp; //!< previous value of octahedral plastic shear strain vector<double> m_gc; //!< cumulative value of octahedral plastic shear strain mat3d m_Fp; //!< deformation gradient at previous time double m_Rhat; //!< reactive heat supply density vector<double> m_wy; //!< mass fraction of yielded bonds vector<double> m_Eyt; //!< trial yield damage criterion at current time vector<double> m_Eym; //!< max yield damage criterion up to current time vector<double> m_di; //!< individual family intact damage (0 = no damage, 1 = complete damage) vector<double> m_dy; //!< individual family yield damage (0 = no damage, 1 = complete damage) vector<double> m_d; //!< total damage for individual family (0 = no damage, 1 = complete damage) vector<bool> m_byld; //!< flag on which bonds have already yielded at start of current time vector<bool> m_byldt; //!< trial value of m_byld FEReactivePlasticDamage* m_pMat; //!< parent material };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEDiscreteElementMaterial.cpp
.cpp
5,325
190
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEDiscreteElementMaterial.h" #include <FECore/FEModel.h> BEGIN_FECORE_CLASS(FEDiscreteContractileMaterial, FEDiscreteElasticMaterial) ADD_PARAMETER(m_Vmax, "Vmax" ); ADD_PARAMETER(m_ac , "ac" ); ADD_PARAMETER(m_Fmax, "Fmax"); ADD_PARAMETER(m_Ksh , "Ksh" ); ADD_PARAMETER(m_Lmax, "Lmax"); ADD_PARAMETER(m_L0 , "L0" ); ADD_PROPERTY(m_Sv , "Sv" , FEProperty::Optional); ADD_PROPERTY(m_Ftl, "Ftl", FEProperty::Optional); ADD_PROPERTY(m_Ftv, "Fvl", FEProperty::Optional); END_FECORE_CLASS(); FEDiscreteContractileMaterial::FEDiscreteContractileMaterial(FEModel* fem) : FEDiscreteElasticMaterial(fem) { m_Vmax = 1.0; m_ac = 0.0; m_Fmax = 1.0; m_L0 = 0.0; m_Ksh = 1.0; m_Lmax = 1.0; m_Sv = nullptr; m_Ftl = nullptr; m_Ftv = nullptr; } double FEDiscreteContractileMaterial::passive_force(double L, double V) { return (L > 1.0 ? m_Fmax * ((exp(m_Ksh*(L - 1.0) / m_Lmax) - 1.0) / (exp(m_Ksh) - 1.0)) : 0.0); } double FEDiscreteContractileMaterial::passive_force_deriv_L(double L, double V) { if (L < 1.0) return 0.0; double dF = (m_Fmax / (exp(m_Ksh) - 1.0)) * ((m_Ksh / m_Lmax)*(exp(m_Ksh*(L - 1.0) / m_Lmax))); return dF; } double FEDiscreteContractileMaterial::passive_force_deriv_V(double L, double V) { return 0.0; } double FEDiscreteContractileMaterial::active_force(double L, double V) { double Ftl = (m_Ftl ? m_Ftl->value(L) : 1.0); double Ftv = (m_Ftv ? m_Ftv->value(V) : 1.0); return m_ac*m_Fmax*Ftl*Ftv; } double FEDiscreteContractileMaterial::active_force_deriv_L(double L, double V) { double dFtl = (m_Ftl ? m_Ftl->derive(L) : 0.0); double Ftv = (m_Ftv ? m_Ftv->value(V) : 1.0); return m_ac*m_Fmax*dFtl*Ftv; } double FEDiscreteContractileMaterial::active_force_deriv_V(double L, double V) { double Ftl = (m_Ftl ? m_Ftl->value(L) : 1.0); double dFtv = (m_Ftv ? m_Ftv->derive(V) : 0.0); return m_ac*m_Fmax*Ftl*dFtv; } double FEDiscreteContractileMaterial::force_deriv_L(FEDiscreteMaterialPoint& mp) { vec3d e0 = mp.m_dr0; double L0 = e0.unit(); vec3d et = mp.m_drt; double Lm = et.unit(); if (m_L0 != 0.0) L0 = m_L0; // stretch double L = Lm / L0; // normalized velocity double Vm = mp.m_dvt*et; double Sv = (m_Sv ? m_Sv->value(m_ac) : 1.0); double V = Vm / (m_Vmax * Sv); return passive_force_deriv_L(L, V)/L0 + active_force_deriv_L(L, V)/L0; } double FEDiscreteContractileMaterial::force_deriv_V(FEDiscreteMaterialPoint& mp) { vec3d e0 = mp.m_dr0; double L0 = e0.unit(); vec3d et = mp.m_drt; double Lm = et.unit(); if (m_L0 != 0.0) L0 = m_L0; // stretch double L = Lm / L0; // normalized velocity double Vm = mp.m_dvt*et; double Sv = (m_Sv ? m_Sv->value(m_ac) : 1.0); double V = Vm / (m_Vmax * Sv); return passive_force_deriv_V(L, V) / (m_Vmax * Sv) + active_force_deriv_V(L, V) / (m_Vmax * Sv); } double FEDiscreteContractileMaterial::force(FEDiscreteMaterialPoint& mp) { vec3d e0 = mp.m_dr0; double L0 = e0.unit(); vec3d et = mp.m_drt; double Lm = et.unit(); if (m_L0 != 0.0) L0 = m_L0; // stretch double L = Lm / L0; // normalized velocity double Vm = mp.m_dvt*et; double Sv = (m_Sv ? m_Sv->value(m_ac) : 1.0); double V = Vm / (m_Vmax * Sv); // passive element double Fp = passive_force(L, V); // active element double Fc = active_force(L, V); // add them up together double F = Fp + Fc; // return return F; } // evaluate the force at a discrete element vec3d FEDiscreteContractileMaterial::Force(FEDiscreteMaterialPoint& mp) { vec3d e = mp.m_drt; e.unit(); double F = force(mp); return e*F; } // evaluate the stiffness at a discrete element (= dF / dr) mat3d FEDiscreteContractileMaterial::Stiffness(FEDiscreteMaterialPoint& mp) { double F = force(mp); vec3d e = mp.m_drt; double L = e.unit(); mat3ds exe = dyad(e); mat3dd I(1.0); mat3ds E = (I - exe)/L; vec3d v = mp.m_dvt; double V = mp.m_dvt * e; double Fl = force_deriv_L(mp); double Fv = force_deriv_V(mp); double dt = GetFEModel()->GetTime().timeIncrement; vec3d f = e*(-Fl) - (e/dt + v/L + e*(L*V))*Fv; return E*F - (e & f); }
C++
3D
febiosoftware/FEBio
FEBioMech/FEGrowthTensor.h
.h
5,138
167
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2019 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticFiberMaterial.h" #include "FEFiberMaterial.h" #include "febiomech_api.h" //----------------------------------------------------------------------------- //! Base class for growth tensors. //! class FEBIOMECH_API FEGrowthTensor : public FEMaterialProperty { public: FECORE_BASE_CLASS(FEGrowthTensor); public: FEGrowthTensor(FEModel* pfem); virtual ~FEGrowthTensor(); //! growth tensor virtual mat3d GrowthTensor(FEMaterialPoint& pt, const vec3d& a0) = 0; //! inverse of growth tensor virtual mat3d GrowthTensorInverse(FEMaterialPoint& pt, const vec3d& a0) = 0; //! referential solid density virtual double GrowthDensity(FEMaterialPoint& pt, const vec3d& a0) = 0; //! initialize bool Init() override; public: FEVec3dValuator* m_fiber; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! Volume growth //! class FEVolumeGrowth : public FEGrowthTensor { public: FEVolumeGrowth(FEModel* pfem) : FEGrowthTensor(pfem) { m_gm = 1; } virtual ~FEVolumeGrowth(){} //! growth tensor mat3d GrowthTensor(FEMaterialPoint& pt, const vec3d& a0) override; //! inverse of growth tensor mat3d GrowthTensorInverse(FEMaterialPoint& pt, const vec3d& a0) override; //! referential solid density double GrowthDensity(FEMaterialPoint& pt, const vec3d& a0) override; public: FEParamDouble m_gm; //! isotropic growth multiplier // declare the parameter list DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! Area growth //! class FEAreaGrowth : public FEGrowthTensor { public: FEAreaGrowth(FEModel* pfem) : FEGrowthTensor(pfem) { m_gm = 1; } virtual ~FEAreaGrowth(){} //! growth tensor mat3d GrowthTensor(FEMaterialPoint& pt, const vec3d& a0) override; //! inverse of growth tensor mat3d GrowthTensorInverse(FEMaterialPoint& pt, const vec3d& a0) override; //! referential solid density double GrowthDensity(FEMaterialPoint& pt, const vec3d& a0) override; public: FEParamDouble m_gm; //! growth multiplier // declare the parameter list DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! Fiber growth //! class FEFiberGrowth : public FEGrowthTensor { public: FEFiberGrowth(FEModel* pfem) : FEGrowthTensor(pfem) { m_gm = 1; } virtual ~FEFiberGrowth(){} //! growth tensor mat3d GrowthTensor(FEMaterialPoint& pt, const vec3d& a0) override; //! inverse of growth tensor mat3d GrowthTensorInverse(FEMaterialPoint& pt, const vec3d& a0) override; //! referential solid density double GrowthDensity(FEMaterialPoint& pt, const vec3d& a0) override; public: FEParamDouble m_gm; //! growth multiplier // declare the parameter list DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! General growth //! class FEGeneralGrowth : public FEGrowthTensor { public: FEGeneralGrowth(FEModel* pfem) : FEGrowthTensor(pfem) { m_gi = 1; m_ga = 1; } virtual ~FEGeneralGrowth(){} //! growth tensor mat3d GrowthTensor(FEMaterialPoint& pt, const vec3d& a0) override; //! inverse of growth tensor mat3d GrowthTensorInverse(FEMaterialPoint& pt, const vec3d& a0) override; //! referential solid density double GrowthDensity(FEMaterialPoint& pt, const vec3d& a0) override; public: FEParamDouble m_gi; //! growth multiplier for isotropic growth FEParamDouble m_ga; //! growth multiplier for anisotropic growth // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEIsotropicElastic.cpp
.cpp
4,418
149
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEIsotropicElastic.h" //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEIsotropicElastic, FEElasticMaterial) ADD_PARAMETER(m_E, FE_RANGE_GREATER(0.0), "E")->setUnits(UNIT_PRESSURE)->setLongName("Young's modulus"); ADD_PARAMETER(m_v, FE_RANGE_RIGHT_OPEN(-1.0, 0.5), "v")->setLongName("Poisson's ratio"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- mat3ds FEIsotropicElastic::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3d &F = pt.m_F; double Ji = 1.0 / pt.m_J; double E = m_E(mp); double v = m_v(mp); // lame parameters double lam = Ji*(v*E/((1+v)*(1-2*v))); double mu = Ji*(0.5*E/(1+v)); // calculate left Cauchy-Green tensor (ie. b-matrix) mat3ds b = pt.LeftCauchyGreen(); // calculate trace of Green-Lagrance strain tensor double trE = 0.5*(b.tr()-3); // calculate square of b-matrix // (we commented out the matrix components we do not need) mat3ds b2 = b.sqr(); // calculate stress mat3ds s = b*(lam*trE - mu) + b2*mu; return s; } //----------------------------------------------------------------------------- tens4ds FEIsotropicElastic::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); double E = m_E(mp); double v = m_v(mp); // deformation gradient mat3d& F = pt.m_F; double Ji = 1.0 / pt.m_J; // lame parameters double lam = Ji*(v*E/((1+v)*(1-2*v))); double mu = Ji*(0.5*E/(1+v)); // left cauchy-green matrix (i.e. the 'b' matrix) mat3ds b = pt.LeftCauchyGreen(); return dyad1s(b)*lam + dyad4s(b)*(2.0*mu); } //----------------------------------------------------------------------------- double FEIsotropicElastic::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); double mE = m_E(mp); double mv = m_v(mp); mat3ds E = (pt.RightCauchyGreen() - mat3dd(1))/2; double lam = mv*mE/((1+mv)*(1-2*mv)); double mu = 0.5*mE/(1+mv); double trE = E.tr(); double Enorm = E.norm(); double sed = lam*trE*trE/2 + mu*Enorm*Enorm; return sed; } //----------------------------------------------------------------------------- mat3ds FEIsotropicElastic::PK2Stress(FEMaterialPoint& pt, const mat3ds E) { double mE = m_E(pt); double mv = m_v(pt); // lame parameters double lam = (mv*mE/((1+mv)*(1-2*mv))); double mu = (0.5*mE/(1+mv)); // Identity mat3dd I(1); // calculate stress mat3ds S = I*(E.tr()*lam) + E*(2*mu); return S; } //----------------------------------------------------------------------------- tens4dmm FEIsotropicElastic::MaterialTangent(FEMaterialPoint& pt, const mat3ds E) { double mE = m_E(pt); double mv = m_v(pt); // lame parameters double lam = (mv*mE/((1+mv)*(1-2*mv))); double mu = (0.5*mE/(1+mv)); // Identity mat3dd I(1); tens4dmm c = dyad1s(I)*lam + dyad4s(I)*(2*mu); return c; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEABUnconstrained.cpp
.cpp
14,188
333
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2019 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "FECore/stdafx.h" #include "FEABUnconstrained.h" #include <iostream> #include <typeinfo> using namespace std; BEGIN_FECORE_CLASS(FEABUnconstrained, FEElasticMaterial); ADD_PARAMETER(m_ksi, FE_RANGE_GREATER(0.0), "ksi"); ADD_PARAMETER(m_N, FE_RANGE_GREATER(0.0), "N"); ADD_PARAMETER(m_term, FE_RANGE_CLOSED(3,30), "n_term"); ADD_PARAMETER(m_kappa, FE_RANGE_GREATER(0.0), "kappa"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FEABUnconstrained::FEABUnconstrained(FEModel* pfem) : FEElasticMaterial(pfem) { m_N = 100.0; m_ksi = 0.00001; m_kappa = 0.0; m_term = 30; m_eps = 1e-12; } //----------------------------------------------------------------------------- void FEABUnconstrained::EigenValues(mat3ds& A, double l[3], vec3d r[3], const double eps) { A.eigen(l, r); // correct for numerical inaccuracy double d01 = fabs(l[0] - l[1]); double d12 = fabs(l[1] - l[2]); double d02 = fabs(l[0] - l[2]); if (d01 < eps) l[1] = l[0]; //= 0.5*(l[0]+l[1]); if (d02 < eps) l[2] = l[0]; //= 0.5*(l[0]+l[2]); if (d12 < eps) l[2] = l[1]; //= 0.5*(l[1]+l[2]); } //----------------------------------------------------------------------------- //! Calculates the Cauchy stress mat3ds FEABUnconstrained::Stress(FEMaterialPoint& mp) { double ksi = m_ksi(mp); double kappa = m_kappa(mp); // extract elastic material data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; // get the left Cauchy-Green tensor mat3ds b = pt.LeftCauchyGreen(); // get the eigenvalues and eigenvectors of b double lam2[3]; // these are the squares of the eigenvalues of V vec3d ev[3]; EigenValues(b, lam2, ev, m_eps); // get the eigenvalues of V double lam[3]; mat3ds N[3]; for (int i = 0; i < 3; ++i) { lam[i] = sqrt(lam2[i]); N[i] = dyad(ev[i]); } // Invariants of b double I1 = b.tr(); // stress mat3ds s; s.zero(); const double f_a[] = { 3.0, 9.0 / 5.0, 297.0 / 175.0, 1539.0 / 875.0, 126117.0 / 67373.0, 43733439.0 / 21896875.0, \ 231321177.0 / 109484375.0, 20495009043.0 / 9306171875.0, 1073585186448381.0 / 476522530859375.0, 4387445039583.0 / 1944989921875.0, \ 1000263375846831627.0 / 453346207767578125.0, 280865021365240713.0 / 133337119931640625.0, 148014872740758343473.0 / 75350125192138671875.0, 137372931237386537808993.0 / 76480377070020751953125.0, \ 41722474198742657618857192737.0 / 25674386102028896409912109375.0, 12348948373636682700768301125723.0 / 8344175483159391333221435546875.0, 5001286000741585238340074032091091.0 / 3590449627018291035442047119140625.0, \ 185364329915163811141785118512534489.0 / 132846636199676768311355743408203125.0, 6292216384025878939310787532157558451.0 / 4160197291516193533960877227783203125.0, 299869254759556271677902570230858640837.0 / 170568088952163934892395966339111328125.0, \ 316689568216860631885141475537178451746044283.0 / 148810301691076651811854156590061187744140625.0, 670194310437429598283653289122392937145371137.0 / 258140319260030926612400067554187774658203125.0, 19697015384373759058671314622426656486031717197919.0 / 6332687088594936951180328352888571262359619140625.0, \ 178793788985653424246012689916144867915861856840849.0 / 49756827124674504616416865629838774204254150390625.0, 323844166067349737493036492206152479344269351967043143667.0 / 82039106319990447886052744467343800746748447418212890625.0, 200808116689754604893460969866238617668631975356485302537199.0 / 49409916306357883385918130190559334540655314922332763671875.0, \ 27506481209689719715275759452624078040221544551995885750037973.0 / 7164437864421893090958128877631103508395020663738250732421875.0, 16356939619211770477227805130221533318985185730316048281126247721.0 / 5122573073061653560035062147506239008502439774572849273681640625.0, 30976199222209837888906735596203249520053107250807132769871859115868101.0 / 14801698741072505317694781203956860833766632412399612367153167724609375.0, \ 519588001407316958447129785511020819131555326399179970047767492196701159.0 / 902903623205422824379381653441368510859764577156376354396343231201171875.0 }; double alpha = sqrt(I1) / sqrt(3.0 * m_N); double alpha0 = 1.0 / sqrt(m_N); /////////////////////////////// double beta = 0, beta0 = 0, alpha2 = alpha * alpha, alpha02 = alpha0 * alpha0; int num_fa = sizeof(f_a) / sizeof(f_a[0]); if (m_term > num_fa) { m_term = num_fa; } beta = 1 + f_a[m_term - 1] / f_a[m_term - 2] * alpha2; beta0 = 1 + f_a[m_term - 1] / f_a[m_term - 2] * alpha02; for (int i = 2; i < m_term; i++) { beta = 1 + f_a[m_term - i] / f_a[m_term - i - 1] * alpha2 * beta; beta0 = 1 + f_a[m_term - i] / f_a[m_term - i - 1] * alpha02 * beta0; }; beta = f_a[0] * alpha * beta; beta0 = f_a[0] * alpha0 * beta0; //////////////////////////////// double WI = ksi * m_N * (beta / sqrt(I1) / 2.0 / sqrt(3.0 * m_N)); double W1[3]; double T[3], T_NH[3]; double I1_1[3]; double W10 = ksi * m_N * (beta0 / sqrt(3.0) / 2.0 / sqrt(3.0 * m_N)) * 2.0; ///////////////////////////////////////////////////////////////////// double aaaI = exp((I1) / 3 - 1); //Simple //double TCom = kappa * log(J) / J; //NH Term double TCom = kappa * (J * J - 1) / J; //NH Term for (int i = 0; i < 3; ++i) { I1_1[i] = 2 * lam[i]; W1[i] = WI * I1_1[i] - W10 / lam[i]; T[i] = lam[i] * W1[i] / J; T[i] += TCom; //NH Term s += N[i] * T[i]; } return s; } //----------------------------------------------------------------------------- //! Calculates the spatial tangent tens4ds FEABUnconstrained::Tangent(FEMaterialPoint& mp) { double ksi = m_ksi(mp); double kappa = m_kappa(mp); int i, j; // extract elastic material data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; // get the left Cauchy-Green tensor mat3ds b = pt.LeftCauchyGreen(); // Invariants of b double I1 = b.tr(); // get the eigenvalues and eigenvectors of b double lam2[3]; // these are the squares of the eigenvalues of V vec3d ev[3]; EigenValues(b, lam2, ev, m_eps); // get the eigenvalues of V double lam[3]; mat3ds N[3]; for (i = 0; i < 3; ++i) { lam[i] = sqrt(lam2[i]); N[i] = dyad(ev[i]); } // principal stresses mat3ds s; s.zero(); const double f_a[] = { 3.0, 9.0 / 5.0, 297.0 / 175.0, 1539.0 / 875.0, 126117.0 / 67373.0, 43733439.0 / 21896875.0, \ 231321177.0 / 109484375.0, 20495009043.0 / 9306171875.0, 1073585186448381.0 / 476522530859375.0, 4387445039583.0 / 1944989921875.0, \ 1000263375846831627.0 / 453346207767578125.0, 280865021365240713.0 / 133337119931640625.0, 148014872740758343473.0 / 75350125192138671875.0, 137372931237386537808993.0 / 76480377070020751953125.0, \ 41722474198742657618857192737.0 / 25674386102028896409912109375.0, 12348948373636682700768301125723.0 / 8344175483159391333221435546875.0, 5001286000741585238340074032091091.0 / 3590449627018291035442047119140625.0, \ 185364329915163811141785118512534489.0 / 132846636199676768311355743408203125.0, 6292216384025878939310787532157558451.0 / 4160197291516193533960877227783203125.0, 299869254759556271677902570230858640837.0 / 170568088952163934892395966339111328125.0, \ 316689568216860631885141475537178451746044283.0 / 148810301691076651811854156590061187744140625.0, 670194310437429598283653289122392937145371137.0 / 258140319260030926612400067554187774658203125.0, 19697015384373759058671314622426656486031717197919.0 / 6332687088594936951180328352888571262359619140625.0, \ 178793788985653424246012689916144867915861856840849.0 / 49756827124674504616416865629838774204254150390625.0, 323844166067349737493036492206152479344269351967043143667.0 / 82039106319990447886052744467343800746748447418212890625.0, 200808116689754604893460969866238617668631975356485302537199.0 / 49409916306357883385918130190559334540655314922332763671875.0, \ 27506481209689719715275759452624078040221544551995885750037973.0 / 7164437864421893090958128877631103508395020663738250732421875.0, 16356939619211770477227805130221533318985185730316048281126247721.0 / 5122573073061653560035062147506239008502439774572849273681640625.0, 30976199222209837888906735596203249520053107250807132769871859115868101.0 / 14801698741072505317694781203956860833766632412399612367153167724609375.0, \ 519588001407316958447129785511020819131555326399179970047767492196701159.0 / 902903623205422824379381653441368510859764577156376354396343231201171875.0 }; double alpha = sqrt(I1) / sqrt(3.0 * m_N); double alpha0 = 1.0 / sqrt(m_N); ////////////////////////////////////// double beta = 0, beta0 = 0, beta_alpha = 0, alpha2 = alpha * alpha, alpha02 = alpha0 * alpha0; int num_fa = sizeof(f_a) / sizeof(f_a[0]); if (m_term > num_fa) { m_term = num_fa; } beta = 1 + f_a[m_term - 1] / f_a[m_term - 2] * alpha2; beta0 = 1 + f_a[m_term - 1] / f_a[m_term - 2] * alpha02; beta_alpha = 1 + f_a[m_term - 1] / f_a[m_term - 2] * alpha2 * (2 * m_term - 1) / (2 * m_term - 3); for (int i = 2; i < m_term; i++) { beta = 1 + f_a[m_term - i] / f_a[m_term - i - 1] * alpha2 * beta; beta0 = 1 + f_a[m_term - i] / f_a[m_term - i - 1] * alpha02 * beta0; beta_alpha = 1 + f_a[m_term - i] / f_a[m_term - i - 1] * alpha2 * beta_alpha * (2 * m_term - 2 * i + 1) / (2 * m_term - 2 * i - 1); }; beta = f_a[0] * alpha * beta; beta0 = f_a[0] * alpha0 * beta0; beta_alpha = f_a[0] * beta_alpha; //////////////////////////////////////// double WI = ksi * m_N * (beta / sqrt(I1) / 2.0 / sqrt(3.0 * m_N)); double WII = ksi * m_N * (beta_alpha / I1 / sqrt(3.0 * m_N) - beta * pow(I1, (-3.0 / 2.0))) / 4.0 / sqrt(3.0 * m_N); double W1[3]; double W11[3][3]; double T[3], T_NH[3]; double I1_1[3]; double I1_11 = 2; double W10 = ksi * m_N * (beta0 / sqrt(3.0) / 2.0 / sqrt(3 * m_N)) * 2.0; ///////////////////////////////////////////////////////////////////// double TCom = kappa * (J * J - 1) / J; //NH Term for (int i = 0; i < 3; ++i) { I1_1[i] = 2 * lam[i]; W1[i] = WI * I1_1[i] - W10 / lam[i]; T[i] = lam[i] * W1[i] / J; T[i] += TCom; s += N[i] * T[i]; } // coefficients appearing in elasticity tensor double D[3][3], E[3][3]; double D_NH[3][3], E_NH[3][3]; //NH Term double DComii = 2 * kappa / J + TCom; //NH Term double DComij = 2 * kappa * J; //NH Term double EComij = 2 * (-kappa * J * J + kappa) / J; //NH Term for (i = 0; i < 3; ++i) { I1_1[i] = 2 * lam[i]; W11[i][i] = WII * I1_1[i] * I1_1[i] + WI * I1_11 + W10 / lam2[i]; D[i][i] = lam2[i] * W11[i][i] / J - T[i]; D[i][i] += DComii; for (j = i + 1; j < 3; ++j) { W11[i][j] = WII * I1_1[i] * I1_1[j]; D[i][j] = lam[i] * lam[j] * W11[i][j] / J; D[i][j] += DComij; if (lam2[j] != lam2[i]) { E[i][j] = 2 * (lam2[j] * T[i] - lam2[i] * T[j]) / (lam2[i] - lam2[j]); } else { E[i][j] = 2 * W10 / J; E[i][j] += EComij; } } } // spatial elasticity tensor tens4ds c(0.0); mat3dd I(1.0); for (i = 0; i < 3; ++i) { c += dyad1s(N[i]) * D[i][i]; for (j = i + 1; j < 3; ++j) { c += dyad1s(N[i], N[j]) * D[i][j]; c += dyad4s(N[i], N[j]) * E[i][j]; } } return c; } //----------------------------------------------------------------------------- double FEABUnconstrained::StrainEnergyDensity(FEMaterialPoint& mp) { double ksi = m_ksi(mp); double kappa = m_kappa(mp); // extract elastic material data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; double lnJ = log(J); // get the left Cauchy-Green tensor mat3ds b = pt.LeftCauchyGreen(); // get the eigenvalues and eigenvectors of b double lam2[3]; // these are the squares of the eigenvalues of V vec3d ev[3]; EigenValues(b, lam2, ev, m_eps); // get the eigenvalues of V double lam[3]; lam[0] = sqrt(lam2[0]); lam[1] = sqrt(lam2[1]); lam[2] = sqrt(lam2[2]); // Invariants of b double I1 = b.tr(); // strain energy density double alpha = sqrt(I1) / sqrt(3*m_N); double beta = alpha * (3.0 - alpha * alpha) / (1.0 - alpha * alpha) -0.5 * pow(alpha, (10.0 / 3.0)) + 3.0 * pow(alpha, 5.0)*(alpha - 0.76)*(alpha - 1.0); double alpha0 = 1 / sqrt(m_N); double beta0 = alpha0 * (3.0 - alpha0 * alpha0) / (1.0 - alpha0 * alpha0) -0.5 * pow(alpha0, (10.0 / 3.0)) + 3.0 * pow(alpha0, 5.0)*(alpha0 - 0.76)*(alpha0 - 1.0); double W10 = ksi * m_N * (beta0 / sqrt(3) / 2 / sqrt(3 * m_N)) * 2; double sedCom = kappa / kappa / kappa * cosh(kappa*(J - 1) - 1); double sed = ksi * m_N * (sqrt(I1)*beta / sqrt(3 * m_N) + log(beta / sinh(beta))) - W10 * lnJ +sedCom; return sed; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEMovingFrameLoad.cpp
.cpp
5,349
166
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEMovingFrameLoad.h" #include "FEElasticMaterialPoint.h" #include <FECore/log.h> BEGIN_FECORE_CLASS(FEMovingFrameLoad, FEBodyForce) ADD_PARAMETER(m_wi.x, "wx")->setLongName("x-angular velocity")->setUnits(UNIT_ANGULAR_VELOCITY); ADD_PARAMETER(m_wi.y, "wy")->setLongName("y-angular velocity")->setUnits(UNIT_ANGULAR_VELOCITY); ADD_PARAMETER(m_wi.z, "wz")->setLongName("z-angular velocity")->setUnits(UNIT_ANGULAR_VELOCITY); ADD_PARAMETER(m_at.x, "ax")->setLongName("x-linear acceleration")->setUnits(UNIT_ACCELERATION); ADD_PARAMETER(m_at.y, "ay")->setLongName("y-linear acceleration")->setUnits(UNIT_ACCELERATION); ADD_PARAMETER(m_at.z, "az")->setLongName("z-linear acceleration")->setUnits(UNIT_ACCELERATION); ADD_PARAMETER(m_frame, "frame")->setEnums("fixed\0moving\0"); ADD_PARAMETER(m_wt, "wt")->setLongName("Angular velocity in fixed frame")->setUnits(UNIT_ANGULAR_VELOCITY)->SetFlags(FE_PARAM_HIDDEN); ADD_PARAMETER(m_Wt, "Wt")->setLongName("Angular velocity in moving frame")->setUnits(UNIT_ANGULAR_VELOCITY)->SetFlags(FE_PARAM_HIDDEN); ADD_PARAMETER(m_rt, "rt")->setLongName("Rotation vector in fixed frame")->setUnits(UNIT_RADIAN)->SetFlags(FE_PARAM_HIDDEN); END_FECORE_CLASS(); FEMovingFrameLoad::FEMovingFrameLoad(FEModel* fem) : FEBodyForce(fem) { m_frame = 0; // assume fixed frame angular velocity } void FEMovingFrameLoad::Activate() { m_ap = m_at; m_wp = m_wt; m_Wp = m_Wt; m_alp = m_alt; m_Alp = m_Alt; m_qp = m_qt; FEBodyForce::Activate(); } void FEMovingFrameLoad::PrepStep() { const FETimeInfo& tp = GetTimeInfo(); double dt = tp.timeIncrement; double alpha = tp.alphaf; // evaluate quantities at current time (t) and intermediate time if (m_frame == 0) { m_wt = m_wi; // input is ang vel in fixed frame // current quantities m_alp = m_alt; m_alt = (m_wt - m_wp) / dt; quatd wt(m_wt.x, m_wt.y, m_wt.z, 0.0); m_qt = m_qp + (wt * m_qp) * (0.5 * dt); m_qt.MakeUnit(); // intermediate quantities m_al = m_alt * alpha + m_alp * (1.0 - alpha); m_w = m_wt * alpha + m_wp * (1.0 - alpha); quatd wa(m_w.x, m_w.y, m_w.z, 0.0); m_q = m_qp + (wa * m_qp) * (0.5 * dt * alpha); m_q.MakeUnit(); m_qp = m_qt; m_wp = m_wt; // quantities in body frame quatd qti = m_qt.Inverse(); m_Wt = qti * m_wt; m_rt = m_qt.GetRotationVector(); quatd qi = m_q.Inverse(); m_Al = qi * m_al; m_W = qi * m_w; } else { m_Wt = m_wi; // input is ang vel in body frame // current quantities m_Alp = m_Alt; m_Alt = (m_Wt - m_Wp) / dt; quatd Wt(m_Wt.x, m_Wt.y, m_Wt.z, 0.0); m_qt = m_qp + (m_qp * Wt) * (0.5 * dt); m_qt.MakeUnit(); // intermediate quantities m_Al = m_Alt * alpha + m_Alp * (1.0 - alpha); m_W = m_Wt * alpha + m_Wp * (1.0 - alpha); quatd Wa(m_W.x, m_W.y, m_W.z, 0.0); m_q = m_qp + (m_qp * Wa) * (0.5 * dt * alpha); m_q.MakeUnit(); m_qp = m_qt; m_Wp = m_Wt; // quantities in fixed frame m_wt = m_qt * m_Wt; m_rt = m_qt.GetRotationVector(); m_alp = m_alt; m_alt = m_qt * m_Alt; m_al = m_q * m_Al; m_w = m_q * m_W; } // linear acceleration (always assumed to be given in the fixed frame) m_a = m_at * alpha + m_ap * (1.0 - alpha); m_ap = m_at; quatd qi = m_q.Inverse(); m_A = qi * m_a; FEBodyForce::PrepStep(); } vec3d FEMovingFrameLoad::force(FEMaterialPoint& pt) { FEElasticMaterialPoint& ep = *pt.ExtractData<FEElasticMaterialPoint>(); const FETimeInfo& tp = GetTimeInfo(); double alpha = tp.alphaf; // NOTE: position and velocity at material point are already evaluated at intermediate time vec3d r = pt.m_rt; vec3d v = ep.m_v; vec3d f = m_A + (m_Al ^ r) + (m_W ^ (m_W ^ r)) + (m_W ^ v) * 2.0; return f; } mat3d FEMovingFrameLoad::stiffness(FEMaterialPoint& pt) { FEElasticMaterialPoint& ep = *pt.ExtractData<FEElasticMaterialPoint>(); vec3d v = ep.m_v; const FETimeInfo& tp = GetTimeInfo(); double gamma = tp.gamma; double dt = tp.timeIncrement; double alpha = tp.alphaf; mat3da Sw(m_W); mat3da A(m_Al); mat3d S2 = Sw * Sw; mat3d K = (S2 + A + Sw * (4.0 * gamma / dt))*alpha; return K; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEBodyForce.cpp
.cpp
2,392
67
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEBodyForce.h" #include "FESolidMaterial.h" #include "FEElasticDomain.h" //----------------------------------------------------------------------------- FEBodyForce::FEBodyForce(FEModel* pfem) : FEBodyLoad(pfem) { } //----------------------------------------------------------------------------- // NOTE: Work in progress! Working on integrating body loads as model loads void FEBodyForce::LoadVector(FEGlobalVector& R) { for (int i = 0; i<Domains(); ++i) { FEDomain* dom = Domain(i); FEElasticDomain* edom = dynamic_cast<FEElasticDomain*>(dom); if (edom) edom->BodyForce(R, *this); } } //----------------------------------------------------------------------------- // NOTE: Work in progress! Working on integrating body loads as model loads void FEBodyForce::StiffnessMatrix(FELinearSystem& LS) { for (int i = 0; i<Domains(); ++i) { FEDomain* dom = Domain(i); FEElasticDomain* edom = dynamic_cast<FEElasticDomain*>(dom); if (edom) edom->BodyForceStiffness(LS, *this); } } double FEBodyForce::divforce(FEMaterialPoint& pt) { return (stiffness(pt)).trace(); }
C++
3D
febiosoftware/FEBio
FEBioMech/FECellGrowth.h
.h
2,277
61
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticMaterial.h" //----------------------------------------------------------------------------- //! Material class that implements the equilibrium of a perfect osmometer. // class FECellGrowth : public FEElasticMaterial { public: //! When used on its own (not in a solid mixture), this materials //! is intrinsically unstable FECellGrowth(FEModel* pfem); //! Initialization routine bool Init() override; //! Returns the Cauchy stress virtual mat3ds Stress(FEMaterialPoint& mp) override; //! Returs the spatial tangent virtual tens4ds Tangent(FEMaterialPoint& mp) override; // declare the parameter list DECLARE_FECORE_CLASS(); public: double m_phir; //!< intracellular solid volume fraction normalized to reference configuration double m_cr; //!< intracellular osmolarity normalized to reference configuration double m_ce; //!< extracellular osmolarity double m_Rgas; //!< universal gas constant double m_Tabs; //!< absolute temperature };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FELinearTrussDomain.cpp
.cpp
11,511
449
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FELinearTrussDomain.h" #include <FECore/FEModel.h> #include <FECore/FELinearSystem.h> #include "FEBodyForce.h" #include "FEBioMech.h" #include <FECore/log.h> BEGIN_FECORE_CLASS(FELinearTrussDomain, FETrussDomain) ADD_PARAMETER(m_a0, "cross_sectional_area"); END_FECORE_CLASS(); FELinearTrussDomain::FELinearTrussDomain(FEModel* pfem) : FETrussDomain(pfem), FEElasticDomain(pfem), m_dofU(pfem), m_dofV(pfem), m_dofR(pfem) { m_pMat = nullptr; m_a0 = 0.0; m_dofU.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT)); m_dofR.AddVariable(FEBioMech::GetVariableName(FEBioMech::RIGID_ROTATION)); m_dofV.AddVariable(FEBioMech::GetVariableName(FEBioMech::VELOCITY)); } const FEDofList& FELinearTrussDomain::GetDOFList() const { return m_dofU; } void FELinearTrussDomain::SetMaterial(FEMaterial* pmat) { FETrussDomain::SetMaterial(pmat); m_pMat = dynamic_cast<FETrussMaterial*>(pmat); assert(m_pMat); } bool FELinearTrussDomain::Init() { if (m_a0 <= 0.0) { feLogError("Cross sectional area of \"%s\" must be positive.", GetName().c_str()); return false; } for (FETrussElement& el : m_Elem) { el.m_a0 = m_a0; } return FETrussDomain::Init(); } void FELinearTrussDomain::Reset() { ForEachMaterialPoint([](FEMaterialPoint& mp) { mp.Init(); }); } void FELinearTrussDomain::UnpackLM(FEElement &el, vector<int>& lm) { lm.resize(12); FENode& n1 = m_pMesh->Node(el.m_node[0]); FENode& n2 = m_pMesh->Node(el.m_node[1]); lm[0] = n1.m_ID[m_dofU[0]]; lm[1] = n1.m_ID[m_dofU[1]]; lm[2] = n1.m_ID[m_dofU[2]]; lm[3] = n2.m_ID[m_dofU[0]]; lm[4] = n2.m_ID[m_dofU[1]]; lm[5] = n2.m_ID[m_dofU[2]]; // rigid rotational dofs lm[6 ] = n1.m_ID[m_dofR[0]]; lm[7 ] = n1.m_ID[m_dofR[1]]; lm[8 ] = n1.m_ID[m_dofR[2]]; lm[9 ] = n2.m_ID[m_dofR[0]]; lm[10] = n2.m_ID[m_dofR[1]]; lm[11] = n2.m_ID[m_dofR[2]]; } void FELinearTrussDomain::Activate() { for (int i=0; i<Nodes(); ++i) { FENode& node = Node(i); if (node.HasFlags(FENode::EXCLUDE) == false) { if (node.m_rid < 0) { node.set_active(m_dofU[0]); node.set_active(m_dofU[1]); node.set_active(m_dofU[2]); } } } } void FELinearTrussDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { ForEachMaterialPoint([&](FEMaterialPoint& mp) { mp.Update(timeInfo); }); } void FELinearTrussDomain::MassMatrix(FELinearSystem& LS, double scale) { for (FETrussElement& el : m_Elem) { matrix me(2, 2); me.zero(); ElementMassMatrix(el, me); // The element mass matrix calculated above only evaluates the 2x2 mass matrix // Thus, we need to inlate it to a 6x6 mass matrix. FEElementMatrix Me(6, 6); Me.zero(); for (int i=0; i<2; ++i) { for (int j = 0; j < 2; ++j) { Me[3 * i ][3 * j ] = scale*me[i][j]; Me[3 * i + 1][3 * j + 1] = scale*me[i][j]; Me[3 * i + 2][3 * j + 2] = scale*me[i][j]; } } vector<int> lm; UnpackLM(el, lm); Me.SetNodes(el.m_node); Me.SetIndices(lm); LS.Assemble(Me); } } void FELinearTrussDomain::ElementMassMatrix(FETrussElement& el, matrix& me) { double L = el.m_L0; double A = el.m_a0; double rho = m_pMat->Density(); me[0][0] = rho * A * L / 3.0; me[0][1] = rho * A * L / 6.0; me[1][0] = rho * A * L / 6.0; me[1][1] = rho * A * L / 3.0; } void FELinearTrussDomain::StiffnessMatrix(FELinearSystem& LS) { vector<int> lm; for (FETrussElement& el : m_Elem) { FEElementMatrix ke(el); ElementStiffness(el, ke); UnpackLM(el, lm); ke.SetNodes(el.m_node); ke.SetIndices(lm); LS.Assemble(ke); } } void FELinearTrussDomain::ElementStiffness(FETrussElement& el, matrix& ke) { // intial length double L = el.m_L0; // current length double l = el.m_Lt; // get the elastic tangent FEMaterialPoint& mp = *el.GetMaterialPoint(0); FETrussMaterialPoint& pt = *mp.ExtractData<FETrussMaterialPoint>(); double E = m_pMat->Tangent(mp); // element initial volume double V = L*el.m_a0; // Kirchhoff Stress double tau = pt.m_tau; // scalar stiffness double k = V / (l*l)*( E - 2*tau); // axial force T = s*a = t*V/l double T = tau*V/l; vec3d n = GetTrussAxisVector(el); // calculate the tangent matrix ke.resize(6, 6); FETimeInfo& ti = GetFEModel()->GetTime(); double alphaf = ti.alphaf; ke[0][0] = ke[3][3] = (k*n.x*n.x + T/l)*alphaf; ke[1][1] = ke[4][4] = (k*n.y*n.y + T/l)*alphaf; ke[2][2] = ke[5][5] = (k*n.z*n.z + T/l)*alphaf; ke[0][1] = ke[1][0] = ke[3][4] = ke[4][3] = k*n.x*n.y*alphaf; ke[1][2] = ke[2][1] = ke[4][5] = ke[5][4] = k*n.y*n.z*alphaf; ke[0][2] = ke[2][0] = ke[3][5] = ke[5][3] = k*n.x*n.z*alphaf; ke[0][3] = ke[3][0] = -ke[0][0]; ke[0][4] = ke[4][0] = -ke[0][1]; ke[0][5] = ke[5][0] = -ke[0][2]; ke[1][3] = ke[3][1] = -ke[1][0]; ke[1][4] = ke[4][1] = -ke[1][1]; ke[1][5] = ke[5][1] = -ke[1][2]; ke[2][3] = ke[3][2] = -ke[2][0]; ke[2][4] = ke[4][2] = -ke[2][1]; ke[2][5] = ke[5][2] = -ke[2][2]; } void FELinearTrussDomain::InternalForces(FEGlobalVector& R) { // element force vector vector<double> fe; vector<int> lm; for (FETrussElement& el : m_Elem) { ElementInternalForces(el, fe); UnpackLM(el, lm); R.Assemble(el.m_node, lm, fe); } } void FELinearTrussDomain::ElementInternalForces(FETrussElement& el, vector<double>& fe) { FEMaterialPoint& mp = *el.GetMaterialPoint(0); FETrussMaterialPoint& pt = *(mp.ExtractData<FETrussMaterialPoint>()); FETimeInfo& ti = GetFEModel()->GetTime(); double alphaf = ti.alphaf; vec3d rt[2]; for (int i = 0; i < 2; ++i) { FENode& nd = m_pMesh->Node(el.m_node[i]); rt[i] = nd.m_rt * alphaf + nd.m_rp * (1 - alphaf); } vec3d n = rt[1] - rt[0]; n.unit(); // get the element's Kirchhoff stress double tau = pt.m_tau; // initial length double L = el.m_L0; // current length double l = el.m_Lt; // initial volume double V = L*el.m_a0; // calculate nodal forces fe.resize(6); fe[0] = tau*V/l*n.x; fe[1] = tau*V/l*n.y; fe[2] = tau*V/l*n.z; fe[3] = -fe[0]; fe[4] = -fe[1]; fe[5] = -fe[2]; } //! Calculates inertial forces for dynamic analyses void FELinearTrussDomain::InertialForces(FEGlobalVector& R, vector<double>& F) { vector<double> fe; vector<int> lm; for (FETrussElement& el : m_Elem) { ElementInertialForces(el, fe); UnpackLM(el, lm); R.Assemble(el.m_node, lm, fe); } } void FELinearTrussDomain::ElementInertialForces(FETrussElement& el, vector<double>& fe) { FEMaterialPoint& mp = *el.GetMaterialPoint(0); FETrussMaterialPoint& pt = *(mp.ExtractData<FETrussMaterialPoint>()); FETimeInfo& ti = GetFEModel()->GetTime(); double alpham = ti.alpham; // get the nodal accelerations vec3d a[2]; int neln = el.Nodes(); for (int i = 0; i < neln; ++i) { FENode& node = m_pMesh->Node(el.m_node[i]); a[i] = node.m_ap* (1 - alpham) + node.m_at* alpham; } // calculate element contribution to inertial force matrix me(2, 2); ElementMassMatrix(el, me); fe.resize(6, 0.0); fe[0] = -(me[0][0] * a[0].x + me[0][1] * a[1].x); fe[1] = -(me[0][0] * a[0].y + me[0][1] * a[1].y); fe[2] = -(me[0][0] * a[0].z + me[0][1] * a[1].z); fe[3] = -(me[1][0] * a[0].x + me[1][1] * a[1].x); fe[4] = -(me[1][0] * a[0].y + me[1][1] * a[1].y); fe[5] = -(me[1][0] * a[0].z + me[1][1] * a[1].z); } //! calculate body force on a truss domain void FELinearTrussDomain::BodyForce(FEGlobalVector& R, FEBodyForce& bf) { vector<double> fe(6); vector<int> lm; double density = m_pMat->Density(); for (FETrussElement& el : m_Elem) { zero(fe); int nint = el.GaussPoints(); double* w = el.GaussWeights(); for (int n = 0; n < nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); // get the force vec3d f = bf.force(mp); // get element shape functions double* H = el.H(n); // get the initial Jacobian double J0 = el.m_a0 * el.m_L0 / 2.0; // set integrand fe[0] -= H[0] * density * f.x * J0 * w[n]; fe[1] -= H[0] * density * f.y * J0 * w[n]; fe[2] -= H[0] * density * f.z * J0 * w[n]; fe[3] -= H[1] * density * f.x * J0 * w[n]; fe[4] -= H[1] * density * f.y * J0 * w[n]; fe[5] -= H[1] * density * f.z * J0 * w[n]; } UnpackLM(el, lm); R.Assemble(el.m_node, lm, fe); } } //! body force stiffness matrix void FELinearTrussDomain::BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) { double density = m_pMat->Density(); vector<int> lm; for (FETrussElement& el : m_Elem) { FEElementMatrix ke(6, 6); ke.zero(); int nint = el.GaussPoints(); int neln = el.Nodes(); double* gw = el.GaussWeights(); for (int n = 0; n < nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); double* H = el.H(n); double J0 = el.m_a0 * el.m_L0 / 2.0; double Jdw = J0 * density * gw[n]; mat3d K = bf.stiffness(mp); // put it together for (int a=0; a<neln; ++a) for (int b = 0; b < neln; ++b) { ke.sub(3 * a, 3 * b, K * (H[a] * H[b] * Jdw)); } } UnpackLM(el, lm); ke.SetIndices(lm); ke.SetNodes(el.m_node); LS.Assemble(ke); } } void FELinearTrussDomain::Update(const FETimeInfo& tp) { // get the poisson's ratio. FELinearTrussMaterial* mat = dynamic_cast<FELinearTrussMaterial*>(m_pMat); double nu = (mat ? mat->m_v : 0.5); double alpham = tp.alpham; double alphaf = tp.alphaf; FEMesh& mesh = *m_pMesh; for (FETrussElement& el : m_Elem) { // calculate the current length vec3d rt[2], vt[2], at[2]; for (int j = 0; j < el.Nodes(); ++j) { FENode& node = m_pMesh->Node(el.m_node[j]); rt[j] = node.m_rt * alphaf + node.m_rp*(1 - alphaf); vec3d vtj = node.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2]); vt[j] = vtj * alphaf + node.m_vp * (1 - alphaf); at[j] = node.m_at * alpham + node.m_ap * (1 - alpham); } el.m_Lt = (rt[1] - rt[0]).norm(); vec3d e = (rt[1] - rt[0]).normalized(); for (int n = 0; n < el.GaussPoints(); ++n) { FEMaterialPoint& mp = *(el.GetMaterialPoint(n)); FETrussMaterialPoint& pt = *(mp.ExtractData<FETrussMaterialPoint>()); mp.m_rt = el.Evaluate(rt, n); pt.m_v = el.Evaluate(vt, n); pt.m_a = el.Evaluate(at, n); // calculate stretch pt.m_lam = el.m_Lt / el.m_L0; // volume ratio (this assume linear truss material!) double J = pow(pt.m_lam, 1.0 - 2.0 * nu); // calculate stress pt.m_tau = m_pMat->Stress(mp); pt.m_s = dyad(e) * (pt.m_tau / J); } } }
C++
3D
febiosoftware/FEBio
FEBioMech/FEOrthoElastic.h
.h
2,371
64
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticMaterial.h" //----------------------------------------------------------------------------- // This class implements a version of orthotropic elasticity that remains // valid for large deformations class FEOrthoElastic : public FEElasticMaterial { public: FEParamDouble m_E1, m_E2, m_E3; // Young's moduli FEParamDouble m_v12, m_v23, m_v31; // Poisson's ratio FEParamDouble m_G12, m_G23, m_G31; // Shear moduli public: FEOrthoElastic(FEModel* pfem); //! calculate stress at material point virtual mat3ds Stress(FEMaterialPoint& pt) override; //! calculate tangent stiffness at material point virtual tens4ds Tangent(FEMaterialPoint& pt) override; //! calculate strain energy density at material point virtual double StrainEnergyDensity(FEMaterialPoint& pt) override; //! data initialization bool Validate() override; private: // Helper function for evaluating Lame coefficients at material point bool EvaluateLameCoefficients(FEMaterialPoint& pt, double lam[3][3], double mu[3]); // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FESSIShellDomain.cpp
.cpp
35,845
1,143
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FESSIShellDomain.h" #include "FECore/FEElemElemList.h" #include <FECore/FESolidDomain.h> #include <FECore/FEModelParam.h> #include <FECore/FEDataStream.h> #include <FECore/log.h> #include <FECore/FEMesh.h> #include "FEBioMech.h" //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FESSIShellDomain, FEShellDomainNew) ADD_PARAMETER(m_bnodalnormals, "shell_normal_nodal"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FESSIShellDomain::FESSIShellDomain(FEModel* pfem) : FEShellDomainNew(pfem), m_dofU(pfem), m_dofSU(pfem), m_dofR(pfem) { m_bnodalnormals = true; // TODO: Can this be done in Init, since there is no error checking if (pfem) { m_dofU.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT)); m_dofSU.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT)); m_dofR.AddVariable(FEBioMech::GetVariableName(FEBioMech::RIGID_ROTATION)); } } //----------------------------------------------------------------------------- bool FESSIShellDomain::Init() { FEShellDomain::Init(); FindSSI(); // check for initially inverted shells try { for (int i = 0; i < Elements(); ++i) { FEShellElementNew& el = ShellElement(i); int neln = el.Nodes(); int nint = el.GaussPoints(); el.m_E.resize(nint, mat3ds(0, 0, 0, 0, 0, 0)); for (int n = 0; n < nint; ++n) { double J0 = detJ0(el, n); } } } catch (NegativeJacobian e) { feLogError("Zero or negative jacobians detected at integration points of domain: %s\n", GetName().c_str()); return false; } return true; } //----------------------------------------------------------------------------- void FESSIShellDomain::Serialize(DumpStream& ar) { FEShellDomainNew::Serialize(ar); ar & m_bnodalnormals; } //----------------------------------------------------------------------------- //! Calculate all shell normals (i.e. the shell directors). //! And find shell nodes bool FESSIShellDomain::InitShells() { if (!FEShellDomain::InitShells()) return false; FEMesh& mesh = *GetMesh(); // check for zero shell thickness for (int i = 0; i < Elements(); ++i) { FEShellElementNew& el = ShellElement(i); int nn = el.Nodes(); for (int j = 0; j < nn; ++j) { if (el.m_h0[j] <= 0.0) { string name = GetName(); feLogError("Zero shell thickness found in \"%s\"", name.c_str()); return false; } } } if (!m_bnodalnormals) { for (int i = 0; i<Elements(); ++i) { FEShellElementNew& el = ShellElement(i); int ne = el.Nodes(); vec3d gr(0,0,0), gs(0,0,0); double Mr[FEElement::MAX_NODES], Ms[FEElement::MAX_NODES]; el.shape_deriv(Mr, Ms, 0, 0); for (int j = 0; j<ne; ++j) { gr += mesh.Node(el.m_node[j]).m_r0*Mr[j]; gs += mesh.Node(el.m_node[j]).m_r0*Ms[j]; } vec3d d0 = gr ^ gs; d0.unit(); for (int j = 0; j<ne; ++j) { el.m_d0[j] = d0 * el.m_h0[j]; } } } for (int i = 0; i < Elements(); ++i) { FEShellElementNew& el = ShellElement(i); int ni = el.GaussPoints(); vec3d g0[3]; for (int j = 0; j < ni; ++j) { //NOTE: calculate covariant first since contravariant depends on it! CoBaseVectors0(el, j, g0); el.m_gt[0][j] = el.m_gp[0][j] = el.m_g0[0][j] = g0[0]; el.m_gt[1][j] = el.m_gp[1][j] = el.m_g0[1][j] = g0[1]; el.m_gt[2][j] = el.m_gp[2][j] = el.m_g0[2][j] = g0[2]; ContraBaseVectors0(el, j, g0); el.m_G0[0][j] = el.m_Gt[0][j] = g0[0]; el.m_G0[1][j] = el.m_Gt[1][j] = g0[1]; el.m_G0[2][j] = el.m_Gt[2][j] = g0[2]; } } return true; } //----------------------------------------------------------------------------- void FESSIShellDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { FEShellDomain::PreSolveUpdate(timeInfo); } //----------------------------------------------------------------------------- //! Find interfaces between solid element faces and shell elements //! void FESSIShellDomain::FindSSI() { // find out if there are solid domains in this model vector<FESolidDomain*> psd; FEMesh& mesh = *GetMesh(); int ndom = mesh.Domains(); for (int i = 0; i<ndom; ++i) { FEDomain& pdom = mesh.Domain(i); FESolidDomain* psdom = dynamic_cast<FESolidDomain*>(&pdom); if (psdom) psd.push_back(psdom); } size_t nsdom = psd.size(); // if there are no solid domains we're done if (nsdom == 0) return; // tag all nodes that belong to this shell domain vector<int> tag(mesh.Nodes(), 0); for (int i=0; i<Nodes(); ++i) tag[m_Node[i]] = 1; int nelem = Elements(); int nf[9]; vec3d g[3]; // loop over all solid domains for (int i=0; i<nsdom; ++i) { // get the next domain FESolidDomain& di = *psd[i]; // see if there are any potential candidates // NOTE: We can't use the domain's node list since it might not be initialized yet // since shell domains are initialized before solid domains bool hasNodes = false; for (int j = 0; j < di.Elements(); ++j) { FEElement& el = di.Element(j); int ne = el.Nodes(); for (int k = 0; k < ne; ++k) { FENode& node = mesh.Node(el.m_node[k]); if (tag[el.m_node[k]] == 1) { hasNodes = true; break; } } if (hasNodes) break; } // if the solid domain shares nodes with this shell domain, // there might be matches in this domain if (hasNodes) { // build a node-element list for faster lookup FENodeElemList NEL; NEL.Create(di); // check all shell elements for (int l = 0; l < nelem; ++l) { FEShellElement& sel = Element(l); int n0 = sel.m_node[0]; int nval = NEL.Valence(n0); // see if we can match any shells FEElement** ppe = NEL.ElementList(n0); for (int j = 0; j < nval; ++j) { FESolidElement& elj = dynamic_cast<FESolidElement&>(*ppe[j]); // loop over all its faces int nfaces = elj.Faces(); for (int k = 0; k < nfaces; ++k) { int nn = elj.GetFace(k, nf); // see if it matches this face bool found = false; if (nn == sel.Nodes()) { switch (nn) { case 3: if (sel.HasNode(nf[0]) && sel.HasNode(nf[1]) && sel.HasNode(nf[2])) found = true; break; case 4: if (sel.HasNode(nf[0]) && sel.HasNode(nf[1]) && sel.HasNode(nf[2]) && sel.HasNode(nf[3])) found = true; break; case 6: if (sel.HasNode(nf[0]) && sel.HasNode(nf[1]) && sel.HasNode(nf[2])) found = true; break; case 7: if (sel.HasNode(nf[0]) && sel.HasNode(nf[1]) && sel.HasNode(nf[2])) found = true; break; case 8: if (sel.HasNode(nf[0]) && sel.HasNode(nf[1]) && sel.HasNode(nf[2]) && sel.HasNode(nf[3])) found = true; break; case 9: if (sel.HasNode(nf[0]) && sel.HasNode(nf[1]) && sel.HasNode(nf[2]) && sel.HasNode(nf[3])) found = true; break; default: assert(false); } } // see if we found a match if (found) { // check interface side // get outward normal to solid element face vec3d n0 = mesh.Node(nf[0]).m_r0, n1 = mesh.Node(nf[1]).m_r0, n2 = mesh.Node(nf[2]).m_r0; vec3d nsld = (n1 - n0) ^ (n2 - n1); // get outward normal to shell face CoBaseVectors0(sel, 0, g); vec3d nshl = g[2]; // compare normals if (nsld*nshl > 0) { // set solid element attached to shell back face sel.m_elem[0] = elj.GetID(); // store result if (m_bnodalnormals) { elj.m_bitfc.resize(elj.Nodes(), false); for (int n = 0; n < nn; ++n) { int m = elj.FindNode(nf[n]); if (m > -1) elj.m_bitfc[m] = true; } } } else { // set solid element attached to shell front face sel.m_elem[1] = elj.GetID(); } // the same element cannot be both front and back of a shell // so we can leave the loop over the faces break; } } } } } } // check for elements that only have one or two shell nodes // but don't share a whole face // get the node element list FENodeElemList& NEL = mesh.NodeElementList(); for (int i = 0; i<ndom; ++i) { FEDomain& pdom = mesh.Domain(i); FEShellDomain* psdom = dynamic_cast<FEShellDomain*>(&pdom); if (psdom) { // find the solid domain attached to the back of these shells FESolidDomain* sldmn = nullptr; for (int j=0; j<psdom->Elements(); ++j) { FEShellElement& el1 = psdom->Element(j); // identify solid domain at back of shell domain if (el1.m_elem[0] != -1) { FEElement* sel = mesh.FindElementFromID(el1.m_elem[0]); if (sel) sldmn = dynamic_cast<FESolidDomain*>(sel->GetMeshPartition()); break; } } if (sldmn) { // for each node in this shell domain, check the solid elements it belongs to for (int j=0; j<psdom->Nodes(); ++j) { int nid = psdom->NodeIndex(j); int nval = NEL.Valence(nid); FEElement** pe = NEL.ElementList(nid); for (int k=0; k<nval; ++k) { // get the element FEElement& el = *pe[k]; // check that it belongs to the solid domain at the back of the shell domain if ((el.GetMeshPartition() == sldmn) && m_bnodalnormals) { FESolidElement& sel = dynamic_cast<FESolidElement&>(el); if (sel.m_bitfc.size() == 0) sel.m_bitfc.resize(el.Nodes(), false); int lid = sel.FindNode(nid); sel.m_bitfc[lid] = true; } } } } } } } //----------------------------------------------------------------------------- //! calculates covariant basis vectors at an integration point void FESSIShellDomain::CoBaseVectors0(FEShellElement& el, int n, vec3d g[3]) { int i; int neln = el.Nodes(); // current nodal coordinates and directors vec3d r[FEElement::MAX_NODES], D[FEElement::MAX_NODES]; for (i = 0; i<neln; ++i) { FENode& ni = m_pMesh->Node(el.m_node[i]); r[i] = ni.m_r0; D[i] = m_bnodalnormals ? ni.m_d0 : el.m_d0[i]; } double eta = el.gt(n); double* Mr = el.Hr(n); double* Ms = el.Hs(n); double* M = el.H(n); // initialize covariant basis vectors g[0] = g[1] = g[2] = vec3d(0, 0, 0); for (i = 0; i<neln; ++i) { g[0] += (r[i] - D[i] * (1 - eta) / 2)*Mr[i]; g[1] += (r[i] - D[i] * (1 - eta) / 2)*Ms[i]; g[2] += D[i] * (M[i] / 2); } } //----------------------------------------------------------------------------- //! calculates covariant basis vectors at an integration point void FESSIShellDomain::CoBaseVectors0(FEShellElement& el, double r, double s, double t, vec3d g[3]) { int i; int neln = el.Nodes(); // current nodal coordinates and directors vec3d r0[FEElement::MAX_NODES], D[FEElement::MAX_NODES]; for (i = 0; i<neln; ++i) { FENode& ni = m_pMesh->Node(el.m_node[i]); r0[i] = ni.m_r0; D[i] = m_bnodalnormals ? ni.m_d0 : el.m_d0[i]; } double eta = t; double M[FEElement::MAX_NODES]; double Mr[FEElement::MAX_NODES]; double Ms[FEElement::MAX_NODES]; el.shape_fnc(M, r, s); el.shape_deriv(Mr, Ms, r, s); // initialize covariant basis vectors g[0] = g[1] = g[2] = vec3d(0, 0, 0); for (i = 0; i<neln; ++i) { g[0] += (r0[i] - D[i] * (1 - eta) / 2)*Mr[i]; g[1] += (r0[i] - D[i] * (1 - eta) / 2)*Ms[i]; g[2] += D[i] * (M[i] / 2); } } //----------------------------------------------------------------------------- //! calculates contravariant basis vectors at an integration point void FESSIShellDomain::ContraBaseVectors0(FEShellElement& el, int n, vec3d gcnt[3]) { vec3d gcov[3]; // CoBaseVectors0(el, n, gcov); gcov[0] = el.m_g0[0][n]; gcov[1] = el.m_g0[1][n]; gcov[2] = el.m_g0[2][n]; mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); mat3d Ji = J.inverse(); gcnt[0] = vec3d(Ji(0, 0), Ji(0, 1), Ji(0, 2)); gcnt[1] = vec3d(Ji(1, 0), Ji(1, 1), Ji(1, 2)); gcnt[2] = vec3d(Ji(2, 0), Ji(2, 1), Ji(2, 2)); } //----------------------------------------------------------------------------- //! calculates contravariant basis vectors at an integration point void FESSIShellDomain::ContraBaseVectors0(FEShellElement& el, double r, double s, double t, vec3d gcnt[3]) { vec3d gcov[3]; CoBaseVectors0(el, r, s, t, gcov); mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); mat3d Ji = J.inverse(); gcnt[0] = vec3d(Ji(0, 0), Ji(0, 1), Ji(0, 2)); gcnt[1] = vec3d(Ji(1, 0), Ji(1, 1), Ji(1, 2)); gcnt[2] = vec3d(Ji(2, 0), Ji(2, 1), Ji(2, 2)); } //----------------------------------------------------------------------------- double FESSIShellDomain::invjac0(FEShellElement& el, double Ji[3][3], int n) { vec3d gcov[3]; // CoBaseVectors0(el, n, gcov); gcov[0] = el.m_g0[0][n]; gcov[1] = el.m_g0[1][n]; gcov[2] = el.m_g0[2][n]; mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); double det = J.det(); // make sure the determinant is positive if (det <= 0) throw NegativeJacobian(el.GetID(), n + 1, det); // calculate the inverse of the jacobian double deti = 1.0 / det; Ji[0][0] = deti*(J[1][1] * J[2][2] - J[1][2] * J[2][1]); Ji[1][0] = deti*(J[1][2] * J[2][0] - J[1][0] * J[2][2]); Ji[2][0] = deti*(J[1][0] * J[2][1] - J[1][1] * J[2][0]); Ji[0][1] = deti*(J[0][2] * J[2][1] - J[0][1] * J[2][2]); Ji[1][1] = deti*(J[0][0] * J[2][2] - J[0][2] * J[2][0]); Ji[2][1] = deti*(J[0][1] * J[2][0] - J[0][0] * J[2][1]); Ji[0][2] = deti*(J[0][1] * J[1][2] - J[1][1] * J[0][2]); Ji[1][2] = deti*(J[0][2] * J[1][0] - J[0][0] * J[1][2]); Ji[2][2] = deti*(J[0][0] * J[1][1] - J[0][1] * J[1][0]); return det; } //----------------------------------------------------------------------------- double FESSIShellDomain::invjac0(FEShellElement& el, double Ji[3][3], double r, double s, double t) { vec3d gcov[3]; CoBaseVectors0(el, r, s, t, gcov); mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); double det = J.det(); // make sure the determinant is positive if (det <= 0) throw NegativeJacobian(el.GetID(), -1, det); // calculate the inverse of the jacobian double deti = 1.0 / det; Ji[0][0] = deti*(J[1][1] * J[2][2] - J[1][2] * J[2][1]); Ji[1][0] = deti*(J[1][2] * J[2][0] - J[1][0] * J[2][2]); Ji[2][0] = deti*(J[1][0] * J[2][1] - J[1][1] * J[2][0]); Ji[0][1] = deti*(J[0][2] * J[2][1] - J[0][1] * J[2][2]); Ji[1][1] = deti*(J[0][0] * J[2][2] - J[0][2] * J[2][0]); Ji[2][1] = deti*(J[0][1] * J[2][0] - J[0][0] * J[2][1]); Ji[0][2] = deti*(J[0][1] * J[1][2] - J[1][1] * J[0][2]); Ji[1][2] = deti*(J[0][2] * J[1][0] - J[0][0] * J[1][2]); Ji[2][2] = deti*(J[0][0] * J[1][1] - J[0][1] * J[1][0]); return det; } //----------------------------------------------------------------------------- //! Calculate jacobian with respect to reference frame double FESSIShellDomain::detJ0(FEShellElement &el, int n) { vec3d gcov[3]; // CoBaseVectors0(el, n, gcov); gcov[0] = el.m_g0[0][n]; gcov[1] = el.m_g0[1][n]; gcov[2] = el.m_g0[2][n]; mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); return J.det(); } //----------------------------------------------------------------------------- // jacobian with respect to current frame double FESSIShellDomain::detJ0(FEShellElement& el, double r, double s, double t) { vec3d Gcov[3]; CoBaseVectors0(el, r, s, t, Gcov); mat3d J = mat3d(Gcov[0].x, Gcov[1].x, Gcov[2].x, Gcov[0].y, Gcov[1].y, Gcov[2].y, Gcov[0].z, Gcov[1].z, Gcov[2].z); return J.det(); } //----------------------------------------------------------------------------- //! calculates covariant basis vectors at an integration point void FESSIShellDomain::CoBaseVectors(FEShellElement& el, int n, vec3d g[3]) { int neln = el.Nodes(); // current nodal coordinates and directors vec3d r[FEElement::MAX_NODES], D[FEElement::MAX_NODES]; for (int i=0; i<neln; ++i) { FENode& ni = m_pMesh->Node(el.m_node[i]); r[i] = ni.m_rt; D[i] = m_bnodalnormals ? ni.m_d0 : el.m_d0[i]; D[i] += ni.get_vec3d(m_dofU[0], m_dofU[1], m_dofU[2]) - ni.get_vec3d(m_dofSU[0], m_dofSU[1], m_dofSU[2]); } double eta = el.gt(n); double* Mr = el.Hr(n); double* Ms = el.Hs(n); double* M = el.H(n); // initialize covariant basis vectors g[0] = g[1] = g[2] = vec3d(0,0,0); for (int i=0; i<neln; ++i) { g[0] += (r[i] - D[i]*(1-eta)/2)*Mr[i]; g[1] += (r[i] - D[i]*(1-eta)/2)*Ms[i]; g[2] += D[i]*(M[i]/2); } } //----------------------------------------------------------------------------- //! calculates covariant basis vectors at an integration point at previous time void FESSIShellDomain::CoBaseVectorsP(FEShellElement& el, int n, vec3d g[3]) { int i; int neln = el.Nodes(); // previous time nodal coordinates and directors vec3d r[FEElement::MAX_NODES], D[FEElement::MAX_NODES]; for (i=0; i<neln; ++i) { FENode& ni = m_pMesh->Node(el.m_node[i]); r[i] = ni.m_rp; D[i] = m_bnodalnormals ? ni.m_d0 : el.m_d0[i]; D[i] += ni.m_rp - ni.m_r0 - ni.get_vec3d_prev(m_dofSU[0], m_dofSU[1], m_dofSU[2]); } double eta = el.gt(n); double* Mr = el.Hr(n); double* Ms = el.Hs(n); double* M = el.H(n); // initialize covariant basis vectors g[0] = g[1] = g[2] = vec3d(0,0,0); for (i=0; i<neln; ++i) { g[0] += (r[i] - D[i]*(1-eta)/2)*Mr[i]; g[1] += (r[i] - D[i]*(1-eta)/2)*Ms[i]; g[2] += D[i]*(M[i]/2); } } //----------------------------------------------------------------------------- //! calculates covariant basis vectors at an integration point at intermediate time void FESSIShellDomain::CoBaseVectors(FEShellElement& el, int n, vec3d g[3], const double alpha) { vec3d gt[3], gp[3]; // CoBaseVectors(el, n, gt); gt[0] = el.m_gt[0][n]; gt[1] = el.m_gt[1][n]; gt[2] = el.m_gt[2][n]; // CoBaseVectorsP(el, n, gp); gp[0] = el.m_gp[0][n]; gp[1] = el.m_gp[1][n]; gp[2] = el.m_gp[2][n]; for (int i=0; i<3; ++i) g[i] = gt[i]*alpha + gp[i]*(1-alpha); } //----------------------------------------------------------------------------- //! calculates covariant basis vectors at an integration point void FESSIShellDomain::CoBaseVectors(FEShellElement& el, double r, double s, double t, vec3d g[3]) { int i; int neln = el.Nodes(); // current nodal coordinates and directors vec3d rt[FEElement::MAX_NODES], D[FEElement::MAX_NODES]; for (i=0; i<neln; ++i) { FENode& ni = m_pMesh->Node(el.m_node[i]); rt[i] = ni.m_rt; D[i] = m_bnodalnormals ? ni.m_d0 : el.m_d0[i]; D[i] += ni.get_vec3d(m_dofU[0], m_dofU[1], m_dofU[2]) - ni.get_vec3d(m_dofSU[0], m_dofSU[1], m_dofSU[2]); } double eta = t; double M[FEElement::MAX_NODES]; double Mr[FEElement::MAX_NODES]; double Ms[FEElement::MAX_NODES]; el.shape_fnc(M, r, s); el.shape_deriv(Mr, Ms, r, s); // initialize covariant basis vectors g[0] = g[1] = g[2] = vec3d(0,0,0); for (i=0; i<neln; ++i) { g[0] += (rt[i] - D[i]*(1-eta)/2)*Mr[i]; g[1] += (rt[i] - D[i]*(1-eta)/2)*Ms[i]; g[2] += D[i]*(M[i]/2); } } //----------------------------------------------------------------------------- //! calculates covariant basis vectors at an integration point void FESSIShellDomain::CoBaseVectors(FEShellElement& el, double r, double s, double t, vec3d g[3], const double alpha) { int i; int neln = el.Nodes(); // current nodal coordinates and directors vec3d rt[FEElement::MAX_NODES], D[FEElement::MAX_NODES]; for (i=0; i<neln; ++i) { FENode& ni = m_pMesh->Node(el.m_node[i]); rt[i] = ni.m_rt*alpha + ni.m_rp*(1-alpha); D[i] = m_bnodalnormals ? ni.m_d0 : el.m_d0[i]; D[i] += (ni.get_vec3d(m_dofU[0], m_dofU[1], m_dofU[2]) - ni.get_vec3d(m_dofSU[0], m_dofSU[1], m_dofSU[2]))*alpha + (ni.get_vec3d_prev(m_dofU[0], m_dofU[1], m_dofU[2]) - ni.get_vec3d_prev(m_dofSU[0], m_dofSU[1], m_dofSU[2]))*(1-alpha); } double eta = t; double M[FEElement::MAX_NODES]; double Mr[FEElement::MAX_NODES]; double Ms[FEElement::MAX_NODES]; el.shape_fnc(M, r, s); el.shape_deriv(Mr, Ms, r, s); // initialize covariant basis vectors g[0] = g[1] = g[2] = vec3d(0,0,0); for (i=0; i<neln; ++i) { g[0] += (rt[i] - D[i]*(1-eta)/2)*Mr[i]; g[1] += (rt[i] - D[i]*(1-eta)/2)*Ms[i]; g[2] += D[i]*(M[i]/2); } } //----------------------------------------------------------------------------- //! calculates contravariant basis vectors at an integration point void FESSIShellDomain::ContraBaseVectors(FEShellElement& el, int n, vec3d gcnt[3]) { vec3d gcov[3]; // CoBaseVectors(el, n, gcov); gcov[0] = el.m_gt[0][n]; gcov[1] = el.m_gt[1][n]; gcov[2] = el.m_gt[2][n]; mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); mat3d Ji = J.inverse(); gcnt[0] = vec3d(Ji(0,0),Ji(0,1),Ji(0,2)); gcnt[1] = vec3d(Ji(1,0),Ji(1,1),Ji(1,2)); gcnt[2] = vec3d(Ji(2,0),Ji(2,1),Ji(2,2)); } //----------------------------------------------------------------------------- //! calculates contravariant basis vectors at an integration point void FESSIShellDomain::ContraBaseVectors(FEShellElement& el, int n, vec3d gcnt[3], const double alpha) { vec3d gcov[3]; CoBaseVectors(el, n, gcov, alpha); mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); mat3d Ji = J.inverse(); gcnt[0] = vec3d(Ji(0,0),Ji(0,1),Ji(0,2)); gcnt[1] = vec3d(Ji(1,0),Ji(1,1),Ji(1,2)); gcnt[2] = vec3d(Ji(2,0),Ji(2,1),Ji(2,2)); } //----------------------------------------------------------------------------- //! calculates contravariant basis vectors at an integration point void FESSIShellDomain::ContraBaseVectors(FEShellElement& el, double r, double s, double t, vec3d gcnt[3]) { vec3d gcov[3]; CoBaseVectors(el, r, s, t, gcov); mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); mat3d Ji = J.inverse(); gcnt[0] = vec3d(Ji(0,0),Ji(0,1),Ji(0,2)); gcnt[1] = vec3d(Ji(1,0),Ji(1,1),Ji(1,2)); gcnt[2] = vec3d(Ji(2,0),Ji(2,1),Ji(2,2)); } //----------------------------------------------------------------------------- //! calculates contravariant basis vectors at an integration point void FESSIShellDomain::ContraBaseVectors(FEShellElement& el, double r, double s, double t, vec3d gcnt[3], const double alpha) { vec3d gcov[3]; CoBaseVectors(el, r, s, t, gcov, alpha); mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); mat3d Ji = J.inverse(); gcnt[0] = vec3d(Ji(0,0),Ji(0,1),Ji(0,2)); gcnt[1] = vec3d(Ji(1,0),Ji(1,1),Ji(1,2)); gcnt[2] = vec3d(Ji(2,0),Ji(2,1),Ji(2,2)); } //----------------------------------------------------------------------------- // jacobian with respect to current frame double FESSIShellDomain::detJ(FEShellElement& el, int n) { vec3d gcov[3]; // CoBaseVectors(el, n, gcov); gcov[0] = el.m_gt[0][n]; gcov[1] = el.m_gt[1][n]; gcov[2] = el.m_gt[2][n]; mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); return J.det(); } //----------------------------------------------------------------------------- // jacobian with respect to intermediate time frame double FESSIShellDomain::detJ(FEShellElement& el, int n, const double alpha) { vec3d gcovt[3], gcovp[3], gcov[3]; // CoBaseVectors(el, n, gcovt); gcovt[0] = el.m_gt[0][n]; gcovt[1] = el.m_gt[1][n]; gcovt[2] = el.m_gt[2][n]; // CoBaseVectorsP(el, n, gcovp); gcovp[0] = el.m_gp[0][n]; gcovp[1] = el.m_gp[1][n]; gcovp[2] = el.m_gp[2][n]; for (int i=0; i<3; ++i) gcov[i] = gcovt[i]*alpha + gcovp[i]*(1-alpha); mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); return J.det(); } //----------------------------------------------------------------------------- // jacobian with respect to current frame double FESSIShellDomain::detJ(FEShellElement& el, double r, double s, double t) { vec3d gcov[3]; CoBaseVectors(el, r, s, t, gcov); mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); return J.det(); } //----------------------------------------------------------------------------- double FESSIShellDomain::defgrad(FEShellElement& el, mat3d& F, int n) { vec3d gcov[3], Gcnt[3]; // CoBaseVectors(el, n, gcov); gcov[0] = el.m_gt[0][n]; gcov[1] = el.m_gt[1][n]; gcov[2] = el.m_gt[2][n]; // ContraBaseVectors0(el, n, Gcnt); Gcnt[0] = el.m_G0[0][n]; Gcnt[1] = el.m_G0[1][n]; Gcnt[2] = el.m_G0[2][n]; F = (gcov[0] & Gcnt[0]) + (gcov[1] & Gcnt[1]) + (gcov[2] & Gcnt[2]); double J = F.det(); if (J <= 0) throw NegativeJacobian(el.GetID(), n, J, &el); return J; } //----------------------------------------------------------------------------- double FESSIShellDomain::defgradp(FEShellElement& el, mat3d& F, int n) { vec3d gcov[3], Gcnt[3]; // CoBaseVectorsP(el, n, gcov); gcov[0] = el.m_gp[0][n]; gcov[1] = el.m_gp[1][n]; gcov[2] = el.m_gp[2][n]; // ContraBaseVectors0(el, n, Gcnt); Gcnt[0] = el.m_G0[0][n]; Gcnt[1] = el.m_G0[1][n]; Gcnt[2] = el.m_G0[2][n]; F = (gcov[0] & Gcnt[0]) + (gcov[1] & Gcnt[1]) + (gcov[2] & Gcnt[2]); double J = F.det(); if (J <= 0) throw NegativeJacobian(el.GetID(), n, J, &el); return J; } //----------------------------------------------------------------------------- double FESSIShellDomain::defgrad(FEShellElement& el, mat3d& F, double r, double s, double t) { vec3d gcov[3], Gcnt[3]; CoBaseVectors(el, r, s, t, gcov); ContraBaseVectors0(el, r, s, t, Gcnt); F = (gcov[0] & Gcnt[0]) + (gcov[1] & Gcnt[1]) + (gcov[2] & Gcnt[2]); double J = F.det(); if (J <= 0) throw NegativeJacobian(el.GetID(), -1, J, &el); return J; } //----------------------------------------------------------------------------- //! evaluate a vector function over the shell vec3d FESSIShellDomain::evaluate(FEShellElement& el, vec3d* vn, vec3d* dvn, int n) { vec3d gcnt[3]; // ContraBaseVectors(el, n, gcnt); gcnt[0] = el.m_Gt[0][n]; gcnt[1] = el.m_Gt[1][n]; gcnt[2] = el.m_Gt[2][n]; double eta = el.gt(n); const double* M = el.H(n); vec3d v(0, 0, 0); int neln = el.Nodes(); for (int i=0; i<neln; ++i) { double Mu = (1+eta)/2*M[i]; double Md = (1-eta)/2*M[i]; v += vn[i]*Mu + dvn[i]*Md; } return v; } //----------------------------------------------------------------------------- //! Calculate the inverse jacobian with respect to the current frame at //! integration point n. The inverse jacobian is return in Ji. The return value //! is the determinant of the jacobian (not the inverse!) double FESSIShellDomain::invjact(FEShellElement& el, double Ji[3][3], int n) { vec3d gcov[3]; // CoBaseVectors(el, n, gcov); gcov[0] = el.m_gt[0][n]; gcov[1] = el.m_gt[1][n]; gcov[2] = el.m_gt[2][n]; mat3d J = mat3d(gcov[0].x, gcov[1].x, gcov[2].x, gcov[0].y, gcov[1].y, gcov[2].y, gcov[0].z, gcov[1].z, gcov[2].z); double det = J.det(); // make sure the determinant is positive if (det <= 0) throw NegativeJacobian(el.GetID(), n+1, det); // calculate the inverse of the jacobian double deti = 1.0 / det; Ji[0][0] = deti*(J[1][1]*J[2][2] - J[1][2]*J[2][1]); Ji[1][0] = deti*(J[1][2]*J[2][0] - J[1][0]*J[2][2]); Ji[2][0] = deti*(J[1][0]*J[2][1] - J[1][1]*J[2][0]); Ji[0][1] = deti*(J[0][2]*J[2][1] - J[0][1]*J[2][2]); Ji[1][1] = deti*(J[0][0]*J[2][2] - J[0][2]*J[2][0]); Ji[2][1] = deti*(J[0][1]*J[2][0] - J[0][0]*J[2][1]); Ji[0][2] = deti*(J[0][1]*J[1][2] - J[1][1]*J[0][2]); Ji[1][2] = deti*(J[0][2]*J[1][0] - J[0][0]*J[1][2]); Ji[2][2] = deti*(J[0][0]*J[1][1] - J[0][1]*J[1][0]); return det; } //----------------------------------------------------------------------------- //! evaluate a scalar function over the shell double FESSIShellDomain::evaluate(FEShellElement& el, double* pn, double* dpn, int n) { vec3d gcnt[3]; // ContraBaseVectors(el, n, gcnt); gcnt[0] = el.m_Gt[0][n]; gcnt[1] = el.m_Gt[1][n]; gcnt[2] = el.m_Gt[2][n]; double eta = el.gt(n); const double* M = el.H(n); double p = 0; int neln = el.Nodes(); for (int i=0; i<neln; ++i) { double Mu = (1+eta)/2*M[i]; double Md = (1-eta)/2*M[i]; p += Mu*pn[i] + Md*dpn[i]; } return p; } //----------------------------------------------------------------------------- //! calculate the gradient of a scalar function over the shell vec3d FESSIShellDomain::gradient(FEShellElement& el, double* pn, double* dpn, int n) { vec3d gcnt[3]; // ContraBaseVectors(el, n, gcnt); gcnt[0] = el.m_Gt[0][n]; gcnt[1] = el.m_Gt[1][n]; gcnt[2] = el.m_Gt[2][n]; double eta = el.gt(n); const double* Mr = el.Hr(n); const double* Ms = el.Hs(n); const double* M = el.H(n); vec3d gradp(0, 0, 0); int neln = el.Nodes(); for (int i=0; i<neln; ++i) { vec3d gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; vec3d gradMu = (gradM*(1+eta) + gcnt[2]*M[i])/2; vec3d gradMd = (gradM*(1-eta) - gcnt[2]*M[i])/2; gradp += gradMu*pn[i] + gradMd*dpn[i]; } return gradp; } //----------------------------------------------------------------------------- //! evaluate a scalar function over the shell double FESSIShellDomain::evaluate(FEShellElement& el, vector<double> pn, vector<double> dpn, int n) { vec3d gcnt[3]; // ContraBaseVectors(el, n, gcnt); gcnt[0] = el.m_Gt[0][n]; gcnt[1] = el.m_Gt[1][n]; gcnt[2] = el.m_Gt[2][n]; double eta = el.gt(n); const double* M = el.H(n); double p = 0; int neln = el.Nodes(); for (int i=0; i<neln; ++i) { double Mu = (1+eta)/2*M[i]; double Md = (1-eta)/2*M[i]; p += Mu*pn[i] + Md*dpn[i]; } return p; } //----------------------------------------------------------------------------- //! calculate the gradient of a scalar function over the shell vec3d FESSIShellDomain::gradient(FEShellElement& el, vector<double> pn, vector<double> dpn, int n) { vec3d gcnt[3]; // ContraBaseVectors(el, n, gcnt); gcnt[0] = el.m_Gt[0][n]; gcnt[1] = el.m_Gt[1][n]; gcnt[2] = el.m_Gt[2][n]; double eta = el.gt(n); const double* Mr = el.Hr(n); const double* Ms = el.Hs(n); const double* M = el.H(n); int neln = el.Nodes(); vec3d gradp(0, 0, 0); for (int i=0; i<neln; ++i) { vec3d gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; vec3d gradMu = (gradM*(1+eta) + gcnt[2]*M[i])/2; vec3d gradMd = (gradM*(1-eta) - gcnt[2]*M[i])/2; gradp += gradMu*pn[i] + gradMd*dpn[i]; } return gradp; } void FESSIShellDomain::Update(const FETimeInfo& tp) { int NS = Elements(); FEMesh& mesh = *GetMesh(); int NE = Elements(); #pragma omp parallel for for (int i = 0; i < NE; ++i) { FEShellElement& e = Element(i); if (e.isActive()) { int n = e.Nodes(); for (int j = 0; j < n; ++j) { FENode& nj = mesh.Node(e.m_node[j]); vec3d D = nj.m_dt; double h = D.norm(); e.m_ht[j] = h; } vec3d g[3]; int ni = e.GaussPoints(); for (int j = 0; j < ni; ++j) { CoBaseVectors(e, j, g); e.m_gt[0][j] = g[0]; e.m_gt[1][j] = g[1]; e.m_gt[2][j] = g[2]; CoBaseVectorsP(e, j, g); e.m_gp[0][j] = g[0]; e.m_gp[1][j] = g[1]; e.m_gp[2][j] = g[2]; // NOTE: calculate covariant vectors first since contravariant depends on them ContraBaseVectors(e, j, g); e.m_Gt[0][j] = g[0]; e.m_Gt[1][j] = g[1]; e.m_Gt[2][j] = g[2]; } } }; } //================================================================================================= template <class T> void _writeIntegratedElementValueT(FESSIShellDomain& dom, FEDataStream& ar, std::function<T (const FEMaterialPoint& mp)> fnc) { for (int i = 0; i<dom.Elements(); ++i) { FEShellElement& el = dom.Element(i); double* gw = el.GaussWeights(); // integrate T ew(0.0); for (int j = 0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); T vj = fnc(mp); double detJ = dom.detJ0(el, j)*gw[j]; ew += vj*detJ; } ar << ew; } } void writeIntegratedElementValue(FESSIShellDomain& dom, FEDataStream& ar, std::function<double(const FEMaterialPoint& mp)> fnc) { _writeIntegratedElementValueT<double>(dom, ar, fnc); } void writeIntegratedElementValue(FESSIShellDomain& dom, FEDataStream& ar, std::function<vec3d (const FEMaterialPoint& mp)> fnc) { _writeIntegratedElementValueT<vec3d >(dom, ar, fnc); }
C++
3D
febiosoftware/FEBio
FEBioMech/FEFiberExpLinear.cpp
.cpp
6,219
214
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include <limits> #include "FEFiberExpLinear.h" #include <FECore/expint_Ei.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEFiberExpLinear, FEFiberMaterial) ADD_PARAMETER(m_c3, FE_RANGE_GREATER_OR_EQUAL(0.0), "c3")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c4, FE_RANGE_GREATER_OR_EQUAL(0.0), "c4"); ADD_PARAMETER(m_c5, FE_RANGE_GREATER_OR_EQUAL(0.0), "c5")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_lam1, FE_RANGE_GREATER_OR_EQUAL(1.0), "lambda"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FEFiberExpLinear::FEFiberExpLinear(FEModel* pfem) : FEFiberMaterial(pfem) { m_c3 = 0; m_c4 = 0; m_c5 = 0; m_lam1 = 1.0; m_epsf = 0.0; } //----------------------------------------------------------------------------- //! Calculate the fiber stress mat3ds FEFiberExpLinear::FiberStress(FEMaterialPoint& mp, const vec3d& a0) { // get the material point data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // get the spatial fiber vector and stretch vec3d a = pt.m_F * a0; double l = a.unit(); // fiber stress mat3ds s; s.zero(); if (l >= 1.0) { // other stuff we need mat3ds A = dyad(a); double J = pt.m_J; double c3 = m_c3(mp); double c4 = m_c4(mp); double c5 = m_c5(mp); double lam1 = m_lam1(mp); // if c3==0 we enforce continuity of the slope if (c3 == 0) { c3 = c5 / c4 * exp(-c4 * (lam1 - 1)); } // calculate fiber stress double Wl = 0.0; if (l < lam1) { Wl = c3 * (exp(c4 * (l - 1.0)) - 1.0); } else { // c6 is chosen so that continuity of the stress is always enforced double c6 = c3 * (exp(c4 * (lam1 - 1.0)) - 1.0) - c5 * lam1; Wl = c5 * l + c6; } s += A * (Wl / J); } return s; } //----------------------------------------------------------------------------- //! Calculate the fiber tangent tens4ds FEFiberExpLinear::FiberTangent(FEMaterialPoint& mp, const vec3d& a0) { double eps = m_epsf * std::numeric_limits<double>::epsilon(); // get material point data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // get the spatial fiber axis vec3d a = pt.m_F * a0; double l = a.unit(); // fiber tangent tens4ds c(0.0); if (l >= 1.0 + eps) { // Invariants of B (= invariants of C) double J = pt.m_J; double I4 = l * l; // some useful tensors mat3dd I(1.0); mat3ds A = dyad(a); tens4ds AxA = dyad1s(A); double c3 = m_c3(mp); double c4 = m_c4(mp); double c5 = m_c5(mp); double lam1 = m_lam1(mp); // if c3==0 we enforce continuity of the slope if (c3 == 0) { c3 = c5 / c4 * exp(-c4 * (lam1 - 1)); } double Fl = 0.0, Fll = 0.0; if (l < lam1) { Fl = c3 * (exp(c4 * (l - 1.0)) - 1.0) / l; Fll = -c3 * (exp(c4 * (l - 1.0)) - 1.0) / (l * l) + c3 * c4 * exp(c4 * (l - 1.0)) / l; } else { // c6 is chosen so that continuity of the stress is always enforced double c6 = c3 * (exp(c4 * (lam1 - 1.0)) - 1.0) - c5 * lam1; Fl = c5 + c6 / l; Fll = -c6 / (l * l); } double W44 = (Fll - Fl / l) / (4 * l * l); c += AxA * (4.0 * W44 * I4 * I4 / J); } return c; } //----------------------------------------------------------------------------- //! Calculate the fiber strain energy density double FEFiberExpLinear::FiberStrainEnergyDensity(FEMaterialPoint& mp, const vec3d& a0) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // get the deformation gradient mat3d F = pt.m_F; // calculate the current material axis lam*a = F*a0; vec3d a = F * a0; // normalize material axis and store fiber stretch double lam = a.unit(); // strain energy density double sed = 0.0; if (lam >= 1) { double c3 = m_c3(mp); double c4 = m_c4(mp); double c5 = m_c5(mp); double lam1 = m_lam1(mp); // if c3==0 we enforce continuity of the slope if (c3 == 0) c3 = c5 / c4 * exp(-c4 * (lam1 - 1)); if (lam < lam1) { sed = c3 * exp(-c4) * (expint_Ei(c4 * lam) - expint_Ei(c4)) - c3 * log(lam); } else { // c6 is chosen so that continuity of the stress is always enforced double c6 = c3 * (exp(c4 * (lam1 - 1.0)) - 1.0) - c5 * lam1; sed = c5 * (lam - lam1) + c6 * log(lam / lam1) + c3 * exp(-c4) * (expint_Ei(c4 * lam1) - expint_Ei(c4)) - c3 * log(lam1); } } return sed; } //============================================================================================ // define the material parameters BEGIN_FECORE_CLASS(FEElasticFiberExpLinear, FEElasticFiberMaterial) ADD_PARAMETER(m_fib.m_c3, FE_RANGE_GREATER_OR_EQUAL(0.0), "c3")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_fib.m_c4, FE_RANGE_GREATER_OR_EQUAL(0.0), "c4"); ADD_PARAMETER(m_fib.m_c5, FE_RANGE_GREATER_OR_EQUAL(0.0), "c5")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_fib.m_lam1, FE_RANGE_GREATER_OR_EQUAL(1.0), "lambda"); END_FECORE_CLASS();
C++
3D
febiosoftware/FEBio
FEBioMech/FEEFDNeoHookean.cpp
.cpp
4,978
171
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEEFDNeoHookean.h" // define the material parameters BEGIN_FECORE_CLASS(FEEFDNeoHookean, FEElasticMaterial) ADD_PARAMETER(m_NH.m_E, "E")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_NH.m_v, "v"); ADD_PARAMETER(m_EFD.m_beta, 3, "beta"); ADD_PARAMETER(m_EFD.m_ksi , 3, "ksi" )->setUnits(UNIT_PRESSURE); END_FECORE_CLASS(); ////////////////////////////////////////////////////////////////////// // FEEFDNeoHookean ////////////////////////////////////////////////////////////////////// FEEFDNeoHookean::FEEFDNeoHookean(FEModel* pfem) : FEElasticMaterial(pfem), m_EFD(pfem), m_NH(pfem) { int a = 0; } bool FEEFDNeoHookean::Init() { if (FEElasticMaterial::Init() == false) return false; if (m_NH.Init() == false) return false; if (m_EFD.Init() == false) return false; return true; } void FEEFDNeoHookean::Serialize(DumpStream& ar) { FEElasticMaterial::Serialize(ar); m_NH.Serialize(ar); m_EFD.Serialize(ar); } mat3ds FEEFDNeoHookean::Stress(FEMaterialPoint& mp) { // --- M A T R I X C O N T R I B U T I O N --- mat3ds s = m_NH.Stress(mp); // --- F I B E R C O N T R I B U T I O N --- // evaluate stress and add it to matrix contribution s += m_EFD.Stress(mp); return s; } tens4ds FEEFDNeoHookean::Tangent(FEMaterialPoint& mp) { // --- M A T R I X C O N T R I B U T I O N --- tens4ds c = m_NH.Tangent(mp); // --- F I B E R C O N T R I B U T I O N --- // evaluate stress and add it to matrix contribution c += m_EFD.Tangent(mp); return c; } //----------------------------------------------------------------------------- //! calculate strain energy density at material point double FEEFDNeoHookean::StrainEnergyDensity(FEMaterialPoint& mp) { // --- M A T R I X C O N T R I B U T I O N --- double sed = m_NH.StrainEnergyDensity(mp); // --- F I B E R C O N T R I B U T I O N --- sed += m_EFD.StrainEnergyDensity(mp); return sed; } ////////////////////////////////////////////////////////////////////// // FEEFDNeoHookeanOld ////////////////////////////////////////////////////////////////////// // define the material parameters BEGIN_FECORE_CLASS(FEEFDNeoHookeanOld, FEElasticMaterial) ADD_PARAMETER(m_NH.m_E, "E")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_NH.m_v, "v"); ADD_PARAMETER(m_EFD.m_beta, 3, "beta"); ADD_PARAMETER(m_EFD.m_ksi , 3, "ksi" )->setUnits(UNIT_PRESSURE); END_FECORE_CLASS(); bool FEEFDNeoHookeanOld::Init() { if (FEElasticMaterial::Init() == false) return false; if (m_NH.Init() == false) return false; if (m_EFD.Init() == false) return false; return true; } void FEEFDNeoHookeanOld::Serialize(DumpStream& ar) { FEElasticMaterial::Serialize(ar); m_NH.Serialize(ar); m_EFD.Serialize(ar); } mat3ds FEEFDNeoHookeanOld::Stress(FEMaterialPoint& mp) { // --- M A T R I X C O N T R I B U T I O N --- mat3ds s = m_NH.Stress(mp); // --- F I B E R C O N T R I B U T I O N --- // evaluate stress and add it to matrix contribution s += m_EFD.Stress(mp); return s; } tens4ds FEEFDNeoHookeanOld::Tangent(FEMaterialPoint& mp) { // --- M A T R I X C O N T R I B U T I O N --- tens4ds c = m_NH.Tangent(mp); // --- F I B E R C O N T R I B U T I O N --- // evaluate stress and add it to matrix contribution c += m_EFD.Tangent(mp); return c; } //----------------------------------------------------------------------------- //! calculate strain energy density at material point double FEEFDNeoHookeanOld::StrainEnergyDensity(FEMaterialPoint& mp) { // --- M A T R I X C O N T R I B U T I O N --- double sed = m_NH.StrainEnergyDensity(mp); // --- F I B E R C O N T R I B U T I O N --- sed += m_EFD.StrainEnergyDensity(mp); return sed; }
C++
3D
febiosoftware/FEBio
FEBioMech/FERigidMaterial.h
.h
3,009
88
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticMaterial.h" //----------------------------------------------------------------------------- //! Rigd body material data //! Since rigid elements are skipped during the stiffness and residual calculations //! we don't implement the Stress and Tangent functions //! \todo make the m_rc a parameter //! \todo Can I remove the m_bc variable? class FERigidMaterial : public FESolidMaterial { public: FERigidMaterial(FEModel* pfem); public: double m_E; //!< Young's modulus double m_v; //!< Poisson's ratio vec3d m_rc; //!< center of mass public: int m_pmid; //!< parent material ID bool m_com; //!< center of mass input flag int m_nRB; //!< rigid body ID (TODO: rigid materials can be assigned to mulitple rigid bodies, so does it make sense to store this?) public: // inherited from FEMaterial bool IsRigid() const override { return true; } public: //! get the ID of the rigid body this material is assigned to (-1 if not) int GetRigidBodyID() { return m_nRB; } //! Set the rigid body ID this material is assigned to void SetRigidBodyID(int rid) { m_nRB = rid; } public: //! Create a rigid material point FEMaterialPointData* CreateMaterialPointData() override { return new FEElasticMaterialPoint(); } //! calculate stress at material point virtual mat3ds Stress(FEMaterialPoint& pt) override { return mat3ds(); } //! calculate tangent stiffness at material point virtual tens4ds Tangent(FEMaterialPoint& pt) override { return tens4ds(); } //! data initialization bool Init() override; //! serialization void Serialize(DumpStream& ar) override; // declare a parameter list DECLARE_FECORE_CLASS(); private: bool m_binit; //!< flag for first initialization };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEFiberNaturalNeoHookean.cpp
.cpp
4,841
155
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2020 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include <limits> #include "FEFiberNaturalNeoHookean.h" //----------------------------------------------------------------------------- // FEFiberNH //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEFiberNaturalNH, FEFiberMaterial) ADD_PARAMETER(m_ksi, FE_RANGE_GREATER_OR_EQUAL(0.0), "ksi"); ADD_PARAMETER(m_lam0 , FE_RANGE_GREATER_OR_EQUAL(1.0), "lam0"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEFiberNaturalNH::FEFiberNaturalNH(FEModel* pfem) : FEFiberMaterial(pfem) { m_ksi = 0; m_lam0 = 1; m_epsf = 1; } //----------------------------------------------------------------------------- mat3ds FEFiberNaturalNH::FiberStress(FEMaterialPoint& mp, const vec3d& n0) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; double ksi = m_ksi(mp); double lam0 = m_lam0(mp); // get stretch ratio lamn along fiber vec3d nt = F*n0; double lamn = nt.unit(); double epsn = log(lamn/lam0); const double epsf = m_epsf* std::numeric_limits<double>::epsilon(); // only take fibers in tension into consideration mat3ds s; if (epsn > epsf) { // calculate the outer product of nt mat3ds N = dyad(nt); // calculate the fiber stress s = N*(ksi*epsn/J); } else { s.zero(); } return s; } //----------------------------------------------------------------------------- tens4ds FEFiberNaturalNH::FiberTangent(FEMaterialPoint& mp, const vec3d& n0) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; double ksi = m_ksi(mp); double lam0 = m_lam0(mp); // get stretch ratio lamn along fiber vec3d nt = F*n0; double lamn = nt.unit(); double epsn = log(lamn/lam0); const double epsf = m_epsf* std::numeric_limits<double>::epsilon(); // only take fibers in tension into consideration tens4ds c; if (epsn > epsf) { // calculate the outer product of nt mat3ds N = dyad(nt); tens4ds NxN = dyad1s(N); // calculate the fiber tangent c = NxN*(ksi*(1-2*epsn)/J); } else { c.zero(); } return c; } //----------------------------------------------------------------------------- //! Strain energy density double FEFiberNaturalNH::FiberStrainEnergyDensity(FEMaterialPoint& mp, const vec3d& n0) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient mat3d &F = pt.m_F; double ksi = m_ksi(mp); double lam0 = m_lam0(mp); // get stretch ratio lamn along fiber vec3d nt = F*n0; double lamn = nt.unit(); double epsn = log(lamn/lam0); const double epsf = m_epsf* std::numeric_limits<double>::epsilon(); // only take fibers in tension into consideration double sed = 0.0; if (epsn > epsf) sed = 0.5*ksi*epsn*epsn; return sed; } // define the material parameters BEGIN_FECORE_CLASS(FEElasticFiberNaturalNH, FEElasticFiberMaterial) ADD_PARAMETER(m_fib.m_ksi, FE_RANGE_GREATER_OR_EQUAL(0.0), "ksi"); ADD_PARAMETER(m_fib.m_lam0 , FE_RANGE_GREATER_OR_EQUAL(1.0), "lam0"); END_FECORE_CLASS();
C++
3D
febiosoftware/FEBio
FEBioMech/FERigidContractileForce.h
.h
3,133
88
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECore/vec3d.h" #include "FERigidConnector.h" //----------------------------------------------------------------------------- //! The FERigidContractileForce class implements a contractile force between //! arbitrary points (not necessarily nodes) on two rigid bodies. class FERigidContractileForce : public FERigidConnector { public: //! constructor FERigidContractileForce(FEModel* pfem); //! destructor ~FERigidContractileForce() {} //! initialization bool Init() override; //! calculates the joint forces void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! calculates the joint stiffness void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! calculate Lagrangian augmentation bool Augment(int naug, const FETimeInfo& tp) override; //! serialize data to archive void Serialize(DumpStream& ar) override; //! update state void Update() override; //! Reset data void Reset() override; //! evaluate relative translation vec3d RelativeTranslation(const bool global) override; //! evaluate relative rotation vec3d RelativeRotation(const bool global) override; public: // parameters double m_f0; //! contractile force vec3d m_a0; //! initial absolute position vector of insertion on body A vec3d m_b0; //! initial absolute position vector of insertion on body B // output parameters vec3d m_at; //!< current absolute position of spring on body A vec3d m_bt; //!< current absolute position of spring on body B protected: vec3d m_qa0; //! initial relative position vector of insertion on body A vec3d m_qb0; //! initial relative position vector of insertion on body B DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FESolidDomainFactory.cpp
.cpp
6,485
189
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FESolidDomainFactory.h" #include "FERigidMaterial.h" #include "FEUncoupledMaterial.h" #include "FEElasticSolidDomain.h" #include "FEElasticShellDomain.h" #include "FELinearTrussDomain.h" #include "FERigidSolidDomain.h" #include "FERigidShellDomain.h" #include "FERemodelingElasticDomain.h" #include "FEUDGHexDomain.h" #include "FEUT4Domain.h" #include "FE3FieldElasticSolidDomain.h" #include "FEDiscreteElasticDomain.h" #include "FERemodelingElasticMaterial.h" #include "FECore/FEDiscreteMaterial.h" #include "FEDiscreteElementMaterial.h" #include "FESRIElasticSolidDomain.h" //----------------------------------------------------------------------------- FEDomain* FESolidDomainFactory::CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat) { FEModel* pfem = pmat->GetFEModel(); FE_Element_Class eclass = spec.eclass; FE_Element_Shape eshape = spec.eshape; FE_Element_Type etype = spec.etype; // this will store the domain we are going to allocate FEDomain* pd = nullptr; // try to allocate the domain if (eclass == FE_ELEM_SOLID) { if (dynamic_cast<FESolidMaterial*>(pmat) == nullptr) return nullptr; const char* sztype = nullptr; if (dynamic_cast<FERigidMaterial* >(pmat)) sztype = "rigid-solid"; else if (dynamic_cast<FERemodelingElasticMaterial*>(pmat)) sztype = "remodeling-solid"; else if (eshape == ET_HEX8) { // three-field implementation for uncoupled materials if (dynamic_cast<FEUncoupledMaterial*>(pmat) && (spec.m_bthree_field)) sztype = "three-field-solid"; else { if (etype == FE_HEX8G1) sztype = "udg-hex"; else sztype = "elastic-solid"; } } else if ((eshape == ET_TET10) || (eshape == ET_TET15) || (eshape == ET_TET20)) { if ((etype == FE_TET10G8RI4) || (etype == FE_TET10G4RI1)) { sztype = "sri-solid"; } else { if (dynamic_cast<FEUncoupledMaterial*>(pmat) && (spec.m_bthree_field)) sztype = "three-field-solid"; else sztype = "elastic-solid"; } } else if ((eshape == ET_HEX20) || (eshape == ET_HEX27) || (eshape == ET_PYRA13)) { // if (dynamic_cast<FEUncoupledMaterial*>(pmat) && (spec.m_bthree_field_hex)) sztype = "three-field-solid"; sztype = "elastic-solid"; } else if (eshape == ET_TET4) { if (spec.m_but4) sztype = "ut4-solid"; else sztype = "elastic-solid"; } else if (eshape == ET_TET5) { sztype = "elastic-solid"; } else if (eshape == ET_PENTA6) { // three-field implementation for uncoupled materials if (dynamic_cast<FEUncoupledMaterial*>(pmat) && (spec.m_bthree_field)) sztype = "three-field-solid"; else sztype = "elastic-solid"; } else if (eshape == ET_PENTA15) { // three-field implementation for uncoupled materials // if (dynamic_cast<FEUncoupledMaterial*>(pmat) && (spec.m_bthree_field_hex)) sztype = "three-field-solid"; sztype = "elastic-solid"; } else if (eshape == ET_PYRA5) { // three-field implementation for uncoupled materials if (dynamic_cast<FEUncoupledMaterial*>(pmat) && (spec.m_bthree_field)) sztype = "three-field-solid"; else sztype = "elastic-solid"; } if (sztype) pd = fecore_new<FESolidDomain>(sztype, pfem); } else if (eclass == FE_ELEM_SHELL) { if (dynamic_cast<FESolidMaterial*>(pmat) == nullptr) return nullptr; const char* sztype = nullptr; if (dynamic_cast<FERigidMaterial*>(pmat)) { if (spec.m_shell_formulation == OLD_SHELL) sztype = "rigid-shell-old"; else sztype = "rigid-shell"; } else if (dynamic_cast<FESolidMaterial*>(pmat)) { if ((eshape == ET_QUAD4) || (eshape == ET_TRI3) || (eshape == ET_QUAD8) || (eshape == ET_TRI6)) { switch (spec.m_shell_formulation) { case NEW_SHELL: // three-field implementation for uncoupled materials if (dynamic_cast<FEUncoupledMaterial*>(pmat)) { if (spec.m_bthree_field) sztype = "three-field-shell"; else if ((eshape == ET_QUAD4) && spec.m_bthree_field) sztype = "three-field-shell"; else if ((eshape == ET_TRI3) && spec.m_bthree_field) sztype = "three-field-shell"; else sztype = "elastic-shell"; } else sztype = "elastic-shell"; break; case OLD_SHELL: sztype = "elastic-shell-old"; break; case EAS_SHELL: sztype = "elastic-shell-eas"; break; case ANS_SHELL: sztype = "elastic-shell-ans"; break; default: return 0; } } } if (sztype) pd = fecore_new<FEShellDomain>(sztype, pfem); } else if (eclass == FE_ELEM_TRUSS) { const char* sztype = nullptr; if (dynamic_cast<FETrussMaterial*>(pmat)) if (eshape == ET_TRUSS2) sztype = "linear-truss"; if (sztype) pd = fecore_new<FETrussDomain>(sztype, pfem); } else if (eclass == FE_ELEM_DISCRETE) { const char* sztype = nullptr; if (dynamic_cast<FEDiscreteMaterial*>(pmat)) { // if (eclass == FE_ELEM_WIRE ) sztype = "deformable-spring"; if (eclass == FE_ELEM_WIRE ) sztype = "deformable-spring2"; else if (eclass == FE_ELEM_DISCRETE) { if (dynamic_cast<FEDiscreteElasticMaterial*>(pmat)) sztype = "discrete"; } else return 0; } if (sztype) pd = fecore_new<FEDiscreteDomain>(sztype, pfem); } if (pd) pd->SetMaterial(pmat); return pd; }
C++
3D
febiosoftware/FEBio
FEBioMech/FE3FieldElasticSolidDomain.cpp
.cpp
19,072
662
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include <limits> #include "FE3FieldElasticSolidDomain.h" #include "FEUncoupledMaterial.h" #include <FECore/FEModel.h> #include "FECore/log.h" //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FE3FieldElasticSolidDomain, FEElasticSolidDomain) ADD_PARAMETER(m_blaugon, "laugon"); ADD_PARAMETER(m_augtol , "atol"); ADD_PARAMETER(m_naugmin, "minaug"); ADD_PARAMETER(m_naugmax, "maxaug"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- void FE3FieldElasticSolidDomain::ELEM_DATA::Serialize(DumpStream& ar) { ar & eJ; ar & ep; ar & Lk; ar & eJt; ar & eJp; } //----------------------------------------------------------------------------- //! constructor FE3FieldElasticSolidDomain::FE3FieldElasticSolidDomain(FEModel* pfem) : FEElasticSolidDomain(pfem) { m_blaugon = false; m_augtol = 0.01; m_naugmin = 0; m_naugmax = 0; } //----------------------------------------------------------------------------- //! \todo Do I really use this? FE3FieldElasticSolidDomain& FE3FieldElasticSolidDomain::operator = (FE3FieldElasticSolidDomain& d) { m_Elem = d.m_Elem; m_pMesh = d.m_pMesh; return (*this); } //----------------------------------------------------------------------------- bool FE3FieldElasticSolidDomain::DoAugmentations() const { return m_blaugon; } //----------------------------------------------------------------------------- //! Initialize the 3-field domain data bool FE3FieldElasticSolidDomain::Init() { // make sure the domain material uses an uncoupled formulation if (dynamic_cast<FEUncoupledMaterial*>(m_pMat) == 0) return false; if (FEElasticSolidDomain::Init() == false) return false; // allocate element data int NE = Elements(); m_Data.resize(NE); // initialize element data for (int i=0; i<NE; ++i) { ELEM_DATA& d = m_Data[i]; d.eJ = d.eJt = d.eJp = 1.0; d.ep = 0.0; d.Lk = 0.0; } return true; } //----------------------------------------------------------------------------- void FE3FieldElasticSolidDomain::Reset() { FEElasticSolidDomain::Reset(); // initialize element data size_t NE = m_Data.size(); for (size_t i=0; i<NE; ++i) { ELEM_DATA& d = m_Data[i]; d.eJ = d.eJt = d.eJp = 1.0; d.ep = 0.0; d.Lk = 0.0; } } //----------------------------------------------------------------------------- //! Initialize element data void FE3FieldElasticSolidDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { FEElasticSolidDomain::PreSolveUpdate(timeInfo); int NE = (int)m_Data.size(); #pragma omp parallel for for (int i=0; i<NE; ++i) { ELEM_DATA& d = m_Data[i]; d.eJp = d.eJt; } } //----------------------------------------------------------------------------- //! Stiffness matrix for three-field domain void FE3FieldElasticSolidDomain::StiffnessMatrix(FELinearSystem& LS) { FEModel& fem = *GetFEModel(); // repeat over all solid elements int NE = (int)m_Elem.size(); #pragma omp parallel for for (int iel=0; iel<NE; ++iel) { FESolidElement& el = m_Elem[iel]; // element stiffness matrix FEElementMatrix ke(el); // create the element's stiffness matrix int ndof = 3*el.Nodes(); ke.resize(ndof, ndof); ke.zero(); // calculate material stiffness (i.e. constitutive component) ElementMaterialStiffness(iel, ke); // calculate geometrical stiffness ElementGeometricalStiffness(iel, ke); // Calculate dilatational stiffness ElementDilatationalStiffness(fem, iel, ke); // assign symmetic parts // TODO: Can this be omitted by changing the Assemble routine so that it only // grabs elements from the upper diagonal matrix? for (int i=0; i<ndof; ++i) for (int j=i+1; j<ndof; ++j) ke[j][i] = ke[i][j]; // get the element's LM vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- //! calculates dilatational element stiffness component for element iel void FE3FieldElasticSolidDomain::ElementDilatationalStiffness(FEModel& fem, int iel, matrix& ke) { int i, j, n; FESolidElement& elem = Element(iel); ELEM_DATA& ed = m_Data[iel]; const int nint = elem.GaussPoints(); const int neln = elem.Nodes(); const int ndof = 3*neln; // get the elements material FEUncoupledMaterial* pmi = dynamic_cast<FEUncoupledMaterial*>(m_pMat); assert(pmi); // average global derivatives vector<double> gradN(3*neln); zero(gradN); // initial element volume double Ve = 0; // global derivatives of shape functions double Gx, Gy, Gz; const double *gw = elem.GaussWeights(); // jacobian double Ji[3][3], Jt, J0; double *Gr, *Gs, *Gt; // repeat over gauss-points for (n=0; n<nint; ++n) { // calculate jacobian J0 = detJ0(elem, n); Jt = invjact(elem, Ji, n, m_alphaf)*m_alphaf; Jt *= gw[n]; Ve += J0*gw[n]; Gr = elem.Gr(n); Gs = elem.Gs(n); Gt = elem.Gt(n); // calculate global gradient of shape functions // note that we need the transposed of Ji, not Ji itself ! for (i=0; i<neln; ++i) { Gx = Ji[0][0]*Gr[i]+Ji[1][0]*Gs[i]+Ji[2][0]*Gt[i]; Gy = Ji[0][1]*Gr[i]+Ji[1][1]*Gs[i]+Ji[2][1]*Gt[i]; Gz = Ji[0][2]*Gr[i]+Ji[1][2]*Gs[i]+Ji[2][2]*Gt[i]; gradN[3*i ] += Gx*Jt; gradN[3*i+1] += Gy*Jt; gradN[3*i+2] += Gz*Jt; } } // get effective modulus double k = pmi->UJJ(ed.eJ); // next, we add the Lagrangian contribution // note that this term will always be zero if the material does not // use the augmented lagrangian k += ed.Lk*pmi->hpp(ed.eJ); // divide by initial volume k /= Ve; // calculate dilatational stiffness component // we only calculate the upper triangular part // since ke is symmetric. for (i=0; i<ndof; ++i) for (j=i; j<ndof; ++j) ke[i][j] += k*gradN[i]*gradN[j]; } //----------------------------------------------------------------------------- //! Calculates element material stiffness element matrix void FE3FieldElasticSolidDomain::ElementMaterialStiffness(int iel, matrix &ke) { FESolidElement &el = Element(iel); ELEM_DATA& ed = m_Data[iel]; // Get the current element's data const int nint = el.GaussPoints(); const int neln = el.Nodes(); const int ndof = 3*neln; // global derivatives of shape functions const int NME = FEElement::MAX_NODES; vec3d G[NME]; double Gxi, Gyi, Gzi; double Gxj, Gyj, Gzj; // The 'D' matrix double D[6][6] = {0}; // The 'D' matrix // The 'D*BL' matrix double DBL[6][3]; // weights at gauss points const double *gw = el.GaussWeights(); // get the material FEUncoupledMaterial& mat = dynamic_cast<FEUncoupledMaterial&>(*m_pMat); // we need the following tensors for the dilational stiffness mat3dd I(1); tens4ds IxI = dyad1s(I); tens4ds I4 = dyad4s(I); tens4ds Cp = IxI - I4*2; // calculate element stiffness matrix for (int n=0; n<nint; ++n) { // calculate jacobian double detJt = ShapeGradient(el, n, G, m_alphaf)*gw[n]*m_alphaf; // setup the material point // NOTE: deformation gradient and determinant have already been evaluated in the stress routine FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); // get the material's tangent // Note that we are only grabbing the deviatoric tangent. // The other tangent terms depend on the pressure p // which we seperately tens4ds C = Cp*ed.ep + mat.DevTangent(mp); // get the 'D' matrix C.extract(D); // we only calculate the upper triangular part // since ke is symmetric. The other part is // determined below using this symmetry. for (int i = 0, i3 = 0; i<neln; ++i, i3 += 3) { Gxi = G[i].x; Gyi = G[i].y; Gzi = G[i].z; for (int j = i, j3 = i3; j<neln; ++j, j3 += 3) { Gxj = G[j].x; Gyj = G[j].y; Gzj = G[j].z; // calculate D*BL matrices DBL[0][0] = (D[0][0]*Gxj+D[0][3]*Gyj+D[0][5]*Gzj); DBL[0][1] = (D[0][1]*Gyj+D[0][3]*Gxj+D[0][4]*Gzj); DBL[0][2] = (D[0][2]*Gzj+D[0][4]*Gyj+D[0][5]*Gxj); DBL[1][0] = (D[1][0]*Gxj+D[1][3]*Gyj+D[1][5]*Gzj); DBL[1][1] = (D[1][1]*Gyj+D[1][3]*Gxj+D[1][4]*Gzj); DBL[1][2] = (D[1][2]*Gzj+D[1][4]*Gyj+D[1][5]*Gxj); DBL[2][0] = (D[2][0]*Gxj+D[2][3]*Gyj+D[2][5]*Gzj); DBL[2][1] = (D[2][1]*Gyj+D[2][3]*Gxj+D[2][4]*Gzj); DBL[2][2] = (D[2][2]*Gzj+D[2][4]*Gyj+D[2][5]*Gxj); DBL[3][0] = (D[3][0]*Gxj+D[3][3]*Gyj+D[3][5]*Gzj); DBL[3][1] = (D[3][1]*Gyj+D[3][3]*Gxj+D[3][4]*Gzj); DBL[3][2] = (D[3][2]*Gzj+D[3][4]*Gyj+D[3][5]*Gxj); DBL[4][0] = (D[4][0]*Gxj+D[4][3]*Gyj+D[4][5]*Gzj); DBL[4][1] = (D[4][1]*Gyj+D[4][3]*Gxj+D[4][4]*Gzj); DBL[4][2] = (D[4][2]*Gzj+D[4][4]*Gyj+D[4][5]*Gxj); DBL[5][0] = (D[5][0]*Gxj+D[5][3]*Gyj+D[5][5]*Gzj); DBL[5][1] = (D[5][1]*Gyj+D[5][3]*Gxj+D[5][4]*Gzj); DBL[5][2] = (D[5][2]*Gzj+D[5][4]*Gyj+D[5][5]*Gxj); ke[i3 ][j3 ] += (Gxi*DBL[0][0] + Gyi*DBL[3][0] + Gzi*DBL[5][0] )*detJt; ke[i3 ][j3+1] += (Gxi*DBL[0][1] + Gyi*DBL[3][1] + Gzi*DBL[5][1] )*detJt; ke[i3 ][j3+2] += (Gxi*DBL[0][2] + Gyi*DBL[3][2] + Gzi*DBL[5][2] )*detJt; ke[i3+1][j3 ] += (Gyi*DBL[1][0] + Gxi*DBL[3][0] + Gzi*DBL[4][0] )*detJt; ke[i3+1][j3+1] += (Gyi*DBL[1][1] + Gxi*DBL[3][1] + Gzi*DBL[4][1] )*detJt; ke[i3+1][j3+2] += (Gyi*DBL[1][2] + Gxi*DBL[3][2] + Gzi*DBL[4][2] )*detJt; ke[i3+2][j3 ] += (Gzi*DBL[2][0] + Gyi*DBL[4][0] + Gxi*DBL[5][0] )*detJt; ke[i3+2][j3+1] += (Gzi*DBL[2][1] + Gyi*DBL[4][1] + Gxi*DBL[5][1] )*detJt; ke[i3+2][j3+2] += (Gzi*DBL[2][2] + Gyi*DBL[4][2] + Gxi*DBL[5][2] )*detJt; } } } } //----------------------------------------------------------------------------- //! calculates element's geometrical stiffness component for each integration point void FE3FieldElasticSolidDomain::ElementGeometricalStiffness(int iel, matrix &ke) { FESolidElement &el = Element(iel); const int NME = FEElement::MAX_NODES; double Gx[NME], Gy[NME], Gz[NME]; double *Grn, *Gsn, *Gtn; double Gr, Gs, Gt; // nr of nodes int neln = el.Nodes(); // nr of integration points int nint = el.GaussPoints(); // jacobian double Ji[3][3], detJt; // weights at gauss points const double *gw = el.GaussWeights(); // stiffness component for the initial stress component of stiffness matrix double kab; // calculate geometrical element stiffness matrix for (int n=0; n<nint; ++n) { // calculate jacobian detJt = invjact(el, Ji, n, m_alphaf)*gw[n]*m_alphaf; Grn = el.Gr(n); Gsn = el.Gs(n); Gtn = el.Gt(n); for (int i = 0; i<neln; ++i) { Gr = Grn[i]; Gs = Gsn[i]; Gt = Gtn[i]; // calculate global gradient of shape functions // note that we need the transposed of Ji, not Ji itself ! Gx[i] = Ji[0][0]*Gr+Ji[1][0]*Gs+Ji[2][0]*Gt; Gy[i] = Ji[0][1]*Gr+Ji[1][1]*Gs+Ji[2][1]*Gt; Gz[i] = Ji[0][2]*Gr+Ji[1][2]*Gs+Ji[2][2]*Gt; } // get the material point data FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); // element's Cauchy-stress tensor at gauss point n // s is the voight vector mat3ds& s = pt.m_s; for (int i = 0; i<neln; ++i) for (int j = i; j<neln; ++j) { kab = (Gx[i]*(s.xx()*Gx[j]+s.xy()*Gy[j]+s.xz()*Gz[j]) + Gy[i]*(s.xy()*Gx[j]+s.yy()*Gy[j]+s.yz()*Gz[j]) + Gz[i]*(s.xz()*Gx[j]+s.yz()*Gy[j]+s.zz()*Gz[j]))*detJt; ke[3*i ][3*j ] += kab; ke[3*i+1][3*j+1] += kab; ke[3*i+2][3*j+2] += kab; } } } //----------------------------------------------------------------------------- //! This function loops over all elements and updates the stress void FE3FieldElasticSolidDomain::Update(const FETimeInfo& tp) { bool berr = false; int NE = (int) m_Elem.size(); #pragma omp parallel for shared(NE, berr) for (int i=0; i<NE; ++i) { try { UpdateElementStress(i, tp); } catch (NegativeJacobian e) { #pragma omp critical { berr = true; if (e.DoOutput()) feLogError(e.what()); } } } if (berr) throw NegativeJacobianDetected(); } //----------------------------------------------------------------------------- //! This function updates the stresses for elements using the three-field formulation. //! For such elements, the stress is a sum of a deviatoric stress, calculate by the //! material and a dilatational term. void FE3FieldElasticSolidDomain::UpdateElementStress(int iel, const FETimeInfo& tp) { double dt = GetFEModel()->GetTime().timeIncrement; // get the material FEUncoupledMaterial& mat = *(dynamic_cast<FEUncoupledMaterial*>(m_pMat)); // get the solid element FESolidElement& el = m_Elem[iel]; ELEM_DATA& ed = m_Data[iel]; // get the number of integration points int nint = el.GaussPoints(); // get the integration weights double* gw = el.GaussWeights(); // number of nodes int neln = el.Nodes(); // nodal coordinates const int NME = FEElement::MAX_NODES; vec3d r0[NME], r[NME], vel[NME], acc[NME]; for (int j=0; j<neln; ++j) { FENode& node = m_pMesh->Node(el.m_node[j]); r0[j] = node.m_r0; r[j] = node.m_rt*m_alphaf + node.m_rp*(1-m_alphaf); vel[j] = node.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2])*m_alphaf + node.m_vp*(1-m_alphaf); acc[j] = node.m_at*m_alpham + node.m_ap*(1-m_alpham); } // calculate the average dilatation and pressure double v = 0, vt = 0, V = 0; for (int n=0; n<nint; ++n) { v += detJt(el, n, m_alphaf)*gw[n]; vt+= detJt(el, n)*gw[n]; V += detJ0(el, n)*gw[n]; } // calculate volume ratio ed.eJ = v / V; ed.eJt = vt / V; double eUt = mat.U(ed.eJt); double eUp = mat.U(ed.eJp); // Calculate pressure. This is a sum of a Lagrangian term and a penalty term // <--- Lag. mult. --> <-- penalty --> ed.ep = ed.Lk*mat.hp(ed.eJ) + mat.UJ(ed.eJ); // ed.ep = mat.UJ(ed.eJ); // loop over the integration points and calculate // the stress at the integration point for (int n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); pt.m_p = ed.ep; // material point coordinates // TODO: I'm not entirly happy with this solution // since the material point coordinates are not used by most materials. mp.m_r0 = el.Evaluate(r0, n); mp.m_rt = el.Evaluate(r, n); // get the deformation gradient and determinant double Jt, Jp; mat3d Ft, Fp; Jt = defgrad(el, Ft, n); Jp = defgradp(el, Fp, n); pt.m_F = (m_alphaf==1.0? Ft : Ft*m_alphaf + Fp*(1-m_alphaf)); pt.m_J = pt.m_F.det(); mat3d Fi = pt.m_F.inverse(); pt.m_L = (Ft - Fp)*Fi/dt; pt.m_v = el.Evaluate(vel, n); pt.m_a = el.Evaluate(acc, n); // update specialized material points m_pMat->UpdateSpecializedMaterialPoints(mp, tp); // calculate the stress at this material point // Note that we don't call the material's Stress member function. // The reason is that we need to use the averaged pressure for the element // and the Stress function uses the pointwise pressure. // Therefore we call the DevStress function and add the pressure term // seperately. pt.m_s = mat.DevStress(mp); // adjust stress for strain energy conservation if (m_alphaf == 0.5) { // evaluate deviatoric strain energy at current and previous time mat3d Ftmp = pt.m_F; double Jtmp = pt.m_J; pt.m_F = Ft; pt.m_J = Jt; double Wt = mat.DevStrainEnergyDensity(mp); pt.m_F = Ftmp; pt.m_J = Jtmp; // store total strain energy density at current time pt.m_Wt = Wt + eUt; double Wp = pt.m_Wp; mat3ds D = pt.RateOfDeformation(); double D2 = D.dotdot(D); if (D2 > std::numeric_limits<double>::epsilon()) pt.m_s += D*(((Wt-Wp)/(dt*pt.m_J) - pt.m_s.dotdot(D))/D2); if (fabs(ed.eJt - ed.eJp) > std::numeric_limits<double>::epsilon()) pt.m_s += mat3dd((eUt-eUp)/(ed.eJ*(ed.eJt-ed.eJp))); } else pt.m_s += mat3dd(ed.ep); } } //----------------------------------------------------------------------------- //! Do augmentation bool FE3FieldElasticSolidDomain::Augment(int naug) { FEUncoupledMaterial* pmi = dynamic_cast<FEUncoupledMaterial*>(m_pMat); assert(pmi); // make sure Augmented Lagrangian flag is on if (m_blaugon == false) return true; // do the augmentation int n; double normL0 = 0, normL1 = 0, L0, L1; double k = pmi->m_K; FEMesh& mesh = *m_pMesh; int NE = Elements(); for (n=0; n<NE; ++n) { ELEM_DATA& ed = m_Data[n]; L0 = ed.Lk; normL0 += L0*L0; L1 = L0 + k*pmi->h(ed.eJ); normL1 += L1*L1; } normL0 = sqrt(normL0); normL1 = sqrt(normL1); // check convergence double pctn = 0; if (fabs(normL1) > 1e-10) pctn = fabs((normL1 - normL0)/normL1); feLog(" material %d\n", pmi->GetID()); feLog(" CURRENT CHANGE REQUIRED\n"); feLog(" pressure norm : %15le%15le%15le\n", normL1, pctn, m_augtol); // check convergence bool bconv = true; if (pctn >= m_augtol) bconv = false; if (m_naugmin > naug) bconv = false; if ((m_naugmax > 0) && (m_naugmax <= naug)) bconv = true; // do the augmentation only if we have not yet converged if (bconv == false) { for (n=0; n<NE; ++n) { ELEM_DATA& ed = m_Data[n]; double hi = pmi->h(ed.eJ); ed.Lk += k*pmi->h(ed.eJ); ed.ep = ed.Lk*pmi->hp(ed.eJ) + k*log(ed.eJ)/ed.eJ; } } return bconv; } //----------------------------------------------------------------------------- //! Data serialization void FE3FieldElasticSolidDomain::Serialize(DumpStream &ar) { FEElasticSolidDomain::Serialize(ar); ar & m_Data; }
C++
3D
febiosoftware/FEBio
FEBioMech/FECentrifugalBodyForce.h
.h
1,849
53
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEBodyForce.h" //----------------------------------------------------------------------------- //! This class defines a centrigufal force class FECentrifugalBodyForce : public FEBodyForce { public: FECentrifugalBodyForce(FEModel* pfem); vec3d force(FEMaterialPoint& mp) override; double divforce(FEMaterialPoint& mp) override; mat3d stiffness(FEMaterialPoint& mp) override; public: vec3d n; // rotation axis vec3d c; // point on axis of rotation (e.g., center of rotation) double w; // angular speed DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEPreStrainConstraint.cpp
.cpp
6,542
199
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEPreStrainConstraint.h" #include "FEElasticMixture.h" #include "FEUncoupledElasticMixture.h" #include "FEPreStrainElastic.h" #include <FECore/FECoreKernel.h> #include <FECore/FEMesh.h> #include <FECore/log.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEPreStrainConstraint, FENLConstraint) ADD_PARAMETER(m_laugon , "update" ); ADD_PARAMETER(m_tol , "tolerance"); ADD_PARAMETER(m_naugmin, "min_iters"); ADD_PARAMETER(m_naugmax, "max_iters"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEPreStrainConstraint::FEPreStrainConstraint(FEModel* pfem) : FENLConstraint(pfem) { m_laugon = true; // This feature requires augmentations so turn it on m_naugmin = 0; m_naugmax = -1; m_tol = 0.0; } bool FEPreStrainConstraint::Augment(int naug, const FETimeInfo& tp) { if (IsActive() == false) return true; if (m_laugon == false) return true; FEMesh& m = GetMesh(); int ND = m.Domains(); // do pre-strain augmentations bool bconv = true; for (int i=0; i<ND; ++i) { FEDomain& dom = m.Domain(i); FEMaterial* pmat = dom.GetMaterial(); FEPrestrainMaterial* pm = dynamic_cast<FEPrestrainMaterial*>(pmat); if (pm) bconv &= Augment(&dom, 0, naug); else { for (int j=0; j<pmat->Properties(); ++j) { FEPrestrainMaterial* pmj = dynamic_cast<FEPrestrainMaterial*>(pmat->GetProperty(j)); if (pmj) bconv &= Augment(&dom, j, naug); } } } return bconv; } //----------------------------------------------------------------------------- //! Check an augmentation for a specific domain/material pair bool FEPreStrainConstraint::Augment(FEDomain* psd, int n, int naug) { // make sure this is a prestrain material FEPrestrainMaterial* pmat = dynamic_cast<FEPrestrainMaterial*>(psd->GetMaterial()); if (pmat == nullptr) return true; // check convergence double max_err = 0; bool bconv = true; int NE = psd->Elements(); for (int i=0; i<NE; ++i) { FEElement& el = psd->ElementRef(i); int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FEMaterialPoint& mp = *(el.GetMaterialPoint(i)->GetPointData(n)); FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); FEPrestrainMaterialPoint& pt = *mp.ExtractData<FEPrestrainMaterialPoint>(); const mat3d& Fc = pt.PrestrainCorrection(); const mat3d& F = ep.m_F; mat3d Fc_next = UpdateFc(F, Fc, mp, pmat); mat3d U = Fc_next - Fc; double normU = U.norm(); if (normU >= max_err) max_err = normU; } } if ((m_tol > 0) && (max_err >= m_tol)) bconv = false; feLog("max norm = %lg (%lg)\n", max_err, m_tol); // ensure we have done the required min or max augmentations if (naug < m_naugmin) bconv = false; if ((m_naugmax >= 0)&&(naug >= m_naugmax)) bconv = true; // only augment when we did not converge if (bconv == false) { for (int i=0; i<NE; ++i) { FEElement& el = psd->ElementRef(i); int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FEMaterialPoint& mp = *(el.GetMaterialPoint(i)->GetPointData(n)); FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); FEPrestrainMaterialPoint& pt = *mp.ExtractData<FEPrestrainMaterialPoint>(); const mat3d& Fc = pt.PrestrainCorrection(); const mat3d& F = ep.m_F; mat3d Fc_next = UpdateFc(F, Fc, mp, pmat); pt.setPrestrainCorrection(Fc_next); } } } return bconv; } //----------------------------------------------------------------------------- mat3d FEGPAConstraint::UpdateFc(const mat3d& F, const mat3d& Fc_prev, FEMaterialPoint& mp, FEPrestrainMaterial* pmat) { return F * Fc_prev; } //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEInSituStretchConstraint, FEPreStrainConstraint) ADD_PARAMETER(m_max_stretch, "max_stretch"); ADD_PARAMETER(m_biso , "isochoric" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEInSituStretchConstraint::FEInSituStretchConstraint(FEModel* pfem) : FEPreStrainConstraint(pfem) { m_max_stretch = 0.0; m_biso = true; } //----------------------------------------------------------------------------- mat3d FEInSituStretchConstraint::UpdateFc(const mat3d& F, const mat3d& Fc_prev, FEMaterialPoint& mp, FEPrestrainMaterial* pmat) { FEPrestrainMaterialPoint& psp = *mp.ExtractData<FEPrestrainMaterialPoint>(); FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FEElasticMaterial* elasticMat = pmat->GetElasticMaterial(); if (elasticMat == nullptr) return mat3dd(1.0); FEVec3dValuator* fiber = dynamic_cast<FEVec3dValuator*>(elasticMat->GetProperty("fiber")); if (fiber == nullptr) return mat3dd(1.0); // calculate the fiber stretch mat3d Q = elasticMat->GetLocalCS(mp); vec3d a0 = fiber->unitVector(mp); vec3d ar = Q * a0; vec3d a = F*ar; double l = a.norm(); if ((m_max_stretch == 0.0) ||(l <= m_max_stretch)) { double li = (m_biso ? sqrt(l) : 1.0); // setup the new correction mat3d U(1.0/l, 0.0, 0.0, 0.0, li, 0.0, 0.0, 0.0, li); mat3d Fc = Q*U*Q.transpose(); return Fc; } else { return psp.PrestrainCorrection(); } }
C++
3D
febiosoftware/FEBio
FEBioMech/FEPointConstraint.h
.h
2,692
77
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FENLConstraint.h> #include <FECore/FESolidElement.h> #include <FECore/FEGlobalVector.h> #include <FECore/FEDofList.h> //----------------------------------------------------------------------------- //! This class implements a point constraint. That is, it forces a node of a //! mesh in the same relative position with respect to the element in which the //! node is located. class FEPointConstraint : public FENLConstraint { public: //! constructor FEPointConstraint(FEModel* pfem); //! initialize data bool Init() override; //! serialize void Serialize(DumpStream& ar) override; //! Calculate the constraint force void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! calculate the constraint stiffness void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! augmentations \todo implement this bool Augment(int naug, const FETimeInfo& tp) override { return true; } //! build connectivity for matrix profile void BuildMatrixProfile(FEGlobalMatrix& M) override; public: double m_eps; //!< penalty parameter int m_node_id; //!< id of node public: int m_node; //!< node to which the constraint is applied FESolidElement* m_pel; //!< element in which the node is located. double m_rs[3]; //!< natural coordinates in element m_pel FEDofList m_dofU; // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEActiveContractionMaterial.h
.h
2,278
53
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2022 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEMaterial.h> #include <FECore/tens4d.h> #include "febiomech_api.h" //----------------------------------------------------------------------------- //! A material class describing the active fiber contraction model of Estrada et al. in doi: 10.1115/1.4044030 class FEBIOMECH_API FEActiveContractionMaterial : public FEMaterialProperty { public: FEActiveContractionMaterial(FEModel* pfem) : FEMaterialProperty(pfem) {} virtual ~FEActiveContractionMaterial(){} //! calculate the active contractile stress virtual mat3ds ActiveStress(FEMaterialPoint& mp, const vec3d& a0) = 0; //! active contraction stiffness contribution virtual tens4ds ActiveStiffness(FEMaterialPoint& mp, const vec3d& a0) = 0; //! update force-velocity material point virtual void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp, const vec3d& a0) {} FECORE_BASE_CLASS(FEActiveContractionMaterial) };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEPrescribedDisplacement.h
.h
1,469
37
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2020 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEPrescribedDOF.h> class FEPrescribedDisplacement : public FEPrescribedDOF { public: FEPrescribedDisplacement(FEModel* fem); private: DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEEdgeToSurfaceContactPotential.cpp
.cpp
20,461
828
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEEdgeToSurfaceContactPotential.h" #include <FECore/FENode.h> #include <FECore/FEGlobalMatrix.h> #include <FECore/FELinearSystem.h> #include <FECore/FEBox.h> #include <stdexcept> void FEE2SCPSurface::Update() { // This assumes we are inside a omp parallel region! #pragma omp for for (int i = 0; i < Elements(); ++i) { FESurfaceElement& el = Element(i); vec3d re[FEElement::MAX_NODES]; GetNodalCoordinates(el, re); for (int n = 0; n < el.GaussPoints(); ++n) { FESurfaceMaterialPoint& mp = static_cast<FESurfaceMaterialPoint&>(*el.GetMaterialPoint(n)); mp.m_rt = el.eval(re, n); // kinematics at integration points mp.dxr = el.eval_deriv1(re, n); mp.dxs = el.eval_deriv2(re, n); mp.m_Jt = (mp.dxr ^ mp.dxs).norm(); } } } FEE2SCPSurface::FEE2SCPSurface(FEModel* fem) : FESurface(fem) { } //================================================================================================= FEE2SCPEdge::FEE2SCPEdge(FEModel* fem) : FEEdge(fem) { } FEMaterialPoint* FEE2SCPEdge::CreateMaterialPoint() { return new FEE2SCPPoint(); } bool FEE2SCPEdge::Create(FESegmentSet& eset) { return FEEdge::Create(eset, FE_LINE2NI); } void FEE2SCPEdge::Update() { // This assumes we are inside a omp parallel region! #pragma omp for for (int i = 0; i < Elements(); ++i) { FELineElement& el = Element(i); vec3d rt[FEElement::MAX_NODES]; GetNodalCoordinates(el, rt); // Jacobian is length in spatial coordinates divided by length in parametric coordinates (=2) double J = (rt[1] - rt[0]).Length() / 2.0; for (int n = 0; n < el.GaussPoints(); ++n) { FEE2SCPPoint& mp = static_cast<FEE2SCPPoint&>(*el.GetMaterialPoint(n)); mp.m_rt = el.eval(rt, n); mp.m_Jt = J; mp.m_gap = 0.0; mp.m_tc = vec3d(0, 0, 0); } } } //================================================================================================= BEGIN_FECORE_CLASS(FEEdgeToSurfaceContactPotential, FESurfaceConstraint) ADD_PARAMETER(m_kc, "kc"); ADD_PARAMETER(m_p, "p"); ADD_PARAMETER(m_Rin, "R_in"); ADD_PARAMETER(m_Rout, "R_out"); ADD_PARAMETER(m_Rmin, "R0_min"); ADD_PARAMETER(m_wtol, "w_tol"); ADD_PROPERTY(m_edge, "edgelist")->AddFlag(FEProperty::Reference); END_FECORE_CLASS(); FEEdgeToSurfaceContactPotential::FEEdgeToSurfaceContactPotential(FEModel* fem) : FESurfaceConstraint(fem), m_edge(fem), m_surf(fem) { m_kc = 0.0; m_p = 4; m_Rin = 1.0; m_Rout = 2.0; m_Rmin = 0.0; m_wtol = 0.0; } FESurface* FEEdgeToSurfaceContactPotential::GetSurface() { return &m_surf; } static bool is_neighbor(FESurfaceElement& e1, FESurfaceElement& e2) { int n1 = e1.Nodes(); int n2 = e2.Nodes(); for (int i = 0; i < n1; ++i) for (int j = 0; j < n2; ++j) { if (e1.m_node[i] == e2.m_node[j]) return true; } return false; } struct BOX { public: vec3d r0, r1; public: BOX() {} BOX(const vec3d& p0, const vec3d& p1) : r0(p0), r1(p1) {} void add(const vec3d& r) { if (r.x < r0.x) r0.x = r.x; if (r.y < r0.y) r0.y = r.y; if (r.z < r0.z) r0.z = r.z; if (r.x > r1.x) r1.x = r.x; if (r.y > r1.y) r1.y = r.y; if (r.z > r1.z) r1.z = r.z; } void inflate(double l) { r0.x -= l; r0.y -= l; r0.z -= l; r1.x += l; r1.y += l; r1.z += l; } bool isInside(const vec3d& r) const { return ( (r.x >= r0.x) && (r.x <= r1.x) && (r.y >= r0.y) && (r.y <= r1.y) && (r.z >= r0.z) && (r.z <= r1.z)); } double MaxExtent() const { double sx = r1.x - r0.x; double sy = r1.y - r0.y; double sz = r1.z - r0.z; if ((sx >= sy) && (sx >= sz)) return sx; if ((sy >= sx) && (sy >= sz)) return sy; if ((sz >= sx) && (sz >= sy)) return sz; // we should never reach here return 0; } double width () const { return r1.x - r0.x; } double height() const { return r1.y - r0.y; } double depth () const { return r1.z - r0.z; } }; class Grid { public: class Cell { public: Cell() {} Cell(const Cell& c) : m_box(c.m_box), m_elemList(c.m_elemList), m_nbr(c.m_nbr) {} void operator = (const Cell& c) { m_box = c.m_box; m_elemList = c.m_elemList; m_nbr = c.m_nbr; } void add(FESurfaceElement* el) { m_elemList.insert(el); } bool empty() const { return m_elemList.empty(); } public: BOX m_box; set<FESurfaceElement*> m_elemList; vector<Cell*> m_nbr; }; Cell* FindCell(const vec3d& r) { if (box.isInside(r) == false) return nullptr; int ix = (int)(m_nx * (r.x - box.r0.x) / box.width()); int iy = (int)(m_ny * (r.y - box.r0.y) / box.height()); int iz = (int)(m_nz * (r.z - box.r0.z) / box.depth()); if (ix == m_nx) ix--; if (iy == m_ny) iy--; if (iz == m_nz) iz--; int icell = iz * (m_nx * m_ny) + iy * m_nx + ix; Cell* c = m_cell + icell; assert(c->m_box.isInside(r)); return m_cell + icell; } int GetCellNeighborHood(const vec3d& r, Cell** cellList) { Cell* c = FindCell(r); if (c == nullptr) return 0; int n = 0; for (int i = 0; i < 27; ++i) { Cell* ci = c->m_nbr[i]; if ((ci != nullptr) && (ci->empty() == false)) cellList[n++] = ci; } return n; } public: Grid() { m_nx = m_ny = m_nz = 0; m_cell = nullptr; } bool Build(FESurface& s, int boxDivs, double minBoxSize) { // update the bounding box for (int i = 0; i < s.Nodes(); ++i) { FENode& node = s.Node(i); vec3d ri = node.m_rt; if (i == 0) box.r0 = box.r1 = ri; else box.add(ri); } // inflate a little, just to be sure double R = box.MaxExtent(); box.inflate(minBoxSize); // determine the sizes double W = box.width(); double H = box.height(); double D = box.depth(); double boxSize = box.MaxExtent() / boxDivs; if (boxSize < minBoxSize) boxSize = minBoxSize; m_nx = (int)(W / boxSize); if (m_nx < 1) m_nx = 1; m_ny = (int)(H / boxSize); if (m_ny < 1) m_ny = 1; m_nz = (int)(D / boxSize); if (m_nz < 1) m_nz = 1; // allocate the grid int ncells = m_nx * m_ny * m_nz; m_cell = new Cell[ncells]; // helper lookup-table for cell neighbors const int LUT[27][3] = { {-1,-1,-1},{ 0,-1,-1},{1,-1,-1}, {-1, 0,-1},{ 0, 0,-1},{1, 0,-1}, {-1, 1,-1},{ 0, 1,-1},{1, 1,-1}, {-1,-1, 0},{ 0,-1, 0},{1,-1, 0}, {-1, 0, 0},{ 0, 0, 0},{1, 0, 0}, {-1, 1, 0},{ 0, 1, 0},{1, 1, 0}, {-1,-1, 1},{ 0,-1, 1},{1,-1, 1}, {-1, 0, 1},{ 0, 0, 1},{1, 0, 1}, {-1, 1, 1},{ 0, 1, 1},{1, 1, 1} }; // construct cells Cell* c = m_cell; double X0 = box.r0.x; double Y0 = box.r0.y; double Z0 = box.r0.z; for (int k = 0; k < m_nz; ++k) { double z0 = Z0 + k * D / m_nz; double z1 = Z0 + (k+1) * D / m_nz; for (int j = 0; j < m_ny; ++j) { double y0 = Y0 + j * H / m_ny; double y1 = Y0 + (j + 1) * H / m_ny; for (int i = 0; i < m_nx; ++i, ++c) { double x0 = X0 + i * W / m_nx; double x1 = X0 + (i + 1) * W / m_nx; c->m_box = BOX(vec3d(x0, y0, z0), vec3d(x1, y1, z1)); double R = c->m_box.MaxExtent(); c->m_box.inflate(R * 1e-4); // assign neighbors c->m_nbr.assign(27, nullptr); for (int n = 0; n < 27; ++n) { const int* l = LUT[n]; c->m_nbr[n] = GetCell(i + l[0], j + l[1], k + l[2]); } } } } // assign elements to grid cells for (int i = 0; i < s.Elements(); ++i) { FESurfaceElement& el = s.Element(i); int nint = el.GaussPoints(); for (int n = 0; n < nint; ++n) { FESurfaceMaterialPoint& mp = static_cast<FESurfaceMaterialPoint&>(*el.GetMaterialPoint(n)); Cell* c = FindCell(mp.m_rt); assert(c); if (c == nullptr) return false; c->add(&el); } } return true; } Cell* GetCell(int i, int j, int k) const { if ((i < 0) || (i >= m_nx)) return nullptr; if ((j < 0) || (j >= m_ny)) return nullptr; if ((k < 0) || (k >= m_nz)) return nullptr; return m_cell + (k * (m_nx * m_ny) + j * m_nx + i); } ~Grid() { delete [] m_cell; } protected: BOX box; int m_nx, m_ny, m_nz; Cell* m_cell; }; // initialization bool FEEdgeToSurfaceContactPotential::Init() { if (FESurfaceConstraint::Init() == false) return false; for (int i = 0; i < m_edge.Elements(); ++i) { FELineElement& el = m_edge.Element(i); vec3d r0[FEElement::MAX_NODES]; m_edge.GetReferenceNodalCoordinates(el, r0); int nint = el.GaussPoints(); for (int n = 0; n < nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); mp.m_r0 = el.Evaluate(r0, n); } } m_activeElements.resize(m_edge.Elements()); return true; } // update void FEEdgeToSurfaceContactPotential::Update() { FESurfaceConstraint::Update(); // update the constants m_c1 = 0.5 * m_p * m_kc / ((m_Rout - m_Rin) * pow(m_Rin, m_p + 1.0)); m_c2 = m_kc / pow(m_Rin, m_p) - m_c1 * (m_Rin - m_Rout) * (m_Rin - m_Rout); // Update the surfaces #pragma omp parallel { m_edge.Update(); m_surf.Update(); } // build the grid int ndivs = (int)pow(m_surf.Elements(), 0.33333); if (ndivs < 2) ndivs = 2; Grid g; if (g.Build(m_surf, ndivs, m_Rout) == false) { throw std::runtime_error("Failed to build grid in FEEdgeToSurfaceContact::Update"); } // build the list of active elements //#pragma omp parallel for shared(g) schedule(dynamic) for (int i = 0; i < m_edge.Elements(); ++i) { FELineElement& el1 = m_edge.Element(i); set<FESurfaceElement*>& activeElems = m_activeElements[i]; activeElems.clear(); // list of elements to exclude. This will be elements // already processed set<FESurfaceElement*> excludeList; for (int n = 0; n < el1.GaussPoints(); ++n) { FEE2SCPPoint& mp1 = static_cast<FEE2SCPPoint&>(*el1.GetMaterialPoint(n)); mp1.m_gap = 0.0; vec3d r1 = mp1.m_rt; vec3d R1 = mp1.m_r0; // find the grid cell this point is in and loop over the cell's neighborhood Grid::Cell* c[27] = { nullptr }; int nc = g.GetCellNeighborHood(r1, &c[0]); for (int l = 0; l < nc; ++l) { Grid::Cell* cl = c[l]; for (FESurfaceElement* el2 : cl->m_elemList) { // make sure we did not process this element yet // and the element is not a neighbor (which can be the case for self-contact) if (excludeList.find(el2) == excludeList.end()) { // Next, we see if any integration point of el2 is close to the current // integration point of el1. vec3d r12; for (int m = 0; m < el2->GaussPoints(); ++m) { FEMaterialPoint* mp2 = el2->GetMaterialPoint(m); vec3d r2 = mp2->m_rt; vec3d R2 = mp2->m_r0; r12.x = r1.x - r2.x; r12.y = r1.y - r2.y; r12.z = r1.z - r2.z; // vec3d r12 = r1 - mp2.m_rt; if ((r12.x < m_Rout) && (r12.x > -m_Rout) && (r12.y < m_Rout) && (r12.y > -m_Rout) && (r12.z < m_Rout) && (r12.z > -m_Rout) && (r12.norm2() < m_Rout * m_Rout)) { double L12 = (R2 - R1).norm2(); double l12 = r12.unit(); if (L12 >= m_Rmin) { // we found one, so insert it to the list of active elements activeElems.insert(el2); // also insert it to the exclude list excludeList.insert(el2); // fprintf(stderr, "r12: %lg, %lg, %lg\n", r12.x, r12.y, r12.z); // fprintf(stderr, "n1 : %lg, %lg, %lg\n", n1.x, n1.y, n1.z); // fprintf(stderr, "l12 = %lg\n", l12); if ((mp1.m_gap == 0.0) || (l12 < mp1.m_gap)) { mp1.m_gap = l12; } break; } } } } } } } } } // Build the matrix profile void FEEdgeToSurfaceContactPotential::BuildMatrixProfile(FEGlobalMatrix& M) { // connect every element of the edge list to the surface for (int i = 0; i < m_edge.Elements(); ++i) { FELineElement& el1 = m_edge.Element(i); // add the dofs of element 1 vector<int> lm; for (int j = 0; j < el1.Nodes(); ++j) { FENode& node = m_edge.Node(el1.m_lnode[j]); lm.push_back(node.m_ID[0]); lm.push_back(node.m_ID[1]); lm.push_back(node.m_ID[2]); } // add all active dofs of surface 2 set<FESurfaceElement*>& activeElems = m_activeElements[i]; for (FESurfaceElement* el2 : activeElems) { for (int j = 0; j < el2->Nodes(); ++j) { FENode& node = m_surf.Node(el2->m_lnode[j]); lm.push_back(node.m_ID[0]); lm.push_back(node.m_ID[1]); lm.push_back(node.m_ID[2]); } } M.build_add(lm); } } double FEEdgeToSurfaceContactPotential::PotentialDerive(double r) { double f = 0.0; if (r < m_Rin) { f = (m_kc / pow(r, m_p)) - m_c2; } else if (r < m_Rout) { f = m_c1 * (r - m_Rout) * (r - m_Rout); } return f; } double FEEdgeToSurfaceContactPotential::PotentialDerive2(double r) { double f = 0.0; if (r < m_Rin) { f = -m_p*m_kc / pow(r, m_p + 1.0); } else if (r < m_Rout) { f = 2.0*m_c1 * (r - m_Rout); } return f; } // The LoadVector function evaluates the "forces" that contribute to the residual of the system void FEEdgeToSurfaceContactPotential::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { const int ndof = 3; // clear all contact tractions #pragma omp parallel for for (int i = 0; i < m_edge.Elements(); ++i) { FELineElement& el = m_edge.Element(i); for (int n = 0; n < el.GaussPoints(); ++n) { FEE2SCPPoint& cp = static_cast<FEE2SCPPoint&>(*el.GetMaterialPoint(n)); cp.m_Ln = 0.0; cp.m_tc = vec3d(0, 0, 0); } } // loop over all elements of the edge list #pragma omp parallel for shared(R) for (int i = 0; i < m_edge.Elements(); ++i) { FELineElement& eli = m_edge.Element(i); int na = eli.Nodes(); vector<double> fe; vector<int> lm; // loop over all elements of surf 2 set<FESurfaceElement*>& activeElems = m_activeElements[i]; for (FESurfaceElement* elj : activeElems) { int nb = elj->Nodes(); // evaluate contribution to force vector fe.assign((na + nb) * ndof, 0.0); ElementForce(eli, *elj, fe); // setup the lm vector lm.resize(3 * (na + nb)); for (int a = 0; a < na; ++a) { FENode& node = m_edge.Node(eli.m_lnode[a]); lm[3*a ] = node.m_ID[0]; lm[3*a + 1] = node.m_ID[1]; lm[3*a + 2] = node.m_ID[2]; } for (int b = 0; b < nb; ++b) { FENode& node = m_surf.Node(elj->m_lnode[b]); lm[3*na + 3*b ] = node.m_ID[0]; lm[3*na + 3*b + 1] = node.m_ID[1]; lm[3*na + 3*b + 2] = node.m_ID[2]; } // assemble R.Assemble(lm, fe); } } // update contact pressures (only needed for plot output) #pragma omp parallel { #pragma omp for for (int i = 0; i < m_edge.Elements(); ++i) { FELineElement& el = m_edge.Element(i); for (int n = 0; n < el.GaussPoints(); ++n) { FEE2SCPPoint& cp = static_cast<FEE2SCPPoint&>(*el.GetMaterialPoint(n)); cp.m_Ln = cp.m_tc.norm(); } } } } void FEEdgeToSurfaceContactPotential::ElementForce(FELineElement& el1, FESurfaceElement& el2, vector<double>& fe) { int na = el1.Nodes(); int nb = el2.Nodes(); double* w1 = el1.GaussWeights(); double* w2 = el2.GaussWeights(); for (int n = 0; n < el1.GaussPoints(); ++n) { const double* H1 = el1.H(n); FEE2SCPPoint& mp1 = static_cast<FEE2SCPPoint&>(*el1.GetMaterialPoint(n)); double Jw1 = mp1.m_Jt*w1[n]; vec3d r1 = mp1.m_rt; for (int m = 0; m < el2.GaussPoints(); ++m) { const double* H2 = el2.H(m); FESurfaceMaterialPoint& mp2 = static_cast<FESurfaceMaterialPoint&>(*el2.GetMaterialPoint(m)); double Jw2 = mp2.m_Jt*w2[m]; double Jw12 = Jw1 * Jw2; // get the position of the integration point vec3d r2 = mp2.m_rt; // get the normalized direction vector vec3d e12 = r1 - r2; double r12 = e12.unit(); // calculate the potential derivative double df = PotentialDerive(r12); // add to the force if (df != 0.0) { vec3d F = e12 * df; mp1.m_tc += F * Jw2; for (int a = 0; a < na; ++a) { fe[3 * a ] += F.x * (H1[a] * Jw12); fe[3 * a + 1] += F.y * (H1[a] * Jw12); fe[3 * a + 2] += F.z * (H1[a] * Jw12); } for (int b = 0; b < nb; ++b) { fe[3 * (na + b) ] -= F.x * (H2[b] * Jw12); fe[3 * (na + b) + 1] -= F.y * (H2[b] * Jw12); fe[3 * (na + b) + 2] -= F.z * (H2[b] * Jw12); } } } } } // Evaluates the contriubtion to the stiffness matrix void FEEdgeToSurfaceContactPotential::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { const int ndof = 3; // loop over all elements of surf 1 #pragma omp parallel for shared(LS) for (int i = 0; i < m_edge.Elements(); ++i) { FELineElement& eli = m_edge.Element(i); int na = eli.Nodes(); set<FESurfaceElement*>& activeElems = m_activeElements[i]; for (FESurfaceElement* elj : activeElems) { int nb = elj->Nodes(); FEElementMatrix ke((na + nb) * ndof, (na + nb) * ndof); ke.zero(); ElementStiffness(eli, *elj, ke); vector<int> lm(3 * (na+nb)); vector<int> en(na + nb); for (int a = 0; a < na; ++a) { FENode& node = m_edge.Node(eli.m_lnode[a]); lm[3 * a ] = node.m_ID[0]; lm[3 * a + 1] = node.m_ID[1]; lm[3 * a + 2] = node.m_ID[2]; en[a] = eli.m_node[a]; } for (int b = 0; b < nb; ++b) { FENode& node = m_surf.Node(elj->m_lnode[b]); lm[3 * na + 3 * b ] = node.m_ID[0]; lm[3 * na + 3 * b + 1] = node.m_ID[1]; lm[3 * na + 3 * b + 2] = node.m_ID[2]; en[na + b] = elj->m_node[b]; } ke.SetIndices(lm); ke.SetNodes(en); LS.Assemble(ke); } } } void FEEdgeToSurfaceContactPotential::ElementStiffness(FELineElement& el1, FESurfaceElement& el2, matrix& ke) { double* w1 = el1.GaussWeights(); double* w2 = el2.GaussWeights(); int na = el1.Nodes(); int nb = el2.Nodes(); for (int n = 0; n < el1.GaussPoints(); ++n) { const double* H1 = el1.H(n); FEE2SCPPoint& mp1 = static_cast<FEE2SCPPoint&>(*el1.GetMaterialPoint(n)); double Jw1 = mp1.m_Jt*w1[n]; vec3d r1 = mp1.m_rt; for (int m = 0; m < el2.GaussPoints(); ++m) { const double* H2 = el2.H(m); FESurfaceMaterialPoint& mp2 = static_cast<FESurfaceMaterialPoint&>(*el2.GetMaterialPoint(m)); double Jw2 = mp2.m_Jt*w2[m]; vec3d r2 = mp2.m_rt; // get the normalized direction vector vec3d e12 = r1 - r2; double r12 = e12.unit(); // calculate the potential's derivatives double df = PotentialDerive(r12); double d2f = PotentialDerive2(r12); // add to the stiffness mat3dd I(1.0); mat3d ExE = dyad(e12); mat3d P = (I - ExE) / r12; mat3d M = ExE * d2f + P * df; // 1-1 contribution for (int a = 0; a < na; ++a) { for (int b = 0; b < na; ++b) { mat3d K2 = M * Jw2; ke.add(3 * a, 3 * b, K2 * (H1[a] * H1[b])*Jw1); } } // 1-2 contribution for (int a = 0; a < na; ++a) { for (int b = 0; b < nb; ++b) { mat3d K2b = M * (H2[b] * Jw2); ke.sub(3 * a, 3 * na + 3 * b, K2b * (H1[a] * Jw1)); } } // 2-1 contribution for (int b = 0; b < nb; ++b) { for (int a = 0; a < na; ++a) { mat3d K1a = M * (H1[a] * Jw1); ke.sub(3 * na + 3*b, 3 * a, K1a * (H2[b] * Jw2)); } } // 2-2 contribution for (int a = 0; a < nb; ++a) { for (int b = 0; b < nb; ++b) { mat3d K1 = M * Jw1; ke.add(3*na + 3 * a, 3*na + 3 * b, K1 * (H2[a] * H2[b]) * Jw2); } } } } ke *= -1.0; } void FEEdgeToSurfaceContactPotential::Serialize(DumpStream& ar) { FESurfaceConstraint::Serialize(ar); m_edge.Serialize(ar); m_surf.Serialize(ar); }
C++
3D
febiosoftware/FEBio
FEBioMech/FEShenoyMaterial.cpp
.cpp
3,945
166
// ShenoyMaterial.cpp : Defines the exported functions for the DLL application. // #include "stdafx.h" #include "FEShenoyMaterial.h" BEGIN_FECORE_CLASS(FEShenoyMaterial, FEElasticMaterial) ADD_PARAMETER(m_mu, FE_RANGE_GREATER_OR_EQUAL(0.0), "mu"); ADD_PARAMETER(m_k , FE_RANGE_GREATER_OR_EQUAL(0.0), "k"); ADD_PARAMETER(m_Ef, FE_RANGE_GREATER_OR_EQUAL(0.0), "Ef"); ADD_PARAMETER(m_lamc, FE_RANGE_GREATER_OR_EQUAL(1.0), "lam_c"); ADD_PARAMETER(m_lamt, FE_RANGE_NOT_EQUAL(0.0), "lam_t"); ADD_PARAMETER(m_n , FE_RANGE_GREATER_OR_EQUAL(1.0), "n"); ADD_PARAMETER(m_m , FE_RANGE_GREATER_OR_EQUAL(1.0), "m"); END_FECORE_CLASS(); FEShenoyMaterial::FEShenoyMaterial(FEModel* fem) : FEElasticMaterial(fem) { m_mu = 0.0; m_k = 0.0; m_Ef = 0.0; m_lamc = 1.0; m_lamt = 0.0; m_n = 5; m_m = 1; } double FEShenoyMaterial::fiberStress(double lam) { double lam1 = m_lamc - m_lamt * 0.5; double lam2 = m_lamc + m_lamt * 0.5; if (lam < lam1) return 0.0; else if (lam > lam2) { return m_Ef*((lam2 - lam1) / (m_n + 1.0) + (pow(1.0 + lam - lam2, m_m + 1.0) - 1.0) / (m_m + 1.0)); } else { return m_Ef*(pow((lam - lam1)/(lam2 - lam1), m_n)*(lam - lam1)) / (m_n + 1); } } double FEShenoyMaterial::fiberTangent(double lam) { double lam1 = m_lamc - m_lamt * 0.5; double lam2 = m_lamc + m_lamt * 0.5; if (lam < lam1) return 0.0; else if (lam > lam2) { return m_Ef*pow(1.0 + lam - lam2, m_m); } else { return m_Ef*pow((lam - lam1) / (lam2 - lam1), m_n); } } mat3ds FEShenoyMaterial::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3ds B = pt.LeftCauchyGreen(); double J = pt.m_J; double Jm23 = pow(J, -2.0 / 3.0); mat3ds Bbar = B*Jm23; mat3dd I(1.0); double lam[3] = {0}; vec3d n[3]; B.eigen(lam, n); lam[0] = (lam[0] >= 0.0 ? sqrt(lam[0]) : 0.0); lam[1] = (lam[1] >= 0.0 ? sqrt(lam[1]) : 0.0); lam[2] = (lam[2] >= 0.0 ? sqrt(lam[2]) : 0.0); // isotropic component of the stress mat3ds s_b = Bbar.dev()*(m_mu / J) + I*(m_k * (J - 1.0)); // anisotropic (fiber) contribution of the stress double df[3] = {0}; df[0] = fiberStress(lam[0]); df[1] = fiberStress(lam[1]); df[2] = fiberStress(lam[2]); mat3ds s_f = (dyad(n[0])*(df[0] * lam[0]) + dyad(n[1])*(df[1] * lam[1]) + dyad(n[2])*(df[2] * lam[2])) / J; // add them together mat3ds s = s_b + s_f; // and done return s; } tens4ds FEShenoyMaterial::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3ds B = pt.LeftCauchyGreen(); double J = pt.m_J; double Jm23 = pow(J, -2.0 / 3.0); mat3ds Bbar = B*Jm23; mat3dd I(1.0); double lam[3] = { 0 }; vec3d n[3]; B.eigen(lam, n); lam[0] = (lam[0] >= 0.0 ? sqrt(lam[0]) : 0.0); lam[1] = (lam[1] >= 0.0 ? sqrt(lam[1]) : 0.0); lam[2] = (lam[2] >= 0.0 ? sqrt(lam[2]) : 0.0); double I1bar = Bbar.tr(); tens4ds IxI = dyad1s(I); tens4ds I4 = dyad4s(I); tens4ds c_b = (I4*(2.0*I1bar / 3.0) - (dyad1s(Bbar, I))*(2.0 / 3.0) + IxI*(I1bar*2.0 / 9.0))*(m_mu / J) \ + (IxI*(2.0*J - 1) - I4*(2.0*(J - 1.0)))*m_k; double df[3] = {0}, ddf[3] = {0}, sf[3] = {0}; df[0] = fiberStress(lam[0]); df[1] = fiberStress(lam[1]); df[2] = fiberStress(lam[2]); ddf[0] = fiberTangent(lam[0]); ddf[1] = fiberTangent(lam[1]); ddf[2] = fiberTangent(lam[2]); sf[0] = lam[0] * df[0] / J; sf[1] = lam[1] * df[1] / J; sf[2] = lam[2] * df[2] / J; tens4ds c_f; c_f.zero(); for (int a=0; a<3; ++a) { c_f += dyad1s(dyad(n[a]))*(lam[a]*(lam[a]*ddf[a] - df[a])/J); } int p[][2] = {{0,1},{1,2},{0,2}}; for (int i=0; i < 3; ++i) { int a = p[i][0]; int b = p[i][1]; double g = 0.0; if (fabs(lam[a] - lam[b]) <= 1e-10) { g = 0.5*lam[a]*lam[a]*ddf[a] / J - sf[a]; } else { g = (sf[a]*lam[b]*lam[b] - sf[b]*lam[a]*lam[a])/(lam[a]*lam[a] - lam[b]*lam[b]); } mat3ds Nab = dyads(n[a], n[b]); c_f += dyad1s(Nab)*(g); } tens4ds c = c_b + c_f; return c; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEDamageCriterion.h
.h
6,851
227
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECore/FEMaterial.h" #include "febiomech_api.h" //----------------------------------------------------------------------------- // Virtual base class for damage criterion class FEBIOMECH_API FEDamageCriterion : public FEMaterialProperty { public: FEDamageCriterion(FEModel* pfem) : FEMaterialProperty(pfem) {} //! damage virtual double DamageCriterion(FEMaterialPoint& pt) = 0; //! criterion tangent with respect to stress virtual mat3ds CriterionStressTangent(FEMaterialPoint& pt) { return mat3ds(0); } FECORE_BASE_CLASS(FEDamageCriterion); }; //----------------------------------------------------------------------------- // Simo's damage criterion class FEDamageCriterionSimo : public FEDamageCriterion { public: FEDamageCriterionSimo(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // Strain energy density as damage criterion class FEDamageCriterionSED : public FEDamageCriterion { public: FEDamageCriterionSED(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // Specific strain energy as damage criterion class FEDamageCriterionSSE : public FEDamageCriterion { public: FEDamageCriterionSSE(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // von Mises stress as damage criterion class FEDamageCriterionVMS : public FEDamageCriterion { public: FEDamageCriterionVMS(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); //! criterion tangent with respect to stress mat3ds CriterionStressTangent(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // Drucker yield criterion class FEDamageCriterionDrucker : public FEDamageCriterion { public: FEDamageCriterionDrucker(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt) override; //! criterion tangent with respect to stress mat3ds CriterionStressTangent(FEMaterialPoint& pt) override; public: FEParamDouble m_c; //!< Drucker material parameter DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- // max shear stress as damage criterion class FEDamageCriterionMSS : public FEDamageCriterion { public: FEDamageCriterionMSS(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); //! criterion tangent with respect to stress mat3ds CriterionStressTangent(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // max normal stress as damage criterion class FEDamageCriterionMNS : public FEDamageCriterion { public: FEDamageCriterionMNS(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); //! criterion tangent with respect to stress mat3ds CriterionStressTangent(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // max normal Lagrange strain as damage criterion class FEDamageCriterionMNLS : public FEDamageCriterion { public: FEDamageCriterionMNLS(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // max octahedral strain as damage criterion class FEDamageCriterionOSS : public FEDamageCriterion { public: FEDamageCriterionOSS(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // max octahedral natural strain as damage criterion class FEDamageCriterionONS : public FEDamageCriterion { public: FEDamageCriterionONS(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt); }; //----------------------------------------------------------------------------- // Drucker-Prager yield criterion class FEDamageCriterionDruckerPrager : public FEDamageCriterion { public: FEDamageCriterionDruckerPrager(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt) override; //! criterion tangent with respect to stress mat3ds CriterionStressTangent(FEMaterialPoint& pt) override; public: FEParamDouble m_b; //!< Drucker-Prager material parameter DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- // Deshpande-Fleck yield criterion class FEDamageCriterionDeshpandeFleck : public FEDamageCriterion { public: FEDamageCriterionDeshpandeFleck(FEModel* pfem) : FEDamageCriterion(pfem) {} //! damage double DamageCriterion(FEMaterialPoint& pt) override; //! criterion tangent with respect to stress mat3ds CriterionStressTangent(FEMaterialPoint& pt) override; public: FEParamDouble m_beta; //!< Deshpande-Fleck material parameter DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FETractionLoad.h
.h
2,116
64
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FESurfaceLoad.h> #include <FECore/FEModelParam.h> //----------------------------------------------------------------------------- //! FETractionLoad is a surface that has a constant (deformation independant) //! traction force on it. //! class FETractionLoad : public FESurfaceLoad { public: //! constructor FETractionLoad(FEModel* pfem); //! Set the surface to apply the load to void SetSurface(FESurface* ps) override; // initialization bool Init() override; public: //! calculate contact forces void LoadVector(FEGlobalVector& R) override; //! calculate stiffness void StiffnessMatrix(FELinearSystem& LS) override; protected: double m_scale; //!< scale factor for traction FEParamVec3 m_traction; //!< vector traction bool m_bshellb; bool m_blinear; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FETiedInterface.cpp
.cpp
19,771
730
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FETiedInterface.h" #include <FECore/FEClosestPointProjection.h> #include <FECore/FELinearSystem.h> #include <FECore/log.h> //----------------------------------------------------------------------------- // Define sliding interface parameters BEGIN_FECORE_CLASS(FETiedInterface, FEContactInterface) ADD_PARAMETER(m_laugon , "laugon" )->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0LAGMULT\0"); ADD_PARAMETER(m_atol , "tolerance" ); ADD_PARAMETER(m_eps , "penalty" ); ADD_PARAMETER(m_naugmin , "minaug" ); ADD_PARAMETER(m_naugmax , "maxaug" ); ADD_PARAMETER(m_stol , "search_tolerance"); ADD_PARAMETER(m_boffset , "offset_shells" ); ADD_PARAMETER(m_Dmax , "max_distance" ); ADD_PARAMETER(m_bspecial, "special" ); ADD_PARAMETER(m_breloc , "node_reloc" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. Initialize default values. FETiedInterface::FETiedInterface(FEModel* pfem) : FEContactInterface(pfem), ss(pfem), ms(pfem) { static int count = 1; SetID(count++); // define sibling relationships ss.SetSibling(&ms); ms.SetSibling(&ss); // initial parameter values m_laugon = FECore::PENALTY_METHOD; m_atol = 0.01; m_eps = 1.0; m_stol = 0.0001; m_naugmin = 0; m_naugmax = 10; m_boffset = false; m_Dmax = 0.0; m_bspecial = true; m_breloc = false; // set parents ss.SetContactInterface(this); ms.SetContactInterface(this); } //----------------------------------------------------------------------------- //! Initialization. This function intializes the surfaces data and projects the //! primary surface onto the secondary surface. //! bool FETiedInterface::Init() { // set surface options ss.SetShellOffset(m_boffset); // create the surfaces if (ss.Init() == false) return false; if (ms.Init() == false) return false; return true; } //----------------------------------------------------------------------------- //! build the matrix profile for use in the stiffness matrix void FETiedInterface::BuildMatrixProfile(FEGlobalMatrix& K) { FEMesh& mesh = GetMesh(); // get the DOFS const int dof_X = GetDOFIndex("x"); const int dof_Y = GetDOFIndex("y"); const int dof_Z = GetDOFIndex("z"); const int dof_RU = GetDOFIndex("Ru"); const int dof_RV = GetDOFIndex("Rv"); const int dof_RW = GetDOFIndex("Rw"); if (m_laugon != FECore::LAGMULT_METHOD) { const int LMSIZE = 6 * (FEElement::MAX_NODES + 1); vector<int> lm(LMSIZE); for (int j = 0; j < ss.Nodes(); ++j) { FESurfaceElement* pe = ss.m_data[j].m_pme; if (pe != 0) { FESurfaceElement& me = *pe; int* en = &me.m_lnode[0]; int n = me.Nodes(); lm.assign(LMSIZE, -1); lm[0] = ss.Node(j).m_ID[dof_X]; lm[1] = ss.Node(j).m_ID[dof_Y]; lm[2] = ss.Node(j).m_ID[dof_Z]; lm[3] = ss.Node(j).m_ID[dof_RU]; lm[4] = ss.Node(j).m_ID[dof_RV]; lm[5] = ss.Node(j).m_ID[dof_RW]; for (int k = 0; k < n; ++k) { vector<int>& id = ms.Node(en[k]).m_ID; lm[6 * (k + 1)] = id[dof_X]; lm[6 * (k + 1) + 1] = id[dof_Y]; lm[6 * (k + 1) + 2] = id[dof_Z]; lm[6 * (k + 1) + 3] = id[dof_RU]; lm[6 * (k + 1) + 4] = id[dof_RV]; lm[6 * (k + 1) + 5] = id[dof_RW]; } K.build_add(lm); } } } else { vector<int> lm; for (int j = 0; j < ss.Nodes(); ++j) { FESurfaceElement* pe = ss.m_data[j].m_pme; if (pe != 0) { FESurfaceElement& me = *pe; int* en = &me.m_lnode[0]; int n = me.Nodes(); lm.assign(3*(n+2), -1); lm[0] = ss.Node(j).m_ID[dof_X]; lm[1] = ss.Node(j).m_ID[dof_Y]; lm[2] = ss.Node(j).m_ID[dof_Z]; for (int k = 0; k < n; ++k) { vector<int>& id = ms.Node(en[k]).m_ID; lm[3 * (k + 1) ] = id[dof_X]; lm[3 * (k + 1) + 1] = id[dof_Y]; lm[3 * (k + 1) + 2] = id[dof_Z]; } lm[3 * (n + 1) ] = m_LM[3 * j ]; lm[3 * (n + 1)+1] = m_LM[3 * j +1]; lm[3 * (n + 1)+2] = m_LM[3 * j +2]; K.build_add(lm); } } } } //----------------------------------------------------------------------------- //! Interface activation void FETiedInterface::Activate() { // Don't forget to call base member! FEContactInterface::Activate(); // project primary surface onto secondary surface ProjectSurface(ss, ms, m_breloc); } //----------------------------------------------------------------------------- //! return number of equations to be allocated for Lagrange multipliers int FETiedInterface::InitEquations(int neq) { // make sure we want to use Lagrange Multiplier method if (m_laugon != FECore::LAGMULT_METHOD) return 0; // allocate three equations per primary node int NN = ss.Nodes(); m_LM.resize(3 * NN); for (int i = 0; i < 3 * NN; ++i) m_LM[i] = neq++; return 3 * NN; } //----------------------------------------------------------------------------- //! Update tied interface data. This function re-evaluates the gaps between //! the primary node and their projections onto the secondary surface. //! void FETiedInterface::Update() { // get the mesh FEMesh& mesh = *ss.GetMesh(); // loop over all primary nodes for (int i=0; i<ss.Nodes(); ++i) { FESurfaceElement* pme = ss.m_data[i].m_pme; if (pme) { // get the current primary nodal position vec3d rt = ss.Node(i).m_rt; // get the natural coordinates of the primary projection // onto the secondary element double r = ss.m_data[i].m_rs[0]; double s = ss.m_data[i].m_rs[1]; // get the nodal coordinates int ne = pme->Nodes(); vec3d y[FEElement::MAX_NODES]; for (int l=0; l<ne; ++l) y[l] = ms.Node( pme->m_lnode[l] ).m_rt; // calculate the primary node projection vec3d q = pme->eval(y, r, s); // calculate the secondary normal vec3d nu = ss.SurfaceNormal(*pme, r, s); // calculate the gap function // (taking possible offset into account) ss.m_data[i].m_vgap = (rt - q) - nu*ss.m_data[i].m_off; ss.m_data[i].m_gap = ss.m_data[i].m_vgap.norm(); // calculate force ss.m_data[i].m_Tc = ss.m_data[i].m_Lm + ss.m_data[i].m_vgap*m_eps; } } } //----------------------------------------------------------------------------- //! project surface void FETiedInterface::ProjectSurface(FETiedContactSurface& ss, FETiedContactSurface& ms, bool bmove) { // closest point projection method FEClosestPointProjection cpp(ms); cpp.SetTolerance(m_stol); cpp.HandleSpecialCases(m_bspecial); cpp.Init(); // let's count contact pairs int contacts = 0; // loop over all primary nodes for (int i=0; i<ss.Nodes(); ++i) { // get the next node FENode& node = ss.Node(i); ss.m_data[i].m_pme = nullptr; // get the nodal position of this primary node vec3d x = node.m_rt; // find the secondary element vec3d q; vec2d rs; FESurfaceElement* pme = cpp.Project(x, q, rs); if (pme) { // make sure we are within the max distance double D = (x - q).norm(); if ((m_Dmax == 0.0) || (D <= m_Dmax)) { // store the secondary element ss.m_data[i].m_pme = pme; // store the natural coordinates of the projection on the secondary element ss.m_data[i].m_rs = rs; // calculate the secondary normal vec3d nu = ms.SurfaceNormal(*pme, rs[0], rs[1]); // calculate gap ss.m_data[i].m_vgap = (x - q) - nu*ss.m_data[i].m_off; // move the node if necessary if (bmove && (ss.m_data[i].m_vgap.norm()>0)) { node.m_r0 = node.m_rt = q + nu*ss.m_data[i].m_off; ss.m_data[i].m_vgap = vec3d(0,0,0); } // calculate force ss.m_data[i].m_Tc = ss.m_data[i].m_Lm + ss.m_data[i].m_vgap*m_eps; contacts++; } } } // if we found no contact pairs, let's report this since this is probably not the user's intention if (contacts == 0) { std::string name = GetName(); feLogWarning("No contact pairs found for tied interface \"%s\".\nThis contact interface may not have any effect.", name.c_str()); } } //----------------------------------------------------------------------------- //! This function calculates the contact forces for a tied interface. void FETiedInterface::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { // shape function values double N[FEElement::MAX_NODES]; // element contact force vector vector<double> fe; // the lm array for this force vector vector<int> lm; // the en array vector<int> en; vector<int> sLM; vector<int> mLM; // loop over all primary facets const int NE = ss.Elements(); for (int j = 0; j < NE; ++j) { // get the primary element FESurfaceElement& sel = ss.Element(j); // get the element's LM vector ss.UnpackLM(sel, sLM); int nseln = sel.Nodes(); double* w = sel.GaussWeights(); // loop over primary element nodes (which are the integration points as well) for (int n = 0; n < nseln; ++n) { int m = sel.m_lnode[n]; // see if this node's constraint is active // that is, if it has a secondary element associated with it // TODO: is this a good way to test for an active constraint // The rigid wall criteria seems to work much better. if (ss.m_data[m].m_pme != 0) { // calculate jacobian and weight double Jw = ss.jac0(sel, n)*w[n]; // get nodal contact force vec3d tc = ss.m_data[m].m_Lm; // add penalty contribution for penalty and aug lag method if (m_laugon != FECore::LAGMULT_METHOD) tc += ss.m_data[m].m_vgap*m_eps; // get the secondary element FESurfaceElement& mel = *ss.m_data[m].m_pme; ms.UnpackLM(mel, mLM); int nmeln = mel.Nodes(); // isoparametric coordinates of the projected primary node // onto the secondary element double r = ss.m_data[m].m_rs[0]; double s = ss.m_data[m].m_rs[1]; // get the secondary shape function values at this primary node mel.shape_fnc(N, r, s); // allocate "element" force vector if (m_laugon != FECore::LAGMULT_METHOD) fe.resize(3 * (nmeln + 1)); else fe.resize(3 * (nmeln + 2)); // calculate contribution to force vector from nodes fe[0] = -Jw * tc.x; fe[1] = -Jw * tc.y; fe[2] = -Jw * tc.z; for (int l = 0; l < nmeln; ++l) { fe[3 * (l + 1) ] = Jw * tc.x*N[l]; fe[3 * (l + 1) + 1] = Jw * tc.y*N[l]; fe[3 * (l + 1) + 2] = Jw * tc.z*N[l]; } // setup lm vector if (m_laugon != FECore::LAGMULT_METHOD) lm.resize(3 * (nmeln + 1)); else lm.resize(3 * (nmeln + 2)); // fill the lm array lm[0] = sLM[n * 3]; lm[1] = sLM[n * 3 + 1]; lm[2] = sLM[n * 3 + 2]; for (int l = 0; l < nmeln; ++l) { lm[3 * (l + 1) ] = mLM[l * 3]; lm[3 * (l + 1) + 1] = mLM[l * 3 + 1]; lm[3 * (l + 1) + 2] = mLM[l * 3 + 2]; } if (m_laugon != FECore::LAGMULT_METHOD) en.resize(nmeln + 1); else en.resize(nmeln + 2); // fill the en array en[0] = sel.m_node[n]; for (int l = 0; l < nmeln; ++l) en[l + 1] = mel.m_node[l]; if (m_laugon == FECore::LAGMULT_METHOD) { // get the gap function vec3d g = ss.m_data[m].m_vgap; // add contribution from Lagrange multipliers fe[3 * (nmeln + 1) ] = -Jw * g.x; fe[3 * (nmeln + 1)+1] = -Jw * g.y; fe[3 * (nmeln + 1)+2] = -Jw * g.z; // add the Lagrange multiplier equations to lm lm[3 * (nmeln + 1) ] = m_LM[3 * m ]; lm[3 * (nmeln + 1)+1] = m_LM[3 * m+1]; lm[3 * (nmeln + 1)+2] = m_LM[3 * m+2]; // fill the en array en[nmeln + 1] = -1; } // assemble into global force vector R.Assemble(en, lm, fe); } } } } //----------------------------------------------------------------------------- //! Calculate the stiffness matrix contribution. void FETiedInterface::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { vector<int> sLM, mLM, lm, en; const int MN = FEElement::MAX_NODES; FEElementMatrix ke; // shape functions double H[MN]; // loop over all primary elements const int NE = ss.Elements(); for (int i = 0; i < NE; ++i) { // get the next element FESurfaceElement& se = ss.Element(i); int nseln = se.Nodes(); // get the element's LM vector ss.UnpackLM(se, sLM); double* w = se.GaussWeights(); // loop over all integration points (that is nodes) for (int n = 0; n < nseln; ++n) { int m = se.m_lnode[n]; // get the secondary element FESurfaceElement* pme = ss.m_data[m].m_pme; if (pme) { // get the secondary element FESurfaceElement& me = *pme; int nmeln = me.Nodes(); ms.UnpackLM(me, mLM); // calculate jacobian double Jw = ss.jac0(se, n)*w[n]; // primary node natural coordinates in secondary element double r = ss.m_data[m].m_rs[0]; double s = ss.m_data[m].m_rs[1]; // get the secondary shape function values at this primary node me.shape_fnc(H, r, s); if (m_laugon != FECore::LAGMULT_METHOD) { // number of degrees of freedom int ndof = 3 * (1 + nmeln); // fill stiffness matrix ke.resize(ndof, ndof); ke.zero(); ke[0][0] = Jw*m_eps; ke[1][1] = Jw*m_eps; ke[2][2] = Jw*m_eps; for (int k = 0; k < nmeln; ++k) { ke[0][3 + 3 * k ] = -Jw*m_eps*H[k]; ke[1][3 + 3 * k + 1] = -Jw*m_eps*H[k]; ke[2][3 + 3 * k + 2] = -Jw*m_eps*H[k]; ke[3 + 3 * k ][0] = -Jw*m_eps*H[k]; ke[3 + 3 * k + 1][1] = -Jw*m_eps*H[k]; ke[3 + 3 * k + 2][2] = -Jw*m_eps*H[k]; } for (int k = 0; k < nmeln; ++k) for (int l = 0; l < nmeln; ++l) { ke[3 + 3 * k ][3 + 3 * l ] = Jw*m_eps*H[k] * H[l]; ke[3 + 3 * k + 1][3 + 3 * l + 1] = Jw*m_eps*H[k] * H[l]; ke[3 + 3 * k + 2][3 + 3 * l + 2] = Jw*m_eps*H[k] * H[l]; } } else { // number of degrees of freedom int ndof = 3 * (2 + nmeln); // fill stiffness matrix ke.resize(ndof, ndof); ke.zero(); int L = 3 * (nmeln + 1); ke[0][L ] = ke[L ][0] = Jw; ke[1][L+1] = ke[L+1][1] = Jw; ke[2][L+2] = ke[L+2][2] = Jw; for (int k = 0; k < nmeln; ++k) { ke[3 + 3*k ][L ] = -Jw*H[k]; ke[3 + 3*k + 1][L + 1] = -Jw*H[k]; ke[3 + 3*k + 2][L + 2] = -Jw*H[k]; ke[L ][3 + 3*k ] = -Jw*H[k]; ke[L+1][3 + 3*k + 1] = -Jw*H[k]; ke[L+2][3 + 3*k + 2] = -Jw*H[k]; } } // create lm array if (m_laugon != FECore::LAGMULT_METHOD) lm.resize(3 * (1 + nmeln)); else lm.resize(3 * (2 + nmeln)); lm[0] = sLM[n * 3]; lm[1] = sLM[n * 3 + 1]; lm[2] = sLM[n * 3 + 2]; for (int k = 0; k < nmeln; ++k) { lm[3 * (k + 1)] = mLM[k * 3]; lm[3 * (k + 1) + 1] = mLM[k * 3 + 1]; lm[3 * (k + 1) + 2] = mLM[k * 3 + 2]; } if (m_laugon == FECore::LAGMULT_METHOD) { lm[3 * (nmeln + 1)] = m_LM[3 * m]; lm[3 * (nmeln + 1) + 1] = m_LM[3 * m + 1]; lm[3 * (nmeln + 1) + 2] = m_LM[3 * m + 2]; } // create the en array if (m_laugon != FECore::LAGMULT_METHOD) en.resize(nmeln + 1); else en.resize(nmeln + 2); en[0] = se.m_node[n]; for (int k = 0; k < nmeln; ++k) en[k + 1] = me.m_node[k]; if (m_laugon == FECore::LAGMULT_METHOD) en[nmeln + 1] = -1; // assemble stiffness matrix ke.SetNodes(en); ke.SetIndices(lm); LS.Assemble(ke); } } } } //----------------------------------------------------------------------------- //! Do an augmentation. bool FETiedInterface::Augment(int naug, const FETimeInfo& tp) { // make sure we need to augment if (m_laugon != FECore::AUGLAG_METHOD) return true; int i; // calculate initial norms double normL0 = 0; for (i=0; i<ss.Nodes(); ++i) { vec3d lm = ss.m_data[i].m_Lm; normL0 += lm*lm; } normL0 = sqrt(normL0); // update Lagrange multipliers and calculate current norms double normL1 = 0; double normgc = 0; int N = 0; for (i=0; i<ss.Nodes(); ++i) { vec3d lm = ss.m_data[i].m_Lm + ss.m_data[i].m_vgap*m_eps; normL1 += lm*lm; if (ss.m_data[i].m_pme != 0) { double g = ss.m_data[i].m_vgap.norm(); normgc += g*g; ++N; } } if (N == 0) N=1; normL1 = sqrt(normL1); normgc = sqrt(normgc / N); // check convergence of constraints feLog(" tied interface # %d\n", GetID()); feLog(" CURRENT REQUIRED\n"); double pctn = 0; if (fabs(normL1) > 1e-10) pctn = fabs((normL1 - normL0)/normL1); feLog(" normal force : %15le %15le\n", pctn, m_atol); feLog(" gap function : %15le ***\n", normgc); // check convergence bool bconv = true; if (pctn >= m_atol) bconv = false; if (naug < m_naugmin ) bconv = false; if (naug >= m_naugmax) bconv = true; if (bconv == false) { for (i=0; i<ss.Nodes(); ++i) { // update Lagrange multipliers ss.m_data[i].m_Lm = ss.m_data[i].m_Lm + ss.m_data[i].m_vgap*m_eps; } } return bconv; } //----------------------------------------------------------------------------- //! Serialize the data to the archive. void FETiedInterface::Serialize(DumpStream &ar) { // store contact data FEContactInterface::Serialize(ar); // store contact surface data ms.Serialize(ar); ss.Serialize(ar); // serialize pointers if (ar.IsShallow() == false) { if (ar.IsSaving()) { int NN = ss.Nodes(); ar << NN; for (int i=0; i<NN; ++i) { FESurfaceElement* pe = ss.m_data[i].m_pme; if (pe) ar << pe->m_lid; else ar << -1; } } else { int NN, lid; ar >> NN; for (int i=0; i<NN; ++i) { ar >> lid; if (lid < 0) ss.m_data[i].m_pme = nullptr; else ss.m_data[i].m_pme = &ms.Element(lid); } } } } void FETiedInterface::PrepStep() { if (m_laugon == FECore::LAGMULT_METHOD) { for (int i = 0; i < ss.Nodes(); ++i) { ss.m_data[i].m_Lp = ss.m_data[i].m_Lm; } } } //! Update Lagrange multipliers void FETiedInterface::Update(const std::vector<double>& Ui, const std::vector<double>& ui) { if (m_laugon == FECore::LAGMULT_METHOD) { for (int i = 0; i < ss.Nodes(); ++i) { ss.m_data[i].m_Lm.x = ss.m_data[i].m_Lp.x + Ui[m_LM[3 * i ]] + ui[m_LM[3 * i ]]; ss.m_data[i].m_Lm.y = ss.m_data[i].m_Lp.y + Ui[m_LM[3 * i + 1]] + ui[m_LM[3 * i + 1]]; ss.m_data[i].m_Lm.z = ss.m_data[i].m_Lp.z + Ui[m_LM[3 * i + 2]] + ui[m_LM[3 * i + 2]]; } } } void FETiedInterface::UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) { if (m_laugon != FECore::LAGMULT_METHOD) return; for (int i = 0; i < ss.Nodes(); ++i) { Ui[m_LM[3 * i ]] += ui[m_LM[3 * i ]]; Ui[m_LM[3 * i + 1]] += ui[m_LM[3 * i + 1]]; Ui[m_LM[3 * i + 2]] += ui[m_LM[3 * i + 2]]; } }
C++
3D
febiosoftware/FEBio
FEBioMech/FESolidMaterial.h
.h
2,788
79
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEMaterial.h> #include <FECore/tens4d.h> #include "febiomech_api.h" //----------------------------------------------------------------------------- //! Base class for solid-materials. //! These materials need to define the stress and tangent functions. //! class FEBIOMECH_API FESolidMaterial : public FEMaterial { public: //! constructor FESolidMaterial(FEModel* pfem); //! calculate stress at material point virtual mat3ds Stress(FEMaterialPoint& pt) = 0; //! calculate tangent stiffness at material point virtual tens4ds Tangent(FEMaterialPoint& pt) = 0; //! calculate the 2nd Piola-Kirchhoff stress at material point virtual mat3ds PK2Stress(FEMaterialPoint& pt, const mat3ds E); //! calculate material tangent stiffness at material point virtual tens4dmm MaterialTangent(FEMaterialPoint& pt, const mat3ds E); //! calculate secant tangent stiffness at material point virtual tens4dmm SecantTangent(FEMaterialPoint& pt, bool mat = false); //! return the material density void SetDensity(const double d); //! evaluate density virtual double Density(FEMaterialPoint& pt); //! Is this a rigid material or not virtual bool IsRigid() const { return false; } tens4dmm SolidTangent(FEMaterialPoint& pt); virtual mat3ds SecantStress(FEMaterialPoint& pt, bool PK2 = false); virtual bool UseSecantTangent() { return false; } protected: FEParamDouble m_density; //!< material density DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FESolidMaterial) };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEKinematicGrowth.cpp
.cpp
7,000
215
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2019 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "FEKinematicGrowth.h" #include <FECore/FECoreKernel.h> #include <FECore/FEModel.h> #include <FECore/log.h> #include "FEUncoupledMaterial.h" //----------------------------------------------------------------------------- //! Material point // FEMaterialPointData* FEKinematicMaterialPoint::Copy() { FEKinematicMaterialPoint* pt = new FEKinematicMaterialPoint(*this); if (m_pNext) pt->m_pNext = m_pNext->Copy(); return pt; } //----------------------------------------------------------------------------- void FEKinematicMaterialPoint::Init() { FEMaterialPointData::Init(); // intialize data m_rhor = 0; m_Fe = mat3dd(1); m_Je = 1; m_Fg = mat3dd(1); } //----------------------------------------------------------------------------- void FEKinematicMaterialPoint::Update(const FETimeInfo& timeInfo) { FEMaterialPointData::Update(timeInfo); } //----------------------------------------------------------------------------- void FEKinematicMaterialPoint::Serialize(DumpStream& ar) { if (ar.IsSaving()) { ar << m_Fe << m_Fg << m_rhor; } else { ar >> m_Fe >> m_Fg >> m_rhor; } FEMaterialPointData::Serialize(ar); } //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEKinematicGrowth, FEElasticMaterial) ADD_PROPERTY(m_pBase, "elastic"); ADD_PROPERTY(m_pGrowth, "growth"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FEKinematicGrowth::FEKinematicGrowth(FEModel* pfem) : FEElasticMaterial(pfem) { m_pBase = nullptr; m_pGrowth = nullptr; } //----------------------------------------------------------------------------- //! create material point FEMaterialPointData* FEKinematicGrowth::CreateMaterialPointData() { FEElasticMaterial* pme = GetBaseMaterial(); FEMaterialPointData* ep = pme->CreateMaterialPointData(); return new FEKinematicMaterialPoint(ep); } //----------------------------------------------------------------------------- //! data initialization bool FEKinematicGrowth::Init() { FEUncoupledMaterial* m_pMat = dynamic_cast<FEUncoupledMaterial*>((FEElasticMaterial*)m_pBase); if (m_pMat != nullptr) { feLogError("Elastic material should not be of type uncoupled"); return false; } return FEElasticMaterial::Init(); } //----------------------------------------------------------------------------- //! Returns the Cauchy stress mat3ds FEKinematicGrowth::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pe = *mp.ExtractData<FEElasticMaterialPoint>(); FEKinematicMaterialPoint& pt = *mp.ExtractData<FEKinematicMaterialPoint>(); // overwrite the elastic material point deformation gradient information // to match elastic deformation gradient of kinematic growth material mat3d F = pe.m_F; double J = pe.m_J; pe.m_F = pt.m_Fe; pe.m_J = pt.m_Je; // evaluate stress FEElasticMaterial* emat = GetBaseMaterial(); mat3ds s = emat->Stress(mp); // restore deformation gradient pe.m_F = F; pe.m_J = J; return s; } //----------------------------------------------------------------------------- //! Returns the spatial tangent tens4ds FEKinematicGrowth::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pe = *mp.ExtractData<FEElasticMaterialPoint>(); FEKinematicMaterialPoint& pt = *mp.ExtractData<FEKinematicMaterialPoint>(); // overwrite the elastic material point deformation gradient information // to match elastic deformation gradient of kinematic growth material mat3d F = pe.m_F; double J = pe.m_J; pe.m_F = pt.m_Fe; pe.m_J = pt.m_Je; // evaluate tangent FEElasticMaterial* emat = GetBaseMaterial(); tens4ds c = emat->Tangent(mp); // restore deformation gradient pe.m_F = F; pe.m_J = J; return c; } //----------------------------------------------------------------------------- //! Returns the strain energy density double FEKinematicGrowth::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pe = *mp.ExtractData<FEElasticMaterialPoint>(); FEKinematicMaterialPoint& pt = *mp.ExtractData<FEKinematicMaterialPoint>(); // overwrite the elastic material point deformation gradient information // to match elastic deformation gradient of kinematic growth material mat3d F = pe.m_F; double J = pe.m_J; pe.m_F = pt.m_Fe; pe.m_J = pt.m_Je; // evaluate sed FEElasticMaterial* emat = GetBaseMaterial(); double sed = emat->StrainEnergyDensity(mp); // restore deformation gradient pe.m_F = F; pe.m_J = J; return sed; } //----------------------------------------------------------------------------- //! update material point at each iteration void FEKinematicGrowth::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { // Get the growth tensor inverse FEGrowthTensor* gmat = GetGrowthMaterial(); // material axes mat3d Q = GetLocalCS(mp); // get the fiber vector in local coordinates vec3d fiber = gmat->m_fiber->unitVector(mp); // convert to global coordinates vec3d a0 = Q * fiber; FEElasticMaterialPoint& pe = *mp.ExtractData<FEElasticMaterialPoint>(); // Get the deformation gradient and evaluate elastic deformation mat3d Fg = gmat->GrowthTensor(mp, a0); mat3d Fe = pe.m_F*gmat->GrowthTensorInverse(mp, a0); // extract Kinematic growth material point FEKinematicMaterialPoint& pt = *mp.ExtractData<FEKinematicMaterialPoint>(); pt.m_Fg = Fg; pt.m_Fe = Fe; pt.m_Je = Fe.det(); pt.m_rhor = GetBaseMaterial()->Density(mp)*GetGrowthMaterial()->GrowthDensity(mp, a0); }
C++
3D
febiosoftware/FEBio
FEBioMech/FEInitialVelocity.h
.h
2,098
70
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEInitialCondition.h> #include "febiomech_api.h" #include <FECore/FEModelParam.h> class FEBIOMECH_API FEInitialVelocity : public FENodalIC { public: FEInitialVelocity(FEModel* fem); bool Init() override; // set the initial value void SetValue(const vec3d& v0); // return the values for node i void GetNodalValues(int inode, std::vector<double>& values) override; private: FEParamVec3 m_v0; DECLARE_FECORE_CLASS(); }; class FEBIOMECH_API FEInitialShellVelocity : public FENodalIC { public: FEInitialShellVelocity(FEModel* fem); bool Init() override; // set the initial value void SetValue(const vec3d& v0); // return the values for node i void GetNodalValues(int inode, std::vector<double>& values) override; private: FEParamVec3 m_v0; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FELungMaterial.cpp
.cpp
4,047
122
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "FELungMaterial.h" #include <math.h> BEGIN_FECORE_CLASS(FELungMaterial, FEElasticMaterial) ADD_PARAMETER(m_E, FE_RANGE_GREATER(0.0), "E"); ADD_PARAMETER(m_v, FE_RANGE_GREATER(0.0), "v"); ADD_PARAMETER(m_c1, FE_RANGE_GREATER(0.0), "c1"); ADD_PARAMETER(m_c3, FE_RANGE_GREATER(0.0), "c3"); ADD_PARAMETER(m_d1, FE_RANGE_GREATER(0.0), "d1"); ADD_PARAMETER(m_d3, FE_RANGE_GREATER(0.0), "d3"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FELungMaterial::FELungMaterial(FEModel* pfem) : FEElasticMaterial(pfem) { } bool FELungMaterial::Init() { if (FEElasticMaterial::Init() == false) return false; m_c = m_E/(4*(1+m_v)); m_b = m_v/(1-2*m_v); return true; } double FELungMaterial::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3ds B = pt.LeftCauchyGreen(); double I1 = B.tr(); double I3 = B.det(); return m_c*(I1-3) +m_c/m_b*(pow(I3, -m_b)-1) +m_c1*pow((pow(I3, -1.0/3.0)*I1-3), m_d1) +m_c3*pow((pow(I3, 1.0/3.0)-1), m_d3); } mat3ds FELungMaterial::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3ds B = pt.LeftCauchyGreen(); double I1 = B.tr(); double I3 = B.det(); double J = pt.m_J; mat3dd I(1.0); mat3ds s = (2*m_c*B - 2*m_c*pow(I3, -m_b)*I + +2*m_c1*m_d1*pow(I3, -1.0/3.0)*pow(pow(I3, -1.0/3.0)*I1-3, m_d1-1)*(B-I1/3.0*I) +2.0/3.0*m_c3*m_d3*pow(pow(I3, 1.0/3.0)-1, m_d3-1)*pow(I3,1.0/3.0)*I)/J; return s; } tens4ds FELungMaterial::Tangent(FEMaterialPoint& mp) { // As in the Stress function, we need the data from the FEElasticMaterialPoint // class to calculate the tangent. FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // Get the deformation gradient and its determinant double J = pt.m_J; mat3ds B = pt.LeftCauchyGreen(); double I1 = B.tr(); double I3 = B.det(); // define identity tensor and some useful // dyadic products of the identity tensor. mat3dd I(1.0); tens4ds IxI = dyad1s(I); tens4ds I4 = dyad4s(I); tens4ds bxI = dyad1s(B,I); double term = m_c1*m_d1*pow(I3,-1.0/3.0)*pow(pow(I3,-1.0/3.0)*I1-3, m_d1-1); tens4ds c = (4*m_c*pow(I3, -m_b)*(m_b*IxI+I4) -4.0/3.0*term*(bxI-I1/3.0*IxI) +4*m_c1*m_d1*pow(I3,-2.0/3.0)*(m_d1-1)*pow(pow(I3,-1.0/3.0)*I1-3, m_d1-2)*(dyad1s(B)-I1/3.0*bxI+1.0/9.0*I1*I1*IxI) +4.0/3.0*term*I1*I4 +4.0/9.0*m_c3*m_d3*((m_d3-1)*pow(I3, 2.0/3.0)*pow(pow(I3,1.0/3.0)-1, m_d3-2)+pow(pow(I3,1.0/3.0)-1, m_d3-1)*pow(I3,1.0/3.0))*IxI -4.0/3.0*m_c3*m_d3*pow(pow(I3,1.0/3.0)-1,m_d3-1)*pow(I3,1.0/3.0)*I4)/J; return c; }
C++
3D
febiosoftware/FEBio
FEBioMech/FESpringMaterial.cpp
.cpp
4,771
175
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FESpringMaterial.h" #include <FECore/FEElement.h> vec3d FESpringMaterial::Force(FEDiscreteMaterialPoint& mp) { vec3d e = mp.m_drt; e.unit(); // calculate spring lengths double L0 = mp.m_dr0.norm(); double Lt = mp.m_drt.norm(); double DL = Lt - L0; // evaluate the spring force return e*force(DL); } mat3d FESpringMaterial::Stiffness(FEDiscreteMaterialPoint& mp) { vec3d e = mp.m_drt; e.unit(); // calculate spring lengths double L0 = mp.m_dr0.norm(); double Lt = mp.m_drt.norm(); double DL = Lt - L0; // evaluate the stiffness double F = force(DL); double E = stiffness(DL); if (Lt == 0) { F = 0; Lt = 1; e = vec3d(1, 1, 1); } mat3d A; A.zero(); A[0][0] = ((E - F / Lt)*e.x*e.x + F / Lt); A[1][1] = ((E - F / Lt)*e.y*e.y + F / Lt); A[2][2] = ((E - F / Lt)*e.z*e.z + F / Lt); A[0][1] = A[1][0] = (E - F / Lt)*e.x*e.y; A[1][2] = A[2][1] = (E - F / Lt)*e.y*e.z; A[0][2] = A[2][0] = (E - F / Lt)*e.x*e.z; return A; } double FESpringMaterial::StrainEnergy(FEDiscreteMaterialPoint& mp) { // calculate spring lengths double L0 = mp.m_dr0.norm(); double Lt = mp.m_drt.norm(); double DL = Lt - L0; // evaluate the spring force return strainEnergy(DL); } //----------------------------------------------------------------------------- // FELinearSpring //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FELinearSpring, FESpringMaterial) ADD_PARAMETER(m_E, FE_RANGE_GREATER(0.0), "E"); END_FECORE_CLASS(); FELinearSpring::FELinearSpring(FEModel* pfem) : FESpringMaterial(pfem) { m_E = 1.0; } double FELinearSpring::force(double dl) { return m_E*dl; } double FELinearSpring::stiffness(double dl) { return m_E; } double FELinearSpring::strainEnergy(double dl) { return m_E*dl*dl/2; } //----------------------------------------------------------------------------- // FETensionOnlyLinearSpring //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FETensionOnlyLinearSpring, FESpringMaterial) ADD_PARAMETER(m_E, FE_RANGE_GREATER(0.0), "E"); END_FECORE_CLASS(); double FETensionOnlyLinearSpring::force(double dl) { if (dl >= 0) return m_E*dl; else return 0; } double FETensionOnlyLinearSpring::stiffness(double dl) { return (dl >= 0 ? m_E : 0); } double FETensionOnlyLinearSpring::strainEnergy(double dl) { if(dl >= 0) return m_E*dl*dl/2; else return 0; } //----------------------------------------------------------------------------- // FEExperimentalSpring //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEExperimentalSpring, FESpringMaterial) ADD_PARAMETER(m_E , "E"); ADD_PARAMETER(m_sM, "sM"); ADD_PARAMETER(m_sm, "sm"); END_FECORE_CLASS(); FEExperimentalSpring::FEExperimentalSpring(FEModel* pfem) : FESpringMaterial(pfem) { m_E = 0.0; m_sM = 0.0; m_sm = 0.0; } double FEExperimentalSpring::force(double dl) { if (dl >= 0.0) return m_sM*(1.0 - exp(-m_E*dl / m_sM)); else return -m_sm*(1.0 - exp(m_E*dl / m_sm)); } double FEExperimentalSpring::stiffness(double dl) { if (dl >= 0.0) return m_E*exp(-m_E*dl / m_sM); else return m_E*exp(m_E*dl / m_sm); } double FEExperimentalSpring::strainEnergy(double dl) { if (dl >= 0.0) return m_sM*(m_sM/m_E*(exp(-m_E*dl/m_sM) - 1) + dl); else return m_sm*(m_sm/m_E*(exp(-m_E*dl/m_sm) - 1) - dl); }
C++
3D
febiosoftware/FEBio
FEBioMech/FEFiberKiousisUncoupled.h
.h
2,513
60
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticFiberMaterialUC.h" //----------------------------------------------------------------------------- //! Material class for single fiber, tension only //! D. E. Kiousis, T. C. Gasser and G. A. Holzapfel //! Smooth contact strategies with emphasis on the modeling of balloon angioplasty with stenting //! Int. J. Numer. Meth. Engng 2008; 75:826–855, equation (21) class FEUncoupledFiberKiousis : public FEElasticFiberMaterialUC { public: FEUncoupledFiberKiousis(FEModel* pfem); //! Cauchy stress virtual mat3ds DevFiberStress(FEMaterialPoint& mp, const vec3d& a0) override; // Spatial tangent virtual tens4ds DevFiberTangent(FEMaterialPoint& mp, const vec3d& a0) override; //! Strain energy density virtual double DevFiberStrainEnergyDensity(FEMaterialPoint& mp, const vec3d& a0) override; protected: FEParamDouble m_d1; // material coefficient d1 (proportional to initial fiber modulus) FEParamDouble m_d2; // material coefficient d2 (square of stretch when fiber engages) FEParamDouble m_n; // material coefficient n (power exponent) // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEOsmoticVirialExpansion.cpp
.cpp
3,331
95
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEOsmoticVirialExpansion.h" //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEOsmoticVirialExpansion, FEElasticMaterial) ADD_PARAMETER(m_phiwr, FE_RANGE_CLOSED(0.0, 1.0), "phiw0"); ADD_PARAMETER(m_cr , FE_RANGE_GREATER_OR_EQUAL(0.0), "cr"); ADD_PARAMETER(m_c1, "c1"); ADD_PARAMETER(m_c2, "c2"); ADD_PARAMETER(m_c3, "c3"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEOsmoticVirialExpansion::FEOsmoticVirialExpansion(FEModel* pfem) : FEElasticMaterial(pfem) { m_c1 = m_c2 = m_c3 = 0; } //----------------------------------------------------------------------------- mat3ds FEOsmoticVirialExpansion::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; // calculate concentration in current configuration double c = m_phiwr*m_cr/(J-1+m_phiwr); // calculate osmotic pressure double p = m_c1*c + m_c2*c*c + m_c3*pow(c,3); // calculate T = -p*I mat3dd I(1.0); // identity tensor mat3ds s = -p*I; return s; } //----------------------------------------------------------------------------- tens4ds FEOsmoticVirialExpansion::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; // calculate concentration in current configuration double c = m_phiwr*m_cr/(J-1+m_phiwr); // calculate osmotic pressure double p = m_c1*c + m_c2*c*c + m_c3*pow(c,3); // calculate derivative of osmotic pressure w.r.t. J double dpdJ = -(m_c1 + 2*m_c2*c + 3*m_c3*c*c)*c/(J -1 + m_phiwr); mat3dd I(1.0); // Identity tens4ds IxI = dyad1s(I); tens4ds I4 = dyad4s(I); // calculate tangent osmotic modulus tens4ds C = IxI*(-J*dpdJ) + (2.0*I4 - IxI)*p; return C; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEBodyForce.h
.h
2,165
59
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEMaterialPoint.h> #include <FECore/FEBodyLoad.h> #include "febiomech_api.h" //----------------------------------------------------------------------------- //! This class is the base class for body forces //! Derived classes need to implement the force and stiffness functions. // class FEBIOMECH_API FEBodyForce : public FEBodyLoad { public: //! constructor FEBodyForce(FEModel* pfem); public: //! calculate the body force at a material point virtual vec3d force(FEMaterialPoint& pt) = 0; //! calculate the divergence of the body force at a material point //! TODO: Is this used anywhere? virtual double divforce(FEMaterialPoint& pt); //! calculate constribution to stiffness matrix virtual mat3d stiffness(FEMaterialPoint& pt) = 0; public: void LoadVector(FEGlobalVector& R) override; void StiffnessMatrix(FELinearSystem& LS) override; };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEDamageMooneyRivlin.h
.h
2,350
69
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEUncoupledMaterial.h" #include "FEDamageMaterialPoint.h" class FEDamageMooneyRivlin : public FEUncoupledMaterial { public: FEDamageMooneyRivlin(FEModel* pfem); public: double c1; //!< Mooney-Rivlin coefficient C1 double c2; //!< Mooney-Rivlin coefficient C2 double m_beta; //!< damage parameter beta double m_smin; //!< damage parameter psi-min double m_smax; //!< damage parameter psi-max public: // returns a pointer to a new material point object FEMaterialPointData* CreateMaterialPointData() override; public: //! calculate deviatoric stress at material point mat3ds DevStress(FEMaterialPoint& pt) override; //! calculate deviatoric tangent stiffness at material point tens4ds DevTangent(FEMaterialPoint& pt) override; //! calculate deviatoric strain energy density double DevStrainEnergyDensity(FEMaterialPoint& mp) override; //! data initialization bool Validate() override; // calculate damage reduction factor double Damage(FEMaterialPoint& pt); // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FENonlinearSpring.cpp
.cpp
3,268
115
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "FENonlinearSpring.h" BEGIN_FECORE_CLASS(FENonlinearSpringMaterial, FEDiscreteElasticMaterial) ADD_PARAMETER(m_scale, "scale"); ADD_PARAMETER(m_measure, "measure", 0, "elongation\0strain\0stretch\0"); ADD_PROPERTY(m_F, "force"); END_FECORE_CLASS(); FENonlinearSpringMaterial::FENonlinearSpringMaterial(FEModel* pfem) : FEDiscreteElasticMaterial(pfem) { m_scale = 1.0; m_measure = 0; m_F = nullptr; } vec3d FENonlinearSpringMaterial::Force(FEDiscreteMaterialPoint& mp) { vec3d t = mp.m_drt; t.unit(); // calculate spring lenghts double L0 = mp.m_dr0.norm(); double Lt = mp.m_drt.norm(); double DL = Lt - L0; // evaluate the deformation measure double s = 0.0; switch (m_measure) { case 0: s = DL; break; case 1: s = DL / L0; break; case 2: s = Lt / L0; break; default: break; } // get the force double F = m_scale * m_F->value(s); // evaluate the spring force return t*F; } mat3d FENonlinearSpringMaterial::Stiffness(FEDiscreteMaterialPoint& mp) { vec3d e = mp.m_drt; e.unit(); // calculate spring lengths double L0 = mp.m_dr0.norm(); double Lt = mp.m_drt.norm(); double DL = Lt - L0; // evaluate the deformation measure double s = 0.0, ds = 1.0;; switch (m_measure) { case 0: s = DL; break; case 1: s = DL / L0; ds = 1.0 / L0; break; case 2: s = Lt / L0; ds = 1.0 / L0; break; default: break; } // get the force double F = m_scale * m_F->value(s); // evaluate the stiffness double E = m_scale * m_F->derive(s) * ds; if (Lt == 0) { F = 0; Lt = 1; e = vec3d(1, 1, 1); } mat3d A; A.zero(); A[0][0] = ((E - F / Lt) * e.x * e.x + F / Lt); A[1][1] = ((E - F / Lt) * e.y * e.y + F / Lt); A[2][2] = ((E - F / Lt) * e.z * e.z + F / Lt); A[0][1] = A[1][0] = (E - F / Lt) * e.x * e.y; A[1][2] = A[2][1] = (E - F / Lt) * e.y * e.z; A[0][2] = A[2][0] = (E - F / Lt) * e.x * e.z; return A; } double FENonlinearSpringMaterial::StrainEnergy(FEDiscreteMaterialPoint& mp) { // TODO: implement this assert(false); return 0.0; }
C++
3D
febiosoftware/FEBio
FEBioMech/FESpringRuptureCriterion.cpp
.cpp
2,394
70
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FESpringRuptureCriterion.h" #include "FEDiscreteElasticMaterial.h" #include <FECore/FEElement.h> BEGIN_FECORE_CLASS(FESpringForceCriterion, FEMeshAdaptorCriterion) END_FECORE_CLASS(); FESpringForceCriterion::FESpringForceCriterion(FEModel* fem) : FEMeshAdaptorCriterion(fem) { } bool FESpringForceCriterion::GetMaterialPointValue(FEMaterialPoint& mp, double& value) { FEDiscreteElasticMaterialPoint* ep = mp.ExtractData<FEDiscreteElasticMaterialPoint>(); if (ep == nullptr) return false; vec3d& Ft = ep->m_Ft; double F = ep->m_drt*Ft; value = F; return true; } BEGIN_FECORE_CLASS(FESpringStretchCriterion, FEMeshAdaptorCriterion) END_FECORE_CLASS(); FESpringStretchCriterion::FESpringStretchCriterion(FEModel* fem) : FEMeshAdaptorCriterion(fem) { } bool FESpringStretchCriterion::GetMaterialPointValue(FEMaterialPoint& mp, double& value) { FEDiscreteElasticMaterialPoint* ep = mp.ExtractData<FEDiscreteElasticMaterialPoint>(); if (ep == nullptr) return false; double L0 = ep->m_dr0.norm(); double Lt = ep->m_drt.norm(); double s = Lt / L0; value = s; return true; }
C++
3D
febiosoftware/FEBio
FEBioMech/FECubicCLE.h
.h
2,336
60
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticMaterial.h" //----------------------------------------------------------------------------- //! This class implements a cubic conewise linear elastic (CLE) material (Curnier et al. 1995 J Elasticity). class FECubicCLE : public FEElasticMaterial { public: double m_lp1; // diagonal first lamé constants (tension) double m_lm1; // diagonal first lamé constants (compression) double m_l2; // off-diagonal first lamé constants double m_mu; // shear moduli public: FECubicCLE(FEModel* pfem) : FEElasticMaterial(pfem) {} //! calculate stress at material point mat3ds Stress(FEMaterialPoint& pt) override; //! calculate tangent stiffness at material point tens4ds Tangent(FEMaterialPoint& pt) override; //! calculate strain energy density at material point double StrainEnergyDensity(FEMaterialPoint& pt) override; //! data initialization bool Validate() override; // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FERigidPlanarJoint.h
.h
4,721
126
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FERigidConnector.h" #include "febiomech_api.h" //----------------------------------------------------------------------------- //! The FERigidPlanarJoint class implements a planar joint. The rigid joint //! allows the user to connect two rigid bodies at a point in space //! and allow 2D translation in a plane and rotation about the plane normal. class FEBIOMECH_API FERigidPlanarJoint : public FERigidConnector { public: //! constructor FERigidPlanarJoint(FEModel* pfem); //! destructor virtual ~FERigidPlanarJoint() {} //! initialization bool Init() override; //! calculates the joint forces void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! calculates the joint stiffness void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! calculate Lagrangian augmentation bool Augment(int naug, const FETimeInfo& tp) override; //! serialize data to archive void Serialize(DumpStream& ar) override; //! update state void Update() override; //! Reset data void Reset() override; //! evaluate relative translation vec3d RelativeTranslation(const bool global = false) override; //! evaluate relative rotation vec3d RelativeRotation(const bool global = false) override; //! initial position vec3d InitialPosition() const; //! current position vec3d Position() const; //! current orientation quatd Orientation() const; private: // lag. mult. methods int InitEquations(int neq) override; void BuildMatrixProfile(FEGlobalMatrix& M) override; void UnpackLM(vector<int>& lm); void PrepStep(); void Update(const std::vector<double>& Ui, const std::vector<double>& ui) override; void UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) override; public: // parameters int m_laugon; //!< enforcement method double m_atol; //! augmented Lagrangian tolerance double m_gtol; //! augmented Lagrangian gap tolerance double m_qtol; //! augmented Lagrangian angular gap tolerance int m_naugmin; //! minimum number of augmentations int m_naugmax; //! maximum number of augmentations vec3d m_q0; //! initial position of joint double m_qpx; //! prescribed rotation along first axis double m_dpy; //! prescribed translation along second axis double m_dpz; //! prescribed translation along third axis bool m_bqx; //! flag for prescribing rotation along first axis bool m_bdy; //! flag for prescribing translation along second axis bool m_bdz; //! flag for prescribing translation along third axis double m_eps; //! penalty factor for constraining force double m_ups; //! penalty factor for constraining moment bool m_bautopen; //!< auto-penalty for gap and ang tolerance protected: vec3d m_qa0; //! initial relative position vector of joint w.r.t. A vec3d m_qb0; //! initial relative position vector of joint w.r.t. B vec3d m_e0[3]; //! initial joint basis vec3d m_ea0[3]; //! initial joint basis w.r.t. A vec3d m_eb0[3]; //! initial joint basis w.r.t. B vec3d m_L; //! Lagrange multiplier for constraining force vec3d m_U; //! Lagrange multiplier for constraining moment vec3d m_Fp, m_Mp; vector<int> m_LM; // Lagrange multiplier equation numbers DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FECoupledVerondaWestmann.cpp
.cpp
3,985
123
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FECoupledVerondaWestmann.h" //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FECoupledVerondaWestmann, FEElasticMaterial) ADD_PARAMETER(m_c1, FE_RANGE_GREATER(0.0), "c1")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c2, "c2"); ADD_PARAMETER(m_k , FE_RANGE_GREATER(0.0), "k" )->setUnits(UNIT_PRESSURE); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! calculate stress at material point mat3ds FECoupledVerondaWestmann::Stress(FEMaterialPoint& mp) { // get the elastic material point data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // determinant of deformation gradient double J = pt.m_J; // calculate left Cauchy-Green tensor mat3ds B = pt.LeftCauchyGreen(); // calculate square of B mat3ds B2 = B.sqr(); // Invariants of B (= invariants of C) double I1 = B.tr(); // identity tensor mat3dd I(1.0); // calculate stress return B*(m_c1*m_c2*(2.0*exp(m_c2*(I1-3)) - I1)/J) + B2*(m_c1*m_c2/J) + I*(m_k*log(J)/J); } //----------------------------------------------------------------------------- //! calculate tangent at material point tens4ds FECoupledVerondaWestmann::Tangent(FEMaterialPoint& mp) { // get material point data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate left Cauchy-Green tensor: B = F*Ft mat3ds B = pt.LeftCauchyGreen(); // Invariants of B (= invariants of C) double I1 = B.tr(); double J = pt.m_J; // some useful tensors mat3dd I(1.0); tens4ds IxI = dyad1s(I); tens4ds IoI = dyad4s(I); tens4ds BxB = dyad1s(B); tens4ds BoB = dyad4s(B); // strain energy derivates double W1 = m_c1; double W2 = m_c2; // spatial tangent tens4ds c = BxB*(2.0*W1*W2*(2.0*W2*exp(W2*(I1-3))-1)/J) + BoB*(2.0*W1*W2/J) + IxI*(m_k/J) - IoI*(2.0*m_k*log(J)/J); return c; } //----------------------------------------------------------------------------- //! calculate strain energy density at material point double FECoupledVerondaWestmann::StrainEnergyDensity(FEMaterialPoint& mp) { // get the elastic material point data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // determinant of deformation gradient double J = pt.m_J; double lnJ = log(J); // calculate left Cauchy-Green tensor mat3ds B = pt.LeftCauchyGreen(); // calculate square of B mat3ds B2 = B.sqr(); // Invariants of B (= invariants of C) double I1 = B.tr(); double I2 = (I1*I1 - B2.tr())/2.0; double sed = m_c1*(exp(m_c2*(I1-3))-1) - m_c1*m_c2*(I2-3)/2 + m_k*lnJ*lnJ/2; return sed; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEViscoElasticMaterial.h
.h
3,856
119
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticMaterial.h" //----------------------------------------------------------------------------- //! Material point data for visco-elastic materials class FEViscoElasticMaterialPoint : public FEMaterialPointData { public: enum { MAX_TERMS = 6 }; public: //! constructor FEViscoElasticMaterialPoint(FEMaterialPointData* mp = nullptr); //! copy material point data FEMaterialPointData* Copy(); //! Initialize material point data void Init(); //! Update material point data void Update(const FETimeInfo& timeInfo); //! Serialize data to archive void Serialize(DumpStream& ar); public: mat3ds m_Se; //!< elastic PK2 stress mat3ds m_Sep; //!< elastic 2nd PK stress at previous time mat3ds m_H[MAX_TERMS]; //!< internal variables mat3ds m_Hp[MAX_TERMS]; //!< internal variables at previous timestep double m_alpha[MAX_TERMS]; //!< exponent of right-stretch tensor in series spring double m_alphap[MAX_TERMS]; //!< alpha at previous time step double m_sed; //!< elastic strain energy density double m_sedp; //!< elastic strain energy density at previous time }; //----------------------------------------------------------------------------- //! This class implements a large deformation visco-elastic material // class FEViscoElasticMaterial : public FEElasticMaterial { public: // NOTE: make sure that this parameter is the // same as the MAX_TERMS in the FEViscoElasticMaterialPoint class enum { MAX_TERMS = FEViscoElasticMaterialPoint::MAX_TERMS }; public: //! default constructor FEViscoElasticMaterial(FEModel* pfem); //! get the elastic base material FEElasticMaterial* GetBaseMaterial(); //! Set the base material void SetBaseMaterial(FEElasticMaterial* pbase); public: //! stress function mat3ds Stress(FEMaterialPoint& pt) override; //! tangent function tens4ds Tangent(FEMaterialPoint& pt) override; //! strain energy density double StrainEnergyDensity(FEMaterialPoint& pt) override; //! calculate exponent of right-stretch tensor in series spring bool SeriesStretchExponent(FEMaterialPoint& pt); // returns a pointer to a new material point object FEMaterialPointData* CreateMaterialPointData() override; public: // material parameters FEParamDouble m_g0; //!< intitial visco-elastic coefficient double m_g[MAX_TERMS]; //!< visco-elastic coefficients double m_t[MAX_TERMS]; //!< relaxation times private: FEElasticMaterial* m_Base; //!< pointer to elastic solid material public: // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEIsotropicLeeSacks.cpp
.cpp
4,220
135
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEIsotropicLeeSacks.h" // define the material parameters BEGIN_FECORE_CLASS(FEIsotropicLeeSacks, FEElasticMaterial) ADD_PARAMETER(m_c0, "c0")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c1, "c1")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c2, "c2")->setUnits(UNIT_NONE); ADD_PARAMETER(m_k , "k")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_tangent_scale , "tangent_scale"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEIsotropicLeeSacks::FEIsotropicLeeSacks(FEModel* pfem) : FEElasticMaterial(pfem) { m_c0 = 0.0; m_c1 = 0.0; m_c2 = 0.0; m_k = 0.0; m_tangent_scale = 1.0; } //----------------------------------------------------------------------------- //! Calculates the strain energy density double FEIsotropicLeeSacks::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate right Cauchy-Green tensor and Lagrange strain tensor mat3ds b = pt.LeftCauchyGreen(); double J = pt.m_J; double I1 = b.tr(); // evaluate volumetric strain energy double lnJ = log(J); double U = 0.5 * m_k * pow(lnJ, 2); // Evaluate exp(Q) double Q = m_c2 * (I1 - 3.0) * (I1 - 3.0); double eQ = exp(Q); // Evaluate the strain energy density double sed = m_c0*(0.5*(I1 - 3) - lnJ) + 0.5*m_c1*(eQ - 1.0) + U; return sed; } //----------------------------------------------------------------------------- //! Calculates the deviatoric stress mat3ds FEIsotropicLeeSacks::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate deviatoric mat3ds b = pt.LeftCauchyGreen(); double J = pt.m_J; double I1 = b.tr(); // evaluate volumetric strain energy double p = m_k * log(J)/J; mat3dd I(1.0); // Evaluate exp(Q) double Q = m_c2 * (I1 - 3.0) * (I1 - 3.0); double eQ = exp(Q); mat3ds s = I * p + (b - I)*(m_c0/J) + b*(2.0*m_c1*m_c2*(I1 - 3)*eQ/J); return s; } //----------------------------------------------------------------------------- //! Calculates the deviatoric tangent tens4ds FEIsotropicLeeSacks::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // apply tangent scale double c0 = m_c0 * m_tangent_scale; // calculate deviatoric mat3ds b = pt.LeftCauchyGreen(); double J = pt.m_J; double I1 = b.tr(); // we'll need these tensors mat3dd I(1.0); tens4ds IoI = dyad4s(I); tens4ds IxI = dyad1s(I); tens4ds bxb = dyad1s(b); // evaluate volumetric tangent double lnJ = log(J); double p = m_k * lnJ / J; double pJ = m_k * (1.0 - lnJ) / (J*J); tens4ds cp = IxI * (p + J * pJ) + IoI * (2.0 * c0/J -2.0 * p); // evaluate strain tangent double Q = m_c2 * (I1 - 3.0) * (I1 - 3.0); double eQ = exp(Q); tens4ds cw = bxb*(4.0*m_c1*m_c2*eQ*(1.0+2.0*m_c2*(I1 - 3.0)*(I1 - 3.0)) / J); // put it together tens4ds c = cw + cp; return c; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEDiscreteElasticMaterial.cpp
.cpp
2,833
95
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEDiscreteElasticMaterial.h" FEMaterialPointData* FEDiscreteElasticMaterialPoint::Copy() { FEDiscreteElasticMaterialPoint* pt = new FEDiscreteElasticMaterialPoint(*this); if (m_pNext) pt->m_pNext = m_pNext->Copy(); return pt; } //============================================================================= FEDiscreteElasticMaterial::FEDiscreteElasticMaterial(FEModel* pfem) : FEDiscreteMaterial(pfem) { } FEMaterialPointData* FEDiscreteElasticMaterial::CreateMaterialPointData() { return new FEDiscreteElasticMaterialPoint; } //============================================================================= // FECompositeDiscreteElasticMaterial //============================================================================= BEGIN_FECORE_CLASS(FECompositeDiscreteMaterial, FEDiscreteElasticMaterial) ADD_PROPERTY(m_mats, "mat"); END_FECORE_CLASS(); FECompositeDiscreteMaterial::FECompositeDiscreteMaterial(FEModel* pfem) : FEDiscreteElasticMaterial(pfem) { } vec3d FECompositeDiscreteMaterial::Force(FEDiscreteMaterialPoint& mp) { vec3d force; for(auto mat : m_mats) { force += mat->Force(mp); } return force; } mat3d FECompositeDiscreteMaterial::Stiffness(FEDiscreteMaterialPoint& mp) { mat3d stiffness; stiffness.zero(); for(auto mat : m_mats) { stiffness += mat->Stiffness(mp); } return stiffness; } double FECompositeDiscreteMaterial::StrainEnergy(FEDiscreteMaterialPoint& mp) { double energy = 0; for(auto mat : m_mats) { energy += mat->StrainEnergy(mp); } return energy; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEElasticANSShellDomain.h
.h
5,869
156
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FESSIShellDomain.h" #include "FEElasticDomain.h" #include "FESolidMaterial.h" //----------------------------------------------------------------------------- //! Domain described by 3D shell elements class FEElasticANSShellDomain : public FESSIShellDomain, public FEElasticDomain { public: FEElasticANSShellDomain(FEModel* pfem); //! \todo do I really need this? FEElasticANSShellDomain& operator = (FEElasticANSShellDomain& d); //! Activate the domain void Activate() override; //! Unpack shell element data void UnpackLM(FEElement& el, vector<int>& lm) override; //! Set flag for update for dynamic quantities void SetDynamicUpdateFlag(bool b); //! serialization void Serialize(DumpStream& ar) override; //! get the material (overridden from FEDomain) FEMaterial* GetMaterial() override { return m_pMat; } //! set the material void SetMaterial(FEMaterial* pmat) override; //! get the total dof list const FEDofList& GetDOFList() const override; public: // overrides from FEElasticDomain //! internal stress forces void InternalForces(FEGlobalVector& R) override; //! Calculates inertial forces for dynamic problems void InertialForces(FEGlobalVector& R, vector<double>& F) override; //! calculate body force void BodyForce(FEGlobalVector& R, FEBodyForce& bf) override; // update stresses void Update(const FETimeInfo& tp) override; // update the element stress void UpdateElementStress(int iel, const FETimeInfo& tp); //! initialize elements for this domain void PreSolveUpdate(const FETimeInfo& timeInfo) override; //! calculates the global stiffness matrix for this domain void StiffnessMatrix(FELinearSystem& LS) override; // inertial stiffness void MassMatrix(FELinearSystem& LS, double scale) override; // body force stiffness void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) override; // evaluate strain E and matrix hu and hw void EvaluateEh(FEShellElementNew& el, const int n, const vec3d* Gcnt, mat3ds& E, vector<matrix>& hu, vector<matrix>& hw, vector<vec3d>& Nu, vector<vec3d>& Nw); public: // --- S T I F F N E S S --- //! calculates the shell element stiffness matrix void ElementStiffness(int iel, matrix& ke); // --- R E S I D U A L --- //! Calculates the internal stress vector for shell elements void ElementInternalForce(FEShellElementNew& el, vector<double>& fe); //! Calculate extenral body forces for shell elements void ElementBodyForce(FEModel& fem, FEShellElementNew& el, vector<double>& fe); //! Calculate extenral body forces for shell elements void ElementBodyForce(FEBodyForce& BF, FEShellElementNew& el, vector<double>& fe); //! Calculates the inertial force for shell elements void ElementInertialForce(FEShellElementNew& el, vector<double>& fe); //! calculates the solid element mass matrix void ElementMassMatrix(FEShellElementNew& el, matrix& ke, double a); //! calculates the stiffness matrix due to body forces void ElementBodyForceStiffness(FEBodyForce& bf, FEShellElementNew& el, matrix& ke); public: // --- A N S M E T H O D --- // Evaluate contravariant components of mat3ds tensor void mat3dsCntMat61(const mat3ds s, const vec3d* Gcnt, matrix& S); // Evaluate contravariant components of tens4ds tensor void tens4dsCntMat66(const tens4ds c, const vec3d* Gcnt, matrix& C); void tens4dmmCntMat66(const tens4dmm c, const vec3d* Gcnt, matrix& C); // Evaluate the strain using the ANS method void CollocationStrainsANS(FEShellElementNew& el, vector<double>& E, vector< vector<vec3d>>& HU, vector< vector<vec3d>>& HW, matrix& NS, matrix& NN); void EvaluateANS(FEShellElementNew& el, const int n, const vec3d* Gcnt, mat3ds& Ec, vector<matrix>& hu, vector<matrix>& hw, vector<double>& E, vector< vector<vec3d>>& HU, vector< vector<vec3d>>& HW); protected: FESolidMaterial* m_pMat; int m_nEAS; bool m_update_dynamic; //!< flag for updating quantities only used in dynamic analysis bool m_secant_stress; //!< use secant approximation to stress bool m_secant_tangent; //!< flag for using secant tangent FEDofList m_dofV; FEDofList m_dofSV; FEDofList m_dofSA; FEDofList m_dofR; FEDofList m_dof; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEElasticShellDomainOld.h
.h
4,965
142
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEShellDomain.h> #include <FECore/FEDofList.h> #include "FEElasticDomain.h" #include "FESolidMaterial.h" //----------------------------------------------------------------------------- //! Domain described by 3D shell elements class FEElasticShellDomainOld : public FEShellDomainOld, public FEElasticDomain { public: FEElasticShellDomainOld(FEModel* pfem); //! \todo do I really need this? FEElasticShellDomainOld& operator = (FEElasticShellDomainOld& d); //! Initialize domain bool Init() override; //! Activate the domain void Activate() override; //! Unpack shell element data void UnpackLM(FEElement& el, vector<int>& lm) override; //! get the material (overridden from FEDomain) FEMaterial* GetMaterial() override { return m_pMat; } //! set the material void SetMaterial(FEMaterial* pmat) override; //! get total dof list const FEDofList& GetDOFList() const override; public: // overrides from FEElasticDomain //! calculates the residual // void Residual(FESolver* psolver, vector<double>& R); //! internal stress forces void InternalForces(FEGlobalVector& R) override; //! Calculates inertial forces for dynamic problems | todo implement this (removed assert DSR) void InertialForces(FEGlobalVector& R, vector<double>& F) override { } //! calculate body force void BodyForce(FEGlobalVector& R, FEBodyForce& bf) override; // update stresses void Update(const FETimeInfo& tp) override; //! calculates the global stiffness matrix for this domain void StiffnessMatrix(FELinearSystem& LS) override; // inertial stiffness \todo implement this (removed assert DSR) void MassMatrix(FELinearSystem& LS, double scale) override { } // body force stiffness \todo implement this (removed assert DSR) void BodyForceStiffness (FELinearSystem& LS, FEBodyForce& bf) override { } public: //! calculates covariant basis vectors at an integration point void CoBaseVectors0(FEShellElementOld& el, int n, vec3d g[3]); //! calculates contravariant basis vectors at an integration point void ContraBaseVectors0(FEShellElementOld& el, int n, vec3d g[3]); // inverse jacobian with respect to reference frame double invjac0(FEShellElementOld& el, double J[3][3], int n); // jacobian with respect to reference frame double detJ0(FEShellElementOld& el, int n); //! calculates covariant basis vectors at an integration point void CoBaseVectors(FEShellElementOld& el, int n, vec3d g[3]); //! calculates contravariant basis vectors at an integration point void ContraBaseVectors(FEShellElementOld& el, int n, vec3d g[3]); // jacobian with respect to current frame double detJ(FEShellElementOld& el, int n); // calculate deformation gradient double defgrad(FEShellElementOld& el, mat3d& F, int n); // inverse jacobian with respect to current frame double invjact(FEShellElementOld& el, double J[3][3], int n); public: // --- S T I F F N E S S --- //! calculates the shell element stiffness matrix void ElementStiffness(int iel, matrix& ke); // --- R E S I D U A L --- //! Calculates the internal stress vector for shell elements void ElementInternalForce(FEShellElementOld& el, vector<double>& fe); //! Calculate extenral body forces for shell elements void ElementBodyForce(FEModel& fem, FEShellElementOld& el, vector<double>& fe); //! Calculate extenral body forces for shell elements void ElementBodyForce(FEBodyForce& BF, FEShellElementOld& el, vector<double>& fe); protected: FESolidMaterial* m_pMat; FEDofList m_dofSU; // shell displacement dofs FEDofList m_dofSR; // shell rotation dofs FEDofList m_dofR; // rigid rotation dofs FEDofList m_dof; };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FESRIElasticSolidDomain.h
.h
1,733
43
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticSolidDomain.h" //----------------------------------------------------------------------------- //! Class implementing selective reduced integration for the evaluation of the internal force vector class FESRIElasticSolidDomain : public FEElasticSolidDomain { public: FESRIElasticSolidDomain(FEModel* pfem); public: //! internal stress forces virtual void ElementInternalForce(FESolidElement& el, vector<double>& fe); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEFixedDisplacement.h
.h
1,502
41
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEFixedBC.h> class FEFixedDisplacement : public FEFixedBC { public: FEFixedDisplacement(FEModel* fem); bool Init() override; private: bool m_dofx, m_dofy, m_dofz; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEPipetteAspiration.h
.h
2,361
67
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FESurfaceLoad.h> #include <FECore/FEModelParam.h> //----------------------------------------------------------------------------- //! The pressure surface is a surface domain that sustains pressure boundary //! conditions //! class FEPipetteAspiration : public FESurfaceLoad { public: //! constructor FEPipetteAspiration(FEModel* pfem); //! initialization bool Init() override; public: //! calculate residual void LoadVector(FEGlobalVector& R) override; //! calculate stiffness void StiffnessMatrix(FELinearSystem& LS) override; //! label material points that get pressure void PrepStep() override; protected: FEParamDouble m_pressure; //!< pressure value double m_radius; //!< pipette radius vec3d m_center; //!< pipette center vec3d m_normal; //!< pipette normal direction private: int m_contact; //!< contact surface on which pipette is used std::vector< std::vector<bool>> m_tag; //!< tag for material points of surface DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FETiedContactSurface.h
.h
2,648
82
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEContactSurface.h" //----------------------------------------------------------------------------- //! This class describes a contact surface used for tied contact. //! this class is used in contact analyses to describe a contacting //! surface in a tied contact interface. class FETiedContactSurface : public FEContactSurface { public: class Data : public FEContactMaterialPoint { public: Data(); void Init() override; void Serialize(DumpStream& ar) override; public: vec3d m_vgap; //!< gap function at nodes vec2d m_rs; //!< natural coordinates of projection on secondary surface element vec3d m_Lm, m_Lp; //!< Lagrange multipliers (current, previous time step) vec3d m_Tc; //!< contact forces double m_off; //!< offset values (used for shells) }; public: //! constructor FETiedContactSurface(FEModel* pfem); //! Initializes data structures bool Init(); //! data serialization void Serialize(DumpStream& ar); //! offset shell surfaces (must be called before Init()) void SetShellOffset(bool b) { m_boffset = b; } public: void GetContactTraction(int nface, vec3d& pt); void GetNodalContactPressure(int nface, double* pn); void GetNodalContactTraction(int nface, vec3d* tn); public: vector<Data> m_data; //!< integration point data protected: bool m_boffset; //!< offset shells };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEInitialRigidKinematics.cpp
.cpp
2,430
69
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEInitialRigidKinematics.h" #include "FEBioMech.h" #include <FECore/FEMaterialPoint.h> #include <FECore/FENode.h> BEGIN_FECORE_CLASS(FEInitialRigidKinematics, FENodalIC) ADD_PARAMETER(m_v, "velocity")->setUnits(UNIT_VELOCITY); ADD_PARAMETER(m_w, "angular_velocity")->setUnits(UNIT_ANGULAR_VELOCITY); ADD_PARAMETER(m_c, "center_of_rotation")->setUnits(UNIT_LENGTH); END_FECORE_CLASS(); FEInitialRigidKinematics::FEInitialRigidKinematics(FEModel* fem) : FENodalIC(fem) { m_v = vec3d(0, 0, 0); m_w = vec3d(0, 0, 0); m_c = vec3d(0, 0, 0); } // initialization bool FEInitialRigidKinematics::Init() { FEDofList dofs(GetFEModel()); if (dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::VELOCITY)) == false) return false; SetDOFList(dofs); return FENodalIC::Init(); } // return the values for node i void FEInitialRigidKinematics::GetNodalValues(int inode, std::vector<double>& values) { assert(values.size() == 3); const FENodeSet& nset = *GetNodeSet(); const FENode& node = *nset.Node(inode); vec3d r = node.m_rt; vec3d v = m_v + (m_w ^ (r - m_c)); values[0] = v.x; values[1] = v.y; values[2] = v.z; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEPrescribedActiveContractionTransIsoUC.cpp
.cpp
3,371
99
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEPrescribedActiveContractionTransIsoUC.h" //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEPrescribedActiveContractionTransIsoUC, FEUncoupledMaterial) ADD_PARAMETER(m_T0 , "T0" ); ADD_PROPERTY(m_Q, "mat_axis")->SetFlags(FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEPrescribedActiveContractionTransIsoUC::FEPrescribedActiveContractionTransIsoUC(FEModel* pfem) : FEUncoupledMaterial(pfem) { m_T0 = 0.0; } //----------------------------------------------------------------------------- bool FEPrescribedActiveContractionTransIsoUC::Validate() { if (FEUncoupledMaterial::Validate() == false) return false; // fiber direction in local coordinate system (reference configuration) m_n0.x = 1; m_n0.y = 0; m_n0.z = 0; return true; } //----------------------------------------------------------------------------- void FEPrescribedActiveContractionTransIsoUC::Serialize(DumpStream& ar) { FEUncoupledMaterial::Serialize(ar); if (ar.IsShallow()) return; ar & m_n0; } //----------------------------------------------------------------------------- mat3ds FEPrescribedActiveContractionTransIsoUC::DevStress(FEMaterialPoint &mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient double J = pt.m_J; mat3d F = pt.m_F; mat3ds b = pt.LeftCauchyGreen(); // get the local coordinate systems mat3d Q = GetLocalCS(mp); // evaluate fiber direction in global coordinate system vec3d n0 = Q*m_n0; // evaluate the deformed fiber direction vec3d nt = F*n0; mat3ds N = dyad(nt); // evaluate the active stress double T0 = m_T0(mp); mat3ds s = (b-N)*(T0/J); return s; } //----------------------------------------------------------------------------- tens4ds FEPrescribedActiveContractionTransIsoUC::DevTangent(FEMaterialPoint &mp) { return tens4ds(0.0); }
C++
3D
febiosoftware/FEBio
FEBioMech/FECoupledTransIsoMooneyRivlin.h
.h
2,449
66
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticMaterial.h" #include <FECore/FEModelParam.h> //----------------------------------------------------------------------------- //! Coupled transversely-isotropic Mooney-Rivlin material //! class FECoupledTransIsoMooneyRivlin : public FEElasticMaterial { public: FECoupledTransIsoMooneyRivlin(FEModel* pfem); public: FEParamDouble m_c1; //!< Mooney-Rivlin coefficient C1 FEParamDouble m_c2; //!< Mooney-Rivlin coefficient C2 FEParamDouble m_c3; //!< fiber stress scale factor FEParamDouble m_c4; //!< exponential scale factor FEParamDouble m_c5; //!< slope of linear stress region FEParamDouble m_flam; //!< fiber stretch at which fibers are straight FEParamDouble m_K; //!< "bulk"-modulus FEVec3dValuator* m_fiber; public: //! calculate deviatoric stress at material point mat3ds Stress(FEMaterialPoint& pt) override; //! calculate deviatoric tangent stiffness at material point tens4ds Tangent(FEMaterialPoint& pt) override; //! calculate strain energy density at material point double StrainEnergyDensity(FEMaterialPoint& pt) override; // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEFiberNHUC.h
.h
2,150
63
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticFiberMaterialUC.h" #include "FEFiberMaterial.h" //----------------------------------------------------------------------------- //! Neo-Hookean law class FEFiberNHUC : public FEFiberMaterialUncoupled { public: FEFiberNHUC(FEModel* pfem); //! Cauchy stress mat3ds DevFiberStress(FEMaterialPoint& mp, const vec3d& a0) override; // Spatial tangent tens4ds DevFiberTangent(FEMaterialPoint& mp, const vec3d& a0) override; //! Strain energy density double DevFiberStrainEnergyDensity(FEMaterialPoint& mp, const vec3d& a0) override; public: double m_mu; // shear modulus DECLARE_FECORE_CLASS(); // declare the parameter list }; class FEUncoupledFiberNH : public FEElasticFiberMaterialUC_T<FEFiberNHUC> { public: FEUncoupledFiberNH(FEModel* fem) : FEElasticFiberMaterialUC_T<FEFiberNHUC>(fem) {} DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEMassDamping.cpp
.cpp
2,135
59
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEMassDamping.h" #include <FEBioMech/FEElasticMaterialPoint.h> BEGIN_FECORE_CLASS(FEMassDamping, FEBodyForce) ADD_PARAMETER(m_C, "C"); END_FECORE_CLASS(); FEMassDamping::FEMassDamping(FEModel* fem) : FEBodyForce(fem) { m_C = 0.0; } //! calculate the body force at a material point vec3d FEMassDamping::force(FEMaterialPoint& mp) { FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); return ep.m_v*m_C; } //! calculate the divergence of the body force at a material point double FEMassDamping::divforce(FEMaterialPoint& mp) { FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); return ep.m_L.trace()*m_C; } //! calculate constribution to stiffness matrix mat3d FEMassDamping::stiffness(FEMaterialPoint& pt) { double dt = CurrentTimeIncrement(); return mat3dd(-m_C / dt); }
C++
3D
febiosoftware/FEBio
FEBioMech/FEGenericBodyForce.h
.h
3,115
93
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEBodyForce.h" #include <FECore/FEModelParam.h> //----------------------------------------------------------------------------- //! This class defines a non-homogeneous body force, i.e. the force can depend //! on the reference position class FEGenericBodyForce : public FEBodyForce { public: //! constructor FEGenericBodyForce(FEModel* pfem); //! evaluate the body force vec3d force(FEMaterialPoint& pt) override; //! evaluate the divergence of the body force double divforce(FEMaterialPoint& pt) override { return 0; } //! stiffness mat3d stiffness(FEMaterialPoint& pt) override; private: void StiffnessMatrix(FELinearSystem& LS) override; public: FEParamVec3 m_force; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! This class defines a deformation-independent constant force (e.g. gravity) // NOTE: This class is obsolete! class FEConstBodyForceOld : public FEBodyForce { public: FEConstBodyForceOld(FEModel* pfem) : FEBodyForce(pfem) { m_f = vec3d(0, 0, 0); } vec3d force(FEMaterialPoint& pt) override { return m_f; } double divforce(FEMaterialPoint& pt) override { return 0; } mat3d stiffness(FEMaterialPoint& pt) override { return mat3ds(0, 0, 0, 0, 0, 0); } protected: vec3d m_f; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- // Class that implements old body force // NOTE: This class is obsolete! class FENonConstBodyForceOld : public FEBodyForce { public: FENonConstBodyForceOld(FEModel* fem); vec3d force(FEMaterialPoint& pt) override; double divforce(FEMaterialPoint& pt) override { return 0; } mat3d stiffness(FEMaterialPoint& pt) override { return mat3ds(0, 0, 0, 0, 0, 0); } private: FEParamDouble m_f[3]; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEReactiveViscoelastic.h
.h
5,132
133
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticMaterial.h" #include "FEBondRelaxation.h" #include "FEBondRecruitment.h" #include "FEReactiveVEMaterialPoint.h" #include "FEDamageMaterial.h" #include "FEReactiveFatigue.h" #include "FEReactivePlasticDamage.h" #include <FECore/FEFunction1D.h> //----------------------------------------------------------------------------- //! This class implements a large deformation reactive viscoelastic material // class FEReactiveViscoelasticMaterial : public FEElasticMaterial { public: //! default constructor FEReactiveViscoelasticMaterial(FEModel* pfem); //! get the elastic base material FEElasticMaterial* GetBaseMaterial() { return m_pBase; } //! Set the base material void SetBaseMaterial(FEElasticMaterial* pbase) { m_pBase = pbase; } //! get the elastic bond material FEElasticMaterial* GetBondMaterial() { return m_pBond; } //! Set the base material void SetBondMaterial(FEElasticMaterial* pbond) { m_pBond = pbond; } public: //! data initialization bool Init() override; void Serialize(DumpStream& ar) override; //! stress function mat3ds Stress(FEMaterialPoint& pt) override; mat3ds StressStrongBonds(FEMaterialPoint& pt); mat3ds StressWeakBonds(FEMaterialPoint& pt); //! tangent function tens4ds Tangent(FEMaterialPoint& pt) override; tens4ds TangentStrongBonds(FEMaterialPoint& pt); tens4ds TangentWeakBonds(FEMaterialPoint& pt); //! strain energy density function double StrainEnergyDensity(FEMaterialPoint& pt) override; double StrongBondSED(FEMaterialPoint& pt) override; double WeakBondSED(FEMaterialPoint& pt) override; //! cull generations void CullGenerations(FEMaterialPoint& pt); //! evaluate bond mass fraction for a given generation double BreakingBondMassFraction(FEMaterialPoint& pt, const int ig, const mat3ds D); //! evaluate bond mass fraction of reforming generation double ReformingBondMassFraction(FEMaterialPoint& pt); //! detect new generation bool NewGeneration(FEMaterialPoint& pt); //! return number of generations int RVEGenerations(FEMaterialPoint& pt); //! returns a pointer to a new material point object FEMaterialPointData* CreateMaterialPointData() override; //! specialized material points void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) override; //! get base material point FEMaterialPoint* GetBaseMaterialPoint(FEMaterialPoint& mp); //! get bond material point FEMaterialPoint* GetBondMaterialPoint(FEMaterialPoint& mp); //! evaluate scalar strain measure (same type as trigger strain for bond breaking) double ScalarStrain(FEMaterialPoint& mp); private: FEElasticMaterial* m_pBase; //!< pointer to elastic solid material for strong bonds FEElasticMaterial* m_pBond; //!< pointer to elastic solid material for reactive bonds FEBondRelaxation* m_pRelx; //!< pointer to bond relaxation material for reactive bonds FEBondRecruitment* m_pWCDF; //!< pointer to weak bond recruitment function private: FEDamageMaterial* m_pDmg; //!< pointer to base material if it is a FEDamageMaterial FEReactiveFatigue* m_pFtg; //!< pointer to base material if it is a FEReactiveFatigue FEReactivePlasticDamage* m_pRPD; //!< pointer to base material if it is a FEReactivePlasticDamage double Damage(FEMaterialPoint& mp); //!< return damage in this material public: double m_wmin; //!< minimum value of relaxation int m_btype; //!< bond kinetics type int m_ttype; //!< bond breaking trigger type double m_emin; //!< strain threshold for triggering new generation int m_nmax; //!< highest number of generations achieved in analysis DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEForceVelocityContraction.h
.h
3,448
98
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEActiveContractionMaterial.h" //----------------------------------------------------------------------------- class FEForceVelocityMaterialPoint : public FEMaterialPointData { public: enum { MAX_TERMS = 3 }; public: FEForceVelocityMaterialPoint(); FEMaterialPointData* Copy(); void Init(); void Serialize(DumpStream& ar); public: double m_lambdap; double m_H[MAX_TERMS]; double m_Hp[MAX_TERMS]; }; //----------------------------------------------------------------------------- //! A material class describing the active fiber contraction model of Estrada et al. in doi: 10.1115/1.4044030 class FEForceVelocityContraction : public FEActiveContractionMaterial { public: enum { MAX_TERMS = 3 }; public: FEForceVelocityContraction(FEModel* pfem); //! initialization bool Init() override; //! calculate the active stress mat3ds ActiveStress(FEMaterialPoint& mp, const vec3d& a0) override; //! active contraction stiffness contribution tens4ds ActiveStiffness(FEMaterialPoint& mp, const vec3d& a0) override; //! create material point data FEMaterialPointData* CreateMaterialPointData() override { return new FEForceVelocityMaterialPoint; } public: //! update force-velocity material point void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp, const vec3d& a0) override; protected: double m_ascl; //!< activation scale factor double m_Tmax; //!< activation scale factor double m_ca0; //!< intracellular calcium concentration double m_camax; //!< peak calcium concentration double m_beta; //!< shape of peak isometric tension-sarcomere length relation double m_l0; //!< unloaded length double m_refl; //!< sarcomere length double m_alpha[MAX_TERMS]; double m_A[MAX_TERMS]; double m_at; bool m_bfvel; //!< flag for calculating force-velocity contraction response DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FESurfaceForceUniform.cpp
.cpp
4,113
118
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FESurfaceForceUniform.h" #include "FEBioMech.h" #include <FECore/FEFacetSet.h> //============================================================================= BEGIN_FECORE_CLASS(FESurfaceForceUniform, FESurfaceLoad) ADD_PARAMETER(m_scale , "scale")->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE); ADD_PARAMETER(m_force , "force")->SetFlags(0)->setUnits(UNIT_FORCE); ADD_PARAMETER(m_bshellb , "shell_bottom"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FESurfaceForceUniform::FESurfaceForceUniform(FEModel* pfem) : FESurfaceLoad(pfem) { m_scale = 1.0; m_force = m_traction = vec3d(0, 0, 0); m_bshellb = false; } //----------------------------------------------------------------------------- //! allocate storage void FESurfaceForceUniform::SetSurface(FESurface* ps) { FESurfaceLoad::SetSurface(ps); } //----------------------------------------------------------------------------- // initialization bool FESurfaceForceUniform::Init() { // get the degrees of freedom m_dof.Clear(); if (m_bshellb == false) { m_dof.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT)); } else { m_dof.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT)); } if (m_dof.IsEmpty()) return false; if (FESurfaceLoad::Init() == false) return false; // evaluate uniform traction based on applied force FESurface& surf = GetSurface(); surf.SetShellBottom(m_bshellb); double area = 0; for (int i=0; i<surf.Elements(); ++i) { FESurfaceElement& el = surf.Element(i); area += surf.FaceArea(el); } m_traction = m_force/area; return true; } //----------------------------------------------------------------------------- void FESurfaceForceUniform::LoadVector(FEGlobalVector& R) { FESurface& surf = GetSurface(); surf.SetShellBottom(m_bshellb); // evaluate the integral FESurfaceForceUniform* load = this; surf.LoadVector(R, m_dof, true, [=](FESurfaceMaterialPoint& pt, const FESurfaceDofShape& dof_a, std::vector<double>& val) { // evaluate traction at this material point vec3d t = m_traction*m_scale; if (load->m_bshellb) t = -t; double J = (pt.dxr ^ pt.dxs).norm(); double H_u = dof_a.shape; val[0] = H_u * t.x*J; val[1] = H_u * t.y*J; val[2] = H_u * t.z*J; }); } //----------------------------------------------------------------------------- void FESurfaceForceUniform::StiffnessMatrix(FELinearSystem& LS) { // Nothing to do here. // TODO: I think if the linear flag is false, I do need to evaluate a stiffness. }
C++
3D
febiosoftware/FEBio
FEBioMech/FERadialBodyForce.h
.h
1,791
49
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEBodyForce.h" //! This class defines a radial body force. //! The body force depends on the current nodal coordinates class FERadialBodyForce : public FEBodyForce { public: FERadialBodyForce(FEModel* pfem); vec3d force(FEMaterialPoint& mp) override; double divforce(FEMaterialPoint& mp) override; mat3d stiffness(FEMaterialPoint& mp) override; public: vec3d c; // force center double p; // power double s[3]; // scale factors for body force components DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEPerfectOsmometer.cpp
.cpp
3,625
109
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEPerfectOsmometer.h" #include <FECore/log.h> // define the material parameters BEGIN_FECORE_CLASS(FEPerfectOsmometer, FEElasticMaterial) ADD_PARAMETER(m_phiwr, FE_RANGE_CLOSED(0.0, 1.0), "phiw0"); ADD_PARAMETER(m_iosm , FE_RANGE_GREATER_OR_EQUAL(0.0), "iosm")->setUnits("n/L^3"); ADD_PARAMETER(m_bosm , FE_RANGE_GREATER_OR_EQUAL(0.0), "bosm")->setUnits("n/L^3"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEPerfectOsmometer::FEPerfectOsmometer(FEModel* pfem) : FEElasticMaterial(pfem) { m_Rgas = 0; m_Tabs = 0; } //----------------------------------------------------------------------------- bool FEPerfectOsmometer::Init() { if (FEElasticMaterial::Init() == false) return false; m_Rgas = GetGlobalConstant("R"); m_Tabs = GetGlobalConstant("T"); if (m_Rgas <= 0) { feLogError("A positive universal gas constant R must be defined in Globals section"); return false; } if (m_Tabs <= 0) { feLogError("A positive absolute temperature T must be defined in Globals section"); return false; } return true; } //----------------------------------------------------------------------------- mat3ds FEPerfectOsmometer::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; // calculate internal concentration in current configuration double iosm = m_iosm*m_phiwr/(J-1+m_phiwr); // calculate osmotic pressure double p = m_Rgas*m_Tabs*(iosm - m_bosm); // calculate T = -p*I mat3dd I(1.0); // identity tensor mat3ds s = -p*I; return s; } //----------------------------------------------------------------------------- tens4ds FEPerfectOsmometer::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; // calculate internal osmolarity in current configuration double iosm = m_iosm*m_phiwr/(J-1+m_phiwr); // calculate osmotic pressure double p = m_Rgas*m_Tabs*(iosm - m_bosm); // calculate derivative of osmotic pressure w.r.t. J double dp = -m_Rgas*m_Tabs*iosm/(J-1+m_phiwr); mat3dd I(1.0); // Identity tens4ds I1 = dyad1s(I); tens4ds I4 = dyad4s(I); // calculate tangent osmotic modulus tens4ds c = -J*dp*I1 + p*(2.0*I4 - I1); return c; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEAzimuthConstraint.h
.h
2,873
82
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FENodeSetConstraint.h> #include <FECore/FENodeSet.h> #include "febiomech_api.h" class FEBIOMECH_API FEAzimuthConstraint : public FENodeSetConstraint { public: FEAzimuthConstraint(FEModel* fem); //! initialization bool Init() override; //! Calculate the constraint force void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! calculate the constraint stiffness void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! augmentations bool Augment(int naug, const FETimeInfo& tp) override; //! build connectivity for matrix profile void BuildMatrixProfile(FEGlobalMatrix& M) override; //! return number of equations to be allocated for Lagrange multipliers int InitEquations(int neq) override; //! Update Lagrange multipliers void PrepStep(); void Update(const std::vector<double>& Ui, const std::vector<double>& ui) override; void UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) override; //! serialization void Serialize(DumpStream& ar) override; //! return node set FENodeSet* GetNodeSet() override; private: int m_laugon; //!< Augmentation flag double m_tol; //!< augmentation tolerance double m_eps; //!< penalty factor int m_minaug; //!< minimum nr of augmentations int m_maxaug; //!< max nr of augmentations private: vector<vec3d> m_Lm, m_Lp; //!< Lagrange multipliers private: vector<int> m_eq; //!< equation nr of LM FEDofList m_dofU; //!< dof list FENodeSet m_nodeSet; //!< the node set to apply this constraint to DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEOrthotropicCLE.cpp
.cpp
8,522
248
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEOrthotropicCLE.h" #include <FECore/log.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEOrthotropicCLE, FEElasticMaterial) ADD_PARAMETER(lp11, "lp11")->setLongName("lambda_11 tensile")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(lm11, "lm11")->setLongName("lambda_11 compressive")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(lp22, "lp22")->setLongName("lambda_22 tensile")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(lm22, "lm22")->setLongName("lambda_22 compressive")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(lp33, "lp33")->setLongName("lambda_33 tensile")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(lm33, "lm33")->setLongName("lambda_33 compressive")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(l12, "l12")->setLongName("lambda_12")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(l23, "l23")->setLongName("lambda_23")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(l31, "l31")->setLongName("lambda_13")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(mu1, FE_RANGE_GREATER_OR_EQUAL(0.0), "mu1")->setLongName("mu_1")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(mu2, FE_RANGE_GREATER_OR_EQUAL(0.0), "mu2")->setLongName("mu_2")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(mu3, FE_RANGE_GREATER_OR_EQUAL(0.0), "mu3")->setLongName("mu_3")->setUnits(UNIT_PRESSURE); ADD_PROPERTY(m_Q, "mat_axis")->SetFlags(FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Check material parameters. bool FEOrthotropicCLE::Validate() { if (FEElasticMaterial::Validate() == false) return false; // Evaluate Lame coefficients double lam[3][3]; double mu[3]; mu[0] = mu1; mu[1] = mu2; mu[2] = mu3; lam[0][0] = lm11; lam[0][1] = l12 ; lam[0][2] = l31; lam[1][0] = l12 ; lam[1][1] = lm22; lam[1][2] = l23; lam[2][0] = l31 ; lam[2][1] = l23 ; lam[2][2] = lm33; // check that stiffness matrix is positive definite mat3ds c(lam[0][0]+2*mu[0],lam[1][1]+2*mu[1],lam[2][2]+2*mu[2],lam[0][1],lam[1][2],lam[0][2]); double l[3]; c.exact_eigen(l); if ((l[0] < 0) || (l[1] < 0) || (l[2] < 0)) { feLogError("Stiffness matrix is not positive definite."); return false; } // repeat check with all tensile diagonal first lamé constants lam[0][0] = lp11; lam[1][1] = lp22; lam[2][2] = lp33; // check that compliance matrix is positive definite c = mat3ds(lam[0][0]+2*mu[0],lam[1][1]+2*mu[1],lam[2][2]+2*mu[2],lam[0][1],lam[1][2],lam[0][2]); c.exact_eigen(l); if ((l[0] < 0) || (l[1] < 0) || (l[2] < 0)) { feLogError("Stiffness matrix is not positive definite."); return false; } return true; } //----------------------------------------------------------------------------- //! Calculates the stress mat3ds FEOrthotropicCLE::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // Evaluate Lame coefficients double lam[3][3]; double mu[3]; mu[0] = mu1; mu[1] = mu2; mu[2] = mu3; lam[0][0] = lm11; lam[0][1] = l12 ; lam[0][2] = l31; lam[1][0] = l12 ; lam[1][1] = lm22; lam[1][2] = l23; lam[2][0] = l31 ; lam[2][1] = l23 ; lam[2][2] = lm33; int i,j; vec3d a0; // texture direction in reference configuration mat3ds A0[3]; // texture tensor in reference configuration double AE[3]; // E:A mat3ds E = pt.Strain(); mat3d F = pt.m_F; double J = pt.m_J; // get local coordinates mat3d Q = GetLocalCS(mp); for (i=0; i<3; i++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to a0 a0.x = Q[0][i]; a0.y = Q[1][i]; a0.z = Q[2][i]; A0[i] = dyad(a0); AE[i] = a0*(E*a0); } lam[0][0] = (AE[0] >= 0) ? lp11 : lm11; lam[1][1] = (AE[1] >= 0) ? lp22 : lm22; lam[2][2] = (AE[2] >= 0) ? lp33 : lm33; mat3ds s; s.zero(); for (i=0; i<3; ++i) { s += (A0[i]*E).sym()*(mu[i]); for (j=0; j<3; ++j) { s += A0[j]*(lam[i][j]*AE[i]); } } s = (F*s*F.transpose()).sym()/J; return s; } //----------------------------------------------------------------------------- //! Calculates the elasticity tensor tens4ds FEOrthotropicCLE::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // Evaluate Lame coefficients double lam[3][3]; double mu[3]; mu[0] = mu1; mu[1] = mu2; mu[2] = mu3; lam[0][0] = lm11; lam[0][1] = l12 ; lam[0][2] = l31; lam[1][0] = l12 ; lam[1][1] = lm22; lam[1][2] = l23; lam[2][0] = l31 ; lam[2][1] = l23 ; lam[2][2] = lm33; int i,j; vec3d a0; // texture direction in reference configuration mat3ds A[3]; // texture tensor in current configuration double AE[3]; // E:A mat3ds E = pt.Strain(); mat3d F = pt.m_F; double J = pt.m_J; // get local coordinates mat3d Q = GetLocalCS(mp); for (i=0; i<3; i++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to a0 a0.x = Q[0][i]; a0.y = Q[1][i]; a0.z = Q[2][i]; A[i] = dyad(F*a0); AE[i] = a0*(E*a0); } lam[0][0] = (AE[0] >= 0) ? lp11 : lm11; lam[1][1] = (AE[1] >= 0) ? lp22 : lm22; lam[2][2] = (AE[2] >= 0) ? lp33 : lm33; tens4ds c; c.zero(); mat3ds B = pt.LeftCauchyGreen(); for (i=0; i<3; ++i) { c += dyad4s(A[i], B)*mu[i]; for (j=0; j<3; ++j) { c += dyad1s(A[i],A[j])*lam[i][j]/2; } } c /= J; return c; } //----------------------------------------------------------------------------- //! Calculates the strain energy density double FEOrthotropicCLE::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // Evaluate Lame coefficients double lam[3][3]; double mu[3]; mu[0] = mu1; mu[1] = mu2; mu[2] = mu3; lam[0][0] = lm11; lam[0][1] = l12 ; lam[0][2] = l31; lam[1][0] = l12 ; lam[1][1] = lm22; lam[1][2] = l23; lam[2][0] = l31 ; lam[2][1] = l23 ; lam[2][2] = lm33; int i,j; vec3d a0; // texture direction in reference configuration mat3ds A0; // texture tensor in reference configuration double AE[3], AE2[3]; // Ka mat3ds E = pt.Strain(); // get local coordinates mat3d Q = GetLocalCS(mp); for (i=0; i<3; i++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to a0 a0.x = Q[0][i]; a0.y = Q[1][i]; a0.z = Q[2][i]; A0 = dyad(a0); AE[i] = a0*(E*a0); AE2[i] = a0*(E*E*a0); } lam[0][0] = (AE[0] >= 0) ? lp11 : lm11; lam[1][1] = (AE[1] >= 0) ? lp22 : lm22; lam[2][2] = (AE[2] >= 0) ? lp33 : lm33; double W = 0; for (i=0; i<3; ++i) { W += AE2[i]*mu[i]; for (j=0; j<3; ++j) { W += AE[i]*AE[j]*lam[i][j]/2; } } return W; }
C++
3D
febiosoftware/FEBio
FEBioMech/FERigidFollowerForce.cpp
.cpp
5,667
162
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FERigidFollowerForce.h" #include "FERigidBody.h" #include "FECore/FEAnalysis.h" #include "FECore/FEMaterial.h" #include "FECore/FELoadCurve.h" #include "FEMechModel.h" #include "FERigidMaterial.h" #include <FECore/FELinearSystem.h> //============================================================================= BEGIN_FECORE_CLASS(FERigidFollowerForce, FERigidLoad); ADD_PARAMETER(m_rid , "rb" )->setEnums("$(rigid_materials)"); ADD_PARAMETER(m_X , "insertion"); ADD_PARAMETER(m_f , "force" ); ADD_PARAMETER(m_brelative, "relative" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FERigidFollowerForce::FERigidFollowerForce(FEModel* pfem) : FERigidLoad(pfem) { m_rid = -1; m_X = m_f = vec3d(0,0,0); m_brelative = false; } //----------------------------------------------------------------------------- //! do some sanity checks bool FERigidFollowerForce::Init() { // At this point the rigid ID's are still associated with the materials. // We want to associate them with the rigid objects instead. FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel()); FERigidMaterial* pm = dynamic_cast<FERigidMaterial*>(fem.GetMaterial(m_rid-1)); if (pm == 0) return false; m_rid = pm->GetRigidBodyID(); if (m_rid < 0) return false; // all is well in the world return true; } //----------------------------------------------------------------------------- void FERigidFollowerForce::Serialize(DumpStream& ar) { FEModelLoad::Serialize(ar); ar & m_rid; ar & m_X & m_f; ar & m_brelative; } //----------------------------------------------------------------------------- //! Residual void FERigidFollowerForce::LoadVector(FEGlobalVector& R) { FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel()); FERigidBody& body = *fem.GetRigidBody(m_rid); const FETimeInfo& tp = fem.GetTime(); double alpha = tp.alphaf; // get the attachment position in global coordinates for body A vec3d Z = (m_brelative ? m_X : m_X - body.m_r0); vec3d zt = body.GetRotation()*Z; vec3d zp = body.GetPreviousRotation()*Z; vec3d z = zt*alpha + zp*(1-alpha); // calculate the force value vec3d ft = body.GetRotation()*m_f; vec3d fp = body.GetPreviousRotation()*m_f; vec3d f = ft*alpha + fp*(1-alpha); // get the moment about the center of mass vec3d m = z ^ f; // apply force and moment to body int n; n = body.m_LM[0]; if (n >= 0) R[n] += f.x; n = body.m_LM[1]; if (n >= 0) R[n] += f.y; n = body.m_LM[2]; if (n >= 0) R[n] += f.z; n = body.m_LM[3]; if (n >= 0) R[n] += m.x; n = body.m_LM[4]; if (n >= 0) R[n] += m.y; n = body.m_LM[5]; if (n >= 0) R[n] += m.z; body.m_Fr += f; body.m_Mr += m; } //----------------------------------------------------------------------------- //! Stiffness matrix //! TODO: Only the stiffness contribution in the were the axial forces are applied //! to the center of mass has been implemented. void FERigidFollowerForce::StiffnessMatrix(FELinearSystem& LS) { FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel()); FERigidBody& body = *fem.GetRigidBody(m_rid); const FETimeInfo& tp = fem.GetTime(); double alpha = tp.alphaf; // get the attachment position in global coordinates for body A vec3d Z = (m_brelative ? m_X : m_X - body.m_r0); vec3d zt = body.GetRotation()*Z; vec3d zp = body.GetPreviousRotation()*Z; vec3d z = zt*alpha + zp*(1-alpha); // calculate the force value vec3d ft = body.GetRotation()*m_f; vec3d fp = body.GetPreviousRotation()*m_f; vec3d f = ft*alpha + fp*(1-alpha); // build the stiffness matrix components mat3da fthat(ft); mat3da zthat(zt); mat3da fhat(f); mat3da zhat(z); mat3d Krq = fthat*(-alpha); mat3d Kqq = (fhat*zthat - zhat*fthat)*alpha; // put it all together FEElementMatrix K; K.resize(6, 6); K.zero(); K.sub(0,3, Krq); K.sub(3,3, Kqq); // get the equation numbers vector<int> lm(6); lm[ 0] = body.m_LM[0]; lm[ 1] = body.m_LM[1]; lm[ 2] = body.m_LM[2]; lm[ 3] = body.m_LM[3]; lm[ 4] = body.m_LM[4]; lm[ 5] = body.m_LM[5]; // assemble into global matrix K.SetIndices(lm); LS.Assemble(K); }
C++
3D
febiosoftware/FEBio
FEBioMech/FEElasticMixture.cpp
.cpp
10,288
316
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEElasticMixture.h" #include <FECore/FECoreKernel.h> #include <FECore/log.h> //----------------------------------------------------------------------------- FEElasticMixtureMaterialPoint::FEElasticMixtureMaterialPoint() : FEMaterialPointArray(new FEElasticMaterialPoint) { } //----------------------------------------------------------------------------- FEMaterialPointData* FEElasticMixtureMaterialPoint::Copy() { FEElasticMixtureMaterialPoint* pt = new FEElasticMixtureMaterialPoint; pt->m_w = m_w; pt->m_mp = m_mp; if (m_pNext) pt->m_pNext = m_pNext->Copy(); return pt; } //----------------------------------------------------------------------------- void FEElasticMixtureMaterialPoint::Init() { // allocate weight array m_w.resize(Components(), 1.0); // don't forget to initialize the base class FEMaterialPointArray::Init(); } //----------------------------------------------------------------------------- void FEElasticMixtureMaterialPoint::Serialize(DumpStream& ar) { FEMaterialPointArray::Serialize(ar); ar & m_w; } //============================================================================= // FEElasticMixture //============================================================================= BEGIN_FECORE_CLASS(FEElasticMixture, FEElasticMaterial) ADD_PROPERTY(m_pMat, "solid"); ADD_PROPERTY(m_Q, "mat_axis")->SetFlags(FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEElasticMixture::FEElasticMixture(FEModel* pfem) : FEElasticMaterial(pfem) { } //----------------------------------------------------------------------------- FEMaterialPointData* FEElasticMixture::CreateMaterialPointData() { FEElasticMixtureMaterialPoint* pt = new FEElasticMixtureMaterialPoint(); int NMAT = Materials(); for (int i=0; i<NMAT; ++i) { FEMaterialPointData* mpi = m_pMat[i]->CreateMaterialPointData(); mpi->SetPrev(pt); FEMaterialPoint* pi = new FEMaterialPoint(mpi); pt->AddMaterialPoint(pi); } return pt; } //----------------------------------------------------------------------------- void FEElasticMixture::AddMaterial(FEElasticMaterial* pm) { m_pMat.push_back(pm); } //----------------------------------------------------------------------------- //! data initialization bool FEElasticMixture::Init() { // check if any of the solid materials are elastic mixtures -- none allowed, // otherwise FEBio does not know which FEElasticMixtureMaterialPoint to access int nmix = 0; for (int i=0; i<Materials(); ++i) if (dynamic_cast<FEElasticMixture*>(m_pMat[i])) nmix++; if (nmix > 0) { feLogError("Solids in solid mixture material cannot be solid mixtures"); return false; } return FEElasticMaterial::Init(); } //----------------------------------------------------------------------------- //! This function evaluates the stress at the material point by evaluating the //! individual stress components. mat3ds FEElasticMixture::Stress(FEMaterialPoint& mp) { FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); vector<double>& w = pt.m_w; assert(w.size() == m_pMat.size()); // get the elastic material point FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate stress mat3ds s; s.zero(); for (int i=0; i < (int) m_pMat.size(); ++i) { FEMaterialPoint& mpi = *pt.GetPointData(i); mpi.m_elem = mp.m_elem; mpi.m_index = mp.m_index; mpi.m_rt = mp.m_rt; mpi.m_r0 = mp.m_r0; // copy the elastic material point data to the components FEElasticMaterialPoint& epi = *mpi.ExtractData<FEElasticMaterialPoint>(); epi.m_F = ep.m_F; epi.m_J = ep.m_J; epi.m_v = ep.m_v; epi.m_a = ep.m_a; epi.m_L = ep.m_L; s += epi.m_s = m_pMat[i]->Stress(mpi)*w[i]; } return s; } //----------------------------------------------------------------------------- tens4ds FEElasticMixture::Tangent(FEMaterialPoint& mp) { FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); vector<double>& w = pt.m_w; assert(w.size() == m_pMat.size()); // get the elastic material point FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate elasticity tensor tens4ds c(0.); for (int i=0; i < (int) m_pMat.size(); ++i) { FEMaterialPoint& mpi = *pt.GetPointData(i); mpi.m_elem = mp.m_elem; mpi.m_index = mp.m_index; mpi.m_rt = mp.m_rt; mpi.m_r0 = mp.m_r0; // copy the elastic material point data to the components FEElasticMaterialPoint& epi = *mpi.ExtractData<FEElasticMaterialPoint>(); epi.m_F = ep.m_F; epi.m_J = ep.m_J; epi.m_v = ep.m_v; epi.m_a = ep.m_a; epi.m_L = ep.m_L; c += m_pMat[i]->Tangent(mpi)*w[i]; } return c; } //----------------------------------------------------------------------------- //! This function evaluates the stress at the material point by evaluating the //! individual stress components. double FEElasticMixture::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); vector<double>& w = pt.m_w; assert(w.size() == m_pMat.size()); // get the elastic material point FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate strain energy density double sed = 0.0; for (int i=0; i < (int) m_pMat.size(); ++i) { FEMaterialPoint& mpi = *pt.GetPointData(i); mpi.m_elem = mp.m_elem; mpi.m_index = mp.m_index; mpi.m_rt = mp.m_rt; mpi.m_r0 = mp.m_r0; // copy the elastic material point data to the components FEElasticMaterialPoint& epi = *mpi.ExtractData<FEElasticMaterialPoint>(); epi.m_F = ep.m_F; epi.m_J = ep.m_J; epi.m_v = ep.m_v; epi.m_a = ep.m_a; epi.m_L = ep.m_L; sed += m_pMat[i]->StrainEnergyDensity(mpi)*w[i]; } return sed; } //----------------------------------------------------------------------------- //! This function evaluates the stress at the material point by evaluating the //! individual stress components. double FEElasticMixture::StrongBondSED(FEMaterialPoint& mp) { FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); vector<double>& w = pt.m_w; assert(w.size() == m_pMat.size()); // get the elastic material point FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate strain energy density double sed = 0.0; for (int i=0; i < (int) m_pMat.size(); ++i) { FEMaterialPoint& mpi = *pt.GetPointData(i); mpi.m_elem = mp.m_elem; mpi.m_index = mp.m_index; mpi.m_rt = mp.m_rt; mpi.m_r0 = mp.m_r0; // copy the elastic material point data to the components FEElasticMaterialPoint& epi = *mpi.ExtractData<FEElasticMaterialPoint>(); epi.m_F = ep.m_F; epi.m_J = ep.m_J; epi.m_v = ep.m_v; epi.m_a = ep.m_a; epi.m_L = ep.m_L; sed += m_pMat[i]->StrongBondSED(mpi)*w[i]; } return sed; } //----------------------------------------------------------------------------- //! This function evaluates the stress at the material point by evaluating the //! individual stress components. double FEElasticMixture::WeakBondSED(FEMaterialPoint& mp) { FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); vector<double>& w = pt.m_w; assert(w.size() == m_pMat.size()); // get the elastic material point FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate strain energy density double sed = 0.0; for (int i=0; i < (int) m_pMat.size(); ++i) { FEMaterialPoint& mpi = *pt.GetPointData(i); mpi.m_elem = mp.m_elem; mpi.m_index = mp.m_index; mpi.m_rt = mp.m_rt; mpi.m_r0 = mp.m_r0; // copy the elastic material point data to the components FEElasticMaterialPoint& epi = *mpi.ExtractData<FEElasticMaterialPoint>(); epi.m_F = ep.m_F; epi.m_J = ep.m_J; epi.m_v = ep.m_v; epi.m_a = ep.m_a; epi.m_L = ep.m_L; sed += m_pMat[i]->WeakBondSED(mpi)*w[i]; } return sed; } //----------------------------------------------------------------------------- //! specialized material points void FEElasticMixture::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); for (int i=0; i < (int) m_pMat.size(); ++i) { FEMaterialPoint& mpi = *pt.GetPointData(i); mpi.m_elem = mp.m_elem; mpi.m_index = mp.m_index; mpi.m_rt = mp.m_rt; mpi.m_r0 = mp.m_r0; FEElasticMaterialPoint& epi = *mpi.ExtractData<FEElasticMaterialPoint>(); FEMaterial* pmj = GetMaterial(i); pmj->UpdateSpecializedMaterialPoints(mpi, tp); } }
C++
3D
febiosoftware/FEBio
FEBioMech/FEElasticFiberMaterial.cpp
.cpp
2,942
86
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEElasticFiberMaterial.h" #include "FEFiberMaterialPoint.h" #include <FECore/FEConstValueVec3.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEElasticFiberMaterial, FEElasticMaterial) ADD_PROPERTY(m_fiber, "fiber"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMaterialPointData* FEElasticFiberMaterial::CreateMaterialPointData() { FEFiberMaterialPoint* mp = new FEFiberMaterialPoint(new FEElasticMaterialPoint); return mp; } //----------------------------------------------------------------------------- FEElasticFiberMaterial::FEElasticFiberMaterial(FEModel* pfem) : FEElasticMaterial(pfem) { m_fiber = nullptr; m_Us = mat3dd(1); m_bUs = false; } //----------------------------------------------------------------------------- // get the fiber vector (in global coordinates) vec3d FEElasticFiberMaterial::FiberVector(FEMaterialPoint& mp) { // get the material coordinate system mat3d Q = GetLocalCS(mp); // get local fiber direction vec3d fiber = m_fiber->unitVector(mp); // convert to global coordinates vec3d a0 = Q*fiber; // account for prior deformation in multigenerational formulation vec3d a = FiberPreStretch(a0); return a; } //----------------------------------------------------------------------------- vec3d FEElasticFiberMaterial::FiberPreStretch(const vec3d a0) { // account for prior deformation in multigenerational formulation if (m_bUs) { vec3d a = (m_Us*a0); a.unit(); return a; } else return a0; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEIsotropicLeeSacksUncoupled.cpp
.cpp
4,241
126
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEIsotropicLeeSacksUncoupled.h" // define the material parameters BEGIN_FECORE_CLASS(FEIsotropicLeeSacksUncoupled, FEUncoupledMaterial) ADD_PARAMETER(m_c0, "c0")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c1, "c1")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c2, "c2")->setUnits(UNIT_NONE); ADD_PARAMETER(m_tangent_scale, "tangent_scale"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEIsotropicLeeSacksUncoupled::FEIsotropicLeeSacksUncoupled(FEModel* pfem) : FEUncoupledMaterial(pfem) { m_c0 = 0.0; m_c1 = 0.0; m_c2 = 0.0; m_tangent_scale = 1.0; } //----------------------------------------------------------------------------- //! Calculates the strain energy density double FEIsotropicLeeSacksUncoupled::DevStrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate left Cauchy-Green tensor and invariants mat3ds b = pt.DevLeftCauchyGreen(); double I1 = b.tr(); // Evaluate exp(Q) double Q = m_c2 * (I1 - 3.0) * (I1 - 3.0); double eQ = exp(Q); // Evaluate the strain energy density double sed = 0.5*m_c0*(I1 - 3.0) + 0.5*m_c1*(eQ - 1.0); return sed; } //----------------------------------------------------------------------------- //! Calculates the deviatoric stress mat3ds FEIsotropicLeeSacksUncoupled::DevStress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // calculate left Cauchy-Green tensor and invariants mat3ds b = pt.DevLeftCauchyGreen(); double I1 = b.tr(); double J = pt.m_J; // Evaluate exp(Q) double Q = m_c2 * (I1 - 3.0) * (I1 - 3.0); double eQ = exp(Q); // evaluate deviatoric stress mat3ds T = b * (m_c0 + 2.0 * m_c1 * m_c2 * (I1 - 3) * eQ); mat3ds s = T.dev() / J; return s; } //----------------------------------------------------------------------------- //! Calculates the deviatoric tangent tens4ds FEIsotropicLeeSacksUncoupled::DevTangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // apply tangent scale double c0 = m_c0 * m_tangent_scale; // calculate left Cauchy-Green tensor and invariants mat3ds b = pt.DevLeftCauchyGreen(); double I1 = b.tr(); double J = pt.m_J; // Evaluate exp(Q) double Q = m_c2 * (I1 - 3.0) * (I1 - 3.0); double eQ = exp(Q); double g = 4.0 * m_c1 * m_c2 * eQ * (1.0 + 2.0 * m_c2 * (I1 - 3.0) * (I1 - 3.0)); // we'll need these tensors mat3dd I(1.0); tens4ds IoI = dyad4s(I); tens4ds IxI = dyad1s(I); tens4ds bxb = dyad1s(b); // evaluate stress tensor T = F*S*F^t mat3ds T = b * (c0 + 2.0 * m_c1 * m_c2 * (I1 - 3) * eQ); // evaluate tangents tens4ds cT = (IoI - IxI / 3.0) * (2.0 * T.tr() / 3.0) - dyad1s(T.dev(), I)*(2.0/3.0); tens4ds cw = bxb * g; mat3ds chat = b * (g * I1); double cbar = g * I1 * I1; tens4ds c = cT + cw - dyad1s(chat, I) / 3.0 + IxI*(cbar / 9.0); return c / J; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEIsotropicLeeSacksUncoupled.h
.h
1,906
52
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEUncoupledMaterial.h" class FEIsotropicLeeSacksUncoupled : public FEUncoupledMaterial { public: FEIsotropicLeeSacksUncoupled(FEModel* pfem); //! calculate deviatoric stress at material point mat3ds DevStress(FEMaterialPoint& pt) override; //! calculate deviatoric tangent stiffness at material point tens4ds DevTangent(FEMaterialPoint& pt) override; //! calculate strain energy density at material point double DevStrainEnergyDensity(FEMaterialPoint& pt) override; public: double m_c0; double m_c1; double m_c2; double m_tangent_scale; // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEScaledElasticMaterial.cpp
.cpp
2,794
74
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2022 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "FEScaledElasticMaterial.h" // define the material parameters BEGIN_FECORE_CLASS(FEScaledElasticMaterial, FEElasticMaterial) ADD_PROPERTY(m_pBase, "solid"); ADD_PARAMETER(m_scale, FE_RANGE_CLOSED(0,1), "scale"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! stress function mat3ds FEScaledElasticMaterial::Stress(FEMaterialPoint& pt) { // get the elastic material point data FEElasticMaterialPoint& mp = *pt.ExtractData<FEElasticMaterialPoint>(); double scale = m_scale(pt); return m_pBase->Stress(pt)*scale; } //----------------------------------------------------------------------------- //! tangent function tens4ds FEScaledElasticMaterial::Tangent(FEMaterialPoint& pt) { // get the elastic material point data FEElasticMaterialPoint& mp = *pt.ExtractData<FEElasticMaterialPoint>(); double scale = m_scale(pt); return m_pBase->Tangent(pt)*scale; } //----------------------------------------------------------------------------- //! strain energy density function double FEScaledElasticMaterial::StrainEnergyDensity(FEMaterialPoint& pt) { // get the elastic material point data FEElasticMaterialPoint& mp = *pt.ExtractData<FEElasticMaterialPoint>(); double scale = m_scale(pt); return m_pBase->StrainEnergyDensity(pt)*scale; } FEMaterialPointData* FEScaledElasticMaterial::CreateMaterialPointData() { return m_pBase->CreateMaterialPointData(); }
C++
3D
febiosoftware/FEBio
FEBioMech/FESphericalFiberDistribution.cpp
.cpp
11,514
461
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FESphericalFiberDistribution.h" // The following file contains the integration points and weights // for the integration over a unit sphere in spherical coordinates #include "geodesic.h" #ifndef SQR #define SQR(x) ((x)*(x)) #endif // define the material parameters BEGIN_FECORE_CLASS(FESphericalFiberDistribution, FEElasticMaterial) ADD_PARAMETER(m_alpha, FE_RANGE_GREATER_OR_EQUAL(0.0), "alpha"); ADD_PARAMETER(m_beta , FE_RANGE_GREATER_OR_EQUAL(2.0), "beta" ); ADD_PARAMETER(m_ksi , FE_RANGE_GREATER_OR_EQUAL(0.0), "ksi" ); ADD_PROPERTY(m_Q, "mat_axis")->SetFlags(FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- // FESphericalFiberDistribution //----------------------------------------------------------------------------- FESphericalFiberDistribution::FESphericalFiberDistribution(FEModel* pfem) : FEElasticMaterial(pfem) { } //----------------------------------------------------------------------------- mat3ds FESphericalFiberDistribution::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; // get local coordinates mat3d Q = GetLocalCS(mp); // loop over all integration points vec3d n0e, n0a, n0q, nt; double In, Wl; const double eps = 0; mat3ds s; s.zero(); const int nint = 45; for (int n=0; n<nint; ++n) { // set the global fiber direction in material coordinate system n0a.x = XYZ2[n][0]; n0a.y = XYZ2[n][1]; n0a.z = XYZ2[n][2]; double wn = XYZ2[n][3]; // calculate material coefficients double ksi = m_ksi(mp); double alpha = m_alpha(mp); double beta = m_beta(mp); // --- quadrant 1,1,1 --- // rotate to reference configuration n0e = Q*n0a; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy derivative Wl = beta*ksi*pow(In - 1.0, beta-1.0)*exp(alpha*pow(In - 1.0, beta)); // calculate the stress s += dyad(nt)*(Wl*wn); } // --- quadrant -1,1,1 --- n0q = vec3d(-n0a.x, n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy derivative Wl = beta*ksi*pow(In - 1.0, beta-1.0)*exp(alpha*pow(In - 1.0, beta)); // calculate the stress s += dyad(nt)*(Wl*wn); } // --- quadrant -1,-1,1 --- n0q = vec3d(-n0a.x, -n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy derivative Wl = beta*ksi*pow(In - 1.0, beta-1.0)*exp(alpha*pow(In - 1.0, beta)); // calculate the stress s += dyad(nt)*(Wl*wn); } // --- quadrant 1,-1,1 --- n0q = vec3d(n0a.x, -n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy derivative Wl = beta*ksi*pow(In - 1.0, beta-1.0)*exp(alpha*pow(In - 1.0, beta)); // calculate the stress s += dyad(nt)*(Wl*wn); } } // we multiply by two to add contribution from other half-sphere return s*(4.0/J); } //----------------------------------------------------------------------------- tens4ds FESphericalFiberDistribution::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; // get local coordinates mat3d Q = GetLocalCS(mp); // loop over all integration points vec3d n0e, n0a, n0q, nt; double In, Wll; const double eps = 0; tens4ds cf, cfw; cf.zero(); mat3ds N2; tens4ds N4; tens4ds c; c.zero(); const int nint = 45; for (int n=0; n<nint; ++n) { // set the global fiber direction in material coordinate system n0a.x = XYZ2[n][0]; n0a.y = XYZ2[n][1]; n0a.z = XYZ2[n][2]; double wn = XYZ2[n][3]; // calculate material coefficients double ksi = m_ksi(mp); double alpha = m_alpha(mp); double beta = m_beta(mp); // --- quadrant 1,1,1 --- // rotate to reference configuration n0e = Q*n0a; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy derivative double pIn = alpha*pow(In - 1.0,beta); Wll = beta*ksi*pow(In - 1.0, beta-2.0)*(beta*pIn+beta-1.0)*exp(pIn); N2 = dyad(nt); N4 = dyad1s(N2); c += N4*(Wll*wn); } // --- quadrant -1,1,1 --- n0q = vec3d(-n0a.x, n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy derivative double pIn = alpha*pow(In - 1.0,beta); Wll = beta*ksi*pow(In - 1.0, beta-2.0)*(beta*pIn+beta-1.0)*exp(pIn); N2 = dyad(nt); N4 = dyad1s(N2); c += N4*(Wll*wn); } // --- quadrant -1,-1,1 --- n0q = vec3d(-n0a.x, -n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy derivative double pIn = alpha*pow(In - 1.0,beta); Wll = beta*ksi*pow(In - 1.0, beta-2.0)*(beta*pIn+beta-1.0)*exp(pIn); N2 = dyad(nt); N4 = dyad1s(N2); c += N4*(Wll*wn); } // --- quadrant 1,-1,1 --- n0q = vec3d(n0a.x, -n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy derivative double pIn = alpha*pow(In - 1.0,beta); Wll = beta*ksi*pow(In - 1.0, beta-2.0)*(beta*pIn+beta-1.0)*exp(pIn); N2 = dyad(nt); N4 = dyad1s(N2); c += N4*(Wll*wn); } } // multiply by two to integrate over other half of sphere return c*(2.0*4.0/J); } //----------------------------------------------------------------------------- double FESphericalFiberDistribution::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; // get local coordinates mat3d Q = GetLocalCS(mp); // loop over all integration points vec3d n0e, n0a, n0q, nt; double In, W; const double eps = 0; double sed = 0.0; const int nint = 45; for (int n=0; n<nint; ++n) { // set the global fiber direction in material coordinate system n0a.x = XYZ2[n][0]; n0a.y = XYZ2[n][1]; n0a.z = XYZ2[n][2]; double wn = XYZ2[n][3]; // calculate material coefficients double ksi = m_ksi(mp); double alpha = m_alpha(mp); double beta = m_beta(mp); // --- quadrant 1,1,1 --- // rotate to reference configuration n0e = Q*n0a; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy density if (alpha > 0) W = ksi/alpha*(exp(alpha*pow(In - 1.0, beta))-1); else W = ksi*pow(In - 1.0, beta); // add to total sed sed += W*wn; } // --- quadrant -1,1,1 --- n0q = vec3d(-n0a.x, n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy density if (alpha > 0) W = ksi/alpha*(exp(alpha*pow(In - 1.0, beta))-1); else W = ksi*pow(In - 1.0, beta); // add to total sed sed += W*wn; } // --- quadrant -1,-1,1 --- n0q = vec3d(-n0a.x, -n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy density if (alpha > 0) W = ksi/alpha*(exp(alpha*pow(In - 1.0, beta))-1); else W = ksi*pow(In - 1.0, beta); // add to total sed sed += W*wn; } // --- quadrant 1,-1,1 --- n0q = vec3d(n0a.x, -n0a.y, n0a.z); // rotate to reference configuration n0e = Q*n0q; // get the global spatial fiber direction in current configuration nt = F*n0e; // Calculate In = n0e*C*n0e In = nt*nt; // only take fibers in tension into consideration if (In > 1. + eps) { // calculate strain energy density if (alpha > 0) W = ksi/alpha*(exp(alpha*pow(In - 1.0, beta))-1); else W = ksi*pow(In - 1.0, beta); // add to total sed sed += W*wn; } } // we multiply by two to add contribution from other half-sphere return sed*2.0; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEUT4Domain.h
.h
4,676
149
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECore/FENodeElemList.h" #include "FECore/tens4d.h" #include "FEElasticMaterial.h" #include "FEElasticSolidDomain.h" //----------------------------------------------------------------------------- //! Domain for nodally integrated tet elements //! This class implements the uniform nodal strain tetrahedron with //! isochoric stabilization as described by Gee, Dohrmann, Key and Wall (2009) //! class FEBIOMECH_API FEUT4Domain : public FEElasticSolidDomain { public: struct UT4NODE { int inode; // index of FE node double Vi; // reference nodal volume double vi; // current nodal volume mat3d Fi; // average deformation gradient mat3ds si; // nodal stress void Serialize(DumpStream& ar); }; public: //! constructor FEUT4Domain(FEModel* pfem); //! destructor ~FEUT4Domain(); //! data serialization void Serialize(DumpStream& ar) override; //! get nodal data int UT4Nodes() { return (int) m_NODE.size(); } UT4NODE& UT4Node(int i) { return m_NODE[i]; } //! return the node-element list for this domain FENodeElemList& GetNodeElemList() { return m_NEL; } //! initialization function bool Init() override; //! build the matrix profile void BuildMatrixProfile(FEGlobalMatrix& M) override; //! Set UT4 parameters void SetUT4Parameters(double alpha, bool bdev); //! override Create so we can grab the ut4 parameters bool Create(int nelems, FE_Element_Spec espec) override; public: // overrides from FEElasticDomain //! Update domain data void Update(const FETimeInfo& tp) override; //! calculates the internal force vector void InternalForces(FEGlobalVector& R) override; //! calculates the global stiffness matrix for this domain void StiffnessMatrix(FELinearSystem& LS) override; protected: //! calculates the nodal internal forces void NodalInternalForces(FEGlobalVector& R); //! calculates the element internal forces void ElementInternalForces(FEGlobalVector& R); //! Calculates the internal stress vector for solid elements void ElementInternalForces(FESolidElement& el, vector<double>& fe); protected: //! Calculates the element stiffness matrix void ElementalStiffnessMatrix(FELinearSystem& LS); //! calculates the solid element stiffness matrix void ElementStiffness(const FETimeInfo& tp, int iel, matrix& ke) override; //! Calculates the nodal stiffness matrix void NodalStiffnessMatrix(FELinearSystem& LS); //! geometrical stiffness (i.e. initial stress) void ElementGeometricalStiffness(FESolidElement& el, matrix& ke) override; //! material stiffness component void ElementMaterialStiffness(FESolidElement& el, matrix& ke) override; //! nodal geometry stiffness contribution void NodalGeometryStiffness(UT4NODE& node, matrix& ke); //! nodal material stiffness contribution void NodalMaterialStiffness(UT4NODE& node, matrix& ke, FESolidMaterial* pme); protected: //! calculate the volume of a tet element double TetVolume(vec3d* r); tens4ds Cvol(const tens4ds& C, const mat3ds& S); double m_alpha; //!< stabilization factor alpha bool m_bdev; //!< use deviatoric components only for the element contribution private: vector<int> m_tag; //!< nodal tags vector<UT4NODE> m_NODE; //!< Nodal data vector<double> m_Ve0; //!< initial element volumes double (*m_Be)[6][3]; double (*m_DB)[6][3]; double (*m_Ge)[4][3]; FENodeElemList m_NEL; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FERigidRevoluteJoint.h
.h
4,628
128
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECore/vec3d.h" #include "FERigidConnector.h" #include "febiomech_api.h" //----------------------------------------------------------------------------- //! The FERigidRevoluteJoint class implements a revolute joint. The rigid joint //! allows the user to connect two rigid bodies at a point in space //! and allow rotation about a single prescribed axis. class FEBIOMECH_API FERigidRevoluteJoint : public FERigidConnector { public: //! constructor FERigidRevoluteJoint(FEModel* pfem); //! destructor ~FERigidRevoluteJoint(); //! initialization bool Init() override; //! calculates the joint forces void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! calculates the joint stiffness void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! calculate Lagrangian augmentation bool Augment(int naug, const FETimeInfo& tp) override; //! serialize data to archive void Serialize(DumpStream& ar) override; //! update state void Update() override; //! Reset data void Reset() override; //! evaluate relative translation vec3d RelativeTranslation(const bool global = false) override; //! evaluate relative rotation vec3d RelativeRotation(const bool global = false) override; //! initial position vec3d InitialPosition() const; //! current position vec3d Position() const; //! current axis quatd Orientation() const; private: // lag. mult. methods int InitEquations(int neq) override; void BuildMatrixProfile(FEGlobalMatrix& M) override; void UnpackLM(vector<int>& lm); void PrepStep(); void Update(const std::vector<double>& Ui, const std::vector<double>& ui) override; void UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) override; public: // parameters int m_laugon; double m_atol; //! augmented Lagrangian tolerance double m_gtol; //! augmented Lagrangian gap tolerance double m_qtol; //! augmented Lagrangian angular gap tolerance int m_naugmin; //! minimum number of augmentations int m_naugmax; //! maximum number of augmentations double m_eps; //! penalty factor for constraining force double m_ups; //! penalty factor for constraining moment double m_cps; //! linear damping coefficient for constraining force double m_rps; //! angular damping coefficient for constraining moment vec3d m_q0; //! initial position of joint double m_qp; //! prescribed rotation bool m_bq; //! flag for prescribing rotation double m_Mp; //! prescribed moment bool m_bautopen; //!< auto-penalty for gap and ang tolerance double m_torsion_stiffness = 0.0; //!< torsional stiffness about the joint axis protected: vec3d m_qa0; //! initial relative position vector of joint w.r.t. A vec3d m_qb0; //! initial relative position vector of joint w.r.t. B vec3d m_e0[3]; //! initial joint basis vec3d m_ea0[3]; //! initial joint basis w.r.t. A vec3d m_eb0[3]; //! initial joint basis w.r.t. B vec3d m_L; //! Lagrange multiplier for constraining force vec3d m_U; //! Lagrange multiplier for constraining moment vec3d m_Fp, m_Up; vector<int> m_LM; // Lagrange multiplier equation numbers DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEPeriodicBoundary.cpp
.cpp
19,003
788
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEPeriodicBoundary.h" #include <FECore/FEMesh.h> #include <FECore/FENormalProjection.h> #include <FECore/FELinearSystem.h> #include <FECore/log.h> FEPeriodicSurface::Data::Data() { m_gap = vec3d(0, 0, 0); m_rs = vec2d(0, 0); m_Lm = vec3d(0, 0, 0); m_Tn = vec3d(0, 0, 0); m_Fr = vec3d(0, 0, 0); } void FEPeriodicSurface::Data::Init() { FEContactMaterialPoint::Init(); m_gap = vec3d(0, 0, 0); m_rs = vec2d(0, 0); m_Lm = vec3d(0, 0, 0); m_Tn = vec3d(0, 0, 0); m_Fr = vec3d(0, 0, 0); } void FEPeriodicSurface::Data::Serialize(DumpStream& ar) { FEContactMaterialPoint::Serialize(ar); ar & m_gap; ar & m_rs; ar & m_Lm; ar & m_Tn; ar & m_Fr; } //----------------------------------------------------------------------------- // Define sliding interface parameters BEGIN_FECORE_CLASS(FEPeriodicBoundary, FEContactInterface) ADD_PARAMETER(m_laugon , "laugon")->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0"); ADD_PARAMETER(m_atol , "tolerance"); ADD_PARAMETER(m_eps , "penalty" ); ADD_PARAMETER(m_btwo_pass, "two_pass" ); ADD_PARAMETER(m_off , "offset" ); ADD_PARAMETER(m_naugmin , "minaug" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Creates a surface for use with a sliding interface. All surface data //! structures are allocated. //! Note that it is assumed that the element array is already created //! and initialized. bool FEPeriodicSurface::Init() { // always intialize base class first! if (FEContactSurface::Init() == false) return false; // get the number of nodes int nn = Nodes(); // allocate other surface data m_data.resize(nn); return true; } //----------------------------------------------------------------------------- void FEPeriodicSurface::CopyFrom(FEPeriodicSurface& s) { m_Node = s.m_Node; int NE = s.Elements(); Create(NE); for (int i=0; i<NE; ++i) Element(i) = s.Element(i); } //----------------------------------------------------------------------------- //! Calculate the center of mass for this surface //! vec3d FEPeriodicSurface::CenterOfMass() { vec3d c(0,0,0); int N = Nodes(); for (int i=0; i<N; ++i) c += Node(i).m_r0; if (N != 0) c /= (double) N; return c; } //----------------------------------------------------------------------------- void FEPeriodicSurface::Serialize(DumpStream& ar) { FEContactSurface::Serialize(ar); ar & m_data; } //----------------------------------------------------------------------------- void FEPeriodicSurface::GetContactTraction(int nface, vec3d& pt) { FESurfaceElement& el = Element(nface); int ne = el.Nodes(); pt = vec3d(0,0,0); for (int k=0; k<ne; ++k) pt += m_data[el.m_lnode[k]].m_Tn; pt /= ne; } //----------------------------------------------------------------------------- void FEPeriodicSurface::GetNodalContactPressure(int nface, double* pg) { FESurfaceElement& el = Element(nface); int ne = el.Nodes(); for (int i=0; i<ne; ++i) { vec3d tn = m_data[el.m_lnode[i]].m_Tn; pg[i] = tn.norm(); } } //----------------------------------------------------------------------------- void FEPeriodicSurface::GetNodalContactTraction(int nface, vec3d* tn) { FESurfaceElement& el = Element(nface); int ne = el.Nodes(); for (int i=0; i<ne; ++i) { tn[i] = m_data[el.m_lnode[i]].m_Tn; } } //----------------------------------------------------------------------------- // FEPeriodicBoundary //----------------------------------------------------------------------------- FEPeriodicBoundary::FEPeriodicBoundary(FEModel* pfem) : FEContactInterface(pfem), m_ss(pfem), m_ms(pfem) { static int count = 1; SetID(count++); m_stol = 0.01; m_atol = 0; m_eps = 0; m_btwo_pass = false; m_off = vec3d(0,0,0); m_naugmin = 0; // set parents m_ss.SetContactInterface(this); m_ms.SetContactInterface(this); m_ss.SetSibling(&m_ms); m_ms.SetSibling(&m_ss); } //----------------------------------------------------------------------------- bool FEPeriodicBoundary::Init() { // create the surfaces if (m_ss.Init() == false) return false; if (m_ms.Init() == false) return false; return true; } //----------------------------------------------------------------------------- void FEPeriodicBoundary::Activate() { // don't forget to call the base class FEContactInterface::Activate(); // project primary surface onto secondary surface ProjectSurface(m_ss, m_ms, false); ProjectSurface(m_ms, m_ss, false); } //----------------------------------------------------------------------------- void FEPeriodicBoundary::CopyFrom(FESurfacePairConstraint* pci) { // cast to a periodic boundary FEPeriodicBoundary& pb = dynamic_cast<FEPeriodicBoundary&>(*pci); // copy parameters GetParameterList() = pb.GetParameterList(); // copy nodes m_ss.CopyFrom(pb.m_ss); m_ms.CopyFrom(pb.m_ms); } //----------------------------------------------------------------------------- //! build the matrix profile for use in the stiffness matrix // TODO: what if two_pass ?? void FEPeriodicBoundary::BuildMatrixProfile(FEGlobalMatrix& K) { FEModel& fem = *GetFEModel(); FEMesh& mesh = GetMesh(); // get the DOFS const int dof_X = GetDOFIndex("x"); const int dof_Y = GetDOFIndex("y"); const int dof_Z = GetDOFIndex("z"); const int dof_RU = GetDOFIndex("Ru"); const int dof_RV = GetDOFIndex("Rv"); const int dof_RW = GetDOFIndex("Rw"); vector<int> lm(6*5); for (int j=0; j<m_ss.Nodes(); ++j) { FESurfaceElement& me = *m_ss.m_data[j].m_pme; int* en = &me.m_node[0]; int n = me.Nodes(); if (n == 3) { lm[6*(3+1) ] = -1; lm[6*(3+1)+1] = -1; lm[6*(3+1)+2] = -1; lm[6*(3+1)+3] = -1; lm[6*(3+1)+4] = -1; lm[6*(3+1)+5] = -1; } lm[0] = m_ss.Node(j).m_ID[dof_X]; lm[1] = m_ss.Node(j).m_ID[dof_Y]; lm[2] = m_ss.Node(j).m_ID[dof_Z]; lm[3] = m_ss.Node(j).m_ID[dof_RU]; lm[4] = m_ss.Node(j).m_ID[dof_RV]; lm[5] = m_ss.Node(j).m_ID[dof_RW]; for (int k=0; k<n; ++k) { vector<int>& id = mesh.Node(en[k]).m_ID; lm[6*(k+1) ] = id[dof_X]; lm[6*(k+1)+1] = id[dof_Y]; lm[6*(k+1)+2] = id[dof_Z]; lm[6*(k+1)+3] = id[dof_RU]; lm[6*(k+1)+4] = id[dof_RV]; lm[6*(k+1)+5] = id[dof_RW]; } K.build_add(lm); } } //----------------------------------------------------------------------------- //! project surface void FEPeriodicBoundary::ProjectSurface(FEPeriodicSurface& ss, FEPeriodicSurface& ms, bool bmove) { int i; double rs[2]; // get the primary's center of mass vec3d cs = ss.CenterOfMass(); // get the secondary's center of mass vec3d cm = ms.CenterOfMass(); // get the relative distance vec3d cr = cs - cm; // unit vector in direction of cr // this will serve as the projection distance vec3d cn(cr); double D = cn.unit(); // initialize projection data FENormalProjection np(ms); np.SetTolerance(m_stol); np.SetSearchRadius(1.1*D); np.Init(); // loop over all primary nodes for (i=0; i<ss.Nodes(); ++i) { FENode& node = ss.Node(i); // get the nodal position vec3d r0 = node.m_r0; // find the intersection with the secondary surface ss.m_data[i].m_pme = np.Project3(r0, cn, rs); assert(ss.m_data[i].m_pme); ss.m_data[i].m_rs[0] = rs[0]; ss.m_data[i].m_rs[1] = rs[1]; } } //----------------------------------------------------------------------------- void FEPeriodicBoundary::Update() { int i, j, ne; FESurfaceElement* pme; FEMesh& mesh = *m_ss.GetMesh(); vec3d us, um; vec3d umi[FEElement::MAX_NODES]; // update gap functions int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FEPeriodicSurface& ss = (np == 0? m_ss : m_ms); FEPeriodicSurface& ms = (np == 0? m_ms : m_ss); // off-set sign double s = (np==0?1.0:-1.0); int N = ss.Nodes(); for (i=0; i<N; ++i) { // calculate the primary displacement FENode& node = ss.Node(i); us = node.m_rt - node.m_r0; // get the secondary element pme = ss.m_data[i].m_pme; // calculate the secondary displacement ne = pme->Nodes(); for (j=0; j<ne; ++j) { FENode& node = ms.Node(pme->m_lnode[j]); umi[j] = node.m_rt - node.m_r0; } um = pme->eval(umi, ss.m_data[i].m_rs[0], ss.m_data[i].m_rs[1]); // calculate gap function ss.m_data[i].m_gap = us - um + m_off*s; } } } //----------------------------------------------------------------------------- void FEPeriodicBoundary::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { int j, k, l, m, n; int nseln, nmeln; double *Gr, *Gs; // jacobian double detJ; vec3d dxr, dxs; double* w; // natural coordinates of primary node in secondary element double r, s; // contact force vec3d tc; // shape function values double N[FEElement::MAX_NODES]; // element contact force vector vector<double> fe; // the lm array for this force vector vector<int> lm; // the en array vector<int> en; vector<int> sLM; vector<int> mLM; vec3d r0[FEElement::MAX_NODES], rt[FEElement::MAX_NODES]; int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FEPeriodicSurface& ss = (np == 0? m_ss : m_ms); FEPeriodicSurface& ms = (np == 0? m_ms : m_ss); // zero reaction forces for (int i=0; i<ss.Nodes(); ++i) ss.m_data[i].m_Fr = vec3d(0,0,0); // loop over all primary facets int ne = ss.Elements(); for (j=0; j<ne; ++j) { // get the primary element FESurfaceElement& sel = ss.Element(j); // get the elements LM vector ss.UnpackLM(sel, sLM); nseln = sel.Nodes(); for (int i=0; i<nseln; ++i) { r0[i] = ss.Node(sel.m_lnode[i]).m_r0; rt[i] = ss.Node(sel.m_lnode[i]).m_rt; } w = sel.GaussWeights(); // loop over primary element nodes (which are the integration points as well) for (n=0; n<nseln; ++n) { Gr = sel.Gr(n); Gs = sel.Gs(n); m = sel.m_lnode[n]; // calculate jacobian dxr = dxs = vec3d(0,0,0); for (k=0; k<nseln; ++k) { dxr.x += Gr[k]*r0[k].x; dxr.y += Gr[k]*r0[k].y; dxr.z += Gr[k]*r0[k].z; dxs.x += Gs[k]*r0[k].x; dxs.y += Gs[k]*r0[k].y; dxs.z += Gs[k]*r0[k].z; } detJ = (dxr ^ dxs).norm(); // get primary node contact force tc = ss.m_data[m].m_Lm + ss.m_data[m].m_gap*m_eps; ss.m_data[m].m_Tn = tc; // get the secondary element FESurfaceElement& mel = *ss.m_data[m].m_pme; ms.UnpackLM(mel, mLM); nmeln = mel.Nodes(); // isoparametric coordinates of the projected primary node // onto the secondary element r = ss.m_data[m].m_rs[0]; s = ss.m_data[m].m_rs[1]; // get the secondary shape function values at this primary node if (nmeln == 4) { // quadrilateral N[0] = 0.25*(1-r)*(1-s); N[1] = 0.25*(1+r)*(1-s); N[2] = 0.25*(1+r)*(1+s); N[3] = 0.25*(1-r)*(1+s); } else if (nmeln == 3) { // triangle N[0] = 1 - r - s; N[1] = r; N[2] = s; } else { assert(false); } // calculate force vector fe.resize(3*(nmeln+1)); fe[0] = -detJ*w[n]*tc.x; fe[1] = -detJ*w[n]*tc.y; fe[2] = -detJ*w[n]*tc.z; for (l=0; l<nmeln; ++l) { fe[3*(l+1) ] = detJ*w[n]*tc.x*N[l]; fe[3*(l+1)+1] = detJ*w[n]*tc.y*N[l]; fe[3*(l+1)+2] = detJ*w[n]*tc.z*N[l]; } // fill the lm array lm.resize(3*(nmeln+1)); lm[0] = sLM[n*3 ]; lm[1] = sLM[n*3+1]; lm[2] = sLM[n*3+2]; for (l=0; l<nmeln; ++l) { lm[3*(l+1) ] = mLM[l*3 ]; lm[3*(l+1)+1] = mLM[l*3+1]; lm[3*(l+1)+2] = mLM[l*3+2]; } // fill the en array en.resize(nmeln+1); en[0] = sel.m_node[n]; for (l=0; l<nmeln; ++l) en[l+1] = mel.m_node[l]; // assemble into global force vector R.Assemble(en, lm, fe); // also store in the reaction force vector vec3d& fr = ss.m_data[m].m_Fr; fr.x += fe[0]; fr.y += fe[1]; fr.z += fe[2]; } } } } //----------------------------------------------------------------------------- void FEPeriodicBoundary::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { int j, k, l, n, m; int nseln, nmeln, ndof; FEElementMatrix ke; const int MN = FEElement::MAX_NODES; vector<int> lm(3*(MN+1)); vector<int> en(MN+1); double *Gr, *Gs, *w; vec3d rt[MN], r0[MN]; vec3d rtm[MN]; double detJ, r, s; vec3d dxr, dxs; double H[MN]; vec3d gap, Lm, tc; // curvature tensor K double K[2][2] = {0}; // double scale = -0.0035*m_fem.GetMesh().GetBoundingBox().radius(); vector<int> sLM; vector<int> mLM; int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FEPeriodicSurface& ss = (np == 0? m_ss : m_ms); FEPeriodicSurface& ms = (np == 0? m_ms : m_ss); // loop over all primary elements int ne = ss.Elements(); for (j=0; j<ne; ++j) { FESurfaceElement& se = ss.Element(j); // get the element's LM vector ss.UnpackLM(se, sLM); nseln = se.Nodes(); for (int i=0; i<nseln; ++i) { r0[i] = ss.Node(se.m_lnode[i]).m_r0; rt[i] = ss.Node(se.m_lnode[i]).m_rt; } w = se.GaussWeights(); // loop over all integration points (that is nodes) for (n=0; n<nseln; ++n) { Gr = se.Gr(n); Gs = se.Gs(n); m = se.m_lnode[n]; // calculate jacobian dxr = dxs = vec3d(0,0,0); for (k=0; k<nseln; ++k) { dxr.x += Gr[k]*r0[k].x; dxr.y += Gr[k]*r0[k].y; dxr.z += Gr[k]*r0[k].z; dxs.x += Gs[k]*r0[k].x; dxs.y += Gs[k]*r0[k].y; dxs.z += Gs[k]*r0[k].z; } detJ = (dxr ^ dxs).norm(); // get the secondary element FESurfaceElement& me = *ss.m_data[m].m_pme; ms.UnpackLM(me, mLM); nmeln = me.Nodes(); // get the secondary element node positions for (k=0; k<nmeln; ++k) rtm[k] = ms.Node(me.m_lnode[k]).m_rt; // primary node natural coordinates in secondary element r = ss.m_data[m].m_rs[0]; s = ss.m_data[m].m_rs[1]; // get primary node normal force tc = ss.m_data[m].m_Lm + ss.m_data[m].m_gap*m_eps; //ss.T[m]; // get the secondary shape function values at this primary node if (nmeln == 4) { // quadrilateral H[0] = 0.25*(1-r)*(1-s); H[1] = 0.25*(1+r)*(1-s); H[2] = 0.25*(1+r)*(1+s); H[3] = 0.25*(1-r)*(1+s); } else if (nmeln == 3) { // triangle H[0] = 1 - r - s; H[1] = r; H[2] = s; } else { assert(false); } // number of degrees of freedom ndof = 3*(1 + nmeln); // fill stiffness matrix ke.resize(ndof, ndof); ke.zero(); ke[0][0] = w[n]*detJ*m_eps; ke[1][1] = w[n]*detJ*m_eps; ke[2][2] = w[n]*detJ*m_eps; for (k=0; k<nmeln; ++k) { ke[0][3+3*k ] = -w[n]*detJ*m_eps*H[k]; ke[1][3+3*k+1] = -w[n]*detJ*m_eps*H[k]; ke[2][3+3*k+2] = -w[n]*detJ*m_eps*H[k]; ke[3+3*k ][0] = -w[n]*detJ*m_eps*H[k]; ke[3+3*k+1][1] = -w[n]*detJ*m_eps*H[k]; ke[3+3*k+2][2] = -w[n]*detJ*m_eps*H[k]; } for (k=0; k<nmeln; ++k) for (l=0; l<nmeln; ++l) { ke[3+3*k ][3+3*l ] = w[n]*detJ*m_eps*H[k]*H[l]; ke[3+3*k+1][3+3*l+1] = w[n]*detJ*m_eps*H[k]*H[l]; ke[3+3*k+2][3+3*l+2] = w[n]*detJ*m_eps*H[k]*H[l]; } // create lm array lm[0] = sLM[n*3 ]; lm[1] = sLM[n*3+1]; lm[2] = sLM[n*3+2]; for (k=0; k<nmeln; ++k) { lm[3*(k+1) ] = mLM[k*3 ]; lm[3*(k+1)+1] = mLM[k*3+1]; lm[3*(k+1)+2] = mLM[k*3+2]; } // create the en array en.resize(nmeln+1); en[0] = se.m_node[n]; for (k=0; k<nmeln; ++k) en[k+1] = me.m_node[k]; // assemble stiffness matrix ke.SetNodes(en); ke.SetIndices(lm); LS.Assemble(ke); } } } } //----------------------------------------------------------------------------- bool FEPeriodicBoundary::Augment(int naug, const FETimeInfo& tp) { // make sure we need to augment if (m_laugon != FECore::AUGLAG_METHOD) return true; int i; double g; vec3d lm; // calculate initial norms double normL0 = 0; for (i=0; i<m_ss.Nodes(); ++i) { lm = m_ss.m_data[i].m_Lm; normL0 += lm*lm; } for (i=0; i<m_ms.Nodes(); ++i) { lm = m_ms.m_data[i].m_Lm; normL0 += lm*lm; } normL0 = sqrt(normL0); // update Lagrange multipliers and calculate current norms double normL1 = 0; double normgc = 0; int N = 0; for (i=0; i<m_ss.Nodes(); ++i) { lm = m_ss.m_data[i].m_Lm + m_ss.m_data[i].m_gap*m_eps; normL1 += lm*lm; g = m_ss.m_data[i].m_gap.norm(); normgc += g*g; ++N; } for (i=0; i<m_ms.Nodes(); ++i) { lm = m_ms.m_data[i].m_Lm + m_ms.m_data[i].m_gap*m_eps; normL1 += lm*lm; g = m_ms.m_data[i].m_gap.norm(); normgc += g*g; ++N; } if (N == 0) N=1; normL1 = sqrt(normL1); normgc = sqrt(normgc / N); feLog(" tied interface # %d\n", GetID()); feLog(" CURRENT REQUIRED\n"); double pctn = 0; if (fabs(normL1) > 1e-10) pctn = fabs((normL1 - normL0)/normL1); feLog(" normal force : %15le %15le\n", pctn, m_atol); feLog(" gap function : %15le ***\n", normgc); // check convergence of constraints bool bconv = true; if (pctn >= m_atol) bconv = false; if (m_naugmin > naug) bconv = false; // update Lagrange multipliers if we did not converge if (bconv == false) { for (i=0; i<m_ss.Nodes(); ++i) { // update Lagrange multipliers m_ss.m_data[i].m_Lm = m_ss.m_data[i].m_Lm + m_ss.m_data[i].m_gap*m_eps; } for (i=0; i<m_ms.Nodes(); ++i) { // update Lagrange multipliers m_ms.m_data[i].m_Lm = m_ms.m_data[i].m_Lm + m_ms.m_data[i].m_gap*m_eps; } } return bconv; } //----------------------------------------------------------------------------- void FEPeriodicBoundary::Serialize(DumpStream &ar) { // store contact data FEContactInterface::Serialize(ar); // store contact surface data m_ms.Serialize(ar); m_ss.Serialize(ar); }
C++
3D
febiosoftware/FEBio
FEBioMech/FECGSolidSolver.h
.h
3,763
127
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FESolver.h> #include <FECore/FEGlobalVector.h> #include <FECore/FETimeInfo.h> #include <FECore/FEDofList.h> //----------------------------------------------------------------------------- //! This class implements a solver for solid mechanics problems that uses //! the conjugate gradient method to solve the nonlinear finite element equations class FECGSolidSolver : public FESolver { public: //! constructor FECGSolidSolver(FEModel* pfem); //! initialization bool Init() override; //! clean up void Clean() override; //! Performs a CG step bool SolveStep() override; private: bool CalculatePreconditioner(); public: //! update model void Update(std::vector<double>& u) override; //! update nodal positions, velocities, accelerations, etc. void UpdateKinematics(vector<double>& ui); // Initialize linear equation system (TODO: Is this the right place to do this?) // \todo Can I make this part of the Init function? virtual bool InitEquations() override; protected: //! update rigid bodies void UpdateRigidBodies(vector<double>& ui); //! Evaluate the residual bool Residual(vector<double>& R); //! assemble into the residual void AssembleResidual(int node_id, int dof, double f, vector<double>& R); //! contact forces void ContactForces(FEGlobalVector& R); //! the non-linear constraint forces void NonLinearConstraintForces(FEGlobalVector& R, const FETimeInfo& tp); //! Inertial forces void InertialForces(FEGlobalVector& R); //! helper function for setting up the solution phase void PrepStep(); //! modified linesearch for Hager-Zhang solver double LineSearchCG(double s); public: double m_Dtol; double m_Etol; double m_Rtol; double m_Rmin; double m_LStol; double m_LSmin; int m_LSiter; int m_CGmethod; int m_precon; vector<double> m_Mi; //!< inverse mass vector for explicit analysis // Newmark parameters (for dynamic analyses) double m_beta; //!< Newmark parameter beta (displacement integration) double m_gamma; //!< Newmark parameter gamme (velocity integration) private: vector<double> m_R0; vector<double> m_R1; vector<double> m_Ui; vector<double> m_ui; vector<double> m_Ut; vector<double> m_Fn; vector<double> m_Fd; vector<double> m_Fr; int m_neq; int m_nreq; //int m_CGmethod; // 0 = Hager-Zhang (default), 1 = steepest descent protected: FEDofList m_dofU, m_dofV, m_dofQ, m_dofRQ,m_dofSU, m_dofSV, m_dofSA, m_rigidSolver; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEExplicitSolidSolver.cpp
.cpp
36,642
1,261
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEExplicitSolidSolver.h" #include "FEElasticSolidDomain.h" #include "FEElasticShellDomain.h" #include "FELinearTrussDomain.h" #include "FEElasticTrussDomain.h" #include "FERigidMaterial.h" #include "FEBodyForce.h" #include "FEContactInterface.h" #include "FERigidBody.h" #include "RigidBC.h" #include "FEMechModel.h" #include <FECore/FENodalLoad.h> #include <FECore/FESurfaceLoad.h> #include "FECore/log.h" #include <FECore/FEModel.h> #include <FECore/FEAnalysis.h> #include <FECore/FELinearConstraintManager.h> #include <FECore/FENLConstraint.h> #include "FEResidualVector.h" #include "FEBioMech.h" #include "FESolidAnalysis.h" //----------------------------------------------------------------------------- // define the parameter list BEGIN_FECORE_CLASS(FEExplicitSolidSolver, FESolver) ADD_PARAMETER(m_mass_lumping, "mass_lumping"); ADD_PARAMETER(m_dyn_damping, "dyn_damping"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEExplicitSolidSolver::FEExplicitSolidSolver(FEModel* pfem) : FESolver(pfem), m_dofU(pfem), m_dofV(pfem), m_dofQ(pfem), m_dofRQ(pfem), m_dofSU(pfem), m_dofSV(pfem), m_dofSA(pfem), m_rigidSolver(pfem) { m_dyn_damping = 1; m_niter = 0; m_nreq = 0; m_mass_lumping = HRZ_LUMPING; // Allocate degrees of freedom // TODO: Can this be done in Init, since there is no error checking if (pfem) { DOFS& dofs = pfem->GetDOFS(); int varD = dofs.AddVariable("displacement", VAR_VEC3); dofs.SetDOFName(varD, 0, "x"); dofs.SetDOFName(varD, 1, "y"); dofs.SetDOFName(varD, 2, "z"); int varQ = dofs.AddVariable("rotation", VAR_VEC3); dofs.SetDOFName(varQ, 0, "u"); dofs.SetDOFName(varQ, 1, "v"); dofs.SetDOFName(varQ, 2, "w"); int varQR = dofs.AddVariable("rigid rotation", VAR_VEC3); dofs.SetDOFName(varQR, 0, "Ru"); dofs.SetDOFName(varQR, 1, "Rv"); dofs.SetDOFName(varQR, 2, "Rw"); int varV = dofs.AddVariable("velocity", VAR_VEC3); dofs.SetDOFName(varV, 0, "vx"); dofs.SetDOFName(varV, 1, "vy"); dofs.SetDOFName(varV, 2, "vz"); int varSU = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT), VAR_VEC3); dofs.SetDOFName(varSU, 0, "sx"); dofs.SetDOFName(varSU, 1, "sy"); dofs.SetDOFName(varSU, 2, "sz"); int varSV = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_VELOCITY), VAR_VEC3); dofs.SetDOFName(varSV, 0, "svx"); dofs.SetDOFName(varSV, 1, "svy"); dofs.SetDOFName(varSV, 2, "svz"); int varSA = dofs.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_ACCELERATION), VAR_VEC3); dofs.SetDOFName(varSA, 0, "sax"); dofs.SetDOFName(varSA, 1, "say"); dofs.SetDOFName(varSA, 2, "saz"); // get the DOF indices m_dofU.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT)); m_dofV.AddVariable(FEBioMech::GetVariableName(FEBioMech::VELOCITY)); m_dofQ.AddVariable(FEBioMech::GetVariableName(FEBioMech::ROTATION)); m_dofRQ.AddVariable(FEBioMech::GetVariableName(FEBioMech::RIGID_ROTATION)); m_dofSU.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT)); m_dofSV.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_VELOCITY)); m_dofSA.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_ACCELERATION)); } } //----------------------------------------------------------------------------- void FEExplicitSolidSolver::Clean() { } //----------------------------------------------------------------------------- bool FEExplicitSolidSolver::CalculateMassMatrix() { FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); vector<double> massVector(m_neq), dummy(m_neq); FEGlobalVector M(fem, massVector, dummy); matrix me; vector <int> lm; vector <double> el_lumped_mass; // loop over all domains if (m_mass_lumping == NO_MASS_LUMPING) { // use consistent mass matrix. // TODO: implement this assert(false); return false; } else if (m_mass_lumping == ROW_SUM_LUMPING) { for (int nd = 0; nd < mesh.Domains(); ++nd) { // check whether it is a solid domain FEElasticSolidDomain* pbd = dynamic_cast<FEElasticSolidDomain*>(&mesh.Domain(nd)); if (pbd) // it is an elastic solid domain { FESolidMaterial* pme = dynamic_cast<FESolidMaterial*>(pbd->GetMaterial()); // loop over all the elements for (int iel = 0; iel < pbd->Elements(); ++iel) { FESolidElement& el = pbd->Element(iel); pbd->UnpackLM(el, lm); int nint = el.GaussPoints(); int neln = el.Nodes(); me.resize(neln, neln); me.zero(); // create the element mass matrix for (int n = 0; n < nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); double d = pme->Density(mp); double detJ0 = pbd->detJ0(el, n)*el.GaussWeights()[n]; double* H = el.H(n); for (int i = 0; i < neln; ++i) for (int j = 0; j < neln; ++j) { double kab = H[i] * H[j] * detJ0*d; me[i][j] += kab; } } // reduce to a lumped mass vector and add up the total el_lumped_mass.assign(3 * neln, 0.0); for (int i = 0; i < neln; ++i) { for (int j = 0; j < neln; ++j) { double kab = me[i][j]; el_lumped_mass[3 * i] += kab; el_lumped_mass[3 * i + 1] += kab; el_lumped_mass[3 * i + 2] += kab; } } // assemble element matrix into inv_mass vector M.Assemble(el.m_node, lm, el_lumped_mass); } // loop over elements } else if (dynamic_cast<FEElasticShellDomain*>(&mesh.Domain(nd))) { FEElasticShellDomain* psd = dynamic_cast<FEElasticShellDomain*>(&mesh.Domain(nd)); FESolidMaterial* pme = dynamic_cast<FESolidMaterial*>(psd->GetMaterial()); // loop over all the elements for (int iel = 0; iel < psd->Elements(); ++iel) { FEShellElement& el = psd->Element(iel); psd->UnpackLM(el, lm); // create the element's stiffness matrix FEElementMatrix ke(el); int neln = el.Nodes(); int ndof = 6 * el.Nodes(); ke.resize(ndof, ndof); ke.zero(); // calculate inertial stiffness psd->ElementMassMatrix(el, ke, 1.0); // reduce to a lumped mass vector and add up the total el_lumped_mass.assign(ndof, 0.0); for (int i = 0; i < ndof; ++i) { for (int j = 0; j < ndof; ++j) { double kab = ke[i][j]; el_lumped_mass[i] += kab; } } // assemble element matrix into inv_mass vector M.Assemble(el.m_node, lm, el_lumped_mass); } } else if (dynamic_cast<FELinearTrussDomain*>(&mesh.Domain(nd))) { FELinearTrussDomain* ptd = dynamic_cast<FELinearTrussDomain*>(&mesh.Domain(nd)); // loop over all the elements for (int iel = 0; iel < ptd->Elements(); ++iel) { FETrussElement& el = ptd->Element(iel); ptd->UnpackLM(el, lm); // create the element's stiffness matrix FEElementMatrix ke(el); int neln = el.Nodes(); ke.resize(neln, neln); ke.zero(); // calculate inertial stiffness ptd->ElementMassMatrix(el, ke); // reduce to a lumped mass vector and add up the total el_lumped_mass.assign(3 * neln, 0.0); for (int i = 0; i < neln; ++i) { for (int j = 0; j < neln; ++j) { double kab = ke[i][j]; el_lumped_mass[3 * i ] += kab; el_lumped_mass[3 * i + 1] += kab; el_lumped_mass[3 * i + 2] += kab; } } // assemble element matrix into inv_mass vector M.Assemble(el.m_node, lm, el_lumped_mass); } } else if (dynamic_cast<FEElasticTrussDomain*>(&mesh.Domain(nd))) { FEElasticTrussDomain* ptd = dynamic_cast<FEElasticTrussDomain*>(&mesh.Domain(nd)); // loop over all the elements for (int iel = 0; iel < ptd->Elements(); ++iel) { FETrussElement& el = ptd->Element(iel); ptd->UnpackLM(el, lm); // create the element's stiffness matrix FEElementMatrix ke(el); int neln = el.Nodes(); ke.resize(neln, neln); ke.zero(); // calculate inertial stiffness ptd->ElementMassMatrix(el, ke); // reduce to a lumped mass vector and add up the total el_lumped_mass.assign(3 * neln, 0.0); for (int i = 0; i < neln; ++i) { for (int j = 0; j < neln; ++j) { double kab = ke[i][j]; el_lumped_mass[3 * i ] += kab; el_lumped_mass[3 * i + 1] += kab; el_lumped_mass[3 * i + 2] += kab; } } // assemble element matrix into inv_mass vector M.Assemble(el.m_node, lm, el_lumped_mass); } } else { // return false; } } } else if (m_mass_lumping == HRZ_LUMPING) { for (int nd = 0; nd < mesh.Domains(); ++nd) { // check whether it is a solid domain FEElasticSolidDomain* pbd = dynamic_cast<FEElasticSolidDomain*>(&mesh.Domain(nd)); if (pbd) // it is an elastic solid domain { FESolidMaterial* pme = dynamic_cast<FESolidMaterial*>(pbd->GetMaterial()); // loop over all the elements for (int iel = 0; iel < pbd->Elements(); ++iel) { FESolidElement& el = pbd->Element(iel); pbd->UnpackLM(el, lm); int nint = el.GaussPoints(); int neln = el.Nodes(); me.resize(neln, neln); me.zero(); // calculate the element mass matrix (and element mass). double Me = 0.0; double* w = el.GaussWeights(); for (int n = 0; n < nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); double d = pme->Density(mp); double detJ0 = pbd->detJ0(el, n)*el.GaussWeights()[n]; Me += d * detJ0 * w[n]; double* H = el.H(n); for (int i = 0; i < neln; ++i) for (int j = 0; j < neln; ++j) { double kab = H[i] * H[j] * detJ0*d; me[i][j] += kab; } } // calculate sum of diagonals double S = 0.0; for (int i = 0; i < neln; ++i) S += me[i][i]; // reduce to a lumped mass vector and add up the total el_lumped_mass.assign(3 * neln, 0.0); for (int i = 0; i < neln; ++i) { double mab = me[i][i] * Me / S; el_lumped_mass[3 * i ] = mab; el_lumped_mass[3 * i + 1] = mab; el_lumped_mass[3 * i + 2] = mab; } // assemble element matrix into inv_mass vector M.Assemble(el.m_node, lm, el_lumped_mass); } // loop over elements } else if(dynamic_cast<FEElasticShellDomain*>(&mesh.Domain(nd))) { FEElasticShellDomain* psd = dynamic_cast<FEElasticShellDomain*>(&mesh.Domain(nd)); FESolidMaterial* pme = dynamic_cast<FESolidMaterial*>(psd->GetMaterial()); // loop over all the elements for (int iel = 0; iel < psd->Elements(); ++iel) { FEShellElement& el = psd->Element(iel); psd->UnpackLM(el, lm); // create the element's stiffness matrix FEElementMatrix ke(el); int neln = el.Nodes(); int ndof = 6 * el.Nodes(); ke.resize(ndof, ndof); ke.zero(); // calculate inertial stiffness psd->ElementMassMatrix(el, ke, 1.0); // calculate the element mass double Me = 0.0; double* w = el.GaussWeights(); for (int n = 0; n < el.GaussPoints(); ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); double d = pme->Density(mp); double detJ0 = psd->detJ0(el, n) * el.GaussWeights()[n]; Me += d * detJ0 * w[n]; } // calculate sum of diagonals double S = 0.0; for (int i = 0; i < ndof; ++i) S += ke[i][i] / 3.0; // reduce to a lumped mass vector and add up the total el_lumped_mass.assign(ndof, 0.0); for (int i = 0; i < ndof; ++i) { double mab = ke[i][i] * Me / S; el_lumped_mass[i] = mab; } // assemble element matrix into inv_mass vector M.Assemble(el.m_node, lm, el_lumped_mass); } } else { // TODO: we can only do solid domains right now. return false; } } } else { assert(false); return false; } // we need the inverse of the lumped masses later // Also, make sure the lumped masses are positive. for (int i = 0; i < massVector.size(); ++i) { m_data[i].mi = 0; if (massVector[i] != 0.0) m_data[i].mi = 1.0 / massVector[i]; } return true; } //----------------------------------------------------------------------------- //! initialize equations bool FEExplicitSolidSolver::InitEquations() { if (FESolver::InitEquations() == false) return false; // allocate rigid body equation numbers m_neq = m_rigidSolver.InitEquations(m_neq); return true; } //----------------------------------------------------------------------------- bool FEExplicitSolidSolver::Init() { if (FESolver::Init() == false) return false; FEMechModel& fem = dynamic_cast<FEMechModel&>(*GetFEModel()); FEMesh& mesh = fem.GetMesh(); // set the dynamic update flag only if we are running a dynamic analysis // NOTE: I don't think we need to set the dynamic update flag, in fact, we should // turn it off, since it's on by default, and it incurs a significant performance overhead // bool b = (fem.GetCurrentStep()->m_nanalysis == FESolidAnalysis::DYNAMIC ? true : false); for (int i = 0; i < mesh.Domains(); ++i) { FEElasticSolidDomain* d = dynamic_cast<FEElasticSolidDomain*>(&mesh.Domain(i)); FEElasticShellDomain* s = dynamic_cast<FEElasticShellDomain*>(&mesh.Domain(i)); if (d) d->SetDynamicUpdateFlag(false); if (s) s->SetDynamicUpdateFlag(false); } // get nr of equations int neq = m_neq; // allocate vectors m_data.resize(neq); m_Rt.assign(neq, 0); m_Fr.assign(neq, 0); m_Ut.assign(neq, 0); m_ui.assign(neq, 0); fem.Update(); // we need to fill the total displacement vector m_Ut gather(m_Ut, mesh, m_dofU[0]); gather(m_Ut, mesh, m_dofU[1]); gather(m_Ut, mesh, m_dofU[2]); gather(m_Ut, mesh, m_dofQ[0]); gather(m_Ut, mesh, m_dofQ[1]); gather(m_Ut, mesh, m_dofQ[2]); gather(m_Ut, mesh, m_dofSU[0]); gather(m_Ut, mesh, m_dofSU[1]); gather(m_Ut, mesh, m_dofSU[2]); // calculate the inverse mass vector for the explicit analysis if (CalculateMassMatrix() == false) { feLogError("Failed building mass matrix."); return false; } // calculate the initial acceleration // (Only when the totiter == 0, in case of a restart) if (fem.GetCurrentStep()->m_ntotiter == 0) { // Calculate initial residual to be used on the first time step if (Residual(m_Rt) == false) return false; for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); int n; if ((n = node.m_ID[m_dofU[0]]) >= 0) { m_data[n].a = node.m_at.x = m_Rt[n] * m_data[n].mi; } if ((n = node.m_ID[m_dofU[1]]) >= 0) { m_data[n].a = node.m_at.y = m_Rt[n] * m_data[n].mi; } if ((n = node.m_ID[m_dofU[2]]) >= 0) { m_data[n].a = node.m_at.z = m_Rt[n] * m_data[n].mi; } if ((n = node.m_ID[m_dofSU[0]]) >= 0) { m_data[n].a = m_Rt[n] * m_data[n].mi; node.set(m_dofSA[0], m_data[n].a);} if ((n = node.m_ID[m_dofSU[1]]) >= 0) { m_data[n].a = m_Rt[n] * m_data[n].mi; node.set(m_dofSA[1], m_data[n].a);} if ((n = node.m_ID[m_dofSU[2]]) >= 0) { m_data[n].a = m_Rt[n] * m_data[n].mi; node.set(m_dofSA[2], m_data[n].a);} } // do rigid bodies for (int i = 0; i < fem.RigidBodies(); ++i) { FERigidBody& rb = *fem.GetRigidBody(i); vec3d Fn, Mn; int n; if ((n = rb.m_LM[0]) >= 0) { Fn.x = m_Rt[n]; } if ((n = rb.m_LM[1]) >= 0) { Fn.y = m_Rt[n]; } if ((n = rb.m_LM[2]) >= 0) { Fn.z = m_Rt[n]; } if ((n = rb.m_LM[3]) >= 0) { Mn.x = m_Rt[n]; } if ((n = rb.m_LM[4]) >= 0) { Mn.y = m_Rt[n]; } if ((n = rb.m_LM[5]) >= 0) { Mn.z = m_Rt[n]; } rb.m_at = Fn / rb.m_mass; // TODO: angular acceleration } } return true; } //----------------------------------------------------------------------------- //! Updates the current state of the model void FEExplicitSolidSolver::Update(vector<double>& ui) { FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // update kinematics UpdateKinematics(ui); // update element stresses fem.Update(); } //----------------------------------------------------------------------------- //! Update the kinematics of the model, such as nodal positions, velocities, //! accelerations, etc. void FEExplicitSolidSolver::UpdateKinematics(vector<double>& ui) { // get the mesh FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); // update rigid bodies UpdateRigidBodies(ui); // total displacements vector<double> U(m_Ut.size()); #pragma omp parallel for for (int i=0; i<m_Ut.size(); ++i) U[i] = ui[i] + m_Ut[i]; // update flexible nodes // translational dofs scatter3(U, mesh, m_dofU[0], m_dofU[1], m_dofU[2]); // rotational dofs // TODO: Commenting this out, since this is only needed for the old shells, which I'm not sure // if they would work with the explicit solver anyways. // scatter(U, mesh, m_dofQ[0]); // scatter(U, mesh, m_dofQ[1]); // scatter(U, mesh, m_dofQ[2]); // shell displacement scatter3(U, mesh, m_dofSU[0], m_dofSU[1], m_dofSU[2]); // make sure the prescribed displacements are fullfilled int ndis = fem.BoundaryConditions(); for (int i=0; i<ndis; ++i) { FEBoundaryCondition& bc = *fem.BoundaryCondition(i); if (bc.IsActive()) bc.Update(); } // enforce the linear constraints // TODO: do we really have to do this? Shouldn't the algorithm // already guarantee that the linear constraints are satisfied? FELinearConstraintManager& LCM = fem.GetLinearConstraintManager(); if (LCM.LinearConstraints() > 0) { LCM.Update(); } // Update the spatial nodal positions // Don't update rigid nodes since they are already updated #pragma omp parallel for for (int i=0; i<mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); if (node.m_rid == -1) node.m_rt = node.m_r0 + node.get_vec3d(m_dofU[0], m_dofU[1], m_dofU[2]); } } //----------------------------------------------------------------------------- //! Updates the rigid body data void FEExplicitSolidSolver::UpdateRigidBodies(vector<double>& ui) { // get the number of rigid bodies FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel()); const int NRB = fem.RigidBodies(); if (NRB == 0) return; // first calculate the rigid body displacement increments for (int i=0; i<NRB; ++i) { // get the rigid body FERigidBody& RB = *fem.GetRigidBody(i); int *lm = RB.m_LM; double* du = RB.m_du; if (RB.m_prb == 0) { for (int j=0; j<6; ++j) { du[j] = (lm[j] >=0 ? ui[lm[j]] : 0); } } } // for prescribed displacements, the displacement increments are evaluated differently // TODO: Is this really necessary? Why can't the ui vector contain the correct values? for (int i = 0; i < NRB; ++i) { FERigidBody& RB = *fem.GetRigidBody(i); for (int j = 0; j < 6; ++j) { FERigidPrescribedBC* dc = RB.m_pDC[j]; if (dc) { int I = dc->GetBC(); RB.m_du[I] = dc->Value() - RB.m_Up[I]; } } } // update the rigid bodies for (int i=0; i<NRB; ++i) { // get the rigid body FERigidBody& RB = *fem.GetRigidBody(i); double* du = RB.m_du; // This is the "old" update algorithm which has some issues. It does not produce the correct // rigid body orientation when the rotational degrees of freedom are prescribed. RB.m_rt.x = RB.m_rp.x + du[0]; RB.m_rt.y = RB.m_rp.y + du[1]; RB.m_rt.z = RB.m_rp.z + du[2]; vec3d r = vec3d(du[3], du[4], du[5]); double w = sqrt(r.x*r.x + r.y*r.y + r.z*r.z); quatd dq = quatd(w, r); quatd Q = dq*RB.m_qp; Q.MakeUnit(); RB.SetRotation(Q); if (RB.m_prb) du = RB.m_dul; RB.m_Ut[0] = RB.m_Up[0] + du[0]; RB.m_Ut[1] = RB.m_Up[1] + du[1]; RB.m_Ut[2] = RB.m_Up[2] + du[2]; RB.m_Ut[3] = RB.m_Up[3] + du[3]; RB.m_Ut[4] = RB.m_Up[4] + du[4]; RB.m_Ut[5] = RB.m_Up[5] + du[5]; } // we need to update the position of rigid nodes fem.UpdateRigidMesh(); // Since the rigid nodes are repositioned we need to update the displacement DOFS FEMesh& mesh = fem.GetMesh(); int N = mesh.Nodes(); for (int i=0; i<N; ++i) { FENode& node = mesh.Node(i); if (node.m_rid >= 0) { vec3d ut = node.m_rt - node.m_r0; node.set_vec3d(m_dofU[0], m_dofU[1], m_dofU[2], ut); } } } //----------------------------------------------------------------------------- //! Save data to dump file void FEExplicitSolidSolver::Serialize(DumpStream& ar) { FESolver::Serialize(ar); ar & m_nrhs & m_niter & m_nref & m_ntotref & m_naug & m_neq & m_nreq; if (ar.IsShallow() == false) { ar & m_Ut & m_Rt; if (ar.IsSaving()) { int N = (int)m_data.size(); ar << N; for (int i = 0; i < N; ++i) { Data& d = m_data[i]; ar << d.v << d.a << d.mi; } } else if (ar.IsLoading()) { int N = 0; ar >> N; m_data.resize(N); for (int i = 0; i < N; ++i) { Data& d = m_data[i]; ar >> d.v >> d.a >> d.mi; } } } } //----------------------------------------------------------------------------- //! This function mainly calls the DoSolve routine //! and deals with exceptions that require the immediate termination of //! the solution eg negative Jacobians. bool FEExplicitSolidSolver::SolveStep() { bool bret; try { // let's try to solve the step bret = DoSolve(); } catch (NegativeJacobian e) { // A negative jacobian was detected feLogError("Negative jacobian was detected at element %d at gauss point %d\njacobian = %lg\n", e.m_iel, e.m_ng+1, e.m_vol); return false; } catch (MaxStiffnessReformations) // shouldn't happen for an explicit analysis! { // max nr of reformations is reached feLogError("Max nr of reformations reached."); return false; } catch (ForceConversion) { // user forced conversion of problem feLogWarning("User forced conversion.\nSolution might not be stable."); return true; } catch (IterationFailure) { // user caused a forced iteration failure feLogWarning("User forced iteration failure."); return false; } catch (ZeroLinestepSize) // shouldn't happen for an explicit analysis! { // a zero line step size was detected feLogError("Zero line step size."); return false; } catch (EnergyDiverging) // shouldn't happen for an explicit analysis! { // problem was diverging after stiffness reformation feLogError("Problem diverging uncontrollably."); return false; } catch (FEMultiScaleException) { // the RVE problem didn't solve feLogError("The RVE problem has failed. Aborting macro run."); return false; } return bret; } //----------------------------------------------------------------------------- //! Prepares the data for the time step. void FEExplicitSolidSolver::PrepStep() { int i, j; // initialize counters m_niter = 0; // nr of iterations m_nrhs = 0; // nr of RHS evaluations m_nref = 0; // nr of stiffness reformations m_ntotref = 0; m_naug = 0; // nr of augmentations // store previous mesh state // we need them for velocity and acceleration calculations FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel()); FEMesh& mesh = fem.GetMesh(); #pragma omp parallel for for (i=0; i<mesh.Nodes(); ++i) { FENode& ni = mesh.Node(i); ni.m_rp = ni.m_rt; ni.m_vp = ni.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2]); ni.m_ap = ni.m_at; ni.UpdateValues(); } const FETimeInfo& tp = fem.GetTime(); // apply prescribed displacements // we save the prescribed displacements increments in the ui vector vector<double>& ui = m_ui; zero(ui); int neq = m_neq; int nbc = fem.BoundaryConditions(); for (i=0; i<nbc; ++i) { FEBoundaryCondition& bc = *fem.BoundaryCondition(i); if (bc.IsActive()) bc.PrepStep(ui); } // initialize rigid bodies int NO = fem.RigidBodies(); for (i=0; i<NO; ++i) fem.GetRigidBody(i)->Init(); // calculate local rigid displacements for (i = 0; i < NO; ++i) { FERigidBody& rb = *fem.GetRigidBody(i); for (int j = 0; j < 6; ++j) { FERigidPrescribedBC* dc = rb.m_pDC[j]; if (dc) { int I = dc->GetBC(); rb.m_dul[I] = dc->Value() - rb.m_Ut[I]; } } } // calculate global rigid displacements for (i=0; i<NO; ++i) { FERigidBody* prb = fem.GetRigidBody(i); if (prb) { FERigidBody& RB = *prb; if (RB.m_prb == 0) { for (j=0; j<6; ++j) RB.m_du[j] = RB.m_dul[j]; } else { double* dul = RB.m_dul; vec3d dr = vec3d(dul[0], dul[1], dul[2]); vec3d v = vec3d(dul[3], dul[4], dul[5]); double w = sqrt(v.x*v.x + v.y*v.y + v.z*v.z); quatd dq = quatd(w, v); FERigidBody* pprb = RB.m_prb; vec3d r0 = RB.m_rt; quatd Q0 = RB.GetRotation(); dr = Q0*dr; dq = Q0*dq*Q0.Inverse(); while (pprb) { vec3d r1 = pprb->m_rt; dul = pprb->m_dul; quatd Q1 = pprb->GetRotation(); dr = r0 + dr - r1; // grab the parent's local displacements vec3d dR = vec3d(dul[0], dul[1], dul[2]); v = vec3d(dul[3], dul[4], dul[5]); w = sqrt(v.x*v.x + v.y*v.y + v.z*v.z); quatd dQ = quatd(w, v); dQ = Q1*dQ*Q1.Inverse(); // update global displacements quatd Qi = Q1.Inverse(); dr = dR + r1 + dQ*dr - r0; dq = dQ*dq; // move up in the chain pprb = pprb->m_prb; Q0 = Q1; } // set global displacements double* du = RB.m_du; du[0] = dr.x; du[1] = dr.y; du[2] = dr.z; v = dq.GetVector(); w = dq.GetAngle(); du[3] = w*v.x; du[4] = w*v.y; du[5] = w*v.z; } } } // store rigid displacements in Ui vector for (i=0; i<NO; ++i) { FERigidBody& RB = *fem.GetRigidBody(i); for (j=0; j<6; ++j) { int I = -RB.m_LM[j]-2; if (I >= 0) ui[I] = RB.m_du[j]; } } // intialize material point data for (i=0; i<mesh.Domains(); ++i) mesh.Domain(i).PreSolveUpdate(tp); // NOTE: Commenting this out since I don't think anything needs to be updated here. // This also halves the number of update calls, so gives a performance boost. // fem.Update(); } //----------------------------------------------------------------------------- bool FEExplicitSolidSolver::DoSolve() { // Get the current step FEMechModel& fem = dynamic_cast<FEMechModel&>(*GetFEModel()); FEAnalysis* pstep = fem.GetCurrentStep(); // prepare for solve PrepStep(); // feLog(" %d\n", m_niter+1); // get the mesh FEMesh& mesh = fem.GetMesh(); int N = mesh.Nodes(); // this is the total number of nodes in the mesh double dt = fem.GetTime().timeIncrement; // collect accelerations, velocities, displacements // NOTE: I don't think this is necessary /* #pragma omp parallel for shared(mesh) for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); vec3d vt = node.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2]); int n; if ((n = node.m_ID[m_dofU[0]]) >= 0) { m_vn[n] = vt.x; m_an[n] = node.m_at.x; } if ((n = node.m_ID[m_dofU[1]]) >= 0) { m_vn[n] = vt.y; m_an[n] = node.m_at.y; } if ((n = node.m_ID[m_dofU[2]]) >= 0) { m_vn[n] = vt.z; m_an[n] = node.m_at.z; } if ((n = node.m_ID[m_dofSU[0]]) >= 0) { m_vn[n] = node.get(m_dofSV[0]); m_an[n] = node.get(m_dofSA[0]); } if ((n = node.m_ID[m_dofSU[1]]) >= 0) { m_vn[n] = node.get(m_dofSV[1]); m_an[n] = node.get(m_dofSA[1]); } if ((n = node.m_ID[m_dofSU[2]]) >= 0) { m_vn[n] = node.get(m_dofSV[2]); m_an[n] = node.get(m_dofSA[2]); } } */ // do rigid bodies for (int i = 0; i < fem.RigidBodies(); ++i) { FERigidBody& rb = *fem.GetRigidBody(i); int n; if ((n = rb.m_LM[0]) >= 0) { m_data[n].v = rb.m_vt.x; m_data[n].a = rb.m_at.x; } if ((n = rb.m_LM[1]) >= 0) { m_data[n].v = rb.m_vt.y; m_data[n].a = rb.m_at.y; } if ((n = rb.m_LM[2]) >= 0) { m_data[n].v = rb.m_vt.z; m_data[n].a = rb.m_at.z; } // convert to rigid frame quatd Q = rb.GetRotation(); quatd Qi = Q.Inverse(); vec3d Wn = Qi * rb.m_wt; vec3d An = Qi * rb.m_alt; if ((n = rb.m_LM[3]) >= 0) { m_data[n].v = Wn.x; m_data[n].a = An.x; } if ((n = rb.m_LM[4]) >= 0) { m_data[n].v = Wn.y; m_data[n].a = An.y; } if ((n = rb.m_LM[5]) >= 0) { m_data[n].v = Wn.z; m_data[n].a = An.z; } } double Dnorm = 0.0; #pragma omp parallel for reduction(+: Dnorm) for (int i = 0; i < m_neq; ++i) { // velocity predictor m_data[i].v += m_data[i].a * dt*0.5; // update displacements m_ui[i] = dt * m_data[i].v; // update norm Dnorm += m_ui[i] * m_ui[i]; } Dnorm = sqrt(Dnorm); feLog("\t displacement norm : %lg\n", Dnorm); // the update is done in the spatial frame, so we need to update // rigid body rotation increment for (int i = 0; i < fem.RigidBodies(); ++i) { FERigidBody& rb = *fem.GetRigidBody(i); quatd Q = rb.GetRotation(); vec3d dq(0, 0, 0); int n; if ((n = rb.m_LM[3]) >= 0) { dq.x = m_ui[n]; } if ((n = rb.m_LM[4]) >= 0) { dq.y = m_ui[n]; } if ((n = rb.m_LM[5]) >= 0) { dq.z = m_ui[n]; } vec3d qt = Q * dq; if ((n = rb.m_LM[3]) >= 0) { m_ui[n] = qt.x; } if ((n = rb.m_LM[4]) >= 0) { m_ui[n] = qt.y; } if ((n = rb.m_LM[5]) >= 0) { m_ui[n] = qt.z; } } Update(m_ui); // evaluate acceleration Residual(m_Rt); double Rnorm = 0.0; #pragma omp parallel shared(Rnorm) { #pragma omp for reduction(+: Rnorm) nowait for (int i = 0; i < m_neq; ++i) { Rnorm += m_Rt[i] * m_Rt[i]; } #pragma omp for nowait for (int i = 0; i < m_neq; ++i) { // update total displacement m_Ut[i] += m_ui[i]; } #pragma omp for for (int i = 0; i < m_neq; ++i) { m_data[i].a = m_Rt[i] * m_data[i].mi; // update velocity m_data[i].v = m_dyn_damping * (m_data[i].v + m_data[i].a * dt * 0.5); } // scatter velocity and accelerations #pragma omp for nowait for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); int n; if ((n = node.m_ID[m_dofU[0]]) >= 0) { node.set(m_dofV[0], m_data[n].v); node.m_at.x = m_data[n].a; } if ((n = node.m_ID[m_dofU[1]]) >= 0) { node.set(m_dofV[1], m_data[n].v); node.m_at.y = m_data[n].a; } if ((n = node.m_ID[m_dofU[2]]) >= 0) { node.set(m_dofV[2], m_data[n].v); node.m_at.z = m_data[n].a; } if ((n = node.m_ID[m_dofSU[0]]) >= 0) { node.set(m_dofSV[0], m_data[n].v); node.set(m_dofSA[0], m_data[n].a); } if ((n = node.m_ID[m_dofSU[1]]) >= 0) { node.set(m_dofSV[1], m_data[n].v); node.set(m_dofSA[1], m_data[n].a); } if ((n = node.m_ID[m_dofSU[2]]) >= 0) { node.set(m_dofSV[2], m_data[n].v); node.set(m_dofSA[2], m_data[n].a); } } } Rnorm = sqrt(Rnorm); feLog("\t force vector norm : %lg\n", Rnorm); // do rigid bodies for (int i = 0; i < fem.RigidBodies(); ++i) { FERigidBody& rb = *fem.GetRigidBody(i); quatd Q = rb.GetRotation(); quatd Qi = Q.Inverse(); // get the force and moment vec3d Fn(0, 0, 0), Mn; int n; if ((n = rb.m_LM[0]) >= 0) Fn.x = m_Rt[n]; if ((n = rb.m_LM[1]) >= 0) Fn.y = m_Rt[n]; if ((n = rb.m_LM[2]) >= 0) Fn.z = m_Rt[n]; if ((n = rb.m_LM[3]) >= 0) Mn.x = m_Rt[n]; if ((n = rb.m_LM[4]) >= 0) Mn.y = m_Rt[n]; if ((n = rb.m_LM[5]) >= 0) Mn.z = m_Rt[n]; // convert to rigid frame Mn = Qi * Mn; // linear momentum update vec3d An = Fn / rb.m_mass; rb.m_at = Q*An; vec3d Vn(0,0,0); if ((n = rb.m_LM[0]) >= 0) Vn.x = m_dyn_damping * (m_data[n].v + An.x * dt * 0.5); if ((n = rb.m_LM[1]) >= 0) Vn.y = m_dyn_damping * (m_data[n].v + An.y * dt * 0.5); if ((n = rb.m_LM[2]) >= 0) Vn.z = m_dyn_damping * (m_data[n].v + An.z * dt * 0.5); rb.m_vt = Q * Vn; // angular momentum update // NOTE: This currently adds a_{n}, not a_{n+1}, because in order // to evaluate a_{n+1}, I need W_{n+1}. This looks like a nonlinear problem // so probably need to do something else here. vec3d Wn(0,0,0); if ((n = rb.m_LM[3]) >= 0) Wn.x = m_dyn_damping * (m_data[n].v + m_data[n].a * dt*0.5); if ((n = rb.m_LM[4]) >= 0) Wn.y = m_dyn_damping * (m_data[n].v + m_data[n].a * dt*0.5); if ((n = rb.m_LM[5]) >= 0) Wn.z = m_dyn_damping * (m_data[n].v + m_data[n].a * dt*0.5); rb.m_wt = Q * Wn; mat3ds I0 = rb.m_moi; mat3ds I0inv = I0.inverse(); vec3d Pn = I0inv * (Mn - (Wn ^ (I0 * Wn))); rb.m_alt = Q * Pn; // update some other stuff mat3d R = Q.RotationMatrix(); mat3d It = R * I0 * R.transpose(); rb.m_ht = It * rb.m_wt; } // increase iteration number m_niter++; // do minor iterations callbacks fem.DoCallback(CB_MINOR_ITERS); return true; } //----------------------------------------------------------------------------- //! calculates the residual vector //! Note that the concentrated nodal forces are not calculated here. //! This is because they do not depend on the geometry //! so we only calculate them once (in Quasin) and then add them here. bool FEExplicitSolidSolver::Residual(vector<double>& R) { TRACK_TIME(Timer_Residual); // get the time information FEMechModel& fem = static_cast<FEMechModel&>(*GetFEModel()); const FETimeInfo& tp = fem.GetTime(); // initialize residual with concentrated nodal loads zero(R); // zero nodal reaction forces zero(m_Fr); // setup the global vector FEResidualVector RHS(fem, R, m_Fr); // zero rigid body reaction forces int NRB = fem.RigidBodies(); for (int i=0; i<NRB; ++i) { FERigidBody& RB = *fem.GetRigidBody(i); RB.m_Fr = RB.m_Mr = vec3d(0,0,0); } // get the mesh FEMesh& mesh = fem.GetMesh(); // calculate the internal (stress) forces for (int i=0; i<mesh.Domains(); ++i) { FEElasticDomain& dom = dynamic_cast<FEElasticDomain&>(mesh.Domain(i)); dom.InternalForces(RHS); } // calculate forces due to model loads int nml = fem.ModelLoads(); for (int i=0; i<nml; ++i) { FEModelLoad* pml = fem.ModelLoad(i); if (pml->IsActive()) pml->LoadVector(RHS); } // calculate contact forces if (fem.SurfacePairConstraints() > 0) { ContactForces(RHS); } // calculate nonlinear constraint forces // note that these are the linear constraints // enforced using the augmented lagrangian NonLinearConstraintForces(RHS, tp); // set the nodal reaction forces // TODO: Is this a good place to do this? #pragma omp parallel for for (int i=0; i<mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); node.set_load(m_dofU[0], 0); node.set_load(m_dofU[1], 0); node.set_load(m_dofU[2], 0); node.set_load(m_dofSU[0], 0); node.set_load(m_dofSU[1], 0); node.set_load(m_dofSU[2], 0); int n; if ((n = -node.m_ID[m_dofU[0]] - 2) >= 0) node.set_load(m_dofU[0], -m_Fr[n]); if ((n = -node.m_ID[m_dofU[1]] - 2) >= 0) node.set_load(m_dofU[1], -m_Fr[n]); if ((n = -node.m_ID[m_dofU[2]] - 2) >= 0) node.set_load(m_dofU[2], -m_Fr[n]); if ((n = -node.m_ID[m_dofSU[0]] - 2) >= 0) node.set_load(m_dofSU[0], -m_Fr[n]); if ((n = -node.m_ID[m_dofSU[1]] - 2) >= 0) node.set_load(m_dofSU[1], -m_Fr[n]); if ((n = -node.m_ID[m_dofSU[2]] - 2) >= 0) node.set_load(m_dofSU[2], -m_Fr[n]); } // increase RHS counter m_nrhs++; return true; } //----------------------------------------------------------------------------- //! Calculates the contact forces void FEExplicitSolidSolver::ContactForces(FEGlobalVector& R) { FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); for (int i = 0; i<fem.SurfacePairConstraints(); ++i) { FEContactInterface* pci = dynamic_cast<FEContactInterface*>(fem.SurfacePairConstraint(i)); if (pci->IsActive()) pci->LoadVector(R, tp); } } //----------------------------------------------------------------------------- //! calculate the nonlinear constraint forces void FEExplicitSolidSolver::NonLinearConstraintForces(FEGlobalVector& R, const FETimeInfo& tp) { FEModel& fem = *GetFEModel(); int N = fem.NonlinearConstraints(); for (int i=0; i<N; ++i) { FENLConstraint* plc = fem.NonlinearConstraint(i); if (plc->IsActive()) plc->LoadVector(R, tp); } }
C++
3D
febiosoftware/FEBio
FEBioMech/FEActiveFiberContraction.cpp
.cpp
4,705
166
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEActiveFiberContraction.h" #include "FEElasticMaterial.h" #include <FECore/log.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEActiveFiberContraction, FEActiveContractionMaterial); ADD_PARAMETER(m_ascl , "ascl"); ADD_PARAMETER(m_Tmax , "Tmax"); ADD_PARAMETER(m_ca0 , "ca0"); ADD_PARAMETER(m_camax, "camax"); ADD_PARAMETER(m_beta , "beta"); ADD_PARAMETER(m_l0 , "l0"); ADD_PARAMETER(m_refl , "refl"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEActiveFiberContraction::FEActiveFiberContraction(FEModel* pfem) : FEActiveContractionMaterial(pfem) { m_ascl = 0; m_Tmax = 1.0; m_ca0 = 1.0; m_camax = 0.0; } //----------------------------------------------------------------------------- bool FEActiveFiberContraction::Init() { if (FEActiveContractionMaterial::Init() == false) return false; // for backward compatibility we set m_camax to m_ca0 if it is not defined if (m_camax == 0.0) m_camax = m_ca0; if (m_camax <= 0.0) { feLogError("camax must be larger than zero"); return false; } return true; } //----------------------------------------------------------------------------- mat3ds FEActiveFiberContraction::ActiveStress(FEMaterialPoint& mp, const vec3d& a0) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // get the deformation gradient mat3d F = pt.m_F; double J = pt.m_J; double Jm13 = pow(J, -1.0 / 3.0); // calculate the current material axis lam*a = F*a0; vec3d a = F*a0; // normalize material axis and store fiber stretch double lam, lamd; lam = a.unit(); lamd = lam*Jm13; // i.e. lambda tilde // calculate dyad of a: AxA = (a x a) mat3ds AxA = dyad(a); // get the activation double saf = 0.0; if (m_ascl > 0) { // current sarcomere length double strl = m_refl*lamd; // sarcomere length change double dl = strl - m_l0; if (dl >= 0) { // calcium sensitivity double eca50i = (exp(m_beta*dl) - 1); // ratio of Camax/Ca0 double rca = m_camax / m_ca0; // active fiber stress saf = m_Tmax*(eca50i / (eca50i + rca*rca))*m_ascl; } } return AxA*saf; } //----------------------------------------------------------------------------- tens4ds FEActiveFiberContraction::ActiveStiffness(FEMaterialPoint& mp, const vec3d& a0) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // get the deformation gradient mat3d F = pt.m_F; double J = pt.m_J; double Jm13 = pow(J, -1.0 / 3.0); // calculate the current material axis lam*a = F*a0; vec3d a = F*a0; // normalize material axis and store fiber stretch double lam, lamd; lam = a.unit(); lamd = lam*Jm13; // i.e. lambda tilde // calculate dyad of a: AxA = (a x a) mat3ds AxA = dyad(a); tens4ds AxAxAxA = dyad1s(AxA); double c = 0; if (m_ascl > 0) { // current sarcomere length double strl = m_refl*lamd; // sarcomere length change double dl = strl - m_l0; if (dl >= 0) { // calcium sensitivity double eca50i = (exp(m_beta*dl) - 1); double decl = m_beta*m_refl*exp(m_beta*dl); // ratio of Camax/Ca0 double rca = m_camax / m_ca0; double d = eca50i + rca*rca; // active fiber stress double saf = m_Tmax*(eca50i / d)*m_ascl; double dsf = m_Tmax*m_ascl*decl*(1.0/ d - eca50i / (d*d)); c = (lamd*dsf - 2.0*saf); } } return AxAxAxA*c; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEElasticMixture.h
.h
3,508
105
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEElasticMaterial.h" //----------------------------------------------------------------------------- //! Material point data for mixtures //! class FEElasticMixtureMaterialPoint : public FEMaterialPointArray { public: //! constructor FEElasticMixtureMaterialPoint(); //! Copy material point data FEMaterialPointData* Copy() override; //! material point initialization void Init() override; //! data serialization void Serialize(DumpStream& ar) override; public: vector<double> m_w; //!< material weights }; //----------------------------------------------------------------------------- //! Elastic mixtures //! This class describes a mixture of elastic solids. The user must declare //! elastic solids that can be combined within this class. The stress and //! tangent tensors evaluated in this class represent the sum of the respective //! tensors of all the solids forming the mixture. //! \todo This class defines two accessor interfaces. Modify to use the FEMaterial interface only. class FEElasticMixture : public FEElasticMaterial { public: FEElasticMixture(FEModel* pfem); // returns a pointer to a new material point object FEMaterialPointData* CreateMaterialPointData() override; // return number of materials int Materials() { return (int)m_pMat.size(); } // return a material component FEElasticMaterial* GetMaterial(int i) { return m_pMat[i]; } // Add a material component void AddMaterial(FEElasticMaterial* pm); //! specialized material points void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) override; public: //! data initialization bool Init() override; //! calculate stress at material point mat3ds Stress(FEMaterialPoint& pt) override; //! calculate tangent stiffness at material point tens4ds Tangent(FEMaterialPoint& pt) override; //! calculate strain energy density at material point double StrainEnergyDensity(FEMaterialPoint& pt) override; public: double StrongBondSED(FEMaterialPoint& pt) override; double WeakBondSED(FEMaterialPoint& pt) override; private: std::vector<FEElasticMaterial*> m_pMat; //!< pointers to elastic materials DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEElasticBeamMaterial.h
.h
3,123
100
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEMaterial.h> #include "febiomech_api.h" class FEElasticBeamMaterialPoint : public FEMaterialPointData { public: FEElasticBeamMaterialPoint(); void Init() override; //! The Update function is used to update material point data //! Note that this gets called at the start of the time step during PreSolveUpdate void Update(const FETimeInfo& timeInfo) override; public: vec3d m_t; // stress vector vec3d m_m; // moment vector // local coordinate system mat3d m_Q; // strain measures vec3d m_G0; vec3d m_Gamma; vec3d m_Kappa; // rotation information quatd m_Rp; // rotation at previous time step quatd m_Ri; // increment at current time step quatd m_Rt; // current rotation vec3d m_k; // spatial curvature vec3d m_kn; // spatial curvature at current increment (temp storage) // dynamics vec3d m_vt, m_vp; // linear velocity at current and previous time vec3d m_at, m_ap; // linear acceleration at current and previous time vec3d m_wt, m_wp; // (spatial) angular velocity at current and previous time vec3d m_alt, m_alp; // (spatial) angular acceleration at current and previous time vec3d m_dpt; // rate of linear momentum (current) vec3d m_dht; // rate of angular momentum (current) // for output mat3ds m_s; // Cauchy stress tensor in global coordinates }; class FEElasticBeamMaterial : public FEMaterial { public: FEElasticBeamMaterial(FEModel* fem); void Stress(FEElasticBeamMaterialPoint& mp); void Tangent(FEElasticBeamMaterialPoint& mp, matrix& C); FEMaterialPointData* CreateMaterialPointData() override; public: double m_density; double m_A, m_A1, m_A2; double m_E, m_G; double m_I1, m_I2; DECLARE_FECORE_CLASS(); }; class FEBIOMECH_API FEBeamStress : public FEDomainParameter { public: FEBeamStress(); FEParamValue value(FEMaterialPoint& mp) override; };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEUncoupledActiveContraction.h
.h
1,953
57
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEUncoupledMaterial.h" //----------------------------------------------------------------------------- // This material implements an active contraction model which can be used // as a component of an uncoupled solid matrix material. class FEUncoupledActiveContraction : public FEUncoupledMaterial { public: //! constructor FEUncoupledActiveContraction(FEModel* pfem); //! deviatoric stress mat3ds DevStress(FEMaterialPoint& pt) override; //! deviatoric tangent tens4ds DevTangent(FEMaterialPoint& pt) override; public: double m_Tmax; double m_ca0; double m_camax; double m_beta; double m_l0; double m_refl; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEIncompNeoHookean.h
.h
2,056
57
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEUncoupledMaterial.h" #include "febiomech_api.h" //----------------------------------------------------------------------------- //! Incompressible Neo-Hookean material class FEBIOMECH_API FEIncompNeoHookean : public FEUncoupledMaterial { public: FEIncompNeoHookean(FEModel* pfem); public: FEParamDouble m_G; //!< Shear modulus public: //! calculate deviatoric stress at material point mat3ds DevStress(FEMaterialPoint& pt) override; //! calculate deviatoric tangent stiffness at material point tens4ds DevTangent(FEMaterialPoint& pt) override; //! calculate deviatoric strain energy density at material point double DevStrainEnergyDensity(FEMaterialPoint& pt) override; // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FERigidPrismaticJoint.cpp
.cpp
29,923
960
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FERigidPrismaticJoint.h" #include "FERigidBody.h" #include "FECore/log.h" #include <FECore/FELinearSystem.h> #include <FECore/ad.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FERigidPrismaticJoint, FERigidConnector); ADD_PARAMETER(m_laugon, "laugon")->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0LAGMULT\0"); ADD_PARAMETER(m_atol, "tolerance" ); ADD_PARAMETER(m_gtol, "gaptol" ); ADD_PARAMETER(m_qtol, "angtol" ); ADD_PARAMETER(m_eps , "force_penalty" ); ADD_PARAMETER(m_ups , "moment_penalty"); ADD_PARAMETER(m_cps , "force_damping" ); ADD_PARAMETER(m_rps , "moment_damping"); ADD_PARAMETER(m_q0 , "joint_origin" ); ADD_PARAMETER(m_e0[0], "translation_axis" ); ADD_PARAMETER(m_e0[1], "transverse_axis"); ADD_PARAMETER(m_naugmin, "minaug" ); ADD_PARAMETER(m_naugmax, "maxaug" ); ADD_PARAMETER(m_bd , "prescribed_translation"); ADD_PARAMETER(m_dp , "translation" ); ADD_PARAMETER(m_Fp , "force" ); ADD_PARAMETER(m_bautopen, "auto_penalty"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FERigidPrismaticJoint::FERigidPrismaticJoint(FEModel* pfem) : FERigidConnector(pfem) { m_nID = m_ncount++; m_laugon = FECore::AUGLAG_METHOD; // for backward compatibility m_atol = 0; m_gtol = 0; m_qtol = 0; m_naugmin = 0; m_naugmax = 10; m_dp = 0; m_Fp = 0; m_bd = false; m_eps = m_ups = 1.0; m_cps = m_rps = 0.0; m_e0[0] = vec3d(1,0,0); m_e0[1] = vec3d(0,1,0); m_bautopen = false; } FERigidPrismaticJoint::~FERigidPrismaticJoint() { } //----------------------------------------------------------------------------- //! TODO: This function is called twice: once in the Init and once in the Solve //! phase. Is that necessary? bool FERigidPrismaticJoint::Init() { if (m_bd && (m_Fp != 0)) { feLogError("Translation and force cannot be prescribed simultaneously in rigid connector %d (prismatic joint)\n", m_nID+1); return false; } // initialize joint basis m_e0[0].unit(); m_e0[2] = m_e0[0] ^ m_e0[1]; m_e0[2].unit(); m_e0[1] = m_e0[2] ^ m_e0[0]; m_e0[1].unit(); // reset force m_F = vec3d(0,0,0); m_L = vec3d(0,0,0); m_M = vec3d(0,0,0); m_U = vec3d(0,0,0); m_U1 = m_U2 = vec3d(0, 0, 0); m_Lp = vec3d(0, 0, 0); m_U1p = m_U2p = vec3d(0, 0, 0); // base class first if (FERigidConnector::Init() == false) return false; m_qa0 = m_q0 - m_rbA->m_r0; m_qb0 = m_q0 - m_rbB->m_r0; m_ea0[0] = m_e0[0]; m_ea0[1] = m_e0[1]; m_ea0[2] = m_e0[2]; m_eb0[0] = m_e0[0]; m_eb0[1] = m_e0[1]; m_eb0[2] = m_e0[2]; return true; } //----------------------------------------------------------------------------- void FERigidPrismaticJoint::Serialize(DumpStream& ar) { FERigidConnector::Serialize(ar); ar & m_qa0 & m_qb0; ar & m_L & m_U; ar & m_e0; ar & m_ea0; ar & m_eb0; ar & m_U1 & m_U2 & m_LM; ar & m_Fp & m_U1p & m_U2p; } //----------------------------------------------------------------------------- //! initial position vec3d FERigidPrismaticJoint::InitialPosition() const { return m_q0; } //----------------------------------------------------------------------------- //! current position vec3d FERigidPrismaticJoint::Position() const { FERigidBody& RBa = *m_rbA; vec3d qa = m_qa0; RBa.GetRotation().RotateVector(qa); return RBa.m_rt + qa; } //----------------------------------------------------------------------------- //! current orientation quatd FERigidPrismaticJoint::Orientation() const { quatd Q0(vec3d(1, 0, 0), m_e0[0]); FERigidBody& RBa = *m_rbA; return RBa.GetRotation()*Q0; } //----------------------------------------------------------------------------- //! \todo Why is this class not using the FESolver for assembly? void FERigidPrismaticJoint::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { vector<double> fa(6); vector<double> fb(6); vec3d eat[3], eap[3], ea[3]; vec3d ebt[3], ebp[3], eb[3]; FERigidBody& RBa = *m_rbA; FERigidBody& RBb = *m_rbB; double alpha = tp.alphaf; // body A vec3d ra = RBa.m_rt*alpha + RBa.m_rp*(1-alpha); vec3d zat = m_qa0; RBa.GetRotation().RotateVector(zat); vec3d zap = m_qa0; RBa.m_qp.RotateVector(zap); vec3d za = zat*alpha + zap*(1-alpha); eat[0] = m_ea0[0]; RBa.GetRotation().RotateVector(eat[0]); eat[1] = m_ea0[1]; RBa.GetRotation().RotateVector(eat[1]); eat[2] = m_ea0[2]; RBa.GetRotation().RotateVector(eat[2]); eap[0] = m_ea0[0]; RBa.m_qp.RotateVector(eap[0]); eap[1] = m_ea0[1]; RBa.m_qp.RotateVector(eap[1]); eap[2] = m_ea0[2]; RBa.m_qp.RotateVector(eap[2]); ea[0] = eat[0]*alpha + eap[0]*(1-alpha); ea[1] = eat[1]*alpha + eap[1]*(1-alpha); ea[2] = eat[2]*alpha + eap[2]*(1-alpha); // body b vec3d rb = RBb.m_rt*alpha + RBb.m_rp*(1-alpha); vec3d zbt = m_qb0; RBb.GetRotation().RotateVector(zbt); vec3d zbp = m_qb0; RBb.m_qp.RotateVector(zbp); vec3d zb = zbt*alpha + zbp*(1-alpha); ebt[0] = m_eb0[0]; RBb.GetRotation().RotateVector(ebt[0]); ebt[1] = m_eb0[1]; RBb.GetRotation().RotateVector(ebt[1]); ebt[2] = m_eb0[2]; RBb.GetRotation().RotateVector(ebt[2]); ebp[0] = m_eb0[0]; RBb.m_qp.RotateVector(ebp[0]); ebp[1] = m_eb0[1]; RBb.m_qp.RotateVector(ebp[1]); ebp[2] = m_eb0[2]; RBb.m_qp.RotateVector(ebp[2]); eb[0] = ebt[0]*alpha + ebp[0]*(1-alpha); eb[1] = ebt[1]*alpha + ebp[1]*(1-alpha); eb[2] = ebt[2]*alpha + ebp[2]*(1-alpha); if (m_laugon != FECore::LAGMULT_METHOD) { // incremental compound rotation of B w.r.t. A vec3d vth = ((ea[0] ^ eb[0]) + (ea[1] ^ eb[1]) + (ea[2] ^ eb[2])) / 2; mat3ds P = m_bd ? mat3dd(1) : mat3dd(1) - dyad(ea[0]); vec3d p = m_bd ? ea[0] * m_dp : vec3d(0, 0, 0); vec3d c = P * (rb + zb - ra - za) - p; m_F = m_L + c * m_eps + ea[0] * m_Fp; vec3d ksi = vth; m_M = m_U + ksi * m_ups; // add damping if (m_cps > 0) { // body A vec3d vat = RBa.m_vt + (RBa.m_wt ^ zat); vec3d vap = RBa.m_vp + (RBa.m_wp ^ zap); vec3d va = vat * alpha + vap * (1 - alpha); // body b vec3d vbt = RBb.m_vt + (RBb.m_wt ^ zbt); vec3d vbp = RBb.m_vp + (RBb.m_wp ^ zbp); vec3d vb = vbt * alpha + vbp * (1 - alpha); m_F += P * (vb - va) * m_cps; } if (m_rps > 0) { // body A vec3d wa = RBa.m_wt * alpha + RBa.m_wp * (1 - alpha); // body b vec3d wb = RBb.m_wt * alpha + RBb.m_wp * (1 - alpha); m_M += (wb - wa) * m_rps; } fa[0] = m_F.x; fa[1] = m_F.y; fa[2] = m_F.z; fa[3] = za.y * m_F.z - za.z * m_F.y + m_M.x; fa[4] = za.z * m_F.x - za.x * m_F.z + m_M.y; fa[5] = za.x * m_F.y - za.y * m_F.x + m_M.z; fb[0] = -m_F.x; fb[1] = -m_F.y; fb[2] = -m_F.z; fb[3] = -zb.y * m_F.z + zb.z * m_F.y - m_M.x; fb[4] = -zb.z * m_F.x + zb.x * m_F.z - m_M.y; fb[5] = -zb.x * m_F.y + zb.y * m_F.x - m_M.z; for (int i = 0; i < 6; ++i) if (RBa.m_LM[i] >= 0) R[RBa.m_LM[i]] += fa[i]; for (int i = 0; i < 6; ++i) if (RBb.m_LM[i] >= 0) R[RBb.m_LM[i]] += fb[i]; } else { mat3dd I(1.0); mat3d P = I - dyad(ea[0]); vec3d d = rb + zb - ra - za; double ad = m_ea0[0] * d; mat3d D = I * (ad) + (ea[0] & d); mat3d DT = D.transpose(); mat3da eahat(ea[0]); vec3d F = P * m_F; vec3d Ma = (za ^ F) + eahat*(DT*m_F); vec3d Mb = (zb ^ F); fa[0] = -F.x; fa[1] = -F.y; fa[2] = -F.z; fa[3] = -Ma.x; fa[4] = -Ma.y; fa[5] = -Ma.z; fb[0] = F.x; fb[1] = F.y; fb[2] = F.z; fb[3] = Mb.x; fb[4] = Mb.y; fb[5] = Mb.z; for (int i = 0; i < 6; ++i) if (RBa.m_LM[i] >= 0) R[RBa.m_LM[i]] += fa[i]; for (int i = 0; i < 6; ++i) if (RBb.m_LM[i] >= 0) R[RBb.m_LM[i]] += fb[i]; // translational constraint vec3d c = P*d; R[m_LM[0]] += c.x; R[m_LM[1]] += c.y; R[m_LM[2]] += c.z; // rotational constraint vec3d ksi1 = eb[0] - ea[0]; vec3d ksi2 = eb[1] - ea[1]; R[m_LM[3]] += ksi1.x; R[m_LM[4]] += ksi1.y; R[m_LM[5]] += ksi1.z; R[m_LM[6]] += ksi2.x; R[m_LM[7]] += ksi2.y; R[m_LM[8]] += ksi2.z; } RBa.m_Fr -= vec3d(fa[0],fa[1],fa[2]); RBa.m_Mr -= vec3d(fa[3],fa[4],fa[5]); RBb.m_Fr -= vec3d(fb[0],fb[1],fb[2]); RBb.m_Mr -= vec3d(fb[3],fb[4],fb[5]); } //----------------------------------------------------------------------------- //! \todo Why is this class not using the FESolver for assembly? void FERigidPrismaticJoint::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { double alpha = tp.alphaf; double beta = tp.beta; double gamma = tp.gamma; // get time increment double dt = tp.timeIncrement; vec3d eat[3], eap[3], ea[3]; vec3d ebt[3], ebp[3], eb[3]; FERigidBody& RBa = *m_rbA; FERigidBody& RBb = *m_rbB; // body A quatd Qat = RBa.GetRotation(); quatd Qap = RBa.m_qp; vec3d rat = RBa.m_rt; vec3d rap = RBa.m_rp; vec3d ra = rat * alpha + rap * (1 - alpha); vec3d zat = Qat * m_qa0; vec3d zap = Qap * m_qa0; vec3d za = zat * alpha + zap * (1 - alpha); eat[0] = m_ea0[0]; RBa.GetRotation().RotateVector(eat[0]); eat[1] = m_ea0[1]; RBa.GetRotation().RotateVector(eat[1]); eat[2] = m_ea0[2]; RBa.GetRotation().RotateVector(eat[2]); eap[0] = m_ea0[0]; RBa.m_qp.RotateVector(eap[0]); eap[1] = m_ea0[1]; RBa.m_qp.RotateVector(eap[1]); eap[2] = m_ea0[2]; RBa.m_qp.RotateVector(eap[2]); ea[0] = eat[0]*alpha + eap[0]*(1-alpha); ea[1] = eat[1]*alpha + eap[1]*(1-alpha); ea[2] = eat[2]*alpha + eap[2]*(1-alpha); mat3d zahat; zahat.skew(za); mat3d zathat; zathat.skew(zat); // body b quatd Qbt = RBb.GetRotation(); quatd Qbp = RBb.m_qp; vec3d rbt = RBb.m_rt; vec3d rbp = RBb.m_rp; vec3d rb = rbt * alpha + rbp * (1 - alpha); vec3d zbt = Qbt * m_qb0; vec3d zbp = Qbp * m_qb0; vec3d zb = zbt * alpha + zbp * (1 - alpha); ebt[0] = m_eb0[0]; RBb.GetRotation().RotateVector(ebt[0]); ebt[1] = m_eb0[1]; RBb.GetRotation().RotateVector(ebt[1]); ebt[2] = m_eb0[2]; RBb.GetRotation().RotateVector(ebt[2]); ebp[0] = m_eb0[0]; RBb.m_qp.RotateVector(ebp[0]); ebp[1] = m_eb0[1]; RBb.m_qp.RotateVector(ebp[1]); ebp[2] = m_eb0[2]; RBb.m_qp.RotateVector(ebp[2]); eb[0] = ebt[0]*alpha + ebp[0]*(1-alpha); eb[1] = ebt[1]*alpha + ebp[1]*(1-alpha); eb[2] = ebt[2]*alpha + ebp[2]*(1-alpha); mat3d zbhat; zbhat.skew(zb); mat3d zbthat; zbthat.skew(zbt); if (m_laugon != FECore::LAGMULT_METHOD) { // incremental compound rotation of B w.r.t. A vec3d vth = ((ea[0] ^ eb[0]) + (ea[1] ^ eb[1]) + (ea[2] ^ eb[2])) / 2; mat3ds P = m_bd ? mat3dd(1) : mat3dd(1) - dyad(ea[0]); vec3d p = m_bd ? ea[0] * m_dp : vec3d(0, 0, 0); vec3d d = rb + zb - ra - za; vec3d c = P * d - p; m_F = m_L + c * m_eps + ea[0] * m_Fp; vec3d ksi = vth; m_M = m_U + ksi * m_ups; mat3d eahat[3], ebhat[3], eathat[3], ebthat[3]; for (int j = 0; j < 3; ++j) { eahat[j] = skew(ea[j]); ebhat[j] = skew(eb[j]); eathat[j] = skew(eat[j]); ebthat[j] = skew(ebt[j]); } mat3d Q = m_bd ? eathat[0] * m_dp : ((ea[0] & d) + mat3dd(1) * (ea[0] * d)) * eathat[0]; mat3d Wba = (ebhat[0] * eathat[0] + ebhat[1] * eathat[1] + ebhat[2] * eathat[2]) / 2; mat3d Wab = (eahat[0] * ebthat[0] + eahat[1] * ebthat[1] + eahat[2] * ebthat[2]) / 2; mat3d K; // add damping mat3ds A; mat3d Ba, Bb, Ca, Cb; A.zero(); Ba.zero(); Bb.zero(); Ca.zero(); Cb.zero(); if ((m_cps > 0) || (m_rps > 0)) { mat3dd I(1); // body A vec3d vat = RBa.m_vt + (RBa.m_wt ^ zat); vec3d vap = RBa.m_vp + (RBa.m_wp ^ zap); vec3d va = vat * alpha + vap * (1 - alpha); quatd qai = RBa.GetRotation() * RBa.m_qp.Inverse(); qai.MakeUnit(); vec3d cai = qai.GetVector() * (2 * tan(qai.GetAngle() / 2)); mat3d Ta = I + skew(cai) / 2 + dyad(cai) / 4; vec3d wa = RBa.m_wt * alpha + RBa.m_wp * (1 - alpha); // body b vec3d vbt = RBb.m_vt + (RBb.m_wt ^ zbt); vec3d vbp = RBb.m_vp + (RBb.m_wp ^ zbp); vec3d vb = vbt * alpha + vbp * (1 - alpha); quatd qbi = RBb.GetRotation() * RBb.m_qp.Inverse(); qbi.MakeUnit(); vec3d cbi = qbi.GetVector() * (2 * tan(qbi.GetAngle() / 2)); mat3d Tb = I + skew(cbi) / 2 + dyad(cbi) / 4; vec3d wb = RBb.m_wt * alpha + RBb.m_wp * (1 - alpha); m_F += (vb - va) * m_cps; vec3d w = wb - wa; m_M += P * w * m_rps; A = P * (gamma / beta / dt); Ba = P * (zathat * Ta.transpose() * (gamma / beta / dt) + skew(RBa.m_wt) * zathat); Bb = P * (zbthat * Tb.transpose() * (gamma / beta / dt) + skew(RBb.m_wt) * zbthat); Ca = Ta.transpose() * (gamma / beta / dt); Cb = Tb.transpose() * (gamma / beta / dt); } mat3da Fhat(m_F); FEElementMatrix ke(12, 12); ke.zero(); // row 1 ke.set(0, 0, P * (m_eps)+A * (m_cps)); ke.set(0, 3, (P * zathat + Q) * (-m_eps) + eathat[0]*m_Fp + Ba*(-m_cps)); ke.set(0, 6, P * (-m_eps) + A * (-m_cps)); ke.set(0, 9, P * zbthat * (m_eps)+Bb * (m_cps)); // row 2 ke.set(3, 0, zahat*P*m_eps + zahat*A*m_cps); ke.set(3, 3, zahat*(P * zathat + Q) * (-m_eps) - Fhat * zathat - Wba * m_ups - (zahat * Ba) * m_cps - Ca * m_rps); ke.set(3, 6, zahat*P * (-m_eps) + zahat * A * (-m_cps)); ke.set(3, 9, zahat*P * zbthat * m_eps + Wab * m_ups + zahat * Bb * m_cps + Cb * m_rps); // row 3 ke.set(6, 0, P * (-m_eps) + A * (-m_cps)); ke.set(6, 3, (P * zathat + Q)*m_eps - eathat[0]*m_Fp + Ba*m_cps); ke.set(6, 6, P*m_eps + A*m_cps); ke.set(6, 9, P*zbthat*(-m_eps) - Bb*m_cps); // row 4 ke.set(9, 0, zbhat*P*(-m_eps) - zbhat*A*m_cps); ke.set(9, 3, zbhat * (P * zathat + Q) * m_eps + Wba * m_ups + (zbhat * Ba) * m_cps + Ca * m_rps); ke.set(9, 6, zbhat * P * (m_eps)+zbhat * A * (m_cps)); ke.set(9, 9, zbhat * P * zbthat * (-m_eps) + Fhat * zbthat - Wab * m_ups - (zbhat * Bb) * m_cps - Cb * m_rps); ke *= alpha; vector<int> LM(12); for (int j = 0; j < 6; ++j) { LM[j ] = RBa.m_LM[j]; LM[j + 6] = RBb.m_LM[j]; } ke.SetIndices(LM); LS.Assemble(ke); } else { dd::vec3d pa(ra); dd::quatd qa(Qat); dd::vec3d pb(rb); dd::quatd qb(Qbt); dd::vec3d lam(m_F); dd::vec3d mu1(m_U1); dd::vec3d mu2(m_U2); auto F = [&]() { dd::vec3d a = qa * m_ea0[0]; return lam - a*(lam*a); }; auto c = [&]() { dd::vec3d za = qa * m_qa0; dd::vec3d zb = qb * m_qb0; dd::vec3d d = pb + zb - pa - za; dd::vec3d a = qa * m_ea0[0]; return d - a*(d*a); }; auto m1 = [&]() { dd::vec3d a1 = qa * m_ea0[0]; dd::vec3d b1 = qb * m_eb0[0]; return b1 - a1; }; auto m2 = [&]() { dd::vec3d a2 = qa * m_ea0[1]; dd::vec3d b2 = qb * m_eb0[1]; return b2 - a2; }; auto Ma = [&] { dd::vec3d za = qa * m_qa0; dd::vec3d ea0 = qa * m_ea0[0]; dd::vec3d ea1 = qa * m_ea0[1]; dd::vec3d d = pb + zb - pa - za; dd::vec3d t = lam * (ea0 * d) + d * (ea0 * lam); return (za ^ lam) + (ea0 ^ t) + (ea0 ^ mu1) + (ea1 ^ mu2); }; auto Mb = [&] { dd::vec3d zb = qb * m_qb0; dd::vec3d eb0 = qb * m_eb0[0]; dd::vec3d eb1 = qb * m_eb0[1]; return (zb ^ lam) + (eb0 ^ mu1) + (eb1 ^ mu2); }; mat3d K00 = -dd::D( F, pa); mat3d K10 = -dd::D(Ma, pa); mat3d K20 = dd::D( F, pa); mat3d K30 = dd::D(Mb, pa); mat3d K40 = dd::D( c, pa); mat3d K50 = dd::D(m1, pa); mat3d K60 = dd::D(m2, pa); mat3d K01 = -dd::D( F, qa); mat3d K11 = -dd::D(Ma, qa); mat3d K21 = dd::D( F, qa); mat3d K31 = dd::D(Mb, qa); mat3d K41 = dd::D( c, qa); mat3d K51 = dd::D(m1, qa); mat3d K61 = dd::D(m2, qa); mat3d K02 = -dd::D( F, pb); mat3d K12 = -dd::D(Ma, pb); mat3d K22 = dd::D( F, pb); mat3d K32 = dd::D(Mb, pb); mat3d K42 = dd::D( c, pb); mat3d K52 = dd::D(m1, pb); mat3d K62 = dd::D(m2, pb); mat3d K03 = -dd::D( F, qb); mat3d K13 = -dd::D(Ma, qb); mat3d K23 = dd::D( F, qb); mat3d K33 = dd::D(Mb, qb); mat3d K43 = dd::D( c, qb); mat3d K53 = dd::D(m1, qb); mat3d K63 = dd::D(m2, qb); mat3d K04 = -dd::D( F, lam); mat3d K14 = -dd::D(Ma, lam); mat3d K24 = dd::D( F, lam); mat3d K34 = dd::D(Mb, lam); mat3d K44 = dd::D( c, lam); mat3d K54 = dd::D(m1, lam); mat3d K64 = dd::D(m2, lam); mat3d K05 = -dd::D( F, mu1); mat3d K15 = -dd::D(Ma, mu1); mat3d K25 = dd::D( F, mu1); mat3d K35 = dd::D(Mb, mu1); mat3d K45 = dd::D( c, mu1); mat3d K55 = dd::D(m1, mu1); mat3d K65 = dd::D(m2, mu1); mat3d K06 = -dd::D( F, mu2); mat3d K16 = -dd::D(Ma, mu2); mat3d K26 = dd::D( F, mu2); mat3d K36 = dd::D(Mb, mu2); mat3d K46 = dd::D( c, mu2); mat3d K56 = dd::D(m1, mu2); mat3d K66 = dd::D(m2, mu2); matrix kd(21, 21); kd.zero(); kd.sub( 0, 0, K00); kd.sub( 0, 3, K01); kd.sub( 0, 6, K02); kd.sub( 0, 9, K03); kd.sub( 0, 12, K04); kd.sub( 0, 15, K05); kd.sub( 0, 18, K06); kd.sub( 3, 0, K10); kd.sub( 3, 3, K11); kd.sub( 3, 6, K12); kd.sub( 3, 9, K13); kd.sub( 3, 12, K14); kd.sub( 3, 15, K15); kd.sub( 3, 18, K16); kd.sub( 6, 0, K20); kd.sub( 6, 3, K21); kd.sub( 6, 6, K22); kd.sub( 6, 9, K23); kd.sub( 6, 12, K24); kd.sub( 6, 15, K25); kd.sub( 6, 18, K26); kd.sub( 9, 0, K30); kd.sub( 9, 3, K31); kd.sub( 9, 6, K32); kd.sub( 9, 9, K33); kd.sub( 9, 12, K34); kd.sub( 9, 15, K35); kd.sub( 9, 18, K36); kd.sub(12, 0, K40); kd.sub(12, 3, K41); kd.sub(12, 6, K42); kd.sub(12, 9, K43); kd.sub(12, 12, K44); kd.sub(12, 15, K45); kd.sub(12, 18, K46); kd.sub(15, 0, K50); kd.sub(15, 3, K51); kd.sub(15, 6, K52); kd.sub(15, 9, K53); kd.sub(15, 12, K54); kd.sub(15, 15, K55); kd.sub(15, 18, K56); kd.sub(18, 0, K60); kd.sub(18, 3, K61); kd.sub(18, 6, K62); kd.sub(18, 9, K63); kd.sub(18, 12, K64); kd.sub(18, 15, K65); kd.sub(18, 18, K66); FEElementMatrix ke(21, 21); ke = kd; vector<int> LM(21); UnpackLM(LM); ke.SetIndices(LM); LS.Assemble(ke); } } //----------------------------------------------------------------------------- bool FERigidPrismaticJoint::Augment(int naug, const FETimeInfo& tp) { if (m_laugon != FECore::AUGLAG_METHOD) return true; vec3d ra, rb, qa, qb, c, ksi, Lm; vec3d za, zb; vec3d eat[3], eap[3], ea[3]; vec3d ebt[3], ebp[3], eb[3]; double normF0, normF1; vec3d Um; double normM0, normM1; bool bconv = true; FERigidBody& RBa = *m_rbA; FERigidBody& RBb = *m_rbB; double alpha = tp.alphaf; ra = RBa.m_rt*alpha + RBa.m_rp*(1-alpha); rb = RBb.m_rt*alpha + RBb.m_rp*(1-alpha); vec3d zat = m_qa0; RBa.GetRotation().RotateVector(zat); vec3d zap = m_qa0; RBa.m_qp.RotateVector(zap); za = zat*alpha + zap*(1-alpha); eat[0] = m_ea0[0]; RBa.GetRotation().RotateVector(eat[0]); eat[1] = m_ea0[1]; RBa.GetRotation().RotateVector(eat[1]); eat[2] = m_ea0[2]; RBa.GetRotation().RotateVector(eat[2]); eap[0] = m_ea0[0]; RBa.m_qp.RotateVector(eap[0]); eap[1] = m_ea0[1]; RBa.m_qp.RotateVector(eap[1]); eap[2] = m_ea0[2]; RBa.m_qp.RotateVector(eap[2]); ea[0] = eat[0]*alpha + eap[0]*(1-alpha); ea[1] = eat[1]*alpha + eap[1]*(1-alpha); ea[2] = eat[2]*alpha + eap[2]*(1-alpha); vec3d zbt = m_qb0; RBb.GetRotation().RotateVector(zbt); vec3d zbp = m_qb0; RBb.m_qp.RotateVector(zbp); zb = zbt*alpha + zbp*(1-alpha); ebt[0] = m_eb0[0]; RBb.GetRotation().RotateVector(ebt[0]); ebt[1] = m_eb0[1]; RBb.GetRotation().RotateVector(ebt[1]); ebt[2] = m_eb0[2]; RBb.GetRotation().RotateVector(ebt[2]); ebp[0] = m_eb0[0]; RBb.m_qp.RotateVector(ebp[0]); ebp[1] = m_eb0[1]; RBb.m_qp.RotateVector(ebp[1]); ebp[2] = m_eb0[2]; RBb.m_qp.RotateVector(ebp[2]); eb[0] = ebt[0]*alpha + ebp[0]*(1-alpha); eb[1] = ebt[1]*alpha + ebp[1]*(1-alpha); eb[2] = ebt[2]*alpha + ebp[2]*(1-alpha); // incremental compound rotation of B w.r.t. A vec3d vth = ((ea[0] ^ eb[0]) + (ea[1] ^ eb[1]) + (ea[2] ^ eb[2]))/2; mat3ds P = m_bd ? mat3dd(1) : mat3dd(1) - dyad(ea[0]); vec3d p = m_bd ? ea[0]*m_dp : vec3d(0,0,0); c = P*(rb + zb - ra - za) - p; normF0 = sqrt(m_L*m_L); // calculate trial multiplier Lm = m_L + c*m_eps; normF1 = sqrt(Lm*Lm); ksi = vth; normM0 = sqrt(m_U*m_U); // calculate trial multiplier Um = m_U + ksi*m_ups; normM1 = sqrt(Um*Um); // check convergence of constraints feLog(" rigid connector # %d (prismatic joint)\n", m_nID+1); feLog(" CURRENT REQUIRED\n"); double pctn = 0; double gap = c.norm(); double qap = ksi.norm(); if (fabs(normF1) > 1e-10) pctn = fabs((normF1 - normF0)/normF1); if (m_atol) feLog(" force : %15le %15le\n", pctn, m_atol); else feLog(" force : %15le ***\n", pctn); if (m_gtol) feLog(" gap : %15le %15le\n", gap, m_gtol); else feLog(" gap : %15le ***\n", gap); double qctn = 0; if (fabs(normM1) > 1e-10) qctn = fabs((normM1 - normM0)/normM1); if (m_atol) feLog(" moment: %15le %15le\n", qctn, m_atol); else feLog(" moment: %15le ***\n", qctn); if (m_qtol) feLog(" angle : %15le %15le\n", qap, m_qtol); else feLog(" angle : %15le ***\n", qap); if (m_atol && ((pctn >= m_atol) || (qctn >= m_atol))) bconv = false; if (m_gtol && (gap >= m_gtol)) bconv = false; if (m_qtol && (qap >= m_qtol)) bconv = false; if (naug < m_naugmin ) bconv = false; if (naug >= m_naugmax) bconv = true; if (!bconv) { // update multipliers m_L = Lm; m_U = Um; } // auto-penalty update (works only with gaptol and angtol) if (m_bautopen) { if (m_gtol && (gap > m_gtol)) { m_eps = fmax(gap / m_gtol, 100)*m_eps; feLog(" force_penalty : %15le\n", m_eps); } if (m_qtol && (qap > m_qtol)) { m_ups = fmax(qap / m_qtol, 100)*m_ups; feLog(" moment_penalty : %15le\n", m_ups); } } return bconv; } //----------------------------------------------------------------------------- void FERigidPrismaticJoint::Update() { if (m_laugon == FECore::LAGMULT_METHOD) return; vec3d ra, rb; vec3d za, zb; vec3d eat[3], eap[3], ea[3]; vec3d ebt[3], ebp[3], eb[3]; FERigidBody& RBa = *m_rbA; FERigidBody& RBb = *m_rbB; const FETimeInfo& tp = GetTimeInfo(); double alpha = tp.alphaf; ra = RBa.m_rt*alpha + RBa.m_rp*(1-alpha); rb = RBb.m_rt*alpha + RBb.m_rp*(1-alpha); vec3d zat = m_qa0; RBa.GetRotation().RotateVector(zat); vec3d zap = m_qa0; RBa.m_qp.RotateVector(zap); za = zat*alpha + zap*(1-alpha); eat[0] = m_ea0[0]; RBa.GetRotation().RotateVector(eat[0]); eat[1] = m_ea0[1]; RBa.GetRotation().RotateVector(eat[1]); eat[2] = m_ea0[2]; RBa.GetRotation().RotateVector(eat[2]); eap[0] = m_ea0[0]; RBa.m_qp.RotateVector(eap[0]); eap[1] = m_ea0[1]; RBa.m_qp.RotateVector(eap[1]); eap[2] = m_ea0[2]; RBa.m_qp.RotateVector(eap[2]); ea[0] = eat[0]*alpha + eap[0]*(1-alpha); ea[1] = eat[1]*alpha + eap[1]*(1-alpha); ea[2] = eat[2]*alpha + eap[2]*(1-alpha); vec3d zbt = m_qb0; RBb.GetRotation().RotateVector(zbt); vec3d zbp = m_qb0; RBb.m_qp.RotateVector(zbp); zb = zbt*alpha + zbp*(1-alpha); ebt[0] = m_eb0[0]; RBb.GetRotation().RotateVector(ebt[0]); ebt[1] = m_eb0[1]; RBb.GetRotation().RotateVector(ebt[1]); ebt[2] = m_eb0[2]; RBb.GetRotation().RotateVector(ebt[2]); ebp[0] = m_eb0[0]; RBb.m_qp.RotateVector(ebp[0]); ebp[1] = m_eb0[1]; RBb.m_qp.RotateVector(ebp[1]); ebp[2] = m_eb0[2]; RBb.m_qp.RotateVector(ebp[2]); eb[0] = ebt[0]*alpha + ebp[0]*(1-alpha); eb[1] = ebt[1]*alpha + ebp[1]*(1-alpha); eb[2] = ebt[2]*alpha + ebp[2]*(1-alpha); // incremental compound rotation of B w.r.t. A vec3d vth = ((ea[0] ^ eb[0]) + (ea[1] ^ eb[1]) + (ea[2] ^ eb[2]))/2; mat3ds P = m_bd ? mat3dd(1) : mat3dd(1) - dyad(ea[0]); vec3d p = m_bd ? ea[0]*m_dp : vec3d(0,0,0); vec3d c = P*(rb + zb - ra - za) - p; m_F = m_L + c*m_eps + ea[0]*m_Fp; vec3d ksi = vth; m_M = m_U + ksi*m_ups; // add damping if (m_cps > 0) { // body A vec3d vat = RBa.m_vt + (RBa.m_wt ^ zat); vec3d vap = RBa.m_vp + (RBa.m_wp ^ zap); vec3d va = vat*alpha + vap*(1-alpha); // body b vec3d vbt = RBb.m_vt + (RBb.m_wt ^ zbt); vec3d vbp = RBb.m_vp + (RBb.m_wp ^ zbp); vec3d vb = vbt*alpha + vbp*(1-alpha); m_F += P*(vb - va)*m_cps; } if (m_rps > 0) { // body A vec3d wa = RBa.m_wt*alpha + RBa.m_wp*(1-alpha); // body b vec3d wb = RBb.m_wt*alpha + RBb.m_wp*(1-alpha); m_M += (wb - wa)*m_rps; } } //----------------------------------------------------------------------------- void FERigidPrismaticJoint::Reset() { m_F = vec3d(0,0,0); m_L = vec3d(0,0,0); m_M = vec3d(0,0,0); m_U = vec3d(0,0,0); FERigidBody& RBa = *m_rbA; FERigidBody& RBb = *m_rbB; m_qa0 = m_q0 - RBa.m_r0; m_qb0 = m_q0 - RBb.m_r0; m_ea0[0] = m_e0[0]; m_ea0[1] = m_e0[1]; m_ea0[2] = m_e0[2]; m_eb0[0] = m_e0[0]; m_eb0[1] = m_e0[1]; m_eb0[2] = m_e0[2]; } //----------------------------------------------------------------------------- vec3d FERigidPrismaticJoint::RelativeTranslation(const bool global) { FERigidBody& RBa = *m_rbA; FERigidBody& RBb = *m_rbB; // body A vec3d ra = RBa.m_rt; vec3d za = m_qa0; RBa.GetRotation().RotateVector(za); // body B vec3d rb = RBb.m_rt; vec3d zb = m_qb0; RBb.GetRotation().RotateVector(zb); // relative translation in global coordinate system vec3d x = rb + zb - ra - za; if (global) return x; // evaluate local basis for body A vec3d ea[3]; ea[0] = m_ea0[0]; RBa.GetRotation().RotateVector(ea[0]); ea[1] = m_ea0[1]; RBa.GetRotation().RotateVector(ea[1]); ea[2] = m_ea0[2]; RBa.GetRotation().RotateVector(ea[2]); // project relative translation onto local basis vec3d y(x*ea[0], x*ea[1], x*ea[2]); return y; } //----------------------------------------------------------------------------- vec3d FERigidPrismaticJoint::RelativeRotation(const bool global) { FERigidBody& RBa = *m_rbA; FERigidBody& RBb = *m_rbB; // get relative rotation quatd Q = RBb.GetRotation()*RBa.GetRotation().Inverse(); Q.MakeUnit(); // relative rotation vector vec3d q = Q.GetRotationVector(); if (global) return q; // evaluate local basis for body A vec3d ea[3]; ea[0] = m_ea0[0]; RBa.GetRotation().RotateVector(ea[0]); ea[1] = m_ea0[1]; RBa.GetRotation().RotateVector(ea[1]); ea[2] = m_ea0[2]; RBa.GetRotation().RotateVector(ea[2]); // project relative rotation onto local basis vec3d y(q*ea[0], q*ea[1], q*ea[2]); return y; } // allocate equations int FERigidPrismaticJoint::InitEquations(int neq) { const int LMeq = 9; m_LM.resize(LMeq, -1); if (m_laugon == FECore::LAGMULT_METHOD) { for (int i = 0; i < LMeq; ++i) m_LM[i] = neq + i; return LMeq; } else return 0; } // Build the matrix profile void FERigidPrismaticJoint::BuildMatrixProfile(FEGlobalMatrix& M) { vector<int> lm; UnpackLM(lm); // add it to the pile M.build_add(lm); } void FERigidPrismaticJoint::UnpackLM(vector<int>& lm) { // add the dofs of rigid body A lm.resize(21); lm[0] = m_rbA->m_LM[0]; lm[1] = m_rbA->m_LM[1]; lm[2] = m_rbA->m_LM[2]; lm[3] = m_rbA->m_LM[3]; lm[4] = m_rbA->m_LM[4]; lm[5] = m_rbA->m_LM[5]; // add the dofs of rigid body B lm[6] = m_rbB->m_LM[0]; lm[7] = m_rbB->m_LM[1]; lm[8] = m_rbB->m_LM[2]; lm[9] = m_rbB->m_LM[3]; lm[10] = m_rbB->m_LM[4]; lm[11] = m_rbB->m_LM[5]; // add the LM equations if (m_laugon == FECore::LAGMULT_METHOD) { for (int i = 0; i < m_LM.size(); ++i) lm[12 + i] = m_LM[i]; } } void FERigidPrismaticJoint::PrepStep() { m_Lp = m_F; m_U1p = m_U1; m_U2p = m_U2; } void FERigidPrismaticJoint::Update(const std::vector<double>& Ui, const std::vector<double>& ui) { if (m_laugon == FECore::LAGMULT_METHOD) { m_F.x = m_Lp.x + Ui[m_LM[0]] + ui[m_LM[0]]; m_F.y = m_Lp.y + Ui[m_LM[1]] + ui[m_LM[1]]; m_F.z = m_Lp.z + Ui[m_LM[2]] + ui[m_LM[2]]; m_U1.x = m_U1p.x + Ui[m_LM[3]] + ui[m_LM[3]]; m_U1.y = m_U1p.y + Ui[m_LM[4]] + ui[m_LM[4]]; m_U1.z = m_U1p.z + Ui[m_LM[5]] + ui[m_LM[5]]; m_U2.x = m_U2p.x + Ui[m_LM[6]] + ui[m_LM[6]]; m_U2.y = m_U2p.y + Ui[m_LM[7]] + ui[m_LM[7]]; m_U2.z = m_U2p.z + Ui[m_LM[8]] + ui[m_LM[8]]; m_M = m_U1 + m_U2; } } void FERigidPrismaticJoint::UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) { if (m_laugon == FECore::LAGMULT_METHOD) { for (int n : m_LM) Ui[n] += ui[n]; } }
C++
3D
febiosoftware/FEBio
FEBioMech/FEDamageMaterial.cpp
.cpp
4,302
133
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEDamageMaterial.h" #include "FEDamageCriterion.h" #include "FEDamageCDF.h" #include "FEUncoupledMaterial.h" #include <FECore/log.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEDamageMaterial, FEElasticMaterial) // set material properties ADD_PROPERTY(m_pBase, "elastic"); ADD_PROPERTY(m_pDamg, "damage"); ADD_PROPERTY(m_pCrit, "criterion"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEDamageMaterial::FEDamageMaterial(FEModel* pfem) : FEElasticMaterial(pfem) { m_pBase = 0; m_pDamg = 0; m_pCrit = 0; } //----------------------------------------------------------------------------- // returns a pointer to a new material point object FEMaterialPointData* FEDamageMaterial::CreateMaterialPointData() { return new FEDamageMaterialPoint(m_pBase->CreateMaterialPointData()); } //----------------------------------------------------------------------------- //! Initialization. bool FEDamageMaterial::Init() { FEUncoupledMaterial* m_pMat = dynamic_cast<FEUncoupledMaterial*>((FEElasticMaterial*)m_pBase); if (m_pMat != nullptr) { feLogError("Elastic material should not be of type uncoupled"); return false; } return FEElasticMaterial::Init(); } //----------------------------------------------------------------------------- //! calculate stress at material point mat3ds FEDamageMaterial::Stress(FEMaterialPoint& pt) { // evaluate the damage double d = Damage(pt); // evaluate the stress mat3ds s = m_pBase->Stress(pt); // return damaged stress return s*(1-d); } //----------------------------------------------------------------------------- //! calculate tangent stiffness at material point tens4ds FEDamageMaterial::Tangent(FEMaterialPoint& pt) { // evaluate the damage double d = Damage(pt); // evaluate the tangent tens4ds c = m_pBase->Tangent(pt); // return damaged tangent return c*(1-d); } //----------------------------------------------------------------------------- //! calculate strain energy density at material point double FEDamageMaterial::StrainEnergyDensity(FEMaterialPoint& pt) { // evaluate the damage double d = Damage(pt); // evaluate the strain energy density double sed = m_pBase->StrainEnergyDensity(pt); // return damaged sed return sed*(1-d); } //----------------------------------------------------------------------------- //! calculate damage at material point double FEDamageMaterial::Damage(FEMaterialPoint& pt) { // get the damage material point data FEDamageMaterialPoint& pd = *pt.ExtractData<FEDamageMaterialPoint>(); // evaluate the trial value of the damage criterion // this must be done before evaluating the damage pd.m_Etrial = m_pCrit->DamageCriterion(pt); // evaluate and set the damage double d = m_pDamg->Damage(pt); pd.m_D = d; return d; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEFungOrthotropic.cpp
.cpp
8,720
257
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEFungOrthotropic.h" #include <FECore/log.h> // define the material parameters BEGIN_FECORE_CLASS(FEFungOrthotropic, FEUncoupledMaterial) ADD_PARAMETER(E1, FE_RANGE_GREATER(0.0), "E1")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(E2, FE_RANGE_GREATER(0.0), "E2")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(E3, FE_RANGE_GREATER(0.0), "E3")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(G12, FE_RANGE_GREATER_OR_EQUAL(0.0), "G12")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(G23, FE_RANGE_GREATER_OR_EQUAL(0.0), "G23")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(G31, FE_RANGE_GREATER_OR_EQUAL(0.0), "G31")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(v12, "v12"); ADD_PARAMETER(v23, "v23"); ADD_PARAMETER(v31, "v31"); ADD_PARAMETER(m_c, FE_RANGE_GREATER(0.0), "c")->setUnits(UNIT_PRESSURE); ADD_PROPERTY(m_Q, "mat_axis")->SetFlags(FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEFungOrthotropic::FEFungOrthotropic(FEModel* pfem) : FEUncoupledMaterial(pfem) { } //----------------------------------------------------------------------------- //! Data initialization bool FEFungOrthotropic::Validate() { if (FEUncoupledMaterial::Validate() == false) return false; if (v12 > sqrt(E1/E2)) { feLogError("Invalid value for v12. Let v12 <= sqrt(E1/E2)"); return false; } if (v23 > sqrt(E2/E3)) { feLogError("Invalid value for v23. Let v23 <= sqrt(E2/E3)"); return false; } if (v31 > sqrt(E3/E1)) { feLogError("Invalid value for v31. Let v31 <= sqrt(E3/E1)"); return false; } // Evaluate Lame coefficients mu[0] = G12 + G31 - G23; mu[1] = G12 - G31 + G23; mu[2] =-G12 + G31 + G23; lam[0][0] = 1.0/E1; lam[0][1] = -v12/E1; lam[0][2] = -v31/E3; lam[1][0] = -v12/E1; lam[1][1] = 1.0/E2; lam[1][2] = -v23/E2; lam[2][0] = -v31/E3; lam[2][1] = -v23/E2; lam[2][2] = 1.0/E3; mat3d c(lam); c = c.inverse(); lam[0][0] = c[0][0] - 2*mu[0]; lam[1][1] = c[1][1] - 2*mu[1]; lam[2][2] = c[2][2] - 2*mu[2]; lam[1][2] = c[1][2]; lam[2][1] = c[2][1]; lam[2][0] = c[2][0]; lam[0][2] = c[0][2]; lam[0][1] = c[0][1]; lam[1][0] = c[1][0]; return true; } //----------------------------------------------------------------------------- //! Calculates the deviatoric stress mat3ds FEFungOrthotropic::DevStress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); int i,j; vec3d a0[3]; // texture direction in reference configuration vec3d a[3]; // texture direction in current configuration mat3ds A[3]; // texture tensor in current configuration double K[3]; // Ka double L[3]; // La double eQ; // exp(Q) mat3ds bmi; // B - I // Evaluate the deformation gradient mat3d &F = pt.m_F; double detF = pt.m_J; mat3d Fd = F*pow(detF,-1./3.); // calculate deviatoric left and right Cauchy-Green tensor mat3ds b = pt.DevLeftCauchyGreen(); mat3ds c = pt.DevRightCauchyGreen(); mat3ds c2 = c.sqr(); // get the local coordinate systems mat3d Q = GetLocalCS(mp); for (i=0; i<3; i++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to a0 a0[i].x = Q[0][i]; a0[i].y = Q[1][i]; a0[i].z = Q[2][i]; K[i] = a0[i]*(c*a0[i]); L[i] = a0[i]*(c2*a0[i]); a[i] = Fd*a0[i]/sqrt(K[i]); // Evaluate the texture direction in the current configuration A[i] = dyad(a[i]); // Evaluate the texture tensor in the current configuration } // Evaluate exp(Q) eQ = 0; for (i=0; i<3; i++) { eQ += 2*mu[i]*(L[i]-2*K[i]+1); for (j=0; j<3; j++) eQ += lam[i][j]*(K[i]-1)*(K[j]-1); } eQ = exp(eQ/(4.*m_c)); // Evaluate the stress mat3ds s; s.zero(); // Initialize for summation bmi = b - mat3dd(1.); for (i=0; i<3; i++) { s += (A[i]*bmi).sym()*(2.0*mu[i] * K[i]); for (j=0; j<3; j++) s += lam[i][j]*((K[i]-1)*K[j]*A[j]+(K[j]-1)*K[i]*A[i])/2.; } s *= eQ/(2.0*detF); return s.dev(); } //----------------------------------------------------------------------------- //! Calculates the deviatoric tangent tens4ds FEFungOrthotropic::DevTangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); int i,j; vec3d a0[3]; // texture direction in reference configuration vec3d a[3]; // texture direction in current configuration mat3ds A[3]; // texture tensor in current configuration double K[3]; // Ka double L[3]; // La double eQ; // exp(Q) mat3ds bmi; // B - I // Evaluate the strain and texture mat3d &F = pt.m_F; double detF = pt.m_J; mat3d Fd = F*pow(detF,-1./3.); // calculate left and right Cauchy-Green tensor mat3ds b = pt.DevLeftCauchyGreen(); mat3ds c = pt.DevRightCauchyGreen(); mat3ds c2 = c.sqr(); mat3dd I(1.); // get the local coordinate systems mat3d Q = GetLocalCS(mp); for (i=0; i<3; i++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to a0 a0[i].x = Q[0][i]; a0[i].y = Q[1][i]; a0[i].z = Q[2][i]; K[i] = a0[i]*(c*a0[i]); L[i] = a0[i]*(c2*a0[i]); a[i] = Fd*a0[i]/sqrt(K[i]); // Evaluate the texture direction in the current configuration A[i] = dyad(a[i]); // Evaluate the texture tensor in the current configuration } // Evaluate exp(Q) eQ = 0; for (i=0; i<3; i++) { eQ += 2*mu[i]*(L[i]-2*K[i]+1); for (j=0; j<3; j++) eQ += lam[i][j]*(K[i]-1)*(K[j]-1); } eQ = exp(eQ/(4.*m_c)); // Evaluate the distortional part of the Cauchy stress mat3ds sd; sd.zero(); // Initialize for summation tens4ds C(0.0); bmi = b - I; for (i=0; i<3; i++) { sd += ((A[i]*bmi).sym())*(2.0*mu[i] * K[i]); for (j=0; j<3; j++) sd += lam[i][j]*((K[i]-1)*K[j]*A[j]+(K[j]-1)*K[i]*A[i])/2.; C += mu[i]*K[i]*dyad4s(A[i],b); for (j=0; j<3; j++) C += lam[i][j]*K[i]*K[j]*dyad1s(A[i],A[j])/2.; } sd *= eQ/(2.0*detF); // This is the distortional part of the elasticity tensor C = (eQ/detF)*C + (2*detF/m_c/eQ)*dyad1s(sd); // This is the final value of the elasticity tensor tens4ds IxI = dyad1s(I); tens4ds I4 = dyad4s(I); C += - 1./3.*(ddots(C,IxI) - IxI*(C.tr()/3.)) + 2./3.*((I4-IxI/3.)*sd.tr()-dyad1s(sd.dev(),I)); return C; } //----------------------------------------------------------------------------- //! Calculates the strain energy density double FEFungOrthotropic::DevStrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); int i,j; vec3d a0[3]; // texture direction in reference configuration mat3ds A0[3]; // texture tensor in current configuration double eQ = 0.0; // exp(Q) double AE[3], AE2[3]; // calculate right Cauchy-Green tensor and Lagrange strain tensor mat3ds C = pt.DevRightCauchyGreen(); mat3dd I(1.); mat3ds E = (C - I)*0.5; mat3ds E2 = E.sqr(); // get the local coordinate systems mat3d Q = GetLocalCS(mp); for (i=0; i<3; i++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to a0 a0[i].x = Q[0][i]; a0[i].y = Q[1][i]; a0[i].z = Q[2][i]; A0[i] = dyad(a0[i]); // Evaluate the texture tensor in the reference configuration AE[i] = A0[i].dotdot(E); AE2[i] = A0[i].dotdot(E2); } // Evaluate exp(Q) for (i=0; i<3; i++) { eQ += 2*mu[i]*AE2[i]; for (j=0; j<3; j++) eQ += lam[i][j]*AE[i]*AE[j]; } eQ = exp(eQ/m_c); // Evaluate the strain energy density double sed = 0.5*m_c*(eQ-1); return sed; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEWrinkleOgdenMaterial.h
.h
2,079
60
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEMembraneMaterial.h" //----------------------------------------------------------------------------- // This class implements a wrinkle model for an Ogden material // class FEWrinkleOgdenMaterial : public FEMembraneMaterial { public: FEWrinkleOgdenMaterial(FEModel* pfem); public: // material parameters double m_u; double m_a; double m_l0[2]; // pre-stretch bool m_bwrinkle; // wrinkle flag public: // material interface //! calculate stress at material point void Stress(FEMaterialPoint& pt, double s[3]) override; //! calculate tangent stiffness at material point void Tangent(FEMaterialPoint& pt, double D[3][3]) override; protected: void principals(FEMaterialPoint& pt, double l[2], double v[4]); // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEActiveContractionMaterial.cpp
.cpp
1,361
30
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2022 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEActiveContractionMaterial.h"
C++
3D
febiosoftware/FEBio
FEBioMech/FEOgdenMaterial.cpp
.cpp
7,601
251
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEOgdenMaterial.h" //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEOgdenMaterial, FEUncoupledMaterial); ADD_PARAMETER(m_c[0], "c1")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c[1], "c2")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c[2], "c3")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c[3], "c4")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c[4], "c5")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_c[5], "c6")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_m[0], FE_RANGE_NOT_EQUAL(0.0), "m1"); ADD_PARAMETER(m_m[1], FE_RANGE_NOT_EQUAL(0.0), "m2"); ADD_PARAMETER(m_m[2], FE_RANGE_NOT_EQUAL(0.0), "m3"); ADD_PARAMETER(m_m[3], FE_RANGE_NOT_EQUAL(0.0), "m4"); ADD_PARAMETER(m_m[4], FE_RANGE_NOT_EQUAL(0.0), "m5"); ADD_PARAMETER(m_m[5], FE_RANGE_NOT_EQUAL(0.0), "m6"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FEOgdenMaterial::FEOgdenMaterial(FEModel* pfem) : FEUncoupledMaterial(pfem) { for (int i=0; i<MAX_TERMS; ++i) { m_c[i] = 0; m_m[i] = 1; } m_eps = 1e-12; } //----------------------------------------------------------------------------- void FEOgdenMaterial::EigenValues(mat3ds& A, double l[3], vec3d r[3], const double eps) { A.eigen(l, r); // correct for numerical inaccuracy double d01 = fabs(l[0] - l[1]); double d12 = fabs(l[1] - l[2]); double d02 = fabs(l[0] - l[2]); if (d01 < eps) l[1] = l[0]; //= 0.5*(l[0]+l[1]); if (d02 < eps) l[2] = l[0]; //= 0.5*(l[0]+l[2]); if (d12 < eps) l[2] = l[1]; //= 0.5*(l[1]+l[2]); } //----------------------------------------------------------------------------- //! Calculates the Cauchy stress mat3ds FEOgdenMaterial::DevStress(FEMaterialPoint &mp) { // extract elastic material data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; // get the left Cauchy-Green tensor mat3ds b = pt.DevLeftCauchyGreen(); // get the eigenvalues and eigenvectors of b double lam2[3]; // these are the squares of the eigenvalues of V vec3d ev[3]; EigenValues(b, lam2, ev, m_eps); // get the eigenvalues of V double lam[3]; lam[0] = sqrt(lam2[0]); lam[1] = sqrt(lam2[1]); lam[2] = sqrt(lam2[2]); double ci[MAX_TERMS] = { 0 }, mi[MAX_TERMS] = {0}; for (int i = 0; i < MAX_TERMS; ++i) { ci[i] = m_c[i](mp); mi[i] = m_m[i](mp); } // stress mat3ds s; s.zero(); double T; for (int i=0; i<3; ++i) { T = 0; for (int j=0; j<MAX_TERMS; ++j) T += ci[j]/mi[j]*(pow(lam[i], mi[j]) - 1)/J; s += dyad(ev[i])*T; } return s.dev(); } //----------------------------------------------------------------------------- //! Calculates the spatial tangent tens4ds FEOgdenMaterial::DevTangent(FEMaterialPoint& mp) { int i,j,k; // extract elastic material data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // jacobian double J = pt.m_J; // get the left Cauchy-Green tensor mat3ds b = pt.DevLeftCauchyGreen(); // get the eigenvalues and eigenvectors of b double lam2[3]; // these are the squares of the eigenvalues of V vec3d ev[3]; EigenValues(b, lam2, ev, m_eps); // get the eigenvalues of V double lam[3]; mat3ds N[3]; for (i=0; i<3; ++i) { lam[i] = sqrt(lam2[i]); N[i] = dyad(ev[i]); } double ci[MAX_TERMS] = { 0 }, mi[MAX_TERMS] = { 0 }; for (int i = 0; i < MAX_TERMS; ++i) { ci[i] = m_c[i](mp); mi[i] = m_m[i](mp); } // calculate the powers of eigenvalues double lamp[3][MAX_TERMS]; for (j=0; j<MAX_TERMS; ++j) { lamp[0][j] = pow(lam[0], mi[j]); lamp[1][j] = pow(lam[1], mi[j]); lamp[2][j] = pow(lam[2], mi[j]); } // principal stresses mat3ds s; s.zero(); double T[3]; for (i=0; i<3; ++i) { T[i] = 0; for (j=0; j<MAX_TERMS; ++j) T[i] += ci[j]/mi[j]*(lamp[i][j] - 1)/J; s += N[i]*T[i]; } // coefficients appearing in elasticity tensor double D[3][3],E[3][3]; for (j=0; j<3; ++j) { D[j][j] = 0; for (k=0; k<MAX_TERMS; ++k) D[j][j] += ci[k]/mi[k]*((mi[k]-2)*lamp[j][k]+2)/J; for (i=j+1; i<3; ++i) { D[i][j] = 0; if (lam2[j] != lam2[i]) E[i][j] = 2*(lam2[j]*T[i] - lam2[i]*T[j])/(lam2[i]-lam2[j]); else { E[i][j] = 0; for (k=0; k<MAX_TERMS; ++k) E[i][j] += ci[k]/mi[k]*((mi[k]-2)*lamp[j][k]+2)/J; } } } // spatial elasticity tensor tens4ds c(0.0); mat3dd I(1.0); for (j=0; j<3; ++j) { c += dyad1s(N[j])*D[j][j]; for (i=j+1; i<3; ++i) { c += dyad1s(N[i],N[j])*D[i][j]; c += dyad4s(N[i],N[j])*E[i][j]; } } // This is the final value of the elasticity tensor tens4ds IxI = dyad1s(I); tens4ds I4 = dyad4s(I); c += - 1./3.*(ddots(c,IxI) - IxI*(c.tr()/3.)) + 2./3.*((I4-IxI/3.)*s.tr()-dyad1s(s.dev(),I)); return c; } //----------------------------------------------------------------------------- double FEOgdenMaterial::DevStrainEnergyDensity(FEMaterialPoint& mp) { // extract elastic material data FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // get the left Cauchy-Green tensor mat3ds b = pt.DevLeftCauchyGreen(); // get the eigenvalues and eigenvectors of b double lam2[3]; // these are the squares of the eigenvalues of V vec3d ev[3]; EigenValues(b, lam2, ev, m_eps); // get the eigenvalues of V double lam[3]; lam[0] = sqrt(lam2[0]); lam[1] = sqrt(lam2[1]); lam[2] = sqrt(lam2[2]); double ci[MAX_TERMS] = { 0 }, mi[MAX_TERMS] = { 0 }; for (int i = 0; i < MAX_TERMS; ++i) { ci[i] = m_c[i](mp); mi[i] = m_m[i](mp); } // strain energy density double sed = 0; for (int j=0; j<MAX_TERMS; ++j) sed += ci[j]/(mi[j]*mi[j])* (pow(lam[0], mi[j]) + pow(lam[1], mi[j]) + pow(lam[2], mi[j]) - 3); return sed; }
C++
3D
febiosoftware/FEBio
FEBioMech/adcm.h
.h
3,054
91
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/ad.h> #include <FECore/ad2.h> namespace ad { template <class T> double StrainEnergy(T* p, FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); ::mat3ds C = pt.RightCauchyGreen(); auto W = std::bind(&T::StrainEnergy_AD, p, mp, std::placeholders::_1); return ad::Evaluate(W, C); } template <class T> ::mat3ds PK2Stress(T* p, FEMaterialPoint& mp, ::mat3ds& C) { auto W = std::bind(&T::StrainEnergy_AD, p, mp, std::placeholders::_1); return ad::Derive(W, C) * 2.0; } template <class T> ::mat3ds PK2Stress(T* p, FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); ::mat3ds C = pt.RightCauchyGreen(); return PK2Stress(p, mp, C); } template <class T> ::tens4ds Tangent(T* p, FEMaterialPoint& mp, ::mat3ds& C) { auto S = std::bind(&T::PK2Stress_AD, p, mp, std::placeholders::_1); return Derive(S, C) * 2.0; } template <class T> ::tens4ds Tangent(T* p, FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); ::mat3ds C = pt.RightCauchyGreen(); return Tangent(p, mp, C); } } namespace ad2 { template <class T> ::mat3ds PK2Stress(T* p, FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); ::mat3ds C = pt.RightCauchyGreen(); auto W = std::bind(&T::StrainEnergy_AD2, p, mp, std::placeholders::_1); return ad2::Derive(W, C) * 2.0; } template <class T> ::tens4ds Tangent(T* p, FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); ::mat3ds C = pt.RightCauchyGreen(); auto W = std::bind(&T::StrainEnergy_AD2, p, mp, std::placeholders::_1); return ad2::Derive2(W, C) * 4.0; } }
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEDeformationMapGenerator.h
.h
1,715
50
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEDataGenerator.h> class FENodeDataMap; class FEDeformationMapGenerator : public FEElemDataGenerator { public: FEDeformationMapGenerator(FEModel* fem); ~FEDeformationMapGenerator(); bool Init() override; // generate the data array for the given element set FEDataMap* Generate() override; private: std::string m_nodeDisplacementMap; private: FENodeDataMap* m_nodeMap; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FERadialBodyForce.cpp
.cpp
2,815
103
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FERadialBodyForce.h" #include "FEElasticMaterial.h" BEGIN_FECORE_CLASS(FERadialBodyForce, FEBodyForce); ADD_PARAMETER(p, "p"); ADD_PARAMETER(c, "c"); ADD_PARAMETER(s[0], "sx"); ADD_PARAMETER(s[1], "sy"); ADD_PARAMETER(s[2], "sz"); END_FECORE_CLASS(); FERadialBodyForce::FERadialBodyForce(FEModel* pfem) : FEBodyForce(pfem) { p = 0; c = vec3d(0, 0, 0); s[0] = 1; s[1] = 1; s[2] = 1; } vec3d FERadialBodyForce::force(FEMaterialPoint& mp) { vec3d x = mp.m_rt - c; if (p == 0) { vec3d f(s[0] * x.x, s[1] * x.y, s[2] * x.z); return f; } else { double R = x.norm(); double Rp = pow(R, p); vec3d f(s[0] * Rp * x.x, s[1] * Rp * x.y, s[2] * Rp * x.z); return f; } } mat3d FERadialBodyForce::stiffness(FEMaterialPoint& mp) { mat3d K; K.zero(); if (p == 0) { K[0][0] = -s[0]; K[1][1] = -s[1]; K[2][2] = -s[2]; } else { vec3d x = mp.m_rt - c; mat3d XX = (x & x); double R = x.norm(); double Rp = -pow(R, p); double Rpm2 = -pow(R, p-2 ); K[0][0] = s[0] * p * Rpm2 * XX[0][0] + s[0] * Rp; K[0][1] = s[0] * p * Rpm2 * XX[0][1]; K[0][2] = s[0] * p * Rpm2 * XX[0][2]; K[1][0] = s[1] * p * Rpm2 * XX[1][0]; K[1][1] = s[1] * p * Rpm2 * XX[1][1] + s[1] * Rp; K[1][2] = s[1] * p * Rpm2 * XX[1][2]; K[2][0] = s[2] * p * Rpm2 * XX[2][0]; K[2][1] = s[2] * p * Rpm2 * XX[2][1]; K[2][2] = s[2] * p * Rpm2 * XX[2][2] + s[2] * Rp; } return K; } double FERadialBodyForce::divforce(FEMaterialPoint& mp) { // TODO: implement this assert(false); return 0; }
C++
3D
febiosoftware/FEBio
FEBioMech/FESolidSolver2.h
.h
5,753
186
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECore/FENewtonSolver.h" #include <FECore/FETimeInfo.h> #include "FECore/FEGlobalVector.h" #include "FERigidSolver.h" #include <FECore/FEDofList.h> //----------------------------------------------------------------------------- //! The FESolidSolver2 class solves large deformation solid mechanics problems //! It can deal with quasi-static and dynamic problems //! class FEBIOMECH_API FESolidSolver2 : public FENewtonSolver { enum ARC_LENGTH_METHOD { NONE, CRISFIELD, }; public: //! constructor FESolidSolver2(FEModel* pfem); //! destructor virtual ~FESolidSolver2(); //! serialize data to/from dump file void Serialize(DumpStream& ar) override; //! Initializes data structures bool Init() override; //! initialize the step bool InitStep(double time) override; //! Initialize linear equation system bool InitEquations() override; bool InitEquations2() override; //! Generate warnings if needed void SolverWarnings(); //! Return the rigid solver FERigidSolver* GetRigidSolver(); public: //{ --- evaluation and update --- //! Perform an update void Update(vector<double>& ui) override; //! perform an updated where ui also contains displacement increments of prescribed displacements //! NOTE: This is a temporary hack that is only by the JFNKMatrix void Update2(const vector<double>& ui) override; //! update nodal positions, velocities, accelerations, etc. virtual void UpdateKinematics(vector<double>& ui); //! Update EAS void UpdateEAS(vector<double>& ui); void UpdateIncrementsEAS(vector<double>& ui, const bool binc); //! update DOF increments virtual void UpdateIncrements(vector<double>& Ui, vector<double>& ui, bool emap); //} //{ --- Solution functions --- //! prepares the data for the first QN iteration void PrepStep() override; //! Performs a Newton-Raphson iteration bool Quasin() override; //! Apply arc-length void DoArcLength(); //} //{ --- Stiffness matrix routines --- //! calculates the global stiffness matrix virtual bool StiffnessMatrix() override; //! contact stiffness void ContactStiffness(FELinearSystem& LS); //! calculates stiffness contributon of nonlinear constraints void NonLinearConstraintStiffness(FELinearSystem& LS, const FETimeInfo& tp); //} //{ --- Residual routines --- //! Calculate the contact forces void ContactForces(FEGlobalVector& R); //! Calculates residual virtual bool Residual(vector<double>& R) override; //! Calculate nonlinear constraint forces void NonLinearConstraintForces(FEGlobalVector& R, const FETimeInfo& tp); //! Internal forces void InternalForces(FEGlobalVector& R); //! external forces void ExternalForces(FEGlobalVector& R); //} private: //! Calculate initial accelerations for dynamics problems bool InitAccelerations(); public: // convergence tolerances double m_Dtol; //!< displacement tolerance bool m_logSolve; //!< flag to use Aggarwal's log method // equation numbers int m_nreq; //!< start of rigid body equations public: vector<double> m_Fr; //!< nodal reaction forces vector<double> m_Fint; //!< internal load vector vector<double> m_Fext; //!< external load vector vector<double> m_Uip; //!< previous converged displacement increment // generalized alpha method (for dynamic analyses) double m_rhoi; //!< spectral radius double m_alphaf; //!< alpha step for Y={v,e} double m_alpham; //!< alpha step for Ydot={∂v/∂t,∂e/∂t} double m_alpha; //!< Newmark parameter alpha (force integration) double m_beta; //!< Newmark parameter beta (displacement integration) double m_gamma; //!< Newmark parameter gamme (velocity integration) bool m_init_accelerations; //!< calculate initial accelerations for dynamic problems // arc-length parameters int m_arcLength; //!< arc-length method flag (0 = off, 1 = Crisfield) double m_al_scale; //!< arc-length scaling parameter (i.e. psi). double m_al_lam; //!< current arc-length lambda double m_al_inc; //!< arc-length lambda increment at current timestep double m_al_ds; //!< arc-length constraint double m_al_gamma; //!< acr-length increment at current iteration protected: FEDofList m_dofU, m_dofV; FEDofList m_dofQ; FEDofList m_dofRQ; FEDofList m_dofSU, m_dofSV, m_dofSA; FEDofList m_dofBW, m_dofBA; protected: FERigidSolverNew m_rigidSolver; // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FEMRVonMisesFibers.h
.h
2,786
84
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEUncoupledMaterial.h" #include "FEUncoupledFiberExpLinear.h" //----------------------------------------------------------------------------- class FEMRVonMisesMaterialPoint : public FEMaterialPointData { public: FEMRVonMisesMaterialPoint(FEMaterialPointData* mp = nullptr); FEMaterialPointData* Copy() override; void Serialize(DumpStream& ar) override; public: double m_kf; double m_tp; }; //----------------------------------------------------------------------------- //! Transversely Isotropic Multiple material //! This material has an isotopric Multiple basis and single preferred //! fiber direction. class FEMRVonMisesFibers: public FEUncoupledMaterial { public: FEMRVonMisesFibers (FEModel* pfem); public: double c1; //!< Mooney-Rivlin coefficient C1 double c2; //!< Mooney-Rivlin coefficient C2 double kf; //!< Fiber Concentration Factor double tp; //!< Preferred Fiber Orientation IN RADIANS int gipt; //!< Gauss Integration Points int vmc; //!< Choice of von Mises distribution double var_n; //!< Exponent for the constrained von Mises distribution public: //! calculate stress at material point virtual mat3ds DevStress(FEMaterialPoint& pt) override; //! calculate tangent stiffness at material point virtual tens4ds DevTangent(FEMaterialPoint& pt) override; //! create material point data FEMaterialPointData* CreateMaterialPointData() override; // declare parameter list DECLARE_FECORE_CLASS(); protected: FEFiberExpLinearUC m_fib; };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FERigidFollowerForce.h
.h
2,178
61
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECore/FEModelLoad.h" #include "FERigidForce.h" #include "febiomech_api.h" //----------------------------------------------------------------------------- //! a follower force on a rigid body class FEBIOMECH_API FERigidFollowerForce : public FERigidLoad { public: //! constructor FERigidFollowerForce(FEModel* pfem); //! initialization bool Init() override; //! Serialization void Serialize(DumpStream& ar) override; //! Residual void LoadVector(FEGlobalVector& R) override; //! Stiffness matrix void StiffnessMatrix(FELinearSystem& LS) override; public: int m_rid; //!< rigid body ID vec3d m_X; //!< coordinates of attachements in reference state vec3d m_f; //!< force bool m_brelative; //!< if active, the ra0 and rb0 are relative w.r.t. the COM DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMech/FESlidingInterface.cpp
.cpp
52,109
1,924
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FESlidingInterface.h" #include <FECore/FEShellDomain.h> #include "FECore/FEClosestPointProjection.h" #include "FECore/FEModel.h" #include "FECore/FEGlobalMatrix.h" #include "FECore/log.h" #include <FECore/FELinearSystem.h> #include <FECore/FEAnalysis.h> FESlidingSurface::FESlidingPoint::FESlidingPoint() { m_gap = 0.0; m_nu = vec3d(0,0,0); m_rs = vec2d(0,0); m_rsp = vec2d(0,0); m_Lm = 0.0; m_M.zero(); m_Lt = vec2d(0,0); m_off = 0.0; m_eps = 1.0; m_Ln = 0.0; } void FESlidingSurface::FESlidingPoint::Serialize(DumpStream& ar) { FEContactMaterialPoint::Serialize(ar); ar & m_nu & m_eps & m_off; ar & m_rs & m_rsp; ar & m_Lm & m_Lt; ar & m_M; } void FESlidingSurface::FESlidingPoint::Init() { FEContactMaterialPoint::Init(); m_gap = 0.0; m_nu = vec3d(0, 0, 0); m_rs = vec2d(0, 0); m_rsp = vec2d(0, 0); m_Lm = 0.0; m_M.zero(); m_Lt = vec2d(0, 0); m_off = 0.0; m_eps = 1.0; } //----------------------------------------------------------------------------- // Define sliding interface parameters BEGIN_FECORE_CLASS(FESlidingInterface, FEContactInterface) ADD_PARAMETER(m_laugon , "laugon" )->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0"); ADD_PARAMETER(m_atol , "tolerance" ); ADD_PARAMETER(m_eps , "penalty" ); ADD_PARAMETER(m_bautopen , "auto_penalty" ); ADD_PARAMETER(m_btwo_pass , "two_pass" ); ADD_PARAMETER(m_gtol , "gaptol" ); ADD_PARAMETER(m_mu , "fric_coeff" ); ADD_PARAMETER(m_epsf , "fric_penalty" ); ADD_PARAMETER(m_naugmin , "minaug" ); ADD_PARAMETER(m_naugmax , "maxaug" ); ADD_PARAMETER(m_stol , "search_tol" ); ADD_PARAMETER(m_ktmult , "ktmult" ); ADD_PARAMETER(m_knmult , "knmult" ); ADD_PARAMETER(m_breloc , "node_reloc" ); ADD_PARAMETER(m_nsegup , "seg_up" ); ADD_PARAMETER(m_sradius , "search_radius"); ADD_PARAMETER(m_bupdtpen , "update_penalty"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FESlidingSurface::FESlidingSurface(FEModel* pfem) : FEContactSurface(pfem) {} //----------------------------------------------------------------------------- //! build the matrix profile for use in the stiffness matrix void FESlidingInterface::BuildMatrixProfile(FEGlobalMatrix& K) { // TODO: this is currently for max 6 nodes (hence 7=6+1) vector<int> lm(6*7); FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); // get the DOFS const int dof_X = fem.GetDOFIndex("x"); const int dof_Y = fem.GetDOFIndex("y"); const int dof_Z = fem.GetDOFIndex("z"); const int dof_RU = fem.GetDOFIndex("Ru"); const int dof_RV = fem.GetDOFIndex("Rv"); const int dof_RW = fem.GetDOFIndex("Rw"); int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FESlidingSurface& ss = (np==0? m_ss : m_ms); FESlidingSurface& ms = (np==0? m_ms : m_ss); for (int j=0; j<ss.Nodes(); ++j) { FESurfaceElement* pe = ss.m_data[j].m_pme; if (pe != 0) { FESurfaceElement& me = *pe; int* en = &me.m_node[0]; // Note that we need to grab the rigid degrees of freedom as well // this is in case one of the nodes belongs to a rigid body. int n = me.Nodes(); if (n == 3) { lm[6*(3+1) ] = -1;lm[6*(3+2) ] = -1;lm[6*(3+3) ] = -1; lm[6*(3+1)+1] = -1;lm[6*(3+2)+1] = -1;lm[6*(3+3)+1] = -1; lm[6*(3+1)+2] = -1;lm[6*(3+2)+2] = -1;lm[6*(3+3)+2] = -1; lm[6*(3+1)+3] = -1;lm[6*(3+2)+3] = -1;lm[6*(3+3)+3] = -1; lm[6*(3+1)+4] = -1;lm[6*(3+2)+4] = -1;lm[6*(3+3)+4] = -1; lm[6*(3+1)+5] = -1;lm[6*(3+2)+5] = -1;lm[6*(3+3)+5] = -1; } if (n == 4) { lm[6*(4+1) ] = -1;lm[6*(4+2) ] = -1; lm[6*(4+1)+1] = -1;lm[6*(4+2)+1] = -1; lm[6*(4+1)+2] = -1;lm[6*(4+2)+2] = -1; lm[6*(4+1)+3] = -1;lm[6*(4+2)+3] = -1; lm[6*(4+1)+4] = -1;lm[6*(4+2)+4] = -1; lm[6*(4+1)+5] = -1;lm[6*(4+2)+5] = -1; } lm[0] = ss.Node(j).m_ID[dof_X]; lm[1] = ss.Node(j).m_ID[dof_Y]; lm[2] = ss.Node(j).m_ID[dof_Z]; lm[3] = ss.Node(j).m_ID[dof_RU]; lm[4] = ss.Node(j).m_ID[dof_RV]; lm[5] = ss.Node(j).m_ID[dof_RW]; for (int k=0; k<n; ++k) { vector<int>& id = mesh.Node(en[k]).m_ID; lm[6*(k+1) ] = id[dof_X]; lm[6*(k+1)+1] = id[dof_Y]; lm[6*(k+1)+2] = id[dof_Z]; lm[6*(k+1)+3] = id[dof_RU]; lm[6*(k+1)+4] = id[dof_RV]; lm[6*(k+1)+5] = id[dof_RW]; } K.build_add(lm); } } } } //----------------------------------------------------------------------------- //! Creates a surface for use with a sliding interface. All surface data //! structures are allocated. //! Note that it is assumed that the element array is already created //! and initialized. bool FESlidingSurface::Init() { // always intialize base class first! if (FEContactSurface::Init() == false) return false; // make sure the sibling surface has been set assert(m_pSibling); // get the number of nodes int nn = Nodes(); // allocate integration point data m_data.resize(nn); for (int i = 0; i < nn; ++i) { FESlidingPoint& d = m_data[i]; d.Init(); } // we calculate the gap offset values // This value is used to take the shell thickness into account // note that we force rigid shells to have zero thickness FEMesh& m = *m_pMesh; vector<double> tag(m.Nodes()); zero(tag); for (int nd=0; nd<m.Domains(); ++nd) { FEShellDomain* psd = dynamic_cast<FEShellDomain*>(&m.Domain(nd)); if (psd) { for (int i=0; i<psd->Elements(); ++i) { FEShellElement& el = psd->Element(i); int n = el.Nodes(); for (int j=0; j<n; ++j) tag[el.m_node[j]] = 0.5*el.m_h0[j]; } } } for (int i=0; i<nn; ++i) m_data[i].m_off = tag[NodeIndex(i)]; return true; } //----------------------------------------------------------------------------- //! vec3d FESlidingSurface::traction(int inode) { vec3d t(0,0,0); if (m_data[inode].m_pme) { FESurfaceElement& el = *m_data[inode].m_pme; double Tn = m_data[inode].m_Lm; double T1 = -m_data[inode].m_Lt[0]; double T2 = -m_data[inode].m_Lt[1]; double r = m_data[inode].m_rs[0]; double s = m_data[inode].m_rs[1]; vec3d tn = m_data[inode].m_nu*Tn, tt; vec3d e[2]; ContraBaseVectors(el, r, s, e); tt = e[0]*T1 + e[1]*T2; t = tn + tt; } return t; } //----------------------------------------------------------------------------- vec3d FESlidingSurface::GetContactForce() { const int MN = FEElement::MAX_NODES; double Tn[MN],T1[MN],T2[MN]; // initialize contact force vec3d f(0,0,0); // loop over all elements of the surface for (int n=0; n<Elements(); ++n) { FESurfaceElement& el = Element(n); int nseln = el.Nodes(); // nodal contact pressures and frictional tractions for (int i=0; i<nseln; ++i) { Tn[i] = m_data[el.m_lnode[i]].m_Ln; T1[i] = -m_data[el.m_lnode[i]].m_Lt[0]; T2[i] = -m_data[el.m_lnode[i]].m_Lt[1]; } int nint = el.GaussPoints(); // evaluate the contact force for that element for (int i=0; i<nint; ++i) { // area in reference configuration vec3d g0[2],g[2]; double r = el.gr(i); double s = el.gs(i); CoBaseVectors0(el, r, s, g0); double A = (g0[0] ^ g0[1]).unit(); // traction components at integration point double t1 = el.eval(T1,i); double t2 = el.eval(T2,i); double t3 = el.eval(Tn,i); // unit normal vector vec3d n = SurfaceNormal(el, i); // contravariant basis in spatial frame ContraBaseVectors(el, r, s, g); // Piola traction vec3d t = g[0]*t1 + g[1]*t2 + n*t3; // gauss weight double w = el.GaussWeights()[i]; // contact force f += t*(w*A); } } return f; } //----------------------------------------------------------------------------- double FESlidingSurface::GetContactArea() { const int MN = FEElement::MAX_NODES; double Tn[MN]; // initialize contact area double a = 0; // loop over all elements of the primary surface for (int n=0; n<Elements(); ++n) { FESurfaceElement& el = Element(n); int nint = el.GaussPoints(); int nseln = el.Nodes(); // nodal contact pressures for (int i=0; i<nseln; ++i) { Tn[i] = m_data[el.m_lnode[i]].m_Ln; } // evaluate the contact force for that element for (int i=0; i<nint; ++i) { // get data for this integration point double Ln = el.eval(Tn,i); double s = (Ln > 0) ? 1 : 0; // get the base vectors vec3d g[2]; CoBaseVectors(el, i, g); // normal (magnitude = area) vec3d n = g[0] ^ g[1]; // gauss weight double w = el.GaussWeights()[i]; // contact force a += n.norm()*(w*s); } } return a; } //----------------------------------------------------------------------------- void FESlidingSurface::Serialize(DumpStream& ar) { // serialize base class FEContactSurface::Serialize(ar); // serialize data ar & m_data; } //----------------------------------------------------------------------------- void FESlidingSurface::GetContactTraction(int nface, vec3d& pt) { FESurfaceElement& el = Element(nface); int ne = el.Nodes(); pt = vec3d(0,0,0); for (int k=0; k<ne; ++k) { int nj = el.m_lnode[k]; if (m_data[nj].m_gap > 0) pt += m_data[nj].m_nu*m_data[nj].m_Ln; } pt /= ne; } //----------------------------------------------------------------------------- void FESlidingSurface::GetNodalContactPressure(int nface, double* pg) { FESurfaceElement& f = Element(nface); int ne = f.Nodes(); for (int j=0; j<ne; ++j) pg[j] = m_data[f.m_lnode[j]].m_Ln; } //----------------------------------------------------------------------------- void FESlidingSurface::GetNodalContactTraction(int nface, vec3d* tn) { FESurfaceElement& e = Element(nface); int ne = e.Nodes(); for (int j=0; j<ne; ++j) { int nj = e.m_lnode[j]; double gi = m_data[nj].m_gap; double Li = m_data[nj].m_Ln; vec3d ti = m_data[nj].m_nu; if (gi > 0) tn[j] = ti*Li; else tn[j] = vec3d(0,0,0); } } /////////////////////////////////////////////////////////////////////////////// // FESlidingInterface /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- //! constructor FESlidingInterface::FESlidingInterface(FEModel* pfem) : FEContactInterface(pfem), m_ss(pfem), m_ms(pfem) { static int count = 1; SetID(count++); m_mu = 0; m_epsf = 0; m_naugmin = 0; m_naugmax = 10; m_gtol = 0; m_stol = 0.01; m_ktmult = 0; m_knmult = 1; m_breloc = false; m_bupdtpen = false; m_nsegup = 0; // always do segment updates m_bautopen = false; // don't use auto-penalty m_btwo_pass = false; // don't use two-pass m_sradius = 0; // no search radius limitation // set parents m_ms.SetContactInterface(this); m_ss.SetContactInterface(this); // set the siblings m_ms.SetSibling(&m_ss); m_ss.SetSibling(&m_ms); }; //----------------------------------------------------------------------------- //! Calculates the auto penalty factor void FESlidingInterface::CalcAutoPenalty(FESlidingSurface& s) { // zero penalty values for (int i=0; i<s.Nodes(); ++i) s.m_data[i].m_eps = 0.0; // get the mesh FEMesh& mesh = *s.GetMesh(); // get the node element list for this surface FENodeElemList NEL; NEL.Create(s); // loop over all surface elements for (int i=0; i<s.Elements(); ++i) { // get the next face FESurfaceElement& face = s.Element(i); // we need a measure for the modulus double eps = AutoPenalty(face, s); // distribute values over nodes for (int k=0; k<face.Nodes(); ++k) { int m = face.m_lnode[k]; s.m_data[m].m_eps += eps; } } // scale values according to valence (TODO: Why are we doing this?) for (int i=0; i<s.Nodes(); ++i) s.m_data[i].m_eps /= NEL.Valence(i); } //----------------------------------------------------------------------------- //! Initializes the sliding interface data bool FESlidingInterface::Init() { // set data m_bfirst = true; m_normg0 = 0.0; // create the surfaces if (m_ss.Init() == false) return false; if (m_ms.Init() == false) return false; return true; } //----------------------------------------------------------------------------- void FESlidingInterface::Activate() { // don't forget to call the base class FEContactInterface::Activate(); // project primary surface onto secondary surface ProjectSurface(m_ss, m_ms, true, m_breloc); if (m_bautopen) CalcAutoPenalty(m_ss); // for two-pass algorithms we repeat the previous // two steps with primary and secondary surface switched if (m_btwo_pass) { ProjectSurface(m_ms, m_ss, true); if (m_bautopen) CalcAutoPenalty(m_ms); } } //----------------------------------------------------------------------------- //! Projects the primary surface onto the secondary surface. //! That is, for each primary surface node we determine the closest //! secondary surface element and the projection of that node onto //! this element. //! \todo this function needs to identify the different types of contact: //! 1/ first contact //! 2/ crossing of element boundary //! 3/ contact termination //! either by failure to find projection or when g < tolerance void FESlidingInterface::ProjectSurface(FESlidingSurface& ss, FESlidingSurface& ms, bool bupseg, bool bmove) { // node projection data double r, s; vec3d q; FEClosestPointProjection cpp(ms); cpp.SetTolerance(m_stol); cpp.SetSearchRadius(m_sradius); cpp.HandleSpecialCases(true); cpp.Init(); // loop over all primary surface nodes for (int i=0; i<ss.Nodes(); ++i) { // get the node FENode& node = ss.Node(i); // get the nodal position vec3d x = node.m_rt; // get the global node number int m = ss.NodeIndex(i); // get the previous secondary surface element (if any) FESurfaceElement* pme = ss.m_data[i].m_pme; // If the node is in contact, let's see if the node still is // on the same element if (pme != 0) { FESurfaceElement& mel = *pme; r = ss.m_data[i].m_rs[0]; s = ss.m_data[i].m_rs[1]; q = ms.ProjectToSurface(mel, x, r, s); ss.m_data[i].m_rs[0] = r; ss.m_data[i].m_rs[1] = s; // we only check when we can update the segments // otherwise, we just stick with this element, even // if the node is no longer inside it. if (bupseg) { if (!ms.IsInsideElement(mel, r, s, m_stol)) { // see if the node might have moved to another element FESurfaceElement* pold = pme; ss.m_data[i].m_rs = vec2d(0,0); pme = cpp.Project(m, q, ss.m_data[i].m_rs); if (pme == 0) { // nope, it has genuinly left contact int* n = &pold->m_node[0]; // feLog("node %d has left element (%d, %d, %d, %d)\n", m+1, n[0]+1, n[1]+1, n[2]+1, n[3]+1); } else { /* if (pme != pold) { feLog("node %d has switched segments: ", m + 1); int* n = &pold->m_node[0]; feLog("from (%d, %d, %d, %d), ", n[0] + 1, n[1] + 1, n[2] + 1, n[3] + 1); n = &pme->m_node[0]; feLog("to (%d, %d, %d, %d)\n", n[0] + 1, n[1] + 1, n[2] + 1, n[3] + 1); } */ if (m_mu*m_epsf > 0) { // the node has moved to another segment. // If friction is active we need to translate the frictional // data to the new segment. FESurfaceElement& eo = *pold; FESurfaceElement& en = *pme; MapFrictionData(i, ss, ms, en, eo, q); } } } } } else if (bupseg) { // get the secondary surface element // don't forget to initialize the search for the first node! ss.m_data[i].m_rs = vec2d(0,0); pme = cpp.Project(m, q, ss.m_data[i].m_rs); if (pme) { // the node has come into contact so make sure to initialize // the previous natural coordinates for friction. ss.m_data[i].m_rsp = ss.m_data[i].m_rs; } } // if we found a secondary surface element, update the gap and normal data ss.m_data[i].m_pme = pme; if (pme != 0) { FESurfaceElement& mel = *ss.m_data[i].m_pme; r = ss.m_data[i].m_rs[0]; s = ss.m_data[i].m_rs[1]; // if this is a new contact, copy the current coordinates // to the previous ones ss.m_data[i].m_M = ss.Metric0(mel, r, s); // the normal is set to the secondary surface element normal ss.m_data[i].m_nu = ss.SurfaceNormal(mel, r, s); // calculate gap ss.m_data[i].m_gap = -(ss.m_data[i].m_nu*(x - q)) + ss.m_data[i].m_off; if (bmove && (ss.m_data[i].m_gap>0)) { node.m_r0 = node.m_rt = q + ss.m_data[i].m_nu*ss.m_data[i].m_off; ss.m_data[i].m_gap = 0; } // TODO: what should we do if the gap function becomes // negative? setting the Lagrange multipliers to zero // might make the system unstable. /* if (ss.gap[i] < 0) { ss.Lm[i] = 0; ss.Lt[i][0] = 0; ss.Lt[i][1] = 0; ss.pme[i] = 0; } */ } else { // TODO: Is this a good criteria for out-of-contact? // perhaps this is not even necessary. // since the node is not in contact, we set the gap function // and Lagrangian multiplier to zero ss.m_data[i].m_gap = 0; ss.m_data[i].m_Lm = 0; ss.m_data[i].m_Lt[0] = ss.m_data[i].m_Lt[1] = 0; } } } //----------------------------------------------------------------------------- //! updates sliding interface data //! niter is the number of Newton iterations. void FESlidingInterface::Update() { int niter = GetFEModel()->GetCurrentStep()->GetFESolver()->m_niter; // should we do a segment update or not? // TODO: check what happens when m_nsegup == -1 and m_npass = 2; // We have to make sure that in this case, both surfaces get at least // one pass! bool bupdate = (m_bfirst || (m_nsegup == 0)? true : (niter <= m_nsegup)); // project primary surface onto secondary surface // this also calculates the nodal gap functions ProjectSurface(m_ss, m_ms, bupdate); if (m_btwo_pass) ProjectSurface(m_ms, m_ss, bupdate); // Update the net contact pressures UpdateContactPressures(); // set the first-entry-flag to false m_bfirst = false; } //----------------------------------------------------------------------------- void FESlidingInterface::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { // element contact force vector vector<double> fe; // the lm array for this force vector vector<int> lm; // the en array vector<int> en; // the elements LM vectors vector<int> sLM; vector<int> mLM; const int MN = FEElement::MAX_NODES; vec3d r0[MN]; double w[MN]; double* Gr, *Gs; double detJ[MN]; vec3d dxr, dxs; // do two-pass int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { // pick the primary and secondary surfaces FESlidingSurface& ss = (np==0? m_ss : m_ms); FESlidingSurface& ms = (np==0? m_ms : m_ss); // loop over all primary surface facets int ne = ss.Elements(); for (int j=0; j<ne; ++j) { // get the next element FESurfaceElement& sel = ss.Element(j); int nseln = sel.Nodes(); // get the element's LM array ss.UnpackLM(sel, sLM); // nodal coordinates for (int i=0; i<nseln; ++i) r0[i] = ss.GetMesh()->Node(sel.m_node[i]).m_r0; // we calculate all the metrics we need before we // calculate the nodal forces for (int n=0; n<nseln; ++n) { Gr = sel.Gr(n); Gs = sel.Gs(n); // calculate jacobian // note that we are integrating over the reference surface dxr = dxs = vec3d(0,0,0); for (int k=0; k<nseln; ++k) { dxr.x += Gr[k]*r0[k].x; dxr.y += Gr[k]*r0[k].y; dxr.z += Gr[k]*r0[k].z; dxs.x += Gs[k]*r0[k].x; dxs.y += Gs[k]*r0[k].y; dxs.z += Gs[k]*r0[k].z; } // jacobians detJ[n] = (dxr ^ dxs).norm(); // integration weights w[n] = sel.GaussWeights()[n]; } // loop over primary surface element nodes (which are the integration points as well) // and calculate the contact nodal force for (int n=0; n<nseln; ++n) { // get the local node number int m = sel.m_lnode[n]; // see if this node's constraint is active // that is, if it has an element associated with it // TODO: is this a good way to test for an active constraint // The rigid wall criteria seems to work much better. if (ss.m_data[m].m_pme != 0) { // This node is active and could lead to a non-zero // contact force. // get the secondary surface element FESurfaceElement& mel = *ss.m_data[m].m_pme; ms.UnpackLM(mel, mLM); // calculate the degrees of freedom int nmeln = mel.Nodes(); int ndof = 3*(nmeln+1); fe.resize(ndof); // calculate the nodal force ContactNodalForce(m, ss, mel, fe); // multiply force with weights for (int l=0; l<ndof; ++l) fe[l] *= detJ[n]*w[n]; // fill the lm array lm.resize(3*(nmeln+1)); lm[0] = sLM[n*3 ]; lm[1] = sLM[n*3+1]; lm[2] = sLM[n*3+2]; for (int l=0; l<nmeln; ++l) { lm[3*(l+1) ] = mLM[l*3 ]; lm[3*(l+1)+1] = mLM[l*3+1]; lm[3*(l+1)+2] = mLM[l*3+2]; } // fill the en array en.resize(nmeln+1); en[0] = sel.m_node[n]; for (int l=0; l<nmeln; ++l) en[l+1] = mel.m_node[l]; // assemble into global force vector R.Assemble(en, lm, fe); } } } } } //----------------------------------------------------------------------------- //! Calculates the contact force on a node. //! \param[in] m local node number //! \param[out] fe force vector void FESlidingInterface::ContactNodalForce(int m, FESlidingSurface& ss, FESurfaceElement& mel, vector<double>& fe) { vec3d dxr, dxs; // normal force double tn, Ln; // gap function double gap; // tangents vec3d tau1, tau2; // max nr of element nodes const int MAXMN = FEElement::MAX_NODES; // secondary surface element nodes vec3d rtm[MAXMN]; // shape function values double H[MAXMN], Hr[MAXMN], Hs[MAXMN]; // contact vectors double N[3*(MAXMN+1)], N1[3*(MAXMN+1)], N2[3*(MAXMN+1)]; double T1[3*(MAXMN+1)], T2[3*(MAXMN+1)], D1[3*(MAXMN+1)], D2[3*(MAXMN+1)]; // surface metrics double A[2][2], M[2][2], K[2][2]; double detA; double eps, scale = Penalty(); // get the mesh FEMesh& mesh = GetFEModel()->GetMesh(); double Tt[2]; int nmeln, ndof; // gap function gap = ss.m_data[m].m_gap; // normal penalty eps = ss.m_data[m].m_eps*scale; // get primary surface node normal force Ln = ss.m_data[m].m_Lm; tn = Ln + eps*gap; tn = MBRACKET(tn); // get the primary surface node normal vec3d& nu = ss.m_data[m].m_nu; nmeln = mel.Nodes(); ndof = 3*(1 + nmeln); // metric tensors mat2d Mk = ss.m_data[m].m_M; mat2d Mki = Mk.inverse(); // get the secondary surface element node positions for (int k=0; k<nmeln; ++k) rtm[k] = mesh.Node(mel.m_node[k]).m_rt; // isoparametric coordinates of the projected node // onto the secondary surface element double r = ss.m_data[m].m_rs[0]; double s = ss.m_data[m].m_rs[1]; // get the coordinates at the previous step double rp = ss.m_data[m].m_rsp[0]; double sp = ss.m_data[m].m_rsp[1]; // get the secondary surface element shape function values at this node mel.shape_fnc(H, r, s); // --- N O R M A L T R A C T I O N --- // calculate contact vectors for normal traction N[0] = nu.x; N[1] = nu.y; N[2] = nu.z; for (int l=0; l<nmeln; ++l) { N[3*(l+1) ] = -H[l]*nu.x; N[3*(l+1)+1] = -H[l]*nu.y; N[3*(l+1)+2] = -H[l]*nu.z; } // calculate force vector for (int l=0; l<ndof; ++l) fe[l] = tn*N[l]; // --- T A N G E N T I A L T R A C T I O N --- if (m_mu*m_epsf > 0) { // Lagrangian traction double Lt[2]; Lt[0] = ss.m_data[m].m_Lt[0]; Lt[1] = ss.m_data[m].m_Lt[1]; // calculate contact vector for tangential traction // only if both the friction coefficient and friction // penalty factor are non-zero // get the secondary surface shape function derivative values at this node mel.shape_deriv(Hr, Hs, r, s); // get the tangent vectors tau1 = tau2 = vec3d(0,0,0); for (int k=0; k<nmeln; ++k) { tau1.x += Hr[k]*rtm[k].x; tau1.y += Hr[k]*rtm[k].y; tau1.z += Hr[k]*rtm[k].z; tau2.x += Hs[k]*rtm[k].x; tau2.y += Hs[k]*rtm[k].y; tau2.z += Hs[k]*rtm[k].z; } // set up the Ti vectors T1[0] = tau1.x; T2[0] = tau2.x; T1[1] = tau1.y; T2[1] = tau2.y; T1[2] = tau1.z; T2[2] = tau2.z; for (int k=0; k<nmeln; ++k) { T1[(k+1)*3 ] = -H[k]*tau1.x; T1[(k+1)*3+1] = -H[k]*tau1.y; T1[(k+1)*3+2] = -H[k]*tau1.z; T2[(k+1)*3 ] = -H[k]*tau2.x; T2[(k+1)*3+1] = -H[k]*tau2.y; T2[(k+1)*3+2] = -H[k]*tau2.z; } // set up the Ni vectors N1[0] = N2[0] = 0; N1[1] = N2[1] = 0; N1[2] = N2[2] = 0; for (int k=0; k<nmeln; ++k) { N1[(k+1)*3 ] = -Hr[k]*nu.x; N1[(k+1)*3+1] = -Hr[k]*nu.y; N1[(k+1)*3+2] = -Hr[k]*nu.z; N2[(k+1)*3 ] = -Hs[k]*nu.x; N2[(k+1)*3+1] = -Hs[k]*nu.y; N2[(k+1)*3+2] = -Hs[k]*nu.z; } // calculate metric tensor M[0][0] = tau1*tau1; M[0][1] = tau1*tau2; M[1][0] = tau2*tau1; M[1][1] = tau2*tau2; // calculate curvature tensor K[0][0] = 0; K[0][1] = 0; K[1][0] = 0; K[1][1] = 0; double Grr[FEElement::MAX_NODES]; double Grs[FEElement::MAX_NODES]; double Gss[FEElement::MAX_NODES]; mel.shape_deriv2(Grr, Grs, Gss, r, s); for (int k=0; k<nmeln; ++k) { K[0][0] += (nu*rtm[k])*Grr[k]; K[0][1] += (nu*rtm[k])*Grs[k]; K[1][0] += (nu*rtm[k])*Grs[k]; K[1][1] += (nu*rtm[k])*Gss[k]; } // setup A matrix A[0][0] = M[0][0] + gap*K[0][0]; A[0][1] = M[0][1] + gap*K[0][1]; A[1][0] = M[1][0] + gap*K[1][0]; A[1][1] = M[1][1] + gap*K[1][1]; detA = A[0][0]*A[1][1] - A[0][1]*A[1][0]; // setup Di vectors for (int k=0; k<ndof; ++k) { D1[k] = (1/detA)*(A[1][1]*(T1[k]+gap*N1[k]) - A[0][1]*(T2[k] + gap*N2[k])); D2[k] = (1/detA)*(A[0][0]*(T2[k]+gap*N2[k]) - A[0][1]*(T1[k] + gap*N1[k])); } // calculate friction tractions // a. calculate trial state Tt[0] = Lt[0] + m_epsf*(Mk[0][0]*(r - rp) + Mk[0][1]*(s - sp)); Tt[1] = Lt[1] + m_epsf*(Mk[1][0]*(r - rp) + Mk[1][1]*(s - sp)); double TMT = Tt[0]*(Mki[0][0]*Tt[0]+Mki[0][1]*Tt[1])+Tt[1]*(Mki[1][0]*Tt[0]+Mki[1][1]*Tt[1]); assert(TMT >= 0); double phi = sqrt(TMT) - m_mu* tn; // b. return map if (phi > 0) { Tt[0] = m_mu* tn *Tt[0]/sqrt(TMT); Tt[1] = m_mu* tn *Tt[1]/sqrt(TMT); } // tangential force vector for (int l=0; l<ndof; ++l) fe[l] -= (Tt[0]*D1[l] + Tt[1]*D2[l]); } } //----------------------------------------------------------------------------- void FESlidingInterface::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { FEElementMatrix ke; const int MAXMN = FEElement::MAX_NODES; vector<int> lm(3*(MAXMN + 1)); vector<int> en(MAXMN+1); double *Gr, *Gs, w[MAXMN]; vec3d r0[MAXMN]; double detJ[MAXMN]; vec3d dxr, dxs; vector<int> sLM; vector<int> mLM; // do two-pass int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { // get the primary and secondary surface FESlidingSurface& ss = (np==0?m_ss:m_ms); FESlidingSurface& ms = (np==0?m_ms:m_ss); // loop over all primary surface elements int ne = ss.Elements(); for (int j=0; j<ne; ++j) { // unpack the next element FESurfaceElement& se = ss.Element(j); int nseln = se.Nodes(); // get the element's LM array ss.UnpackLM(se, sLM); // get the nodal coordinates for (int i=0; i<nseln; ++i) r0[i] = ss.GetMesh()->Node(se.m_node[i]).m_r0; // get all the metrics we need for (int n=0; n<nseln; ++n) { Gr = se.Gr(n); Gs = se.Gs(n); // calculate jacobian dxr = dxs = vec3d(0,0,0); for (int k=0; k<nseln; ++k) { dxr.x += Gr[k]*r0[k].x; dxr.y += Gr[k]*r0[k].y; dxr.z += Gr[k]*r0[k].z; dxs.x += Gs[k]*r0[k].x; dxs.y += Gs[k]*r0[k].y; dxs.z += Gs[k]*r0[k].z; } detJ[n] = (dxr ^ dxs).norm(); w[n] = se.GaussWeights()[n]; } // loop over all integration points (that is nodes) for (int n=0; n<nseln; ++n) { int m = se.m_lnode[n]; // see if this node's constraint is active // that is, if it has an element associated with it if (ss.m_data[m].m_pme != 0) { // get the secondary surface element FESurfaceElement& me = *ss.m_data[m].m_pme; // get the secondary surface element's LM array ms.UnpackLM(me, mLM); int nmeln = me.Nodes(); int ndof = 3*(nmeln+1); // calculate the stiffness matrix ke.resize(ndof, ndof); ContactNodalStiffness(m, ss, me, ke); // muliply with weights for (int k=0; k<ndof; ++k) for (int l=0; l<ndof; ++l) ke[k][l] *= detJ[n]*w[n]; // fill the lm array lm[0] = sLM[n*3 ]; lm[1] = sLM[n*3+1]; lm[2] = sLM[n*3+2]; for (int k=0; k<nmeln; ++k) { lm[3*(k+1) ] = mLM[k*3 ]; lm[3*(k+1)+1] = mLM[k*3+1]; lm[3*(k+1)+2] = mLM[k*3+2]; } // create the en array en.resize(nmeln+1); en[0] = se.m_node[n]; for (int k=0; k<nmeln; ++k) en[k+1] = me.m_node[k]; // assemble stiffness matrix ke.SetNodes(en); ke.SetIndices(lm); LS.Assemble(ke); } } } } } //----------------------------------------------------------------------------- void FESlidingInterface::ContactNodalStiffness(int m, FESlidingSurface& ss, FESurfaceElement& mel, matrix& ke) { const int MAXMN = FEElement::MAX_NODES; vector<int> lm(3*(MAXMN+1)); vector<int> en(MAXMN + 1); vec3d dxr, dxs; double H[MAXMN], Hr[MAXMN], Hs[MAXMN]; double N[3*(MAXMN+1)], T1[3*(MAXMN+1)], T2[3*(MAXMN+1)]; double N1[3*(MAXMN+1)], N2[3*(MAXMN+1)], D1[3*(MAXMN+1)], D2[3*(MAXMN+1)]; double Nb1[3*(MAXMN+1)], Nb2[3*(MAXMN+1)]; // get the mesh FEMesh& mesh = GetFEModel()->GetMesh(); // nr of element nodes and degrees of freedom int nmeln = mel.Nodes(); int ndof = 3*(1 + nmeln); // penalty factor double scale = Penalty(); double eps = ss.m_data[m].m_eps*scale; // nodal coordinates vec3d rt[MAXMN]; for (int j=0; j<nmeln; ++j) rt[j] = mesh.Node(mel.m_node[j]).m_rt; // node natural coordinates in secondary surface element double r = ss.m_data[m].m_rs[0]; double s = ss.m_data[m].m_rs[1]; // gap double gap = ss.m_data[m].m_gap; // lagrange multiplier double Lm = ss.m_data[m].m_Lm; // get node normal force double tn = Lm + eps*gap; tn = MBRACKET(tn); // get the node normal vec3d& nu = ss.m_data[m].m_nu; // get the secondary surface element shape function values and the derivatives at this node mel.shape_fnc(H, r, s); mel.shape_deriv(Hr, Hs, r, s); // get the tangent vectors vec3d tau[2]; ss.CoBaseVectors(mel, r, s, tau); // set up the N vector N[0] = nu.x; N[1] = nu.y; N[2] = nu.z; for (int k=0; k<nmeln; ++k) { N[(k+1)*3 ] = -H[k]*nu.x; N[(k+1)*3+1] = -H[k]*nu.y; N[(k+1)*3+2] = -H[k]*nu.z; } // set up the Ti vectors T1[0] = tau[0].x; T2[0] = tau[1].x; T1[1] = tau[0].y; T2[1] = tau[1].y; T1[2] = tau[0].z; T2[2] = tau[1].z; for (int k=0; k<nmeln; ++k) { T1[(k+1)*3 ] = -H[k]*tau[0].x; T1[(k+1)*3+1] = -H[k]*tau[0].y; T1[(k+1)*3+2] = -H[k]*tau[0].z; T2[(k+1)*3 ] = -H[k]*tau[1].x; T2[(k+1)*3+1] = -H[k]*tau[1].y; T2[(k+1)*3+2] = -H[k]*tau[1].z; } // set up the Ni vectors N1[0] = N2[0] = 0; N1[1] = N2[1] = 0; N1[2] = N2[2] = 0; for (int k=0; k<nmeln; ++k) { N1[(k+1)*3 ] = -Hr[k]*nu.x; N1[(k+1)*3+1] = -Hr[k]*nu.y; N1[(k+1)*3+2] = -Hr[k]*nu.z; N2[(k+1)*3 ] = -Hs[k]*nu.x; N2[(k+1)*3+1] = -Hs[k]*nu.y; N2[(k+1)*3+2] = -Hs[k]*nu.z; } // calculate metric tensor mat2d M; M[0][0] = tau[0]*tau[0]; M[0][1] = tau[0]*tau[1]; M[1][0] = tau[1]*tau[0]; M[1][1] = tau[1]*tau[1]; // calculate reciprocal metric tensor mat2d Mi = M.inverse(); // calculate curvature tensor double K[2][2] = {0}; double Grr[FEElement::MAX_NODES]; double Grs[FEElement::MAX_NODES]; double Gss[FEElement::MAX_NODES]; mel.shape_deriv2(Grr, Grs, Gss, r, s); for (int k=0; k<nmeln; ++k) { K[0][0] += (nu*rt[k])*Grr[k]; K[0][1] += (nu*rt[k])*Grs[k]; K[1][0] += (nu*rt[k])*Grs[k]; K[1][1] += (nu*rt[k])*Gss[k]; } // setup A matrix A = M + gK double A[2][2]; A[0][0] = M[0][0] + gap*K[0][0]; A[0][1] = M[0][1] + gap*K[0][1]; A[1][0] = M[1][0] + gap*K[1][0]; A[1][1] = M[1][1] + gap*K[1][1]; // calculate determinant of A double detA = A[0][0]*A[1][1] - A[0][1]*A[1][0]; // setup Di vectors for (int k=0; k<ndof; ++k) { D1[k] = (1/detA)*(A[1][1]*(T1[k]+gap*N1[k]) - A[0][1]*(T2[k] + gap*N2[k])); D2[k] = (1/detA)*(A[0][0]*(T2[k]+gap*N2[k]) - A[0][1]*(T1[k] + gap*N1[k])); } // setup Nbi vectors for (int k=0; k<ndof; ++k) { Nb1[k] = N1[k] - K[0][1]*D2[k]; Nb2[k] = N2[k] - K[0][1]*D1[k]; } // --- N O R M A L S T I F F N E S S --- double sum; for (int k=0; k<ndof; ++k) for (int l=0; l<ndof; ++l) { sum = 0; sum = Mi[0][0]*Nb1[k]*Nb1[l]+Mi[0][1]*(Nb1[k]*Nb2[l]+Nb2[k]*Nb1[l])+Mi[1][1]*Nb2[k]*Nb2[l]; sum *= gap; sum -= D1[k]*N1[l]+D2[k]*N2[l]+N1[k]*D1[l]+N2[k]*D2[l]; sum += K[0][1]*(D1[k]*D2[l]+D2[k]*D1[l]); sum *= tn*m_knmult; sum += eps*HEAVYSIDE(Lm+eps*gap)*N[k]*N[l]; ke[k][l] = sum; } // --- T A N G E N T I A L S T I F F N E S S --- // We only calculate the tangential stiffness if friction is enabled. We also // make sure that the gap >= 0, i.e. the node is actually in contact, otherwise // I've noticed that the solution can diverge quickly. if ((m_mu*m_epsf > 0) && (gap >=0)) { // get the traction multipliers double Lt[2]; Lt[0] = ss.m_data[m].m_Lt[0]; Lt[1] = ss.m_data[m].m_Lt[1]; // get the metric tensor and its inverse mat2d& Mk = ss.m_data[m].m_M; mat2d Mki = Mk.inverse(); // get the previous isoparameteric coordinates double rp = ss.m_data[m].m_rsp[0]; double sp = ss.m_data[m].m_rsp[1]; // get the traction double Tt[2]; // a. trial state Tt[0] = Lt[0] + Mk[0][0]*(r - rp) + Mk[0][1]*(s - sp); Tt[1] = Lt[1] + Mk[1][0]*(r - rp) + Mk[1][1]*(s - sp); double TMT = Tt[0]*(Mki[0][0]*Tt[0] + Mki[0][1]*Tt[1]) + Tt[1]*(Mki[1][0]*Tt[0] + Mki[1][1]*Tt[1]); // calculate the normalized traction vector vec3d pt = tau[0]*Tt[0] + tau[1]*Tt[1]; pt.unit(); // calculate the covariant version double Pt[2] = {Tt[0]/sqrt(TMT), Tt[1]/sqrt(TMT)}; double Ptc[2]; Ptc[0] = Mki[0][0]*Pt[0]+Mki[0][1]*Pt[1]; Ptc[1] = Mki[1][0]*Pt[0]+Mki[1][1]*Pt[1]; //b. return map bool bstick = true; double phi = sqrt(TMT) - m_mu*tn; if (phi > 0) { Tt[0] = m_mu*Tt[0]/sqrt(TMT); Tt[1] = m_mu*Tt[1]/sqrt(TMT); bstick = false; } // we need to define additional arrays for the tangential // contribution of the contact stiffness double T11[3*(MAXMN+1)] = {0}, T12[3*(MAXMN+1)] = {0}, T21[3*(MAXMN+1)] = {0}, T22[3*(MAXMN+1)] = {0}; // Tab matrix double N11[3*(MAXMN+1)] = {0}, N12[3*(MAXMN+1)] = {0}, N21[3*(MAXMN+1)] = {0}, N22[3*(MAXMN+1)] = {0}; // Nab matrix double P1[3*(MAXMN+1)] = {0}, P2[3*(MAXMN+1)] = {0}; // P arrays double Tb11[3*(MAXMN+1)], Tb21[3*(MAXMN+1)], Tb12[3*(MAXMN+1)], Tb22[3*(MAXMN+1)]; // Tbar matrix double Pb1[3*(MAXMN+1)], Pb2[3*(MAXMN+1)]; // Pbar array for (int k=0; k<nmeln; ++k) { T11[3*(k+1) ] = -Hr[k]*tau[0].x; T11[3*(k+1)+1] = -Hr[k]*tau[0].y; T11[3*(k+1)+2] = -Hr[k]*tau[0].z; T12[3*(k+1) ] = -Hs[k]*tau[0].x; T12[3*(k+1)+1] = -Hs[k]*tau[0].y; T12[3*(k+1)+2] = -Hs[k]*tau[0].z; T21[3*(k+1) ] = -Hr[k]*tau[1].x; T21[3*(k+1)+1] = -Hr[k]*tau[1].y; T21[3*(k+1)+2] = -Hr[k]*tau[1].z; T22[3*(k+1) ] = -Hs[k]*tau[1].x; T22[3*(k+1)+1] = -Hs[k]*tau[1].y; T22[3*(k+1)+2] = -Hs[k]*tau[1].z; if (nmeln==4) { N12[3*(k+1) ] = N21[3*(k+1) ] = -0.25*nu.x; N12[3*(k+1)+1] = N21[3*(k+1)+1] = -0.25*nu.y; N12[3*(k+1)+2] = N21[3*(k+1)+2] = -0.25*nu.z; } else if (nmeln == 6) assert(false); P1[3*(k+1) ] = -Hr[k]*pt.x; P1[3*(k+1)+1] = -Hr[k]*pt.y; P1[3*(k+1)+2] = -Hr[k]*pt.z; P2[3*(k+1) ] = -Hs[k]*pt.x; P2[3*(k+1)+1] = -Hs[k]*pt.y; P2[3*(k+1)+2] = -Hs[k]*pt.z; } vec3d g12(0,0,0); if (nmeln == 4) { const double Grs[4] = {0.25, -0.25, 0.25, -0.25}; g12 = rt[0]*Grs[0]+rt[1]*Grs[1]+rt[2]*Grs[2]+rt[3]*Grs[3]; } else if (nmeln == 6) { const double Grs[6] = {4.0, 0.0, 0.0, -4.0, 4.0, -4.0}; g12 = rt[0]*Grs[0]+rt[1]*Grs[1]+rt[2]*Grs[2]+rt[3]*Grs[3]+rt[4]*Grs[4]+rt[5]*Grs[5]; } else { assert(false); } double gt1 = g12*tau[0]; double gt2 = g12*tau[1]; double gp = g12*pt; for (int k=0; k<ndof; ++k) { Tb11[k] = T11[k] - gt1*D2[k]; Tb12[k] = T12[k] - gt1*D1[k]; Tb21[k] = T21[k] - gt2*D2[k]; Tb22[k] = T22[k] - gt2*D1[k]; Pb1[k] = P1[k] - gp*D2[k]; Pb2[k] = P2[k] - gp*D1[k]; } // raise the indices of A double Ac[2][2]; for (int k=0; k<2; ++k) for (int l=0; l<2; ++l) { Ac[k][l] = 0; for (int i=0; i<2; ++i) for (int j=0; j<2; ++j) Ac[k][l] += Mki[k][i]*Mki[l][j]*A[i][j]; } vec3d Hrs[2][2] = {{vec3d(0,0,0),vec3d(0,0,0)},{vec3d(0,0,0),vec3d(0,0,0)}}; if (nmeln == 4) { const double Grs[4] = {0.25, -0.25, 0.25, -0.25}; Hrs[0][1] = Hrs[1][0] = rt[0]*Grs[0]+rt[1]*Grs[1]+rt[2]*Grs[2]+rt[3]*Grs[3]; } else if (nmeln == 6) { const double Grs[6] = {4.0, 0.0, 0.0, -4.0, 4.0, -4.0}; Hrs[0][1] = Hrs[1][0] = rt[0]*Grs[0]+rt[1]*Grs[1]+rt[2]*Grs[2]+rt[3]*Grs[3]+rt[4]*Grs[4]+rt[5]*Grs[5]; } // calculate stiffness matrix // NOTE: I think I need Mi (iso Mki) for KT1 and KT2. I only need Mk (iso M) for the direct stiffnesses double kij; for (int i=0; i<ndof; ++i) for (int j=0; j<ndof; ++j) { // KT1 kij = T11[i]*D1[j] + T12[i]*D2[j]; kij += D1[i]*T11[j] + D2[i]*T12[j]; kij -= (Hrs[0][1]*tau[0])*D1[i]*D2[j] + (Hrs[1][0]*tau[0])*D2[i]*D1[j]; kij += Tb11[i]*D1[j] + Tb21[i]*D2[j]; kij += D1[i]*Tb11[j] + D2[i]*Tb21[j]; kij += gap*(N11[i]*D1[j] + N12[i]*D2[j] + D1[i]*N11[j] + D2[i]*N12[j]); kij -= N[i]*Nb1[j] - Nb1[i]*N[j]; kij -= T1[i]*Mi[0][0]*Tb11[j] + T1[i]*Mi[0][1]*Tb21[j] + T2[i]*Mi[1][0]*Tb11[j] + T2[i]*Mi[1][1]*Tb21[j]; kij -= Tb11[i]*Mi[0][0]*T1[j] + Tb21[i]*Mi[0][1]*T1[j] + Tb11[i]*Mi[1][0]*T2[j] + Tb21[i]*Mi[1][1]*T2[j]; ke[i][j] += m_ktmult*(Tt[0]*Ac[0][0] + Tt[1]*Ac[1][0])*kij; // KT2 kij = T21[i]*D1[j] + T22[i]*D2[j]; kij += D1[i]*T21[j] + D2[i]*T22[j]; kij -= (Hrs[0][1]*tau[1])*D1[i]*D2[j] + (Hrs[1][0]*tau[1])*D2[i]*D1[j]; kij += Tb12[i]*D1[j] + Tb22[i]*D2[j]; kij += D1[i]*Tb12[j] + D2[i]*Tb22[j]; kij += gap*(N21[i]*D1[j] + N22[i]*D2[j] + D1[i]*N21[j] + D2[i]*N22[j]); kij -= N[i]*Nb2[j] - Nb2[i]*N[j]; kij -= T1[i]*Mi[0][0]*Tb12[j] + T1[i]*Mi[0][1]*Tb22[j] + T2[i]*Mi[1][0]*Tb12[j] + T2[i]*Mi[1][1]*Tb22[j]; kij -= Tb12[i]*Mi[0][0]*T1[j] + Tb22[i]*Mi[0][1]*T1[j] + Tb12[i]*Mi[1][0]*T2[j] + Tb22[i]*Mi[1][1]*T2[j]; ke[i][j] += m_ktmult*(Tt[0]*Ac[0][1] + Tt[1]*Ac[1][1])*kij; // kdirect if (bstick) { kij = Mk[0][0]*D1[i]*D1[j] + Mk[0][1]*D1[i]*D2[j] + Mk[1][0]*D2[i]*D1[j] + Mk[1][1]*D2[i]*D2[j]; ke[i][j] += m_epsf*kij; } else { kij = (1.0 - Ptc[0]*Pt[0])*(Mk[0][0]*D1[i]*D1[j]+Mk[0][1]*D1[i]*D2[j]); kij += ( - Ptc[0]*Pt[1])*(Mk[1][0]*D1[i]*D1[j]+Mk[1][1]*D1[i]*D2[j]); kij += ( - Ptc[1]*Pt[0])*(Mk[0][0]*D2[i]*D1[j]+Mk[0][1]*D2[i]*D2[j]); kij += (1.0 - Ptc[1]*Pt[1])*(Mk[1][0]*D2[i]*D1[j]+Mk[1][1]*D2[i]*D2[j]); ke[i][j] += m_ktmult*m_epsf*m_mu*tn/sqrt(TMT)*kij; } } } } //----------------------------------------------------------------------------- bool FESlidingInterface::Augment(int naug, const FETimeInfo& tp) { // make sure we need to augment if (m_laugon != FECore::AUGLAG_METHOD) return true; double Ln; double Lt[2]; bool bconv = true; mat2d Mi; // penalty factor double eps, scale = Penalty(); // --- c a l c u l a t e i n i t i a l n o r m s --- // a. normal component double normL0 = 0; for (int i=0; i<m_ss.Nodes(); ++i) normL0 += m_ss.m_data[i].m_Lm*m_ss.m_data[i].m_Lm; for (int i=0; i<m_ms.Nodes(); ++i) normL0 += m_ms.m_data[i].m_Lm*m_ms.m_data[i].m_Lm; // b. tangential component if (m_mu*m_epsf > 0) { for (int i=0; i<m_ss.Nodes(); ++i) { if (m_ss.m_data[i].m_pme) { Lt[0] = m_ss.m_data[i].m_Lt[0]; Lt[1] = m_ss.m_data[i].m_Lt[1]; mat2d& M = m_ss.m_data[i].m_M; Mi = M.inverse(); normL0 += Lt[0]*(Mi[0][0]*Lt[0] + Mi[0][1]*Lt[1]) + Lt[1]*(Mi[1][0]*Lt[0] + Mi[1][1]*Lt[1]); } } for (int i=0; i<m_ms.Nodes(); ++i) { if (m_ms.m_data[i].m_pme) { Lt[0] = m_ms.m_data[i].m_Lt[0]; Lt[1] = m_ms.m_data[i].m_Lt[1]; mat2d& M = m_ms.m_data[i].m_M; Mi = M.inverse(); normL0 += Lt[0]*(Mi[0][0]*Lt[0] + Mi[0][1]*Lt[1]) + Lt[1]*(Mi[1][0]*Lt[0] + Mi[1][1]*Lt[1]); } } } normL0 = sqrt(normL0); // --- c a l c u l a t e c u r r e n t n o r m s --- // a. normal component double normL1 = 0; // force norm double normg1 = 0; // gap norm int N = 0; for (int i=0; i<m_ss.Nodes(); ++i) { eps = m_ss.m_data[i].m_eps*scale; // update Lagrange multipliers Ln = m_ss.m_data[i].m_Lm + eps*m_ss.m_data[i].m_gap; Ln = MBRACKET(Ln); normL1 += Ln*Ln; if (m_ss.m_data[i].m_gap > 0) { normg1 += m_ss.m_data[i].m_gap*m_ss.m_data[i].m_gap; ++N; } } for (int i=0; i<m_ms.Nodes(); ++i) { eps = m_ms.m_data[i].m_eps*scale; // update Lagrange multipliers Ln = m_ms.m_data[i].m_Lm + eps*m_ms.m_data[i].m_gap; Ln = MBRACKET(Ln); normL1 += Ln*Ln; if (m_ms.m_data[i].m_gap > 0) { normg1 += m_ms.m_data[i].m_gap*m_ms.m_data[i].m_gap; ++N; } } if (N == 0) N=1; // b. tangential component if (m_mu*m_epsf > 0) { double r, s, rp, sp; for (int i=0; i<m_ss.Nodes(); ++i) { if (m_ss.m_data[i].m_pme) { r = m_ss.m_data[i].m_rs[0]; s = m_ss.m_data[i].m_rs[1]; rp = m_ss.m_data[i].m_rsp[0]; sp = m_ss.m_data[i].m_rsp[1]; Ln = m_ss.m_data[i].m_Lm; mat2d& Mk = m_ss.m_data[i].m_M; Mi = Mk.inverse(); Lt[0] = m_ss.m_data[i].m_Lt[0] + m_epsf*(Mk[0][0]*(r - rp) + Mk[0][1]*(s - sp)); Lt[1] = m_ss.m_data[i].m_Lt[1] + m_epsf*(Mk[1][0]*(r - rp) + Mk[1][1]*(s - sp)); double TMT = Lt[0]*(Mi[0][0]*Lt[0]+Mi[0][1]*Lt[1])+Lt[1]*(Mi[1][0]*Lt[0]+Mi[1][1]*Lt[1]); double phi = sqrt(TMT) - m_mu*Ln; // b. return map if (phi > 0) { Lt[0] = m_mu*Ln*Lt[0]/sqrt(TMT); Lt[1] = m_mu*Ln*Lt[1]/sqrt(TMT); } normL1 += Lt[0]*(Mi[0][0]*Lt[0] + Mi[0][1]*Lt[1]) + Lt[1]*(Mi[1][0]*Lt[0] + Mi[1][1]*Lt[1]); } } for (int i=0; i<m_ms.Nodes(); ++i) { if (m_ms.m_data[i].m_pme) { r = m_ms.m_data[i].m_rs[0]; s = m_ms.m_data[i].m_rs[1]; rp = m_ms.m_data[i].m_rsp[0]; sp = m_ms.m_data[i].m_rsp[1]; Ln = m_ms.m_data[i].m_Lm; mat2d& Mk = m_ms.m_data[i].m_M; Mi = Mk.inverse(); Lt[0] = m_ms.m_data[i].m_Lt[0] + m_epsf*(Mk[0][0]*(r - rp) + Mk[0][1]*(s - sp)); Lt[1] = m_ms.m_data[i].m_Lt[1] + m_epsf*(Mk[1][0]*(r - rp) + Mk[1][1]*(s - sp)); double TMT = Lt[0]*(Mi[0][0]*Lt[0]+Mi[0][1]*Lt[1])+Lt[1]*(Mi[1][0]*Lt[0]+Mi[1][1]*Lt[1]); double phi = sqrt(TMT) - m_mu*Ln; // b. return map if (phi > 0) { Lt[0] = m_mu*Ln*Lt[0]/sqrt(TMT); Lt[1] = m_mu*Ln*Lt[1]/sqrt(TMT); } normL1 += Lt[0]*(Mi[0][0]*Lt[0] + Mi[0][1]*Lt[1]) + Lt[1]*(Mi[1][0]*Lt[0] + Mi[1][1]*Lt[1]); } } } normL1 = sqrt(normL1); normg1 = sqrt(normg1 / N); if (naug == 0) m_normg0 = 0; // calculate and print convergence norms double lnorm = 0, gnorm = 0; if (normL1 != 0) lnorm = fabs(normL1 - normL0)/normL1; else lnorm = fabs(normL1 - normL0); // if (normg1 != 0) gnorm = fabs(normg1 - m_normg0)/normg1; else gnorm = fabs(normg1 - m_normg0); gnorm = fabs(normg1 - m_normg0); feLog(" sliding interface # %d\n", GetID()); feLog(" CURRENT REQUIRED\n"); feLog(" normal force : %15le", lnorm); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n"); feLog(" gap function : %15le", gnorm); if (m_gtol > 0) feLog("%15le\n", m_gtol); else feLog(" ***\n"); // check convergence bconv = true; if ((m_atol > 0) && (lnorm > m_atol)) bconv = false; if ((m_gtol > 0) && (gnorm > m_gtol)) bconv = false; if (m_naugmin > naug) bconv = false; if (m_naugmax <= naug) bconv = true; if (bconv == false) { // we did not converge so update multipliers for (int i=0; i<m_ss.Nodes(); ++i) { eps = m_ss.m_data[i].m_eps*scale; // update Lagrange multipliers Ln = m_ss.m_data[i].m_Lm + eps*m_ss.m_data[i].m_gap; m_ss.m_data[i].m_Lm = MBRACKET(Ln); if ((m_mu*m_epsf > 0) && (m_ss.m_data[i].m_pme)) { // update the metrics FESurfaceElement& mel = *m_ss.m_data[i].m_pme; double r = m_ss.m_data[i].m_rs[0], s = m_ss.m_data[i].m_rs[1]; double rp = m_ss.m_data[i].m_rsp[0], sp = m_ss.m_data[i].m_rsp[1]; double Ln = m_ss.m_data[i].m_Lm; mat2d Mk = m_ss.m_data[i].m_M; mat2d Mki = Mk.inverse(); // update traction multipliers // a. trial state Lt[0] = m_ss.m_data[i].m_Lt[0] + m_epsf*(Mk[0][0]*(r - rp) + Mk[0][1]*(s - sp)); Lt[1] = m_ss.m_data[i].m_Lt[1] + m_epsf*(Mk[1][0]*(r - rp) + Mk[1][1]*(s - sp)); double TMT = Lt[0]*(Mki[0][0]*Lt[0]+Mki[0][1]*Lt[1])+Lt[1]*(Mki[1][0]*Lt[0]+Mki[1][1]*Lt[1]); assert(TMT >= 0); double phi = sqrt(TMT) - m_mu*Ln; // b. return map if (phi > 0) { Lt[0] = m_mu*Ln*Lt[0]/sqrt(TMT); Lt[1] = m_mu*Ln*Lt[1]/sqrt(TMT); } m_ss.m_data[i].m_M = m_ss.Metric0(mel, r, s); m_ss.m_data[i].m_Lt[0] = Lt[0]; m_ss.m_data[i].m_Lt[1] = Lt[1]; } } for (int i=0; i<m_ms.Nodes(); ++i) { eps = m_ms.m_data[i].m_eps*scale; // update Lagrange multipliers Ln = m_ms.m_data[i].m_Lm + eps*m_ms.m_data[i].m_gap; m_ms.m_data[i].m_Lm = MBRACKET(Ln); if ((m_mu*m_epsf > 0) && (m_ms.m_data[i].m_pme)) { // update the metrics FESurfaceElement& mel = *m_ms.m_data[i].m_pme; double r = m_ms.m_data[i].m_rs[0], s = m_ms.m_data[i].m_rs[1]; double rp = m_ms.m_data[i].m_rsp[0], sp = m_ms.m_data[i].m_rsp[1]; double Ln = m_ms.m_data[i].m_Lm; mat2d Mk = m_ms.m_data[i].m_M; mat2d Mki = Mk.inverse(); // update traction multipliers // a. trial state double Lt[2]; Lt[0] = m_ms.m_data[i].m_Lt[0] + m_epsf*(Mk[0][0]*(r - rp) + Mk[0][1]*(s - sp)); Lt[1] = m_ms.m_data[i].m_Lt[1] + m_epsf*(Mk[1][0]*(r - rp) + Mk[1][1]*(s - sp)); double TMT = Lt[0]*(Mki[0][0]*Lt[0]+Mki[0][1]*Lt[1])+Lt[1]*(Mki[1][0]*Lt[0]+Mki[1][1]*Lt[1]); assert(TMT >= 0); double phi = sqrt(TMT) - m_mu*Ln; // b. return map if (phi > 0) { Lt[0] = m_mu*Ln*Lt[0]/sqrt(TMT); Lt[1] = m_mu*Ln*Lt[1]/sqrt(TMT); } m_ms.m_data[i].m_M = m_ms.Metric0(mel, r, s); m_ms.m_data[i].m_Lt[0] = Lt[0]; m_ms.m_data[i].m_Lt[1] = Lt[1]; } } } if (bconv) { for (int i=0; i<m_ss.Nodes(); ++i) m_ss.m_data[i].m_rsp = m_ss.m_data[i].m_rs; for (int i=0; i<m_ms.Nodes(); ++i) m_ms.m_data[i].m_rsp = m_ms.m_data[i].m_rs; } // store the last gap norm m_normg0 = normg1; return bconv; } //----------------------------------------------------------------------------- //! This function transforms friction data between two segments void FESlidingInterface::MapFrictionData(int inode, FESlidingSurface& ss, FESlidingSurface& ms, FESurfaceElement &en, FESurfaceElement &eo, vec3d &q) { // first we find the projection of the old point on the new segment double r = ss.m_data[inode].m_rs[0]; double s = ss.m_data[inode].m_rs[1]; double rp = ss.m_data[inode].m_rsp[0], ro = rp; double sp = ss.m_data[inode].m_rsp[1], so = sp; vec3d xn = ms.Local2Global(eo, rp, sp); vec3d qn; qn = ms.ProjectToSurface(en, xn, rp, sp); ss.m_data[inode].m_rsp[0] = rp; ss.m_data[inode].m_rsp[1] = sp; // next, we transform the frictional traction // since these tractions are decomposed in the local // element coordinate system, we have to do a coordinate transformation // note that this transformation needs to be done in curvilinear // coordinates since the base vectors may not be orthonormal. Also // note that we are doing this in the reference configuration vec3d to[2], tn[2]; ms.ContraBaseVectors0(eo, ro, so, to); ms.CoBaseVectors0(en, r, s, tn); double Lt[2]; Lt[0] = ss.m_data[inode].m_Lt[0]; Lt[1] = ss.m_data[inode].m_Lt[1]; vec3d t; t = to[0]*Lt[0] + to[1]*Lt[1]; Lt[0] = t*tn[0]; Lt[1] = t*tn[1]; ss.m_data[inode].m_Lt[0] = Lt[0]; ss.m_data[inode].m_Lt[1] = Lt[1]; } //----------------------------------------------------------------------------- void FESlidingInterface::UpdateContactPressures() { int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FESlidingSurface& ss = (np == 0? m_ss : m_ms); FESlidingSurface& ms = (np == 0? m_ms : m_ss); // loop over all nodes of the primary surface for (int n=0; n<ss.Nodes(); ++n) { // get the normal tractions at the integration points double gap = ss.m_data[n].m_gap; double eps = m_eps*ss.m_data[n].m_eps; ss.m_data[n].m_Ln = MBRACKET(ss.m_data[n].m_Lm + eps*gap); FESurfaceElement* pme = ss.m_data[n].m_pme; if (m_btwo_pass && pme) { int me = pme->Nodes(); if (me < 6) { double ti[6]; for (int j=0; j<me; ++j) { int k = pme->m_lnode[j]; gap = ms.m_data[k].m_gap; eps = m_eps*ms.m_data[k].m_eps; ti[j] = MBRACKET(ms.m_data[k].m_Lm + m_eps*ms.m_data[k].m_eps*ms.m_data[k].m_gap); } // project the data to the nodes double tn[6]; pme->FEElement::project_to_nodes(ti, tn); // now evaluate the traction at the intersection point double Ln = pme->eval(tn, ss.m_data[n].m_rs[0], ss.m_data[n].m_rs[1]); ss.m_data[n].m_Ln += MBRACKET(Ln); } } } } } //----------------------------------------------------------------------------- void FESlidingInterface::Serialize(DumpStream& ar) { // store contact data FEContactInterface::Serialize(ar); // store contact surface data m_ms.Serialize(ar); m_ss.Serialize(ar); // restore element pointers SerializePointers(m_ss, m_ms, ar); SerializePointers(m_ms, m_ss, ar); ar & m_bfirst & m_normg0; } void FESlidingInterface::SerializePointers(FESlidingSurface& ss, FESlidingSurface& ms, DumpStream& ar) { if (ar.IsSaving()) { for (int i = 0; i < ss.m_data.size(); i++) { FESurfaceElement* pe = ss.m_data[i].m_pme; int eid = (pe ? pe->m_lid : -1); ar << eid; } } else { for (int i = 0; i < ss.m_data.size(); i++) { int eid = -1; ar >> eid; if (eid >= 0) { FESurfaceElement* pe = &ms.Element(eid); ss.m_data[i].m_pme = pe; } else ss.m_data[i].m_pme = nullptr; } } }
C++
3D
febiosoftware/FEBio
FEBioMech/FEBondRecruitment.cpp
.cpp
10,920
313
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEBondRecruitment.h" #include <FECore/log.h> #include <FECore/gamma.h> #include <math.h> /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEBondRecruitmentUser, FEBondRecruitment) ADD_PROPERTY(m_brf, "function"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEBondRecruitmentUser::FEBondRecruitmentUser(FEModel* pfem) : FEBondRecruitment(pfem) { m_brf = nullptr; } //----------------------------------------------------------------------------- // User-defined loadcurve for bond recruitment function double FEBondRecruitmentUser::brf(FEMaterialPoint& mp, const double X) { return m_brf->value(X); } /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEBondRecruitmentPower, FEBondRecruitment) ADD_PARAMETER(m_alpha, "alpha" )->setLongName("power exponent"); ADD_PARAMETER(m_mu0 , "mu0" )->setLongName("constant mu0"); ADD_PARAMETER(m_mu1 , "mu1" )->setLongName("power coefficient"); ADD_PARAMETER(m_s , FE_RANGE_GREATER(0.0) , "scale" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEBondRecruitmentPower::FEBondRecruitmentPower(FEModel* pfem) : FEBondRecruitment(pfem) { m_alpha = 2; m_mu0 = 1; m_mu1 = 0; m_s = 1; } //----------------------------------------------------------------------------- // Power bond recruitment function double FEBondRecruitmentPower::brf(FEMaterialPoint& mp, const double X) { double brf = 0; double alpha = m_alpha(mp); double mu0 = m_mu0(mp); double mu1 = m_mu1(mp); double s = m_s(mp); // this brf only admits positive values if (X > 0) brf = mu0 + mu1*pow(X/s,alpha); return brf; } /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEBondRecruitmentExp, FEBondRecruitment) ADD_PARAMETER(m_alpha, FE_RANGE_GREATER_OR_EQUAL(0.0), "alpha" ); ADD_PARAMETER(m_mu0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "mu0" ); ADD_PARAMETER(m_mu1 , "mu1" ); ADD_PARAMETER(m_s , FE_RANGE_GREATER(0.0) , "scale" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEBondRecruitmentExp::FEBondRecruitmentExp(FEModel* pfem) : FEBondRecruitment(pfem) { m_alpha = 1; m_mu0 = 1; m_mu1 = 0; m_s = 1; } //----------------------------------------------------------------------------- // Exponential bond recruitment function double FEBondRecruitmentExp::brf(FEMaterialPoint& mp, const double X) { double brf = 0; double alpha = m_alpha(mp); double mu0 = m_mu0(mp); double mu1 = m_mu1(mp); double s = m_s(mp); // this brf only admits positive values if (X > 0) brf = mu0*exp(mu1*pow(X/s,alpha)); return brf; } /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEBondRecruitmentPoly, FEBondRecruitment) ADD_PARAMETER(m_mu0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "mu0" ); ADD_PARAMETER(m_mu1 , "mu1" ); ADD_PARAMETER(m_mu2 , "mu2" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEBondRecruitmentPoly::FEBondRecruitmentPoly(FEModel* pfem) : FEBondRecruitment(pfem) { m_mu0 = 1; m_mu1 = 0; m_mu2 = 0; } //----------------------------------------------------------------------------- // Poly bond recruitment function double FEBondRecruitmentPoly::brf(FEMaterialPoint& mp, const double X) { double brf = 0; double mu0 = m_mu0(mp); double mu1 = m_mu1(mp); double mu2 = m_mu2(mp); // this brf only admits positive arguments if (X > 0) brf = mu0 + mu1*X + mu2*X*X; return brf; } /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEBondRecruitmentLogNormal, FEBondRecruitment) ADD_PARAMETER(m_mu , FE_RANGE_GREATER(0.0), "mu"); ADD_PARAMETER(m_sigma, FE_RANGE_GREATER(0.0), "sigma"); ADD_PARAMETER(m_max , FE_RANGE_GREATER_OR_EQUAL(0.0), "max")->setLongName("max recruitment increase"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEBondRecruitmentLogNormal::FEBondRecruitmentLogNormal(FEModel* pfem) : FEBondRecruitment(pfem) { m_mu = 1; m_sigma = 1; m_max = 0; } //----------------------------------------------------------------------------- // Lognormal damage cumulative distribution function double FEBondRecruitmentLogNormal::brf(FEMaterialPoint& mp, const double X) { double brf = 0; double mu = m_mu(mp); double sigma = m_sigma(mp); double maxr = m_max(mp); // this brf only admits positive values if (X >= 0) brf = 1.0 + maxr*(0.5*erfc(-log(X/mu)/sigma/sqrt(2.))); return brf; } /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEBondRecruitmentWeibull, FEBondRecruitment) ADD_PARAMETER(m_alpha, FE_RANGE_GREATER_OR_EQUAL(0.0), "alpha"); ADD_PARAMETER(m_mu , FE_RANGE_GREATER_OR_EQUAL(0.0), "mu"); ADD_PARAMETER(m_ploc, "ploc"); ADD_PARAMETER(m_max , FE_RANGE_GREATER_OR_EQUAL(0.0), "max")->setLongName("max recruitment increase"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEBondRecruitmentWeibull::FEBondRecruitmentWeibull(FEModel* pfem) : FEBondRecruitment(pfem) { m_alpha = 1; m_mu = 1; m_ploc = 0; m_max = 0; } //----------------------------------------------------------------------------- // Weibull damage cumulative distribution function double FEBondRecruitmentWeibull::brf(FEMaterialPoint& mp, const double X) { double brf = 0; double alpha = m_alpha(mp); double mu = m_mu(mp); double ploc = m_ploc(mp); double maxr = m_max(mp); // this brf only admits positive values if (X > ploc) brf = 1 + maxr*(1 - exp(-pow((X-ploc)/mu,alpha))); return brf; } /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEBondRecruitmentPQP, FEBondRecruitment) ADD_PARAMETER(m_mumin, FE_RANGE_GREATER_OR_EQUAL(0.0), "mumin"); ADD_PARAMETER(m_mumax, "mumax"); ADD_PARAMETER(m_max , FE_RANGE_GREATER_OR_EQUAL(0.0), "max")->setLongName("max recruitment increase"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEBondRecruitmentPQP::FEBondRecruitmentPQP(FEModel* pfem) : FEBondRecruitment(pfem) { m_mumin = 0; m_mumax = 1; m_max = 0; } //----------------------------------------------------------------------------- //! Initialization. bool FEBondRecruitmentPQP::Validate() { return FEBondRecruitment::Validate(); } //----------------------------------------------------------------------------- // Piecewise S-shaped quintic polynomial damage bond recruitment function double FEBondRecruitmentPQP::brf(FEMaterialPoint& mp, const double X) { double brf = 0; double mumin = m_mumin(mp); double mumax = m_mumax(mp); double maxr = m_max(mp); if (X <= mumin) brf = 1; else if (X >= mumax) brf = 1+maxr; else { double x = (X - mumin)/(mumax - mumin); brf = 1 + maxr*(pow(x,3)*(10 - 15*x + 6*x*x)); } return brf; } /////////////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEBondRecruitmentGamma, FEBondRecruitment) ADD_PARAMETER(m_alpha, FE_RANGE_GREATER(0), "alpha"); ADD_PARAMETER(m_mu , FE_RANGE_GREATER_OR_EQUAL(0.0), "mu" ); ADD_PARAMETER(m_max , FE_RANGE_GREATER_OR_EQUAL(0.0), "max")->setLongName("max recruitment increase"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEBondRecruitmentGamma::FEBondRecruitmentGamma(FEModel* pfem) : FEBondRecruitment(pfem) { m_alpha = 2; m_mu = 4; m_max = 0; } //----------------------------------------------------------------------------- // Gamma damage cumulative distribution function double FEBondRecruitmentGamma::brf(FEMaterialPoint& mp, const double X) { double brf = 1; double alpha = m_alpha(mp); double mu = m_mu(mp); double maxr = m_max(mp); // this CDF only admits positive values double scale = gamma_inc_Q(alpha,0); if (X > 0) brf = 1 + maxr*gamma_inc_P(alpha,X/mu)/scale; return brf; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEGenericTransIsoHyperelastic.cpp
.cpp
9,450
295
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEGenericTransIsoHyperelastic.h" #include <FECore/MMath.h> #include <FECore/MObj2String.h> #include <FECore/log.h> #include <FECore/FEConstValueVec3.h> BEGIN_FECORE_CLASS(FEGenericTransIsoHyperelastic, FEElasticMaterial) ADD_PARAMETER(m_exp, "W"); ADD_PROPERTY(m_fiber, "fiber"); END_FECORE_CLASS(); FEGenericTransIsoHyperelastic::FEGenericTransIsoHyperelastic(FEModel* fem) : FEElasticMaterial(fem) { m_fiber = nullptr; } bool FEGenericTransIsoHyperelastic::Init() { vector<string> vars = { "I1", "I2", "I4", "I5", "J" }; // add all user parameters FEParameterList& pl = GetParameterList(); FEParamIterator pi = pl.first(); m_param.clear(); for (int i = 0; i < pl.Parameters(); ++i, ++pi) { FEParam& p = *pi; if (p.GetFlags() & FEParamFlag::FE_PARAM_USER) { vars.push_back(p.name()); m_param.push_back((double*)p.data_ptr()); } } // create math object m_W.AddVariables(vars); if (m_W.Create(m_exp) == false) return false; // calculate all derivatives MITEM W1 = MSimplify(MDerive(m_W.GetExpression(), *m_W.Variable(0), 1)); MITEM W2 = MSimplify(MDerive(m_W.GetExpression(), *m_W.Variable(1), 1)); MITEM W4 = MSimplify(MDerive(m_W.GetExpression(), *m_W.Variable(2), 1)); MITEM W5 = MSimplify(MDerive(m_W.GetExpression(), *m_W.Variable(3), 1)); MITEM WJ = MSimplify(MDerive(m_W.GetExpression(), *m_W.Variable(4), 1)); m_W1.AddVariables(vars); m_W1.SetExpression(W1); m_W2.AddVariables(vars); m_W2.SetExpression(W2); m_W4.AddVariables(vars); m_W4.SetExpression(W4); m_W5.AddVariables(vars); m_W5.SetExpression(W5); m_WJ.AddVariables(vars); m_WJ.SetExpression(WJ); MITEM W11 = MDerive(m_W1.GetExpression(), *m_W1.Variable(0), 1); MITEM W12 = MDerive(m_W1.GetExpression(), *m_W1.Variable(1), 1); MITEM W14 = MDerive(m_W1.GetExpression(), *m_W1.Variable(2), 1); MITEM W15 = MDerive(m_W1.GetExpression(), *m_W1.Variable(3), 1); MITEM W22 = MDerive(m_W2.GetExpression(), *m_W2.Variable(1), 1); MITEM W24 = MDerive(m_W2.GetExpression(), *m_W2.Variable(2), 1); MITEM W25 = MDerive(m_W2.GetExpression(), *m_W2.Variable(3), 1); MITEM W44 = MDerive(m_W4.GetExpression(), *m_W4.Variable(2), 1); MITEM W45 = MDerive(m_W4.GetExpression(), *m_W4.Variable(3), 1); MITEM W55 = MDerive(m_W5.GetExpression(), *m_W5.Variable(3), 1); m_W11.AddVariables(vars); m_W11.SetExpression(W11); m_W12.AddVariables(vars); m_W12.SetExpression(W12); m_W14.AddVariables(vars); m_W14.SetExpression(W14); m_W15.AddVariables(vars); m_W15.SetExpression(W15); m_W22.AddVariables(vars); m_W22.SetExpression(W22); m_W24.AddVariables(vars); m_W24.SetExpression(W24); m_W25.AddVariables(vars); m_W25.SetExpression(W25); m_W44.AddVariables(vars); m_W44.SetExpression(W44); m_W45.AddVariables(vars); m_W45.SetExpression(W45); m_W55.AddVariables(vars); m_W55.SetExpression(W55); MITEM WJJ = MDerive(m_WJ.GetExpression(), *m_WJ.Variable(4), 1); m_WJJ.AddVariables(vars); m_WJJ.SetExpression(WJJ); #ifndef NDEBUG MObj2String o2s; string sW1 = o2s.Convert(m_W1); feLog("W1 = %s\n", sW1.c_str()); string sW2 = o2s.Convert(m_W2); feLog("W2 = %s\n", sW2.c_str()); string sW4 = o2s.Convert(m_W4); feLog("W4 = %s\n", sW4.c_str()); string sW5 = o2s.Convert(m_W5); feLog("W5 = %s\n", sW5.c_str()); string sWJ = o2s.Convert(m_WJ); feLog("WJ = %s\n", sWJ.c_str()); string sW11 = o2s.Convert(m_W11); feLog("W11 = %s\n", sW11.c_str()); string sW12 = o2s.Convert(m_W12); feLog("W12 = %s\n", sW12.c_str()); string sW14 = o2s.Convert(m_W14); feLog("W14 = %s\n", sW14.c_str()); string sW15 = o2s.Convert(m_W15); feLog("W15 = %s\n", sW15.c_str()); string sW22 = o2s.Convert(m_W22); feLog("W22 = %s\n", sW22.c_str()); string sW24 = o2s.Convert(m_W24); feLog("W24 = %s\n", sW24.c_str()); string sW25 = o2s.Convert(m_W25); feLog("W25 = %s\n", sW25.c_str()); string sW44 = o2s.Convert(m_W44); feLog("W44 = %s\n", sW44.c_str()); string sW45 = o2s.Convert(m_W45); feLog("W45 = %s\n", sW45.c_str()); string sW55 = o2s.Convert(m_W55); feLog("W55 = %s\n", sW55.c_str()); string sWJJ = o2s.Convert(m_WJJ); feLog("WJJ = %s\n", sWJJ.c_str()); #endif return FEElasticMaterial::Init(); } mat3ds FEGenericTransIsoHyperelastic::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3d& F = pt.m_F; double J = pt.m_J; mat3ds B = pt.LeftCauchyGreen(); mat3ds B2 = B.sqr(); // get the material fiber axis vec3d a0 = m_fiber->unitVector(mp); // get the spatial fiber axis vec3d a = pt.m_F*a0; double lam = a.unit(); // evaluate the invariants double I1 = B.tr(); double I2 = 0.5*(I1*I1 - B2.tr()); double I4 = lam*lam; double I5 = I4*(a*(B*a)); // create the parameter list vector<double> v = { I1, I2, I4, I5, J }; for (int i = 0; i < m_param.size(); ++i) v.push_back(*m_param[i]); // evaluate the strain energy derivatives double W1 = m_W1.value_s(v); double W2 = m_W2.value_s(v); double W4 = m_W4.value_s(v); double W5 = m_W5.value_s(v); double WJ = m_WJ.value_s(v); mat3dd I(1.0); mat3ds AxA = dyad(a); mat3ds aBa = dyads(a, B*a); mat3ds s = (B*(W1 + W2*I1) - B2*W2 + AxA*(W4*I4) + aBa*(W5*I4))*(2.0 / J) + WJ*I; // all done! return s; } tens4ds FEGenericTransIsoHyperelastic::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3d& F = pt.m_F; double J = pt.m_J; mat3ds B = pt.LeftCauchyGreen(); mat3ds B2 = B.sqr(); // get the material fiber axis vec3d a0 = m_fiber->unitVector(mp); // get the spatial fiber axis vec3d a = pt.m_F*a0; double lam = a.unit(); // evaluate the invariants double I1 = B.tr(); double I2 = 0.5*(I1*I1 - B2.tr()); double I4 = lam*lam; double I5 = I4*(a*(B*a)); // evaluate parameters vector<double> v = { I1, I2, I4, I5, J }; for (int i = 0; i < m_param.size(); ++i) v.push_back(*m_param[i]); // evaluate strain energy derivatives double W1 = m_W1.value_s(v); double W2 = m_W2.value_s(v); double W4 = m_W4.value_s(v); double W5 = m_W5.value_s(v); double WJ = m_WJ.value_s(v); double W11 = m_W11.value_s(v); double W12 = m_W12.value_s(v); double W14 = m_W14.value_s(v); double W15 = m_W15.value_s(v); double W22 = m_W22.value_s(v); double W24 = m_W24.value_s(v); double W25 = m_W25.value_s(v); double W44 = m_W44.value_s(v); double W45 = m_W45.value_s(v); double W55 = m_W55.value_s(v); double WJJ = m_WJJ.value_s(v); mat3dd I(1.0); tens4ds IxI = dyad1s(I); tens4ds BxB = dyad1s(B); tens4ds B2xB2 = dyad1s(B2); tens4ds BoB2 = dyad1s(B, B2); tens4ds Ib = dyad4s(B); tens4ds II = dyad4s(I); mat3ds A = dyad(a); mat3ds aBa = dyads(a, B*a); tens4ds Baa = dyad1s(B, A); tens4ds BaBa = dyad1s(B, aBa); tens4ds B2A = dyad1s(B2, A); tens4ds B2aBa = dyad1s(B2, aBa); tens4ds AxA = dyad1s(A); tens4ds AaBa = dyad1s(A, aBa); tens4ds aBaaBa = dyad1s(aBa, aBa); tens4ds AB = dyad5s(A, B); // stiffness contribution from isotropic terms tens4ds cw_iso = BxB*(W11 + 2 * W12*I1 + W22*I1*I1 + W2) - BoB2*(W12 + W22*I1) + B2xB2*W22 - Ib*W2; // stiffness constribution from anisotropic terms tens4ds cw_ani = Baa*(I4*(W14 + W24*I1)) \ + BaBa*(I4*(W15 + W25*I1)) \ - B2A*(I4*W24) \ - B2aBa*(I4*W25) \ + AxA*(I4*I4*W44) \ + AaBa*(I4*I4*W45) \ + aBaaBa*(I4*I4*W55) \ + AB*(I4*W5); // let's sum them up tens4ds cw = cw_iso + cw_ani; // the "pressure" term tens4ds cp = IxI*(WJJ*J + WJ) - II*(2 * WJ); // add it up tens4ds c = cp + cw*(4.0 / J); // all done return c; } double FEGenericTransIsoHyperelastic::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3d& F = pt.m_F; double J = pt.m_J; mat3ds B = pt.LeftCauchyGreen(); mat3ds B2 = B.sqr(); // get the material fiber axis vec3d a0 = m_fiber->unitVector(mp); // get the spatial fiber axis vec3d a = pt.m_F*a0; double lam = a.unit(); // evaluate the invariants double I1 = B.tr(); double I2 = 0.5*(I1*I1 - B2.tr()); double I4 = lam*lam; double I5 = I4*(a*(B*a)); // evaluate parameters vector<double> v = { I1, I2, I4, I5, J }; for (int i = 0; i < m_param.size(); ++i) v.push_back(*m_param[i]); double W = m_W.value_s(v); return W; }
C++
3D
febiosoftware/FEBio
FEBioMech/FEFiberCDFUncoupled.cpp
.cpp
8,079
249
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2023 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEFiberCDFUncoupled.h" #include "FEFiberCDFMaterialPoint.h" #include <limits> #include <FECore/log.h> //----------------------------------------------------------------------------- // FEFiberCDFUncoupled //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEFiberCDFUncoupled, FEFiberMaterialUncoupled) ADD_PARAMETER(m_E , FE_RANGE_GREATER_OR_EQUAL(0.0), "E" )->setUnits(UNIT_PRESSURE)->setLongName("fiber modulus"); ADD_PROPERTY (m_CDF, "cdf")->SetLongName("cumulative distribution function"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEFiberCDFUncoupled::FEFiberCDFUncoupled(FEModel* pfem) : FEFiberMaterialUncoupled(pfem) { m_E = 0; m_epsf = 1.0; m_CDF = nullptr; } //----------------------------------------------------------------------------- // returns a pointer to a new material point object FEMaterialPointData* FEFiberCDFUncoupled::CreateMaterialPointData() { return new FEFiberCDFMaterialPoint(FEFiberMaterialUncoupled::CreateMaterialPointData()); } //----------------------------------------------------------------------------- mat3ds FEFiberCDFUncoupled::DevFiberStress(FEMaterialPoint& mp, const vec3d& n0) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient double J = pt.m_J; mat3d F = pt.m_F*pow(J, -1./3.); // loop over all integration points mat3ds C = pt.DevRightCauchyGreen(); mat3ds s; // Calculate In - 1 = n0*C*n0 - 1 double In_1 = n0*(C*n0) - 1; FEFiberCDFMaterialPoint& fp = *mp.ExtractData<FEFiberCDFMaterialPoint>(); fp.SetFiberStrain(In_1); // only take fibers in tension into consideration const double eps = m_epsf* std::numeric_limits<double>::epsilon(); if (In_1 >= eps) { double ksi = m_E(mp)/4; // get the global spatial fiber direction in current configuration vec3d nt = F*n0; // calculate the outer product of nt mat3ds N = dyad(nt); // perform integration Integrate(mp, In_1); // calculate strain energy first derivative double Wl = ksi*fp.m_ds_t*In_1; // calculate the fiber stress s = N*(2.0*Wl/J); } else { s.zero(); } return s.dev(); } //----------------------------------------------------------------------------- tens4ds FEFiberCDFUncoupled::DevFiberTangent(FEMaterialPoint& mp, const vec3d& n0) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // deformation gradient double J = pt.m_J; mat3d F = pt.m_F*pow(J, -1./3.); // loop over all integration points mat3ds C = pt.DevRightCauchyGreen(); tens4ds c; // Calculate In - 1 = n0*C*n0 - 1 double In_1 = n0*(C*n0) - 1; FEFiberCDFMaterialPoint& fp = *mp.ExtractData<FEFiberCDFMaterialPoint>(); fp.SetFiberStrain(In_1); // only take fibers in tension into consideration const double eps = m_epsf*std::numeric_limits<double>::epsilon(); if (In_1 >= eps) { double ksi = m_E(mp)/4; // get the global spatial fiber direction in current configuration vec3d nt = F*n0; // calculate the outer product of nt mat3ds N = dyad(nt); tens4ds NxN = dyad1s(N); // perform integration Integrate(mp, In_1); // calculate strain energy 2nd derivative double Wll = ksi*fp.m_d2s_t; // calculate the fiber tangent c = NxN*(4.0*Wll/J); // calculate strain energy first derivative double Wl = ksi*fp.m_ds_t*In_1; // calculate the fiber stress mat3ds s = N*(2.0*Wl/J); // This is the final value of the elasticity tensor mat3dd I(1); tens4ds IxI = dyad1s(I); tens4ds I4 = dyad4s(I); c += ((I4+IxI/3.0)*s.tr() - dyad1s(I,s))*(2./3.) - (ddots(IxI, c)-IxI*(c.tr()/3.))/3.; } else { c.zero(); } return c; } //----------------------------------------------------------------------------- double FEFiberCDFUncoupled::DevFiberStrainEnergyDensity(FEMaterialPoint& mp, const vec3d& n0) { double sed = 0.0; FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3d F = pt.m_F*pow(pt.m_J, -1./3.); // loop over all integration points mat3ds C = pt.DevRightCauchyGreen(); // Calculate In - 1 = n0*C*n0 - 1 double In = n0*(C*n0); double In_1 = In - 1.0; FEFiberCDFMaterialPoint& fp = *mp.ExtractData<FEFiberCDFMaterialPoint>(); fp.SetFiberStrain(In_1); // only take fibers in tension into consideration const double eps = 0; if (In_1 >= eps) { double ksi = m_E(mp)/4; // perform integration Integrate(mp, In_1); // calculate strain energy sed = fp.m_sed_t*ksi; } return sed; } //----------------------------------------------------------------------------- void FEFiberCDFUncoupled::Integrate(FEMaterialPoint& mp, const double In_1) { double dImax = 1e-2; FEFiberCDFMaterialPoint& fp = *mp.ExtractData<FEFiberCDFMaterialPoint>(); // check increment in strain double dIn = In_1 - fp.m_In_1_p; // if small enough, integrate in a single step if (fabs(dIn) <= dImax) { fp.Integrate(m_CDF->cdf(mp,In_1)); return; } // otherwise, integrate over multiple steps double In_1_p = fp.m_In_1_p; double d2s_p = fp.m_d2s_p; double ds_p = fp.m_ds_p; double sed_p = fp.m_sed_p; double In_1_t, d2s_t, ds_t, sed_t; do { In_1_t = In_1_p + dImax; if (In_1_t > In_1) In_1_t = In_1; dIn = In_1_t - In_1_p; d2s_t = m_CDF->cdf(mp,In_1_t); sed_t = sed_p + ds_p*dIn + 0.25*dIn*dIn*(d2s_t + d2s_p); ds_t = ds_p + 0.5*dIn*(d2s_t + d2s_p); fp.m_d2s_t = d2s_t; fp.m_ds_t = ds_t; fp.m_sed_t = sed_t; In_1_p = In_1_t; d2s_p = d2s_t; ds_p = ds_t; sed_p = sed_t; } while (In_1_t < In_1); return; } //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEElasticFiberCDFUncoupled, FEElasticFiberMaterialUC) ADD_PARAMETER(m_fib.m_E , FE_RANGE_GREATER_OR_EQUAL(0.0), "E" )->setUnits(UNIT_PRESSURE)->setLongName("fiber modulus"); ADD_PROPERTY (m_fib.m_CDF , "cdf")->SetLongName("cumulative distribution function"); END_FECORE_CLASS();
C++
3D
febiosoftware/FEBio
FEBioMech/FEElasticTrussDomain.cpp
.cpp
11,730
456
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEElasticTrussDomain.h" #include <FECore/FEModel.h> #include <FECore/FELinearSystem.h> #include "FEUncoupledMaterial.h" #include "FEElasticMaterialPoint.h" #include "FEBioMech.h" #include "FEBodyForce.h" //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEElasticTrussDomain, FETrussDomain) ADD_PARAMETER(m_a0, "cross_sectional_area"); ADD_PARAMETER(m_v, "v")->setLongName("Poisson's ratio"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor FEElasticTrussDomain::FEElasticTrussDomain(FEModel* pfem) : FETrussDomain(pfem), FEElasticDomain(pfem), m_dofU(pfem) { m_a0 = 0.0; m_v = 0.5; m_pMat = 0; // TODO: Can this be done in Init, since there is no error checking if (pfem) { m_dofU.AddVariable(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT)); } } //----------------------------------------------------------------------------- //! copy operator FEElasticTrussDomain& FEElasticTrussDomain::operator = (FEElasticTrussDomain& d) { m_Elem = d.m_Elem; m_pMesh = d.m_pMesh; return (*this); } //----------------------------------------------------------------------------- //! get the dof list const FEDofList& FEElasticTrussDomain::GetDOFList() const { return m_dofU; } //----------------------------------------------------------------------------- double FEElasticTrussDomain::detJt(FETrussElement& el) const { const FENode& n0 = Node(el.m_lnode[0]); const FENode& n1 = Node(el.m_lnode[1]); vec3d d = n1.m_rt - n0.m_rt; return d.Length() * 0.5; } //----------------------------------------------------------------------------- void FEElasticTrussDomain::SetMaterial(FEMaterial* pmat) { FETrussDomain::SetMaterial(pmat); m_pMat = dynamic_cast<FESolidMaterial*>(pmat); assert(m_pMat); } //----------------------------------------------------------------------------- //! initialize the domain bool FEElasticTrussDomain::Init() { if (m_a0 != 0.0) { for (int i = 0; i < Elements(); ++i) { FETrussElement& el = Element(i); el.m_a0 = m_a0; } } for (int i = 0; i < (int)m_Elem.size(); ++i) { // unpack the element FETrussElement& el = m_Elem[i]; // nodal coordinates vec3d r0[2]; for (int j = 0; j < 2; ++j) r0[j] = m_pMesh->Node(el.m_node[j]).m_r0; // initial length el.m_L0 = (r0[1] - r0[0]).norm(); } return FETrussDomain::Init(); } //----------------------------------------------------------------------------- void FEElasticTrussDomain::Reset() { ForEachMaterialPoint([](FEMaterialPoint& mp) { mp.Init(); }); } //----------------------------------------------------------------------------- void FEElasticTrussDomain::UnpackLM(FEElement &el, vector<int>& lm) { lm.resize(6); FENode& n1 = m_pMesh->Node(el.m_node[0]); FENode& n2 = m_pMesh->Node(el.m_node[1]); lm[0] = n1.m_ID[m_dofU[0]]; lm[1] = n1.m_ID[m_dofU[1]]; lm[2] = n1.m_ID[m_dofU[2]]; lm[3] = n2.m_ID[m_dofU[0]]; lm[4] = n2.m_ID[m_dofU[1]]; lm[5] = n2.m_ID[m_dofU[2]]; } //----------------------------------------------------------------------------- void FEElasticTrussDomain::Activate() { for (int i=0; i<Nodes(); ++i) { FENode& node = Node(i); if (node.HasFlags(FENode::EXCLUDE) == false) { if (node.m_rid < 0) { node.set_active(m_dofU[0]); node.set_active(m_dofU[1]); node.set_active(m_dofU[2]); } } } } //----------------------------------------------------------------------------- void FEElasticTrussDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { ForEachMaterialPoint([&](FEMaterialPoint& mp) { mp.Update(timeInfo); }); } //----------------------------------------------------------------------------- void FEElasticTrussDomain::StiffnessMatrix(FELinearSystem& LS) { int NT = (int)m_Elem.size(); vector<int> lm; for (int iel =0; iel<NT; ++iel) { FETrussElement& el = m_Elem[iel]; FEElementMatrix ke(el); ElementStiffness(iel, ke); UnpackLM(el, lm); ke.SetIndices(lm); LS.Assemble(ke); } } //----------------------------------------------------------------------------- //! intertial stiffness matrix void FEElasticTrussDomain::MassMatrix(FELinearSystem& LS, double scale) { for (int n = 0; n < Elements(); ++n) { FETrussElement& el = Element(n); matrix me(2, 2); me.zero(); ElementMassMatrix(el, me); FEElementMatrix Me(6, 6); Me.zero(); for (int i=0; i<2; ++i) { for (int j = 0; j < 2; ++j) { Me[3 * i ][3 * j ] = me[i][j]; Me[3 * i + 1][3 * j + 1] = me[i][j]; Me[3 * i + 2][3 * j + 2] = me[i][j]; } } vector<int> lm; UnpackLM(el, lm); Me.SetIndices(lm); LS.Assemble(Me); } } //----------------------------------------------------------------------------- void FEElasticTrussDomain::ElementStiffness(int iel, matrix& ke) { FETrussElement& el = Element(iel); // get the elastic tangent FEMaterialPoint& mp = *el.GetMaterialPoint(0); tens4ds c = m_pMat->Tangent(mp); double E = c(0, 0); // element initial volume double V = el.m_L0*el.m_a0; double l = el.m_L0 / el.m_lam; // Kirchhoff Stress double tau = el.m_tau; // scalar stiffness double k = E;// V / (l * l) * (E - 2 * tau); // axial force T = s*a = t*V/l double T = tau*V/l; vec3d n = GetTrussAxisVector(el); // calculate the tangent matrix ke.resize(6, 6); ke[0][0] = ke[3][3] = k*n.x*n.x + T/l; ke[1][1] = ke[4][4] = k*n.y*n.y + T/l; ke[2][2] = ke[5][5] = k*n.z*n.z + T/l; ke[0][1] = ke[1][0] = ke[3][4] = ke[4][3] = k*n.x*n.y; ke[1][2] = ke[2][1] = ke[4][5] = ke[5][4] = k*n.y*n.z; ke[0][2] = ke[2][0] = ke[3][5] = ke[5][3] = k*n.x*n.z; ke[0][3] = ke[3][0] = -ke[0][0]; ke[0][4] = ke[4][0] = -ke[0][1]; ke[0][5] = ke[5][0] = -ke[0][2]; ke[1][3] = ke[3][1] = -ke[1][0]; ke[1][4] = ke[4][1] = -ke[1][1]; ke[1][5] = ke[5][1] = -ke[1][2]; ke[2][3] = ke[3][2] = -ke[2][0]; ke[2][4] = ke[4][2] = -ke[2][1]; ke[2][5] = ke[5][2] = -ke[2][2]; } //---------------------------------------------------------------------------- //! elemental mass matrix void FEElasticTrussDomain::ElementMassMatrix(FETrussElement& el, matrix& me) { // nodal coordinates vec3d r0[2]; for (int i = 0; i < 2; ++i) { r0[i] = m_pMesh->Node(el.m_node[i]).m_r0; } double L = (r0[1] - r0[0]).norm(); double A = el.m_a0; double rho = m_pMat->Density(*el.GetMaterialPoint(0)); me[0][0] = rho * A * L / 3.0; me[0][1] = rho * A * L / 6.0; me[1][0] = rho * A * L / 6.0; me[1][1] = rho * A * L / 3.0; } //---------------------------------------------------------------------------- void FEElasticTrussDomain::InternalForces(FEGlobalVector& R) { // element force vector int NT = (int)m_Elem.size(); #pragma omp parallel for for (int i=0; i<NT; ++i) { FETrussElement& el = m_Elem[i]; vector<double> fe; ElementInternalForces(el, fe); vector<int> lm; UnpackLM(el, lm); R.Assemble(el.m_node, lm, fe); } } //----------------------------------------------------------------------------- void FEElasticTrussDomain::ElementInternalForces(FETrussElement& el, vector<double>& fe) { FEMaterialPoint& mp = *el.GetMaterialPoint(0); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); vec3d n = GetTrussAxisVector(el); // nodal coordinates vec3d r0[2] = { m_pMesh->Node(el.m_node[0]).m_r0, m_pMesh->Node(el.m_node[1]).m_r0 }; vec3d rt[2] = { m_pMesh->Node(el.m_node[0]).m_rt, m_pMesh->Node(el.m_node[1]).m_rt }; // initial length double L = (r0[1] - r0[0]).norm(); // current length double l = (rt[1] - rt[0]).norm(); // stress in element double tau = pt.m_s.xx(); // elements initial volume double V = L*el.m_a0; // current volume double v = V * pt.m_J; // current area double a = v / l; // calculate nodal forces fe.resize(6); fe[0] = tau*a*n.x; fe[1] = tau*a*n.y; fe[2] = tau*a*n.z; fe[3] = -fe[0]; fe[4] = -fe[1]; fe[5] = -fe[2]; } //! calculate body force \todo implement this void FEElasticTrussDomain::BodyForce(FEGlobalVector& R, FEBodyForce& bf) { FEMesh& mesh = *GetMesh(); // loop over all the elements int NE = Elements(); #pragma omp parallel for for (int i = 0; i < NE; ++i) { // get the next element FETrussElement& el = Element(i); int neln = el.Nodes(); // only consider active elements if (el.isActive()) { // total size of the element vector int ndof = 3* el.Nodes(); // setup the element vector vector<double> fe; fe.assign(ndof, 0); // jacobian double Jt = detJt(el); // loop over integration points double* w = el.GaussWeights(); int nint = el.GaussPoints(); for (int n = 0; n < nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); double* H = el.H(n); mp.m_Jt = Jt; mp.m_shape = el.H(n); // get the value of the integrand for this node vec3d f = bf.force(mp); // loop over all nodes for (int j = 0; j < neln; ++j) { // add it all up fe[3 * j ] += H[j] * f.x * w[n]; fe[3 * j +1] += H[j] * f.y * w[n]; fe[3 * j +2] += H[j] * f.z * w[n]; } } // get the element's LM vector vector<int> lm(ndof, -1); UnpackLM(el, lm); // Assemble into global vector R.Assemble(el.m_node, lm, fe); } } } //----------------------------------------------------------------------------- //! Update the truss' stresses void FEElasticTrussDomain::Update(const FETimeInfo& tp) { FEUncoupledMaterial* um = dynamic_cast<FEUncoupledMaterial*>(GetMaterial()); // loop over all elements #pragma omp parallel for for (int i=0; i<(int) m_Elem.size(); ++i) { // unpack the element FETrussElement& el = m_Elem[i]; // nodal coordinates vec3d r0[2], rt[2]; for (int j=0; j<2; ++j) { r0[j] = m_pMesh->Node(el.m_node[j]).m_r0; rt[j] = m_pMesh->Node(el.m_node[j]).m_rt; } double l = (rt[1] - rt[0]).norm(); double L = (r0[1] - r0[0]).norm(); double lam = l / L; double linv2 = 1.0 / sqrt(pow(lam, 2.0*m_v)); // calculate strain el.m_lam = l / L; // setup deformation gradient (assuming incompressibility) mat3d F(lam, 0.0, 0.0, 0.0, linv2, 0.0, 0.0, 0.0, linv2); // calculate stress FEMaterialPoint& mp = *el.GetMaterialPoint(0); FEElasticMaterialPoint& ep = *mp.ExtractData<FEElasticMaterialPoint>(); ep.m_F = F; ep.m_J = F.det(); if (um) { mat3ds devs = um->DevStress(mp); double p = -devs.yy(); ep.m_s = devs + mat3dd(p); } else { ep.m_s = m_pMat->Stress(mp); } } }
C++