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
FEBioMix/FEMembraneReactionRateConst.cpp
.cpp
1,557
36
/*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 "FEMembraneReactionRateConst.h" // Material parameters for the FEMembraneReactionRateConst material BEGIN_FECORE_CLASS(FEMembraneReactionRateConst, FEMembraneReactionRate) ADD_PARAMETER(m_k, FE_RANGE_GREATER_OR_EQUAL(0.0), "k"); END_FECORE_CLASS();
C++
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicFluidPressureLoad.cpp
.cpp
4,604
131
/*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 "FEMultiphasicFluidPressureLoad.h" #include "FESoluteInterface.h" #include "FEOsmoticCoefficient.h" #include <FECore/FECoreKernel.h> #include <FECore/FEModel.h> #include <FECore/FEMaterial.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEMultiphasicFluidPressureLoad, FESurfaceLoad) ADD_PARAMETER(m_p0 , "pressure"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMultiphasicFluidPressureLoad::FEMultiphasicFluidPressureLoad(FEModel* pfem) : FESurfaceLoad(pfem) { m_p0 = 0; m_dofP = pfem->GetDOFIndex("p"); m_dof.Clear(); m_dof.AddDof(m_dofP); } //----------------------------------------------------------------------------- bool FEMultiphasicFluidPressureLoad::Init() { if (FESurfaceLoad::Init() == false) return false; m_Rgas = GetFEModel()->GetGlobalConstant("R"); m_Tabs = GetFEModel()->GetGlobalConstant("T"); return true; } //----------------------------------------------------------------------------- //! Activate the degrees of freedom for this BC void FEMultiphasicFluidPressureLoad::Activate() { FESurface* ps = &GetSurface(); for (int i=0; i<ps->Nodes(); ++i) { FENode& node = ps->Node(i); // mark node as having prescribed DOF node.set_bc(m_dofP, DOF_PRESCRIBED); } } //----------------------------------------------------------------------------- //! Evaluate and prescribe the resistance pressure void FEMultiphasicFluidPressureLoad::Update() { // prescribe this pressure at the nodes FESurface* ps = &GetSurface(); int N = ps->Nodes(); vector<double> posm(N,0); vector<int> nosm(N,0); for (int i=0; i<ps->Elements(); ++i) { FESurfaceElement& el = m_psurf->Element(i); FEElement* pe = el.m_elem[0].pe; FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); FESoluteInterface* psi = pm->ExtractProperty<FESoluteInterface>(); if (psi) { // calculate average osmotic contribution to pressure in this element double nint = pe->GaussPoints(); double p = 0; for (int n=0; n<nint; ++n) { FEMaterialPoint& mp = *pe->GetMaterialPoint(n); double osm = psi->GetOsmolarity(mp); double Phi = psi->GetOsmoticCoefficient()->OsmoticCoefficient(mp); p -= m_Rgas*m_Tabs*Phi*osm; } p /= nint; for (int i=0; i<el.Nodes(); ++i) { int inode = el.m_lnode[i]; posm[inode] += p; ++nosm[inode]; } } } // now prescribe the effective fluid pressure at surface nodes for (int i=0; i<N; ++i) { if (nosm[i] > 0) posm[i] /= nosm[i]; if (ps->Node(i).m_ID[m_dofP] < -1) { FENode& node = ps->Node(i); // set nodal value node.set(m_dofP, m_p0 + posm[i]); } } GetFEModel()->SetMeshUpdateFlag(true); } //----------------------------------------------------------------------------- //! serialization void FEMultiphasicFluidPressureLoad::Serialize(DumpStream& ar) { FESurfaceLoad::Serialize(ar); }
C++
3D
febiosoftware/FEBio
FEBioMix/FESupplyBinding.cpp
.cpp
4,551
129
/*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 "FESupplyBinding.h" // define the material parameters BEGIN_FECORE_CLASS(FESupplyBinding, FESoluteSupply) ADD_PARAMETER(m_kf , FE_RANGE_GREATER(0.0), "kf"); ADD_PARAMETER(m_kr , FE_RANGE_GREATER_OR_EQUAL(0.0), "kr"); ADD_PARAMETER(m_crt, FE_RANGE_GREATER_OR_EQUAL(0.0), "Rtot"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FESupplyBinding::FESupplyBinding(FEModel* pfem) : FESoluteSupply(pfem) { m_kf = m_kr = m_crt = 0; } //----------------------------------------------------------------------------- //! Solute supply double FESupplyBinding::Supply(FEMaterialPoint& mp) { double crhat = -ReceptorLigandSupply(mp); return crhat; } //----------------------------------------------------------------------------- //! Tangent of solute supply with respect to strain double FESupplyBinding::Tangent_Supply_Strain(FEMaterialPoint &mp) { return 0; } //----------------------------------------------------------------------------- //! Tangent of solute supply with respect to referential concentration double FESupplyBinding::Tangent_Supply_Concentration(FEMaterialPoint &mp) { FESolutesMaterialPoint& pt = *mp.ExtractData<FESolutesMaterialPoint>(); double crc = pt.m_sbmr[0]; double dcrhatdcr = -m_kf*(m_crt - crc); return dcrhatdcr; } //----------------------------------------------------------------------------- //! Receptor-ligand complex supply double FESupplyBinding::ReceptorLigandSupply(FEMaterialPoint& mp) { FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& ppt = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double J = et.m_J; double ca = spt.m_ca[0]; double phi0 = ppt.m_phi0t; double cr = (J-phi0)*ca; double crc = spt.m_sbmr[0]; double crchat = m_kf*cr*(m_crt-crc) - m_kr*crc; return crchat; } //----------------------------------------------------------------------------- //! Solute supply at steady state double FESupplyBinding::SupplySS(FEMaterialPoint& mp) { return 0; } //----------------------------------------------------------------------------- //! Receptor-ligand concentration at steady-state double FESupplyBinding::ReceptorLigandConcentrationSS(FEMaterialPoint& mp) { FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& ppt = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double J = et.m_J; double ca = spt.m_ca[0]; double phi0 = ppt.m_phi0t; double cr = (J-phi0)*ca; double Kd = m_kr/m_kf; // dissociation constant double crc = m_crt*cr/(Kd+cr); return crc; } //----------------------------------------------------------------------------- //! Referential solid supply (moles of solid/referential volume/time) double FESupplyBinding::SolidSupply(FEMaterialPoint& mp) { return ReceptorLigandSupply(mp); } //----------------------------------------------------------------------------- //! Referential solid concentration (moles of solid/referential volume) //! at steady-state double FESupplyBinding::SolidConcentrationSS(FEMaterialPoint& mp) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicSolver.cpp
.cpp
37,768
1,275
/*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 "FEMultiphasicSolver.h" #include "FEBioMech/FEElasticDomain.h" #include "FEBiphasicDomain.h" #include "FEBiphasicSoluteDomain.h" #include "FEMultiphasicDomain.h" #include "FETriphasicDomain.h" #include "FESlidingInterface2.h" #include "FESlidingInterface3.h" #include "FESlidingInterfaceMP.h" #include "FESlidingInterfaceBiphasic.h" #include "FESlidingInterfaceBiphasicMixed.h" #include "FEBioMech/FEPressureLoad.h" #include "FEBioMech/FEResidualVector.h" #include <FEBioMech/FESolidLinearSystem.h> #include <FEBioMech/FERigidConnector.h> #include <FEBioMech/FESlidingElasticInterface.h> #include <FEBioMech/FESSIShellDomain.h> #include "FECore/log.h" #include "FECore/DOFS.h" #include "FECore/sys.h" #include <FECore/FEModel.h> #include <FECore/FEModelLoad.h> #include <FECore/FEAnalysis.h> #include <FECore/FENodalLoad.h> #include <FECore/FEBoundaryCondition.h> #include <FECore/FENLConstraint.h> #include <FECore/FELinearConstraintManager.h> #include "FEMultiphasicAnalysis.h" //----------------------------------------------------------------------------- // define the parameter list BEGIN_FECORE_CLASS(FEMultiphasicSolver, FENewtonSolver) BEGIN_PARAM_GROUP("Nonlinear solver"); // make sure this matches FENewtonSolver. ADD_PARAMETER(m_Dtol , FE_RANGE_GREATER_OR_EQUAL(0.0), "dtol" ); ADD_PARAMETER(m_Etol , FE_RANGE_GREATER_OR_EQUAL(0.0), "etol"); ADD_PARAMETER(m_Rtol , FE_RANGE_GREATER_OR_EQUAL(0.0), "rtol"); ADD_PARAMETER(m_Ptol, "ptol"); ADD_PARAMETER(m_Ctol, "ctol"); ADD_PARAMETER(m_forcePositive, "force_positive_concentrations"); END_PARAM_GROUP(); // obsolete parameters ADD_PARAMETER(m_rhoi , "rhoi" )->SetFlags(FE_PARAM_OBSOLETE); ADD_PARAMETER(m_alpha , "alpha" )->SetFlags(FE_PARAM_OBSOLETE); ADD_PARAMETER(m_beta , "beta" )->SetFlags(FE_PARAM_OBSOLETE); ADD_PARAMETER(m_gamma , "gamma" )->SetFlags(FE_PARAM_OBSOLETE); ADD_PARAMETER(m_logSolve , "logSolve" )->SetFlags(FE_PARAM_OBSOLETE); ADD_PARAMETER(m_arcLength, "arc_length" )->SetFlags(FE_PARAM_OBSOLETE); ADD_PARAMETER(m_al_scale , "arc_length_scale")->SetFlags(FE_PARAM_OBSOLETE); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMultiphasicSolver::FEMultiphasicSolver(FEModel* pfem) : FENewtonSolver(pfem), m_dofU(pfem), m_dofV(pfem), m_dofRQ(pfem), m_dofSU(pfem), m_dofSV(pfem), m_dofSA(pfem), m_rigidSolver(pfem) { // default values m_Rtol = 0; // deactivate residual convergence m_Dtol = 0.001; m_Etol = 0.01; m_Ptol = 0.01; m_Ctol = 0.01; m_Rmin = 1.0e-20; m_Rmax = 0; // not used if zero m_ndeq = 0; m_npeq = 0; m_nreq = 0; m_niter = 0; m_msymm = REAL_UNSYMMETRIC; // assume non-symmetric stiffness matrix by default // Preferred strategy is Broyden's method SetDefaultStrategy(QN_BROYDEN); m_forcePositive = true; // force all concentrations to remain positive m_solutionNorm.push_back(ConvergenceInfo()); if (pfem) { m_dofP = pfem->GetDOFIndex("p"); m_dofSP = pfem->GetDOFIndex("q"); m_dofU.AddVariable("displacement"); m_dofRQ.AddVariable("rigid rotation"); m_dofV.AddVariable("velocity"); m_dofSU.AddVariable("shell displacement"); m_dofSV.AddVariable("shell velocity"); m_dofSA.AddVariable("shell acceleration"); } m_dofC = m_dofSC = -1; } //----------------------------------------------------------------------------- //! Allocates and initializes the data structures. // bool FEMultiphasicSolver::Init() { // initialize base class if (FENewtonSolver::Init() == false) return false; FEModel& fem = *GetFEModel(); // allocate vectors // m_Fn.assign(m_neq, 0); m_Fr.assign(m_neq, 0); m_Ui.assign(m_neq, 0); m_Ut.assign(m_neq, 0); m_Uip.assign(m_neq, 0); // we need to fill the total displacement vector m_Ut FEMesh& mesh = fem.GetMesh(); 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_dofSU[0]); gather(m_Ut, mesh, m_dofSU[1]); gather(m_Ut, mesh, m_dofSU[2]); SolverWarnings(); // allocate poro-vectors // assert((m_ndeq > 0) || (m_npeq > 0)); m_di.assign(m_ndeq, 0); m_Di.assign(m_ndeq, 0); if (m_npeq > 0) { m_pi.assign(m_npeq, 0); m_Pi.assign(m_npeq, 0); // we need to fill the total displacement vector m_Ut // (displacements are already handled in base class) FEMesh& mesh = fem.GetMesh(); gather(m_Ut, mesh, m_dofP); gather(m_Ut, mesh, m_dofSP); } // get number of DOFS DOFS& fedofs = fem.GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); int MAX_DDOFS = fedofs.GetVariableSize("shell concentration"); // allocate concentration-vectors m_ci.assign(MAX_CDOFS,vector<double>(0,0)); m_Ci.assign(MAX_CDOFS,vector<double>(0,0)); for (int i=0; i<MAX_CDOFS; ++i) { m_ci[i].assign(m_nceq[i], 0); m_Ci[i].assign(m_nceq[i], 0); } // we need to fill the total displacement vector m_Ut vector<int> dofs; for (int j=0; j<(int)m_nceq.size(); ++j) { if (m_nceq[j]) { dofs.push_back(m_dofC + j); } } for (int j=0; j<MAX_DDOFS; ++j) { if (m_nceq[j]) dofs.push_back(m_dofSC + j); } gather(m_Ut, mesh, dofs); return true; } //----------------------------------------------------------------------------- //! Initialize equations bool FEMultiphasicSolver::InitEquations() { // First call the base class. // This will initialize all equation numbers, except the rigid body equation numbers if (FENewtonSolver::InitEquations() == false) return false; // store the number of equations we currently have m_nreq = m_neq; // Next, we assign equation numbers to the rigid body degrees of freedom int neq = m_rigidSolver.InitEquations(m_neq); if (neq == -1) return false; else m_neq = neq; // Next, we add any Lagrange Multipliers FEModel& fem = *GetFEModel(); for (int i = 0; i < fem.NonlinearConstraints(); ++i) { FENLConstraint* lmc = fem.NonlinearConstraint(i); if (lmc->IsActive()) { m_neq += lmc->InitEquations(m_neq); } } for (int i = 0; i < fem.SurfacePairConstraints(); ++i) { FESurfacePairConstraint* spc = fem.SurfacePairConstraint(i); if (spc->IsActive()) { m_neq += spc->InitEquations(m_neq); } } // get dofs m_dofP = fem.GetDOFIndex("p"); m_dofSP = fem.GetDOFIndex("q"); m_dofC = fem.GetDOFIndex("concentration", 0); m_dofSC = fem.GetDOFIndex("shell concentration", 0); // determined the nr of pressure and concentration equations FEMesh& mesh = fem.GetMesh(); m_ndeq = m_npeq = 0; for (int i=0; i<mesh.Nodes(); ++i) { FENode& n = mesh.Node(i); if (n.m_ID[m_dofU[0]] != -1) m_ndeq++; if (n.m_ID[m_dofU[1]] != -1) m_ndeq++; if (n.m_ID[m_dofU[2]] != -1) m_ndeq++; if (n.m_ID[m_dofSU[0]] != -1) m_ndeq++; if (n.m_ID[m_dofSU[1]] != -1) m_ndeq++; if (n.m_ID[m_dofSU[2]] != -1) m_ndeq++; if (n.m_ID[m_dofP] != -1) m_npeq++; if (n.m_ID[m_dofSP] != -1) m_npeq++; } // determine the nr of concentration equations DOFS& fedofs = fem.GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); m_nceq.assign(MAX_CDOFS, 0); // get number of DOFS for (int i=0; i<mesh.Nodes(); ++i) { FENode& n = mesh.Node(i); for (int j=0; j<MAX_CDOFS; ++j) { if (n.m_ID[m_dofC+j] != -1) m_nceq[j]++; if (n.m_ID[m_dofSC+j] != -1) m_nceq[j]++; } } return true; } //! Generate warnings if needed void FEMultiphasicSolver::SolverWarnings() { FEModel& fem = *GetFEModel(); // Generate warning if rigid connectors are used with symmetric stiffness if (m_msymm == REAL_SYMMETRIC) { for (int i = 0; i < fem.NonlinearConstraints(); ++i) { FENLConstraint* plc = fem.NonlinearConstraint(i); FERigidConnector* prc = dynamic_cast<FERigidConnector*>(plc); if (prc) { feLogWarning("Rigid connectors require non-symmetric stiffness matrix.\nSet symmetric_stiffness flag to 0 in Control section."); break; } } // Generate warning if sliding-elastic contact is used with symmetric stiffness if (fem.SurfacePairConstraints() > 0) { // loop over all contact interfaces for (int i = 0; i < fem.SurfacePairConstraints(); ++i) { FEContactInterface* pci = dynamic_cast<FEContactInterface*>(fem.SurfacePairConstraint(i)); FESlidingElasticInterface* pbw = dynamic_cast<FESlidingElasticInterface*>(pci); if (pbw) { feLogWarning("The sliding-elastic contact algorithm runs better with a non-symmetric stiffness matrix.\nYou may set symmetric_stiffness flag to 0 in Control section."); break; } } } } } //! Prepares the data for the first QN iteration. void FEMultiphasicSolver::PrepStep() { for (int j=0; j<(int)m_nceq.size(); ++j) if (m_nceq[j]) zero(m_Ci[j]); zero(m_Pi); zero(m_Di); // for concentration nodal loads we need to multiply the time step size FEModel& fem = *GetFEModel(); for (int i = 0; i < fem.ModelLoads(); ++i) { FENodalDOFLoad* pl = dynamic_cast<FENodalDOFLoad*>(fem.ModelLoad(i)); if (pl && pl->IsActive()) { bool adjust = false; int dof = pl->GetDOF(); if ((dof == m_dofP) || (dof == m_dofSP)) adjust = true; else if ((m_dofC > -1) && (dof == m_dofC)) adjust = true; else if ((m_dofSC > -1) && (dof == m_dofSC)) adjust = true; if (adjust) { pl->SetDtScale(true); } } } FETimeInfo& tp = fem.GetTime(); double dt = tp.timeIncrement; tp.augmentation = 0; // zero total displacements zero(m_Ui); // store previous mesh state // we need them for velocity and acceleration calculations FEMesh& mesh = fem.GetMesh(); for (int i = 0; i < mesh.Nodes(); ++i) { FENode& ni = mesh.Node(i); vec3d vs = (ni.m_rt - ni.m_rp)/dt; vec3d vq = (ni.m_dt - ni.m_dp)/dt; ni.m_rp = ni.m_rt; ni.m_vp = ni.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2]); ni.m_dp = ni.m_dt; ni.UpdateValues(); ni.set_vec3d(m_dofV[0], m_dofV[1], m_dofV[2], vs); // solid shell ni.set_vec3d(m_dofSV[0], m_dofSV[1], m_dofSV[2], vs - vq); } // apply concentrated nodal forces // since these forces do not depend on the geometry // we can do this once outside the NR loop. // vector<double> dummy(m_neq, 0.0); // zero(m_Fn); // FEResidualVector Fn(*GetFEModel(), m_Fn, dummy); // NodalLoads(Fn, tp); // apply boundary conditions // we save the prescribed displacements increments in the ui vector vector<double>& ui = m_ui; zero(ui); int nbc = fem.BoundaryConditions(); for (int i = 0; i < nbc; ++i) { FEBoundaryCondition& dc = *fem.BoundaryCondition(i); if (dc.IsActive()) dc.PrepStep(ui); } // do the linear constraints fem.GetLinearConstraintManager().PrepStep(); // initialize rigid bodies m_rigidSolver.PrepStep(tp, ui); // intialize material point data // NOTE: do this before the stresses are updated // TODO: does it matter if the stresses are updated before // the material point data is initialized for (int i = 0; i < mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); if (dom.IsActive()) dom.PreSolveUpdate(tp); } // update model state UpdateModel(); for (int i = 0; i < fem.NonlinearConstraints(); ++i) { FENLConstraint* plc = fem.NonlinearConstraint(i); if (plc && plc->IsActive()) plc->PrepStep(); } for (int i = 0; i < fem.SurfacePairConstraints(); ++i) { FESurfacePairConstraint* psc = fem.SurfacePairConstraint(i); if (psc && psc->IsActive()) psc->PrepStep(); } // see if we need to do contact augmentations m_baugment = false; for (int i = 0; i < fem.SurfacePairConstraints(); ++i) { FEContactInterface& ci = dynamic_cast<FEContactInterface&>(*fem.SurfacePairConstraint(i)); if (ci.IsActive() && (ci.m_laugon == FECore::AUGLAG_METHOD)) m_baugment = true; } // see if we have to do nonlinear constraint augmentations if (fem.NonlinearConstraints() != 0) m_baugment = true; } //----------------------------------------------------------------------------- //! Implements the BFGS algorithm to solve the nonlinear FE equations. //! The details of this implementation of the BFGS method can be found in: //! "Finite Element Procedures", K.J. Bathe, p759 and following //! bool FEMultiphasicSolver::Quasin() { // convergence norms double normR1; // residual norm double normE1; // energy norm double normD; // displacement norm double normd; // displacement increment norm double normRi; // initial residual norm double normEi; // initial energy norm double normEm; // max energy norm double normDi; // initial displacement norm // poro convergence norms data double normPi; // initial pressure norm double normP; // current pressure norm double normp; // incremement pressure norm // get number of DOFS FEModel& fem = *GetFEModel(); DOFS& fedofs = fem.GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); // solute convergence data vector<double> normCi(MAX_CDOFS); // initial concentration norm vector<double> normC(MAX_CDOFS); // current concentration norm vector<double> normc(MAX_CDOFS); // incremement concentration norm // prepare for the first iteration const FETimeInfo& tp = fem.GetTime(); PrepStep(); // init QN method if (QNInit() == false) return false; // loop until converged or when max nr of reformations reached bool bconv = false; // convergence flag do { feLog(" %d\n", m_niter+1); // assume we'll converge. bconv = true; // solve the equations (returns line search; solution stored in m_ui) double s = QNSolve(); // extract the pressure increments GetDisplacementData(m_di, m_ui); // set initial convergence norms if (m_niter == 0) { normRi = fabs(m_R0*m_R0); normEi = fabs(m_ui*m_R0); normDi = fabs(m_di*m_di); normEm = normEi; m_residuNorm.norm0 = normRi; m_energyNorm.norm0 = normEi; m_solutionNorm[0].norm0 = normDi; } // update all degrees of freedom for (int i = 0; i<m_neq; ++i) m_Ui[i] += s*m_ui[i]; // update displacements for (int i = 0; i<m_ndeq; ++i) m_Di[i] += s*m_di[i]; // calculate norms normR1 = m_R1*m_R1; normd = (m_di*m_di)*(s*s); normD = m_Di*m_Di; normE1 = s*fabs(m_ui*m_R1); m_residuNorm.norm = normR1; m_energyNorm.norm = normE1; m_solutionNorm[0].norm = normd; // check residual norm if ((m_Rtol > 0) && (normR1 > m_Rtol*normRi)) bconv = false; // check displacement norm if ((m_Dtol > 0) && (normd > (m_Dtol*m_Dtol)*normD )) bconv = false; // check energy norm if ((m_Etol > 0) && (normE1 > m_Etol*normEi)) bconv = false; // check linestep size if ((m_lineSearch->m_LStol > 0) && (s < m_lineSearch->m_LSmin)) bconv = false; // check energy divergence if (m_bdivreform) { if (normE1 > normEm) bconv = false; } // check poroelastic convergence // extract the pressure increments GetPressureData(m_pi, m_ui); // set initial norm if (m_niter == 0) normPi = fabs(m_pi*m_pi); // update total pressure for (int i = 0; i<m_npeq; ++i) m_Pi[i] += s*m_pi[i]; // calculate norms normP = m_Pi*m_Pi; normp = (m_pi*m_pi)*(s*s); // check convergence if ((m_Ptol > 0) && (normp > (m_Ptol*m_Ptol)*normP)) bconv = false; // check solute convergence // extract the concentration increments for (int j = 0; j<(int)m_nceq.size(); ++j) { if (m_nceq[j]) { GetConcentrationData(m_ci[j], m_ui,j); // set initial norm if (m_niter == 0) normCi[j] = fabs(m_ci[j]*m_ci[j]); // update total concentration for (int i = 0; i<m_nceq[j]; ++i) m_Ci[j][i] += s*m_ci[j][i]; // calculate norms normC[j] = m_Ci[j]*m_Ci[j]; normc[j] = (m_ci[j]*m_ci[j])*(s*s); } } // check convergence if (m_Ctol > 0) { for (int j = 0; j<(int)m_nceq.size(); ++j) if (m_nceq[j]) bconv = bconv && (normc[j] <= (m_Ctol*m_Ctol)*normC[j]); } // print convergence summary feLog(" Nonlinear solution status: time= %lg\n", tp.currentTime); feLog("\tstiffness updates = %d\n", m_qnstrategy->m_nups); feLog("\tright hand side evaluations = %d\n", m_nrhs); feLog("\tstiffness matrix reformations = %d\n", m_nref); if (m_lineSearch->m_LStol > 0) feLog("\tstep from line search = %lf\n", s); feLog("\tconvergence norms : INITIAL CURRENT REQUIRED\n"); feLog("\t residual %15le %15le %15le\n", normRi, normR1, m_Rtol*normRi); feLog("\t energy %15le %15le %15le\n", normEi, normE1, m_Etol*normEi); feLog("\t displacement %15le %15le %15le\n", normDi, normd ,(m_Dtol*m_Dtol)*normD ); feLog("\t fluid pressure %15le %15le %15le\n", normPi, normp ,(m_Ptol*m_Ptol)*normP ); for (int j = 0; j<(int)m_nceq.size(); ++j) { if (m_nceq[j]) feLog("\t solute %d concentration %15le %15le %15le\n", j+1, normCi[j], normc[j] ,(m_Ctol*m_Ctol)*normC[j] ); } if ((bconv == false) && (normR1 < m_Rmin)) { // check for almost zero-residual on the first iteration // this might be an indication that there is no force on the system feLogWarning("No force acting on the system."); bconv = true; } // check if we have converged. // If not, calculate the BFGS update vectors if (bconv == false) { if (s < m_lineSearch->m_LSmin) { // check for zero linestep size feLogWarning("Zero linestep size. Stiffness matrix will now be reformed"); QNForceReform(true); } else if ((normE1 > normEm) && m_bdivreform) { // check for diverging feLogWarning("Problem is diverging. Stiffness matrix will now be reformed"); normEm = normE1; normEi = normE1; normRi = normR1; normDi = normd; normPi = normp; for (int j = 0; j<(int)m_nceq.size(); ++j) if (m_nceq[j]) normCi[j] = normc[j]; QNForceReform(true); } // Do the QN update (This may also do a stiffness reformation if necessary) bool bret = QNUpdate(); // something went wrong with the update, so we'll need to break if (bret == false) break; } else if (m_baugment) { // Do augmentations bconv = DoAugmentations(); } // increase iteration number m_niter++; // do minor iterations callbacks fem.DoCallback(CB_MINOR_ITERS); } while (bconv == false); // if converged we update the total displacements if (bconv) { m_Ut += m_Ui; } return bconv; } //----------------------------------------------------------------------------- //! 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 FEMultiphasicSolver::Residual(vector<double>& R) { int i; // get the time information FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // initialize residual with concentrated nodal loads zero(R); // zero nodal reaction forces zero(m_Fr); // setup global RHS vector FEResidualVector RHS(fem, R, m_Fr); // zero rigid body reaction forces m_rigidSolver.Residual(); // get the mesh FEMesh& mesh = fem.GetMesh(); // internal stress work for (i=0; i<mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); FEElasticDomain* ped = dynamic_cast<FEElasticDomain*>(&dom); FEBiphasicDomain* pbd = dynamic_cast<FEBiphasicDomain* >(&dom); FEBiphasicSoluteDomain* pbs = dynamic_cast<FEBiphasicSoluteDomain*>(&dom); FETriphasicDomain* ptd = dynamic_cast<FETriphasicDomain* >(&dom); FEMultiphasicDomain* pmd = dynamic_cast<FEMultiphasicDomain* >(&dom); if (pbd) { if (fem.GetCurrentStep()->m_nanalysis == FEMultiphasicAnalysis::STEADY_STATE) pbd->InternalForcesSS(RHS); else pbd->InternalForces(RHS); } else if (pbs) { if (fem.GetCurrentStep()->m_nanalysis == FEMultiphasicAnalysis::STEADY_STATE) pbs->InternalForcesSS(RHS); else pbs->InternalForces(RHS); } else if (ptd) { if (fem.GetCurrentStep()->m_nanalysis == FEMultiphasicAnalysis::STEADY_STATE) ptd->InternalForcesSS(RHS); else ptd->InternalForces(RHS); } else if (pmd) { if (fem.GetCurrentStep()->m_nanalysis == FEMultiphasicAnalysis::STEADY_STATE) pmd->InternalForcesSS(RHS); else pmd->InternalForces(RHS); } else if (ped) ped->InternalForces(RHS); } // add model loads int NML = fem.ModelLoads(); for (i = 0; i < NML; ++i) { FEModelLoad& mli = *fem.ModelLoad(i); if (mli.IsActive()) mli.LoadVector(RHS); } // calculate contact forces ContactForces(RHS); // calculate linear 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? for (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); 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]); } // increase RHS counter m_nrhs++; return true; } //----------------------------------------------------------------------------- //! Calculates global stiffness matrix. bool FEMultiphasicSolver::StiffnessMatrix() { FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // get the mesh FEMesh& mesh = fem.GetMesh(); FESolidLinearSystem LS(&fem, &m_rigidSolver, *m_pK, m_Fd, m_ui, (m_msymm == REAL_SYMMETRIC), m_alpha, m_nreq); // calculate the stiffness matrix for each domain FEAnalysis* pstep = fem.GetCurrentStep(); bool bsymm = (m_msymm == REAL_SYMMETRIC); if (pstep->m_nanalysis == FEMultiphasicAnalysis::STEADY_STATE) { for (int i=0; i<mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); FEElasticDomain* pde = dynamic_cast<FEElasticDomain* >(&dom); FEBiphasicDomain* pbd = dynamic_cast<FEBiphasicDomain* >(&dom); FEBiphasicSoluteDomain* pbs = dynamic_cast<FEBiphasicSoluteDomain*>(&dom); FETriphasicDomain* ptd = dynamic_cast<FETriphasicDomain* >(&dom); FEMultiphasicDomain* pmd = dynamic_cast<FEMultiphasicDomain* >(&dom); if (pbd) pbd->StiffnessMatrixSS(LS, bsymm); else if (pbs) pbs->StiffnessMatrixSS(LS, bsymm); else if (ptd) ptd->StiffnessMatrixSS(LS, bsymm); else if (pmd) pmd->StiffnessMatrixSS(LS, bsymm); else if (pde) pde->StiffnessMatrix(LS); } } else { for (int i = 0; i<mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); FEElasticDomain* pde = dynamic_cast<FEElasticDomain* >(&dom); FEBiphasicDomain* pbd = dynamic_cast<FEBiphasicDomain* >(&dom); FEBiphasicSoluteDomain* pbs = dynamic_cast<FEBiphasicSoluteDomain*>(&dom); FETriphasicDomain* ptd = dynamic_cast<FETriphasicDomain* >(&dom); FEMultiphasicDomain* pmd = dynamic_cast<FEMultiphasicDomain* >(&dom); if (pbd) pbd->StiffnessMatrix(LS, bsymm); else if (pbs) pbs->StiffnessMatrix(LS, bsymm); else if (ptd) ptd->StiffnessMatrix(LS, bsymm); else if (pmd) pmd->StiffnessMatrix(LS, bsymm); else if (pde) pde->StiffnessMatrix(LS); } } // calculate contact stiffness ContactStiffness(LS); // calculate stiffness matrices for model loads int nsl = fem.ModelLoads(); for (int i = 0; i<nsl; ++i) { FEModelLoad* pml = fem.ModelLoad(i); if (pml->IsActive()) pml->StiffnessMatrix(LS); } // calculate nonlinear constraint stiffness // note that this is the contribution of the // constrainst enforced with augmented lagrangian NonLinearConstraintStiffness(LS, tp); // add contributions from rigid bodies m_rigidSolver.StiffnessMatrix(*m_pK, tp); return true; } //----------------------------------------------------------------------------- void FEMultiphasicSolver::GetDisplacementData(vector<double> &di, vector<double> &ui) { FEModel& fem = *GetFEModel(); int N = fem.GetMesh().Nodes(), nid, m = 0; zero(di); for (int i=0; i<N; ++i) { FENode& n = fem.GetMesh().Node(i); nid = n.m_ID[m_dofU[0]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); di[m++] = ui[nid]; assert(m <= (int) di.size()); } nid = n.m_ID[m_dofU[1]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); di[m++] = ui[nid]; assert(m <= (int) di.size()); } nid = n.m_ID[m_dofU[2]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); di[m++] = ui[nid]; assert(m <= (int) di.size()); } nid = n.m_ID[m_dofSU[0]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); di[m++] = ui[nid]; assert(m <= (int) di.size()); } nid = n.m_ID[m_dofSU[1]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); di[m++] = ui[nid]; assert(m <= (int) di.size()); } nid = n.m_ID[m_dofSU[2]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); di[m++] = ui[nid]; assert(m <= (int) di.size()); } } } //----------------------------------------------------------------------------- void FEMultiphasicSolver::GetPressureData(vector<double> &pi, vector<double> &ui) { FEModel& fem = *GetFEModel(); int N = fem.GetMesh().Nodes(), nid, m = 0; zero(pi); for (int i=0; i<N; ++i) { FENode& n = fem.GetMesh().Node(i); nid = n.m_ID[m_dofP]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); pi[m++] = ui[nid]; assert(m <= (int) pi.size()); } nid = n.m_ID[m_dofSP]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); pi[m++] = ui[nid]; assert(m <= (int) pi.size()); } } } //----------------------------------------------------------------------------- void FEMultiphasicSolver::GetConcentrationData(vector<double> &ci, vector<double> &ui, const int sol) { FEModel& fem = *GetFEModel(); int N = fem.GetMesh().Nodes(), nid, m = 0; zero(ci); for (int i=0; i<N; ++i) { FENode& n = fem.GetMesh().Node(i); nid = n.m_ID[m_dofC+sol]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); ci[m++] = ui[nid]; assert(m <= (int) ci.size()); } nid = n.m_ID[m_dofSC+sol]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); ci[m++] = ui[nid]; assert(m <= (int) ci.size()); } } } //! Update EAS void FEMultiphasicSolver::UpdateEAS(vector<double>& ui) { FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); // update EAS on shell domains for (int i = 0; i < mesh.Domains(); ++i) { FESSIShellDomain* sdom = dynamic_cast<FESSIShellDomain*>(&mesh.Domain(i)); if (sdom && sdom->IsActive()) sdom->UpdateEAS(ui); } } //! Update EAS void FEMultiphasicSolver::UpdateIncrementsEAS(vector<double>& ui, const bool binc) { FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); // update EAS on shell domains for (int i = 0; i < mesh.Domains(); ++i) { FESSIShellDomain* sdom = dynamic_cast<FESSIShellDomain*>(&mesh.Domain(i)); if (sdom && sdom->IsActive()) sdom->UpdateIncrementsEAS(ui, binc); } } //! Update the model's kinematic data. This is overriden from FEBiphasicSolver so //! that solute data is updated void FEMultiphasicSolver::UpdateKinematics(vector<double>& ui) { // first update all solid-mechanics kinematics FEModel& fem = *GetFEModel(); // get the mesh FEMesh& mesh = fem.GetMesh(); // update rigid bodies m_rigidSolver.UpdateRigidBodies(m_Ui, ui); // total displacements vector<double> U(m_Ut.size()); int U_size = (int)U.size(); #pragma omp parallel for for (int i = 0; i < U_size; ++i) { U[i] = ui[i] + m_Ui[i] + m_Ut[i]; } // update flexible nodes // translational dofs scatter3(U, mesh, m_dofU[0], m_dofU[1], m_dofU[2]); // shell dofs scatter3(U, mesh, m_dofSU[0], m_dofSU[1], m_dofSU[2]); // make sure the boundary conditions are fullfilled int nbcs = fem.BoundaryConditions(); for (int i = 0; i < nbcs; ++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 int NN = mesh.Nodes(); #pragma omp parallel { #pragma omp for for (int i = 0; i < NN; ++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]); } node.m_dt = node.m_d0 + node.get_vec3d(m_dofU[0], m_dofU[1], m_dofU[2]) - node.get_vec3d(m_dofSU[0], m_dofSU[1], m_dofSU[2]); } } // update nonlinear constraints (needed for updating Lagrange Multiplier) for (int i = 0; i < fem.NonlinearConstraints(); ++i) { FENLConstraint* nlc = fem.NonlinearConstraint(i); if (nlc->IsActive()) nlc->Update(m_Ui, ui); } for (int i = 0; i < fem.SurfacePairConstraints(); ++i) { FESurfacePairConstraint* spc = fem.SurfacePairConstraint(i); if (spc->IsActive()) spc->Update(m_Ui, ui); } // update poroelastic data UpdatePoro(ui); // update solute-poroelastic data UpdateSolute(ui); } //----------------------------------------------------------------------------- //! Updates the poroelastic data void FEMultiphasicSolver::UpdatePoro(vector<double>& ui) { int i, n; FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); double dt = fem.GetTime().timeIncrement; // update poro-elasticity data for (i=0; i<mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); // update nodal pressures n = node.m_ID[m_dofP]; if (n >= 0) node.set(m_dofP, 0 + m_Ut[n] + m_Ui[n] + ui[n]); n = node.m_ID[m_dofSP]; if (n >= 0) node.set(m_dofSP, 0 + m_Ut[n] + m_Ui[n] + ui[n]); } // update poro-elasticity data for (i=0; i<mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); // update velocities vec3d vt = (node.m_rt - node.m_rp) / dt; node.set_vec3d(m_dofV[0], m_dofV[1], m_dofV[2], vt); } } //----------------------------------------------------------------------------- //! Updates the solute data void FEMultiphasicSolver::UpdateSolute(vector<double>& ui) { int i, j, n; FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); double dt = fem.GetTime().timeIncrement; // get number of DOFS DOFS& fedofs = fem.GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); int MAX_DDOFS = fedofs.GetVariableSize("shell concentration"); // update solute data for (i=0; i<mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); // update nodal concentration for (j=0; j<MAX_CDOFS; ++j) { n = node.m_ID[m_dofC+j]; // Force the concentrations to remain positive if (n >= 0) { double ct = 0 + m_Ut[n] + m_Ui[n] + ui[n]; if ((ct < 0.0) && m_forcePositive) ct = 0.0; node.set(m_dofC + j, ct); } } for (int j=0; j<MAX_DDOFS; ++j) { int n = node.m_ID[m_dofSC+j]; // Force the concentrations to remain positive if (n >= 0) { double ct = 0 + m_Ut[n] + m_Ui[n] + ui[n]; if ((ct < 0) && m_forcePositive) ct = 0.0; node.set(m_dofSC + j, ct); } } } } //! Updates the current state of the model void FEMultiphasicSolver::Update(vector<double>& ui) { FEModel& fem = *GetFEModel(); FETimeInfo& tp = fem.GetTime(); tp.currentIteration = m_niter; // update EAS UpdateEAS(ui); UpdateIncrementsEAS(ui, true); // update kinematics UpdateKinematics(ui); // update domains FEMesh& mesh = fem.GetMesh(); for (int i = 0; i < mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); dom.IncrementalUpdate(ui, false); } // update model state UpdateModel(); } void FEMultiphasicSolver::UpdateModel() { // mark all free-draining surfaces FEModel& fem = *GetFEModel(); for (int i = 0; i<fem.SurfacePairConstraints(); ++i) { FEContactInterface* pci = dynamic_cast<FEContactInterface*>(fem.SurfacePairConstraint(i)); FESlidingInterface2* psi2 = dynamic_cast<FESlidingInterface2*>(pci); if (psi2) psi2->MarkFreeDraining(); FESlidingInterface3* psi3 = dynamic_cast<FESlidingInterface3*>(pci); if (psi3) psi3->MarkAmbient(); FESlidingInterfaceMP* psiMP = dynamic_cast<FESlidingInterfaceMP*>(pci); if (psiMP) psiMP->MarkAmbient(); FESlidingInterfaceBiphasic* psib = dynamic_cast<FESlidingInterfaceBiphasic*>(pci); if (psib) psib->MarkFreeDraining(); FESlidingInterfaceBiphasicMixed* psbm = dynamic_cast<FESlidingInterfaceBiphasicMixed*>(pci); if (psbm) psbm->MarkFreeDraining(); } // Update all contact interfaces FENewtonSolver::UpdateModel(); // set free-draining boundary conditions for (int i = 0; i<fem.SurfacePairConstraints(); ++i) { FEContactInterface* pci = dynamic_cast<FEContactInterface*>(fem.SurfacePairConstraint(i)); FESlidingInterface2* psi2 = dynamic_cast<FESlidingInterface2*>(pci); if (psi2) psi2->SetFreeDraining(); FESlidingInterface3* psi3 = dynamic_cast<FESlidingInterface3*>(pci); if (psi3) psi3->SetAmbient(); FESlidingInterfaceMP* psiMP = dynamic_cast<FESlidingInterfaceMP*>(pci); if (psiMP) psiMP->SetAmbient(); FESlidingInterfaceBiphasic* psib = dynamic_cast<FESlidingInterfaceBiphasic*>(pci); if (psib) psib->SetFreeDraining(); FESlidingInterfaceBiphasicMixed* psbm = dynamic_cast<FESlidingInterfaceBiphasicMixed*>(pci); if (psbm) psbm->SetFreeDraining(); } // make sure the prescribed BCs (fluid and solutes) are fullfilled int nbcs = fem.BoundaryConditions(); for (int i = 0; i<nbcs; ++i) { FEBoundaryCondition& bc = *fem.BoundaryCondition(i); if (bc.IsActive()) bc.Repair(); } } //----------------------------------------------------------------------------- //! Save data to dump file void FEMultiphasicSolver::Serialize(DumpStream& ar) { // Serialize parameters FENewtonSolver::Serialize(ar); ar& m_nrhs; ar& m_niter; ar& m_nref& m_ntotref; ar& m_naug; ar& m_nreq; ar& m_Ut& m_Ui; if (ar.IsLoading()) { // m_Fn.assign(m_neq, 0); m_Fr.assign(m_neq, 0); // m_Ui.assign(m_neq, 0); } // serialize rigid solver m_rigidSolver.Serialize(ar); if (ar.IsShallow()) return; ar & m_dofP & m_dofSP & m_dofC & m_dofSC; ar & m_ndeq & m_npeq & m_nceq; ar & m_nceq; ar & m_di & m_Di; ar & m_pi & m_Pi; ar & m_ci & m_Ci; } //! Calculates the contact forces void FEMultiphasicSolver::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); } } //! This function calculates the contact stiffness matrix void FEMultiphasicSolver::ContactStiffness(FELinearSystem& LS) { 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->StiffnessMatrix(LS, tp); } } //! calculate the nonlinear constraint forces void FEMultiphasicSolver::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); } } //! Calculate the stiffness contribution due to nonlinear constraints void FEMultiphasicSolver::NonLinearConstraintStiffness(FELinearSystem& LS, 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->StiffnessMatrix(LS, tp); } }
C++
3D
febiosoftware/FEBio
FEBioMix/FETriphasic.cpp
.cpp
21,109
624
/*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 "FETriphasic.h" #include "FECore/FECoreKernel.h" #include <FECore/log.h> #ifndef SQR #define SQR(x) ((x)*(x)) #endif //----------------------------------------------------------------------------- // Material parameters for the FETriphasic material BEGIN_FECORE_CLASS(FETriphasic, FEMaterial) ADD_PARAMETER(m_phi0 , FE_RANGE_CLOSED (0.0, 1.0), "phi0"); ADD_PARAMETER(m_rhoTw , FE_RANGE_GREATER_OR_EQUAL(0.0), "fluid_density"); ADD_PARAMETER(m_penalty, FE_RANGE_GREATER_OR_EQUAL(0.0), "penalty"); ADD_PARAMETER(m_cFr , "fixed_charge_density"); // set material properties ADD_PROPERTY(m_pSolid , "solid" , FEProperty::Required | FEProperty::TopLevel); ADD_PROPERTY(m_pPerm , "permeability" ); ADD_PROPERTY(m_pOsmC , "osmotic_coefficient"); ADD_PROPERTY(m_pSolute, "solute" ); ADD_PROPERTY(m_Q, "mat_axis", FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! FETriphasic constructor FETriphasic::FETriphasic(FEModel* pfem) : FEMaterial(pfem) { m_cFr = 0; m_Rgas = 0; m_Tabs = 0; m_Fc = 0; m_phi0 = 0; m_rhoTw = 0; m_penalty = 1; m_pSolid = 0; m_pPerm = 0; m_pOsmC = 0; } //----------------------------------------------------------------------------- void FETriphasic::AddSolute(FESolute* ps) { m_pSolute.push_back(ps); } //----------------------------------------------------------------------------- bool FETriphasic::Init() { // make sure there are exactly two solutes if (m_pSolute.size() != 2) { feLogError("Exactly two solutes must be specified"); return false; } // Set the solute IDs since they are referenced in the FESolute::Init() function m_pSolute[0]->SetSoluteLocalID(0); m_pSolute[1]->SetSoluteLocalID(1); if (m_pSolid->Init() == false) return false; if (m_pPerm->Init() == false) return false; if (m_pOsmC->Init() == false) return false; for (int i=0; i<Solutes(); ++i) if (m_pSolute[i]->Init() == false) return false; // Call base class initialization. This will also initialize all properties. if (FEMaterial::Init() == false) return false; // parameter checking if ((m_pSolute[0]->ChargeNumber() != 1) && (m_pSolute[0]->ChargeNumber() != -1)) { feLogError("charge_number for first solute must be +1 or -1"); return false; } if ((m_pSolute[1]->ChargeNumber() != 1) && (m_pSolute[1]->ChargeNumber() != -1)) { feLogError("charge_number for second solute must be +1 or -1"); return false; } if (m_pSolute[0]->ChargeNumber() != -m_pSolute[1]->ChargeNumber()) { feLogError("charge_number of solutes must have opposite signs"); return false; } m_Rgas = GetGlobalConstant("R"); m_Tabs = GetGlobalConstant("T"); m_Fc = GetGlobalConstant("Fc"); 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; } if (m_Fc <= 0) { feLogError("A positive Faraday constant Fc must be defined in Globals section" ); return false; } return true; } //----------------------------------------------------------------------------- // update specialized material points void FETriphasic::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { m_pSolid->UpdateSpecializedMaterialPoints(mp, tp); m_pPerm->UpdateSpecializedMaterialPoints(mp, tp); m_pOsmC->UpdateSpecializedMaterialPoints(mp, tp); for (int i=0; i<Solutes(); ++i) m_pSolute[i]->UpdateSpecializedMaterialPoints(mp, tp); } //----------------------------------------------------------------------------- void FETriphasic::Serialize(DumpStream& ar) { FEMaterial::Serialize(ar); if (ar.IsShallow()) return; ar & m_Rgas & m_Tabs & m_Fc; } //----------------------------------------------------------------------------- //! Porosity in current configuration double FETriphasic::Porosity(FEMaterialPoint& pt) { FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pet = *pt.ExtractData<FEBiphasicMaterialPoint>(); // relative volume double J = et.m_J; // porosity // double phiw = 1 - m_phi0/J; double phi0 = pet.m_phi0t; double phiw = 1 - phi0/J; // check for pore collapse // TODO: throw an error if pores collapse phiw = (phiw > 0) ? phiw : 0; return phiw; } //----------------------------------------------------------------------------- //! Fixed charge density in current configuration double FETriphasic::FixedChargeDensity(FEMaterialPoint& pt) { FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pet = *pt.ExtractData<FEBiphasicMaterialPoint>(); // relative volume double J = et.m_J; double phi0 = pet.m_phi0; double phisr = pet.m_phi0t; double cF = m_cFr(pt)*(1-phi0)/(J-phisr); return cF; } //----------------------------------------------------------------------------- //! Electric potential double FETriphasic::ElectricPotential(FEMaterialPoint& pt, const bool eform) { int i, j; // Solve electroneutrality polynomial for zeta FESolutesMaterialPoint& set = *pt.ExtractData<FESolutesMaterialPoint>(); const int nsol = 2; double cF = FixedChargeDensity(pt); double c[2]; // effective concentration double khat[2]; // solubility int z[2]; // charge number for (i=0; i<nsol; ++i) { c[i] = set.m_c[i]; khat[i] = m_pSolute[i]->m_pSolub->Solubility(pt); z[i] = m_pSolute[i]->ChargeNumber(); } double zeta, psi; // evaluate polynomial coefficients double a[3] = {0}; for (i=0; i<nsol; ++i) { j = z[i] + 1; a[j] += z[i]*khat[i]*c[i]; } a[1] = cF; // solve polynomial zeta = 1.0; if (a[2]) { zeta = (-a[1]+sqrt(a[1]*a[1]-4*a[0]*a[2]))/(2*a[2]); // quadratic } else if (a[1]) { zeta = -a[0]/a[1]; // linear } // Return exponential (non-dimensional) form if desired if (eform) return zeta; // Otherwise return dimensional value of electric potential psi = -m_Rgas*m_Tabs/m_Fc*log(zeta); return psi; } //----------------------------------------------------------------------------- //! actual concentration double FETriphasic::Concentration(FEMaterialPoint& pt, const int ion) { FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // effective concentration double c = spt.m_c[ion]; // partition coefficient double kappa = PartitionCoefficient(pt, ion); // actual concentration double ca = kappa*c; return ca; } //----------------------------------------------------------------------------- //! The stress of a triphasic material is the sum of the fluid pressure //! and the elastic stress. Note that this function is declared in the base class //! so you do not have to reimplement it in a derived class, unless additional //! pressure terms are required. mat3ds FETriphasic::Stress(FEMaterialPoint& mp) { // calculate solid material stress mat3ds s = m_pSolid->Stress(mp); // fluid pressure double p = Pressure(mp); // add fluid pressure s.xx() -= p; s.yy() -= p; s.zz() -= p; return s; } //----------------------------------------------------------------------------- //! The tangent is the elastic tangent. Note //! that this function is declared in the base class, so you don't have to //! reimplement it unless additional tangent components are required. tens4ds FETriphasic::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& ept = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& ppt = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); // call solid tangent routine tens4ds C = m_pSolid->Tangent(mp); // relative volume and solid volume fraction double J = ept.m_J; double phi0 = ppt.m_phi0t; // get the charge density and its derivatives double cF = FixedChargeDensity(mp); double dcFdJ = -cF/(J - phi0); // fluid pressure and solute concentration double p = Pressure(mp); // get the effective concentration double c[2] = {spt.m_c[0],spt.m_c[1]}; // get the charge number int z[2] = {m_pSolute[0]->ChargeNumber(),m_pSolute[1]->ChargeNumber()}; // evaluate the solubility and its derivatives w.r.t. J and c double khat[2] = { m_pSolute[0]->m_pSolub->Solubility(mp), m_pSolute[1]->m_pSolub->Solubility(mp)}; double dkhdJ[2] = { m_pSolute[0]->m_pSolub->Tangent_Solubility_Strain(mp), m_pSolute[1]->m_pSolub->Tangent_Solubility_Strain(mp)}; // evaluate electric potential (nondimensional exponential form) and its derivatives // also evaluate partition coefficients and their derivatives double zeta = ElectricPotential(mp, true); double zz[2] = {pow(zeta, z[0]), pow(zeta, z[1])}; double kappa[2] = {zz[0]*khat[0], zz[1]*khat[1]}; double den = SQR(z[0])*kappa[0]*c[0]+SQR(z[1])*kappa[1]*c[1]; double zidzdJ = 0; if (den > 0) zidzdJ = -(dcFdJ+z[0]*zz[0]*dkhdJ[0]*c[0] +z[1]*zz[1]*dkhdJ[1]*c[1])/den; double dkdJ[2] = { zz[0]*dkhdJ[0]+z[0]*kappa[0]*zidzdJ, zz[1]*dkhdJ[1]+z[1]*kappa[1]*zidzdJ}; // osmotic coefficient and its derivative w.r.t. strain double osmc = m_pOsmC->OsmoticCoefficient(mp); double dodJ = m_pOsmC->Tangent_OsmoticCoefficient_Strain(mp); double dp = m_Rgas*m_Tabs*J*(c[0]*(osmc*dkdJ[0]+dodJ*kappa[0]) +c[1]*(osmc*dkdJ[1]+dodJ*kappa[1])); // adjust tangent for pressures double D[6][6] = {0}; C.extract(D); D[0][0] -= -p + dp; D[1][1] -= -p + dp; D[2][2] -= -p + dp; D[0][1] -= p + dp; D[1][0] -= p + dp; D[1][2] -= p + dp; D[2][1] -= p + dp; D[0][2] -= p + dp; D[2][0] -= p + dp; D[3][3] -= -p; D[4][4] -= -p; D[5][5] -= -p; return tens4ds(D); } //----------------------------------------------------------------------------- //! Calculate fluid flux vec3d FETriphasic::FluidFlux(FEMaterialPoint& pt) { FEBiphasicMaterialPoint& ppt = *pt.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); // pressure gradient vec3d gradp = ppt.m_gradp; // concentration double c[2] = {spt.m_c[0], spt.m_c[1]}; // concentration gradient vec3d gradc[2] = {spt.m_gradc[0], spt.m_gradc[1]}; // solute diffusivity in mixture mat3ds D[2] = { m_pSolute[0]->m_pDiff->Diffusivity(pt), m_pSolute[1]->m_pDiff->Diffusivity(pt)}; // solute free diffusivity double D0[2] = { m_pSolute[0]->m_pDiff->Free_Diffusivity(pt), m_pSolute[1]->m_pDiff->Free_Diffusivity(pt)}; // solubility double khat[2] = { m_pSolute[0]->m_pSolub->Solubility(pt), m_pSolute[1]->m_pSolub->Solubility(pt)}; int z[2] = { m_pSolute[0]->ChargeNumber(), m_pSolute[1]->ChargeNumber()}; double zeta = ElectricPotential(pt, true); double zz[2] = {pow(zeta, z[0]),pow(zeta, z[1])}; double kappa[2] = {zz[0]*khat[0],zz[1]*khat[1]}; // identity matrix mat3dd I(1); // hydraulic permeability mat3ds kt = m_pPerm->Permeability(pt); // effective hydraulic permeability mat3ds ke = kt.inverse() + ( (I-D[0]/D0[0])*(kappa[0]*c[0]/D0[0]) +(I-D[1]/D0[1])*(kappa[1]*c[1]/D0[1]) )*(m_Rgas*m_Tabs/phiw); ke = ke.inverse(); // fluid flux w vec3d w = -(ke*(gradp + ((D[0]*gradc[0])*(kappa[0]/D0[0]) + (D[1]*gradc[1])*(kappa[1]/D0[1]))*m_Rgas*m_Tabs)); return w; } //----------------------------------------------------------------------------- //! Calculate solute molar flux vec3d FETriphasic::SoluteFlux(FEMaterialPoint& pt, const int ion) { FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); // concentration double c = spt.m_c[ion]; // concentration gradient vec3d gradc = spt.m_gradc[ion]; // solute diffusivity in mixture mat3ds D = m_pSolute[ion]->m_pDiff->Diffusivity(pt); // solute free diffusivity double D0 = m_pSolute[ion]->m_pDiff->Free_Diffusivity(pt); // solubility double khat = m_pSolute[ion]->m_pSolub->Solubility(pt); int z = m_pSolute[ion]->ChargeNumber(); double zeta = ElectricPotential(pt, true); double zz = pow(zeta, z); double kappa = zz*khat; // fluid flux w vec3d w = FluidFlux(pt); // solute flux j vec3d j = (D*(w*(c/D0) - gradc*phiw))*kappa; return j; } //----------------------------------------------------------------------------- //! actual fluid pressure double FETriphasic::Pressure(FEMaterialPoint& pt) { FEBiphasicMaterialPoint& ppt = *pt.ExtractData<FEBiphasicMaterialPoint>(); // effective pressure double p = ppt.m_p; // effective concentration double ca[2] = {Concentration(pt, 0), Concentration(pt, 1)}; // osmotic coefficient double osmc = m_pOsmC->OsmoticCoefficient(pt); // actual pressure double pa = p + m_Rgas*m_Tabs*osmc*(ca[0]+ca[1]); return pa; } //----------------------------------------------------------------------------- //! Current density vec3d FETriphasic::CurrentDensity(FEMaterialPoint& pt) { vec3d j[2]; j[0] = SoluteFlux(pt, 0); j[1] = SoluteFlux(pt, 1); int z[2] = {m_pSolute[0]->ChargeNumber(), m_pSolute[1]->ChargeNumber()}; vec3d Ie = (j[0]*z[0] + j[1]*z[1])*m_Fc; return Ie; } //----------------------------------------------------------------------------- //! partition coefficient double FETriphasic::PartitionCoefficient(FEMaterialPoint& pt, const int sol) { // solubility double khat = m_pSolute[sol]->m_pSolub->Solubility(pt); // charge number int z = m_pSolute[sol]->ChargeNumber(); // electric potential double zeta = ElectricPotential(pt, true); double zz = pow(zeta, z); // partition coefficient double kappa = zz*khat; return kappa; } //----------------------------------------------------------------------------- //! partition coefficients and their derivatives void FETriphasic::PartitionCoefficientFunctions(FEMaterialPoint& mp, vector<double>& kappa, vector<double>& dkdJ, vector< vector<double> >& dkdc) { int isol, jsol, ksol; FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); const int nsol = (int)m_pSolute.size(); vector<double> c(nsol); vector<int> z(nsol); vector<double> khat(nsol); vector<double> dkhdJ(nsol); vector<double> dkhdJJ(nsol); vector< vector<double> > dkhdc(nsol, vector<double>(nsol)); vector< vector<double> > dkhdJc(nsol, vector<double>(nsol)); vector< vector< vector<double> > > dkhdcc(nsol, dkhdc); // use dkhdc to initialize only vector<double> zz(nsol); kappa.resize(nsol); double den = 0; double num = 0; double zeta = ElectricPotential(mp, true); for (isol=0; isol<nsol; ++isol) { // get the effective concentration, its gradient and its time derivative c[isol] = spt.m_c[isol]; // get the charge number z[isol] = m_pSolute[isol]->ChargeNumber(); // evaluate the solubility and its derivatives w.r.t. J and c khat[isol] = m_pSolute[isol]->m_pSolub->Solubility(mp); dkhdJ[isol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain(mp); dkhdJJ[isol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain_Strain(mp); for (jsol=0; jsol<nsol; ++jsol) { dkhdc[isol][jsol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Concentration(mp,jsol); dkhdJc[isol][jsol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain_Concentration(mp,jsol); for (ksol=0; ksol<nsol; ++ksol) { dkhdcc[isol][jsol][ksol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Concentration_Concentration(mp,jsol,ksol); } } zz[isol] = pow(zeta, z[isol]); kappa[isol] = zz[isol]*khat[isol]; den += SQR(z[isol])*kappa[isol]*c[isol]; num += pow((double)z[isol],3)*kappa[isol]*c[isol]; } // get the charge density and its derivatives double J = ept.m_J; double phi0 = ppt.m_phi0t; double cF = FixedChargeDensity(mp); double dcFdJ = -cF/(J - phi0); double dcFdJJ = 2*cF/SQR(J-phi0); // evaluate electric potential (nondimensional exponential form) and its derivatives // also evaluate partition coefficients and their derivatives double zidzdJ = 0; double zidzdJJ = 0, zidzdJJ1 = 0, zidzdJJ2 = 0; vector<double> zidzdc(nsol,0); vector<double> zidzdJc(nsol,0), zidzdJc1(nsol,0), zidzdJc2(nsol,0); vector< vector<double> > zidzdcc(nsol, vector<double>(nsol,0)); vector< vector<double> > zidzdcc1(nsol, vector<double>(nsol,0)); vector<double> zidzdcc2(nsol,0); double zidzdcc3 = 0; if (den > 0) { for (isol=0; isol<nsol; ++isol) zidzdJ += z[isol]*zz[isol]*dkhdJ[isol]*c[isol]; zidzdJ = -(dcFdJ+zidzdJ)/den; for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { zidzdJJ1 += SQR(z[jsol])*c[jsol]*(z[jsol]*zidzdJ*kappa[jsol]+zz[jsol]*dkhdJ[jsol]); zidzdJJ2 += z[jsol]*zz[jsol]*c[jsol]*(zidzdJ*z[jsol]*dkhdJ[jsol]+dkhdJJ[jsol]); zidzdc[isol] += z[jsol]*zz[jsol]*dkhdc[jsol][isol]*c[jsol]; } zidzdc[isol] = -(z[isol]*kappa[isol]+zidzdc[isol])/den; zidzdcc3 += pow(double(z[isol]),3)*kappa[isol]*c[isol]; } zidzdJJ = zidzdJ*(zidzdJ-zidzdJJ1/den)-(dcFdJJ+zidzdJJ2)/den; for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { zidzdJc1[isol] += SQR(z[jsol])*c[jsol]*(zidzdc[isol]*z[jsol]*kappa[jsol]+zz[jsol]*dkhdc[jsol][isol]); zidzdJc2[isol] += z[jsol]*zz[jsol]*c[jsol]*(zidzdc[isol]*z[jsol]*dkhdJ[jsol]+dkhdJc[jsol][isol]); zidzdcc2[isol] += SQR(z[jsol])*zz[jsol]*c[jsol]*dkhdc[jsol][isol]; for (ksol=0; ksol<nsol; ++ksol) zidzdcc1[isol][jsol] += z[ksol]*zz[ksol]*c[ksol]*dkhdcc[ksol][isol][jsol]; } zidzdJc[isol] = zidzdJ*(zidzdc[isol]-(SQR(z[isol])*kappa[isol] + zidzdJc1[isol])/den) -(z[isol]*zz[isol]*dkhdJ[isol] + zidzdJc2[isol])/den; } for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { zidzdcc[isol][jsol] = zidzdc[isol]*zidzdc[jsol]*(1 - zidzdcc3/den) - zidzdcc1[isol][jsol]/den - z[isol]*(z[isol]*kappa[isol]*zidzdc[jsol]+zz[isol]*dkhdc[isol][jsol])/den - z[jsol]*(z[jsol]*kappa[jsol]*zidzdc[isol]+zz[jsol]*dkhdc[jsol][isol])/den - zidzdc[jsol]*zidzdcc2[isol]/den - zidzdc[isol]*zidzdcc2[jsol]/den; } } } dkdJ.resize(nsol); dkdc.resize(nsol, vector<double>(nsol,0)); for (isol=0; isol<nsol; ++isol) { dkdJ[isol] = zz[isol]*dkhdJ[isol]+z[isol]*kappa[isol]*zidzdJ; for (jsol=0; jsol<nsol; ++jsol) { dkdc[isol][jsol] = zz[isol]*dkhdc[isol][jsol]+z[isol]*kappa[isol]*zidzdc[jsol]; } } } double FETriphasic::GetReferentialFixedChargeDensity(const FEMaterialPoint& mp) { const FEElasticMaterialPoint* ept = (mp.ExtractData<FEElasticMaterialPoint >()); const FEBiphasicMaterialPoint* bpt = (mp.ExtractData<FEBiphasicMaterialPoint>()); const FESolutesMaterialPoint* spt = (mp.ExtractData<FESolutesMaterialPoint >()); double cf = (ept->m_J - bpt->m_phi0t) * spt->m_cF / (1 - bpt->m_phi0); return cf; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMembraneReactionRateIonChannel.h
.h
2,815
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 "FEMembraneReaction.h" class FEBIOMIX_API FEMembraneReactionRateIonChannel : public FEMembraneReactionRate { public: //! constructor FEMembraneReactionRateIonChannel(FEModel* pfem); // initialization bool Init() override; //! reaction rate at material point double ReactionRate(FEMaterialPoint& pt) override; //! tangent of reaction rate with strain at material point double Tangent_ReactionRate_Strain(FEMaterialPoint& pt) override; //! tangent of reaction rate with effective fluid pressure at material point double Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) override {return 0; } double Tangent_ReactionRate_Pe(FEMaterialPoint& pt) override { return 0; } double Tangent_ReactionRate_Pi(FEMaterialPoint& pt) override { return 0; } //! tangent of reaction rate with effective solute concentration at material point double Tangent_ReactionRate_Concentration(FEMaterialPoint& pt, const int isol) override {return 0; } double Tangent_ReactionRate_Ce(FEMaterialPoint& pt, const int isol) override; double Tangent_ReactionRate_Ci(FEMaterialPoint& pt, const int isol) override; public: int m_sol; //!< solute id (1-based) for ion int m_lid; //!< local id of solute (zero-based) int m_z; //!< charge number of channel ion int m_sbm; //!< sbm id (1-based) for channel protein double m_g; //!< channel conductance DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasic.cpp
.cpp
12,422
388
/*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 "FEBiphasic.h" #include "FECore/FECoreKernel.h" //----------------------------------------------------------------------------- // Material parameters for the FEBiphasic material BEGIN_FECORE_CLASS(FEBiphasic, FEMaterial) ADD_PARAMETER(m_phi0 , FE_RANGE_CLOSED(0.0, 1.0), "phi0"); ADD_PARAMETER(m_rhoTw, FE_RANGE_GREATER_OR_EQUAL(0.0), "fluid_density")->setUnits(UNIT_DENSITY); ADD_PARAMETER(m_tau , FE_RANGE_GREATER_OR_EQUAL(0.0), "tau"); // set material properties ADD_PROPERTY(m_pSolid, "solid", FEProperty::Required | FEProperty::TopLevel); ADD_PROPERTY(m_pPerm, "permeability"); ADD_PROPERTY(m_pSupp, "solvent_supply", FEProperty::Optional); ADD_PROPERTY(m_pAmom, "active_supply", FEProperty::Optional); ADD_PROPERTY(m_Q, "mat_axis", FEProperty::Optional); END_FECORE_CLASS(); //============================================================================ // FEBiphasicMaterialPoint //============================================================================ FEBiphasicMaterialPoint::FEBiphasicMaterialPoint(FEMaterialPointData* ppt) : FEMaterialPointData(ppt) {} //----------------------------------------------------------------------------- FEMaterialPointData* FEBiphasicMaterialPoint::Copy() { FEBiphasicMaterialPoint* pt = new FEBiphasicMaterialPoint(*this); if (m_pNext) pt->m_pNext = m_pNext->Copy(); return pt; } //----------------------------------------------------------------------------- void FEBiphasicMaterialPoint::Serialize(DumpStream& ar) { FEMaterialPointData::Serialize(ar); ar & m_p & m_gradp & m_gradpp; ar & m_w & m_pa & m_phi0 & m_phi0t & m_phi0p & m_phi0hat & m_Jp; ar & m_ss; } //----------------------------------------------------------------------------- void FEBiphasicMaterialPoint::Init() { m_p = m_pa = 0; m_gradp = m_gradpp = vec3d(0,0,0); m_w = vec3d(0,0,0); m_phi0 = m_phi0t = m_phi0p = 0; m_phi0hat = 0; m_Jp = 1; m_ss.zero(); FEMaterialPointData::Init(); } //============================================================================ // FEBiphasic //============================================================================ //----------------------------------------------------------------------------- //! FEBiphasic constructor FEBiphasic::FEBiphasic(FEModel* pfem) : FEMaterial(pfem) { m_rhoTw = 0; m_phi0 = 0; m_tau = 0; m_pSolid = 0; m_pPerm = 0; m_pSupp = 0; m_pAmom = 0; } //----------------------------------------------------------------------------- // initialize bool FEBiphasic::Init() { if (!m_pSolid->Init()) return false; if (!m_pPerm->Init()) return false; if (m_pSupp && !m_pSupp->Init()) return false; if (m_pAmom && !m_pAmom->Init()) return false; return FEMaterial::Init(); } //----------------------------------------------------------------------------- // returns a pointer to a new material point object FEMaterialPointData* FEBiphasic::CreateMaterialPointData() { // create the solid material point FEMaterialPointData* ep = m_pSolid->CreateMaterialPointData(); // create biphasic material point FEBiphasicMaterialPoint* pt = new FEBiphasicMaterialPoint(ep); return pt; } //----------------------------------------------------------------------------- // update specialized material points void FEBiphasic::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { m_pSolid->UpdateSpecializedMaterialPoints(mp, tp); m_pPerm->UpdateSpecializedMaterialPoints(mp, tp); if (m_pSupp) m_pSupp->UpdateSpecializedMaterialPoints(mp, tp); if (m_pAmom) m_pAmom->UpdateSpecializedMaterialPoints(mp, tp); } //----------------------------------------------------------------------------- //! Porosity in current configuration double FEBiphasic::Porosity(FEMaterialPoint& pt) { FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pet = *pt.ExtractData<FEBiphasicMaterialPoint>(); // relative volume double J = et.m_J; // porosity // double phiw = 1 - m_phi0/J; double phi0 = pet.m_phi0t; double phiw = 1 - phi0/J; // check for pore collapse // TODO: throw an error if pores collapse phiw = (phiw > 0) ? phiw : 0; return phiw; } //----------------------------------------------------------------------------- //! The stress of a poro-elastic material is the sum of the fluid pressure //! and the elastic stress. Note that this function is declared in the base class //! so you do not have to reimplement it in a derived class, unless additional //! pressure terms are required. mat3ds FEBiphasic::Stress(FEMaterialPoint& mp) { FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // calculate solid material stress mat3ds s = m_pSolid->Stress(mp); // add fluid pressure s.xx() -= pt.m_p; s.yy() -= pt.m_p; s.zz() -= pt.m_p; return s; } mat3ds FEBiphasic::SecantStress(FEMaterialPoint& mp) { FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // calculate solid material stress mat3ds s = m_pSolid->SecantStress(mp); // add fluid pressure s.xx() -= pt.m_p; s.yy() -= pt.m_p; s.zz() -= pt.m_p; return s; } //----------------------------------------------------------------------------- //! The tangent is the sum of the elastic tangent plus the fluid tangent. Note //! that this function is declared in the base class, so you don't have to //! reimplement it unless additional tangent components are required. tens4dmm FEBiphasic::Tangent(FEMaterialPoint& mp) { FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // call solid tangent routine tens4dmm c = m_pSolid->Tangent(mp); // fluid pressure double p = pt.m_p; // adjust tangent for pressures double D[6][6] = {0}; c.extract(D); D[0][0] -= -p; D[1][1] -= -p; D[2][2] -= -p; D[0][1] -= p; D[1][0] -= p; D[1][2] -= p; D[2][1] -= p; D[0][2] -= p; D[2][0] -= p; D[3][3] -= -p; D[4][4] -= -p; D[5][5] -= -p; return tens4dmm(D); } //----------------------------------------------------------------------------- //! The tangent is the sum of the elastic tangent plus the fluid tangent. Note //! that this function is declared in the base class, so you don't have to //! reimplement it unless additional tangent components are required. tens4dmm FEBiphasic::SecantTangent(FEMaterialPoint& mp) { FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // call solid tangent routine tens4dmm c = m_pSolid->SecantTangent(mp); // fluid pressure double p = pt.m_p; // adjust tangent for pressures double D[6][6] = {0}; c.extract(D); D[0][0] -= -p; D[1][1] -= -p; D[2][2] -= -p; D[0][1] -= p; D[1][0] -= p; D[1][2] -= p; D[2][1] -= p; D[0][2] -= p; D[2][0] -= p; D[3][3] -= -p; D[4][4] -= -p; D[5][5] -= -p; return tens4dmm(D); } //----------------------------------------------------------------------------- //! actual fluid pressure (same as effective pressure here) double FEBiphasic::Pressure(FEMaterialPoint& pt) { FEBiphasicMaterialPoint& ppt = *pt.ExtractData<FEBiphasicMaterialPoint>(); return ppt.m_p; } //----------------------------------------------------------------------------- //! Return the permeability tensor as a double array void FEBiphasic::Permeability(double k[3][3], FEMaterialPoint& pt) { mat3ds kt = m_pPerm->Permeability(pt); k[0][0] = kt.xx(); k[1][1] = kt.yy(); k[2][2] = kt.zz(); k[0][1] = k[1][0] = kt.xy(); k[1][2] = k[2][1] = kt.yz(); k[2][0] = k[0][2] = kt.xz(); } //----------------------------------------------------------------------------- mat3ds FEBiphasic::Permeability(FEMaterialPoint& mp) { return m_pPerm->Permeability(mp); } //----------------------------------------------------------------------------- //! return tangent of permeability with strain tens4dmm FEBiphasic::Tangent_Permeability_Strain(FEMaterialPoint& mp) { return m_pPerm->Tangent_Permeability_Strain(mp); } //! return the material permeability property mat3ds FEBiphasic::MaterialPermeability(FEMaterialPoint& mp, const mat3ds E) { // Evaluate right Cauchy-Green tensor from E mat3ds C = mat3dd(1) + E*2; // Evaluate right stretch tensor U from C vec3d v[3]; double lam[3]; C.eigen2(lam, v); lam[0] = sqrt(lam[0]); lam[1] = sqrt(lam[1]); lam[2] = sqrt(lam[2]); mat3ds U = dyad(v[0])*lam[0] + dyad(v[1])*lam[1] + dyad(v[2])*lam[2]; double J = lam[0]*lam[1]*lam[2]; // temporarily replace F in material point with U FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3ds Ui = dyad(v[0])/lam[0] + dyad(v[1])/lam[1] + dyad(v[2])/lam[2]; mat3d Fsafe = pt.m_F; double Jsafe = pt.m_J; pt.m_F = U; pt.m_J = J; // Evaluate hydraulic permeability mat3ds k = Permeability(mp); // Restore original F pt.m_F = Fsafe; pt.m_J = Jsafe; // Convert spatial permeability to material permeability mat3ds K = (Ui*k*Ui).sym()*J; return K; } //----------------------------------------------------------------------------- //! calculate spatial tangent stiffness at material point, using secant method tens4dmm FEBiphasic::SecantTangent_Permeability_Strain(FEMaterialPoint& mp) { // extract the deformation gradient FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); mat3d F = pt.m_F; double J = pt.m_J; mat3ds E = pt.Strain(); mat3dd I(1); // calculate the material permeability at the current deformation gradient mat3ds K = MaterialPermeability(mp,E); // create deformation gradient increment double eps = 1e-9; vec3d e[3]; e[0] = vec3d(1,0,0); e[1] = vec3d(0,1,0); e[2] = vec3d(0,0,1); tens4dmm Kmm; for (int k=0; k<3; ++k) { // evaluate incremental material permeability mat3ds dE = dyads(e[k], e[k])*(eps/2); mat3ds dK = (MaterialPermeability(mp,E+dE) - K)/eps; // evaluate the secant modulus Kmm(0,0,k,k) = dK.xx(); Kmm(1,1,k,k) = dK.yy(); Kmm(2,2,k,k) = dK.zz(); Kmm(0,1,k,k) = Kmm(1,0,k,k) = dK.xy(); Kmm(1,2,k,k) = Kmm(2,1,k,k) = dK.yz(); Kmm(2,0,k,k) = Kmm(0,2,k,k) = dK.xz(); for (int l=0; l<3; ++l) { if (l != k) { // evaluate incremental material permeability mat3ds dE = dyads(e[k], e[l])*(eps/2); mat3ds dK = (MaterialPermeability(mp,E+dE) - K)/eps; // evaluate the secant modulus Kmm(0,0,k,l) = Kmm(0,0,l,k) = dK.xx(); Kmm(1,1,k,l) = Kmm(1,1,l,k) = dK.yy(); Kmm(2,2,k,l) = Kmm(2,2,l,k) = dK.zz(); Kmm(0,1,k,l) = Kmm(0,1,l,k) = Kmm(1,0,k,l) = Kmm(1,0,l,k) = dK.xy(); Kmm(1,2,k,l) = Kmm(1,2,l,k) = Kmm(2,1,k,l) = Kmm(2,1,l,k) = dK.yz(); Kmm(2,0,k,l) = Kmm(2,0,l,k) = Kmm(0,2,k,l) = Kmm(0,2,l,k) = dK.xz(); } } } return Kmm.pp(F)/J; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBioMixData.cpp
.cpp
14,177
482
/*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 "FEBioMixData.h" #include "FEBiphasicSolute.h" #include "FETriphasic.h" #include "FEMultiphasic.h" #include "FECore/FEModel.h" #include <FECore/FESolidDomain.h> //----------------------------------------------------------------------------- double FENodeConcentration::value(const FENode& node) { const int dof_C = GetFEModel()->GetDOFIndex("concentration", 0); return node.get(dof_C); } //----------------------------------------------------------------------------- double FENodeFluidPressure::value(const FENode& node) { const int dof_P = GetFEModel()->GetDOFIndex("p"); return node.get(dof_P); } //----------------------------------------------------------------------------- double FENodeSoluteConcentration_::value(const FENode& node) { double val = 0.0; const int dof_C = GetFEModel()->GetDOFIndex("concentration", m_nsol); return node.get(dof_C); } //----------------------------------------------------------------------------- double FELogElemFluidPressure::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FEBiphasicMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FEBiphasicMaterialPoint>(); if (ppt) val += ppt->m_pa; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemFluidFluxX::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FEBiphasicMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FEBiphasicMaterialPoint>(); if (ppt) val += ppt->m_w.x; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemFluidFluxY::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FEBiphasicMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FEBiphasicMaterialPoint>(); if (ppt) val += ppt->m_w.y; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemFluidFluxZ::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FEBiphasicMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FEBiphasicMaterialPoint>(); if (ppt) val += ppt->m_w.z; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSoluteConcentration::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_ca[0]; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSoluteFluxX::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_j[0].x; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSoluteFluxY::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_j[0].y; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSoluteFluxZ::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_j[0].z; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSoluteRefConcentration::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_sbmr[0]; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogFixedChargeDensity::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i = 0; i < nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_cF; } return val / (double)nint; } //----------------------------------------------------------------------------- double FELogElemSoluteConcentration_::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_ca[m_nsol]; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSoluteFluxX_::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_j[m_nsol].x; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSoluteFluxY_::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_j[m_nsol].y; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSoluteFluxZ_::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_j[m_nsol].z; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemElectricPotential::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_psi; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemCurrentDensityX::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_Ie.x; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemCurrentDensityY::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_Ie.y; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemCurrentDensityZ::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_Ie.z; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemSBMConcentration_::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i=0; i<nint; ++i) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(i)->ExtractData<FESolutesMaterialPoint>(); if (ppt) val += ppt->m_sbmr[m_nsol]; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemPorosity::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i = 0; i < nint; ++i) { const FEMaterialPoint* mp = el.GetMaterialPoint(i); const FEElasticMaterialPoint* et = (mp->ExtractData<FEElasticMaterialPoint>()); const FEBiphasicMaterialPoint* pt = (mp->ExtractData<FEBiphasicMaterialPoint>()); double p = (et && pt ? (1 - pt->m_phi0t / et->m_J) : 0.0); val += p; } return val / (double) nint; } //----------------------------------------------------------------------------- double FELogElemPermeability::value(FEElement& el) { FEDomain* dom = dynamic_cast<FEDomain*>(el.GetMeshPartition()); if (dom == nullptr) return 0.0; FEMaterial* mat = dom->GetMaterial(); if (mat == nullptr) return 0.0; FEBiphasic* biphasic = mat->ExtractProperty<FEBiphasic>(); if (biphasic == nullptr) return 0.0; double val = 0.0; int nint = el.GaussPoints(); for (int i = 0; i < nint; ++i) { const FEMaterialPoint* mp = el.GetMaterialPoint(i); mat3ds K = biphasic->Permeability(const_cast<FEMaterialPoint&>(*mp)); switch (m_comp) { case 0: val += K(0, 0); break; case 1: val += K(1, 1); break; case 2: val += K(2, 2); break; case 3: val += K(0, 1); break; case 4: val += K(1, 2); break; case 5: val += K(0, 2); break; } } return val / (double)nint; } //----------------------------------------------------------------------------- double FELogElemSolidStress::value(FEElement& el) { double val = 0.0; int nint = el.GaussPoints(); for (int i = 0; i < nint; ++i) { const FEMaterialPoint* mp = el.GetMaterialPoint(i); const FEBiphasicMaterialPoint* pt = (mp->ExtractData<FEBiphasicMaterialPoint>()); if (pt) { mat3ds ss = pt->m_ss; switch (m_comp) { case 0: val += ss(0, 0); break; case 1: val += ss(1, 1); break; case 2: val += ss(2, 2); break; case 3: val += ss(0, 1); break; case 4: val += ss(1, 2); break; case 5: val += ss(0, 2); break; } } } return val / (double)nint; } FELogSBMRefAppDensity::FELogSBMRefAppDensity(FEModel* fem, int n) : FELogElemData(fem), sbmid(n) { } double FELogSBMRefAppDensity::value(FEElement& el) { FESolidDomain* dom = dynamic_cast<FESolidDomain*>(el.GetMeshPartition()); if (dom == nullptr) return 0; FEMultiphasic* pm = dynamic_cast<FEMultiphasic*> (dom->GetMaterial()); if (pm == nullptr) return 0; // figure out the local SBM IDs. This depends on the material int n = -1; for (int i = 0; i < pm->SBMs(); ++i) if (pm->GetSBM(i)->GetSBMID() == sbmid) { n = i; break; } if (n == -1) return 0; // calculate average concentration double ew = 0; for (int j = 0; j < el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); FESolutesMaterialPoint* st = (mp.ExtractData<FESolutesMaterialPoint>()); if (st && (n >= 0) && (n < st->m_sbmr.size())) ew += st->m_sbmr[n]; } ew /= el.GaussPoints(); return ew; } //============================================================================= FELogDomainIntegralSBMConcentration::FELogDomainIntegralSBMConcentration(FEModel* fem, int sbm) : FELogDomainData(fem) { m_sbm = sbm; } double FELogDomainIntegralSBMConcentration::value(FEDomain& dom) { double sum = 0.0; if (dynamic_cast<FESolidDomain*>(&dom)) { FESolidDomain& solidDomain = dynamic_cast<FESolidDomain&>(dom); for (int i = 0; i < solidDomain.Elements(); ++i) { FESolidElement& el = solidDomain.Element(i); double val = 0.0; int nint = el.GaussPoints(); double* gw = el.GaussWeights(); for (int n = 0; n < nint; ++n) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(n)->ExtractData<FESolutesMaterialPoint>(); if (ppt) { double Jw = solidDomain.detJt(el, n) * gw[n]; val += ppt->m_sbmr[m_sbm] * Jw; } } sum += val; } } return sum; } //============================================================================= FELogDomainIntegralSoluteConcentration::FELogDomainIntegralSoluteConcentration(FEModel* fem, int sol) : FELogDomainData(fem) { m_nsol = sol; } double FELogDomainIntegralSoluteConcentration::value(FEDomain& dom) { double sum = 0.0; if (dynamic_cast<FESolidDomain*>(&dom)) { FESolidDomain& solidDomain = dynamic_cast<FESolidDomain&>(dom); for (int i = 0; i < solidDomain.Elements(); ++i) { FESolidElement& el = solidDomain.Element(i); double val = 0.0; int nint = el.GaussPoints(); double* gw = el.GaussWeights(); for (int n = 0; n < nint; ++n) { FESolutesMaterialPoint* ppt = el.GetMaterialPoint(n)->ExtractData<FESolutesMaterialPoint>(); if (ppt) { double Jw = solidDomain.detJt(el, n) * gw[n]; val += ppt->m_ca[m_nsol] * Jw; } } sum += val; } } return sum; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESupplySynthesisBinding.h
.h
2,891
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 "FEBiphasicSolute.h" //----------------------------------------------------------------------------- // This class implements a material that has a solute supply based on // receptor-ligand binding kinetics as described by the Langmuir or Hill equation // and also includes a constant supply rate (synthesis when positive, degradation // when negative). class FEBIOMIX_API FESupplySynthesisBinding : public FESoluteSupply { public: //! constructor FESupplySynthesisBinding(FEModel* pfem); //! Solute supply double Supply(FEMaterialPoint& pt) override; //! Tangent of supply with respect to strain double Tangent_Supply_Strain(FEMaterialPoint& mp) override; //! Tangent of supply with respect to concentration double Tangent_Supply_Concentration(FEMaterialPoint& mp) override; //! receptor-ligand complex supply double ReceptorLigandSupply(FEMaterialPoint& mp) override; //! Solute supply at steady-state double SupplySS(FEMaterialPoint& pt) override; //! receptor-ligand complex concentration at steady-state double ReceptorLigandConcentrationSS(FEMaterialPoint& mp) override; //! referential solid supply double SolidSupply(FEMaterialPoint& pt) override; //! referential solid volume fraction under steady-state conditions double SolidConcentrationSS(FEMaterialPoint& pt) override; public: double m_supp; //!< synthesis rate double m_kf; //!< forward reaction rate constant double m_kr; //!< reverse reaction rate constant double m_crt; //!< total receptor concentration (referential) // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicSolidDomain.cpp
.cpp
68,483
1,760
/*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 "FEMultiphasicSolidDomain.h" #include "FEMultiphasicMultigeneration.h" #include <FECore/FEModel.h> #include <FECore/FEAnalysis.h> #include <FECore/log.h> #include <FECore/DOFS.h> #include <FEBioMech/FEBioMech.h> #include <FECore/FELinearSystem.h> #include <FECore/sys.h> #ifndef SQR #define SQR(x) ((x)*(x)) #endif //----------------------------------------------------------------------------- FEMultiphasicSolidDomain::FEMultiphasicSolidDomain(FEModel* pfem) : FESolidDomain(pfem), FEMultiphasicDomain(pfem), m_dofU(pfem), m_dofSU(pfem), m_dofR(pfem), m_dof(pfem) { m_pMat = nullptr; // 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)); } } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::SetMaterial(FEMaterial* pmat) { FEDomain::SetMaterial(pmat); m_pMat = dynamic_cast<FEMultiphasic*>(pmat); assert(m_pMat); } //----------------------------------------------------------------------------- // get total dof list const FEDofList& FEMultiphasicSolidDomain::GetDOFList() const { return m_dof; } //----------------------------------------------------------------------------- //! Unpack the element LM data. void FEMultiphasicSolidDomain::UnpackLM(FEElement& el, vector<int>& lm) { // get nodal DOFS const int nsol = m_pMat->Solutes(); int N = el.Nodes(); int ndpn = 4+nsol; lm.resize(N*(ndpn+3)); for (int i=0; i<N; ++i) { int n = el.m_node[i]; FENode& node = m_pMesh->Node(n); vector<int>& id = node.m_ID; // first the displacement dofs lm[ndpn*i ] = id[m_dofU[0]]; lm[ndpn*i+1] = id[m_dofU[1]]; lm[ndpn*i+2] = id[m_dofU[2]]; // now the pressure dofs lm[ndpn*i+3] = id[m_dofP]; // concentration dofs for (int k=0; k<nsol; ++k) lm[ndpn*i+4+k] = id[m_dofC+m_pMat->GetSolute(k)->GetSoluteDOF()]; // rigid rotational dofs // TODO: Do we really need this? lm[ndpn*N + 3*i ] = id[m_dofR[0]]; lm[ndpn*N + 3*i+1] = id[m_dofR[1]]; lm[ndpn*N + 3*i+2] = id[m_dofR[2]]; } // substitute interface dofs for solid-shell interfaces FESolidElement& sel = static_cast<FESolidElement&>(el); for (int i=0; i<sel.m_bitfc.size(); ++i) { if (sel.m_bitfc[i]) { FENode& node = m_pMesh->Node(sel.m_node[i]); vector<int>& id = node.m_ID; // first the back-face displacement dofs lm[ndpn*i ] = id[m_dofSU[0]]; lm[ndpn*i+1] = id[m_dofSU[1]]; lm[ndpn*i+2] = id[m_dofSU[2]]; // now the pressure dof (if the shell has it) if (id[m_dofQ] != -1) lm[ndpn*i+3] = id[m_dofQ]; // concentration dofs for (int k=0; k<nsol; ++k) { int dofd = m_dofD+m_pMat->GetSolute(k)->GetSoluteDOF(); if (id[dofd] != -1) lm[ndpn*i+4+k] = id[dofd]; } } } } //----------------------------------------------------------------------------- bool FEMultiphasicSolidDomain::Init() { // initialize base class if (FESolidDomain::Init() == false) return false; // extract the initial concentrations of the solid-bound molecules const int nsbm = m_pMat->SBMs(); const int nsol = m_pMat->Solutes(); for (int i = 0; i<(int)m_Elem.size(); ++i) { // get the solid element FESolidElement& el = m_Elem[i]; // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n = 0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEBiphasicMaterialPoint& pb = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); // initialize multiphasic solutes ps.m_nsol = nsol; ps.m_c.assign(nsol,0); ps.m_ca.assign(nsol,0); ps.m_crp.assign(nsol, 0); ps.m_gradc.assign(nsol,vec3d(0,0,0)); ps.m_k.assign(nsol, 0); ps.m_dkdJ.assign(nsol, 0); ps.m_dkdc.resize(nsol, vector<double>(nsol,0)); ps.m_j.assign(nsol,vec3d(0,0,0)); ps.m_bsb.assign(nsol, false); ps.m_nsbm = nsbm; ps.m_sbmr.assign(nsbm,0); ps.m_sbmrp.assign(nsbm,0); ps.m_sbmrhat.assign(nsbm,0); ps.m_sbmrhatp.assign(nsbm,0); ps.m_sbmrmin.assign(nsbm,0); ps.m_sbmrmax.assign(nsbm,0); // assign bounds on apparent densities of the solid-bound molecules for (int i = 0; i<nsbm; ++i) { ps.m_sbmr[i] = ps.m_sbmrp[i] = m_pMat->GetSBM(i)->m_rho0(mp); ps.m_sbmrmin[i] = m_pMat->GetSBM(i)->m_rhomin; ps.m_sbmrmax[i] = m_pMat->GetSBM(i)->m_rhomax; } // initialize referential solid volume fraction pb.m_phi0 = pb.m_phi0t = m_pMat->SolidReferentialVolumeFraction(mp); if (pb.m_phi0 > 1.0) { feLogError("Referential solid volume fraction of multiphasic material cannot exceed unity!\nCheck ratios of sbm apparent and true densities."); return false; } // evaluate reaction rates at initial time // check if this mixture includes chemical reactions int nreact = (int)m_pMat->Reactions(); if (nreact) { // for chemical reactions involving solid-bound molecules, // update their concentration // multiphasic material point data FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); double phi0 = pb.m_phi0t; for (int isbm=0; isbm<nsbm; ++isbm) { // combine the molar supplies from all the reactions for (int k=0; k<nreact; ++k) { double zetahat = m_pMat->GetReaction(k)->ReactionSupply(mp); double v = m_pMat->GetReaction(k)->m_v[nsol+isbm]; // remember to convert from molar supply to referential mass supply ps.m_sbmrhat[isbm] += (pt.m_J-phi0)*m_pMat->SBMMolarMass(isbm)*v*zetahat; } } } } } // set the active degrees of freedom list FEDofList dofs(GetFEModel()); for (int i=0; i<nsol; ++i) { int m = m_pMat->GetSolute(i)->GetSoluteDOF(); dofs.AddDof(m_dofC + m); dofs.AddDof(m_dofD + m); } m_dof = dofs; return true; } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::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]); } } } const int nsol = m_pMat->Solutes(); // Activate dof_P and dof_C, except when a solid element is connected to the // back of a shell element, in which case activate dof_Q and dof_D for those nodes. FEMesh& m = *GetMesh(); for (int i=0; i<Elements(); ++i) { FESolidElement& el = m_Elem[i]; int neln = el.Nodes(); for (int j=0; j<neln; ++j) { FENode& node = m.Node(el.m_node[j]); if (el.m_bitfc.size()>0 && el.m_bitfc[j]) { node.set_active(m_dofQ); for (int l=0; l<nsol; ++l) node.set_active(m_dofD + m_pMat->GetSolute(l)->GetSoluteDOF()); } else { node.set_active(m_dofP); for (int l=0; l<nsol; ++l) node.set_active(m_dofC + m_pMat->GetSolute(l)->GetSoluteDOF()); } } } } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::InitMaterialPoints() { const int nsol = m_pMat->Solutes(); FEMesh& m = *GetMesh(); // fix initial conditions for solid element nodes that are attached to the back of shells // this is needed because initial conditions for solid elements are prescribed to m_dofC // but we have to use m_dofD degrees of freedom for those solid element nodes for (int i=0; i<Elements(); ++i) { FESolidElement& el = m_Elem[i]; // only process solid elements attached to the back of a shell if (el.m_bitfc.size()>0) { int neln = el.Nodes(); vector<double> cic(nsol,0); // get the solute concentrations from nodes not attached to shells for (int j=0; j<neln; ++j) { FENode& node = m.Node(el.m_node[j]); if (!el.m_bitfc[j]) { for (int l=0; l<nsol; ++l) cic[l] = node.get(m_dofC + m_pMat->GetSolute(l)->GetSoluteDOF()); break; } } // assign those concentrations to nodes attached to shells for (int j=0; j<neln; ++j) { FENode& node = m.Node(el.m_node[j]); if (el.m_bitfc[j]) { for (int l=0; l<nsol; ++l) node.set(m_dofD + m_pMat->GetSolute(l)->GetSoluteDOF(), cic[l]); } } } } const int nsbm = m_pMat->SBMs(); const int NE = FEElement::MAX_NODES; double p0[NE]; vector< vector<double> > c0(nsol, vector<double>(NE)); vector<int> sid(nsol); for (int j = 0; j<nsol; ++j) sid[j] = m_pMat->GetSolute(j)->GetSoluteDOF(); for (int j = 0; j<(int)m_Elem.size(); ++j) { // get the solid element FESolidElement& el = m_Elem[j]; // get the number of nodes int neln = el.Nodes(); // get initial values of fluid pressure and solute concentrations if (el.m_bitfc.size() == 0) { for (int i = 0; i<neln; ++i) { FENode& ni = m.Node(el.m_node[i]); p0[i] = ni.get(m_dofP); for (int isol = 0; isol<nsol; ++isol) c0[isol][i] = ni.get(m_dofC + sid[isol]); } } else { for (int i = 0; i<neln; ++i) { FENode& ni = m.Node(el.m_node[i]); p0[i] = el.m_bitfc[i] ? ni.get(m_dofQ) : ni.get(m_dofP); for (int isol = 0; isol<nsol; ++isol) c0[isol][i] = (ni.m_ID[m_dofD + isol] != -1) ? ni.get(m_dofD + sid[isol]) : ni.get(m_dofC + sid[isol]); } } // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n = 0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pm = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); // initialize effective fluid pressure and its gradient pt.m_p = el.Evaluate(p0, n); pt.m_gradp = gradient(el, p0, n); // initialize multiphasic solutes ps.m_nsol = nsol; ps.m_nsbm = nsbm; // initialize effective solute concentrations for (int isol = 0; isol<nsol; ++isol) { ps.m_c[isol] = el.Evaluate(c0[isol], n); ps.m_gradc[isol] = gradient(el, c0[isol], n); } // determine if solute is 'solid-bound' for (int isol = 0; isol<nsol; ++isol) { FESolute* soli = m_pMat->GetSolute(isol); if (soli->m_pDiff->Diffusivity(mp).norm() == 0) ps.m_bsb[isol] = true; // initialize solute concentrations ps.m_ca[isol] = m_pMat->Concentration(mp, isol); } // initialize referential solid volume fraction pt.m_phi0t = m_pMat->SolidReferentialVolumeFraction(mp); // initialize electric potential ps.m_psi = m_pMat->ElectricPotential(mp); // initialize fluxes pt.m_w = m_pMat->FluidFlux(mp); for (int isol = 0; isol<nsol; ++isol) { ps.m_j[isol] = m_pMat->SoluteFlux(mp, isol); ps.m_crp[isol] = pm.m_J*m_pMat->Porosity(mp)*ps.m_ca[isol]; } pt.m_pa = m_pMat->Pressure(mp); // calculate FCD, current and stress ps.m_cF = m_pMat->FixedChargeDensity(mp); ps.m_Ie = m_pMat->CurrentDensity(mp); pm.m_s = m_pMat->Stress(mp); } } } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::Reset() { // reset base class FESolidDomain::Reset(); const int nsol = m_pMat->Solutes(); const int nsbm = m_pMat->SBMs(); for (int i=0; i<(int) m_Elem.size(); ++i) { // get the solid element FESolidElement& el = m_Elem[i]; // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); // initialize multiphasic solutes ps.m_nsol = nsol; ps.m_c.assign(nsol,0); ps.m_ca.assign(nsol,0); ps.m_crp.assign(nsol, 0); ps.m_gradc.assign(nsol,vec3d(0,0,0)); ps.m_k.assign(nsol, 0); ps.m_dkdJ.assign(nsol, 0); ps.m_dkdc.resize(nsol, vector<double>(nsol,0)); ps.m_j.assign(nsol,vec3d(0,0,0)); ps.m_bsb.assign(nsol, false); ps.m_nsbm = nsbm; ps.m_sbmr.assign(nsbm,0); ps.m_sbmrp.assign(nsbm,0); ps.m_sbmrhat.assign(nsbm,0); ps.m_sbmrhatp.assign(nsbm,0); ps.m_sbmrmin.assign(nsbm,0); ps.m_sbmrmax.assign(nsbm,0); // assign bounds on apparent densities of the solid-bound molecules for (int i = 0; i<nsbm; ++i) { ps.m_sbmr[i] = ps.m_sbmrp[i] = m_pMat->GetSBM(i)->m_rho0(mp); ps.m_sbmrmin[i] = m_pMat->GetSBM(i)->m_rhomin; ps.m_sbmrmax[i] = m_pMat->GetSBM(i)->m_rhomax; } // initialize referential solid volume fraction pt.m_phi0 = pt.m_phi0t = m_pMat->SolidReferentialVolumeFraction(mp); // reset chemical reaction element data ps.m_cri.clear(); ps.m_crd.clear(); for (int j=0; j<m_pMat->Reactions(); ++j) m_pMat->GetReaction(j)->ResetElementData(mp); } } m_breset = true; } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { FESolidDomain::PreSolveUpdate(timeInfo); const int NE = FEElement::MAX_NODES; vec3d x0[NE], xt[NE], r0, rt; FEMesh& m = *GetMesh(); for (size_t iel=0; iel<m_Elem.size(); ++iel) { FESolidElement& el = m_Elem[iel]; int neln = el.Nodes(); for (int i=0; i<neln; ++i) { x0[i] = m.Node(el.m_node[i]).m_r0; xt[i] = m.Node(el.m_node[i]).m_rt; } int n = el.GaussPoints(); for (int j=0; j<n; ++j) { r0 = el.Evaluate(x0, j); rt = el.Evaluate(xt, j); FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMaterialPoint& pe = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); FEMultigenSBMMaterialPoint* pmg = mp.ExtractData<FEMultigenSBMMaterialPoint>(); mp.m_r0 = r0; mp.m_rt = rt; pe.m_J = defgrad(el, pe.m_F, j); // reset determinant of solid deformation gradient at previous time pt.m_Jp = pe.m_J; // reset referential solid volume fraction at previous time pt.m_phi0p = pt.m_phi0t; // reset referential actual solute concentration at previous time for (int j=0; j<m_pMat->Solutes(); ++j) { ps.m_crp[j] = pe.m_J*m_pMat->Porosity(mp)*ps.m_ca[j]; } // reset referential solid-bound molecule concentrations at previous time ps.m_sbmrp = ps.m_sbmr; ps.m_sbmrhatp = ps.m_sbmrhat; // reset generational referential solid-bound molecule concentrations at previous time if (pmg) { for (int i=0; i<pmg->m_ngen; ++i) { for (int j=0; j<ps.m_nsbm; ++j) { pmg->m_gsbmrp[i][j] = pmg->m_gsbmr[i][j]; } } } // reset chemical reaction element data for (int j=0; j<m_pMat->Reactions(); ++j) m_pMat->GetReaction(j)->InitializeElementData(mp); mp.Update(timeInfo); } } } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::InternalForces(FEGlobalVector& R) { size_t NE = m_Elem.size(); // get nodal DOFS int nsol = m_pMat->Solutes(); int ndpn = 4+nsol; #pragma omp parallel for for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FESolidElement& el = m_Elem[i]; // get the element force vector and initialize it to zero int ndof = ndpn*el.Nodes(); fe.assign(ndof, 0); // calculate internal force vector ElementInternalForce(el, fe); // get the element's LM vector UnpackLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe); } } //----------------------------------------------------------------------------- //! calculates the internal equivalent nodal forces for solid elements void FEMultiphasicSolidDomain::ElementInternalForce(FESolidElement& el, vector<double>& fe) { int i, isol, n; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; vec3d gradN; mat3ds s; const double* Gr, *Gs, *Gt, *H; int nint = el.GaussPoints(); int neln = el.Nodes(); double* gw = el.GaussWeights(); const int nsol = m_pMat->Solutes(); int ndpn = 4+nsol; const int nreact = m_pMat->Reactions(); double dt = GetFEModel()->GetTime().timeIncrement; // repeat for all integration points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = invjact(el, Ji, n); detJt *= gw[n]; Gr = el.Gr(n); Gs = el.Gs(n); Gt = el.Gt(n); H = el.H(n); // next we get the determinant double Jp = bpt.m_Jp; double J = pt.m_J; // and then finally double divv = ((J-Jp)/dt)/J; // get the stress for this integration point s = pt.m_s; // get the flux vec3d& w = bpt.m_w; vector<vec3d> j(spt.m_j); vector<int> z(nsol); vector<double> kappa(spt.m_k); vec3d je(0,0,0); for (isol=0; isol<nsol; ++isol) { // get the charge number z[isol] = m_pMat->GetSolute(isol)->ChargeNumber(); je += j[isol]*z[isol]; } // evaluate the porosity, its derivative w.r.t. J, and its gradient double phiw = m_pMat->Porosity(mp); vector<double> chat(nsol,0); // get the solvent supply double phiwhat = 0; if (m_pMat->GetSolventSupply()) phiwhat = m_pMat->GetSolventSupply()->Supply(mp); // chemical reactions for (i=0; i<nreact; ++i) { FEChemicalReaction* pri = m_pMat->GetReaction(i); double zhat = pri->ReactionSupply(mp); phiwhat += phiw*pri->m_Vbar*zhat; for (isol=0; isol<nsol; ++isol) chat[isol] += phiw*zhat*pri->m_v[isol]; } for (i=0; i<neln; ++i) { // calculate global gradient of shape functions // note that we need the transposed of Ji, not Ji itself ! gradN = vec3d(Ji[0][0]*Gr[i]+Ji[1][0]*Gs[i]+Ji[2][0]*Gt[i], Ji[0][1]*Gr[i]+Ji[1][1]*Gs[i]+Ji[2][1]*Gt[i], Ji[0][2]*Gr[i]+Ji[1][2]*Gs[i]+Ji[2][2]*Gt[i]); // calculate internal force vec3d fu = s*gradN; // the '-' sign is so that the internal forces get subtracted // from the global residual vector fe[ndpn*i ] -= fu.x*detJt; fe[ndpn*i+1] -= fu.y*detJt; fe[ndpn*i+2] -= fu.z*detJt; fe[ndpn*i+3] -= dt*(w*gradN + (phiwhat - divv)*H[i])*detJt; for (isol=0; isol<nsol; ++isol) fe[ndpn*i+4+isol] -= dt*(gradN*(j[isol]+je*m_pMat->m_penalty) + H[i]*(chat[isol] - (phiw*spt.m_ca[isol] - spt.m_crp[isol]/J)/dt) )*detJt; } } } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::InternalForcesSS(FEGlobalVector& R) { size_t NE = m_Elem.size(); // get nodal DOFS int nsol = m_pMat->Solutes(); int ndpn = 4+nsol; #pragma omp parallel for for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FESolidElement& el = m_Elem[i]; // get the element force vector and initialize it to zero int ndof = ndpn*el.Nodes(); fe.assign(ndof, 0); // calculate internal force vector ElementInternalForceSS(el, fe); // get the element's LM vector UnpackLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe); } } //----------------------------------------------------------------------------- //! calculates the internal equivalent nodal forces for solid elements void FEMultiphasicSolidDomain::ElementInternalForceSS(FESolidElement& el, vector<double>& fe) { int i, isol, n; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; vec3d gradN; mat3ds s; const double* Gr, *Gs, *Gt, *H; int nint = el.GaussPoints(); int neln = el.Nodes(); double* gw = el.GaussWeights(); const int nsol = m_pMat->Solutes(); int ndpn = 4+nsol; const int nreact = m_pMat->Reactions(); double dt = GetFEModel()->GetTime().timeIncrement; // repeat for all integration points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = invjact(el, Ji, n); detJt *= gw[n]; Gr = el.Gr(n); Gs = el.Gs(n); Gt = el.Gt(n); H = el.H(n); // get the stress for this integration point s = pt.m_s; // get the flux vec3d& w = bpt.m_w; vector<vec3d> j(spt.m_j); vector<int> z(nsol); vector<double> kappa(spt.m_k); vec3d je(0,0,0); for (isol=0; isol<nsol; ++isol) { // get the charge number z[isol] = m_pMat->GetSolute(isol)->ChargeNumber(); je += j[isol]*z[isol]; } // evaluate the porosity, its derivative w.r.t. J, and its gradient double phiw = m_pMat->Porosity(mp); vector<double> chat(nsol,0); // get the solvent supply double phiwhat = 0; if (m_pMat->GetSolventSupply()) phiwhat = m_pMat->GetSolventSupply()->Supply(mp); // chemical reactions for (i=0; i<nreact; ++i) { FEChemicalReaction* pri = m_pMat->GetReaction(i); double zhat = pri->ReactionSupply(mp); phiwhat += phiw*pri->m_Vbar*zhat; for (isol=0; isol<nsol; ++isol) chat[isol] += phiw*zhat*pri->m_v[isol]; } for (i=0; i<neln; ++i) { // calculate global gradient of shape functions // note that we need the transposed of Ji, not Ji itself ! gradN = vec3d(Ji[0][0]*Gr[i]+Ji[1][0]*Gs[i]+Ji[2][0]*Gt[i], Ji[0][1]*Gr[i]+Ji[1][1]*Gs[i]+Ji[2][1]*Gt[i], Ji[0][2]*Gr[i]+Ji[1][2]*Gs[i]+Ji[2][2]*Gt[i]); // calculate internal force vec3d fu = s*gradN; // the '-' sign is so that the internal forces get subtracted // from the global residual vector fe[ndpn*i ] -= fu.x*detJt; fe[ndpn*i+1] -= fu.y*detJt; fe[ndpn*i+2] -= fu.z*detJt; fe[ndpn*i+3] -= dt*(w*gradN + H[i]*phiwhat)*detJt; for (isol=0; isol<nsol; ++isol) fe[ndpn*i+4+isol] -= dt*(gradN*(j[isol]+je*m_pMat->m_penalty) + H[i]*phiw*chat[isol] )*detJt; } } } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::StiffnessMatrix(FELinearSystem& LS, bool bsymm) { const int nsol = m_pMat->Solutes(); int ndpn = 4+nsol; // 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); // allocate stiffness matrix int neln = el.Nodes(); int ndof = neln*ndpn; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementMultiphasicStiffness(el, ke, bsymm); // get the lm vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) { const int nsol = m_pMat->Solutes(); int ndpn = 4+nsol; // 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); // allocate stiffness matrix int neln = el.Nodes(); int ndof = neln*ndpn; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementMultiphasicStiffnessSS(el, ke, bsymm); // get the lm vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- //! calculates element stiffness matrix for element iel //! bool FEMultiphasicSolidDomain::ElementMultiphasicStiffness(FESolidElement& el, matrix& ke, bool bsymm) { int nint = el.GaussPoints(); int neln = el.Nodes(); double *Gr, *Gs, *Gt, *H; // jacobian double Ji[3][3], detJ; // Gradient of shape functions vector<vec3d> gradN(neln); // gauss-weights double* gw = el.GaussWeights(); double dt = GetFEModel()->GetTime().timeIncrement; const int nsol = m_pMat->Solutes(); int ndpn = 4+nsol; const int nsbm = m_pMat->SBMs(); const int nreact = m_pMat->Reactions(); // zero stiffness matrix ke.zero(); // loop over gauss-points for (int n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint >()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint >()); // calculate jacobian detJ = invjact(el, Ji, n)*gw[n]; vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]); vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]); vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]); Gr = el.Gr(n); Gs = el.Gs(n); Gt = el.Gt(n); H = el.H(n); // calculate global gradient of shape functions for (int i=0; i<neln; ++i) gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i]; // get stress tensor mat3ds s = ept.m_s; // get elasticity tensor tens4ds C = m_pMat->Tangent(mp); // next we get the determinant double J = ept.m_J; // get the fluid flux and pressure gradient vec3d w = ppt.m_w; vec3d gradp = ppt.m_gradp; vector<double> c(spt.m_c); vector<vec3d> gradc(spt.m_gradc); vector<int> z(nsol); vector<double> kappa(spt.m_k); // get the charge number for (int isol=0; isol<nsol; ++isol) z[isol] = m_pMat->GetSolute(isol)->ChargeNumber(); vector<double> dkdJ(spt.m_dkdJ); vector< vector<double> > dkdc(spt.m_dkdc); vector< vector<double> > dkdr(spt.m_dkdr); vector< vector<double> > dkdJr(spt.m_dkdJr); vector< vector< vector<double> > > dkdrc(spt.m_dkdrc); // evaluate the porosity and its derivative double phiw = m_pMat->Porosity(mp); double phi0 = ppt.m_phi0t; double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the osmotic coefficient double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp); // evaluate the permeability mat3ds K = m_pMat->GetPermeability()->Permeability(mp); tens4dmm dKdE = m_pMat->GetPermeability()->Tangent_Permeability_Strain(mp); vector<mat3ds> dKdc(nsol); vector<mat3ds> D(nsol); vector<tens4dmm> dDdE(nsol); vector< vector<mat3ds> > dDdc(nsol, vector<mat3ds>(nsol)); vector<double> D0(nsol); vector< vector<double> > dD0dc(nsol, vector<double>(nsol)); vector<double> dodc(nsol); vector<mat3ds> dTdc(nsol); vector<mat3ds> ImD(nsol); mat3dd I(1); // evaluate the solvent supply and its derivatives mat3ds Phie; Phie.zero(); double Phip = 0; vector<double> Phic(nsol,0); vector<mat3ds> dchatde(nsol); if (m_pMat->GetSolventSupply()) { Phie = m_pMat->GetSolventSupply()->Tangent_Supply_Strain(mp); Phip = m_pMat->GetSolventSupply()->Tangent_Supply_Pressure(mp); } // chemical reactions vector<double> reactionSupply(nreact, 0.0); vector<mat3ds> tangentReactionSupplyStrain(nreact); vector< vector<double> > tangentReactionSupplyConcentration(nreact, vector<double>(nsol)); for (int i = 0; i < nreact; ++i) { FEChemicalReaction* reacti = m_pMat->GetReaction(i); reactionSupply[i] = reacti->ReactionSupply(mp); tangentReactionSupplyStrain[i] = reacti->Tangent_ReactionSupply_Strain(mp); for (int isol = 0; isol < nsol; ++isol) { tangentReactionSupplyConcentration[i][isol] = reacti->Tangent_ReactionSupply_Concentration(mp, isol); } Phie += reacti->m_Vbar*(I*reactionSupply[i] + tangentReactionSupplyStrain [i]*(J*phiw)); } for (int isol=0; isol<nsol; ++isol) { FESolute* soli = m_pMat->GetSolute(isol); // evaluate the permeability derivatives dKdc[isol] = m_pMat->GetPermeability()->Tangent_Permeability_Concentration(mp,isol); // evaluate the diffusivity tensor and its derivatives D[isol] = soli->m_pDiff->Diffusivity(mp); dDdE[isol] = soli->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity D0[isol] = soli->m_pDiff->Free_Diffusivity(mp); // evaluate the derivative of the osmotic coefficient dodc[isol] = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp,isol); // evaluate the stress tangent with concentration // dTdc[isol] = pm->GetSolid()->Tangent_Concentration(mp,isol); dTdc[isol] = mat3ds(0,0,0,0,0,0); ImD[isol] = I-D[isol]/D0[isol]; for (int jsol=0; jsol<nsol; ++jsol) { dDdc[isol][jsol] = soli->m_pDiff->Tangent_Diffusivity_Concentration(mp,jsol); dD0dc[isol][jsol] = soli->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,jsol); } // evaluate the solvent supply tangent with concentration if (m_pMat->GetSolventSupply()) Phic[isol] = m_pMat->GetSolventSupply()->Tangent_Supply_Concentration(mp,isol); // chemical reactions dchatde[isol].zero(); for (int ireact=0; ireact<nreact; ++ireact) { FEChemicalReaction* reacti = m_pMat->GetReaction(ireact); dchatde[isol] += reacti->m_v[isol] *(I*reactionSupply[ireact] + tangentReactionSupplyStrain[ireact] *(J*phiw)); Phic[isol] += phiw* reacti->m_Vbar*tangentReactionSupplyConcentration[ireact][isol]; } } // Miscellaneous constants double R = m_pMat->m_Rgas; double T = m_pMat->m_Tabs; double penalty = m_pMat->m_penalty; // evaluate the effective permeability and its derivatives mat3ds Ki = K.inverse(); mat3ds Ke(0,0,0,0,0,0); tens4d G = (dyad1(Ki,I) - dyad4(Ki,I)*2)*2 - ddot(dyad2(Ki,Ki),dKdE); vector<mat3ds> Gc(nsol); vector<mat3ds> dKedc(nsol); for (int isol=0; isol<nsol; ++isol) { Ke += ImD[isol]*(kappa[isol]*c[isol]/D0[isol]); G += dyad1(ImD[isol],I)*(R*T*c[isol]*J/D0[isol]/phiw*(dkdJ[isol]-kappa[isol]/phiw*dpdJ)) +(dyad1(I,I) - dyad2(I,I)*2 - dDdE[isol]/D0[isol])*(R*T*kappa[isol]*c[isol]/phiw/D0[isol]); Gc[isol] = ImD[isol]*(kappa[isol]/D0[isol]); for (int jsol=0; jsol<nsol; ++jsol) { Gc[isol] += ImD[jsol]*(c[jsol]/D0[jsol]*(dkdc[jsol][isol]-kappa[jsol]/D0[jsol]*dD0dc[jsol][isol])) -(dDdc[jsol][isol]-D[jsol]*(dD0dc[jsol][isol]/D0[jsol])*(kappa[jsol]*c[jsol]/SQR(D0[jsol]))); } Gc[isol] *= R*T/phiw; } Ke = (Ki + Ke*(R*T/phiw)).inverse(); tens4d dKedE = (dyad1(Ke,I) - dyad4(Ke,I)*2)*2 - ddot(dyad2(Ke,Ke),G); for (int isol=0; isol<nsol; ++isol) dKedc[isol] = -(Ke*(-Ki*dKdc[isol]*Ki + Gc[isol])*Ke).sym(); // calculate all the matrices vec3d vtmp,gp,qpu; vector<vec3d> gc(nsol),qcu(nsol),wc(nsol),jce(nsol); vector< vector<vec3d> > jc(nsol, vector<vec3d>(nsol)); mat3d wu, jue; vector<mat3d> ju(nsol); vector< vector<double> > qcc(nsol, vector<double>(nsol)); vector< vector<double> > dchatdc(nsol, vector<double>(nsol)); double sum; mat3ds De; for (int i=0; i<neln; ++i) { for (int j=0; j<neln; ++j) { // Kuu matrix mat3d Kuu = (mat3dd(gradN[i]*(s*gradN[j])) + vdotTdotv(gradN[i], C, gradN[j]))*detJ; ke[ndpn*i ][ndpn*j ] += Kuu[0][0]; ke[ndpn*i ][ndpn*j+1] += Kuu[0][1]; ke[ndpn*i ][ndpn*j+2] += Kuu[0][2]; ke[ndpn*i+1][ndpn*j ] += Kuu[1][0]; ke[ndpn*i+1][ndpn*j+1] += Kuu[1][1]; ke[ndpn*i+1][ndpn*j+2] += Kuu[1][2]; ke[ndpn*i+2][ndpn*j ] += Kuu[2][0]; ke[ndpn*i+2][ndpn*j+1] += Kuu[2][1]; ke[ndpn*i+2][ndpn*j+2] += Kuu[2][2]; // calculate the kpu matrix gp = vec3d(0,0,0); for (int isol=0; isol<nsol; ++isol) gp += (D[isol]*gradc[isol])*(kappa[isol]/D0[isol]); gp = gradp+gp*(R*T); wu = vdotTdotv(-gp, dKedE, gradN[j]); for (int isol=0; isol<nsol; ++isol) { wu += (((Ke*(D[isol]*gradc[isol])) & gradN[j])*(J*dkdJ[isol] - kappa[isol]) +Ke*(2*kappa[isol]*(gradN[j]*(D[isol]*gradc[isol]))))*(-R*T/D0[isol]) + (Ke*vdotTdotv(gradc[isol], dDdE[isol], gradN[j]))*(-kappa[isol]*R*T/D0[isol]); } qpu = -gradN[j]*(1.0/dt); vtmp = (wu.transpose()*gradN[i] + (qpu + Phie*gradN[j])*H[i])*(detJ*dt); ke[ndpn*i+3][ndpn*j ] += vtmp.x; ke[ndpn*i+3][ndpn*j+1] += vtmp.y; ke[ndpn*i+3][ndpn*j+2] += vtmp.z; // calculate the kup matrix vtmp = -gradN[i]*H[j]*detJ; ke[ndpn*i ][ndpn*j+3] += vtmp.x; ke[ndpn*i+1][ndpn*j+3] += vtmp.y; ke[ndpn*i+2][ndpn*j+3] += vtmp.z; // calculate the kpp matrix ke[ndpn*i+3][ndpn*j+3] += (H[i]*H[j]*Phip - gradN[i]*(Ke*gradN[j]))*(detJ*dt); // calculate kcu matrix data jue.zero(); De.zero(); for (int isol=0; isol<nsol; ++isol) { gc[isol] = -gradc[isol]*phiw + w*c[isol]/D0[isol]; ju[isol] = ((D[isol]*gc[isol]) & gradN[j])*(J*dkdJ[isol]) + vdotTdotv(gc[isol], dDdE[isol], gradN[j])*kappa[isol] + (((D[isol]*gradc[isol]) & gradN[j])*(-phis) +(D[isol]*((gradN[j]*w)*2) - ((D[isol]*w) & gradN[j]))*c[isol]/D0[isol] )*kappa[isol] +D[isol]*wu*(kappa[isol]*c[isol]/D0[isol]); jue += ju[isol]*z[isol]; De += D[isol]*(z[isol]*kappa[isol]*c[isol]/D0[isol]); qcu[isol] = qpu*(c[isol]*(kappa[isol]+J*phiw*dkdJ[isol])); // chemical reactions for (int ireact=0; ireact<nreact; ++ireact) { FEChemicalReaction* reacti = m_pMat->GetReaction(ireact); double sum1 = 0; double sum2 = 0; for (int isbm=0; isbm<nsbm; ++isbm) { sum1 += m_pMat->SBMMolarMass(isbm)*reacti->m_v[nsol+isbm]* ((J-phi0)*dkdr[isol][isbm]-kappa[isol]/m_pMat->SBMDensity(isbm)); sum2 += m_pMat->SBMMolarMass(isbm)*reacti->m_v[nsol+isbm]* (dkdr[isol][isbm]+(J-phi0)*dkdJr[isol][isbm]-dkdJ[isol]/m_pMat->SBMDensity(isbm)); } double zhat = reactionSupply[ireact]; mat3dd zhatI(zhat); mat3ds dzde = tangentReactionSupplyStrain[ireact]; qcu[isol] -= ((zhatI+dzde*(J-phi0))*gradN[j])*(sum1*c[isol]) +gradN[j]*(c[isol]*(J-phi0)*sum2*zhat); } } for (int isol=0; isol<nsol; ++isol) { // calculate the kcu matrix vtmp = ((ju[isol]+jue*penalty).transpose()*gradN[i] + (qcu[isol] + dchatde[isol]*gradN[j])*H[i])*(detJ*dt); ke[ndpn*i+4+isol][ndpn*j ] += vtmp.x; ke[ndpn*i+4+isol][ndpn*j+1] += vtmp.y; ke[ndpn*i+4+isol][ndpn*j+2] += vtmp.z; // calculate the kcp matrix ke[ndpn*i+4+isol][ndpn*j+3] -= (gradN[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradN[j]) ))*(detJ*dt); // calculate the kuc matrix sum = 0; for (int jsol=0; jsol<nsol; ++jsol) sum += c[jsol]*(dodc[isol]*kappa[jsol]+osmc*dkdc[jsol][isol]); vtmp = (dTdc[isol]*gradN[i] - gradN[i]*(R*T*(osmc*kappa[isol]+sum)))*H[j]*detJ; ke[ndpn*i ][ndpn*j+4+isol] += vtmp.x; ke[ndpn*i+1][ndpn*j+4+isol] += vtmp.y; ke[ndpn*i+2][ndpn*j+4+isol] += vtmp.z; // calculate the kpc matrix vtmp = vec3d(0,0,0); for (int jsol=0; jsol<nsol; ++jsol) vtmp += (D[jsol]*(dkdc[jsol][isol]-kappa[jsol]/D0[jsol]*dD0dc[jsol][isol]) +dDdc[jsol][isol]*kappa[jsol])/D0[jsol]*gradc[jsol]; wc[isol] = (dKedc[isol]*gp)*(-H[j]) -Ke*((D[isol]*gradN[j])*(kappa[isol]/D0[isol])+vtmp*H[j])*(R*T); ke[ndpn*i+3][ndpn*j+4+isol] += (gradN[i]*wc[isol]+H[i]*H[j]*Phic[isol])*(detJ*dt); } // calculate data for the kcc matrix jce.assign(nsol, vec3d(0,0,0)); for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { if (jsol != isol) { jc[isol][jsol] = ((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*H[j] +(D[isol]*(w*(-H[j]*dD0dc[isol][jsol]/D0[isol])+wc[jsol]))*(kappa[isol]*c[isol]/D0[isol]); qcc[isol][jsol] = -H[j]*phiw/dt*c[isol]*dkdc[isol][jsol]; } else { jc[isol][jsol] = (D[isol]*(gradN[j]*(-phiw)+w*(H[j]/D0[isol])))*kappa[isol] +((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*H[j] +(D[isol]*(w*(-H[j]*dD0dc[isol][jsol]/D0[isol])+wc[jsol]))*(kappa[isol]*c[isol]/D0[isol]); qcc[isol][jsol] = -H[j]*phiw/dt*(c[isol]*dkdc[isol][jsol] + kappa[isol]); } jce[jsol] += jc[isol][jsol]*z[isol]; // chemical reactions dchatdc[isol][jsol] = 0; for (int ireact=0; ireact<nreact; ++ireact) { FEChemicalReaction* reacti = m_pMat->GetReaction(ireact); dchatdc[isol][jsol] += reacti->m_v[isol] * tangentReactionSupplyConcentration[ireact][jsol]; double sum1 = 0; double sum2 = 0; for (int isbm=0; isbm<nsbm; ++isbm) { sum1 += m_pMat->SBMMolarMass(isbm)*reacti->m_v[nsol+isbm]* ((J-phi0)*dkdr[isol][isbm]-kappa[isol]/m_pMat->SBMDensity(isbm)); sum2 += m_pMat->SBMMolarMass(isbm)*reacti->m_v[nsol+isbm]* ((J-phi0)*dkdrc[isol][isbm][jsol]-dkdc[isol][jsol]/m_pMat->SBMDensity(isbm)); } double zhat = reactionSupply[ireact]; double dzdc = tangentReactionSupplyConcentration[ireact][jsol]; if (jsol != isol) { qcc[isol][jsol] -= H[j]*phiw*c[isol]*(dzdc*sum1+zhat*sum2); } else { qcc[isol][jsol] -= H[j]*phiw*((zhat+c[isol]*dzdc)*sum1+c[isol]*zhat*sum2); } } } } // calculate the kcc matrix for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { ke[ndpn*i+4+isol][ndpn*j+4+jsol] += (gradN[i]*(jc[isol][jsol]+jce[jsol]*penalty) + H[i]*(qcc[isol][jsol] + H[j]*phiw*dchatdc[isol][jsol]))*(detJ*dt); } } } } } // Enforce symmetry by averaging top-right and bottom-left corners of stiffness matrix double tmp; if (bsymm) { for (int i=0; i<ndpn*neln; ++i) for (int j=i+1; j<ndpn*neln; ++j) { tmp = 0.5*(ke[i][j]+ke[j][i]); ke[i][j] = ke[j][i] = tmp; } } return true; } //----------------------------------------------------------------------------- //! calculates element stiffness matrix for element iel //! for steady-state response (zero solid velocity, zero time derivative of //! solute concentration) //! bool FEMultiphasicSolidDomain::ElementMultiphasicStiffnessSS(FESolidElement& el, matrix& ke, bool bsymm) { int i, j, isol, jsol, n, ireact; int nint = el.GaussPoints(); int neln = el.Nodes(); double *Gr, *Gs, *Gt, *H; // jacobian double Ji[3][3], detJ; // Gradient of shape functions vector<vec3d> gradN(neln); // gauss-weights double* gw = el.GaussWeights(); double dt = GetFEModel()->GetTime().timeIncrement; const int nsol = m_pMat->Solutes(); int ndpn = 4+nsol; const int nreact = m_pMat->Reactions(); // zero stiffness matrix ke.zero(); // loop over gauss-points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint >()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint >()); // calculate jacobian detJ = invjact(el, Ji, n)*gw[n]; vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]); vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]); vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]); Gr = el.Gr(n); Gs = el.Gs(n); Gt = el.Gt(n); H = el.H(n); // calculate global gradient of shape functions for (i=0; i<neln; ++i) gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i]; // get stress tensor mat3ds s = ept.m_s; // get elasticity tensor tens4ds C = m_pMat->Tangent(mp); // next we get the determinant double J = ept.m_J; // get the fluid flux and pressure gradient vec3d w = ppt.m_w; vec3d gradp = ppt.m_gradp; vector<double> c(spt.m_c); vector<vec3d> gradc(spt.m_gradc); vector<int> z(nsol); vector<double> zz(nsol); vector<double> kappa(spt.m_k); // get the charge number for (isol=0; isol<nsol; ++isol) z[isol] = m_pMat->GetSolute(isol)->ChargeNumber(); vector<double> dkdJ(spt.m_dkdJ); vector< vector<double> > dkdc(spt.m_dkdc); // evaluate the porosity and its derivative double phiw = m_pMat->Porosity(mp); double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the osmotic coefficient double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp); // evaluate the permeability mat3ds K = m_pMat->GetPermeability()->Permeability(mp); tens4dmm dKdE = m_pMat->GetPermeability()->Tangent_Permeability_Strain(mp); vector<mat3ds> dKdc(nsol); vector<mat3ds> D(nsol); vector<tens4dmm> dDdE(nsol); vector< vector<mat3ds> > dDdc(nsol, vector<mat3ds>(nsol)); vector<double> D0(nsol); vector< vector<double> > dD0dc(nsol, vector<double>(nsol)); vector<double> dodc(nsol); vector<mat3ds> dTdc(nsol); vector<mat3ds> ImD(nsol); mat3dd I(1); // evaluate the solvent supply and its derivatives double phiwhat = 0; mat3ds Phie; Phie.zero(); double Phip = 0; vector<double> Phic(nsol,0); if (m_pMat->GetSolventSupply()) { phiwhat = m_pMat->GetSolventSupply()->Supply(mp); Phie = m_pMat->GetSolventSupply()->Tangent_Supply_Strain(mp); Phip = m_pMat->GetSolventSupply()->Tangent_Supply_Pressure(mp); } // chemical reactions for (i=0; i<nreact; ++i) Phie += m_pMat->GetReaction(i)->m_Vbar*(I*m_pMat->GetReaction(i)->ReactionSupply(mp) +m_pMat->GetReaction(i)->Tangent_ReactionSupply_Strain(mp)*(J*phiw)); for (isol=0; isol<nsol; ++isol) { // evaluate the permeability derivatives dKdc[isol] = m_pMat->GetPermeability()->Tangent_Permeability_Concentration(mp,isol); // evaluate the diffusivity tensor and its derivatives D[isol] = m_pMat->GetSolute(isol)->m_pDiff->Diffusivity(mp); dDdE[isol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity D0[isol] = m_pMat->GetSolute(isol)->m_pDiff->Free_Diffusivity(mp); // evaluate the derivative of the osmotic coefficient dodc[isol] = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp,isol); // evaluate the stress tangent with concentration // dTdc[isol] = pm->GetSolid()->Tangent_Concentration(mp,isol); dTdc[isol] = mat3ds(0,0,0,0,0,0); ImD[isol] = I-D[isol]/D0[isol]; for (jsol=0; jsol<nsol; ++jsol) { dDdc[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Diffusivity_Concentration(mp,jsol); dD0dc[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,jsol); } // evaluate the solvent supply tangent with concentration if (m_pMat->GetSolventSupply()) Phic[isol] = m_pMat->GetSolventSupply()->Tangent_Supply_Concentration(mp,isol); } // Miscellaneous constants double R = m_pMat->m_Rgas; double T = m_pMat->m_Tabs; double penalty = m_pMat->m_penalty; // evaluate the effective permeability and its derivatives mat3ds Ki = K.inverse(); mat3ds Ke(0,0,0,0,0,0); tens4d G = (dyad1(Ki,I) - dyad4(Ki,I)*2)*2 - ddot(dyad2(Ki,Ki),dKdE); vector<mat3ds> Gc(nsol); vector<mat3ds> dKedc(nsol); for (isol=0; isol<nsol; ++isol) { Ke += ImD[isol]*(kappa[isol]*c[isol]/D0[isol]); G += dyad1(ImD[isol],I)*(R*T*c[isol]*J/D0[isol]/phiw*(dkdJ[isol]-kappa[isol]/phiw*dpdJ)) +(dyad1(I,I) - dyad2(I,I)*2 - dDdE[isol]/D0[isol])*(R*T*kappa[isol]*c[isol]/phiw/D0[isol]); Gc[isol] = ImD[isol]*(kappa[isol]/D0[isol]); for (jsol=0; jsol<nsol; ++jsol) { Gc[isol] += ImD[jsol]*(c[jsol]/D0[jsol]*(dkdc[jsol][isol]-kappa[jsol]/D0[jsol]*dD0dc[jsol][isol])) -(dDdc[jsol][isol]-D[jsol]*(dD0dc[jsol][isol]/D0[jsol])*(kappa[jsol]*c[jsol]/SQR(D0[jsol]))); } Gc[isol] *= R*T/phiw; } Ke = (Ki + Ke*(R*T/phiw)).inverse(); tens4d dKedE = (dyad1(Ke,I) - 2*dyad4(Ke,I))*2 - ddot(dyad2(Ke,Ke),G); for (isol=0; isol<nsol; ++isol) dKedc[isol] = -(Ke*(-Ki*dKdc[isol]*Ki + Gc[isol])*Ke).sym(); // calculate all the matrices vec3d vtmp,gp,qpu; vector<vec3d> gc(nsol),wc(nsol),jce(nsol); vector< vector<vec3d> > jc(nsol, vector<vec3d>(nsol)); mat3d wu, jue; vector<mat3d> ju(nsol); vector< vector<double> > dchatdc(nsol, vector<double>(nsol)); double sum; mat3ds De; for (i=0; i<neln; ++i) { for (j=0; j<neln; ++j) { // Kuu matrix mat3d Kuu = (mat3dd(gradN[i]*(s*gradN[j])) + vdotTdotv(gradN[i], C, gradN[j]))*detJ; ke[ndpn*i ][ndpn*j ] += Kuu[0][0]; ke[ndpn*i ][ndpn*j+1] += Kuu[0][1]; ke[ndpn*i ][ndpn*j+2] += Kuu[0][2]; ke[ndpn*i+1][ndpn*j ] += Kuu[1][0]; ke[ndpn*i+1][ndpn*j+1] += Kuu[1][1]; ke[ndpn*i+1][ndpn*j+2] += Kuu[1][2]; ke[ndpn*i+2][ndpn*j ] += Kuu[2][0]; ke[ndpn*i+2][ndpn*j+1] += Kuu[2][1]; ke[ndpn*i+2][ndpn*j+2] += Kuu[2][2]; // calculate the kpu matrix gp = vec3d(0,0,0); for (isol=0; isol<nsol; ++isol) gp += (D[isol]*gradc[isol])*(kappa[isol]/D0[isol]); gp = gradp+gp*(R*T); wu = vdotTdotv(-gp, dKedE, gradN[j]); for (isol=0; isol<nsol; ++isol) { wu += (((Ke*(D[isol]*gradc[isol])) & gradN[j])*(J*dkdJ[isol] - kappa[isol]) +Ke*(2*kappa[isol]*(gradN[j]*(D[isol]*gradc[isol]))))*(-R*T/D0[isol]) + (Ke*vdotTdotv(gradc[isol], dDdE[isol], gradN[j]))*(-kappa[isol]*R*T/D0[isol]); } qpu = Phie*gradN[j]; vtmp = (wu.transpose()*gradN[i] + qpu*H[i])*(detJ*dt); ke[ndpn*i+3][ndpn*j ] += vtmp.x; ke[ndpn*i+3][ndpn*j+1] += vtmp.y; ke[ndpn*i+3][ndpn*j+2] += vtmp.z; // calculate the kup matrix vtmp = -gradN[i]*H[j]*detJ; ke[ndpn*i ][ndpn*j+3] += vtmp.x; ke[ndpn*i+1][ndpn*j+3] += vtmp.y; ke[ndpn*i+2][ndpn*j+3] += vtmp.z; // calculate the kpp matrix ke[ndpn*i+3][ndpn*j+3] += (H[i]*H[j]*Phip - gradN[i]*(Ke*gradN[j]))*(detJ*dt); // calculate kcu matrix data jue.zero(); De.zero(); for (isol=0; isol<nsol; ++isol) { gc[isol] = -gradc[isol]*phiw + w*c[isol]/D0[isol]; ju[isol] = ((D[isol]*gc[isol]) & gradN[j])*(J*dkdJ[isol]) + vdotTdotv(gc[isol], dDdE[isol], gradN[j])*kappa[isol] + (((D[isol]*gradc[isol]) & gradN[j])*(-phis) +(D[isol]*((gradN[j]*w)*2) - ((D[isol]*w) & gradN[j]))*c[isol]/D0[isol] )*kappa[isol] +D[isol]*wu*(kappa[isol]*c[isol]/D0[isol]); jue += ju[isol]*z[isol]; De += D[isol]*(z[isol]*kappa[isol]*c[isol]/D0[isol]); } for (isol=0; isol<nsol; ++isol) { // calculate the kcu matrix vtmp = ((ju[isol]+jue*penalty).transpose()*gradN[i])*(detJ*dt); ke[ndpn*i+4+isol][ndpn*j ] += vtmp.x; ke[ndpn*i+4+isol][ndpn*j+1] += vtmp.y; ke[ndpn*i+4+isol][ndpn*j+2] += vtmp.z; // calculate the kcp matrix ke[ndpn*i+4+isol][ndpn*j+3] -= (gradN[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradN[j]) ))*(detJ*dt); // calculate the kuc matrix sum = 0; for (jsol=0; jsol<nsol; ++jsol) sum += c[jsol]*(dodc[isol]*kappa[jsol]+osmc*dkdc[jsol][isol]); vtmp = (dTdc[isol]*gradN[i] - gradN[i]*(R*T*(osmc*kappa[isol]+sum)))*H[j]*detJ; ke[ndpn*i ][ndpn*j+4+isol] += vtmp.x; ke[ndpn*i+1][ndpn*j+4+isol] += vtmp.y; ke[ndpn*i+2][ndpn*j+4+isol] += vtmp.z; // calculate the kpc matrix vtmp = vec3d(0,0,0); for (jsol=0; jsol<nsol; ++jsol) vtmp += (D[jsol]*(dkdc[jsol][isol]-kappa[jsol]/D0[jsol]*dD0dc[jsol][isol]) +dDdc[jsol][isol]*kappa[jsol])/D0[jsol]*gradc[jsol]; wc[isol] = (dKedc[isol]*gp)*(-H[j]) -Ke*((D[isol]*gradN[j])*(kappa[isol]/D0[isol])+vtmp*H[j])*(R*T); ke[ndpn*i+3][ndpn*j+4+isol] += (gradN[i]*wc[isol]+H[i]*H[j]*Phic[isol])*(detJ*dt); } // calculate data for the kcc matrix jce.assign(nsol, vec3d(0,0,0)); for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { if (jsol != isol) { jc[isol][jsol] = ((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*H[j] +(D[isol]*(w*(-H[j]*dD0dc[isol][jsol]/D0[isol])+wc[jsol]))*(kappa[isol]*c[isol]/D0[isol]); } else { jc[isol][jsol] = (D[isol]*(gradN[j]*(-phiw)+w*(H[j]/D0[isol])))*kappa[isol] +((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*H[j] +(D[isol]*(w*(-H[j]*dD0dc[isol][jsol]/D0[isol])+wc[jsol]))*(kappa[isol]*c[isol]/D0[isol]); } jce[jsol] += jc[isol][jsol]*z[isol]; // chemical reactions dchatdc[isol][jsol] = 0; for (ireact=0; ireact<nreact; ++ireact) dchatdc[isol][jsol] += m_pMat->GetReaction(ireact)->m_v[isol] *m_pMat->GetReaction(ireact)->Tangent_ReactionSupply_Concentration(mp,jsol); } } // calculate the kcc matrix for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { ke[ndpn*i+4+isol][ndpn*j+4+jsol] += (gradN[i]*(jc[isol][jsol]+jce[jsol]*penalty) + H[i]*H[j]*phiw*dchatdc[isol][jsol])*(detJ*dt); } } } } } // Enforce symmetry by averaging top-right and bottom-left corners of stiffness matrix double tmp; if (bsymm) { for (i=0; i<ndpn*neln; ++i) for (j=i+1; j<ndpn*neln; ++j) { tmp = 0.5*(ke[i][j]+ke[j][i]); ke[i][j] = ke[j][i] = tmp; } } return true; } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::Update(const FETimeInfo& tp) { FEModel& fem = *GetFEModel(); bool berr = false; int NE = (int) m_Elem.size(); double dt = fem.GetTime().timeIncrement; #pragma omp parallel for shared(NE, berr) for (int i=0; i<NE; ++i) { try { UpdateElementStress(i, dt); } catch (NegativeJacobian e) { #pragma omp critical { berr = true; if (e.DoOutput()) feLogError(e.what()); } } } if (berr) throw NegativeJacobianDetected(); } //----------------------------------------------------------------------------- void FEMultiphasicSolidDomain::UpdateElementStress(int iel, double dt) { int j, k, n; int nint, neln; double* gw; vec3d r0[FEElement::MAX_NODES]; vec3d rt[FEElement::MAX_NODES]; double pn[FEElement::MAX_NODES]; FEMesh& mesh = *m_pMesh; // get the multiphasic material FEMultiphasic* pmb = m_pMat; const int nsol = (int)pmb->Solutes(); vector< vector<double> > ct(nsol, vector<double>(FEElement::MAX_NODES)); vector<int> sid(nsol); for (j=0; j<nsol; ++j) sid[j] = pmb->GetSolute(j)->GetSoluteDOF(); // get the solid element FESolidElement& el = m_Elem[iel]; // get the number of integration points nint = el.GaussPoints(); // get the number of nodes neln = el.Nodes(); // get the integration weights gw = el.GaussWeights(); // get the nodal data for (j=0; j<neln; ++j) { FENode& node = mesh.Node(el.m_node[j]); r0[j] = node.m_r0; rt[j] = node.m_rt; if (el.m_bitfc.size()>0 && el.m_bitfc[j]) { pn[j] = (node.m_ID[m_dofQ] != -1) ? node.get(m_dofQ) : node.get(m_dofP); for (k=0; k<nsol; ++k) ct[k][j] = (node.m_ID[m_dofD + sid[k]] != -1) ? node.get(m_dofD + sid[k]) : node.get(m_dofC + sid[k]); } else { pn[j] = node.get(m_dofP); for (k=0; k<nsol; ++k) ct[k][j] = node.get(m_dofC + sid[k]); } } // loop over the integration points and calculate // the stress at the integration point for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); // material point coordinates // TODO: I'm not entirly happy with this solution // since the material point coordinates are used by most materials. mp.m_r0 = el.Evaluate(r0, n); mp.m_rt = el.Evaluate(rt, n); // get the deformation gradient and determinant pt.m_J = defgrad(el, pt.m_F, n); mat3d Fp; defgradp(el, Fp, n); mat3d Fi = pt.m_F.inverse(); pt.m_L = (pt.m_F - Fp)*Fi / dt; // multiphasic material point data FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // update SBM referential densities pmb->UpdateSolidBoundMolecules(mp); // evaluate referential solid volume fraction ppt.m_phi0t = pmb->SolidReferentialVolumeFraction(mp); if (m_breset) ppt.m_phi0 = ppt.m_phi0t; // evaluate fluid pressure at gauss-point ppt.m_p = el.Evaluate(pn, n); // calculate the gradient of p at gauss-point ppt.m_gradp = gradient(el, pn, n); for (k=0; k<nsol; ++k) { // evaluate effective solute concentrations at gauss-point spt.m_c[k] = el.Evaluate(&ct[k][0], n); // calculate the gradient of c at gauss-point spt.m_gradc[k] = gradient(el, &ct[k][0], n); } // update the fluid and solute fluxes // and evaluate the actual fluid pressure and solute concentration ppt.m_w = pmb->FluidFlux(mp); spt.m_psi = pmb->ElectricPotential(mp); for (k=0; k<nsol; ++k) { spt.m_ca[k] = pmb->Concentration(mp,k); spt.m_j[k] = pmb->SoluteFlux(mp,k); } spt.m_cF = pmb->FixedChargeDensity(mp); ppt.m_pa = pmb->Pressure(mp); spt.m_Ie = pmb->CurrentDensity(mp); pmb->PartitionCoefficientFunctions(mp, spt.m_k, spt.m_dkdJ, spt.m_dkdc, spt.m_dkdr, spt.m_dkdJr, spt.m_dkdrc); // update specialized material points m_pMat->UpdateSpecializedMaterialPoints(mp, GetFEModel()->GetTime()); // calculate the solid stress at this material point ppt.m_ss = pmb->GetElasticMaterial()->Stress(mp); // evaluate the stress pt.m_s = pmb->Stress(mp); // evaluate the referential solid density spt.m_rhor = pmb->SolidReferentialApparentDensity(mp); // update chemical reaction element data for (int j=0; j<m_pMat->Reactions(); ++j) pmb->GetReaction(j)->UpdateElementData(mp); } if (m_breset) m_breset = false; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESoluteFlux.h
.h
2,453
75
/*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> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! The flux surface is a surface domain that sustains a solute flux boundary //! condition //! class FEBIOMIX_API FESoluteFlux : public FESurfaceLoad { public: //! constructor FESoluteFlux(FEModel* pfem); //! Initialization bool Init() override; //! serialization void Serialize(DumpStream& ar) override; //! Set the surface to apply the load to void SetSurface(FESurface* ps) override; void SetLinear(bool blinear) { m_blinear = blinear; } void SetSolute(int isol) { m_isol = isol; } //! calculate flux stiffness void StiffnessMatrix(FELinearSystem& LS) override; //! calculate residual void LoadVector(FEGlobalVector& R) override; protected: FEParamDouble m_flux; //!< flux scale factor magnitude bool m_blinear; //!< linear or not (true is non-follower, false is follower) bool m_bshellb; //!< flag for prescribing flux on shell bottom int m_isol; //!< solute index protected: FEDofList m_dofC; FEDofList m_dofU; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPermConstIso.h
.h
1,889
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 "FEBiphasic.h" //----------------------------------------------------------------------------- // This class implements a poroelastic material that has a constant permeability class FEBIOMIX_API FEPermConstIso : public FEHydraulicPermeability { public: //! constructor FEPermConstIso(FEModel* pfem); //! permeability mat3ds Permeability(FEMaterialPoint& pt) override; //! Tangent of permeability tens4dmm Tangent_Permeability_Strain(FEMaterialPoint& mp) override; public: FEParamDouble m_perm; //!< permeability // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMembraneMassActionForward.h
.h
2,546
58
/*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 "FEMembraneReaction.h" //----------------------------------------------------------------------------- //! Law of mass action for forward membrane reaction (must use effective concentrations) class FEBIOMIX_API FEMembraneMassActionForward : public FEMembraneReaction { public: //! constructor FEMembraneMassActionForward(FEModel* pfem); //! molar supply at material point double ReactionSupply(FEMaterialPoint& pt) override; //! tangent of molar supply with strain at material point double Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) override; //! tangent of molar supply with effective pressure at material point double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) override; double Tangent_ReactionSupply_Pi(FEMaterialPoint& pt) override; double Tangent_ReactionSupply_Pe(FEMaterialPoint& pt) override; //! tangent of molar supply with effective concentration at material point double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) override; double Tangent_ReactionSupply_Ci(FEMaterialPoint& pt, const int sol) override; double Tangent_ReactionSupply_Ce(FEMaterialPoint& pt, const int sol) override; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMassActionReversibleEffective.h
.h
2,453
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 "FEChemicalReaction.h" //----------------------------------------------------------------------------- //! Law of mass action for reversible chemical reaction //! using effective concentrations. class FEBIOMIX_API FEMassActionReversibleEffective : public FEChemicalReaction { public: //! constructor FEMassActionReversibleEffective(FEModel* pfem); //! molar supply at material point double ReactionSupply(FEMaterialPoint& pt) override; //! tangent of molar supply with strain (J) at material point mat3ds Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) override; //! tangent of molar supply with effective pressure at material point double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) override; //! tangent of molar supply with effective concentration at material point double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) override; //! molar supply at material point double FwdReactionSupply(FEMaterialPoint& pt); //! molar supply at material point double RevReactionSupply(FEMaterialPoint& pt); DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicSolver.h
.h
5,026
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) 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 <FEBioMech/FERigidSolver.h> #include <FECore/FEDofList.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- // This class adds additional functionality to the FESolidSolver2 to solve // solute problems. class FEBIOMIX_API FEMultiphasicSolver : public FENewtonSolver { public: //! con/descructor FEMultiphasicSolver(FEModel* pfem); virtual ~FEMultiphasicSolver(){} //! Initialize data structures bool Init() override; //! Initialize equations bool InitEquations() override; //! prepares the data for the first QN iteration void PrepStep() override; //! Performs a Newton-Raphson iteration bool Quasin() override; //! serialize data to/from dump file void Serialize(DumpStream& ar) override; //! Generate warnings if needed void SolverWarnings(); //! preferred matrix type should be unsymmetric. Matrix_Type PreferredMatrixType() const override { return REAL_UNSYMMETRIC; }; public: void Update(vector<double>& ui) override; //! update contact void UpdateModel() override; //! Update EAS void UpdateEAS(vector<double>& ui); void UpdateIncrementsEAS(vector<double>& ui, const bool binc); //! update kinematics virtual void UpdateKinematics(vector<double>& ui); //! Update poroelastic data void UpdatePoro(vector<double>& ui); //! Update solute data void UpdateSolute(vector<double>& ui); public: //! Calculates residual (overridden from FESolidSolver2) bool Residual(vector<double>& R) override; //! calculates the global stiffness matrix (overridden from FESolidSolver2) bool StiffnessMatrix() override; void ContactForces(FEGlobalVector& R); void ContactStiffness(FELinearSystem& LS); void NonLinearConstraintForces(FEGlobalVector& R, const FETimeInfo& tp); void NonLinearConstraintStiffness(FELinearSystem& LS, const FETimeInfo& tp); protected: void GetDisplacementData(vector<double>& di, vector<double>& ui); void GetPressureData(vector<double>& pi, vector<double>& ui); void GetConcentrationData(vector<double>& ci, vector<double>& ui, const int sol); public: // Parameters double m_Dtol; //!< displacement tolerance double m_Ctol; //!< concentration tolerance double m_Ptol; //!< pressure tolerance bool m_forcePositive; //!< force conentrations to remain positive public: // equation numbers int m_ndeq; //!< number of equations related to displacement dofs int m_npeq; //!< number of equations related to pressure dofs int m_nreq; //!< start of rigid body equations vector<int> m_nceq; //!< number of equations related to concentration dofs vector<double> m_Fr; //!< nodal reaction forces vector<double> m_Uip; //!< previous converged displacement increment // poro data vector<double> m_di; //!< displacement increment vector vector<double> m_Di; //!< total displacement vector for iteration vector<double> m_pi; //!< pressure increment vector vector<double> m_Pi; //!< Total pressure vector for iteration // solute data vector< vector<double> > m_ci; //!< concentration increment vector vector< vector<double> > m_Ci; //!< Total concentration vector for iteration protected: FEDofList m_dofU, m_dofV; FEDofList m_dofRQ; FEDofList m_dofSU, m_dofSV, m_dofSA; int m_dofP; //!< pressure dof index int m_dofSP; //!< shell pressure dof index int m_dofC; //!< concentration dof index int m_dofSC; //!< shell concentration dof FERigidSolverNew m_rigidSolver; protected: // obsolete parameters double m_rhoi = -2; double m_alpha = 1; double m_beta = 0.25; double m_gamma = 0.5; bool m_logSolve = false; int m_arcLength = 0; double m_al_scale = 0; // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicDomain.h
.h
2,888
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 <vector> #include <FEBioMech/FEElasticDomain.h> #include "FEBiphasic.h" //----------------------------------------------------------------------------- class FEModel; class FEGlobalVector; class FEBodyForce; class FESolver; //----------------------------------------------------------------------------- //! Abstract interface class for biphasic domains. //! A biphasic domain is used by the biphasic solver. //! This interface defines the functions that have to be implemented by a //! biphasic domain. There are basically two categories: residual functions //! that contribute to the global residual vector. And stiffness matrix //! function that calculate contributions to the global stiffness matrix. class FEBIOMIX_API FEBiphasicDomain : public FEElasticDomain { public: FEBiphasicDomain(FEModel* pfem); // --- R E S I D U A L --- //! internal work for steady-state case virtual void InternalForcesSS(FEGlobalVector& R) = 0; // --- S T I F F N E S S M A T R I X --- //! calculates the global stiffness matrix for this domain virtual void StiffnessMatrix(FELinearSystem& LS, bool bsymm) = 0; //! calculates the global stiffness matrix (steady-state case) virtual void StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) = 0; public: // biphasic domain "properties" virtual vec3d FluidFlux(FEMaterialPoint& mp) = 0; protected: FEBiphasic* m_pMat; int m_dofP; //!< pressure dof index int m_dofQ; //!< shell extra pressure dof index int m_dofVX; int m_dofVY; int m_dofVZ; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMichaelisMenten.h
.h
2,790
71
/*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 "FEChemicalReaction.h" //----------------------------------------------------------------------------- //! Forward chemical reaction following Michaelis-Menten kinetics. //! The maximum uptake rate is given by the forward reaction rate //! which is defined in the parent class FEChemicalReaction. //! Optionally, a minimum concentration may be prescribed for the //! reactant to trigger the reaction. class FEBIOMIX_API FEMichaelisMenten : public FEChemicalReaction { public: //! constructor FEMichaelisMenten(FEModel* pfem); //! data initialization and checking bool Init() override; //! molar supply at material point double ReactionSupply(FEMaterialPoint& pt) override; //! tangent of molar supply with strain at material point mat3ds Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) override; //! tangent of molar supply with effective pressure at material point double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) override; //! tangent of molar supply with effective concentration at material point double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) override; public: double m_Km; //!< concentration at which half-maximum rate occurs int m_Rid; //!< local id of reactant int m_Pid; //!< local id of product bool m_Rtype; //!< flag for reactant type (solute = false, sbm = true) double m_c0; //!< minimum reactant concentration to trigger reaction // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPermRefOrtho.h
.h
2,493
65
/*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 "FEBiphasic.h" //----------------------------------------------------------------------------- // This class implements a poroelastic material that has a strain-dependent // permeability which is orthotropic in the reference state, but exhibits // further strain-induced anisotropy, according to the constitutive relation // of Ateshian and Weiss (JBME 2010) class FEBIOMIX_API FEPermRefOrtho : public FEHydraulicPermeability { public: //! constructor FEPermRefOrtho(FEModel* pfem); //! permeability mat3ds Permeability(FEMaterialPoint& pt) override; //! Tangent of permeability tens4dmm Tangent_Permeability_Strain(FEMaterialPoint& mp) override; private: void reportError(double J, double phisr); public: FEParamDouble m_perm0; //!< permeability for I term FEParamDouble m_perm1[3]; //!< permeability for b term FEParamDouble m_perm2[3]; //!< permeability for b^2 term FEParamDouble m_M0; //!< nonlinear exponential coefficient FEParamDouble m_alpha0; //!< nonlinear power exponent FEParamDouble m_M[3]; //!< nonlinear exponential coefficient FEParamDouble m_alpha[3]; //!< nonlinear power exponent // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEChemicalReaction.h
.h
5,474
140
/*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 "FEReaction.h" #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Base class for reaction rates. class FEBIOMIX_API FEReactionRate : public FEMaterialProperty { public: //! constructor FEReactionRate(FEModel* pfem) : FEMaterialProperty(pfem), m_pReact(nullptr) {} //! reaction rate at material point virtual double ReactionRate(FEMaterialPoint& pt) = 0; //! tangent of reaction rate with strain at material point virtual mat3ds Tangent_ReactionRate_Strain(FEMaterialPoint& pt) = 0; //! tangent of reaction rate with effective fluid pressure at material point virtual double Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) = 0; //! reset, initialize and update chemical reaction data in the FESolutesMaterialPoint virtual void ResetElementData(FEMaterialPoint& mp) {} virtual void InitializeElementData(FEMaterialPoint& mp) {} virtual void UpdateElementData(FEMaterialPoint& mp) {} public: FEReaction* m_pReact; //!< pointer to parent reaction FECORE_BASE_CLASS(FEReactionRate) }; //----------------------------------------------------------------------------- //! Base class for chemical reactions. class FEBIOMIX_API FEChemicalReaction : public FEReaction { public: //! constructor FEChemicalReaction(FEModel* pfem); //! initialization bool Init() override; public: //! set the forward reaction rate void SetForwardReactionRate(FEReactionRate* pfwd) { m_pFwd = pfwd; } //! set the reverse reaction rate void SetReverseReactionRate(FEReactionRate* prev) { m_pRev = prev; } public: //! reset, initialize and update optional chemical reaction data in the FESolutesMaterialPoint void ResetElementData(FEMaterialPoint& mp) { if (m_pFwd) m_pFwd->ResetElementData(mp); if (m_pRev) m_pRev->ResetElementData(mp); } void InitializeElementData(FEMaterialPoint& mp) { if (m_pFwd) m_pFwd->InitializeElementData(mp); if (m_pRev) m_pRev->InitializeElementData(mp); } void UpdateElementData(FEMaterialPoint& mp) { if (m_pFwd) m_pFwd->UpdateElementData(mp); if (m_pRev) m_pRev->UpdateElementData(mp); } public: //! molar supply at material point virtual double ReactionSupply(FEMaterialPoint& pt) = 0; //! tangent of molar supply with strain at material point virtual mat3ds Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) = 0; //! tangent of molar supply with effective pressure at material point virtual double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) = 0; //! tangent of molar supply with effective concentration at material point virtual double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) = 0; public: //! Serialization void Serialize(DumpStream& ar) override; public: vector<FEReactantSpeciesRef*> m_vRtmp; //!< helper variable for reading in stoichiometric coefficients for reactants vector<FEProductSpeciesRef*> m_vPtmp; //!< helper variable for reading in stoichiometric coefficients for products FEReactionRate* m_pFwd; //!< pointer to forward reaction rate FEReactionRate* m_pRev; //!< pointer to reverse reaction rate public: intmap m_solR; //!< stoichiometric coefficients of solute reactants (input) intmap m_solP; //!< stoichiometric coefficients of solute products (input) intmap m_sbmR; //!< stoichiometric coefficients of solid-bound reactants (input) intmap m_sbmP; //!< stoichiometric coefficients of solid-bound products (input) public: int m_nsol; //!< number of solutes in the mixture vector<int> m_vR; //!< stoichiometric coefficients of reactants vector<int> m_vP; //!< stoichiometric coefficients of products vector<int> m_v; //!< net stoichiometric coefficients of reactants and products double m_Vbar; //!< weighted molar volume of reactants and products bool m_Vovr; //!< override flag for m_Vbar DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEChemicalReaction) };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEConcentrationIndependentReaction.cpp
.cpp
4,022
114
/*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 "FEConcentrationIndependentReaction.h" BEGIN_FECORE_CLASS(FEConcentrationIndependentReaction, FEChemicalReaction) // set material properties ADD_PROPERTY(m_pFwd, "forward_rate", FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEConcentrationIndependentReaction::FEConcentrationIndependentReaction(FEModel* pfem) : FEChemicalReaction(pfem) { } //----------------------------------------------------------------------------- //! molar supply at material point double FEConcentrationIndependentReaction::ReactionSupply(FEMaterialPoint& pt) { FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // get reaction rate double kF = m_pFwd->ReactionRate(pt); // evaluate the reaction molar supply double zhat = kF; // contribution of solid-bound molecules const int nsol = (int)spt.m_ca.size(); const int nsbm = (int)spt.m_sbmr.size(); for (int i=0; i<nsbm; ++i) { int vR = m_vR[nsol+i]; if (vR > 0) { double c = m_psm->SBMConcentration(pt, i); zhat *= pow(c, vR); } } return zhat; } //----------------------------------------------------------------------------- //! tangent of molar supply with strain at material point mat3ds FEConcentrationIndependentReaction::Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) { FEElasticMaterialPoint& ept = *pt.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& bpt = *pt.ExtractData<FEBiphasicMaterialPoint>(); const int nsol = m_nsol; const int nsbm = (int)m_v.size() - nsol; double J = ept.m_J; double phi0 = bpt.m_phi0t; double kF = m_pFwd->ReactionRate(pt); mat3ds dkFde = m_pFwd->Tangent_ReactionRate_Strain(pt); double zhat = ReactionSupply(pt); mat3ds dzhatde = mat3dd(0); if (kF > 0) { dzhatde += dkFde/kF; } mat3ds I = mat3dd(1); for (int isbm = 0; isbm<nsbm; ++isbm) dzhatde -= I*(m_vR[nsol+isbm]/(J-phi0)); dzhatde *= zhat; return dzhatde; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective pressure at material point double FEConcentrationIndependentReaction::Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) { double kF = m_pFwd->ReactionRate(pt); double dkFdp = m_pFwd->Tangent_ReactionRate_Pressure(pt); double zhat = ReactionSupply(pt); double dzhatdp = 0; if (kF > 0) { dzhatdp = dkFdp*zhat/kF; } return dzhatdp; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective concentration at material point double FEConcentrationIndependentReaction::Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FETiedMultiphasicInterface.cpp
.cpp
61,772
1,664
/*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 "FETiedMultiphasicInterface.h" #include "FEBiphasic.h" #include "FEBiphasicSolute.h" #include "FETriphasic.h" #include "FEMultiphasic.h" #include "FECore/FEModel.h" #include "FECore/FEAnalysis.h" #include "FECore/FENormalProjection.h" #include <FECore/FELinearSystem.h> #include "FECore/log.h" //----------------------------------------------------------------------------- // Define sliding interface parameters BEGIN_FECORE_CLASS(FETiedMultiphasicInterface, FEContactInterface) ADD_PARAMETER(m_laugon , "laugon" )->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0"); ADD_PARAMETER(m_atol , "tolerance" ); ADD_PARAMETER(m_gtol , "gaptol" ); ADD_PARAMETER(m_ptol , "ptol" ); ADD_PARAMETER(m_ctol , "ctol" ); ADD_PARAMETER(m_epsn , "penalty" ); ADD_PARAMETER(m_bautopen , "auto_penalty" ); ADD_PARAMETER(m_bupdtpen , "update_penalty" ); ADD_PARAMETER(m_btwo_pass, "two_pass" ); ADD_PARAMETER(m_knmult , "knmult" ); ADD_PARAMETER(m_stol , "search_tol" ); ADD_PARAMETER(m_epsp , "pressure_penalty" ); ADD_PARAMETER(m_epsc , "concentration_penalty"); ADD_PARAMETER(m_bsymm , "symmetric_stiffness"); ADD_PARAMETER(m_srad , "search_radius" ); ADD_PARAMETER(m_naugmin , "minaug" ); ADD_PARAMETER(m_naugmax , "maxaug" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- void FETiedMultiphasicContactPoint::Serialize(DumpStream& ar) { FETiedBiphasicContactPoint::Serialize(ar); ar & m_Lmc; ar & m_epsc; ar & m_cg; } //----------------------------------------------------------------------------- // FETiedMultiphasicSurface //----------------------------------------------------------------------------- FETiedMultiphasicSurface::FETiedMultiphasicSurface(FEModel* pfem) : FEBiphasicContactSurface(pfem) { m_bporo = m_bsolu = false; m_dofC = -1; } //----------------------------------------------------------------------------- //! create material point data FEMaterialPoint* FETiedMultiphasicSurface::CreateMaterialPoint() { return new FETiedMultiphasicContactPoint; } //----------------------------------------------------------------------------- void FETiedMultiphasicSurface::UnpackLM(FEElement& el, vector<int>& lm) { // get nodal DOFS DOFS& dofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = dofs.GetVariableSize("concentration"); int N = el.Nodes(); lm.resize(N*(4+MAX_CDOFS)); // pack the equation numbers for (int i=0; i<N; ++i) { int n = el.m_node[i]; FENode& node = m_pMesh->Node(n); vector<int>& id = node.m_ID; // first the displacement dofs lm[3*i ] = id[m_dofX]; lm[3*i+1] = id[m_dofY]; lm[3*i+2] = id[m_dofZ]; // now the pressure dofs lm[3*N+i] = id[m_dofP]; // concentration dofs for (int k=0; k<MAX_CDOFS; ++k) lm[(4 + k)*N + i] = id[m_dofC+k]; } } //----------------------------------------------------------------------------- bool FETiedMultiphasicSurface::Init() { // initialize surface data first if (FEBiphasicContactSurface::Init() == false) return false; // store concentration index DOFS& dofs = GetFEModel()->GetDOFS(); m_dofC = dofs.GetDOF("concentration", 0); if (m_dofC < 0) return false; // allocate node normals m_nn.assign(Nodes(), vec3d(0,0,0)); // determine solutes for this surface using the first surface element // TODO: Check that all elements use the same set of solutes as the first element int nsol = 0; if (Elements()) { FESurfaceElement& se = Element(0); // get the element this surface element belongs to FEElement* pe = se.m_elem[0].pe; if (pe) { // get the material FEMaterial* pm = m_pfem->GetMaterial(pe->GetMatID()); // check type of element FEBiphasic* pb = dynamic_cast<FEBiphasic*> (pm); FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (pm); FETriphasic* pt = dynamic_cast<FETriphasic*>(pm); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*> (pm); if (pb) { m_bporo = true; nsol = 0; } else if (pbs) { m_bporo = m_bsolu = true; nsol = 1; m_sid.assign(nsol, pbs->GetSolute()->GetSoluteID() - 1); } else if (pt) { m_bporo = m_bsolu = true; nsol = 2; m_sid.resize(nsol); m_sid[0] = pt->m_pSolute[0]->GetSoluteID() - 1; m_sid[1] = pt->m_pSolute[1]->GetSoluteID() - 1; } else if (pmp) { m_bporo = m_bsolu = true; nsol = pmp->Solutes(); m_sid.resize(nsol); for (int isol=0; isol<nsol; ++isol) { m_sid[isol] = pmp->GetSolute(isol)->GetSoluteID() - 1; } } } } // allocate data structures int NE = Elements(); m_poro.resize(NE,false); for (int i=0; i<NE; ++i) { FESurfaceElement& el = Element(i); // get the element this surface element belongs to FEElement* pe = el.m_elem[0].pe; if (pe) { // get the material FEMaterial* pm = m_pfem->GetMaterial(pe->GetMatID()); // see if this is a poro-elastic element FEBiphasic* bp = dynamic_cast<FEBiphasic*> (pm); FEBiphasicSolute* bs = dynamic_cast<FEBiphasicSolute*> (pm); FETriphasic* tp = dynamic_cast<FETriphasic*> (pm); FEMultiphasic* mp = dynamic_cast<FEMultiphasic*> (pm); if (bp || bs || tp || mp) { m_poro[i] = true; m_bporo = true; } if (bs || tp || mp) { m_bsolu = true; } } int nint = el.GaussPoints(); if (nsol) { for (int j=0; j<nint; ++j) { FETiedMultiphasicContactPoint& data = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); data.m_Lmc.resize(nsol); data.m_epsc.resize(nsol); data.m_cg.resize(nsol); } } } return true; } //----------------------------------------------------------------------------- //! This function calculates the node normal. Due to the piecewise continuity //! of the surface elements this normal is not uniquely defined so in order to //! obtain a unique normal the normal is averaged for each node over all the //! element normals at the node void FETiedMultiphasicSurface::UpdateNodeNormals() { int N = Nodes(), i, j, ne, jp1, jm1; vec3d y[FEElement::MAX_NODES], n; // zero nodal normals zero(m_nn); // loop over all elements for (i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); ne = el.Nodes(); // get the nodal coordinates for (j=0; j<ne; ++j) y[j] = Node(el.m_lnode[j]).m_rt; // calculate the normals for (j=0; j<ne; ++j) { jp1 = (j+1)%ne; jm1 = (j+ne-1)%ne; n = (y[jp1] - y[j]) ^ (y[jm1] - y[j]); m_nn[el.m_lnode[j]] += n; } } // normalize all vectors for (i=0; i<N; ++i) m_nn[i].unit(); } //----------------------------------------------------------------------------- void FETiedMultiphasicSurface::Serialize(DumpStream& ar) { FEBiphasicContactSurface::Serialize(ar); ar & m_dofC; ar & m_bporo; ar & m_bsolu; ar & m_poro; ar & m_nn; ar & m_sid; } //----------------------------------------------------------------------------- // FETiedMultiphasicInterface //----------------------------------------------------------------------------- FETiedMultiphasicInterface::FETiedMultiphasicInterface(FEModel* pfem) : FEContactInterface(pfem), m_ss(pfem), m_ms(pfem) { static int count = 1; SetID(count++); // initial values m_knmult = 1; m_atol = 0.1; m_epsn = 1; m_epsp = 1; m_epsc = 1; m_btwo_pass = false; m_stol = 0.01; m_bsymm = true; m_srad = 1.0; m_gtol = 0; m_ptol = 0; m_ctol = 0; m_bautopen = false; m_bupdtpen = false; m_naugmin = 0; m_naugmax = 10; m_dofP = pfem->GetDOFIndex("p"); m_dofC = pfem->GetDOFIndex("concentration", 0); // set parents m_ss.SetContactInterface(this); m_ms.SetContactInterface(this); m_ss.SetSibling(&m_ms); m_ms.SetSibling(&m_ss); } //----------------------------------------------------------------------------- FETiedMultiphasicInterface::~FETiedMultiphasicInterface() { } //----------------------------------------------------------------------------- bool FETiedMultiphasicInterface::Init() { m_Rgas = GetFEModel()->GetGlobalConstant("R"); m_Tabs = GetFEModel()->GetGlobalConstant("T"); // initialize surface data if (m_ss.Init() == false) return false; if (m_ms.Init() == false) return false; // determine which solutes are common to both contact surfaces m_sid.clear(); m_ssl.clear(); m_msl.clear(); m_sz.clear(); for (int is=0; is<m_ss.m_sid.size(); ++is) { for (int im=0; im<m_ms.m_sid.size(); ++im) { if (m_ms.m_sid[im] == m_ss.m_sid[is]) { m_sid.push_back(m_ss.m_sid[is]); m_ssl.push_back(is); m_msl.push_back(im); FESoluteData* sd = FindSoluteData(m_ss.m_sid[is] + 1); m_sz.push_back(sd->m_z); } } } return true; } //----------------------------------------------------------------------------- //! build the matrix profile for use in the stiffness matrix void FETiedMultiphasicInterface::BuildMatrixProfile(FEGlobalMatrix& K) { 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_P = fem.GetDOFIndex("p"); const int dof_C = fem.GetDOFIndex("concentration", 0); int nsol = (int)m_sid.size(); int ndpn = 7 + nsol; vector<int> lm(ndpn*FEElement::MAX_NODES*2); int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FETiedMultiphasicSurface& ss = (np == 0? m_ss : m_ms); int k, l; for (int j=0; j<ss.Elements(); ++j) { FESurfaceElement& se = ss.Element(j); int nint = se.GaussPoints(); int* sn = &se.m_node[0]; for (k=0; k<nint; ++k) { FETiedMultiphasicContactPoint& data = static_cast<FETiedMultiphasicContactPoint&>(*se.GetMaterialPoint(k)); FESurfaceElement* pe = data.m_pme; if (pe != 0) { FESurfaceElement& me = *pe; int* mn = &me.m_node[0]; assign(lm, -1); int nseln = se.Nodes(); int nmeln = me.Nodes(); for (l=0; l<nseln; ++l) { vector<int>& id = mesh.Node(sn[l]).m_ID; lm[ndpn*l ] = id[dof_X]; lm[ndpn*l+1] = id[dof_Y]; lm[ndpn*l+2] = id[dof_Z]; lm[ndpn*l+3] = id[dof_P]; for (int m=0; m<nsol; ++m) { lm[ndpn*l+4+m] = id[dof_C + m_sid[m]]; } } for (l=0; l<nmeln; ++l) { vector<int>& id = mesh.Node(mn[l]).m_ID; lm[ndpn*(l+nseln) ] = id[dof_X]; lm[ndpn*(l+nseln)+1] = id[dof_Y]; lm[ndpn*(l+nseln)+2] = id[dof_Z]; lm[ndpn*(l+nseln)+3] = id[dof_P]; for (int m=0; m<nsol; ++m) { lm[ndpn*(l+nseln)+4+m] = id[dof_C + m_sid[m]]; } } K.build_add(lm); } } } } } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::UpdateAutoPenalty() { // calculate the penalty if (m_bautopen) { CalcAutoPenalty(m_ss); CalcAutoPenalty(m_ms); if (m_ss.m_bporo) CalcAutoPressurePenalty(m_ss); for (int is=0; is<m_ssl.size(); ++is) CalcAutoConcentrationPenalty(m_ss, m_ssl[is]); if (m_ms.m_bporo) CalcAutoPressurePenalty(m_ms); for (int im=0; im<m_msl.size(); ++im) CalcAutoConcentrationPenalty(m_ms, m_msl[im]); } } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::Activate() { // don't forget to call the base class FEContactInterface::Activate(); UpdateAutoPenalty(); // project the surfaces onto each other // this will evaluate the gap functions in the reference configuration InitialProjection(m_ss, m_ms); if (m_btwo_pass) InitialProjection(m_ms, m_ss); } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::CalcAutoPenalty(FETiedMultiphasicSurface& s) { // loop over all surface elements for (int i=0; i<s.Elements(); ++i) { // get the surface element FESurfaceElement& el = s.Element(i); // calculate a penalty double eps = AutoPenalty(el, s); // assign to integation points of surface element int nint = el.GaussPoints(); for (int j=0; j<nint; ++j) { FETiedMultiphasicContactPoint& pt = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsn = eps; } } } //----------------------------------------------------------------------------- //! This function calculates a contact penalty parameter based on the //! material and geometrical properties of the primary and secondary surfaces //! double FETiedMultiphasicInterface::AutoPenalty(FESurfaceElement& el, FESurface &s) { // get the mesh FEMesh& m = GetFEModel()->GetMesh(); // get the element this surface element belongs to FEElement* pe = el.m_elem[0].pe; if (pe == 0) return 0.0; tens4ds S; // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); // extract the material FEMaterial* pme = GetFEModel()->GetMaterial(pe->GetMatID()); if (pme == 0) return 0.0; // get the tangent (stiffness) if (dynamic_cast<FEMultiphasic*>(pme)) { FEMultiphasic* pmm = dynamic_cast<FEMultiphasic*>(pme); S = pmm->Tangent(mp); } else if (dynamic_cast<FETriphasic*>(pme)) { FETriphasic* pmt = dynamic_cast<FETriphasic*>(pme); S = pmt->Tangent(mp); } else if (dynamic_cast<FEBiphasicSolute*>(pme)) { FEBiphasicSolute* pms = dynamic_cast<FEBiphasicSolute*>(pme); S = pms->Tangent(mp); } else if (dynamic_cast<FEBiphasic*>(pme)) { FEBiphasic* pmb = dynamic_cast<FEBiphasic*>(pme); S = (pmb->Tangent(mp)).supersymm(); } else if (dynamic_cast<FEElasticMaterial*>(pme)) { FEElasticMaterial* pm = dynamic_cast<FEElasticMaterial*>(pme); S = pm->Tangent(mp); } // get the inverse (compliance) at this point tens4ds C = S.inverse(); // evaluate element surface normal at parametric center vec3d t[2]; s.CoBaseVectors0(el, 0, 0, t); vec3d n = t[0] ^ t[1]; n.unit(); // evaluate normal component of the compliance matrix // (equivalent to inverse of Young's modulus along n) double eps = 1./(n*(vdotTdotv(n, C, n)*n)); // get the area of the surface element double A = s.FaceArea(el); // get the volume of the volume element double V = m.ElementVolume(*pe); return eps*A/V; } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::CalcAutoPressurePenalty(FETiedMultiphasicSurface& s) { // loop over all surface elements for (int i=0; i<s.Elements(); ++i) { // get the surface element FESurfaceElement& el = s.Element(i); // calculate a penalty double eps = AutoPressurePenalty(el, s); // assign to integation points of surface element int nint = el.GaussPoints(); for (int j=0; j<nint; ++j) { FETiedMultiphasicContactPoint& pt = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsp = eps; } } } //----------------------------------------------------------------------------- double FETiedMultiphasicInterface::AutoPressurePenalty(FESurfaceElement& el, FETiedMultiphasicSurface& s) { // get the mesh FEMesh& m = GetFEModel()->GetMesh(); // evaluate element surface normal at parametric center vec3d t[2]; s.CoBaseVectors0(el, 0, 0, t); vec3d n = t[0] ^ t[1]; n.unit(); // get the element this surface element belongs to FEElement* pe = el.m_elem[0].pe; if (pe == 0) return 0.0; // get the material FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); mat3ds K; // check type of element FEBiphasic* pb = dynamic_cast<FEBiphasic*> (pm); FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (pm); FETriphasic* ptp = dynamic_cast<FETriphasic*> (pm); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*> (pm); if (pb) { double k[3][3]; pb->Permeability(k, mp); K = mat3ds(k[0][0], k[1][1], k[2][2], k[0][1], k[1][2], k[0][2]); } else if (ptp) K = ptp->GetPermeability()->Permeability(mp); else if (pbs) K = pbs->GetPermeability()->Permeability(mp); else if (pmp) K = pmp->GetPermeability()->Permeability(mp); double eps = n*(K*n); // get the area of the surface element double A = s.FaceArea(el); // get the volume of the volume element double V = m.ElementVolume(*pe); return eps*A/V; } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::CalcAutoConcentrationPenalty(FETiedMultiphasicSurface& s, const int isol) { // loop over all surface elements int ni = 0; for (int i=0; i<s.Elements(); ++i) { // get the surface element FESurfaceElement& el = s.Element(i); // calculate a penalty double eps = AutoConcentrationPenalty(el, s, isol); // assign to integation points of surface element int nint = el.GaussPoints(); for (int j=0; j<nint; ++j, ++ni) { FETiedMultiphasicContactPoint& pt = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsc[isol] = eps; } } } //----------------------------------------------------------------------------- double FETiedMultiphasicInterface::AutoConcentrationPenalty(FESurfaceElement& el, FETiedMultiphasicSurface& s, const int isol) { // get the mesh FEMesh& m = GetFEModel()->GetMesh(); // evaluate element surface normal at parametric center vec3d t[2]; s.CoBaseVectors0(el, 0, 0, t); vec3d n = t[0] ^ t[1]; n.unit(); // get the element this surface element belongs to FEElement* pe = el.m_elem[0].pe; if (pe == 0) return 0.0; // get the material FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); mat3ds D; // see if this is a biphasic-solute or multiphasic element FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (pm); FETriphasic* ptp = dynamic_cast<FETriphasic*> (pm); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*> (pm); if (pbs) { D = pbs->GetSolute()->m_pDiff->Diffusivity(mp) *(pbs->Porosity(mp)*pbs->GetSolute()->m_pSolub->Solubility(mp)); } else if (ptp) { D = ptp->GetSolute(isol)->m_pDiff->Diffusivity(mp) *(ptp->Porosity(mp)*ptp->GetSolute(isol)->m_pSolub->Solubility(mp)); } else if (pmp) { D = pmp->GetSolute(isol)->m_pDiff->Diffusivity(mp) *(pmp->Porosity(mp)*pmp->GetSolute(isol)->m_pSolub->Solubility(mp)); } // evaluate normal component of diffusivity double eps = n*(D*n); // get the area of the surface element double A = s.FaceArea(el); // get the volume of the volume element double V = m.ElementVolume(*pe); return eps*A/V; } //----------------------------------------------------------------------------- // Perform initial projection between tied surfaces in reference configuration void FETiedMultiphasicInterface::InitialProjection(FETiedMultiphasicSurface& ss, FETiedMultiphasicSurface& ms) { FESurfaceElement* pme; vec3d r, nu; double rs[2]; // initialize projection data FENormalProjection np(ms); np.SetTolerance(m_stol); np.SetSearchRadius(m_srad); np.Init(); // loop over all integration points int n = 0; for (int i=0; i<ss.Elements(); ++i) { FESurfaceElement& el = ss.Element(i); int nint = el.GaussPoints(); for (int j=0; j<nint; ++j, ++n) { // calculate the global position of the integration point r = ss.Local2Global(el, j); // calculate the normal at this integration point nu = ss.SurfaceNormal(el, j); // find the intersection point with the secondary surface pme = np.Project2(r, nu, rs); FETiedMultiphasicContactPoint& pt = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_pme = pme; pt.m_rs[0] = rs[0]; pt.m_rs[1] = rs[1]; if (pme) { // the node could potentially be in contact // find the global location of the intersection point vec3d q = ms.Local2Global(*pme, rs[0], rs[1]); // calculate the gap function pt.m_Gap = q - r; } else { // the node is not in contact pt.m_Gap = vec3d(0,0,0); } } } } //----------------------------------------------------------------------------- // Evaluate gap functions for position and fluid pressure void FETiedMultiphasicInterface::ProjectSurface(FETiedMultiphasicSurface& ss, FETiedMultiphasicSurface& ms) { FEMesh& mesh = GetFEModel()->GetMesh(); FESurfaceElement* pme; vec3d r; const int MN = FEElement::MAX_NODES; double ps[MN], p1; int nsol = (int)m_sid.size(); vector< vector<double> > cs(nsol, vector<double>(MN)); vector<double> c1(nsol); // loop over all integration points for (int i=0; i<ss.Elements(); ++i) { FESurfaceElement& el = ss.Element(i); bool sporo = ss.m_poro[i]; int ne = el.Nodes(); int nint = el.GaussPoints(); // get the nodal pressures p1 = 0; if (sporo) { for (int j=0; j<ne; ++j) ps[j] = mesh.Node(el.m_node[j]).get(m_dofP); } // get the nodal concentrations for (int isol=0; isol<nsol; ++isol) { for (int j=0; j<ne; ++j) cs[isol][j] = mesh.Node(el.m_node[j]).get(m_dofC + m_sid[isol]); } for (int j=0; j<nint; ++j) { FETiedMultiphasicContactPoint& pt = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); // calculate the global position of the integration point r = ss.Local2Global(el, j); // get the pressure at the integration point if (sporo) p1 = el.eval(ps, j); // get the concentration at the integration point for (int isol=0; isol<nsol; ++isol) c1[isol] = el.eval(&cs[isol][0], j); // calculate the normal at this integration point pt.m_nu = ss.SurfaceNormal(el, j); // if this node is tied, evaluate gap functions pme = pt.m_pme; if (pme) { // find the global location of the intersection point vec3d q = ms.Local2Global(*pme, pt.m_rs[0], pt.m_rs[1]); // calculate the gap function vec3d g = q - r; pt.m_dg = g - pt.m_Gap; // calculate the pressure gap function bool mporo = ms.m_poro[pme->m_lid]; if (sporo && mporo) { double pm[FEElement::MAX_NODES]; for (int k=0; k<pme->Nodes(); ++k) pm[k] = mesh.Node(pme->m_node[k]).get(m_dofP); double p2 = pme->eval(pm, pt.m_rs[0], pt.m_rs[1]); pt.m_pg = p1 - p2; } // calculate the concentration gap functions for (int isol=0; isol<nsol; ++isol) { int sid = m_sid[isol]; double cm[MN]; for (int k=0; k<pme->Nodes(); ++k) cm[k] = mesh.Node(pme->m_node[k]).get(m_dofC + sid); double c2 = pme->eval(cm, pt.m_rs[0], pt.m_rs[1]); pt.m_cg[m_ssl[isol]] = c1[isol] - c2; } } else { // the node is not tied pt.m_dg = vec3d(0,0,0); if (sporo) { pt.m_pg = 0; pt.m_Lmp = 0; } for (int isol=0; isol<nsol; ++isol) { pt.m_Lmc[m_ssl[isol]] = 0; pt.m_cg[m_ssl[isol]] = 0; } } } } } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::Update() { // project the surfaces onto each other // this will update the gap functions as well ProjectSurface(m_ss, m_ms); if (m_btwo_pass) ProjectSurface(m_ms, m_ss); } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { int i, j, k; vector<int> sLM, mLM, LM, en; vector<double> fe; const int MN = FEElement::MAX_NODES; double detJ[MN], w[MN], *Hs, Hm[MN]; double N[MN*10]; int nsol = (int)m_sid.size(); vec3d tn[MN]; double wn[MN]; vector< vector<double> > jn(nsol,vector<double>(MN)); FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); FESolver* psolver = pstep->GetFESolver(); double dt = fem.GetTime().timeIncrement; // Update auto-penalty if requested if (m_bupdtpen && psolver->m_niter == 0) UpdateAutoPenalty(); // loop over the nr of passes int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { // get primary and seconary surface FETiedMultiphasicSurface& ss = (np == 0? m_ss : m_ms); FETiedMultiphasicSurface& ms = (np == 0? m_ms : m_ss); vector<int>& sl = (np == 0? m_ssl : m_msl); // loop over all primary surface elements for (i=0; i<ss.Elements(); ++i) { // get the surface element FESurfaceElement& se = ss.Element(i); bool sporo = ss.m_bporo; // get the nr of nodes and integration points int nseln = se.Nodes(); int nint = se.GaussPoints(); // copy the LM vector; we'll need it later ss.UnpackLM(se, sLM); // we calculate all the metrics we need before we // calculate the nodal forces for (j=0; j<nint; ++j) { // get the base vectors vec3d g[2]; ss.CoBaseVectors(se, j, g); // jacobians: J = |g0xg1| detJ[j] = (g[0] ^ g[1]).norm(); // integration weights w[j] = se.GaussWeights()[j]; FETiedMultiphasicContactPoint& pt = static_cast<FETiedMultiphasicContactPoint&>(*se.GetMaterialPoint(j)); // contact traction double eps = m_epsn*pt.m_epsn; // penalty tn[j] = pt.m_Lmd + pt.m_dg*eps; // contact traction // normal fluid flux double epsp = m_epsp*pt.m_epsp; wn[j] = pt.m_Lmp + epsp*pt.m_pg; // normal solute flux for (int isol=0; isol<nsol; ++isol) { int l = sl[isol]; double epsc = m_epsc*pt.m_epsc[l]; jn[isol][j] = pt.m_Lmc[l] + epsc*pt.m_cg[l]; } } // loop over all integration points // note that we are integrating over the current surface for (j=0; j<nint; ++j) { FETiedMultiphasicContactPoint& pt = static_cast<FETiedMultiphasicContactPoint&>(*se.GetMaterialPoint(j)); // get the secondary surface element FESurfaceElement* pme = pt.m_pme; if (pme) { // get the secondary surface element FESurfaceElement& me = *pme; bool mporo = ms.m_bporo; // get the nr of secondary surface element nodes int nmeln = me.Nodes(); // copy LM vector ms.UnpackLM(me, mLM); // calculate degrees of freedom int ndof = 3*(nseln + nmeln); // build the LM vector LM.resize(ndof); for (k=0; k<nseln; ++k) { LM[3*k ] = sLM[3*k ]; LM[3*k+1] = sLM[3*k+1]; LM[3*k+2] = sLM[3*k+2]; } for (k=0; k<nmeln; ++k) { LM[3*(k+nseln) ] = mLM[3*k ]; LM[3*(k+nseln)+1] = mLM[3*k+1]; LM[3*(k+nseln)+2] = mLM[3*k+2]; } // build the en vector en.resize(nseln+nmeln); for (k=0; k<nseln; ++k) en[k ] = se.m_node[k]; for (k=0; k<nmeln; ++k) en[k+nseln] = me.m_node[k]; // get element shape functions Hs = se.H(j); // get secondary surface element shape functions double r = pt.m_rs[0]; double s = pt.m_rs[1]; me.shape_fnc(Hm, r, s); // calculate the force vector fe.resize(ndof); zero(fe); for (k=0; k<nseln; ++k) { N[3*k ] = Hs[k]*tn[j].x; N[3*k+1] = Hs[k]*tn[j].y; N[3*k+2] = Hs[k]*tn[j].z; } for (k=0; k<nmeln; ++k) { N[3*(k+nseln) ] = -Hm[k]*tn[j].x; N[3*(k+nseln)+1] = -Hm[k]*tn[j].y; N[3*(k+nseln)+2] = -Hm[k]*tn[j].z; } for (k=0; k<ndof; ++k) fe[k] += N[k]*detJ[j]*w[j]; // assemble the global residual R.Assemble(en, LM, fe); // do the biphasic stuff if (sporo && mporo) { // calculate nr of pressure dofs int ndof = nseln + nmeln; // fill the LM LM.resize(ndof); for (k=0; k<nseln; ++k) LM[k ] = sLM[3*nseln+k]; for (k=0; k<nmeln; ++k) LM[k + nseln] = mLM[3*nmeln+k]; // fill the force array fe.resize(ndof); zero(fe); for (k=0; k<nseln; ++k) N[k ] = Hs[k]; for (k=0; k<nmeln; ++k) N[k+nseln] = -Hm[k]; for (k=0; k<ndof; ++k) fe[k] += dt*N[k]*wn[j]*detJ[j]*w[j]; // assemble residual R.Assemble(en, LM, fe); } for (int isol=0; isol<nsol; ++isol) { int sid = m_sid[isol]; // calculate nr of concentration dofs int ndof = nseln + nmeln; // fill the LM LM.resize(ndof); for (k=0; k<nseln; ++k) LM[k ] = sLM[(4+sid)*nseln+k]; for (k=0; k<nmeln; ++k) LM[k + nseln] = mLM[(4+sid)*nmeln+k]; // fill the force array fe.resize(ndof); zero(fe); for (k=0; k<nseln; ++k) N[k ] = Hs[k]; for (k=0; k<nmeln; ++k) N[k+nseln] = -Hm[k]; for (k=0; k<ndof; ++k) fe[k] += dt*N[k]*jn[isol][j]*detJ[j]*w[j]; // assemble residual R.Assemble(en, LM, fe); } } } } } } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { int i, j, k, l; vector<int> sLM, mLM, LM, en; const int MN = FEElement::MAX_NODES; double detJ[MN], w[MN], *Hs, Hm[MN]; FEElementMatrix ke; int nsol = (int)m_sid.size(); vec3d tn[MN]; double wn[MN]; vector< vector<double> > jn(nsol,vector<double>(MN)); FEModel& fem = *GetFEModel(); // see how many reformations we've had to do so far int nref = GetSolver()->m_nref; // set higher order stiffness mutliplier // NOTE: this algorithm doesn't really need this // but I've added this functionality to compare with the other contact // algorithms and to see the effect of the different stiffness contributions double knmult = m_knmult; if (m_knmult < 0) { int ni = int(-m_knmult); if (nref >= ni) { knmult = 1; feLog("Higher order stiffness terms included.\n"); } else knmult = 0; } // do single- or two-pass int npass = (m_btwo_pass?2:1); for (int np=0; np < npass; ++np) { // get the primary and secondary surface FETiedMultiphasicSurface& ss = (np == 0? m_ss : m_ms); FETiedMultiphasicSurface& ms = (np == 0? m_ms : m_ss); vector<int>& sl = (np == 0? m_ssl : m_msl); // loop over all primary surface elements for (i=0; i<ss.Elements(); ++i) { // get the next element FESurfaceElement& se = ss.Element(i); bool sporo = ss.m_bporo; // get nr of nodes and integration points int nseln = se.Nodes(); int nint = se.GaussPoints(); double pn[MN]; vector< vector<double> >cn(nsol,vector<double>(MN)); for (j=0; j<nseln; ++j) { pn[j] = ss.GetMesh()->Node(se.m_node[j]).get(m_dofP); for (int isol=0; isol<nsol; ++isol) { cn[isol][j] = ss.GetMesh()->Node(se.m_node[j]).get(m_dofC + m_sid[isol]); } } // copy the LM vector ss.UnpackLM(se, sLM); // we calculate all the metrics we need before we // calculate the nodal forces for (j=0; j<nint; ++j) { // get the base vectors vec3d g[2]; ss.CoBaseVectors(se, j, g); // jacobians: J = |g0xg1| detJ[j] = (g[0] ^ g[1]).norm(); // integration weights w[j] = se.GaussWeights()[j]; FETiedMultiphasicContactPoint& pd = static_cast<FETiedMultiphasicContactPoint&>(*se.GetMaterialPoint(j)); // contact traction double eps = m_epsn*pd.m_epsn; // penalty tn[j] = pd.m_Lmd + pd.m_dg*eps; // contact traction // normal fluid flux double epsp = m_epsp*pd.m_epsp; wn[j] = pd.m_Lmp + epsp*pd.m_pg; // normal solute flux for (int isol=0; isol<nsol; ++isol) { int l = sl[isol]; double epsc = m_epsc*pd.m_epsc[l]; jn[isol][j] = pd.m_Lmc[l] + epsc*pd.m_cg[l]; } // contravariant basis vectors of primary surface vec3d Gs[2]; ss.ContraBaseVectors(se, j, Gs); } // loop over all integration points for (j=0; j<nint; ++j) { FETiedMultiphasicContactPoint& pt = static_cast<FETiedMultiphasicContactPoint&>(*se.GetMaterialPoint(j)); // get the secondary surface element FESurfaceElement* pme = pt.m_pme; if (pme) { FESurfaceElement& me = *pme; bool mporo = ms.m_bporo; // get the nr of secondary surface nodes int nmeln = me.Nodes(); // nodal data double pm[MN]; vector< vector<double> > cm(nsol,vector<double>(MN)); for (k=0; k<nmeln; ++k) { pm[k] = ms.GetMesh()->Node(me.m_node[k]).get(m_dofP); for (int isol=0; isol<nsol; ++isol) { cm[isol][k] = ms.GetMesh()->Node(me.m_node[k]).get(m_dofC + m_sid[isol]); } } // copy the LM vector ms.UnpackLM(me, mLM); int ndpn; // number of dofs per node int ndof; // number of dofs in stiffness matrix if (nsol) { // calculate dofs for biphasic-solute contact ndpn = 4+nsol; ndof = ndpn*(nseln+nmeln); // build the LM vector LM.resize(ndof); for (k=0; k<nseln; ++k) { LM[ndpn*k ] = sLM[3*k ]; // x-dof LM[ndpn*k+1] = sLM[3*k+1]; // y-dof LM[ndpn*k+2] = sLM[3*k+2]; // z-dof LM[ndpn*k+3] = sLM[3*nseln+k]; // p-dof for (int isol=0; isol<nsol; ++isol) LM[ndpn*k+4+isol] = sLM[(4+m_sid[isol])*nseln+k]; // c-dof } for (k=0; k<nmeln; ++k) { LM[ndpn*(k+nseln) ] = mLM[3*k ]; // x-dof LM[ndpn*(k+nseln)+1] = mLM[3*k+1]; // y-dof LM[ndpn*(k+nseln)+2] = mLM[3*k+2]; // z-dof LM[ndpn*(k+nseln)+3] = mLM[3*nmeln+k]; // p-dof for (int isol=0; isol<nsol; ++isol) LM[ndpn*(k+nseln)+4+isol] = mLM[(4+m_sid[isol])*nmeln+k]; // c-dof } } else if (sporo && mporo) { // calculate dofs for biphasic contact ndpn = 4; ndof = ndpn*(nseln+nmeln); // build the LM vector LM.resize(ndof); for (k=0; k<nseln; ++k) { LM[ndpn*k ] = sLM[3*k ]; // x-dof LM[ndpn*k+1] = sLM[3*k+1]; // y-dof LM[ndpn*k+2] = sLM[3*k+2]; // z-dof LM[ndpn*k+3] = sLM[3*nseln+k]; // p-dof } for (k=0; k<nmeln; ++k) { LM[ndpn*(k+nseln) ] = mLM[3*k ]; // x-dof LM[ndpn*(k+nseln)+1] = mLM[3*k+1]; // y-dof LM[ndpn*(k+nseln)+2] = mLM[3*k+2]; // z-dof LM[ndpn*(k+nseln)+3] = mLM[3*nmeln+k]; // p-dof } } else { // calculate dofs for elastic contact ndpn = 3; ndof = ndpn*(nseln + nmeln); // build the LM vector LM.resize(ndof); for (k=0; k<nseln; ++k) { LM[3*k ] = sLM[3*k ]; LM[3*k+1] = sLM[3*k+1]; LM[3*k+2] = sLM[3*k+2]; } for (k=0; k<nmeln; ++k) { LM[3*(k+nseln) ] = mLM[3*k ]; LM[3*(k+nseln)+1] = mLM[3*k+1]; LM[3*(k+nseln)+2] = mLM[3*k+2]; } } // build the en vector en.resize(nseln+nmeln); for (k=0; k<nseln; ++k) en[k ] = se.m_node[k]; for (k=0; k<nmeln; ++k) en[k+nseln] = me.m_node[k]; // shape functions Hs = se.H(j); // secondary surface element shape functions double r = pt.m_rs[0]; double s = pt.m_rs[1]; me.shape_fnc(Hm, r, s); // get normal vector vec3d nu = pt.m_nu; // penalty double eps = m_epsn*pt.m_epsn; // create the stiffness matrix ke.resize(ndof, ndof); ke.zero(); // --- S O L I D - S O L I D C O N T A C T --- mat3ds Ns = mat3dd(1); double* Gr = se.Gr(j); double* Gs = se.Gs(j); vec3d gs[2]; ss.CoBaseVectors(se, j, gs); vec3d as[MN]; mat3d As[MN]; for (int c=0; c<nseln; ++c) { as[c] = (nu ^ (gs[1]*Gr[c] - gs[0]*Gs[c]))/detJ[j]; As[c] = (tn[j] & as[c]); } for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; mat3d Kac = (Ns*(Hs[c]*eps)+As[c])*(Hs[a]*detJ[j]*w[j]); ke[k ][l ] += Kac(0,0); ke[k ][l+1] += Kac(0,1); ke[k ][l+2] += Kac(0,2); ke[k+1][l ] += Kac(1,0); ke[k+1][l+1] += Kac(1,1); ke[k+1][l+2] += Kac(1,2); ke[k+2][l ] += Kac(2,0); ke[k+2][l+1] += Kac(2,1); ke[k+2][l+2] += Kac(2,2); } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; mat3d Kad = (Ns*(-Hs[a]*Hm[d]*eps))*(detJ[j]*w[j]); ke[k ][l ] += Kad(0,0); ke[k ][l+1] += Kad(0,1); ke[k ][l+2] += Kad(0,2); ke[k+1][l ] += Kad(1,0); ke[k+1][l+1] += Kad(1,1); ke[k+1][l+2] += Kad(1,2); ke[k+2][l ] += Kad(2,0); ke[k+2][l+1] += Kad(2,1); ke[k+2][l+2] += Kad(2,2); } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; mat3d Kbc = (Ns*(Hs[c]*eps)+As[c])*(-Hm[b]*detJ[j]*w[j]); ke[k ][l ] += Kbc(0,0); ke[k ][l+1] += Kbc(0,1); ke[k ][l+2] += Kbc(0,2); ke[k+1][l ] += Kbc(1,0); ke[k+1][l+1] += Kbc(1,1); ke[k+1][l+2] += Kbc(1,2); ke[k+2][l ] += Kbc(2,0); ke[k+2][l+1] += Kbc(2,1); ke[k+2][l+2] += Kbc(2,2); } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; mat3d Kbd = Ns*(Hm[b]*Hm[d]*eps*detJ[j]*w[j]); ke[k ][l ] += Kbd(0,0); ke[k ][l+1] += Kbd(0,1); ke[k ][l+2] += Kbd(0,2); ke[k+1][l ] += Kbd(1,0); ke[k+1][l+1] += Kbd(1,1); ke[k+1][l+2] += Kbd(1,2); ke[k+2][l ] += Kbd(2,0); ke[k+2][l+1] += Kbd(2,1); ke[k+2][l+2] += Kbd(2,2); } } // --- M U L T I P H A S I C S T I F F N E S S --- if (sporo && mporo) { double dt = fem.GetTime().timeIncrement; double epsp = m_epsp*pt.m_epsp; // --- S O L I D - P R E S S U R E / S O L U T E C O N T A C T --- for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; vec3d gac = (as[c]*(Hs[a]*wn[j]))*(dt*detJ[j]*w[j]); ke[k+3][l ] += gac.x; ke[k+3][l+1] += gac.y; ke[k+3][l+2] += gac.z; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]; vec3d hac = (as[c]*(Hs[a]*jn[isol][j])*epsc)*(dt*detJ[j]*w[j]); ke[k+4+isol][l ] += hac.x; ke[k+4+isol][l+1] += hac.y; ke[k+4+isol][l+2] += hac.z; } } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; vec3d gbc = (-as[c]*(Hm[b]*wn[j]))*(dt*detJ[j]*w[j]); ke[k+3][l ] += gbc.x; ke[k+3][l+1] += gbc.y; ke[k+3][l+2] += gbc.z; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]; vec3d hbc = (-as[c]*(Hm[b]*jn[isol][j])*epsc)*(dt*detJ[j]*w[j]); ke[k+4+isol][l ] += hbc.x; ke[k+4+isol][l+1] += hbc.y; ke[k+4+isol][l+2] += hbc.z; } } } // --- P R E S S U R E - P R E S S U R E / C O N C E N T R A T I O N - C O N C E N T R A T I O N C O N T A C T --- for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; double gac = (-Hs[a]*Hs[c]*epsp)*(dt*detJ[j]*w[j]); ke[k+3][l+3] += gac; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]; double hac = (-Hs[a]*Hs[c]*epsc)*(dt*detJ[j]*w[j]); ke[k+4+isol][l+4+isol] += hac; } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; double gad = (Hs[a]*Hm[d]*epsp)*(dt*detJ[j]*w[j]); ke[k+3][l+3] += gad; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]; double had = (Hs[a]*Hm[d]*epsc)*(dt*detJ[j]*w[j]); ke[k+4+isol][l+4+isol] += had; } } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; double gbc = (Hm[b]*Hs[c]*epsp)*(dt*detJ[j]*w[j]); ke[k+3][l+3] += gbc; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]; double hbc = (Hm[b]*Hs[c]*epsc)*(dt*detJ[j]*w[j]); ke[k+4+isol][l+4+isol] += hbc; } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; double gbd = (-Hm[b]*Hm[d]*epsp)*(dt*detJ[j]*w[j]); ke[k+3][l+3] += gbd; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]; double hbd = (-Hm[b]*Hm[d]*epsc)*(dt*detJ[j]*w[j]); ke[k+4+isol][l+4+isol] += hbd; } } } } // assemble the global stiffness ke.SetNodes(en); ke.SetIndices(LM); LS.Assemble(ke); } } } } } //----------------------------------------------------------------------------- bool FETiedMultiphasicInterface::Augment(int naug, const FETimeInfo& tp) { // make sure we need to augment if (m_laugon != FECore::AUGLAG_METHOD) return true; vec3d Ln; double Lp; int nsol = (int)m_sid.size(); vector<double>Lc(nsol); bool bconv = true; bool bporo = (m_ss.m_bporo && m_ms.m_bporo); bool bsolu = (m_ss.m_bsolu && m_ms.m_bsolu); int NS = m_ss.Elements(); int NM = m_ms.Elements(); // --- 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, normP = 0, normDP = 0, normC = 0; vector<double>normDC(nsol,0); for (int i=0; i<NS; ++i) { FESurfaceElement& el = m_ss.Element(i); for (int j = 0; j<el.GaussPoints(); ++j) { FETiedMultiphasicContactPoint& ds = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); normL0 += ds.m_Lmd*ds.m_Lmd; } } for (int i=0; i<NM; ++i) { FESurfaceElement& el = m_ms.Element(i); for (int j=0; j<el.GaussPoints(); ++j) { FETiedMultiphasicContactPoint& dm = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); normL0 += dm.m_Lmd*dm.m_Lmd; } } // b. gap component // (is calculated during update) double maxgap = 0; double maxpg = 0; vector<double> maxcg(nsol,0); // update Lagrange multipliers double normL1 = 0, eps, epsp, epsc; for (int i = 0; i<NS; ++i) { FESurfaceElement& el = m_ss.Element(i); for (int j = 0; j<el.GaussPoints(); ++j) { FETiedMultiphasicContactPoint& ds = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); // update Lagrange multipliers on primary surface eps = m_epsn*ds.m_epsn; ds.m_Lmd = ds.m_Lmd + ds.m_dg*eps; normL1 += ds.m_Lmd*ds.m_Lmd; if (m_ss.m_bporo) { Lp = 0; Lc.assign(nsol, 0); if (ds.m_pme) { epsp = m_epsp*ds.m_epsp; Lp = ds.m_Lmp + epsp*ds.m_pg; maxpg = max(maxpg,fabs(ds.m_pg)); normDP += ds.m_pg*ds.m_pg; for (int isol=0; isol<nsol; ++isol) { int l = m_ssl[isol]; epsc = m_epsc*ds.m_epsc[l]; Lc[isol] = ds.m_Lmc[l] + epsc*ds.m_cg[l]; maxcg[isol] = max(maxcg[isol],fabs(ds.m_cg[l])); normDC[isol] += ds.m_cg[l]*ds.m_cg[l]; } } ds.m_Lmp = Lp; for (int isol=0; isol<nsol; ++isol) ds.m_Lmc[m_ssl[isol]] = Lc[isol]; } maxgap = max(maxgap,sqrt(ds.m_dg*ds.m_dg)); } } for (int i = 0; i<NM; ++i) { FESurfaceElement& el = m_ms.Element(i); for (int j = 0; j<el.GaussPoints(); ++j) { FETiedMultiphasicContactPoint& dm = static_cast<FETiedMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); // update Lagrange multipliers on secondary surface eps = m_epsn*dm.m_epsn; dm.m_Lmd = dm.m_Lmd + dm.m_dg*eps; normL1 += dm.m_Lmd*dm.m_Lmd; if (m_ms.m_bporo) { Lp = 0; Lc.assign(nsol, 0); if (dm.m_pme) { epsp = m_epsp*dm.m_epsp; Lp = dm.m_Lmp + epsp*dm.m_pg; maxpg = max(maxpg,fabs(dm.m_pg)); normDP += dm.m_pg*dm.m_pg; for (int isol=0; isol<nsol; ++isol) { int l = m_msl[isol]; epsc = m_epsc*dm.m_epsc[l]; Lc[isol] = dm.m_Lmc[l] + epsc*dm.m_cg[l]; maxcg[isol] = max(maxcg[isol],fabs(dm.m_cg[l])); normDC[isol] += dm.m_cg[l]*dm.m_cg[l]; } } dm.m_Lmp = Lp; for (int isol=0; isol<nsol; ++isol) dm.m_Lmc[m_msl[isol]] = Lc[isol]; } maxgap = max(maxgap,sqrt(dm.m_dg*dm.m_dg)); } } // Ideally normP should be evaluated from the fluid pressure at the // contact interface (not easily accessible). The next best thing // is to use the contact traction. normP = normL1; normC = normL1/(m_Rgas*m_Tabs); // calculate relative norms double lnorm = (normL1 != 0 ? fabs((normL1 - normL0) / normL1) : fabs(normL1 - normL0)); double pnorm = (normP != 0 ? (normDP/normP) : normDP); vector<double> cnorm(nsol); for (int isol=0; isol<nsol; ++isol) cnorm[isol] = (normC != 0 ? (normDC[isol]/normC) : normDC[isol]); // check convergence if ((m_gtol > 0) && (maxgap > m_gtol)) bconv = false; if ((m_ptol > 0) && (bporo && maxpg > m_ptol)) bconv = false; for (int isol=0; isol<nsol; ++isol) if ((m_ctol > 0) && (bsolu && maxcg[isol] > m_ctol)) bconv = false; if ((m_atol > 0) && (lnorm > m_atol)) bconv = false; if ((m_atol > 0) && (pnorm > m_atol)) bconv = false; for (int isol=0; isol<nsol; ++isol) if ((m_atol > 0) && (cnorm[isol] > m_atol)) bconv = false; if (naug < m_naugmin ) bconv = false; if (naug >= m_naugmax) bconv = true; feLog(" sliding interface # %d\n", GetID()); feLog(" CURRENT REQUIRED\n"); feLog(" D multiplier : %15le", lnorm); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n"); if (bporo) { feLog(" P gap : %15le", pnorm); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n"); } for (int isol=0; isol<nsol; ++isol) { feLog(" C[%d] gap : %15le", m_sid[isol], cnorm[isol]); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n"); } feLog(" maximum gap : %15le", maxgap); if (m_gtol > 0) feLog("%15le\n", m_gtol); else feLog(" ***\n"); if (bporo) { feLog(" maximum pgap : %15le", maxpg); if (m_ptol > 0) feLog("%15le\n", m_ptol); else feLog(" ***\n"); } for (int isol=0; isol<nsol; ++isol) { feLog(" maximum cgap[%d] : %15le", m_sid[isol], maxcg[isol]); if (m_ctol > 0) feLog("%15le\n", m_ctol); else feLog(" ***\n"); } return bconv; } //----------------------------------------------------------------------------- void FETiedMultiphasicInterface::Serialize(DumpStream &ar) { // store base class data FEContactInterface::Serialize(ar); // store contact surface data m_ms.Serialize(ar); m_ss.Serialize(ar); // serialize element pointers SerializeElementPointers(m_ss, m_ms, ar); SerializeElementPointers(m_ms, m_ss, ar); // serialize interface data ar & m_epsp; ar & m_epsc; ar & m_sid; ar & m_ssl; ar & m_msl; ar & m_sz; if (ar.IsShallow()) return; ar & m_dofP & m_dofC; ar & m_Rgas & m_Tabs; } //----------------------------------------------------------------------------- FESoluteData* FETiedMultiphasicInterface::FindSoluteData(int nid) { FEModel& fem = *GetFEModel(); int N = GetFEModel()->GlobalDataItems(); for (int i=0; i<N; ++i) { FESoluteData* psd = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (psd && (psd->GetID() == nid)) return psd; } return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicSolidDomain.h
.h
4,366
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 "FECore/FESolidDomain.h" #include "FEMultiphasic.h" #include "FEMultiphasicDomain.h" #include <FECore/FEDofList.h> //----------------------------------------------------------------------------- //! Domain class for multiphasic 3D solid elements //! Note that this class inherits from FEElasticSolidDomain since this domain //! also needs to calculate elastic stiffness contributions. //! class FEBIOMIX_API FEMultiphasicSolidDomain : public FESolidDomain, public FEMultiphasicDomain { public: //! constructor FEMultiphasicSolidDomain(FEModel* pfem); //! Reset data void Reset() override; //! get the material (overridden from FEDomain) FEMaterial* GetMaterial() override { return m_pMat; } //! set the material void SetMaterial(FEMaterial* pmat) override; //! Unpack solid element data (overridden from FEDomain) void UnpackLM(FEElement& el, vector<int>& lm) override; //! initialize elements for this domain void PreSolveUpdate(const FETimeInfo& timeInfo) override; //! calculates the global stiffness matrix for this domain void StiffnessMatrix(FELinearSystem& LS, bool bsymm) override; //! calculates the global stiffness matrix for this domain (steady-state case) void StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) override; //! initialize class bool Init() override; //! activate void Activate() override; //! initialize material points in the domain void InitMaterialPoints() override; // update domain data void Update(const FETimeInfo& tp) override; // update element state data void UpdateElementStress(int iel, double dt); // get total dof list const FEDofList& GetDOFList() const override; public: // internal work (overridden from FEElasticDomain) void InternalForces(FEGlobalVector& R) override; // internal work (steady-state case) void InternalForcesSS(FEGlobalVector& R) override; public: //! element internal force vector void ElementInternalForce(FESolidElement& el, vector<double>& fe); //! element internal force vector (steady-state case) void ElementInternalForceSS(FESolidElement& el, vector<double>& fe); //! calculates the element triphasic stiffness matrix bool ElementMultiphasicStiffness(FESolidElement& el, matrix& ke, bool bsymm); //! calculates the element triphasic stiffness matrix bool ElementMultiphasicStiffnessSS(FESolidElement& el, matrix& ke, bool bsymm); protected: // overridden from FEElasticDomain, but not implemented in this domain void BodyForce(FEGlobalVector& R, FEBodyForce& bf) override {} void InertialForces(FEGlobalVector& R, vector<double>& F) override {} void StiffnessMatrix(FELinearSystem& LS) override {} void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) override {} void MassMatrix(FELinearSystem& LS, double scale) override {} protected: FEDofList m_dofU; FEDofList m_dofSU; FEDofList m_dofR; FEDofList m_dof; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateNims.cpp
.cpp
5,374
163
/*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 "FEReactionRateNims.h" #include "FESoluteInterface.h" #include "FESolutesMaterialPoint.h" #include "FECore/FEModel.h" #include <FECore/log.h> // Material parameters for the FEMultiphasic material BEGIN_FECORE_CLASS(FEReactionRateNims, FEReactionRate) ADD_PARAMETER(m_sol , "sol")->setEnums("$(solutes)"); ADD_PARAMETER(m_k0, "k0"); ADD_PARAMETER(m_kc, "kc"); ADD_PARAMETER(m_kr, "kr"); ADD_PARAMETER(m_cc , FE_RANGE_GREATER (0.0), "cc"); ADD_PARAMETER(m_cr , FE_RANGE_GREATER (0.0), "cr"); ADD_PARAMETER(m_trel, FE_RANGE_GREATER_OR_EQUAL(0.0), "trel"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEReactionRateNims::FEReactionRateNims(FEModel* pfem) : FEReactionRate(pfem) { m_lid = m_cmax = -1; m_sol = -1; m_k0 = 0.0; m_cc = 0.0; m_kc = 0.0; m_cr = 0.0; m_kr = 0.0; m_trel = 0.0; } //----------------------------------------------------------------------------- bool FEReactionRateNims::Init() { if (FEReactionRate::Init() == false) return false; // do only once if (m_lid == -1) { // get number of DOFS DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); // check validity of sol if (m_sol < 1 || m_sol > MAX_CDOFS) { feLogError("sol value outside of valid range for solutes"); return false; } // convert global sol value to local id FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); m_lid = psm->FindLocalSoluteID(m_sol); // check validity of local id if (m_lid == -1) { feLogError("sol does not match any solute in multiphasic material"); return false; } } return true; } #ifndef max #define max(a,b) ((a)>(b)?(a):(b)) #endif //----------------------------------------------------------------------------- //! reaction rate at material point double FEReactionRateNims::ReactionRate(FEMaterialPoint& pt) { // get the time double t = GetFEModel()->GetTime().currentTime; FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); double c = spt.m_ca[m_lid]; double cmax = max(c,spt.m_crd[m_cmax]); double k = m_k0(pt); double kr = m_kr(pt); double kc = m_kc(pt); double trel = m_trel(pt); double cr = m_cr(pt); double cc = m_cc(pt); // if we are past the release time and got exposed to the solute if ((trel > 0) && (t >= trel)) { if (cmax < cr) k += (kr - k)*cmax/cr; else k = kr; } // otherwise else { // evaluate reaction rate if (cmax < cc) k += (kc - k)*cmax/cc; else k = kc; } return k; } //----------------------------------------------------------------------------- //! tangent of reaction rate with strain at material point mat3ds FEReactionRateNims::Tangent_ReactionRate_Strain(FEMaterialPoint& pt) { return mat3dd(0); } //----------------------------------------------------------------------------- //! tangent of reaction rate with effective fluid pressure at material point double FEReactionRateNims::Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) { return 0; } //----------------------------------------------------------------------------- //! reset, initialize and update chemical reaction data in the FESolutesMaterialPoint void FEReactionRateNims::ResetElementData(FEMaterialPoint& mp) { // store the solute maximum concentration in the optional // chemical reaction data vector m_crd in the solutes material point FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); spt.m_crd.push_back(0); m_cmax = (int)spt.m_crd.size() - 1; } void FEReactionRateNims::InitializeElementData(FEMaterialPoint& mp) { FESolutesMaterialPoint& pt = *mp.ExtractData<FESolutesMaterialPoint>(); double c = pt.m_ca[m_lid]; double cmax = pt.m_crd[m_cmax]; if (c > cmax) pt.m_crd[m_cmax] = c; } void FEReactionRateNims::UpdateElementData(FEMaterialPoint& mp) { }
C++
3D
febiosoftware/FEBio
FEBioMix/FEFiberPowLinearSBM.cpp
.cpp
10,179
318
/*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 "FEFiberPowLinearSBM.h" #include "FEMultiphasic.h" #include <FECore/log.h> #include <FEBioMech/FEElasticMixture.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEFiberPowLinearSBM, FEElasticMaterial) ADD_PARAMETER(m_E0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "E0" )->setUnits(UNIT_PRESSURE);; ADD_PARAMETER(m_lam0 , FE_RANGE_GREATER (1.0), "lam0" ); ADD_PARAMETER(m_beta , FE_RANGE_GREATER_OR_EQUAL(2.0), "beta" ); ADD_PARAMETER(m_rho0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "rho0" )->setUnits(UNIT_DENSITY);; ADD_PARAMETER(m_g , FE_RANGE_GREATER_OR_EQUAL(0.0), "gamma"); ADD_PARAMETER(m_sbm , "sbm")->setEnums("$(sbms)"); ADD_PROPERTY(m_fiber, "fiber"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- // FEFiberPowLinear //----------------------------------------------------------------------------- bool FEFiberPowLinearSBM::Init() { if (FEElasticMaterial::Init() == false) return false; // get the parent material which must be a multiphasic material FEMultiphasic* pMP = dynamic_cast<FEMultiphasic*> (GetAncestor()); if (pMP == 0) { feLogError("Parent material must be multiphasic"); return false; } // extract the local id of the SBM whose density controls Young's modulus from the global id m_lsbm = pMP->FindLocalSBMID(m_sbm); if (m_lsbm == -1) { feLogError("Invalid value for sbm"); return false; } FEElasticMaterial* pem = pMP->GetSolid(); FEElasticMixture* psm = dynamic_cast<FEElasticMixture*>(pem); if (psm == nullptr) m_comp = -1; // in case material is not a solid mixture for (int i=0; i<psm->Materials(); ++i) { pem = psm->GetMaterial(i); if (pem == this) { m_comp = i; break; } } return true; } //----------------------------------------------------------------------------- //! Create material point data FEMaterialPointData* FEFiberPowLinearSBM::CreateMaterialPointData() { return new FERemodelingMaterialPoint(new FEElasticMaterialPoint); } //----------------------------------------------------------------------------- //! update specialize material point data void FEFiberPowLinearSBM::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); FERemodelingMaterialPoint* rpt = mp.ExtractData<FERemodelingMaterialPoint>(); rpt->m_rhor = spt.m_sbmr[m_lsbm]; rpt->m_rhorp = spt.m_sbmrp[m_lsbm]; rpt->m_sed = StrainEnergyDensity(mp); } //----------------------------------------------------------------------------- mat3ds FEFiberPowLinearSBM::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double lam0 = m_lam0(mp); double beta = m_beta(mp); // initialize material constants double rhor = spt.m_sbmr[m_lsbm]; double E = FiberModulus(mp, rhor); double I0 = lam0*lam0; double ksi = E/4/(beta-1)*pow(I0, -3./2.)*pow(I0-1, 2-beta); double b = ksi*pow(I0-1, beta-1) + E/2/sqrt(I0); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; // loop over all integration points vec3d nt; double In, sn; const double eps = 0; mat3ds C = pt.RightCauchyGreen(); mat3ds s; // get the material coordinate system mat3d Q = GetLocalCS(mp); // get local fiber direction vec3d fiber = m_fiber->unitVector(mp); // convert to global coordinates vec3d n0 = Q*fiber; // Calculate In In = n0*(C*n0); // only take fibers in tension into consideration if (In - 1 >= eps) { // get the global spatial fiber direction in current configuration nt = F*n0/sqrt(In); // calculate the outer product of nt mat3ds N = dyad(nt); // calculate the fiber stress magnitude sn = (In < I0) ? 2*In*ksi*pow(In-1, beta-1) : 2*b*In - E*sqrt(In); // calculate the fiber stress s = N*(sn/J); } else { s.zero(); } return s; } //----------------------------------------------------------------------------- tens4ds FEFiberPowLinearSBM::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double lam0 = m_lam0(mp); double beta = m_beta(mp); // initialize material constants double rhor = spt.m_sbmr[m_lsbm]; double E = FiberModulus(mp, rhor); double I0 = lam0*lam0; double ksi = E/4/(beta-1)*pow(I0, -3./2.)*pow(I0-1, 2-beta); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; // loop over all integration points vec3d nt; double In, cn; const double eps = 0; mat3ds C = pt.RightCauchyGreen(); tens4ds c; // get the material coordinate system mat3d Q = GetLocalCS(mp); // get local fiber direction vec3d fiber = m_fiber->unitVector(mp); // convert to global coordinates vec3d n0 = Q*fiber; // Calculate In In = n0*(C*n0); // only take fibers in tension into consideration if (In - 1 >= eps) { // get the global spatial fiber direction in current configuration nt = F*n0/sqrt(In); // calculate the outer product of nt mat3ds N = dyad(nt); tens4ds NxN = dyad1s(N); // calculate modulus cn = (In < I0) ? 4*In*In*ksi*(beta-1)*pow(In-1, beta-2) : E*sqrt(In); // calculate the fiber tangent c = NxN*(cn/J); } else { c.zero(); } return c; } //----------------------------------------------------------------------------- double FEFiberPowLinearSBM::StrainEnergyDensity(FEMaterialPoint& mp) { double sed = 0.0; FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double lam0 = m_lam0(mp); double beta = m_beta(mp); // initialize material constants double rhor = spt.m_sbmr[m_lsbm]; double E = FiberModulus(mp, rhor); double I0 = lam0*lam0; double ksi = E/4/(beta-1)*pow(I0, -3./2.)*pow(I0-1, 2-beta); double b = ksi*pow(I0-1, beta-1) + E/2/sqrt(I0); // loop over all integration points double In; const double eps = 0; mat3ds C = pt.RightCauchyGreen(); // get the material coordinate system mat3d Q = GetLocalCS(mp); // get local fiber direction vec3d fiber = m_fiber->unitVector(mp); // convert to global coordinates vec3d n0 = Q*fiber; // Calculate In = n0*C*n0 In = n0*(C*n0); // only take fibers in tension into consideration if (In - 1 >= eps) { // calculate strain energy density sed = (In < I0) ? ksi/beta*pow(In-1, beta) : b*(In-I0) - E*(sqrt(In)-sqrt(I0)) + ksi/beta*pow(I0-1, beta); } return sed; } //----------------------------------------------------------------------------- //! evaluate referential mass density double FEFiberPowLinearSBM::Density(FEMaterialPoint& pt) { FERemodelingMaterialPoint* rpt = pt.ExtractData<FERemodelingMaterialPoint>(); if (rpt) return rpt->m_rhor; else { FEElasticMixtureMaterialPoint* emp = pt.ExtractData<FEElasticMixtureMaterialPoint>(); if (emp) { rpt = emp->GetPointData(m_comp)->ExtractData<FERemodelingMaterialPoint>(); if (rpt) return rpt->m_rhor; } } return 0.0; } //----------------------------------------------------------------------------- //! calculate strain energy density at material point double FEFiberPowLinearSBM::StrainEnergy(FEMaterialPoint& mp) { return StrainEnergyDensity(mp); } //----------------------------------------------------------------------------- //! calculate tangent of strain energy density with mass density double FEFiberPowLinearSBM::Tangent_SE_Density(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; return StrainEnergy(mp)*m_g(mp)/rhor; } //----------------------------------------------------------------------------- //! calculate tangent of stress with mass density mat3ds FEFiberPowLinearSBM::Tangent_Stress_Density(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; return Stress(mp)*m_g(mp)/rhor; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateNims.h
.h
3,418
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 "FEChemicalReaction.h" //----------------------------------------------------------------------------- //! Concentration-history-dependent reaction rate. //! Reaction rate depends on concentration of a solute (e.g., growth factor) //! and whether solute has been released (removed) at some release time. //! Before release, reaction rate varies linearly with history of maximum solute //! concentration cmax, from k0 at cmax=0 to kc at cmax=cc, then holds constant at kc. //! After release, reaction rate increases from k0 at cmax=0 to kr at cmax=cr, //! then holds constant at kr. Release time is trel. class FEBIOMIX_API FEReactionRateNims : public FEReactionRate { public: //! constructor FEReactionRateNims(FEModel* pfem); //! data initialization and checking bool Init() override; //! reaction rate at material point double ReactionRate(FEMaterialPoint& pt) override; //! tangent of reaction rate with strain at material point mat3ds Tangent_ReactionRate_Strain(FEMaterialPoint& pt) override; //! tangent of reaction rate with effective fluid pressure at material point double Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) override; //! reset, initialize and update chemical reaction data in the FESolutesMaterialPoint void ResetElementData(FEMaterialPoint& mp) override; void InitializeElementData(FEMaterialPoint& mp) override; void UpdateElementData(FEMaterialPoint& mp) override; public: int m_sol; //!< solute id (1-based) int m_lid; //!< local id of solute (zero-based) FEParamDouble m_k0; //!< reaction rate at zero concentration FEParamDouble m_cc; //!< concentration cc FEParamDouble m_kc; //!< reaction rate at cc; FEParamDouble m_cr; //!< concentration cr; FEParamDouble m_kr; //!< reaction rate at cr; FEParamDouble m_trel; //!< release time; int m_cmax; //!< index of entry in m_crd DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMatchingOsmoticCoefficientLoad.cpp
.cpp
5,507
148
/*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 "FEMatchingOsmoticCoefficientLoad.h" #include "FEBioMix.h" #include <FECore/FEModel.h> //============================================================================= BEGIN_FECORE_CLASS(FEMatchingOsmoticCoefficientLoad, FESurfaceLoad) ADD_PARAMETER(m_ambp, "ambient_pressure"); ADD_PARAMETER(m_ambc, "ambient_osmolarity"); ADD_PARAMETER(m_bshellb, "shell_bottom"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FEMatchingOsmoticCoefficientLoad::FEMatchingOsmoticCoefficientLoad(FEModel* pfem) : FESurfaceLoad(pfem) { m_ambp = m_ambc = 0.0; m_bshellb = false; m_dofP = pfem->GetDOFIndex("p"); m_dofQ = pfem->GetDOFIndex("q"); } //----------------------------------------------------------------------------- //! initialize bool FEMatchingOsmoticCoefficientLoad::Init() { if (FESurfaceLoad::Init() == false) return false; return true; } //----------------------------------------------------------------------------- //! Activate the degrees of freedom for this BC void FEMatchingOsmoticCoefficientLoad::Activate() { FESurface* ps = &GetSurface(); FEModel* fem = GetFEModel(); for (int i = 0; i < ps->Elements(); ++i) { FESurfaceElement& el = ps->Element(i); // get the element connected to this surface FEElement* elem = el.m_elem[0].pe; FEMaterial* pm = fem->GetMaterial(elem->GetMatID()); // get the multihasic material for this element FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*>(pm); // if the material is multiphasic, set prescribable fluid dofs if (pmp) { for (int j = 0; j < el.Nodes(); ++j) { FENode& node = ps->Node(el.m_lnode[j]); // mark node as having prescribed DOF if (!m_bshellb) node.set_bc(m_dofP, DOF_PRESCRIBED); else node.set_bc(m_dofQ, DOF_PRESCRIBED); } } } FESurfaceLoad::Activate(); } //----------------------------------------------------------------------------- //! Evaluate and prescribe the ambient effective fluid pressure, using the multiphasic osmotic coefficient void FEMatchingOsmoticCoefficientLoad::Update() { FESurface* ps = &GetSurface(); FEModel* fem = GetFEModel(); vector<double> pn(ps->Nodes(), 0); vector<int> cnt(ps->Nodes(), 0); for (int i = 0; i < ps->Elements(); ++i) { FESurfaceElement& el = ps->Element(i); // get the element connected to this surface FEElement* elem = el.m_elem[0].pe; FEMaterial* pm = fem->GetMaterial(elem->GetMatID()); // get the multihasic material for this element FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*>(pm); double Phi = 0; if (pmp) { // get average osmotic coefficient in this multiphasic element int nint = elem->GaussPoints(); for (int n = 0; n < nint; ++n) { FEMaterialPoint& mp = *elem->GetMaterialPoint(n); Phi += pmp->GetOsmoticCoefficient()->OsmoticCoefficient(mp); } Phi /= nint; // evaluate effective fluid pressure on the boundary double pe = m_ambp - pmp->m_Rgas * pmp->m_Tabs * Phi * m_ambc; // project to nodes of that face for (int j = 0; j < el.Nodes(); ++j) { int n = el.m_lnode[j]; pn[n] += pe; ++cnt[n]; } } } // prescribe the projected nodal values of the effective fluid pressure for (int i = 0; i < ps->Nodes(); ++i) { if (ps->Node(i).m_ID[m_dofP] < -1) { assert(cnt[i]); FENode& node = ps->Node(i); // prescribe effective pressure at this node double pe = pn[i] / cnt[i]; if (!m_bshellb) node.set(m_dofP, pe); else node.set(m_dofQ, pe); } } fem->SetMeshUpdateFlag(true); } //----------------------------------------------------------------------------- //! serialization void FEMatchingOsmoticCoefficientLoad::Serialize(DumpStream& ar) { FESurfaceLoad::Serialize(ar); }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicAnalysis.h
.h
1,546
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 <FECore/FEAnalysis.h> #include "febiomix_api.h" class FEBIOMIX_API FEBiphasicAnalysis : public FEAnalysis { public: enum BiphasicAnalysisType{ STEADY_STATE, TRANSIENT }; public: FEBiphasicAnalysis(FEModel* fem); DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEActiveConstantSupply.cpp
.cpp
2,515
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 "FEActiveConstantSupply.h" #include "FEBioMech/FEElasticMaterial.h" // define the material parameters BEGIN_FECORE_CLASS(FEActiveConstantSupply, FEActiveMomentumSupply) ADD_PARAMETER(m_asupp, "supply"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEActiveConstantSupply::FEActiveConstantSupply(FEModel* pfem) : FEActiveMomentumSupply(pfem) { m_asupp = 0; } //----------------------------------------------------------------------------- //! Active momentum supply vector. //! The momentum supply is oriented along the first material axis vec3d FEActiveConstantSupply::ActiveSupply(FEMaterialPoint& mp) { FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); // get the local coordinate systems mat3d Q = GetLocalCS(mp); // active momentum supply vector direction vec3d V(Q[0][0], Q[1][0], Q[2][0]); mat3d F = et.m_F; vec3d pw = (F*V)*m_asupp; return pw; } //----------------------------------------------------------------------------- //! Tangent of permeability vec3d FEActiveConstantSupply::Tangent_ActiveSupply_Strain(FEMaterialPoint &mp) { return vec3d(0,0,0); }
C++
3D
febiosoftware/FEBio
FEBioMix/FEOsmCoefConst.h
.h
2,106
56
/*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 "FEBiphasicSolute.h" //----------------------------------------------------------------------------- // This class implements a material that has a constant osmotic coefficient class FEBIOMIX_API FEOsmCoefConst : public FEOsmoticCoefficient { public: //! constructor FEOsmCoefConst(FEModel* pfem); //! osmotic coefficient double OsmoticCoefficient(FEMaterialPoint& pt) override; //! Tangent of osmotic coefficient with respect to strain (J=detF) double Tangent_OsmoticCoefficient_Strain(FEMaterialPoint& mp) override; //! Tangent of osmotic coefficient with respect to concentration double Tangent_OsmoticCoefficient_Concentration(FEMaterialPoint& mp, const int isol) override; public: double m_osmcoef; //!< osmotic coefficient // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESoluteFlux.cpp
.cpp
4,721
161
/*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 "FESoluteFlux.h" #include <FECore/FEAnalysis.h> #include <FECore/FEFacetSet.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FESoluteFlux, FESurfaceLoad) ADD_PARAMETER(m_flux , "flux"); ADD_PARAMETER(m_blinear, "linear"); ADD_PARAMETER(m_bshellb, "shell_bottom"); ADD_PARAMETER(m_isol , "solute_id")->setEnums("$(solutes)"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FESoluteFlux::FESoluteFlux(FEModel* pfem) : FESurfaceLoad(pfem), m_dofC(pfem), m_dofU(pfem) { m_flux = 1.0; m_blinear = false; m_bshellb = false; m_isol = -1; } //----------------------------------------------------------------------------- //! allocate storage void FESoluteFlux::SetSurface(FESurface* ps) { FESurfaceLoad::SetSurface(ps); m_flux.SetItemList(ps->GetFacetSet()); } //----------------------------------------------------------------------------- //! serialization void FESoluteFlux::Serialize(DumpStream& ar) { FESurfaceLoad::Serialize(ar); if (ar.IsShallow() == false) { ar & m_dofC & m_dofU; } } //----------------------------------------------------------------------------- bool FESoluteFlux::Init() { if (m_psurf == nullptr) return false; m_psurf->SetShellBottom(m_bshellb); if (m_isol == -1) return false; // set up the dof lists m_dofC.Clear(); m_dofU.Clear(); if (m_bshellb == false) { m_dofC.AddDof(GetDOFIndex("concentration", m_isol - 1)); m_dofU.AddDof(GetDOFIndex("x")); m_dofU.AddDof(GetDOFIndex("y")); m_dofU.AddDof(GetDOFIndex("z")); } else { m_dofC.AddDof(GetDOFIndex("shell concentration", m_isol - 1)); m_dofU.AddDof(GetDOFIndex("sx")); m_dofU.AddDof(GetDOFIndex("sy")); m_dofU.AddDof(GetDOFIndex("sz")); } m_dof.AddDofs(m_dofU); m_dof.AddDofs(m_dofC); return FESurfaceLoad::Init(); } //----------------------------------------------------------------------------- void FESoluteFlux::LoadVector(FEGlobalVector& R) { double dt = CurrentTimeIncrement(); m_psurf->SetShellBottom(m_bshellb); FESoluteFlux* flux = this; m_psurf->LoadVector(R, m_dofC, m_blinear, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, std::vector<double>& fa) { double wr = flux->m_flux(mp); if (flux->m_bshellb) wr = -wr; vec3d dxt = mp.dxr ^ mp.dxs; // volumetric flow rate double f = dxt.norm()*wr* dt; double H_i = dof_a.shape; fa[0] = H_i * f; }); } //----------------------------------------------------------------------------- void FESoluteFlux::StiffnessMatrix(FELinearSystem& LS) { // time increment double dt = CurrentTimeIncrement(); m_psurf->SetShellBottom(m_bshellb); // evaluate the stiffness contribution FESoluteFlux* flux = this; m_psurf->LoadStiffness(LS, m_dofC, m_dofU, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) { // shape functions and derivatives double H_i = dof_a.shape; double Gr_j = dof_b.shape_deriv_r; double Gs_j = dof_b.shape_deriv_s; double wr = flux->m_flux(mp); if (flux->m_bshellb) wr = -wr; // calculate surface normal vec3d dxt = mp.dxr ^ mp.dxs; // calculate stiffness component vec3d t1 = dxt / dxt.norm()*wr; vec3d t2 = mp.dxs*Gr_j - mp.dxr*Gs_j; vec3d kab = (t1 ^ t2)*(H_i)*dt; Kab[0][0] = kab.x; Kab[0][1] = kab.y; Kab[0][2] = kab.z; }); }
C++
3D
febiosoftware/FEBio
FEBioMix/FESolubConst.cpp
.cpp
3,233
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.*/ #include "stdafx.h" #include "FESolubConst.h" //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FESolubConst, FESoluteSolubility) ADD_PARAMETER(m_solub, FE_RANGE_GREATER_OR_EQUAL(0.0), "solub")->setLongName("solubility"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FESolubConst::FESolubConst(FEModel* pfem) : FESoluteSolubility(pfem) { m_solub = 1; } //----------------------------------------------------------------------------- //! Solubility double FESolubConst::Solubility(FEMaterialPoint& mp) { // --- constant solubility --- return m_solub; } //----------------------------------------------------------------------------- //! Tangent of solubility with respect to strain double FESolubConst::Tangent_Solubility_Strain(FEMaterialPoint &mp) { return 0; } //----------------------------------------------------------------------------- //! Tangent of solubility with respect to concentration double FESolubConst::Tangent_Solubility_Concentration(FEMaterialPoint &mp, const int isol) { return 0; } //----------------------------------------------------------------------------- //! Cross derivative of solubility with respect to strain and concentration double FESolubConst::Tangent_Solubility_Strain_Concentration(FEMaterialPoint &mp, const int isol) { return 0; } //----------------------------------------------------------------------------- //! Second derivative of solubility with respect to strain double FESolubConst::Tangent_Solubility_Strain_Strain(FEMaterialPoint &mp) { return 0; } //----------------------------------------------------------------------------- //! Second derivative of solubility with respect to concentration double FESolubConst::Tangent_Solubility_Concentration_Concentration(FEMaterialPoint &mp, const int isol, const int jsol) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicMultigeneration.h
.h
3,542
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 "FEMultiphasic.h" //----------------------------------------------------------------------------- // forward declaration of material class class FEMultiphasicMultigeneration; //----------------------------------------------------------------------------- //! Multigenerational SBM material point. //! This material point stores the inverse of the relative deformation gradient, //! and the increment in the mass of solid-bound molecular species in //! multiple generations. class FEBIOMIX_API FEMultigenSBMMaterialPoint : public FEMaterialPointData { public: FEMultigenSBMMaterialPoint(FEMultiphasicMultigeneration* pm, FEMaterialPointData* pt) : m_pmat(pm), FEMaterialPointData(pt) { m_tgen = 0.0; } FEMaterialPointData* Copy(); void Serialize(DumpStream& ar); void Init(); void Update(const FETimeInfo& timeInfo); public: // multigenerational material data int m_ngen; //!< number of generations vector <mat3d> m_Fi; //!< inverse of relative deformation gradient vector <double> m_Ji; //!< determinant of Fi (store for efficiency) int m_nsbm; //!< number of solid-bound molecules vector< vector<double> > m_gsbmr; //!< sbmr content at each generation vector< vector<double> > m_gsbmrp; //!< gsbmr at previous time point vector<double> m_lsbmr; //!< last generation sbmr values double m_tgen; //!< last generation time private: FEMultiphasicMultigeneration* m_pmat; }; //----------------------------------------------------------------------------- //! Multigeneration multiphasic material. class FEMultiphasicMultigeneration : public FEMultiphasic { public: //! constructor FEMultiphasicMultigeneration(FEModel* pfem); //! returns a pointer to a new material point object FEMaterialPointData* CreateMaterialPointData() override; //! Update solid bound molecules void UpdateSolidBoundMolecules(FEMaterialPoint& mp) override; int CheckGeneration(const double t); double GetGenerationTime(const int igen); public: double m_gtime; //!< time duration of each generation DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMassActionForwardEffective.cpp
.cpp
4,533
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 "FEMassActionForwardEffective.h" #include "FESoluteInterface.h" #include "FEBiphasic.h" BEGIN_FECORE_CLASS(FEMassActionForwardEffective, FEChemicalReaction) // set material properties ADD_PROPERTY(m_pFwd, "forward_rate", FEProperty::Optional); END_FECORE_CLASS(); //! constructor //----------------------------------------------------------------------------- FEMassActionForwardEffective::FEMassActionForwardEffective(FEModel* pfem) : FEChemicalReaction(pfem) { } //----------------------------------------------------------------------------- //! molar supply at material point double FEMassActionForwardEffective::ReactionSupply(FEMaterialPoint& pt) { // get reaction rate double kF = m_pFwd->ReactionRate(pt); // evaluate the reaction molar supply double zhat = kF; // start with contribution from solutes int nsol = m_psm->Solutes(); for (int i=0; i<nsol; ++i) { int vR = m_vR[i]; if (vR > 0) { double c = m_psm->GetEffectiveSoluteConcentration(pt, i); zhat *= pow(c, vR); } } // add contribution of solid-bound molecules const int nsbm = m_psm->SBMs(); for (int i=0; i<nsbm; ++i) { int vR = m_vR[nsol+i]; if (vR > 0) { double c = m_psm->SBMConcentration(pt, i); zhat *= pow(c, vR); } } return zhat; } //----------------------------------------------------------------------------- //! tangent of molar supply with strain at material point mat3ds FEMassActionForwardEffective::Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& ept = *pt.ExtractData<FEElasticMaterialPoint>(); double J = ept.m_J; double phi0 = pbm->GetReferentialSolidVolumeFraction(pt); double kF = m_pFwd->ReactionRate(pt); mat3ds dkFde = m_pFwd->Tangent_ReactionRate_Strain(pt); double zhat = ReactionSupply(pt); mat3ds dzhatde = mat3dd(0); if (kF > 0) dzhatde = dkFde*(zhat/kF); return dzhatde; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective pressure at material point double FEMassActionForwardEffective::Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) { double kF = m_pFwd->ReactionRate(pt); double dkFdp = m_pFwd->Tangent_ReactionRate_Pressure(pt); double zhat = ReactionSupply(pt); double dzhatdp = 0; if (kF > 0) dzhatdp = dkFdp*zhat/kF; return dzhatdp; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective concentration at material point double FEMassActionForwardEffective::Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) { const int nsol = m_nsol; // if the derivative is taken with respect to a solid-bound molecule, return 0 if (sol >= nsol) return 0; double zhat = ReactionSupply(pt); double dzhatdc = 0; double c = m_psm->GetEffectiveSoluteConcentration(pt, sol); if ((zhat > 0) && (c > 0)) dzhatdc = m_vR[sol]/c*zhat; return dzhatdc; }
C++
3D
febiosoftware/FEBio
FEBioMix/FETriphasicDomain.h
.h
4,077
114
/*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/FESolidDomain.h" #include "FETriphasic.h" #include "FEBioMech/FEElasticDomain.h" #include <FECore/FEDofList.h> //----------------------------------------------------------------------------- //! Domain class for triphasic 3D solid elements //! Note that this class inherits from FEElasticSolidDomain since this domain //! also needs to calculate elastic stiffness contributions. //! class FEBIOMIX_API FETriphasicDomain : public FESolidDomain, public FEElasticDomain { public: //! constructor FETriphasicDomain(FEModel* pfem); //! reset domain data void Reset() override; //! get material (overridden from FEDomain) FEMaterial* GetMaterial() override; //! get the total dof const FEDofList& GetDOFList() const override; //! set the material void SetMaterial(FEMaterial* pmat) override; //! Unpack solid element data (overridden from FEDomain) void UnpackLM(FEElement& el, vector<int>& lm) override; //! activate void Activate() override; //! initialize elements for this domain void PreSolveUpdate(const FETimeInfo& timeInfo) override; // update domain data void Update(const FETimeInfo& tp) override; //! update element state data void UpdateElementStress(int iel); public: // internal work (overridden from FEElasticDomain) void InternalForces(FEGlobalVector& R) override; // internal work (steady-state case) void InternalForcesSS(FEGlobalVector& R); //! calculates the global stiffness matrix for this domain void StiffnessMatrix(FELinearSystem& LS, bool bsymm); //! calculates the global stiffness matrix for this domain (steady-state case) void StiffnessMatrixSS(FELinearSystem& LS, bool bsymm); protected: //! element internal force vector void ElementInternalForce(FESolidElement& el, vector<double>& fe); //! element internal force vector (steady-state case) void ElementInternalForceSS(FESolidElement& el, vector<double>& fe); //! calculates the element triphasic stiffness matrix bool ElementTriphasicStiffness(FESolidElement& el, matrix& ke, bool bsymm); //! calculates the element triphasic stiffness matrix bool ElementTriphasicStiffnessSS(FESolidElement& el, matrix& ke, bool bsymm); protected: // overridden from FEElasticDomain, but not implemented in this domain void BodyForce(FEGlobalVector& R, FEBodyForce& bf) override {} void InertialForces(FEGlobalVector& R, vector<double>& F) override {} void StiffnessMatrix(FELinearSystem& LS) override {} void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) override {} void MassMatrix(FELinearSystem& LS, double scale) override {} protected: FETriphasic* m_pMat; FEDofList m_dofU; FEDofList m_dofR; FEDofList m_dof; int m_dofP; //!< pressure dof index int m_dofC; //!< concentration dof index };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FENodalFluidFlux.cpp
.cpp
2,189
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.*/ #include "stdafx.h" #include "FENodalFluidFlux.h" #include <FECore/FENodeSet.h> #include <FECore/FEMaterialPoint.h> #include <FECore/FENode.h> #include "FEBioMix.h" BEGIN_FECORE_CLASS(FENodalFluidFlux, FENodalLoad) ADD_PARAMETER(m_w, "value"); END_FECORE_CLASS(); FENodalFluidFlux::FENodalFluidFlux(FEModel* fem) : FENodalLoad(fem) { m_w = 0.0; } bool FENodalFluidFlux::SetDofList(FEDofList& dofList) { return dofList.AddVariable(FEBioMix::GetVariableName(FEBioMix::FLUID_PRESSURE)); } void FENodalFluidFlux::GetNodalValues(int inode, std::vector<double>& val) { assert(val.size() == 1); const FENodeSet& nset = *GetNodeSet(); int nid = nset[inode]; const FENode& node = *nset.Node(inode); FEMaterialPoint mp; mp.m_r0 = node.m_r0; mp.m_index = inode; const FETimeInfo& tp = GetTimeInfo(); // for consistency with evaluation of residual and stiffness matrix val[0] = m_w(mp)* tp.timeIncrement; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMassActionReversible.h
.h
2,339
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 "FEChemicalReaction.h" //----------------------------------------------------------------------------- //! Law of mass action for reversible chemical reaction. class FEBIOMIX_API FEMassActionReversible : public FEChemicalReaction { public: //! constructor FEMassActionReversible(FEModel* pfem); //! molar supply at material point double ReactionSupply(FEMaterialPoint& pt) override; //! tangent of molar supply with strain (J) at material point mat3ds Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) override; //! tangent of molar supply with effective pressure at material point double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) override; //! tangent of molar supply with effective concentration at material point double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) override; //! molar supply at material point double FwdReactionSupply(FEMaterialPoint& pt); //! molar supply at material point double RevReactionSupply(FEMaterialPoint& pt); DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEFixedFluidPressure.h
.h
1,501
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/FEFixedBC.h> #include "febiomix_api.h" class FEBIOMIX_API FEFixedFluidPressure : public FEFixedBC { public: FEFixedFluidPressure(FEModel* fem); bool Init() override; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBioMix.cpp
.cpp
27,730
532
/*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 "FEBioMix.h" #include "FEBiphasic.h" #include "FEBiphasicSolute.h" #include "FEMultiphasicStandard.h" #include "FEMultiphasicMultigeneration.h" #include "FESolute.h" #include "FETriphasic.h" #include "FEDiffConstIso.h" #include "FEDiffConstOrtho.h" #include "FEDiffRefIso.h" #include "FEDiffAlbroIso.h" #include "FEPermConstIso.h" #include "FEPermHolmesMow.h" #include "FEPermExpIso.h" #include "FEPermRefIso.h" #include "FEPermRefOrtho.h" #include "FEPermRefTransIso.h" #include "FEOsmCoefConst.h" #include "FEOsmCoefManning.h" #include "FESFDSBM.h" #include "FEFiberExpPowSBM.h" #include "FEFiberPowLinearSBM.h" #include "FESolventSupplyStarling.h" #include "FESolubConst.h" #include "FESolubManning.h" #include "FESupplyBinding.h" #include "FESupplyConst.h" #include "FESupplySynthesisBinding.h" #include "FESupplyMichaelisMenten.h" #include "FECarterHayes.h" #include "FEReactionRateConst.h" #include "FEReactionRateHuiskes.h" #include "FEReactionRateRuberti.h" #include "FEReactionRateNims.h" #include "FEReactionRateExpSED.h" #include "FEReactionRateSoluteAsSBM.h" #include "FEMembraneReactionRateConst.h" #include "FEMembraneReactionRateIonChannel.h" #include "FEMembraneReactionRateVoltageGated.h" #include "FEMassActionForward.h" #include "FEMassActionForwardEffective.h" #include "FEMichaelisMenten.h" #include "FEMassActionReversible.h" #include "FEMassActionReversibleEffective.h" #include "FEConcentrationIndependentReaction.h" #include "FEMembraneMassActionForward.h" #include "FEMembraneMassActionReversible.h" #include "FEActiveConstantSupply.h" #include "FEPorousNeoHookean.h" #include "FEMixtureNormalTraction.h" #include "FEFluidFlux.h" #include "FESoluteFlux.h" #include "FESoluteNaturalFlux.h" #include "FEPressureStabilization.h" #include "FEMatchingOsmoticCoefficientLoad.h" #include "FEMatchingOsmoticCoefficientBC.h" #include "FEMultiphasicFluidPressureLoad.h" #include "FESlidingInterface2.h" #include "FESlidingInterfaceBiphasic.h" #include "FESlidingInterfaceBiphasicMixed.h" #include "FESlidingInterface3.h" #include "FESlidingInterfaceMP.h" #include "FETiedBiphasicInterface.h" #include "FETiedMultiphasicInterface.h" #include "FEBiphasicSolver.h" #include "FEBiphasicSoluteSolver.h" #include "FEMultiphasicSolver.h" #include "FEBioMixPlot.h" #include "FEBioMixData.h" #include "FEMixDomainFactory.h" #include "FEBiphasicSolidDomain.h" #include "FEBiphasicShellDomain.h" #include "FEBiphasicSoluteSolidDomain.h" #include "FEBiphasicSoluteShellDomain.h" #include "FETriphasicDomain.h" #include "FEMultiphasicSolidDomain.h" #include "FEMultiphasicShellDomain.h" #include "FESBMPointSource.h" #include "FESolutePointSource.h" #include "FEFixedFluidPressure.h" #include "FEPrescribedNodalFluidPressure.h" #include "FEFixedConcentration.h" #include "FEPrescribedConcentration.h" #include "FEMultiphasicFluidPressureBC.h" #include "FEInitialEffectiveFluidPressure.h" #include "FEInitialConcentration.h" #include "FENodalFluidFlux.h" #include "FEBiphasicModule.h" #include "FEBiphasicAnalysis.h" #include "FEBiphasicSoluteAnalysis.h" #include "FEMultiphasicAnalysis.h" #include <FECore/FETimeStepController.h> //----------------------------------------------------------------------------- const char* FEBioMix::GetVariableName(FEBioMix::FEBIOMIX_VARIABLE var) { switch (var) { case FLUID_PRESSURE: return "fluid pressure"; break; } assert(false); return nullptr; } //----------------------------------------------------------------------------- //! Initialization of the FEBioMix module. This function registers all the classes //! in this module with the FEBio framework. void FEBioMix::InitModule() { //----------------------------------------------------------------------------- // Domain factory FECoreKernel& febio = FECoreKernel::GetInstance(); febio.RegisterDomain(new FEMixDomainFactory); // extensions to "solid" module febio.SetActiveModule("solid"); REGISTER_FECORE_CLASS(FECarterHayes , "Carter-Hayes"); REGISTER_FECORE_CLASS(FEPorousNeoHookean , "porous neo-Hookean"); REGISTER_FECORE_CLASS(FEFiberExpPowSBM , "fiber-exp-pow sbm" ); REGISTER_FECORE_CLASS(FEFiberPowLinearSBM, "fiber-pow-linear sbm"); REGISTER_FECORE_CLASS(FEMixtureNormalTraction, "normal_traction"); //====================================================================== // setup the "biphasic" module febio.CreateModule(new FEBiphasicModule, "biphasic", "{" " \"title\" : \"Biphasic Analysis\"," " \"info\" : \"Transient or quasi-static biphasic analysis.\"" "}"); febio.AddModuleDependency("solid"); //----------------------------------------------------------------------------- // analyis classes (default type must match module name!) REGISTER_FECORE_CLASS(FEBiphasicAnalysis, "biphasic"); //----------------------------------------------------------------------------- // solver classes REGISTER_FECORE_CLASS(FEBiphasicSolver , "biphasic"); //----------------------------------------------------------------------------- // Domain classes REGISTER_FECORE_CLASS(FEBiphasicSolidDomain, "biphasic-solid"); REGISTER_FECORE_CLASS(FEBiphasicShellDomain, "biphasic-shell"); //----------------------------------------------------------------------------- // Materials REGISTER_FECORE_CLASS(FEBiphasic , "biphasic"); REGISTER_FECORE_CLASS(FEPermConstIso , "perm-const-iso"); REGISTER_FECORE_CLASS(FEPermHolmesMow , "perm-Holmes-Mow"); REGISTER_FECORE_CLASS(FEPermExpIso , "perm-exp-iso"); REGISTER_FECORE_CLASS(FEPermRefIso , "perm-ref-iso"); REGISTER_FECORE_CLASS(FEPermRefOrtho , "perm-ref-ortho"); REGISTER_FECORE_CLASS(FEPermRefTransIso , "perm-ref-trans-iso"); REGISTER_FECORE_CLASS(FESolventSupplyStarling, "Starling"); REGISTER_FECORE_CLASS(FEActiveConstantSupply , "active-const-supply"); //----------------------------------------------------------------------------- // Boundary conditions REGISTER_FECORE_CLASS(FEFixedFluidPressure , "zero fluid pressure"); REGISTER_FECORE_CLASS(FEPrescribedNodalFluidPressure, "prescribed fluid pressure"); REGISTER_FECORE_CLASS(FEPrescribedShellFluidPressure, "prescribed shell fluid pressure"); //----------------------------------------------------------------------------- // Initial conditions REGISTER_FECORE_CLASS(FEInitialEffectiveFluidPressure, "initial fluid pressure"); REGISTER_FECORE_CLASS(FEInitialShellEffectiveFluidPressure, "initial shell fluid pressure"); REGISTER_FECORE_CLASS(FEInitialConcentration , "initial concentration"); REGISTER_FECORE_CLASS(FEInitialShellConcentration, "initial shell concentration"); //----------------------------------------------------------------------------- // Nodal loads REGISTER_FECORE_CLASS(FENodalFluidFlux, "nodal fluidflux"); //----------------------------------------------------------------------------- // Surface loads REGISTER_FECORE_CLASS(FEFluidFlux , "fluidflux"); REGISTER_FECORE_CLASS(FEPressureStabilization, "pressure_stabilization"); //----------------------------------------------------------------------------- // Contact interfaces REGISTER_FECORE_CLASS(FESlidingInterface2 , "sliding2"); REGISTER_FECORE_CLASS(FESlidingInterfaceBiphasic , "sliding-biphasic"); REGISTER_FECORE_CLASS(FESlidingInterfaceBiphasicMixed, "sliding-biphasic-mixed"); REGISTER_FECORE_CLASS(FETiedBiphasicInterface , "tied-biphasic"); //----------------------------------------------------------------------------- // classes derived from FEPlotData REGISTER_FECORE_CLASS(FEPlotMPSpecificStrainEnergy , "specific strain energy"); REGISTER_FECORE_CLASS(FEPlotEffectiveElasticity , "effective elasticity" ); REGISTER_FECORE_CLASS(FEPlotEffectiveFluidPressure , "effective fluid pressure" ); REGISTER_FECORE_CLASS(FEPlotEffectiveShellFluidPressure , "effective shell fluid pressure" ); REGISTER_FECORE_CLASS(FEPlotActualFluidPressure , "fluid pressure" ); REGISTER_FECORE_CLASS(FEPlotFluidFlux , "fluid flux" ); REGISTER_FECORE_CLASS(FEPlotNodalFluidFlux , "nodal fluid flux"); REGISTER_FECORE_CLASS(FEPlotContactGapMP , "contact gap" ); REGISTER_FECORE_CLASS(FEPlotPressureGap , "pressure gap" ); REGISTER_FECORE_CLASS(FEPlotFluidForce , "fluid force" ); REGISTER_FECORE_CLASS(FEPlotFluidForce2 , "fluid force2" ); REGISTER_FECORE_CLASS(FEPlotFluidLoadSupport , "fluid load support" ); REGISTER_FECORE_CLASS(FEPlotMixtureFluidFlowRate , "fluid flow rate" ); REGISTER_FECORE_CLASS(FEPlotReferentialSolidVolumeFraction , "referential solid volume fraction"); REGISTER_FECORE_CLASS(FEPlotPorosity , "porosity" ); REGISTER_FECORE_CLASS(FEPlotPerm , "permeability" ); REGISTER_FECORE_CLASS(FEPlotSolidStress , "solid stress" ); REGISTER_FECORE_CLASS(FEPlotLocalFluidLoadSupport , "local fluid load support" ); REGISTER_FECORE_CLASS(FEPlotEffectiveFrictionCoeff , "effective friction coefficient" ); //----------------------------------------------------------------------------- // Element log data REGISTER_FECORE_CLASS(FELogElemFluidPressure , "p"); REGISTER_FECORE_CLASS(FELogElemFluidFluxX , "wx"); REGISTER_FECORE_CLASS(FELogElemFluidFluxY , "wy"); REGISTER_FECORE_CLASS(FELogElemFluidFluxZ , "wz"); REGISTER_FECORE_CLASS(FELogElemPorosity , "porosity"); REGISTER_FECORE_CLASS_T(FELogElemPermeability_T, 0 , "Kpxx"); REGISTER_FECORE_CLASS_T(FELogElemPermeability_T, 1 , "Kpyy"); REGISTER_FECORE_CLASS_T(FELogElemPermeability_T, 2 , "Kpzz"); REGISTER_FECORE_CLASS_T(FELogElemPermeability_T, 3 , "Kpxy"); REGISTER_FECORE_CLASS_T(FELogElemPermeability_T, 4 , "Kpyz"); REGISTER_FECORE_CLASS_T(FELogElemPermeability_T, 5 , "Kpxz"); REGISTER_FECORE_CLASS_T(FELogElemSolidStress_T, 0, "esxx"); REGISTER_FECORE_CLASS_T(FELogElemSolidStress_T, 1, "esyy"); REGISTER_FECORE_CLASS_T(FELogElemSolidStress_T, 2, "eszz"); REGISTER_FECORE_CLASS_T(FELogElemSolidStress_T, 3, "esxy"); REGISTER_FECORE_CLASS_T(FELogElemSolidStress_T, 4, "esyz"); REGISTER_FECORE_CLASS_T(FELogElemSolidStress_T, 5, "esxz"); //====================================================================== // setup the "solute" module (i.e. biphasic-solute) febio.CreateModule(new FEBiphasicSoluteModule, "solute", "{" " \"title\" : \"Biphasic Solute Analysis\"," " \"info\" : \"Transient or quasi-static biphasic analysis with a single solute.\"" "}"); febio.AddModuleDependency("biphasic"); //----------------------------------------------------------------------------- // Global data classes REGISTER_FECORE_CLASS(FESoluteData, "solute"); //----------------------------------------------------------------------------- // analyis classes (default type must match module name!) REGISTER_FECORE_CLASS(FEBiphasicSoluteAnalysis, "solute"); //----------------------------------------------------------------------------- // solver classes (default type must match module name!) REGISTER_FECORE_CLASS(FEBiphasicSoluteSolver, "solute"); //----------------------------------------------------------------------------- // Domain classes REGISTER_FECORE_CLASS(FEBiphasicSoluteSolidDomain, "biphasic-solute-solid"); REGISTER_FECORE_CLASS(FEBiphasicSoluteShellDomain, "biphasic-solute-shell"); REGISTER_FECORE_CLASS(FETriphasicDomain, "triphasic-solid"); //----------------------------------------------------------------------------- // Materials REGISTER_FECORE_CLASS(FEBiphasicSolute , "biphasic-solute"); REGISTER_FECORE_CLASS(FESoluteMaterial , "solute"); REGISTER_FECORE_CLASS(FETriphasic , "triphasic"); REGISTER_FECORE_CLASS(FEDiffConstIso , "diff-const-iso"); REGISTER_FECORE_CLASS(FEDiffConstOrtho , "diff-const-ortho"); REGISTER_FECORE_CLASS(FEDiffRefIso , "diff-ref-iso"); REGISTER_FECORE_CLASS(FEDiffAlbroIso , "diff-Albro-iso"); REGISTER_FECORE_CLASS(FEOsmCoefConst , "osm-coef-const"); REGISTER_FECORE_CLASS(FEOsmCoefManning , "osm-coef-Manning"); REGISTER_FECORE_CLASS(FESolubConst , "solub-const"); REGISTER_FECORE_CLASS(FESolubManning , "solub-Manning"); REGISTER_FECORE_CLASS(FESupplyBinding , "supply-binding"); REGISTER_FECORE_CLASS(FESupplyConst , "supply-const"); REGISTER_FECORE_CLASS(FESupplySynthesisBinding, "supply-synthesis-binding"); REGISTER_FECORE_CLASS(FESupplyMichaelisMenten , "supply-Michaelis-Menten"); //----------------------------------------------------------------------------- // Surface loads REGISTER_FECORE_CLASS(FESoluteFlux, "soluteflux"); REGISTER_FECORE_CLASS(FESoluteNaturalFlux, "solute natural flux"); REGISTER_FECORE_CLASS(FEMultiphasicFluidPressureLoad, "fluid pressure", 0x0400); // Deprecated, use the BC version. //----------------------------------------------------------------------------- // boundary conditions REGISTER_FECORE_CLASS(FEFixedConcentration, "zero concentration"); REGISTER_FECORE_CLASS(FEPrescribedConcentration, "prescribed concentration"); REGISTER_FECORE_CLASS(FEMultiphasicFluidPressureBC, "actual fluid pressure"); //----------------------------------------------------------------------------- // Contact interfaces REGISTER_FECORE_CLASS(FESlidingInterface3, "sliding-biphasic-solute"); //----------------------------------------------------------------------------- // classes derived from FEPlotData REGISTER_FECORE_CLASS(FEPlotEffectiveSoluteConcentration , "effective solute concentration"); REGISTER_FECORE_CLASS(FEPlotEffectiveShellSoluteConcentration, "effective shell solute concentration"); REGISTER_FECORE_CLASS(FEPlotActualSoluteConcentration , "solute concentration"); REGISTER_FECORE_CLASS(FEPlotConcentrationGap , "concentration gap" ); REGISTER_FECORE_CLASS(FEPlotPartitionCoefficient , "partition coefficient"); REGISTER_FECORE_CLASS(FEPlotSoluteFlux , "solute flux" ); REGISTER_FECORE_CLASS(FEPlotSoluteVolumetricFlux , "solute volumetric flux" ); REGISTER_FECORE_CLASS(FEPlotOsmolarity , "osmolarity"); REGISTER_FECORE_CLASS(FEPlotCurrentDensity , "current density" ); REGISTER_FECORE_CLASS(FEPlotFixedChargeDensity , "fixed charge density"); REGISTER_FECORE_CLASS(FEPlotReferentialFixedChargeDensity , "referential fixed charge density"); REGISTER_FECORE_CLASS(FEPlotElectricPotential , "electric potential" ); //----------------------------------------------------------------------------- // classes derived from FELogNodeData REGISTER_FECORE_CLASS(FENodeConcentration, "c"); REGISTER_FECORE_CLASS(FENodeFluidPressure, "pe"); REGISTER_FECORE_CLASS_T(FENodeSoluteConcentration_T, 0, "ce1"); REGISTER_FECORE_CLASS_T(FENodeSoluteConcentration_T, 1, "ce2"); REGISTER_FECORE_CLASS_T(FENodeSoluteConcentration_T, 2, "ce3"); REGISTER_FECORE_CLASS_T(FENodeSoluteConcentration_T, 3, "ce4"); REGISTER_FECORE_CLASS_T(FENodeSoluteConcentration_T, 4, "ce5"); REGISTER_FECORE_CLASS_T(FENodeSoluteConcentration_T, 5, "ce6"); REGISTER_FECORE_CLASS_T(FENodeSoluteConcentration_T, 6, "ce7"); REGISTER_FECORE_CLASS_T(FENodeSoluteConcentration_T, 7, "ce8"); //----------------------------------------------------------------------------- // Element log data REGISTER_FECORE_CLASS(FELogElemSoluteConcentration , "c"); REGISTER_FECORE_CLASS(FELogElemSoluteFluxX , "jx"); REGISTER_FECORE_CLASS(FELogElemSoluteFluxY , "jy"); REGISTER_FECORE_CLASS(FELogElemSoluteFluxZ , "jz"); REGISTER_FECORE_CLASS(FELogElemSoluteRefConcentration, "crc"); REGISTER_FECORE_CLASS(FELogFixedChargeDensity , "cF"); REGISTER_FECORE_CLASS_T(FELogElemSoluteConcentration_T, 0, "c1"); REGISTER_FECORE_CLASS_T(FELogElemSoluteConcentration_T, 1, "c2"); REGISTER_FECORE_CLASS_T(FELogElemSoluteConcentration_T, 2, "c3"); REGISTER_FECORE_CLASS_T(FELogElemSoluteConcentration_T, 3, "c4"); REGISTER_FECORE_CLASS_T(FELogElemSoluteConcentration_T, 4, "c5"); REGISTER_FECORE_CLASS_T(FELogElemSoluteConcentration_T, 5, "c6"); REGISTER_FECORE_CLASS_T(FELogElemSoluteConcentration_T, 6, "c7"); REGISTER_FECORE_CLASS_T(FELogElemSoluteConcentration_T, 7, "c8"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxX_T, 0, "j1x"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxY_T, 0, "j1y"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxZ_T, 0, "j1z"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxX_T, 1, "j2x"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxY_T, 1, "j2y"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxZ_T, 1, "j2z"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxX_T, 2, "j3x"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxY_T, 2, "j3y"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxZ_T, 2, "j3z"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxX_T, 3, "j4x"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxY_T, 3, "j4y"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxZ_T, 3, "j4z"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxX_T, 4, "j5x"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxY_T, 4, "j5y"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxZ_T, 4, "j5z"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxX_T, 5, "j6x"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxY_T, 5, "j6y"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxZ_T, 5, "j6z"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxX_T, 6, "j7x"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxY_T, 6, "j7y"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxZ_T, 6, "j7z"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxX_T, 7, "j8x"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxY_T, 7, "j8y"); REGISTER_FECORE_CLASS_T(FELogElemSoluteFluxZ_T, 7, "j8z"); //====================================================================== // setup the "multiphasic" module febio.CreateModule(new FEMultiphasicModule, "multiphasic", "{" " \"title\" : \"Multiphasic Analysis\"," " \"info\" : \"Transient or quasi-static analysis with solutes.\"" "}"); febio.AddModuleDependency("solute"); //----------------------------------------------------------------------------- // Global data classes REGISTER_FECORE_CLASS(FESBMData, "solid_bound"); //----------------------------------------------------------------------------- // analyis classes (default type must match module name!) REGISTER_FECORE_CLASS(FEMultiphasicAnalysis, "multiphasic"); //----------------------------------------------------------------------------- // solver classes REGISTER_FECORE_CLASS(FEMultiphasicSolver , "multiphasic"); //----------------------------------------------------------------------------- // Domain classes REGISTER_FECORE_CLASS(FEMultiphasicSolidDomain, "multiphasic-solid"); REGISTER_FECORE_CLASS(FEMultiphasicShellDomain, "multiphasic-shell"); //----------------------------------------------------------------------------- // Materials REGISTER_FECORE_CLASS(FEMultiphasicStandard , "multiphasic" ); REGISTER_FECORE_CLASS(FEMultiphasicMultigeneration , "multiphasic-multigeneration"); REGISTER_FECORE_CLASS(FESFDSBM , "spherical fiber distribution sbm"); REGISTER_FECORE_CLASS(FEReactionRateConst , "constant reaction rate" ); REGISTER_FECORE_CLASS(FEReactionRateHuiskes , "Huiskes reaction rate" ); REGISTER_FECORE_CLASS(FEReactionRateRuberti , "Ruberti reaction rate" ); REGISTER_FECORE_CLASS(FEReactionRateNims , "Nims reaction rate" ); REGISTER_FECORE_CLASS(FEReactionRateExpSED , "exp-sed reaction rate" ); REGISTER_FECORE_CLASS(FEReactionRateSoluteAsSBM , "solute-as-sbm reaction rate"); REGISTER_FECORE_CLASS(FEMembraneReactionRateConst , "membrane constant reaction rate"); REGISTER_FECORE_CLASS(FEMembraneReactionRateIonChannel , "membrane ion channel reaction rate"); REGISTER_FECORE_CLASS(FEMembraneReactionRateVoltageGated , "membrane voltage-gated reaction rate"); REGISTER_FECORE_CLASS(FEMassActionForward , "mass-action-forward" ); REGISTER_FECORE_CLASS(FEMassActionForwardEffective , "mass-action-forward-effective"); REGISTER_FECORE_CLASS(FEMembraneMassActionForward , "membrane-mass-action-forward"); REGISTER_FECORE_CLASS(FEConcentrationIndependentReaction , "concentration-independent"); REGISTER_FECORE_CLASS(FEMassActionReversible , "mass-action-reversible" ); REGISTER_FECORE_CLASS(FEMassActionReversibleEffective , "mass-action-reversible-effective"); REGISTER_FECORE_CLASS(FEMembraneMassActionReversible , "membrane-mass-action-reversible"); REGISTER_FECORE_CLASS(FEMichaelisMenten , "Michaelis-Menten" ); REGISTER_FECORE_CLASS(FESolidBoundMolecule , "solid_bound" ); REGISTER_FECORE_CLASS(FEReactantSpeciesRef, "vR"); REGISTER_FECORE_CLASS(FEProductSpeciesRef , "vP"); REGISTER_FECORE_CLASS(FEInternalReactantSpeciesRef, "vRi"); REGISTER_FECORE_CLASS(FEInternalProductSpeciesRef , "vPi"); REGISTER_FECORE_CLASS(FEExternalReactantSpeciesRef, "vRe"); REGISTER_FECORE_CLASS(FEExternalProductSpeciesRef , "vPe"); //----------------------------------------------------------------------------- // Surface loads REGISTER_FECORE_CLASS(FEMatchingOsmoticCoefficientLoad, "matching_osm_coef", 0x0300); // deprecated, use BC version //----------------------------------------------------------------------------- // Boundary conditions REGISTER_FECORE_CLASS(FEMatchingOsmoticCoefficientBC, "matching_osm_coef"); //----------------------------------------------------------------------------- // Body loads REGISTER_FECORE_CLASS(FESBMPointSource , "sbm point source"); REGISTER_FECORE_CLASS(FESolutePointSource, "solute point source"); //----------------------------------------------------------------------------- // Contact interfaces REGISTER_FECORE_CLASS(FESlidingInterfaceMP , "sliding-multiphasic" ); REGISTER_FECORE_CLASS(FEAmbientConcentration , "ambient_concentration" ); REGISTER_FECORE_CLASS(FETiedMultiphasicInterface, "tied-multiphasic" ); //----------------------------------------------------------------------------- // classes derived from FEPlotData REGISTER_FECORE_CLASS(FEPlotReceptorLigandConcentration , "receptor-ligand concentration" ); REGISTER_FECORE_CLASS(FEPlotSBMConcentration , "sbm concentration" ); REGISTER_FECORE_CLASS(FEPlotSBMArealConcentration , "sbm areal concentration" ); REGISTER_FECORE_CLASS(FEPlotSBMRefAppDensity , "sbm referential apparent density"); REGISTER_FECORE_CLASS(FEPlotOsmoticCoefficient , "osmotic coefficient" ); //----------------------------------------------------------------------------- // Element log data REGISTER_FECORE_CLASS(FELogElemElectricPotential , "psi"); REGISTER_FECORE_CLASS(FELogElemCurrentDensityX , "Iex"); REGISTER_FECORE_CLASS(FELogElemCurrentDensityY , "Iey"); REGISTER_FECORE_CLASS(FELogElemCurrentDensityZ , "Iez"); REGISTER_FECORE_CLASS_T(FELogElemSBMConcentration_T, 0, "sbm1"); REGISTER_FECORE_CLASS_T(FELogElemSBMConcentration_T, 1, "sbm2"); REGISTER_FECORE_CLASS_T(FELogElemSBMConcentration_T, 2, "sbm3"); REGISTER_FECORE_CLASS_T(FELogElemSBMConcentration_T, 3, "sbm4"); REGISTER_FECORE_CLASS_T(FELogElemSBMConcentration_T, 4, "sbm5"); REGISTER_FECORE_CLASS_T(FELogElemSBMConcentration_T, 5, "sbm6"); REGISTER_FECORE_CLASS_T(FELogElemSBMConcentration_T, 6, "sbm7"); REGISTER_FECORE_CLASS_T(FELogElemSBMConcentration_T, 7, "sbm8"); REGISTER_FECORE_CLASS_T(FELogSBMRefAppDensity_T, 1, "sbm1_referential_apparent_density"); REGISTER_FECORE_CLASS_T(FELogSBMRefAppDensity_T, 2, "sbm2_referential_apparent_density"); REGISTER_FECORE_CLASS_T(FELogSBMRefAppDensity_T, 3, "sbm3_referential_apparent_density"); REGISTER_FECORE_CLASS_T(FELogSBMRefAppDensity_T, 4, "sbm4_referential_apparent_density"); REGISTER_FECORE_CLASS_T(FELogSBMRefAppDensity_T, 5, "sbm5_referential_apparent_density"); REGISTER_FECORE_CLASS_T(FELogSBMRefAppDensity_T, 6, "sbm6_referential_apparent_density"); REGISTER_FECORE_CLASS_T(FELogSBMRefAppDensity_T, 7, "sbm7_referential_apparent_density"); REGISTER_FECORE_CLASS_T(FELogSBMRefAppDensity_T, 8, "sbm8_referential_apparent_density"); //----------------------------------------------------------------------------- // domain log data REGISTER_FECORE_CLASS_T(FELogDomainIntegralSBMConcentration_T, 0, "sbm1_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSBMConcentration_T, 1, "sbm2_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSBMConcentration_T, 2, "sbm3_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSBMConcentration_T, 3, "sbm4_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSBMConcentration_T, 4, "sbm5_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSBMConcentration_T, 5, "sbm6_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSBMConcentration_T, 6, "sbm7_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSBMConcentration_T, 7, "sbm8_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSoluteConcentration_T, 0, "c1_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSoluteConcentration_T, 1, "c2_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSoluteConcentration_T, 2, "c3_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSoluteConcentration_T, 3, "c4_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSoluteConcentration_T, 4, "c5_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSoluteConcentration_T, 5, "c6_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSoluteConcentration_T, 6, "c7_integral"); REGISTER_FECORE_CLASS_T(FELogDomainIntegralSoluteConcentration_T, 7, "c8_integral"); febio.SetActiveModule(0); }
C++
3D
febiosoftware/FEBio
FEBioMix/FEFluidFlux.h
.h
2,597
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/FESurfaceLoad.h> #include <FECore/FEModelParam.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! This boundary condition sustains a fluid flux on a surface //! class FEBIOMIX_API FEFluidFlux : public FESurfaceLoad { public: //! constructor FEFluidFlux(FEModel* pfem); void SetLinear(bool blinear) { m_blinear = blinear; } void SetMixture(bool bmix) { m_bmixture = bmix; } // initialization bool Init() override; // serialization void Serialize(DumpStream& ar) override; //! Set the surface to apply the load to void SetSurface(FESurface* ps) override; //! calculate flux stiffness void StiffnessMatrix(FELinearSystem& LS) override; //! calculate residual void LoadVector(FEGlobalVector& R) override; private: // evaluate solid velocity at integration point vec3d SolidVelocity(FESurfaceMaterialPoint& pt); protected: FEParamDouble m_flux; //!< fluid flux bool m_bmixture; //!< mixture velocity or relative fluid flux bool m_bshellb; //!< flag for prescribing flux on shell bottom bool m_blinear; //!< type (linear or nonlinear) // degrees of freedom FEDofList m_dofP; // pressure FEDofList m_dofU; // displacement FEDofList m_dofV; // velocity DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPrescribedNodalFluidPressure.cpp
.cpp
2,695
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) 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 "FEPrescribedNodalFluidPressure.h" //======================================================================================= // NOTE: I'm setting FEBoundaryCondition is the base class since I don't want to pull // in the parameters of FEPrescribedDOF. BEGIN_FECORE_CLASS(FEPrescribedNodalFluidPressure, FEBoundaryCondition) ADD_PARAMETER(m_scale, "value")->setUnits(UNIT_PRESSURE)->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE); ADD_PARAMETER(m_brelative, "relative"); END_FECORE_CLASS(); FEPrescribedNodalFluidPressure::FEPrescribedNodalFluidPressure(FEModel* fem) : FEPrescribedDOF(fem) { } bool FEPrescribedNodalFluidPressure::Init() { if (SetDOF("p") == false) return false; return FEPrescribedDOF::Init(); } //======================================================================================= // NOTE: I'm setting FEBoundaryCondition is the base class since I don't want to pull // in the parameters of FEPrescribedDOF. BEGIN_FECORE_CLASS(FEPrescribedShellFluidPressure, FEBoundaryCondition) ADD_PARAMETER(m_scale, "value")->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE); ADD_PARAMETER(m_brelative, "relative"); END_FECORE_CLASS(); FEPrescribedShellFluidPressure::FEPrescribedShellFluidPressure(FEModel* fem) : FEPrescribedDOF(fem) { } bool FEPrescribedShellFluidPressure::Init() { if (SetDOF("q") == false) return false; return FEPrescribedDOF::Init(); }
C++
3D
febiosoftware/FEBio
FEBioMix/FEChemicalReaction.cpp
.cpp
7,423
221
/*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 "FEChemicalReaction.h" #include <FECore/FEElementTraits.h> #include <FECore/DOFS.h> #include <FECore/FEModel.h> #include <FECore/log.h> #include "FESoluteInterface.h" #include "FESolute.h" #include <stdlib.h> //============================================================================= BEGIN_FECORE_CLASS(FEChemicalReaction, FEReaction) ADD_PARAMETER(m_Vovr, "override_vbar")->SetFlags(FE_PARAM_WATCH); ADD_PARAMETER(m_Vbar , "Vbar")->SetWatchVariable(&m_Vovr); ADD_PROPERTY(m_vRtmp, "vR", FEProperty::Optional)->SetLongName("Reactants"); ADD_PROPERTY(m_vPtmp, "vP", FEProperty::Optional)->SetLongName("Products"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEChemicalReaction::FEChemicalReaction(FEModel* pfem) : FEReaction(pfem) { // additional initializations m_Vbar = 0.0; m_Vovr = false; m_nsol = -1; m_pFwd = m_pRev = 0; } //----------------------------------------------------------------------------- bool FEChemicalReaction::Init() { // set the parents for the reaction rates if (m_pFwd) m_pFwd->m_pReact = this; if (m_pRev) m_pRev->m_pReact = this; // initialize base class if (FEReaction::Init() == false) return false; // initialize the reaction coefficients int isol, isbm, itot; int nsol = m_psm->Solutes(); int nsbm = m_psm->SBMs(); int ntot = nsol + nsbm; // initialize the stoichiometric coefficients to zero m_nsol = nsol; m_vR.assign(ntot, 0); m_vP.assign(ntot, 0); m_v.assign(ntot, 0); // create the intmaps for (int i = 0; i < m_vRtmp.size(); ++i) { FEReactionSpeciesRef* pvr = m_vRtmp[i]; pvr->Init(); if (pvr->IsSolute()) SetStoichiometricCoefficient(m_solR, pvr->m_speciesID - 1, pvr->m_v); if (pvr->IsSBM() ) SetStoichiometricCoefficient(m_sbmR, pvr->m_speciesID - 1, pvr->m_v); } for (int i = 0; i < m_vPtmp.size(); ++i) { FEReactionSpeciesRef* pvp = m_vPtmp[i]; pvp->Init(); if (pvp->IsSolute()) SetStoichiometricCoefficient(m_solP, pvp->m_speciesID - 1, pvp->m_v); if (pvp->IsSBM() ) SetStoichiometricCoefficient(m_sbmP, pvp->m_speciesID - 1, pvp->m_v); } // cycle through all the solutes in the mixture and determine // if they participate in this reaction itrmap it; intmap solR = m_solR; intmap solP = m_solP; for (isol = 0; isol<nsol; ++isol) { int sid = m_psm->GetSolute(isol)->GetSoluteID() - 1; it = solR.find(sid); if (it != solR.end()) m_vR[isol] = it->second; it = solP.find(sid); if (it != solP.end()) m_vP[isol] = it->second; } // cycle through all the solid-bound molecules in the mixture // and determine if they participate in this reaction intmap sbmR = m_sbmR; intmap sbmP = m_sbmP; for (isbm = 0; isbm<nsbm; ++isbm) { int sid = m_psm->GetSBM(isbm)->GetSBMID() - 1; it = sbmR.find(sid); if (it != sbmR.end()) m_vR[nsol + isbm] = it->second; it = sbmP.find(sid); if (it != sbmP.end()) m_vP[nsol + isbm] = it->second; } // evaluate the net stoichiometric coefficient for (itot = 0; itot<ntot; ++itot) { m_v[itot] = m_vP[itot] - m_vR[itot]; } // evaluate the weighted molar volume of reactants and products if (!m_Vovr) { m_Vbar = 0; for (isol = 0; isol<nsol; ++isol) { FESolute* sol = m_psm->GetSolute(isol); m_Vbar += m_v[isol] * sol->MolarMass() / sol->Density(); } for (isbm = 0; isbm < nsbm; ++isbm) { FESolidBoundMolecule* sbm = m_psm->GetSBM(isbm); m_Vbar += m_v[nsol + isbm] * sbm->MolarMass() / sbm->Density(); } } // check that the chemical reaction satisfies electroneutrality int znet = 0; for (isol = 0; isol<nsol; ++isol) { znet += m_v[isol] * m_psm->GetSolute(isol)->ChargeNumber(); } for (isbm = 0; isbm < nsbm; ++isbm) { znet += m_v[nsol + isbm] * m_psm->GetSBM(isbm)->ChargeNumber(); } if (znet != 0) { feLogError("chemical reaction must satisfy electroneutrality"); return false; } if (m_pFwd && !m_pFwd->Init()) return false; if (m_pRev && !m_pRev->Init()) return false; return true; } //----------------------------------------------------------------------------- //! Data serialization void FEChemicalReaction::Serialize(DumpStream& ar) { FEReaction::Serialize(ar); if (ar.IsShallow() == false) { if (ar.IsSaving()) { itrmap p; ar << m_nsol << m_vR << m_vP << m_v << m_Vovr; ar << (int) m_solR.size(); for (p = m_solR.begin(); p!=m_solR.end(); ++p) {ar << p->first; ar << p->second;} ar << (int) m_solP.size(); for (p = m_solP.begin(); p!=m_solP.end(); ++p) {ar << p->first; ar << p->second;} ar << (int) m_sbmR.size(); for (p = m_sbmR.begin(); p!=m_sbmR.end(); ++p) {ar << p->first; ar << p->second;} ar << (int) m_sbmP.size(); for (p = m_sbmP.begin(); p!=m_sbmP.end(); ++p) {ar << p->first; ar << p->second;} } else { // restore pointers if (m_pFwd) m_pFwd->m_pReact = this; if (m_pRev) m_pRev->m_pReact = this; ar >> m_nsol >> m_vR >> m_vP >> m_v >> m_Vovr; int size, id, vR; ar >> size; for (int i=0; i<size; ++i) { ar >> id; ar >> vR; SetStoichiometricCoefficient(m_solR, id, vR); } ar >> size; for (int i=0; i<size; ++i) { ar >> id; ar >> vR; SetStoichiometricCoefficient(m_solP, id, vR); } ar >> size; for (int i=0; i<size; ++i) { ar >> id; ar >> vR; SetStoichiometricCoefficient(m_sbmR, id, vR); } ar >> size; for (int i=0; i<size; ++i) { ar >> id; ar >> vR; SetStoichiometricCoefficient(m_sbmP, id, vR); } } } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMembraneMassActionReversible.h
.h
2,751
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 "FEMembraneReaction.h" //----------------------------------------------------------------------------- //! Law of mass action for reversible membrane reaction //! (must use effective concentrations). class FEBIOMIX_API FEMembraneMassActionReversible : public FEMembraneReaction { public: //! constructor FEMembraneMassActionReversible(FEModel* pfem); //! molar supply at material point double ReactionSupply(FEMaterialPoint& pt) override; //! tangent of molar supply with strain at material point double Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) override; //! tangent of molar supply with effective pressure at material point double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) override; double Tangent_ReactionSupply_Pi(FEMaterialPoint& pt) override; double Tangent_ReactionSupply_Pe(FEMaterialPoint& pt) override; //! tangent of molar supply with effective concentration at material point double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) override; double Tangent_ReactionSupply_Ci(FEMaterialPoint& pt, const int sol) override; double Tangent_ReactionSupply_Ce(FEMaterialPoint& pt, const int sol) override; //! molar supply at material point double FwdReactionSupply(FEMaterialPoint& pt); //! molar supply at material point double RevReactionSupply(FEMaterialPoint& pt); DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSolute.cpp
.cpp
11,517
364
/*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 "FEBiphasicSolute.h" #include <FECore/FEModel.h> #include <FECore/FECoreKernel.h> #include <FECore/log.h> //============================================================================= // B I P H A S I C S O L U T E //============================================================================= //----------------------------------------------------------------------------- // Material parameters for the FEBiphasicSolute material BEGIN_FECORE_CLASS(FEBiphasicSolute, FEMaterial) ADD_PARAMETER(m_phi0 , FE_RANGE_CLOSED(0.0, 1.0) , "phi0"); ADD_PARAMETER(m_rhoTw, FE_RANGE_GREATER_OR_EQUAL(0.0), "fluid_density"); // set material properties ADD_PROPERTY(m_pSolid , "solid", FEProperty::Required | FEProperty::TopLevel); ADD_PROPERTY(m_pPerm , "permeability"); ADD_PROPERTY(m_pOsmC , "osmotic_coefficient"); ADD_PROPERTY(m_pSolute, "solute"); ADD_PROPERTY(m_Q, "mat_axis", FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! FEBiphasicSolute constructor FEBiphasicSolute::FEBiphasicSolute(FEModel* pfem) : FEMaterial(pfem) { m_phi0 = 0; m_rhoTw = 0; m_rhoTu = 0; m_Mu = 0; m_Rgas = 0; m_Tabs = 0; m_pSolid = 0; m_pPerm = 0; m_pOsmC = 0; m_pSolute = 0; } //----------------------------------------------------------------------------- FEMaterialPointData* FEBiphasicSolute::CreateMaterialPointData() { FEBiphasicMaterialPoint* pbp = new FEBiphasicMaterialPoint(m_pSolid->CreateMaterialPointData()); return new FESolutesMaterialPoint(pbp); } //----------------------------------------------------------------------------- bool FEBiphasicSolute::Init() { // we need to set the solute ID before we call FEMaterial::Init() // because it is used in FESolute::Init() m_pSolute->SetSoluteLocalID(0); if (!m_pSolid->Init()) return false; if (!m_pPerm->Init()) return false; if (!m_pOsmC->Init()) return false; if (!m_pSolute->Init()) return false; // Call base class which calls the Init member of all properties if (FEMaterial::Init() == false) return false; m_Rgas = GetFEModel()->GetGlobalConstant("R"); m_Tabs = GetFEModel()->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; } //----------------------------------------------------------------------------- // update specialized material points void FEBiphasicSolute::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { m_pSolid->UpdateSpecializedMaterialPoints(mp, tp); m_pPerm->UpdateSpecializedMaterialPoints(mp, tp); m_pOsmC->UpdateSpecializedMaterialPoints(mp, tp); m_pSolute->UpdateSpecializedMaterialPoints(mp, tp); } //----------------------------------------------------------------------------- void FEBiphasicSolute::Serialize(DumpStream& ar) { FEMaterial::Serialize(ar); if (ar.IsShallow()) return; ar & m_Rgas & m_Tabs & m_Mu; } //----------------------------------------------------------------------------- //! Porosity in current configuration double FEBiphasicSolute::Porosity(FEMaterialPoint& pt) { FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pet = *pt.ExtractData<FEBiphasicMaterialPoint>(); // relative volume double J = et.m_J; // porosity // double phiw = 1 - m_phi0/J; double phi0 = pet.m_phi0t; double phiw = 1 - phi0/J; // check for pore collapse // TODO: throw an error if pores collapse phiw = (phiw > 0) ? phiw : 0; return phiw; } //----------------------------------------------------------------------------- //! The stress of a solute-poroelastic material is the sum of the fluid pressure //! and the elastic stress. Note that this function is declared in the base class //! so you do not have to reimplement it in a derived class, unless additional //! pressure terms are required. mat3ds FEBiphasicSolute::Stress(FEMaterialPoint& mp) { FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // calculate solid material stress mat3ds s = m_pSolid->Stress(mp); // add fluid pressure s.xx() -= pt.m_pa; s.yy() -= pt.m_pa; s.zz() -= pt.m_pa; return s; } //----------------------------------------------------------------------------- //! The tangent is the elastic tangent. Note //! that this function is declared in the base class, so you don't have to //! reimplement it unless additional tangent components are required. tens4ds FEBiphasicSolute::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& ept = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& ppt = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); // call solid tangent routine tens4ds C = m_pSolid->Tangent(mp); // relative volume double J = ept.m_J; // fluid pressure and solute concentration double p = ppt.m_pa; double c = spt.m_c[0]; // solubility and its derivative w.r.t. strain double kappa = m_pSolute->m_pSolub->Solubility(mp); double dkdJ = m_pSolute->m_pSolub->Tangent_Solubility_Strain(mp); // osmotic coefficient and its derivative w.r.t. strain double osmc = m_pOsmC->OsmoticCoefficient(mp); double dodJ = m_pOsmC->Tangent_OsmoticCoefficient_Strain(mp); double dp = m_Rgas*m_Tabs*c*J*(dodJ*kappa+osmc*dkdJ); // adjust tangent for pressures double D[6][6] = {0}; C.extract(D); D[0][0] -= -p + dp; D[1][1] -= -p + dp; D[2][2] -= -p + dp; D[0][1] -= p + dp; D[1][0] -= p + dp; D[1][2] -= p + dp; D[2][1] -= p + dp; D[0][2] -= p + dp; D[2][0] -= p + dp; D[3][3] -= -p; D[4][4] -= -p; D[5][5] -= -p; return tens4ds(D); } //----------------------------------------------------------------------------- //! Calculate fluid flux vec3d FEBiphasicSolute::FluidFlux(FEMaterialPoint& pt) { FEBiphasicMaterialPoint& ppt = *pt.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); // pressure gradient vec3d gradp = ppt.m_gradp; // concentration double c = spt.m_c[0]; // concentration gradient vec3d gradc = spt.m_gradc[0]; // hydraulic permeability mat3ds kt = m_pPerm->Permeability(pt); // solute diffusivity in mixture mat3ds D = m_pSolute->m_pDiff->Diffusivity(pt); // solute free diffusivity double D0 = m_pSolute->m_pDiff->Free_Diffusivity(pt); // solubility double kappa = m_pSolute->m_pSolub->Solubility(pt); // identity matrix mat3dd I(1); // effective hydraulic permeability mat3ds ke = kt.inverse() + (I-D/D0)*(m_Rgas*m_Tabs*kappa*c/phiw/D0); ke = ke.inverse(); // fluid flux w vec3d w = -(ke*(gradp + (D*gradc)*(m_Rgas*m_Tabs*kappa/D0))); return w; } //----------------------------------------------------------------------------- //! Calculate solute molar flux vec3d FEBiphasicSolute::SoluteFlux(FEMaterialPoint& pt) { FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); // concentration double c = spt.m_c[0]; // concentration gradient vec3d gradc = spt.m_gradc[0]; // solute diffusivity in mixture mat3ds D = m_pSolute->m_pDiff->Diffusivity(pt); // solute free diffusivity double D0 = m_pSolute->m_pDiff->Free_Diffusivity(pt); // solubility double kappa = m_pSolute->m_pSolub->Solubility(pt); // fluid flux w vec3d w = FluidFlux(pt); // solute flux j vec3d j = D*(w*(c/D0) - gradc*phiw)*kappa; return j; } //----------------------------------------------------------------------------- //! actual fluid pressure double FEBiphasicSolute::Pressure(FEMaterialPoint& pt) { FEBiphasicMaterialPoint& ppt = *pt.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // effective pressure double p = ppt.m_p; // effective concentration double c = spt.m_c[0]; // osmotic coefficient double osmc = m_pOsmC->OsmoticCoefficient(pt); // solubility double kappa = m_pSolute->m_pSolub->Solubility(pt); // actual pressure double pa = p + m_Rgas*m_Tabs*osmc*kappa*c; return pa; } //----------------------------------------------------------------------------- //! actual concentration double FEBiphasicSolute::Concentration(FEMaterialPoint& pt) { FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // solubility double kappa = m_pSolute->m_pSolub->Solubility(pt); // actual concentration = solubility * effective concentration double ca = kappa*spt.m_c[0]; return ca; } //----------------------------------------------------------------------------- //! referential solute concentration double FEBiphasicSolute::ReferentialConcentration(FEMaterialPoint& pt) { FEElasticMaterialPoint& ept = *pt.ExtractData<FEElasticMaterialPoint>(); double J = ept.m_J; double phiw = Porosity(pt); double cr = J*phiw*Concentration(pt); return cr; } //----------------------------------------------------------------------------- //! partition coefficients and their derivatives void FEBiphasicSolute::PartitionCoefficientFunctions(FEMaterialPoint& mp, double& kappa, double& dkdJ, double& dkdc) { // evaluate the solubility and its derivatives w.r.t. J and c kappa = m_pSolute->m_pSolub->Solubility(mp); dkdJ = m_pSolute->m_pSolub->Tangent_Solubility_Strain(mp); dkdc = m_pSolute->m_pSolub->Tangent_Solubility_Concentration(mp,0); } double FEBiphasicSolute::GetReferentialFixedChargeDensity(const FEMaterialPoint& mp) { const FEElasticMaterialPoint* ept = (mp.ExtractData<FEElasticMaterialPoint >()); const FEBiphasicMaterialPoint* bpt = (mp.ExtractData<FEBiphasicMaterialPoint>()); const FESolutesMaterialPoint* spt = (mp.ExtractData<FESolutesMaterialPoint >()); double cf = (ept->m_J - bpt->m_phi0t) * spt->m_cF / (1 - bpt->m_phi0); return cf; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEFiberExpPowSBM.h
.h
3,552
94
/*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 <FEBioMech/FEElasticMaterial.h> #include <FEBioMech/FERemodelingElasticMaterial.h> #include <FECore/FEModelParam.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Material class for single fiber, tension only //! Exponential-power law //! Fiber modulus depends on SBM content class FEBIOMIX_API FEFiberExpPowSBM : public FEElasticMaterial, public FERemodelingInterface { public: FEFiberExpPowSBM(FEModel* pfem) : FEElasticMaterial(pfem) { m_sbm = -1; m_fiber = nullptr; } //! Initialization bool Init() override; //! Cauchy stress mat3ds Stress(FEMaterialPoint& mp) override; // Spatial tangent tens4ds Tangent(FEMaterialPoint& mp) override; //! Strain energy density double StrainEnergyDensity(FEMaterialPoint& mp) override; //! evaluate referential mass density double Density(FEMaterialPoint& pt) override; //! return fiber modulus double FiberModulus(FEMaterialPoint& pt, double rhor) { return m_ksi0(pt)*pow(rhor/m_rho0(pt), m_g(pt));} //! Create material point data FEMaterialPointData* CreateMaterialPointData() override; //! update specialize material point data void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) override; public: // --- remodeling interface --- //! calculate strain energy density at material point double StrainEnergy(FEMaterialPoint& pt) override; //! calculate tangent of strain energy density with mass density double Tangent_SE_Density(FEMaterialPoint& pt) override; //! calculate tangent of stress with mass density mat3ds Tangent_Stress_Density(FEMaterialPoint& pt) override; public: FEParamDouble m_alpha; // coefficient of (In-1) in exponential FEParamDouble m_beta; // power of (In-1) in exponential FEParamDouble m_ksi0; // fiber modulus ksi = ksi0*(rhor/rho0)^gamma FEParamDouble m_rho0; // rho0 FEParamDouble m_g; // gamma int m_lsbm; //!< local id of solid-bound molecule public: FEVec3dValuator* m_fiber; //!< fiber orientation // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicFluidPressureBC.h
.h
2,438
72
/*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/FEPrescribedBC.h> #include <FECore/FEModelParam.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Prescribe the actual fluid pressure in a multiphasic mixture //! class FEBIOMIX_API FEMultiphasicFluidPressureBC : public FEPrescribedSurface { public: //! constructor FEMultiphasicFluidPressureBC(FEModel* pfem); //! set the dilatation void Update() override; //! initialize bool Init() override; //! serialization void Serialize(DumpStream& ar) override; public: // return the value for node i, dof j void GetNodalValues(int nodelid, std::vector<double>& val) override; // copy data from another class void CopyFrom(FEBoundaryCondition* pbc) override; private: FEParamDouble m_p; //!< prescribed fluid pressure vector<double> m_pe; //!< effective fluid pressure private: double m_Rgas; double m_Tabs; int m_dofP; int m_dofC; public: bool m_bshellb; //!< flag for prescribing pressure on shell bottom DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasic.cpp
.cpp
34,405
1,014
/*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 "FEMultiphasic.h" #include <FECore/FEModel.h> #include <FECore/FECoreKernel.h> #include <FECore/log.h> #include <FECore/tens4d.h> #include <FECore/tools.h> #include <complex> using namespace std; #ifndef SQR #define SQR(x) ((x)*(x)) #endif // Material parameters for the FEMultiphasic material BEGIN_FECORE_CLASS(FEMultiphasic, FEMaterial) ADD_PARAMETER(m_phi0 , FE_RANGE_CLOSED (0.0, 1.0), "phi0" ); ADD_PARAMETER(m_rhoTw , FE_RANGE_GREATER_OR_EQUAL(0.0), "fluid_density"); ADD_PARAMETER(m_penalty, FE_RANGE_GREATER_OR_EQUAL(0.0), "penalty" ); ADD_PARAMETER(m_cFr , "fixed_charge_density"); // define the material properties ADD_PROPERTY(m_pSolid , "solid" , FEProperty::Required | FEProperty::TopLevel); ADD_PROPERTY(m_pPerm , "permeability" ); ADD_PROPERTY(m_pOsmC , "osmotic_coefficient"); ADD_PROPERTY(m_pSupp , "solvent_supply" , FEProperty::Optional); ADD_PROPERTY(m_pSolute, "solute" , FEProperty::Optional); ADD_PROPERTY(m_pSBM , "solid_bound" , FEProperty::Optional); ADD_PROPERTY(m_pReact , "reaction" , FEProperty::Optional); ADD_PROPERTY(m_pMReact, "membrane_reaction" , FEProperty::Optional); ADD_PROPERTY(m_Q, "mat_axis", FEProperty::Optional); END_FECORE_CLASS(); //============================================================================= // FEMultiphasic //============================================================================= //----------------------------------------------------------------------------- //! FEMultiphasic constructor FEMultiphasic::FEMultiphasic(FEModel* pfem) : FEMaterial(pfem) { m_rhoTw = 0; m_Rgas = 0; m_Tabs = 0; m_Fc = 0; m_penalty = 1; m_pSolid = 0; m_pPerm = 0; m_pOsmC = 0; m_pSupp = 0; } //----------------------------------------------------------------------------- void FEMultiphasic::AddSolidBoundMolecule(FESolidBoundMolecule* psbm) { m_pSBM.push_back(psbm); } //----------------------------------------------------------------------------- void FEMultiphasic::AddChemicalReaction(FEChemicalReaction* pcr) { m_pReact.push_back(pcr); } //----------------------------------------------------------------------------- void FEMultiphasic::AddMembraneReaction(FEMembraneReaction* pcr) { m_pMReact.push_back(pcr); } //----------------------------------------------------------------------------- //! Returns the local ID of the SBM, given the global ID. //! \param nid global ID (one - based) //! \return the local ID (zero-based index) or -1 if not found. int FEMultiphasic::FindLocalSBMID(int nid) { int lsbm = -1; int nsbm = (int) SBMs(); for (int isbm=0; isbm<nsbm; ++isbm) { if (m_pSBM[isbm]->GetSBMID() == nid) { lsbm = isbm; break; } } return lsbm; } //----------------------------------------------------------------------------- bool FEMultiphasic::Init() { // set the solute IDs first, since they are referenced in FESolute::Init() for (int i = 0; i<Solutes(); ++i) { m_pSolute[i]->SetSoluteLocalID(i); } if (m_pSolid->Init() == false) return false; if (m_pPerm->Init() == false) return false; if (m_pOsmC->Init() == false) return false; if (m_pSupp && (m_pSupp->Init() == false)) return false; for (int i=0; i<Solutes(); ++i) if (m_pSolute[i]->Init() == false) return false; for (int i=0; i<SBMs(); ++i) if (m_pSBM[i]->Init() == false) return false; for (int i=0; i<Reactions(); ++i) if (m_pReact[i]->Init() == false) return false; for (int i=0; i<MembraneReactions(); ++i) if (m_pMReact[i]->Init() == false) return false; // call the base class. // This also initializes all properties if (FEMaterial::Init() == false) return false; // Determine how to solve for the electric potential psi int isol; int zmin = 0, zmax = 0, z; for (isol=0; isol<(int)m_pSolute.size(); ++isol) { z = m_pSolute[isol]->ChargeNumber(); if (z < zmin) zmin = z; if (z > zmax) zmax = z; } m_zmin = zmin; m_ndeg = zmax - zmin; // polynomial degree m_Rgas = GetFEModel()->GetGlobalConstant("R"); m_Tabs = GetFEModel()->GetGlobalConstant("T"); m_Fc = GetFEModel()->GetGlobalConstant("Fc"); 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; } if ((zmin || zmax) && (m_Fc <= 0)) { feLogError("A positive Faraday constant Fc must be defined in Globals section"); return false; } return true; } //----------------------------------------------------------------------------- // update specialized material points void FEMultiphasic::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { m_pSolid->UpdateSpecializedMaterialPoints(mp, tp); m_pPerm->UpdateSpecializedMaterialPoints(mp, tp); m_pOsmC->UpdateSpecializedMaterialPoints(mp, tp); if (m_pSupp) m_pSupp->UpdateSpecializedMaterialPoints(mp, tp); for (int i=0; i<Solutes(); ++i) m_pSolute[i]->UpdateSpecializedMaterialPoints(mp, tp); for (int i=0; i<SBMs(); ++i) m_pSBM[i]->UpdateSpecializedMaterialPoints(mp, tp); for (int i=0; i<Reactions(); ++i) m_pReact[i]->UpdateSpecializedMaterialPoints(mp, tp); for (int i=0; i<MembraneReactions(); ++i) m_pMReact[i]->UpdateSpecializedMaterialPoints(mp, tp); } //----------------------------------------------------------------------------- void FEMultiphasic::Serialize(DumpStream& ar) { FEMaterial::Serialize(ar); if (ar.IsShallow()) return; ar & m_Rgas & m_Tabs & m_Fc; ar & m_zmin & m_ndeg; } //----------------------------------------------------------------------------- //! Solid referential apparent density double FEMultiphasic::SolidReferentialApparentDensity(FEMaterialPoint& pt) { FEBiphasicMaterialPoint& pet = *pt.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // evaluate referential apparent density of base solid double density = m_pSolid->Density(pt); double rhosr = pet.m_phi0t*density; // add contribution from solid-bound molecules for (int isbm=0; isbm<(int)spt.m_sbmr.size(); ++isbm) rhosr += spt.m_sbmr[isbm]; return rhosr; } //! Return solid referential apparent density double FEMultiphasic::GetReferentialSolidVolumeFraction(const FEMaterialPoint& pt) { const FEBiphasicMaterialPoint& bt = *pt.ExtractData<FEBiphasicMaterialPoint>(); return bt.m_phi0t; } //----------------------------------------------------------------------------- //! Evaluate and return solid referential volume fraction double FEMultiphasic::SolidReferentialVolumeFraction(FEMaterialPoint& pt) { // get referential apparent density of base solid (assumed constant) double phisr = m_phi0(pt); // add contribution from solid-bound 'solutes' FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); const int nsol = (int)m_pSolute.size(); double f = 0; for (int isol=0; isol<nsol; ++isol) if (spt.m_bsb[isol]) f += spt.m_ca[isol]*m_pSolute[isol]->MolarMass()/m_pSolute[isol]->Density(); phisr = (phisr + et.m_J*f)/(1+f); // add contribution from solid-bound molecules for (int isbm=0; isbm<(int)m_pSBM.size(); ++isbm) phisr += SBMReferentialVolumeFraction(pt, isbm); FEBiphasicMaterialPoint& bt = *pt.ExtractData<FEBiphasicMaterialPoint>(); bt.m_phi0t = phisr; return phisr; } //----------------------------------------------------------------------------- //! Evaluate and return tangent of solid referential volume fraction w.r.t. relative volume double FEMultiphasic::TangentSRVFStrain(FEMaterialPoint& pt) { // get referential apparent density of base solid (assumed constant) double phis0 = m_phi0(pt); double phisr = SolidReferentialVolumeFraction(pt); // add contribution from solid-bound 'solutes' FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double J = et.m_J; FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); const int nsol = (int)m_pSolute.size(); double f = 0; double s = 0; for (int isol=0; isol<nsol; ++isol) { if (spt.m_bsb[isol]) { f += spt.m_ca[isol]*m_pSolute[isol]->MolarMass()/m_pSolute[isol]->Density(); s += spt.m_ca[isol]*m_pSolute[isol]->MolarMass()/m_pSolute[isol]->Density()*spt.m_dkdJ[isol]/spt.m_k[isol]; } } double d = 1+f; double dphisrdJ = f/d + (J-phis0)*s/(d*d); // add contribution from solid-bound molecules f = s = 0; for (int isbm=0; isbm<(int)m_pSBM.size(); ++isbm) { f += spt.m_sbmr[isbm]/m_pSBM[isbm]->Density(); } dphisrdJ += f/(J-phisr + f); return dphisrdJ; } //----------------------------------------------------------------------------- //! evaluate and return tangent of solid referential volume fraction w.r.t. to concentration double FEMultiphasic::TangentSRVFConcentration(FEMaterialPoint& pt, const int sol) { // get referential apparent density of base solid (assumed constant) double phis0 = m_phi0(pt); double phisr = SolidReferentialVolumeFraction(pt); // add contribution from solid-bound 'solutes' FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double J = et.m_J; FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); const int nsol = (int)m_pSolute.size(); double f = 0; if (spt.m_bsb[sol]) { for (int isol=0; isol<nsol; ++isol) { if (spt.m_bsb[isol]) { f += spt.m_ca[isol]*spt.m_dkdc[isol][sol]*m_pSolute[isol]->MolarMass()/m_pSolute[isol]->Density(); if (isol == sol) f += spt.m_k[isol]*m_pSolute[isol]->MolarMass()/m_pSolute[isol]->Density(); } } } double dphisrdc = pow(J-phisr,2)/(J-phis0)*f; return dphisrdc; } //----------------------------------------------------------------------------- //! Porosity in current configuration double FEMultiphasic::Porosity(FEMaterialPoint& pt) { FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& bt = *pt.ExtractData<FEBiphasicMaterialPoint>(); // solid referential volume fraction double phisr = bt.m_phi0t; // relative volume double J = et.m_J; double phiw = 1 - phisr/J; // check for pore collapse // TODO: throw an error if pores collapse phiw = (phiw > 0) ? phiw : 0; return phiw; } //----------------------------------------------------------------------------- //! Fixed charge density in current configuration double FEMultiphasic::FixedChargeDensity(FEMaterialPoint& pt) { FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& bt = *pt.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // relative volume double J = et.m_J; double phi0 = bt.m_phi0t; double ce = 0; // add contribution from charged solid-bound molecules for (int isbm=0; isbm<(int)m_pSBM.size(); ++isbm) ce += SBMChargeNumber(isbm)*spt.m_sbmr[isbm]/SBMMolarMass(isbm); double cFr = m_cFr(pt); double cF = (cFr*(1-bt.m_phi0)+ce)/(J-phi0); // add contribution from solid-bound 'solutes' const int nsol = (int)m_pSolute.size(); for (int isol=0; isol<nsol; ++isol) if (spt.m_bsb[isol]) cF += spt.m_ca[isol]*m_pSolute[isol]->ChargeNumber(); return cF; } //----------------------------------------------------------------------------- //! Electric potential double FEMultiphasic::ElectricPotential(FEMaterialPoint& pt, const bool eform) { // check if solution is neutral if (m_ndeg == 0) { if (eform) return 1.0; else return 0.0; } int i, j; // if not neutral, solve electroneutrality polynomial for zeta FESolutesMaterialPoint& set = *pt.ExtractData<FESolutesMaterialPoint>(); const int nsol = (int)m_pSolute.size(); double cF = FixedChargeDensity(pt); vector<double> c(nsol,0); // effective concentration vector<double> khat(nsol,1); // solubility vector<int> z(nsol,0); // charge number for (i=0; i<nsol; ++i) { if (!set.m_bsb[i]) { c[i] = set.m_c[i]; khat[i] = m_pSolute[i]->m_pSolub->Solubility(pt); z[i] = m_pSolute[i]->ChargeNumber(); } } // evaluate polynomial coefficients const int n = m_ndeg; vector<double> a(n+1,0); if (m_zmin < 0) { for (i=0; i<nsol; ++i) { j = z[i] - m_zmin; a[j] += z[i]*khat[i]*c[i]; } a[-m_zmin] = cF; } else { for (i=0; i<nsol; ++i) { j = z[i]; a[j] += z[i]*khat[i]*c[i]; } a[0] = cF; } // solve polynomial double psi = set.m_psi; // use previous solution as initial guess double zeta = exp(-m_Fc*psi/m_Rgas/m_Tabs); if (!solvepoly(n, a, zeta)) { zeta = 1.0; } // Return exponential (non-dimensional) form if desired if (eform) return zeta; // Otherwise return dimensional value of electric potential psi = -m_Rgas*m_Tabs/m_Fc*log(zeta); return psi; } //----------------------------------------------------------------------------- //! partition coefficient double FEMultiphasic::PartitionCoefficient(FEMaterialPoint& pt, const int sol) { // solubility double khat = m_pSolute[sol]->m_pSolub->Solubility(pt); // charge number int z = m_pSolute[sol]->ChargeNumber(); // electric potential double zeta = ElectricPotential(pt, true); double zz = pow(zeta, z); // partition coefficient double kappa = zz*khat; return kappa; } //----------------------------------------------------------------------------- //! partition coefficients and their derivatives void FEMultiphasic::PartitionCoefficientFunctions(FEMaterialPoint& mp, vector<double>& kappa, vector<double>& dkdJ, vector< vector<double> >& dkdc, vector< vector<double> >& dkdr, vector< vector<double> >& dkdJr, vector< vector< vector<double> > >& dkdrc) { int isol, jsol, ksol; int isbm; FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); const int nsol = (int)m_pSolute.size(); const int nsbm = (int)m_pSBM.size(); vector<double> c(nsol); vector<int> z(nsol); vector<double> khat(nsol); vector<double> dkhdJ(nsol); vector<double> dkhdJJ(nsol); vector< vector<double> > dkhdc(nsol, vector<double>(nsol)); vector< vector<double> > dkhdJc(nsol, vector<double>(nsol)); vector< vector< vector<double> > > dkhdcc(nsol, dkhdc); // use dkhdc to initialize only vector<double> zz(nsol); kappa.resize(nsol); double den = 0; double num = 0; double zeta = ElectricPotential(mp, true); for (isol=0; isol<nsol; ++isol) { // get the effective concentration, its gradient and its time derivative c[isol] = spt.m_c[isol]; // get the charge number z[isol] = m_pSolute[isol]->ChargeNumber(); // evaluate the solubility and its derivatives w.r.t. J and c khat[isol] = m_pSolute[isol]->m_pSolub->Solubility(mp); dkhdJ[isol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain(mp); dkhdJJ[isol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain_Strain(mp); for (jsol=0; jsol<nsol; ++jsol) { dkhdc[isol][jsol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Concentration(mp,jsol); dkhdJc[isol][jsol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Strain_Concentration(mp,jsol); for (ksol=0; ksol<nsol; ++ksol) { dkhdcc[isol][jsol][ksol] = m_pSolute[isol]->m_pSolub->Tangent_Solubility_Concentration_Concentration(mp,jsol,ksol); } } zz[isol] = pow(zeta, z[isol]); kappa[isol] = zz[isol]*khat[isol]; den += SQR(z[isol])*kappa[isol]*c[isol]; num += pow((double)z[isol],3)*kappa[isol]*c[isol]; } // get the charge density and its derivatives double J = ept.m_J; double phi0 = ppt.m_phi0t; double cF = FixedChargeDensity(mp); double dcFdJ = -cF/(J - phi0); double dcFdJJ = 2*cF/SQR(J-phi0); // evaluate electric potential (nondimensional exponential form) and its derivatives // also evaluate partition coefficients and their derivatives double zidzdJ = 0; double zidzdJJ = 0, zidzdJJ1 = 0, zidzdJJ2 = 0; vector<double> zidzdc(nsol,0); vector<double> zidzdJc(nsol,0), zidzdJc1(nsol,0), zidzdJc2(nsol,0); vector< vector<double> > zidzdcc(nsol, vector<double>(nsol,0)); vector< vector<double> > zidzdcc1(nsol, vector<double>(nsol,0)); vector<double> zidzdcc2(nsol,0); double zidzdcc3 = 0; if (den > 0) { for (isol=0; isol<nsol; ++isol) zidzdJ += z[isol]*zz[isol]*dkhdJ[isol]*c[isol]; zidzdJ = -(dcFdJ+zidzdJ)/den; for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { zidzdJJ1 += SQR(z[jsol])*c[jsol]*(z[jsol]*zidzdJ*kappa[jsol]+zz[jsol]*dkhdJ[jsol]); zidzdJJ2 += z[jsol]*zz[jsol]*c[jsol]*(zidzdJ*z[jsol]*dkhdJ[jsol]+dkhdJJ[jsol]); zidzdc[isol] += z[jsol]*zz[jsol]*dkhdc[jsol][isol]*c[jsol]; } zidzdc[isol] = -(z[isol]*kappa[isol]+zidzdc[isol])/den; zidzdcc3 += pow(double(z[isol]),3)*kappa[isol]*c[isol]; } zidzdJJ = zidzdJ*(zidzdJ-zidzdJJ1/den)-(dcFdJJ+zidzdJJ2)/den; for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { zidzdJc1[isol] += SQR(z[jsol])*c[jsol]*(zidzdc[isol]*z[jsol]*kappa[jsol]+zz[jsol]*dkhdc[jsol][isol]); zidzdJc2[isol] += z[jsol]*zz[jsol]*c[jsol]*(zidzdc[isol]*z[jsol]*dkhdJ[jsol]+dkhdJc[jsol][isol]); zidzdcc2[isol] += SQR(z[jsol])*zz[jsol]*c[jsol]*dkhdc[jsol][isol]; for (ksol=0; ksol<nsol; ++ksol) zidzdcc1[isol][jsol] += z[ksol]*zz[ksol]*c[ksol]*dkhdcc[ksol][isol][jsol]; } zidzdJc[isol] = zidzdJ*(zidzdc[isol]-(SQR(z[isol])*kappa[isol] + zidzdJc1[isol])/den) -(z[isol]*zz[isol]*dkhdJ[isol] + zidzdJc2[isol])/den; } for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { zidzdcc[isol][jsol] = zidzdc[isol]*zidzdc[jsol]*(1 - zidzdcc3/den) - zidzdcc1[isol][jsol]/den - z[isol]*(z[isol]*kappa[isol]*zidzdc[jsol]+zz[isol]*dkhdc[isol][jsol])/den - z[jsol]*(z[jsol]*kappa[jsol]*zidzdc[isol]+zz[jsol]*dkhdc[jsol][isol])/den - zidzdc[jsol]*zidzdcc2[isol]/den - zidzdc[isol]*zidzdcc2[jsol]/den; } } } dkdJ.resize(nsol); dkdc.resize(nsol, vector<double>(nsol,0)); for (isol=0; isol<nsol; ++isol) { dkdJ[isol] = zz[isol]*dkhdJ[isol]+z[isol]*kappa[isol]*zidzdJ; for (jsol=0; jsol<nsol; ++jsol) { dkdc[isol][jsol] = zz[isol]*dkhdc[isol][jsol]+z[isol]*kappa[isol]*zidzdc[jsol]; } } vector<double> zidzdr(nsbm,0); vector<double> zidzdJr(nsbm,0); vector< vector<double> > zidzdrc(nsbm, vector<double>(nsol,0)); dkdr.resize(nsol, vector<double>(nsbm)); dkdJr.resize(nsol, vector<double>(nsbm)); dkdrc.resize(nsol, zidzdrc); // use zidzdrc for initialization only if (den > 0) { for (isbm=0; isbm<nsbm; ++isbm) { zidzdr[isbm] = -(cF/SBMDensity(isbm) + SBMChargeNumber(isbm)/SBMMolarMass(isbm))/(J-phi0)/den; for (isol=0; isol<nsol; ++isol) { zidzdJr[isbm] += SQR(z[isol])*dkdJ[isol]*c[isol]; } zidzdJr[isbm] = 1/(J-phi0) + zidzdJr[isbm]/den; zidzdJr[isbm] = (zidzdJr[isbm] + zidzdJ)*zidzdr[isbm]; zidzdJr[isbm] += cF/SBMDensity(isbm)/SQR(J-phi0)/den; for (isol=0; isol<nsol; ++isol) { zidzdrc[isbm][isol] = SQR(z[isol])*kappa[isol]; for (jsol=0; jsol<nsol; ++jsol) zidzdrc[isbm][isol] += SQR(z[jsol])*zz[jsol]*c[jsol]*dkhdc[jsol][isol]; zidzdrc[isbm][isol] = zidzdr[isbm]*(zidzdc[isol]*(1+num/den) - zidzdrc[isbm][isol]/den); } } } for (isbm=0; isbm<nsbm; ++isbm) { for (isol=0; isol<nsol; ++isol) { dkdr[isol][isbm] = z[isol]*kappa[isol]*zidzdr[isbm]; dkdJr[isol][isbm] = z[isol]*((dkhdJ[isol]*zz[isol]+(z[isol]-1)*kappa[isol]*zidzdJ)*zidzdr[isbm] +kappa[isol]*zidzdJr[isbm]); for (jsol=0; jsol<nsol; ++jsol) { dkdrc[isol][isbm][jsol] = z[isol]*(zz[isol]*dkhdc[isol][jsol]*zidzdr[isbm] +(z[isol]-1)*kappa[isol]*zidzdr[isbm]*zidzdc[jsol] +kappa[isol]*zidzdrc[isbm][jsol]); } } } } //----------------------------------------------------------------------------- //! actual concentration double FEMultiphasic::Concentration(FEMaterialPoint& pt, const int sol) { FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // effective concentration double c = spt.m_c[sol]; // partition coefficient double kappa = PartitionCoefficient(pt, sol); // actual concentration double ca = kappa*c; return ca; } //----------------------------------------------------------------------------- //! The stress of a triphasic material is the sum of the fluid pressure //! and the elastic stress. Note that this function is declared in the base class //! so you do not have to reimplement it in a derived class, unless additional //! pressure terms are required. mat3ds FEMultiphasic::Stress(FEMaterialPoint& mp) { // calculate solid material stress mat3ds s = m_pSolid->Stress(mp); // fluid pressure double p = Pressure(mp); // add fluid pressure s.xx() -= p; s.yy() -= p; s.zz() -= p; return s; } //----------------------------------------------------------------------------- //! The tangent is the elastic tangent. Note //! that this function is declared in the base class, so you don't have to //! reimplement it unless additional tangent components are required. tens4ds FEMultiphasic::Tangent(FEMaterialPoint& mp) { int i; FEElasticMaterialPoint& ept = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& bpt = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); const int nsol = (int)m_pSolute.size(); // call solid tangent routine tens4ds C = m_pSolid->Tangent(mp); double D[6][6] = {0}; C.extract(D); // relative volume and solid volume fraction double J = ept.m_J; double phi0 = bpt.m_phi0t; // get the charge density and its derivatives double cF = FixedChargeDensity(mp); double dcFdJ = -cF/(J - phi0); // fluid pressure and solute concentration double p = Pressure(mp); // get remaining variables double zeta = ElectricPotential(mp, true); vector<double> c(nsol); vector<int> z(nsol); vector<double> khat(nsol); vector<double> dkhdJ(nsol); vector<double> zz(nsol); vector<double> kappa(nsol); double den = 0; for (i=0; i<nsol; ++i) { c[i] = spt.m_c[i]; z[i] = m_pSolute[i]->ChargeNumber(); khat[i] = m_pSolute[i]->m_pSolub->Solubility(mp); dkhdJ[i] = m_pSolute[i]->m_pSolub->Tangent_Solubility_Strain(mp); zz[i] = pow(zeta, z[i]); kappa[i] = zz[i]*khat[i]; den += SQR(z[i])*kappa[i]*c[i]; } // evaluate electric potential (nondimensional exponential form) and its derivatives // also evaluate partition coefficients and their derivatives double zidzdJ = 0; if (den > 0) { zidzdJ = dcFdJ; for (i=0; i<nsol; ++i) zidzdJ += z[i]*zz[i]*dkhdJ[i]*c[i]; zidzdJ = -zidzdJ/den; } vector<double> dkdJ(nsol); for (i=0; i<nsol; ++i) dkdJ[i] = zz[i]*dkhdJ[i]+z[i]*kappa[i]*zidzdJ; // osmotic coefficient and its derivative w.r.t. strain double osmc = m_pOsmC->OsmoticCoefficient(mp); double dodJ = m_pOsmC->Tangent_OsmoticCoefficient_Strain(mp); double dp = 0; for (i=0; i<nsol; ++i) { dp += c[i]*(osmc*dkdJ[i]+dodJ*kappa[i]); } dp *= m_Rgas*m_Tabs*J; // adjust tangent for pressures D[0][0] -= -p + dp; D[1][1] -= -p + dp; D[2][2] -= -p + dp; D[0][1] -= p + dp; D[1][0] -= p + dp; D[1][2] -= p + dp; D[2][1] -= p + dp; D[0][2] -= p + dp; D[2][0] -= p + dp; D[3][3] -= -p; D[4][4] -= -p; D[5][5] -= -p; return tens4ds(D); } //----------------------------------------------------------------------------- //! Calculate fluid flux vec3d FEMultiphasic::FluidFlux(FEMaterialPoint& pt) { int i; FEBiphasicMaterialPoint& ppt = *pt.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); const int nsol = (int)m_pSolute.size(); vector<double> c(nsol); vector<vec3d> gradc(nsol); vector<mat3ds> D(nsol); vector<double> D0(nsol); vector<double> khat(nsol); vector<int> z(nsol); vector<double> zz(nsol); vector<double> kappa(nsol); // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); // pressure gradient vec3d gradp = ppt.m_gradp; // electric potential double zeta = ElectricPotential(pt, true); for (i=0; i<nsol; ++i) { // concentration c[i] = spt.m_c[i]; // concentration gradient gradc[i] = spt.m_gradc[i]; // solute diffusivity in mixture D[i] = m_pSolute[i]->m_pDiff->Diffusivity(pt); // solute free diffusivity D0[i] = m_pSolute[i]->m_pDiff->Free_Diffusivity(pt); // solubility khat[i] = m_pSolute[i]->m_pSolub->Solubility(pt); z[i] = m_pSolute[i]->ChargeNumber(); zz[i] = pow(zeta, z[i]); kappa[i] = zz[i]*khat[i]; } // identity matrix mat3dd I(1); // hydraulic permeability mat3ds kt = m_pPerm->Permeability(pt); // effective hydraulic permeability mat3ds ke; ke.zero(); for (i=0; i<nsol; ++i) ke += (I-D[i]/D0[i])*(kappa[i]*c[i]/D0[i]); ke = (kt.inverse() + ke*(m_Rgas*m_Tabs/phiw)).inverse(); // fluid flux w vec3d w(0,0,0); for (i=0; i<nsol; ++i) w += (D[i]*gradc[i])*(kappa[i]/D0[i]); w = -(ke*(gradp + w*m_Rgas*m_Tabs)); return w; } //----------------------------------------------------------------------------- //! Calculate solute molar flux vec3d FEMultiphasic::SoluteFlux(FEMaterialPoint& pt, const int sol) { FEBiphasicMaterialPoint& bpt = *pt.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); // concentration double c = spt.m_c[sol]; // concentration gradient vec3d gradc = spt.m_gradc[sol]; // solute diffusivity in mixture mat3ds D = m_pSolute[sol]->m_pDiff->Diffusivity(pt); // solute free diffusivity double D0 = m_pSolute[sol]->m_pDiff->Free_Diffusivity(pt); // solubility double khat = m_pSolute[sol]->m_pSolub->Solubility(pt); int z = m_pSolute[sol]->ChargeNumber(); double zeta = ElectricPotential(pt, true); double zz = pow(zeta, z); double kappa = zz*khat; // fluid flux w vec3d w = bpt.m_w; // solute flux j vec3d j = (D*(w*(c/D0) - gradc*phiw))*kappa; return j; } //----------------------------------------------------------------------------- //! actual fluid pressure double FEMultiphasic::Pressure(FEMaterialPoint& pt) { FEBiphasicMaterialPoint& ppt = *pt.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *pt.ExtractData<FESolutesMaterialPoint>(); const int nsol = (int)m_pSolute.size(); // effective pressure double p = ppt.m_p; // osmolarity double c = spt.Osmolarity(); // osmotic coefficient double osmc = m_pOsmC->OsmoticCoefficient(pt); // actual pressure double pa = p + m_Rgas*m_Tabs*osmc*c; return pa; } //----------------------------------------------------------------------------- //! Current density vec3d FEMultiphasic::CurrentDensity(FEMaterialPoint& pt) { int i; const int nsol = (int)m_pSolute.size(); vector<vec3d> j(nsol); vector<int> z(nsol); vec3d Ie(0,0,0); for (i=0; i<nsol; ++i) { j[i] = SoluteFlux(pt, i); z[i] = m_pSolute[i]->ChargeNumber(); Ie += j[i]*z[i]; } Ie *= m_Fc; return Ie; } //----------------------------------------------------------------------------- //! Evaluate effective permeability mat3ds FEMultiphasic::EffectivePermeability(FEMaterialPoint& pt) { // evaluate the hydraulic permeability mat3ds K = GetPermeability()->Permeability(pt); const int nsol = Solutes(); // if there are no solutes in this mixture, we're done if (nsol == 0) return K; // initialize effective permeability mat3ds Ke = K.inverse(); // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); double tmp = m_Rgas*m_Tabs/phiw; mat3dd I(1.0); FESolutesMaterialPoint& spt = *(pt.ExtractData<FESolutesMaterialPoint >()); // add solute contributions (but not 'solid-bound' solutes) for (int isol=0; isol<nsol; ++isol) { if (!spt.m_bsb[isol]) { // concentration double ca = spt.m_ca[isol]; // solute diffusivity in mixture mat3ds D = m_pSolute[isol]->m_pDiff->Diffusivity(pt); // solute free diffusivity double D0 = m_pSolute[isol]->m_pDiff->Free_Diffusivity(pt); Ke += (I - D/D0)*(tmp*ca/D0); } } return Ke.inverse(); } //----------------------------------------------------------------------------- //! Evaluate tangent of effective permeability w.r.t. strain tens4dmm FEMultiphasic::TangentPermeabilityStrain(FEMaterialPoint& pt, const mat3ds& Ke) { // get the hydraulic permeability strain tangent tens4dmm dKdE = GetPermeability()->Tangent_Permeability_Strain(pt); const int nsol = Solutes(); // if there are no solutes in this mixture, we're done if (nsol == 0) return dKdE; // evaluate the inverse of the hydraulic permeability mat3ds Ki = GetPermeability()->Permeability(pt).inverse(); // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); mat3dd I(1.0); FEElasticMaterialPoint& ept = *(pt.ExtractData<FEElasticMaterialPoint >()); FESolutesMaterialPoint& spt = *(pt.ExtractData<FESolutesMaterialPoint >()); tens4dmm dKedE; dKedE.zero(); // add solute contributions for (int isol=0; isol<nsol; ++isol) { // concentration double ca = spt.m_ca[isol]; // solute free diffusivity double D0 = m_pSolute[isol]->m_pDiff->Free_Diffusivity(pt); // solute diffusivity in mixture, normalized by D0 mat3ds D = m_pSolute[isol]->m_pDiff->Diffusivity(pt)/D0; // solute diffusiviety strain tangent, normalized by D0 tens4dmm dDdE = m_pSolute[isol]->m_pDiff->Tangent_Diffusivity_Strain(pt)/D0; dKedE += (dDdE + (dyad4mm(I, D) + dyad4mm(D,I) - dyad4mm(I,I))*2 - dyad1mm(D,I) + dyad1mm(I-D,I)*(1./phiw - ept.m_J*spt.m_dkdJ[isol]/spt.m_k[isol]))*ca/D0; } dKedE = dKedE*(m_Rgas*m_Tabs/phiw) + ddot(dyad2mm(Ki,Ki), dKdE); return ddot(dyad2mm(Ke, Ke), dKedE); } //----------------------------------------------------------------------------- //! Evaluate tangent of effective permeability w.r.t. concentration mat3ds FEMultiphasic::TangentPermeabilityConcentration(FEMaterialPoint& pt, const int sol, const mat3ds& Ke) { mat3ds dKedc(0,0,0,0,0,0); const int nsol = Solutes(); if (nsol == 0) return dKedc; // fluid volume fraction (porosity) in current configuration double phiw = Porosity(pt); mat3dd I(1.0); FESolutesMaterialPoint& spt = *(pt.ExtractData<FESolutesMaterialPoint >()); // add solute contributions for (int isol=0; isol<nsol; ++isol) { // concentration double ca = spt.m_ca[isol]; // solute free diffusivity double D0 = m_pSolute[isol]->m_pDiff->Free_Diffusivity(pt); // solute diffusivity in mixture, normalized by D0 mat3ds D = m_pSolute[isol]->m_pDiff->Diffusivity(pt)/D0; // solute free diffusivity concentration tangent double dD0dc = m_pSolute[isol]->m_pDiff->Tangent_Free_Diffusivity_Concentration(pt, sol); // solute diffusivity concentration tangent mat3ds dDdc = m_pSolute[isol]->m_pDiff->Tangent_Diffusivity_Concentration(pt,sol); double kd = (isol == sol) ? 1 : 0; dKedc += (I-D)*((spt.m_dkdc[isol][sol]*spt.m_c[isol] + spt.m_k[isol]*kd - dD0dc*ca/D0)/D0) - (dDdc - D*dD0dc)*(ca/D0/D0); } dKedc *= m_Rgas*m_Tabs/phiw; return -(Ke*dKedc*Ke).sym(); } double FEMultiphasic::GetReferentialFixedChargeDensity(const FEMaterialPoint& mp) { const FEElasticMaterialPoint* ept = (mp.ExtractData<FEElasticMaterialPoint >()); const FEBiphasicMaterialPoint* bpt = (mp.ExtractData<FEBiphasicMaterialPoint>()); const FESolutesMaterialPoint* spt = (mp.ExtractData<FESolutesMaterialPoint >()); double cf = (ept->m_J - bpt->m_phi0t) * spt->m_cF / (1 - bpt->m_phi0); return cf; }
C++
3D
febiosoftware/FEBio
FEBioMix/FERemodelingSolid.h
.h
3,474
92
/*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 "FEBioMech/FEElasticMaterial.h" #include "FEBioMech/FERemodelingElasticMaterial.h" #include "FEMultiphasic.h" #include "febiomix_api.h" //----------------------------------------------------------------------------- //! This is a container material for an elastic material associated with a SBM. Its strain energy density, stress //! and elasticity are scaled by the mass fraction of the SBM, relative to the SBM's true density. class FEBIOMIX_API FERemodelingSolid : public FEElasticMaterial, public FERemodelingInterface { public: FERemodelingSolid(FEModel* pfem) : FEElasticMaterial(pfem) { m_sbm = -1; m_lsbm = -1; m_pMat = nullptr; m_pMP = nullptr; } protected: int m_lsbm; //!< local id of solid-bound molecule public: //! data initialization and checking bool Init() override; //! serialization void Serialize(DumpStream& ar) override; //! calculate stress at material point mat3ds Stress(FEMaterialPoint& pt) override; //! calculate tangent stiffness at material point tens4ds Tangent(FEMaterialPoint& pt) override; //! evaluate referential mass density double Density(FEMaterialPoint& pt) override; //! Create material point data FEMaterialPointData* CreateMaterialPointData() override; //! calculate strain energy density at material point double StrainEnergyDensity(FEMaterialPoint& pt) override { return StrainEnergy(pt); } //! update specialize material point data void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) override; public: // --- remodeling interface --- //! calculate strain energy density at material point double StrainEnergy(FEMaterialPoint& pt) override; //! calculate tangent of strain energy density with mass density double Tangent_SE_Density(FEMaterialPoint& pt) override; //! calculate tangent of stress with mass density mat3ds Tangent_Stress_Density(FEMaterialPoint& pt) override; public: FEElasticMaterial* m_pMat; //!< elastic material which obeys simple remodeling rule private: FEMultiphasic* m_pMP; //!< multiphasic domain containing this material // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPorousNeoHookean.cpp
.cpp
5,235
152
/*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 "FEPorousNeoHookean.h" #include "FEBiphasicSolute.h" #include "FEMultiphasic.h" #include "FETriphasic.h" //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEPorousNeoHookean, FEElasticMaterial) ADD_PARAMETER(m_E , FE_RANGE_GREATER ( 0.0), "E" )->setUnits(UNIT_PRESSURE)->setLongName("Young's modulus"); ADD_PARAMETER(m_phisr, FE_RANGE_CLOSED (0.0 , 1.0), "phi0" )->setLongName("solid volume fraction"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- bool FEPorousNeoHookean::Init() { FECoreBase* ancestor = GetAncestor(); FEBiphasic* bparnt = dynamic_cast<FEBiphasic*>(ancestor); FEBiphasicSolute* bsprnt = dynamic_cast<FEBiphasicSolute*>(ancestor); FEMultiphasic* mparnt = dynamic_cast<FEMultiphasic*>(ancestor); if (bparnt) m_phisr = bparnt->m_phi0; else if (bsprnt) m_phisr = bsprnt->m_phi0; else if (mparnt) m_phisr = mparnt->m_phi0; return true; } //----------------------------------------------------------------------------- mat3ds FEPorousNeoHookean::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); double E = m_E(mp); double lam = m_lam(mp); double phisr = ReferentialSolidVolumeFraction(mp); double phiwr = 1 - phisr; double mu = E/3*(1+0.5*phiwr*phiwr); double J = pt.m_J; double Jbar = (J-phisr)/phiwr; double lnJbar = log(Jbar); double R = pow(Jbar/J, 2./3.); double mu1 = mu/J; // calculate left Cauchy-Green tensor mat3ds b = pt.LeftCauchyGreen(); double I1 = b.tr(); // Identity mat3dd I(1); // calculate stress mat3ds s = b*(mu1*R) + I*((mu1*(phisr*R*I1/3. - J) + lam*lnJbar)/(J - phisr)); return s; } //----------------------------------------------------------------------------- tens4ds FEPorousNeoHookean::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); double E = m_E(mp); double lam = m_lam(mp); double phisr = ReferentialSolidVolumeFraction(mp); double phiwr = 1 - phisr; double mu = E/3*(1+0.5*phiwr*phiwr); double J = pt.m_J; double Jbar = (J-phisr)/phiwr; double lnJbar = log(Jbar); double R = pow(Jbar/J, 2./3.); double mu1 = mu/J; double lam1 = lam/J; double g = mu1*R*phisr/(J-phisr); double h = (lam1*lnJbar - mu1)*J/(J-phisr); double Jdg = mu1*R*(2*phisr - 3*J)*phisr/3./pow(J - phisr, 2); double Jdh = J*(mu1*phisr + lam1*(J - phisr*lnJbar))/pow(J - phisr, 2); // calculate left Cauchy-Green tensor mat3ds b = pt.LeftCauchyGreen(); double I1 = b.tr(); // Identity mat3dd I(1); tens4ds bIIb = dyad1s(I, b); tens4ds II = dyad1s(I); tens4ds I4 = dyad4s(I); tens4ds c = bIIb*2.*g/3. + II*(Jdg*I1/3 + Jdh) - I4*(2*(g*I1/3 + h)); return c; } //----------------------------------------------------------------------------- double FEPorousNeoHookean::StrainEnergyDensity(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); double E = m_E(mp); double lam = m_lam(mp); double phisr = ReferentialSolidVolumeFraction(mp); double phiwr = 1 - phisr; double mu = E/3*(1+0.5*phiwr*phiwr); double J = pt.m_J; double Jbar = (J-phisr)/phiwr; double lnJbar = log(Jbar); // calculate left Cauchy-Green tensor mat3ds b = pt.LeftCauchyGreen(); double I1bar = b.tr()*pow(Jbar/J, 2./3.); double sed = mu*((I1bar-3)/2.0 - lnJbar)+lam*lnJbar*lnJbar/2.0; return sed; } //----------------------------------------------------------------------------- double FEPorousNeoHookean::ReferentialSolidVolumeFraction(FEMaterialPoint& mp) { return m_phisr(mp); }
C++
3D
febiosoftware/FEBio
FEBioMix/FENodalFluidFlux.h
.h
1,948
51
/*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/FENodalLoad.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- // Class that implements an equivalent nodal force load. // This load will be applied directly to the load vector of the system class FEBIOMIX_API FENodalFluidFlux : public FENodalLoad { public: FENodalFluidFlux(FEModel* fem); protected: // required functions of FENodalLoad // Set the dof list bool SetDofList(FEDofList& dofList) override; // get the nodal values void GetNodalValues(int inode, std::vector<double>& val) override; private: FEParamDouble m_w; //!< the applied flux DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESolute.cpp
.cpp
8,293
259
/*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 "FESolute.h" #include <FECore/FEModel.h> #include <FECore/DOFS.h> #include <FECore/log.h> //============================================================================= // FESoluteData //============================================================================= //----------------------------------------------------------------------------- // Material parameters for FESoluteData BEGIN_FECORE_CLASS(FESoluteData, FEGlobalData) ADD_PARAMETER(m_rhoT, "density")->setUnits(UNIT_DENSITY); ADD_PARAMETER(m_M, "molar_mass")->setUnits(UNIT_MOLAR_MASS); ADD_PARAMETER(m_z, "charge_number")->setUnits(UNIT_NONE); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FESoluteData::FESoluteData(FEModel* pfem) : FEGlobalData(pfem) { m_rhoT = 1; m_M = 1; m_z = 0; } //----------------------------------------------------------------------------- // TODO: Maybe I can use the ID to make sure the dof is not duplicated. bool FESoluteData::Init() { // for each solute we have to add a concentration degree of freedom FEModel& fem = *GetFEModel(); DOFS& fedofs = fem.GetDOFS(); int varC = fedofs.GetVariableIndex("concentration"); int varD = fedofs.GetVariableIndex("shell concentration"); int varAC = fedofs.GetVariableIndex("concentration tderiv"); int cdofs = fedofs.GetVariableSize(varC); int ddofs = fedofs.GetVariableSize(varD); char sz[8] = {0}; int max_len = sizeof sz; snprintf(sz, max_len, "c%d", cdofs+1); fedofs.AddDOF(varC, sz); snprintf(sz, max_len, "d%d", ddofs+1); fedofs.AddDOF(varD, sz); snprintf(sz, max_len, "ac%d", cdofs+1); fedofs.AddDOF(varAC, sz); return true; } //============================================================================= // FESolute //============================================================================= //----------------------------------------------------------------------------- // Material parameters for FESoluteData BEGIN_FECORE_CLASS(FESoluteMaterial, FESolute) // These parameters cannot (or should not) be set in the input file since // they are copied from the FESoluteData class. // ADD_PARAMETER(m_rhoT, "density"); // ADD_PARAMETER(m_M, "molar_mass"); // ADD_PARAMETER(m_z, "charge_number"); ADD_PARAMETER(m_ID, "sol", FE_PARAM_ATTRIBUTE, "$(solutes)"); // set material properties ADD_PROPERTY(m_pDiff , "diffusivity"); ADD_PROPERTY(m_pSolub, "solubility"); ADD_PROPERTY(m_pSupp , "supply", FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FESoluteMaterial::FESoluteMaterial(FEModel* fem) : FESolute(fem) { } //----------------------------------------------------------------------------- //! FESolute constructor FESolute::FESolute(FEModel* pfem) : FEMaterialProperty(pfem) { m_rhoT = 0; m_M = 0; m_z = 0; m_ID = -1; m_pDiff = 0; m_pSolub = 0; m_pSupp = 0; } //----------------------------------------------------------------------------- FESoluteData* FESolute::FindSoluteData(int nid) { FEModel& fem = *GetFEModel(); int N = GetFEModel()->GlobalDataItems(); for (int i=0; i<N; ++i) { FESoluteData* psd = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (psd && (psd->GetID() == nid)) return psd; } return 0; } //----------------------------------------------------------------------------- bool FESolute::Init() { if (FEMaterialProperty::Init() == false) return false; FESoluteData* psd = FindSoluteData(m_ID); if (psd == 0) { feLogError("no match with global solute data"); return false; } m_rhoT = psd->m_rhoT; m_M = psd->m_M; m_z = (int) psd->m_z; SetName(psd->GetName()); if (m_rhoT < 0) { feLogError("density must be positive" ); return false; } if (m_M < 0) { feLogError("molar_mass must be positive"); return false; } return true; } //----------------------------------------------------------------------------- //! Data serialization void FESolute::Serialize(DumpStream& ar) { FEMaterialProperty::Serialize(ar); ar & m_ID & m_LID; ar & m_rhoT& m_M& m_z; } //============================================================================= // FESBMData //============================================================================= //----------------------------------------------------------------------------- // Material parameters for FESoluteData BEGIN_FECORE_CLASS(FESBMData, FEGlobalData) ADD_PARAMETER(m_rhoT, "density" )->setUnits(UNIT_DENSITY); ADD_PARAMETER(m_M , "molar_mass" )->setUnits(UNIT_MOLAR_MASS); ADD_PARAMETER(m_z , "charge_number")->setUnits(UNIT_NONE); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FESBMData::FESBMData(FEModel* pfem) : FEGlobalData(pfem) { m_rhoT = 1; m_M = 1; m_z = 0; } //============================================================================= // FESolidBoundMolecule //============================================================================= // Material parameters for the FESolidBoundMolecule material BEGIN_FECORE_CLASS(FESolidBoundMolecule, FEMaterialProperty) ADD_PARAMETER(m_ID, "sbm", FE_PARAM_ATTRIBUTE, "$(sbms)"); ADD_PARAMETER(m_rho0 , "rho0" )->setLongName("initial density")->setUnits(UNIT_DENSITY); ADD_PARAMETER(m_rhomin, "rhomin")->setLongName("minimum density")->setUnits(UNIT_DENSITY); ADD_PARAMETER(m_rhomax, "rhomax")->setLongName("maximum density")->setUnits(UNIT_DENSITY); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! FESolidBoundMolecule constructor FESolidBoundMolecule::FESolidBoundMolecule(FEModel* pfem) : FEMaterialProperty(pfem) { m_ID = -1; m_rhoT = 1; m_M = 1; m_z = 0; m_rho0 = 0; m_rhomin = 0; m_rhomax = 0; } //----------------------------------------------------------------------------- FESBMData* FESolidBoundMolecule::FindSBMData(int nid) { FEModel& fem = *GetFEModel(); int N = GetFEModel()->GlobalDataItems(); for (int i=0; i<N; ++i) { FESBMData* psd = dynamic_cast<FESBMData*>(fem.GetGlobalData(i)); if (psd && (psd->GetID() == nid)) return psd; } return 0; } //----------------------------------------------------------------------------- bool FESolidBoundMolecule::Init() { if (FEMaterialProperty::Init() == false) return false; FESBMData* psd = FindSBMData(m_ID); if (psd == 0) { feLogError("no match with global solid-bound molecule data"); return false; } m_rhoT = psd->m_rhoT; m_M = psd->m_M; m_z = psd->m_z; SetName(psd->GetName()); if (m_rhoT < 0) { feLogError("density must be positive" ); return false; } if (m_M < 0) { feLogError("molar_mass must be positive"); return false; } return true; } //----------------------------------------------------------------------------- //! Data serialization void FESolidBoundMolecule::Serialize(DumpStream& ar) { FEMaterialProperty::Serialize(ar); ar & m_ID; ar & m_rhoT & m_M & m_z & m_rho0; ar & m_rhomin & m_rhomax; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEInitialEffectiveFluidPressure.cpp
.cpp
2,202
58
/*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 "FEInitialEffectiveFluidPressure.h" //============================================================================= BEGIN_FECORE_CLASS(FEInitialEffectiveFluidPressure, FEInitialCondition) ADD_PARAMETER(m_data, "value"); END_FECORE_CLASS(); FEInitialEffectiveFluidPressure::FEInitialEffectiveFluidPressure(FEModel* fem) : FEInitialDOF(fem) { } bool FEInitialEffectiveFluidPressure::Init() { if (SetDOF("p") == false) return false; return FEInitialDOF::Init(); } //============================================================================= BEGIN_FECORE_CLASS(FEInitialShellEffectiveFluidPressure, FEInitialCondition) ADD_PARAMETER(m_data, "value"); END_FECORE_CLASS(); FEInitialShellEffectiveFluidPressure::FEInitialShellEffectiveFluidPressure(FEModel* fem) : FEInitialDOF(fem) { } bool FEInitialShellEffectiveFluidPressure::Init() { if (SetDOF("q") == false) return false; return FEInitialDOF::Init(); }
C++
3D
febiosoftware/FEBio
FEBioMix/FESoluteNaturalFlux.cpp
.cpp
16,752
459
/*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 "FESoluteNaturalFlux.h" #include "FEMultiphasic.h" #include <FECore/FEModel.h> #include <FECore/FEAnalysis.h> #include <FECore/FESolidDomain.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FESoluteNaturalFlux, FESurfaceLoad) ADD_PARAMETER(m_bshellb, "shell_bottom"); ADD_PARAMETER(m_isol , "solute_id")->setEnums("$(solutes)"); ADD_PARAMETER(m_bup , "update"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FESoluteNaturalFlux::FESoluteNaturalFlux(FEModel* pfem) : FESurfaceLoad(pfem), m_dofC(pfem), m_dofU(pfem), m_dofP(pfem) { m_bshellb = false; m_isol = -1; m_bup = false; } //----------------------------------------------------------------------------- //! allocate storage void FESoluteNaturalFlux::SetSurface(FESurface* ps) { FESurfaceLoad::SetSurface(ps); } //----------------------------------------------------------------------------- //! serialization void FESoluteNaturalFlux::Serialize(DumpStream& ar) { FESurfaceLoad::Serialize(ar); if (ar.IsShallow() == false) { ar & m_dofC & m_dofU & m_dofP; } } //----------------------------------------------------------------------------- bool FESoluteNaturalFlux::Init() { if (m_isol <= 0) return false; // set up the dof lists FEModel* fem = GetFEModel(); m_dofC.Clear(); m_dofU.Clear(); m_dofP.Clear(); if (m_bshellb == false) { m_dofC.AddDof(fem->GetDOFIndex("concentration", m_isol - 1)); m_dofU.AddDof(fem->GetDOFIndex("x")); m_dofU.AddDof(fem->GetDOFIndex("y")); m_dofU.AddDof(fem->GetDOFIndex("z")); m_dofP.AddDof(fem->GetDOFIndex("p")); } else { m_dofC.AddDof(fem->GetDOFIndex("shell concentration", m_isol - 1)); m_dofU.AddDof(fem->GetDOFIndex("sx")); m_dofU.AddDof(fem->GetDOFIndex("sy")); m_dofU.AddDof(fem->GetDOFIndex("sz")); m_dofP.AddDof(fem->GetDOFIndex("q")); } m_dof.AddDofs(m_dofU); m_dof.AddDofs(m_dofP); m_dof.AddDofs(m_dofC); return FESurfaceLoad::Init(); } //----------------------------------------------------------------------------- void FESoluteNaturalFlux::Update() { if (m_bup) { for (int is=0; is<m_psurf->Elements(); ++is) { // get surface element FESurfaceElement& el = m_psurf->Element(is); // get underlying solid element FESolidElement* pe = dynamic_cast<FESolidElement*>(el.m_elem[0].pe); if (pe == nullptr) break; // get element data int neln = pe->Nodes(); int nint = pe->GaussPoints(); FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get the local solute id FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm); if (psi == nullptr) break; int sid = psi->FindLocalSoluteID(m_isol); if (sid == -1) break; // identify nodes on the surface vector<bool> nsrf(neln,false); for (int j=0; j<neln; ++j) { for (int k=0; k < el.Nodes(); ++k) { if (el.m_node[k] == pe->m_node[j]) nsrf[j] = true; } } // get average effective concentration of nodes not on surface double cavg = 0; int m = 0; for (int i=0; i<neln; ++i) { if (!nsrf[i]) { int n = pe->m_node[i]; FENode& node = GetMesh().Node(n); int dof = m_dofC[m_isol-1]; if (dof != -1) { cavg += node.get(dof); ++m; } } } // assign this average value to surface nodes as initial guess if (m) { cavg /= m; for (int i=0; i<neln; ++i) { if (nsrf[i]) { int n = pe->m_node[i]; FENode& node = GetMesh().Node(n); int dof = m_dofC[m_isol-1]; if (dof != -1) node.set(dof, cavg); } } } } } } //----------------------------------------------------------------------------- void FESoluteNaturalFlux::LoadVector(FEGlobalVector& R) { double dt = CurrentTimeIncrement(); // element force vector vector<double> fe; vector<int> lm; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; const double* Gr, *Gs, *Gt, *H; for (int is=0; is<m_psurf->Elements(); ++is) { // get surface element FESurfaceElement& el = m_psurf->Element(is); // get surface normal vec3d nu(0,0,0); for (int n=0; n<el.GaussPoints(); ++n) { FESurfaceMaterialPoint* pt = dynamic_cast<FESurfaceMaterialPoint*>(el.GetMaterialPoint(n)); nu += pt->dxr ^ pt->dxs; } nu.unit(); // get underlying solid element FESolidElement* pe = dynamic_cast<FESolidElement*>(el.m_elem[0].pe); if (pe == nullptr) break; // determine the solid domain to which this solid element belongs FESolidDomain* sdom = dynamic_cast<FESolidDomain*>(pe->GetMeshPartition()); // get element data int nint = pe->GaussPoints(); int neln = pe->Nodes(); double* gw = pe->GaussWeights(); FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get the local solute id FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm); if (psi == nullptr) break; int sid = psi->FindLocalSoluteID(m_isol); if (sid == -1) break; // get the element force vector and initialize it to zero fe.assign(neln, 0); // 1 concentration dof per node lm.resize(neln); // unpack lm and get nodal effective solute concentrations vector<double> ce(neln,0); for (int i=0; i<neln; ++i) { int n = pe->m_node[i]; FENode& node = GetMesh().Node(n); vector<int>& id = node.m_ID; int dof = m_dofC[m_isol-1]; if (dof != -1) { lm[i] = id[dof]; ce[i] = node.get(dof); } } // for each integration point in the solid element for (int n=0; n<nint; ++n) { FEMaterialPoint& pt = *pe->GetMaterialPoint(n); FEBiphasicMaterialPoint& pb = *(pt.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = sdom->invjact(*pe, Ji, n); detJt *= gw[n]*dt; // get shape functions and their derivatives H = pe->H(n); Gr = pe->Gr(n); Gs = pe->Gs(n); Gt = pe->Gt(n); // get contravariant basis vectors vec3d gcntv[3]; sdom->ContraBaseVectors(*pe, n, gcntv); // evaluate gradient of shape function and gradient of effective concentration // (using ps.m_gradc[n] doesn't work, because it doesn't get updated until convergence) vector<vec3d> gradN(neln); vec3d gradc(0,0,0); for (int i=0; i<neln; ++i) { gradN[i] = gcntv[0]*Gr[i] + gcntv[1]*Gs[i] + gcntv[2]*Gt[i]; gradc += gradN[i]*ce[i]; } for (int i=0; i<neln; ++i) fe[i] -= H[i]*(gradc*nu)*detJt; } R.Assemble(pe->m_node, lm, fe); } // Now do the surface implementation, the normal way FESoluteNaturalFlux* flux = this; m_psurf->LoadVector(R, m_dofC, false, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, std::vector<double>& fa) { // get surface element FESurfaceElement& el = *mp.SurfaceElement(); // get underlying solid element FEElement* pe = el.m_elem[0].pe; FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get the local solute id FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm); if (psi == nullptr) { fa[0] = 0; return; } int sid = psi->FindLocalSoluteID(flux->m_isol); // get element-averaged fluid flux and actual solute concentration vec3d w(0,0,0); double c = 0; int nint = pe->GaussPoints(); for (int n=0; n<nint; ++n) { FEMaterialPoint& pt = *pe->GetMaterialPoint(n); FEBiphasicMaterialPoint& pb = *(pt.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); w += pb.m_w; c += ps.m_ca[sid]; } w /= nint; c /= nint; // evaluate desired natural solute flux vec3d dxt = mp.dxr ^ mp.dxs; double jn = c*(w*dxt); if (flux->m_bshellb) jn = -jn; // molar flow rate double f = jn* dt; double H_i = dof_a.shape; fa[0] = H_i * f; }); } //----------------------------------------------------------------------------- void FESoluteNaturalFlux::StiffnessMatrix(FELinearSystem& LS) { // time increment double dt = CurrentTimeIncrement(); int ndpn = 4; // 3 displacement dofs + 1 concentration dof // element stiffness matrix vector<int> lm; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; const double* Gr, *Gs, *Gt, *H; for (int is=0; is<m_psurf->Elements(); ++is) { // get surface element FESurfaceElement& el = m_psurf->Element(is); // get surface normal vec3d nu(0,0,0); for (int n=0; n<el.GaussPoints(); ++n) { FESurfaceMaterialPoint* pt = dynamic_cast<FESurfaceMaterialPoint*>(el.GetMaterialPoint(n)); nu += pt->dxr ^ pt->dxs; } nu.unit(); // get underlying solid element FESolidElement* pe = dynamic_cast<FESolidElement*>(el.m_elem[0].pe); if (pe == nullptr) break; // determine the solid domain to which this solid element belongs FESolidDomain* sdom = dynamic_cast<FESolidDomain*>(pe->GetMeshPartition()); // get element data int nint = pe->GaussPoints(); int neln = pe->Nodes(); double* gw = pe->GaussWeights(); int ndof = neln*ndpn; FEElementMatrix ke(*pe); ke.resize(ndof, ndof); FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get the local solute id FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm); if (psi == nullptr) break; int sid = psi->FindLocalSoluteID(m_isol); if (sid == -1) break; // initialize stiffness matrix it to zero ke.zero(); lm.resize(ndof); // unpack lm and get nodal effective solute concentrations vector<double> ce(neln,0); for (int i=0; i<neln; ++i) { int n = pe->m_node[i]; FENode& node = GetMesh().Node(n); vector<int>& id = node.m_ID; lm[ndpn*i ] = id[m_dofU[0]]; lm[ndpn*i+1] = id[m_dofU[1]]; lm[ndpn*i+2] = id[m_dofU[2]]; int dof = m_dofC[m_isol-1]; if (dof != -1) { lm[ndpn*i+3] = id[dof]; ce[i] = node.get(dof); } } ke.SetIndices(lm); // for each integration point in the solid element for (int n=0; n<nint; ++n) { FEMaterialPoint& pt = *pe->GetMaterialPoint(n); FEBiphasicMaterialPoint& pb = *(pt.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = sdom->invjact(*pe, Ji, n); detJt *= gw[n]*dt; // get shape functions and their derivatives H = pe->H(n); Gr = pe->Gr(n); Gs = pe->Gs(n); Gt = pe->Gt(n); // get contravariant basis vectors vec3d gcntv[3]; sdom->ContraBaseVectors(*pe, n, gcntv); // evaluate gradient of shape function and gradient of effective concentration // don't use ps.m_gradc[n] as it doesn't get updated until next convergence vector<vec3d> gradN(neln); vec3d gradc(0,0,0); for (int i=0; i<neln; ++i) { gradN[i] = gcntv[0]*Gr[i] + gcntv[1]*Gs[i] + gcntv[2]*Gt[i]; gradc += gradN[i]*ce[i]; } for (int i=0, in = 0; i<neln; ++i, in += ndpn) { for (int j=0, jn = 0; j<neln; ++j, jn += ndpn) { vec3d kcu = (gradN[j]*(nu*gradc) - gradc*(gradN[j]*nu))*H[i]; double kcc = H[i]*(gradN[j]*nu); ke[in+3][jn ] += kcu.x*detJt; ke[in+3][jn+1] += kcu.y*detJt; ke[in+3][jn+2] += kcu.z*detJt; ke[in+3][jn+3] += kcc*detJt; } } } LS.Assemble(ke); } // Now do the surface implementation, the normal way // evaluate the stiffness contribution FESoluteNaturalFlux* flux = this; m_psurf->LoadStiffness(LS, m_dofC, m_dofU, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) { // get surface element FESurfaceElement& el = *mp.SurfaceElement(); // get underlying solid element FEElement* pe = el.m_elem[0].pe; FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get the local solute id FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(pm); if (psi == nullptr) return; int sid = psi->FindLocalSoluteID(flux->m_isol); // get element-averaged fluid flux and actual solute concentration vec3d w(0,0,0); double c = 0; int nint = pe->GaussPoints(); for (int n=0; n<nint; ++n) { FEMaterialPoint& pt = *pe->GetMaterialPoint(n); FEBiphasicMaterialPoint& pb = *(pt.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); w += pb.m_w; c += ps.m_ca[sid]; } w /= nint; c /= nint; // shape functions and derivatives double H_i = dof_a.shape; double Gr_j = dof_b.shape_deriv_r; double Gs_j = dof_b.shape_deriv_s; // calculate surface normal vec3d dxt = mp.dxr ^ mp.dxs; vec3d nu = dxt.normalized(); double jn = c*(w*nu); if (flux->m_bshellb) jn = -jn; // calculate stiffness component vec3d t1 = nu*jn; vec3d t2 = mp.dxs*Gr_j - mp.dxr*Gs_j; vec3d kab = (t1 ^ t2)*(H_i)*dt; Kab[0][0] = kab.x; Kab[0][1] = kab.y; Kab[0][2] = kab.z; }); }
C++
3D
febiosoftware/FEBio
FEBioMix/FECarterHayes.cpp
.cpp
7,640
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.*/ #include "stdafx.h" #include "FECarterHayes.h" #include "FEMultiphasic.h" #include <FECore/log.h> #include <FEBioMech/FEElasticMixture.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FECarterHayes, FEElasticMaterial) ADD_PARAMETER(m_E0 , FE_RANGE_GREATER(0.0) , "E0" )->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_rho0, FE_RANGE_GREATER(0.0) , "rho0" )->setUnits(UNIT_DENSITY); ADD_PARAMETER(m_g , FE_RANGE_GREATER_OR_EQUAL(0.0), "gamma"); ADD_PARAMETER(m_v , FE_RANGE_RIGHT_OPEN(-1.0, 0.5), "v" ); ADD_PARAMETER(m_sbm , "sbm")->setEnums("$(sbms)"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- bool FECarterHayes::Init() { if (FEElasticMaterial::Init() == false) return false; // get the parent material which must be a multiphasic material FEMultiphasic* pMP = GetAncestor()->ExtractProperty<FEMultiphasic>(); if (pMP == 0) { feLogError("Parent material must be multiphasic"); return false; } // extract the local id of the SBM whose density controls Young's modulus from the global id m_lsbm = pMP->FindLocalSBMID(m_sbm); if (m_lsbm == -1) { feLogError("Invalid value for sbm"); return false; } FEElasticMaterial* pem = pMP->GetSolid(); FEElasticMixture* psm = dynamic_cast<FEElasticMixture*>(pem); if (psm == nullptr) { m_comp = -1; // in case material is not a solid mixture return true; } for (int i=0; i<psm->Materials(); ++i) { pem = psm->GetMaterial(i); if (pem == this) { m_comp = i; break; } } return true; } //----------------------------------------------------------------------------- void FECarterHayes::Serialize(DumpStream& ar) { FEElasticMaterial::Serialize(ar); if (ar.IsShallow()) return; ar & m_lsbm; } //----------------------------------------------------------------------------- //! Create material point data FEMaterialPointData* FECarterHayes::CreateMaterialPointData() { return new FERemodelingMaterialPoint(new FEElasticMaterialPoint); } //----------------------------------------------------------------------------- //! update specialize material point data void FECarterHayes::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); FERemodelingMaterialPoint* rpt = mp.ExtractData<FERemodelingMaterialPoint>(); rpt->m_rhor = spt.m_sbmr[m_lsbm]; rpt->m_rhorp = spt.m_sbmrp[m_lsbm]; rpt->m_sed = StrainEnergyDensity(mp); } //----------------------------------------------------------------------------- double FECarterHayes::StrainEnergy(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double detF = pt.m_J; double lndetF = log(detF); // calculate left Cauchy-Green tensor mat3ds b = pt.LeftCauchyGreen(); double I1 = b.tr(); // lame parameters double rhor = spt.m_sbmr[m_lsbm]; double m_E = YoungModulus(rhor); double lam = m_v*m_E/((1+m_v)*(1-2*m_v)); double mu = 0.5*m_E/(1+m_v); double sed = mu*((I1-3)/2 - lndetF)+lam*lndetF*lndetF/2; return sed; } //----------------------------------------------------------------------------- mat3ds FECarterHayes::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double detF = pt.m_J; double detFi = 1.0/detF; double lndetF = log(detF); // evaluate the strain energy FERemodelingMaterialPoint& rpt = *mp.ExtractData<FERemodelingMaterialPoint>(); rpt.m_sed = StrainEnergy(mp); // calculate left Cauchy-Green tensor mat3ds b = pt.LeftCauchyGreen(); // lame parameters double rhor = spt.m_sbmr[m_lsbm]; double m_E = YoungModulus(rhor); double lam = m_v*m_E/((1+m_v)*(1-2*m_v)); double mu = 0.5*m_E/(1+m_v); // Identity mat3dd I(1); // calculate stress mat3ds s = (b - I)*(mu*detFi) + I*(lam*lndetF*detFi); return s; } //----------------------------------------------------------------------------- tens4ds FECarterHayes::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); // deformation gradient double detF = pt.m_J; // lame parameters double rhor = spt.m_sbmr[m_lsbm]; double m_E = YoungModulus(rhor); double lam = m_v*m_E/((1+m_v)*(1-2*m_v)); double mu = 0.5*m_E/(1+m_v); double lam1 = lam / detF; double mu1 = (mu - lam*log(detF)) / detF; double D[6][6] = {0}; D[0][0] = lam1+2.*mu1; D[0][1] = lam1 ; D[0][2] = lam1 ; D[1][0] = lam1 ; D[1][1] = lam1+2.*mu1; D[1][2] = lam1 ; D[2][0] = lam1 ; D[2][1] = lam1 ; D[2][2] = lam1+2.*mu1; D[3][3] = mu1; D[4][4] = mu1; D[5][5] = mu1; return tens4ds(D); } //----------------------------------------------------------------------------- //! evaluate referential mass density double FECarterHayes::Density(FEMaterialPoint& pt) { FERemodelingMaterialPoint* rpt = pt.ExtractData<FERemodelingMaterialPoint>(); if (rpt) return rpt->m_rhor; else { FEElasticMixtureMaterialPoint* emp = pt.ExtractData<FEElasticMixtureMaterialPoint>(); if (emp) { rpt = emp->GetPointData(m_comp)->ExtractData<FERemodelingMaterialPoint>(); if (rpt) return rpt->m_rhor; } } return 0.0; } //----------------------------------------------------------------------------- //! calculate tangent of strain energy density with mass density double FECarterHayes::Tangent_SE_Density(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; return StrainEnergy(mp)*m_g/rhor; } //----------------------------------------------------------------------------- //! calculate tangent of stress with mass density mat3ds FECarterHayes::Tangent_Stress_Density(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; return Stress(mp)*m_g/rhor; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicShellDomain.h
.h
5,428
130
/*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 <FEBioMech/FESSIShellDomain.h> #include "FEBiphasicDomain.h" #include "FEBiphasic.h" //----------------------------------------------------------------------------- //! Domain class for biphasic 3D shell elements //! class FEBIOMIX_API FEBiphasicShellDomain : public FESSIShellDomain, public FEBiphasicDomain { public: //! constructor FEBiphasicShellDomain(FEModel* pfem); //! activate void Activate() override; //! reset domain data void Reset() override; //! intitialize element data void PreSolveUpdate(const FETimeInfo& timeInfo) override; //! Unpack shell element data (overridden from FEDomain) void UnpackLM(FEElement& el, vector<int>& lm) override; //! get material (overridden from FEDomain) FEMaterial* GetMaterial() override; //! get the total dof const FEDofList& GetDOFList() const override; //! set the material void SetMaterial(FEMaterial* pmat) override; public: // update domain data void Update(const FETimeInfo& tp) override; // update element stress void UpdateElementStress(int iel); //! calculates the global stiffness matrix for this domain void StiffnessMatrix(FELinearSystem& LS, bool bsymm) override; //! calculates the global stiffness matrix (steady-state case) void StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) override; public: // internal work (overridden from FEElasticDomain) void InternalForces(FEGlobalVector& R) override; // internal work (steady-state case) void InternalForcesSS(FEGlobalVector& R) override; public: //! element internal force vector void ElementInternalForce(FEShellElement& el, vector<double>& fe); //! element internal force vector (stead-state case) void ElementInternalForceSS(FEShellElement& el, vector<double>& fe); //! calculates the element biphasic stiffness matrix bool ElementBiphasicStiffness(FEShellElement& el, matrix& ke, bool bsymm); //! calculates the element biphasic stiffness matrix for steady-state response bool ElementBiphasicStiffnessSS(FEShellElement& el, matrix& ke, bool bsymm); public: // overridden from FEElasticDomain, but not all implemented in this domain void BodyForce(FEGlobalVector& R, FEBodyForce& bf) override; void ElementBodyForce(FEBodyForce& BF, FEShellElement& el, vector<double>& fe); void InertialForces(FEGlobalVector& R, vector<double>& F) override {} void StiffnessMatrix(FELinearSystem& LS) override {} void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) override; void ElementBodyForceStiffness(FEBodyForce& BF, FEShellElement &el, matrix &ke); void MassMatrix(FELinearSystem& LS, double scale) override {} public: // biphasic domain "properties" // NOTE: I'm thinking about defining properties for domain classes. These would be similar to material // properties (and may require material properties to be evaluated), but are different in that they are // not meant to be customized. For example, the biphasic solver assumes Darcy's law in the evaluation // of the fluid flux. Although one can see the fluid flux as a material property, since the code makes explicit // use of this constitutive equation (apparent from the fact that the biphasic material needs to define the permeability and its // strain derivate) it is not a true material property: i.e. it is not meant to be changed and is an inherent // assumption in this implementation. Consequently, the fluid flux would be a good example of a domain property. // That is why I've taken this calculation out of the FEBiphasic class and placed it here. vec3d FluidFlux(FEMaterialPoint& mp) override; protected: bool m_secant_stress; //!< use secant approximation to stress bool m_secant_tangent; //!< flag for using secant tangent bool m_secant_perm_tangent; //!< flag for using secant tangent on permeability protected: int m_dofSX; int m_dofSY; int m_dofSZ; FEDofList m_dof; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSoluteSolidDomain.h
.h
4,330
116
/*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/FESolidDomain.h" #include "FEBiphasicSolute.h" #include "FEBiphasicSoluteDomain.h" #include <FECore/FEDofList.h> //----------------------------------------------------------------------------- //! Domain class for biphasic-solute 3D solid elements //! Note that this class inherits from FEElasticSolidDomain since this domain //! also needs to calculate elastic stiffness contributions. //! class FEBIOMIX_API FEBiphasicSoluteSolidDomain : public FESolidDomain, public FEBiphasicSoluteDomain { public: //! constructor FEBiphasicSoluteSolidDomain(FEModel* pfem); //! reset domain data void Reset() override; //! get material (overridden from FEDomain) FEMaterial* GetMaterial() override; //! get the total dof const FEDofList& GetDOFList() const override; //! set the material void SetMaterial(FEMaterial* pmat) override; //! Unpack solid element data (overridden from FEDomain) void UnpackLM(FEElement& el, vector<int>& lm) override; //! Activate void Activate() override; //! initialize material points in the domain void InitMaterialPoints() override; //! initialize elements for this domain void PreSolveUpdate(const FETimeInfo& timeInfo) override; // update domain data void Update(const FETimeInfo& tp) override; // update element stress void UpdateElementStress(int iel); public: // internal work (overridden from FEElasticDomain) void InternalForces(FEGlobalVector& R) override; // internal work (steady-state analyses) void InternalForcesSS(FEGlobalVector& R) override; public: //! calculates the global stiffness matrix for this domain void StiffnessMatrix(FELinearSystem& LS, bool bsymm) override; //! calculates the global stiffness matrix for this domain (steady-state case) void StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) override; protected: //! element internal force vector void ElementInternalForce(FESolidElement& el, vector<double>& fe); //! element internal force vector (steady-state analyses) void ElementInternalForceSS(FESolidElement& el, vector<double>& fe); //! calculates the element solute-poroelastic stiffness matrix bool ElementBiphasicSoluteStiffness(FESolidElement& el, matrix& ke, bool bsymm); //! calculates the element solute-poroelastic stiffness matrix bool ElementBiphasicSoluteStiffnessSS(FESolidElement& el, matrix& ke, bool bsymm); protected: // overridden from FEElasticDomain, but not implemented in this domain void BodyForce(FEGlobalVector& R, FEBodyForce& bf) override {} void InertialForces(FEGlobalVector& R, vector<double>& F) override {} void StiffnessMatrix(FELinearSystem& LS) override {} void BodyForceStiffness(FELinearSystem& LS, FEBodyForce& bf) override {} void MassMatrix(FELinearSystem& LS, double scale) override {} protected: FEDofList m_dofU; FEDofList m_dofSU; FEDofList m_dofR; FEDofList m_dof; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateExpSED.cpp
.cpp
3,353
87
/*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 "FEReactionRateExpSED.h" #include "FEBioMech/FERemodelingElasticMaterial.h" #include "FEBiphasic.h" // Material parameters for the FEMultiphasic material BEGIN_FECORE_CLASS(FEReactionRateExpSED, FEReactionRate) ADD_PARAMETER(m_B , "B"); ADD_PARAMETER(m_Psi0, FE_RANGE_NOT_EQUAL(0.0), "Psi0"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEReactionRateExpSED::FEReactionRateExpSED(FEModel* pfem) : FEReactionRate(pfem) { m_B = 0; m_Psi0 = 0; } //----------------------------------------------------------------------------- //! reaction rate at material point double FEReactionRateExpSED::ReactionRate(FEMaterialPoint& pt) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); double phir = pbm->SolidReferentialVolumeFraction(pt); FERemodelingMaterialPoint& rpt = *(pt.ExtractData<FERemodelingMaterialPoint>()); FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double J = et.m_J; double sed = rpt.m_sed; double zhat = m_B(pt)*exp(sed/m_Psi0(pt))/(J-phir); return zhat; } //----------------------------------------------------------------------------- //! tangent of reaction rate with strain at material point mat3ds FEReactionRateExpSED::Tangent_ReactionRate_Strain(FEMaterialPoint& pt) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double phir = pbm->SolidReferentialVolumeFraction(pt); double p = pbm->GetActualFluidPressure(pt); double J = et.m_J; double zhat = ReactionRate(pt); mat3dd I(1); mat3ds dzhatde = (I/(phir-J) + (et.m_s+I*p)/m_Psi0(pt))*zhat; return dzhatde; } //----------------------------------------------------------------------------- //! tangent of reaction rate with effective fluid pressure at material point double FEReactionRateExpSED::Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicShellDomain.cpp
.cpp
108,585
2,507
/*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 "FEMultiphasicShellDomain.h" #include "FEMultiphasicMultigeneration.h" #include "FECore/FEModel.h" #include "FECore/FEAnalysis.h" #include "FECore/log.h" #include "FECore/DOFS.h" #include <FEBioMech/FEBioMech.h> #include <FECore/FELinearSystem.h> #ifndef SQR #define SQR(x) ((x)*(x)) #endif //----------------------------------------------------------------------------- FEMultiphasicShellDomain::FEMultiphasicShellDomain(FEModel* pfem) : FESSIShellDomain(pfem), FEMultiphasicDomain(pfem), m_dofSU(pfem), m_dofR(pfem), m_dof(pfem) { // TODO: Can this be done in Init, since there is no error checking if (pfem) { m_dofSU.AddVariable(FEBioMech::GetVariableName(FEBioMech::SHELL_DISPLACEMENT)); m_dofR.AddVariable(FEBioMech::GetVariableName(FEBioMech::RIGID_ROTATION)); } } //----------------------------------------------------------------------------- //! get the material (overridden from FEDomain) FEMaterial* FEMultiphasicShellDomain::GetMaterial() { return m_pMat; } //----------------------------------------------------------------------------- //! get the total dof const FEDofList& FEMultiphasicShellDomain::GetDOFList() const { return m_dof; } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::SetMaterial(FEMaterial* pmat) { FEDomain::SetMaterial(pmat); m_pMat = dynamic_cast<FEMultiphasic*>(pmat); assert(m_pMat); } //----------------------------------------------------------------------------- //! Unpack the element LM data. void FEMultiphasicShellDomain::UnpackLM(FEElement& el, vector<int>& lm) { // get nodal DOFS const int nsol = m_pMat->Solutes(); int N = el.Nodes(); int ndpn = 8+2*nsol; lm.resize(N*ndpn); for (int i=0; i<N; ++i) { int n = el.m_node[i]; FENode& node = m_pMesh->Node(n); vector<int>& id = node.m_ID; // first the displacement dofs lm[ndpn*i ] = id[m_dofU[0]]; lm[ndpn*i+1] = id[m_dofU[1]]; lm[ndpn*i+2] = id[m_dofU[2]]; // next the shell dofs lm[ndpn*i+3] = id[m_dofSU[0]]; lm[ndpn*i+4] = id[m_dofSU[1]]; lm[ndpn*i+5] = id[m_dofSU[2]]; // now the pressure dofs lm[ndpn*i+6] = id[m_dofP]; lm[ndpn*i+7] = id[m_dofQ]; // concentration dofs in shell domain for (int k=0; k<nsol; ++k) { lm[ndpn*i+8+2*k] = id[m_dofC+m_pMat->GetSolute(k)->GetSoluteDOF()]; lm[ndpn*i+9+2*k] = id[m_dofD+m_pMat->GetSolute(k)->GetSoluteDOF()]; } } } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::UnpackMembraneLM(FEShellElement& el, vector<int>& lm) { FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); // get the first material point FEMaterialPoint& mp = *el.GetMaterialPoint(0); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); int nse = (int)ps.m_ide.size(); int nsi = (int)ps.m_idi.size(); vector<int> ide = ps.m_ide; vector<int> idi = ps.m_idi; int neln = el.Nodes(); int ndpn = 8 + nse + nsi; lm.resize(neln*ndpn); for (int i=0; i<neln; ++i) { int n = el.m_node[i]; FENode& node = mesh.Node(n); vector<int>& id = node.m_ID; // first the displacement dofs lm[ndpn*i ] = id[m_dofU[0]]; lm[ndpn*i+1] = id[m_dofU[1]]; lm[ndpn*i+2] = id[m_dofU[2]]; // next the shell dofs lm[ndpn*i+3] = id[m_dofSU[0]]; lm[ndpn*i+4] = id[m_dofSU[1]]; lm[ndpn*i+5] = id[m_dofSU[2]]; // now the pressure dofs lm[ndpn*i+6] = id[m_dofP]; lm[ndpn*i+7] = id[m_dofQ]; // concentration dofs for (int k=0; k<nse; ++k) lm[ndpn*i+8+k] = id[m_dofC + ide[k]]; for (int k=0; k<nsi; ++k) lm[ndpn*i+8+nse+k] = id[m_dofD + idi[k]]; } } //----------------------------------------------------------------------------- //! build connectivity for matrix profile void FEMultiphasicShellDomain::BuildMatrixProfile(FEGlobalMatrix& M) { vector<int> elm; const int NE = Elements(); for (int j = 0; j<NE; ++j) { FEElement& el = ElementRef(j); UnpackLM(el, elm); M.build_add(elm); } // if we have membrane reactions, build matrix profile for those if (m_pMat->MembraneReactions()) { for (int j = 0; j<NE; ++j) { FEShellElement& el = dynamic_cast<FEShellElement&>(ElementRef(j)); UnpackMembraneLM(el, elm); M.build_add(elm); } } } //----------------------------------------------------------------------------- bool FEMultiphasicShellDomain::Init() { // initialize base class if (FESSIShellDomain::Init() == false) return false; // extract the initial concentrations of the solid-bound molecules const int nsbm = m_pMat->SBMs(); const int nsol = m_pMat->Solutes(); for (int i = 0; i<(int)m_Elem.size(); ++i) { UpdateShellMPData(i); // get the solid element FEShellElement& el = m_Elem[i]; // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n = 0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEBiphasicMaterialPoint& pb = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); double h = el.Evaluate(el.m_ht, n); // shell thickness // initialize multiphasic solutes ps.m_nsol = nsol; ps.m_c.assign(nsol,0); ps.m_ca.assign(nsol,0); ps.m_crp.assign(nsol, 0); ps.m_gradc.assign(nsol,vec3d(0,0,0)); ps.m_k.assign(nsol, 0); ps.m_dkdJ.assign(nsol, 0); ps.m_dkdc.resize(nsol, vector<double>(nsol,0)); ps.m_j.assign(nsol,vec3d(0,0,0)); ps.m_bsb.assign(nsol, false); ps.m_nsbm = nsbm; ps.m_sbmr.assign(nsbm, 0); ps.m_sbmrp.assign(nsbm, 0); ps.m_sbmrhatp.assign(nsbm, 0); ps.m_sbmrhat.assign(nsbm,0); ps.m_sbmrmin.assign(nsbm,0); ps.m_sbmrmax.assign(nsbm,0); // assign bounds on apparent densities of the solid-bound molecules for (int i = 0; i<nsbm; ++i) { ps.m_sbmr[i] = ps.m_sbmrp[i] = m_pMat->GetSBM(i)->m_rho0(mp); ps.m_sbmrmin[i] = m_pMat->GetSBM(i)->m_rhomin; ps.m_sbmrmax[i] = m_pMat->GetSBM(i)->m_rhomax; } // initialize referential solid volume fraction pb.m_phi0 = pb.m_phi0t = m_pMat->SolidReferentialVolumeFraction(mp); if (pb.m_phi0 > 1.0) { feLogError("Referential solid volume fraction of multiphasic material cannot exceed unity!\nCheck ratios of sbm apparent and true densities."); return false; } // evaluate reaction rates at initial time // check if this mixture includes chemical reactions int nreact = (int)m_pMat->Reactions(); if (nreact) { // for chemical reactions involving solid-bound molecules, // update their concentration // multiphasic material point data FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); double phi0 = pb.m_phi0t; for (int isbm=0; isbm<nsbm; ++isbm) { // combine the molar supplies from all the reactions for (int k=0; k<nreact; ++k) { double zetahat = m_pMat->GetReaction(k)->ReactionSupply(mp); double v = m_pMat->GetReaction(k)->m_v[nsol+isbm]; // remember to convert from molar supply to referential mass supply ps.m_sbmrhat[isbm] += (pt.m_J-phi0)*m_pMat->SBMMolarMass(isbm)*v*zetahat; } } } // check if this mixture includes membrane reactions int mreact = (int)m_pMat->MembraneReactions(); if (mreact) { // for membrane reactions involving solid-bound molecules, // update their concentration // multiphasic material point data FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); for (int isbm=0; isbm<nsbm; ++isbm) { // combine the molar supplies from all the reactions for (int k=0; k<mreact; ++k) { double zetahat = m_pMat->GetMembraneReaction(k)->ReactionSupply(mp); double v = m_pMat->GetMembraneReaction(k)->m_v[nsol+isbm]; // remember to convert from molar supply to referential mass supply ps.m_sbmrhat[isbm] += pt.m_J/h*m_pMat->SBMMolarMass(isbm)*v*zetahat; } } } } } return true; } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::Activate() { const int nsol = m_pMat->Solutes(); 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]); if (node.HasFlags(FENode::SHELL)) { node.set_active(m_dofSU[0]); node.set_active(m_dofSU[1]); node.set_active(m_dofSU[2]); } } node.set_active(m_dofP); for (int l=0; l<nsol; ++l) { int dofc = m_dofC + m_pMat->GetSolute(l)->GetSoluteDOF(); node.set_active(dofc); } if (node.HasFlags(FENode::SHELL)) { node.set_active(m_dofQ); for (int l=0; l<nsol; ++l) { int dofd = m_dofD + m_pMat->GetSolute(l)->GetSoluteDOF(); node.set_active(dofd); } } } } } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::InitMaterialPoints() { const int nsol = m_pMat->Solutes(); const int nsbm = m_pMat->SBMs(); FEMesh& m = *GetMesh(); const int NE = FEElement::MAX_NODES; double p0[NE], q0[NE]; vector< vector<double> > c0(nsol, vector<double>(NE)); vector< vector<double> > d0(nsol, vector<double>(NE)); vector<int> sid(nsol); for (int j = 0; j<nsol; ++j) sid[j] = m_pMat->GetSolute(j)->GetSoluteDOF(); for (int i = 0; i<(int)m_Elem.size(); ++i) { // get the solid element FEShellElement& el = m_Elem[i]; // get the number of nodes int neln = el.Nodes(); // get initial values of fluid pressure and solute concentrations for (int i = 0; i<neln; ++i) { p0[i] = m.Node(el.m_node[i]).get(m_dofP); q0[i] = m.Node(el.m_node[i]).get(m_dofQ); for (int isol = 0; isol<nsol; ++isol) { c0[isol][i] = m.Node(el.m_node[i]).get(m_dofC + sid[isol]); d0[isol][i] = m.Node(el.m_node[i]).get(m_dofD + sid[isol]); } } // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n = 0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pm = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); // initialize effective fluid pressure, its gradient pt.m_p = evaluate(el, p0, q0, n); pt.m_gradp = gradient(el, p0, q0, n); // initialize multiphasic solutes ps.m_nsol = nsol; ps.m_nsbm = nsbm; // initialize effective solute concentrations for (int isol = 0; isol<nsol; ++isol) { ps.m_c[isol] = evaluate(el, c0[isol], d0[isol], n); ps.m_gradc[isol] = gradient(el, c0[isol], d0[isol], n); } // determine if solute is 'solid-bound' for (int isol = 0; isol<nsol; ++isol) { FESolute* soli = m_pMat->GetSolute(isol); if (soli->m_pDiff->Diffusivity(mp).norm() == 0) ps.m_bsb[isol] = true; // initialize solute concentrations ps.m_ca[isol] = m_pMat->Concentration(mp, isol); } // initialize referential solid volume fraction pt.m_phi0t = m_pMat->SolidReferentialVolumeFraction(mp); // initialize electric potential ps.m_psi = m_pMat->ElectricPotential(mp); // initialize fluxes pt.m_w = m_pMat->FluidFlux(mp); for (int isol = 0; isol<nsol; ++isol) { ps.m_j[isol] = m_pMat->SoluteFlux(mp, isol); ps.m_crp[isol] = pm.m_J*m_pMat->Porosity(mp)*ps.m_ca[isol]; } pt.m_pa = m_pMat->Pressure(mp); // calculate FCD, current and stress ps.m_cF = m_pMat->FixedChargeDensity(mp); ps.m_Ie = m_pMat->CurrentDensity(mp); pm.m_s = m_pMat->Stress(mp); } } } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::Reset() { // reset base class FESSIShellDomain::Reset(); const int nsol = m_pMat->Solutes(); const int nsbm = m_pMat->SBMs(); for (int i=0; i<(int) m_Elem.size(); ++i) { // get the solid element FEShellElement& el = m_Elem[i]; // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEBiphasicMaterialPoint& pb = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); // initialize multiphasic solutes ps.m_nsol = nsol; ps.m_c.assign(nsol,0); ps.m_ca.assign(nsol,0); ps.m_crp.assign(nsol, 0); ps.m_gradc.assign(nsol,vec3d(0,0,0)); ps.m_k.assign(nsol, 0); ps.m_dkdJ.assign(nsol, 0); ps.m_dkdc.resize(nsol, vector<double>(nsol,0)); ps.m_j.assign(nsol,vec3d(0,0,0)); ps.m_bsb.assign(nsol, false); ps.m_nsbm = nsbm; ps.m_sbmr.assign(nsbm, 0); ps.m_sbmrp.assign(nsbm, 0); ps.m_sbmrhatp.assign(nsbm, 0); ps.m_sbmrhat.assign(nsbm,0); ps.m_sbmrmin.assign(nsbm,0); ps.m_sbmrmax.assign(nsbm,0); // assign bounds on apparent densities of the solid-bound molecules for (int i = 0; i<nsbm; ++i) { ps.m_sbmr[i] = ps.m_sbmrp[i] = m_pMat->GetSBM(i)->m_rho0(mp); ps.m_sbmrmin[i] = m_pMat->GetSBM(i)->m_rhomin; ps.m_sbmrmax[i] = m_pMat->GetSBM(i)->m_rhomax; } // initialize referential solid volume fraction pb.m_phi0 = pb.m_phi0t = m_pMat->SolidReferentialVolumeFraction(mp); // reset chemical reaction element data ps.m_cri.clear(); ps.m_crd.clear(); for (int j=0; j<m_pMat->Reactions(); ++j) m_pMat->GetReaction(j)->ResetElementData(mp); // reset membrane reaction data if (m_pMat->MembraneReactions()) { ps.m_strain = 0; ps.m_pe = ps.m_pi = 0; ps.m_ide.clear(); ps.m_idi.clear(); ps.m_ce.clear(); ps.m_ci.clear(); for (int j=0; j<m_pMat->MembraneReactions(); ++j) m_pMat->GetMembraneReaction(j)->ResetElementData(mp); } } } m_breset = true; } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { FESSIShellDomain::PreSolveUpdate(timeInfo); const int NE = FEElement::MAX_NODES; vec3d x0[NE], xt[NE], r0, rt; FEMesh& m = *GetMesh(); for (size_t iel=0; iel<m_Elem.size(); ++iel) { FEShellElement& el = m_Elem[iel]; int neln = el.Nodes(); for (int i=0; i<neln; ++i) { x0[i] = m.Node(el.m_node[i]).m_r0; xt[i] = m.Node(el.m_node[i]).m_rt; } int n = el.GaussPoints(); for (int j=0; j<n; ++j) { r0 = el.Evaluate(x0, j); rt = el.Evaluate(xt, j); FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMaterialPoint& pe = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); FEMultigenSBMMaterialPoint* pmg = mp.ExtractData<FEMultigenSBMMaterialPoint>(); mp.m_r0 = r0; mp.m_rt = rt; pe.m_J = defgrad(el, pe.m_F, j); // reset determinant of solid deformation gradient at previous time pt.m_Jp = pe.m_J; // reset referential solid volume fraction at previous time pt.m_phi0p = pt.m_phi0t; // reset referential actual solute concentration at previous time for (int k=0; k<m_pMat->Solutes(); ++k) { ps.m_crp[k] = pe.m_J*m_pMat->Porosity(mp)*ps.m_ca[k]; } // reset referential solid-bound molecule concentrations at previous time ps.m_sbmrp = ps.m_sbmr; ps.m_sbmrhatp = ps.m_sbmrhat; // Jansen initialization for (int k=0; k<ps.m_sbmrhat.size(); ++k) ps.m_sbmrhat[k] = - ps.m_sbmrhatp[k]; // reset generational referential solid-bound molecule concentrations at previous time if (pmg) { for (int i=0; i<pmg->m_ngen; ++i) { for (int j=0; j<ps.m_nsbm; ++j) { pmg->m_gsbmrp[i][j] = pmg->m_gsbmr[i][j]; } } } // reset chemical reaction element data for (int j=0; j<m_pMat->Reactions(); ++j) m_pMat->GetReaction(j)->InitializeElementData(mp); // reset membrane reaction element data for (int j=0; j<m_pMat->MembraneReactions(); ++j) m_pMat->GetMembraneReaction(j)->InitializeElementData(mp); mp.Update(timeInfo); } } } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::InternalForces(FEGlobalVector& R) { int NE = (int)m_Elem.size(); // get nodal DOFS int nsol = m_pMat->Solutes(); int ndpn = 2*(4+nsol); #pragma omp parallel for for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FEShellElement& el = m_Elem[i]; // get the element force vector and initialize it to zero int ndof = ndpn*el.Nodes(); fe.assign(ndof, 0); // calculate internal force vector ElementInternalForce(el, fe); // get the element's LM vector UnpackLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe, true); } MembraneReactionFluxes(R); } //----------------------------------------------------------------------------- //! calculates the internal equivalent nodal forces for solid elements void FEMultiphasicShellDomain::ElementInternalForce(FEShellElement& el, vector<double>& fe) { int i, isol, n; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; vec3d gradM, gradMu, gradMw; double Mu, Mw; mat3ds s; const double* Mr, *Ms, *M; int nint = el.GaussPoints(); int neln = el.Nodes(); double* gw = el.GaussWeights(); double eta; const int nsol = m_pMat->Solutes(); int ndpn = 2*(4+nsol); const int nreact = m_pMat->Reactions(); const int mreact = m_pMat->MembraneReactions(); double dt = GetFEModel()->GetTime().timeIncrement; vec3d gcnt[3]; // repeat for all integration points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = invjact(el, Ji, n); detJt *= gw[n]; // get the stress vector for this integration point s = pt.m_s; eta = el.gt(n); Mr = el.Hr(n); Ms = el.Hs(n); M = el.H(n); ContraBaseVectors(el, n, gcnt); // next we get the determinant double Jp = bpt.m_Jp; double J = pt.m_J; // and then finally double divv = ((J-Jp)/dt)/J; // get the flux vec3d& w = bpt.m_w; vector<vec3d> j(spt.m_j); vector<int> z(nsol); vector<double> kappa(spt.m_k); vec3d je(0,0,0); for (isol=0; isol<nsol; ++isol) { // get the charge number z[isol] = m_pMat->GetSolute(isol)->ChargeNumber(); je += j[isol]*z[isol]; } // evaluate the porosity, its derivative w.r.t. J, and its gradient double phiw = m_pMat->Porosity(mp); vector<double> chat(nsol,0); // get the solvent supply double phiwhat = 0; if (m_pMat->GetSolventSupply()) phiwhat = m_pMat->GetSolventSupply()->Supply(mp); // chemical reactions for (i=0; i<nreact; ++i) { FEChemicalReaction* pri = m_pMat->GetReaction(i); double zhat = pri->ReactionSupply(mp); phiwhat += phiw*pri->m_Vbar*zhat; for (isol=0; isol<nsol; ++isol) chat[isol] += phiw*zhat*pri->m_v[isol]; } // membrane reactions for (i=0; i<mreact; ++i) { FEMembraneReaction* pri = m_pMat->GetMembraneReaction(i); double zhat = pri->ReactionSupply(mp); phiwhat += phiw*pri->m_Vbar*zhat; for (isol=0; isol<nsol; ++isol) chat[isol] += phiw*zhat*pri->m_v[isol]; } for (i=0; i<neln; ++i) { gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; gradMu = (gradM*(1+eta) + gcnt[2]*M[i])/2; gradMw = (gradM*(1-eta) - gcnt[2]*M[i])/2; Mu = (1+eta)/2*M[i]; Mw = (1-eta)/2*M[i]; // calculate internal force vec3d fu = s*gradMu; vec3d fw = s*gradMw; // the '-' sign is so that the internal forces get subtracted // from the global residual vector fe[ndpn*i ] -= fu.x*detJt; fe[ndpn*i+1] -= fu.y*detJt; fe[ndpn*i+2] -= fu.z*detJt; fe[ndpn*i+3] -= fw.x*detJt; fe[ndpn*i+4] -= fw.y*detJt; fe[ndpn*i+5] -= fw.z*detJt; fe[ndpn*i+6] -= dt*(w*gradMu + (phiwhat - divv)*Mu)*detJt; fe[ndpn*i+7] -= dt*(w*gradMw + (phiwhat - divv)*Mw)*detJt; for (isol=0; isol<nsol; ++isol) { fe[ndpn*i+8+2*isol] -= dt*(gradMu*(j[isol]+je*m_pMat->m_penalty) + Mu*(chat[isol] - (phiw*spt.m_ca[isol] - spt.m_crp[isol]/J)/dt) )*detJt; fe[ndpn*i+9+2*isol] -= dt*(gradMw*(j[isol]+je*m_pMat->m_penalty) + Mw*(chat[isol] - (phiw*spt.m_ca[isol] - spt.m_crp[isol]/J)/dt) )*detJt; } } } } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::InternalForcesSS(FEGlobalVector& R) { int NE = (int)m_Elem.size(); // get nodal DOFS int nsol = m_pMat->Solutes(); int ndpn = 2*(4+nsol); #pragma omp parallel for for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FEShellElement& el = m_Elem[i]; // get the element force vector and initialize it to zero int ndof = ndpn*el.Nodes(); fe.assign(ndof, 0); // calculate internal force vector ElementInternalForceSS(el, fe); // get the element's LM vector UnpackLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe, true); } } //----------------------------------------------------------------------------- //! calculates the internal equivalent nodal forces for solid elements void FEMultiphasicShellDomain::ElementInternalForceSS(FEShellElement& el, vector<double>& fe) { int i, isol, n; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; vec3d gradM, gradMu, gradMw; double Mu, Mw; mat3ds s; const double* Mr, *Ms, *M; int nint = el.GaussPoints(); int neln = el.Nodes(); double* gw = el.GaussWeights(); double eta; vec3d gcnt[3]; const int nsol = m_pMat->Solutes(); int ndpn = 2*(4+nsol); const int nreact = m_pMat->Reactions(); const int mreact = m_pMat->MembraneReactions(); double dt = GetFEModel()->GetTime().timeIncrement; // repeat for all integration points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = invjact(el, Ji, n); detJt *= gw[n]; // get the stress vector for this integration point s = pt.m_s; eta = el.gt(n); Mr = el.Hr(n); Ms = el.Hs(n); M = el.H(n); ContraBaseVectors(el, n, gcnt); // get the flux vec3d& w = bpt.m_w; vector<vec3d> j(spt.m_j); vector<int> z(nsol); vector<double> kappa(spt.m_k); vec3d je(0,0,0); for (isol=0; isol<nsol; ++isol) { // get the charge number z[isol] = m_pMat->GetSolute(isol)->ChargeNumber(); je += j[isol]*z[isol]; } // evaluate the porosity, its derivative w.r.t. J, and its gradient double phiw = m_pMat->Porosity(mp); vector<double> chat(nsol,0); // get the solvent supply double phiwhat = 0; if (m_pMat->GetSolventSupply()) phiwhat = m_pMat->GetSolventSupply()->Supply(mp); // chemical reactions for (i=0; i<nreact; ++i) { FEChemicalReaction* pri = m_pMat->GetReaction(i); double zhat = pri->ReactionSupply(mp); phiwhat += phiw*pri->m_Vbar*zhat; for (isol=0; isol<nsol; ++isol) chat[isol] += phiw*zhat*pri->m_v[isol]; } // membrane reactions for (i=0; i<mreact; ++i) { FEMembraneReaction* pri = m_pMat->GetMembraneReaction(i); double zhat = pri->ReactionSupply(mp); phiwhat += phiw*pri->m_Vbar*zhat; for (isol=0; isol<nsol; ++isol) chat[isol] += phiw*zhat*pri->m_v[isol]; } for (i=0; i<neln; ++i) { gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; gradMu = (gradM*(1+eta) + gcnt[2]*M[i])/2; gradMw = (gradM*(1-eta) - gcnt[2]*M[i])/2; Mu = (1+eta)/2*M[i]; Mw = (1-eta)/2*M[i]; // calculate internal force vec3d fu = s*gradMu; vec3d fw = s*gradMw; // the '-' sign is so that the internal forces get subtracted // from the global residual vector fe[ndpn*i ] -= fu.x*detJt; fe[ndpn*i+1] -= fu.y*detJt; fe[ndpn*i+2] -= fu.z*detJt; fe[ndpn*i+3] -= fw.x*detJt; fe[ndpn*i+4] -= fw.y*detJt; fe[ndpn*i+5] -= fw.z*detJt; fe[ndpn*i+6] -= dt*(w*gradMu + Mu*phiwhat)*detJt; fe[ndpn*i+7] -= dt*(w*gradMw + Mw*phiwhat)*detJt; for (isol=0; isol<nsol; ++isol) { fe[ndpn*i+8+2*isol] -= dt*(gradMu*(j[isol]+je*m_pMat->m_penalty) + Mu*phiw*chat[isol] )*detJt; fe[ndpn*i+9+2*isol] -= dt*(gradMw*(j[isol]+je*m_pMat->m_penalty) + Mw*phiw*chat[isol] )*detJt; } } } } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::StiffnessMatrix(FELinearSystem& LS, bool bsymm) { const int nsol = m_pMat->Solutes(); int ndpn = 2*(4+nsol); // repeat over all solid elements int NE = (int)m_Elem.size(); #pragma omp parallel for for (int iel=0; iel<NE; ++iel) { FEShellElement& el = m_Elem[iel]; // element stiffness matrix FEElementMatrix ke(el); int neln = el.Nodes(); int ndof = neln*ndpn; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementMultiphasicStiffness(el, ke, bsymm); // get lm vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } MembraneReactionStiffnessMatrix(LS); } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) { const int nsol = m_pMat->Solutes(); int ndpn = 2*(4+nsol); // repeat over all solid elements int NE = (int)m_Elem.size(); #pragma omp parallel for for (int iel=0; iel<NE; ++iel) { FEShellElement& el = m_Elem[iel]; // element stiffness matrix FEElementMatrix ke(el); int neln = el.Nodes(); int ndof = neln*ndpn; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementMultiphasicStiffnessSS(el, ke, bsymm); vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- //! calculates element stiffness matrix for element iel //! bool FEMultiphasicShellDomain::ElementMultiphasicStiffness(FEShellElement& el, matrix& ke, bool bsymm) { int i, j, isol, jsol, n, ireact, isbm; int nint = el.GaussPoints(); int neln = el.Nodes(); const double* Mr, *Ms, *M; // jacobian double Ji[3][3], detJ; // Gradient of shape functions vector<vec3d> gradMu(neln), gradMw(neln); vector<double> Mu(neln), Mw(neln); vec3d gradM; double tmp; // gauss-weights double* gw = el.GaussWeights(); double eta; vec3d gcnt[3]; double dt = GetFEModel()->GetTime().timeIncrement; const int nsol = m_pMat->Solutes(); int ndpn = 2*(4+nsol); const int nsbm = m_pMat->SBMs(); const int nreact = m_pMat->Reactions(); const int mreact = m_pMat->MembraneReactions(); // zero stiffness matrix ke.zero(); // loop over gauss-points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint >()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint >()); // calculate jacobian detJ = invjact(el, Ji, n)*gw[n]; eta = el.gt(n); Mr = el.Hr(n); Ms = el.Hs(n); M = el.H(n); ContraBaseVectors(el, n, gcnt); // calculate global gradient of shape functions for (i=0; i<neln; ++i) { // calculate global gradient of shape functions gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; gradMu[i] = (gradM*(1+eta) + gcnt[2]*M[i])/2; gradMw[i] = (gradM*(1-eta) - gcnt[2]*M[i])/2; Mu[i] = (1+eta)/2*M[i]; Mw[i] = (1-eta)/2*M[i]; } // get stress tensor mat3ds s = ept.m_s; // get elasticity tensor tens4ds C = m_pMat->Tangent(mp); // next we get the determinant double J = ept.m_J; // get the fluid flux and pressure gradient vec3d w = ppt.m_w; vec3d gradp = ppt.m_gradp; vector<double> c(spt.m_c); vector<vec3d> gradc(spt.m_gradc); vector<int> z(nsol); vector<double> kappa(spt.m_k); // get the charge number for (isol=0; isol<nsol; ++isol) z[isol] = m_pMat->GetSolute(isol)->ChargeNumber(); vector<double> dkdJ(spt.m_dkdJ); vector< vector<double> > dkdc(spt.m_dkdc); vector< vector<double> > dkdr(spt.m_dkdr); vector< vector<double> > dkdJr(spt.m_dkdJr); vector< vector< vector<double> > > dkdrc(spt.m_dkdrc); // evaluate the porosity and its derivative double phiw = m_pMat->Porosity(mp); double phi0 = ppt.m_phi0t; double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the osmotic coefficient double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp); // evaluate the permeability mat3ds K = m_pMat->GetPermeability()->Permeability(mp); tens4dmm dKdE = m_pMat->GetPermeability()->Tangent_Permeability_Strain(mp); vector<mat3ds> dKdc(nsol); vector<mat3ds> D(nsol); vector<tens4dmm> dDdE(nsol); vector< vector<mat3ds> > dDdc(nsol, vector<mat3ds>(nsol)); vector<double> D0(nsol); vector< vector<double> > dD0dc(nsol, vector<double>(nsol)); vector<double> dodc(nsol); vector<mat3ds> dTdc(nsol); vector<mat3ds> ImD(nsol); mat3dd I(1); // evaluate the solvent supply and its derivatives mat3ds Phie; Phie.zero(); double Phip = 0; vector<double> Phic(nsol,0); vector<mat3ds> dchatde(nsol); if (m_pMat->GetSolventSupply()) { Phie = m_pMat->GetSolventSupply()->Tangent_Supply_Strain(mp); Phip = m_pMat->GetSolventSupply()->Tangent_Supply_Pressure(mp); } // chemical reactions for (i=0; i<nreact; ++i) Phie += m_pMat->GetReaction(i)->m_Vbar*(I*m_pMat->GetReaction(i)->ReactionSupply(mp) +m_pMat->GetReaction(i)->Tangent_ReactionSupply_Strain(mp)*(J*phiw)); // membrane reactions for (i=0; i<mreact; ++i) Phie += m_pMat->GetMembraneReaction(i)->m_Vbar*mat3dd(m_pMat->GetMembraneReaction(i)->ReactionSupply(mp) +m_pMat->GetMembraneReaction(i)->Tangent_ReactionSupply_Strain(mp)*(J*phiw)); for (isol=0; isol<nsol; ++isol) { // evaluate the permeability derivatives dKdc[isol] = m_pMat->GetPermeability()->Tangent_Permeability_Concentration(mp,isol); // evaluate the diffusivity tensor and its derivatives D[isol] = m_pMat->GetSolute(isol)->m_pDiff->Diffusivity(mp); dDdE[isol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity D0[isol] = m_pMat->GetSolute(isol)->m_pDiff->Free_Diffusivity(mp); // evaluate the derivative of the osmotic coefficient dodc[isol] = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp,isol); // evaluate the stress tangent with concentration // dTdc[isol] = pm->GetSolid()->Tangent_Concentration(mp,isol); dTdc[isol] = mat3ds(0,0,0,0,0,0); ImD[isol] = I-D[isol]/D0[isol]; for (jsol=0; jsol<nsol; ++jsol) { dDdc[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Diffusivity_Concentration(mp,jsol); dD0dc[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,jsol); } // evaluate the solvent supply tangent with concentration if (m_pMat->GetSolventSupply()) Phic[isol] = m_pMat->GetSolventSupply()->Tangent_Supply_Concentration(mp,isol); // chemical reactions dchatde[isol].zero(); for (ireact=0; ireact<nreact; ++ireact) { dchatde[isol] += m_pMat->GetReaction(ireact)->m_v[isol] *(I*m_pMat->GetReaction(ireact)->ReactionSupply(mp) +m_pMat->GetReaction(ireact)->Tangent_ReactionSupply_Strain(mp)*(J*phiw)); Phic[isol] += phiw*m_pMat->GetReaction(ireact)->m_Vbar *m_pMat->GetReaction(ireact)->Tangent_ReactionSupply_Concentration(mp, isol); } // membrane reactions for (ireact=0; ireact<mreact; ++ireact) { dchatde[isol] += m_pMat->GetMembraneReaction(ireact)->m_v[isol] *mat3dd(m_pMat->GetMembraneReaction(ireact)->ReactionSupply(mp) +m_pMat->GetMembraneReaction(ireact)->Tangent_ReactionSupply_Strain(mp)*(J*phiw)); Phic[isol] += phiw*m_pMat->GetMembraneReaction(ireact)->m_Vbar *m_pMat->GetMembraneReaction(ireact)->Tangent_ReactionSupply_Concentration(mp, isol); } } // Miscellaneous constants double R = m_pMat->m_Rgas; double T = m_pMat->m_Tabs; double penalty = m_pMat->m_penalty; // evaluate the effective permeability and its derivatives mat3ds Ki = K.inverse(); mat3ds Ke(0,0,0,0,0,0); tens4d G = (dyad1(Ki,I) - dyad4(Ki,I)*2)*2 - ddot(dyad2(Ki,Ki),dKdE); vector<mat3ds> Gc(nsol); vector<mat3ds> dKedc(nsol); for (isol=0; isol<nsol; ++isol) { Ke += ImD[isol]*(kappa[isol]*c[isol]/D0[isol]); G += dyad1(ImD[isol],I)*(R*T*c[isol]*J/D0[isol]/phiw*(dkdJ[isol]-kappa[isol]/phiw*dpdJ)) +(dyad1(I,I) - dyad2(I,I)*2 - dDdE[isol]/D0[isol])*(R*T*kappa[isol]*c[isol]/phiw/D0[isol]); Gc[isol] = ImD[isol]*(kappa[isol]/D0[isol]); for (jsol=0; jsol<nsol; ++jsol) { Gc[isol] += ImD[jsol]*(c[jsol]/D0[jsol]*(dkdc[jsol][isol]-kappa[jsol]/D0[jsol]*dD0dc[jsol][isol])) -(dDdc[jsol][isol]-D[jsol]*(dD0dc[jsol][isol]/D0[jsol])*(kappa[jsol]*c[jsol]/SQR(D0[jsol]))); } Gc[isol] *= R*T/phiw; } Ke = (Ki + Ke*(R*T/phiw)).inverse(); tens4d dKedE = (dyad1(Ke,I) - 2*dyad4(Ke,I))*2 - ddot(dyad2(Ke,Ke),G); for (isol=0; isol<nsol; ++isol) dKedc[isol] = -(Ke*(-Ki*dKdc[isol]*Ki + Gc[isol])*Ke).sym(); // calculate all the matrices vec3d vtmp,gp,qpu, qpw; vector<vec3d> gc(nsol),qcu(nsol),qcw(nsol),wc(nsol),wd(nsol),jce(nsol),jde(nsol); vector< vector<vec3d> > jc(nsol, vector<vec3d>(nsol)); vector< vector<vec3d> > jd(nsol, vector<vec3d>(nsol)); mat3d wu, ww, jue, jwe; vector<mat3d> ju(nsol), jw(nsol); vector< vector<double> > qcc(nsol, vector<double>(nsol)); vector< vector<double> > qcd(nsol, vector<double>(nsol)); vector< vector<double> > dchatdc(nsol, vector<double>(nsol)); double sum; mat3ds De; for (i=0; i<neln; ++i) { for (j=0; j<neln; ++j) { // Kuu matrix mat3d Kuu = (mat3dd(gradMu[i]*(s*gradMu[j])) + vdotTdotv(gradMu[i], C, gradMu[j]))*detJ; mat3d Kuw = (mat3dd(gradMu[i]*(s*gradMw[j])) + vdotTdotv(gradMu[i], C, gradMw[j]))*detJ; mat3d Kwu = (mat3dd(gradMw[i]*(s*gradMu[j])) + vdotTdotv(gradMw[i], C, gradMu[j]))*detJ; mat3d Kww = (mat3dd(gradMw[i]*(s*gradMw[j])) + vdotTdotv(gradMw[i], C, gradMw[j]))*detJ; ke[ndpn*i ][ndpn*j ] += Kuu[0][0]; ke[ndpn*i ][ndpn*j+1] += Kuu[0][1]; ke[ndpn*i ][ndpn*j+2] += Kuu[0][2]; ke[ndpn*i+1][ndpn*j ] += Kuu[1][0]; ke[ndpn*i+1][ndpn*j+1] += Kuu[1][1]; ke[ndpn*i+1][ndpn*j+2] += Kuu[1][2]; ke[ndpn*i+2][ndpn*j ] += Kuu[2][0]; ke[ndpn*i+2][ndpn*j+1] += Kuu[2][1]; ke[ndpn*i+2][ndpn*j+2] += Kuu[2][2]; ke[ndpn*i ][ndpn*j+3] += Kuw[0][0]; ke[ndpn*i ][ndpn*j+4] += Kuw[0][1]; ke[ndpn*i ][ndpn*j+5] += Kuw[0][2]; ke[ndpn*i+1][ndpn*j+3] += Kuw[1][0]; ke[ndpn*i+1][ndpn*j+4] += Kuw[1][1]; ke[ndpn*i+1][ndpn*j+5] += Kuw[1][2]; ke[ndpn*i+2][ndpn*j+3] += Kuw[2][0]; ke[ndpn*i+2][ndpn*j+4] += Kuw[2][1]; ke[ndpn*i+2][ndpn*j+5] += Kuw[2][2]; ke[ndpn*i+3][ndpn*j ] += Kwu[0][0]; ke[ndpn*i+3][ndpn*j+1] += Kwu[0][1]; ke[ndpn*i+3][ndpn*j+2] += Kwu[0][2]; ke[ndpn*i+4][ndpn*j ] += Kwu[1][0]; ke[ndpn*i+4][ndpn*j+1] += Kwu[1][1]; ke[ndpn*i+4][ndpn*j+2] += Kwu[1][2]; ke[ndpn*i+5][ndpn*j ] += Kwu[2][0]; ke[ndpn*i+5][ndpn*j+1] += Kwu[2][1]; ke[ndpn*i+5][ndpn*j+2] += Kwu[2][2]; ke[ndpn*i+3][ndpn*j+3] += Kww[0][0]; ke[ndpn*i+3][ndpn*j+4] += Kww[0][1]; ke[ndpn*i+3][ndpn*j+5] += Kww[0][2]; ke[ndpn*i+4][ndpn*j+3] += Kww[1][0]; ke[ndpn*i+4][ndpn*j+4] += Kww[1][1]; ke[ndpn*i+4][ndpn*j+5] += Kww[1][2]; ke[ndpn*i+5][ndpn*j+3] += Kww[2][0]; ke[ndpn*i+5][ndpn*j+4] += Kww[2][1]; ke[ndpn*i+5][ndpn*j+5] += Kww[2][2]; // calculate the kpu matrix gp = vec3d(0,0,0); for (isol=0; isol<nsol; ++isol) gp += (D[isol]*gradc[isol])*(kappa[isol]/D0[isol]); gp = gradp+gp*(R*T); wu = vdotTdotv(-gp, dKedE, gradMu[j]); ww = vdotTdotv(-gp, dKedE, gradMw[j]); for (isol=0; isol<nsol; ++isol) { wu += (((Ke*(D[isol]*gradc[isol])) & gradMu[j])*(J*dkdJ[isol] - kappa[isol]) +Ke*(2*kappa[isol]*(gradMu[j]*(D[isol]*gradc[isol]))))*(-R*T/D0[isol]) + (Ke*vdotTdotv(gradc[isol], dDdE[isol], gradMu[j]))*(-kappa[isol]*R*T/D0[isol]); ww += (((Ke*(D[isol]*gradc[isol])) & gradMw[j])*(J*dkdJ[isol] - kappa[isol]) +Ke*(2*kappa[isol]*(gradMw[j]*(D[isol]*gradc[isol]))))*(-R*T/D0[isol]) + (Ke*vdotTdotv(gradc[isol], dDdE[isol], gradMw[j]))*(-kappa[isol]*R*T/D0[isol]); } qpu = -gradMu[j]*(1.0/dt); qpw = -gradMw[j]*(1.0/dt); vec3d kpu = (wu.transpose()*gradMu[i] + (qpu + Phie*gradMu[j])*Mu[i])*(detJ*dt); vec3d kpw = (ww.transpose()*gradMu[i] + (qpw + Phie*gradMw[j])*Mu[i])*(detJ*dt); vec3d kqu = (wu.transpose()*gradMw[i] + (qpu + Phie*gradMu[j])*Mw[i])*(detJ*dt); vec3d kqw = (ww.transpose()*gradMw[i] + (qpw + Phie*gradMw[j])*Mw[i])*(detJ*dt); ke[ndpn*i+6][ndpn*j ] += kpu.x; ke[ndpn*i+6][ndpn*j+1] += kpu.y; ke[ndpn*i+6][ndpn*j+2] += kpu.z; ke[ndpn*i+6][ndpn*j+3] += kpw.x; ke[ndpn*i+6][ndpn*j+4] += kpw.y; ke[ndpn*i+6][ndpn*j+5] += kpw.z; ke[ndpn*i+7][ndpn*j ] += kqu.x; ke[ndpn*i+7][ndpn*j+1] += kqu.y; ke[ndpn*i+7][ndpn*j+2] += kqu.z; ke[ndpn*i+7][ndpn*j+3] += kqw.x; ke[ndpn*i+7][ndpn*j+4] += kqw.y; ke[ndpn*i+7][ndpn*j+5] += kqw.z; // calculate the kup matrix vec3d kup = gradMu[i]*(-Mu[j]*detJ); vec3d kuq = gradMu[i]*(-Mw[j]*detJ); vec3d kwp = gradMw[i]*(-Mu[j]*detJ); vec3d kwq = gradMw[i]*(-Mw[j]*detJ); ke[ndpn*i ][ndpn*j+6] += kup.x; ke[ndpn*i ][ndpn*j+7] += kuq.x; ke[ndpn*i+1][ndpn*j+6] += kup.y; ke[ndpn*i+1][ndpn*j+7] += kuq.y; ke[ndpn*i+2][ndpn*j+6] += kup.z; ke[ndpn*i+2][ndpn*j+7] += kuq.z; ke[ndpn*i+3][ndpn*j+6] += kwp.x; ke[ndpn*i+3][ndpn*j+7] += kwq.x; ke[ndpn*i+4][ndpn*j+6] += kwp.y; ke[ndpn*i+4][ndpn*j+7] += kwq.y; ke[ndpn*i+5][ndpn*j+6] += kwp.z; ke[ndpn*i+5][ndpn*j+7] += kwq.z; // calculate the kpp matrix ke[ndpn*i+6][ndpn*j+6] += (Mu[i]*Mu[j]*Phip - gradMu[i]*(Ke*gradMu[j]))*(detJ*dt); ke[ndpn*i+6][ndpn*j+7] += (Mu[i]*Mw[j]*Phip - gradMu[i]*(Ke*gradMw[j]))*(detJ*dt); ke[ndpn*i+7][ndpn*j+6] += (Mw[i]*Mu[j]*Phip - gradMw[i]*(Ke*gradMu[j]))*(detJ*dt); ke[ndpn*i+7][ndpn*j+7] += (Mw[i]*Mw[j]*Phip - gradMw[i]*(Ke*gradMw[j]))*(detJ*dt); // calculate kcu matrix data jue.zero(); jwe.zero(); De.zero(); for (isol=0; isol<nsol; ++isol) { gc[isol] = -gradc[isol]*phiw + w*c[isol]/D0[isol]; ju[isol] = ((D[isol]*gc[isol]) & gradMu[j])*(J*dkdJ[isol]) + vdotTdotv(gc[isol], dDdE[isol], gradMu[j])*kappa[isol] + (((D[isol]*gradc[isol]) & gradMu[j])*(-phis) +(D[isol]*((gradMu[j]*w)*2) - ((D[isol]*w) & gradMu[j]))*c[isol]/D0[isol] )*kappa[isol] +D[isol]*wu*(kappa[isol]*c[isol]/D0[isol]); jw[isol] = ((D[isol]*gc[isol]) & gradMw[j])*(J*dkdJ[isol]) + vdotTdotv(gc[isol], dDdE[isol], gradMw[j])*kappa[isol] + (((D[isol]*gradc[isol]) & gradMw[j])*(-phis) +(D[isol]*((gradMw[j]*w)*2) - ((D[isol]*w) & gradMw[j]))*c[isol]/D0[isol] )*kappa[isol] +D[isol]*ww*(kappa[isol]*c[isol]/D0[isol]); jue += ju[isol]*z[isol]; jwe += jw[isol]*z[isol]; De += D[isol]*(z[isol]*kappa[isol]*c[isol]/D0[isol]); qcu[isol] = qpu*(c[isol]*(kappa[isol]+J*phiw*dkdJ[isol])); qcw[isol] = qpw*(c[isol]*(kappa[isol]+J*phiw*dkdJ[isol])); // chemical reactions for (ireact=0; ireact<nreact; ++ireact) { double sum1 = 0; double sum2 = 0; for (isbm=0; isbm<nsbm; ++isbm) { sum1 += m_pMat->SBMMolarMass(isbm)*m_pMat->GetReaction(ireact)->m_v[nsol+isbm]* ((J-phi0)*dkdr[isol][isbm]-kappa[isol]/m_pMat->SBMDensity(isbm)); sum2 += m_pMat->SBMMolarMass(isbm)*m_pMat->GetReaction(ireact)->m_v[nsol+isbm]* (dkdr[isol][isbm]+(J-phi0)*dkdJr[isol][isbm]-dkdJ[isol]/m_pMat->SBMDensity(isbm)); } double zhat = m_pMat->GetReaction(ireact)->ReactionSupply(mp); mat3dd zhatI(zhat); mat3ds dzde = m_pMat->GetReaction(ireact)->Tangent_ReactionSupply_Strain(mp); qcu[isol] -= ((zhatI+dzde*(J-phi0))*gradMu[j])*(sum1*c[isol]) +gradMu[j]*(c[isol]*(J-phi0)*sum2*zhat); qcw[isol] -= ((zhatI+dzde*(J-phi0))*gradMw[j])*(sum1*c[isol]) +gradMw[j]*(c[isol]*(J-phi0)*sum2*zhat); } // membrane reactions for (ireact=0; ireact<mreact; ++ireact) { double sum1 = 0; double sum2 = 0; for (isbm=0; isbm<nsbm; ++isbm) { sum1 += m_pMat->SBMMolarMass(isbm)*m_pMat->GetMembraneReaction(ireact)->m_v[nsol+isbm]* ((J-phi0)*dkdr[isol][isbm]-kappa[isol]/m_pMat->SBMDensity(isbm)); sum2 += m_pMat->SBMMolarMass(isbm)*m_pMat->GetMembraneReaction(ireact)->m_v[nsol+isbm]* (dkdr[isol][isbm]+(J-phi0)*dkdJr[isol][isbm]-dkdJ[isol]/m_pMat->SBMDensity(isbm)); } double zhat = m_pMat->GetMembraneReaction(ireact)->ReactionSupply(mp); mat3dd zhatI(zhat); mat3ds dzde = mat3dd(m_pMat->GetMembraneReaction(ireact)->Tangent_ReactionSupply_Strain(mp)); qcu[isol] -= ((zhatI+dzde*(J-phi0))*gradMu[j])*(sum1*c[isol]) +gradMu[j]*(c[isol]*(J-phi0)*sum2*zhat); qcw[isol] -= ((zhatI+dzde*(J-phi0))*gradMw[j])*(sum1*c[isol]) +gradMw[j]*(c[isol]*(J-phi0)*sum2*zhat); } } for (isol=0; isol<nsol; ++isol) { // calculate the kcu matrix vec3d kcu = ((ju[isol]+jue*penalty).transpose()*gradMu[i] + (qcu[isol] + dchatde[isol]*gradMu[j])*Mu[i])*(detJ*dt); vec3d kcw = ((jw[isol]+jwe*penalty).transpose()*gradMu[i] + (qcw[isol] + dchatde[isol]*gradMw[j])*Mu[i])*(detJ*dt); vec3d kdu = ((ju[isol]+jue*penalty).transpose()*gradMw[i] + (qcu[isol] + dchatde[isol]*gradMu[j])*Mw[i])*(detJ*dt); vec3d kdw = ((jw[isol]+jwe*penalty).transpose()*gradMw[i] + (qcw[isol] + dchatde[isol]*gradMw[j])*Mw[i])*(detJ*dt); ke[ndpn*i+8+2*isol][ndpn*j ] += kcu.x; ke[ndpn*i+8+2*isol][ndpn*j+1] += kcu.y; ke[ndpn*i+8+2*isol][ndpn*j+2] += kcu.z; ke[ndpn*i+8+2*isol][ndpn*j+3] += kcw.x; ke[ndpn*i+8+2*isol][ndpn*j+4] += kcw.y; ke[ndpn*i+8+2*isol][ndpn*j+5] += kcw.z; ke[ndpn*i+9+2*isol][ndpn*j ] += kdu.x; ke[ndpn*i+9+2*isol][ndpn*j+1] += kdu.y; ke[ndpn*i+9+2*isol][ndpn*j+2] += kdu.z; ke[ndpn*i+9+2*isol][ndpn*j+3] += kdw.x; ke[ndpn*i+9+2*isol][ndpn*j+4] += kdw.y; ke[ndpn*i+9+2*isol][ndpn*j+5] += kdw.z; // calculate the kcp matrix ke[ndpn*i+8+2*isol][ndpn*j+6] -= (gradMu[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradMu[j]) ))*(detJ*dt); ke[ndpn*i+8+2*isol][ndpn*j+7] -= (gradMu[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradMw[j]) ))*(detJ*dt); ke[ndpn*i+9+2*isol][ndpn*j+6] -= (gradMw[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradMu[j]) ))*(detJ*dt); ke[ndpn*i+9+2*isol][ndpn*j+7] -= (gradMw[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradMw[j]) ))*(detJ*dt); // calculate the kuc matrix sum = 0; for (jsol=0; jsol<nsol; ++jsol) sum += c[jsol]*(dodc[isol]*kappa[jsol]+osmc*dkdc[jsol][isol]); vec3d kuc = (dTdc[isol]*gradMu[i] - gradMu[i]*(R*T*(osmc*kappa[isol]+sum)))*Mu[j]*detJ; vec3d kud = (dTdc[isol]*gradMu[i] - gradMu[i]*(R*T*(osmc*kappa[isol]+sum)))*Mw[j]*detJ; vec3d kwc = (dTdc[isol]*gradMw[i] - gradMw[i]*(R*T*(osmc*kappa[isol]+sum)))*Mu[j]*detJ; vec3d kwd = (dTdc[isol]*gradMw[i] - gradMw[i]*(R*T*(osmc*kappa[isol]+sum)))*Mw[j]*detJ; ke[ndpn*i ][ndpn*j+8+2*isol] += kuc.x; ke[ndpn*i ][ndpn*j+9+2*isol] += kud.x; ke[ndpn*i+1][ndpn*j+8+2*isol] += kuc.y; ke[ndpn*i+1][ndpn*j+9+2*isol] += kud.y; ke[ndpn*i+2][ndpn*j+8+2*isol] += kuc.z; ke[ndpn*i+2][ndpn*j+9+2*isol] += kud.z; ke[ndpn*i+3][ndpn*j+8+2*isol] += kwc.x; ke[ndpn*i+3][ndpn*j+9+2*isol] += kwd.x; ke[ndpn*i+4][ndpn*j+8+2*isol] += kwc.y; ke[ndpn*i+4][ndpn*j+9+2*isol] += kwd.y; ke[ndpn*i+5][ndpn*j+8+2*isol] += kwc.z; ke[ndpn*i+5][ndpn*j+9+2*isol] += kwd.z; // calculate the kpc matrix vtmp = vec3d(0,0,0); for (jsol=0; jsol<nsol; ++jsol) vtmp += (D[jsol]*(dkdc[jsol][isol]-kappa[jsol]/D0[jsol]*dD0dc[jsol][isol]) +dDdc[jsol][isol]*kappa[jsol])/D0[jsol]*gradc[jsol]; wc[isol] = (dKedc[isol]*gp)*(-Mu[j]) -Ke*((D[isol]*gradMu[j])*(kappa[isol]/D0[isol])+vtmp*Mu[j])*(R*T); wd[isol] = (dKedc[isol]*gp)*(-Mw[j]) -Ke*((D[isol]*gradMw[j])*(kappa[isol]/D0[isol])+vtmp*Mw[j])*(R*T); ke[ndpn*i+6][ndpn*j+8+2*isol] += (gradMu[i]*wc[isol])*(detJ*dt); ke[ndpn*i+6][ndpn*j+9+2*isol] += (gradMu[i]*wd[isol])*(detJ*dt); ke[ndpn*i+7][ndpn*j+8+2*isol] += (gradMw[i]*wc[isol])*(detJ*dt); ke[ndpn*i+7][ndpn*j+9+2*isol] += (gradMw[i]*wd[isol])*(detJ*dt); } // calculate data for the kcc matrix jce.assign(nsol, vec3d(0,0,0)); jde.assign(nsol, vec3d(0,0,0)); for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { if (jsol != isol) { jc[isol][jsol] = ((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*Mu[j] +(D[isol]*(w*(-Mu[j]*dD0dc[isol][jsol]/D0[isol])+wc[jsol]))*(kappa[isol]*c[isol]/D0[isol]); jd[isol][jsol] = ((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*Mw[j] +(D[isol]*(w*(-Mw[j]*dD0dc[isol][jsol]/D0[isol])+wd[jsol]))*(kappa[isol]*c[isol]/D0[isol]); qcc[isol][jsol] = -Mu[j]*phiw/dt*c[isol]*dkdc[isol][jsol]; qcd[isol][jsol] = -Mw[j]*phiw/dt*c[isol]*dkdc[isol][jsol]; } else { jc[isol][jsol] = (D[isol]*(gradMu[j]*(-phiw)+w*(Mu[j]/D0[isol])))*kappa[isol] +((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*Mu[j] +(D[isol]*(w*(-Mu[j]*dD0dc[isol][jsol]/D0[isol])+wc[jsol]))*(kappa[isol]*c[isol]/D0[isol]); jd[isol][jsol] = (D[isol]*(gradMw[j]*(-phiw)+w*(Mw[j]/D0[isol])))*kappa[isol] +((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*Mw[j] +(D[isol]*(w*(-Mw[j]*dD0dc[isol][jsol]/D0[isol])+wd[jsol]))*(kappa[isol]*c[isol]/D0[isol]); qcc[isol][jsol] = -Mu[j]*phiw/dt*(c[isol]*dkdc[isol][jsol] + kappa[isol]); qcd[isol][jsol] = -Mw[j]*phiw/dt*(c[isol]*dkdc[isol][jsol] + kappa[isol]); } jce[jsol] += jc[isol][jsol]*z[isol]; jde[jsol] += jd[isol][jsol]*z[isol]; // chemical reactions dchatdc[isol][jsol] = 0; for (ireact=0; ireact<nreact; ++ireact) { dchatdc[isol][jsol] += m_pMat->GetReaction(ireact)->m_v[isol] *m_pMat->GetReaction(ireact)->Tangent_ReactionSupply_Concentration(mp,jsol); double sum1 = 0; double sum2 = 0; for (isbm=0; isbm<nsbm; ++isbm) { sum1 += m_pMat->SBMMolarMass(isbm)*m_pMat->GetReaction(ireact)->m_v[nsol+isbm]* ((J-phi0)*dkdr[isol][isbm]-kappa[isol]/m_pMat->SBMDensity(isbm)); sum2 += m_pMat->SBMMolarMass(isbm)*m_pMat->GetReaction(ireact)->m_v[nsol+isbm]* ((J-phi0)*dkdrc[isol][isbm][jsol]-dkdc[isol][jsol]/m_pMat->SBMDensity(isbm)); } double zhat = m_pMat->GetReaction(ireact)->ReactionSupply(mp); double dzdc = m_pMat->GetReaction(ireact)->Tangent_ReactionSupply_Concentration(mp, jsol); if (jsol != isol) { qcc[isol][jsol] -= Mu[j]*phiw*c[isol]*(dzdc*sum1+zhat*sum2); qcd[isol][jsol] -= Mw[j]*phiw*c[isol]*(dzdc*sum1+zhat*sum2); } else { qcc[isol][jsol] -= Mu[j]*phiw*((zhat+c[isol]*dzdc)*sum1+c[isol]*zhat*sum2); qcd[isol][jsol] -= Mw[j]*phiw*((zhat+c[isol]*dzdc)*sum1+c[isol]*zhat*sum2); } } // membrane reactions for (ireact=0; ireact<mreact; ++ireact) { dchatdc[isol][jsol] += m_pMat->GetMembraneReaction(ireact)->m_v[isol] *m_pMat->GetMembraneReaction(ireact)->Tangent_ReactionSupply_Concentration(mp,jsol); double sum1 = 0; double sum2 = 0; for (isbm=0; isbm<nsbm; ++isbm) { sum1 += m_pMat->SBMMolarMass(isbm)*m_pMat->GetMembraneReaction(ireact)->m_v[nsol+isbm]* ((J-phi0)*dkdr[isol][isbm]-kappa[isol]/m_pMat->SBMDensity(isbm)); sum2 += m_pMat->SBMMolarMass(isbm)*m_pMat->GetMembraneReaction(ireact)->m_v[nsol+isbm]* ((J-phi0)*dkdrc[isol][isbm][jsol]-dkdc[isol][jsol]/m_pMat->SBMDensity(isbm)); } double zhat = m_pMat->GetMembraneReaction(ireact)->ReactionSupply(mp); double dzdc = m_pMat->GetMembraneReaction(ireact)->Tangent_ReactionSupply_Concentration(mp, jsol); if (jsol != isol) { qcc[isol][jsol] -= Mu[j]*phiw*c[isol]*(dzdc*sum1+zhat*sum2); qcd[isol][jsol] -= Mw[j]*phiw*c[isol]*(dzdc*sum1+zhat*sum2); } else { qcc[isol][jsol] -= Mu[j]*phiw*((zhat+c[isol]*dzdc)*sum1+c[isol]*zhat*sum2); qcd[isol][jsol] -= Mw[j]*phiw*((zhat+c[isol]*dzdc)*sum1+c[isol]*zhat*sum2); } } } } // calculate the kcc matrix for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { ke[ndpn*i+8+2*isol][ndpn*j+8+2*jsol] += (gradMu[i]*(jc[isol][jsol]+jce[jsol]*penalty) + Mu[i]*(qcc[isol][jsol] + Mu[j]*phiw*dchatdc[isol][jsol]))*(detJ*dt); ke[ndpn*i+8+2*isol][ndpn*j+9+2*jsol] += (gradMu[i]*(jd[isol][jsol]+jde[jsol]*penalty) + Mu[i]*(qcd[isol][jsol] + Mw[j]*phiw*dchatdc[isol][jsol]))*(detJ*dt); ke[ndpn*i+9+2*isol][ndpn*j+8+2*jsol] += (gradMw[i]*(jc[isol][jsol]+jce[jsol]*penalty) + Mw[i]*(qcc[isol][jsol] + Mu[j]*phiw*dchatdc[isol][jsol]))*(detJ*dt); ke[ndpn*i+9+2*isol][ndpn*j+9+2*jsol] += (gradMw[i]*(jd[isol][jsol]+jde[jsol]*penalty) + Mw[i]*(qcd[isol][jsol] + Mw[j]*phiw*dchatdc[isol][jsol]))*(detJ*dt); } } } } } // Enforce symmetry by averaging top-right and bottom-left corners of stiffness matrix if (bsymm) { for (i=0; i<ndpn*neln; ++i) for (j=i+1; j<ndpn*neln; ++j) { tmp = 0.5*(ke[i][j]+ke[j][i]); ke[i][j] = ke[j][i] = tmp; } } return true; } //----------------------------------------------------------------------------- //! calculates element stiffness matrix for element iel //! for steady-state response (zero solid velocity, zero time derivative of //! solute concentration) //! bool FEMultiphasicShellDomain::ElementMultiphasicStiffnessSS(FEShellElement& el, matrix& ke, bool bsymm) { int i, j, isol, jsol, n, ireact; int nint = el.GaussPoints(); int neln = el.Nodes(); const double* Mr, *Ms, *M; // jacobian double Ji[3][3], detJ; // Gradient of shape functions vector<vec3d> gradMu(neln), gradMw(neln); vector<double> Mu(neln), Mw(neln); vec3d gradM; double tmp; // gauss-weights double* gw = el.GaussWeights(); double eta; vec3d gcnt[3]; double dt = GetFEModel()->GetTime().timeIncrement; const int nsol = m_pMat->Solutes(); int ndpn = 2*(4+nsol); const int nreact = m_pMat->Reactions(); const int mreact = m_pMat->MembraneReactions(); // zero stiffness matrix ke.zero(); // loop over gauss-points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint >()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint >()); // calculate jacobian detJ = invjact(el, Ji, n)*gw[n]; eta = el.gt(n); Mr = el.Hr(n); Ms = el.Hs(n); M = el.H(n); ContraBaseVectors(el, n, gcnt); // calculate global gradient of shape functions for (i=0; i<neln; ++i) { // calculate global gradient of shape functions gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; gradMu[i] = (gradM*(1+eta) + gcnt[2]*M[i])/2; gradMw[i] = (gradM*(1-eta) - gcnt[2]*M[i])/2; Mu[i] = (1+eta)/2*M[i]; Mw[i] = (1-eta)/2*M[i]; } // get stress tensor mat3ds s = ept.m_s; // get elasticity tensor tens4ds C = m_pMat->Tangent(mp); // next we get the determinant double J = ept.m_J; // get the fluid flux and pressure gradient vec3d w = ppt.m_w; vec3d gradp = ppt.m_gradp; vector<double> c(spt.m_c); vector<vec3d> gradc(spt.m_gradc); vector<int> z(nsol); vector<double> zz(nsol); vector<double> kappa(spt.m_k); // get the charge number for (isol=0; isol<nsol; ++isol) z[isol] = m_pMat->GetSolute(isol)->ChargeNumber(); vector<double> dkdJ(spt.m_dkdJ); vector< vector<double> > dkdc(spt.m_dkdc); // evaluate the porosity and its derivative double phiw = m_pMat->Porosity(mp); double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the osmotic coefficient double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp); // evaluate the permeability mat3ds K = m_pMat->GetPermeability()->Permeability(mp); tens4dmm dKdE = m_pMat->GetPermeability()->Tangent_Permeability_Strain(mp); vector<mat3ds> dKdc(nsol); vector<mat3ds> D(nsol); vector<tens4dmm> dDdE(nsol); vector< vector<mat3ds> > dDdc(nsol, vector<mat3ds>(nsol)); vector<double> D0(nsol); vector< vector<double> > dD0dc(nsol, vector<double>(nsol)); vector<double> dodc(nsol); vector<mat3ds> dTdc(nsol); vector<mat3ds> ImD(nsol); mat3dd I(1); // evaluate the solvent supply and its derivatives mat3ds Phie; Phie.zero(); double Phip = 0; vector<double> Phic(nsol,0); if (m_pMat->GetSolventSupply()) { Phie = m_pMat->GetSolventSupply()->Tangent_Supply_Strain(mp); Phip = m_pMat->GetSolventSupply()->Tangent_Supply_Pressure(mp); } // chemical reactions for (i=0; i<nreact; ++i) Phie += m_pMat->GetReaction(i)->m_Vbar*(I*m_pMat->GetReaction(i)->ReactionSupply(mp) +m_pMat->GetReaction(i)->Tangent_ReactionSupply_Strain(mp)*(J*phiw)); // membrane reactions for (i=0; i<mreact; ++i) Phie += m_pMat->GetReaction(i)->m_Vbar*mat3dd(m_pMat->GetMembraneReaction(i)->ReactionSupply(mp) +m_pMat->GetMembraneReaction(i)->Tangent_ReactionSupply_Strain(mp)*(J*phiw)); for (isol=0; isol<nsol; ++isol) { // evaluate the permeability derivatives dKdc[isol] = m_pMat->GetPermeability()->Tangent_Permeability_Concentration(mp,isol); // evaluate the diffusivity tensor and its derivatives D[isol] = m_pMat->GetSolute(isol)->m_pDiff->Diffusivity(mp); dDdE[isol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity D0[isol] = m_pMat->GetSolute(isol)->m_pDiff->Free_Diffusivity(mp); // evaluate the derivative of the osmotic coefficient dodc[isol] = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp,isol); // evaluate the stress tangent with concentration // dTdc[isol] = pm->GetSolid()->Tangent_Concentration(mp,isol); dTdc[isol] = mat3ds(0,0,0,0,0,0); ImD[isol] = I-D[isol]/D0[isol]; for (jsol=0; jsol<nsol; ++jsol) { dDdc[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Diffusivity_Concentration(mp,jsol); dD0dc[isol][jsol] = m_pMat->GetSolute(isol)->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,jsol); } // evaluate the solvent supply tangent with concentration if (m_pMat->GetSolventSupply()) Phic[isol] = m_pMat->GetSolventSupply()->Tangent_Supply_Concentration(mp,isol); } // Miscellaneous constants double R = m_pMat->m_Rgas; double T = m_pMat->m_Tabs; double penalty = m_pMat->m_penalty; // evaluate the effective permeability and its derivatives mat3ds Ki = K.inverse(); mat3ds Ke(0,0,0,0,0,0); tens4d G = (dyad1(Ki,I) - dyad4(Ki,I)*2)*2 - ddot(dyad2(Ki,Ki),dKdE); vector<mat3ds> Gc(nsol); vector<mat3ds> dKedc(nsol); for (isol=0; isol<nsol; ++isol) { Ke += ImD[isol]*(kappa[isol]*c[isol]/D0[isol]); G += dyad1(ImD[isol],I)*(R*T*c[isol]*J/D0[isol]/phiw*(dkdJ[isol]-kappa[isol]/phiw*dpdJ)) +(dyad1(I,I) - dyad2(I,I)*2 - dDdE[isol]/D0[isol])*(R*T*kappa[isol]*c[isol]/phiw/D0[isol]); Gc[isol] = ImD[isol]*(kappa[isol]/D0[isol]); for (jsol=0; jsol<nsol; ++jsol) { Gc[isol] += ImD[jsol]*(c[jsol]/D0[jsol]*(dkdc[jsol][isol]-kappa[jsol]/D0[jsol]*dD0dc[jsol][isol])) -(dDdc[jsol][isol]-D[jsol]*(dD0dc[jsol][isol]/D0[jsol])*(kappa[jsol]*c[jsol]/SQR(D0[jsol]))); } Gc[isol] *= R*T/phiw; } Ke = (Ki + Ke*(R*T/phiw)).inverse(); tens4d dKedE = (dyad1(Ke,I) - 2*dyad4(Ke,I))*2 - ddot(dyad2(Ke,Ke),G); for (isol=0; isol<nsol; ++isol) dKedc[isol] = -(Ke*(-Ki*dKdc[isol]*Ki + Gc[isol])*Ke).sym(); // calculate all the matrices vec3d vtmp,gp,qpu, qpw; vector<vec3d> gc(nsol),wc(nsol),wd(nsol),jce(nsol),jde(nsol); vector< vector<vec3d> > jc(nsol, vector<vec3d>(nsol)); vector< vector<vec3d> > jd(nsol, vector<vec3d>(nsol)); mat3d wu, ww, jue, jwe; vector<mat3d> ju(nsol), jw(nsol); vector< vector<double> > dchatdc(nsol, vector<double>(nsol)); double sum; mat3ds De; for (i=0; i<neln; ++i) { for (j=0; j<neln; ++j) { // Kuu matrix mat3d Kuu = (mat3dd(gradMu[i]*(s*gradMu[j])) + vdotTdotv(gradMu[i], C, gradMu[j]))*detJ; mat3d Kuw = (mat3dd(gradMu[i]*(s*gradMw[j])) + vdotTdotv(gradMu[i], C, gradMw[j]))*detJ; mat3d Kwu = (mat3dd(gradMw[i]*(s*gradMu[j])) + vdotTdotv(gradMw[i], C, gradMu[j]))*detJ; mat3d Kww = (mat3dd(gradMw[i]*(s*gradMw[j])) + vdotTdotv(gradMw[i], C, gradMw[j]))*detJ; ke[ndpn*i ][ndpn*j ] += Kuu[0][0]; ke[ndpn*i ][ndpn*j+1] += Kuu[0][1]; ke[ndpn*i ][ndpn*j+2] += Kuu[0][2]; ke[ndpn*i+1][ndpn*j ] += Kuu[1][0]; ke[ndpn*i+1][ndpn*j+1] += Kuu[1][1]; ke[ndpn*i+1][ndpn*j+2] += Kuu[1][2]; ke[ndpn*i+2][ndpn*j ] += Kuu[2][0]; ke[ndpn*i+2][ndpn*j+1] += Kuu[2][1]; ke[ndpn*i+2][ndpn*j+2] += Kuu[2][2]; ke[ndpn*i ][ndpn*j+3] += Kuw[0][0]; ke[ndpn*i ][ndpn*j+4] += Kuw[0][1]; ke[ndpn*i ][ndpn*j+5] += Kuw[0][2]; ke[ndpn*i+1][ndpn*j+3] += Kuw[1][0]; ke[ndpn*i+1][ndpn*j+4] += Kuw[1][1]; ke[ndpn*i+1][ndpn*j+5] += Kuw[1][2]; ke[ndpn*i+2][ndpn*j+3] += Kuw[2][0]; ke[ndpn*i+2][ndpn*j+4] += Kuw[2][1]; ke[ndpn*i+2][ndpn*j+5] += Kuw[2][2]; ke[ndpn*i+3][ndpn*j ] += Kwu[0][0]; ke[ndpn*i+3][ndpn*j+1] += Kwu[0][1]; ke[ndpn*i+3][ndpn*j+2] += Kwu[0][2]; ke[ndpn*i+4][ndpn*j ] += Kwu[1][0]; ke[ndpn*i+4][ndpn*j+1] += Kwu[1][1]; ke[ndpn*i+4][ndpn*j+2] += Kwu[1][2]; ke[ndpn*i+5][ndpn*j ] += Kwu[2][0]; ke[ndpn*i+5][ndpn*j+1] += Kwu[2][1]; ke[ndpn*i+5][ndpn*j+2] += Kwu[2][2]; ke[ndpn*i+3][ndpn*j+3] += Kww[0][0]; ke[ndpn*i+3][ndpn*j+4] += Kww[0][1]; ke[ndpn*i+3][ndpn*j+5] += Kww[0][2]; ke[ndpn*i+4][ndpn*j+3] += Kww[1][0]; ke[ndpn*i+4][ndpn*j+4] += Kww[1][1]; ke[ndpn*i+4][ndpn*j+5] += Kww[1][2]; ke[ndpn*i+5][ndpn*j+3] += Kww[2][0]; ke[ndpn*i+5][ndpn*j+4] += Kww[2][1]; ke[ndpn*i+5][ndpn*j+5] += Kww[2][2]; // calculate the kpu matrix gp = vec3d(0,0,0); for (isol=0; isol<nsol; ++isol) gp += (D[isol]*gradc[isol])*(kappa[isol]/D0[isol]); gp = gradp+gp*(R*T); wu = vdotTdotv(-gp, dKedE, gradMu[j]); ww = vdotTdotv(-gp, dKedE, gradMw[j]); for (isol=0; isol<nsol; ++isol) { wu += (((Ke*(D[isol]*gradc[isol])) & gradMu[j])*(J*dkdJ[isol] - kappa[isol]) +Ke*(2*kappa[isol]*(gradMu[j]*(D[isol]*gradc[isol]))))*(-R*T/D0[isol]) + (Ke*vdotTdotv(gradc[isol], dDdE[isol], gradMu[j]))*(-kappa[isol]*R*T/D0[isol]); ww += (((Ke*(D[isol]*gradc[isol])) & gradMw[j])*(J*dkdJ[isol] - kappa[isol]) +Ke*(2*kappa[isol]*(gradMw[j]*(D[isol]*gradc[isol]))))*(-R*T/D0[isol]) + (Ke*vdotTdotv(gradc[isol], dDdE[isol], gradMw[j]))*(-kappa[isol]*R*T/D0[isol]); } qpu = Phie*gradMu[j]; qpw = Phie*gradMw[j]; vec3d kpu = (wu.transpose()*gradMu[i] + qpu*Mu[i])*(detJ*dt); vec3d kpw = (ww.transpose()*gradMu[i] + qpw*Mu[i])*(detJ*dt); vec3d kqu = (wu.transpose()*gradMw[i] + qpu*Mw[i])*(detJ*dt); vec3d kqw = (ww.transpose()*gradMw[i] + qpw*Mw[i])*(detJ*dt); ke[ndpn*i+6][ndpn*j ] += kpu.x; ke[ndpn*i+6][ndpn*j+1] += kpu.y; ke[ndpn*i+6][ndpn*j+2] += kpu.z; ke[ndpn*i+6][ndpn*j+3] += kpw.x; ke[ndpn*i+6][ndpn*j+4] += kpw.y; ke[ndpn*i+6][ndpn*j+5] += kpw.z; ke[ndpn*i+7][ndpn*j ] += kqu.x; ke[ndpn*i+7][ndpn*j+1] += kqu.y; ke[ndpn*i+7][ndpn*j+2] += kqu.z; ke[ndpn*i+7][ndpn*j+3] += kqw.x; ke[ndpn*i+7][ndpn*j+4] += kqw.y; ke[ndpn*i+7][ndpn*j+5] += kqw.z; // calculate the kup matrix vec3d kup = gradMu[i]*(-Mu[j]*detJ); vec3d kuq = gradMu[i]*(-Mw[j]*detJ); vec3d kwp = gradMw[i]*(-Mu[j]*detJ); vec3d kwq = gradMw[i]*(-Mw[j]*detJ); ke[ndpn*i ][ndpn*j+6] += kup.x; ke[ndpn*i ][ndpn*j+7] += kuq.x; ke[ndpn*i+1][ndpn*j+6] += kup.y; ke[ndpn*i+1][ndpn*j+7] += kuq.y; ke[ndpn*i+2][ndpn*j+6] += kup.z; ke[ndpn*i+2][ndpn*j+7] += kuq.z; ke[ndpn*i+3][ndpn*j+6] += kwp.x; ke[ndpn*i+3][ndpn*j+7] += kwq.x; ke[ndpn*i+4][ndpn*j+6] += kwp.y; ke[ndpn*i+4][ndpn*j+7] += kwq.y; ke[ndpn*i+5][ndpn*j+6] += kwp.z; ke[ndpn*i+5][ndpn*j+7] += kwq.z; // calculate the kpp matrix ke[ndpn*i+6][ndpn*j+6] += (Mu[i]*Mu[j]*Phip - gradMu[i]*(Ke*gradMu[j]))*(detJ*dt); ke[ndpn*i+6][ndpn*j+7] += (Mu[i]*Mw[j]*Phip - gradMu[i]*(Ke*gradMw[j]))*(detJ*dt); ke[ndpn*i+7][ndpn*j+6] += (Mw[i]*Mu[j]*Phip - gradMw[i]*(Ke*gradMu[j]))*(detJ*dt); ke[ndpn*i+7][ndpn*j+7] += (Mw[i]*Mw[j]*Phip - gradMw[i]*(Ke*gradMw[j]))*(detJ*dt); // calculate kcu matrix data jue.zero(); jwe.zero(); De.zero(); for (isol=0; isol<nsol; ++isol) { gc[isol] = -gradc[isol]*phiw + w*c[isol]/D0[isol]; ju[isol] = ((D[isol]*gc[isol]) & gradMu[j])*(J*dkdJ[isol]) + vdotTdotv(gc[isol], dDdE[isol], gradMu[j])*kappa[isol] + (((D[isol]*gradc[isol]) & gradMu[j])*(-phis) +(D[isol]*((gradMu[j]*w)*2) - ((D[isol]*w) & gradMu[j]))*c[isol]/D0[isol] )*kappa[isol] +D[isol]*wu*(kappa[isol]*c[isol]/D0[isol]); jw[isol] = ((D[isol]*gc[isol]) & gradMw[j])*(J*dkdJ[isol]) + vdotTdotv(gc[isol], dDdE[isol], gradMw[j])*kappa[isol] + (((D[isol]*gradc[isol]) & gradMw[j])*(-phis) +(D[isol]*((gradMw[j]*w)*2) - ((D[isol]*w) & gradMw[j]))*c[isol]/D0[isol] )*kappa[isol] +D[isol]*ww*(kappa[isol]*c[isol]/D0[isol]); jue += ju[isol]*z[isol]; jwe += jw[isol]*z[isol]; De += D[isol]*(z[isol]*kappa[isol]*c[isol]/D0[isol]); } for (isol=0; isol<nsol; ++isol) { // calculate the kcu matrix vec3d kcu = ((ju[isol]+jue*penalty).transpose()*gradMu[i])*(detJ*dt); vec3d kcw = ((jw[isol]+jwe*penalty).transpose()*gradMu[i])*(detJ*dt); vec3d kdu = ((ju[isol]+jue*penalty).transpose()*gradMw[i])*(detJ*dt); vec3d kdw = ((jw[isol]+jwe*penalty).transpose()*gradMw[i])*(detJ*dt); ke[ndpn*i+8+2*isol][ndpn*j ] += kcu.x; ke[ndpn*i+8+2*isol][ndpn*j+1] += kcu.y; ke[ndpn*i+8+2*isol][ndpn*j+2] += kcu.z; ke[ndpn*i+8+2*isol][ndpn*j+3] += kcw.x; ke[ndpn*i+8+2*isol][ndpn*j+4] += kcw.y; ke[ndpn*i+8+2*isol][ndpn*j+5] += kcw.z; ke[ndpn*i+9+2*isol][ndpn*j ] += kdu.x; ke[ndpn*i+9+2*isol][ndpn*j+1] += kdu.y; ke[ndpn*i+9+2*isol][ndpn*j+2] += kdu.z; ke[ndpn*i+9+2*isol][ndpn*j+3] += kdw.x; ke[ndpn*i+9+2*isol][ndpn*j+4] += kdw.y; ke[ndpn*i+9+2*isol][ndpn*j+5] += kdw.z; // calculate the kcp matrix ke[ndpn*i+8+2*isol][ndpn*j+6] -= (gradMu[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradMu[j]) ))*(detJ*dt); ke[ndpn*i+8+2*isol][ndpn*j+7] -= (gradMu[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradMw[j]) ))*(detJ*dt); ke[ndpn*i+9+2*isol][ndpn*j+6] -= (gradMw[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradMu[j]) ))*(detJ*dt); ke[ndpn*i+9+2*isol][ndpn*j+7] -= (gradMw[i]*( (D[isol]*(kappa[isol]*c[isol]/D0[isol]) +De*penalty) *(Ke*gradMw[j]) ))*(detJ*dt); // calculate the kuc matrix sum = 0; for (jsol=0; jsol<nsol; ++jsol) sum += c[jsol]*(dodc[isol]*kappa[jsol]+osmc*dkdc[jsol][isol]); vec3d kuc = (dTdc[isol]*gradMu[i] - gradMu[i]*(R*T*(osmc*kappa[isol]+sum)))*Mu[j]*detJ; vec3d kud = (dTdc[isol]*gradMu[i] - gradMu[i]*(R*T*(osmc*kappa[isol]+sum)))*Mw[j]*detJ; vec3d kwc = (dTdc[isol]*gradMw[i] - gradMw[i]*(R*T*(osmc*kappa[isol]+sum)))*Mu[j]*detJ; vec3d kwd = (dTdc[isol]*gradMw[i] - gradMw[i]*(R*T*(osmc*kappa[isol]+sum)))*Mw[j]*detJ; ke[ndpn*i ][ndpn*j+8+2*isol] += kuc.x; ke[ndpn*i ][ndpn*j+9+2*isol] += kud.x; ke[ndpn*i+1][ndpn*j+8+2*isol] += kuc.y; ke[ndpn*i+1][ndpn*j+9+2*isol] += kud.y; ke[ndpn*i+2][ndpn*j+8+2*isol] += kuc.z; ke[ndpn*i+2][ndpn*j+9+2*isol] += kud.z; ke[ndpn*i+3][ndpn*j+8+2*isol] += kwc.x; ke[ndpn*i+3][ndpn*j+9+2*isol] += kwd.x; ke[ndpn*i+4][ndpn*j+8+2*isol] += kwc.y; ke[ndpn*i+4][ndpn*j+9+2*isol] += kwd.y; ke[ndpn*i+5][ndpn*j+8+2*isol] += kwc.z; ke[ndpn*i+5][ndpn*j+9+2*isol] += kwd.z; // calculate the kpc matrix vtmp = vec3d(0,0,0); for (jsol=0; jsol<nsol; ++jsol) vtmp += (D[jsol]*(dkdc[jsol][isol]-kappa[jsol]/D0[jsol]*dD0dc[jsol][isol]) +dDdc[jsol][isol]*kappa[jsol])/D0[jsol]*gradc[jsol]; wc[isol] = (dKedc[isol]*gp)*(-Mu[j]) -Ke*((D[isol]*gradMu[j])*(kappa[isol]/D0[isol])+vtmp*Mu[j])*(R*T); wd[isol] = (dKedc[isol]*gp)*(-Mw[j]) -Ke*((D[isol]*gradMw[j])*(kappa[isol]/D0[isol])+vtmp*Mw[j])*(R*T); ke[ndpn*i+6][ndpn*j+8+2*isol] += (gradMu[i]*wc[isol])*(detJ*dt); ke[ndpn*i+6][ndpn*j+9+2*isol] += (gradMu[i]*wd[isol])*(detJ*dt); ke[ndpn*i+7][ndpn*j+8+2*isol] += (gradMw[i]*wc[isol])*(detJ*dt); ke[ndpn*i+7][ndpn*j+9+2*isol] += (gradMw[i]*wd[isol])*(detJ*dt); } // calculate data for the kcc matrix jce.assign(nsol, vec3d(0,0,0)); jde.assign(nsol, vec3d(0,0,0)); for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { if (jsol != isol) { jc[isol][jsol] = ((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*Mu[j] +(D[isol]*(w*(-Mu[j]*dD0dc[isol][jsol]/D0[isol])+wc[jsol]))*(kappa[isol]*c[isol]/D0[isol]); jd[isol][jsol] = ((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*Mw[j] +(D[isol]*(w*(-Mw[j]*dD0dc[isol][jsol]/D0[isol])+wd[jsol]))*(kappa[isol]*c[isol]/D0[isol]); } else { jc[isol][jsol] = (D[isol]*(gradMu[j]*(-phiw)+w*(Mu[j]/D0[isol])))*kappa[isol] +((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*Mu[j] +(D[isol]*(w*(-Mu[j]*dD0dc[isol][jsol]/D0[isol])+wc[jsol]))*(kappa[isol]*c[isol]/D0[isol]); jd[isol][jsol] = (D[isol]*(gradMw[j]*(-phiw)+w*(Mw[j]/D0[isol])))*kappa[isol] +((D[isol]*dkdc[isol][jsol]+dDdc[isol][jsol]*kappa[isol])*gc[isol])*Mw[j] +(D[isol]*(w*(-Mw[j]*dD0dc[isol][jsol]/D0[isol])+wd[jsol]))*(kappa[isol]*c[isol]/D0[isol]); } jce[jsol] += jc[isol][jsol]*z[isol]; jde[jsol] += jd[isol][jsol]*z[isol]; // chemical reactions dchatdc[isol][jsol] = 0; for (ireact=0; ireact<nreact; ++ireact) dchatdc[isol][jsol] += m_pMat->GetReaction(ireact)->m_v[isol] *m_pMat->GetReaction(ireact)->Tangent_ReactionSupply_Concentration(mp,jsol); // membrane reactions for (ireact=0; ireact<mreact; ++ireact) dchatdc[isol][jsol] += m_pMat->GetMembraneReaction(ireact)->m_v[isol] *m_pMat->GetMembraneReaction(ireact)->Tangent_ReactionSupply_Concentration(mp,jsol); } } // calculate the kcc matrix for (isol=0; isol<nsol; ++isol) { for (jsol=0; jsol<nsol; ++jsol) { ke[ndpn*i+8+2*isol][ndpn*j+8+2*jsol] += (gradMu[i]*(jc[isol][jsol]+jce[jsol]*penalty) + Mu[i]*Mu[j]*phiw*dchatdc[isol][jsol])*(detJ*dt); ke[ndpn*i+8+2*isol][ndpn*j+9+2*jsol] += (gradMu[i]*(jd[isol][jsol]+jde[jsol]*penalty) + Mu[i]*Mw[j]*phiw*dchatdc[isol][jsol])*(detJ*dt); ke[ndpn*i+9+2*isol][ndpn*j+8+2*jsol] += (gradMw[i]*(jc[isol][jsol]+jce[jsol]*penalty) + Mw[i]*Mu[j]*phiw*dchatdc[isol][jsol])*(detJ*dt); ke[ndpn*i+9+2*isol][ndpn*j+9+2*jsol] += (gradMw[i]*(jd[isol][jsol]+jde[jsol]*penalty) + Mw[i]*Mw[j]*phiw*dchatdc[isol][jsol])*(detJ*dt); } } } } } // Enforce symmetry by averaging top-right and bottom-left corners of stiffness matrix if (bsymm) { for (i=0; i<ndpn*neln; ++i) for (j=i+1; j<ndpn*neln; ++j) { tmp = 0.5*(ke[i][j]+ke[j][i]); ke[i][j] = ke[j][i] = tmp; } } return true; } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::MembraneReactionFluxes(FEGlobalVector& R) { const int mreact = m_pMat->MembraneReactions(); if (mreact == 0) return; int NE = (int)m_Elem.size(); #pragma omp parallel for for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FEShellElement& el = m_Elem[i]; // calculate internal force vector ElementMembraneReactionFlux(el, fe); // get the element's LM vector UnpackMembraneLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe, true); } } //----------------------------------------------------------------------------- //! element external work of flux generated by membrane reactions void FEMultiphasicShellDomain::ElementMembraneReactionFlux(FEShellElement& el, vector<double>& fe) { double dt = GetFEModel()->GetTime().timeIncrement; // get the first material point FEMaterialPoint& mp = *el.GetMaterialPoint(0); FESolutesMaterialPoint& ps = *mp.ExtractData<FESolutesMaterialPoint>(); int nse = (int)ps.m_ce.size(); int nsi = (int)ps.m_ci.size(); int ndpn = 8 + nse + nsi; // nr integration points int nint = el.GaussPoints(); // nr of element nodes int neln = el.Nodes(); fe.resize(neln*ndpn,0); // get the element's nodal positions vec3d re[FEElement::MAX_NODES], ri[FEElement::MAX_NODES]; for (int j=0; j<neln; ++j) { FENode& nd = GetFEModel()->GetMesh().Node(el.m_node[j]); // nodal positions at front and back surfaces re[j] = nd.m_rt; ri[j] = nd.st(); } double *Mr, *Ms; double *M; double *w = el.GaussWeights(); vec3d dxer, dxes, dxet; vec3d dxir, dxis, dxit; // repeat over integration points for (int n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FESolutesMaterialPoint& ps = *mp.ExtractData<FESolutesMaterialPoint>(); M = el.H(n); Mr = el.Hr(n); Ms = el.Hs(n); // evaluate normal solute flux at integration point vector<double> je(nse,0), ji(nsi,0); for (int ireact=0; ireact<m_pMat->MembraneReactions(); ++ireact) { FEMembraneReaction* react = m_pMat->GetMembraneReaction(ireact); FESoluteInterface* psm = react->m_psm; double zbar = react->ReactionSupply(mp); double zve = 0, zvi = 0; for (int k=0; k<nse; ++k) { int id = ps.m_ide[k]; zve += react->m_z[id]*react->m_ve[id]; } for (int k=0; k<nsi; ++k) { int id = ps.m_idi[k]; zvi += react->m_z[id]*react->m_vi[id]; } // Divide fluxes by two because we are integrating over the shell volume // but we should only integrate over the shell surface. for (int k=0; k<nse; ++k) je[k] -= zbar*(react->m_ve[ps.m_ide[k]] + zve)/2; for (int k=0; k<nsi; ++k) ji[k] -= zbar*(react->m_vi[ps.m_idi[k]] + zvi)/2; } dxer = dxes = vec3d(0,0,0); dxir = dxis = vec3d(0,0,0); for (int i=0; i<neln; ++i) { dxer += re[i]*Mr[i]; dxes += re[i]*Ms[i]; dxir += ri[i]*Mr[i]; dxis += ri[i]*Ms[i]; } double ae = (dxer ^ dxes).norm()*w[n]*dt; double ai = (dxir ^ dxis).norm()*w[n]*dt; for (int i=0; i<neln; ++i) { for (int k=0; k<nse; ++k) fe[ndpn*i+8+k] += M[i]*je[k]*ae; for (int k=0; k<nsi; ++k) fe[ndpn*i+8+nse+k] += M[i]*ji[k]*ai; } } } //----------------------------------------------------------------------------- //! calculates the membrane reaction stiffness matrix for this domain void FEMultiphasicShellDomain::MembraneReactionStiffnessMatrix(FELinearSystem& LS) { const int mreact = m_pMat->MembraneReactions(); if (mreact == 0) return; // repeat over all solid elements int NE = (int)m_Elem.size(); #pragma omp parallel for for (int iel=0; iel<NE; ++iel) { FEShellElement& el = m_Elem[iel]; // element stiffness matrix FEElementMatrix ke(el); vector<int> lm; UnpackMembraneLM(el, lm); ke.SetIndices(lm); // calculate the element stiffness matrix ElementMembraneFluxStiffness(el, ke); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- //! calculates the element membrane flux stiffness matrix bool FEMultiphasicShellDomain::ElementMembraneFluxStiffness(FEShellElement& el, matrix& ke) { double dt = GetFEModel()->GetTime().timeIncrement; // get the first material point FEMaterialPoint& mp = *el.GetMaterialPoint(0); FESolutesMaterialPoint& ps = *mp.ExtractData<FESolutesMaterialPoint>(); int nse = (int)ps.m_ce.size(); int nsi = (int)ps.m_ci.size(); int ndpn = 8 + nse + nsi; // nr integration points int nint = el.GaussPoints(); // nr of element nodes int neln = el.Nodes(); int ndof = ndpn*neln; // allocate stiffness matrix ke.resize(ndof, ndof); // get the element's nodal coordinates vec3d re[FEElement::MAX_NODES], ri[FEElement::MAX_NODES]; for (int j=0; j<neln; ++j) { FENode& nd = GetFEModel()->GetMesh().Node(el.m_node[j]); re[j] = nd.m_rt; ri[j] = nd.st(); } double *Mr, *Ms; double *M; double *w = el.GaussWeights(); vec3d dxir, dxis, dxit; vec3d dxer, dxes, dxet; // repeat over integration points ke.zero(); for (int n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FESolutesMaterialPoint& ps = *mp.ExtractData<FESolutesMaterialPoint>(); M = el.H(n); Mr = el.Hr(n); Ms = el.Hs(n); // evaluate normal solute flux and its derivatives at integration point // take summation over all membrane reactions vector<double> je(nse,0), ji(nsi,0); vector<double> djedJ(nse,0), djidJ(nsi,0); vector<double> djedp(nse,0), djidp(nsi,0); vector< vector<double> > djedc(nse,vector<double>(nse,0)); vector< vector<double> > djidc(nsi,vector<double>(nsi,0)); for (int ireact=0; ireact<m_pMat->MembraneReactions(); ++ireact) { FEMembraneReaction* react = m_pMat->GetMembraneReaction(ireact); FESoluteInterface* psm = react->m_psm; double zbar = react->ReactionSupply(mp); double dzdJ = react->Tangent_ReactionSupply_Strain(mp); double dzdpe = react->Tangent_ReactionSupply_Pe(mp); double dzdpi = react->Tangent_ReactionSupply_Pi(mp); vector<double> dzdce(nse,0), dzdci(nsi,0); double zve = 0, zvi = 0; for (int k=0; k<nse; ++k) { dzdce[k] = react->Tangent_ReactionSupply_Ce(mp, k); int id = ps.m_ide[k]; zve += react->m_z[id]*react->m_ve[id]; } for (int k=0; k<nsi; ++k) { dzdci[k] = react->Tangent_ReactionSupply_Ci(mp, k); int id = ps.m_idi[k]; zvi += react->m_z[id]*react->m_vi[id]; } // Divide fluxes by two because we are integrating over the shell volume // but we should only integrate over the shell surface. for (int k=0; k<nse; ++k) { je[k] -= zbar*(react->m_ve[ps.m_ide[k]] + zve)/2; djedJ[k] -= dzdJ*(react->m_ve[ps.m_ide[k]] + zve)/2; djedp[k] -= dzdpe*(react->m_ve[ps.m_ide[k]] + zve)/2; for (int l=0; l<nse; ++l) djedc[k][l] -= dzdce[l]*(react->m_ve[ps.m_ide[k]] + zve)/2; } for (int k=0; k<nsi; ++k) { ji[k] -= zbar*(react->m_vi[ps.m_idi[k]] + zvi)/2; djidJ[k] -= dzdJ*(react->m_vi[ps.m_idi[k]] + zvi)/2; djidp[k] -= dzdpi*(react->m_vi[ps.m_idi[k]] + zvi)/2; for (int l=0; l<nsi; ++l) djidc[k][l] -= dzdci[l]*(react->m_vi[ps.m_idi[k]] + zvi)/2; } } dxer = dxes = vec3d(0,0,0); dxir = dxis = vec3d(0,0,0); for (int i=0; i<neln; ++i) { dxer += re[i]*Mr[i]; dxes += re[i]*Ms[i]; dxir += ri[i]*Mr[i]; dxis += ri[i]*Ms[i]; } dxet = dxer ^ dxes; dxit = dxir ^ dxis; double Je = (dxer ^ dxes).norm(); double Ji = (dxir ^ dxis).norm(); vec3d ne = dxet/Je; vec3d ni = dxit/Ji; for (int i=0; i<neln; ++i) { int ir = ndpn*i+8; for (int j=0; j<neln; ++j) { int ic = ndpn*j; // front face vec3d ge = dxes*Mr[j] - dxer*Ms[j]; mat3d Ae; Ae.skew(ge); vec3d ve = Ae*ne; for (int k=0; k<nse; ++k) { vec3d kcu = ve*(je[k] + djedJ[k]*Je)*M[i]*w[n]*dt; ke[ir+k][ic ] -= kcu.x; ke[ir+k][ic+1] -= kcu.y; ke[ir+k][ic+2] -= kcu.z; double kcp = djedp[k]*M[i]*M[j]*Je*w[n]*dt; ke[ir+k][ic+6] -= kcp; for (int l=0; l<nse; ++l) { double kcc = djedc[k][l]*M[i]*M[j]*Je*w[n]*dt; ke[ir+k][ic+8+l] -= kcc; } } // back face vec3d gi = dxis*Mr[j] - dxir*Ms[j]; mat3d Ai; Ai.skew(gi); vec3d vi = Ai*ni; for (int k=0; k<nsi; ++k) { vec3d kdw = vi*(ji[k] + djidJ[k]*Ji)*M[i]*w[n]*dt; ke[ir+nse+k][ic+3] -= kdw.x; ke[ir+nse+k][ic+4] -= kdw.y; ke[ir+nse+k][ic+5] -= kdw.z; double kdq = djidp[k]*M[i]*M[j]*Ji*w[n]*dt; ke[ir+nse+k][ic+7] -= kdq; for (int l=0; l<nsi; ++l) { double kdd = djidc[k][l]*M[i]*M[j]*Ji*w[n]*dt; ke[ir+nse+k][ic+8+nse+l] -= kdd; } } } } } return true; } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::Update(const FETimeInfo& tp) { FESSIShellDomain::Update(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(); } //----------------------------------------------------------------------------- void FEMultiphasicShellDomain::UpdateElementStress(int iel, const FETimeInfo& tp) { double dt = tp.timeIncrement; int j, k, n; int nint, neln; double* gw; vec3d r0[FEElement::MAX_NODES]; vec3d rt[FEElement::MAX_NODES]; double pn[FEElement::MAX_NODES], qn[FEElement::MAX_NODES]; DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); int MAX_DDOFS = fedofs.GetVariableSize("shell concentration"); FEMesh& mesh = *m_pMesh; // get the multiphasic material FEMultiphasic* pmb = m_pMat; const int nsol = (int)pmb->Solutes(); vector<int> sid(nsol); for (j=0; j<nsol; ++j) sid[j] = pmb->GetSolute(j)->GetSoluteDOF(); // get the shell element FEShellElement& el = m_Elem[iel]; // get the number of integration points nint = el.GaussPoints(); // get the number of nodes neln = el.Nodes(); vector< vector<double> > cn(MAX_CDOFS, vector<double>(neln)); vector< vector<double> > dn(MAX_DDOFS, vector<double>(neln)); // get the integration weights gw = el.GaussWeights(); const double *M, *Mr, *Ms; // get the nodal data for (j=0; j<neln; ++j) { r0[j] = mesh.Node(el.m_node[j]).m_r0; rt[j] = mesh.Node(el.m_node[j]).m_rt; pn[j] = mesh.Node(el.m_node[j]).get(m_dofP); qn[j] = mesh.Node(el.m_node[j]).get(m_dofQ); for (k=0; k<MAX_CDOFS; ++k) cn[k][j] = mesh.Node(el.m_node[j]).get(m_dofC + k); for (k=0; k<MAX_DDOFS; ++k) dn[k][j] = mesh.Node(el.m_node[j]).get(m_dofD + k); } // loop over the integration points and calculate // the stress at the integration point for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); // material point coordinates // TODO: I'm not entirly happy with this solution // since the material point coordinates are used by most materials. mp.m_r0 = el.Evaluate(r0, n); mp.m_rt = el.Evaluate(rt, n); // get the deformation gradient and determinant pt.m_J = defgrad(el, pt.m_F, n); mat3d Fp; defgradp(el, Fp, n); mat3d Fi = pt.m_F.inverse(); pt.m_L = (pt.m_F - Fp)*Fi / dt; // multiphasic material point data FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // update membrane reaction data if needed if (m_pMat->MembraneReactions()) { int nse = (int)spt.m_ce.size(); int nsi = (int)spt.m_ci.size(); M = el.H(n); Mr = el.Hr(n); Ms = el.Hs(n); double pe = 0, pi = 0; vector<double> ce(nse,0), ci(nsi,0); vec3d dxr(0,0,0), dxs(0,0,0); vec3d dXr(0,0,0), dXs(0,0,0); for (int j=0; j<neln; ++j) { dxr += rt[j]*Mr[j]; dxs += rt[j]*Ms[j]; dXr += r0[j]*Mr[j]; dXs += r0[j]*Ms[j]; pe += pn[j]*M[j]; pi += qn[j]*M[j]; for (int k=0; k<nse; ++k) ce[k] += cn[spt.m_ide[k]][j]*M[j]; for (int k=0; k<nsi; ++k) ci[k] += dn[spt.m_idi[k]][j]*M[j]; } spt.m_strain = (dxr ^ dxs).norm()/(dXr ^ dXs).norm(); spt.m_pe = pe; spt.m_pi = pi; spt.m_ce = ce; spt.m_ci = ci; } for (k=0; k<nsol; ++k) { // evaluate effective solute concentrations at gauss-point spt.m_c[k] = evaluate(el, cn[sid[k]], dn[sid[k]], n); // calculate the gradient of c at gauss-point spt.m_gradc[k] = gradient(el, cn[sid[k]], dn[sid[k]], n); } // update SBM referential densities pmb->UpdateSolidBoundMolecules(mp); // evaluate referential solid volume fraction ppt.m_phi0t = pmb->SolidReferentialVolumeFraction(mp); if (m_breset) ppt.m_phi0 = ppt.m_phi0t; // evaluate fluid pressure at gauss-point ppt.m_p = evaluate(el, pn, qn, n); // calculate the gradient of p at gauss-point ppt.m_gradp = gradient(el, pn, qn, n); // update the fluid and solute fluxes // and evaluate the actual fluid pressure and solute concentration ppt.m_w = pmb->FluidFlux(mp); spt.m_psi = pmb->ElectricPotential(mp); for (k=0; k<nsol; ++k) { spt.m_ca[k] = pmb->Concentration(mp,k); spt.m_j[k] = pmb->SoluteFlux(mp,k); } ppt.m_pa = pmb->Pressure(mp); spt.m_cF = pmb->FixedChargeDensity(mp); spt.m_Ie = pmb->CurrentDensity(mp); pmb->PartitionCoefficientFunctions(mp, spt.m_k, spt.m_dkdJ, spt.m_dkdc, spt.m_dkdr, spt.m_dkdJr, spt.m_dkdrc); // update specialized material points m_pMat->UpdateSpecializedMaterialPoints(mp, GetFEModel()->GetTime()); // calculate the solid stress at this material point ppt.m_ss = pmb->GetElasticMaterial()->Stress(mp); // evaluate the stress pt.m_s = pmb->Stress(mp); // evaluate the referential solid density spt.m_rhor = pmb->SolidReferentialApparentDensity(mp); // update chemical reaction element data for (int j=0; j<m_pMat->Reactions(); ++j) pmb->GetReaction(j)->UpdateElementData(mp); // update membrane reaction element data for (int j=0; j<m_pMat->MembraneReactions(); ++j) pmb->GetMembraneReaction(j)->UpdateElementData(mp); } if (m_breset) m_breset = false; } //----------------------------------------------------------------------------- // Extract the solute DOFs for the solid elements on either side of the shell domain void FEMultiphasicShellDomain::UpdateShellMPData(int iel) { if (m_pMat->MembraneReactions() == 0) return; static bool bfirst = true; if (bfirst) { FEMesh& mesh = *GetMesh(); // get the shell element FEShellElement& el = m_Elem[iel]; FEElement* si = mesh.FindElementFromID(el.m_elem[0]); FEElement* se = mesh.FindElementFromID(el.m_elem[1]); if ((si == nullptr) || (se == nullptr)) return; FEMultiphasic* mpi = dynamic_cast<FEMultiphasic*>(GetFEModel()->GetMaterial(si->GetMatID())); FEMultiphasic* mpe = dynamic_cast<FEMultiphasic*>(GetFEModel()->GetMaterial(se->GetMatID())); if ((mpi == nullptr) || (mpe == nullptr)) return; vector<int> idi(mpi->Solutes(),-1); vector<int> ide(mpe->Solutes(),-1); for (int i=0; i<mpi->Solutes(); ++i) idi[i] = mpi->GetSolute(i)->GetSoluteDOF(); for (int i=0; i<mpe->Solutes(); ++i) ide[i] = mpe->GetSolute(i)->GetSoluteDOF(); // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n = 0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); ps.m_ide = ide; ps.m_idi = idi; ps.m_ce.resize(ide.size()); ps.m_ci.resize(idi.size()); } bfirst = false; } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEInitialEffectiveFluidPressure.h
.h
1,678
46
/*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/FEInitialCondition.h> class FEInitialEffectiveFluidPressure : public FEInitialDOF { public: FEInitialEffectiveFluidPressure(FEModel* fem); bool Init() override; DECLARE_FECORE_CLASS(); }; class FEInitialShellEffectiveFluidPressure : public FEInitialDOF { public: FEInitialShellEffectiveFluidPressure(FEModel* fem); bool Init() override; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESFDSBM.h
.h
2,637
76
/*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 <FEBioMech/FEElasticMaterial.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Material class for the spherical fiber distribution with //! fiber modulus dependent on sbm referential density class FEBIOMIX_API FESFDSBM : public FEElasticMaterial { public: FESFDSBM(FEModel* pfem) : FEElasticMaterial(pfem) { m_alpha = 0; m_sbm = -1; } //! Initialization bool Init() override; //! Cauchy stress mat3ds Stress(FEMaterialPoint& mp) override; // Spatial tangent tens4ds Tangent(FEMaterialPoint& mp) override; // Strain energy density double StrainEnergyDensity(FEMaterialPoint& mp) override; //! return fiber modulus double FiberModulus(double rhor) { return m_ksi0*pow(rhor/m_rho0, m_g);} // declare the parameter list DECLARE_FECORE_CLASS(); public: double m_alpha; // coefficient of exponential argument double m_beta; // power in power-law relation double m_ksi0; // ksi = ksi0*(rhor/rho0)^gamma double m_rho0; // rho0 double m_g; // gamma int m_sbm; //!< global id of solid-bound molecule int m_lsbm; //!< local id of solid-bound molecule static int m_nres; // integration rule static double m_cth[]; static double m_sth[]; static double m_cph[]; static double m_sph[]; static double m_w[]; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESolventSupply.cpp
.cpp
1,657
39
/*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 "FESolventSupply.h" //----------------------------------------------------------------------------- // Derivative of supply w.r.t. solute concentration at material point // Set this to zero by default because biphasic problems do not require it double FESolventSupply::Tangent_Supply_Concentration(FEMaterialPoint& pt, const int isol) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESupplySynthesisBinding.cpp
.cpp
4,726
129
/*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 "FESupplySynthesisBinding.h" // define the material parameters BEGIN_FECORE_CLASS(FESupplySynthesisBinding, FESoluteSupply) ADD_PARAMETER(m_supp, "supp"); ADD_PARAMETER(m_kf , FE_RANGE_GREATER (0.0), "kf" ); ADD_PARAMETER(m_kr , FE_RANGE_GREATER_OR_EQUAL(0.0), "kr" ); ADD_PARAMETER(m_crt , FE_RANGE_GREATER_OR_EQUAL(0.0), "Rtot"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FESupplySynthesisBinding::FESupplySynthesisBinding(FEModel* pfem) : FESoluteSupply(pfem) { m_supp = m_kf = m_kr = m_crt = 0; } //----------------------------------------------------------------------------- //! Solute supply double FESupplySynthesisBinding::Supply(FEMaterialPoint& mp) { double crhat = m_supp-ReceptorLigandSupply(mp); return crhat; } //----------------------------------------------------------------------------- //! Tangent of solute supply with respect to strain double FESupplySynthesisBinding::Tangent_Supply_Strain(FEMaterialPoint &mp) { return 0; } //----------------------------------------------------------------------------- //! Tangent of solute supply with respect to referential concentration double FESupplySynthesisBinding::Tangent_Supply_Concentration(FEMaterialPoint &mp) { FESolutesMaterialPoint& pt = *mp.ExtractData<FESolutesMaterialPoint>(); double crc = pt.m_sbmr[0]; double dcrhatdcr = -m_kf*(m_crt - crc); return dcrhatdcr; } //----------------------------------------------------------------------------- //! Receptor-ligand complex supply double FESupplySynthesisBinding::ReceptorLigandSupply(FEMaterialPoint& mp) { FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& ppt = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double J = et.m_J; double ca = spt.m_ca[0]; double phi0 = ppt.m_phi0t; double cr = (J-phi0)*ca; double crc = spt.m_sbmr[0]; double crchat = m_kf*cr*(m_crt-crc) - m_kr*crc; return crchat; } //----------------------------------------------------------------------------- //! Solute supply at steady state double FESupplySynthesisBinding::SupplySS(FEMaterialPoint& mp) { return m_supp; } //----------------------------------------------------------------------------- //! Receptor-ligand concentration at steady-state double FESupplySynthesisBinding::ReceptorLigandConcentrationSS(FEMaterialPoint& mp) { FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& ppt = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double J = et.m_J; double ca = spt.m_ca[0]; double phi0 = ppt.m_phi0t; double cr = (J-phi0)*ca; double Kd = m_kr/m_kf; // dissociation constant double crc = m_crt*cr/(Kd+cr); return crc; } //----------------------------------------------------------------------------- //! Referential solid supply (moles of solid/referential volume/time) double FESupplySynthesisBinding::SolidSupply(FEMaterialPoint& mp) { return ReceptorLigandSupply(mp); } //----------------------------------------------------------------------------- //! Referential solid concentration (moles of solid/referential volume) //! at steady-state double FESupplySynthesisBinding::SolidConcentrationSS(FEMaterialPoint& mp) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEOsmoticCoefficient.h
.h
2,157
55
/*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 "febiomix_api.h" //----------------------------------------------------------------------------- //! Base class for osmotic coefficient. //! These materials need to define the osmotic coefficient and tangent functions. //! class FEBIOMIX_API FEOsmoticCoefficient : public FEMaterialProperty { public: //! constructor FEOsmoticCoefficient(FEModel* pfem) : FEMaterialProperty(pfem) {} //! osmotic coefficient virtual double OsmoticCoefficient(FEMaterialPoint& pt) = 0; //! tangent of osmotic coefficient with respect to strain virtual double Tangent_OsmoticCoefficient_Strain(FEMaterialPoint& mp) = 0; //! tangent of osmotic coefficient with respect to concentration virtual double Tangent_OsmoticCoefficient_Concentration(FEMaterialPoint& mp, const int isol) = 0; FECORE_BASE_CLASS(FEOsmoticCoefficient) };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicAnalysis.h
.h
1,556
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 <FECore/FEAnalysis.h> #include "febiomix_api.h" class FEBIOMIX_API FEMultiphasicAnalysis : public FEAnalysis { public: enum MultiphasicAnalysisType { STEADY_STATE, TRANSIENT }; public: FEMultiphasicAnalysis(FEModel* fem); DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMembraneReactionRateIonChannel.cpp
.cpp
5,999
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.*/ #include "stdafx.h" #include "FEMembraneReactionRateIonChannel.h" #include "FESoluteInterface.h" #include "FESolutesMaterialPoint.h" #include "FESolute.h" #include <FEBioMech/FEElasticMaterialPoint.h> #include <FECore/FEModel.h> #include <FECore/log.h> // Material parameters for the FEMembraneReactionRateConst material BEGIN_FECORE_CLASS(FEMembraneReactionRateIonChannel, FEMembraneReactionRate) ADD_PARAMETER(m_g, FE_RANGE_GREATER_OR_EQUAL(0.0), "g"); ADD_PARAMETER(m_sol, "sol"); ADD_PARAMETER(m_sbm, "sbm"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMembraneReactionRateIonChannel::FEMembraneReactionRateIonChannel(FEModel* pfem) : FEMembraneReactionRate(pfem) { m_sol = -1; m_sbm = -1; m_lid = -1; m_g = 0; m_z = 0; } //----------------------------------------------------------------------------- bool FEMembraneReactionRateIonChannel::Init() { if (FEMembraneReactionRate::Init() == false) return false; // do only once if (m_lid == -1) { // get number of DOFS DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); // check validity of sol if (m_sol < 1 || m_sol > MAX_CDOFS) { feLogError("sol value outside of valid range for solutes"); return false; } FEModel& fem = *GetFEModel(); int N = GetFEModel()->GlobalDataItems(); for (int i=0; i<N; ++i) { FESoluteData* psd = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (psd && (psd->GetID() == m_sol)) { m_lid = m_sol - 1; m_z = psd->m_z; break; } } } return true; } //----------------------------------------------------------------------------- double FEMembraneReactionRateIonChannel::ReactionRate(FEMaterialPoint& pt) { FESolutesMaterialPoint& ps = *pt.ExtractData<FESolutesMaterialPoint>(); double ci = ps.m_ci[m_lid]; double ce = ps.m_ce[m_lid]; double R = GetGlobalConstant("R"); double T = GetGlobalConstant("T"); double Fc = GetGlobalConstant("Fc"); FESoluteInterface* psi = m_pReact->m_psm; assert(psi); double ksi = (m_sbm > -1) ? psi->SBMArealConcentration(pt, m_sbm - 1): 1.0; double k = 0; if ((ci > 0) && (ce > 0)) k = (ci != ce) ? R*T*m_g/ksi/pow(Fc*m_z,2)*log(ci/ce)/(ci-ce) : R*T*m_g/pow(Fc*m_z,2)/ce; return k; } //----------------------------------------------------------------------------- //! tangent of reaction rate with strain at material point double FEMembraneReactionRateIonChannel::Tangent_ReactionRate_Strain(FEMaterialPoint& pt) { // get the areal strain FEElasticMaterialPoint& pe = *(pt.ExtractData<FEElasticMaterialPoint>()); FEShellElement*sel = dynamic_cast<FEShellElement*>(pt.m_elem); assert(sel); double Jg = pe.m_J*sel->Evaluate(sel->m_h0, pt.m_index)/sel->Evaluate(sel->m_ht, pt.m_index); return ReactionRate(pt)/Jg; } //----------------------------------------------------------------------------- double FEMembraneReactionRateIonChannel::Tangent_ReactionRate_Ci(FEMaterialPoint& pt, const int isol) { if (isol != m_lid) return 0; FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); double ci = ps.m_ci[m_lid]; double ce = ps.m_ce[m_lid]; double R = GetGlobalConstant("R"); double T = GetGlobalConstant("T"); double Fc = GetGlobalConstant("Fc"); FESoluteInterface* psi = m_pReact->m_psm; assert(psi); double ksi = (m_sbm > -1) ? psi->SBMArealConcentration(pt, m_sbm - 1) : 1.0; double dkdc = 0; if ((ci > 0) && (ce > 0)) dkdc = (ci != ce) ? R*T/pow(Fc*m_z,2)*m_g/ksi*(ci*(1-log(ci/ce))-ce)/pow(ci-ce,2)/ci : -R*T*m_g/pow(ci*Fc*m_z,2)/2; return dkdc; } //----------------------------------------------------------------------------- double FEMembraneReactionRateIonChannel::Tangent_ReactionRate_Ce(FEMaterialPoint& pt, const int isol) { if (isol != m_lid) return 0; FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); double ci = ps.m_ci[m_lid]; double ce = ps.m_ce[m_lid]; double R = GetGlobalConstant("R"); double T = GetGlobalConstant("T"); double Fc = GetGlobalConstant("Fc"); FESoluteInterface* psi = m_pReact->m_psm; assert(psi); double ksi = (m_sbm > -1) ? psi->SBMArealConcentration(pt, m_sbm - 1) : 1.0; double dkdc = 0; if ((ci > 0) && (ce > 0)) dkdc = (ci != ce) ? R*T*m_g/ksi/pow(Fc*m_z,2)*(ce*(1+log(ci/ce))-ci)/pow(ci-ce,2)/ce : -R*T*m_g/pow(ci*Fc*m_z,2)/2; return dkdc; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESoluteNaturalFlux.h
.h
2,514
76
/*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/FESurfaceLoad.h> #include <FECore/FEModelParam.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! The flux surface is a surface domain that sustains a solute natural flux boundary //! condition //! class FEBIOMIX_API FESoluteNaturalFlux : public FESurfaceLoad { public: //! constructor FESoluteNaturalFlux(FEModel* pfem); //! Initialization bool Init() override; //! serialization void Serialize(DumpStream& ar) override; //! Set the surface to apply the load to void SetSurface(FESurface* ps) override; void SetSolute(int isol) { m_isol = isol; } //! calculate flux stiffness void StiffnessMatrix(FELinearSystem& LS) override; //! calculate residual void LoadVector(FEGlobalVector& R) override; //! update void Update() override; protected: bool m_bshellb; //!< flag for prescribing flux on shell bottom int m_isol; //!< solute index bool m_bup; //!< flag to call Update function protected: FEDofList m_dofC; FEDofList m_dofU; FEDofList m_dofP; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESlidingInterfaceBiphasic.h
.h
7,381
200
/*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 "FEBioMech/FEContactInterface.h" #include "FEBiphasicContactSurface.h" //----------------------------------------------------------------------------- class FEBIOMIX_API FESlidingSurfaceBiphasic : public FEBiphasicContactSurface { public: //! constructor FESlidingSurfaceBiphasic(FEModel* pfem); //! initialization bool Init() override; // data serialization void Serialize(DumpStream& ar) override; //! initialize sliding surface and store previous values void InitSlidingSurface(); //! evaluate net contact force vec3d GetContactForce() override; //! evaluate net contact area double GetContactArea() override; //! evaluate net fluid force vec3d GetFluidForce() override; //! calculate the nodal normals void UpdateNodeNormals(); void SetPoroMode(bool bporo) { m_bporo = bporo; } //! create material point data FEMaterialPoint* CreateMaterialPoint() override; public: void GetVectorGap (int nface, vec3d& pg) override; void GetContactTraction(int nface, vec3d& pt) override; void GetSlipTangent (int nface, vec3d& pt); void GetMuEffective (int nface, double& pg) override; void GetLocalFLS (int nface, double& pg) override; void GetNodalVectorGap (int nface, vec3d* pg) override; void GetNodalContactPressure(int nface, double* pg) override; void GetNodalContactTraction(int nface, vec3d* pt) override; void GetStickStatus(int nface, double& pg) override; void EvaluateNodalContactPressures(); void EvaluateNodalContactTractions(); private: void GetContactPressure(int nface, double& pg); public: bool m_bporo; //!< set poro-mode vector<bool> m_poro; //!< surface element poro status vector<vec3d> m_nn; //!< node normals vector<vec3d> m_tn; //!< nodal contact tractions vector<double> m_pn; //!< nodal contact pressures vec3d m_Ft; //!< total contact force (from equivalent nodal forces) }; //----------------------------------------------------------------------------- class FEBIOMIX_API FESlidingInterfaceBiphasic : public FEContactInterface { public: //! constructor FESlidingInterfaceBiphasic(FEModel* pfem); //! destructor ~FESlidingInterfaceBiphasic(); //! initialization bool Init() override; //! interface activation void Activate() override; //! calculate the slip direction on the primary surface vec3d SlipTangent(FESlidingSurfaceBiphasic& ss, const int nel, const int nint, FESlidingSurfaceBiphasic& ms, double& dh, vec3d& r); //! calculate contact traction vec3d ContactTraction(FESlidingSurfaceBiphasic& ss, const int nel, const int n, FESlidingSurfaceBiphasic& ms, double& pn); //! calculate contact pressures for file output void UpdateContactPressures(); //! serialize data to archive void Serialize(DumpStream& ar) override; //! mark free-draining condition void MarkFreeDraining(); //! set free-draining condition void SetFreeDraining(); //! return the primary and secondary surface FESurface* GetPrimarySurface() override { return &m_ss; } FESurface* GetSecondarySurface() override { return &m_ms; } //! return integration rule class bool UseNodalIntegration() override { return false; } //! build the matrix profile for use in the stiffness matrix void BuildMatrixProfile(FEGlobalMatrix& K) override; public: //! calculate contact forces void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! calculate contact stiffness void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! calculate Lagrangian augmentations bool Augment(int naug, const FETimeInfo& tp) override; //! update void Update() override; protected: void ProjectSurface(FESlidingSurfaceBiphasic& ss, FESlidingSurfaceBiphasic& ms, bool bupseg, bool bmove = false); //! calculate penalty factor void UpdateAutoPenalty(); void CalcAutoPenalty(FESlidingSurfaceBiphasic& s); void CalcAutoPressurePenalty(FESlidingSurfaceBiphasic& s); double AutoPressurePenalty(FESurfaceElement& el, FESlidingSurfaceBiphasic& s); public: FESlidingSurfaceBiphasic m_ss; //!< primary surface FESlidingSurfaceBiphasic m_ms; //!< secondary surface int m_knmult; //!< higher order stiffness multiplier bool m_btwo_pass; //!< two-pass flag double m_atol; //!< augmentation tolerance double m_gtol; //!< gap tolerance double m_ptol; //!< pressure gap tolerance double m_stol; //!< search tolerance bool m_bsymm; //!< use symmetric stiffness components only double m_srad; //!< contact search radius int m_naugmax; //!< maximum nr of augmentations int m_naugmin; //!< minimum nr of augmentations int m_nsegup; //!< segment update parameter bool m_breloc; //!< node relocation on startup bool m_bsmaug; //!< smooth augmentation bool m_bsmfls; //!< smooth local fluid load support double m_epsn; //!< normal penalty factor bool m_bautopen; //!< use autopenalty factor bool m_bupdtpen; //!< update penalty at each time step double m_mu; //!< friction coefficient bool m_bfreeze; //!< freeze stick/slip status bool m_bflips; //!< flip primary surface normal bool m_bflipm; //!< flip secondary surface normal bool m_bshellbs; //!< flag for prescribing pressure on shell bottom for primary surface bool m_bshellbm; //!< flag for prescribing pressure on shell bottom for secondary surface // biphasic contact parameters double m_epsp; //!< flow rate penalty double m_phi; //!< solid-solid contact fraction protected: int m_dofP; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSoluteSolidDomain.cpp
.cpp
42,259
1,170
/*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 "FEBiphasicSoluteSolidDomain.h" #include "FECore/FEAnalysis.h" #include "FECore/log.h" #include <FECore/FEModel.h> #include <FEBioMech/FEBioMech.h> #include <FECore/FELinearSystem.h> #include "FEBiphasicAnalysis.h" //----------------------------------------------------------------------------- FEBiphasicSoluteSolidDomain::FEBiphasicSoluteSolidDomain(FEModel* pfem) : FESolidDomain(pfem), FEBiphasicSoluteDomain(pfem), m_dofU(pfem), m_dofSU(pfem), m_dofR(pfem), m_dof(pfem) { // 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)); } } //----------------------------------------------------------------------------- //! get the material (overridden from FEDomain) FEMaterial* FEBiphasicSoluteSolidDomain::GetMaterial() { return m_pMat; } //----------------------------------------------------------------------------- //! get the total dof const FEDofList& FEBiphasicSoluteSolidDomain::GetDOFList() const { return m_dof; } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::SetMaterial(FEMaterial* pmat) { FEDomain::SetMaterial(pmat); m_pMat = dynamic_cast<FEBiphasicSolute*>(pmat); assert(m_pMat); } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::Activate() { int dofc = m_dofC + m_pMat->GetSolute()->GetSoluteDOF(); int dofd = m_dofD + m_pMat->GetSolute()->GetSoluteDOF(); 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]); } } } // Activate dof_P and dof_C, except when a solid element is connected to the // back of a shell element, in which case activate dof_Q and dof_D for those nodes. FEMesh& m = *GetMesh(); for (int i=0; i<Elements(); ++i) { FESolidElement& el = m_Elem[i]; int neln = el.Nodes(); for (int j=0; j<neln; ++j) { FENode& node = m.Node(el.m_node[j]); if (el.m_bitfc.size()>0 && el.m_bitfc[j]) { node.set_active(m_dofQ); node.set_active(dofd ); } else { node.set_active(m_dofP); node.set_active(dofc ); } } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::InitMaterialPoints() { FEMesh& m = *GetMesh(); int dofc = m_dofC + m_pMat->GetSolute()->GetSoluteDOF(); const int NE = FEElement::MAX_NODES; double p0[NE], c0[NE]; for (int i = 0; i<(int)m_Elem.size(); ++i) { // get the solid element FESolidElement& el = m_Elem[i]; // get the number of nodes int neln = el.Nodes(); // get initial values of fluid pressure and solute concentrations for (int i = 0; i<neln; ++i) { FENode& node = m.Node(el.m_node[i]); p0[i] = node.get(m_dofP); c0[i] = node.get(dofc); } // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n = 0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pm = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); // initialize effective fluid pressure, its gradient, and fluid flux pt.m_p = el.Evaluate(p0, n); pt.m_gradp = gradient(el, p0, n); pt.m_w = m_pMat->FluidFlux(mp); // initialize effective solute concentrations ps.m_c[0] = el.Evaluate(c0, n); ps.m_gradc[0] = gradient(el, c0, n); ps.m_ca[0] = m_pMat->Concentration(mp); ps.m_j[0] = m_pMat->SoluteFlux(mp); ps.m_crp[0] = pm.m_J*m_pMat->Porosity(mp)*ps.m_ca[0]; pt.m_pa = m_pMat->Pressure(mp); // determine if solute is 'solid-bound' FESolute* soli = m_pMat->GetSolute(); if (soli->m_pDiff->Diffusivity(mp).norm() == 0) ps.m_bsb[0] = true; // initialize referential solid volume fraction pt.m_phi0t = m_pMat->m_phi0(mp); // calculate stress pm.m_s = m_pMat->Stress(mp); } } } //----------------------------------------------------------------------------- //! Unpack the element LM data. void FEBiphasicSoluteSolidDomain::UnpackLM(FEElement& el, vector<int>& lm) { int dofc = m_dofC + m_pMat->GetSolute()->GetSoluteDOF(); int dofd = m_dofD + m_pMat->GetSolute()->GetSoluteDOF(); int N = el.Nodes(); lm.resize(N*8); for (int i=0; i<N; ++i) { int n = el.m_node[i]; FENode& node = m_pMesh->Node(n); vector<int>& id = node.m_ID; // first the displacement dofs lm[5*i ] = id[m_dofU[0]]; lm[5*i+1] = id[m_dofU[1]]; lm[5*i+2] = id[m_dofU[2]]; // now the pressure dofs lm[5*i+3] = id[m_dofP]; // concentration dofs lm[5*i+4] = id[dofc]; // rigid rotational dofs // TODO: Do I really need this lm[5*N + 3*i ] = id[m_dofR[0]]; lm[5*N + 3*i+1] = id[m_dofR[1]]; lm[5*N + 3*i+2] = id[m_dofR[2]]; } // substitute interface dofs for solid-shell interfaces FESolidElement& sel = static_cast<FESolidElement&>(el); for (int i = 0; i<sel.m_bitfc.size(); ++i) { if (sel.m_bitfc[i]) { FENode& node = m_pMesh->Node(el.m_node[i]); vector<int>& id = node.m_ID; // first the back-face displacement dofs lm[5*i ] = id[m_dofSU[0]]; lm[5*i+1] = id[m_dofSU[1]]; lm[5*i+2] = id[m_dofSU[2]]; // now the pressure dof (if the shell has it) if (id[m_dofQ] > -1) lm[5*i+3] = id[m_dofQ]; // concentration dofs if (id[dofd] > -1) lm[5*i+4] = id[dofd]; } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::Reset() { // reset base class FESolidDomain::Reset(); const int nsol = 1; const int nsbm = 1; // loop over all material points ForEachMaterialPoint([=](FEMaterialPoint& mp) { FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint >()); // initialize referential solid volume fraction pt.m_phi0 = pt.m_phi0t = m_pMat->m_phi0(mp); // initialize multiphasic solutes ps.m_nsol = nsol; ps.m_c.assign(nsol,0); ps.m_ca.assign(nsol,0); ps.m_crp.assign(nsol, 0); ps.m_gradc.assign(nsol,vec3d(0,0,0)); ps.m_bsb.assign(nsol, false); ps.m_k.assign(nsol, 0); ps.m_dkdJ.assign(nsol, 0); ps.m_dkdc.resize(nsol, vector<double>(nsol,0)); ps.m_j.assign(nsol,vec3d(0,0,0)); ps.m_nsbm = nsbm; ps.m_sbmr.assign(nsbm,0); ps.m_sbmrp.assign(nsbm,0); ps.m_sbmrhat.assign(nsbm,0); ps.m_sbmrhatp.assign(nsbm,0); }); } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { int dofc = m_dofC + m_pMat->GetSolute()->GetSoluteDOF(); int dofd = m_dofD + m_pMat->GetSolute()->GetSoluteDOF(); const int NE = FEElement::MAX_NODES; vec3d x0[NE], xt[NE], r0, rt; double pn[NE], p, ct[NE], c; FEMesh& m = *GetMesh(); for (size_t iel=0; iel<m_Elem.size(); ++iel) { FESolidElement& el = m_Elem[iel]; int neln = el.Nodes(); for (int i=0; i<neln; ++i) { FENode& node = m.Node(el.m_node[i]); x0[i] = node.m_r0; xt[i] = node.m_rt; pn[i] = m.Node(el.m_node[i]).get(m_dofP); if (el.m_bitfc.size()>0 && el.m_bitfc[i]) { pn[i] = (node.m_ID[m_dofQ] != -1) ? node.get(m_dofQ) : node.get(m_dofP); ct[i] = (node.m_ID[dofd] != -1) ? node.get(dofd) : node.get(dofc); } else { pn[i] = node.get(m_dofP); ct[i] = node.get(dofc); } } int n = el.GaussPoints(); for (int j=0; j<n; ++j) { r0 = el.Evaluate(x0, j); rt = el.Evaluate(xt, j); p = el.Evaluate(pn, j); c = el.Evaluate(ct, j); FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pb = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint >()); mp.m_r0 = r0; mp.m_rt = rt; pt.m_J = defgrad(el, pt.m_F, j); pb.m_Jp = pt.m_J; pb.m_p = p; pb.m_gradp = gradient(el, pn, j); pb.m_phi0p = pb.m_phi0t; ps.m_c[0] = c; ps.m_gradc[0] = gradient(el, ct, j); // reset referential actual solute concentration at previous time ps.m_crp[0] = pt.m_J*m_pMat->Porosity(mp)*ps.m_ca[0]; // reset referential receptor-ligand complex concentration at previous time ps.m_sbmrp[0] = ps.m_sbmr[0]; // reset referential receptor-ligand complex concentration supply at previous time ps.m_sbmrhatp[0] = ps.m_sbmrhat[0]; mp.Update(timeInfo); } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::InternalForces(FEGlobalVector& R) { size_t NE = m_Elem.size(); #pragma omp parallel for shared (NE) for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FESolidElement& el = m_Elem[i]; // get the element force vector and initialize it to zero int ndof = 5*el.Nodes(); fe.assign(ndof, 0); // calculate internal force vector ElementInternalForce(el, fe); // get the element's LM vector UnpackLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe); } } //----------------------------------------------------------------------------- //! calculates the internal equivalent nodal forces for solid elements void FEBiphasicSoluteSolidDomain::ElementInternalForce(FESolidElement& el, vector<double>& fe) { int i, n; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; vec3d gradN; mat3ds s; const double* Gr, *Gs, *Gt, *H; int nint = el.GaussPoints(); int neln = el.Nodes(); double* gw = el.GaussWeights(); double dt = GetFEModel()->GetTime().timeIncrement; // repeat for all integration points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = invjact(el, Ji, n); detJt *= gw[n]; // get the stress vector for this integration point s = pt.m_s; Gr = el.Gr(n); Gs = el.Gs(n); Gt = el.Gt(n); H = el.H(n); // next we get the determinant double Jp = bpt.m_Jp; double J = pt.m_J; // and then finally double divv = ((J-Jp)/dt)/J; // get the flux vec3d& w = bpt.m_w; // get the solute flux vec3d& j = spt.m_j[0]; // Evaluate porosity and solute supply and receptor-ligand kinetics double phiw = m_pMat->Porosity(mp); double crhat = 0; if (m_pMat->GetSolute()->m_pSupp) crhat = m_pMat->GetSolute()->m_pSupp->Supply(mp); for (i=0; i<neln; ++i) { // calculate global gradient of shape functions // note that we need the transposed of Ji, not Ji itself ! gradN = vec3d(Ji[0][0]*Gr[i]+Ji[1][0]*Gs[i]+Ji[2][0]*Gt[i], Ji[0][1]*Gr[i]+Ji[1][1]*Gs[i]+Ji[2][1]*Gt[i], Ji[0][2]*Gr[i]+Ji[1][2]*Gs[i]+Ji[2][2]*Gt[i]); // calculate internal force vec3d fu = s*gradN; // the '-' sign is so that the internal forces get subtracted // from the global residual vector fe[5*i ] -= fu.x*detJt; fe[5*i+1] -= fu.y*detJt; fe[5*i+2] -= fu.z*detJt; fe[5*i+3] -= dt*(w*gradN - divv*H[i])*detJt; fe[5*i+4] -= dt*(gradN*j + H[i]*(crhat/J - (phiw*spt.m_ca[0] - spt.m_crp[0]/J)/dt) )*detJt; } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::InternalForcesSS(FEGlobalVector& R) { size_t NE = m_Elem.size(); #pragma omp parallel for shared (NE) for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FESolidElement& el = m_Elem[i]; // get the element force vector and initialize it to zero int ndof = 5*el.Nodes(); fe.assign(ndof, 0); // calculate internal force vector ElementInternalForceSS(el, fe); // get the element's LM vector UnpackLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe); } } //----------------------------------------------------------------------------- //! calculates the internal equivalent nodal forces for solid elements void FEBiphasicSoluteSolidDomain::ElementInternalForceSS(FESolidElement& el, vector<double>& fe) { int i, n; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; vec3d gradN; mat3ds s; const double* Gr, *Gs, *Gt, *H; int nint = el.GaussPoints(); int neln = el.Nodes(); double* gw = el.GaussWeights(); double dt = GetFEModel()->GetTime().timeIncrement; // repeat for all integration points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = invjact(el, Ji, n); detJt *= gw[n]; // get the stress vector for this integration point s = pt.m_s; Gr = el.Gr(n); Gs = el.Gs(n); Gt = el.Gt(n); H = el.H(n); // next we get the determinant double J = pt.m_J; // get the flux vec3d& w = bpt.m_w; // get the solute flux vec3d& j = spt.m_j[0]; // Evaluate solute supply and receptor-ligand kinetics double crhat = 0; if (m_pMat->GetSolute()->m_pSupp) crhat = m_pMat->GetSolute()->m_pSupp->Supply(mp); for (i=0; i<neln; ++i) { // calculate global gradient of shape functions // note that we need the transposed of Ji, not Ji itself ! gradN = vec3d(Ji[0][0]*Gr[i]+Ji[1][0]*Gs[i]+Ji[2][0]*Gt[i], Ji[0][1]*Gr[i]+Ji[1][1]*Gs[i]+Ji[2][1]*Gt[i], Ji[0][2]*Gr[i]+Ji[1][2]*Gs[i]+Ji[2][2]*Gt[i]); // calculate internal force vec3d fu = s*gradN; // the '-' sign is so that the internal forces get subtracted // from the global residual vector fe[5*i ] -= fu.x*detJt; fe[5*i+1] -= fu.y*detJt; fe[5*i+2] -= fu.z*detJt; fe[5*i+3] -= dt*(w*gradN)*detJt; fe[5*i+4] -= dt*(gradN*j + H[i]*(crhat/J))*detJt; } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::StiffnessMatrix(FELinearSystem& LS, bool bsymm) { // repeat over all solid elements const 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); int neln = el.Nodes(); int ndof = neln*5; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementBiphasicSoluteStiffness(el, ke, bsymm); // get lm vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) { // repeat over all solid elements const 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); int neln = el.Nodes(); int ndof = neln*5; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementBiphasicSoluteStiffnessSS(el, ke, bsymm); // get lm vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- //! calculates element stiffness matrix for element iel //! bool FEBiphasicSoluteSolidDomain::ElementBiphasicSoluteStiffness(FESolidElement& el, matrix& ke, bool bsymm) { int i, j, n; int nint = el.GaussPoints(); int neln = el.Nodes(); double *Gr, *Gs, *Gt, *H; // jacobian double Ji[3][3], detJ; // Gradient of shape functions vector<vec3d> gradN(neln); double tmp; // gauss-weights double* gw = el.GaussWeights(); double dt = GetFEModel()->GetTime().timeIncrement; // zero stiffness matrix ke.zero(); // loop over gauss-points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint >()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint >()); // calculate jacobian detJ = invjact(el, Ji, n)*gw[n]; vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]); vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]); vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]); Gr = el.Gr(n); Gs = el.Gs(n); Gt = el.Gt(n); H = el.H(n); // calculate global gradient of shape functions for (i=0; i<neln; ++i) gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i]; // get stress tensor mat3ds s = ept.m_s; // get elasticity tensor tens4ds C = m_pMat->Tangent(mp); // get the fluid flux and pressure gradient vec3d gradp = ppt.m_gradp; vec3d w = ppt.m_w; // evaluate the permeability and its derivatives mat3ds K = m_pMat->GetPermeability()->Permeability(mp); tens4dmm dKdE = m_pMat->GetPermeability()->Tangent_Permeability_Strain(mp); mat3ds dKdc = m_pMat->GetPermeability()->Tangent_Permeability_Concentration(mp, 0); // next we get the determinant double J = ept.m_J; // get the fluid flux and pressure gradient // get the effective concentration, its gradient and its time derivative double c = spt.m_c[0]; vec3d gradc = spt.m_gradc[0]; // evaluate the porosity and its derivative double phiw = m_pMat->Porosity(mp); double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the solubility and its derivatives double kappa = spt.m_k[0]; double dkdJ = spt.m_dkdJ[0]; double dkdc = spt.m_dkdc[0][0]; // evaluate the diffusivity tensor and its derivatives mat3ds D = m_pMat->GetSolute()->m_pDiff->Diffusivity(mp); mat3ds dDdc = m_pMat->GetSolute()->m_pDiff->Tangent_Diffusivity_Concentration(mp, 0); tens4dmm dDdE = m_pMat->GetSolute()->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity double D0 = m_pMat->GetSolute()->m_pDiff->Free_Diffusivity(mp); double dD0dc = m_pMat->GetSolute()->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,0); // evaluate the osmotic coefficient and its derivatives double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp); double dodc = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp, 0); // evaluate the stress tangent with concentration // mat3ds dTdc = pm->GetSolid()->Tangent_Concentration(mp, 0); mat3ds dTdc(0,0,0,0,0,0); // Miscellaneous constants mat3dd I(1); double R = m_pMat->m_Rgas; double T = m_pMat->m_Tabs; // evaluate the effective permeability and its derivatives mat3ds Ki = K.inverse(); mat3ds ImD = I-D/D0; mat3ds Ke = (Ki + ImD*(R*T*kappa*c/phiw/D0)).inverse(); tens4d G = (dyad1(Ki,I) - dyad4(Ki,I)*2)*2 - ddot(dyad2(Ki,Ki),dKdE) +dyad1(ImD,I)*(R*T*c*J/D0/phiw*(dkdJ-kappa/phiw*dpdJ)) +(dyad1(I,I) - dyad2(I,I)*2 - dDdE/D0)*(R*T*kappa*c/phiw/D0); tens4d dKedE = (dyad1(Ke,I) - 2*dyad4(Ke,I))*2 - ddot(dyad2(Ke,Ke),G); mat3ds Gc = -(Ki*dKdc*Ki).sym() + ImD*(R*T/phiw/D0*(dkdc*c+kappa-kappa*c/D0*dD0dc)) +R*T*kappa*c/phiw/D0/D0*(D*dD0dc/D0 - dDdc); mat3ds dKedc = -(Ke*Gc*Ke).sym(); // evaluate the tangents of solute supply double dcrhatdJ = 0; double dcrhatdc = 0; if (m_pMat->GetSolute()->m_pSupp) { dcrhatdJ = m_pMat->GetSolute()->m_pSupp->Tangent_Supply_Strain(mp); double dcrhatdcr = m_pMat->GetSolute()->m_pSupp->Tangent_Supply_Concentration(mp); dcrhatdc = J*phiw*(kappa + c*dkdc)*dcrhatdcr; } // calculate all the matrices vec3d vtmp,gp,gc,qpu,qcu,wc,jc; mat3d wu,ju; double qcc; for (i=0; i<neln; ++i) { for (j=0; j<neln; ++j) { // Kuu matrix mat3d Kuu = (mat3dd(gradN[i]*(s*gradN[j])) + vdotTdotv(gradN[i], C, gradN[j]))*detJ; ke[5*i ][5*j ] += Kuu[0][0]; ke[5*i ][5*j+1] += Kuu[0][1]; ke[5*i ][5*j+2] += Kuu[0][2]; ke[5*i+1][5*j ] += Kuu[1][0]; ke[5*i+1][5*j+1] += Kuu[1][1]; ke[5*i+1][5*j+2] += Kuu[1][2]; ke[5*i+2][5*j ] += Kuu[2][0]; ke[5*i+2][5*j+1] += Kuu[2][1]; ke[5*i+2][5*j+2] += Kuu[2][2]; // calculate the kup matrix vtmp = -gradN[i]*H[j]*detJ; ke[5*i ][5*j+3] += vtmp.x; ke[5*i+1][5*j+3] += vtmp.y; ke[5*i+2][5*j+3] += vtmp.z; // calculate the kuc matrix vtmp = (dTdc*gradN[i] - gradN[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*H[j]*detJ; ke[5*i ][5*j+4] += vtmp.x; ke[5*i+1][5*j+4] += vtmp.y; ke[5*i+2][5*j+4] += vtmp.z; // calculate the kpu matrix gp = gradp+(D*gradc)*R*T*kappa/D0; wu = vdotTdotv(-gp, dKedE, gradN[j]) -(((Ke*(D*gradc)) & gradN[j])*(J*dkdJ - kappa) +Ke*(2*kappa*(gradN[j]*(D*gradc))))*R*T/D0 - Ke*vdotTdotv(gradc, dDdE, gradN[j])*(kappa*R*T/D0); qpu = -gradN[j]*(1.0/dt); vtmp = (wu.transpose()*gradN[i] + qpu*H[i])*(detJ*dt); ke[5*i+3][5*j ] += vtmp.x; ke[5*i+3][5*j+1] += vtmp.y; ke[5*i+3][5*j+2] += vtmp.z; // calculate the kpp matrix ke[5*i+3][5*j+3] -= gradN[i]*(Ke*gradN[j])*(detJ*dt); // calculate the kpc matrix wc = (dKedc*gp)*(-H[j]) -Ke*((((D*(dkdc-kappa*dD0dc/D0)+dDdc*kappa)*gradc)*H[j] +(D*gradN[j])*kappa)*(R*T/D0)); ke[5*i+3][5*j+4] += (gradN[i]*wc)*(detJ*dt); // calculate the kcu matrix gc = -gradc*phiw + w*c/D0; ju = ((D*gc) & gradN[j])*(J*dkdJ) + vdotTdotv(gc, dDdE, gradN[j])*kappa + (((D*gradc) & gradN[j])*(-phis) +(D*((gradN[j]*w)*2) - ((D*w) & gradN[j]))*c/D0 )*kappa +D*wu*(kappa*c/D0); qcu = qpu*(c*(kappa+J*phiw*dkdJ)); vtmp = (ju.transpose()*gradN[i] + qcu*H[i])*(detJ*dt); ke[5*i+4][5*j ] += vtmp.x; ke[5*i+4][5*j+1] += vtmp.y; ke[5*i+4][5*j+2] += vtmp.z; // calculate the kcp matrix ke[5*i+4][5*j+3] -= (gradN[i]*((D*Ke)*gradN[j]))*(kappa*c/D0)*(detJ*dt); // calculate the kcc matrix jc = (D*(-gradN[j]*phiw+w*(H[j]/D0)))*kappa +((D*dkdc+dDdc*kappa)*gc)*H[j] +(D*(w*(-H[j]*dD0dc/D0)+wc))*(kappa*c/D0); qcc = -H[j]*phiw/dt*(c*dkdc + kappa); ke[5*i+4][5*j+4] += (gradN[i]*jc + H[i]*qcc)*(detJ*dt); } } } // Enforce symmetry by averaging top-right and bottom-left corners of stiffness matrix if (bsymm) { for (i=0; i<5*neln; ++i) for (j=i+1; j<5*neln; ++j) { tmp = 0.5*(ke[i][j]+ke[j][i]); ke[i][j] = ke[j][i] = tmp; } } return true; } //----------------------------------------------------------------------------- //! calculates element stiffness matrix for element iel //! for steady-state response (zero solid velocity, zero time derivative of //! solute concentration) //! bool FEBiphasicSoluteSolidDomain::ElementBiphasicSoluteStiffnessSS(FESolidElement& el, matrix& ke, bool bsymm) { int i, j, n; int nint = el.GaussPoints(); int neln = el.Nodes(); double *Gr, *Gs, *Gt, *H; // jacobian double Ji[3][3], detJ; // Gradient of shape functions vector<vec3d> gradN(neln); double tmp; // gauss-weights double* gw = el.GaussWeights(); double dt = GetFEModel()->GetTime().timeIncrement; // zero stiffness matrix ke.zero(); // loop over gauss-points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint >()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint >()); // calculate jacobian detJ = invjact(el, Ji, n)*gw[n]; vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]); vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]); vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]); Gr = el.Gr(n); Gs = el.Gs(n); Gt = el.Gt(n); H = el.H(n); // calculate global gradient of shape functions for (i=0; i<neln; ++i) gradN[i] = g1*Gr[i] + g2*Gs[i] + g3*Gt[i]; // get stress tensor mat3ds s = ept.m_s; // get elasticity tensor tens4ds C = m_pMat->Tangent(mp); // next we get the determinant double J = ept.m_J; // get the fluid flux and pressure gradient vec3d w = ppt.m_w; vec3d gradp = ppt.m_gradp; // get the effective concentration, its gradient and its time derivative double c = spt.m_c[0]; vec3d gradc = spt.m_gradc[0]; // evaluate the permeability and its derivatives mat3ds K = m_pMat->GetPermeability()->Permeability(mp); tens4dmm dKdE = m_pMat->GetPermeability()->Tangent_Permeability_Strain(mp); mat3ds dKdc = m_pMat->GetPermeability()->Tangent_Permeability_Concentration(mp, 0); // evaluate the porosity and its derivative double phiw = m_pMat->Porosity(mp); double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the solubility and its derivatives double kappa = spt.m_k[0]; double dkdJ = spt.m_dkdJ[0]; double dkdc = spt.m_dkdc[0][0]; // evaluate the diffusivity tensor and its derivatives mat3ds D = m_pMat->GetSolute()->m_pDiff->Diffusivity(mp); mat3ds dDdc = m_pMat->GetSolute()->m_pDiff->Tangent_Diffusivity_Concentration(mp, 0); tens4dmm dDdE = m_pMat->GetSolute()->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity double D0 = m_pMat->GetSolute()->m_pDiff->Free_Diffusivity(mp); double dD0dc = m_pMat->GetSolute()->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,0); // evaluate the osmotic coefficient and its derivatives double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp); double dodc = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp, 0); // evaluate the stress tangent with concentration // mat3ds dTdc = pm->GetSolid()->Tangent_Concentration(mp, 0); mat3ds dTdc(0,0,0,0,0,0); // Miscellaneous constants mat3dd I(1); double R = m_pMat->m_Rgas; double T = m_pMat->m_Tabs; // evaluate the effective permeability and its derivatives mat3ds Ki = K.inverse(); mat3ds ImD = I-D/D0; mat3ds Ke = (Ki + ImD*(R*T*kappa*c/phiw/D0)).inverse(); tens4d G = (dyad1(Ki,I) - dyad4(Ki,I)*2)*2 - ddot(dyad2(Ki,Ki),dKdE) +dyad1(ImD,I)*(R*T*c*J/D0/phiw*(dkdJ-kappa/phiw*dpdJ)) +(dyad1(I,I) - dyad2(I,I)*2 - dDdE/D0)*(R*T*kappa*c/phiw/D0); tens4d dKedE = (dyad1(Ke,I) - 2*dyad4(Ke,I))*2 - ddot(dyad2(Ke,Ke),G); mat3ds Gc = -(Ki*dKdc*Ki).sym() + ImD*(R*T/phiw/D0*(dkdc*c+kappa-kappa*c/D0*dD0dc)) +R*T*kappa*c/phiw/D0/D0*(D*dD0dc/D0 - dDdc); mat3ds dKedc = -(Ke*Gc*Ke).sym(); // calculate all the matrices vec3d vtmp,gp,gc,wc,jc; mat3d wu,ju; for (i=0; i<neln; ++i) { for (j=0; j<neln; ++j) { // Kuu matrix mat3d Kuu = (mat3dd(gradN[i]*(s*gradN[j])) + vdotTdotv(gradN[i], C, gradN[j]))*detJ; ke[5*i ][5*j ] += Kuu[0][0]; ke[5*i ][5*j+1] += Kuu[0][1]; ke[5*i ][5*j+2] += Kuu[0][2]; ke[5*i+1][5*j ] += Kuu[1][0]; ke[5*i+1][5*j+1] += Kuu[1][1]; ke[5*i+1][5*j+2] += Kuu[1][2]; ke[5*i+2][5*j ] += Kuu[2][0]; ke[5*i+2][5*j+1] += Kuu[2][1]; ke[5*i+2][5*j+2] += Kuu[2][2]; // calculate the kpu matrix gp = gradp+(D*gradc)*R*T*kappa/D0; wu = vdotTdotv(-gp, dKedE, gradN[j]) -(((Ke*(D*gradc)) & gradN[j])*(J*dkdJ - kappa) +Ke*(2*kappa*(gradN[j]*(D*gradc))))*R*T/D0 - Ke*vdotTdotv(gradc, dDdE, gradN[j])*(kappa*R*T/D0); vtmp = (wu.transpose()*gradN[i])*(detJ*dt); ke[5*i+3][5*j ] += vtmp.x; ke[5*i+3][5*j+1] += vtmp.y; ke[5*i+3][5*j+2] += vtmp.z; // calculate the kcu matrix gc = -gradc*phiw + w*c/D0; ju = ((D*gc) & gradN[j])*(J*dkdJ) + vdotTdotv(gc, dDdE, gradN[j])*kappa + (((D*gradc) & gradN[j])*(-phis) +(D*((gradN[j]*w)*2) - ((D*w) & gradN[j]))*c/D0 )*kappa +D*wu*(kappa*c/D0); vtmp = (ju.transpose()*gradN[i])*(detJ*dt); ke[5*i+4][5*j ] += vtmp.x; ke[5*i+4][5*j+1] += vtmp.y; ke[5*i+4][5*j+2] += vtmp.z; // calculate the kup matrix vtmp = -gradN[i]*H[j]*detJ; ke[5*i ][5*j+3] += vtmp.x; ke[5*i+1][5*j+3] += vtmp.y; ke[5*i+2][5*j+3] += vtmp.z; // calculate the kpp matrix ke[5*i+3][5*j+3] -= gradN[i]*(Ke*gradN[j])*(detJ*dt); // calculate the kcp matrix ke[5*i+4][5*j+3] -= (gradN[i]*((D*Ke)*gradN[j]))*(kappa*c/D0)*(detJ*dt); // calculate the kuc matrix vtmp = (dTdc*gradN[i] - gradN[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*H[j]*detJ; ke[5*i ][5*j+4] += vtmp.x; ke[5*i+1][5*j+4] += vtmp.y; ke[5*i+2][5*j+4] += vtmp.z; // calculate the kpc matrix wc = (dKedc*gp)*(-H[j]) -Ke*((((D*(dkdc-kappa*dD0dc/D0)+dDdc*(kappa/D0))*gradc)*H[j] +(D*gradN[j])*kappa)*(R*T/D0)); ke[5*i+3][5*j+4] += (gradN[i]*wc)*(detJ*dt); // calculate the kcc matrix jc = (D*(-gradN[j]*phiw+w*(H[j]/D0)))*kappa +((D*dkdc+dDdc*kappa)*gc)*H[j] +(D*(w*(-H[j]*dD0dc/D0)+wc))*(kappa*c/D0); ke[5*i+4][5*j+4] += (gradN[i]*jc)*(detJ*dt); } } } // Enforce symmetry by averaging top-right and bottom-left corners of stiffness matrix if (bsymm) { for (i=0; i<5*neln; ++i) for (j=i+1; j<5*neln; ++j) { tmp = 0.5*(ke[i][j]+ke[j][i]); ke[i][j] = ke[j][i] = tmp; } } return true; } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::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); } catch (NegativeJacobian e) { #pragma omp critical { berr = true; if (e.DoOutput()) feLogError(e.what()); } } } if (berr) throw NegativeJacobianDetected(); } //----------------------------------------------------------------------------- void FEBiphasicSoluteSolidDomain::UpdateElementStress(int iel) { FEModel& fem = *GetFEModel(); double dt = fem.GetTime().timeIncrement; bool sstate = (fem.GetCurrentStep()->m_nanalysis == FEBiphasicAnalysis::STEADY_STATE); int dofc = m_dofC + m_pMat->GetSolute()->GetSoluteDOF(); int dofd = m_dofD + m_pMat->GetSolute()->GetSoluteDOF(); // get the solid element FESolidElement& el = m_Elem[iel]; // get the number of integration points int nint = el.GaussPoints(); // get the number of nodes int neln = el.Nodes(); // get the nodal data FEMesh& mesh = *m_pMesh; vec3d r0[FEElement::MAX_NODES]; vec3d rt[FEElement::MAX_NODES]; double pn[FEElement::MAX_NODES], ct[FEElement::MAX_NODES]; for (int j=0; j<neln; ++j) { FENode& node = mesh.Node(el.m_node[j]); r0[j] = node.m_r0; rt[j] = node.m_rt; if (el.m_bitfc.size()>0 && el.m_bitfc[j]) { pn[j] = (node.m_ID[m_dofQ] != -1) ? node.get(m_dofQ) : node.get(m_dofP); ct[j] = (node.m_ID[dofd] != -1) ? node.get(dofd) : node.get(dofc); } else { pn[j] = node.get(m_dofP); ct[j] = node.get(dofc); } } // 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>()); // material point coordinates // TODO: I'm not entirly happy with this solution // since the material point coordinates are used by most materials. mp.m_r0 = el.Evaluate(r0, n); mp.m_rt = el.Evaluate(rt, n); // get the deformation gradient and determinant pt.m_J = defgrad(el, pt.m_F, n); mat3d Fp; defgradp(el, Fp, n); mat3d Fi = pt.m_F.inverse(); pt.m_L = (pt.m_F - Fp)*Fi / dt; // solute-poroelastic data FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // evaluate fluid pressure at gauss-point ppt.m_p = el.Evaluate(pn, n); // calculate the gradient of p at gauss-point ppt.m_gradp = gradient(el, pn, n); // evaluate effective solute concentration at gauss-point spt.m_c[0] = el.Evaluate(ct, n); // calculate the gradient of c at gauss-point spt.m_gradc[0] = gradient(el, ct, n); // for biphasic-solute materials also update the porosity, fluid and solute fluxes // and evaluate the actual fluid pressure and solute concentration ppt.m_w = m_pMat->FluidFlux(mp); ppt.m_pa = m_pMat->Pressure(mp); spt.m_j[0] = m_pMat->SoluteFlux(mp); spt.m_ca[0] = m_pMat->Concentration(mp); if (m_pMat->GetSolute()->m_pSupp) { if (sstate) spt.m_sbmr[0] = m_pMat->GetSolute()->m_pSupp->ReceptorLigandConcentrationSS(mp); else { // update m_crc using midpoint rule spt.m_sbmrhat[0] = m_pMat->GetSolute()->m_pSupp->ReceptorLigandSupply(mp); spt.m_sbmr[0] = spt.m_sbmrp[0] + (spt.m_sbmrhat[0]+spt.m_sbmrhatp[0])/2*dt; // update phi0 using backward difference integration // NOTE: MolarMass was removed since not used ppt.m_phi0hat = 0; // ppt.m_phi0hat = pmb->GetSolid()->MolarMass()/pmb->GetSolid()->Density()*pmb->GetSolute()->m_pSupp->SolidSupply(mp); ppt.m_phi0t = ppt.m_phi0p + ppt.m_phi0hat*dt; } } m_pMat->PartitionCoefficientFunctions(mp, spt.m_k[0], spt.m_dkdJ[0], spt.m_dkdc[0][0]); // update specialized material points m_pMat->UpdateSpecializedMaterialPoints(mp, GetFEModel()->GetTime()); // calculate the solid stress at this material point ppt.m_ss = m_pMat->GetElasticMaterial()->Stress(mp); // calculate the stress at this material point (must be done after evaluating m_pa) pt.m_s = m_pMat->Stress(mp); } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicAnalysis.cpp
.cpp
1,682
38
/*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 "FEBiphasicAnalysis.h" BEGIN_FECORE_CLASS(FEBiphasicAnalysis, FEAnalysis) // The analysis parameter is already defined in the FEAnalysis base class. // Here, we just need to set the enum values for the analysis parameter. FindParameterFromData(&m_nanalysis)->setEnums("STEADY-STATE\0TRANSIENT\0"); END_FECORE_CLASS() FEBiphasicAnalysis::FEBiphasicAnalysis(FEModel* fem) : FEAnalysis(fem) { }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMassActionForward.h
.h
2,157
54
/*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 "FEChemicalReaction.h" //----------------------------------------------------------------------------- //! Law of mass action for forward chemical reaction. class FEBIOMIX_API FEMassActionForward : public FEChemicalReaction { public: //! constructor FEMassActionForward(FEModel* pfem); //! molar supply at material point double ReactionSupply(FEMaterialPoint& pt) override; //! tangent of molar supply with strain (J) at material point mat3ds Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) override; //! tangent of molar supply with effective pressure at material point double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) override; //! tangent of molar supply with effective concentration at material point double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) override; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicFluidPressureBC.cpp
.cpp
8,716
217
/*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 "FEMultiphasicFluidPressureBC.h" #include "FEBioMix.h" #include "FEMultiphasic.h" #include <FECore/FEModel.h> #include <FECore/FESurface.h> //============================================================================= BEGIN_FECORE_CLASS(FEMultiphasicFluidPressureBC, FEPrescribedSurface) ADD_PARAMETER(m_p, "pressure")->setUnits("P")->setLongName("fluid pressure"); ADD_PARAMETER(m_bshellb , "shell_bottom"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FEMultiphasicFluidPressureBC::FEMultiphasicFluidPressureBC(FEModel* pfem) : FEPrescribedSurface(pfem) { m_p = 0; m_dofP = -1; m_dofC = -1; m_Rgas = 0; m_Tabs = 0; m_bshellb = false; } //----------------------------------------------------------------------------- //! initialize bool FEMultiphasicFluidPressureBC::Init() { FEModel* pfem = GetFEModel(); m_dofP = m_bshellb ? pfem->GetDOFIndex("q") : pfem->GetDOFIndex("p"); m_dofC = m_bshellb ? pfem->GetDOFIndex("shell concentration", 0) : pfem->GetDOFIndex("concentration", 0); SetDOFList(m_dofP); if (FEPrescribedSurface::Init() == false) return false; m_Rgas = GetFEModel()->GetGlobalConstant("R"); m_Tabs = GetFEModel()->GetGlobalConstant("T"); m_pe.assign(GetSurface()->Nodes(), 0.0); return true; } //----------------------------------------------------------------------------- //! Evaluate and prescribe the resistance pressure void FEMultiphasicFluidPressureBC::Update() { // prescribe this dilatation at the nodes FESurface* ps = GetSurface(); int N = ps->Nodes(); std::vector<vector<double>> peNodes(N, vector<double>()); // Project sum of all kappa and osm_coef values from int points to nodes on surface // All values put into map, including duplicates for (int i=0; i<ps->Elements(); ++i) { FESurfaceElement& el = ps->Element(i); // evaluate average prescribed pressure on this face double p = 0; for (int j=0; j<el.GaussPoints(); ++j) { FEMaterialPoint* pt = el.GetMaterialPoint(j); p += m_p(*pt); } p /= el.GaussPoints(); FEElement* e = el.m_elem[0].pe; FEMaterial* pm = GetFEModel()->GetMaterial(e->GetMatID()); FESoluteInterface* psi = pm->ExtractProperty<FESoluteInterface>(); FESolidElement* se = dynamic_cast<FESolidElement*>(e); FEShellElement* sh = dynamic_cast<FEShellElement*>(e); if (se) { double peo[FEElement::MAX_NODES] = {0}; if (psi) { const int nsol = psi->Solutes(); std::vector<double> kappa(nsol,0); double osc = 0; const int nint = se->GaussPoints(); // get the average osmotic coefficient and partition coefficients in the solid element for (int j=0; j<nint; ++j) { FEMaterialPoint* pt = se->GetMaterialPoint(j); osc += psi->GetOsmoticCoefficient()->OsmoticCoefficient(*pt); for (int k=0; k<nsol; ++k) kappa[k] += psi->GetPartitionCoefficient(*pt, k); } osc /= nint; for (int k=0; k<nsol; ++k) kappa[k] /= nint; // loop over face nodes for (int j=0; j<el.Nodes(); ++j) { double osm = 0; FENode& node = ps->Node(el.m_lnode[j]); // calculate osmolarity at this node, using nodal effective solute concentrations for (int k=0; k<nsol; ++k) osm += node.get(m_dofC+psi->GetSolute(k)->GetSoluteID()-1)*kappa[k]; // evaluate effective fluid pressure at this node peo[j] = p - m_Rgas*m_Tabs*osc*osm; } } else { // loop over face nodes for (int j=0; j<el.Nodes(); ++j) { FENode& node = ps->Node(el.m_lnode[j]); // evaluate effective fluid pressure at this node peo[j] = p; } } // only keep the dilatations at the nodes of the surface face for (int j=0; j<el.Nodes(); ++j) peNodes[el.m_lnode[j]].push_back(peo[j]); } //If no solid element, insert all 0s else if (sh) { double peo[FEElement::MAX_NODES] = {0}; if (psi) { const int nsol = psi->Solutes(); std::vector<double> kappa(nsol,0); double osc = 0; const int nint = sh->GaussPoints(); // get the average osmotic coefficient and partition coefficients in the solid element for (int j=0; j<nint; ++j) { FEMaterialPoint* pt = sh->GetMaterialPoint(j); osc += psi->GetOsmoticCoefficient()->OsmoticCoefficient(*pt); for (int k=0; k<nsol; ++k) kappa[k] += psi->GetPartitionCoefficient(*pt, k); } osc /= nint; for (int k=0; k<nsol; ++k) kappa[k] /= nint; // loop over face nodes for (int j=0; j<el.Nodes(); ++j) { double osm = 0; FENode& node = ps->Node(el.m_lnode[j]); // calculate osmolarity at this node, using nodal effective solute concentrations for (int k=0; k<nsol; ++k) osm += node.get(m_dofC+psi->GetSolute(k)->GetSoluteID()-1)*kappa[k]; // evaluate effective fluid pressure at this node peo[j] = p - m_Rgas*m_Tabs*osc*osm; } } else { // loop over face nodes for (int j=0; j<el.Nodes(); ++j) { FENode& node = ps->Node(el.m_lnode[j]); // evaluate effective fluid pressure at this node peo[j] = p; } } // only keep the dilatations at the nodes of the surface face for (int j=0; j<el.Nodes(); ++j) peNodes[el.m_lnode[j]].push_back(peo[j]); } } //For each node, average the nodal pe for (int i=0; i<ps->Nodes(); ++i) { double pe = 0; for (int j = 0; j < peNodes[i].size(); ++j) pe += peNodes[i][j]; pe /= peNodes[i].size(); // store value for now m_pe[i] = pe; } FEPrescribedSurface::Update(); } //----------------------------------------------------------------------------- void FEMultiphasicFluidPressureBC::GetNodalValues(int nodelid, std::vector<double>& val) { val[0] = m_pe[nodelid]; } //----------------------------------------------------------------------------- // copy data from another class void FEMultiphasicFluidPressureBC::CopyFrom(FEBoundaryCondition* pbc) { // TODO: implement this assert(false); } //----------------------------------------------------------------------------- //! serialization void FEMultiphasicFluidPressureBC::Serialize(DumpStream& ar) { FEPrescribedSurface::Serialize(ar); ar & m_pe; if (ar.IsShallow()) return; ar & m_dofC & m_dofP; ar & m_Rgas & m_Tabs; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEDiffConstIso.h
.h
2,374
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 "FEBiphasicSolute.h" //----------------------------------------------------------------------------- // This class implements a material that has a constant diffusivity class FEBIOMIX_API FEDiffConstIso : public FESoluteDiffusivity { public: //! constructor FEDiffConstIso(FEModel* pfem); //! free diffusivity double Free_Diffusivity(FEMaterialPoint& pt) override; //! Tangent of diffusivity with respect to concentration double Tangent_Free_Diffusivity_Concentration(FEMaterialPoint& mp, const int isol) override; //! diffusivity mat3ds Diffusivity(FEMaterialPoint& pt) override; //! Tangent of diffusivity with respect to strain tens4dmm Tangent_Diffusivity_Strain(FEMaterialPoint& mp) override; //! Tangent of diffusivity with respect to concentration mat3ds Tangent_Diffusivity_Concentration(FEMaterialPoint& mp, const int isol) override; //! data checking bool Validate() override; public: FEParamDouble m_free_diff; //!< free diffusivity FEParamDouble m_diff; //!< diffusivity // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEReaction.h
.h
3,336
106
/*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 "febiomix_api.h" #include <map> //----------------------------------------------------------------------------- class FESoluteInterface; //----------------------------------------------------------------------------- //! Base class for reactions. typedef std::map<int,int> intmap; typedef std::map<int,int>::iterator itrmap; class FEBIOMIX_API FEReaction : public FEMaterialProperty { public: //! constructor FEReaction(FEModel* pfem); //! initialization bool Init() override; //! serialization void Serialize(DumpStream& dmp); public: //! set stoichiometric coefficient void SetStoichiometricCoefficient(intmap& RP, int id, int v) { RP.insert(std::pair<int, int>(id, v)); } public: //TODO: Make this protected again FESoluteInterface* m_psm; //!< solute interface to parent class }; //----------------------------------------------------------------------------- class FEBIOMIX_API FEReactionSpeciesRef : public FEMaterialProperty { public: enum SpeciesType { UnknownSpecies, SoluteSpecies, SBMSpecies }; public: FEReactionSpeciesRef(FEModel* fem); bool Init() override; int GetSpeciesType() const; bool IsSolute() const; bool IsSBM() const; public: int m_speciesID; // the species ID int m_v; // stoichiometric coefficient // these parameters are mostly for parsing older files that used "sol" or "sbm" int m_solId; int m_sbmId; private: int m_speciesType; // solute or sbm? DECLARE_FECORE_CLASS(); }; class FEBIOMIX_API FEReactantSpeciesRef : public FEReactionSpeciesRef { public: FEReactantSpeciesRef(FEModel* fem) : FEReactionSpeciesRef(fem) {} DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEReactantSpeciesRef) }; class FEBIOMIX_API FEProductSpeciesRef : public FEReactionSpeciesRef { public: FEProductSpeciesRef(FEModel* fem) : FEReactionSpeciesRef(fem) {} DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEProductSpeciesRef) };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEHydraulicPermeability.h
.h
2,230
55
/*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 "febiomix_api.h" //----------------------------------------------------------------------------- //! Base class for hydraulic permeability of porous materials. //! These materials need to define the permeability and tangent permeability functions. //! class FEBIOMIX_API FEHydraulicPermeability : public FEMaterialProperty { public: FEHydraulicPermeability(FEModel* pfem) : FEMaterialProperty(pfem) {} virtual ~FEHydraulicPermeability(){} //! hydraulic permeability virtual mat3ds Permeability(FEMaterialPoint& pt) = 0; //! tangent of hydraulic permeability with respect to strain virtual tens4dmm Tangent_Permeability_Strain(FEMaterialPoint& mp) = 0; //! tangent of hydraulic permeability with respect to concentration mat3ds Tangent_Permeability_Concentration(FEMaterialPoint& mp, const int isol); FECORE_BASE_CLASS(FEHydraulicPermeability); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESlidingInterfaceMP.cpp
.cpp
125,088
3,196
/*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 "FESlidingInterfaceMP.h" #include "FEBiphasic.h" #include "FEBiphasicSolute.h" #include "FETriphasic.h" #include "FEMultiphasic.h" #include "FECore/FEModel.h" #include "FECore/log.h" #include "FECore/DOFS.h" #include "FECore/FENormalProjection.h" #include "FECore/FEAnalysis.h" #include <FECore/FELinearSystem.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEAmbientConcentration, FECoreClass) ADD_PARAMETER(m_sol, "sol", FE_PARAM_ATTRIBUTE, "$(solutes)"); ADD_PARAMETER(m_ambc, "ambient_concentration")->MakeVolatile(false); END_FECORE_CLASS(); FEAmbientConcentration::FEAmbientConcentration(FEModel* fem) : FECoreClass(fem) { m_sol = -1; m_ambc = 0.0; } //----------------------------------------------------------------------------- // Define sliding interface parameters BEGIN_FECORE_CLASS(FESlidingInterfaceMP, FEContactInterface) ADD_PARAMETER(m_laugon , "laugon" )->setLongName("Enforcement method")->setEnums("PENALTY\0AUGLAG\0"); ADD_PARAMETER(m_atol , "tolerance" ); ADD_PARAMETER(m_gtol , "gaptol" )->setUnits(UNIT_LENGTH);; ADD_PARAMETER(m_ptol , "ptol" ); ADD_PARAMETER(m_ctol , "ctol" ); ADD_PARAMETER(m_epsn , "penalty" ); ADD_PARAMETER(m_bautopen , "auto_penalty" ); ADD_PARAMETER(m_bupdtpen , "update_penalty" ); ADD_PARAMETER(m_btwo_pass, "two_pass" ); ADD_PARAMETER(m_knmult , "knmult" ); ADD_PARAMETER(m_stol , "search_tol" ); ADD_PARAMETER(m_epsp , "pressure_penalty" ); ADD_PARAMETER(m_epsc , "concentration_penalty"); ADD_PARAMETER(m_bsymm , "symmetric_stiffness" ); ADD_PARAMETER(m_srad , "search_radius" )->setUnits(UNIT_LENGTH);; ADD_PARAMETER(m_nsegup , "seg_up" ); ADD_PARAMETER(m_breloc , "node_reloc" ); ADD_PARAMETER(m_mu , "fric_coeff" ); ADD_PARAMETER(m_phi , "contact_frac" ); ADD_PARAMETER(m_bsmaug , "smooth_aug" ); ADD_PARAMETER(m_bsmfls , "smooth_fls" ); ADD_PARAMETER(m_naugmin , "minaug" ); ADD_PARAMETER(m_naugmax , "maxaug" ); ADD_PARAMETER(m_ambp , "ambient_pressure" ); ADD_PROPERTY(m_ambctmp, "ambient_concentration",FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- void FEMultiphasicContactPoint::Serialize(DumpStream& ar) { FEBiphasicContactPoint::Serialize(ar); ar & m_Lmc; ar & m_epsc; ar & m_cg; ar & m_c1; } //----------------------------------------------------------------------------- // FESlidingSurfaceMP //----------------------------------------------------------------------------- FESlidingSurfaceMP::FESlidingSurfaceMP(FEModel* pfem) : FEBiphasicContactSurface(pfem) { m_bporo = m_bsolu = false; m_dofC = -1; } //----------------------------------------------------------------------------- FESlidingSurfaceMP::~FESlidingSurfaceMP() { } //----------------------------------------------------------------------------- //! create material point data FEMaterialPoint* FESlidingSurfaceMP::CreateMaterialPoint() { return new FEMultiphasicContactPoint; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::UnpackLM(FEElement& el, vector<int>& lm) { // get nodal DOFS DOFS& dofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = dofs.GetVariableSize("concentration"); int N = el.Nodes(); lm.resize(N*(4+MAX_CDOFS)); // pack the equation numbers for (int i=0; i<N; ++i) { int n = el.m_node[i]; FENode& node = m_pMesh->Node(n); vector<int>& id = node.m_ID; // first the displacement dofs lm[3*i ] = id[m_dofX]; lm[3*i+1] = id[m_dofY]; lm[3*i+2] = id[m_dofZ]; // now the pressure dofs lm[3*N+i] = id[m_dofP]; // concentration dofs for (int k=0; k<MAX_CDOFS; ++k) lm[(4 + k)*N + i] = id[m_dofC+k]; } } //----------------------------------------------------------------------------- bool FESlidingSurfaceMP::Init() { // initialize surface data first if (FEBiphasicContactSurface::Init() == false) return false; // store concentration index DOFS& dofs = GetFEModel()->GetDOFS(); m_dofC = dofs.GetDOF("concentration", 0); // allocate node normals and pressures m_nn.assign(Nodes(), vec3d(0,0,0)); m_tn.assign(Nodes(), vec3d(0,0,0)); m_pn.assign(Nodes(), 0); // determine solutes for this surface using the first surface element // TODO: Check that all elements use the same set of solutes as the first element int nsol = 0; if (Elements()) { FESurfaceElement& se = Element(0); // get the element this surface element belongs to FEElement* pe = se.m_elem[0].pe; if (pe) { // get the material FEMaterial* pm = m_pfem->GetMaterial(pe->GetMatID()); // check type of element FEBiphasic* pb = dynamic_cast<FEBiphasic*> (pm); FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (pm); FETriphasic* ptp = dynamic_cast<FETriphasic*> (pm); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*> (pm); if (pb) { m_bporo = true; nsol = 0; } else if (pbs) { m_bporo = m_bsolu = true; nsol = 1; m_sid.assign(nsol, pbs->GetSolute()->GetSoluteID() - 1); } else if (ptp) { m_bporo = m_bsolu = true; nsol = ptp->Solutes(); m_sid.resize(nsol); for (int isol=0; isol<nsol; ++isol) { m_sid[isol] = ptp->GetSolute(isol)->GetSoluteID() - 1; } } else if (pmp) { m_bporo = m_bsolu = true; nsol = pmp->Solutes(); m_sid.resize(nsol); for (int isol=0; isol<nsol; ++isol) { m_sid[isol] = pmp->GetSolute(isol)->GetSoluteID() - 1; } } } } // allocate data structures int NE = Elements(); for (int i=0; i<NE; ++i) { FESurfaceElement& el = Element(i); int nint = el.GaussPoints(); if (nsol) { for (int j=0; j<nint; ++j) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); data.m_Lmc.resize(nsol); data.m_epsc.resize(nsol); data.m_cg.resize(nsol); data.m_c1.resize(nsol); data.m_epsc.assign(nsol,1); data.m_c1.assign(nsol,0.0); data.m_cg.assign(nsol,0.0); data.m_Lmc.assign(nsol,0.0); } } } return true; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::InitSlidingSurface() { for (int i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); int nint = el.GaussPoints(); for (int j=0; j<nint; ++j) { // Store current surface projection values as previous FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); data.m_rsp = data.m_rs; data.m_pmep = data.m_pme; } } } //----------------------------------------------------------------------------- //! Evaluate the nodal contact pressures by averaging values from surrounding //! faces. This function ensures that nodal contact pressures are always //! positive, so that they can be used to detect free-draining status. void FESlidingSurfaceMP::EvaluateNodalContactPressures() { const int N = Nodes(); // number of faces with non-zero contact pressure connected to this node vector<int> nfaces(N,0); // zero nodal contact pressures zero(m_pn); // loop over all elements for (int i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); int ne = el.Nodes(); // get the average contact pressure for that face double pn = 0; GetContactPressure(i, pn); if (pn > 0) { for (int j=0; j<ne; ++j) { m_pn[el.m_lnode[j]] += pn; ++nfaces[el.m_lnode[j]]; } } } // get average over all contacting faces sharing that node for (int i=0; i<N; ++i) if (nfaces[i] > 0) m_pn[i] /= nfaces[i]; } //----------------------------------------------------------------------------- //! Evaluate the nodal contact pressures by averaging values from surrounding //! faces. This function ensures that nodal contact pressures are always //! positive, so that they can be used to detect free-draining status. void FESlidingSurfaceMP::EvaluateNodalContactTractions() { const int N = Nodes(); // number of faces with non-zero contact pressure connected to this node vector<int> nfaces(N,0); // zero nodal contact pressures zero(m_tn); // loop over all elements for (int i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); int ne = el.Nodes(); // get the average contact traction and pressure for that face vec3d tn(0,0,0); GetContactTraction(i, tn); double pn = 0; GetContactPressure(i, pn); if (pn > 0) { for (int j=0; j<ne; ++j) { m_tn[el.m_lnode[j]] += tn; ++nfaces[el.m_lnode[j]]; } } } // get average over all contacting faces sharing that node for (int i=0; i<N; ++i) if (nfaces[i] > 0) m_tn[i] /= nfaces[i]; } //----------------------------------------------------------------------------- //! This function calculates the node normal. Due to the piecewise continuity //! of the surface elements this normal is not uniquely defined so in order to //! obtain a unique normal the normal is averaged for each node over all the //! element normals at the node void FESlidingSurfaceMP::UpdateNodeNormals() { int N = Nodes(), i, j, ne, jp1, jm1; const int MN = FEElement::MAX_NODES; vec3d y[MN], n; // zero nodal normals zero(m_nn); // loop over all elements for (i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); ne = el.Nodes(); // get the nodal coordinates for (j=0; j<ne; ++j) y[j] = Node(el.m_lnode[j]).m_rt; // calculate the normals for (j=0; j<ne; ++j) { jp1 = (j+1)%ne; jm1 = (j+ne-1)%ne; n = (y[jp1] - y[j]) ^ (y[jm1] - y[j]); m_nn[el.m_lnode[j]] += n; } } // normalize all vectors for (i=0; i<N; ++i) m_nn[i].unit(); } //----------------------------------------------------------------------------- vec3d FESlidingSurfaceMP::GetContactForce() { return m_Ft; } //----------------------------------------------------------------------------- double FESlidingSurfaceMP::GetContactArea() { // 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(); // evaluate the contact force for that element for (int i=0; i<nint; ++i) { // get data for this integration point FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(i)); double s = (data.m_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; } //----------------------------------------------------------------------------- vec3d FESlidingSurfaceMP::GetFluidForce() { int n, i; const int MN = FEElement::MAX_NODES; double pn[MN]; // get parent contact interface to extract ambient fluid pressure FESlidingInterfaceMP* simp = dynamic_cast<FESlidingInterfaceMP*>(GetContactInterface()); double ambp = simp->m_ambp; // initialize contact force vec3d f(0,0,0); // loop over all elements of the surface for (n=0; n<Elements(); ++n) { FESurfaceElement& el = Element(n); int nseln = el.Nodes(); // nodal pressures for (i=0; i<nseln; ++i) pn[i] = GetMesh()->Node(el.m_node[i]).get(m_dofP); int nint = el.GaussPoints(); // evaluate the fluid force for that element for (i=0; i<nint; ++i) { // 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]; // fluid pressure for fluid load support double p = el.eval(pn, i) - ambp; // contact force f += n*(w*p); } } return f; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::Serialize(DumpStream& ar) { FEBiphasicContactSurface::Serialize(ar); ar & m_dofP & m_dofC; ar & m_bporo; ar & m_bsolu; ar & m_nn; ar & m_sid; ar & m_pn; ar & m_tn; ar & m_Ft; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetVectorGap(int nface, vec3d& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = vec3d(0,0,0); for (int k=0; k<ni; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_dg; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetContactPressure(int nface, double& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = 0; for (int k = 0; k < ni; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_Ln; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetContactTraction(int nface, vec3d& pt) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pt = vec3d(0,0,0); for (int k = 0; k < ni; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(k)); pt += data.m_tr; } pt /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetSlipTangent(int nface, vec3d& pt) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pt = vec3d(0,0,0); for (int k=0; k<ni; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(k)); if (!data.m_bstick) pt += data.m_s1; } pt /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetMuEffective(int nface, double& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = 0; for (int k=0; k<ni; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_mueff; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetLocalFLS(int nface, double& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = 0; for (int k = 0; k < ni; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_fls; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetNodalVectorGap(int nface, vec3d* pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); vec3d gi[FEElement::MAX_INTPOINTS]; for (int k=0; k<ni; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(k)); gi[k] = data.m_dg; } el.project_to_nodes(gi, pg); } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetNodalContactPressure(int nface, double* pn) { FESurfaceElement& el = Element(nface); for (int k=0; k<el.Nodes(); ++k) pn[k] = m_pn[el.m_lnode[k]]; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetStickStatus(int nface, double& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = 0; for (int k=0; k<ni; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(k)); if (data.m_bstick) pg += 1.0; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceMP::GetNodalContactTraction(int nface, vec3d* tn) { FESurfaceElement& el = Element(nface); for (int k=0; k<el.Nodes(); ++k) tn[k] = m_tn[el.m_lnode[k]]; } //----------------------------------------------------------------------------- // FESlidingInterfaceMP //----------------------------------------------------------------------------- FESlidingInterfaceMP::FESlidingInterfaceMP(FEModel* pfem) : FEContactInterface(pfem), m_ss(pfem), m_ms(pfem) { static int count = 1; SetID(count++); // initial values m_knmult = 1; m_atol = 0.1; m_epsn = 1; m_epsp = 1; m_epsc = 1; m_btwo_pass = false; m_stol = 0.01; m_bsymm = true; m_srad = 1.0; m_gtol = 0; m_ptol = 0; m_ctol = 0; m_ambp = 0; m_nsegup = 0; m_bautopen = false; m_breloc = false; m_bsmaug = false; m_bupdtpen = false; m_mu = 0.0; m_phi = 0.0; m_naugmin = 0; m_naugmax = 10; m_bfreeze = false; m_dofP = -1; m_dofC = -1; m_ss.SetSibling(&m_ms); m_ms.SetSibling(&m_ss); m_ss.SetContactInterface(this); m_ms.SetContactInterface(this); } //----------------------------------------------------------------------------- FESlidingInterfaceMP::~FESlidingInterfaceMP() { } //----------------------------------------------------------------------------- bool FESlidingInterfaceMP::Init() { m_Rgas = GetFEModel()->GetGlobalConstant("R"); m_Tabs = GetFEModel()->GetGlobalConstant("T"); // get number of DOFS FEModel* fem = GetFEModel(); DOFS& fedofs = fem->GetDOFS(); int nsol = fedofs.GetVariableSize("concentration"); m_ambc.assign(nsol, 0.0); m_dofP = fem->GetDOFIndex("p"); m_dofC = fem->GetDOFIndex("concentration", 0); // initialize surface data if (m_ss.Init() == false) return false; if (m_ms.Init() == false) return false; // determine which solutes are common to both contact surfaces m_sid.clear(); m_ssl.clear(); m_msl.clear(); m_sz.clear(); for (int is=0; is<m_ss.m_sid.size(); ++is) { for (int im=0; im<m_ms.m_sid.size(); ++im) { if (m_ms.m_sid[im] == m_ss.m_sid[is]) { m_sid.push_back(m_ss.m_sid[is]); m_ssl.push_back(is); m_msl.push_back(im); FESoluteData* sd = FindSoluteData(m_ss.m_sid[is]+1); m_sz.push_back(sd->m_z); } } } // cycle through all the solutes and determine ambient concentrations for (int i = 0; i < m_ambctmp.size(); ++i) { FEAmbientConcentration* aci = m_ambctmp[i]; int isol = aci->m_sol - 1; assert((isol >= 0) && (isol < nsol)); m_ambc[isol] = aci->m_ambc; } return true; } //----------------------------------------------------------------------------- //! build the matrix profile for use in the stiffness matrix void FESlidingInterfaceMP::BuildMatrixProfile(FEGlobalMatrix& K) { 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_P = fem.GetDOFIndex("p"); const int dof_C = fem.GetDOFIndex("concentration", 0); int nsol = (int)m_sid.size(); int ndpn = 7 + nsol; vector<int> lm(ndpn*FEElement::MAX_NODES*2); int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FESlidingSurfaceMP& ss = (np == 0? m_ss : m_ms); int k, l; for (int j=0; j<ss.Elements(); ++j) { FESurfaceElement& se = ss.Element(j); int nint = se.GaussPoints(); int* sn = &se.m_node[0]; for (k=0; k<nint; ++k) { FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*se.GetMaterialPoint(k)); FESurfaceElement* pe = data.m_pme; if (pe != 0) { FESurfaceElement& me = *pe; int* mn = &me.m_node[0]; assign(lm, -1); int nseln = se.Nodes(); int nmeln = me.Nodes(); for (l=0; l<nseln; ++l) { vector<int>& id = mesh.Node(sn[l]).m_ID; lm[ndpn*l ] = id[dof_X]; lm[ndpn*l+1] = id[dof_Y]; lm[ndpn*l+2] = id[dof_Z]; lm[ndpn*l+3] = id[dof_P]; for (int m=0; m<nsol; ++m) { lm[ndpn*l+4+m] = id[dof_C + m_sid[m]]; } } for (l=0; l<nmeln; ++l) { vector<int>& id = mesh.Node(mn[l]).m_ID; lm[ndpn*(l+nseln) ] = id[dof_X]; lm[ndpn*(l+nseln)+1] = id[dof_Y]; lm[ndpn*(l+nseln)+2] = id[dof_Z]; lm[ndpn*(l+nseln)+3] = id[dof_P]; for (int m=0; m<nsol; ++m) { lm[ndpn*(l+nseln)+4+m] = id[dof_C + m_sid[m]]; } } K.build_add(lm); } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::UpdateAutoPenalty() { // calculate the penalty if (m_bautopen) { CalcAutoPenalty(m_ss); CalcAutoPenalty(m_ms); if (m_ss.m_bporo) CalcAutoPressurePenalty(m_ss); for (int is=0; is<m_ssl.size(); ++is) CalcAutoConcentrationPenalty(m_ss, m_ssl[is]); if (m_ms.m_bporo) CalcAutoPressurePenalty(m_ms); for (int im=0; im<m_msl.size(); ++im) CalcAutoConcentrationPenalty(m_ms, m_msl[im]); } } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::Activate() { // don't forget to call the base members FEContactInterface::Activate(); UpdateAutoPenalty(); // update sliding interface data Update(); } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::CalcAutoPenalty(FESlidingSurfaceMP& s) { // loop over all surface elements for (int i=0; i<s.Elements(); ++i) { // get the surface element FESurfaceElement& el = s.Element(i); // calculate a penalty double eps = AutoPenalty(el, s); // assign to integation points of surface element int nint = el.GaussPoints(); for (int j=0; j<nint; ++j) { FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsn = eps; } } } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::CalcAutoPressurePenalty(FESlidingSurfaceMP& s) { // loop over all surface elements for (int i=0; i<s.Elements(); ++i) { // get the surface element FESurfaceElement& el = s.Element(i); // calculate a penalty double eps = AutoPressurePenalty(el, s); // assign to integation points of surface element int nint = el.GaussPoints(); for (int j=0; j<nint; ++j) { FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsp = eps; } } } //----------------------------------------------------------------------------- //! This function calculates a contact penalty parameter based on the //! material and geometrical properties of the primary and secondary surfaces //! double FESlidingInterfaceMP::AutoPenalty(FESurfaceElement& el, FESurface &s) { // get the mesh FEMesh& m = GetFEModel()->GetMesh(); // get the element this surface element belongs to FEElement* pe = el.m_elem[0].pe; if (pe == 0) return 0.0; tens4ds S; // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); // extract the material FEMaterial* pme = GetFEModel()->GetMaterial(pe->GetMatID()); if (pme == 0) return 0.0; // get the tangent (stiffness) if (dynamic_cast<FEMultiphasic*>(pme)) { FEMultiphasic* pmm = dynamic_cast<FEMultiphasic*>(pme); S = pmm->Tangent(mp); } else if (dynamic_cast<FETriphasic*>(pme)) { FETriphasic* pms = dynamic_cast<FETriphasic*>(pme); S = pms->Tangent(mp); } else if (dynamic_cast<FEBiphasicSolute*>(pme)) { FEBiphasicSolute* pms = dynamic_cast<FEBiphasicSolute*>(pme); S = pms->Tangent(mp); } else if (dynamic_cast<FEBiphasic*>(pme)) { FEBiphasic* pmb = dynamic_cast<FEBiphasic*>(pme); S = (pmb->Tangent(mp)).supersymm(); } else if (dynamic_cast<FEElasticMaterial*>(pme)) { FEElasticMaterial* pm = dynamic_cast<FEElasticMaterial*>(pme); S = pm->Tangent(mp); } // get the inverse (compliance) at this point tens4ds C = S.inverse(); // evaluate element surface normal at parametric center vec3d t[2]; s.CoBaseVectors0(el, 0, 0, t); vec3d n = t[0] ^ t[1]; n.unit(); // evaluate normal component of the compliance matrix // (equivalent to inverse of Young's modulus along n) double eps = 1./(n*(vdotTdotv(n, C, n)*n)); // get the area of the surface element double A = s.FaceArea(el); // get the volume of the volume element double V = m.ElementVolume(*pe); return eps*A/V; } //----------------------------------------------------------------------------- double FESlidingInterfaceMP::AutoPressurePenalty(FESurfaceElement& el, FESlidingSurfaceMP& s) { // get the mesh FEMesh& m = GetFEModel()->GetMesh(); // evaluate element surface normal at parametric center vec3d t[2]; s.CoBaseVectors0(el, 0, 0, t); vec3d n = t[0] ^ t[1]; n.unit(); // get the element this surface element belongs to FEElement* pe = el.m_elem[0].pe; if (pe == 0) return 0.0; // get the material FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); mat3ds K; // check type of element FEBiphasic* pb = dynamic_cast<FEBiphasic*> (pm); FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (pm); FETriphasic* ptp = dynamic_cast<FETriphasic*> (pm); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*> (pm); if (pb) K = pb->GetPermeability()->Permeability(mp); else if (pbs) K = pbs->GetPermeability()->Permeability(mp); else if (ptp) K = ptp->GetPermeability()->Permeability(mp); else if (pmp) K = pmp->GetPermeability()->Permeability(mp); double eps = n*(K*n); // get the area of the surface element double A = s.FaceArea(el); // get the volume of the volume element double V = m.ElementVolume(*pe); return eps*A/V; } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::CalcAutoConcentrationPenalty(FESlidingSurfaceMP& s, const int isol) { // loop over all surface elements int ni = 0; for (int i=0; i<s.Elements(); ++i) { // get the surface element FESurfaceElement& el = s.Element(i); // calculate a modulus double eps = AutoConcentrationPenalty(el, s, isol); // assign to integation points of surface element int nint = el.GaussPoints(); for (int j=0; j<nint; ++j, ++ni) { FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsc[isol] = eps; } } } //----------------------------------------------------------------------------- double FESlidingInterfaceMP::AutoConcentrationPenalty(FESurfaceElement& el, FESlidingSurfaceMP& s, const int isol) { // get the mesh FEMesh& m = GetFEModel()->GetMesh(); // evaluate element surface normal at parametric center vec3d t[2]; s.CoBaseVectors0(el, 0, 0, t); vec3d n = t[0] ^ t[1]; n.unit(); // get the element this surface element belongs to FEElement* pe = el.m_elem[0].pe; if (pe == 0) return 0.0; // get the material FEMaterial* pm = GetFEModel()->GetMaterial(pe->GetMatID()); // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); mat3ds D; // see if this is a biphasic-solute or multiphasic element FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (pm); FETriphasic* ptp = dynamic_cast<FETriphasic*> (pm); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*> (pm); if (pbs) { D = pbs->GetSolute()->m_pDiff->Diffusivity(mp) *(pbs->Porosity(mp)*pbs->GetSolute()->m_pSolub->Solubility(mp)); } else if (ptp) { D = ptp->GetSolute(isol)->m_pDiff->Diffusivity(mp) *(ptp->Porosity(mp)*ptp->GetSolute(isol)->m_pSolub->Solubility(mp)); } else if (pmp) { D = pmp->GetSolute(isol)->m_pDiff->Diffusivity(mp) *(pmp->Porosity(mp)*pmp->GetSolute(isol)->m_pSolub->Solubility(mp)); } // evaluate normal component of diffusivity double eps = n*(D*n); // get the area of the surface element double A = s.FaceArea(el); // get the volume of the volume element double V = m.ElementVolume(*pe); return eps*A/V; } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::ProjectSurface(FESlidingSurfaceMP& ss, FESlidingSurfaceMP& ms, bool bupseg, bool bmove) { FEMesh& mesh = GetFEModel()->GetMesh(); FESurfaceElement* pme; vec3d r, nu; double rs[2] = {0,0}; double Ln; const int MN = FEElement::MAX_NODES; int nsol = (int)m_sid.size(); double ps[MN], p1 = 0.0; vector< vector<double> > cs(nsol, vector<double>(MN)); vector<double> c1(nsol); c1.assign(nsol,0); double psf = GetPenaltyScaleFactor(); // initialize projection data FENormalProjection np(ms); np.SetTolerance(m_stol); np.SetSearchRadius(m_srad); np.Init(); // if we need to project the nodes onto the secondary surface, // let's do this first if (bmove) { int NN = ss.Nodes(); int NE = ss.Elements(); // first we need to calculate the node normals vector<vec3d> normal; normal.assign(NN, vec3d(0,0,0)); for (int i=0; i<NE; ++i) { FESurfaceElement& el = ss.Element(i); int ne = el.Nodes(); for (int j=0; j<ne; ++j) { vec3d r0 = ss.Node(el.m_lnode[ j ]).m_rt; vec3d rp = ss.Node(el.m_lnode[(j+ 1)%ne]).m_rt; vec3d rm = ss.Node(el.m_lnode[(j+ne-1)%ne]).m_rt; vec3d n = (rp - r0)^(rm - r0); normal[el.m_lnode[j]] += n; } } for (int i=0; i<NN; ++i) normal[i].unit(); // loop over all nodes for (int i=0; i<NN; ++i) { FENode& node = ss.Node(i); // get the spatial nodal coordinates vec3d rt = node.m_rt; vec3d nu = normal[i]; // project onto the secondary surface vec3d q; double rs[2] = {0,0}; FESurfaceElement* pme = np.Project(rt, nu, rs); if (pme) { // the node could potentially be in contact // find the global location of the intersection point vec3d q = ms.Local2Global(*pme, rs[0], rs[1]); // calculate the gap function // NOTE: this has the opposite sign compared // to Gerard's notes. double gap = nu*(rt - q); if (gap>0) node.m_r0 = node.m_rt = q; } } } // loop over all integration points // TODO: commenting this pragma line made my code recover slidingelastic test case results //#pragma omp parallel for for (int i=0; i<ss.Elements(); ++i) { FESurfaceElement& el = ss.Element(i); bool sporo = ss.m_bporo; int ne = el.Nodes(); int nint = el.GaussPoints(); // get the nodal pressures if (sporo) { for (int j=0; j<ne; ++j) ps[j] = mesh.Node(el.m_node[j]).get(m_dofP); } // get the nodal concentrations for (int isol=0; isol<nsol; ++isol) { for (int j=0; j<ne; ++j) cs[isol][j] = mesh.Node(el.m_node[j]).get(m_dofC + m_sid[isol]); } for (int j=0; j<nint; ++j) { FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); // calculate the global position of the integration point r = ss.Local2Global(el, j); // get the pressure at the integration point if (sporo) p1 = el.eval(ps, j); // get the concentration at the integration point for (int isol=0; isol<nsol; ++isol) c1[isol] = el.eval(&cs[isol][0], j); // calculate the normal at this integration point nu = ss.SurfaceNormal(el, j); // first see if the old intersected face is still good enough pme = pt.m_pme; if (pme) { double g; // see if the ray intersects this element if (ms.Intersect(*pme, r, nu, rs, g, m_stol)) { pt.m_rs[0] = rs[0]; pt.m_rs[1] = rs[1]; } else { pme = 0; } } // find the intersection point with the secondary surface if (pme == 0 && bupseg) pme = np.Project(r, nu, rs); pt.m_pme = pme; pt.m_nu = nu; pt.m_rs[0] = rs[0]; pt.m_rs[1] = rs[1]; if (pme) { // the node could potentially be in contact // find the global location of the intersection point vec3d q = ms.Local2Global(*pme, rs[0], rs[1]); // calculate the gap function // NOTE: this has the opposite sign compared // to Gerard's notes. double g = nu*(r - q); double eps = m_epsn*pt.m_epsn*psf; Ln = pt.m_Lmd + eps*g; pt.m_gap = (g <= m_srad? g : 0); bool mporo = ms.m_bporo; if ((Ln >= 0) && (g <= m_srad)) { // get the pressure at the contact point // account for mixed multiphasic-elastic contact with elastic primary // calculate the pressure gap function double p2 = 0; if (mporo) { double pm[MN]; for (int k=0; k<pme->Nodes(); ++k) pm[k] = mesh.Node(pme->m_node[k]).get(m_dofP); p2 = pme->eval(pm, rs[0], rs[1]); } if (sporo) { pt.m_p1 = p1; if (mporo) { pt.m_pg = p1 - p2; } } else if (mporo) { pt.m_p1 = p2; } for (int isol=0; isol<nsol; ++isol) { int sid = m_sid[isol]; double cm[MN]; for (int k=0; k<pme->Nodes(); ++k) cm[k] = mesh.Node(pme->m_node[k]).get(m_dofC + sid); double c2 = pme->eval(cm, rs[0], rs[1]); pt.m_cg[m_ssl[isol]] = c1[isol] - c2; pt.m_c1[m_ssl[isol]] = c1[isol]; } } else { pt.m_Lmd = 0; pt.m_gap = 0; pt.m_pme = 0; pt.m_dg = pt.m_Lmt = vec3d(0,0,0); if (sporo || mporo) { pt.m_Lmp = 0; pt.m_pg = 0; pt.m_p1 = 0; } for (int isol=0; isol<nsol; ++isol) { pt.m_Lmc[m_ssl[isol]] = 0; pt.m_cg[m_ssl[isol]] = 0; pt.m_c1[m_ssl[isol]] = 0; } } } else { // the node is not in contact pt.m_Lmd = 0; pt.m_gap = 0; pt.m_dg = pt.m_Lmt = vec3d(0,0,0); if (sporo) { pt.m_Lmp = 0; pt.m_pg = 0; pt.m_p1 = 0; } for (int isol=0; isol<nsol; ++isol) { pt.m_Lmc[m_ssl[isol]] = 0; pt.m_cg[m_ssl[isol]] = 0; pt.m_c1[m_ssl[isol]] = 0; } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::Update() { double rs[2]={0,0}; FEModel& fem = *GetFEModel(); // get number of DOFS DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); static int naug = 0; static int biter = 0; // get the iteration number // we need this number to see if we can do segment updates or not // also reset number of iterations after each augmentation FEAnalysis* pstep = fem.GetCurrentStep(); FESolver* psolver = pstep->GetFESolver(); if (psolver->m_niter == 0) { biter = 0; naug = psolver->m_naug; // check update of auto-penalty if (m_bupdtpen) UpdateAutoPenalty(); } else if (psolver->m_naug > naug) { biter = psolver->m_niter; naug = psolver->m_naug; } int niter = psolver->m_niter - biter; bool bupseg = ((m_nsegup == 0)? true : (niter <= m_nsegup)); // get the logfile // Logfile& log = GetLogfile(); // log.printf("seg_up iteration # %d\n", niter+1); // project the surfaces onto each other // this will update the gap functions as well static bool bfirst = true; ProjectSurface(m_ss, m_ms, bupseg, (m_breloc && bfirst)); // TODO: there was a bug below - the right part of the OR statement was m_ss.m_bporo if (m_btwo_pass || m_ms.m_bporo) ProjectSurface(m_ms, m_ss, bupseg); bfirst = false; // Call InitSlidingSurface on the first iteration of each time step // TODO: previously had the line below controlling InitSlidingSurface, but SlidingBiphasic uses nsolve_iter // if (niter == 0) int nsolve_iter = psolver->m_niter; if (nsolve_iter == 0) { m_ss.InitSlidingSurface(); if (m_btwo_pass) m_ms.InitSlidingSurface(); m_bfreeze = false; } // Update the net contact pressures UpdateContactPressures(); if (niter == 0) m_bfreeze = false; // set poro flag bool bporo = (m_ss.m_bporo || m_ms.m_bporo); // only continue if we are doing a poro-elastic simulation if (bporo == false) return; // TODO: this line is above the "only continue if..." line in SlidingMP // update node normals m_ss.UpdateNodeNormals(); m_ms.UpdateNodeNormals(); // Now that the nodes have been projected, we need to figure out // if we need to modify the constraints on the pressure and concentration dofs. // If the nodes are not in contact, they must match ambient // conditions. Since all nodes have been previously marked to be // under ambient conditions in MarkAmbient(), we just need to reverse // this setting here, for nodes that are in contact. // Next, we loop over each surface, visiting the nodes // and finding out if that node is in contact or not int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FESlidingSurfaceMP& ss = (np == 0? m_ss : m_ms); FESlidingSurfaceMP& ms = (np == 0? m_ms : m_ss); // initialize projection data FENormalProjection project(ss); project.SetTolerance(m_stol); project.SetSearchRadius(m_srad); project.Init(); // loop over all the nodes of the primary surface for (int n=0; n<ss.Nodes(); ++n) { if (ss.m_pn[n] > 0) { FENode& node = ss.Node(n); int id = node.m_ID[m_dofP]; if (id < -1) // mark node as non-ambient (= pos ID) node.m_ID[m_dofP] = -id-2; for (int j=0; j<MAX_CDOFS; ++j) { id = node.m_ID[m_dofC+j]; if (id < -1) // mark node as non-ambient (= pos ID) node.m_ID[m_dofC+j] = -id-2; } } } // loop over all nodes of the secondary surface // the secondary surface is trickier since we need // to look at the primary's surface projection if (ms.m_bporo) { for (int n=0; n<ms.Nodes(); ++n) { // get the node FENode& node = ms.Node(n); // project it onto the primary surface FESurfaceElement* pse = project.Project(node.m_rt, ms.m_nn[n], rs); if (pse) { // we found an element, so let's see if it's even remotely close to contact // find the global location of the intersection point vec3d q = ss.Local2Global(*pse, rs[0], rs[1]); // calculate the gap function double g = ms.m_nn[n]*(node.m_rt - q); // TODO: SlidingMP uses R, SlidingBiphasic uses m_srad if (fabs(g) <= m_srad) { // we found an element so let's calculate the nodal traction values for this element // get the normal tractions at the nodes double tn[FEElement::MAX_NODES]; for (int i=0; i<pse->Nodes(); ++i) tn[i] = ss.m_pn[pse->m_lnode[i]]; // now evaluate the traction at the intersection point double tp = pse->eval(tn, rs[0], rs[1]); // if tp > 0, mark node as non-ambient. (= pos ID) if (tp > 0) { int id = node.m_ID[m_dofP]; if (id < -1) // mark as non-ambient node.m_ID[m_dofP] = -id-2; for (int j=0; j<MAX_CDOFS; ++j) { id = node.m_ID[m_dofC+j]; if (id < -1) // mark as non-ambient node.m_ID[m_dofC+j] = -id-2; } } } } } } } } //----------------------------------------------------------------------------- vec3d FESlidingInterfaceMP::SlipTangent(FESlidingSurfaceMP& ss, const int nel, const int nint, FESlidingSurfaceMP& ms, double& dh, vec3d& r) { vec3d s1(0,0,0); dh = 0; r = vec3d(0,0,0); // get primary surface element FESurfaceElement& se = ss.Element(nel); // get integration point data FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*se.GetMaterialPoint(nint)); double g = data.m_gap; vec3d nu = data.m_nu; // find secondary surface element FESurfaceElement* pme = data.m_pme; // calculate previous positions vec3d x2p = ms.Local2GlobalP(*pme, data.m_rs[0], data.m_rs[1]); vec3d x1p = ss.Local2GlobalP(se, nint); // calculate dx2 vec3d x2 = ms.Local2Global(*pme, data.m_rs[0], data.m_rs[1]); vec3d dx2 = x2 - x2p; // calculate dx1 vec3d x1 = ss.Local2Global(se, nint); vec3d dx1 = x1 - x1p; // get current and previous covariant basis vectors vec3d gscov[2], gscovp[2]; ss.CoBaseVectors(se, nint, gscov); ss.CoBaseVectorsP(se, nint, gscovp); // calculate delta gscov vec3d dgscov[2]; dgscov[0] = gscov[0] - gscovp[0]; dgscov[1] = gscov[1] - gscovp[1]; // calculate m, J, Nhat vec3d m = ((dgscov[0] ^ gscov[1]) + (gscov[0] ^ dgscov[1])); double detJ = (gscov[0] ^ gscov[1]).norm(); mat3d Nhat = (mat3dd(1) - (nu & nu)); // calculate c vec3d c = Nhat*m*(1.0/detJ); // calculate slip direction s1 double norm = (Nhat*(c*(-g) + dx1 - dx2)).norm(); if (norm != 0) { s1 = (Nhat*(c*(-g) + dx1 - dx2))/norm; dh = norm; r = c*(-g) + dx1 - dx2; } return s1; } //----------------------------------------------------------------------------- vec3d FESlidingInterfaceMP::ContactTraction(FESlidingSurfaceMP& ss, const int nel, const int n, FESlidingSurfaceMP& ms, double& pn) { vec3d s1(0,0,0); vec3d dr(0,0,0); vec3d t(0,0,0); pn = 0; double tn = 0, ts = 0, mueff = 0; double psf = GetPenaltyScaleFactor(); int nsol = (int)m_sid.size(); vector<double> c1(nsol); c1.assign(nsol,0); // get the mesh FEMesh& m = GetFEModel()->GetMesh(); // get the primary surface element FESurfaceElement& se = ss.Element(nel); // get the integration point data FEMultiphasicContactPoint& data = static_cast<FEMultiphasicContactPoint&>(*se.GetMaterialPoint(n)); // penalty double eps = m_epsn*data.m_epsn*psf; // normal gap double g = data.m_gap; // normal traction Lagrange multiplier double Lm = data.m_Lmd; // vector traction Lagrange multiplier vec3d Lt = data.m_Lmt; // get the normal at this integration point vec3d nu = data.m_nu; // get the fluid pressure at this integration point double p = data.m_p1; // get the solute concentrations at this integration point for (int isol=0; isol<nsol; ++isol) c1[isol] = data.m_c1[m_ssl[isol]]; // get the fluid pressure for load sharing at this integration point double ph = data.m_p1 - m_ambp; // get poro status of primary surface bool sporo = ss.m_bporo; // get current and previous secondary elements FESurfaceElement* pme = data.m_pme; FESurfaceElement* pmep = data.m_pmep; // zero the effective friction coefficient data.m_mueff = 0.0; data.m_fls = 0.0; data.m_s1 = vec3d(0,0,0); // get local FLS from element projection // TODO: Gerard: I added an optional 'pamb' argument to GetGPLocalFLS double fls = 0; if (m_bsmfls) { double lfls[FEElement::MAX_INTPOINTS]; ss.GetGPLocalFLS(nel, lfls, m_ambp); fls = lfls[n]; } // if we just returned from an augmentation, do not update stick or slip status if (m_bfreeze && pme) { if (data.m_bstick) { // calculate current global position of the integration point vec3d xo = ss.Local2Global(se, n); // calculate current global position of the previous intersection point vec3d xt = ms.Local2Global(*pmep, data.m_rsp[0], data.m_rsp[1]); // calculate vector gap vec3d dg = xt - xo; // calculate trial stick traction, normal component, shear component t = Lt + dg*eps; tn = t*nu; ts = (t - nu*tn).norm(); // contact pressure pn = MBRACKET(-tn); // calculate effective friction coefficient if (pn > 0) { data.m_mueff = ts/pn; data.m_fls = m_bsmfls ? fls : ph/pn; } // store the previous values as the current data.m_pme = data.m_pmep; data.m_rs = data.m_rsp; // recalculate gap data.m_dg = dg; // recalculate pressure gap bool mporo = ms.m_bporo; if (sporo && mporo) { double pm[FEElement::MAX_NODES]; for (int k=0; k<pme->Nodes(); ++k) pm[k] = m.Node(pme->m_node[k]).get(m_dofP); double p2 = pme->eval(pm, data.m_rs[0], data.m_rs[1]); data.m_pg = p - p2; } //TODO: what if stick/slip moves from poro to elastic or vice versa? Should I add // an "else {data.m_pg = 0}" line? // recalculate concentration gaps for (int isol=0; isol<nsol; ++isol) { int sid = m_sid[isol]; double cm[FEElement::MAX_NODES]; for (int k=0; k<pme->Nodes(); ++k) cm[k] = m.Node(pme->m_node[k]).get(m_dofC + sid); double c2 = pme->eval(cm, data.m_rs[0], data.m_rs[1]); data.m_cg[m_ssl[isol]] = c1[isol] - c2; } } else { // recalculate contact pressure for slip pn = MBRACKET(Lm + eps*g); if (pn != 0) { double dh = 0; // slip direction s1 = SlipTangent(ss, nel, n, ms, dh, dr); // calculate effective friction coefficient data.m_fls = m_bsmfls ? fls : ph/pn; data.m_mueff = m_mu*(1.0-(1.0-m_phi)*data.m_fls); data.m_mueff = MBRACKET(data.m_mueff); // total traction t = (nu + s1*data.m_mueff)*(-pn); // reset slip direction data.m_s1 = s1; } else { t = vec3d(0,0,0); } } } // update contact tractions else { data.m_bstick = false; if (pme) { // assume stick and calculate traction if (pmep) { // calculate current global position of the integration point vec3d xo = ss.Local2Global(se, n); // calculate current global position of the previous intersection point vec3d xt = ms.Local2Global(*pmep, data.m_rsp[0], data.m_rsp[1]); // calculate vector gap vec3d dg = xt - xo; // calculate trial stick traction, normal component, shear component t = Lt + dg*eps; tn = t*nu; ts = (t - nu*tn).norm(); // calculate effective friction coefficient if (tn != 0) { data.m_fls = m_bsmfls ? fls : ph/(-tn); mueff = m_mu*(1.0-(1.0-m_phi)*data.m_fls); mueff = MBRACKET(mueff); } // check if stick if ( (tn < 0) && (ts < fabs(tn*mueff)) ) { // set boolean flag for stick data.m_bstick = true; // contact pressure pn = MBRACKET(-tn); // calculate effective friction coefficient if (pn > 0) { data.m_mueff = ts/pn; data.m_fls = m_bsmfls ? fls : ph/pn; } // store the previous values as the current data.m_pme = data.m_pmep; data.m_rs = data.m_rsp; // recalculate gaps data.m_dg = dg; // recalculate pressure gap bool mporo = ms.m_bporo; if (sporo && mporo) { double pm[FEElement::MAX_NODES]; for (int k=0; k<pme->Nodes(); ++k) pm[k] = m.Node(pme->m_node[k]).get(m_dofP); double p2 = pme->eval(pm, data.m_rs[0], data.m_rs[1]); data.m_pg = p - p2; } //TODO: what if stick/slip moves from poro to elastic or vice versa? Should I add // an "else {data.m_pg = 0}" line? // recalculate concentration gaps for (int isol=0; isol<nsol; ++isol) { int sid = m_sid[isol]; double cm[FEElement::MAX_NODES]; for (int k=0; k<pme->Nodes(); ++k) cm[k] = m.Node(pme->m_node[k]).get(m_dofC + sid); double c2 = pme->eval(cm, data.m_rs[0], data.m_rs[1]); data.m_cg[m_ssl[isol]] = c1[isol] - c2; } } else { // recalculate contact pressure for slip pn = MBRACKET(Lm + eps*g); if (pn != 0) { double dh = 0; // slip direction s1 = SlipTangent(ss, nel, n, ms, dh, dr); // calculate effective friction coefficient data.m_fls = m_bsmfls ? fls : ph/pn; data.m_mueff = m_mu*(1.0-(1.0-m_phi)*data.m_fls); data.m_mueff = MBRACKET(data.m_mueff); // total traction t = (nu + s1*data.m_mueff)*(-pn); // reset slip direction data.m_s1 = s1; data.m_bstick = false; } else { t = vec3d(0,0,0); } } } else { // assume slip upon first contact // calculate contact pressure for slip pn = MBRACKET(Lm + eps*g); if (pn != 0) { double dh = 0; // slip direction s1 = SlipTangent(ss, nel, n, ms, dh, dr); // calculate effective friction coefficient data.m_fls = m_bsmfls ? fls : ph/pn; data.m_mueff = m_mu*(1.0-(1.0-m_phi)*data.m_fls); data.m_mueff = MBRACKET(data.m_mueff); // total traction t = (nu + s1*data.m_mueff)*(-pn); // reset slip direction data.m_s1 = s1; data.m_bstick = false; } } } } return t; } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { vector<int> sLM, mLM, LM, en; vector<double> fe; const int MN = FEElement::MAX_NODES; double detJ[MN], w[MN], *Hs, Hm[MN]; double N[MN*10]; int nsol = (int)m_sid.size(); FEModel& fem = *GetFEModel(); // need to multiply multiphasic stiffness entries by the timestep double dt = fem.GetTime().timeIncrement; double psf = GetPenaltyScaleFactor(); m_ss.m_Ft = vec3d(0, 0, 0); m_ms.m_Ft = vec3d(0, 0, 0); // loop over the nr of passes int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { // get primary and secondary surface FESlidingSurfaceMP& ss = (np == 0? m_ss : m_ms); FESlidingSurfaceMP& ms = (np == 0? m_ms : m_ss); vector<int>& sl = (np == 0? m_ssl : m_msl); // loop over all primary surface elements for (int i=0; i<ss.Elements(); ++i) { // get the surface element FESurfaceElement& se = ss.Element(i); bool sporo = ss.m_bporo; // get the nr of nodes and integration points int nseln = se.Nodes(); int nint = se.GaussPoints(); // copy the LM vector; we'll need it later ss.UnpackLM(se, sLM); // we calculate all the metrics we need before we // calculate the nodal forces for (int j=0; j<nint; ++j) { // get the base vectors vec3d g[2]; ss.CoBaseVectors(se, j, g); // jacobians: J = |g0xg1| detJ[j] = (g[0] ^ g[1]).norm(); // integration weights w[j] = se.GaussWeights()[j]; } // loop over all integration points // note that we are integrating over the current surface for (int j=0; j<nint; ++j) { // get integration point data FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*se.GetMaterialPoint(j)); // calculate contact pressure and account for stick double pn; vec3d t = ContactTraction(ss, i, j, ms, pn); // get the secondary surface element FESurfaceElement* pme = pt.m_pme; if (pme) { // get the secondary surface element FESurfaceElement& me = *pme; bool mporo = ms.m_bporo; // get the nr of secondary element nodes int nmeln = me.Nodes(); // copy LM vector ms.UnpackLM(me, mLM); // calculate degrees of freedom int ndof = 3*(nseln + nmeln); // build the LM vector LM.resize(ndof); for (int k=0; k<nseln; ++k) { LM[3*k ] = sLM[3*k ]; LM[3*k+1] = sLM[3*k+1]; LM[3*k+2] = sLM[3*k+2]; } for (int k=0; k<nmeln; ++k) { LM[3*(k+nseln) ] = mLM[3*k ]; LM[3*(k+nseln)+1] = mLM[3*k+1]; LM[3*(k+nseln)+2] = mLM[3*k+2]; } // build the en vector en.resize(nseln+nmeln); for (int k=0; k<nseln; ++k) en[k ] = se.m_node[k]; for (int k=0; k<nmeln; ++k) en[k+nseln] = me.m_node[k]; // get primary element shape functions Hs = se.H(j); // get secondary element shape functions double r = pt.m_rs[0]; double s = pt.m_rs[1]; me.shape_fnc(Hm, r, s); if (pn > 0) { // calculate the force vector fe.resize(ndof); zero(fe); for (int k=0; k<nseln; ++k) { N[3*k ] = Hs[k]*t.x; N[3*k+1] = Hs[k]*t.y; N[3*k+2] = Hs[k]*t.z; } for (int k=0; k<nmeln; ++k) { N[3*(k+nseln) ] = -Hm[k]*t.x; N[3*(k+nseln)+1] = -Hm[k]*t.y; N[3*(k+nseln)+2] = -Hm[k]*t.z; } for (int k=0; k<ndof; ++k) fe[k] += N[k]*detJ[j]*w[j]; // calculate contact forces for (int k=0; k<nseln; ++k) ss.m_Ft += vec3d(fe[3*k], fe[3*k+1], fe[3*k+2]); for (int k = 0; k<nmeln; ++k) ms.m_Ft += vec3d(fe[3*(k+nseln)], fe[3*(k+nseln)+1], fe[3*(k+nseln)+2]); // assemble the global residual R.Assemble(en, LM, fe); // do the biphasic stuff if (sporo && mporo) { // calculate nr of pressure dofs int ndof = nseln + nmeln; // normal fluid flux double epsp = m_epsp*pt.m_epsp*psf; double wn = pt.m_Lmp + epsp*pt.m_pg; // fill the LM LM.resize(ndof); for (int k=0; k<nseln; ++k) LM[k ] = sLM[3*nseln+k]; for (int k=0; k<nmeln; ++k) LM[k+nseln] = mLM[3*nmeln+k]; // fill the force array fe.resize(ndof); zero(fe); for (int k = 0; k<nseln; ++k) N[k ] = Hs[k]; for (int k = 0; k<nmeln; ++k) N[k+nseln] = -Hm[k]; for (int k = 0; k<ndof; ++k) fe[k] += dt*N[k]*wn*detJ[j]*w[j]; // assemble residual R.Assemble(en, LM, fe); } // do the solute stuff for (int isol=0; isol<nsol; ++isol) { int sid = m_sid[isol]; // calculate nr of concentration dofs int ndof = nseln + nmeln; // calculate normal effective solute flux int l = sl[isol]; double epsc = m_epsc*pt.m_epsc[l]*psf; double jn = pt.m_Lmc[l] + epsc*pt.m_cg[l]; // fill the LM LM.resize(ndof); for (int k = 0; k<nseln; ++k) LM[k ] = sLM[(4+sid)*nseln+k]; for (int k = 0; k<nmeln; ++k) LM[k+nseln] = mLM[(4+sid)*nmeln+k]; // fill the force array fe.resize(ndof); zero(fe); for (int k = 0; k<nseln; ++k) N[k] = Hs[k]; for (int k = 0; k<nmeln; ++k) N[k+nseln] = -Hm[k]; for (int k = 0; k<ndof; ++k) fe[k] += dt*N[k]*jn*detJ[j]*w[j]; // assemble residual R.Assemble(en, LM, fe); } } } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { int i, j, k, l; vector<int> sLM, mLM, LM, en; const int MN = FEElement::MAX_NODES; double detJ[MN], w[MN], *Hs, Hm[MN]; FEElementMatrix ke; int nsol = (int)m_sid.size(); vector<double> jn(nsol); FEModel& fem = *GetFEModel(); double psf = GetPenaltyScaleFactor(); // see how many reformations we've had to do so far int nref = GetSolver()->m_nref; // set higher order stiffness mutliplier // NOTE: this algorithm doesn't really need this // but I've added this functionality to compare with the other contact // algorithms and to see the effect of the different stiffness contributions double knmult = m_knmult; if (m_knmult < 0) { int ni = int(-m_knmult); if (nref >= ni) { knmult = 1; feLog("Higher order stiffness terms included.\n"); } else knmult = 0; } // do single- or two-pass int npass = (m_btwo_pass?2:1); for (int np=0; np < npass; ++np) { // get the primary and secondary surface FESlidingSurfaceMP& ss = (np == 0? m_ss : m_ms); FESlidingSurfaceMP& ms = (np == 0? m_ms : m_ss); vector<int>& sl = (np == 0? m_ssl : m_msl); // loop over all primary surface elements for (i=0; i<ss.Elements(); ++i) { // get the next element FESurfaceElement& se = ss.Element(i); bool sporo = ss.m_bporo; // get nr of nodes and integration points int nseln = se.Nodes(); int nint = se.GaussPoints(); double pn[MN] = {0}; vector< vector<double> >cn(nsol,vector<double>(MN)); if (sporo) { for (j=0; j<nseln; ++j) { pn[j] = ss.GetMesh()->Node(se.m_node[j]).get(m_dofP); for (int isol=0; isol<nsol; ++isol) { cn[isol][j] = ss.GetMesh()->Node(se.m_node[j]).get(m_dofC + m_sid[isol]); } } } // copy the LM vector ss.UnpackLM(se, sLM); // we calculate all the metrics we need before we // calculate the nodal forces for (j=0; j<nint; ++j) { // get the base vectors vec3d g[2]; ss.CoBaseVectors(se, j, g); // jacobians: J = |g0xg1| detJ[j] = (g[0] ^ g[1]).norm(); // integration weights w[j] = se.GaussWeights()[j]; } // loop over all integration points for (j=0; j<nint; ++j) { // get integration point data FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*se.GetMaterialPoint(j)); // calculate contact traction and account for stick double pn; vec3d t = ContactTraction(ss, i, j, ms, pn); // get the secondary element FESurfaceElement* pme = pt.m_pme; // calculate normal effective solute flux for (int isol=0; isol<nsol; ++isol) { int l = sl[isol]; double epsc = m_epsc*pt.m_epsc[l]*psf; jn[isol] = pt.m_Lmc[l] + epsc*pt.m_cg[l]; } // normal fluid flux double epsp = m_epsp*pt.m_epsp*psf; double wn = pt.m_Lmp + epsp*pt.m_pg; if (pme) { FESurfaceElement& me = *pme; bool mporo = ms.m_bporo; // get the nr of secondary nodes int nmeln = me.Nodes(); // nodal data double pm[MN] = {0}; vector< vector<double> > cm(nsol,vector<double>(MN)); for (k=0; k<nmeln; ++k) { pm[k] = ms.GetMesh()->Node(me.m_node[k]).get(m_dofP); for (int isol=0; isol<nsol; ++isol) { cm[isol][k] = ms.GetMesh()->Node(me.m_node[k]).get(m_dofC + m_sid[isol]); } } // copy the LM vector ms.UnpackLM(me, mLM); int ndpn; // number of dofs per node int ndof; // number of dofs in stiffness matrix if (nsol) { // calculate dofs for biphasic-solute contact ndpn = 4+nsol; ndof = ndpn*(nseln+nmeln); // build the LM vector LM.resize(ndof); for (k=0; k<nseln; ++k) { LM[ndpn*k ] = sLM[3*k ]; // x-dof LM[ndpn*k+1] = sLM[3*k+1]; // y-dof LM[ndpn*k+2] = sLM[3*k+2]; // z-dof LM[ndpn*k+3] = sLM[3*nseln+k]; // p-dof for (int isol=0; isol<nsol; ++isol) LM[ndpn*k+4+isol] = sLM[(4+m_sid[isol])*nseln+k]; // c-dof } for (k=0; k<nmeln; ++k) { LM[ndpn*(k+nseln) ] = mLM[3*k ]; // x-dof LM[ndpn*(k+nseln)+1] = mLM[3*k+1]; // y-dof LM[ndpn*(k+nseln)+2] = mLM[3*k+2]; // z-dof LM[ndpn*(k+nseln)+3] = mLM[3*nmeln+k]; // p-dof for (int isol=0; isol<nsol; ++isol) LM[ndpn*(k+nseln)+4+isol] = mLM[(4+m_sid[isol])*nmeln+k]; // c-dof } } else if (sporo && mporo) { // calculate dofs for biphasic contact ndpn = 4; ndof = ndpn*(nseln+nmeln); // build the LM vector LM.resize(ndof); for (k=0; k<nseln; ++k) { LM[ndpn*k ] = sLM[3*k ]; // x-dof LM[ndpn*k+1] = sLM[3*k+1]; // y-dof LM[ndpn*k+2] = sLM[3*k+2]; // z-dof LM[ndpn*k+3] = sLM[3*nseln+k]; // p-dof } for (k=0; k<nmeln; ++k) { LM[ndpn*(k+nseln) ] = mLM[3*k ]; // x-dof LM[ndpn*(k+nseln)+1] = mLM[3*k+1]; // y-dof LM[ndpn*(k+nseln)+2] = mLM[3*k+2]; // z-dof LM[ndpn*(k+nseln)+3] = mLM[3*nmeln+k]; // p-dof } } else { // calculate dofs for elastic contact ndpn = 3; ndof = ndpn*(nseln + nmeln); // build the LM vector LM.resize(ndof); for (k=0; k<nseln; ++k) { LM[3*k ] = sLM[3*k ]; LM[3*k+1] = sLM[3*k+1]; LM[3*k+2] = sLM[3*k+2]; } for (k=0; k<nmeln; ++k) { LM[3*(k+nseln) ] = mLM[3*k ]; LM[3*(k+nseln)+1] = mLM[3*k+1]; LM[3*(k+nseln)+2] = mLM[3*k+2]; } } // build the en vector en.resize(nseln+nmeln); for (k=0; k<nseln; ++k) en[k ] = se.m_node[k]; for (k=0; k<nmeln; ++k) en[k+nseln] = me.m_node[k]; // primary shape functions Hs = se.H(j); // secondary shape functions double r = pt.m_rs[0]; double s = pt.m_rs[1]; me.shape_fnc(Hm, r, s); // get primary normal vector vec3d nu = pt.m_nu; // gap function double g = pt.m_gap; // penalty double eps = m_epsn*pt.m_epsn*psf; // only evaluate stiffness matrix if contact traction is non-zero if (pn > 0) { // if stick if (pt.m_bstick) { // create the stiffness matrix ke.resize(ndof, ndof); ke.zero(); // evaluate basis vectors on primary surface vec3d gscov[2]; ss.CoBaseVectors(se, j, gscov); // identity tensor mat3d I = mat3dd(1); // evaluate Mc and Ac and combine them into As double* Gr = se.Gr(j); double* Gs = se.Gs(j); mat3d Ac[MN], As[MN]; mat3d gscovh[2]; gscovh[0].skew(gscov[0]); gscovh[1].skew(gscov[1]); for (int k=0; k<nseln; ++k) { Ac[k] = (gscovh[1]*Gr[k] - gscovh[0]*Gs[k])/detJ[j]; As[k] = t & (Ac[k]*nu); } // --- S O L I D - S O L I D C O N T A C T --- double tmp = detJ[j]*w[j]; for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; mat3d Kac = (I*Hs[a]*Hs[c]*eps - As[c]*Hs[a])*tmp; ke[k ][l ] += Kac(0,0); ke[k ][l+1] += Kac(0,1); ke[k ][l+2] += Kac(0,2); ke[k+1][l ] += Kac(1,0); ke[k+1][l+1] += Kac(1,1); ke[k+1][l+2] += Kac(1,2); ke[k+2][l ] += Kac(2,0); ke[k+2][l+1] += Kac(2,1); ke[k+2][l+2] += Kac(2,2); } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; mat3d Kad = I*(-Hs[a]*Hm[d]*eps)*tmp; ke[k ][l ] += Kad(0,0); ke[k ][l+1] += Kad(0,1); ke[k ][l+2] += Kad(0,2); ke[k+1][l ] += Kad(1,0); ke[k+1][l+1] += Kad(1,1); ke[k+1][l+2] += Kad(1,2); ke[k+2][l ] += Kad(2,0); ke[k+2][l+1] += Kad(2,1); ke[k+2][l+2] += Kad(2,2); } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; mat3d Kbc = (I*(-Hm[b]*Hs[c]*eps) + As[c]*Hm[b])*tmp; ke[k ][l ] += Kbc(0,0); ke[k ][l+1] += Kbc(0,1); ke[k ][l+2] += Kbc(0,2); ke[k+1][l ] += Kbc(1,0); ke[k+1][l+1] += Kbc(1,1); ke[k+1][l+2] += Kbc(1,2); ke[k+2][l ] += Kbc(2,0); ke[k+2][l+1] += Kbc(2,1); ke[k+2][l+2] += Kbc(2,2); } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; mat3d Kbd = I*Hm[b]*Hm[d]*eps*tmp; ke[k ][l ] += Kbd(0,0); ke[k ][l+1] += Kbd(0,1); ke[k ][l+2] += Kbd(0,2); ke[k+1][l ] += Kbd(1,0); ke[k+1][l+1] += Kbd(1,1); ke[k+1][l+2] += Kbd(1,2); ke[k+2][l ] += Kbd(2,0); ke[k+2][l+1] += Kbd(2,1); ke[k+2][l+2] += Kbd(2,2); } } // --- M U L T I P H A S I C S T I F F N E S S --- if (sporo && mporo) { // need to multiply biphasic stiffness entries by the timestep double dt = fem.GetTime().timeIncrement; // --- S O L I D - P R E S S U R E / S O L U T E C O N T A C T --- for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; vec3d gac = (Ac[c]*nu)*(-Hs[a]*wn)*tmp*dt; ke[k+3][l ] += gac.x; ke[k+3][l+1] += gac.y; ke[k+3][l+2] += gac.z; for (int isol=0; isol<nsol; ++isol) { vec3d hac = (Ac[c]*nu)*(-Hs[a]*jn[isol])*tmp*dt; ke[k+4+isol][l ] += hac.x; ke[k+4+isol][l+1] += hac.y; ke[k+4+isol][l+2] += hac.z; } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; vec3d gad = vec3d(0,0,0); ke[k+3][l ] += gad.x; ke[k+3][l+1] += gad.y; ke[k+3][l+2] += gad.z; for (int isol=0; isol<nsol; ++isol) { vec3d had = vec3d(0,0,0); ke[k+4+isol][l ] += had.x; ke[k+4+isol][l+1] += had.y; ke[k+4+isol][l+2] += had.z; } } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; vec3d gbc = (Ac[c]*nu)*Hm[b]*wn*tmp*dt; ke[k+3][l ] += gbc.x; ke[k+3][l+1] += gbc.y; ke[k+3][l+2] += gbc.z; for (int isol=0; isol<nsol; ++isol) { vec3d hbc = (Ac[c]*nu)*Hm[b]*jn[isol]*tmp*dt; ke[k+4+isol][l ] += hbc.x; ke[k+4+isol][l+1] += hbc.y; ke[k+4+isol][l+2] += hbc.z; } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; vec3d gbd = vec3d(0,0,0); ke[k+3][l ] += gbd.x; ke[k+3][l+1] += gbd.y; ke[k+3][l+2] += gbd.z; for (int isol=0; isol<nsol; ++isol) { vec3d hbd = vec3d(0,0,0); ke[k+4+isol][l ] += hbd.x; ke[k+4+isol][l+1] += hbd.y; ke[k+4+isol][l+2] += hbd.z; } } } // --- P R E S S U R E - P R E S S U R E / C O N C E N T R A T I O N - C O N C E N T R A T I O N C O N T A C T --- for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; double gac = (-Hs[a]*Hs[c]*epsp)*tmp*dt; ke[k+3][l+3] += gac; for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { int z = (isol == jsol? 1.0 : 0.0); double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; double hac = (-Hs[a]*Hs[c]*epsc*z)*tmp*dt; ke[k+4+isol][l+4+jsol] += hac; } } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; double gad = (Hs[a]*Hm[d]*epsp)*tmp*dt; ke[k+3][l+3] += gad; for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { int z = (isol == jsol? 1.0 : 0.0); double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; double had = (Hs[a]*Hm[d]*epsc*z)*tmp*dt; ke[k+4+isol][l+4+jsol] += had; } } } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; double gbc = (Hm[b]*Hs[c]*epsp)*tmp*dt; ke[k+3][l+3] += gbc; for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { int z = (isol == jsol? 1.0 : 0.0); double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; double hbc = (Hm[b]*Hs[c]*epsc*z)*tmp*dt; ke[k+4+isol][l+4+jsol] += hbc; } } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; double gbd = (-Hm[b]*Hm[d]*epsp)*tmp*dt; ke[k+3][l+3] += gbd; for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { int z = (isol == jsol? 1.0 : 0.0); double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; double hbd = (-Hm[b]*Hm[d]*epsc*z)*tmp*dt; ke[k+4+isol][l+4+jsol] += hbd; } } } } } // assemble the global stiffness ke.SetNodes(en); ke.SetIndices(LM); LS.Assemble(ke); } // if slip else { // create the stiffness matrix ke.resize(ndof, ndof); ke.zero(); double tn = -pn; // obtain the slip direction s1 and inverse of spatial increment dh double dh = 0, hd = 0; vec3d dr(0,0,0); vec3d s1 = SlipTangent(ss, i, j, ms, dh, dr); if (dh != 0) hd = 1.0 / dh; // evaluate basis vectors on both surfaces vec3d gscov[2], gmcov[2]; ss.CoBaseVectors(se, j, gscov); ms.CoBaseVectors(me, r, s, gmcov); mat2d A; A[0][0] = gscov[0]*gmcov[0]; A[0][1] = gscov[0]*gmcov[1]; A[1][0] = gscov[1]*gmcov[0]; A[1][1] = gscov[1]*gmcov[1]; mat2d a = A.inverse(); // evaluate covariant basis vectors on primary surface at previous time step vec3d gscovp[2]; ss.CoBaseVectorsP(se, j, gscovp); // calculate delta gscov vec3d dgscov[2]; dgscov[0] = gscov[0] - gscovp[0]; dgscov[1] = gscov[1] - gscovp[1]; // evaluate approximate contravariant basis vectors when gap != 0 vec3d gscnt[2], gmcnt[2]; gmcnt[0] = gscov[0]*a[0][0] + gscov[1]*a[0][1]; gmcnt[1] = gscov[0]*a[1][0] + gscov[1]*a[1][1]; gscnt[0] = gmcov[0]*a[0][0] + gmcov[1]*a[1][0]; gscnt[1] = gmcov[0]*a[0][1] + gmcov[1]*a[1][1]; // evaluate N and S tensors and approximations when gap != 0 mat3ds N1 = dyad(nu); mat3d Pn = mat3dd(1) - (nu & nu); mat3d Nb1 = mat3dd(1) - (gscov[0] & gscnt[0]) - (gscov[1] & gscnt[1]); mat3d Nt1 = nu & (Nb1*nu); mat3d S1 = s1 & nu; mat3d Ps = (mat3dd(1) - (s1 & s1))*hd; mat3d St1 = s1 & (Nb1*nu); // evaluate frictional contact vectors and tensors vec3d m = ((dgscov[0] ^ gscov[1]) + (gscov[0] ^ dgscov[1])); vec3d c1 = Pn*m*(1/detJ[j]); mat3d Q1 = (mat3dd(1)*(nu * m) + (nu & m))*(1/detJ[j]); mat3d B = ((Ps*c1) & (Nb1*nu)) - Ps*Pn; mat3d R = (mat3dd(1)*(nu * dr) + (nu & dr))/(-g); mat3d L1 = Ps*(Pn*Q1 + R - mat3dd(1))*Pn*(-g); // evaluate Ac, Mc, and combine into As double* Gr = se.Gr(j); double* Gs = se.Gs(j); mat3d gscovh[2]; mat3d dgscovh[2]; gscovh[0].skew(gscov[0]); gscovh[1].skew(gscov[1]); dgscovh[0].skew(dgscov[0]); dgscovh[1].skew(dgscov[1]); mat3d Ac[MN]; mat3d As[MN]; mat3d Pc[MN]; for (int c=0; c<nseln; ++c){ vec3d mc = gscnt[0]*Gr[c] + gscnt[1]*Gs[c]; mat3d Mc = nu & mc; Ac[c] = (gscovh[1]*Gr[c] - gscovh[0]*Gs[c])/detJ[j]; mat3d Acb = (dgscovh[1]*Gr[c] - dgscovh[0]*Gs[c])/detJ[j]; vec3d hcp = (N1*mc + Ac[c]*nu); vec3d hcmb = (N1*mc*m_mu - Ac[c]*nu*pt.m_mueff); As[c] = Ac[c]+Mc*N1; mat3d Jc = (L1*Ac[c]) - Ps*Pn*Acb*(-g); Pc[c] = (s1 & hcmb) + ((Ps*c1) & hcp)*pt.m_mueff*(-g) - Jc*pt.m_mueff; } // evaluate mb and Mb double Hmr[MN], Hms[MN]; me.shape_deriv(Hmr, Hms, r, s); vec3d mb[MN]; mat3d Pb[MN]; for (k=0; k<nmeln; ++k) { mb[k] = gmcnt[0]*Hmr[k] + gmcnt[1]*Hms[k]; Pb[k] = ((-nu) & mb[k]) - (s1 & mb[k])*pt.m_mueff; } // evaluate Gbc matrix Gbc(nmeln,nseln); for (int b=0; b<nmeln; ++b) { for (int c=0; c<nseln; ++c) { Gbc(b,c) = (a[0][0]*Hmr[b]*Gr[c] + a[0][1]*Hmr[b]*Gs[c] + a[1][0]*Hms[b]*Gr[c] + a[1][1]*Hms[b]*Gs[c])*(-g); } } // define Tt, T mat3d Tt = Nt1 + St1*m_mu; mat3d T = N1 + S1*pt.m_mueff; // --- S O L I D - S O L I D C O N T A C T --- // All Kmn terms have the opposite sign from Brandon's notes // Does FEBio put the negative sign in the stiffness matrix? K*u = f => f - K*u = 0? double tmp = detJ[j]*w[j]; for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; mat3d Kac = ((Tt*eps+B*tn*pt.m_mueff)*Hs[a]*Hs[c]+(As[c]+Pc[c])*Hs[a]*tn)*tmp; ke[k ][l ] += Kac(0,0); ke[k ][l+1] += Kac(0,1); ke[k ][l+2] += Kac(0,2); ke[k+1][l ] += Kac(1,0); ke[k+1][l+1] += Kac(1,1); ke[k+1][l+2] += Kac(1,2); ke[k+2][l ] += Kac(2,0); ke[k+2][l+1] += Kac(2,1); ke[k+2][l+2] += Kac(2,2); } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; mat3d Kad = (Tt*eps+B*tn*pt.m_mueff)*(-Hs[a]*Hm[d]*tmp); ke[k ][l ] += Kad(0,0); ke[k ][l+1] += Kad(0,1); ke[k ][l+2] += Kad(0,2); ke[k+1][l ] += Kad(1,0); ke[k+1][l+1] += Kad(1,1); ke[k+1][l+2] += Kad(1,2); ke[k+2][l ] += Kad(2,0); ke[k+2][l+1] += Kad(2,1); ke[k+2][l+2] += Kad(2,2); } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; mat3d Kbc = ((Tt*eps+B*tn*pt.m_mueff)*(-Hm[b]*Hs[c])-(As[c]+Pc[c])*(Hm[b]*tn)-Pb[b]*(Hs[c]*tn)-T*(Gbc[b][c]*tn))*tmp; ke[k ][l ] += Kbc(0,0); ke[k ][l+1] += Kbc(0,1); ke[k ][l+2] += Kbc(0,2); ke[k+1][l ] += Kbc(1,0); ke[k+1][l+1] += Kbc(1,1); ke[k+1][l+2] += Kbc(1,2); ke[k+2][l ] += Kbc(2,0); ke[k+2][l+1] += Kbc(2,1); ke[k+2][l+2] += Kbc(2,2); } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; mat3d Kbd = ((Tt*eps+B*tn*pt.m_mueff)*Hm[b]*Hm[d]+Pb[b]*Hm[d]*tn)*tmp; ke[k ][l ] += Kbd(0,0); ke[k ][l+1] += Kbd(0,1); ke[k ][l+2] += Kbd(0,2); ke[k+1][l ] += Kbd(1,0); ke[k+1][l+1] += Kbd(1,1); ke[k+1][l+2] += Kbd(1,2); ke[k+2][l ] += Kbd(2,0); ke[k+2][l+1] += Kbd(2,1); ke[k+2][l+2] += Kbd(2,2); } } // --- M U L T I P H A S I C S T I F F N E S S --- if (sporo && mporo) { double dt = fem.GetTime().timeIncrement; double epsp = m_epsp*pt.m_epsp*psf; // p vector (gradients of effective solute concentrations on master surface) double dpmr = me.eval_deriv1(pm, r, s); double dpms = me.eval_deriv2(pm, r, s); vec3d p = gmcnt[0]*dpmr + gmcnt[1]*dpms; // evaluate Pc double Pc[MN]; for (int k=0; k<nseln; ++k) { Pc[k] = (a[0][0]*dpmr*Gr[k] + a[0][1]*dpmr*Gs[k] + a[1][0]*dpms*Gr[k] + a[1][1]*dpms*Gs[k])*(-g); } // q vectors (gradients of effective solute concentrations on master surface) // Cc scalars vector<vec3d> q(nsol); vector< vector<double> > Cc(nsol, vector<double>(MN)); for (int isol=0; isol<nsol; ++isol) { double dcmr = me.eval_deriv1(&cm[isol][0], r, s); double dcms = me.eval_deriv2(&cm[isol][0], r, s); q[isol] = gmcnt[0]*dcmr + gmcnt[1]*dcms; for (int k=0; k<nseln; ++k) { Cc[isol][k] = (a[0][0]*dcmr*Gr[k] + a[0][1]*dcmr*Gs[k] + a[1][0]*dcms*Gr[k] + a[1][1]*dcms*Gs[k])*(-g); } } // --- S O L I D - P R E S S U R E / S O L U T E C O N T A C T --- for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; vec3d gac = (p*Hs[a]*Hs[c]*epsp-((Ac[c]*nu)*wn+nu*epsp*Pc[c])*Hs[a])*tmp*dt; ke[k+3][l ] += gac.x; ke[k+3][l+1] += gac.y; ke[k+3][l+2] += gac.z; vec3d kac = (s1*m_mu*(1.0-m_phi))*(-Hs[a]*Hs[c])*tmp*dt; ke[k ][l+3] += kac.x; ke[k+1][l+3] += kac.y; ke[k+2][l+3] += kac.z; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; vec3d hac = (q[isol]*Hs[a]*Hs[c]*epsc-((Ac[c]*nu)*jn[isol]+nu*Cc[isol][c]*epsc)*Hs[a])*tmp*dt; ke[k+4+isol][l ] += hac.x; ke[k+4+isol][l+1] += hac.y; ke[k+4+isol][l+2] += hac.z; } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; vec3d gad = p*(-Hs[a]*Hm[d]*epsp)*tmp*dt; ke[k+3][l ] += gad.x; ke[k+3][l+1] += gad.y; ke[k+3][l+2] += gad.z; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; vec3d had = q[isol]*(-Hs[a]*Hm[d]*epsc)*tmp*dt; ke[k+4+isol][l ] += had.x; ke[k+4+isol][l+1] += had.y; ke[k+4+isol][l+2] += had.z; } } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; vec3d gbc = (p*(-Hm[b]*Hs[c]*epsp)+((Ac[c]*nu)*wn + nu*Pc[c]*epsp)*Hm[b] + (mb[b]*wn*Hs[c]) - nu*Gbc[b][c]*wn)*tmp*dt; ke[k+3][l ] += gbc.x; ke[k+3][l+1] += gbc.y; ke[k+3][l+2] += gbc.z; vec3d kbc = (s1*m_mu*(1.0-m_phi))*(Hm[b]*Hs[c])*tmp*dt; ke[k ][l+3] += kbc.x; ke[k+1][l+3] += kbc.y; ke[k+2][l+3] += kbc.z; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; vec3d hbc = (q[isol]*(-Hm[b]*Hs[c]*epsc)+((Ac[c]*nu)*jn[isol]+nu*epsc*Cc[isol][c])*Hm[b]+(mb[b]*jn[isol]*Hs[c])-(nu*Gbc[b][c]*jn[isol]))*tmp*dt; ke[k+4+isol][l ] += hbc.x; ke[k+4+isol][l+1] += hbc.y; ke[k+4+isol][l+2] += hbc.z; } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; vec3d gbd = (p*(Hm[b]*Hm[d]*epsp)-(mb[b]*wn*Hm[d]))*tmp*dt; ke[k+3][l ] += gbd.x; ke[k+3][l+1] += gbd.y; ke[k+3][l+2] += gbd.z; for (int isol=0; isol<nsol; ++isol) { double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; vec3d hbd = (q[isol]*(Hm[b]*Hm[d]*epsc)-(mb[b]*jn[isol]*Hm[d]))*tmp*dt; ke[k+4+isol][l ] += hbd.x; ke[k+4+isol][l+1] += hbd.y; ke[k+4+isol][l+2] += hbd.z; } } } // --- P R E S S U R E - P R E S S U R E / C O N C E N T R A T I O N - C O N C E N T R A T I O N C O N T A C T --- for (int a=0; a<nseln; ++a) { k = a*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; double gac = (-Hs[a]*Hs[c]*epsp)*tmp*dt; ke[k+3][l+3] += gac; for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { int z = (isol == jsol? 1.0 : 0.0); double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; double hac = (-Hs[a]*Hs[c]*epsc*z)*(dt*detJ[j]*w[j]); ke[k+4+isol][l+4+jsol] += hac; } } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; double gad = (Hs[a]*Hm[d]*epsp)*(dt*detJ[j]*w[j]); ke[k+3][l+3] += gad; for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { int z = (isol == jsol? 1.0 : 0.0); double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; double had = (Hs[a]*Hm[d]*epsc*z)*(dt*detJ[j]*w[j]); ke[k+4+isol][l+4+jsol] += had; } } } } for (int b=0; b<nmeln; ++b) { k = (nseln+b)*ndpn; for (int c=0; c<nseln; ++c) { l = c*ndpn; double gbc = (Hm[b]*Hs[c]*epsp)*(dt*detJ[j]*w[j]); ke[k+3][l+3] += gbc; for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { int z = (isol == jsol? 1.0 : 0.0); double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; double hbc = (Hm[b]*Hs[c]*epsc*z)*(dt*detJ[j]*w[j]); ke[k+4+isol][l+4+jsol] += hbc; } } } for (int d=0; d<nmeln; ++d) { l = (nseln+d)*ndpn; double gbd = (-Hm[b]*Hm[d]*epsp)*(dt*detJ[j]*w[j]); ke[k+3][l+3] += gbd; for (int isol=0; isol<nsol; ++isol) { for (int jsol=0; jsol<nsol; ++jsol) { int z = (isol == jsol? 1.0 : 0.0); double epsc = m_epsc*pt.m_epsc[sl[isol]]*psf; double hbd = (-Hm[b]*Hm[d]*epsc*z)*(dt*detJ[j]*w[j]); ke[k+4+isol][l+4+jsol] += hbd; } } } } } // assemble the global stiffness ke.SetNodes(en); ke.SetIndices(LM); LS.Assemble(ke); } } } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::UpdateContactPressures() { int np, n, i, j; const int MN = FEElement::MAX_NODES; const int MI = FEElement::MAX_INTPOINTS; double psf = GetPenaltyScaleFactor(); int npass = (m_btwo_pass?2:1); for (np=0; np<npass; ++np) { FESlidingSurfaceMP& ss = (np == 0? m_ss : m_ms); FESlidingSurfaceMP& ms = (np == 0? m_ms : m_ss); // loop over all elements of the primary surface for (n=0; n<ss.Elements(); ++n) { FESurfaceElement& el = ss.Element(n); int nint = el.GaussPoints(); // get the normal tractions at the integration points for (i=0; i<nint; ++i) { // get integration point data FEMultiphasicContactPoint& sd = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(i)); // evaluate traction on primary surface double eps = m_epsn*sd.m_epsn*psf; if (sd.m_bstick) { // if stick, evaluate total traction sd.m_tr = sd.m_Lmt + sd.m_dg*eps; // then derive normal component sd.m_Ln = -sd.m_tr*sd.m_nu; } else { // if slip, evaluate normal traction double Ln = sd.m_Lmd + eps*sd.m_gap; sd.m_Ln = MBRACKET(Ln); // then derive total traction sd.m_tr = -(sd.m_nu*sd.m_Ln + sd.m_s1*sd.m_Ln*sd.m_mueff); } FESurfaceElement* pme = sd.m_pme; if (m_btwo_pass && pme) { int mint = pme->GaussPoints(); vec3d ti[MI]; double pi[MI]; for (j=0; j<mint; ++j) { FEMultiphasicContactPoint& md = static_cast<FEMultiphasicContactPoint&>(*pme->GetMaterialPoint(j)); // evaluate traction on secondary surface double eps = m_epsn*md.m_epsn*psf; if (md.m_bstick) { // if stick, evaluate total traction ti[j] = md.m_Lmt + md.m_dg*eps; // then derive normal component pi[j] = -ti[j]*md.m_nu; } else { // if slip, evaluate normal traction double Ln = md.m_Lmd + eps*md.m_gap; pi[j] = MBRACKET(Ln); // then derive total traction ti[j] = -(md.m_nu + md.m_s1*md.m_mueff)*pi[j]; } } // project the data to the nodes vec3d tn[MN]; double pn[MN]; pme->FEElement::project_to_nodes(pi, pn); pme->project_to_nodes(ti, tn); // now evaluate the traction at the intersection point double Ln = pme->eval(pn, sd.m_rs[0], sd.m_rs[1]); vec3d trac = pme->eval(tn, sd.m_rs[0], sd.m_rs[1]); sd.m_Ln += MBRACKET(Ln); // tractions on secondary-primary are opposite, so subtract sd.m_tr -= trac; } } } ss.EvaluateNodalContactPressures(); ss.EvaluateNodalContactTractions(); } } //----------------------------------------------------------------------------- bool FESlidingInterfaceMP::Augment(int naug, const FETimeInfo& tp) { // make sure we need to augment if (m_laugon != FECore::AUGLAG_METHOD) return true; double Ln, Lp; int nsol = (int)m_sid.size(); vector<double>Lc(nsol); bool bconv = true; double psf = GetPenaltyScaleFactor(); bool bporo = (m_ss.m_bporo && m_ms.m_bporo); bool bsolu = (m_ss.m_bsolu && m_ms.m_bsolu); int NS = m_ss.Elements(); int NM = m_ms.Elements(); // --- 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, normP = 0, normDP = 0, normC = 0; vector<double>normDC(nsol,0); for (int i=0; i<NS; ++i) { FESurfaceElement& el = m_ss.Element(i); for (int j=0; j<el.GaussPoints(); ++j) { FEMultiphasicContactPoint& ds = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); if (ds.m_bstick) normL0 += ds.m_Lmt*ds.m_Lmt; else normL0 += ds.m_Lmd*ds.m_Lmd; } } for (int i=0; i<NM; ++i) { FESurfaceElement& el = m_ms.Element(i); for (int j=0; j<el.GaussPoints(); ++j) { FEMultiphasicContactPoint& dm = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); if (dm.m_bstick) normL0 += dm.m_Lmt*dm.m_Lmt; else normL0 += dm.m_Lmd*dm.m_Lmd; } } // b. gap component // (is calculated during update) double maxgap = 0, maxpg = 0; vector<double> maxcg(nsol,0); // update Lagrange multipliers double normL1 = 0, eps, epsp, epsc; for (int i=0; i<m_ss.Elements(); ++i) { FESurfaceElement& el = m_ss.Element(i); vec3d tn[FEElement::MAX_INTPOINTS]; if (m_bsmaug) m_ss.GetGPSurfaceTraction(i, tn); for (int j=0; j<el.GaussPoints(); ++j) { FEMultiphasicContactPoint& ds = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); // update Lagrange multipliers on primary surface eps = m_epsn*ds.m_epsn*psf; if (ds.m_bstick) { // if stick, augment total traction if (m_bsmaug) { // replace this multiplier with a smoother version ds.m_Lmt = tn[j]; if (m_btwo_pass) ds.m_Lmt /= 2; } else { ds.m_Lmt += ds.m_dg*eps; } // then derive normal component ds.m_Lmd = -ds.m_Lmt*ds.m_nu; Ln = ds.m_Lmd; normL1 += ds.m_Lmt*ds.m_Lmt; if (Ln > 0) maxgap = max(maxgap, fabs(ds.m_dg.norm())); } else { // if slip, augment normal traction if (m_bsmaug) { // replace this multiplier with a smoother version Ln = -(tn[j]*ds.m_nu); ds.m_Lmd = MBRACKET(Ln); if (m_btwo_pass) ds.m_Lmd /= 2; } else { Ln = ds.m_Lmd + eps*ds.m_gap; ds.m_Lmd = MBRACKET(Ln); } // then derive total traction double mueff = m_mu*(1.0-(1.0-m_phi)*(ds.m_p1-m_ambp)/ds.m_Lmd); mueff = MBRACKET(mueff); ds.m_Lmt = -(ds.m_nu*ds.m_Lmd + ds.m_s1*ds.m_Lmd*mueff); normL1 += ds.m_Lmd*ds.m_Lmd; if (Ln > 0) maxgap = max(maxgap, fabs(ds.m_gap)); } if (m_ss.m_bporo) { Lp = 0; Lc.assign(nsol, 0); if (Ln > 0) { epsp = m_epsp*ds.m_epsp*psf; Lp = ds.m_Lmp + epsp*ds.m_pg; maxpg = max(maxpg,fabs(ds.m_pg)); normDP += ds.m_pg*ds.m_pg; for (int isol=0; isol<nsol; ++isol) { int l = m_ssl[isol]; epsc = m_epsc*ds.m_epsc[l]*psf; Lc[isol] = ds.m_Lmc[l] + epsc*ds.m_cg[l]; maxcg[isol] = max(maxcg[isol],fabs(ds.m_cg[l])); normDC[isol] += ds.m_cg[l]*ds.m_cg[l]; } } ds.m_Lmp = Lp; for (int isol=0; isol<nsol; ++isol) ds.m_Lmc[m_ssl[isol]] = Lc[isol]; } } } for (int i=0; i<m_ms.Elements(); ++i) { FESurfaceElement& el = m_ms.Element(i); vec3d tn[FEElement::MAX_INTPOINTS]; if (m_bsmaug) m_ms.GetGPSurfaceTraction(i, tn); for (int j=0; j<el.GaussPoints(); ++j) { FEMultiphasicContactPoint& dm = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); // update Lagrange multipliers on master surface double eps = m_epsn*dm.m_epsn*psf; if (dm.m_bstick) { // if stick, augment total traction if (m_bsmaug) { // replace this multiplier with a smoother version dm.m_Lmt = tn[j]; if (m_btwo_pass) dm.m_Lmt /= 2; } else { dm.m_Lmt += dm.m_dg*eps; } // then derive normal component dm.m_Lmd = -dm.m_Lmt*dm.m_nu; Ln = dm.m_Lmd; normL1 += dm.m_Lmt*dm.m_Lmt; if (Ln > 0) maxgap = max(maxgap, fabs(dm.m_dg.norm())); } else { // if slip, augment normal traction if (m_bsmaug) { // replace this multiplier with a smoother version Ln = -(tn[j]*dm.m_nu); dm.m_Lmd = MBRACKET(Ln); if (m_btwo_pass) dm.m_Lmd /= 2; } else { Ln = dm.m_Lmd + eps*dm.m_gap; dm.m_Lmd = MBRACKET(Ln); } // then derive total traction double mueff = m_mu*(1.0-(1.0-m_phi)*(dm.m_p1-m_ambp)/dm.m_Lmd); mueff = MBRACKET(mueff); dm.m_Lmt = -(dm.m_nu*dm.m_Lmd + dm.m_s1*dm.m_Lmd*mueff); normL1 += dm.m_Lmd*dm.m_Lmd; if (Ln > 0) maxgap = max(maxgap, fabs(dm.m_gap)); } if (m_ms.m_bporo) { Lp = 0; Lc.assign(nsol, 0); if (Ln > 0) { epsp = m_epsp*dm.m_epsp*psf; Lp = dm.m_Lmp + epsp*dm.m_pg; maxpg = max(maxpg,fabs(dm.m_pg)); normDP += dm.m_pg*dm.m_pg; for (int isol=0; isol<nsol; ++isol) { int l = m_ssl[isol]; epsc = m_epsc*dm.m_epsc[l]*psf; Lc[isol] = dm.m_Lmc[l] + epsc*dm.m_cg[l]; maxcg[isol] = max(maxcg[isol],fabs(dm.m_cg[l])); normDC[isol] += dm.m_cg[l]*dm.m_cg[l]; } } dm.m_Lmp = Lp; for (int isol=0; isol<nsol; ++isol) dm.m_Lmc[m_ssl[isol]] = Lc[isol]; } } } // normP should be a measure of the fluid pressure at the // contact interface. However, since it could be zero, // use an average measure of the contact traction instead. normP = normL1; normC = normL1/(m_Rgas*m_Tabs); // calculate relative norms double lnorm = (normL1 != 0 ? fabs((normL1 - normL0) / normL1) : fabs(normL1 - normL0)); double pnorm = (normP != 0 ? (normDP/normP) : normDP); vector<double> cnorm(nsol); for (int isol=0; isol<nsol; ++isol) cnorm[isol] = (normC != 0 ? (normDC[isol]/normC) : normDC[isol]); // check convergence if ((m_gtol > 0) && (maxgap > m_gtol)) bconv = false; if ((m_ptol > 0) && (bporo && maxpg > m_ptol)) bconv = false; for (int isol=0; isol<nsol; ++isol) if ((m_ctol > 0) && (bsolu && maxcg[isol] > m_ctol)) bconv = false; if ((m_atol > 0) && (lnorm > m_atol)) bconv = false; if ((m_atol > 0) && (pnorm > m_atol)) bconv = false; for (int isol=0; isol<nsol; ++isol) if ((m_atol > 0) && (cnorm[isol] > m_atol)) bconv = false; if (naug < m_naugmin ) bconv = false; if (naug >= m_naugmax) bconv = true; feLog(" sliding interface # %d\n", GetID()); feLog(" CURRENT REQUIRED\n"); feLog(" D multiplier : %15le", lnorm); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n"); if (bporo) { feLog(" P gap : %15le", pnorm); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n"); } for (int isol=0; isol<nsol; ++isol) { feLog(" C[%d] gap : %15le", m_sid[isol], cnorm[isol]); if (m_atol > 0) feLog("%15le\n", m_atol); else feLog(" ***\n"); } feLog(" maximum gap : %15le", maxgap); if (m_gtol > 0) feLog("%15le\n", m_gtol); else feLog(" ***\n"); if (bporo) { feLog(" maximum pgap : %15le", maxpg); if (m_ptol > 0) feLog("%15le\n", m_ptol); else feLog(" ***\n"); } for (int isol=0; isol<nsol; ++isol) { feLog(" maximum cgap[%d] : %15le", m_sid[isol], maxcg[isol]); if (m_ctol > 0) feLog("%15le\n", m_ctol); else feLog(" ***\n"); } ProjectSurface(m_ss, m_ms, true); if (m_btwo_pass) ProjectSurface(m_ms, m_ss, true); m_bfreeze = true; return bconv; } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::Serialize(DumpStream &ar) { // serialize contact data FEContactInterface::Serialize(ar); // serialize contact surface data m_ms.Serialize(ar); m_ss.Serialize(ar); ar & m_ambp; ar & m_ambc; ar & m_sid; ar & m_ssl; ar & m_msl; ar & m_sz; // serialize element pointers SerializeElementPointers(m_ss, m_ms, ar); SerializeElementPointers(m_ms, m_ss, ar); } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::MarkAmbient() { int i, j, id, np; // get number of DOFS DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); // Mark all nodes as free-draining. This needs to be done for ALL // contact interfaces prior to executing Update(), where nodes that are // in contact are subsequently marked as non free-draining. This ensures // that for surfaces involved in more than one contact interface, nodes // that have been marked as non free-draining are not reset to // free-draining. for (np=0; np<2; ++np) { FESlidingSurfaceMP& s = (np == 0? m_ss : m_ms); if (s.m_bporo) { // first, mark all nodes as free-draining (= neg. ID) // this is done by setting the dof's equation number // to a negative number for (i=0; i<s.Nodes(); ++i) { id = s.Node(i).m_ID[m_dofP]; if (id >= 0) { FENode& node = s.Node(i); // mark node as free-draining node.m_ID[m_dofP] = -id-2; } } } if (s.m_bsolu) { // first, mark all nodes as free-draining (= neg. ID) // this is done by setting the dof's equation number // to a negative number for (i=0; i<s.Nodes(); ++i) { for (j=0; j<MAX_CDOFS; ++j) { id = s.Node(i).m_ID[m_dofC+j]; if (id >= 0) { FENode& node = s.Node(i); // mark node as free-draining node.m_ID[m_dofC+j] = -id-2; } } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceMP::SetAmbient() { int i, j, np; // get number of DOFS DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); // Set the pressure to zero for the free-draining nodes for (np=0; np<2; ++np) { FESlidingSurfaceMP& s = (np == 0? m_ss : m_ms); if (s.m_bporo) { // loop over all nodes for (i=0; i<s.Nodes(); ++i) { if (s.Node(i).m_ID[m_dofP] < -1) { FENode& node = s.Node(i); // set the fluid pressure to ambient condition node.set(m_dofP, m_ambp); } } } if (s.m_bsolu) { // loop over all nodes for (i=0; i<s.Nodes(); ++i) { for (j=0; j<MAX_CDOFS; ++j) { if (s.Node(i).m_ID[m_dofC+j] < -1) { FENode& node = s.Node(i); // set the fluid pressure to ambient condition node.set(m_dofC + j, m_ambc[j]); } } } } } } //----------------------------------------------------------------------------- FESoluteData* FESlidingInterfaceMP::FindSoluteData(int nid) { FEModel& fem = *GetFEModel(); int N = GetFEModel()->GlobalDataItems(); for (int i=0; i<N; ++i) { FESoluteData* psd = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (psd && (psd->GetID() == nid)) return psd; } return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESoluteInterface.h
.h
7,324
184
/*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/fecore_api.h> #include "febiomix_api.h" #include <FECore/vec3d.h> class FESolute; class FESolidBoundMolecule; class FEOsmoticCoefficient; class FEMaterialPoint; //------------------------------------------------------------------------ // This class should be used by all materials that support solutes // TODO: This is a work in progress. The goal is to reduce the dynamic_casts to materials // that support solutes, and instead provide a single consistent interface to features // that need access to solute data (e.g. plot variables). class FEBIOMIX_API FESoluteInterface { public: FESoluteInterface(){} virtual ~FESoluteInterface(){} // derived classes need to implement the following functions public: // return the number of solutes in the material virtual int Solutes() = 0; // return a solute material virtual FESolute* GetSolute(int i) = 0; //! return the effective solute concentration virtual double GetEffectiveSoluteConcentration(FEMaterialPoint& mp, int soluteIndex) { return 0.0; } // return the actual solution concentration at this material point virtual double GetActualSoluteConcentration(FEMaterialPoint& mp, int soluteIndex) { return 0.0; } // return the partition coefficient at this material point virtual double GetFreeDiffusivity(FEMaterialPoint& mp, int soluteIndex) { return 0.0; } // return the partition coefficient at this material point virtual double GetPartitionCoefficient(FEMaterialPoint& mp, int soluteIndex) { return 0.0; } // return the solute flux at this material point virtual vec3d GetSoluteFlux(FEMaterialPoint& mp, int soluteIndex) { return vec3d(0,0,0); } // get the osmotic coefficient virtual FEOsmoticCoefficient* GetOsmoticCoefficient() { return nullptr; } // get the osmolarity virtual double GetOsmolarity(const FEMaterialPoint& mp) { return 0.0; } // get the electric potential virtual double GetElectricPotential(const FEMaterialPoint& mp) { return 0.0; } // get the current density virtual vec3d GetCurrentDensity(const FEMaterialPoint& mp) { return vec3d(0,0,0); } // get the fixed charge density virtual double GetFixedChargeDensity(const FEMaterialPoint& mp) { return 0.0; } // get the referential fixed charge density virtual double GetReferentialFixedChargeDensity(const FEMaterialPoint& mp) { return 0.0; } // get first derivative of k (partition coefficient) w.r.p. concentration virtual double dkdc(const FEMaterialPoint& mp, int i, int j) { return 0.0; } // get first derivative of k (partition coefficient) w.r.p. J virtual double dkdJ(const FEMaterialPoint& mp, int soluteIndex) { return 0.0; } // return the number of solid-bound molecules virtual int SBMs() const { return 0; } // return the solid-bound modlecule virtual FESolidBoundMolecule* GetSBM(int i) { return nullptr; } //! SBM actual concentration (molar concentration in current configuration) virtual double SBMConcentration(FEMaterialPoint& pt, const int sbm) { return 0.0; } //! SBM areal concentration (mole per shell area) -- should only be called from shell domains virtual double SBMArealConcentration(FEMaterialPoint& pt, const int sbm) { return 0.0; } // return the number of solutes on external side virtual int SolutesExternal(FEMaterialPoint& pt) { return 0; } // return the number of solutes on internal side virtual int SolutesInternal(FEMaterialPoint& pt) { return 0; } //! return the solute ID on external side virtual int GetSoluteIDExternal(FEMaterialPoint& mp, int soluteIndex) { return -1; } //! return the solute ID on internal side virtual int GetSoluteIDInternal(FEMaterialPoint& mp, int soluteIndex) { return -1; } //! return the effective solute concentration on external side virtual double GetEffectiveSoluteConcentrationExternal(FEMaterialPoint& mp, int soluteIndex) { return 0.0; } //! return the effective solute concentration on internal side virtual double GetEffectiveSoluteConcentrationInternal(FEMaterialPoint& mp, int soluteIndex) { return 0.0; } //! return the effective pressure on external side virtual double GetEffectiveFluidPressureExternal(FEMaterialPoint& mp) { return 0.0; } //! return the effective pressure on internal side virtual double GetEffectiveFluidPressureInternal(FEMaterialPoint& mp) { return 0.0; } //! return the membrane areal strain virtual double GetMembraneArealStrain(FEMaterialPoint& mp) { return 0.0; } // additional member functions public: // return the local index of a global solute ID (or -1, if the solute is not in this material) int FindLocalSoluteID(int soluteID); }; template <typename T> class FESoluteInterface_T : public FESoluteInterface { public: double GetEffectiveSoluteConcentration(FEMaterialPoint& mp, int soluteIndex) override { T* spt = mp.ExtractData<T>(); return spt->m_c[soluteIndex]; }; double GetActualSoluteConcentration(FEMaterialPoint& mp, int soluteIndex) override { T* spt = mp.ExtractData<T>(); return spt->m_ca[soluteIndex]; }; double GetPartitionCoefficient(FEMaterialPoint& mp, int soluteIndex) override { T* spt = mp.ExtractData<T>(); return spt->m_k[soluteIndex]; } vec3d GetSoluteFlux(FEMaterialPoint& mp, int soluteIndex) override { T* spt = mp.ExtractData<T>(); return spt->m_j[soluteIndex]; }; double GetOsmolarity(const FEMaterialPoint& mp) override { const T* spt = mp.ExtractData<T>(); return spt->Osmolarity(); } double GetElectricPotential(const FEMaterialPoint& mp) override { const T* spt = mp.ExtractData<T>(); return spt->m_psi; } vec3d GetCurrentDensity(const FEMaterialPoint& mp) override { const T* spt = mp.ExtractData<T>(); return spt->m_Ie; } double dkdc(const FEMaterialPoint& mp, int i, int j) override { const T* spt = mp.ExtractData<T>(); return spt->m_dkdc[i][j]; } double dkdJ(const FEMaterialPoint& mp, int soluteIndex) override { const T* spt = mp.ExtractData<T>(); return spt->m_dkdJ[soluteIndex]; } };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPermExpIso.h
.h
2,137
56
/*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 "FEHydraulicPermeability.h" //----------------------------------------------------------------------------- // This class implements a poroelastic material that has a strain-dependent // permeability which varies exponentially as a function of the // volume ratio J, producing zero permeability in the limit as J->phi0. class FEBIOMIX_API FEPermExpIso : public FEHydraulicPermeability { public: //! constructor FEPermExpIso(FEModel* pfem); //! permeability mat3ds Permeability(FEMaterialPoint& pt) override; //! Tangent of permeability tens4dmm Tangent_Permeability_Strain(FEMaterialPoint& mp) override; public: double m_perm; //!< permeability double m_M; //!< exponential coefficient // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMembraneReactionRateVoltageGated.cpp
.cpp
4,732
134
/*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 "FEMembraneReactionRateVoltageGated.h" #include "FESoluteInterface.h" #include "FESolutesMaterialPoint.h" #include "FESolute.h" #include <FECore/FEModel.h> #include <FECore/log.h> // Material parameters for the FEMembraneReactionRateVoltageGated material BEGIN_FECORE_CLASS(FEMembraneReactionRateVoltageGated, FEMembraneReactionRate) ADD_PARAMETER(m_a, FE_RANGE_GREATER_OR_EQUAL(0.0), "a"); ADD_PARAMETER(m_b, FE_RANGE_GREATER_OR_EQUAL(0.0), "b"); ADD_PARAMETER(m_c, FE_RANGE_GREATER_OR_EQUAL(0.0), "c"); ADD_PARAMETER(m_d, FE_RANGE_GREATER_OR_EQUAL(0.0), "d"); ADD_PARAMETER(m_sol, "sol"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMembraneReactionRateVoltageGated::FEMembraneReactionRateVoltageGated(FEModel* pfem) : FEMembraneReactionRate(pfem) { m_a = m_b = m_c = m_d = 0; m_sol = m_lid = -1; m_z = 0; } //----------------------------------------------------------------------------- bool FEMembraneReactionRateVoltageGated::Init() { if (FEMembraneReactionRate::Init() == false) return false; // do only once if (m_lid == -1) { // get number of DOFS DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); // check validity of sol if (m_sol < 1 || m_sol > MAX_CDOFS) { feLogError("sol value outside of valid range for solutes"); return false; } FEModel& fem = *GetFEModel(); int N = GetFEModel()->GlobalDataItems(); for (int i=0; i<N; ++i) { FESoluteData* psd = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (psd && (psd->GetID() == m_sol)) { m_lid = m_sol - 1; m_z = psd->m_z; break; } } } return true; } //----------------------------------------------------------------------------- double FEMembraneReactionRateVoltageGated::ReactionRate(FEMaterialPoint& pt) { FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); double ci = ps.m_ci[m_lid]; double ce = ps.m_ce[m_lid]; if (ce == 0) return 0; double x = ci/ce; double k = (m_c*log(x) + m_d)/(m_a + pow(x,m_b)); return k; } //----------------------------------------------------------------------------- double FEMembraneReactionRateVoltageGated::Tangent_ReactionRate_Ci(FEMaterialPoint& pt, const int isol) { if (isol != m_lid) return 0; FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); double ci = ps.m_ci[m_lid]; double ce = ps.m_ce[m_lid]; if ((ce == 0) || (ci == 0)) return 0; double x = ci/ce; double xb = pow(x,m_b); double dkdc = (m_a*m_c + xb*(m_c-m_b*m_d) - m_b*m_c*log(x))/pow(m_a+xb,2)/ci; return dkdc; } //----------------------------------------------------------------------------- double FEMembraneReactionRateVoltageGated::Tangent_ReactionRate_Ce(FEMaterialPoint& pt, const int isol) { if (isol != m_lid) return 0; FESolutesMaterialPoint& ps = *(pt.ExtractData<FESolutesMaterialPoint>()); double ci = ps.m_ci[m_lid]; double ce = ps.m_ce[m_lid]; if (ce == 0) return 0; double x = ci/ce; double xb = pow(x,m_b); double dkdc = -(m_a*m_c + xb*(m_c-m_b*m_d) - m_b*m_c*log(x))/pow(m_a+xb,2)/ce; return dkdc; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMatchingOsmoticCoefficientLoad.h
.h
2,438
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/FESurfaceLoad.h> #include "FEMultiphasic.h" //----------------------------------------------------------------------------- //! FEMatchingOsmoticCoefficientBC is a surface boundary condition that imposes the same osmotic //! coefficient in the bath as in the multiphasic material bounded by tha surface class FEBIOMIX_API FEMatchingOsmoticCoefficientLoad : public FESurfaceLoad { public: //! constructor FEMatchingOsmoticCoefficientLoad(FEModel* pfem); //! calculate traction stiffness (there is none) void StiffnessMatrix(FELinearSystem& LS) override {} //! calculate load vector void LoadVector(FEGlobalVector& R) override {} //! set the dilatation void Update() override; //! initialize bool Init() override; //! activate void Activate() override; //! serialization void Serialize(DumpStream& ar) override; private: double m_ambc; //!<ambient osmolarity double m_ambp; //!< ambient fluid pressure bool m_bshellb; //!< shell bottom flag private: int m_dofP, m_dofQ; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEFiberPowLinearSBM.h
.h
3,549
94
/*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 <FEBioMech/FEElasticMaterial.h> #include <FEBioMech/FERemodelingElasticMaterial.h> #include <FECore/FEModelParam.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Material class for single fiber, tension only //! Power law - linear //! Fiber modulus depends on SBM content class FEBIOMIX_API FEFiberPowLinearSBM : public FEElasticMaterial, public FERemodelingInterface { public: FEFiberPowLinearSBM(FEModel* pfem) : FEElasticMaterial(pfem) { m_sbm = -1; m_fiber = nullptr; } //! Initialization bool Init() override; //! Cauchy stress mat3ds Stress(FEMaterialPoint& mp) override; // Spatial tangent tens4ds Tangent(FEMaterialPoint& mp) override; //! Strain energy density double StrainEnergyDensity(FEMaterialPoint& mp) override; //! evaluate referential mass density double Density(FEMaterialPoint& pt) override; //! return fiber modulus double FiberModulus(FEMaterialPoint& pt, double rhor) { return m_E0(pt)*pow(rhor/m_rho0(pt), m_g(pt));} //! Create material point data FEMaterialPointData* CreateMaterialPointData() override; //! update specialize material point data void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) override; public: // --- remodeling interface --- //! calculate strain energy density at material point double StrainEnergy(FEMaterialPoint& pt) override; //! calculate tangent of strain energy density with mass density double Tangent_SE_Density(FEMaterialPoint& pt) override; //! calculate tangent of stress with mass density mat3ds Tangent_Stress_Density(FEMaterialPoint& pt) override; public: FEParamDouble m_E0; // fiber modulus E = E0*(rhor/rho0)^gamma FEParamDouble m_lam0; // stretch ratio at end of toe region FEParamDouble m_beta; // power law exponent in toe region FEParamDouble m_rho0; // rho0 FEParamDouble m_g; // gamma int m_lsbm; //!< local id of solid-bound molecule public: FEVec3dValuator* m_fiber; //!< fiber orientation // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateConst.h
.h
1,988
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 "FEChemicalReaction.h" class FEBIOMIX_API FEReactionRateConst : public FEReactionRate { public: //! constructor FEReactionRateConst(FEModel* pfem) : FEReactionRate(pfem) { m_k = 0; } //! reaction rate at material point double ReactionRate(FEMaterialPoint& pt) override { return m_k(pt); } //! tangent of reaction rate with strain at material point mat3ds Tangent_ReactionRate_Strain(FEMaterialPoint& pt) override { return mat3ds(0); } //! tangent of reaction rate with effective fluid pressure at material point double Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) override {return 0; } public: FEParamDouble m_k; //!< reaction rate DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESlidingInterfaceMP.h
.h
8,880
262
/*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 "FEBioMech/FEContactInterface.h" #include "FEBiphasicContactSurface.h" #include "FESolute.h" #include <FECore/FECoreClass.h> #include <map> //----------------------------------------------------------------------------- class FEBIOMIX_API FEMultiphasicContactPoint : public FEBiphasicContactPoint { public: vector<double> m_Lmc; //!< Lagrange multipliers for solute concentrations vector<double> m_epsc; //!< concentration penalty factors vector<double> m_cg; //!< concentration "gap" vector<double> m_c1; //!< solute concentration void Init() override { FEBiphasicContactPoint::Init(); } void Serialize(DumpStream& ar) override; }; //----------------------------------------------------------------------------- class FEBIOMIX_API FESlidingSurfaceMP : public FEBiphasicContactSurface { public: //! constructor FESlidingSurfaceMP(FEModel* pfem); //! destructor ~FESlidingSurfaceMP(); //! initialization bool Init() override; //! initialize sliding surface and store previous values void InitSlidingSurface(); //! evaluate net contact force vec3d GetContactForce() override; //! evaluate net contact area double GetContactArea() override; //! evaluate net fluid force vec3d GetFluidForce() override; //! calculate the nodal normals void UpdateNodeNormals(); void Serialize(DumpStream& ar) override; void SetPoroMode(bool bporo) { m_bporo = bporo; } void UnpackLM(FEElement& el, vector<int>& lm) override; //! create material point data FEMaterialPoint* CreateMaterialPoint() override; public: void GetVectorGap (int nface, vec3d& pg) override; void GetContactTraction (int nface, vec3d& pt) override; void GetSlipTangent (int nface, vec3d& pt); void GetMuEffective (int nface, double& pg) override; void GetLocalFLS (int nface, double& pg) override; void GetNodalVectorGap (int nface, vec3d* pg) override; void GetNodalContactPressure(int nface, double* pg) override; void GetNodalContactTraction(int nface, vec3d* tn) override; void GetStickStatus (int nface, double& pg) override; void EvaluateNodalContactPressures(); void EvaluateNodalContactTractions(); private: void GetContactPressure(int nface, double& pg); public: bool m_bporo; //!< set poro-mode bool m_bsolu; //!< set solute-mode vector<vec3d> m_nn; //!< node normals vector<double> m_pn; //!< nodal contact pressures vector<vec3d> m_tn; //!< nodal contact tractions vector<int> m_sid; //!< list of solute id's for this surface vec3d m_Ft; //!< total contact force (from equivalent nodal forces) protected: int m_dofC; }; //----------------------------------------------------------------------------- // helper class for reading ambient concentrations class FEAmbientConcentration : public FECoreClass { public: FEAmbientConcentration(FEModel* fem); public: int m_sol; double m_ambc; DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEAmbientConcentration); }; //----------------------------------------------------------------------------- class FEBIOMIX_API FESlidingInterfaceMP : public FEContactInterface { public: //! constructor FESlidingInterfaceMP(FEModel* pfem); //! destructor ~FESlidingInterfaceMP(); //! initialization bool Init() override; //! interface activation void Activate() override; //! calculate the slip direction on the primary surface vec3d SlipTangent(FESlidingSurfaceMP& ss, const int nel, const int nint, FESlidingSurfaceMP& ms, double& dh, vec3d& r); //! calculate contact traction vec3d ContactTraction(FESlidingSurfaceMP& ss, const int nel, const int n, FESlidingSurfaceMP& ms, double& pn); //! calculate contact pressures for file output void UpdateContactPressures(); //! serialize data to archive void Serialize(DumpStream& ar) override; //! mark ambient condition void MarkAmbient(); //! set ambient condition void SetAmbient(); //! return the primary and secondary surface FESurface* GetPrimarySurface() override { return &m_ss; } FESurface* GetSecondarySurface() override { return &m_ms; } //! return integration rule class bool UseNodalIntegration() override { return false; } //! build the matrix profile for use in the stiffness matrix void BuildMatrixProfile(FEGlobalMatrix& K) override; //! get solute data FESoluteData* FindSoluteData(int nid); public: //! calculate contact forces void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! calculate contact stiffness void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! calculate Lagrangian augmentations bool Augment(int naug, const FETimeInfo& tp) override; //! update void Update() override; protected: void ProjectSurface(FESlidingSurfaceMP& ss, FESlidingSurfaceMP& ms, bool bupseg, bool bmove = false); //! calculate penalty factor void UpdateAutoPenalty(); void CalcAutoPenalty(FESlidingSurfaceMP& s); void CalcAutoPressurePenalty(FESlidingSurfaceMP& s); double AutoPressurePenalty(FESurfaceElement& el, FESlidingSurfaceMP& s); void CalcAutoConcentrationPenalty(FESlidingSurfaceMP& s, const int isol); double AutoConcentrationPenalty(FESurfaceElement& el, FESlidingSurfaceMP& s, const int isol); double AutoPenalty(FESurfaceElement& el, FESurface &s); public: FESlidingSurfaceMP m_ss; //!< primary surface FESlidingSurfaceMP m_ms; //!< secondary surface int m_knmult; //!< higher order stiffness multiplier bool m_btwo_pass; //!< two-pass flag double m_atol; //!< augmentation tolerance double m_gtol; //!< gap tolerance double m_ptol; //!< pressure gap tolerance double m_ctol; //!< concentration gap tolerance double m_stol; //!< search tolerance bool m_bsymm; //!< use symmetric stiffness components only double m_srad; //!< contact search radius int m_naugmax; //!< maximum nr of augmentations int m_naugmin; //!< minimum nr of augmentations int m_nsegup; //!< segment update parameter bool m_breloc; //!< node relocation on startup bool m_bsmaug; //!< smooth augmentation bool m_bsmfls; //!< smooth local fluid load support double m_epsn; //!< normal penalty factor bool m_bautopen; //!< use autopenalty factor bool m_bupdtpen; //!< update penalty at each time step double m_mu; //!< friction coefficient bool m_bfreeze; //!< freeze stick/slip status // multiphasic contact parameters double m_phi; //!< solid-solid contact fraction double m_epsp; //!< fluid volumetric flow rate penalty double m_epsc; //!< solute molar flow rate penalty double m_Rgas; //!< universal gas constant double m_Tabs; //!< absolute temperature double m_ambp; //!< ambient pressure vector<double> m_ambc; //!< ambient concentration vector<FEAmbientConcentration*> m_ambctmp; vector<int> m_sid; //!< list of solute ids common to both contact surfaces vector<int> m_ssl; //!< list of primary surface solutes common to both contact surfaces vector<int> m_msl; //!< list of secondary surface solutes common to both contact surfaces vector<int> m_sz; //!< charge number of solutes common to both contact surfaces protected: int m_dofP; int m_dofC; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEDiffRefIso.cpp
.cpp
5,051
145
/*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 "FEDiffRefIso.h" // define the material parameters BEGIN_FECORE_CLASS(FEDiffRefIso, FESoluteDiffusivity) ADD_PARAMETER(m_free_diff, FE_RANGE_GREATER_OR_EQUAL(0.0), "free_diff")->setUnits(UNIT_DIFFUSIVITY)->setLongName("free diffusivity"); ADD_PARAMETER(m_diff0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "diff0" )->setUnits(UNIT_DIFFUSIVITY); ADD_PARAMETER(m_diff1 , FE_RANGE_GREATER_OR_EQUAL(0.0), "diff1" )->setUnits(UNIT_DIFFUSIVITY); ADD_PARAMETER(m_diff2 , FE_RANGE_GREATER_OR_EQUAL(0.0), "diff2" )->setUnits(UNIT_DIFFUSIVITY); ADD_PARAMETER(m_M , FE_RANGE_GREATER_OR_EQUAL(0.0), "M" ); ADD_PARAMETER(m_alpha , FE_RANGE_GREATER_OR_EQUAL(0.0), "alpha" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEDiffRefIso::FEDiffRefIso(FEModel* pfem) : FESoluteDiffusivity(pfem) { m_free_diff = 1; m_diff0 = 1; m_diff1 = 0; m_diff2 = 0; m_M = 0; m_alpha = 0; } //----------------------------------------------------------------------------- //! Free diffusivity double FEDiffRefIso::Free_Diffusivity(FEMaterialPoint& mp) { return m_diff0(mp); } //----------------------------------------------------------------------------- //! Tangent of free diffusivity with respect to concentration double FEDiffRefIso::Tangent_Free_Diffusivity_Concentration(FEMaterialPoint& mp, const int isol) { return 0; } //----------------------------------------------------------------------------- //! Diffusivity tensor. mat3ds FEDiffRefIso::Diffusivity(FEMaterialPoint& mp) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); // Identity mat3dd I(1); // left cauchy-green matrix mat3ds b = et.LeftCauchyGreen(); // relative volume double J = et.m_J; // solid volume fraction in reference configuration double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); // --- strain-dependent permeability --- double f = pow((J-phi0)/(1-phi0),m_alpha(mp))*exp(m_M(mp)*(J*J-1.0)/2.0); double d0 = m_diff0(mp)*f; double d1 = m_diff1(mp)/(J*J)*f; double d2 = 0.5*m_diff2(mp)/pow(J,4)*f; mat3ds dt = d0*I+d1*b+2*d2*b.sqr(); return dt; } //----------------------------------------------------------------------------- //! Tangent of diffusivity with respect to strain tens4dmm FEDiffRefIso::Tangent_Diffusivity_Strain(FEMaterialPoint &mp) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); // Identity mat3dd I(1); // left cauchy-green matrix mat3ds b = et.LeftCauchyGreen(); // relative volume double J = et.m_J; // solid volume fraction in reference configuration double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); double M = m_M(mp); double alpha = m_alpha(mp); double f = pow((J-phi0)/(1-phi0),alpha)*exp(M*(J*J-1.0)/2.0); double d0 = m_diff0(mp)*f; double d1 = m_diff1(mp)/(J*J)*f; double d2 = 0.5*m_diff2(mp)/pow(J,4)*f; double D0prime = (J*J*M+(J*(alpha+1)-phi0)/(J-phi0))*d0; double D1prime = (J*J*M+(J*(alpha-1)+phi0)/(J-phi0))*d1; double D2prime = (J*J*M+(J*(alpha-3)+3*phi0)/(J-phi0))*d2; mat3ds d0hat = I*D0prime; mat3ds d1hat = I*D1prime; mat3ds d2hat = I*D2prime; tens4dmm D4 = dyad1mm(I,d0hat)-dyad4s(I)*(2*d0) + dyad1mm(b,d1hat) + dyad1mm(b.sqr(),d2hat)*2+dyad4s(b)*(4*d2); return D4; } //----------------------------------------------------------------------------- //! Tangent of diffusivity with respect to concentration mat3ds FEDiffRefIso::Tangent_Diffusivity_Concentration(FEMaterialPoint &mp, const int isol) { mat3ds d; d.zero(); return d; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateSoluteAsSBM.cpp
.cpp
3,112
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) 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 "FEReactionRateSoluteAsSBM.h" #include "FEBiphasic.h" #include "FEBioMech/FERemodelingElasticMaterial.h" // Material parameters for the FEMultiphasic material BEGIN_FECORE_CLASS(FEReactionRateSoluteAsSBM, FEReactionRate) ADD_PARAMETER(m_k0, "k0"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEReactionRateSoluteAsSBM::FEReactionRateSoluteAsSBM(FEModel* pfem) : FEReactionRate(pfem) { m_k0 = 0; } //----------------------------------------------------------------------------- //! reaction rate at material point double FEReactionRateSoluteAsSBM::ReactionRate(FEMaterialPoint& pt) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); double phisr = pbm->SolidReferentialVolumeFraction(pt); FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double J = et.m_J; double zhat = m_k0(pt)/(J-phisr); return zhat; } //----------------------------------------------------------------------------- //! tangent of reaction rate with strain at material point mat3ds FEReactionRateSoluteAsSBM::Tangent_ReactionRate_Strain(FEMaterialPoint& pt) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); double phisr = pbm->SolidReferentialVolumeFraction(pt); double dphisrdJ = pbm->TangentSRVFStrain(pt); FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double J = et.m_J; double dzhatdJ = -(1-dphisrdJ)*m_k0(pt)/pow(J-phisr,2); return mat3dd(dzhatdJ); } //----------------------------------------------------------------------------- //! tangent of reaction rate with effective fluid pressure at material point double FEReactionRateSoluteAsSBM::Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicContactSurface.h
.h
3,993
116
/*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 <FEBioMech/FEContactSurface.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- class FEBIOMIX_API FEBiphasicContactPoint : public FEContactMaterialPoint { public: vec3d m_dg; //!< vector gap double m_Lmd; //!< Lagrange multipliers for normal traction vec3d m_Lmt; //!< Lagrange multipliers for vector traction double m_epsn; //!< penalty factor double m_epsp; //!< pressure penalty factor double m_p1; //!< fluid pressure vec3d m_nu; //!< normal at integration points vec3d m_s1; //!< tangent along slip direction vec3d m_tr; //!< contact traction vec2d m_rs; //!< natural coordinates of projection vec2d m_rsp; //!< m_rs at the previous time step bool m_bstick; //!< stick flag double m_Lmp; //!< lagrange multipliers for fluid pressures double m_pg; //!< pressure "gap" for biphasic contact double m_mueff; //!< effective friction coefficient double m_fls; //!< local fluid load support void Init() override { FEContactMaterialPoint::Init(); m_Lmd = 0.0; m_Lmt = m_tr = vec3d(0,0,0); m_Lmp = 0.0; m_epsn = 1.0; m_epsp = 1.0; m_pg = 0.0; m_p1 = 0.0; m_mueff = 0.0; m_fls = 0.0; m_nu = m_s1 = m_dg = vec3d(0,0,0); m_rs = m_rsp = vec2d(0,0); m_bstick = false; m_Lmp = 0.0; m_pg = 0.0; m_mueff = 0.0; m_fls = 0.0; } void Serialize(DumpStream& ar) override; }; //----------------------------------------------------------------------------- //! This class describes a contact surface used in a biphasic/multiphasic analysis. class FEBIOMIX_API FEBiphasicContactSurface : public FEContactSurface { public: //! constructor FEBiphasicContactSurface(FEModel* pfem); //! destructor ~FEBiphasicContactSurface(); //! initialization bool Init(); //! serialization void Serialize(DumpStream& ar); void UnpackLM(FEElement& el, vector<int>& lm); public: //! Get the total force exerted by the fluid virtual vec3d GetFluidForce(); //! Get the total force exerted by the fluid virtual double GetFluidLoadSupport(); //! Get the effective friction coefficient virtual void GetMuEffective (int nface, double& pg); //! Get the local fluid load support virtual void GetLocalFLS (int nface, double& pg); //! Get the local fluid load support projected from the element to the surface Gauss points void GetGPLocalFLS(int nface, double* pt, double ambp = 0); protected: int m_dofP; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicModule.h
.h
1,811
51
/*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/FEModule.h> #include <FEBioMech/FESolidModule.h> #include "febiomix_api.h" class FEBIOMIX_API FEBiphasicModule : public FESolidModule { public: FEBiphasicModule(); void InitModel(FEModel* fem) override; }; class FEBIOMIX_API FEBiphasicSoluteModule : public FEBiphasicModule { public: FEBiphasicSoluteModule(); void InitModel(FEModel* fem) override; }; class FEBIOMIX_API FEMultiphasicModule : public FEBiphasicSoluteModule { public: FEMultiphasicModule(); void InitModel(FEModel* fem) override; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEActiveMomentumSupply.h
.h
2,185
54
/*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 "febiomix_api.h" //----------------------------------------------------------------------------- //! Base class for active momentum supply. //! These materials need to define the momentum supply and its tangents. //! class FEBIOMIX_API FEActiveMomentumSupply : public FEMaterialProperty { FECORE_BASE_CLASS(FEActiveMomentumSupply) public: FEActiveMomentumSupply(FEModel* pfem) : FEMaterialProperty(pfem) {} virtual ~FEActiveMomentumSupply(){} //! active momentum supply virtual vec3d ActiveSupply(FEMaterialPoint& pt) = 0; //! tangent of active momentum supply with respect to strain virtual vec3d Tangent_ActiveSupply_Strain(FEMaterialPoint& mp) = 0; //! tangent of hydraulic permeability with respect to concentration vec3d Tangent_ActiveSupply_Concentration(FEMaterialPoint& mp, const int isol); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBioMixPlot.h
.h
13,946
404
/*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/FEPlotData.h> #include <FECore/FEElement.h> #include <FECore/units.h> //============================================================================= // S U R F A C E D A T A //============================================================================= //----------------------------------------------------------------------------- //! Local fluid load support //! class FEPlotLocalFluidLoadSupport : public FEPlotSurfaceData { public: FEPlotLocalFluidLoadSupport(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM){} bool Save(FESurface& surf, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Effective friction coefficient //! class FEPlotEffectiveFrictionCoeff : public FEPlotSurfaceData { public: FEPlotEffectiveFrictionCoeff(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM){} bool Save(FESurface& surf, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Fluid flow rate //! class FEPlotMixtureFluidFlowRate : public FEPlotSurfaceData { public: FEPlotMixtureFluidFlowRate(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_REGION) { SetUnits(UNIT_FLOW_RATE); } bool Save(FESurface& surf, FEDataStream& a); }; //============================================================================= // D O M A I N D A T A //============================================================================= //----------------------------------------------------------------------------- //! Specific strain energy class FEPlotMPSpecificStrainEnergy : public FEPlotDomainData { public: FEPlotMPSpecificStrainEnergy(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_SPECIFIC_ENERGY); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Actual fluid pressure class FEPlotActualFluidPressure : public FEPlotDomainData { public: FEPlotActualFluidPressure(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_PRESSURE); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Solid stress class FEPlotSolidStress : public FEPlotDomainData { public: FEPlotSolidStress(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM) { SetUnits(UNIT_PRESSURE); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Fluid flux class FEPlotFluidFlux : public FEPlotDomainData { public: FEPlotFluidFlux(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) { SetUnits(UNIT_VELOCITY); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Nodal Fluid flux class FEPlotNodalFluidFlux : public FEPlotDomainData { public: FEPlotNodalFluidFlux(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_MULT) { SetUnits(UNIT_VELOCITY); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Actual solute concentration class FEPlotActualSoluteConcentration : public FEPlotDomainData { public: FEPlotActualSoluteConcentration(FEModel* pfem); bool Save(FEDomain& dom, FEDataStream& a); protected: vector<int> m_sol; }; //----------------------------------------------------------------------------- //! Actual solute concentration class FEPlotPartitionCoefficient : public FEPlotDomainData { public: FEPlotPartitionCoefficient(FEModel* pfem); bool Save(FEDomain& dom, FEDataStream& a); protected: vector<int> m_sol; }; //----------------------------------------------------------------------------- //! Solute flux (for biphasic solute problems) class FEPlotSoluteFlux : public FEPlotDomainData { public: FEPlotSoluteFlux(FEModel* pfem); bool Save(FEDomain& dom, FEDataStream& a); protected: vector<int> m_sol; }; //----------------------------------------------------------------------------- //! Solute volumetric flux class FEPlotSoluteVolumetricFlux : public FEPlotDomainData { public: FEPlotSoluteVolumetricFlux(FEModel* pfem); bool Save(FEDomain& dom, FEDataStream& a); protected: vector<int> m_sol; }; //----------------------------------------------------------------------------- //! Osmolarity class FEPlotOsmolarity : public FEPlotDomainData { public: FEPlotOsmolarity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_CONCENTRATION); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- class FEPlotSBMConcentration : public FEPlotDomainData { public: FEPlotSBMConcentration(FEModel* pfem); bool Save(FEDomain& dom, FEDataStream& a); protected: vector<int> m_sbm; }; //----------------------------------------------------------------------------- class FEPlotSBMArealConcentration : public FEPlotDomainData { public: FEPlotSBMArealConcentration(FEModel* pfem); bool Save(FEDomain& dom, FEDataStream& a); protected: vector<int> m_sbm; }; //----------------------------------------------------------------------------- //! Electric potential class FEPlotElectricPotential : public FEPlotDomainData { public: FEPlotElectricPotential(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_VOLTAGE); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Current density class FEPlotCurrentDensity : public FEPlotDomainData { public: FEPlotCurrentDensity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_VEC3F, FMT_ITEM) { SetUnits(UNIT_CURRENT_DENSITY); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Referential solid volume fraction class FEPlotReferentialSolidVolumeFraction : public FEPlotDomainData { public: FEPlotReferentialSolidVolumeFraction(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){} bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Porosity class FEPlotPorosity : public FEPlotDomainData { public: FEPlotPorosity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){} bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Permeability class FEPlotPerm : public FEPlotDomainData { public: FEPlotPerm(FEModel* pfem) : FEPlotDomainData(pfem, PLT_MAT3FS, FMT_ITEM) { SetUnits(UNIT_PERMEABILITY); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Fixed charge density class FEPlotFixedChargeDensity : public FEPlotDomainData { public: FEPlotFixedChargeDensity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_CONCENTRATION); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Referential fixed charge density class FEPlotReferentialFixedChargeDensity : public FEPlotDomainData { public: FEPlotReferentialFixedChargeDensity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_CONCENTRATION); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Nodal effective fluid pressures class FEPlotEffectiveFluidPressure : public FEPlotDomainData { public: FEPlotEffectiveFluidPressure(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_NODE) { SetUnits(UNIT_PRESSURE); } bool Save(FEDomain& m, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Nodal effective downstream fluid pressures class FEPlotEffectiveShellFluidPressure : public FEPlotDomainData { public: FEPlotEffectiveShellFluidPressure(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_NODE) { SetUnits(UNIT_PRESSURE); } bool Save(FEDomain& m, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Nodal effective solute concentrations (for biphasic-solute problems) class FEPlotEffectiveSoluteConcentration : public FEPlotDomainData { public: FEPlotEffectiveSoluteConcentration(FEModel* pfem); bool Save(FEDomain& m, FEDataStream& a); protected: vector<int> m_sol; }; //----------------------------------------------------------------------------- //! Nodal effective solute concentrations (for biphasic-solute problems) class FEPlotEffectiveShellSoluteConcentration : public FEPlotDomainData { public: FEPlotEffectiveShellSoluteConcentration(FEModel* pfem); bool SetFilter(const char* sz); bool SetFilter(int nsol); bool Save(FEDomain& m, FEDataStream& a); protected: int m_nsol; }; //----------------------------------------------------------------------------- //! Receptor-ligand complex concentration class FEPlotReceptorLigandConcentration : public FEPlotDomainData { public: FEPlotReceptorLigandConcentration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_DENSITY); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Base class for solid-bound molecule referential apparent density class FEPlotSBMRefAppDensity : public FEPlotDomainData { public: FEPlotSBMRefAppDensity(FEModel* pfem); bool Save(FEDomain& dom, FEDataStream& a); protected: vector<int> m_sbm; }; //----------------------------------------------------------------------------- //! effective elasticity class FEPlotEffectiveElasticity : public FEPlotDomainData { public: FEPlotEffectiveElasticity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_TENS4FS, FMT_ITEM) { SetUnits(UNIT_PRESSURE); } bool Save(FEDomain& dom, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Osmotic coefficient class FEPlotOsmoticCoefficient : public FEPlotDomainData { public: FEPlotOsmoticCoefficient(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_ITEM){} bool Save(FEDomain& dom, FEDataStream& a); }; //============================================================================= // S U R F A C E D A T A //============================================================================= //----------------------------------------------------------------------------- //! Fluid force //! class FEPlotFluidForce : public FEPlotSurfaceData { public: FEPlotFluidForce(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_FORCE); } bool Save(FESurface& surf, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Fluid force //! class FEPlotFluidForce2 : public FEPlotSurfaceData { public: FEPlotFluidForce2(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_VEC3F, FMT_REGION) { SetUnits(UNIT_FORCE); } bool Save(FESurface& surf, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Contact gap for multiphasic interfaces //! class FEPlotContactGapMP : public FEPlotSurfaceData { public: FEPlotContactGapMP(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_LENGTH); } bool Save(FESurface& surf, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Fluid pressure gap //! class FEPlotPressureGap : public FEPlotSurfaceData { public: FEPlotPressureGap(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_ITEM) { SetUnits(UNIT_PRESSURE); } bool Save(FESurface& surf, FEDataStream& a); }; //----------------------------------------------------------------------------- //! Fluid load support //! class FEPlotFluidLoadSupport : public FEPlotSurfaceData { public: FEPlotFluidLoadSupport(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_FLOAT, FMT_REGION){} bool Save(FESurface& surf, FEDataStream& a); }; //----------------------------------------------------------------------------- //! concentration gap //! class FEPlotConcentrationGap : public FEPlotSurfaceData { public: FEPlotConcentrationGap(FEModel* pfem); bool Save(FESurface& surf, FEDataStream& a); protected: vector<int> m_sol; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESolute.h
.h
9,130
299
/*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/FEGlobalData.h> #include <FECore/tens4d.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Base class for solute diffusivity. //! These materials need to define the diffusivity and tangent diffusivity functions. //! class FEBIOMIX_API FESoluteDiffusivity : public FEMaterialProperty { public: //! constructor FESoluteDiffusivity(FEModel* pfem) : FEMaterialProperty(pfem) {} //! solute diffusivity virtual mat3ds Diffusivity(FEMaterialPoint& pt) = 0; //! tangent of diffusivity with respect to strain virtual tens4dmm Tangent_Diffusivity_Strain(FEMaterialPoint& mp) = 0; //! tangent of diffusivity with respect to solute concentration virtual mat3ds Tangent_Diffusivity_Concentration(FEMaterialPoint& mp, const int isol) = 0; //! solute diffusivity in free solution virtual double Free_Diffusivity(FEMaterialPoint& pt) = 0; //! tangent of free diffusivity with respect to solute concentration virtual double Tangent_Free_Diffusivity_Concentration(FEMaterialPoint& pt, const int isol) = 0; //! set solute ID void SetSoluteID(const int ID) {m_ID = ID;} //! set solute ID int GetSoluteID() { return m_ID;} private: int m_ID; //!< solute ID FECORE_BASE_CLASS(FESoluteDiffusivity) }; //----------------------------------------------------------------------------- //! Base class for solute solubility. //! These materials need to define the solubility and tangent solubility functions. //! class FEBIOMIX_API FESoluteSolubility : public FEMaterialProperty { public: //! constructor FESoluteSolubility(FEModel* pfem) : FEMaterialProperty(pfem) {} //! solute solubility virtual double Solubility(FEMaterialPoint& pt) = 0; //! tangent of solubility with respect to strain virtual double Tangent_Solubility_Strain(FEMaterialPoint& mp) = 0; //! tangent of solubility with respect to concentration virtual double Tangent_Solubility_Concentration(FEMaterialPoint& mp, const int isol) = 0; //! cross derivative of solubility with respect to strain and concentration virtual double Tangent_Solubility_Strain_Concentration(FEMaterialPoint& mp, const int isol) = 0; //! second derivative of solubility with respect to strain virtual double Tangent_Solubility_Strain_Strain(FEMaterialPoint& mp) = 0; //! second derivative of solubility with respect to concentration virtual double Tangent_Solubility_Concentration_Concentration(FEMaterialPoint& mp, const int isol, const int jsol) = 0; //! set solute ID void SetSoluteID(const int ID) {m_ID = ID;} //! set solute ID int GetSoluteID() { return m_ID;} private: int m_ID; //!< solute ID FECORE_BASE_CLASS(FESoluteSolubility) }; //----------------------------------------------------------------------------- //! Base class for solute supply. //! These materials need to define the solute supply and tangent supply functions. //! The solute supply has units of moles/(referential mixture volume)/time //! class FEBIOMIX_API FESoluteSupply : public FEMaterialProperty { public: //! constructor FESoluteSupply(FEModel* pfem) : FEMaterialProperty(pfem) {} //! solute supply virtual double Supply(FEMaterialPoint& pt) = 0; //! solute supply under steady-state conditions virtual double SupplySS(FEMaterialPoint& pt) = 0; //! tangent of solute supply with respect to strain virtual double Tangent_Supply_Strain(FEMaterialPoint& mp) = 0; //! tangent of solute supply with respect to solute concentration virtual double Tangent_Supply_Concentration(FEMaterialPoint& mp) = 0; //! receptor-ligand complex supply virtual double ReceptorLigandSupply(FEMaterialPoint& pt) = 0; //! receptor-ligand concentration under steady-state conditions virtual double ReceptorLigandConcentrationSS(FEMaterialPoint& pt) = 0; //! referential solid supply virtual double SolidSupply(FEMaterialPoint& pt) = 0; //! referential solid concentration under steady-state conditions virtual double SolidConcentrationSS(FEMaterialPoint& pt) = 0; FECORE_BASE_CLASS(FESoluteSupply) }; //----------------------------------------------------------------------------- //! Global solute data //! This structure uniquely identifies a solute in multiphasic problems class FESoluteData : public FEGlobalData { public: FESoluteData(FEModel* pfem); //! initialization bool Init() override; public: double m_rhoT; //!< true solute density double m_M; //!< solute molecular weight int m_z; //!< solute charge number DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! Base class for solute materials. class FESolute : public FEMaterialProperty { public: FESolute(FEModel* pfem); public: bool Init() override; //! solute density double Density() { return m_rhoT; } //! solute molecular weight double MolarMass() { return m_M; } //! solute charge number int ChargeNumber() { return m_z; } //! Serialization void Serialize(DumpStream& ar) override; //! set solute ID void SetSoluteID(const int ID) {m_ID = ID;} //! get solute ID int GetSoluteID() {return m_ID;} //! set solute local ID void SetSoluteLocalID(const int LID) {m_LID = LID;} //! get solute local ID int GetSoluteLocalID() {return m_LID;} //! return the solute's dof int GetSoluteDOF() const { return m_ID - 1; } private: FESoluteData* FindSoluteData(int nid); private: int m_LID; //!< solute local ID in parent material public: // material parameters int m_ID; //!< solute ID in global table double m_rhoT; //!< true solute density double m_M; //!< solute molecular weight int m_z; //!< charge number of solute public: // material properties FESoluteDiffusivity* m_pDiff; //!< pointer to diffusivity material FESoluteSolubility* m_pSolub; //!< pointer to solubility material FESoluteSupply* m_pSupp; //!< pointer to solute supply material FECORE_BASE_CLASS(FESolute) }; //----------------------------------------------------------------------------- // This class was introduced so that solutes fall in the same paradigm as any other // material property. class FESoluteMaterial : public FESolute { public: FESoluteMaterial(FEModel* fem); DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! Global solid-bound molecule (SBM) data. class FESBMData : public FEGlobalData { public: FESBMData(FEModel* pfem); public: double m_rhoT; //!< SBM true density double m_M; //!< SBM molar mass int m_z; //!< SBM charge number DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! Base class for solid-bound molecules. class FESolidBoundMolecule : public FEMaterialProperty { public: FESolidBoundMolecule(FEModel* pfem); public: bool Init() override; //! solute density double Density() { return m_rhoT; } //! solute molecular weight double MolarMass() { return m_M; } //! solute charge number int ChargeNumber() { return m_z; } //! Serialization void Serialize(DumpStream& ar) override; //! set solute ID void SetSBMID(const int ID) {m_ID = ID;} //! get SBM ID int GetSBMID() {return m_ID;} private: FESBMData* FindSBMData(int nid); private: int m_ID; //!< SBM ID in global table public: double m_rhoT; //!< true SBM density double m_M; //!< SBM molar mass int m_z; //!< charge number of SBM FEParamDouble m_rho0; //!< initial referential (apparent) density of SBM double m_rhomin; //!< minimum referential (apparent) density of SBM double m_rhomax; //!< maximum referential (apparent) density of SBM DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FESolidBoundMolecule) };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateHuiskes.cpp
.cpp
9,551
238
/*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 "FEReactionRateHuiskes.h" #include "FEBiphasic.h" #include "FEMultiphasic.h" #include <FEBioMech/FERemodelingElasticMaterial.h> #include <FEBioMech/FEElasticMixture.h> #include <FECore/FEModel.h> #include <FECore/log.h> // Material parameters for the FEMultiphasic material BEGIN_FECORE_CLASS(FEReactionRateHuiskes, FEReactionRate) ADD_PARAMETER(m_B, "B"); ADD_PARAMETER(m_psi0, FE_RANGE_GREATER_OR_EQUAL(0.0), "psi0")->setUnits(UNIT_SPECIFIC_ENERGY); ADD_PARAMETER(m_D, FE_RANGE_GREATER_OR_EQUAL(0.0), "D")->setUnits(UNIT_LENGTH)->setLongName("sensor distance"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEReactionRateHuiskes::FEReactionRateHuiskes(FEModel* pfem) : FEReactionRate(pfem) { m_B = 0; m_psi0 = 0; m_D = 0; m_comp = -1; m_binit = false; m_M = 0; m_lsbm = -1; } //----------------------------------------------------------------------------- //! initialization bool FEReactionRateHuiskes::Init() { if (m_binit) return true; FEMultiphasic* pbm = dynamic_cast<FEMultiphasic*>(GetAncestor()); if (pbm == nullptr) return true; // in case material is not multiphasic FEChemicalReaction* pcm = dynamic_cast<FEChemicalReaction*>(m_pReact); int sbm = pcm->m_vPtmp[0]->m_speciesID; m_lsbm = pbm->FindLocalSBMID(sbm); m_M = pbm->SBMMolarMass(m_lsbm); // get neighboring elements for given proximity if (m_D > 0) { double mult = 4; //! multiplier of characteristic distance, such that exp(-mult) << 1 FEMesh& mesh = GetFEModel()->GetMesh(); if (m_topo.Create(&mesh) == false) { feLogError("Failed building mesh topo."); return false; } feLogInfo("Evaluating element proximity..."); m_EPL.assign(mesh.Elements(), std::vector<int>()); for (int i=0; i< mesh.Elements(); ++i) { std::vector<int> epl = m_topo.ElementProximityList(i, m_D*mult); m_EPL[i] = epl; } feLogInfo("Done."); } m_binit = true; FEElasticMaterial* pem = pbm->GetSolid(); FEElasticMixture* psm = dynamic_cast<FEElasticMixture*>(pem); if (psm == nullptr) return true; // in case material is not a solid mixture for (int i=0; i<psm->Materials(); ++i) { pem = psm->GetMaterial(i); // check the types of materials that can employ this reaction rate FERemodelingInterface* pri = dynamic_cast<FERemodelingInterface*>(pem); if (pri) { if (sbm == pri->m_sbm) m_comp = pri->m_comp; } } if (m_comp == -1) return false; return true; } //----------------------------------------------------------------------------- //! reaction rate at material point double FEReactionRateHuiskes::ReactionRate(FEMaterialPoint& pt) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); double rhor = pbm->SolidReferentialApparentDensity(pt); double phir = pbm->SolidReferentialVolumeFraction(pt); FERemodelingMaterialPoint* rpt = nullptr; double J = 1; double sed = 0; if (m_comp == -1) { rpt = pt.ExtractData<FERemodelingMaterialPoint>(); FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); J = et.m_J; } else { FEElasticMixtureMaterialPoint* mp = pt.ExtractData<FEElasticMixtureMaterialPoint>(); FEMaterialPoint& mpi = *mp->GetPointData(m_comp); rpt = mpi.ExtractData<FERemodelingMaterialPoint>(); FEElasticMaterialPoint& et = *mpi.ExtractData<FEElasticMaterialPoint>(); J = et.m_J; } sed = rpt->m_sed; double B = m_B(pt); double psi0 = m_psi0(pt); double zhat = B*(sed/rhor - psi0)/(J-phir)/m_M; if (m_D > 0) { FEMesh& mesh = GetFEModel()->GetMesh(); int ie = pt.m_elem->GetLocalID(); int NEPL = (int)m_EPL[ie].size(); #pragma omp parallel for shared (NEPL) for (int i=0; i<NEPL; ++i) { int je = m_EPL[ie][i]; if (je > -1) { FEElement* el = mesh.Element(je); for (int k=0; k<el->GaussPoints(); ++k) { FEMaterialPoint& mp = *(el->GetMaterialPoint(k)); double d = (pt.m_rt - mp.m_rt).unit(); if (m_comp == -1) { rpt = mp.ExtractData<FERemodelingMaterialPoint>(); FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); J = et.m_J; } else { FEElasticMixtureMaterialPoint* mmp = mp.ExtractData<FEElasticMixtureMaterialPoint>(); FEMaterialPoint& mpi = *mmp->GetPointData(m_comp); rpt = mpi.ExtractData<FERemodelingMaterialPoint>(); } sed = rpt->m_sed; rhor = pbm->SolidReferentialApparentDensity(mp); phir = pbm->SolidReferentialVolumeFraction(mp); B = m_B(mp); psi0 = m_psi0(mp); zhat += exp(-d/m_D)*B*(sed/rhor - psi0)/(J-phir)/m_M; } } } } return zhat; } //----------------------------------------------------------------------------- //! tangent of reaction rate with strain at material point mat3ds FEReactionRateHuiskes::Tangent_ReactionRate_Strain(FEMaterialPoint& pt) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double rhor = pbm->SolidReferentialApparentDensity(pt); double phir = pbm->SolidReferentialVolumeFraction(pt); double p = pbm->GetActualFluidPressure(pt); double J = 1; if (m_comp == -1) { FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); J = et.m_J; } else { FEElasticMixtureMaterialPoint* mmp = pt.ExtractData<FEElasticMixtureMaterialPoint>(); FEMaterialPoint& mpi = *mmp->GetPointData(m_comp); FEElasticMaterialPoint& et = *mpi.ExtractData<FEElasticMaterialPoint>(); J = et.m_J; } double zhat = ReactionRate(pt); mat3dd I(1); double B = m_B(pt); mat3ds dzhatde = (I*(-zhat) + (et.m_s+I*p)*(B/rhor/m_M))/(J-phir); if (m_D > 0) { mat3ds s(0); FEMesh& mesh = GetFEModel()->GetMesh(); int ie = pt.m_elem->GetLocalID(); int NEPL = (int)m_EPL[ie].size(); #pragma omp parallel for shared (NEPL) for (int i=0; i<NEPL; ++i) { int je = m_EPL[ie][i]; if (je > -1) { FEElement* el = mesh.Element(je); for (int k=0; k<el->GaussPoints(); ++k) { FEMaterialPoint& mp = *(el->GetMaterialPoint(k)); double d = (pt.m_rt - mp.m_rt).unit(); if (m_comp == -1) { FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); // we just want the effective stress, so subtract the pressure term p = pbm->GetActualFluidPressure(mp); s = et.m_s+I*p; } else { FEElasticMixtureMaterialPoint* mmp = mp.ExtractData<FEElasticMixtureMaterialPoint>(); FEMaterialPoint& mpi = *mmp->GetPointData(m_comp); FEElasticMaterialPoint& et = *mpi.ExtractData<FEElasticMaterialPoint>(); // the stress stored in elastic mixture material points is an effective stress s = et.m_s; } rhor = pbm->SolidReferentialApparentDensity(mp); B = m_B(mp); dzhatde += exp(-d/m_D)*s*(B/rhor/m_M)/(J-phir); } } } } return dzhatde; } //----------------------------------------------------------------------------- //! tangent of reaction rate with effective fluid pressure at material point double FEReactionRateHuiskes::Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEConcentrationIndependentReaction.h
.h
2,186
55
/*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 "FEMultiphasic.h" //----------------------------------------------------------------------------- //! Concentration-independent forward chemical reaction. class FEBIOMIX_API FEConcentrationIndependentReaction : public FEChemicalReaction { public: //! constructor FEConcentrationIndependentReaction(FEModel* pfem); //! molar supply at material point double ReactionSupply(FEMaterialPoint& pt) override; //! tangent of molar supply with strain (J) at material point mat3ds Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) override; //! tangent of molar supply with effective pressure at material point double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) override; //! tangent of molar supply with effective concentration at material point double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) override; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPermRefIso.cpp
.cpp
4,711
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 <FECore/log.h> #include "FEPermRefIso.h" #define INRANGE(x, a, b) ((x)>=(a) && (x)<=(b)) // define the material parameters BEGIN_FECORE_CLASS(FEPermRefIso, FEHydraulicPermeability) ADD_PARAMETER(m_perm0, FE_RANGE_GREATER_OR_EQUAL(0.0), "perm0")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_perm1, FE_RANGE_GREATER_OR_EQUAL(0.0), "perm1")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_perm2, FE_RANGE_GREATER_OR_EQUAL(0.0), "perm2")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_M , FE_RANGE_GREATER_OR_EQUAL(0.0), "M" ); ADD_PARAMETER(m_alpha, FE_RANGE_GREATER_OR_EQUAL(0.0), "alpha"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEPermRefIso::FEPermRefIso(FEModel* pfem) : FEHydraulicPermeability(pfem) { m_perm0 = 1; m_perm1 = 0; m_perm2 = 0; m_M = m_alpha = 0; } //----------------------------------------------------------------------------- //! Initialization. bool FEPermRefIso::Validate() { if (FEHydraulicPermeability::Validate() == false) return false; return true; } //----------------------------------------------------------------------------- //! Permeability tensor. mat3ds FEPermRefIso::Permeability(FEMaterialPoint& mp) { FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // Identity mat3dd I(1); // left cauchy-green matrix mat3ds b = et.LeftCauchyGreen(); // relative volume double J = et.m_J; // referential solid volume fraction double phisr = pt.m_phi0t; // check for potential error if (J <= phisr) feLogError("The perm-ref-iso permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g.",J,phisr); // --- strain-dependent permeability --- double f = pow((J-phisr)/(1-pt.m_phi0),m_alpha)*exp(m_M*(J*J-1.0)/2.0); double k0 = m_perm0(mp)*f; double k1 = m_perm1(mp) /(J*J)*f; double k2 = 0.5*m_perm2(mp)/pow(J,4)*f; mat3ds kt = k0*I+k1*b+2*k2*b.sqr(); return kt; } //----------------------------------------------------------------------------- //! Tangent of permeability tens4dmm FEPermRefIso::Tangent_Permeability_Strain(FEMaterialPoint &mp) { FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // Identity mat3dd I(1); // left cauchy-green matrix mat3ds b = et.LeftCauchyGreen(); // relative volume double J = et.m_J; // referential solid volume fraction double phisr = pt.m_phi0t; double phi0 = pt.m_phi0; // check for potential error if (J <= phisr) feLogError("The perm-ref-iso permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g.",J,phisr); double f = pow((J-phisr)/(1-phi0),m_alpha)*exp(m_M*(J*J-1.0)/2.0); double k0 = m_perm0(mp) *f; double k1 = m_perm1(mp) /(J*J)*f; double k2 = 0.5*m_perm2(mp) /pow(J,4)*f; double K0prime = (1+J*(m_alpha/(J-phi0)+m_M*J))*k0; double K1prime = (J*J*m_M+(J*(m_alpha-1)+phi0)/(J-phisr))*k1; double K2prime = (J*J*m_M+(J*(m_alpha-3)+3*phi0)/(J-phisr))*k2; mat3ds k0hat = I*K0prime; mat3ds k1hat = I*K1prime; mat3ds k2hat = I*K2prime; tens4dmm K4 = dyad1mm(I,k0hat)-dyad4s(I)*(2*k0) + dyad1mm(b,k1hat) + dyad1mm(b.sqr(),k2hat)*2+dyad4s(b)*(4*k2); return K4; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSoluteShellDomain.cpp
.cpp
54,009
1,340
/*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 "FEBiphasicSoluteShellDomain.h" #include "FECore/FEMaterial.h" #include "FECore/FEModel.h" #include "FECore/FEAnalysis.h" #include "FECore/log.h" #include "FECore/DOFS.h" #include <FECore/FELinearSystem.h> #include "FEBiphasicAnalysis.h" //----------------------------------------------------------------------------- FEBiphasicSoluteShellDomain::FEBiphasicSoluteShellDomain(FEModel* pfem) : FESSIShellDomain(pfem), FEBiphasicSoluteDomain(pfem), m_dof(pfem) { m_dofSX = pfem->GetDOFIndex("sx"); m_dofSY = pfem->GetDOFIndex("sy"); m_dofSZ = pfem->GetDOFIndex("sz"); } //----------------------------------------------------------------------------- //! get the material (overridden from FEDomain) FEMaterial* FEBiphasicSoluteShellDomain::GetMaterial() { return m_pMat; } //----------------------------------------------------------------------------- //! get the total dof const FEDofList& FEBiphasicSoluteShellDomain::GetDOFList() const { return m_dof; } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::SetMaterial(FEMaterial* pmat) { FEDomain::SetMaterial(pmat); m_pMat = dynamic_cast<FEBiphasicSolute*>(pmat); assert(m_pMat); } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::Activate() { int dofc = m_dofC + m_pMat->GetSolute()->GetSoluteDOF(); int dofd = m_dofD + m_pMat->GetSolute()->GetSoluteDOF(); 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]); if (node.HasFlags(FENode::SHELL)) { node.set_active(m_dofSU[0]); node.set_active(m_dofSU[1]); node.set_active(m_dofSU[2]); } } node.set_active(m_dofP); node.set_active(dofc ); if (node.HasFlags(FENode::SHELL)) { node.set_active(m_dofQ); node.set_active(dofd ); } } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::InitMaterialPoints() { FEMesh& m = *GetMesh(); const int NE = FEElement::MAX_NODES; double p0[NE], q0[NE], c0[NE], d0[NE]; int id0 = m_pMat->GetSolute()->GetSoluteDOF(); for (int i = 0; i<(int)m_Elem.size(); ++i) { // get the solid element FEShellElement& el = m_Elem[i]; // get the number of nodes int neln = el.Nodes(); // get initial values of fluid pressure and solute concentrations for (int i = 0; i<neln; ++i) { p0[i] = m.Node(el.m_node[i]).get(m_dofP); q0[i] = m.Node(el.m_node[i]).get(m_dofQ); c0[i] = m.Node(el.m_node[i]).get(m_dofC + id0); d0[i] = m.Node(el.m_node[i]).get(m_dofD + id0); } // get the number of integration points int nint = el.GaussPoints(); // loop over the integration points for (int n = 0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pm = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); // initialize effective fluid pressure, its gradient, and fluid flux pt.m_p = evaluate(el, p0, q0, n); pt.m_gradp = gradient(el, p0, q0, n); pt.m_w = m_pMat->FluidFlux(mp); // initialize effective solute concentrations ps.m_c[0] = evaluate(el, c0, d0, n); ps.m_gradc[0] = gradient(el, c0, d0, n); ps.m_ca[0] = m_pMat->Concentration(mp); ps.m_j[0] = m_pMat->SoluteFlux(mp); ps.m_crp[0] = pm.m_J*m_pMat->Porosity(mp)*ps.m_ca[0]; pt.m_pa = m_pMat->Pressure(mp); // initialize referential solid volume fraction pt.m_phi0t = m_pMat->m_phi0(mp); // calculate stress pm.m_s = m_pMat->Stress(mp); } } } //----------------------------------------------------------------------------- //! Unpack the element LM data. void FEBiphasicSoluteShellDomain::UnpackLM(FEElement& el, vector<int>& lm) { int dofc = m_dofC + m_pMat->GetSolute()->GetSoluteDOF(); int dofd = m_dofD + m_pMat->GetSolute()->GetSoluteDOF(); int N = el.Nodes(); int ndpn = 10; lm.resize(N*(ndpn+3)); for (int i=0; i<N; ++i) { int n = el.m_node[i]; FENode& node = m_pMesh->Node(n); vector<int>& id = node.m_ID; // first the displacement dofs lm[ndpn*i ] = id[m_dofU[0]]; lm[ndpn*i+1] = id[m_dofU[1]]; lm[ndpn*i+2] = id[m_dofU[2]]; // next the rotational dofs lm[ndpn*i+3] = id[m_dofSU[0]]; lm[ndpn*i+4] = id[m_dofSU[1]]; lm[ndpn*i+5] = id[m_dofSU[2]]; // now the pressure dofs lm[ndpn*i+6] = id[m_dofP]; lm[ndpn*i+7] = id[m_dofQ]; // concentration dofs lm[ndpn*i+8] = id[dofc]; lm[ndpn*i+9] = id[dofd]; // rigid rotational dofs // TODO: Do I really need this lm[ndpn*N + 3*i ] = id[m_dofR[0]]; lm[ndpn*N + 3*i+1] = id[m_dofR[1]]; lm[ndpn*N + 3*i+2] = id[m_dofR[2]]; } } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::Reset() { // reset base class FESSIShellDomain::Reset(); const int nsol = 1; const int nsbm = 1; // loop over all material points ForEachMaterialPoint([=](FEMaterialPoint& mp) { FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint >()); // initialize referential solid volume fraction pt.m_phi0 = pt.m_phi0t = m_pMat->m_phi0(mp); // initialize multiphasic solutes ps.m_nsol = nsol; ps.m_c.assign(nsol,0); ps.m_ca.assign(nsol,0); ps.m_crp.assign(nsol, 0); ps.m_gradc.assign(nsol,vec3d(0,0,0)); ps.m_k.assign(nsol, 0); ps.m_dkdJ.assign(nsol, 0); ps.m_dkdc.resize(nsol, vector<double>(nsol,0)); ps.m_j.assign(nsol,vec3d(0,0,0)); ps.m_nsbm = nsbm; ps.m_sbmr.assign(nsbm,0); ps.m_sbmrp.assign(nsbm,0); ps.m_sbmrhat.assign(nsbm,0); ps.m_sbmrhatp.assign(nsbm,0); }); } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { FESSIShellDomain::PreSolveUpdate(timeInfo); int dofc = m_dofC + m_pMat->GetSolute()->GetSoluteDOF(); int dofd = m_dofD + m_pMat->GetSolute()->GetSoluteDOF(); const int NE = FEElement::MAX_NODES; vec3d x0[NE], xt[NE], r0, rt; double pn[NE], qn[NE], p; double cn[NE], dn[NE], c; FEMesh& m = *GetMesh(); for (size_t iel=0; iel<m_Elem.size(); ++iel) { FEShellElement& el = m_Elem[iel]; int neln = el.Nodes(); for (int i=0; i<neln; ++i) { x0[i] = m.Node(el.m_node[i]).m_r0; xt[i] = m.Node(el.m_node[i]).m_rt; pn[i] = m.Node(el.m_node[i]).get(m_dofP); qn[i] = m.Node(el.m_node[i]).get(m_dofQ); cn[i] = m.Node(el.m_node[i]).get(dofc); dn[i] = m.Node(el.m_node[i]).get(dofd); } int n = el.GaussPoints(); for (int j=0; j<n; ++j) { r0 = el.Evaluate(x0, j); rt = el.Evaluate(xt, j); p = evaluate(el, pn, qn, j); c = evaluate(el, cn, dn, j); FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pb = *mp.ExtractData<FEBiphasicMaterialPoint>(); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint >()); mp.m_r0 = r0; mp.m_rt = rt; pt.m_J = defgrad(el, pt.m_F, j); pb.m_Jp = pt.m_J; pb.m_p = p; pb.m_gradp = gradient(el, pn, qn, j); pb.m_phi0p = pb.m_phi0t; ps.m_c[0] = c; ps.m_gradc[0] = gradient(el, cn, dn, j); // reset referential actual solute concentration at previous time ps.m_crp[0] = pt.m_J*m_pMat->Porosity(mp)*ps.m_ca[0]; // reset referential receptor-ligand complex concentration at previous time ps.m_sbmrp[0] = ps.m_sbmr[0]; // reset referential receptor-ligand complex concentration supply at previous time ps.m_sbmrhatp[0] = ps.m_sbmrhat[0]; mp.Update(timeInfo); } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::InternalForces(FEGlobalVector& R) { int NE = (int)m_Elem.size(); #pragma omp parallel for shared (NE) for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FEShellElement& el = m_Elem[i]; // get the element force vector and initialize it to zero int ndof = 10*el.Nodes(); fe.assign(ndof, 0); // calculate internal force vector ElementInternalForce(el, fe); // get the element's LM vector UnpackLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe, true); } } //----------------------------------------------------------------------------- //! calculates the internal equivalent nodal forces for solid elements void FEBiphasicSoluteShellDomain::ElementInternalForce(FEShellElement& el, vector<double>& fe) { int i, n; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; vec3d gradM, gradMu, gradMw; double Mu, Mw; mat3ds s; const double* Mr, *Ms, *M; int nint = el.GaussPoints(); int neln = el.Nodes(); double* gw = el.GaussWeights(); double eta; double dt = GetFEModel()->GetTime().timeIncrement; vec3d gcnt[3]; // repeat for all integration points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = invjact(el, Ji, n); detJt *= gw[n]; // get the stress vector for this integration point s = pt.m_s; eta = el.gt(n); Mr = el.Hr(n); Ms = el.Hs(n); M = el.H(n); ContraBaseVectors(el, n, gcnt); // next we get the determinant double Jp = bpt.m_Jp; double J = pt.m_J; // and then finally double divv = ((J-Jp)/dt)/J; // get the flux vec3d& w = bpt.m_w; // get the solute flux vec3d& j = spt.m_j[0]; // Evaluate porosity and solute supply and receptor-ligand kinetics double phiw = m_pMat->Porosity(mp); double crhat = 0; if (m_pMat->GetSolute()->m_pSupp) crhat = m_pMat->GetSolute()->m_pSupp->Supply(mp); for (i=0; i<neln; ++i) { gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; gradMu = (gradM*(1+eta) + gcnt[2]*M[i])/2; gradMw = (gradM*(1-eta) - gcnt[2]*M[i])/2; Mu = (1+eta)/2*M[i]; Mw = (1-eta)/2*M[i]; // calculate internal force vec3d fu = s*gradMu; vec3d fw = s*gradMw; // the '-' sign is so that the internal forces get subtracted // from the global residual vector fe[10*i ] -= fu.x*detJt; fe[10*i+1] -= fu.y*detJt; fe[10*i+2] -= fu.z*detJt; fe[10*i+3] -= fw.x*detJt; fe[10*i+4] -= fw.y*detJt; fe[10*i+5] -= fw.z*detJt; fe[10*i+6] -= dt*(w*gradMu - divv*Mu)*detJt; fe[10*i+7] -= dt*(w*gradMw - divv*Mw)*detJt; fe[10*i+8] -= dt*(gradMu*j + Mu*(crhat/J - (phiw*spt.m_ca[0] - spt.m_crp[0]/J)/dt) )*detJt; fe[10*i+9] -= dt*(gradMw*j + Mw*(crhat/J - (phiw*spt.m_ca[0] - spt.m_crp[0]/J)/dt) )*detJt; } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::InternalForcesSS(FEGlobalVector& R) { int NE = (int)m_Elem.size(); #pragma omp parallel for shared (NE) for (int i=0; i<NE; ++i) { // element force vector vector<double> fe; vector<int> lm; // get the element FEShellElement& el = m_Elem[i]; // get the element force vector and initialize it to zero int ndof = 10*el.Nodes(); fe.assign(ndof, 0); // calculate internal force vector ElementInternalForceSS(el, fe); // get the element's LM vector UnpackLM(el, lm); // assemble element 'fe'-vector into global R vector R.Assemble(el.m_node, lm, fe, true); } } //----------------------------------------------------------------------------- //! calculates the internal equivalent nodal forces for solid elements void FEBiphasicSoluteShellDomain::ElementInternalForceSS(FEShellElement& el, vector<double>& fe) { int i, n; // jacobian matrix, inverse jacobian matrix and determinants double Ji[3][3], detJt; vec3d gradM, gradMu, gradMw; double Mu, Mw; mat3ds s; const double* Mr, *Ms, *M; int nint = el.GaussPoints(); int neln = el.Nodes(); double dt = GetFEModel()->GetTime().timeIncrement; double* gw = el.GaussWeights(); double eta; vec3d gcnt[3]; // repeat for all integration points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& bpt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // calculate the jacobian detJt = invjact(el, Ji, n); detJt *= gw[n]; // get the stress vector for this integration point s = pt.m_s; eta = el.gt(n); Mr = el.Hr(n); Ms = el.Hs(n); M = el.H(n); ContraBaseVectors(el, n, gcnt); // next we get the determinant double J = pt.m_J; // get the flux vec3d& w = bpt.m_w; // get the solute flux vec3d& j = spt.m_j[0]; // Evaluate solute supply and receptor-ligand kinetics double crhat = 0; if (m_pMat->GetSolute()->m_pSupp) crhat = m_pMat->GetSolute()->m_pSupp->Supply(mp); for (i=0; i<neln; ++i) { gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; gradMu = (gradM*(1+eta) + gcnt[2]*M[i])/2; gradMw = (gradM*(1-eta) - gcnt[2]*M[i])/2; Mu = (1+eta)/2*M[i]; Mw = (1-eta)/2*M[i]; // calculate internal force vec3d fu = s*gradMu; vec3d fw = s*gradMw; // the '-' sign is so that the internal forces get subtracted // from the global residual vector fe[10*i ] -= fu.x*detJt; fe[10*i+1] -= fu.y*detJt; fe[10*i+2] -= fu.z*detJt; fe[10*i+3] -= fw.x*detJt; fe[10*i+4] -= fw.y*detJt; fe[10*i+5] -= fw.z*detJt; fe[10*i+6] -= dt*(w*gradMu)*detJt; fe[10*i+7] -= dt*(w*gradMw)*detJt; fe[10*i+8] -= dt*(gradMu*j + Mu*(crhat/J))*detJt; fe[10*i+9] -= dt*(gradMw*j + Mw*(crhat/J))*detJt; } } } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::StiffnessMatrix(FELinearSystem& LS, bool bsymm) { // repeat over all solid elements int NE = (int)m_Elem.size(); #pragma omp parallel for for (int iel=0; iel<NE; ++iel) { FEShellElement& el = m_Elem[iel]; // element stiffness matrix FEElementMatrix ke(el); // allocate stiffness matrix int neln = el.Nodes(); int ndof = neln*10; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementBiphasicSoluteStiffness(el, ke, bsymm); // get lm vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) { // repeat over all solid elements int NE = (int)m_Elem.size(); #pragma omp parallel for for (int iel=0; iel<NE; ++iel) { FEShellElement& el = m_Elem[iel]; // element stiffness matrix FEElementMatrix ke(el); int neln = el.Nodes(); int ndof = neln*10; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementBiphasicSoluteStiffnessSS(el, ke, bsymm); // get lm vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- //! calculates element stiffness matrix for element iel //! bool FEBiphasicSoluteShellDomain::ElementBiphasicSoluteStiffness(FEShellElement& el, matrix& ke, bool bsymm) { int i, j, n; int nint = el.GaussPoints(); int neln = el.Nodes(); double dt = GetFEModel()->GetTime().timeIncrement; const double* Mr, *Ms, *M; // jacobian double Ji[3][3], detJ; // Gradient of shape functions vector<vec3d> gradMu(neln), gradMw(neln); vector<double> Mu(neln), Mw(neln); vec3d gradM; double tmp; // gauss-weights double* gw = el.GaussWeights(); double eta; vec3d gcnt[3]; // zero stiffness matrix ke.zero(); // loop over gauss-points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint >()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint >()); // calculate jacobian detJ = invjact(el, Ji, n)*gw[n]; eta = el.gt(n); Mr = el.Hr(n); Ms = el.Hs(n); M = el.H(n); ContraBaseVectors(el, n, gcnt); // calculate global gradient of shape functions for (i=0; i<neln; ++i) { // calculate global gradient of shape functions gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; gradMu[i] = (gradM*(1+eta) + gcnt[2]*M[i])/2; gradMw[i] = (gradM*(1-eta) - gcnt[2]*M[i])/2; Mu[i] = (1+eta)/2*M[i]; Mw[i] = (1-eta)/2*M[i]; } // get stress tensor mat3ds s = ept.m_s; // get elasticity tensor tens4ds C = m_pMat->Tangent(mp); // get the fluid flux and pressure gradient vec3d gradp = ppt.m_gradp; vec3d w = ppt.m_w; // evaluate the permeability and its derivatives mat3ds K = m_pMat->GetPermeability()->Permeability(mp); tens4dmm dKdE = m_pMat->GetPermeability()->Tangent_Permeability_Strain(mp); mat3ds dKdc = m_pMat->GetPermeability()->Tangent_Permeability_Concentration(mp, 0); // next we get the determinant double J = ept.m_J; // get the fluid flux and pressure gradient // get the effective concentration, its gradient and its time derivative double c = spt.m_c[0]; vec3d gradc = spt.m_gradc[0]; // evaluate the porosity and its derivative double phiw = m_pMat->Porosity(mp); double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the solubility and its derivatives double kappa = spt.m_k[0]; double dkdJ = spt.m_dkdJ[0]; double dkdc = spt.m_dkdc[0][0]; // evaluate the diffusivity tensor and its derivatives mat3ds D = m_pMat->GetSolute()->m_pDiff->Diffusivity(mp); mat3ds dDdc = m_pMat->GetSolute()->m_pDiff->Tangent_Diffusivity_Concentration(mp, 0); tens4dmm dDdE = m_pMat->GetSolute()->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity double D0 = m_pMat->GetSolute()->m_pDiff->Free_Diffusivity(mp); double dD0dc = m_pMat->GetSolute()->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,0); // evaluate the osmotic coefficient and its derivatives double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp); double dodc = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp, 0); // evaluate the stress tangent with concentration // mat3ds dTdc = pm->GetSolid()->Tangent_Concentration(mp, 0); mat3ds dTdc(0,0,0,0,0,0); // Miscellaneous constants mat3dd I(1); double R = m_pMat->m_Rgas; double T = m_pMat->m_Tabs; // evaluate the effective permeability and its derivatives mat3ds Ki = K.inverse(); mat3ds ImD = I-D/D0; mat3ds Ke = (Ki + ImD*(R*T*kappa*c/phiw/D0)).inverse(); tens4d G = (dyad1(Ki,I) - dyad4(Ki,I)*2)*2 - ddot(dyad2(Ki,Ki),dKdE) +dyad1(ImD,I)*(R*T*c*J/D0/phiw*(dkdJ-kappa/phiw*dpdJ)) +(dyad1(I,I) - dyad2(I,I)*2 - dDdE/D0)*(R*T*kappa*c/phiw/D0); tens4d dKedE = (dyad1(Ke,I) - 2*dyad4(Ke,I))*2 - ddot(dyad2(Ke,Ke),G); mat3ds Gc = -(Ki*dKdc*Ki).sym() + ImD*(R*T/phiw/D0*(dkdc*c+kappa-kappa*c/D0*dD0dc)) +R*T*kappa*c/phiw/D0/D0*(D*dD0dc/D0 - dDdc); mat3ds dKedc = -(Ke*Gc*Ke).sym(); // evaluate the tangents of solute supply double dcrhatdJ = 0; double dcrhatdc = 0; if (m_pMat->GetSolute()->m_pSupp) { dcrhatdJ = m_pMat->GetSolute()->m_pSupp->Tangent_Supply_Strain(mp); double dcrhatdcr = m_pMat->GetSolute()->m_pSupp->Tangent_Supply_Concentration(mp); dcrhatdc = J*phiw*(kappa + c*dkdc)*dcrhatdcr; } // calculate all the matrices vec3d vtmp,gp,gc,qpu,qpw,qcu,qcw,wc,wd,jc,jd; mat3d wu,ww,ju,jw; double qcc, qcd; for (i=0; i<neln; ++i) { for (j=0; j<neln; ++j) { // Kuu matrix mat3d Kuu = (mat3dd(gradMu[i]*(s*gradMu[j])) + vdotTdotv(gradMu[i], C, gradMu[j]))*detJ; mat3d Kuw = (mat3dd(gradMu[i]*(s*gradMw[j])) + vdotTdotv(gradMu[i], C, gradMw[j]))*detJ; mat3d Kwu = (mat3dd(gradMw[i]*(s*gradMu[j])) + vdotTdotv(gradMw[i], C, gradMu[j]))*detJ; mat3d Kww = (mat3dd(gradMw[i]*(s*gradMw[j])) + vdotTdotv(gradMw[i], C, gradMw[j]))*detJ; ke[10*i ][10*j ] += Kuu[0][0]; ke[10*i ][10*j+1] += Kuu[0][1]; ke[10*i ][10*j+2] += Kuu[0][2]; ke[10*i+1][10*j ] += Kuu[1][0]; ke[10*i+1][10*j+1] += Kuu[1][1]; ke[10*i+1][10*j+2] += Kuu[1][2]; ke[10*i+2][10*j ] += Kuu[2][0]; ke[10*i+2][10*j+1] += Kuu[2][1]; ke[10*i+2][10*j+2] += Kuu[2][2]; ke[10*i ][10*j+3] += Kuw[0][0]; ke[10*i ][10*j+4] += Kuw[0][1]; ke[10*i ][10*j+5] += Kuw[0][2]; ke[10*i+1][10*j+3] += Kuw[1][0]; ke[10*i+1][10*j+4] += Kuw[1][1]; ke[10*i+1][10*j+5] += Kuw[1][2]; ke[10*i+2][10*j+3] += Kuw[2][0]; ke[10*i+2][10*j+4] += Kuw[2][1]; ke[10*i+2][10*j+5] += Kuw[2][2]; ke[10*i+3][10*j ] += Kwu[0][0]; ke[10*i+3][10*j+1] += Kwu[0][1]; ke[10*i+3][10*j+2] += Kwu[0][2]; ke[10*i+4][10*j ] += Kwu[1][0]; ke[10*i+4][10*j+1] += Kwu[1][1]; ke[10*i+4][10*j+2] += Kwu[1][2]; ke[10*i+5][10*j ] += Kwu[2][0]; ke[10*i+5][10*j+1] += Kwu[2][1]; ke[10*i+5][10*j+2] += Kwu[2][2]; ke[10*i+3][10*j+3] += Kww[0][0]; ke[10*i+3][10*j+4] += Kww[0][1]; ke[10*i+3][10*j+5] += Kww[0][2]; ke[10*i+4][10*j+3] += Kww[1][0]; ke[10*i+4][10*j+4] += Kww[1][1]; ke[10*i+4][10*j+5] += Kww[1][2]; ke[10*i+5][10*j+3] += Kww[2][0]; ke[10*i+5][10*j+4] += Kww[2][1]; ke[10*i+5][10*j+5] += Kww[2][2]; // calculate the kup matrix vec3d kup = gradMu[i]*(-Mu[j]*detJ); vec3d kuq = gradMu[i]*(-Mw[j]*detJ); vec3d kwp = gradMw[i]*(-Mu[j]*detJ); vec3d kwq = gradMw[i]*(-Mw[j]*detJ); ke[10*i ][10*j+6] += kup.x; ke[10*i ][10*j+7] += kuq.x; ke[10*i+1][10*j+6] += kup.y; ke[10*i+1][10*j+7] += kuq.y; ke[10*i+2][10*j+6] += kup.z; ke[10*i+2][10*j+7] += kuq.z; ke[10*i+3][10*j+6] += kwp.x; ke[10*i+3][10*j+7] += kwq.x; ke[10*i+4][10*j+6] += kwp.y; ke[10*i+4][10*j+7] += kwq.y; ke[10*i+5][10*j+6] += kwp.z; ke[10*i+5][10*j+7] += kwq.z; // calculate the kuc matrix vec3d kuc = (dTdc*gradMu[i] - gradMu[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*Mu[j]*detJ; vec3d kud = (dTdc*gradMu[i] - gradMu[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*Mw[j]*detJ; vec3d kwc = (dTdc*gradMw[i] - gradMw[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*Mu[j]*detJ; vec3d kwd = (dTdc*gradMw[i] - gradMw[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*Mw[j]*detJ; ke[10*i ][10*j+8] += kuc.x; ke[10*i ][10*j+9] += kud.x; ke[10*i+1][10*j+8] += kuc.y; ke[10*i+1][10*j+9] += kud.y; ke[10*i+2][10*j+8] += kuc.z; ke[10*i+2][10*j+9] += kud.z; ke[10*i+3][10*j+8] += kwc.x; ke[10*i+3][10*j+9] += kwd.x; ke[10*i+4][10*j+8] += kwc.y; ke[10*i+4][10*j+9] += kwd.y; ke[10*i+5][10*j+8] += kwc.z; ke[10*i+5][10*j+9] += kwd.z; // calculate the kpu matrix gp = gradp+(D*gradc)*R*T*kappa/D0; wu = vdotTdotv(-gp, dKedE, gradMu[j]) -(((Ke*(D*gradc)) & gradMu[j])*(J*dkdJ - kappa) +Ke*(2*kappa*(gradMu[j]*(D*gradc))))*R*T/D0 - Ke*vdotTdotv(gradc, dDdE, gradMu[j])*(kappa*R*T/D0); ww = vdotTdotv(-gp, dKedE, gradMw[j]) -(((Ke*(D*gradc)) & gradMw[j])*(J*dkdJ - kappa) +Ke*(2*kappa*(gradMw[j]*(D*gradc))))*R*T/D0 - Ke*vdotTdotv(gradc, dDdE, gradMw[j])*(kappa*R*T/D0); qpu = -gradMu[j]*(1.0/dt); qpw = -gradMw[j]*(1.0/dt); vec3d kpu = (wu.transpose()*gradMu[i] + qpu*Mu[i])*(detJ*dt); vec3d kpw = (ww.transpose()*gradMu[i] + qpw*Mu[i])*(detJ*dt); vec3d kqu = (wu.transpose()*gradMw[i] + qpu*Mw[i])*(detJ*dt); vec3d kqw = (ww.transpose()*gradMw[i] + qpw*Mw[i])*(detJ*dt); ke[10*i+6][10*j ] += kpu.x; ke[10*i+6][10*j+1] += kpu.y; ke[10*i+6][10*j+2] += kpu.z; ke[10*i+6][10*j+3] += kpw.x; ke[10*i+6][10*j+4] += kpw.y; ke[10*i+6][10*j+5] += kpw.z; ke[10*i+7][10*j ] += kqu.x; ke[10*i+7][10*j+1] += kqu.y; ke[10*i+7][10*j+2] += kqu.z; ke[10*i+7][10*j+3] += kqw.x; ke[10*i+7][10*j+4] += kqw.y; ke[10*i+7][10*j+5] += kqw.z; // calculate the kpp matrix ke[10*i+6][10*j+6] -= gradMu[i]*(Ke*gradMu[j])*(detJ*dt); ke[10*i+6][10*j+7] -= gradMu[i]*(Ke*gradMw[j])*(detJ*dt); ke[10*i+7][10*j+6] -= gradMw[i]*(Ke*gradMu[j])*(detJ*dt); ke[10*i+7][10*j+7] -= gradMw[i]*(Ke*gradMw[j])*(detJ*dt); // calculate the kpc matrix wc = (dKedc*gp)*(-Mu[j]) -Ke*((((D*(dkdc-kappa*dD0dc/D0)+dDdc*kappa)*gradc)*Mu[j] +(D*gradMu[j])*kappa)*(R*T/D0)); wd = (dKedc*gp)*(-Mw[j]) -Ke*((((D*(dkdc-kappa*dD0dc/D0)+dDdc*kappa)*gradc)*Mw[j] +(D*gradMw[j])*kappa)*(R*T/D0)); ke[10*i+6][10*j+8] += (gradMu[i]*wc)*(detJ*dt); ke[10*i+6][10*j+9] += (gradMu[i]*wd)*(detJ*dt); ke[10*i+7][10*j+8] += (gradMw[i]*wc)*(detJ*dt); ke[10*i+7][10*j+9] += (gradMw[i]*wd)*(detJ*dt); // calculate the kcu matrix gc = -gradc*phiw + w*c/D0; ju = ((D*gc) & gradMu[j])*(J*dkdJ) + vdotTdotv(gc, dDdE, gradMu[j])*kappa + (((D*gradc) & gradMu[j])*(-phis) +(D*((gradMu[j]*w)*2) - ((D*w) & gradMu[j]))*c/D0 )*kappa +D*wu*(kappa*c/D0); jw = ((D*gc) & gradMw[j])*(J*dkdJ) + vdotTdotv(gc, dDdE, gradMw[j])*kappa + (((D*gradc) & gradMw[j])*(-phis) +(D*((gradMw[j]*w)*2) - ((D*w) & gradMw[j]))*c/D0 )*kappa +D*ww*(kappa*c/D0); qcu = qpu*(c*(kappa+J*phiw*dkdJ)); qcw = qpw*(c*(kappa+J*phiw*dkdJ)); vec3d kcu = (ju.transpose()*gradMu[i] + qcu*Mu[i])*(detJ*dt); vec3d kcw = (jw.transpose()*gradMu[i] + qcw*Mu[i])*(detJ*dt); vec3d kdu = (ju.transpose()*gradMw[i] + qcu*Mw[i])*(detJ*dt); vec3d kdw = (jw.transpose()*gradMw[i] + qcw*Mw[i])*(detJ*dt); ke[10*i+8][10*j ] += kcu.x; ke[10*i+8][10*j+1] += kcu.y; ke[10*i+8][10*j+2] += kcu.z; ke[10*i+8][10*j+3] += kcw.x; ke[10*i+8][10*j+4] += kcw.y; ke[10*i+8][10*j+5] += kcw.z; ke[10*i+9][10*j ] += kdu.x; ke[10*i+9][10*j+1] += kdu.y; ke[10*i+9][10*j+2] += kdu.z; ke[10*i+9][10*j+3] += kdw.x; ke[10*i+9][10*j+4] += kdw.y; ke[10*i+9][10*j+5] += kdw.z; // calculate the kcp matrix ke[10*i+8][10*j+6] -= (gradMu[i]*((D*Ke)*gradMu[j]))*(kappa*c/D0)*(detJ*dt); ke[10*i+8][10*j+7] -= (gradMu[i]*((D*Ke)*gradMw[j]))*(kappa*c/D0)*(detJ*dt); ke[10*i+9][10*j+6] -= (gradMw[i]*((D*Ke)*gradMu[j]))*(kappa*c/D0)*(detJ*dt); ke[10*i+9][10*j+7] -= (gradMw[i]*((D*Ke)*gradMw[j]))*(kappa*c/D0)*(detJ*dt); // calculate the kcc matrix jc = (D*(-gradMu[j]*phiw+w*(Mu[j]/D0)))*kappa +((D*dkdc+dDdc*kappa)*gc)*Mu[j] +(D*(w*(-Mu[j]*dD0dc/D0)+wc))*(kappa*c/D0); jd = (D*(-gradMw[j]*phiw+w*(Mw[j]/D0)))*kappa +((D*dkdc+dDdc*kappa)*gc)*Mw[j] +(D*(w*(-Mw[j]*dD0dc/D0)+wd))*(kappa*c/D0); qcc = -Mu[j]*phiw/dt*(c*dkdc + kappa); qcd = -Mw[j]*phiw/dt*(c*dkdc + kappa); ke[10*i+8][10*j+8] += (gradMu[i]*jc + Mu[i]*qcc)*(detJ*dt); ke[10*i+8][10*j+9] += (gradMu[i]*jd + Mu[i]*qcd)*(detJ*dt); ke[10*i+9][10*j+8] += (gradMw[i]*jc + Mw[i]*qcc)*(detJ*dt); ke[10*i+9][10*j+9] += (gradMw[i]*jd + Mw[i]*qcd)*(detJ*dt); } } } // Enforce symmetry by averaging top-right and bottom-left corners of stiffness matrix if (bsymm) { for (i=0; i<5*neln; ++i) for (j=i+1; j<5*neln; ++j) { tmp = 0.5*(ke[i][j]+ke[j][i]); ke[i][j] = ke[j][i] = tmp; } } return true; } //----------------------------------------------------------------------------- //! calculates element stiffness matrix for element iel //! for steady-state response (zero solid velocity, zero time derivative of //! solute concentration) //! bool FEBiphasicSoluteShellDomain::ElementBiphasicSoluteStiffnessSS(FEShellElement& el, matrix& ke, bool bsymm) { int i, j, n; int nint = el.GaussPoints(); int neln = el.Nodes(); double dt = GetFEModel()->GetTime().timeIncrement; const double* Mr, *Ms, *M; // jacobian double Ji[3][3], detJ; // Gradient of shape functions vector<vec3d> gradMu(neln), gradMw(neln); vector<double> Mu(neln), Mw(neln); vec3d gradM; double tmp; // gauss-weights double* gw = el.GaussWeights(); double eta; vec3d gcnt[3]; // zero stiffness matrix ke.zero(); // loop over gauss-points for (n=0; n<nint; ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint >()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint >()); // calculate jacobian detJ = invjact(el, Ji, n)*gw[n]; vec3d g1(Ji[0][0],Ji[0][1],Ji[0][2]); vec3d g2(Ji[1][0],Ji[1][1],Ji[1][2]); vec3d g3(Ji[2][0],Ji[2][1],Ji[2][2]); eta = el.gt(n); Mr = el.Hr(n); Ms = el.Hs(n); M = el.H(n); ContraBaseVectors(el, n, gcnt); // calculate global gradient of shape functions for (i=0; i<neln; ++i) { // calculate global gradient of shape functions gradM = gcnt[0]*Mr[i] + gcnt[1]*Ms[i]; gradMu[i] = (gradM*(1+eta) + gcnt[2]*M[i])/2; gradMw[i] = (gradM*(1-eta) - gcnt[2]*M[i])/2; Mu[i] = (1+eta)/2*M[i]; Mw[i] = (1-eta)/2*M[i]; } // get stress tensor mat3ds s = ept.m_s; // get elasticity tensor tens4ds C = m_pMat->Tangent(mp); // get the fluid flux and pressure gradient vec3d gradp = ppt.m_gradp; vec3d w = ppt.m_w; // evaluate the permeability and its derivatives mat3ds K = m_pMat->GetPermeability()->Permeability(mp); tens4dmm dKdE = m_pMat->GetPermeability()->Tangent_Permeability_Strain(mp); mat3ds dKdc = m_pMat->GetPermeability()->Tangent_Permeability_Concentration(mp, 0); // next we get the determinant double J = ept.m_J; // get the fluid flux and pressure gradient // get the effective concentration, its gradient and its time derivative double c = spt.m_c[0]; vec3d gradc = spt.m_gradc[0]; // evaluate the porosity and its derivative double phiw = m_pMat->Porosity(mp); double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the solubility and its derivatives double kappa = spt.m_k[0]; double dkdJ = spt.m_dkdJ[0]; double dkdc = spt.m_dkdc[0][0]; // evaluate the diffusivity tensor and its derivatives mat3ds D = m_pMat->GetSolute()->m_pDiff->Diffusivity(mp); mat3ds dDdc = m_pMat->GetSolute()->m_pDiff->Tangent_Diffusivity_Concentration(mp, 0); tens4dmm dDdE = m_pMat->GetSolute()->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity double D0 = m_pMat->GetSolute()->m_pDiff->Free_Diffusivity(mp); double dD0dc = m_pMat->GetSolute()->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,0); // evaluate the osmotic coefficient and its derivatives double osmc = m_pMat->GetOsmoticCoefficient()->OsmoticCoefficient(mp); double dodc = m_pMat->GetOsmoticCoefficient()->Tangent_OsmoticCoefficient_Concentration(mp, 0); // evaluate the stress tangent with concentration // mat3ds dTdc = pm->GetSolid()->Tangent_Concentration(mp, 0); mat3ds dTdc(0,0,0,0,0,0); // Miscellaneous constants mat3dd I(1); double R = m_pMat->m_Rgas; double T = m_pMat->m_Tabs; // evaluate the effective permeability and its derivatives mat3ds Ki = K.inverse(); mat3ds ImD = I-D/D0; mat3ds Ke = (Ki + ImD*(R*T*kappa*c/phiw/D0)).inverse(); tens4d G = (dyad1(Ki,I) - dyad4(Ki,I)*2)*2 - ddot(dyad2(Ki,Ki),dKdE) +dyad1(ImD,I)*(R*T*c*J/D0/phiw*(dkdJ-kappa/phiw*dpdJ)) +(dyad1(I,I) - dyad2(I,I)*2 - dDdE/D0)*(R*T*kappa*c/phiw/D0); tens4d dKedE = (dyad1(Ke,I) - 2*dyad4(Ke,I))*2 - ddot(dyad2(Ke,Ke),G); mat3ds Gc = -(Ki*dKdc*Ki).sym() + ImD*(R*T/phiw/D0*(dkdc*c+kappa-kappa*c/D0*dD0dc)) +R*T*kappa*c/phiw/D0/D0*(D*dD0dc/D0 - dDdc); mat3ds dKedc = -(Ke*Gc*Ke).sym(); // evaluate the tangents of solute supply double dcrhatdJ = 0; double dcrhatdc = 0; if (m_pMat->GetSolute()->m_pSupp) { dcrhatdJ = m_pMat->GetSolute()->m_pSupp->Tangent_Supply_Strain(mp); double dcrhatdcr = m_pMat->GetSolute()->m_pSupp->Tangent_Supply_Concentration(mp); dcrhatdc = J*phiw*(kappa + c*dkdc)*dcrhatdcr; } // calculate all the matrices vec3d vtmp,gp,gc,wc,wd,jc,jd; mat3d wu,ww,ju,jw; for (i=0; i<neln; ++i) { for (j=0; j<neln; ++j) { // Kuu matrix mat3d Kuu = (mat3dd(gradMu[i]*(s*gradMu[j])) + vdotTdotv(gradMu[i], C, gradMu[j]))*detJ; mat3d Kuw = (mat3dd(gradMu[i]*(s*gradMw[j])) + vdotTdotv(gradMu[i], C, gradMw[j]))*detJ; mat3d Kwu = (mat3dd(gradMw[i]*(s*gradMu[j])) + vdotTdotv(gradMw[i], C, gradMu[j]))*detJ; mat3d Kww = (mat3dd(gradMw[i]*(s*gradMw[j])) + vdotTdotv(gradMw[i], C, gradMw[j]))*detJ; ke[10*i ][10*j ] += Kuu[0][0]; ke[10*i ][10*j+1] += Kuu[0][1]; ke[10*i ][10*j+2] += Kuu[0][2]; ke[10*i+1][10*j ] += Kuu[1][0]; ke[10*i+1][10*j+1] += Kuu[1][1]; ke[10*i+1][10*j+2] += Kuu[1][2]; ke[10*i+2][10*j ] += Kuu[2][0]; ke[10*i+2][10*j+1] += Kuu[2][1]; ke[10*i+2][10*j+2] += Kuu[2][2]; ke[10*i ][10*j+3] += Kuw[0][0]; ke[10*i ][10*j+4] += Kuw[0][1]; ke[10*i ][10*j+5] += Kuw[0][2]; ke[10*i+1][10*j+3] += Kuw[1][0]; ke[10*i+1][10*j+4] += Kuw[1][1]; ke[10*i+1][10*j+5] += Kuw[1][2]; ke[10*i+2][10*j+3] += Kuw[2][0]; ke[10*i+2][10*j+4] += Kuw[2][1]; ke[10*i+2][10*j+5] += Kuw[2][2]; ke[10*i+3][10*j ] += Kwu[0][0]; ke[10*i+3][10*j+1] += Kwu[0][1]; ke[10*i+3][10*j+2] += Kwu[0][2]; ke[10*i+4][10*j ] += Kwu[1][0]; ke[10*i+4][10*j+1] += Kwu[1][1]; ke[10*i+4][10*j+2] += Kwu[1][2]; ke[10*i+5][10*j ] += Kwu[2][0]; ke[10*i+5][10*j+1] += Kwu[2][1]; ke[10*i+5][10*j+2] += Kwu[2][2]; ke[10*i+3][10*j+3] += Kww[0][0]; ke[10*i+3][10*j+4] += Kww[0][1]; ke[10*i+3][10*j+5] += Kww[0][2]; ke[10*i+4][10*j+3] += Kww[1][0]; ke[10*i+4][10*j+4] += Kww[1][1]; ke[10*i+4][10*j+5] += Kww[1][2]; ke[10*i+5][10*j+3] += Kww[2][0]; ke[10*i+5][10*j+4] += Kww[2][1]; ke[10*i+5][10*j+5] += Kww[2][2]; // calculate the kup matrix vec3d kup = gradMu[i]*(-Mu[j]*detJ); vec3d kuq = gradMu[i]*(-Mw[j]*detJ); vec3d kwp = gradMw[i]*(-Mu[j]*detJ); vec3d kwq = gradMw[i]*(-Mw[j]*detJ); ke[10*i ][10*j+6] += kup.z; ke[10*i ][10*j+7] += kuq.x; ke[10*i+1][10*j+6] += kup.y; ke[10*i+1][10*j+7] += kuq.y; ke[10*i+2][10*j+6] += kup.z; ke[10*i+2][10*j+7] += kuq.z; ke[10*i+3][10*j+6] += kwp.x; ke[10*i+3][10*j+7] += kwq.x; ke[10*i+4][10*j+6] += kwp.y; ke[10*i+4][10*j+7] += kwq.y; ke[10*i+5][10*j+6] += kwp.z; ke[10*i+5][10*j+7] += kwq.z; // calculate the kuc matrix vec3d kuc = (dTdc*gradMu[i] - gradMu[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*Mu[j]*detJ; vec3d kud = (dTdc*gradMu[i] - gradMu[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*Mw[j]*detJ; vec3d kwc = (dTdc*gradMw[i] - gradMw[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*Mu[j]*detJ; vec3d kwd = (dTdc*gradMw[i] - gradMw[i]*(R*T*(dodc*kappa*c+osmc*dkdc*c+osmc*kappa)))*Mw[j]*detJ; ke[10*i ][10*j+8] += kuc.z; ke[10*i ][10*j+9] += kud.x; ke[10*i+1][10*j+8] += kuc.y; ke[10*i+1][10*j+9] += kud.y; ke[10*i+2][10*j+8] += kuc.z; ke[10*i+2][10*j+9] += kud.z; ke[10*i+3][10*j+8] += kwc.x; ke[10*i+3][10*j+9] += kwd.x; ke[10*i+4][10*j+8] += kwc.y; ke[10*i+4][10*j+9] += kwd.y; ke[10*i+5][10*j+8] += kwc.z; ke[10*i+5][10*j+9] += kwd.z; // calculate the kpu matrix gp = gradp+(D*gradc)*R*T*kappa/D0; wu = vdotTdotv(-gp, dKedE, gradMu[j]) -(((Ke*(D*gradc)) & gradMu[j])*(J*dkdJ - kappa) +Ke*(2*kappa*(gradMu[j]*(D*gradc))))*R*T/D0 - Ke*vdotTdotv(gradc, dDdE, gradMu[j])*(kappa*R*T/D0); ww = vdotTdotv(-gp, dKedE, gradMw[j]) -(((Ke*(D*gradc)) & gradMw[j])*(J*dkdJ - kappa) +Ke*(2*kappa*(gradMw[j]*(D*gradc))))*R*T/D0 - Ke*vdotTdotv(gradc, dDdE, gradMw[j])*(kappa*R*T/D0); vec3d kpu = (wu.transpose()*gradMu[i])*(detJ*dt); vec3d kpw = (ww.transpose()*gradMu[i])*(detJ*dt); vec3d kqu = (wu.transpose()*gradMw[i])*(detJ*dt); vec3d kqw = (ww.transpose()*gradMw[i])*(detJ*dt); ke[10*i+6][10*j ] += kpu.x; ke[10*i+6][10*j+1] += kpu.y; ke[10*i+6][10*j+2] += kpu.z; ke[10*i+6][10*j+3] += kpw.x; ke[10*i+6][10*j+4] += kpw.y; ke[10*i+6][10*j+5] += kpw.z; ke[10*i+7][10*j ] += kqu.x; ke[10*i+7][10*j+1] += kqu.y; ke[10*i+7][10*j+2] += kqu.z; ke[10*i+7][10*j+3] += kqw.x; ke[10*i+7][10*j+4] += kqw.y; ke[10*i+7][10*j+5] += kqw.z; // calculate the kpp matrix ke[10*i+6][10*j+6] -= gradMu[i]*(Ke*gradMu[j])*(detJ*dt); ke[10*i+6][10*j+7] -= gradMu[i]*(Ke*gradMw[j])*(detJ*dt); ke[10*i+7][10*j+6] -= gradMw[i]*(Ke*gradMu[j])*(detJ*dt); ke[10*i+7][10*j+7] -= gradMw[i]*(Ke*gradMw[j])*(detJ*dt); // calculate the kpc matrix wc = (dKedc*gp)*(-Mu[j]) -Ke*((((D*(dkdc-kappa*dD0dc/D0)+dDdc*kappa)*gradc)*Mu[j] +(D*gradMu[j])*kappa)*(R*T/D0)); wd = (dKedc*gp)*(-Mw[j]) -Ke*((((D*(dkdc-kappa*dD0dc/D0)+dDdc*kappa)*gradc)*Mw[j] +(D*gradMw[j])*kappa)*(R*T/D0)); ke[10*i+6][10*j+8] += (gradMu[i]*wc)*(detJ*dt); ke[10*i+6][10*j+9] += (gradMu[i]*wd)*(detJ*dt); ke[10*i+7][10*j+8] += (gradMw[i]*wc)*(detJ*dt); ke[10*i+7][10*j+9] += (gradMw[i]*wd)*(detJ*dt); // calculate the kcu matrix gc = -gradc*phiw + w*c/D0; ju = ((D*gc) & gradMu[j])*(J*dkdJ) + vdotTdotv(gc, dDdE, gradMu[j])*kappa + (((D*gradc) & gradMu[j])*(-phis) +(D*((gradMu[j]*w)*2) - ((D*w) & gradMu[j]))*c/D0 )*kappa +D*wu*(kappa*c/D0); jw = ((D*gc) & gradMw[j])*(J*dkdJ) + vdotTdotv(gc, dDdE, gradMw[j])*kappa + (((D*gradc) & gradMw[j])*(-phis) +(D*((gradMw[j]*w)*2) - ((D*w) & gradMw[j]))*c/D0 )*kappa +D*ww*(kappa*c/D0); vec3d kcu = (ju.transpose()*gradMu[i])*(detJ*dt); vec3d kcw = (jw.transpose()*gradMu[i])*(detJ*dt); vec3d kdu = (ju.transpose()*gradMw[i])*(detJ*dt); vec3d kdw = (jw.transpose()*gradMw[i])*(detJ*dt); ke[10*i+8][10*j ] += kcu.x; ke[10*i+8][10*j+1] += kcu.y; ke[10*i+8][10*j+2] += kcu.z; ke[10*i+8][10*j+3] += kcw.x; ke[10*i+8][10*j+4] += kcw.y; ke[10*i+8][10*j+5] += kcw.z; ke[10*i+9][10*j ] += kdu.x; ke[10*i+9][10*j+1] += kdu.y; ke[10*i+9][10*j+2] += kdu.z; ke[10*i+9][10*j+3] += kdw.x; ke[10*i+9][10*j+4] += kdw.y; ke[10*i+9][10*j+5] += kdw.z; // calculate the kcp matrix ke[10*i+8][10*j+6] -= (gradMu[i]*((D*Ke)*gradMu[j]))*(kappa*c/D0)*(detJ*dt); ke[10*i+8][10*j+7] -= (gradMu[i]*((D*Ke)*gradMw[j]))*(kappa*c/D0)*(detJ*dt); ke[10*i+9][10*j+6] -= (gradMw[i]*((D*Ke)*gradMu[j]))*(kappa*c/D0)*(detJ*dt); ke[10*i+9][10*j+7] -= (gradMw[i]*((D*Ke)*gradMw[j]))*(kappa*c/D0)*(detJ*dt); // calculate the kcc matrix jc = (D*(-gradMu[j]*phiw+w*(Mu[j]/D0)))*kappa +((D*dkdc+dDdc*kappa)*gc)*Mu[j] +(D*(w*(-Mu[j]*dD0dc/D0)+wc))*(kappa*c/D0); jd = (D*(-gradMw[j]*phiw+w*(Mw[j]/D0)))*kappa +((D*dkdc+dDdc*kappa)*gc)*Mw[j] +(D*(w*(-Mw[j]*dD0dc/D0)+wd))*(kappa*c/D0); ke[10*i+8][10*j+8] += (gradMu[i]*jc)*(detJ*dt); ke[10*i+8][10*j+9] += (gradMu[i]*jd)*(detJ*dt); ke[10*i+9][10*j+8] += (gradMw[i]*jc)*(detJ*dt); ke[10*i+9][10*j+9] += (gradMw[i]*jd)*(detJ*dt); } } } // Enforce symmetry by averaging top-right and bottom-left corners of stiffness matrix if (bsymm) { for (i=0; i<5*neln; ++i) for (j=i+1; j<5*neln; ++j) { tmp = 0.5*(ke[i][j]+ke[j][i]); ke[i][j] = ke[j][i] = tmp; } } return true; } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::Update(const FETimeInfo& tp) { FESSIShellDomain::Update(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); } catch (NegativeJacobian e) { #pragma omp critical { berr = true; if (e.DoOutput()) feLogError(e.what()); } } } if (berr) throw NegativeJacobianDetected(); } //----------------------------------------------------------------------------- void FEBiphasicSoluteShellDomain::UpdateElementStress(int iel) { FEModel& fem = *GetFEModel(); double dt = fem.GetTime().timeIncrement; bool sstate = (fem.GetCurrentStep()->m_nanalysis == FEBiphasicAnalysis::STEADY_STATE); // get the solid element FEShellElement& el = m_Elem[iel]; // get the number of integration points int nint = el.GaussPoints(); // get the number of nodes int neln = el.Nodes(); // get the biphasic-solute material int id0 = m_pMat->GetSolute()->GetSoluteDOF(); // get the nodal data FEMesh& mesh = *m_pMesh; vec3d r0[FEElement::MAX_NODES]; vec3d rt[FEElement::MAX_NODES]; double pn[FEElement::MAX_NODES], qn[FEElement::MAX_NODES]; double cn[FEElement::MAX_NODES], dn[FEElement::MAX_NODES]; for (int j=0; j<neln; ++j) { r0[j] = mesh.Node(el.m_node[j]).m_r0; rt[j] = mesh.Node(el.m_node[j]).m_rt; pn[j] = mesh.Node(el.m_node[j]).get(m_dofP); qn[j] = mesh.Node(el.m_node[j]).get(m_dofQ); cn[j] = mesh.Node(el.m_node[j]).get(m_dofC + id0); dn[j] = mesh.Node(el.m_node[j]).get(m_dofD + id0); } // 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>()); // material point coordinates // TODO: I'm not entirly happy with this solution // since the material point coordinates are used by most materials. mp.m_r0 = el.Evaluate(r0, n); mp.m_rt = el.Evaluate(rt, n); // get the deformation gradient and determinant pt.m_J = defgrad(el, pt.m_F, n); mat3d Fp; defgradp(el, Fp, n); mat3d Fi = pt.m_F.inverse(); pt.m_L = (pt.m_F - Fp)*Fi / dt; // biphasic-solute data FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); // evaluate fluid pressure at gauss-point ppt.m_p = evaluate(el, pn, qn, n); // calculate the gradient of p at gauss-point ppt.m_gradp = gradient(el, pn, qn, n); // evaluate effective solute concentration at gauss-point spt.m_c[0] = evaluate(el, cn, dn, n); // calculate the gradient of c at gauss-point spt.m_gradc[0] = gradient(el, cn, dn, n); // for biphasic-solute materials also update the porosity, fluid and solute fluxes // and evaluate the actual fluid pressure and solute concentration ppt.m_w = m_pMat->FluidFlux(mp); ppt.m_pa = m_pMat->Pressure(mp); spt.m_j[0] = m_pMat->SoluteFlux(mp); spt.m_ca[0] = m_pMat->Concentration(mp); if (m_pMat->GetSolute()->m_pSupp) { if (sstate) spt.m_sbmr[0] = m_pMat->GetSolute()->m_pSupp->ReceptorLigandConcentrationSS(mp); else { // update m_crc using midpoint rule spt.m_sbmrhat[0] = m_pMat->GetSolute()->m_pSupp->ReceptorLigandSupply(mp); spt.m_sbmr[0] = spt.m_sbmrp[0] + (spt.m_sbmrhat[0]+spt.m_sbmrhatp[0])/2*dt; // update phi0 using backward difference integration // NOTE: MolarMass was removed since not used ppt.m_phi0hat = 0; // ppt.m_phi0hat = pmb->GetSolid()->MolarMass()/pmb->GetSolid()->Density()*pmb->GetSolute()->m_pSupp->SolidSupply(mp); ppt.m_phi0t = ppt.m_phi0p + ppt.m_phi0hat*dt; } } m_pMat->PartitionCoefficientFunctions(mp, spt.m_k[0], spt.m_dkdJ[0], spt.m_dkdc[0][0]); // update specialized material points m_pMat->UpdateSpecializedMaterialPoints(mp, GetFEModel()->GetTime()); // calculate the solid stress at this material point ppt.m_ss = m_pMat->GetElasticMaterial()->Stress(mp); // calculate the stress at this material point (must be done after evaluating m_pa) pt.m_s = m_pMat->Stress(mp); } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEFiberExpPowSBM.cpp
.cpp
9,796
308
/*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 "FEFiberExpPowSBM.h" #include "FEMultiphasic.h" #include <FECore/log.h> #include <FEBioMech/FEElasticMixture.h> // define the material parameters BEGIN_FECORE_CLASS(FEFiberExpPowSBM, 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_ksi0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "ksi0" )->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_rho0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "rho0" )->setUnits(UNIT_DENSITY); ADD_PARAMETER(m_g , FE_RANGE_GREATER_OR_EQUAL(0.0), "gamma"); ADD_PARAMETER(m_sbm , "sbm")->setEnums("$(sbms)"); ADD_PROPERTY(m_fiber, "fiber"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- // FEFiberExpPow //----------------------------------------------------------------------------- bool FEFiberExpPowSBM::Init() { if (FEElasticMaterial::Init() == false) return false; // get the parent material which must be a multiphasic material FEMultiphasic* pMP = dynamic_cast<FEMultiphasic*> (GetAncestor()); if (pMP == 0) { feLogError("Parent material must be multiphasic"); return false; } // extract the local id of the SBM whose density controls Young's modulus from the global id m_lsbm = pMP->FindLocalSBMID(m_sbm); if (m_lsbm == -1) { feLogError("Invalid value for sbm"); return false; } FEElasticMaterial* pem = pMP->GetSolid(); FEElasticMixture* psm = dynamic_cast<FEElasticMixture*>(pem); if (psm == nullptr) m_comp = -1; // in case material is not a solid mixture for (int i=0; i<psm->Materials(); ++i) { pem = psm->GetMaterial(i); if (pem == this) { m_comp = i; break; } } return true; } //----------------------------------------------------------------------------- //! Create material point data FEMaterialPointData* FEFiberExpPowSBM::CreateMaterialPointData() { return new FERemodelingMaterialPoint(new FEElasticMaterialPoint); } //----------------------------------------------------------------------------- //! update specialize material point data void FEFiberExpPowSBM::UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); FERemodelingMaterialPoint* rpt = mp.ExtractData<FERemodelingMaterialPoint>(); rpt->m_rhor = spt.m_sbmr[m_lsbm]; rpt->m_rhorp = spt.m_sbmrp[m_lsbm]; rpt->m_sed = StrainEnergyDensity(mp); } //----------------------------------------------------------------------------- mat3ds FEFiberExpPowSBM::Stress(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); // initialize material constants double rhor = spt.m_sbmr[m_lsbm]; double ksi = FiberModulus(mp, rhor); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; // loop over all integration points vec3d nt; double In_1, Wl; const double eps = 0; mat3ds C = pt.RightCauchyGreen(); mat3ds s; // get the material coordinate system mat3d Q = GetLocalCS(mp); // get local fiber direction vec3d fiber = m_fiber->unitVector(mp); // convert to global coordinates vec3d n0 = Q*fiber; // Calculate In = n0*C*n0 In_1 = n0*(C*n0) - 1.0; // only take fibers in tension into consideration if (In_1 >= eps) { double alpha = m_alpha(mp); double beta = m_beta(mp); // get the global spatial fiber direction in current configuration nt = F*n0; // calculate the outer product of nt mat3ds N = dyad(nt); // calculate strain energy derivative Wl = ksi*pow(In_1, beta-1.0)*exp(alpha*pow(In_1, beta)); // calculate the fiber stress s = N*(2.0*Wl/J); } else { s.zero(); } return s; } //----------------------------------------------------------------------------- tens4ds FEFiberExpPowSBM::Tangent(FEMaterialPoint& mp) { FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); // initialize material constants double rhor = spt.m_sbmr[m_lsbm]; double ksi = FiberModulus(mp, rhor); // deformation gradient mat3d &F = pt.m_F; double J = pt.m_J; // loop over all integration points vec3d nt; double In_1, Wll; const double eps = 0; mat3ds C = pt.RightCauchyGreen(); tens4ds c; // get the material coordinate system mat3d Q = GetLocalCS(mp); // get local fiber direction vec3d fiber = m_fiber->unitVector(mp); // convert to global coordinates vec3d n0 = Q*fiber; // Calculate In = n0*C*n0 In_1 = n0*(C*n0) - 1.0; // only take fibers in tension into consideration if (In_1 >= eps) { double alpha = m_alpha(mp); double beta = m_beta(mp); // get the global spatial fiber direction in current configuration nt = F*n0; // calculate the outer product of nt mat3ds N = dyad(nt); tens4ds NxN = dyad1s(N); // calculate strain energy 2nd derivative double tmp = alpha*pow(In_1, beta); Wll = ksi*pow(In_1, beta-2.0)*((tmp+1)*beta-1.0)*exp(tmp); // calculate the fiber tangent c = NxN*(4.0*Wll/J); } else { c.zero(); } return c; } //----------------------------------------------------------------------------- double FEFiberExpPowSBM::StrainEnergyDensity(FEMaterialPoint& mp) { double sed = 0.0; FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); // initialize material constants double rhor = spt.m_sbmr[m_lsbm]; double ksi = FiberModulus(mp, rhor); // loop over all integration points double In_1; const double eps = 0; mat3ds C = pt.RightCauchyGreen(); // get the material coordinate system mat3d Q = GetLocalCS(mp); // get local fiber direction vec3d fiber = m_fiber->unitVector(mp); // convert to global coordinates vec3d n0 = Q*fiber; // Calculate In = n0*C*n0 In_1 = n0*(C*n0) - 1.0; // only take fibers in tension into consideration if (In_1 >= eps) { double alpha = m_alpha(mp); double beta = m_beta(mp); // calculate strain energy derivative if (alpha > 0) { sed = ksi/(alpha*beta)*(exp(alpha*pow(In_1, beta))-1); } else sed = ksi/beta*pow(In_1, beta); } return sed; } //----------------------------------------------------------------------------- //! evaluate referential mass density double FEFiberExpPowSBM::Density(FEMaterialPoint& pt) { FERemodelingMaterialPoint* rpt = pt.ExtractData<FERemodelingMaterialPoint>(); if (rpt) return rpt->m_rhor; else { FEElasticMixtureMaterialPoint* emp = pt.ExtractData<FEElasticMixtureMaterialPoint>(); if (emp) { rpt = emp->GetPointData(m_comp)->ExtractData<FERemodelingMaterialPoint>(); if (rpt) return rpt->m_rhor; } } return 0.0; } //----------------------------------------------------------------------------- //! calculate strain energy density at material point double FEFiberExpPowSBM::StrainEnergy(FEMaterialPoint& mp) { return StrainEnergyDensity(mp); } //----------------------------------------------------------------------------- //! calculate tangent of strain energy density with mass density double FEFiberExpPowSBM::Tangent_SE_Density(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; return StrainEnergy(mp)*m_g(mp)/rhor; } //----------------------------------------------------------------------------- //! calculate tangent of stress with mass density mat3ds FEFiberExpPowSBM::Tangent_Stress_Density(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; return Stress(mp)*m_g(mp)/rhor; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicMultigeneration.cpp
.cpp
11,896
300
/*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 "FEMultiphasicMultigeneration.h" // Material parameters for the FEMultiphasicMultigeneration material BEGIN_FECORE_CLASS(FEMultiphasicMultigeneration, FEMultiphasic) ADD_PARAMETER(m_gtime , FE_RANGE_GREATER(0.0), "gen_time"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! FEMultiphasicMultigeneration.h constructor FEMultiphasicMultigeneration::FEMultiphasicMultigeneration(FEModel* pfem) : FEMultiphasic(pfem) { m_gtime = 0; } //----------------------------------------------------------------------------- FEMaterialPointData* FEMultiphasicMultigeneration::CreateMaterialPointData() { return new FEMultigenSBMMaterialPoint (this, new FESolutesMaterialPoint (new FEBiphasicMaterialPoint (m_pSolid->CreateMaterialPointData()) ) ); } //-------------------------------------------------------------------------------- // Check if time t constitutes a new generation and return that generation int FEMultiphasicMultigeneration::CheckGeneration(const double t) { // each generation has the same length of time // there is always at least one generation int ngen = (int)(t/m_gtime)+1; return ngen; } //-------------------------------------------------------------------------------- // Return the starting time of a generation double FEMultiphasicMultigeneration::GetGenerationTime(const int igen) { return (igen-1)*m_gtime; } //----------------------------------------------------------------------------- void FEMultiphasicMultigeneration::UpdateSolidBoundMolecules(FEMaterialPoint& mp) { double dt = CurrentTimeIncrement(); // check if this mixture includes chemical reactions int nreact = (int)Reactions(); int mreact = (int)MembraneReactions(); if (nreact) { // for chemical reactions involving solid-bound molecules, // update their concentration // multiphasic material point data FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); FEMultigenSBMMaterialPoint& mpt = *(mp.ExtractData<FEMultigenSBMMaterialPoint>()); double phi0 = ppt.m_phi0t; int nsbm = SBMs(); int nsol = Solutes(); int ngen = mpt.m_ngen; for (int isbm=0; isbm<nsbm; ++isbm) { // initialize referential mass density supply spt.m_sbmrhat[isbm] = 0; // initialize referential mass density spt.m_sbmr[isbm] = spt.m_sbmrp[isbm]; // evaluate mass fraction of each generation before SBM update vector<double> mf(ngen,0.0); for (int igen=0; igen<ngen; ++igen) { mf[igen] = (spt.m_sbmr[isbm] > 0) ? mpt.m_gsbmr[igen][isbm]/spt.m_sbmr[isbm] : 0; // initialize generational referential mass density mpt.m_gsbmr[igen][isbm] = mpt.m_gsbmrp[igen][isbm]; } // for each reaction for (int k=0; k<nreact; ++k) { // evaluate the molar supply for this SBM double zetahat = GetReaction(k)->ReactionSupply(mp); double v = GetReaction(k)->m_v[nsol+isbm]; // remember to convert from molar supply to referential mass supply double sbmrhat = (pt.m_J-phi0)*SBMMolarMass(isbm)*v*zetahat; // combine the molar supplies from all the reactions spt.m_sbmrhat[isbm] += sbmrhat; // check if mass is added or removed if (sbmrhat >= 0) { // mass is added only to the current generation // perform the time integration (Euler's method) double dsbmr = dt*sbmrhat; // add this mass increment to the current generation mpt.m_gsbmr[ngen-1][isbm] += dsbmr; spt.m_sbmr[isbm] += dsbmr; // check bounds if ((spt.m_sbmrmax[isbm] > 0) && (spt.m_sbmr[isbm] > spt.m_sbmrmax[isbm])) { dsbmr = spt.m_sbmrmax[isbm] - spt.m_sbmr[isbm]; mpt.m_gsbmr[ngen-1][isbm] += dsbmr; spt.m_sbmr[isbm] += dsbmr; } } else { // mass is removed from all the generations in proportion to mass fraction // perform the time integration (Euler's method) double dsbmr = dt*sbmrhat; // add this (negative) weighted mass increment to all generations for (int igen=0; igen<ngen; ++igen) mpt.m_gsbmr[igen][isbm] += mf[igen]*dsbmr; spt.m_sbmr[isbm] += dsbmr; // check bounds if (spt.m_sbmr[isbm] < spt.m_sbmrmin[isbm]) { dsbmr = spt.m_sbmrmin[isbm] - spt.m_sbmr[isbm]; for (int igen=0; igen<ngen; ++igen) mpt.m_gsbmr[igen][isbm] += mf[igen]*dsbmr; spt.m_sbmr[isbm] += dsbmr; } } } // for each membrane reaction for (int k=0; k<mreact; ++k) { // evaluate the molar supply for this SBM double zetahat = GetMembraneReaction(k)->ReactionSupply(mp); double v = GetMembraneReaction(k)->m_v[nsol+isbm]; // remember to convert from molar supply to referential mass supply double sbmrhat = (pt.m_J-phi0)*SBMMolarMass(isbm)*v*zetahat; // combine the molar supplies from all the reactions spt.m_sbmrhat[isbm] += sbmrhat; // check if mass is added or removed if (sbmrhat >= 0) { // mass is added only to the current generation // perform the time integration (Euler's method) double dsbmr = dt*sbmrhat; // add this mass increment to the current generation mpt.m_gsbmr[ngen-1][isbm] += dsbmr; spt.m_sbmr[isbm] += dsbmr; // check bounds if ((spt.m_sbmrmax[isbm] > 0) && (spt.m_sbmr[isbm] > spt.m_sbmrmax[isbm])) { dsbmr = spt.m_sbmrmax[isbm] - spt.m_sbmr[isbm]; mpt.m_gsbmr[ngen-1][isbm] += dsbmr; spt.m_sbmr[isbm] += dsbmr; } } else { // mass is removed from all the generations in proportion to mass fraction // perform the time integration (Euler's method) double dsbmr = dt*sbmrhat; // add this (negative) weighted mass increment to all generations for (int igen=0; igen<ngen; ++igen) mpt.m_gsbmr[igen][isbm] += mf[igen]*dsbmr; spt.m_sbmr[isbm] += dsbmr; // check bounds if (spt.m_sbmr[isbm] < spt.m_sbmrmin[isbm]) { dsbmr = spt.m_sbmrmin[isbm] - spt.m_sbmr[isbm]; for (int igen=0; igen<ngen; ++igen) mpt.m_gsbmr[igen][isbm] += mf[igen]*dsbmr; spt.m_sbmr[isbm] += dsbmr; } } } } } } //============================================================================= // FEMultigenSBMMaterialPoint //============================================================================= //----------------------------------------------------------------------------- FEMaterialPointData* FEMultigenSBMMaterialPoint::Copy() { FEMultigenSBMMaterialPoint* pt = new FEMultigenSBMMaterialPoint(*this); pt->m_ngen = m_ngen; pt->m_nsbm = m_nsbm; pt->m_pmat = m_pmat; pt->m_Fi = m_Fi; pt->m_Ji = m_Ji; pt->m_gsbmr = m_gsbmr; pt->m_gsbmrp = m_gsbmrp; pt->m_lsbmr = m_lsbmr; pt->m_tgen = m_tgen; if (m_pNext) pt->m_pNext = m_pNext->Copy(); return pt; } //----------------------------------------------------------------------------- void FEMultigenSBMMaterialPoint::Serialize(DumpStream& ar) { FEMaterialPointData::Serialize(ar); ar & m_ngen & m_nsbm & m_tgen; ar & m_Fi; ar & m_Ji; ar & m_gsbmr & m_gsbmrp; ar & m_lsbmr; } //----------------------------------------------------------------------------- void FEMultigenSBMMaterialPoint::Init() { FEMaterialPointData::Init(); m_Fi.clear(); m_Ji.clear(); m_tgen = 0.0; FESolutesMaterialPoint& spt = *((*this).ExtractData<FESolutesMaterialPoint>()); m_nsbm = spt.m_nsbm; m_ngen = 1; // first generation starts at t=0 mat3d Fi(mat3dd(1.0)); double Ji = 1; m_Fi.push_back(Fi); m_Ji.push_back(Ji); m_lsbmr.resize(m_nsbm,0.0); m_gsbmr.push_back(m_lsbmr); m_gsbmrp.push_back(m_lsbmr); } //----------------------------------------------------------------------------- void FEMultigenSBMMaterialPoint::Update(const FETimeInfo& timeInfo) { FEMaterialPointData::Update(timeInfo); // get the time double t = timeInfo.currentTime; // Check if this constitutes a new generation int ngen = m_pmat->CheckGeneration(t); t = m_pmat->GetGenerationTime(ngen); if (t>m_tgen) { // new generation FEElasticMaterialPoint& pt = *((*this).ExtractData<FEElasticMaterialPoint>()); FESolutesMaterialPoint& spt = *((*this).ExtractData<FESolutesMaterialPoint>()); // push back F and J to define relative deformation gradient of this generation mat3d F = pt.m_F; double J = pt.m_J; m_Fi.push_back(F.inverse()); m_Ji.push_back(1.0/J); m_lsbmr = spt.m_sbmr; // sbmr content at start of generation vector<double> gsbmr(m_nsbm,0); // incremental sbmr content for this generation m_gsbmr.push_back(gsbmr); m_gsbmrp.push_back(gsbmr); m_tgen = t; ++m_ngen; } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEDiffRefIso.h
.h
2,756
71
/*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 "FEBiphasicSolute.h" //----------------------------------------------------------------------------- // This class implements a material that has a strain-dependent // diffusivity which is isotropic in the reference state, but exhibits // strain-induced anisotropy, according to the constitutive relation // of Ateshian and Weiss (JBME 2010) class FEBIOMIX_API FEDiffRefIso : public FESoluteDiffusivity { public: //! constructor FEDiffRefIso(FEModel* pfem); //! free diffusivity double Free_Diffusivity(FEMaterialPoint& pt) override; //! Tangent of free diffusivity with respect to concentration double Tangent_Free_Diffusivity_Concentration(FEMaterialPoint& pt, const int isol) override; //! diffusivity mat3ds Diffusivity(FEMaterialPoint& pt) override; //! Tangent of diffusivity with respect to strain tens4dmm Tangent_Diffusivity_Strain(FEMaterialPoint& mp) override; //! Tangent of diffusivity with respect to concentration mat3ds Tangent_Diffusivity_Concentration(FEMaterialPoint& mp, const int isol=0) override; public: FEParamDouble m_free_diff; //!< free diffusivity FEParamDouble m_diff0; //!< diffusivity for I term FEParamDouble m_diff1; //!< diffusivity for b term FEParamDouble m_diff2; //!< diffusivity for b^2 term FEParamDouble m_M; //!< nonlinear exponential coefficient FEParamDouble m_alpha; //!< nonlinear power exponent // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMassActionReversible.cpp
.cpp
7,704
241
/*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 "FEMassActionReversible.h" #include "FESoluteInterface.h" #include "FEBiphasic.h" BEGIN_FECORE_CLASS(FEMassActionReversible, FEChemicalReaction) // set material properties ADD_PROPERTY(m_pFwd, "forward_rate", FEProperty::Optional); ADD_PROPERTY(m_pRev, "reverse_rate", FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMassActionReversible::FEMassActionReversible(FEModel* pfem) : FEChemicalReaction(pfem) { } //----------------------------------------------------------------------------- //! molar supply at material point double FEMassActionReversible::FwdReactionSupply(FEMaterialPoint& pt) { // get forward reaction rate double k = m_pFwd->ReactionRate(pt); // evaluate the reaction molar supply double zhat = k; // start with contribution from solutes int nsol = (int) m_psm->Solutes(); for (int i=0; i<nsol; ++i) { int vR = m_vR[i]; if (vR > 0) { double c = m_psm->GetActualSoluteConcentration(pt, i); zhat *= pow(c, vR); } } // add contribution of solid-bound molecules const int nsbm = (int) m_psm->SBMs(); for (int i=0; i<nsbm; ++i) { int vR = m_vR[nsol+i]; if (vR > 0) { double c = m_psm->SBMConcentration(pt, i); zhat *= pow(c, vR); } } return zhat; } //----------------------------------------------------------------------------- //! molar supply at material point double FEMassActionReversible::RevReactionSupply(FEMaterialPoint& pt) { // get forward reaction rate double k = m_pRev->ReactionRate(pt); // evaluate the reaction molar supply double zhat = k; // start with contribution from solutes int nsol = m_psm->Solutes(); for (int i=0; i<nsol; ++i) { int vP = m_vP[i]; if (vP > 0) { double c = m_psm->GetActualSoluteConcentration(pt, i); zhat *= pow(c, vP); } } // add contribution of solid-bound molecules const int nsbm = m_psm->SBMs(); for (int i=0; i<nsbm; ++i) { int vP = m_vP[nsol+i]; if (vP > 0) { double c = m_psm->SBMConcentration(pt, i); zhat *= pow(c, vP); } } return zhat; } //----------------------------------------------------------------------------- //! molar supply at material point double FEMassActionReversible::ReactionSupply(FEMaterialPoint& pt) { double zhatF = FwdReactionSupply(pt); double zhatR = RevReactionSupply(pt); return zhatF - zhatR; } //----------------------------------------------------------------------------- //! tangent of molar supply with strain at material point mat3ds FEMassActionReversible::Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& ept = *pt.ExtractData<FEElasticMaterialPoint>(); const int nsol = m_nsol; const int nsbm = (int)m_v.size() - nsol; double J = ept.m_J; double phi0 = pbm->GetReferentialSolidVolumeFraction(pt); // forward reaction double kF = m_pFwd->ReactionRate(pt); mat3ds dkFde = m_pFwd->Tangent_ReactionRate_Strain(pt); double zhatF = FwdReactionSupply(pt); mat3ds dzhatFde = mat3dd(0); if (kF > 0) { dzhatFde += dkFde/kF; } mat3ds I = mat3dd(1); for (int isol=0; isol<nsol; ++isol) { double dkdJ = m_psm->dkdJ(pt, isol); double k = m_psm->GetPartitionCoefficient(pt, isol); dzhatFde += I*(m_vR[isol]*dkdJ/k); } for (int isbm = 0; isbm<nsbm; ++isbm) dzhatFde += I*(m_vR[nsol+isbm]/(J-phi0)); dzhatFde *= zhatF; // reverse reaction double kR = m_pRev->ReactionRate(pt); mat3ds dkRde = m_pRev->Tangent_ReactionRate_Strain(pt); double zhatR = RevReactionSupply(pt); mat3ds dzhatRde = mat3dd(0); if (kR > 0) { dzhatRde += dkRde/kR; } for (int isol=0; isol<nsol; ++isol) { double dkdJ = m_psm->dkdJ(pt, isol); double k = m_psm->GetPartitionCoefficient(pt, isol); dzhatRde += I*(m_vP[isol]*dkdJ/k); } for (int isbm = 0; isbm<nsbm; ++isbm) dzhatRde -= I*(m_vP[nsol+isbm]/(J-phi0)); dzhatRde *= zhatR; return dzhatFde - dzhatRde; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective pressure at material point double FEMassActionReversible::Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) { // forward reaction double kF = m_pFwd->ReactionRate(pt); double dzhatFdp = 0; if (kF > 0) { double dkFdp = m_pFwd->Tangent_ReactionRate_Pressure(pt); double zhatF = FwdReactionSupply(pt); dzhatFdp = dkFdp*zhatF/kF; } // reverse reaction double kR = m_pRev->ReactionRate(pt); double dzhatRdp = 0; if (kR > 0) { double dkRdp = m_pRev->Tangent_ReactionRate_Pressure(pt); double zhatR = RevReactionSupply(pt); dzhatRdp = dkRdp*zhatR/kR; } return dzhatFdp - dzhatRdp; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective concentration at material point double FEMassActionReversible::Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) { const int nsol = m_nsol; // if the derivative is taken with respect to a solid-bound molecule, return 0 if (sol >= nsol) { return 0; } // forward reaction double zhatF = FwdReactionSupply(pt); double dzhatFdc = 0; for (int isol=0; isol<nsol; ++isol) { double dkdc = m_psm->dkdc(pt, isol, sol); double k = m_psm->GetPartitionCoefficient(pt, isol); double c = m_psm->GetEffectiveSoluteConcentration(pt, sol); dzhatFdc += m_vR[isol]*dkdc/k; if ((isol == sol) && (c > 0)) dzhatFdc += m_vR[isol]/c; } dzhatFdc *= zhatF; // reverse reaction double zhatR = RevReactionSupply(pt); double dzhatRdc = 0; for (int isol=0; isol<nsol; ++isol) { double dkdc = m_psm->dkdc(pt, isol, sol); double k = m_psm->GetPartitionCoefficient(pt, isol); double c = m_psm->GetEffectiveSoluteConcentration(pt, sol); dzhatRdc += m_vP[isol]*dkdc/k; if ((isol == sol) && (c > 0)) dzhatRdc += m_vP[isol]/c; } dzhatRdc *= zhatR; return dzhatFdc - dzhatRdc; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicStandard.cpp
.cpp
4,388
96
/*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 "FEMultiphasicStandard.h" //----------------------------------------------------------------------------- //! FEMultiphasicStandard constructor FEMultiphasicStandard::FEMultiphasicStandard(FEModel* pfem) : FEMultiphasic(pfem) { } //----------------------------------------------------------------------------- FEMaterialPointData* FEMultiphasicStandard::CreateMaterialPointData() { return new FESolutesMaterialPoint(new FEBiphasicMaterialPoint(m_pSolid->CreateMaterialPointData())); } //----------------------------------------------------------------------------- // call this function from shell domains only void FEMultiphasicStandard::UpdateSolidBoundMolecules(FEMaterialPoint& mp) { double dt = CurrentTimeIncrement(); // check if this mixture includes chemical reactions int nreact = (int)Reactions(); int mreact = (int)MembraneReactions(); if (nreact || mreact) { // for chemical reactions involving solid-bound molecules, // update their concentration // multiphasic material point data FEElasticMaterialPoint& pt = *(mp.ExtractData<FEElasticMaterialPoint>()); FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); FEShellElement* sel = dynamic_cast<FEShellElement*>(mp.m_elem); double h = (sel) ? sel->Evaluate(sel->m_ht, mp.m_index) : 0; // shell thickness double phi0 = ppt.m_phi0t; int nsbm = SBMs(); int nsol = Solutes(); // create a temporary container for spt.m_sbmr so that this variable remains // unchanged as the reaction rates get calculated for each sbm. vector<double> sbmr = spt.m_sbmr; for (int isbm=0; isbm<nsbm; ++isbm) { spt.m_sbmrhat[isbm] = 0; // combine the molar supplies from all the reactions for (int k=0; k<nreact; ++k) { double zetahat = GetReaction(k)->ReactionSupply(mp); double v = GetReaction(k)->m_v[nsol+isbm]; // remember to convert from molar supply to referential mass supply spt.m_sbmrhat[isbm] += (pt.m_J-phi0)*SBMMolarMass(isbm)*v*zetahat; } for (int k=0; k<mreact; ++k) { double zetahat = GetMembraneReaction(k)->ReactionSupply(mp); double v = GetMembraneReaction(k)->m_v[nsol+isbm]; // remember to convert from molar supply to referential mass supply spt.m_sbmrhat[isbm] += pt.m_J/h*SBMMolarMass(isbm)*v*zetahat; } // perform the time integration (midpoint rule) sbmr[isbm] = spt.m_sbmrp[isbm] + dt*(spt.m_sbmrhat[isbm]+spt.m_sbmrhatp[isbm])/2; // check bounds if (sbmr[isbm] < spt.m_sbmrmin[isbm]) sbmr[isbm] = spt.m_sbmrmin[isbm]; if ((spt.m_sbmrmax[isbm] > 0) && (sbmr[isbm] > spt.m_sbmrmax[isbm])) sbmr[isbm] = spt.m_sbmrmax[isbm]; } // now update spt.m_sbmr spt.m_sbmr = sbmr; } }
C++
3D
febiosoftware/FEBio
FEBioMix/FECarterHayes.h
.h
3,602
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.*/ #pragma once #include "FEBioMech/FEElasticMaterial.h" #include "FEBioMech/FERemodelingElasticMaterial.h" #include "febiomix_api.h" //----------------------------------------------------------------------------- //! This is a neo-Hookean material whose Young's modulus is evaluated from the density //! according to the power-law relation proposed by Carter and Hayes for trabecular bone class FEBIOMIX_API FECarterHayes : public FEElasticMaterial, public FERemodelingInterface { public: FECarterHayes(FEModel* pfem) : FEElasticMaterial(pfem) { m_E0 = 0; m_rho0 = 1; m_sbm = -1; m_lsbm = -1; m_g = 0; } public: // parameters double m_E0; //!< Young's modulus at reference sbm density double m_g; //!< gamma exponent for calculation of Young's modulus double m_v; //!< prescribed Poisson's ratio double m_rho0; //!< reference sbm density // int m_sbm; //!< global id of solid-bound molecule protected: int m_lsbm; //!< local id of solid-bound molecule public: //! data initialization and checking bool Init() override; //! serialization void Serialize(DumpStream& ar) override; //! calculate stress at material point mat3ds Stress(FEMaterialPoint& pt) override; //! calculate tangent stiffness at material point tens4ds Tangent(FEMaterialPoint& pt) override; //! evaluate referential mass density double Density(FEMaterialPoint& pt) override; //! Create material point data FEMaterialPointData* CreateMaterialPointData() override; //! calculate strain energy density at material point double StrainEnergyDensity(FEMaterialPoint& pt) override { return StrainEnergy(pt); } //! update specialize material point data void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) override; public: // --- remodeling interface --- //! calculate strain energy density at material point double StrainEnergy(FEMaterialPoint& pt) override; //! calculate tangent of strain energy density with mass density double Tangent_SE_Density(FEMaterialPoint& pt) override; //! calculate tangent of stress with mass density mat3ds Tangent_Stress_Density(FEMaterialPoint& pt) override; //! return Young's modulus double YoungModulus(double rhor) { return m_E0*pow(rhor/m_rho0, m_g);} // declare the parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEOsmCoefConst.cpp
.cpp
2,546
68
/*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 "FEOsmCoefConst.h" //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEOsmCoefConst, FEOsmoticCoefficient) ADD_PARAMETER(m_osmcoef, FE_RANGE_GREATER_OR_EQUAL(0.0), "osmcoef")->setLongName("osmotic coefficient"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEOsmCoefConst::FEOsmCoefConst(FEModel* pfem) : FEOsmoticCoefficient(pfem) { m_osmcoef = 1; } //----------------------------------------------------------------------------- //! Osmotic coefficient double FEOsmCoefConst::OsmoticCoefficient(FEMaterialPoint& mp) { // --- constant osmotic coefficient --- return m_osmcoef; } //----------------------------------------------------------------------------- //! Tangent of osmotic coefficient with respect to strain double FEOsmCoefConst::Tangent_OsmoticCoefficient_Strain(FEMaterialPoint &mp) { return 0; } //----------------------------------------------------------------------------- //! Tangent of osmotic coefficient with respect to concentration double FEOsmCoefConst::Tangent_OsmoticCoefficient_Concentration(FEMaterialPoint &mp, const int isol) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEReaction.cpp
.cpp
5,617
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 "FEReaction.h" #include <FECore/log.h> #include "FESoluteInterface.h" #include "FESolute.h" #include <FECore/FEModel.h> //----------------------------------------------------------------------------- FEReaction::FEReaction(FEModel* pfem) : FEMaterialProperty(pfem) { m_psm = nullptr; } //----------------------------------------------------------------------------- bool FEReaction::Init() { // make sure the parent class is set m_psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); assert(m_psm); if (m_psm == 0) { feLogError("Parent class not set or of incorrect type"); return false; } // TODO: Why does calling the base class cause a crash in cr02??? return true;// FEMaterialProperty::Init(); } void FEReaction::Serialize(DumpStream& dmp) { FEMaterialProperty::Serialize(dmp); if (!dmp.IsShallow()) { if (dmp.IsLoading()) { m_psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); assert(m_psm); } } } //============================================================================= BEGIN_FECORE_CLASS(FEReactionSpeciesRef, FEMaterialProperty) ADD_PARAMETER(m_speciesID, "species", FE_PARAM_ATTRIBUTE, "$(species)"); ADD_PARAMETER(m_solId , "sol")->SetFlags(FE_PARAM_ATTRIBUTE | FE_PARAM_HIDDEN); ADD_PARAMETER(m_sbmId , "sbm")->SetFlags(FE_PARAM_ATTRIBUTE | FE_PARAM_HIDDEN); END_FECORE_CLASS(); FEReactionSpeciesRef::FEReactionSpeciesRef(FEModel* fem) : FEMaterialProperty(fem) { m_speciesID = -1; m_solId = -1; m_sbmId = -1; m_v = 0; m_speciesType = UnknownSpecies; } int FEReactionSpeciesRef::GetSpeciesType() const { assert(m_speciesType != UnknownSpecies); return m_speciesType; } bool FEReactionSpeciesRef::IsSolute() const { return (m_speciesType == SoluteSpecies); } bool FEReactionSpeciesRef::IsSBM() const { return (m_speciesType == SBMSpecies); } bool FEReactionSpeciesRef::Init() { // make sure the species ID is valid if ((m_speciesID == -1) && (m_solId == -1) && (m_sbmId == -1)) return false; // figure out if this is a solute or sbm if (m_speciesType == UnknownSpecies) { FEModel& fem = *GetFEModel(); if (m_speciesID != -1) { int id = m_speciesID - 1; int n = 0; for (int i = 0; i < fem.GlobalDataItems(); ++i) { FESoluteData* sol = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); FESBMData* sbm = dynamic_cast<FESBMData*>(fem.GetGlobalData(i)); if (sol || sbm) { if (id == n) { if (sol) { m_speciesType = SoluteSpecies; m_speciesID = sol->GetID(); } if (sbm) { m_speciesType = SBMSpecies; m_speciesID = sbm->GetID(); } break; } else n++; } } } else if (m_solId != -1) { for (int i = 0; i < fem.GlobalDataItems(); ++i) { FESoluteData* sol = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (sol && (sol->GetID() == m_solId)) { m_speciesType = SoluteSpecies; m_speciesID = sol->GetID(); } } } else if (m_sbmId != -1) { for (int i = 0; i < fem.GlobalDataItems(); ++i) { FESBMData* sbm = dynamic_cast<FESBMData*>(fem.GetGlobalData(i)); if (sbm && (sbm->GetID() == m_sbmId)) { m_speciesType = SBMSpecies; m_speciesID = sbm->GetID(); } } } assert(m_speciesType != UnknownSpecies); if (m_speciesType == UnknownSpecies) return false; } return FEMaterialProperty::Init(); } //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEReactantSpeciesRef, FEReactionSpeciesRef) ADD_PARAMETER(m_v, "vR"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEProductSpeciesRef, FEReactionSpeciesRef) ADD_PARAMETER(m_v, "vP"); END_FECORE_CLASS();
C++