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
FEBioTest/FEJFNKTangentDiagnostic.cpp
.cpp
6,061
257
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEJFNKTangentDiagnostic.h" #include <FECore/FEModel.h> #include <FECore/FEAnalysis.h> #include <FECore/FENewtonSolver.h> #include <FECore/JFNKMatrix.h> #include <FECore/CompactUnSymmMatrix.h> #include <FECore/log.h> #include <FECore/FEGlobalMatrix.h> #include <FEBioXML/XMLReader.h> FEJFNKTangentDiagnostic::FEJFNKTangentDiagnostic(FEModel* fem) : FECoreTask(fem) { m_max_err = 0.0; m_sum_err = 0.0; m_max_err_K = 0.0; m_max_err_A = 0.0; m_max_err_i = -1; m_max_err_j = -1; m_evals = 0; m_max_K = 0.0; m_jfnk_eps = 1e-7; m_small_val = 1e-9; m_nstep = -1; m_nprint = 0; } bool FEJFNKTangentDiagnostic::Init(const char* szfile) { XMLReader xml; if (xml.Open(szfile) == false) { fprintf(stderr, "\nERROR: Failed to open %s\n\n", szfile); return false; } XMLTag tag; if (xml.FindTag("jfnk_diagnostic_spec", tag) == false) { fprintf(stderr, "\nERROR: Failed to read %s\n\n", szfile); return false; } ++tag; do { if (tag == "jfnk_eps" ) tag.value(m_jfnk_eps); else if (tag == "small_value") tag.value(m_small_val); else if (tag == "time_step") tag.value(m_nstep); else if (tag == "print_level") tag.value(m_nprint); else { fprintf(stderr, "ERROR: Failed to read %s\n\n", szfile); return false; } ++tag; } while (!tag.isend()); printf("JFNK Diagnostic parameters:\n"); printf("\tJFNK eps = %lg\n", m_jfnk_eps); printf("\tSmall value = %lg\n", m_small_val); printf("\ttime step = %d\n", m_nstep); printf("\n"); xml.Close(); return GetFEModel()->Init(); } bool cb_diagnose(FEModel* fem, unsigned int nwhen, void* pd) { return ((FEJFNKTangentDiagnostic*)pd)->Diagnose(); } bool FEJFNKTangentDiagnostic::Run() { FEModel& fem = *GetFEModel(); fem.AddCallback(cb_diagnose, CB_MAJOR_ITERS, this); // fem.GetLogFile().SetMode(Logfile::LOG_FILE); printf("Running model ..."); bool ret = fem.Solve(); printf("done!\n"); printf("\nmax K : %lg\n", m_max_K); printf("\nmax error: %lg\n", m_max_err); printf("\tK_exact[%d, %d] = %lg\n", m_max_err_i, m_max_err_j, m_max_err_K); printf("\tK_jfnk [%d, %d] = %lg\n", m_max_err_i, m_max_err_j, m_max_err_A); double avg_err = m_sum_err / m_evals; printf("\navg error: %lg\n\n", avg_err); return true; } bool FEJFNKTangentDiagnostic::Diagnose() { FEModel& fem = *GetFEModel(); // only analyze the requested step int timeSteps = fem.GetCurrentStep()->m_ntimesteps; if ((m_nstep != -1) && (timeSteps != m_nstep)) return true; // get the solver FENewtonSolver* fesolver = dynamic_cast<FENewtonSolver*>(fem.GetCurrentStep()->GetFESolver()); if (fesolver == nullptr) return false; // Force a reform of the stiffness matrix first fesolver->ReformStiffness(); // get the actual stiffness matrix FEGlobalMatrix* G = fesolver->GetStiffnessMatrix(); if (G == nullptr) return false; SparseMatrix* K = G->GetSparseMatrixPtr(); if (K == nullptr) return false; // setup the JFNK matrix JFNKMatrix A(fesolver); A.SetEpsilon(m_jfnk_eps); // get number of equations int neq = K->Rows(); vector<double> ej(neq, 0.0), aj(neq, 0.0), kj(neq, 0.0); vector<bool> cj(neq, false); if (m_nprint) { FILE* fp = fopen("out_exact.txt", "wt"); // print the transpose of the matrix for (int j = 0; j < neq; ++j) { for (int i = 0; i < neq; ++i) { double kij = K->get(i, j); fprintf(fp, "%13.7lg", kij); if (i != neq - 1) fprintf(fp, ","); } fprintf(fp, "\n"); } fclose(fp); } FILE* out = NULL; if (m_nprint) { out = fopen("out_jfnk.txt", "wt"); } // re-evaluate residual vector<double> R(neq, 0.0); fesolver->Residual(R); A.SetReferenceResidual(R); // loop over all columns for (int j = 0; j < neq; ++j) { // create e_i vector ej[j] = 1.0; // multiply with JFNK matrix A.mult_vector(&ej[0], &aj[0]); // get column of K for (int i = 0; i < neq; ++i) { cj[i] = K->check(i, j); double kij = K->get(i, j); kj[i] = kij; if (fabs(kij) > m_max_K) m_max_K = fabs(kij); } // compare difference for (int i = 0; i < neq; ++i) { double aij = aj[i]; double kij = kj[i]; if (m_nprint) { fprintf(out, "%13.7lg", aij); if (i != neq - 1) fprintf(out, ","); } double eij = 0; if (fabs(kij) <= m_small_val) { eij = fabs(kij - aij); } else { double D = 0.5*(fabs(kij) + fabs(aij)); if (D != 0.0) { eij = fabs(kij - aij) / D; } } if (eij != 0.0) { m_sum_err += eij; m_evals++; if (eij > m_max_err) { m_max_err = eij; m_max_err_K = kij; m_max_err_A = aij; m_max_err_i = i; m_max_err_j = j; } } } if (m_nprint) { fprintf(out, "\n"); } // reset e_j vector ej[j] = 0.0; } if (m_nprint) fclose(out); return true; }
C++
3D
febiosoftware/FEBio
FEBioTest/FEResetTest.cpp
.cpp
4,332
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) 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 "FEResetTest.h" #include <FEBioLib/FEBioModel.h> #include <FECore/log.h> #include <FEBioLib/Logfile.h> #include <FECore/FELogSolutionNorm.h> #include <iostream> #include <iomanip> using namespace std; //----------------------------------------------------------------------------- FEResetTest::FEResetTest(FEModel*pfem) : FECoreTask(pfem) { } //----------------------------------------------------------------------------- // initialize the diagnostic bool FEResetTest::Init(const char* sz) { FEBioModel& fem = dynamic_cast<FEBioModel&>(*GetFEModel()); Logfile& log = fem.GetLogFile(); log.SetMode(Logfile::MODE::LOG_FILE); // do the FE initialization return fem.Init(); } //----------------------------------------------------------------------------- // run the diagnostic bool FEResetTest::Run() { FEBioModel* fem = dynamic_cast<FEBioModel*>(GetFEModel()); FELogSolutionNorm sn(fem); // try to run the model cerr << "Running model for the first time.\n"; if (fem->Solve() == false) { cerr << "Failed to run model.\nTest aborted.\n\n"; return false; } // collect results ModelStats stats1 = fem->GetModelStats(); double norm1 = sn.value(); cerr << "time steps = " << stats1.ntimeSteps << endl; cerr << "total iters = " << stats1.ntotalIters << endl; cerr << "total reforms = " << stats1.ntotalReforms << endl; cerr << "total rhs = " << stats1.ntotalRHS << endl; cerr << "solution norm = " << std::setprecision(15) << norm1 << endl; // change the name of the logfile so we can compare std::string logfileName = fem->GetLogfileName(); size_t n = logfileName.rfind('.'); string extension; string filebase; if (n != std::string::npos) { extension = logfileName.substr(n); filebase = logfileName.substr(0, n); } filebase += "_2"; logfileName = filebase + extension; fem->SetLogFilename(logfileName); // reset the model std::cerr << "Resetting model.\n"; if (fem->Reset() == false) { cerr << "Failed to reset model.\nTest aborted.\n\n"; return false; } // try to run it again std::cerr << "Running model for the second time.\n"; if (fem->Solve() == false) { cerr << "Failed to run model second time.\nTest aborted.\n\n"; return false; } // get model stats ModelStats stats2 = fem->GetModelStats(); double norm2 = sn.value(); cerr << "time steps = " << stats2.ntimeSteps << endl; cerr << "total iters = " << stats2.ntotalIters << endl; cerr << "total reforms = " << stats2.ntotalReforms << endl; cerr << "total rhs = " << stats2.ntotalRHS << endl; cerr << "solution norm = " << norm2 << endl; bool success = true; if (stats1.ntimeSteps != stats2.ntimeSteps ) success = false; if (stats1.ntotalIters != stats2.ntotalIters ) success = false; if (stats1.ntotalReforms != stats2.ntotalReforms) success = false; if (stats1.ntotalRHS != stats2.ntotalRHS ) success = false; if (norm1 != norm2) success = false; cerr << " --> Reset test " << (success ? "PASSED" : "FAILED") << endl; return success; }
C++
3D
febiosoftware/FEBio
FEBioTest/FEBioTest.h
.h
1,335
35
/*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 namespace FEBioTest { void InitModule(); }
Unknown
3D
febiosoftware/FEBio
FEBioTest/FEBioTest.cpp
.cpp
2,051
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.*/ #include "stdafx.h" #include "FEBioTest.h" #include <FECore/FECoreKernel.h> #include "FEBioDiagnostic.h" #include "FETangentDiagnostic.h" #include "FERestartDiagnostics.h" #include "FEJFNKTangentDiagnostic.h" #include "FEMaterialTest.h" #include "FEResetTest.h" #include "FEStiffnessDiagnostic.h" namespace FEBioTest { void InitModule() { REGISTER_FECORE_CLASS(FEBioDiagnostic, "diagnose"); REGISTER_FECORE_CLASS(FERestartDiagnostic, "restart_test"); REGISTER_FECORE_CLASS(FEQuickRestartDiagnostic, "quick_restart_test"); REGISTER_FECORE_CLASS(FEJFNKTangentDiagnostic, "jfnk tangent test"); REGISTER_FECORE_CLASS(FEResetTest, "reset_test"); REGISTER_FECORE_CLASS(FEMaterialTest, "material test"); REGISTER_FECORE_CLASS(FEStiffnessDiagnostic, "stiffness_test"); } }
C++
3D
febiosoftware/FEBio
FEBioTest/FEFluidFSITangentDiagnostic.h
.h
2,558
81
/*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 "FEDiagnostic.h" //----------------------------------------------------------------------------- class FEFluidFSIScenario : public FEDiagnosticScenario { public: FEFluidFSIScenario(FEDiagnostic* pdia) : FEDiagnosticScenario(pdia) { m_dt = 1.0; } public: double m_dt; }; //----------------------------------------------------------------------------- class FEFluidFSITangentUniaxial : public FEFluidFSIScenario { public: FEFluidFSITangentUniaxial(FEDiagnostic* pdia); bool Init() override; private: double m_dilation; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! The FEFluidFSITangentDiagnostic class tests the stiffness matrix implementation //! by comparing it to a numerical approximating of the derivative of the //! residual. class FEFluidFSITangentDiagnostic : public FEDiagnostic { public: FEFluidFSITangentDiagnostic(FEModel* fem); virtual ~FEFluidFSITangentDiagnostic(){} bool Init(); bool Run(); FEDiagnosticScenario* CreateScenario(const std::string& sname); protected: void deriv_residual(matrix& ke); void print_matrix(matrix& m); public: FEFluidFSIScenario* m_pscn; };
Unknown
3D
febiosoftware/FEBio
FEBioTest/FEContactDiagnosticBiphasic.h
.h
2,717
88
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEDiagnostic.h" class SparseMatrix; //----------------------------------------------------------------------------- class FEContactBiphasicScenario : public FEDiagnosticScenario { public: FEContactBiphasicScenario(FEDiagnostic* pdia) : FEDiagnosticScenario(pdia) { m_dt = 1.0; } public: double m_dt; }; //----------------------------------------------------------------------------- class FEContactBiphasicTangentHex8 : public FEContactBiphasicScenario { public: FEContactBiphasicTangentHex8(FEDiagnostic* pdia); bool Init() override; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- class FEContactBiphasicTangentHex20 : public FEContactBiphasicScenario { public: FEContactBiphasicTangentHex20(FEDiagnostic* pdia); bool Init() override; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- class FEContactDiagnosticBiphasic : public FEDiagnostic { public: FEContactDiagnosticBiphasic(FEModel* fem); ~FEContactDiagnosticBiphasic(); bool Run(); bool Init(); FEDiagnosticScenario* CreateScenario(const std::string& sname); protected: void print_matrix(matrix& m); void print_matrix(SparseMatrix& m); void deriv_residual(matrix& K); public: FEContactBiphasicScenario* m_pscn; };
Unknown
3D
febiosoftware/FEBio
FEBioTest/FEContactDiagnostic.h
.h
1,613
48
/*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 "FEDiagnostic.h" #include <FECore/DenseMatrix.h> class FEContactDiagnostic : public FEDiagnostic { public: FEContactDiagnostic(FEModel* fem); virtual ~FEContactDiagnostic(); bool Run(); bool Init(); void print_matrix(FECore::DenseMatrix& m); protected: void deriv_residual(FECore::DenseMatrix& K); };
Unknown
3D
febiosoftware/FEBio
FEBioTest/FEDiagnostic.cpp
.cpp
7,280
203
/*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 "FEDiagnostic.h" #include "FETangentDiagnostic.h" #include "FEEASShellTangentDiagnostic.h" #include "FEContactDiagnostic.h" #include "FEPrintMatrixDiagnostic.h" #include "FEPrintHBMatrixDiagnostic.h" #include "FEMemoryDiagnostic.h" #include "FEBiphasicTangentDiagnostic.h" #include "FETiedBiphasicDiagnostic.h" #include "FEMultiphasicTangentDiagnostic.h" #include "FEFluidTangentDiagnostic.h" #include "FEFluidFSITangentDiagnostic.h" #include "FEPolarFluidTangentDiagnostic.h" #include "FEContactDiagnosticBiphasic.h" #include "FEMaterialTest.h" #include "FECore/log.h" #include "FEBioXML/FEBioControlSection.h" #include "FEBioXML/FEBioMaterialSection.h" #include "FEBioXML/FEBioGlobalsSection.h" #include "FECore/FECoreKernel.h" #include "FECore/FESolver.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// FEDiagnostic::FEDiagnostic(FEModel* fem) : FECoreClass(fem) { } FEDiagnostic::~FEDiagnostic() { } void FEDiagnostic::SetFileName(const std::string& fileName) { m_file = fileName; } const std::string& FEDiagnostic::GetFileName() { return m_file; } //----------------------------------------------------------------------------- FEDiagnostic* FEDiagnosticImport::LoadFile(FEModel& fem, const char* szfile) { m_pdia = 0; m_builder = new FEModelBuilder(fem); // Open the XML file XMLReader xml; if (xml.Open(szfile) == false) { errf("FATAL ERROR: Failed opening input file %s\n\n", szfile); return 0; } // define file structure m_map.clear(); m_map["Control" ] = new FEDiagnosticControlSection (this); m_map["Material"] = new FEBioMaterialSection (this); m_map["Scenario"] = new FEDiagnosticScenarioSection(this); m_map["Globals" ] = new FEBioGlobalsSection (this); FECoreKernel& fecore = FECoreKernel::GetInstance(); // loop over all child tags try { // Find the root element XMLTag tag; if (xml.FindTag("febio_diagnostic", tag) == false) return 0; XMLAtt& att = tag.m_att[0]; if (att == "tangent test" ) { fecore.SetActiveModule("solid" ); m_pdia = new FETangentDiagnostic (&fem); } else if (att == "shell tangent test" ) { fecore.SetActiveModule("solid" ); m_pdia = new FEEASShellTangentDiagnostic (&fem); } else if (att == "contact test" ) { fecore.SetActiveModule("solid" ); m_pdia = new FEContactDiagnostic (&fem); } else if (att == "print matrix" ) { fecore.SetActiveModule("solid" ); m_pdia = new FEPrintMatrixDiagnostic (&fem); } else if (att == "print hbmatrix" ) { fecore.SetActiveModule("solid" ); m_pdia = new FEPrintHBMatrixDiagnostic (&fem); } else if (att == "memory test" ) { fecore.SetActiveModule("solid" ); m_pdia = new FEMemoryDiagnostic (&fem); } else if (att == "biphasic tangent test" ) { fecore.SetActiveModule("biphasic" ); m_pdia = new FEBiphasicTangentDiagnostic (&fem); } else if (att == "biphasic contact test" ) { fecore.SetActiveModule("biphasic" ); m_pdia = new FEContactDiagnosticBiphasic (&fem); } else if (att == "tied biphasic test" ) { fecore.SetActiveModule("biphasic" ); m_pdia = new FETiedBiphasicDiagnostic (&fem); } else if (att == "multiphasic tangent test") { fecore.SetActiveModule("multiphasic"); m_pdia = new FEMultiphasicTangentDiagnostic(&fem); } else if (att == "fluid tangent test" ) { fecore.SetActiveModule("fluid" ); m_pdia = new FEFluidTangentDiagnostic (&fem); } else if (att == "fluid-FSI tangent test" ) { fecore.SetActiveModule("fluid-FSI" ); m_pdia = new FEFluidFSITangentDiagnostic (&fem); } else if (att == "polar fluid tangent test") { fecore.SetActiveModule("polar fluid"); m_pdia = new FEPolarFluidTangentDiagnostic (&fem); } else if (att == "material test" ) { fecore.SetActiveModule("solid" ); m_pdia = new FEMaterialTest (&fem); } else { feLog("\nERROR: unknown diagnostic\n\n"); return 0; } // keep a pointer to the fem object fem.SetCurrentStepIndex(0); // parse the file if (ParseFile(tag) == false) return nullptr; } catch (XMLReader::Error& e) { feLog("FATAL ERROR: %s\n", e.what()); return 0; } catch (FEFileException& e) { feLog("FATAL ERROR: %s (line %d)\n", e.GetErrorString(), xml.GetCurrentLine()); return 0; } catch (...) { feLog("FATAL ERROR: unrecoverable error (line %d)\n", xml.GetCurrentLine()); return 0; } // close the XML file xml.Close(); if (m_pdia) m_pdia->SetFileName(szfile); // we're done! return m_pdia; } //----------------------------------------------------------------------------- void FEDiagnosticControlSection::Parse(XMLTag &tag) { FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); ++tag; do { if (tag == "time_steps") tag.value(pstep->m_ntime); else if (tag == "step_size") { tag.value(pstep->m_dt0); fem.GetTime().timeIncrement = pstep->m_dt0; } else throw XMLReader::InvalidValue(tag); ++tag; } while (!tag.isend()); } //----------------------------------------------------------------------------- void FEDiagnosticScenarioSection::Parse(XMLTag &tag) { FEDiagnosticImport& dim = static_cast<FEDiagnosticImport&>(*GetFileReader()); // get the diagnostic FEDiagnostic* pdia = dim.m_pdia; // find the type attribute XMLAtt& type = tag.Attribute("type"); // create the scenario FEDiagnosticScenario* pscn = pdia->CreateScenario(type.cvalue()); if (pscn == nullptr) throw XMLReader::InvalidAttributeValue(tag, "type", type.cvalue()); // parse the parameter list FEParameterList& pl = pscn->GetParameterList(); ++tag; do { if (ReadParameter(tag, pl) == false) throw XMLReader::InvalidTag(tag); ++tag; } while (!tag.isend()); }
C++
3D
febiosoftware/FEBio
FEBioTest/FEFluidTangentDiagnostic.h
.h
2,833
95
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEDiagnostic.h" //----------------------------------------------------------------------------- class FEFluidScenario : public FEDiagnosticScenario { public: FEFluidScenario(FEDiagnostic* pdia) : FEDiagnosticScenario(pdia) { m_dt = 1.0; } public: double m_dt; }; //----------------------------------------------------------------------------- class FEFluidTangentUniaxial : public FEFluidScenario { public: FEFluidTangentUniaxial(FEDiagnostic* pdia); bool Init() override; private: double m_velocity; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- class FEFluidTangentUniaxialSS : public FEFluidScenario { public: FEFluidTangentUniaxialSS(FEDiagnostic* pdia); bool Init() override; private: double m_velocity; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! The FEBiphasicTangentDiagnostic class tests the stiffness matrix implementation //! by comparing it to a numerical approximating of the derivative of the //! residual. class FEFluidTangentDiagnostic : public FEDiagnostic { public: FEFluidTangentDiagnostic(FEModel* fem); virtual ~FEFluidTangentDiagnostic(){} bool Init(); bool Run(); FEDiagnosticScenario* CreateScenario(const std::string& sname); protected: void deriv_residual(matrix& ke); void print_matrix(matrix& m); public: FEFluidScenario* m_pscn; };
Unknown
3D
febiosoftware/FEBio
FEBioTest/FEContactDiagnosticBiphasic.cpp
.cpp
16,202
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 "FEContactDiagnosticBiphasic.h" #include "FEBioMix/FEBiphasicSolver.h" #include "FEBioMix/FEBiphasicSolidDomain.h" #include "FEBioMix/FESlidingInterfaceBiphasic.h" #include "FEBioMech/FEResidualVector.h" #include <FECore/SparseMatrix.h> #include <FECore/log.h> ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// FEContactDiagnosticBiphasic::FEContactDiagnosticBiphasic(FEModel* fem) : FEDiagnostic(fem) { // make sure the correct module is active fem->SetActiveModule("biphasic"); m_pscn = 0; FEAnalysis* pstep = new FEAnalysis(fem); // create a new solver FESolver* pnew_solver = fecore_new<FESolver>("biphasic", fem); assert(pnew_solver); pnew_solver->m_msymm = REAL_UNSYMMETRIC; pstep->SetFESolver(pnew_solver); fem->AddStep(pstep); fem->SetCurrentStep(pstep); } //----------------------------------------------------------------------------- FEContactDiagnosticBiphasic::~FEContactDiagnosticBiphasic() { } //----------------------------------------------------------------------------- // Helper function to print a matrix void FEContactDiagnosticBiphasic::print_matrix(matrix& m) { int i, j; int N = m.rows(); int M = m.columns(); feLog("\n "); for (i=0; i<N; ++i) feLog("%15d ", i); feLog("\n----"); for (i=0; i<N; ++i) feLog("----------------", i); for (i=0; i<N; ++i) { feLog("\n%2d: ", i); for (j=0; j<M; ++j) { feLog("%15lg ", m[i][j]); } } feLog("\n"); } //----------------------------------------------------------------------------- // Helper function to print a sparse matrix void FEContactDiagnosticBiphasic::print_matrix(SparseMatrix& m) { int i, j; int N = m.Rows(); int M = m.Columns(); feLog("\n "); for (i=0; i<N; ++i) feLog("%15d ", i); feLog("\n----"); for (i=0; i<N; ++i) feLog("----------------", i); for (i=0; i<N; ++i) { feLog("\n%2d: ", i); for (j=0; j<M; ++j) { feLog("%15lg ", m.get(i,j)); } } feLog("\n"); } //----------------------------------------------------------------------------- // Initialize the diagnostic. In this function we build the FE model depending // on the scenario. bool FEContactDiagnosticBiphasic::Init() { if (m_pscn == 0) return false; if (m_pscn->Init() == false) return false; return FEDiagnostic::Init(); } //----------------------------------------------------------------------------- bool FEContactDiagnosticBiphasic::Run() { // get the solver FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; pstep->Activate(); FEBiphasicSolver& solver = static_cast<FEBiphasicSolver&>(*pstep->GetFESolver()); solver.m_msymm = REAL_UNSYMMETRIC; solver.Init(); // make sure contact data is up to data fem.Update(); // create the stiffness matrix solver.CreateStiffness(true); // get the stiffness matrix FEGlobalMatrix& K = *solver.GetStiffnessMatrix(); SparseMatrix& K0 = *K; // we need a linear system to evaluate contact int neq = solver.m_neq; vector<double> Fd(neq, 0.0); vector<double> ui(neq, 0.0); FELinearSystem LS(&fem, K, Fd, ui, true); // build the stiffness matrix K.Zero(); solver.ContactStiffness(LS); print_matrix(K0); // calculate the derivative of the residual matrix K1; deriv_residual(K1); print_matrix(K1); // calculate difference matrix int ndpn = 4; int N = mesh.Nodes(); const int ndof = N*ndpn; matrix Kd; Kd.resize(ndof, ndof); double kij, kmax = 0, k0; int i0=-1, j0=-1; for (int i=0; i<ndof; ++i) for (int j=0; j<ndof; ++j) { Kd(i,j) = K1(i,j) - K0.get(i,j); k0 = fabs(K0.get(i,j)); if (k0 < 1e-15) k0 = 1; kij = 100.0*fabs(Kd(i,j))/k0; if (kij > kmax) { kmax = kij; i0 = i; j0 = j; } } print_matrix(Kd); feLog("\nMaximum difference: %lg%% (at (%d,%d))\n", kmax, i0, j0); return (kmax < 1e-3); } //----------------------------------------------------------------------------- void FEContactDiagnosticBiphasic::deriv_residual(matrix& K) { // get the solver FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; FEBiphasicSolver& solver = static_cast<FEBiphasicSolver&>(*pstep->GetFESolver()); // 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"); // get the mesh FEMesh& mesh = fem.GetMesh(); int ndpn = 4; int N = mesh.Nodes(); int ndof = N*ndpn; fem.Update(); // first calculate the initial residual vector<double> R0; R0.assign(ndof, 0); vector<double> dummy(R0); FEResidualVector RHS0(fem, R0, dummy); solver.ContactForces(RHS0); // now calculate the perturbed residuals K.resize(ndof,ndof); int i, j, nj; double dx = 1e-8; vector<double> R1(ndof); for (j=0; j<ndof; ++j) { FENode& node = mesh.Node(j/ndpn); nj = j%ndpn; switch (nj) { case 0: node.add(dof_x, dx); node.m_rt.x += dx; break; case 1: node.add(dof_y, dx); node.m_rt.y += dx; break; case 2: node.add(dof_z, dx); node.m_rt.z += dx; break; case 3: node.add(dof_p, dx); break; } fem.Update(); zero(R1); FEResidualVector RHS1(fem, R1, dummy); solver.ContactForces(RHS1); switch (nj) { case 0: node.sub(dof_x, dx); node.m_rt.x -= dx; break; case 1: node.sub(dof_y, dx); node.m_rt.y -= dx; break; case 2: node.sub(dof_z, dx); node.m_rt.z -= dx; break; case 3: node.sub(dof_p, dx); break; } fem.Update(); for (i=0; i<ndof; ++i) K(i,j) = (R0[i] - R1[i])/dx; } } //----------------------------------------------------------------------------- FEDiagnosticScenario* FEContactDiagnosticBiphasic::CreateScenario(const std::string& sname) { if (sname == "hex8") return (m_pscn = new FEContactBiphasicTangentHex8(this)); else if (sname == "hex20") return (m_pscn = new FEContactBiphasicTangentHex20(this)); return 0; } ////////////////////////////////////////////////////////////////////// // Biphasic Contact Tangent Diagnostic for hex8 Elements ////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEContactBiphasicTangentHex8, FEContactBiphasicScenario) ADD_PARAMETER(m_dt, "time_step" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEContactBiphasicTangentHex8::FEContactBiphasicTangentHex8(FEDiagnostic* pdia) : FEContactBiphasicScenario(pdia) { m_dt = 1; } //----------------------------------------------------------------------------- bool FEContactBiphasicTangentHex8::Init() { vec3d r[16] = { vec3d(0,0,0), vec3d(1,0,0), vec3d(1,1,0), vec3d(0,1,0), vec3d(0,0,1), vec3d(1,0,1), vec3d(1,1,1), vec3d(0,1,1), vec3d(0,0,1), vec3d(1,0,1), vec3d(1,1,1), vec3d(0,1,1), vec3d(0,0,2), vec3d(1,0,2), vec3d(1,1,2), vec3d(0,1,2) }; double p[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; FEModel& fem = *GetDiagnostic()->GetFEModel(); FEMesh& mesh = fem.GetMesh(); // --- create the geometry --- int MAX_DOFS = fem.GetDOFS().GetTotalDOFS(); // get the DOFs const int dof_p = fem.GetDOFIndex("p"); // currently we simply assume a two-element contact problem // so we create two elements const double eps = 0.5; mesh.CreateNodes(16); mesh.SetDOFS(MAX_DOFS); vec3d dr(0,0,eps); for (int i=0; i<8; ++i) { mesh.Node(i).m_r0 = r[i]; mesh.Node(i).set(dof_p, p[i]); } for (int i=8; i<16; ++i) { mesh.Node(i).m_r0 = r[i] - dr; mesh.Node(i).set(dof_p, p[i]+eps); } for (int i=0; i<16; ++i) { FENode& node = mesh.Node(i); node.m_rt = node.m_r0; } // get the material FEMaterial* pm = fem.GetMaterial(0); // get the one-and-only domain FEBiphasicSolidDomain* pbd = new FEBiphasicSolidDomain(&fem); pbd->SetMaterial(pm); pbd->Create(2, FEElementLibrary::GetElementSpecFromType(FE_HEX8G8)); pbd->SetMatID(0); mesh.AddDomain(pbd); FESolidElement& el0 = pbd->Element(0); FESolidElement& el1 = pbd->Element(1); el0.SetID(1); el0.m_node[0] = 0; el0.m_node[1] = 1; el0.m_node[2] = 2; el0.m_node[3] = 3; el0.m_node[4] = 4; el0.m_node[5] = 5; el0.m_node[6] = 6; el0.m_node[7] = 7; el1.SetID(2); el1.m_node[0] = 8; el1.m_node[1] = 9; el1.m_node[2] = 10; el1.m_node[3] = 11; el1.m_node[4] = 12; el1.m_node[5] = 13; el1.m_node[6] = 14; el1.m_node[7] = 15; pbd->CreateMaterialPointData(); // --- create the sliding interface --- FESlidingInterfaceBiphasic* ps = new FESlidingInterfaceBiphasic(&fem); ps->m_atol = 0.1; ps->m_epsn = 1; ps->m_epsp = 1; ps->m_btwo_pass = false; ps->m_nsegup = 0; ps->m_bautopen = true; ps->m_bsymm = false; ps->m_stol = 0.01; FESlidingSurfaceBiphasic& ms = ps->m_ms; ms.Create(1, FE_QUAD4G4); ms.Element(0).m_node[0] = 4; ms.Element(0).m_node[1] = 5; ms.Element(0).m_node[2] = 6; ms.Element(0).m_node[3] = 7; FESlidingSurfaceBiphasic& ss = ps->m_ss; ss.Create(1, FE_QUAD4G4); ss.Element(0).m_node[0] = 11; ss.Element(0).m_node[1] = 10; ss.Element(0).m_node[2] = 9; ss.Element(0).m_node[3] = 8; fem.AddSurfacePairConstraint(ps); return true; } ////////////////////////////////////////////////////////////////////// // Biphasic Contact Tangent Diagnostic for hex20 Elements ////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEContactBiphasicTangentHex20, FEContactBiphasicScenario) ADD_PARAMETER(m_dt, "time_step" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEContactBiphasicTangentHex20::FEContactBiphasicTangentHex20(FEDiagnostic* pdia) : FEContactBiphasicScenario(pdia) { m_dt = 1; } //----------------------------------------------------------------------------- bool FEContactBiphasicTangentHex20::Init() { vec3d r[40] = { vec3d(0,0,0), vec3d(0,0,0.5), vec3d(0,0,1), vec3d(0,0.5,0), vec3d(0,0.5,1), vec3d(0,1,0), vec3d(0,1,0.5), vec3d(0,1,1), vec3d(0.5,0,0), vec3d(0.5,0,1), vec3d(0.5,1,0), vec3d(0.5,1,1), vec3d(1,0,0), vec3d(1,0,0.5), vec3d(1,0,1), vec3d(1,0.5,0), vec3d(1,0.5,1), vec3d(1,1,0), vec3d(1,1,0.5), vec3d(1,1,1), vec3d(0,0,1), vec3d(0,0,1.5), vec3d(0,0,2), vec3d(0,0.5,1), vec3d(0,0.5,2), vec3d(0,1,1), vec3d(0,1,1.5), vec3d(0,1,2), vec3d(0.5,0,1), vec3d(0.5,0,2), vec3d(0.5,1,1), vec3d(0.5,1,2), vec3d(1,0,1), vec3d(1,0,1.5), vec3d(1,0,2), vec3d(1,0.5,1), vec3d(1,0.5,2), vec3d(1,1,1), vec3d(1,1,1.5), vec3d(1,1,2), }; double p[40] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; int el0n[20] = { 1, 13, 18, 6, 3, 15, 20, 8, 9, 16, 11, 4, 10, 17, 12, 5, 2, 14, 19, 7 }; int el1n[20] = { 21, 33, 38, 26, 23, 35, 40, 28, 29, 36, 31, 24, 30, 37, 32, 25, 22, 34, 39, 27 }; int msn[8] = { 21, 26, 38, 33, 24, 31, 36, 29 }; int ssn[9] = { 3, 15, 20, 8, 10, 17, 12, 5 }; FEModel& fem = *GetDiagnostic()->GetFEModel(); FEMesh& mesh = fem.GetMesh(); // --- create the geometry --- int MAX_DOFS = fem.GetDOFS().GetTotalDOFS(); // get the DOFs const int dof_p = fem.GetDOFIndex("p"); // currently we simply assume a two-element contact problem // so we create two elements const double eps = 0.5; mesh.CreateNodes(40); mesh.SetDOFS(MAX_DOFS); vec3d dr(0,0,eps); for (int i=0; i<20; ++i) { mesh.Node(i).m_r0 = r[i]; mesh.Node(i).set(dof_p, p[i]); } for (int i=20; i<40; ++i) { mesh.Node(i).m_r0 = r[i] - dr; mesh.Node(i).set(dof_p, p[i]+eps); } for (int i=0; i<40; ++i) { FENode& node = mesh.Node(i); node.m_rt = node.m_r0; } // get the material FEMaterial* pm = fem.GetMaterial(0); // get the one-and-only domain FEBiphasicSolidDomain* pbd = new FEBiphasicSolidDomain(&fem); pbd->SetMaterial(pm); pbd->Create(2, FEElementLibrary::GetElementSpecFromType(FE_HEX20G27)); pbd->SetMatID(0); mesh.AddDomain(pbd); FESolidElement& el0 = pbd->Element(0); FESolidElement& el1 = pbd->Element(1); el0.SetID(1); for (int i=0; i<20; ++i) { el0.m_node[i] = el0n[i] - 1; } el1.SetID(2); for (int i=0; i<20; ++i) { el1.m_node[i] = el1n[i] - 1; } pbd->CreateMaterialPointData(); // --- create the sliding interface --- FESlidingInterfaceBiphasic* ps = new FESlidingInterfaceBiphasic(&fem); ps->m_atol = 0.1; ps->m_epsn = 1; ps->m_epsp = 1; ps->m_btwo_pass = false; ps->m_nsegup = 0; ps->m_bautopen = true; ps->m_bsymm = false; FESlidingSurfaceBiphasic& ms = ps->m_ms; ms.Create(1, FE_QUAD8G9); for (int i=0; i<8; ++i) ms.Element(0).m_node[i] = msn[i] - 1; FESlidingSurfaceBiphasic& ss = ps->m_ss; ss.Create(1, FE_QUAD8G9); for (int i=0; i<8; ++i) ss.Element(0).m_node[i] = ssn[i] - 1; fem.AddSurfacePairConstraint(ps); return true; }
C++
3D
febiosoftware/FEBio
FEBioTest/FEFluidTangentDiagnostic.cpp
.cpp
14,271
464
/*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 "FEFluidTangentDiagnostic.h" #include "FETangentDiagnostic.h" #include "FEBioFluid/FEFluidSolver.h" #include "FEBioFluid/FEFluidDomain3D.h" #include "FEBioFluid/FEFluidAnalysis.h" #include "FECore/log.h" #include <FECore/FEPrescribedDOF.h> #include <FECore/FEFixedBC.h> #include <FECore/FELoadCurve.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEFluidTangentUniaxial, FEFluidScenario) ADD_PARAMETER(m_velocity, "fluid_velocity"); ADD_PARAMETER(m_dt , "time_step" ); END_FECORE_CLASS(); BEGIN_FECORE_CLASS(FEFluidTangentUniaxialSS, FEFluidScenario) ADD_PARAMETER(m_velocity, "fluid_velocity"); ADD_PARAMETER(m_dt , "time_step" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEFluidTangentUniaxial::FEFluidTangentUniaxial(FEDiagnostic* pdia) : FEFluidScenario(pdia) { m_velocity = 0; m_dt = 1; } //----------------------------------------------------------------------------- // Build the uniaxial loading scenario // Cube with uniaxial velocity prescribed along x on left face and dilatation // fixed on right face. Dynamic analysis. bool FEFluidTangentUniaxial::Init() { int i; vec3d r[8] = { vec3d(0,0,0), vec3d(1,0,0), vec3d(1,1,0), vec3d(0,1,0), vec3d(0,0,1), vec3d(1,0,1), vec3d(1,1,1), vec3d(0,1,1) }; int BC[8][4] = { { 0,-1,-1, 0},{ 0,-1,-1,-1},{ 0,-1,-1,-1}, { 0,-1,-1, 0}, { 0,-1,-1, 0},{ 0,-1,-1,-1},{ 0,-1,-1,-1}, { 0,-1,-1, 0} }; FEModel& fem = *GetDiagnostic()->GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); pstep->m_nanalysis = FEFluidAnalysis::DYNAMIC; int MAX_DOFS = fem.GetDOFS().GetTotalDOFS(); const int dof_WX = fem.GetDOFIndex("wx"); const int dof_WY = fem.GetDOFIndex("wy"); const int dof_WZ = fem.GetDOFIndex("wz"); const int dof_EF = fem.GetDOFIndex("ef"); // --- create the FE problem --- // create the mesh FEMesh& m = fem.GetMesh(); m.CreateNodes(8); m.SetDOFS(MAX_DOFS); FENodeSet* nset[4] = { 0 }; nset[0] = new FENodeSet(&fem); nset[1] = new FENodeSet(&fem); nset[2] = new FENodeSet(&fem); nset[3] = new FENodeSet(&fem); for (i=0; i<8; ++i) { FENode& n = m.Node(i); n.m_rt = n.m_r0 = r[i]; // set displacement BC's if (BC[i][0] == -1) nset[0]->Add(i); if (BC[i][1] == -1) nset[1]->Add(i); if (BC[i][2] == -1) nset[2]->Add(i); if (BC[i][3] == -1) nset[3]->Add(i); } fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WX, nset[0])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WY, nset[1])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WZ, nset[2])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_EF, nset[3])); // get the material FEMaterial* pmat = fem.GetMaterial(0); // create a fluid domain FEFluidDomain3D* pd = new FEFluidDomain3D(&fem); pd->SetMaterial(pmat); pd->Create(1, FEElementLibrary::GetElementSpecFromType(FE_HEX8G8)); pd->SetMatID(0); m.AddDomain(pd); FESolidElement& el = pd->Element(0); el.SetID(1); for (i=0; i<8; ++i) el.m_node[i] = i; pd->CreateMaterialPointData(); // Add a loadcurve FELoadCurve* plc = new FELoadCurve(&fem); plc->Add(0.0, 0.0); plc->Add(1.0, 1.0); fem.AddLoadController(plc); // Add a prescribed BC FENodeSet* dc = new FENodeSet(&fem); dc->Add({ 0, 3, 4, 7 }); FEPrescribedDOF* pdc = new FEPrescribedDOF(&fem, dof_WX, dc); pdc->SetScale(m_velocity, 0); fem.AddBoundaryCondition(pdc); return true; } //----------------------------------------------------------------------------- FEFluidTangentUniaxialSS::FEFluidTangentUniaxialSS(FEDiagnostic* pdia) : FEFluidScenario(pdia) { m_velocity = 0; m_dt = 1; } //----------------------------------------------------------------------------- // Build the uniaxial loading scenario // Cube with uniaxial velocity prescribed along x on left face and dilatation // fixed on right face. Steady-state analysis. bool FEFluidTangentUniaxialSS::Init() { int i; vec3d r[8] = { vec3d(0,0,0), vec3d(1,0,0), vec3d(1,1,0), vec3d(0,1,0), vec3d(0,0,1), vec3d(1,0,1), vec3d(1,1,1), vec3d(0,1,1) }; /* int BC[8][4] = { { 0,-1,-1, 0},{ 0,-1,-1,-1},{ 0,-1,-1,-1}, { 0,-1,-1, 0}, { 0,-1,-1, 0},{ 0,-1,-1,-1},{ 0,-1,-1,-1}, { 0,-1,-1, 0} };*/ int BC[8][4] = { { 0, 0, 0, 0},{ 0, 0, 0, 0},{ 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0},{ 0, 0, 0, 0},{ 0, 0, 0, 0}, { 0, 0, 0, 0} }; FEModel& fem = *GetDiagnostic()->GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); pstep->m_nanalysis = FEFluidAnalysis::STEADY_STATE; int MAX_DOFS = fem.GetDOFS().GetTotalDOFS(); const int dof_WX = fem.GetDOFIndex("wx"); const int dof_WY = fem.GetDOFIndex("wy"); const int dof_WZ = fem.GetDOFIndex("wz"); const int dof_EF = fem.GetDOFIndex("ef"); // --- create the FE problem --- // create the mesh FEMesh& m = fem.GetMesh(); m.CreateNodes(8); m.SetDOFS(MAX_DOFS); FENodeSet* nset[4] = { 0 }; nset[0] = new FENodeSet(&fem); nset[1] = new FENodeSet(&fem); nset[2] = new FENodeSet(&fem); nset[3] = new FENodeSet(&fem); for (i = 0; i<8; ++i) { FENode& n = m.Node(i); n.m_rt = n.m_r0 = r[i]; // set displacement BC's if (BC[i][0] == -1) nset[0]->Add(i); if (BC[i][1] == -1) nset[1]->Add(i); if (BC[i][2] == -1) nset[2]->Add(i); if (BC[i][3] == -1) nset[3]->Add(i); } fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WX, nset[0])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WY, nset[1])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WZ, nset[2])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_EF, nset[3])); // get the material FEMaterial* pmat = fem.GetMaterial(0); // create a fluid domain FEFluidDomain3D* pd = new FEFluidDomain3D(&fem); pd->SetMaterial(pmat); pd->Create(1, FEElementLibrary::GetElementSpecFromType(FE_HEX8G8)); pd->SetMatID(0); m.AddDomain(pd); FESolidElement& el = pd->Element(0); el.SetID(1); for (i=0; i<8; ++i) el.m_node[i] = i; pd->CreateMaterialPointData(); // Add a loadcurve /* FELoadCurve* plc = new FELoadCurve(new FELinearFunction(&fem, 1.0, 0.0)); fem.AddLoadCurve(plc); // Add a prescribed BC int nd[4] = {0, 3, 4, 7}; FEPrescribedDOF* pdc = new FEPrescribedDOF(&fem); fem.AddPrescribedBC(pdc); pdc->SetDOF(dof_WX).SetScale(m_velocity, 0); for (i = 0; i<4; ++i) pdc->AddNode(nd[i]);*/ return true; } //----------------------------------------------------------------------------- // Constructor FEFluidTangentDiagnostic::FEFluidTangentDiagnostic(FEModel* fem) : FEDiagnostic(fem) { // make sure the correct module is active fem->SetActiveModule("fluid"); m_pscn = 0; FEAnalysis* pstep = new FEAnalysis(fem); // create a new solver FESolver* pnew_solver = fecore_new<FESolver>("fluid", fem); assert(pnew_solver); pnew_solver->m_msymm = REAL_UNSYMMETRIC; pstep->SetFESolver(pnew_solver); fem->AddStep(pstep); fem->SetCurrentStep(pstep); } //----------------------------------------------------------------------------- FEDiagnosticScenario* FEFluidTangentDiagnostic::CreateScenario(const std::string& sname) { if (sname == "fluid uni-axial") return (m_pscn = new FEFluidTangentUniaxial(this)); else if (sname == "fluid uni-axial-SS") return (m_pscn = new FEFluidTangentUniaxialSS(this)); return 0; } //----------------------------------------------------------------------------- // Initialize the diagnostic. In this function we build the FE model depending // on the scenario. bool FEFluidTangentDiagnostic::Init() { if (m_pscn == 0) return false; if (m_pscn->Init() == false) return false; return FEDiagnostic::Init(); } //----------------------------------------------------------------------------- // Helper function to print a matrix void FEFluidTangentDiagnostic::print_matrix(matrix& m) { int i, j; int N = m.rows(); int M = m.columns(); feLog("\n "); for (i=0; i<N; ++i) feLog("%15d ", i); feLog("\n----"); for (i=0; i<N; ++i) feLog("----------------", i); for (i=0; i<N; ++i) { feLog("\n%2d: ", i); for (j=0; j<M; ++j) { feLog("%15lg ", m[i][j]); } } feLog("\n"); } //----------------------------------------------------------------------------- // Run the tangent diagnostic. After we run the FE model, we calculate // the element stiffness matrix and compare that to a finite difference // of the element residual. bool FEFluidTangentDiagnostic::Run() { // solve the problem FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; pstep->Activate(); fem.BlockLog(); fem.Solve(); fem.UnBlockLog(); FETimeInfo tp; tp.timeIncrement = dt; tp.alpha = 1; tp.beta = 0.25; tp.gamma = 0.5; tp.alphaf = 1; tp.alpham = 1; FEMesh& mesh = fem.GetMesh(); FEFluidDomain3D& bd = dynamic_cast<FEFluidDomain3D&>(mesh.Domain(0)); // get the one and only element FESolidElement& el = bd.Element(0); int N = mesh.Nodes(); // set up the element stiffness matrix matrix k0(4*N, 4*N); k0.zero(); bd.ElementStiffness(el, k0); bd.ElementMassMatrix(el,k0); // print the element stiffness matrix feLog("\nActual stiffness matrix:\n"); print_matrix(k0); // now calculate the derivative of the residual matrix k1; deriv_residual(k1); // print the approximate element stiffness matrix feLog("\nApproximate stiffness matrix:\n"); print_matrix(k1); // finally calculate the difference matrix feLog("\n"); matrix kd(4*N, 4*N); double kmax = 0, kij; int i0 = -1, j0 = -1, i, j; for (i=0; i<4*N; ++i) for (j=0; j<4*N; ++j) { kd[i][j] = k0[i][j] - k1[i][j]; kij = 100.0*fabs(kd[i][j] / k0[0][0]); if (kij > kmax) { kmax = kij; i0 = i; j0 = j; } } // print the difference feLog("\ndifference matrix:\n"); print_matrix(kd); feLog("\nMaximum difference: %lg%% (at (%d,%d))\n", kmax, i0, j0); return (kmax < 1e-4); } //----------------------------------------------------------------------------- // Calculate a finite difference approximation of the derivative of the // element residual. void FEFluidTangentDiagnostic::deriv_residual(matrix& ke) { int i, j, nj; // get the solver FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; FEFluidSolver& solver = static_cast<FEFluidSolver&>(*pstep->GetFESolver()); FETimeInfo tp; tp.timeIncrement = dt; tp.alpha = 1; tp.beta = 0.25; tp.gamma = 0.5; tp.alphaf = 1; tp.alpham = 1; // get the dof indices const int dof_WX = fem.GetDOFIndex("wx"); const int dof_WY = fem.GetDOFIndex("wy"); const int dof_WZ = fem.GetDOFIndex("wz"); const int dof_EF = fem.GetDOFIndex("ef"); // get the mesh FEMesh& mesh = fem.GetMesh(); FEFluidDomain3D& bd = dynamic_cast<FEFluidDomain3D&>(mesh.Domain(0)); // get the one and only element FESolidElement& el = bd.Element(0); int N = mesh.Nodes(); // first calculate the initial residual vector<double> f0(4*N); zero(f0); bd.ElementInternalForce(el, f0); bd.ElementInertialForce(el, f0); // now calculate the perturbed residuals ke.resize(4*N, 4*N); ke.zero(); double dx = 1e-8; vector<double> f1(4*N); for (j=0; j<4*N; ++j) { FENode& node = mesh.Node(el.m_node[j/4]); nj = j%4; switch (nj) { case 0: node.add(dof_WX, dx); break; case 1: node.add(dof_WY, dx); break; case 2: node.add(dof_WZ, dx); break; case 3: node.add(dof_EF, dx); break; } fem.Update(); zero(f1); bd.ElementInternalForce(el, f1); bd.ElementInertialForce(el, f1); switch (nj) { case 0: node.sub(dof_WX, dx); break; case 1: node.sub(dof_WY, dx); break; case 2: node.sub(dof_WZ, dx); break; case 3: node.sub(dof_EF, dx); break; } fem.Update(); for (i=0; i<4*N; ++i) ke[i][j] = -(f1[i] - f0[i])/dx; } }
C++
3D
febiosoftware/FEBio
FEBioTest/FEMemoryDiagnostic.h
.h
1,547
48
/*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 "FEDiagnostic.h" class FEMemoryDiagnostic : public FEDiagnostic { public: FEMemoryDiagnostic(FEModel* fem); ~FEMemoryDiagnostic(); bool Init(); bool Run(); bool ParseSection(XMLTag& tag); protected: char m_szfile[512]; int m_iters; };
Unknown
3D
febiosoftware/FEBio
FEBioTest/FERestartDiagnostics.h
.h
2,120
69
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FECoreTask.h> #include <FECore/DumpMemStream.h> // This diagnostics tests the running and cold restart features class FERestartDiagnostic : public FECoreTask { public: // constructor FERestartDiagnostic(FEModel* pfem); // initialize the diagnostic bool Init(const char* sz) override; // run the diagnostic bool Run() override; public: bool m_bok; bool m_bfile; // file or memory stream? char m_szdmp[256]; // restart file name DumpMemStream m_dmp; }; // This diagnostics tests simple calls serialize after init class FEQuickRestartDiagnostic : public FECoreTask { public: // constructor FEQuickRestartDiagnostic(FEModel* pfem); // initialize the diagnostic bool Init(const char* sz) override; // run the diagnostic bool Run() override; public: char m_szdmp[256]; // restart file name };
Unknown
3D
febiosoftware/FEBio
FEBioTest/FEPolarFluidTangentDiagnostic.h
.h
2,603
82
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEDiagnostic.h" //----------------------------------------------------------------------------- class FEPolarFluidScenario : public FEDiagnosticScenario { public: FEPolarFluidScenario(FEDiagnostic* pdia) : FEDiagnosticScenario(pdia) { m_time_increment = 0.0; } public: double m_time_increment; }; //----------------------------------------------------------------------------- class FEPolarFluidTangentUniaxial : public FEPolarFluidScenario { public: FEPolarFluidTangentUniaxial(FEDiagnostic* pdia); bool Init() override; private: double m_velocity; double m_angular_velocity; double m_dt; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! The FEBiphasicTangentDiagnostic class tests the stiffness matrix implementation //! by comparing it to a numerical approximating of the derivative of the //! residual. class FEPolarFluidTangentDiagnostic : public FEDiagnostic { public: FEPolarFluidTangentDiagnostic(FEModel* fem); bool Init(); bool Run(); FEDiagnosticScenario* CreateScenario(const std::string& sname); protected: void deriv_residual(matrix& ke); void print_matrix(matrix& m); public: FEPolarFluidScenario* m_pscn; };
Unknown
3D
febiosoftware/FEBio
FEBioTest/FEMultiphasicTangentDiagnostic.cpp
.cpp
12,854
415
/*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 "FEMultiphasicTangentDiagnostic.h" #include "FETangentDiagnostic.h" #include "FEBioMix/FEMultiphasicSolver.h" #include "FEBioMix/FEMultiphasicSolidDomain.h" #include <FECore/FEPrescribedDOF.h> #include <FECore/FEFixedBC.h> #include "FECore/FEInitialCondition.h" #include <FECore/FELoadCurve.h> #include "FECore/log.h" //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEMultiphasicTangentUniaxial, FEDiagnosticScenario) ADD_PARAMETER(m_strain , "solid_strain" ); ADD_PARAMETER(m_pressure , "fluid_pressure"); ADD_PARAMETER(m_dt , "time_step" ); ADD_PARAMETER(m_concentration, "solute_concentration"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMultiphasicTangentUniaxial::FEMultiphasicTangentUniaxial(FEDiagnostic* pdia) : FEMultiphasicScenario(pdia) { m_strain = 0; m_pressure = 0; m_concentration = 0; } //----------------------------------------------------------------------------- // Build the uniaxial loading scenario // Cube with face displaced along x, with zero fluid pressure on displaced face // and impermeable fixed face. bool FEMultiphasicTangentUniaxial::Init() { int i, isol; vec3d r[8] = { vec3d(0,0,0), vec3d(1,0,0), vec3d(1,1,0), vec3d(0,1,0), vec3d(0,0,1), vec3d(1,0,1), vec3d(1,1,1), vec3d(0,1,1) }; int BC[8][3] = { {-1,-1,-1},{ 0,-1,-1},{ 0, 0,-1}, {-1, 0,-1}, {-1,-1, 0},{ 0,-1, 0},{ 0, 0, 0}, {-1, 0, 0} }; // get the material FEModel& fem = *GetDiagnostic()->GetFEModel(); FEMaterial* pmat = fem.GetMaterial(0); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*>(pmat); assert(pmp); int nsol = pmp->Solutes(); double osm = nsol*m_concentration; double pe = -pmp->m_Rgas*pmp->m_Tabs*osm; // --- create the FE problem --- // get the degrees of freedom int MAX_DOFS = fem.GetDOFS().GetTotalDOFS(); 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); // create the mesh FEMesh& m = fem.GetMesh(); m.CreateNodes(8); m.SetDOFS(MAX_DOFS); // create a node set FENodeSet* iset = new FENodeSet(&fem); for (int i = 0; i < 8; ++i) iset->Add(i); // add initial conditions for (isol = 0; isol<nsol; ++isol) { FEInitialDOF* pic = new FEInitialDOF(&fem, dof_c + isol, iset); pic->SetValue(m_concentration); fem.AddInitialCondition(pic); } FEInitialDOF* pip = new FEInitialDOF(&fem, dof_p, iset); pip->SetValue(pe); fem.AddInitialCondition(pip); // add boundary conditions FENodeSet* nset[3]; nset[0] = new FENodeSet(&fem); nset[1] = new FENodeSet(&fem); nset[2] = new FENodeSet(&fem); for (i=0; i<8; ++i) { FENode& n = m.Node(i); n.m_rt = n.m_rp = n.m_r0 = r[i]; // set displacement BC's if (BC[i][0] == -1) nset[0]->Add(i); if (BC[i][1] == -1) nset[1]->Add(i); if (BC[i][2] == -1) nset[2]->Add(i); } fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_x, nset[0])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_y, nset[1])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_z, nset[2])); // create a multiphasic domain FEMultiphasicSolidDomain* pd = new FEMultiphasicSolidDomain(&fem); pd->SetMaterial(pmat); pd->Create(1, FEElementLibrary::GetElementSpecFromType(FE_HEX8G8)); pd->SetMatID(0); m.AddDomain(pd); FESolidElement& el = pd->Element(0); el.SetID(1); for (i=0; i<8; ++i) el.m_node[i] = i; pd->CreateMaterialPointData(); // convert strain to a displacement double d = sqrt(2*m_strain+1) - 1; // Add a loadcurve FELoadCurve* plc = new FELoadCurve(&fem); plc->Add(0.0, 0.0); plc->Add(1.0, 1.0); fem.AddLoadController(plc); // Add a prescribed displacement BC along X FENodeSet* dc = new FENodeSet(&fem); dc->Add({ 1, 2, 5, 6 }); FEPrescribedDOF* pdc = new FEPrescribedDOF(&fem, dof_x, dc); pdc->SetScale(d, 0); fem.AddBoundaryCondition(pdc); // Add a prescribed fluid pressure BC FEPrescribedDOF* ppc = new FEPrescribedDOF(&fem, dof_p, dc); ppc->SetScale(pe, 0); fem.AddBoundaryCondition(ppc); // Add prescribed solute concentration BC for (i=0; i<nsol; ++i) { FEPrescribedDOF* psc = new FEPrescribedDOF(&fem, dof_c + i, dc); psc->SetScale(m_concentration, 0); fem.AddBoundaryCondition(psc); } return true; } ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // Constructor FEMultiphasicTangentDiagnostic::FEMultiphasicTangentDiagnostic(FEModel* fem) : FEDiagnostic(fem) { // make sure the correct module is active fem->SetActiveModule("multiphasic"); m_pscn = 0; FEAnalysis* pstep = new FEAnalysis(fem); // create a new solver FESolver* pnew_solver = fecore_new<FESolver>("multiphasic", fem); assert(pnew_solver); pnew_solver->m_msymm = REAL_UNSYMMETRIC; pstep->SetFESolver(pnew_solver); fem->AddStep(pstep); fem->SetCurrentStep(pstep); } //----------------------------------------------------------------------------- FEDiagnosticScenario* FEMultiphasicTangentDiagnostic::CreateScenario(const std::string& sname) { if (sname == "multiphasic uni-axial") return (m_pscn = new FEMultiphasicTangentUniaxial(this)); return 0; } //----------------------------------------------------------------------------- // Initialize the diagnostic. In this function we build the FE model depending // on the scenario. bool FEMultiphasicTangentDiagnostic::Init() { if (m_pscn == 0) return false; if (m_pscn->Init() == false) return false; return FEDiagnostic::Init(); } //----------------------------------------------------------------------------- // Helper function to print a matrix void FEMultiphasicTangentDiagnostic::print_matrix(matrix& m) { int i, j; int N = m.rows(); int M = m.columns(); feLog("\n "); for (i=0; i<N; ++i) feLog("%15d ", i); feLog("\n----"); for (i=0; i<N; ++i) feLog("----------------", i); for (i=0; i<N; ++i) { feLog("\n%2d: ", i); for (j=0; j<M; ++j) { feLog("%15lg ", m[i][j]); } } feLog("\n"); } //----------------------------------------------------------------------------- // Run the tangent diagnostic. After we run the FE model, we calculate // the element stiffness matrix and compare that to a finite difference // of the element residual. bool FEMultiphasicTangentDiagnostic::Run() { FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; // solve the problem fem.BlockLog(); if (fem.Solve() == false) { fem.UnBlockLog(); return false; } fem.UnBlockLog(); // get the material FEMaterial* pmat = fem.GetMaterial(0); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*>(pmat); assert(pmp); int nsol = pmp->Solutes(); int ndpn = 4+nsol; FEMesh& mesh = fem.GetMesh(); FEMultiphasicSolidDomain& md = static_cast<FEMultiphasicSolidDomain&>(mesh.Domain(0)); // get the one and only element FESolidElement& el = md.Element(0); int N = mesh.Nodes(); // set up the element stiffness matrix matrix k0(ndpn*N, ndpn*N); k0.zero(); md.ElementMultiphasicStiffness(el, k0, false); double k0max = 0; for (int i=0; i<ndpn*N; ++i) for (int j=0; j<ndpn*N; ++j) if (fabs(k0[i][j]) > k0max) k0max = fabs(k0[i][j]); // print the element stiffness matrix feLog("\nActual stiffness matrix:\n"); print_matrix(k0); // now calculate the derivative of the residual matrix k1; deriv_residual(k1); // print the approximate element stiffness matrix feLog("\nApproximate stiffness matrix:\n"); print_matrix(k1); // finally calculate the difference matrix feLog("\n"); matrix kd(ndpn*N, ndpn*N); double kmax = 0, kij; int i0 = -1, j0 = -1, i, j; for (i=0; i<ndpn*N; ++i) for (j=0; j<ndpn*N; ++j) { kd[i][j] = k0[i][j] - k1[i][j]; kij = 100.0*fabs(kd[i][j] / k0max); if (kij > kmax) { kmax = kij; i0 = i; j0 = j; } } // print the difference feLog("\ndifference matrix:\n"); print_matrix(kd); feLog("\nMaximum difference: %lg%% (at (%d,%d))\n", kmax, i0, j0); return (kmax < 1e-4); } //----------------------------------------------------------------------------- // Calculate a finite difference approximation of the derivative of the // element residual. void FEMultiphasicTangentDiagnostic::deriv_residual(matrix& ke) { int i, j, nj; // get the solver FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; FEMultiphasicSolver& solver = static_cast<FEMultiphasicSolver&>(*pstep->GetFESolver()); // get the material FEMaterial* pmat = fem.GetMaterial(0); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic*>(pmat); assert(pmp); int nsol = pmp->Solutes(); int ndpn = 4+nsol; // get the mesh FEMesh& mesh = fem.GetMesh(); 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); FEMultiphasicSolidDomain& md = static_cast<FEMultiphasicSolidDomain&>(mesh.Domain(0)); // get the one and only element FESolidElement& el = md.Element(0); int N = mesh.Nodes(); // first calculate the initial residual vector<double> f0(ndpn*N); vector< vector<double> > f0c(nsol,vector<double>(N)); zero(f0); md.ElementInternalForce(el, f0); // now calculate the perturbed residuals ke.resize(ndpn*N, ndpn*N); ke.zero(); double dx = 1e-8; vector<double> f1(ndpn*N); for (j=0; j<ndpn*N; ++j) { FENode& node = mesh.Node(el.m_node[j/ndpn]); nj = j%ndpn; switch (nj) { case 0: node.add(dof_x, dx); node.m_rt.x += dx; break; case 1: node.add(dof_y, dx); node.m_rt.y += dx; break; case 2: node.add(dof_z, dx); node.m_rt.z += dx; break; case 3: node.add(dof_p, dx); break; default: node.add(dof_c + nj-4, dx); break; } fem.Update(); zero(f1); md.ElementInternalForce(el, f1); switch (nj) { case 0: node.sub(dof_x, dx); node.m_rt.x -= dx; break; case 1: node.sub(dof_y, dx); node.m_rt.y -= dx; break; case 2: node.sub(dof_z, dx); node.m_rt.z -= dx; break; case 3: node.sub(dof_p, dx); break; default: node.sub(dof_c + nj-4, dx); break; } fem.Update(); for (i=0; i<ndpn*N; ++i) ke[i][j] = -(f1[i] - f0[i])/dx; } }
C++
3D
febiosoftware/FEBio
FEBioTest/FEBiphasicTangentDiagnostic.cpp
.cpp
10,520
343
/*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 "FEBiphasicTangentDiagnostic.h" #include "FETangentDiagnostic.h" #include "FEBioMix/FEBiphasicSolver.h" #include "FEBioMix/FEBiphasicSolidDomain.h" #include <FECore/FEPrescribedDOF.h> #include <FECore/FEFixedBC.h> #include <FECore/FELoadCurve.h> #include "FECore/log.h" //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEBiphasicTangentUniaxial, FEBiphasicScenario) ADD_PARAMETER(m_strain , "solid_strain" ); ADD_PARAMETER(m_pressure, "fluid_pressure"); ADD_PARAMETER(m_dt , "time_step" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEBiphasicTangentUniaxial::FEBiphasicTangentUniaxial(FEDiagnostic* pdia) : FEBiphasicScenario(pdia) { m_strain = 0; m_pressure = 0; } //----------------------------------------------------------------------------- // Build the uniaxial loading scenario // Cube with face displaced along x, with zero fluid pressure on displaced face // and impermeable fixed face. bool FEBiphasicTangentUniaxial::Init() { int i; vec3d r[8] = { vec3d(0,0,0), vec3d(1,0,0), vec3d(1,1,0), vec3d(0,1,0), vec3d(0,0,1), vec3d(1,0,1), vec3d(1,1,1), vec3d(0,1,1) }; int BC[8][4] = { {-1,-1,-1, 0},{ 0,-1,-1,-1},{ 0, 0,-1,-1}, {-1, 0,-1, 0}, {-1,-1, 0, 0},{ 0,-1, 0,-1},{ 0, 0, 0,-1}, {-1, 0, 0, 0} }; FEModel& fem = *GetDiagnostic()->GetFEModel(); int MAX_DOFS = fem.GetDOFS().GetTotalDOFS(); 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"); // --- create the FE problem --- // create the mesh FEMesh& m = fem.GetMesh(); m.CreateNodes(8); m.SetDOFS(MAX_DOFS); FENodeSet* nset[4] = { 0 }; for (int i = 0; i < 4; ++i) nset[i] = new FENodeSet(&fem); for (i=0; i<8; ++i) { FENode& n = m.Node(i); n.m_rt = n.m_r0 = r[i]; // set displacement BC's if (BC[i][0] == -1) nset[0]->Add(i); if (BC[i][1] == -1) nset[1]->Add(i); if (BC[i][2] == -1) nset[2]->Add(i); if (BC[i][3] == -1) nset[3]->Add(i); } fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_x, nset[0])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_y, nset[1])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_z, nset[2])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_p, nset[3])); // get the material FEMaterial* pmat = fem.GetMaterial(0); // create a biphasic domain FEBiphasicSolidDomain* pd = new FEBiphasicSolidDomain(&fem); pd->SetMaterial(pmat); pd->Create(1, FEElementLibrary::GetElementSpecFromType(FE_HEX8G8)); pd->SetMatID(0); m.AddDomain(pd); FESolidElement& el = pd->Element(0); el.SetID(1); for (i=0; i<8; ++i) el.m_node[i] = i; pd->CreateMaterialPointData(); // convert strain to a displacement double d = sqrt(2*m_strain+1) - 1; // Add a loadcurve FELoadCurve* plc = new FELoadCurve(&fem); plc->Add(0.0, 0.0); plc->Add(1.0, 1.0); fem.AddLoadController(plc); // Add a prescribed BC FENodeSet* dc = new FENodeSet(&fem); dc->Add({1, 2, 5, 6}); FEPrescribedDOF* pdc = new FEPrescribedDOF(&fem, dof_x, dc); pdc->SetScale(d, 0); fem.AddBoundaryCondition(pdc); return true; } //----------------------------------------------------------------------------- // Constructor FEBiphasicTangentDiagnostic::FEBiphasicTangentDiagnostic(FEModel* fem) : FEDiagnostic(fem) { m_pscn = 0; // make sure the correct module is active fem->SetActiveModule("biphasic"); FEAnalysis* pstep = new FEAnalysis(fem); // create a new solver FESolver* pnew_solver = fecore_new<FESolver>("biphasic", fem); assert(pnew_solver); pnew_solver->m_msymm = REAL_UNSYMMETRIC; pstep->SetFESolver(pnew_solver); fem->AddStep(pstep); fem->SetCurrentStep(pstep); } //----------------------------------------------------------------------------- FEDiagnosticScenario* FEBiphasicTangentDiagnostic::CreateScenario(const std::string& sname) { if (sname == "biphasic uni-axial") return (m_pscn = new FEBiphasicTangentUniaxial(this)); return 0; } //----------------------------------------------------------------------------- // Initialize the diagnostic. In this function we build the FE model depending // on the scenario. bool FEBiphasicTangentDiagnostic::Init() { if (m_pscn == 0) return false; if (m_pscn->Init() == false) return false; return FEDiagnostic::Init(); } //----------------------------------------------------------------------------- // Helper function to print a matrix void FEBiphasicTangentDiagnostic::print_matrix(matrix& m) { int i, j; int N = m.rows(); int M = m.columns(); feLog("\n "); for (i=0; i<N; ++i) feLog("%15d ", i); feLog("\n----"); for (i=0; i<N; ++i) feLog("----------------", i); for (i=0; i<N; ++i) { feLog("\n%2d: ", i); for (j=0; j<M; ++j) { feLog("%15lg ", m[i][j]); } } feLog("\n"); } //----------------------------------------------------------------------------- // Run the tangent diagnostic. After we run the FE model, we calculate // the element stiffness matrix and compare that to a finite difference // of the element residual. bool FEBiphasicTangentDiagnostic::Run() { FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; // solve the problem fem.BlockLog(); fem.Solve(); fem.UnBlockLog(); FEMesh& mesh = fem.GetMesh(); FEBiphasicSolidDomain& bd = static_cast<FEBiphasicSolidDomain&>(mesh.Domain(0)); // get the one and only element FESolidElement& el = bd.Element(0); int N = mesh.Nodes(); // set up the element stiffness matrix matrix k0(4*N, 4*N); k0.zero(); bd.ElementBiphasicStiffness(el, k0, false); // print the element stiffness matrix feLog("\nActual stiffness matrix:\n"); print_matrix(k0); // now calculate the derivative of the residual matrix k1; deriv_residual(k1); // print the approximate element stiffness matrix feLog("\nApproximate stiffness matrix:\n"); print_matrix(k1); // finally calculate the difference matrix feLog("\n"); matrix kd(4*N, 4*N); double kmax = 0, kij; int i0 = -1, j0 = -1, i, j; for (i=0; i<4*N; ++i) for (j=0; j<4*N; ++j) { kd[i][j] = k0[i][j] - k1[i][j]; kij = 100.0*fabs(kd[i][j] / k0[0][0]); if (kij > kmax) { kmax = kij; i0 = i; j0 = j; } } // print the difference feLog("\ndifference matrix:\n"); print_matrix(kd); feLog("\nMaximum difference: %lg%% (at (%d,%d))\n", kmax, i0, j0); return (kmax < 1e-4); } //----------------------------------------------------------------------------- // Calculate a finite difference approximation of the derivative of the // element residual. void FEBiphasicTangentDiagnostic::deriv_residual(matrix& ke) { int i, j, nj; // get the solver FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; // 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"); // get the mesh FEMesh& mesh = fem.GetMesh(); FEBiphasicSolidDomain& bd = static_cast<FEBiphasicSolidDomain&>(mesh.Domain(0)); // get the one and only element FESolidElement& el = bd.Element(0); int N = mesh.Nodes(); // first calculate the initial residual vector<double> f0(4*N); zero(f0); bd.ElementInternalForce(el, f0); // now calculate the perturbed residuals ke.resize(4*N, 4*N); ke.zero(); double dx = 1e-8; vector<double> f1(4*N); for (j=0; j<4*N; ++j) { FENode& node = mesh.Node(el.m_node[j/4]); nj = j%4; switch (nj) { case 0: node.add(dof_x, dx); node.m_rt.x += dx; break; case 1: node.add(dof_y, dx); node.m_rt.y += dx; break; case 2: node.add(dof_z, dx); node.m_rt.z += dx; break; case 3: node.add(dof_p, dx); break; } fem.Update(); zero(f1); bd.ElementInternalForce(el, f1); switch (nj) { case 0: node.sub(dof_x, dx); node.m_rt.x -= dx; break; case 1: node.sub(dof_y, dx); node.m_rt.y -= dx; break; case 2: node.sub(dof_z, dx); node.m_rt.z -= dx; break; case 3: node.sub(dof_p, dx); break; } fem.Update(); for (i=0; i<4*N; ++i) ke[i][j] = -(f1[i] - f0[i])/dx; } }
C++
3D
febiosoftware/FEBio
FEBioTest/FEPrintHBMatrixDiagnostic.cpp
.cpp
3,300
109
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEPrintHBMatrixDiagnostic.h" #include "FEBioMech/FESolidSolver2.h" #include <FECore/CompactMatrix.h> #include <FECore/FEGlobalMatrix.h> #include <NumCore/MatrixTools.h> //----------------------------------------------------------------------------- FEPrintHBMatrixDiagnostic::FEPrintHBMatrixDiagnostic(FEModel* fem) : FEDiagnostic(fem) { } //----------------------------------------------------------------------------- FEPrintHBMatrixDiagnostic::~FEPrintHBMatrixDiagnostic(void) { } //----------------------------------------------------------------------------- bool FEPrintHBMatrixDiagnostic::ParseSection(XMLTag &tag) { FEModel& fem = *GetFEModel(); if (tag == "input") { // get the input file name const char* szfile = tag.szvalue(); // try to read the file FEBioImport im; if (im.Load(fem, szfile) == false) { char szerr[256]; im.GetErrorMessage(szerr); fprintf(stderr, "%s", szerr); return false; } return true; } return false; } //----------------------------------------------------------------------------- bool FEPrintHBMatrixDiagnostic::Run() { // Get the current step FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); // initialize the step pstep->Activate(); // get and initialize the FE solver FENewtonSolver* solver = dynamic_cast<FENewtonSolver*>(pstep->GetFESolver()); if (solver == 0) return false; // do initialization FETimeInfo& tp = fem.GetTime(); tp.currentTime = pstep->m_dt0; tp.timeIncrement = pstep->m_dt0; solver->InitStep(pstep->m_dt0); solver->PrepStep(); // reshape the stiffness matrix if (!solver->ReformStiffness()) return false; // get the matrix SparseMatrix* psm = solver->GetStiffnessMatrix()->GetSparseMatrixPtr(); CompactMatrix* pcm = dynamic_cast<CompactMatrix*>(psm); if (pcm == 0) return false; // print the matrix to file if (NumCore::write_hb(*pcm, "hb_matrix.out") == false) { fprintf(stderr, "Failed writing sparse matrix.\n\n"); } return true; }
C++
3D
febiosoftware/FEBio
FEBioTest/FEBiphasicTangentDiagnostic.h
.h
2,533
81
/*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 "FEDiagnostic.h" //----------------------------------------------------------------------------- class FEBiphasicScenario : public FEDiagnosticScenario { public: FEBiphasicScenario(FEDiagnostic* pdia) : FEDiagnosticScenario(pdia) { m_dt = 1.0; } public: double m_dt; }; //----------------------------------------------------------------------------- class FEBiphasicTangentUniaxial : public FEBiphasicScenario { public: FEBiphasicTangentUniaxial(FEDiagnostic* pdia); bool Init() override; private: double m_strain; double m_pressure; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- //! The FEBiphasicTangentDiagnostic class tests the stiffness matrix implementation //! by comparing it to a numerical approximating of the derivative of the //! residual. class FEBiphasicTangentDiagnostic : public FEDiagnostic { public: FEBiphasicTangentDiagnostic(FEModel* fem); virtual ~FEBiphasicTangentDiagnostic(){} bool Init(); bool Run(); FEDiagnosticScenario* CreateScenario(const std::string& sname); protected: void deriv_residual(matrix& ke); void print_matrix(matrix& m); public: FEBiphasicScenario* m_pscn; };
Unknown
3D
febiosoftware/FEBio
FEBioTest/FEFluidFSITangentDiagnostic.cpp
.cpp
12,872
393
/*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 "FEFluidFSITangentDiagnostic.h" #include "FETangentDiagnostic.h" #include "FEBioLib/FEBox.h" #include "FEBioFluid/FEFluidFSISolver.h" #include "FEBioFluid/FEFluidFSIDomain3D.h" #include "FEBioFluid/FEFluidFSIAnalysis.h" #include "FECore/log.h" #include <FECore/FEFixedBC.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEFluidFSITangentUniaxial, FEFluidFSIScenario) ADD_PARAMETER(m_dilation, "fluid_dilation"); ADD_PARAMETER(m_dt , "time_step" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEFluidFSITangentUniaxial::FEFluidFSITangentUniaxial(FEDiagnostic* pdia) : FEFluidFSIScenario(pdia) { m_dilation = 0; m_dt = 1; } //----------------------------------------------------------------------------- // Build the uniaxial loading scenario // Cube with uniaxial velocity prescribed along x on left face and dilatation // fixed on right face. Dynamic analysis. bool FEFluidFSITangentUniaxial::Init() { int i; vec3d r[8] = { vec3d(-5.0000000e-01, -5.0000000e-01, 0.0000000e+00), vec3d( 5.0000000e-01, -5.0000000e-01, 0.0000000e+00), vec3d( 5.0000000e-01, 5.0000000e-01, 0.0000000e+00), vec3d(-5.0000000e-01, 5.0000000e-01, 0.0000000e+00), vec3d(-5.0000000e-01, -5.0000000e-01, 1.0000000e+00), vec3d( 5.0000000e-01, -5.0000000e-01, 1.0000000e+00), vec3d( 5.0000000e-01, 5.0000000e-01, 1.0000000e+00), vec3d(-5.0000000e-01, 5.0000000e-01, 1.0000000e+00) }; int BC[8][7] = { { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, 0} }; FEModel& fem = *GetDiagnostic()->GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); pstep->m_nanalysis = FEFluidFSIAnalysis::DYNAMIC; // pstep->m_nanalysis = FEFluidFSIAnalysis::STEADY_STATE; int MAX_DOFS = fem.GetDOFS().GetTotalDOFS(); const int dof_X = fem.GetDOFIndex("x"); const int dof_Y = fem.GetDOFIndex("y"); const int dof_Z = fem.GetDOFIndex("z"); const int dof_WX = fem.GetDOFIndex("wx"); const int dof_WY = fem.GetDOFIndex("wy"); const int dof_WZ = fem.GetDOFIndex("wz"); const int dof_EF = fem.GetDOFIndex("ef"); // --- create the FE problem --- // create the mesh FEMesh& m = fem.GetMesh(); m.CreateNodes(8); m.SetDOFS(MAX_DOFS); FENodeSet* nset[7] = { 0 }; for (int i = 0; i < 7; ++i) nset[i] = new FENodeSet(&fem); for (i=0; i<8; ++i) { FENode& n = m.Node(i); n.m_rt = n.m_r0 = r[i]; // set displacement BC's if (BC[i][0] == -1) nset[0]->Add(i); if (BC[i][1] == -1) nset[1]->Add(i); if (BC[i][2] == -1) nset[2]->Add(i); if (BC[i][3] == -1) nset[3]->Add(i); if (BC[i][4] == -1) nset[4]->Add(i); if (BC[i][5] == -1) nset[5]->Add(i); if (BC[i][6] == -1) nset[6]->Add(i); } fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_X , nset[0])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_Y , nset[1])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_Z , nset[2])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WX, nset[3])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WY, nset[4])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_WZ, nset[5])); fem.AddBoundaryCondition(new FEFixedBC(&fem, dof_EF, nset[6])); // get the material FEMaterial* pmat = fem.GetMaterial(0); // create a fluid domain FEFluidFSIDomain3D* pd = new FEFluidFSIDomain3D(&fem); pd->SetMaterial(pmat); pd->Create(1, FEElementLibrary::GetElementSpecFromType(FE_HEX8G8)); pd->SetMatID(0); m.AddDomain(pd); FESolidElement& el = pd->Element(0); el.SetID(1); for (i=0; i<8; ++i) el.m_node[i] = i; pd->CreateMaterialPointData(); // Add a loadcurve /* FELoadCurve* plc = new FELoadCurve(new FELinearFunction(&fem, 1.0, 0.0)); fem.AddLoadCurve(plc); // Add a prescribed BC int nd[4] = {0, 4, 3, 7}; FEPrescribedDOF* pdc = new FEPrescribedDOF(&fem); fem.AddPrescribedBC(pdc); pdc->SetDOF(dof_EF).SetScale(m_dilation, 0); for (i = 0; i<4; ++i) pdc->AddNode(nd[i]);*/ return true; } //----------------------------------------------------------------------------- // Constructor FEFluidFSITangentDiagnostic::FEFluidFSITangentDiagnostic(FEModel* fem) : FEDiagnostic(fem) { m_pscn = 0; // make sure the correct module is active fem->SetActiveModule("fluid-FSI"); FEAnalysis* pstep = new FEAnalysis(fem); // create a new solver FESolver* pnew_solver = fecore_new<FESolver>("fluid-FSI", fem); assert(pnew_solver); pnew_solver->m_msymm = REAL_UNSYMMETRIC; FEFluidFSISolver* fluid_solver = dynamic_cast<FEFluidFSISolver*>(pnew_solver); fluid_solver->m_rhoi = 0; fluid_solver->m_pred = 0; pstep->SetFESolver(pnew_solver); fem->AddStep(pstep); fem->SetCurrentStep(pstep); } //----------------------------------------------------------------------------- FEDiagnosticScenario* FEFluidFSITangentDiagnostic::CreateScenario(const std::string& sname) { if (sname == "fluid uni-axial") return (m_pscn = new FEFluidFSITangentUniaxial(this)); return 0; } //----------------------------------------------------------------------------- // Initialize the diagnostic. In this function we build the FE model depending // on the scenario. bool FEFluidFSITangentDiagnostic::Init() { if (m_pscn == 0) return false; if (m_pscn->Init() == false) return false; return FEDiagnostic::Init(); } //----------------------------------------------------------------------------- // Helper function to print a matrix void FEFluidFSITangentDiagnostic::print_matrix(matrix& m) { int i, j; int N = m.rows(); int M = m.columns(); feLog("\n "); for (i=0; i<N; ++i) feLog("%15d ", i); feLog("\n----"); for (i=0; i<N; ++i) feLog("----------------", i); for (i=0; i<N; ++i) { feLog("\n%2d: ", i); for (j=0; j<M; ++j) { feLog("%15lg ", m[i][j]); } } feLog("\n"); } //----------------------------------------------------------------------------- // Run the tangent diagnostic. After we run the FE model, we calculate // the element stiffness matrix and compare that to a finite difference // of the element residual. bool FEFluidFSITangentDiagnostic::Run() { // solve the problem FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; pstep->Activate(); fem.BlockLog(); fem.Solve(); fem.UnBlockLog(); FETimeInfo tp; tp.timeIncrement = dt; tp.alpha = 1; tp.beta = 0.25; tp.gamma = 0.5; tp.alphaf = 1; tp.alpham = 1; FEMesh& mesh = fem.GetMesh(); FEFluidFSIDomain3D& bd = static_cast<FEFluidFSIDomain3D&>(mesh.Domain(0)); // get the one and only element FESolidElement& el = bd.Element(0); int N = mesh.Nodes(); // set up the element stiffness matrix const int ndpn = 7; matrix k0(ndpn*N, ndpn*N); k0.zero(); bd.ElementStiffness(el, k0); bd.ElementMassMatrix(el,k0); // print the element stiffness matrix feLog("\nActual stiffness matrix:\n"); print_matrix(k0); // now calculate the derivative of the residual matrix k1; deriv_residual(k1); // print the approximate element stiffness matrix feLog("\nApproximate stiffness matrix:\n"); print_matrix(k1); // finally calculate the difference matrix feLog("\n"); matrix kd(ndpn*N, ndpn*N); double kmax = 0, kij; int i0 = -1, j0 = -1, i, j; for (i=0; i<ndpn*N; ++i) for (j=0; j<ndpn*N; ++j) { kd[i][j] = k0[i][j] - k1[i][j]; kij = 100.0*fabs(kd[i][j] / k0[0][0]); if (kij > kmax) { kmax = kij; i0 = i; j0 = j; } } // print the difference feLog("\ndifference matrix:\n"); print_matrix(kd); feLog("\nMaximum difference: %lg%% (at (%d,%d))\n", kmax, i0, j0); return (kmax < 1e-4); } //----------------------------------------------------------------------------- // Calculate a finite difference approximation of the derivative of the // element residual. void FEFluidFSITangentDiagnostic::deriv_residual(matrix& ke) { int i, j, nj; // get the solver FEModel& fem = *GetFEModel(); FEAnalysis* pstep = fem.GetCurrentStep(); double dt = m_pscn->m_dt; fem.GetTime().timeIncrement = pstep->m_dt0 = dt; pstep->m_tstart = 0; pstep->m_tend = dt; pstep->m_final_time = dt; FEFluidFSISolver& solver = static_cast<FEFluidFSISolver&>(*pstep->GetFESolver()); FETimeInfo& tp = fem.GetTime(); tp.alpha = solver.m_alphaf; tp.beta = solver.m_beta; tp.gamma = solver.m_gamma; tp.alphaf = solver.m_alphaf; tp.alpham = solver.m_alpham; // get the dof indices const int dof_X = fem.GetDOFIndex("x"); const int dof_Y = fem.GetDOFIndex("y"); const int dof_Z = fem.GetDOFIndex("z"); const int dof_WX = fem.GetDOFIndex("wx"); const int dof_WY = fem.GetDOFIndex("wy"); const int dof_WZ = fem.GetDOFIndex("wz"); const int dof_EF = fem.GetDOFIndex("ef"); // get the mesh FEMesh& mesh = fem.GetMesh(); FEFluidFSIDomain3D& bd = static_cast<FEFluidFSIDomain3D&>(mesh.Domain(0)); // get the one and only element FESolidElement& el = bd.Element(0); int N = mesh.Nodes(); // first calculate the initial residual const int ndpn = 7; vector<double> f0(ndpn*N); zero(f0); bd.ElementInternalForce(el, f0); bd.ElementInertialForce(el, f0); // now calculate the perturbed residuals ke.resize(ndpn*N, ndpn*N); ke.zero(); double dx = 1e-8; vector<double> f1(ndpn*N); for (j=0; j<ndpn*N; ++j) { FENode& node = mesh.Node(el.m_node[j/ndpn]); nj = j%ndpn; switch (nj) { case 0: node.add(dof_X, dx); node.m_rt.x += dx; break; case 1: node.add(dof_Y, dx); node.m_rt.y += dx; break; case 2: node.add(dof_Z, dx); node.m_rt.z += dx; break; case 3: node.add(dof_WX, dx); break; case 4: node.add(dof_WY, dx); break; case 5: node.add(dof_WZ, dx); break; case 6: node.add(dof_EF, dx); break; } fem.Update(); zero(f1); bd.ElementInternalForce(el, f1); bd.ElementInertialForce(el, f1); switch (nj) { case 0: node.sub(dof_X, dx); node.m_rt.x -= dx; break; case 1: node.sub(dof_Y, dx); node.m_rt.y -= dx; break; case 2: node.sub(dof_Z, dx); node.m_rt.z -= dx; break; case 3: node.sub(dof_WX, dx); break; case 4: node.sub(dof_WY, dx); break; case 5: node.sub(dof_WZ, dx); break; case 6: node.sub(dof_EF, dx); break; } fem.Update(); for (i=0; i<ndpn*N; ++i) ke[i][j] = -(f1[i] - f0[i])/dx; } }
C++
3D
febiosoftware/FEBio
FEBioTest/FETiedBiphasicDiagnostic.h
.h
2,678
85
/*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 "FEDiagnostic.h" class SparseMatrix; //----------------------------------------------------------------------------- class FETiedBiphasicScenario : public FEDiagnosticScenario { public: FETiedBiphasicScenario(FEDiagnostic* pdia) : FEDiagnosticScenario(pdia) { m_dt = 1.0; } public: double m_dt; }; //----------------------------------------------------------------------------- class FETiedBiphasicTangentHex8 : public FETiedBiphasicScenario { public: FETiedBiphasicTangentHex8(FEDiagnostic* pdia); bool Init() override; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- class FETiedBiphasicTangentHex20 : public FETiedBiphasicScenario { public: FETiedBiphasicTangentHex20(FEDiagnostic* pdia); bool Init() override; DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- class FETiedBiphasicDiagnostic : public FEDiagnostic { public: FETiedBiphasicDiagnostic(FEModel* fem); ~FETiedBiphasicDiagnostic(); bool Run(); bool Init(); FEDiagnosticScenario* CreateScenario(const std::string& sname); protected: void print_matrix(matrix& m); void print_matrix(SparseMatrix& m); void deriv_residual(matrix& K); public: FETiedBiphasicScenario* m_pscn; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBioMixPlot.cpp
.cpp
48,617
1,549
/*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 "FEBioMixPlot.h" #include "FEBiphasicSolidDomain.h" #include "FEBiphasicShellDomain.h" #include "FEBiphasicSoluteDomain.h" #include "FEBiphasicSoluteSolidDomain.h" #include "FEBiphasicSoluteShellDomain.h" #include "FETriphasicDomain.h" #include "FEMultiphasicSolidDomain.h" #include "FEMultiphasicShellDomain.h" #include <FEBioMech/FEElasticSolidDomain.h> #include <FEBioMech/FESlidingInterface.h> #include "FEBiphasic.h" #include "FEBiphasicSolute.h" #include "FETriphasic.h" #include "FEMultiphasic.h" #include "FEBiphasicContactSurface.h" #include "FESlidingInterfaceMP.h" #include "FETiedBiphasicInterface.h" #include "FETiedMultiphasicInterface.h" #include "FEBioMech/FEDonnanEquilibrium.h" #include "FEBioMech/FEElasticMixture.h" #include <FECore/FEModel.h> #include <FECore/writeplot.h> #include <FECore/FEEdgeList.h> //============================================================================= // S U R F A C E D A T A //============================================================================= //----------------------------------------------------------------------------- // Plot local fluid load support bool FEPlotLocalFluidLoadSupport::Save(FESurface& surf, FEDataStream& a) { FEBiphasicContactSurface* pcs = dynamic_cast<FEBiphasicContactSurface*>(&surf); if (pcs == 0) return false; writeElementValue<double>(surf, a, [=](int nface) { double gn; pcs->GetLocalFLS(nface, gn); return gn; }); return true; } //----------------------------------------------------------------------------- // Plot effective friction coefficient bool FEPlotEffectiveFrictionCoeff::Save(FESurface& surf, FEDataStream& a) { FEBiphasicContactSurface* pcs = dynamic_cast<FEBiphasicContactSurface*>(&surf); if (pcs == 0) return false; writeElementValue<double>(surf, a, [=](int nface) { double gn; pcs->GetMuEffective(nface, gn); return gn; }); return true; } //----------------------------------------------------------------------------- bool FEPlotMixtureFluidFlowRate::Save(FESurface &surf, FEDataStream &a) { FESurface* pcs = &surf; if (pcs == 0) return false; int NF = pcs->Elements(); double fn = 0; // initialize // calculate net flow rate normal to this surface for (int j = 0; j<NF; ++j) { FESurfaceElement& el = pcs->Element(j); // get the element this surface element belongs to FEElement* pe = el.m_elem[0].pe; if (pe) { // evaluate the average fluid flux in this element int nint = pe->GaussPoints(); vec3d w(0, 0, 0); for (int n = 0; n<nint; ++n) { FEMaterialPoint& mp = *pe->GetMaterialPoint(n); FEBiphasicMaterialPoint* ptf = mp.ExtractData<FEBiphasicMaterialPoint>(); if (ptf) w += ptf->m_w; } w /= nint; vec3d area = pcs->SurfaceNormal(el, 0, 0) * pcs->FaceArea(el); // Evaluate contribution to net flow rate across surface. fn += w*area; } } // save results a << fn; return true; } //----------------------------------------------------------------------------- // Plot contact gap bool FEPlotContactGapMP::Save(FESurface& surf, FEDataStream& a) { FEContactSurface* pcs = dynamic_cast<FEContactSurface*>(&surf); if (pcs == 0) return false; writeAverageElementValue<double>(surf, a, [](const FEMaterialPoint& mp) { const FEContactMaterialPoint* pt = dynamic_cast<const FEContactMaterialPoint*>(&mp); double d = (pt ? pt->m_gap : 0); if (d == 0) { const FETiedBiphasicContactPoint* pd = dynamic_cast<const FETiedBiphasicContactPoint*>(&mp); vec3d vd = (pd ? pd->m_dg : vec3d(0,0,0)); d = (pd ? vd.unit() : 0); } return d; }); return true; } //----------------------------------------------------------------------------- // Plot pressure gap bool FEPlotPressureGap::Save(FESurface& surf, FEDataStream& a) { FEBiphasicContactSurface* pcs = dynamic_cast<FEBiphasicContactSurface*>(&surf); if (pcs == 0) return false; writeAverageElementValue<double>(surf, a, [](const FEMaterialPoint& mp) { const FEBiphasicContactPoint* pt = dynamic_cast<const FEBiphasicContactPoint*>(&mp); return (pt ? pt->m_pg : 0); }); return true; } //----------------------------------------------------------------------------- bool FEPlotFluidForce::Save(FESurface &surf, FEDataStream &a) { FEBiphasicContactSurface* pcs = dynamic_cast<FEBiphasicContactSurface*>(&surf); if (pcs == 0) return false; vec3d fn = pcs->GetFluidForce(); a << fn; return true; } //----------------------------------------------------------------------------- class FEFluidForce2 { public: FEFluidForce2(FESurface& surf, vector<double>& nodalPressures) : m_surf(surf), m_nodalPressures(nodalPressures) {} FEFluidForce2(const FEFluidForce2& fl) : m_surf(fl.m_surf), m_nodalPressures(fl.m_nodalPressures) {} vec3d operator ()(const FEMaterialPoint& mp) { FEElement* pe = mp.m_elem; double pn[FEElement::MAX_NODES]; int neln = pe->Nodes(); for (int j = 0; j<neln; ++j) pn[j] = m_nodalPressures[pe->m_node[j]]; FESurfaceElement& face = static_cast<FESurfaceElement&>(*pe); // get the base vectors vec3d g[2]; m_surf.CoBaseVectors(face, mp.m_index, g); // normal (magnitude = area) vec3d n = g[0] ^ g[1]; // gauss weight double w = face.GaussWeights()[mp.m_index]; // fluid pressure double p = face.eval(pn, mp.m_index); // contact force return n*(w*p); } private: FESurface& m_surf; vector<double>& m_nodalPressures; }; bool FEPlotFluidForce2::Save(FESurface &surf, FEDataStream &a) { // get number of facets int NF = surf.Elements(); if (NF == 0) return false; // this assumes that the surface sits on top of a single domain // so that we can figure out the domain from a single element FESurfaceElement& ref = surf.Element(0); if (ref.m_elem[0].pe == nullptr) return false; // get the element FEMesh& mesh = *surf.GetMesh(); FEElement* el = ref.m_elem[0].pe; if (el == 0) return false; // get the domain this element belongs to FEMeshPartition* dom = el->GetMeshPartition(); if (dom == 0) return false; // see if this is a biphasic domain FEBiphasicSolidDomain* biphasicDomain = dynamic_cast<FEBiphasicSolidDomain*>(dom); if (biphasicDomain == 0) return false; // The biphasic solid domain contains actual nodal pressures. // we want to evaluate this over the surface. vector<double> nodalPressures; biphasicDomain->GetNodalPressures(nodalPressures); // calculate element values writeIntegratedElementValue<vec3d>(surf, a, FEFluidForce2(surf, nodalPressures)); return true; } //----------------------------------------------------------------------------- bool FEPlotFluidLoadSupport::Save(FESurface &surf, FEDataStream &a) { FEBiphasicContactSurface* pcs = dynamic_cast<FEBiphasicContactSurface*>(&surf); if (pcs == 0) return false; double fn = pcs->GetFluidLoadSupport(); a << fn; return true; } //----------------------------------------------------------------------------- // Plot concentration gap FEPlotConcentrationGap::FEPlotConcentrationGap(FEModel* pfem) : FEPlotSurfaceData(pfem, PLT_ARRAY, FMT_ITEM) { DOFS& dofs = pfem->GetDOFS(); int nsol = dofs.GetVariableSize("concentration"); SetArraySize(nsol); // collect the names int ndata = pfem->GlobalDataItems(); vector<string> s; for (int i = 0; i<ndata; ++i) { FESoluteData* ps = dynamic_cast<FESoluteData*>(pfem->GetGlobalData(i)); if (ps) { s.push_back(ps->GetName()); m_sol.push_back(ps->GetID()); } } assert(nsol == (int)s.size()); SetArrayNames(s); SetUnits(UNIT_CONCENTRATION); } bool FEPlotConcentrationGap::Save(FESurface& surf, FEDataStream& a) { FEContactSurface* pcs = dynamic_cast<FEContactSurface*>(&surf); if (pcs == 0) return false; for (int i=0; i<surf.Elements(); ++i) { FESurfaceElement& el = surf.Element(i); FEElement* se = (el.m_elem[0]).pe; FEMaterial* mat = GetFEModel()->GetMaterial(se->GetMatID()); FESoluteInterface* pm = dynamic_cast<FESoluteInterface*>(mat); if ((pm == 0) || (pm->Solutes() == 0)) return false; // figure out the local solute IDs. This depends on the material int nsols = (int)m_sol.size(); vector<int> lid(nsols, -1); int nsc = 0; for (int i = 0; i<(int)m_sol.size(); ++i) { lid[i] = pm->FindLocalSoluteID(m_sol[i]); if (lid[i] != -1) nsc++; } if (nsc == 0) return false; for (int k=0; k<nsols; ++k) { int nsid = lid[k]; if (nsid == -1) a << 0.f; else { // calculate average concentration gp double ew = 0; for (int j = 0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); const FEMultiphasicContactPoint* pt = dynamic_cast<const FEMultiphasicContactPoint*>(&mp); const FETiedMultiphasicContactPoint* tt = dynamic_cast<const FETiedMultiphasicContactPoint*>(&mp); if (pt) ew += pt->m_cg[nsid]; else if (tt) ew += tt->m_cg[nsid]; } ew /= el.GaussPoints(); a << ew; } } } return true; } //============================================================================= // D O M A I N D A T A //============================================================================= //----------------------------------------------------------------------------- class FEMPSpecificStrainEnergy { public: FEMPSpecificStrainEnergy(FEMultiphasic* pm) : m_mat(pm) {} double operator()(const FEMaterialPoint& mp) { return m_mat->GetElasticMaterial()->StrainEnergyDensity(const_cast<FEMaterialPoint&>(mp))/m_mat->SolidReferentialApparentDensity(const_cast<FEMaterialPoint&>(mp)); } private: FEMultiphasic* m_mat; }; bool FEPlotMPSpecificStrainEnergy::Save(FEDomain &dom, FEDataStream& a) { FEMultiphasic* pme = dom.GetMaterial()->ExtractProperty<FEMultiphasic>(); if (pme == 0) return false; if (dom.Class() == FE_DOMAIN_SOLID) { FEMPSpecificStrainEnergy psi(pme); writeAverageElementValue<double>(dom, a, psi); return true; } return false; } //----------------------------------------------------------------------------- bool FEPlotActualFluidPressure::Save(FEDomain &dom, FEDataStream& a) { FESolidDomain& bd = static_cast<FESolidDomain&>(dom); FEShellDomain& bsd = static_cast<FEShellDomain&>(dom); if ((dynamic_cast<FEBiphasicSolidDomain* >(&bd)) || (dynamic_cast<FEBiphasicSoluteSolidDomain*>(&bd)) || (dynamic_cast<FETriphasicDomain* >(&bd)) || (dynamic_cast<FEMultiphasicSolidDomain* >(&bd))) { writeAverageElementValue<double>(dom, a, [](const FEMaterialPoint& mp) { const FEBiphasicMaterialPoint* pt = mp.ExtractData<FEBiphasicMaterialPoint>(); return (pt ? pt->m_pa : 0.0); }); return true; } else if (dynamic_cast<FEElasticSolidDomain* >(&bd)) { for (int i=0; i<bd.Elements(); ++i) { FESolidElement& el = bd.Element(i); FEElasticMixture* pem = dynamic_cast<FEElasticMixture*> (dom.GetMaterial()); if (pem == nullptr) return false; // extract fixed-charge density double ew = 0; for (int j=0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); for (int k=0; k<pem->Materials(); ++k) { FEDonnanEquilibriumMaterialPoint* pd = pt.GetPointData(k)->ExtractData<FEDonnanEquilibriumMaterialPoint>(); if (pd) ew += pd->m_p; } } ew /= el.GaussPoints(); a << ew; } return true; } return false; } //----------------------------------------------------------------------------- bool FEPlotSolidStress::Save(FEDomain &dom, FEDataStream& a) { FESolidDomain* bd = dynamic_cast<FESolidDomain*>(&dom); FEShellDomain* bsd = dynamic_cast<FEShellDomain*>(&dom); if (bd && ( (dynamic_cast<FEBiphasicSolidDomain* >(bd)) || (dynamic_cast<FEBiphasicSoluteSolidDomain*>(bd)) || (dynamic_cast<FETriphasicDomain* >(bd)) || (dynamic_cast<FEMultiphasicSolidDomain*>(bd)))) { writeAverageElementValue<mat3ds>(dom, a, [](const FEMaterialPoint& mp) { const FEBiphasicMaterialPoint* pt = (mp.ExtractData<FEBiphasicMaterialPoint>()); return (pt ? pt->m_ss : mat3ds(0.0)); }); return true; } else if (bsd && ( (dynamic_cast<FEBiphasicShellDomain*>(bsd)) || (dynamic_cast<FEBiphasicSoluteShellDomain*>(bsd)) || (dynamic_cast<FEMultiphasicShellDomain*>(bsd)) )) { writeAverageElementValue<mat3ds>(dom, a, [](const FEMaterialPoint& mp) { const FEBiphasicMaterialPoint* pt = (mp.ExtractData<FEBiphasicMaterialPoint>()); return (pt ? pt->m_ss : mat3ds(0.0)); }); return true; } return false; } //----------------------------------------------------------------------------- bool FEPlotFluidFlux::Save(FEDomain &dom, FEDataStream& a) { FESolidDomain* bd = dynamic_cast<FESolidDomain*>(&dom); FEShellDomain* bsd = dynamic_cast<FEShellDomain*>(&dom); if (bd && ( (dynamic_cast<FEBiphasicSolidDomain* >(bd)) || (dynamic_cast<FEBiphasicSoluteSolidDomain*>(bd)) || (dynamic_cast<FETriphasicDomain* >(bd)) || (dynamic_cast<FEMultiphasicSolidDomain*>(bd)))) { writeAverageElementValue<vec3d>(dom, a, [](const FEMaterialPoint& mp) { const FEBiphasicMaterialPoint* pt = (mp.ExtractData<FEBiphasicMaterialPoint>()); return (pt ? pt->m_w : vec3d(0.0)); }); return true; } else if (bsd && ( (dynamic_cast<FEBiphasicShellDomain*>(bsd)) || (dynamic_cast<FEBiphasicSoluteShellDomain*>(bsd)) || (dynamic_cast<FEMultiphasicShellDomain*>(bsd)) )) { writeAverageElementValue<vec3d>(dom, a, [](const FEMaterialPoint& mp) { const FEBiphasicMaterialPoint* pt = (mp.ExtractData<FEBiphasicMaterialPoint>()); return (pt ? pt->m_w : vec3d(0.0)); }); return true; } return false; } //----------------------------------------------------------------------------- bool FEPlotNodalFluidFlux::Save(FEDomain &dom, FEDataStream& a) { FESolidDomain& bd = static_cast<FESolidDomain&>(dom); if ((dynamic_cast<FEBiphasicSolidDomain* >(&bd)) || (dynamic_cast<FEBiphasicSoluteSolidDomain*>(&bd)) || (dynamic_cast<FETriphasicDomain* >(&bd)) || (dynamic_cast<FEMultiphasicSolidDomain*>(&bd))) { writeNodalProjectedElementValues<vec3d>(dom, a, [](const FEMaterialPoint& mp) { const FEBiphasicMaterialPoint* pt = mp.ExtractData<FEBiphasicMaterialPoint>(); return pt->m_w; }); return true; } return false; } //----------------------------------------------------------------------------- // Finds the solute id of a solute with given ID nsol. // This currently returns either nsol if a solute was found or -1 if not int GetSoluteID(FEModel& fem, int nsol) { int N = fem.GlobalDataItems(); for (int i=0; i<N; ++i) { FESoluteData* psd = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (psd) { if (psd->GetID()-1 == nsol) return psd->GetID(); } } return -1; } //----------------------------------------------------------------------------- // Finds the id of a sbm with given ID nsbm. // This currently returns either nsbm if a solute was found or -1 if not int GetSBMID(FEModel& fem, int nsol) { int N = fem.GlobalDataItems(); for (int i=0; i<N; ++i) { FESBMData* psd = dynamic_cast<FESBMData*>(fem.GetGlobalData(i)); if (psd) { if (psd->GetID()-1 == nsol) return psd->GetID(); } } return -1; } //----------------------------------------------------------------------------- // Finds the solute ID given the name of the solute int GetSoluteID(FEModel& fem, const char* sz) { string soluteName(sz); // find the solute with that name int N = fem.GlobalDataItems(); for (int i=0; i<N; ++i) { FESoluteData* psd = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (psd) { if (psd->GetName() == soluteName) return psd->GetID(); } } return -1; } //----------------------------------------------------------------------------- // Finds the sbm ID given the name of the sbm int GetSBMID(FEModel& fem, const char* sz) { string sbmName(sz); // find the sbm with that name int N = fem.GlobalDataItems(); for (int i=0; i<N; ++i) { FESBMData* psd = dynamic_cast<FESBMData*>(fem.GetGlobalData(i)); if (psd) { if (psd->GetName() == sbmName) return psd->GetID(); } } return -1; } //----------------------------------------------------------------------------- // find the local SBM ID, given a global ID. If the material is not a // multiphasic material, this returns -1. int GetLocalSBMID(FEMultiphasic* pmm, int nsbm) { // figure out the SBM ID to export. This depends on the material type. int nsid = -1; // Check if this solute is present in this specific multiphasic mixture for (int i=0; i<pmm->SBMs(); ++i) if (pmm->GetSBM(i)->GetSBMID() == nsbm) {nsid = i; break;} return nsid; } //================================================================================================= //----------------------------------------------------------------------------- FEPlotActualSoluteConcentration::FEPlotActualSoluteConcentration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_ARRAY, FMT_ITEM) { DOFS& dofs = pfem->GetDOFS(); int nsol = dofs.GetVariableSize("concentration"); SetArraySize(nsol); // collect the names int ndata = pfem->GlobalDataItems(); vector<string> s; for (int i = 0; i<ndata; ++i) { FESoluteData* ps = dynamic_cast<FESoluteData*>(pfem->GetGlobalData(i)); if (ps) { s.push_back(ps->GetName()); m_sol.push_back(ps->GetID()); } } assert(nsol == (int)s.size()); SetArrayNames(s); SetUnits(UNIT_CONCENTRATION); } //----------------------------------------------------------------------------- bool FEPlotActualSoluteConcentration::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* pm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if (pm == 0) return false; // figure out the local solute IDs. This depends on the material int nsols = (int)m_sol.size(); vector<int> lid(nsols, -1); int negs = 0; for (int i = 0; i<(int)m_sol.size(); ++i) { lid[i] = pm->FindLocalSoluteID(m_sol[i]); if (lid[i] < 0) negs++; } if (negs == nsols) return false; // loop over all elements int N = dom.Elements(); for (int i = 0; i<N; ++i) { FEElement& el = dom.ElementRef(i); for (int k=0; k<nsols; ++k) { int nsid = lid[k]; if (nsid == -1) a << 0.f; else { // calculate average concentration double ew = 0; for (int j = 0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); ew += pm->GetActualSoluteConcentration(mp, nsid); } ew /= el.GaussPoints(); a << ew; } } } return true; } //================================================================================================= //----------------------------------------------------------------------------- FEPlotPartitionCoefficient::FEPlotPartitionCoefficient(FEModel* pfem) : FEPlotDomainData(pfem, PLT_ARRAY, FMT_ITEM) { DOFS& dofs = pfem->GetDOFS(); int nsol = dofs.GetVariableSize("concentration"); SetArraySize(nsol); // collect the names int ndata = pfem->GlobalDataItems(); vector<string> s; for (int i = 0; i<ndata; ++i) { FESoluteData* ps = dynamic_cast<FESoluteData*>(pfem->GetGlobalData(i)); if (ps) { s.push_back(ps->GetName()); m_sol.push_back(ps->GetID()); } } assert(nsol == (int)s.size()); SetArrayNames(s); } //----------------------------------------------------------------------------- bool FEPlotPartitionCoefficient::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* pm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if (pm == 0) return false; // figure out the local solute IDs. This depends on the material int nsols = (int)m_sol.size(); vector<int> lid(nsols, -1); int negs = 0; for (int i = 0; i<(int)m_sol.size(); ++i) { lid[i] = pm->FindLocalSoluteID(m_sol[i]); if (lid[i] < 0) negs++; } if (negs == nsols) return false; // loop over all elements int N = dom.Elements(); for (int i = 0; i<N; ++i) { FEElement& el = dom.ElementRef(i); for (int k=0; k<nsols; ++k) { int nsid = lid[k]; if (nsid == -1) a << 0.f; else { // calculate average concentration double ew = 0; for (int j = 0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); ew += pm->GetPartitionCoefficient(mp, nsid); } ew /= el.GaussPoints(); a << ew; } } } return true; } //----------------------------------------------------------------------------- FEPlotSoluteFlux::FEPlotSoluteFlux(FEModel* pfem) : FEPlotDomainData(pfem, PLT_ARRAY_VEC3F, FMT_ITEM) { DOFS& dofs = pfem->GetDOFS(); int nsol = dofs.GetVariableSize("concentration"); SetArraySize(nsol); // collect the names int ndata = pfem->GlobalDataItems(); vector<string> s; for (int i = 0; i<ndata; ++i) { FESoluteData* ps = dynamic_cast<FESoluteData*>(pfem->GetGlobalData(i)); if (ps) { s.push_back(ps->GetName()); m_sol.push_back(ps->GetID()); } } assert(nsol == (int)s.size()); SetArrayNames(s); SetUnits(UNIT_MOLAR_FLUX); } //----------------------------------------------------------------------------- bool FEPlotSoluteFlux::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* pm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if ((pm == 0) || (pm->Solutes() == 0)) return false; // figure out the local solute IDs. This depends on the material int nsols = (int)m_sol.size(); vector<int> lid(nsols, -1); int nsc = 0; for (int i = 0; i<(int)m_sol.size(); ++i) { lid[i] = pm->FindLocalSoluteID(m_sol[i]); if (lid[i] != -1) nsc++; } if (nsc == 0) return false; for (int i = 0; i<dom.Elements(); ++i) { FEElement& el = dom.ElementRef(i); for (int k=0; k<nsols; ++k) { int nsid = lid[k]; if (nsid == -1) a << vec3d(0, 0, 0); else { // calculate average flux vec3d ew = vec3d(0, 0, 0); for (int j = 0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); ew += pm->GetSoluteFlux(mp, nsid); } ew /= el.GaussPoints(); a << ew; } } } return true; } //----------------------------------------------------------------------------- FEPlotSoluteVolumetricFlux::FEPlotSoluteVolumetricFlux(FEModel* pfem) : FEPlotDomainData(pfem, PLT_ARRAY_VEC3F, FMT_ITEM) { DOFS& dofs = pfem->GetDOFS(); int nsol = dofs.GetVariableSize("concentration"); SetArraySize(nsol); // collect the names int ndata = pfem->GlobalDataItems(); vector<string> s; for (int i = 0; i<ndata; ++i) { FESoluteData* ps = dynamic_cast<FESoluteData*>(pfem->GetGlobalData(i)); if (ps) { s.push_back(ps->GetName()); m_sol.push_back(ps->GetID()); } } assert(nsol == (int)s.size()); SetArrayNames(s); SetUnits(UNIT_VELOCITY); } //----------------------------------------------------------------------------- bool FEPlotSoluteVolumetricFlux::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* pm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if ((pm == 0) || (pm->Solutes() == 0)) return false; // figure out the local solute IDs. This depends on the material int nsols = (int)m_sol.size(); vector<int> lid(nsols, -1); int nsc = 0; for (int i = 0; i<(int)m_sol.size(); ++i) { lid[i] = pm->FindLocalSoluteID(m_sol[i]); if (lid[i] != -1) nsc++; } if (nsc == 0) return false; for (int i = 0; i<dom.Elements(); ++i) { FEElement& el = dom.ElementRef(i); for (int k=0; k<nsols; ++k) { int nsid = lid[k]; if (nsid == -1) a << vec3d(0, 0, 0); else { // calculate average flux vec3d ew = vec3d(0, 0, 0); for (int j = 0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); FESolutesMaterialPoint* pt = (mp.ExtractData<FESolutesMaterialPoint>()); if (pt && (pt->m_ca[nsid] > 0)) ew += pt->m_j[nsid]/pt->m_ca[nsid]; } ew /= el.GaussPoints(); a << ew; } } } return true; } //----------------------------------------------------------------------------- bool FEPlotOsmolarity::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); FESolidDomain* sdom = dynamic_cast<FESolidDomain*>(&dom); FEShellDomain* ldom = dynamic_cast<FEShellDomain*>(&dom); if (sdom && psm) { writeAverageElementValue<double>(dom, a, [=](const FEMaterialPoint& mp) { double ew = psm->GetOsmolarity(mp); return ew; }); return true; } else if (sdom && dynamic_cast<FEElasticSolidDomain*>(&dom)) { for (int i=0; i<sdom->Elements(); ++i) { FESolidElement& el = sdom->Element(i); FEElasticMixture* pem = dynamic_cast<FEElasticMixture*> (dom.GetMaterial()); if (pem == nullptr) return false; // extract fixed-charge density double ew = 0; for (int j=0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); for (int k=0; k<pem->Materials(); ++k) { FEDonnanEquilibriumMaterialPoint* pd = pt.GetPointData(k)->ExtractData<FEDonnanEquilibriumMaterialPoint>(); if (pd) ew += pd->m_osm; } } ew /= el.GaussPoints(); a << ew; } return true; } else if (ldom && ( dynamic_cast<FEBiphasicSoluteShellDomain*>(&dom) || dynamic_cast<FEMultiphasicShellDomain*>(&dom))) { writeAverageElementValue<double>(dom, a, [](const FEMaterialPoint& mp) { const FESolutesMaterialPoint* pt = mp.ExtractData<FESolutesMaterialPoint>(); double ew = 0.0; for (int isol = 0; isol<(int)pt->m_ca.size(); ++isol) ew += pt->m_ca[isol]; return ew; }); return true; } return false; } //================================================================================================= // FEPlotSBMConcentration //================================================================================================= //----------------------------------------------------------------------------- FEPlotSBMConcentration::FEPlotSBMConcentration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_ARRAY, FMT_ITEM) { // count SBMs int sbms = 0; int ndata = pfem->GlobalDataItems(); vector<string> names; for (int i=0; i<ndata; ++i) { FESBMData* sbm = dynamic_cast<FESBMData*>(pfem->GetGlobalData(i)); if (sbm) { names.push_back(sbm->GetName()); m_sbm.push_back(sbm->GetID()); sbms++; } } SetArraySize(sbms); SetArrayNames(names); SetUnits(UNIT_CONCENTRATION); } //----------------------------------------------------------------------------- bool FEPlotSBMConcentration::Save(FEDomain &dom, FEDataStream& a) { FEMultiphasic* pm = dynamic_cast<FEMultiphasic*> (dom.GetMaterial()); if (pm == 0) return false; // figure out the local SBM IDs. This depend on the material int nsbm = (int)m_sbm.size(); vector<int> lid(nsbm, -1); for (int i=0; i<(int)m_sbm.size(); ++i) { lid[i] = GetLocalSBMID(pm, m_sbm[i]); } int N = dom.Elements(); for (int i = 0; i<N; ++i) { FEElement& el = dom.ElementRef(i); for (int k=0; k<nsbm; ++k) { int nk = lid[k]; if (nk == -1) a << 0.f; else { // calculate average concentration double ew = 0; for (int j = 0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); FESolutesMaterialPoint* pt = (mp.ExtractData<FESolutesMaterialPoint>()); if (pt) ew += pm->SBMConcentration(mp, nk); } ew /= el.GaussPoints(); a << ew; } } } return true; } //================================================================================================= // FEPlotSBMArealConcentration //================================================================================================= //----------------------------------------------------------------------------- FEPlotSBMArealConcentration::FEPlotSBMArealConcentration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_ARRAY, FMT_ITEM) { // count SBMs int sbms = 0; int ndata = pfem->GlobalDataItems(); vector<string> names; for (int i=0; i<ndata; ++i) { FESBMData* sbm = dynamic_cast<FESBMData*>(pfem->GetGlobalData(i)); if (sbm) { names.push_back(sbm->GetName()); m_sbm.push_back(sbm->GetID()); sbms++; } } SetArraySize(sbms); SetArrayNames(names); SetUnits(UNIT_MOLAR_AREAL_CONCENTRATION); } //----------------------------------------------------------------------------- bool FEPlotSBMArealConcentration::Save(FEDomain &dom, FEDataStream& a) { FEShellDomain* bsd = static_cast<FEShellDomain*>(&dom); if (bsd == nullptr) return false; FEMultiphasic* pm = dynamic_cast<FEMultiphasic*> (dom.GetMaterial()); if (pm == 0) return false; // figure out the local SBM IDs. This depend on the material int nsbm = (int)m_sbm.size(); vector<int> lid(nsbm, -1); for (int i=0; i<(int)m_sbm.size(); ++i) { lid[i] = GetLocalSBMID(pm, m_sbm[i]); } int N = dom.Elements(); for (int i = 0; i<N; ++i) { FEElement& el = dom.ElementRef(i); for (int k=0; k<nsbm; ++k) { int nk = lid[k]; if (nk == -1) a << 0.f; else { // calculate average concentration double ew = 0; for (int j = 0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); FESolutesMaterialPoint* pt = (mp.ExtractData<FESolutesMaterialPoint>()); if (pt) ew += pm->SBMArealConcentration(mp, nk); } ew /= el.GaussPoints(); a << ew; } } } return true; } //----------------------------------------------------------------------------- bool FEPlotElectricPotential::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if (psm == nullptr) return false; writeAverageElementValue<double>(dom, a, [=](const FEMaterialPoint& mp) { return psm->GetElectricPotential(mp); }); return true; } //----------------------------------------------------------------------------- bool FEPlotCurrentDensity::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if (psm == nullptr) return false; writeAverageElementValue<vec3d>(dom, a, [=](const FEMaterialPoint& mp) { return psm->GetCurrentDensity(mp); }); return true; } //----------------------------------------------------------------------------- bool FEPlotReferentialSolidVolumeFraction::Save(FEDomain &dom, FEDataStream& a) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(dom.GetMaterial()); if (pbm == nullptr) return false; writeAverageElementValue<double>(dom, a, [=](const FEMaterialPoint& mp) { double phif0 = pbm->GetReferentialSolidVolumeFraction(mp); return phif0; }); return true; } //----------------------------------------------------------------------------- bool FEPlotPorosity::Save(FEDomain &dom, FEDataStream& a) { FEBiphasicSolidDomain* bmd = dynamic_cast<FEBiphasicSolidDomain*>(&dom); FEBiphasicShellDomain* bsd = dynamic_cast<FEBiphasicShellDomain*>(&dom); FEMultiphasicSolidDomain* pmd = dynamic_cast<FEMultiphasicSolidDomain*>(&dom); FEMultiphasicShellDomain* psd = dynamic_cast<FEMultiphasicShellDomain*>(&dom); if (bmd || bsd || pmd || psd) { writeAverageElementValue<double>(dom, a, [](const FEMaterialPoint& mp) { const FEElasticMaterialPoint* et = (mp.ExtractData<FEElasticMaterialPoint>()); const FEBiphasicMaterialPoint* pt = (mp.ExtractData<FEBiphasicMaterialPoint>()); return (pt ? (1 - pt->m_phi0t/et->m_J) : 0.0); }); return true; } return false; } //----------------------------------------------------------------------------- bool FEPlotPerm::Save(FEDomain &dom, FEDataStream& a) { FEBiphasic* bp = dom.GetMaterial()->ExtractProperty<FEBiphasic>(); if (bp == 0) return false; writeAverageElementValue<mat3ds>(dom, a, [=](const FEMaterialPoint& mp) { return bp->Permeability(const_cast<FEMaterialPoint&>(mp)); }); return true; } //----------------------------------------------------------------------------- bool FEPlotFixedChargeDensity::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); FEElasticSolidDomain* ped = dynamic_cast<FEElasticSolidDomain*>(&dom); if (psm) { writeAverageElementValue<double>(dom, a, [=](const FEMaterialPoint& mp) { double cf = psm->GetFixedChargeDensity(mp); return cf; }); return true; } else if (ped) { for (int i=0; i<ped->Elements(); ++i) { FESolidElement& el = ped->Element(i); FEElasticMixture* pem = dynamic_cast<FEElasticMixture*> (dom.GetMaterial()); if (pem == nullptr) return false; // extract fixed-charge density double ew = 0; for (int j=0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); for (int k=0; k<pem->Materials(); ++k) { FEDonnanEquilibriumMaterialPoint* pd = pt.GetPointData(k)->ExtractData<FEDonnanEquilibriumMaterialPoint>(); if (pd) ew += pd->m_cF; } } ew /= el.GaussPoints(); a << ew; } return true; } return false; } //----------------------------------------------------------------------------- bool FEPlotReferentialFixedChargeDensity::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); FEElasticSolidDomain* ped = dynamic_cast<FEElasticSolidDomain*>(&dom); if (psm) { writeAverageElementValue<double>(dom, a, [=](const FEMaterialPoint& mp) { double cf = psm->GetReferentialFixedChargeDensity(mp); return cf; }); return true; } else if (ped) { for (int i=0; i<ped->Elements(); ++i) { FESolidElement& el = ped->Element(i); FEElasticMixture* pem = dynamic_cast<FEElasticMixture*> (dom.GetMaterial()); if (pem == nullptr) return false; // extract fixed-charge density double ew = 0; for (int j=0; j<el.GaussPoints(); ++j) { FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMixtureMaterialPoint& pt = *mp.ExtractData<FEElasticMixtureMaterialPoint>(); for (int k=0; k<pem->Materials(); ++k) { FEDonnanEquilibriumMaterialPoint* pd = pt.GetPointData(k)->ExtractData<FEDonnanEquilibriumMaterialPoint>(); if (pd) ew += pd->m_cFr; } } ew /= el.GaussPoints(); a << ew; } return true; } return false; } //----------------------------------------------------------------------------- bool FEPlotEffectiveFluidPressure::Save(FEDomain &dom, FEDataStream& a) { FEBiphasicDomain* pd = dynamic_cast<FEBiphasicDomain* >(&dom); FEBiphasicSoluteDomain* psd = dynamic_cast<FEBiphasicSoluteDomain*>(&dom); FETriphasicDomain* ptd = dynamic_cast<FETriphasicDomain* >(&dom); FEMultiphasicDomain* pmd = dynamic_cast<FEMultiphasicDomain* >(&dom); // special handling of mixed biphasic formulation if (pd) { // get the pressure dof index int dof_p = GetFEModel()->GetDOFIndex("p"); if (dof_p == -1) return false; DOFS& dofs = GetFEModel()->GetDOFS(); int varU = dofs.GetVariableIndex("displacement"); int varP = dofs.GetVariableIndex("fluid pressure"); int kd = dofs.GetVariableInterpolationOrder(varU); int kp = dofs.GetVariableInterpolationOrder(varP); if ((kd != 1) && (kp == 1)) { int N = dom.Nodes(); vector<double> p(N, 0.0); for (int i = 0; i < dom.Nodes(); ++i) { FENode& node = dom.Node(i); p[i] = node.get(dof_p); } FEEdgeList EL; if (EL.Create(&dom) == false) return false; for (int i = 0; i < EL.Edges(); ++i) { const FEEdgeList::EDGE& edge = EL.Edge(i); assert(edge.ntype == 3); p[edge.node[2]] = 0.5*(p[edge.node[0]] + p[edge.node[1]]); } a << p; return true; } } if (pd || psd || ptd || pmd) { // get the pressure dof index int dof_p = GetFEModel()->GetDOFIndex("p"); if (dof_p == -1) return false; // write the nodal values writeNodalValues<double>(dom, a, [=, &dom](int i) { FENode& node = dom.Node(i); return node.get(dof_p); }); return true; } return false; } //----------------------------------------------------------------------------- bool FEPlotEffectiveShellFluidPressure::Save(FEDomain &dom, FEDataStream& a) { FEBiphasicShellDomain* pbsd = dynamic_cast<FEBiphasicShellDomain*>(&dom); FEBiphasicSoluteShellDomain* pbssd = dynamic_cast<FEBiphasicSoluteShellDomain*>(&dom); FEMultiphasicShellDomain* pmpsd = dynamic_cast<FEMultiphasicShellDomain*>(&dom); if (pbsd || pbssd || pmpsd) { // get the pressure dof index int dof_q = GetFEModel()->GetDOFIndex("q"); assert(dof_q != -1); // write the nodal values writeNodalValues<double>(dom, a, [=, &dom](int i) { FENode& node = dom.Node(i); return node.get(dof_q); }); return true; } return false; } //================================================================================================= // FEPlotEffectiveSoluteConcentration //================================================================================================= FEPlotEffectiveSoluteConcentration::FEPlotEffectiveSoluteConcentration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_ARRAY, FMT_NODE) { DOFS& dofs = pfem->GetDOFS(); int nsol = dofs.GetVariableSize("concentration"); SetArraySize(nsol); // collect the names int ndata = pfem->GlobalDataItems(); vector<string> s; for (int i=0; i<ndata; ++i) { FESoluteData* ps = dynamic_cast<FESoluteData*>(pfem->GetGlobalData(i)); if (ps) { s.push_back(ps->GetName()); m_sol.push_back(ps->GetID()); } } assert(nsol == (int)s.size()); SetArrayNames(s); SetUnits(UNIT_CONCENTRATION); } //----------------------------------------------------------------------------- bool FEPlotEffectiveSoluteConcentration::Save(FEDomain &dom, FEDataStream& a) { // get the dof DOFS& dofs = GetFEModel()->GetDOFS(); int nsol = dofs.GetVariableSize("concentration"); if (nsol == -1) return false; // get the start index const int dof_C = GetFEModel()->GetDOFIndex("concentration", 0); FESoluteInterface* pm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if (pm == 0) return false; // figure out the local solute IDs. This depends on the material int nsols = (int)m_sol.size(); vector<int> lid(nsols, -1); int negs = 0; for (int i = 0; i<(int)m_sol.size(); ++i) { lid[i] = pm->FindLocalSoluteID(m_sol[i]); if (lid[i] < 0) negs++; } if (negs == nsol) return false; // save the concentrations int N = dom.Nodes(); for (int i = 0; i<N; ++i) { FENode& node = dom.Node(i); for (int j=0; j<nsol; ++j) { double c = (lid[j] >= 0 ? node.get(dof_C + j) : 0.0); a << c; } } return true; } //================================================================================================= //----------------------------------------------------------------------------- FEPlotEffectiveShellSoluteConcentration::FEPlotEffectiveShellSoluteConcentration(FEModel* pfem) : FEPlotDomainData(pfem, PLT_FLOAT, FMT_NODE) { m_nsol = 0; } //----------------------------------------------------------------------------- // Resolve solute by name bool FEPlotEffectiveShellSoluteConcentration::SetFilter(const char* sz) { m_nsol = GetSoluteID(*GetFEModel(), sz); return (m_nsol != -1); } //----------------------------------------------------------------------------- // Resolve solute by solute ID bool FEPlotEffectiveShellSoluteConcentration::SetFilter(int nsol) { m_nsol = GetSoluteID(*GetFEModel(), nsol); return (m_nsol != -1); } //----------------------------------------------------------------------------- bool FEPlotEffectiveShellSoluteConcentration::Save(FEDomain &dom, FEDataStream& a) { FESoluteInterface* pm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if (pm == 0) return false; // make sure we have a valid index int nsid = pm->FindLocalSoluteID(m_nsol); if (nsid == -1) return false; // get the dof const int dof_D = GetFEModel()->GetDOFIndex("shell concentration", nsid); if (dof_D == -1) return false; int N = dom.Nodes(); for (int i = 0; i<N; ++i) { FENode& node = dom.Node(i); a << node.get(dof_D); } return true; } //================================================================================================= bool FEPlotReceptorLigandConcentration::Save(FEDomain &dom, FEDataStream& a) { FEBiphasicSoluteSolidDomain* pbd = dynamic_cast<FEBiphasicSoluteSolidDomain*>(&dom); FEBiphasicSoluteShellDomain* psd = dynamic_cast<FEBiphasicSoluteShellDomain*>(&dom); if (pbd || psd) { writeAverageElementValue<double>(dom, a, [](const FEMaterialPoint& mp) { const FESolutesMaterialPoint* pt = (mp.ExtractData<FESolutesMaterialPoint>()); return (pt ? pt->m_sbmr[0] : 0.0); }); return true; } return false; } //================================================================================================= FEPlotSBMRefAppDensity::FEPlotSBMRefAppDensity(FEModel* pfem) : FEPlotDomainData(pfem, PLT_ARRAY, FMT_ITEM) { // count SBMs int sbms = 0; int ndata = pfem->GlobalDataItems(); vector<string> names; for (int i = 0; i<ndata; ++i) { FESBMData* sbm = dynamic_cast<FESBMData*>(pfem->GetGlobalData(i)); if (sbm) { names.push_back(sbm->GetName()); m_sbm.push_back(sbm->GetID()); sbms++; } } SetArraySize(sbms); SetArrayNames(names); SetUnits(UNIT_DENSITY); } //----------------------------------------------------------------------------- bool FEPlotSBMRefAppDensity::Save(FEDomain &dom, FEDataStream& a) { FEMultiphasic* pm = dynamic_cast<FEMultiphasic*> (dom.GetMaterial()); if (pm == 0) return false; // figure out the local SBM IDs. This depend on the material int nsbm = (int)m_sbm.size(); vector<int> lid(nsbm, -1); for (int i = 0; i<(int)m_sbm.size(); ++i) { lid[i] = GetLocalSBMID(pm, m_sbm[i]); } // figure out the sbm ID to export. This depends on the material type. // loop over all elements for (int i = 0; i<dom.Elements(); ++i) { FEElement& el = dom.ElementRef(i); for (int k=0; k<nsbm; ++k) { int nsid = lid[k]; if (nsid == -1) a << 0.f; else { // 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) ew += st->m_sbmr[nsid]; } ew /= el.GaussPoints(); a << ew; } } } return true; } //----------------------------------------------------------------------------- bool FEPlotEffectiveElasticity::Save(FEDomain &dom, FEDataStream& a) { FEBiphasic* pb = dynamic_cast<FEBiphasic *> (dom.GetMaterial()); FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (dom.GetMaterial()); FETriphasic* ptp = dynamic_cast<FETriphasic *> (dom.GetMaterial()); FEMultiphasic* pmp = dynamic_cast<FEMultiphasic *> (dom.GetMaterial()); if ((pb == 0) && (pbs == 0) && (ptp == 0) && (pmp == 0)) return false; for (int i=0; i<dom.Elements(); ++i) { FEElement& el = dom.ElementRef(i); int nint = el.GaussPoints(); double f = 1.0 / (double) nint; tens4ds s(0.0); for (int j=0; j<nint; ++j) { FEMaterialPoint& pt = *el.GetMaterialPoint(j); if (pb ) s += (pb->Tangent(pt)).supersymm(); else if (pbs) s += pbs->Tangent(pt); else if (ptp) s += ptp->Tangent(pt); else if (pmp) s += pmp->Tangent(pt); } s *= f; // store average elasticity a << s; } return true; } //----------------------------------------------------------------------------- bool FEPlotOsmoticCoefficient::Save(FEDomain &dom, FEDataStream& a) { if ((dom.Class() != FE_DOMAIN_SOLID) && (dom.Class() != FE_DOMAIN_SHELL)) return false; FESoluteInterface* pm = dynamic_cast<FESoluteInterface*>(dom.GetMaterial()); if (pm == nullptr) return false; FEOsmoticCoefficient* osm = pm->GetOsmoticCoefficient(); if (osm == nullptr) return false; writeAverageElementValue<double>(dom, a, [=](const FEMaterialPoint& mp) { double c = osm->OsmoticCoefficient(const_cast<FEMaterialPoint&>(mp)); return c; }); return true; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSoluteSolver.h
.h
2,776
83
/*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 "FEBiphasicSolver.h" #include <FECore/FEDofList.h> //----------------------------------------------------------------------------- // This class adds additional functionality to the FEBiphasicSolver to solve // solute problems. class FEBIOMIX_API FEBiphasicSoluteSolver : public FEBiphasicSolver { public: //! con/descructor FEBiphasicSoluteSolver(FEModel* pfem); virtual ~FEBiphasicSoluteSolver(){} //! 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; public: //! Calculates residual (overridden from FEBiphasicSolver) bool Residual(vector<double>& R) override; //! calculates the global stiffness matrix (overridden from FESolidSolver2) bool StiffnessMatrix() override; //! update kinematics void UpdateKinematics(vector<double>& ui) override; //! Update solute data void UpdateSolute(vector<double>& ui); protected: void GetConcentrationData(vector<double>& ci, vector<double>& ui, const int sol); public: // solute data vector< vector<double> > m_ci; //!< concentration increment vector vector< vector<double> > m_Ci; //!< Total concentration vector for iteration FEDofList m_dofC; //!< concentration dof FEDofList m_dofD; //!< shell concentration dof };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMembraneReaction.cpp
.cpp
13,297
348
/*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 "FEMembraneReaction.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(FEInternalReactantSpeciesRef, FEReactionSpeciesRef) ADD_PARAMETER(m_v, "vRi"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEInternalProductSpeciesRef, FEReactionSpeciesRef) ADD_PARAMETER(m_v, "vPi"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEExternalReactantSpeciesRef, FEReactionSpeciesRef) ADD_PARAMETER(m_v, "vRe"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEExternalProductSpeciesRef, FEReactionSpeciesRef) ADD_PARAMETER(m_v, "vPe"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEMembraneReaction, 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("Membrane reactants"); ADD_PROPERTY(m_vPtmp, "vP", FEProperty::Optional)->SetLongName("Membrane products"); ADD_PROPERTY(m_vRitmp, "vRi", FEProperty::Optional)->SetLongName("Inner membrane reactants"); ADD_PROPERTY(m_vPitmp, "vPi", FEProperty::Optional)->SetLongName("Inner membrane products");; ADD_PROPERTY(m_vRetmp, "vRe", FEProperty::Optional)->SetLongName("Outer membrane reactants"); ADD_PROPERTY(m_vPetmp, "vPe", FEProperty::Optional)->SetLongName("Outer membrane products"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMembraneReaction::FEMembraneReaction(FEModel* pfem) : FEReaction(pfem) { // additional initializations m_Vbar = 0.0; m_Vovr = false; m_nsol = -1; m_pFwd = m_pRev = 0; } //----------------------------------------------------------------------------- // Finds the solute id of a solute with given ID nsol. // This currently returns either nsol if a solute was found or -1 if not FESoluteData* FEMembraneReaction::GetSolute(int nsol) { FEModel& fem = *GetFEModel(); int N = fem.GlobalDataItems(); for (int i=0; i<N; ++i) { FESoluteData* psd = dynamic_cast<FESoluteData*>(fem.GetGlobalData(i)); if (psd) { if (psd->GetID()-1 == nsol) return psd; } } return nullptr; } //----------------------------------------------------------------------------- bool FEMembraneReaction::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; //************* reactants and products in multiphasic domain ************** // create the intmaps for (int i = 0; i < m_vRtmp.size(); ++i) { FEReactionSpeciesRef* pvr = m_vRtmp[i]; 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]; 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); } for (int i = 0; i < m_vRitmp.size(); ++i) { FEReactionSpeciesRef* pvr = m_vRitmp[i]; assert(pvr->IsSolute()); if (pvr->IsSolute()) SetStoichiometricCoefficient(m_solRi, pvr->m_speciesID - 1, pvr->m_v); } for (int i = 0; i < m_vPitmp.size(); ++i) { FEReactionSpeciesRef* pvp = m_vPitmp[i]; assert(pvp->IsSolute()); if (pvp->IsSolute()) SetStoichiometricCoefficient(m_solPi, pvp->m_speciesID - 1, pvp->m_v); } for (int i = 0; i < m_vRetmp.size(); ++i) { FEReactionSpeciesRef* pvr = m_vRetmp[i]; assert(pvr->IsSolute()); if (pvr->IsSolute()) SetStoichiometricCoefficient(m_solRe, pvr->m_speciesID - 1, pvr->m_v); } for (int i = 0; i < m_vPetmp.size(); ++i) { FEReactionSpeciesRef* pvp = m_vPetmp[i]; assert(pvp->IsSolute()); if (pvp->IsSolute()) SetStoichiometricCoefficient(m_solPe, pvp->m_speciesID - 1, pvp->m_v); } // initialize the reaction coefficients const int nsol = m_psm->Solutes(); const int nsbm = m_psm->SBMs(); const 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); // 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 (int 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 (int 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 (int itot = 0; itot<ntot; ++itot) { m_v[itot] = m_vP[itot] - m_vR[itot]; } //********* reactants and products on either side of membrane ********** // count total number of solutes in model DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_DDOFS = fedofs.GetVariableSize("shell concentration"); m_NSOL = MAX_DDOFS; m_z.assign(MAX_DDOFS, 0); // initialize the stoichiometric coefficients to zero m_vRi.assign(MAX_DDOFS, 0); m_vRe.assign(MAX_DDOFS, 0); m_vPi.assign(MAX_DDOFS, 0); m_vPe.assign(MAX_DDOFS, 0); m_vi.assign(MAX_DDOFS, 0); m_ve.assign(MAX_DDOFS, 0); // cycle through all the solutes in the mixture and determine // if they participate in this reaction for (int ISOL = 0; ISOL<MAX_DDOFS; ++ISOL) { it = m_solRi.find(ISOL); if (it != m_solRi.end()) m_vRi[ISOL] = it->second; it = m_solPi.find(ISOL); if (it != m_solPi.end()) m_vPi[ISOL] = it->second; it = m_solRe.find(ISOL); if (it != m_solRe.end()) m_vRe[ISOL] = it->second; it = m_solPe.find(ISOL); if (it != m_solPe.end()) m_vPe[ISOL] = it->second; } // evaluate the net stoichiometric coefficient for (int ISOL = 0; ISOL<MAX_DDOFS; ++ISOL) { m_vi[ISOL] = m_vPi[ISOL] - m_vRi[ISOL]; m_ve[ISOL] = m_vPe[ISOL] - m_vRe[ISOL]; FESoluteData* sd = GetSolute(ISOL); m_z[ISOL] = sd->m_z; } //************** continue with all reactants and products *************** // evaluate the weighted molar volume of reactants and products if (!m_Vovr) { m_Vbar = 0; for (int isol = 0; isol<nsol; ++isol) m_Vbar += m_v[isol] * m_psm->GetSolute(isol)->MolarMass() / m_psm->GetSolute(isol)->Density(); for (int isbm = 0; isbm<nsbm; ++isbm) m_Vbar += m_v[nsol + isbm] * m_psm->GetSBM(isbm)->MolarMass() / m_psm->GetSBM(isbm)->Density(); for (int ISOL = 0; ISOL<MAX_DDOFS; ++ISOL) { FESoluteData* sd = GetSolute(ISOL); m_Vbar += m_vi[ISOL] * sd->m_M / sd->m_rhoT; m_Vbar += m_ve[ISOL] * sd->m_M / sd->m_rhoT; } } // check that the reaction satisfies electroneutrality int znet = 0; for (int isol = 0; isol<nsol; ++isol) znet += m_v[isol] * m_psm->GetSolute(isol)->ChargeNumber(); for (int isbm = 0; isbm<nsbm; ++isbm) znet += m_v[nsol + isbm] * m_psm->GetSBM(isbm)->ChargeNumber(); for (int ISOL = 0; ISOL<MAX_DDOFS; ++ISOL) { znet += m_vi[ISOL] * m_z[ISOL]; znet += m_ve[ISOL] * m_z[ISOL]; } if (znet != 0) { feLogError("membrane reaction must satisfy electroneutrality"); return false; } return true; } //----------------------------------------------------------------------------- //! Data serialization void FEMembraneReaction::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 << m_NSOL; 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;} ar << (int) m_solRi.size(); for (p = m_solRi.begin(); p!=m_solRi.end(); ++p) {ar << p->first; ar << p->second;} ar << (int) m_solPi.size(); for (p = m_solPi.begin(); p!=m_solPi.end(); ++p) {ar << p->first; ar << p->second;} ar << (int) m_solRe.size(); for (p = m_solRe.begin(); p!=m_solRe.end(); ++p) {ar << p->first; ar << p->second;} ar << (int) m_solPe.size(); for (p = m_solPe.begin(); p!=m_solPe.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 >> m_NSOL; 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); } ar >> size; for (int i=0; i<size; ++i) { ar >> id; ar >> vR; SetStoichiometricCoefficient(m_solRi, id, vR); } ar >> size; for (int i=0; i<size; ++i) { ar >> id; ar >> vR; SetStoichiometricCoefficient(m_solPi, id, vR); } ar >> size; for (int i=0; i<size; ++i) { ar >> id; ar >> vR; SetStoichiometricCoefficient(m_solRe, id, vR); } ar >> size; for (int i=0; i<size; ++i) { ar >> id; ar >> vR; SetStoichiometricCoefficient(m_solPe, id, vR); } } } }
C++
3D
febiosoftware/FEBio
FEBioMix/febiomix_api.h
.h
1,531
44
/*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 #ifdef WIN32 #ifdef FECORE_DLL #ifdef febiomix_EXPORTS #define FEBIOMIX_API __declspec(dllexport) #else #define FEBIOMIX_API __declspec(dllimport) #endif #else #define FEBIOMIX_API #endif #else #define FEBIOMIX_API #endif
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPermHolmesMow.h
.h
2,113
59
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEBiphasic.h" //----------------------------------------------------------------------------- // This class implements a poroelastic material that has a strain-dependent // permeability according to the constitutive relation of Holmes & Mow (JB 1990) class FEBIOMIX_API FEPermHolmesMow : public FEHydraulicPermeability { public: //! constructor FEPermHolmesMow(FEModel* pfem); //! initialization bool Init() override; //! permeability mat3ds Permeability(FEMaterialPoint& pt) override; //! Tangent of permeability tens4dmm Tangent_Permeability_Strain(FEMaterialPoint& mp) override; public: FEParamDouble m_perm; //!< permeability double m_M; //!< nonlinear exponential coefficient double m_alpha; //!< nonlinear power exponent // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEFixedConcentration.cpp
.cpp
1,727
45
/*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 "FEFixedConcentration.h" #include <FECore/FEModel.h> BEGIN_FECORE_CLASS(FEFixedConcentration, FEFixedBC) ADD_PARAMETER(m_dof, "c_dof", 0, "$(dof_list:concentration)")->setLongName("species"); END_FECORE_CLASS(); FEFixedConcentration::FEFixedConcentration(FEModel* fem) : FEFixedBC(fem) { m_dof = -1; } bool FEFixedConcentration::Init() { if (m_dof == -1) return false; SetDOFList(m_dof); return FEFixedBC::Init(); }
C++
3D
febiosoftware/FEBio
FEBioMix/FEPermRefOrtho.cpp
.cpp
6,785
201
/*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 "FEPermRefOrtho.h" #include <FECore/log.h> // define the material parameters BEGIN_FECORE_CLASS(FEPermRefOrtho, FEHydraulicPermeability) ADD_PARAMETER(m_perm0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "perm0")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_M0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "M0"); ADD_PARAMETER(m_alpha0, FE_RANGE_GREATER_OR_EQUAL(0.0), "alpha0"); ADD_PARAMETER(m_perm1, 3, "perm1")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_perm2, 3, "perm2")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_M , 3, "M"); ADD_PARAMETER(m_alpha, 3, "alpha"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEPermRefOrtho::FEPermRefOrtho(FEModel* pfem) : FEHydraulicPermeability(pfem) { m_perm0 = 1; m_perm1[0] = 0.0; m_perm1[1] = 0.0; m_perm1[2] = 0.0; m_perm2[0] = 0.0; m_perm2[1] = 0.0; m_perm2[2] = 0.0; m_M0 = 0; m_alpha0 = 0; m_M[0] = 0.0; m_M[1] = 0.0; m_M[2] = 0.0; m_alpha[0] = 0.0; m_alpha[1] = 0.0; m_alpha[2] = 0.0; } void FEPermRefOrtho::reportError(double J, double phisr) { const int MAX_ERRORS = 1; static int n = 0; double t = CurrentTime(); static double t_last = 0; if (t != t_last) { t = t_last; n = 0; } if (n < MAX_ERRORS) { feLogError("The perm-ref-ortho permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g.", J, phisr); n++; } } //----------------------------------------------------------------------------- //! Permeability tensor. mat3ds FEPermRefOrtho::Permeability(FEMaterialPoint& mp) { int a; vec3d V; // orthonormal material directions in reference configuration mat3ds m[3]; // texture tensor in current configuration FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // Identity mat3dd I(1); // deformation gradient mat3d &F = et.m_F; // left cauchy-green matrix mat3ds b = et.LeftCauchyGreen(); // relative volume double J = et.m_J; // referential solid volume fraction double phi0 = pt.m_phi0; double phisr = pt.m_phi0t; // check for potential error if (J <= phisr) reportError(J, phisr); // get the local coordinate systems mat3d Q = GetLocalCS(mp); for (a=0; a<3; a++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to V V.x = Q[0][a]; V.y = Q[1][a]; V.z = Q[2][a]; m[a] = dyad(F*V); // Evaluate texture tensor in the current configuration } // --- strain-dependent permeability --- double f; double M0 = m_M0(mp); double alpha0 = m_alpha0(mp); double k0 = m_perm0(mp)*pow((J-phisr)/(1-phi0),alpha0)*exp(M0*(J*J-1.0)/2.0); double k1[3] = { m_perm1[0](mp), m_perm1[1](mp), m_perm1[2](mp) }; double k2[3] = { m_perm2[0](mp), m_perm2[1](mp), m_perm2[2](mp) }; double alpha[3] = { m_alpha[0](mp), m_alpha[1](mp), m_alpha[2](mp) }; double M[3] = { m_M[0](mp), m_M[1](mp), m_M[2](mp) }; for (a=0; a<3; a++) { f = pow((J-phisr)/(1-phi0),alpha[a])*exp(M[a]*(J*J-1.0)/2.0); k1[a] *= f/(J*J); k2[a] *= 0.5*f/pow(J,4); } mat3ds kt = k0*I +k1[0]*m[0]+k1[1]*m[1]+k1[2]*m[2] +(2.0*k2[0])*(m[0]*b).sym()+(2.0*k2[1])*(m[1]*b).sym()+(2.0*k2[2])*(m[2]*b).sym(); return kt; } //----------------------------------------------------------------------------- //! Tangent of permeability tens4dmm FEPermRefOrtho::Tangent_Permeability_Strain(FEMaterialPoint &mp) { int a; vec3d V; // orthonormal material directions in reference configuration mat3ds m[3]; // texture tensor in current configuration FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // Identity mat3dd I(1); // deformation gradient mat3d &F = et.m_F; // left cauchy-green matrix mat3ds b = et.LeftCauchyGreen(); // relative volume double J = et.m_J; // referential solid volume fraction double phi0 = pt.m_phi0; double phisr = pt.m_phi0t; // check for potential error if (J <= phisr) reportError(J, phisr); // get local coordinates mat3d Q = GetLocalCS(mp); for (a=0; a<3; a++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to V V.x = Q[0][a]; V.y = Q[1][a]; V.z = Q[2][a]; m[a] = dyad(F*V); // Evaluate texture tensor in the current configuration } double f, k0, K0prime, K1prime, K2prime; mat3ds k0hat, k1hat, k2hat; double M0 = m_M0(mp); double alpha0 = m_alpha0(mp); k0 = m_perm0(mp)*pow((J-phisr)/(1-phi0),alpha0)*exp(M0*(J*J-1.0)/2.0); K0prime = (1+J*(alpha0/(J-phisr)+M0*J))*k0; k0hat = mat3dd(K0prime); tens4dmm K4 = dyad1mm(I,k0hat)-dyad4s(I)*(2*k0); double k1[3] = { m_perm1[0](mp), m_perm1[1](mp), m_perm1[2](mp) }; double k2[3] = { m_perm2[0](mp), m_perm2[1](mp), m_perm2[2](mp) }; double alpha[3] = { m_alpha[0](mp), m_alpha[1](mp), m_alpha[2](mp) }; double M[3] = { m_M[0](mp), m_M[1](mp), m_M[2](mp) }; for (a=0; a<3; a++) { f = pow((J-phisr)/(1-phi0),alpha[a])*exp(M[a]*(J*J-1.0)/2.0); k1[a] *= f/(J*J); k2[a] *= 0.5*f/pow(J,4); K1prime = (J*J*M[a]+(J*(alpha[a]-1)+phi0)/(J-phisr))*k1[a]; K2prime = (J*J*M[a]+(J*(alpha[a]-3)+3*phi0)/(J-phisr))*k2[a]; k1hat = mat3dd(K1prime); k2hat = mat3dd(K2prime); K4 += dyad1mm(m[a],k1hat) + dyad1mm((m[a]*b).sym()*2.0,k2hat) +dyad4s(m[a],b)*(2.0*k2[a]); } return K4; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEPermExpIso.cpp
.cpp
3,595
95
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEPermExpIso.h" #include "FEBiphasic.h" #include <FECore/log.h> // define the material parameters BEGIN_FECORE_CLASS(FEPermExpIso, FEHydraulicPermeability) ADD_PARAMETER(m_perm , FE_RANGE_GREATER_OR_EQUAL(0.0), "perm" )->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_M , FE_RANGE_GREATER_OR_EQUAL(0.0), "M" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEPermExpIso::FEPermExpIso(FEModel* pfem) : FEHydraulicPermeability(pfem) { m_perm = 1; m_M = 0; } //----------------------------------------------------------------------------- //! Permeability tensor. mat3ds FEPermExpIso::Permeability(FEMaterialPoint& mp) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); // relative volume double J = et.m_J; // referential solid volume fraction double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); // check for potential error if (J <= phi0) feLogError("The perm-exp-iso permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g.",J,phi0); // --- strain-dependent isotropic permeability --- double k0 = m_perm*exp(m_M*(J-1)/(J-phi0)); return mat3dd(k0); } //----------------------------------------------------------------------------- //! Tangent of permeability tens4dmm FEPermExpIso::Tangent_Permeability_Strain(FEMaterialPoint &mp) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); // relative volume double J = et.m_J; // referential solid volume fraction double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); // check for potential error if (J <= phi0) feLogError("The perm-exp-iso permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g.",J,phi0); mat3dd I(1); // Identity double k0 = m_perm*exp(m_M*(J-1)/(J-phi0)); double k0prime = m_M*(1-phi0)/pow(J-phi0,2)*k0; mat3ds k0hat = I*(k0 + J*k0prime); return dyad1mm(I,k0hat)-dyad4s(I)*(2*k0); }
C++
3D
febiosoftware/FEBio
FEBioMix/FESolutesMaterialPoint.cpp
.cpp
3,982
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) 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 "FESolutesMaterialPoint.h" #include "FECore/DumpStream.h" using namespace std; //============================================================================= // FESolutesMaterialPoint //============================================================================= //----------------------------------------------------------------------------- FESolutesMaterialPoint::FESolutesMaterialPoint(FEMaterialPointData* ppt) : FEMaterialPointData(ppt) { m_nsol = 0; m_psi = 0; m_cF = 0; m_nsbm = 0; m_rhor = 0; m_strain = 0; m_pe = m_pi = 0; } //----------------------------------------------------------------------------- //! Create a shallow copy of the material point data FEMaterialPointData* FESolutesMaterialPoint::Copy() { FESolutesMaterialPoint* pt = new FESolutesMaterialPoint(*this); if (m_pNext) pt->m_pNext = m_pNext->Copy(); return pt; } //----------------------------------------------------------------------------- //! Initialize material point data void FESolutesMaterialPoint::Init() { m_nsol = m_nsbm = 0; m_psi = m_cF = 0; m_Ie = vec3d(0,0,0); m_rhor = 0; m_c.clear(); m_gradc.clear(); m_j.clear(); m_ca.clear(); m_crp.clear(); m_sbmr.clear(); m_sbmrp.clear(); m_sbmrhat.clear(); m_sbmrhatp.clear(); m_sbmrmin.clear(); m_sbmrmax.clear(); m_k.clear(); m_dkdJ.clear(); m_dkdJJ.clear(); m_dkdc.clear(); m_dkdJc.clear(); m_dkdcc.clear(); m_dkdr.clear(); m_dkdJr.clear(); m_dkdrc.clear(); m_cri.clear(); m_crd.clear(); m_strain = 0; m_pe = m_pi = 0; m_ce.clear(); m_ci.clear(); m_ide.clear(); m_idi.clear(); m_bsb.clear(); // don't forget to initialize the base class FEMaterialPointData::Init(); } //----------------------------------------------------------------------------- //! Serialize material point data to the archive void FESolutesMaterialPoint::Serialize(DumpStream& ar) { FEMaterialPointData::Serialize(ar); ar & m_nsol & m_psi & m_cF & m_Ie & m_nsbm & m_rhor; ar & m_c & m_gradc & m_j & m_ca & m_crp & m_k & m_dkdJ & m_dkdJJ; ar & m_dkdc & m_dkdJc & m_dkdcc; ar & m_dkdr & m_dkdJr & m_dkdrc; ar & m_sbmr & m_sbmrp & m_sbmrhat & m_sbmrhatp & m_sbmrmin& m_sbmrmax; ar & m_cri; ar & m_crd; ar & m_strain & m_pe & m_pi; ar & m_ce & m_ide; ar & m_ci & m_idi; ar & m_bsb; } //----------------------------------------------------------------------------- double FESolutesMaterialPoint::Osmolarity() const { double ew = 0.0; for (int isol = 0; isol < (int)m_ca.size(); ++isol) { // exclude solid-bound 'solutes' if (!m_bsb[isol]) ew += m_ca[isol]; } return ew; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMixtureNormalTraction.cpp
.cpp
6,060
212
/*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 "FEMixtureNormalTraction.h" #include "FECore/FEModel.h" #include <FECore/FELinearSystem.h> //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEMixtureNormalTraction, FESurfaceLoad) ADD_PARAMETER(m_traction , "traction" )->setLongName("mixture normal traction")->setUnits(UNIT_PRESSURE); ADD_PARAMETER(m_blinear , "linear" ); ADD_PARAMETER(m_bshellb , "shell_bottom")->setLongName("apply on shell bottom"); ADD_PARAMETER(m_beffective, "effective"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FEMixtureNormalTraction::FEMixtureNormalTraction(FEModel* pfem) : FESurfaceLoad(pfem) { m_traction = 1.0; m_blinear = false; m_bshellb = false; m_beffective = false; } //----------------------------------------------------------------------------- //! allocate storage void FEMixtureNormalTraction::SetSurface(FESurface* ps) { FESurfaceLoad::SetSurface(ps); m_traction.SetItemList(ps->GetFacetSet()); } //----------------------------------------------------------------------------- bool FEMixtureNormalTraction::Init() { if (m_psurf == nullptr) return false; m_psurf->SetShellBottom(m_bshellb); FEModel* fem = GetFEModel(); m_dof.Clear(); if (m_bshellb == false) { m_dof.AddDof("x"); m_dof.AddDof("y"); m_dof.AddDof("z"); if (m_dof.AddDof("p") == false) m_dof.AddDof(-1); } else { m_dof.AddDof(fem->GetDOFIndex("sx")); m_dof.AddDof(fem->GetDOFIndex("sy")); m_dof.AddDof(fem->GetDOFIndex("sz")); if (m_dof.AddDof("q") == false) m_dof.AddDof(-1); } return FESurfaceLoad::Init(); } //----------------------------------------------------------------------------- void FEMixtureNormalTraction::StiffnessMatrix(FELinearSystem& LS) { if (m_blinear) return; m_psurf->SetShellBottom(m_bshellb); bool bsymm = LS.IsSymmetric(); FEMixtureNormalTraction* traction = this; m_psurf->LoadStiffness(LS, m_dof, m_dof, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) { double H_i = dof_a.shape; double Gr_i = dof_a.shape_deriv_r; double Gs_i = dof_a.shape_deriv_s; double H_j = dof_b.shape; double Gr_j = dof_b.shape_deriv_r; double Gs_j = dof_b.shape_deriv_s; // traction at integration point double tr = traction->Traction(mp); if (traction->m_bshellb) tr = -tr; // calculate stiffness component Kab.zero(); if (!bsymm) { // non-symmetric vec3d kab = (mp.dxs*Gr_j - mp.dxr*Gs_j)*H_i * tr; Kab[0][0] = 0; Kab[0][1] = -kab.z; Kab[0][2] = kab.y; Kab[1][0] = kab.z; Kab[1][1] = 0; Kab[1][2] = -kab.x; Kab[2][0] = -kab.y; Kab[2][1] = kab.x; Kab[2][2] = 0; // if prescribed traction is effective, add stiffness component if (traction->m_beffective) { vec3d kab = (mp.dxr ^ mp.dxs)* H_i * H_j; Kab[0][3] = kab.x; Kab[1][3] = kab.y; Kab[2][3] = kab.z; } } else { // symmetric vec3d kab = ((mp.dxs*Gr_j - mp.dxr*Gs_j)*H_i - (mp.dxs*Gr_i - mp.dxr*Gs_i)*H_j)*0.5 * tr; Kab[0][0] = 0; Kab[0][1] = -kab.z; Kab[0][2] = kab.y; Kab[1][0] = kab.z; Kab[1][1] = 0; Kab[1][2] = -kab.x; Kab[2][0] = -kab.y; Kab[2][1] = kab.x; Kab[2][2] = 0; // if prescribed traction is effective, add stiffness component if (traction->m_beffective) { vec3d kab = (mp.dxr ^ mp.dxs) * 0.5*H_i * H_j; Kab[0][3] = kab.x; Kab[1][3] = kab.y; Kab[2][3] = kab.z; // TODO: This is not symmetric! Kab[0][3] = kab.x; Kab[1][3] = kab.y; Kab[2][3] = kab.z; } } }); } //----------------------------------------------------------------------------- double FEMixtureNormalTraction::Traction(FESurfaceMaterialPoint& mp) { FESurfaceElement& el = *mp.SurfaceElement(); // calculate nodal normal tractions double tr = m_traction(mp); // if the prescribed traction is effective, evaluate the total traction if (m_beffective) { // fluid pressure tr -= m_psurf->Evaluate(mp, m_dof[3]); } return tr; } //----------------------------------------------------------------------------- void FEMixtureNormalTraction::LoadVector(FEGlobalVector& R) { m_psurf->SetShellBottom(m_bshellb); FEMixtureNormalTraction* traction = this; m_psurf->LoadVector(R, m_dof, m_blinear, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, vector<double>& fa) { // traction at integration points double tr = traction->Traction(mp); if (traction->m_bshellb) tr = -tr; // force vector vec3d f = (mp.dxr ^ mp.dxs)*tr; double H = dof_a.shape; fa[0] = H * f.x; fa[1] = H * f.y; fa[2] = H * f.z; fa[3] = 0.0; }); }
C++
3D
febiosoftware/FEBio
FEBioMix/FESlidingInterfaceBiphasicMixed.h
.h
7,875
211
/*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 FESlidingSurfaceBiphasicMixed : public FEBiphasicContactSurface { public: //! constructor FESlidingSurfaceBiphasicMixed(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; //! unpack dofs void UnpackLM(FEElement& el, vector<int>& lm) 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 int m_varU, m_varP; 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 FESlidingInterfaceBiphasicMixed : public FEContactInterface { public: //! constructor FESlidingInterfaceBiphasicMixed(FEModel* pfem); //! destructor ~FESlidingInterfaceBiphasicMixed(); //! initialization bool Init() override; //! interface activation void Activate() override; //! calculate the slip direction on the primary surface vec3d SlipTangent(FESlidingSurfaceBiphasicMixed& ss, const int nel, const int nint, FESlidingSurfaceBiphasicMixed& ms, double& dh, vec3d& r); //! calculate contact traction vec3d ContactTraction(FESlidingSurfaceBiphasicMixed& ss, const int nel, const int n, FESlidingSurfaceBiphasicMixed& 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(FESlidingSurfaceBiphasicMixed& ss, FESlidingSurfaceBiphasicMixed& ms, bool bupseg, bool bmove = false); //! calculate penalty factor void UpdateAutoPenalty(); void CalcAutoPenalty(FESlidingSurfaceBiphasicMixed& s); void CalcAutoPressurePenalty(FESlidingSurfaceBiphasicMixed& s); double AutoPressurePenalty(FESurfaceElement& el, FESlidingSurfaceBiphasicMixed& s); //! calculate contact forces void LoadVector(FESlidingSurfaceBiphasicMixed& ss, FESlidingSurfaceBiphasicMixed& ms, FEGlobalVector& R, const FETimeInfo& tp); //! calculate contact stiffness void StiffnessMatrix(FESlidingSurfaceBiphasicMixed& ss, FESlidingSurfaceBiphasicMixed& ms, FELinearSystem& LS, const FETimeInfo& tp); public: FESlidingSurfaceBiphasicMixed m_ss; //!< primary surface FESlidingSurfaceBiphasicMixed 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/FEBioMixData.h
.h
11,659
366
/*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/NodeDataRecord.h" #include "FECore/ElementDataRecord.h" #include <FECore/DomainDataRecord.h> //============================================================================= // N O D E D A T A //============================================================================= //----------------------------------------------------------------------------- // This class uses the deprecated "c" variable to denote concentrations. class FENodeConcentration : public FELogNodeData { public: FENodeConcentration(FEModel* pfem) : FELogNodeData(pfem){} double value(const FENode& node); }; //----------------------------------------------------------------------------- // return the (nodal) effective fluid pressure class FENodeFluidPressure : public FELogNodeData { public: FENodeFluidPressure(FEModel* pfem) : FELogNodeData(pfem) {} double value(const FENode& node); }; //----------------------------------------------------------------------------- class FENodeSoluteConcentration_ : public FELogNodeData { protected: FENodeSoluteConcentration_(FEModel* pfem, int nsol) : FELogNodeData(pfem), m_nsol(nsol) {} double value(const FENode& node); private: int m_nsol; }; template <int N> class FENodeSoluteConcentration_T : public FENodeSoluteConcentration_ { public: FENodeSoluteConcentration_T(FEModel* pfem) : FENodeSoluteConcentration_(pfem, N) {} double value(const FENode& node) { return FENodeSoluteConcentration_::value(node); } }; //============================================================================= // E L E M E N T D A T A //============================================================================= //----------------------------------------------------------------------------- class FELogElemFluidPressure : public FELogElemData { public: FELogElemFluidPressure(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemFluidFluxX : public FELogElemData { public: FELogElemFluidFluxX(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemFluidFluxY : public FELogElemData { public: FELogElemFluidFluxY(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemFluidFluxZ : public FELogElemData { public: FELogElemFluidFluxZ(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemSoluteConcentration : public FELogElemData { public: FELogElemSoluteConcentration(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemSoluteFluxX : public FELogElemData { public: FELogElemSoluteFluxX(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemSoluteFluxY : public FELogElemData { public: FELogElemSoluteFluxY(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemSoluteFluxZ : public FELogElemData { public: FELogElemSoluteFluxZ(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemSoluteRefConcentration : public FELogElemData { public: FELogElemSoluteRefConcentration(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogFixedChargeDensity : public FELogElemData { public: FELogFixedChargeDensity(FEModel* pfem) : FELogElemData(pfem) {} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemSoluteConcentration_ : public FELogElemData { protected: FELogElemSoluteConcentration_(FEModel* pfem, int nsol) : FELogElemData(pfem), m_nsol(nsol) {} double value(FEElement& el); private: int m_nsol; }; template <int N> class FELogElemSoluteConcentration_T : public FELogElemSoluteConcentration_ { public: FELogElemSoluteConcentration_T(FEModel* pfem) : FELogElemSoluteConcentration_(pfem, N) {} double value(FEElement& el) { return FELogElemSoluteConcentration_::value(el); } }; //----------------------------------------------------------------------------- class FELogElemSoluteFluxX_ : public FELogElemData { protected: FELogElemSoluteFluxX_(FEModel* pfem, int nsol) : FELogElemData(pfem), m_nsol(nsol) {} double value(FEElement& el); private: int m_nsol; }; template <int N> class FELogElemSoluteFluxX_T : public FELogElemSoluteFluxX_ { public: FELogElemSoluteFluxX_T(FEModel* pfem) : FELogElemSoluteFluxX_(pfem, N) {} double value(FEElement& el) { return FELogElemSoluteFluxX_::value(el); } }; //----------------------------------------------------------------------------- class FELogElemSoluteFluxY_ : public FELogElemData { protected: FELogElemSoluteFluxY_(FEModel* pfem, int nsol) : FELogElemData(pfem), m_nsol(nsol) {} double value(FEElement& el); private: int m_nsol; }; template <int N> class FELogElemSoluteFluxY_T : public FELogElemSoluteFluxY_ { public: FELogElemSoluteFluxY_T(FEModel* pfem) : FELogElemSoluteFluxY_(pfem, N) {} double value(FEElement& el) { return FELogElemSoluteFluxY_::value(el); } }; //----------------------------------------------------------------------------- class FELogElemSoluteFluxZ_ : public FELogElemData { protected: FELogElemSoluteFluxZ_(FEModel* pfem, int nsol) : FELogElemData(pfem), m_nsol(nsol) {} double value(FEElement& el); private: int m_nsol; }; template <int N> class FELogElemSoluteFluxZ_T : public FELogElemSoluteFluxZ_ { public: FELogElemSoluteFluxZ_T(FEModel* pfem) : FELogElemSoluteFluxZ_(pfem, N) {} double value(FEElement& el) { return FELogElemSoluteFluxZ_::value(el); } }; //----------------------------------------------------------------------------- class FELogElemElectricPotential : public FELogElemData { public: FELogElemElectricPotential(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemCurrentDensityX : public FELogElemData { public: FELogElemCurrentDensityX(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemCurrentDensityY : public FELogElemData { public: FELogElemCurrentDensityY(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemCurrentDensityZ : public FELogElemData { public: FELogElemCurrentDensityZ(FEModel* pfem) : FELogElemData(pfem){} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemSBMConcentration_: public FELogElemData { protected: FELogElemSBMConcentration_(FEModel* pfem, int nsol) : FELogElemData(pfem), m_nsol(nsol) {} double value(FEElement& el); private: int m_nsol; }; template <int N> class FELogElemSBMConcentration_T: public FELogElemSBMConcentration_ { public: FELogElemSBMConcentration_T(FEModel* pfem) : FELogElemSBMConcentration_(pfem, N) {} double value(FEElement& el) { return FELogElemSBMConcentration_::value(el); } }; //----------------------------------------------------------------------------- class FELogElemPorosity : public FELogElemData { public: FELogElemPorosity(FEModel* fem) : FELogElemData(fem) {} double value(FEElement& el); }; //----------------------------------------------------------------------------- class FELogElemPermeability : public FELogElemData { public: FELogElemPermeability(FEModel* fem, int n) : FELogElemData(fem) { m_comp = n; } double value(FEElement& el); protected: int m_comp; }; template <int n> class FELogElemPermeability_T : public FELogElemPermeability { public: FELogElemPermeability_T(FEModel* fem) : FELogElemPermeability(fem, n) {} }; //----------------------------------------------------------------------------- class FELogElemSolidStress : public FELogElemData { public: FELogElemSolidStress(FEModel* fem, int n) : FELogElemData(fem) { m_comp = n; } double value(FEElement& el); protected: int m_comp; }; template <int n> class FELogElemSolidStress_T : public FELogElemSolidStress { public: FELogElemSolidStress_T(FEModel* fem) : FELogElemSolidStress(fem, n) {} }; class FELogSBMRefAppDensity : public FELogElemData { public: FELogSBMRefAppDensity(FEModel* fem, int n); double value(FEElement& el); private: int sbmid = -1; }; template <int n> class FELogSBMRefAppDensity_T : public FELogSBMRefAppDensity { public: FELogSBMRefAppDensity_T(FEModel* fem) : FELogSBMRefAppDensity(fem, n) {} }; //============================================================================= // D O M A I N D A T A //============================================================================= class FELogDomainIntegralSBMConcentration : public FELogDomainData { public: FELogDomainIntegralSBMConcentration(FEModel* fem, int sbm); double value(FEDomain& dom) override; protected: int m_sbm; }; template <int N> class FELogDomainIntegralSBMConcentration_T : public FELogDomainIntegralSBMConcentration { public: FELogDomainIntegralSBMConcentration_T(FEModel* pfem) : FELogDomainIntegralSBMConcentration(pfem, N) {} }; //------------------------------------------------------------------------------------------- class FELogDomainIntegralSoluteConcentration : public FELogDomainData { public: FELogDomainIntegralSoluteConcentration(FEModel* fem, int sol); double value(FEDomain& dom) override; protected: int m_nsol; }; template <int N> class FELogDomainIntegralSoluteConcentration_T : public FELogDomainIntegralSoluteConcentration { public: FELogDomainIntegralSoluteConcentration_T(FEModel* pfem) : FELogDomainIntegralSoluteConcentration(pfem, N) {} };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEDiffAlbroIso.h
.h
2,768
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 "FEBiphasicSolute.h" //----------------------------------------------------------------------------- // This class implements a material that has a porosity and concentration // dependent diffusivity which is isotropic, according to the constitutive relation // of Albro et al (CMBE 2009) class FEBIOMIX_API FEDiffAlbroIso : public FESoluteDiffusivity { public: //! constructor FEDiffAlbroIso(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; //! data initialization and checking bool Init() override; public: FEParamDouble m_diff0; //!< free diffusivity FEParamDouble m_cdinv; //!< inverse of characteristic concentration c_D FEParamDouble m_alphad; //!< non-dimensional coefficient for porosity term int m_lsol; //!< local ID of solute // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESlidingInterface3.cpp
.cpp
69,459
2,304
/*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 "FESlidingInterface3.h" #include "FESlidingInterfaceMP.h" #include "FEBiphasic.h" #include "FEBiphasicSolute.h" #include "FECore/FEModel.h" #include "FECore/log.h" #include "FECore/DOFS.h" #include "FECore/FENormalProjection.h" #include <FECore/FELinearSystem.h> #include <FECore/FEAnalysis.h> //----------------------------------------------------------------------------- // Define sliding interface parameters BEGIN_FECORE_CLASS(FESlidingInterface3, 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_naugmin , "minaug" ); ADD_PARAMETER(m_naugmax , "maxaug" ); ADD_PARAMETER(m_breloc , "node_reloc" ); ADD_PARAMETER(m_bsmaug , "smooth_aug" ); ADD_PARAMETER(m_ambp , "ambient_pressure" ); ADD_PARAMETER(m_ambc , "ambient_concentration"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- // FESlidingSurface3 //----------------------------------------------------------------------------- FESlidingSurface3::FESlidingSurface3(FEModel* pfem) : FEBiphasicContactSurface(pfem) { m_bporo = m_bsolu = false; m_dofC = -1; } //----------------------------------------------------------------------------- FESlidingSurface3::~FESlidingSurface3() { } //----------------------------------------------------------------------------- //! create material point data FEMaterialPoint* FESlidingSurface3::CreateMaterialPoint() { return new FEMultiphasicContactPoint; } //----------------------------------------------------------------------------- void FESlidingSurface3::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 FESlidingSurface3::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 data structures m_nn.assign(Nodes(), vec3d(0,0,0)); m_pn.assign(Nodes(), 0); // determine biphasic and biphasic-solute status m_poro.resize(Elements(),false); m_solu.resize(Elements(),-1); for (int i=0; i<Elements(); ++i) { // get the surface element FESurfaceElement& se = Element(i); // 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()); // see if this is a poro-elastic element FEBiphasic* pb = dynamic_cast<FEBiphasic*> (pm); FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (pm); if (pb || pbs) { m_poro[i] = true; m_bporo = true; } if (pbs) { m_solu[i] = pbs->GetSolute()->GetSoluteID() - 1; m_bsolu = true; } } } // allocate data structures int NE = Elements(); for (int i=0; i<NE; ++i) { FESurfaceElement& el = Element(i); int nint = el.GaussPoints(); int nsol = m_solu.size(); 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; } //----------------------------------------------------------------------------- //! 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 FESlidingSurface3::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]; } //----------------------------------------------------------------------------- //! 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 FESlidingSurface3::UpdateNodeNormals() { vec3d y[FEElement::MAX_NODES]; // zero nodal normals zero(m_nn); // loop over all elements for (int i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); int ne = el.Nodes(); // get the nodal coordinates for (int j=0; j<ne; ++j) y[j] = Node(el.m_lnode[j]).m_rt; // calculate the normals for (int j=0; j<ne; ++j) { int jp1 = (j+1)%ne; int jm1 = (j+ne-1)%ne; vec3d n = (y[jp1] - y[j]) ^ (y[jm1] - y[j]); m_nn[el.m_lnode[j]] += n; } } // normalize all vectors int N = Nodes(); for (int i=0; i<N; ++i) m_nn[i].unit(); } //----------------------------------------------------------------------------- vec3d FESlidingSurface3::GetContactForce() { return m_Ft; } //----------------------------------------------------------------------------- double FESlidingSurface3::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 FESlidingSurface3::GetFluidForce() { int n, i; const int MN = FEElement::MAX_NODES; double pn[MN]; // get parent contact interface to extract ambient fluid pressure FESlidingInterface3* si3 = dynamic_cast<FESlidingInterface3*>(GetContactInterface()); double ambp = si3->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 FESlidingSurface3::Serialize(DumpStream& ar) { FEBiphasicContactSurface::Serialize(ar); ar & m_dofC; ar & m_dofP; ar & m_bporo; ar & m_bsolu; ar & m_nn; ar & m_poro; ar & m_solu; ar & m_pn; ar & m_Ft; } //----------------------------------------------------------------------------- void FESlidingSurface3::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 FESlidingSurface3::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_nu*data.m_Ln; } pt /= ni; } //----------------------------------------------------------------------------- void FESlidingSurface3::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 FESlidingSurface3::GetNodalContactTraction(int nface, vec3d* tn) { FESurfaceElement& el = Element(nface); for (int k=0; k<el.Nodes(); ++k) tn[k] = m_nn[el.m_lnode[k]]*(-m_pn[el.m_lnode[k]]); } //----------------------------------------------------------------------------- // FESlidingInterface3 //----------------------------------------------------------------------------- FESlidingInterface3::FESlidingInterface3(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_ambc = 0; m_nsegup = 0; m_bautopen = false; m_bupdtpen = false; m_breloc = false; m_bsmaug = false; m_naugmin = 0; m_naugmax = 10; m_dofP = pfem->GetDOFIndex("p"); m_dofC = pfem->GetDOFIndex("concentration", 0); m_ss.SetSibling(&m_ms); m_ms.SetSibling(&m_ss); m_ss.SetContactInterface(this); m_ms.SetContactInterface(this); } //----------------------------------------------------------------------------- FESlidingInterface3::~FESlidingInterface3() { } //----------------------------------------------------------------------------- bool FESlidingInterface3::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; return true; } //----------------------------------------------------------------------------- //! build the matrix profile for use in the stiffness matrix void FESlidingInterface3::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_RU = fem.GetDOFIndex("Ru"); const int dof_RV = fem.GetDOFIndex("Rv"); const int dof_RW = fem.GetDOFIndex("Rw"); const int dof_C = fem.GetDOFIndex("concentration", 0); vector<int> lm(8*FEElement::MAX_NODES*2); int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FESlidingSurface3& ss = (np == 0? m_ss : m_ms); FESlidingSurface3& ms = (np == 0? m_ms : m_ss); // get the mesh int sid, mid; int k, l; for (int j=0; j<ss.Elements(); ++j) { FESurfaceElement& se = ss.Element(j); sid = ss.m_solu[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; mid = ms.m_solu[pe->m_lid]; 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[8*l ] = id[dof_X]; lm[8*l+1] = id[dof_Y]; lm[8*l+2] = id[dof_Z]; lm[8*l+3] = id[dof_P]; lm[8*l+4] = id[dof_RU]; lm[8*l+5] = id[dof_RV]; lm[8*l+6] = id[dof_RW]; lm[8*l+7] = id[dof_C + sid]; } for (l=0; l<nmeln; ++l) { vector<int>& id = mesh.Node(mn[l]).m_ID; lm[8*(l+nseln) ] = id[dof_X]; lm[8*(l+nseln)+1] = id[dof_Y]; lm[8*(l+nseln)+2] = id[dof_Z]; lm[8*(l+nseln)+3] = id[dof_P]; lm[8*(l+nseln)+4] = id[dof_RU]; lm[8*(l+nseln)+5] = id[dof_RV]; lm[8*(l+nseln)+6] = id[dof_RW]; lm[8*(l+nseln)+7] = id[dof_C + mid]; } K.build_add(lm); } } } } } //----------------------------------------------------------------------------- void FESlidingInterface3::UpdateAutoPenalty() { // calculate the penalty if (m_bautopen) { CalcAutoPenalty(m_ss); CalcAutoPenalty(m_ms); if (m_ss.m_bporo) CalcAutoPressurePenalty(m_ss); if (m_ss.m_bsolu) CalcAutoConcentrationPenalty(m_ss); if (m_ms.m_bporo) CalcAutoPressurePenalty(m_ms); if (m_ms.m_bsolu) CalcAutoConcentrationPenalty(m_ms); } } //----------------------------------------------------------------------------- void FESlidingInterface3::Activate() { // don't forget to call the base class FEContactInterface::Activate(); UpdateAutoPenalty(); // update sliding interface data Update(); } //----------------------------------------------------------------------------- void FESlidingInterface3::CalcAutoPenalty(FESlidingSurface3& 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 FESlidingInterface3::CalcAutoPressurePenalty(FESlidingSurface3& 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; } } } //----------------------------------------------------------------------------- double FESlidingInterface3::AutoPressurePenalty(FESurfaceElement& el, FESlidingSurface3& 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()); // see if this is a poro-elastic element double eps = 0.0; FEBiphasic* bp = dynamic_cast<FEBiphasic*> (pm); FEBiphasicSolute* bps = dynamic_cast<FEBiphasicSolute*> (pm); if (bp) { // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>()); // setup the material point ept.m_F = mat3dd(1.0); ept.m_J = 1; ept.m_s.zero(); // if this is a poroelastic element, then get the permeability tensor FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); pt.m_p = 0; pt.m_w = vec3d(0,0,0); double K[3][3]; bp->Permeability(K, mp); eps = n.x*(K[0][0]*n.x+K[0][1]*n.y+K[0][2]*n.z) +n.y*(K[1][0]*n.x+K[1][1]*n.y+K[1][2]*n.z) +n.z*(K[2][0]*n.x+K[2][1]*n.y+K[2][2]*n.z); } else if (bps) { // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>()); // setup the material point ept.m_F = mat3dd(1.0); ept.m_J = 1; ept.m_s.zero(); // if this is a biphasic-solute element, then get the permeability tensor FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); ppt.m_p = 0; ppt.m_w = vec3d(0,0,0); spt.m_c[0] = 0; spt.m_j[0] = vec3d(0,0,0); mat3ds K = bps->GetPermeability()->Permeability(mp); 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 FESlidingInterface3::CalcAutoConcentrationPenalty(FESlidingSurface3& 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 modulus double eps = AutoConcentrationPenalty(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_epsc[0] = eps; } } } //----------------------------------------------------------------------------- double FESlidingInterface3::AutoConcentrationPenalty(FESurfaceElement& el, FESlidingSurface3& 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()); // see if this is a biphasic-solute element FEBiphasicSolute* pbs = dynamic_cast<FEBiphasicSolute*> (pm); if (pbs == 0) return 0.0; // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>()); // setup the material point ept.m_F = mat3dd(1.0); ept.m_J = 1; ept.m_s.zero(); // if this is a biphasic-solute element, then get the diffusivity tensor FEBiphasicMaterialPoint& ppt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& spt = *(mp.ExtractData<FESolutesMaterialPoint>()); ppt.m_p = 0; ppt.m_w = vec3d(0,0,0); spt.m_c[0] = 0; spt.m_j[0] = vec3d(0,0,0); mat3ds D = pbs->GetSolute()->m_pDiff->Diffusivity(mp) *(pbs->Porosity(mp)*pbs->GetSolute()->m_pSolub->Solubility(mp)); 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 FESlidingInterface3::ProjectSurface(FESlidingSurface3& ss, FESlidingSurface3& ms, bool bupseg, bool bmove) { FEMesh& mesh = GetFEModel()->GetMesh(); FESurfaceElement* pme; vec3d r, nu; double rs[2]; double Ln; double ps[FEElement::MAX_NODES], p1; double cs[FEElement::MAX_NODES], c1; double R = m_srad*mesh.GetBoundingBox().radius(); 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 // #pragma omp parallel for shared(R, bupseg) for (int i=0; i<ss.Elements(); ++i) { FESurfaceElement& el = ss.Element(i); bool sporo = ss.m_poro[i]; int sid = ss.m_solu[i]; bool ssolu = (sid > -1) ? true : false; 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 if (ssolu) { for (int j=0; j<ne; ++j) cs[j] = mesh.Node(el.m_node[j]).get(m_dofC + sid); } 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 if (ssolu) c1 = el.eval(cs, 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 <= R? g : 0); if ((Ln >= 0) && (g <= R)) { // calculate the pressure gap function bool mporo = ms.m_poro[pme->m_lid]; int mid = ms.m_solu[pme->m_lid]; bool msolu = (mid > -1) ? true : false; 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, rs[0], rs[1]); pt.m_pg = p1 - p2; } if (ssolu && msolu && (sid == mid)) { double cm[FEElement::MAX_NODES]; 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[0] = c1 - c2; } } else { pt.m_Lmd = 0; pt.m_gap = 0; pt.m_pme = 0; if (sporo) { pt.m_Lmp = 0; pt.m_pg = 0; } if (ssolu) { pt.m_Lmc[0] = 0; pt.m_cg[0] = 0; } } } else { // the node is not in contact pt.m_Lmd = 0; pt.m_gap = 0; if (sporo) { pt.m_Lmp = 0; pt.m_pg = 0; } if (ssolu) { pt.m_Lmc[0] = 0; pt.m_cg[0] = 0; } } } } } //----------------------------------------------------------------------------- void FESlidingInterface3::Update() { double rs[2]; FEModel& fem = *GetFEModel(); // get number of DOFS DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); double R = m_srad*fem.GetMesh().GetBoundingBox().radius(); 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)); if (m_btwo_pass || m_ss.m_bporo) ProjectSurface(m_ms, m_ss, bupseg); bfirst = false; // Update the net contact pressures UpdateContactPressures(); // update node normals m_ss.UpdateNodeNormals(); m_ms.UpdateNodeNormals(); // 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; // 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 be 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) { FESlidingSurface3& ss = (np == 0? m_ss : m_ms); FESlidingSurface3& ms = (np == 0? m_ms : m_ss); // 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-free-draining (= 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) { // initialize projection data FENormalProjection np(ss); np.SetTolerance(m_stol); np.SetSearchRadius(m_srad); np.Init(); for (int n = 0; n<ms.Nodes(); ++n) { // get the node FENode& node = ms.Node(n); // project it onto the primary surface FESurfaceElement* pse = np.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); if (fabs(g) <= R) { // 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; } } } } } } } } //----------------------------------------------------------------------------- void FESlidingInterface3::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[10*MN]; FEModel& fem = *GetFEModel(); 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 FESlidingSurface3& ss = (np == 0? m_ss : m_ms); FESlidingSurface3& ms = (np == 0? m_ms : m_ss); // 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_poro[i]; int sid = ss.m_solu[i]; bool ssolu = (sid > -1) ? true : false; // 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) { FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*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_poro[pme->m_lid]; int mid = ms.m_solu[pme->m_lid]; bool msolu = (mid > -1) ? true : false; // 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 (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 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); // get normal vector vec3d nu = pt.m_nu; // gap function double g = pt.m_gap; // lagrange multiplier double Lm = pt.m_Lmd; // penalty double eps = m_epsn*pt.m_epsn*psf; // contact traction double tn = Lm + eps*g; tn = MBRACKET(tn); // calculate the force vector fe.resize(ndof); zero(fe); for (int k = 0; k<nseln; ++k) { N[3*k ] = -Hs[k]*nu.x; N[3*k+1] = -Hs[k]*nu.y; N[3*k+2] = -Hs[k]*nu.z; } for (int k = 0; k<nmeln; ++k) { N[3*(k+nseln) ] = Hm[k]*nu.x; N[3*(k+nseln)+1] = Hm[k]*nu.y; N[3*(k+nseln)+2] = Hm[k]*nu.z; } for (int k = 0; k<ndof; ++k) fe[k] += tn*N[k] * detJ[j] * w[j]; for (int k=0; k<nseln; ++k) { ss.m_Ft += vec3d(fe[k*3], fe[k*3+1], fe[k*3+2]); } for (int k = 0; k<nmeln; ++k) { ms.m_Ft += vec3d(fe[(k + nseln) * 3], fe[(k + nseln) * 3 + 1], fe[(k + nseln) * 3 + 2]); } // assemble the global residual R.Assemble(en, LM, fe); // do the biphasic stuff if (tn > 0) { if (sporo && mporo) { // calculate nr of pressure dofs int ndof = nseln + nmeln; // calculate the flow rate 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*wn*N[k] * detJ[j] * w[j]; // assemble residual R.Assemble(en, LM, fe); } if (ssolu && msolu && (sid == mid)) { // calculate nr of concentration dofs int ndof = nseln + nmeln; // calculate the flow rate double epsc = m_epsc*pt.m_epsc[0]*psf; double jn = pt.m_Lmc[0] + epsc*pt.m_cg[0]; // 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+mid)*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*jn*N[k] * detJ[j] * w[j]; // assemble residual R.Assemble(en, LM, fe); } } } } } } } //----------------------------------------------------------------------------- void FESlidingInterface3::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]; double pt[MN], dpr[MN], dps[MN]; double ct[MN], dcr[MN], dcs[MN]; double N[10*MN]; FEElementMatrix ke; 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 algrotihm 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 FESlidingSurface3& ss = (np == 0? m_ss : m_ms); FESlidingSurface3& ms = (np == 0? m_ms : m_ss); // 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_poro[i]; int sid = ss.m_solu[i]; bool ssolu = (sid > -1) ? true : false; // get nr of nodes and integration points int nseln = se.Nodes(); int nint = se.GaussPoints(); double pn[FEElement::MAX_NODES], cn[FEElement::MAX_NODES]; for (j=0; j<nseln; ++j) { pn[j] = ss.GetMesh()->Node(se.m_node[j]).get(m_dofP); cn[j] = ss.GetMesh()->Node(se.m_node[j]).get(m_dofC + sid); } // 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]; // pressure if (sporo) { pt[j] = se.eval(pn, j); dpr[j] = se.eval_deriv1(pn, j); dps[j] = se.eval_deriv2(pn, j); } // concentration if (ssolu) { ct[j] = se.eval(cn, j); dcr[j] = se.eval_deriv1(cn, j); dcs[j] = se.eval_deriv2(cn, j); } } // loop over all integration points for (j=0; j<nint; ++j) { FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*se.GetMaterialPoint(j)); // get the secondary surface element FESurfaceElement* pme = pt.m_pme; if (pme) { FESurfaceElement& me = *pme; bool mporo = ms.m_poro[pme->m_lid]; int mid = ms.m_solu[pme->m_lid]; bool msolu = (mid > -1) ? true : false; // get the nr of nodes int nmeln = me.Nodes(); // nodal data double pm[FEElement::MAX_NODES], cm[FEElement::MAX_NODES]; for (k=0; k<nmeln; ++k) { pm[k] = ms.GetMesh()->Node(me.m_node[k]).get(m_dofP); cm[k] = ms.GetMesh()->Node(me.m_node[k]).get(m_dofC + mid); } // copy the LM vector ms.UnpackLM(me, mLM); int ndpn; // number of dofs per node int ndof; // number of dofs in stiffness matrix if (ssolu && msolu && (sid == mid)) { // calculate dofs for biphasic-solute contact ndpn = 5; 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 LM[ndpn*k+4] = sLM[(4+sid)*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 LM[ndpn*(k+nseln)+4] = mLM[(4+mid)*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; // gap function double g = pt.m_gap; // lagrange multiplier double Lm = pt.m_Lmd; // penalty double eps = m_epsn*pt.m_epsn*psf; // contact traction double tn = Lm + eps*g; tn = MBRACKET(tn); // double dtn = m_eps*HEAVYSIDE(Lm + eps*g); double dtn = (tn > 0.? eps :0.); // 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 --- // a. NxN-term //------------------------------------ // calculate the N-vector for (k=0; k<nseln; ++k) { N[ndpn*k ] = Hs[k]*nu.x; N[ndpn*k+1] = Hs[k]*nu.y; N[ndpn*k+2] = Hs[k]*nu.z; } for (k=0; k<nmeln; ++k) { N[ndpn*(k+nseln) ] = -Hm[k]*nu.x; N[ndpn*(k+nseln)+1] = -Hm[k]*nu.y; N[ndpn*(k+nseln)+2] = -Hm[k]*nu.z; } if (ndpn == 5) { for (k=0; k<nseln; ++k) { N[ndpn*k+3] = 0; N[ndpn*k+4] = 0; } for (k=0; k<nmeln; ++k) { N[ndpn*(k+nseln)+3] = 0; N[ndpn*(k+nseln)+4] = 0; } } else if (ndpn == 4) { for (k=0; k<nseln; ++k) N[ndpn*k+3] = 0; for (k=0; k<nmeln; ++k) N[ndpn*(k+nseln)+3] = 0; } for (k=0; k<ndof; ++k) for (l=0; l<ndof; ++l) ke[k][l] += dtn*N[k]*N[l]*detJ[j]*w[j]; // b. A-term //------------------------------------- for (k=0; k<nseln; ++k) N[k ] = Hs[k]; for (k=0; k<nmeln; ++k) N[k+nseln] = -Hm[k]; double* Gr = se.Gr(j); double* Gs = se.Gs(j); vec3d gs[2]; ss.CoBaseVectors(se, j, gs); mat3d S1, S2; S1.skew(gs[0]); S2.skew(gs[1]); mat3d As[FEElement::MAX_NODES]; for (l=0; l<nseln; ++l) As[l] = S2*Gr[l] - S1*Gs[l]; if (!m_bsymm) { // non-symmetric for (l=0; l<nseln; ++l) { for (k=0; k<nseln+nmeln; ++k) { ke[k*ndpn ][l*ndpn ] -= knmult*tn*w[j]*N[k]*As[l][0][0]; ke[k*ndpn ][l*ndpn+1] -= knmult*tn*w[j]*N[k]*As[l][0][1]; ke[k*ndpn ][l*ndpn+2] -= knmult*tn*w[j]*N[k]*As[l][0][2]; ke[k*ndpn+1][l*ndpn ] -= knmult*tn*w[j]*N[k]*As[l][1][0]; ke[k*ndpn+1][l*ndpn+1] -= knmult*tn*w[j]*N[k]*As[l][1][1]; ke[k*ndpn+1][l*ndpn+2] -= knmult*tn*w[j]*N[k]*As[l][1][2]; ke[k*ndpn+2][l*ndpn ] -= knmult*tn*w[j]*N[k]*As[l][2][0]; ke[k*ndpn+2][l*ndpn+1] -= knmult*tn*w[j]*N[k]*As[l][2][1]; ke[k*ndpn+2][l*ndpn+2] -= knmult*tn*w[j]*N[k]*As[l][2][2]; } } } else { // symmetric for (l=0; l<nseln; ++l) { for (k=0; k<nseln+nmeln; ++k) { ke[k*ndpn ][l*ndpn ] -= 0.5*knmult*tn*w[j]*N[k]*As[l][0][0]; ke[k*ndpn ][l*ndpn+1] -= 0.5*knmult*tn*w[j]*N[k]*As[l][0][1]; ke[k*ndpn ][l*ndpn+2] -= 0.5*knmult*tn*w[j]*N[k]*As[l][0][2]; ke[k*ndpn+1][l*ndpn ] -= 0.5*knmult*tn*w[j]*N[k]*As[l][1][0]; ke[k*ndpn+1][l*ndpn+1] -= 0.5*knmult*tn*w[j]*N[k]*As[l][1][1]; ke[k*ndpn+1][l*ndpn+2] -= 0.5*knmult*tn*w[j]*N[k]*As[l][1][2]; ke[k*ndpn+2][l*ndpn ] -= 0.5*knmult*tn*w[j]*N[k]*As[l][2][0]; ke[k*ndpn+2][l*ndpn+1] -= 0.5*knmult*tn*w[j]*N[k]*As[l][2][1]; ke[k*ndpn+2][l*ndpn+2] -= 0.5*knmult*tn*w[j]*N[k]*As[l][2][2]; ke[l*ndpn ][k*ndpn ] -= 0.5*knmult*tn*w[j]*N[k]*As[l][0][0]; ke[l*ndpn+1][k*ndpn ] -= 0.5*knmult*tn*w[j]*N[k]*As[l][0][1]; ke[l*ndpn+2][k*ndpn ] -= 0.5*knmult*tn*w[j]*N[k]*As[l][0][2]; ke[l*ndpn ][k*ndpn+1] -= 0.5*knmult*tn*w[j]*N[k]*As[l][1][0]; ke[l*ndpn+1][k*ndpn+1] -= 0.5*knmult*tn*w[j]*N[k]*As[l][1][1]; ke[l*ndpn+2][k*ndpn+1] -= 0.5*knmult*tn*w[j]*N[k]*As[l][1][2]; ke[l*ndpn ][k*ndpn+2] -= 0.5*knmult*tn*w[j]*N[k]*As[l][2][0]; ke[l*ndpn+1][k*ndpn+2] -= 0.5*knmult*tn*w[j]*N[k]*As[l][2][1]; ke[l*ndpn+2][k*ndpn+2] -= 0.5*knmult*tn*w[j]*N[k]*As[l][2][2]; } } } // c. M-term //--------------------------------------- vec3d Gm[2]; ms.ContraBaseVectors(me, r, s, Gm); // evaluate secondary surface normal vec3d mnu = Gm[0] ^ Gm[1]; mnu.unit(); double Hmr[FEElement::MAX_NODES], Hms[FEElement::MAX_NODES]; me.shape_deriv(Hmr, Hms, r, s); vec3d mm[FEElement::MAX_NODES]; for (k=0; k<nmeln; ++k) mm[k] = Gm[0]*Hmr[k] + Gm[1]*Hms[k]; if (!m_bsymm) { // non-symmetric for (k=0; k<nmeln; ++k) { for (l=0; l<nseln+nmeln; ++l) { ke[(k+nseln)*ndpn ][l*ndpn ] += tn*knmult*detJ[j]*w[j]*mnu.x*mm[k].x*N[l]; ke[(k+nseln)*ndpn ][l*ndpn+1] += tn*knmult*detJ[j]*w[j]*mnu.x*mm[k].y*N[l]; ke[(k+nseln)*ndpn ][l*ndpn+2] += tn*knmult*detJ[j]*w[j]*mnu.x*mm[k].z*N[l]; ke[(k+nseln)*ndpn+1][l*ndpn ] += tn*knmult*detJ[j]*w[j]*mnu.y*mm[k].x*N[l]; ke[(k+nseln)*ndpn+1][l*ndpn+1] += tn*knmult*detJ[j]*w[j]*mnu.y*mm[k].y*N[l]; ke[(k+nseln)*ndpn+1][l*ndpn+2] += tn*knmult*detJ[j]*w[j]*mnu.y*mm[k].z*N[l]; ke[(k+nseln)*ndpn+2][l*ndpn ] += tn*knmult*detJ[j]*w[j]*mnu.z*mm[k].x*N[l]; ke[(k+nseln)*ndpn+2][l*ndpn+1] += tn*knmult*detJ[j]*w[j]*mnu.z*mm[k].y*N[l]; ke[(k+nseln)*ndpn+2][l*ndpn+2] += tn*knmult*detJ[j]*w[j]*mnu.z*mm[k].z*N[l]; } } } else { // symmetric for (k=0; k<nmeln; ++k) { for (l=0; l<nseln+nmeln; ++l) { ke[(k+nseln)*ndpn ][l*ndpn ] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.x*mm[k].x*N[l]; ke[(k+nseln)*ndpn ][l*ndpn+1] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.x*mm[k].y*N[l]; ke[(k+nseln)*ndpn ][l*ndpn+2] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.x*mm[k].z*N[l]; ke[(k+nseln)*ndpn+1][l*ndpn ] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.y*mm[k].x*N[l]; ke[(k+nseln)*ndpn+1][l*ndpn+1] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.y*mm[k].y*N[l]; ke[(k+nseln)*ndpn+1][l*ndpn+2] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.y*mm[k].z*N[l]; ke[(k+nseln)*ndpn+2][l*ndpn ] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.z*mm[k].x*N[l]; ke[(k+nseln)*ndpn+2][l*ndpn+1] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.z*mm[k].y*N[l]; ke[(k+nseln)*ndpn+2][l*ndpn+2] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.z*mm[k].z*N[l]; ke[l*ndpn ][(k+nseln)*ndpn ] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.x*mm[k].x*N[l]; ke[l*ndpn+1][(k+nseln)*ndpn ] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.y*mm[k].x*N[l]; ke[l*ndpn+2][(k+nseln)*ndpn ] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.z*mm[k].x*N[l]; ke[l*ndpn ][(k+nseln)*ndpn+1] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.x*mm[k].y*N[l]; ke[l*ndpn+1][(k+nseln)*ndpn+1] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.y*mm[k].y*N[l]; ke[l*ndpn+2][(k+nseln)*ndpn+1] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.z*mm[k].y*N[l]; ke[l*ndpn ][(k+nseln)*ndpn+2] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.x*mm[k].z*N[l]; ke[l*ndpn+1][(k+nseln)*ndpn+2] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.y*mm[k].z*N[l]; ke[l*ndpn+2][(k+nseln)*ndpn+2] += 0.5*knmult*tn*detJ[j]*w[j]*mnu.z*mm[k].z*N[l]; } } } // --- B I P H A S I C - S O L U T E S T I F F N E S S --- if (ssolu && msolu && (sid == mid)) { double dt = fem.GetTime().timeIncrement; double epsp = (tn > 0) ? m_epsp*pt.m_epsp*psf : 0.; double epsc = (tn > 0) ? m_epsc*pt.m_epsc[0]*psf : 0.; // --- 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 --- if (!m_bsymm) { // a. q-term //------------------------------------- double dpmr, dpms; dpmr = me.eval_deriv1(pm, r, s); dpms = me.eval_deriv2(pm, r, s); double dcmr, dcms; dcmr = me.eval_deriv1(cm, r, s); dcms = me.eval_deriv2(cm, r, s); for (k=0; k<nseln+nmeln; ++k) for (l=0; l<nseln+nmeln; ++l) { ke[ndpn*k + 3][ndpn*l ] += dt*w[j]*detJ[j]*epsp*N[k]*N[l]*(dpmr*Gm[0].x + dpms*Gm[1].x); ke[ndpn*k + 3][ndpn*l+1] += dt*w[j]*detJ[j]*epsp*N[k]*N[l]*(dpmr*Gm[0].y + dpms*Gm[1].y); ke[ndpn*k + 3][ndpn*l+2] += dt*w[j]*detJ[j]*epsp*N[k]*N[l]*(dpmr*Gm[0].z + dpms*Gm[1].z); ke[ndpn*k + 4][ndpn*l ] += dt*w[j]*detJ[j]*epsc*N[k]*N[l]*(dcmr*Gm[0].x + dcms*Gm[1].x); ke[ndpn*k + 4][ndpn*l+1] += dt*w[j]*detJ[j]*epsc*N[k]*N[l]*(dcmr*Gm[0].y + dcms*Gm[1].y); ke[ndpn*k + 4][ndpn*l+2] += dt*w[j]*detJ[j]*epsc*N[k]*N[l]*(dcmr*Gm[0].z + dcms*Gm[1].z); } double wn = pt.m_Lmp + epsp*pt.m_pg; double jn = pt.m_Lmc[0] + epsc*pt.m_cg[0]; // b. A-term //------------------------------------- for (l=0; l<nseln; ++l) for (k=0; k<nseln+nmeln; ++k) { ke[ndpn*k + 3][ndpn*l ] -= dt*w[j]*wn*N[k]*(As[l][0][0]*nu.x + As[l][0][1]*nu.y + As[l][0][2]*nu.z); ke[ndpn*k + 3][ndpn*l+1] -= dt*w[j]*wn*N[k]*(As[l][1][0]*nu.x + As[l][1][1]*nu.y + As[l][1][2]*nu.z); ke[ndpn*k + 3][ndpn*l+2] -= dt*w[j]*wn*N[k]*(As[l][2][0]*nu.x + As[l][2][1]*nu.y + As[l][2][2]*nu.z); ke[ndpn*k + 4][ndpn*l ] -= dt*w[j]*jn*N[k]*(As[l][0][0]*nu.x + As[l][0][1]*nu.y + As[l][0][2]*nu.z); ke[ndpn*k + 4][ndpn*l+1] -= dt*w[j]*jn*N[k]*(As[l][1][0]*nu.x + As[l][1][1]*nu.y + As[l][1][2]*nu.z); ke[ndpn*k + 4][ndpn*l+2] -= dt*w[j]*jn*N[k]*(As[l][2][0]*nu.x + As[l][2][1]*nu.y + As[l][2][2]*nu.z); } // c. m-term //--------------------------------------- for (k=0; k<nmeln; ++k) for (l=0; l<nseln+nmeln; ++l) { ke[ndpn*(k+nseln) + 3][ndpn*l ] += dt*w[j]*detJ[j]*wn*N[l]*mm[k].x; ke[ndpn*(k+nseln) + 3][ndpn*l+1] += dt*w[j]*detJ[j]*wn*N[l]*mm[k].y; ke[ndpn*(k+nseln) + 3][ndpn*l+2] += dt*w[j]*detJ[j]*wn*N[l]*mm[k].z; ke[ndpn*(k+nseln) + 4][ndpn*l ] += dt*w[j]*detJ[j]*jn*N[l]*mm[k].x; ke[ndpn*(k+nseln) + 4][ndpn*l+1] += dt*w[j]*detJ[j]*jn*N[l]*mm[k].y; ke[ndpn*(k+nseln) + 4][ndpn*l+2] += dt*w[j]*detJ[j]*jn*N[l]*mm[k].z; } } // --- P R E S S U R E - P R E S S U R E C O N T A C T --- // calculate the N-vector for (k=0; k<nseln; ++k) { N[ndpn*k+3] = Hs[k]; N[ndpn*k+4] = Hs[k]; } for (k=0; k<nmeln; ++k) { N[ndpn*(k+nseln)+3] = -Hm[k]; N[ndpn*(k+nseln)+4] = -Hm[k]; } for (k=3; k<ndof; k+=ndpn) for (l=3; l<ndof; l+=ndpn) ke[k][l] -= dt*epsp*w[j]*detJ[j]*N[k]*N[l]; // --- 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 (k=4; k<ndof; k+=ndpn) for (l=4; l<ndof; l+=ndpn) ke[k][l] -= dt*epsc*w[j]*detJ[j]*N[k]*N[l]; } // --- B I P H A S I C S T I F F N E S S --- else if (sporo && mporo) { // the variable dt is either the timestep or one // depending on whether we are using the symmetric // poro version or not. double dt = fem.GetTime().timeIncrement; double epsp = (tn > 0) ? m_epsp*pt.m_epsp*psf : 0.; // --- S O L I D - P R E S S U R E C O N T A C T --- if (!m_bsymm) { // a. q-term //------------------------------------- double dpmr, dpms; dpmr = me.eval_deriv1(pm, r, s); dpms = me.eval_deriv2(pm, r, s); for (k=0; k<nseln+nmeln; ++k) for (l=0; l<nseln+nmeln; ++l) { ke[ndpn*k + 3][ndpn*l ] += dt*w[j]*detJ[j]*epsp*N[k]*N[l]*(dpmr*Gm[0].x + dpms*Gm[1].x); ke[ndpn*k + 3][ndpn*l+1] += dt*w[j]*detJ[j]*epsp*N[k]*N[l]*(dpmr*Gm[0].y + dpms*Gm[1].y); ke[ndpn*k + 3][ndpn*l+2] += dt*w[j]*detJ[j]*epsp*N[k]*N[l]*(dpmr*Gm[0].z + dpms*Gm[1].z); } double wn = pt.m_Lmp + epsp*pt.m_pg; // b. A-term //------------------------------------- for (l=0; l<nseln; ++l) for (k=0; k<nseln+nmeln; ++k) { ke[ndpn*k + 3][ndpn*l ] -= dt*w[j]*wn*N[k]*(As[l][0][0]*nu.x + As[l][0][1]*nu.y + As[l][0][2]*nu.z); ke[ndpn*k + 3][ndpn*l+1] -= dt*w[j]*wn*N[k]*(As[l][1][0]*nu.x + As[l][1][1]*nu.y + As[l][1][2]*nu.z); ke[ndpn*k + 3][ndpn*l+2] -= dt*w[j]*wn*N[k]*(As[l][2][0]*nu.x + As[l][2][1]*nu.y + As[l][2][2]*nu.z); } // c. m-term //--------------------------------------- for (k=0; k<nmeln; ++k) for (l=0; l<nseln+nmeln; ++l) { ke[ndpn*(k+nseln) + 3][ndpn*l ] += dt*w[j]*detJ[j]*wn*N[l]*mm[k].x; ke[ndpn*(k+nseln) + 3][ndpn*l+1] += dt*w[j]*detJ[j]*wn*N[l]*mm[k].y; ke[ndpn*(k+nseln) + 3][ndpn*l+2] += dt*w[j]*detJ[j]*wn*N[l]*mm[k].z; } } // --- P R E S S U R E - P R E S S U R E C O N T A C T --- // calculate the N-vector for (k=0; k<nseln; ++k) { N[ndpn*k+3] = Hs[k]; } for (k=0; k<nmeln; ++k) { N[ndpn*(k+nseln)+3] = -Hm[k]; } for (k=3; k<ndof; k+=ndpn) for (l=3; l<ndof; l+=ndpn) ke[k][l] -= dt*epsp*w[j]*detJ[j]*N[k]*N[l]; } // assemble the global stiffness ke.SetNodes(en); ke.SetIndices(LM); LS.Assemble(ke); } } } } } //----------------------------------------------------------------------------- void FESlidingInterface3::UpdateContactPressures() { int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FESlidingSurface3& ss = (np == 0? m_ss : m_ms); FESlidingSurface3& ms = (np == 0? m_ms : m_ss); // loop over all elements of the primary surface for (int n=0; n<ss.Elements(); ++n) { FESurfaceElement& el = ss.Element(n); int nint = el.GaussPoints(); // get the normal tractions at the integration points double gap, eps; for (int i=0; i<nint; ++i) { FEMultiphasicContactPoint& pt = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(i)); gap = pt.m_gap; eps = m_epsn*pt.m_epsn; pt.m_Ln = MBRACKET(pt.m_Lmd + eps*gap); FESurfaceElement* pme = pt.m_pme; if (m_btwo_pass && pme) { int mint = pme->GaussPoints(); double ti[FEElement::MAX_NODES]; for (int j=0; j<mint; ++j) { FEMultiphasicContactPoint& md = static_cast<FEMultiphasicContactPoint&>(*pme->GetMaterialPoint(j)); gap = md.m_gap; eps = m_epsn*md.m_epsn; ti[j] = MBRACKET(md.m_Lmd + m_epsn*md.m_epsn*md.m_gap); } // project the data to the nodes double tn[FEElement::MAX_NODES]; pme->FEElement::project_to_nodes(ti, tn); // now evaluate the traction at the intersection point double Ln = pme->eval(tn, pt.m_rs[0], pt.m_rs[1]); pt.m_Ln += MBRACKET(Ln); } } } ss.EvaluateNodalContactPressures(); } } //----------------------------------------------------------------------------- bool FESlidingInterface3::Augment(int naug, const FETimeInfo& tp) { // make sure we need to augment if (m_laugon != FECore::AUGLAG_METHOD) return true; double Ln, Lp, Lc; 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, normDC = 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)); 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)); normL0 += dm.m_Lmd*dm.m_Lmd; } } // b. gap component // (is calculated during update) double maxgap = 0, maxpg = 0, maxcg = 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& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); // update Lagrange multipliers on primary surface if (m_bsmaug) { // replace this multiplier with a smoother version Ln = -(tn[j]*data.m_nu); data.m_Lmd = MBRACKET(Ln); if (m_btwo_pass) data.m_Lmd /= 2; } else { eps = m_epsn*data.m_epsn; Ln = data.m_Lmd + eps*data.m_gap; data.m_Lmd = MBRACKET(Ln); } normL1 += data.m_Lmd*data.m_Lmd; if (m_ss.m_bporo) { Lp = 0; if (Ln > 0) { epsp = m_epsp*data.m_epsp; Lp = data.m_Lmp + epsp*data.m_pg; maxpg = max(maxpg,fabs(data.m_pg)); normDP += data.m_pg*data.m_pg; } data.m_Lmp = Lp; } if (m_ss.m_bsolu) { Lc = 0; if (Ln > 0) { epsc = m_epsc*data.m_epsc[0]; Lc = data.m_Lmc[0] + epsc*data.m_cg[0]; maxcg = max(maxcg,fabs(data.m_cg[0])); normDC += data.m_cg[0]*data.m_cg[0]; } data.m_Lmc[0] = Lc; } if (Ln > 0) maxgap = max(maxgap,fabs(data.m_gap)); } } 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& data = static_cast<FEMultiphasicContactPoint&>(*el.GetMaterialPoint(j)); // update Lagrange multipliers on secondary surface if (m_bsmaug) { // replace this multiplier with a smoother version Ln = -(tn[j]*data.m_nu); data.m_Lmd = MBRACKET(Ln); if (m_btwo_pass) data.m_Lmd /= 2; } else { eps = m_epsn*data.m_epsn; Ln = data.m_Lmd + eps*data.m_gap; data.m_Lmd = MBRACKET(Ln); } normL1 += data.m_Lmd*data.m_Lmd; if (m_ms.m_bporo) { Lp = 0; if (Ln > 0) { epsp = m_epsp*data.m_epsp; Lp = data.m_Lmp + epsp*data.m_pg; maxpg = max(maxpg,fabs(data.m_pg)); normDP += data.m_pg*data.m_pg; } data.m_Lmp = Lp; } if (m_ms.m_bsolu) { Lc = 0; if (Ln > 0) { epsc = m_epsc*data.m_epsc[0]; Lc = data.m_Lmc[0] + epsc*data.m_cg[0]; maxcg = max(maxcg,fabs(data.m_cg[0])); normDC += data.m_cg[0]*data.m_cg[0]; } data.m_Lmc[0] = Lc; } if (Ln > 0) maxgap = max(maxgap,fabs(data.m_gap)); } } // 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); double cnorm = (normC != 0 ? (normDC/normC) : normDC); // check convergence if ((m_gtol > 0) && (maxgap > m_gtol)) bconv = false; if ((m_ptol > 0) && (bporo && maxpg > m_ptol)) bconv = false; if ((m_ctol > 0) && (bsolu && maxcg > m_ctol)) bconv = false; if ((m_atol > 0) && (lnorm > m_atol)) bconv = false; if ((m_atol > 0) && (pnorm > m_atol)) bconv = false; if ((m_atol > 0) && (cnorm > 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"); } if (bsolu) { feLog(" C gap : %15le", cnorm); 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"); } if (bsolu) { feLog(" maximum cgap : %15le", maxcg); if (m_ctol > 0) feLog("%15le\n", m_ctol); else feLog(" ***\n"); } return bconv; } //----------------------------------------------------------------------------- void FESlidingInterface3::Serialize(DumpStream &ar) { // store contact 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); } //----------------------------------------------------------------------------- void FESlidingInterface3::MarkAmbient() { // 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. // get number of DOFS DOFS& fedofs = GetFEModel()->GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); for (int np=0; np<2; ++np) { FESlidingSurface3& 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 (int i=0; i<s.Nodes(); ++i) { int 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 (int i=0; i<s.Nodes(); ++i) { for (int j=0; j<MAX_CDOFS; ++j) { int 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 FESlidingInterface3::SetAmbient() { // 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 (int np=0; np<2; ++np) { FESlidingSurface3& s = (np == 0? m_ss : m_ms); if (s.m_bporo) { // loop over all nodes for (int 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 (int i=0; i<s.Nodes(); ++i) { for (int 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); } } } } } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicStandard.h
.h
1,774
47
/*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" //----------------------------------------------------------------------------- //! Standard multiphasic material. class FEBIOMIX_API FEMultiphasicStandard : public FEMultiphasic { public: //! constructor FEMultiphasicStandard(FEModel* pfem); //! returns a pointer to a new material point object FEMaterialPointData* CreateMaterialPointData(); //! Update solid bound molecules void UpdateSolidBoundMolecules(FEMaterialPoint& mp); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicDomain.h
.h
3,151
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.*/ #pragma once #include "FECore/FESolidDomain.h" #include "FEMultiphasic.h" #include "FEBioMech/FEElasticDomain.h" //----------------------------------------------------------------------------- class FEModel; class FEGlobalVector; class FEBodyForce; class FESolver; //----------------------------------------------------------------------------- //! Abstract interface class for multiphasic 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 FEMultiphasicDomain : public FEElasticDomain { public: FEMultiphasicDomain(FEModel* pfem); virtual ~FEMultiphasicDomain(){} // --- 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; protected: FEMultiphasic* m_pMat; int m_dofP; //!< pressure dof index int m_dofQ; //!< shell extra pressure dof index int m_dofC; //!< concentration dof index int m_dofD; //!< shell extra concentration dof index int m_dofVX; int m_dofVY; int m_dofVZ; protected: bool m_breset; //! flag for calling reset };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FETiedBiphasicInterface.cpp
.cpp
39,609
1,341
/*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 "FETiedBiphasicInterface.h" #include "FEBiphasic.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(FETiedBiphasicInterface, 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_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_bsymm , "symmetric_stiffness"); ADD_PARAMETER(m_srad , "search_radius" ); ADD_PARAMETER(m_naugmin , "minaug" ); ADD_PARAMETER(m_naugmax , "maxaug" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- void FETiedBiphasicContactPoint::Serialize(DumpStream& ar) { FEBiphasicContactPoint::Serialize(ar); ar & m_Gap; ar & m_dg; ar & m_nu; ar & m_rs; ar & m_Lmd; ar & m_tr; ar & m_epsn; ar & m_epsp; } //----------------------------------------------------------------------------- // FETiedBiphasicSurface //----------------------------------------------------------------------------- FETiedBiphasicSurface::FETiedBiphasicSurface(FEModel* pfem) : FEBiphasicContactSurface(pfem) { m_bporo = false; } //----------------------------------------------------------------------------- //! create material point data FEMaterialPoint* FETiedBiphasicSurface::CreateMaterialPoint() { return new FETiedBiphasicContactPoint; } //----------------------------------------------------------------------------- bool FETiedBiphasicSurface::Init() { // initialize surface data first if (FEBiphasicContactSurface::Init() == false) return false; // allocate node normals m_nn.assign(Nodes(), vec3d(0,0,0)); // determine biphasic status m_poro.resize(Elements(),false); for (int i=0; i<Elements(); ++i) { // get the surface element FESurfaceElement& se = Element(i); // 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()); // see if this is a poro-elastic element FEBiphasic* biph = dynamic_cast<FEBiphasic*> (pm); if (biph) { m_poro[i] = true; m_bporo = true; } } } 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 FETiedBiphasicSurface::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 FETiedBiphasicSurface::Serialize(DumpStream& ar) { FEBiphasicContactSurface::Serialize(ar); ar & m_bporo; ar & m_poro; ar & m_nn; } //----------------------------------------------------------------------------- void FETiedBiphasicSurface::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) { FETiedBiphasicContactPoint& data = static_cast<FETiedBiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_dg; } pg /= ni; } //----------------------------------------------------------------------------- void FETiedBiphasicSurface::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) { FETiedBiphasicContactPoint& data = static_cast<FETiedBiphasicContactPoint&>(*el.GetMaterialPoint(k)); pt += data.m_tr; } pt /= ni; } //----------------------------------------------------------------------------- // FETiedBiphasicInterface //----------------------------------------------------------------------------- FETiedBiphasicInterface::FETiedBiphasicInterface(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_btwo_pass = false; m_stol = 0.01; m_bsymm = true; m_srad = 1.0; m_gtol = -1; // we use augmentation tolerance by default m_ptol = -1; // we use augmentation tolerance by default m_bautopen = false; m_bupdtpen = false; m_naugmin = 0; m_naugmax = 10; m_dofP = pfem->GetDOFIndex("p"); // set parents m_ss.SetContactInterface(this); m_ms.SetContactInterface(this); m_ss.SetSibling(&m_ms); m_ms.SetSibling(&m_ss); } //----------------------------------------------------------------------------- FETiedBiphasicInterface::~FETiedBiphasicInterface() { } //----------------------------------------------------------------------------- bool FETiedBiphasicInterface::Init() { // initialize surface data if (m_ss.Init() == false) return false; if (m_ms.Init() == false) return false; return true; } //----------------------------------------------------------------------------- //! build the matrix profile for use in the stiffness matrix void FETiedBiphasicInterface::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_RU = fem.GetDOFIndex("Ru"); const int dof_RV = fem.GetDOFIndex("Rv"); const int dof_RW = fem.GetDOFIndex("Rw"); vector<int> lm(7*FEElement::MAX_NODES*2); int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FETiedBiphasicSurface& ss = (np == 0? m_ss : m_ms); FETiedBiphasicSurface& ms = (np == 0? m_ms : m_ss); int ni = 0, 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, ++ni) { FETiedBiphasicContactPoint& pt = static_cast<FETiedBiphasicContactPoint&>(*se.GetMaterialPoint(k)); FESurfaceElement* pe = pt.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[7*l ] = id[dof_X]; lm[7*l+1] = id[dof_Y]; lm[7*l+2] = id[dof_Z]; lm[7*l+3] = id[dof_P]; lm[7*l+4] = id[dof_RU]; lm[7*l+5] = id[dof_RV]; lm[7*l+6] = id[dof_RW]; } for (l=0; l<nmeln; ++l) { vector<int>& id = mesh.Node(mn[l]).m_ID; lm[7*(l+nseln) ] = id[dof_X]; lm[7*(l+nseln)+1] = id[dof_Y]; lm[7*(l+nseln)+2] = id[dof_Z]; lm[7*(l+nseln)+3] = id[dof_P]; lm[7*(l+nseln)+4] = id[dof_RU]; lm[7*(l+nseln)+5] = id[dof_RV]; lm[7*(l+nseln)+6] = id[dof_RW]; } K.build_add(lm); } } } } } //----------------------------------------------------------------------------- void FETiedBiphasicInterface::UpdateAutoPenalty() { // calculate the penalty if (m_bautopen) { CalcAutoPenalty(m_ss); if (m_ss.m_bporo) CalcAutoPressurePenalty(m_ss); if (m_btwo_pass) { CalcAutoPenalty(m_ms); if (m_ms.m_bporo) CalcAutoPressurePenalty(m_ms); } } } //----------------------------------------------------------------------------- void FETiedBiphasicInterface::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 FETiedBiphasicInterface::CalcAutoPenalty(FETiedBiphasicSurface& 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) { FETiedBiphasicContactPoint& pt = static_cast<FETiedBiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsn = eps; } } } //----------------------------------------------------------------------------- void FETiedBiphasicInterface::CalcAutoPressurePenalty(FETiedBiphasicSurface& 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) { FETiedBiphasicContactPoint& pt = static_cast<FETiedBiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsp = eps; } } } //----------------------------------------------------------------------------- double FETiedBiphasicInterface::AutoPressurePenalty(FESurfaceElement& el, FETiedBiphasicSurface& 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()); // see if this is a poro-elastic element FEBiphasic* biph = dynamic_cast<FEBiphasic*> (pm); if (biph == 0) return 0.0; // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>()); // setup the material point ept.m_F = mat3dd(1.0); ept.m_J = 1; ept.m_s.zero(); // if this is a poroelastic element, then get the permeability tensor FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); pt.m_p = 0; pt.m_w = vec3d(0,0,0); double K[3][3]; biph->Permeability(K, mp); double eps = n.x*(K[0][0]*n.x+K[0][1]*n.y+K[0][2]*n.z) +n.y*(K[1][0]*n.x+K[1][1]*n.y+K[1][2]*n.z) +n.z*(K[2][0]*n.x+K[2][1]*n.y+K[2][2]*n.z); // 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 FETiedBiphasicInterface::InitialProjection(FETiedBiphasicSurface& ss, FETiedBiphasicSurface& ms) { FEMesh& mesh = GetFEModel()->GetMesh(); double R = m_srad*mesh.GetBoundingBox().radius(); 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); FETiedBiphasicContactPoint& pt = static_cast<FETiedBiphasicContactPoint&>(*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 FETiedBiphasicInterface::ProjectSurface(FETiedBiphasicSurface& ss, FETiedBiphasicSurface& ms) { FEMesh& mesh = GetFEModel()->GetMesh(); FESurfaceElement* pme; vec3d r; double ps[FEElement::MAX_NODES], p1; // 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 if (sporo) { for (int j=0; j<ne; ++j) ps[j] = mesh.Node(el.m_node[j]).get(m_dofP); } for (int j=0; j<nint; ++j) { FETiedBiphasicContactPoint& pt = static_cast<FETiedBiphasicContactPoint&>(*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); // 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; // pt.m_gap = pt.m_dg.unit(); // 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; } } else { // the node is not tied pt.m_dg = vec3d(0,0,0); // pt.m_gap = 0; if (sporo) pt.m_pg = 0; } } } } //----------------------------------------------------------------------------- void FETiedBiphasicInterface::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 FETiedBiphasicInterface::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[8*MN]; // get time step // if we're using the symmetric formulation // we need to multiply with the timestep double dt = GetFEModel()->GetTime().timeIncrement; // Update auto-penalty if requested if (m_bupdtpen && GetFEModel()->GetCurrentStep()->GetFESolver()->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 secondary surface FETiedBiphasicSurface& ss = (np == 0? m_ss : m_ms); FETiedBiphasicSurface& ms = (np == 0? m_ms : m_ss); // 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_poro[i]; // 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]; } // loop over all integration points // note that we are integrating over the current surface for (j=0; j<nint; ++j) { FETiedBiphasicContactPoint& pt = static_cast<FETiedBiphasicContactPoint&>(*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_poro[pme->m_lid]; // 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); // get normal vector vec3d nu = pt.m_nu; // gap function vec3d dg = pt.m_dg; // lagrange multiplier vec3d Lm = pt.m_Lmd; // penalty double eps = m_epsn*pt.m_epsn; // contact traction vec3d t = Lm + dg*eps; pt.m_tr = t; // calculate the force vector fe.resize(ndof); zero(fe); for (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 (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 (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 // TODO: I should only do this when the node is actually in contact if (sporo && mporo && pt.m_pme) { // calculate nr of pressure dofs int ndof = nseln + nmeln; // calculate the flow rate double epsp = m_epsp*pt.m_epsp; double wn = pt.m_Lmp + epsp*pt.m_pg; // 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*wn*N[k]*detJ[j]*w[j]; // assemble residual R.Assemble(en, LM, fe); } } } } } } //----------------------------------------------------------------------------- void FETiedBiphasicInterface::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], pt[MN], dpr[MN], dps[MN]; FEElementMatrix ke; // get time step double dt = GetFEModel()->GetTime().timeIncrement; // get the mesh FEMesh* pm = m_ss.GetMesh(); // see how many reformations we've had to do so far int nref = GetSolver()->m_nref; // set higher order stiffness mutliplier // NOTE: this algrotihm 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 FETiedBiphasicSurface& ss = (np == 0? m_ss : m_ms); FETiedBiphasicSurface& ms = (np == 0? m_ms : m_ss); // 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_poro[i]; // get nr of nodes and integration points int nseln = se.Nodes(); int nint = se.GaussPoints(); // nodal pressures double pn[FEElement::MAX_NODES]; for (j=0; j<nseln; ++j) pn[j] = ss.GetMesh()->Node(se.m_node[j]).get(m_dofP); // 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]; // pressure if (sporo) { pt[j] = se.eval(pn, j); dpr[j] = se.eval_deriv1(pn, j); dps[j] = se.eval_deriv2(pn, j); } } // loop over all integration points for (j=0; j<nint; ++j) { FETiedBiphasicContactPoint& pt = static_cast<FETiedBiphasicContactPoint&>(*se.GetMaterialPoint(j)); // get the secondary surface element FESurfaceElement* pme = pt.m_pme; if (pme) { FESurfaceElement& me = *pme; bool mporo = ms.m_poro[pme->m_lid]; // get the nr of secondary surface nodes int nmeln = me.Nodes(); // nodal pressure double pm[FEElement::MAX_NODES]; if (mporo) for (k=0; k<nmeln; ++k) pm[k] = ms.GetMesh()->Node(me.m_node[k]).get(m_dofP); // copy the LM vector ms.UnpackLM(me, mLM); int ndpn; // number of dofs per node int ndof; // number of dofs in stiffness matrix if (sporo && mporo) { // calculate degrees of freedom for biphasic-on-biphasic contact ndpn = 4; ndof = ndpn*(nseln+nmeln); // build the LM vector LM.resize(ndof); for (k=0; k<nseln; ++k) { LM[4*k ] = sLM[3*k ]; // x-dof LM[4*k+1] = sLM[3*k+1]; // y-dof LM[4*k+2] = sLM[3*k+2]; // z-dof LM[4*k+3] = sLM[3*nseln+k]; // p-dof } for (k=0; k<nmeln; ++k) { LM[4*(k+nseln) ] = mLM[3*k ]; // x-dof LM[4*(k+nseln)+1] = mLM[3*k+1]; // y-dof LM[4*(k+nseln)+2] = mLM[3*k+2]; // z-dof LM[4*(k+nseln)+3] = mLM[3*nmeln+k]; // p-dof } } else { // calculate degrees of freedom for biphasic-on-elastic or elastic-on-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; // gap function vec3d dg = pt.m_dg; // lagrange multiplier vec3d Lm = pt.m_Lmd; // penalty double eps = m_epsn*pt.m_epsn; // contact traction vec3d t = Lm + dg*eps; // 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 --- // a. I-term //------------------------------------ for (k=0; k<nseln; ++k) { for (l=0; l<nseln; ++l) { ke[ndpn*k ][ndpn*l ] += eps*Hs[k]*Hs[l]*detJ[j]*w[j]; ke[ndpn*k + 1][ndpn*l + 1] += eps*Hs[k]*Hs[l]*detJ[j]*w[j]; ke[ndpn*k + 2][ndpn*l + 2] += eps*Hs[k]*Hs[l]*detJ[j]*w[j]; } for (l=0; l<nmeln; ++l) { ke[ndpn*k ][ndpn*(nseln+l) ] += -eps*Hs[k]*Hm[l]*detJ[j]*w[j]; ke[ndpn*k + 1][ndpn*(nseln+l) + 1] += -eps*Hs[k]*Hm[l]*detJ[j]*w[j]; ke[ndpn*k + 2][ndpn*(nseln+l) + 2] += -eps*Hs[k]*Hm[l]*detJ[j]*w[j]; } } for (k=0; k<nmeln; ++k) { for (l=0; l<nseln; ++l) { ke[ndpn*(nseln+k) ][ndpn*l ] += -eps*Hm[k]*Hs[l]*detJ[j]*w[j]; ke[ndpn*(nseln+k) + 1][ndpn*l + 1] += -eps*Hm[k]*Hs[l]*detJ[j]*w[j]; ke[ndpn*(nseln+k) + 2][ndpn*l + 2] += -eps*Hm[k]*Hs[l]*detJ[j]*w[j]; } for (l=0; l<nmeln; ++l) { ke[ndpn*(nseln+k) ][ndpn*(nseln+l) ] += eps*Hm[k]*Hm[l]*detJ[j]*w[j]; ke[ndpn*(nseln+k) + 1][ndpn*(nseln+l) + 1] += eps*Hm[k]*Hm[l]*detJ[j]*w[j]; ke[ndpn*(nseln+k) + 2][ndpn*(nseln+l) + 2] += eps*Hm[k]*Hm[l]*detJ[j]*w[j]; } } // b. A-term //------------------------------------- double* Gr = se.Gr(j); double* Gs = se.Gs(j); vec3d gs[2]; ss.CoBaseVectors(se, j, gs); vec3d as[FEElement::MAX_NODES]; mat3d As[FEElement::MAX_NODES]; for (l=0; l<nseln; ++l) { as[l] = nu ^ (gs[1]*Gr[l] - gs[0]*Gs[l]); As[l] = t & as[l]; } if (!m_bsymm) { // non-symmetric for (k=0; k<nseln; ++k) { for (l=0; l<nseln; ++l) { ke[ndpn*k ][ndpn*l ] += Hs[k]*As[l](0,0)*w[j]; ke[ndpn*k ][ndpn*l + 1] += Hs[k]*As[l](0,1)*w[j]; ke[ndpn*k ][ndpn*l + 2] += Hs[k]*As[l](0,2)*w[j]; ke[ndpn*k + 1][ndpn*l ] += Hs[k]*As[l](1,0)*w[j]; ke[ndpn*k + 1][ndpn*l + 1] += Hs[k]*As[l](1,1)*w[j]; ke[ndpn*k + 1][ndpn*l + 2] += Hs[k]*As[l](1,2)*w[j]; ke[ndpn*k + 2][ndpn*l ] += Hs[k]*As[l](2,0)*w[j]; ke[ndpn*k + 2][ndpn*l + 1] += Hs[k]*As[l](2,1)*w[j]; ke[ndpn*k + 2][ndpn*l + 2] += Hs[k]*As[l](2,2)*w[j]; } } for (k=0; k<nmeln; ++k) { for (l=0; l<nseln; ++l) { ke[ndpn*(nseln+k) ][ndpn*l ] += -Hm[k]*As[l](0,0)*w[j]; ke[ndpn*(nseln+k) ][ndpn*l + 1] += -Hm[k]*As[l](0,1)*w[j]; ke[ndpn*(nseln+k) ][ndpn*l + 2] += -Hm[k]*As[l](0,2)*w[j]; ke[ndpn*(nseln+k) + 1][ndpn*l ] += -Hm[k]*As[l](1,0)*w[j]; ke[ndpn*(nseln+k) + 1][ndpn*l + 1] += -Hm[k]*As[l](1,1)*w[j]; ke[ndpn*(nseln+k) + 1][ndpn*l + 2] += -Hm[k]*As[l](1,2)*w[j]; ke[ndpn*(nseln+k) + 2][ndpn*l ] += -Hm[k]*As[l](2,0)*w[j]; ke[ndpn*(nseln+k) + 2][ndpn*l + 1] += -Hm[k]*As[l](2,1)*w[j]; ke[ndpn*(nseln+k) + 2][ndpn*l + 2] += -Hm[k]*As[l](2,2)*w[j]; } } } else { // symmetric for (k=0; k<nseln; ++k) { for (l=0; l<nseln; ++l) { ke[ndpn*k ][ndpn*l ] += 0.5*(Hs[k]*As[l](0,0)+Hs[l]*As[k](0,0))*w[j]; ke[ndpn*k ][ndpn*l + 1] += 0.5*(Hs[k]*As[l](0,1)+Hs[l]*As[k](1,0))*w[j]; ke[ndpn*k ][ndpn*l + 2] += 0.5*(Hs[k]*As[l](0,2)+Hs[l]*As[k](2,0))*w[j]; ke[ndpn*k + 1][ndpn*l ] += 0.5*(Hs[k]*As[l](1,0)+Hs[l]*As[k](0,1))*w[j]; ke[ndpn*k + 1][ndpn*l + 1] += 0.5*(Hs[k]*As[l](1,1)+Hs[l]*As[k](1,1))*w[j]; ke[ndpn*k + 1][ndpn*l + 2] += 0.5*(Hs[k]*As[l](1,2)+Hs[l]*As[k](2,1))*w[j]; ke[ndpn*k + 2][ndpn*l ] += 0.5*(Hs[k]*As[l](2,0)+Hs[l]*As[k](0,2))*w[j]; ke[ndpn*k + 2][ndpn*l + 1] += 0.5*(Hs[k]*As[l](2,1)+Hs[l]*As[k](1,2))*w[j]; ke[ndpn*k + 2][ndpn*l + 2] += 0.5*(Hs[k]*As[l](2,2)+Hs[l]*As[k](2,2))*w[j]; } } for (k=0; k<nmeln; ++k) { for (l=0; l<nseln; ++l) { ke[ndpn*(nseln+k) ][ndpn*l ] += -0.5*Hm[k]*As[l](0,0)*w[j]; ke[ndpn*(nseln+k) ][ndpn*l + 1] += -0.5*Hm[k]*As[l](0,1)*w[j]; ke[ndpn*(nseln+k) ][ndpn*l + 2] += -0.5*Hm[k]*As[l](0,2)*w[j]; ke[ndpn*(nseln+k) + 1][ndpn*l ] += -0.5*Hm[k]*As[l](1,0)*w[j]; ke[ndpn*(nseln+k) + 1][ndpn*l + 1] += -0.5*Hm[k]*As[l](1,1)*w[j]; ke[ndpn*(nseln+k) + 1][ndpn*l + 2] += -0.5*Hm[k]*As[l](1,2)*w[j]; ke[ndpn*(nseln+k) + 2][ndpn*l ] += -0.5*Hm[k]*As[l](2,0)*w[j]; ke[ndpn*(nseln+k) + 2][ndpn*l + 1] += -0.5*Hm[k]*As[l](2,1)*w[j]; ke[ndpn*(nseln+k) + 2][ndpn*l + 2] += -0.5*Hm[k]*As[l](2,2)*w[j]; } } for (k=0; k<nseln; ++k) { for (l=0; l<nmeln; ++l) { ke[ndpn*k ][ndpn*(nseln+l) ] += -0.5*Hm[l]*As[k](0,0)*w[j]; ke[ndpn*k ][ndpn*(nseln+l) + 1] += -0.5*Hm[l]*As[k](1,0)*w[j]; ke[ndpn*k ][ndpn*(nseln+l) + 2] += -0.5*Hm[l]*As[k](2,0)*w[j]; ke[ndpn*k + 1][ndpn*(nseln+l) ] += -0.5*Hm[l]*As[k](0,1)*w[j]; ke[ndpn*k + 1][ndpn*(nseln+l) + 1] += -0.5*Hm[l]*As[k](1,1)*w[j]; ke[ndpn*k + 1][ndpn*(nseln+l) + 2] += -0.5*Hm[l]*As[k](2,1)*w[j]; ke[ndpn*k + 2][ndpn*(nseln+l) ] += -0.5*Hm[l]*As[k](0,2)*w[j]; ke[ndpn*k + 2][ndpn*(nseln+l) + 1] += -0.5*Hm[l]*As[k](1,2)*w[j]; ke[ndpn*k + 2][ndpn*(nseln+l) + 2] += -0.5*Hm[l]*As[k](2,2)*w[j]; } } } // --- B I P H A S I C S T I F F N E S S --- if (sporo && mporo) { double epsp = (pt.m_pme) ? m_epsp*pt.m_epsp : 0.; // --- S O L I D - P R E S S U R E C O N T A C T --- // b. A-term //------------------------------------- double wn = pt.m_Lmp + epsp*pt.m_pg; if (!m_bsymm) { // non-symmetric for (k=0; k<nseln; ++k) for (l=0; l<nseln; ++l) { { ke[4*k + 3][4*l ] += dt*w[j]*wn*Hs[k]*as[l].x; ke[4*k + 3][4*l+1] += dt*w[j]*wn*Hs[k]*as[l].y; ke[4*k + 3][4*l+2] += dt*w[j]*wn*Hs[k]*as[l].z; } } for (k=0; k<nmeln; ++k) for (l=0; l<nseln; ++l) { { ke[4*(k+nseln) + 3][4*l ] += -dt*w[j]*wn*Hm[k]*as[l].x; ke[4*(k+nseln) + 3][4*l+1] += -dt*w[j]*wn*Hm[k]*as[l].y; ke[4*(k+nseln) + 3][4*l+2] += -dt*w[j]*wn*Hm[k]*as[l].z; } } } else { // symmetric for (k=0; k<nseln; ++k) for (l=0; l<nseln; ++l) { { ke[4*k + 3][4*l ] += dt*w[j]*wn*0.5*(Hs[k]*as[l].x+Hs[l]*as[k].x); ke[4*k + 3][4*l+1] += dt*w[j]*wn*0.5*(Hs[k]*as[l].y+Hs[l]*as[k].y); ke[4*k + 3][4*l+2] += dt*w[j]*wn*0.5*(Hs[k]*as[l].z+Hs[l]*as[k].z); } } for (k=0; k<nmeln; ++k) for (l=0; l<nseln; ++l) { { ke[4*(k+nseln) + 3][4*l ] += -dt*w[j]*wn*0.5*Hm[k]*as[l].x; ke[4*(k+nseln) + 3][4*l+1] += -dt*w[j]*wn*0.5*Hm[k]*as[l].y; ke[4*(k+nseln) + 3][4*l+2] += -dt*w[j]*wn*0.5*Hm[k]*as[l].z; } } for (k=0; k<nseln; ++k) for (l=0; l<nmeln; ++l) { { ke[4*k + 3][4*(nseln+l) ] += -dt*w[j]*wn*0.5*Hm[l]*as[k].x; ke[4*k + 3][4*(nseln+l)+1] += -dt*w[j]*wn*0.5*Hm[l]*as[k].y; ke[4*k + 3][4*(nseln+l)+2] += -dt*w[j]*wn*0.5*Hm[l]*as[k].z; } } } // --- P R E S S U R E - P R E S S U R E C O N T A C T --- for (k=0; k<nseln; ++k) { for (l=0; l<nseln; ++l) ke[4*k + 3][4*l+3] += -dt*epsp*w[j]*detJ[j]*Hs[k]*Hs[l]; for (l=0; l<nmeln; ++l) ke[4*k + 3][4*(nseln+l)+3] += dt*epsp*w[j]*detJ[j]*Hs[k]*Hm[l]; } for (k=0; k<nmeln; ++k) { for (l=0; l<nseln; ++l) ke[4*(nseln+k)+3][4*l + 3] += dt*epsp*w[j]*detJ[j]*Hm[k]*Hs[l]; for (l=0; l<nmeln; ++l) ke[4*(nseln+k)+3][4*(nseln+l) + 3] += -dt*epsp*w[j]*detJ[j]*Hm[k]*Hm[l]; } } // assemble the global stiffness ke.SetNodes(en); ke.SetIndices(LM); LS.Assemble(ke); } } } } } //----------------------------------------------------------------------------- bool FETiedBiphasicInterface::Augment(int naug, const FETimeInfo& tp) { // make sure we need to augment if (m_laugon != FECore::AUGLAG_METHOD) return true; int i; vec3d Ln; double Lp; bool bconv = true; bool bporo = (m_ss.m_bporo && m_ms.m_bporo); 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; for (int i=0; i<NS; ++i) { FESurfaceElement& el = m_ss.Element(i); for (int j=0; j<el.GaussPoints(); ++j) { FETiedBiphasicContactPoint& ds = static_cast<FETiedBiphasicContactPoint&>(*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) { FETiedBiphasicContactPoint& dm = static_cast<FETiedBiphasicContactPoint&>(*el.GetMaterialPoint(j)); normL0 += dm.m_Lmd*dm.m_Lmd; } } // b. gap component // (is calculated during update) double maxgap = 0; double maxpg = 0; // update Lagrange multipliers double normL1 = 0, eps, epsp; for (int i = 0; i<NS; ++i) { FESurfaceElement& el = m_ss.Element(i); for (int j = 0; j<el.GaussPoints(); ++j) { FETiedBiphasicContactPoint& ds = static_cast<FETiedBiphasicContactPoint&>(*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; 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; } ds.m_Lmp = Lp; } maxgap = max(maxgap,sqrt(ds.m_dg*ds.m_dg)); } } for (i=0; i<NM; ++i) { FESurfaceElement& el = m_ms.Element(i); for (int j = 0; j<el.GaussPoints(); ++j) { FETiedBiphasicContactPoint& dm = static_cast<FETiedBiphasicContactPoint&>(*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; 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; } dm.m_Lmp = Lp; } 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; // calculate relative norms double lnorm = (normL1 != 0 ? fabs((normL1 - normL0) / normL1) : fabs(normL1 - normL0)); double pnorm = (normP != 0 ? (normDP/normP) : normDP); // check convergence if ((m_gtol > 0) && (maxgap > m_gtol)) bconv = false; if ((m_ptol > 0) && (bporo && maxpg > m_ptol)) bconv = false; if ((m_atol > 0) && (lnorm > m_atol)) bconv = false; if ((m_atol > 0) && (pnorm > m_atol)) bconv = false; if (naug < m_naugmin ) bconv = false; if (naug >= m_naugmax) bconv = true; feLog(" tied biphasic 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"); } 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"); } return bconv; } //----------------------------------------------------------------------------- void FETiedBiphasicInterface::Serialize(DumpStream &ar) { // store contact data FEContactInterface::Serialize(ar); // store contact surface data m_ms.Serialize(ar); m_ss.Serialize(ar); // serialize pointers SerializeElementPointers(m_ss, m_ms, ar); SerializeElementPointers(m_ms, m_ss, ar); }
C++
3D
febiosoftware/FEBio
FEBioMix/FESupplyMichaelisMenten.h
.h
2,641
73
/*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 // Michaelis-Menten kinetics class FEBIOMIX_API FESupplyMichaelisMenten : public FESoluteSupply { public: //! constructor FESupplyMichaelisMenten(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_Vmax; //!< maximum uptake rate double m_Km; //!< concentration at which half-maximum rate occurs // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEOsmCoefManning.h
.h
3,088
78
/*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 "FEOsmoticCoefficient.h" #include <FECore/FEFunction1D.h> //----------------------------------------------------------------------------- // This class implements a material that has an osmotic coefficient behaving // according to the Wells-Manning theory. The Wells correction is provided // by a loadcurve. class FEBIOMIX_API FEOsmCoefManning : public FEOsmoticCoefficient { public: //! constructor FEOsmCoefManning(FEModel* pfem); //! destructor ~FEOsmCoefManning() {} //! Initialization bool Init() override; //! 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; //! Manning response double OsmoticCoefficient_Manning(FEMaterialPoint& pt); double Tangent_OsmoticCoefficient_Strain_Manning(FEMaterialPoint& mp); double Tangent_OsmoticCoefficient_Concentration_Manning(FEMaterialPoint& mp, const int isol); //! Wells response double OsmoticCoefficient_Wells(FEMaterialPoint& pt); double Tangent_OsmoticCoefficient_Strain_Wells(FEMaterialPoint& mp); double Tangent_OsmoticCoefficient_Concentration_Wells(FEMaterialPoint& mp, const int isol); public: double m_ksi; //!< Manning parameter int m_sol; //!< global id of co-ion int m_lsol; //!< local id of co-ion FEFunction1D* m_osmc; //!< osmotic coefficient for Wells correction (mobile ion - mobile interaction) // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEDiffConstOrtho.cpp
.cpp
4,600
123
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEDiffConstOrtho.h" #include <FECore/log.h> // define the material parameters BEGIN_FECORE_CLASS(FEDiffConstOrtho, FESoluteDiffusivity) ADD_PARAMETER(m_free_diff, FE_RANGE_GREATER(0.0) , "free_diff")->setUnits(UNIT_DIFFUSIVITY)->setLongName("free diffusivity"); ADD_PARAMETER(m_diff , 3, FE_RANGE_GREATER_OR_EQUAL(0.0), "diff" )->setUnits(UNIT_DIFFUSIVITY)->setLongName("diffusivity"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEDiffConstOrtho::FEDiffConstOrtho(FEModel* pfem) : FESoluteDiffusivity(pfem) { m_free_diff = 1; m_diff[0] = 1; m_diff[1] = 1; m_diff[2] = 1; } //----------------------------------------------------------------------------- //! Initialization. bool FEDiffConstOrtho::Validate() { if (FESoluteDiffusivity::Validate() == false) return false; FEMesh& mesh = GetMesh(); for (int i=0; i<mesh.Elements(); ++i) { FEElement& elem = *mesh.Element(i); for (int n=0; n<elem.GaussPoints(); ++n) { FEMaterialPoint& mp = *elem.GetMaterialPoint(n); if (m_free_diff(mp) < m_diff[0](mp)) { feLogError("free_diff must be >= diff1 in element %i", elem.GetID()); return false; } if (m_free_diff(mp) < m_diff[1](mp)) { feLogError("free_diff must be >= diff2 in element %i", elem.GetID()); return false; } if (m_free_diff(mp) < m_diff[2](mp)) { feLogError("free_diff must be >= diff3 in element %i", elem.GetID()); return false; } } } return true; } //----------------------------------------------------------------------------- //! Free diffusivity double FEDiffConstOrtho::Free_Diffusivity(FEMaterialPoint& mp) { return m_free_diff(mp); } //----------------------------------------------------------------------------- //! Tangent of free diffusivity with respect to concentration double FEDiffConstOrtho::Tangent_Free_Diffusivity_Concentration(FEMaterialPoint& mp, const int isol) { return 0; } //----------------------------------------------------------------------------- //! Diffusivity tensor mat3ds FEDiffConstOrtho::Diffusivity(FEMaterialPoint& mp) { vec3d a0; // texture direction in reference configuration mat3ds d(0,0,0,0,0,0); // diffusion tensor FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // get the local coordinate systems mat3d Q = GetLocalCS(mp); // --- constant orthotropic diffusivity --- for (int i=0; i<3; i++) { // Perform sum over all three texture directions // Copy the texture direction in the reference configuration to a0 a0.x = Q[0][i]; a0.y = Q[1][i]; a0.z = Q[2][i]; // Evaluate the texture tensor in the current configuration d += dyad(a0)*m_diff[i](mp); } return d; } //----------------------------------------------------------------------------- //! Tangent of diffusivity with respect to strain tens4dmm FEDiffConstOrtho::Tangent_Diffusivity_Strain(FEMaterialPoint &mp) { tens4dmm D; D.zero(); return D; } //----------------------------------------------------------------------------- //! Tangent of diffusivity with respect to concentration mat3ds FEDiffConstOrtho::Tangent_Diffusivity_Concentration(FEMaterialPoint &mp, const int isol) { mat3ds d; d.zero(); return d; }
C++
3D
febiosoftware/FEBio
FEBioMix/FETriphasicDomain.cpp
.cpp
47,136
1,303
/*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 "FETriphasicDomain.h" #include "FECore/FEModel.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 //----------------------------------------------------------------------------- FETriphasicDomain::FETriphasicDomain(FEModel* pfem) : FESolidDomain(pfem), FEElasticDomain(pfem), m_dofU(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_dofR.AddVariable(FEBioMech::GetVariableName(FEBioMech::RIGID_ROTATION)); m_dofP = pfem->GetDOFIndex("p"); m_dofC = pfem->GetDOFIndex("concentration", 0); } } //----------------------------------------------------------------------------- //! get the material (overridden from FEDomain) FEMaterial* FETriphasicDomain::GetMaterial() { return m_pMat; } //----------------------------------------------------------------------------- //! get the total dof const FEDofList& FETriphasicDomain::GetDOFList() const { return m_dof; } //----------------------------------------------------------------------------- void FETriphasicDomain::SetMaterial(FEMaterial* pmat) { FEDomain::SetMaterial(pmat); m_pMat = dynamic_cast<FETriphasic*>(pmat); assert(m_pMat); } //----------------------------------------------------------------------------- //! Unpack the element LM data. void FETriphasicDomain::UnpackLM(FEElement& el, vector<int>& lm) { int dofc0 = m_dofC + m_pMat->m_pSolute[0]->GetSoluteDOF(); int dofc1 = m_dofC + m_pMat->m_pSolute[1]->GetSoluteDOF(); int N = el.Nodes(); lm.resize(N*9); 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[6*i ] = id[m_dofU[0]]; lm[6*i+1] = id[m_dofU[1]]; lm[6*i+2] = id[m_dofU[2]]; // now the pressure dofs lm[6*i+3] = id[m_dofP]; // concentration dofs lm[6*i + 4] = id[dofc0]; lm[6*i + 5] = id[dofc1]; // rigid rotational dofs // TODO: Do I really need these? lm[6*N + 3*i ] = id[m_dofR[0]]; lm[6*N + 3*i+1] = id[m_dofR[1]]; lm[6*N + 3*i+2] = id[m_dofR[2]]; } } //----------------------------------------------------------------------------- void FETriphasicDomain::Activate() { int dofc0 = m_dofC + m_pMat->m_pSolute[0]->GetSoluteDOF(); int dofc1 = m_dofC + m_pMat->m_pSolute[1]->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]); } node.set_active(m_dofP); node.set_active(dofc0 ); node.set_active(dofc1 ); } } // get the triphasic material FETriphasic* pmb = m_pMat; const int nsol = 2; const int nsbm = 0; const int NE = FEElement::MAX_NODES; double p0[NE]; vector< vector<double> > c0(nsol, vector<double>(NE)); FEMesh& m = *GetMesh(); int id[2] = { m_pMat->m_pSolute[0]->GetSoluteID() - 1, m_pMat->m_pSolute[1]->GetSoluteID() - 1 }; 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) { p0[i] = m.Node(el.m_node[i]).get(m_dofP); for (int isol = 0; isol<nsol; ++isol) c0[isol][i] = m.Node(el.m_node[i]).get(m_dofC + id[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 referential solid volume fraction pt.m_phi0t = pmb->m_phi0(mp); // 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 = pmb->FluidFlux(mp); // 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); } ps.m_psi = pmb->ElectricPotential(mp); for (int isol = 0; isol<nsol; ++isol) { ps.m_ca[isol] = pmb->Concentration(mp, isol); ps.m_j[isol] = pmb->SoluteFlux(mp, isol); ps.m_crp[isol] = pm.m_J*m_pMat->Porosity(mp)*ps.m_ca[isol]; } pt.m_pa = pmb->Pressure(mp); ps.m_cF = pmb->FixedChargeDensity(mp); ps.m_Ie = pmb->CurrentDensity(mp); pm.m_s = pmb->Stress(mp); } } } //----------------------------------------------------------------------------- void FETriphasicDomain::Reset() { // reset base class FESolidDomain::Reset(); // get the multiphasic material FETriphasic* pmb = m_pMat; const int nsol = 2; const int nsbm = 0; // 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 = pmb->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; }); } //----------------------------------------------------------------------------- void FETriphasicDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { FESolidDomain::PreSolveUpdate(timeInfo); const int NE = FEElement::MAX_NODES; vec3d x0[NE], xt[NE], r0, rt; double pn[NE], p; 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; pn[i] = m.Node(el.m_node[i]).get(m_dofP); } 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); FEMaterialPoint& mp = *el.GetMaterialPoint(j); FEElasticMaterialPoint& pe = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); FESolutesMaterialPoint& ps = *(mp.ExtractData<FESolutesMaterialPoint>()); mp.m_r0 = r0; mp.m_rt = rt; pe.m_J = defgrad(el, pe.m_F, j); // reset referential solid volume fraction at previous time pt.m_phi0p = pt.m_phi0t; // reset determinant of solid deformation gradient at previous time pt.m_Jp = pe.m_J; pt.m_p = p; pt.m_gradp = gradient(el, pn, j); // reset referential actual solute concentration at previous time for (int j=0; j<2; ++j) { ps.m_crp[j] = pe.m_J*m_pMat->Porosity(mp)*ps.m_ca[j]; } mp.Update(timeInfo); } } } //----------------------------------------------------------------------------- void FETriphasicDomain::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 = 6*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 FETriphasicDomain::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 = *(el.GetMaterialPoint(n)->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; // get the solute flux vec3d j[2] = {spt.m_j[0],spt.m_j[1]}; // get the charge number int z[2] = {m_pMat->m_pSolute[0]->ChargeNumber(), m_pMat->m_pSolute[1]->ChargeNumber()}; vec3d je = j[0]*z[0] + j[1]*z[1]; // evaluate the porosity, its derivative w.r.t. J, and its gradient double phiw = m_pMat->Porosity(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[6*i ] -= fu.x*detJt; fe[6*i+1] -= fu.y*detJt; fe[6*i+2] -= fu.z*detJt; fe[6*i+3] -= dt*(w*gradN - divv*H[i])*detJt; fe[6*i+4] -= dt*(gradN*(j[0]+je*m_pMat->m_penalty) - H[i]*((phiw*spt.m_ca[0] - spt.m_crp[0]/J)/dt) )*detJt; fe[6*i+5] -= dt*(gradN*(j[1]+je*m_pMat->m_penalty) - H[i]*((phiw*spt.m_ca[1] - spt.m_crp[1]/J)/dt) )*detJt; } } } //----------------------------------------------------------------------------- void FETriphasicDomain::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 = 6*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 (steady-state) void FETriphasicDomain::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 = *(el.GetMaterialPoint(n)->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; // get the solute flux vec3d j[2] = {spt.m_j[0],spt.m_j[1]}; // get the charge number int z[2] = {m_pMat->m_pSolute[0]->ChargeNumber(), m_pMat->m_pSolute[1]->ChargeNumber()}; vec3d je = j[0]*z[0] + j[1]*z[1]; 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[6*i ] -= fu.x*detJt; fe[6*i+1] -= fu.y*detJt; fe[6*i+2] -= fu.z*detJt; fe[6*i+3] -= dt*(w*gradN)*detJt; fe[6*i+4] -= dt*(gradN*(j[0]+je*m_pMat->m_penalty))*detJt; fe[6*i+5] -= dt*(gradN*(j[1]+je*m_pMat->m_penalty))*detJt; } } } //----------------------------------------------------------------------------- void FETriphasicDomain::StiffnessMatrix(FELinearSystem& LS, bool bsymm) { // repeat over all solid elements size_t NE = m_Elem.size(); #pragma omp parallel for shared(NE) for (int iel=0; iel<NE; ++iel) { FESolidElement& el = m_Elem[iel]; // element stiffness matrix FEElementMatrix ke(el); // get the lm vector vector<int> lm; UnpackLM(el, lm); ke.SetIndices(lm); // allocate stiffness matrix int neln = el.Nodes(); int ndpn = 6; int ndof = neln*ndpn; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementTriphasicStiffness(el, ke, bsymm); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- void FETriphasicDomain::StiffnessMatrixSS(FELinearSystem& LS, bool bsymm) { // repeat over all solid elements size_t NE = m_Elem.size(); #pragma omp parallel for shared(NE) 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 ndpn = 6; int ndof = neln*ndpn; ke.resize(ndof, ndof); // calculate the element stiffness matrix ElementTriphasicStiffnessSS(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 FETriphasicDomain::ElementTriphasicStiffness(FESolidElement& el, matrix& ke, bool bsymm) { int i, j, isol, jsol, 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; FETriphasic* pm = m_pMat; const int nsol = 2; int ndpn = 4+nsol; // 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> kappa(spt.m_k); // get the charge number for (isol=0; isol<nsol; ++isol) z[isol] = pm->m_pSolute[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 = pm->Porosity(mp); double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the osmotic coefficient double osmc = pm->m_pOsmC->OsmoticCoefficient(mp); // evaluate the permeability mat3ds K = pm->m_pPerm->Permeability(mp); tens4dmm dKdE = pm->m_pPerm->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); for (isol=0; isol<nsol; ++isol) { // evaluate the permeability derivatives dKdc[isol] = pm->m_pPerm->Tangent_Permeability_Concentration(mp,isol); // evaluate the diffusivity tensor and its derivatives D[isol] = pm->m_pSolute[isol]->m_pDiff->Diffusivity(mp); dDdE[isol] = pm->m_pSolute[isol]->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity D0[isol] = pm->m_pSolute[isol]->m_pDiff->Free_Diffusivity(mp); // evaluate the derivative of the osmotic coefficient dodc[isol] = pm->m_pOsmC->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] = pm->m_pSolute[isol]->m_pDiff->Tangent_Diffusivity_Concentration(mp,jsol); dD0dc[isol][jsol] = pm->m_pSolute[isol]->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,jsol); } } // Miscellaneous constants double R = pm->m_Rgas; double T = pm->m_Tabs; double penalty = pm->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),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)); 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[6*i ][6*j ] += Kuu[0][0]; ke[6*i ][6*j+1] += Kuu[0][1]; ke[6*i ][6*j+2] += Kuu[0][2]; ke[6*i+1][6*j ] += Kuu[1][0]; ke[6*i+1][6*j+1] += Kuu[1][1]; ke[6*i+1][6*j+2] += Kuu[1][2]; ke[6*i+2][6*j ] += Kuu[2][0]; ke[6*i+2][6*j+1] += Kuu[2][1]; ke[6*i+2][6*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 = -gradN[j]*(1.0/dt); 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] += (- 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]); qcu[isol] = qpu*(c[isol]*(kappa[isol]+J*phiw*dkdJ[isol])); } for (isol=0; isol<nsol; ++isol) { // calculate the kcu matrix vtmp = ((ju[isol]+jue*penalty).transpose()*gradN[i] + qcu[isol]*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 (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])*(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]); 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]; } } // 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]*(qcc[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 FETriphasicDomain::ElementTriphasicStiffnessSS(FESolidElement& el, matrix& ke, bool bsymm) { int i, j, isol, jsol, 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; FETriphasic* pm = m_pMat; const int nsol = 2; int ndpn = 4+nsol; // 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> kappa(spt.m_k); // get the charge number for (isol=0; isol<nsol; ++isol) z[isol] = pm->m_pSolute[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 = pm->Porosity(mp); double phis = 1. - phiw; double dpdJ = phis/J; // evaluate the osmotic coefficient double osmc = pm->m_pOsmC->OsmoticCoefficient(mp); // evaluate the permeability mat3ds K = pm->m_pPerm->Permeability(mp); tens4dmm dKdE = pm->m_pPerm->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); for (isol=0; isol<nsol; ++isol) { // evaluate the permeability derivatives dKdc[isol] = pm->m_pPerm->Tangent_Permeability_Concentration(mp,isol); // evaluate the diffusivity tensor and its derivatives D[isol] = pm->m_pSolute[isol]->m_pDiff->Diffusivity(mp); dDdE[isol] = pm->m_pSolute[isol]->m_pDiff->Tangent_Diffusivity_Strain(mp); // evaluate the solute free diffusivity D0[isol] = pm->m_pSolute[isol]->m_pDiff->Free_Diffusivity(mp); // evaluate the derivative of the osmotic coefficient dodc[isol] = pm->m_pOsmC->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] = pm->m_pSolute[isol]->m_pDiff->Tangent_Diffusivity_Concentration(mp,jsol); dD0dc[isol][jsol] = pm->m_pSolute[isol]->m_pDiff->Tangent_Free_Diffusivity_Concentration(mp,jsol); } } // Miscellaneous constants double R = pm->m_Rgas; double T = pm->m_Tabs; double penalty = pm->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; 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); 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[6*i ][6*j ] += Kuu[0][0]; ke[6*i ][6*j+1] += Kuu[0][1]; ke[6*i ][6*j+2] += Kuu[0][2]; ke[6*i+1][6*j ] += Kuu[1][0]; ke[6*i+1][6*j+1] += Kuu[1][1]; ke[6*i+1][6*j+2] += Kuu[1][2]; ke[6*i+2][6*j ] += Kuu[2][0]; ke[6*i+2][6*j+1] += Kuu[2][1]; ke[6*i+2][6*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]); } vtmp = (wu.transpose()*gradN[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] += (- 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] + qcu[isol]*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 (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])*(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]; } } // 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))*(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 FETriphasicDomain::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 we encountered an error, throw an exception if (berr) throw NegativeJacobianDetected(); } //----------------------------------------------------------------------------- void FETriphasicDomain::UpdateElementStress(int iel) { // 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 biphasic-solute material int id0 = m_dofC + m_pMat->m_pSolute[0]->GetSoluteDOF(); int id1 = m_dofC + m_pMat->m_pSolute[1]->GetSoluteDOF(); // get the nodal data FEMesh& mesh = *m_pMesh; vec3d r0[FEElement::MAX_NODES]; vec3d rt[FEElement::MAX_NODES]; double pn[FEElement::MAX_NODES], ct[2][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); ct[0][j] = mesh.Node(el.m_node[j]).get(id0); ct[1][j] = mesh.Node(el.m_node[j]).get(id1); } // 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); // 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[0], n); spt.m_c[1] = el.Evaluate(ct[1], n); // calculate the gradient of c at gauss-point spt.m_gradc[0] = gradient(el, ct[0], n); spt.m_gradc[1] = gradient(el, ct[1], 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); spt.m_psi = m_pMat->ElectricPotential(mp); spt.m_ca[0] = m_pMat->Concentration(mp,0); spt.m_ca[1] = m_pMat->Concentration(mp,1); ppt.m_pa = m_pMat->Pressure(mp); spt.m_j[0] = m_pMat->SoluteFlux(mp,0); spt.m_j[1] = m_pMat->SoluteFlux(mp,1); spt.m_cF = m_pMat->FixedChargeDensity(mp); spt.m_Ie = m_pMat->CurrentDensity(mp); m_pMat->PartitionCoefficientFunctions(mp, spt.m_k, spt.m_dkdJ, spt.m_dkdc); // 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); pt.m_s = m_pMat->Stress(mp); } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEDiffConstIso.cpp
.cpp
3,791
107
/*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 "FEDiffConstIso.h" #include <FECore/log.h> #include <FECore/FEMesh.h> // define the material parameters BEGIN_FECORE_CLASS(FEDiffConstIso, FESoluteDiffusivity) ADD_PARAMETER(m_free_diff, FE_RANGE_GREATER_OR_EQUAL(0.0), "free_diff")->setUnits(UNIT_DIFFUSIVITY)->setLongName("free diffusivity"); ADD_PARAMETER(m_diff , FE_RANGE_GREATER_OR_EQUAL(0.0), "diff" )->setUnits(UNIT_DIFFUSIVITY)->setLongName("diffusivity"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEDiffConstIso::FEDiffConstIso(FEModel* pfem) : FESoluteDiffusivity(pfem) { m_free_diff = 1; m_diff = 1; } //----------------------------------------------------------------------------- //! Validation bool FEDiffConstIso::Validate() { if (FESoluteDiffusivity::Validate() == false) return false; FEMesh& mesh = GetMesh(); for (int i=0; i<mesh.Elements(); ++i) { FEElement& elem = *mesh.Element(i); for (int n=0; n<elem.GaussPoints(); ++n) { FEMaterialPoint& mp = *elem.GetMaterialPoint(n); if (m_free_diff(mp) < m_diff(mp)) { feLogError("free_diff must be >= diff in element %i", elem.GetID()); return false; } } } return true; } //----------------------------------------------------------------------------- //! Free diffusivity double FEDiffConstIso::Free_Diffusivity(FEMaterialPoint& mp) { return m_free_diff(mp); } //----------------------------------------------------------------------------- //! Tangent of free diffusivity with respect to concentration double FEDiffConstIso::Tangent_Free_Diffusivity_Concentration(FEMaterialPoint& mp, const int isol) { return 0; } //----------------------------------------------------------------------------- //! Diffusivity tensor mat3ds FEDiffConstIso::Diffusivity(FEMaterialPoint& mp) { // --- constant isotropic diffusivity --- return mat3dd(m_diff(mp)); } //----------------------------------------------------------------------------- //! Tangent of diffusivity with respect to strain tens4dmm FEDiffConstIso::Tangent_Diffusivity_Strain(FEMaterialPoint &mp) { tens4dmm D; D.zero(); return D; } //----------------------------------------------------------------------------- //! Tangent of diffusivity with respect to concentration mat3ds FEDiffConstIso::Tangent_Diffusivity_Concentration(FEMaterialPoint &mp, const int isol) { mat3ds d; d.zero(); return d; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMembraneMassActionReversible.cpp
.cpp
10,517
292
/*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 "FEMembraneMassActionReversible.h" #include "FESoluteInterface.h" BEGIN_FECORE_CLASS(FEMembraneMassActionReversible, FEMembraneReaction) // set material properties ADD_PROPERTY(m_pFwd, "forward_rate", FEProperty::Optional); ADD_PROPERTY(m_pRev, "reverse_rate", FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMembraneMassActionReversible::FEMembraneMassActionReversible(FEModel* pfem) : FEMembraneReaction(pfem) { } //----------------------------------------------------------------------------- //! molar supply at material point double FEMembraneMassActionReversible::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 const 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->SBMArealConcentration(pt, i); zhat *= pow(c, vR); } } // add contribution from internal and external solutes const int nse = (int) m_psm->SolutesExternal(pt); for (int i=0; i<nse; ++i) { int vRe = m_vRe[m_psm->GetSoluteIDExternal(pt,i)]; if (vRe > 0) { // evaluate nodal effective concentrations double c = m_psm->GetEffectiveSoluteConcentrationExternal(pt,i); zhat *= pow(c, vRe); } } const int nsi = (int) m_psm->SolutesInternal(pt); for (int i=0; i<nsi; ++i) { int vRi = m_vRi[m_psm->GetSoluteIDInternal(pt,i)]; if (vRi > 0) { // evaluate nodal effective concentrations double c = m_psm->GetEffectiveSoluteConcentrationInternal(pt,i); zhat *= pow(c, vRi); } } return zhat; } //----------------------------------------------------------------------------- //! molar supply at material point double FEMembraneMassActionReversible::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 const int nsol = (int) 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 = (int) m_psm->SBMs(); for (int i=0; i<nsbm; ++i) { int vP = m_vP[nsol+i]; if (vP > 0) { double c = m_psm->SBMArealConcentration(pt, i); zhat *= pow(c, vP); } } // add contribution from internal and external solutes const int nse = (int) m_psm->SolutesExternal(pt); for (int i=0; i<nse; ++i) { int vPe = m_vPe[m_psm->GetSoluteIDExternal(pt,i)]; if (vPe > 0) { // evaluate nodal effective concentrations double c = m_psm->GetEffectiveSoluteConcentrationExternal(pt,i); zhat *= pow(c, vPe); } } const int nsi = (int) m_psm->SolutesInternal(pt); for (int i=0; i<nsi; ++i) { int vPi = m_vPi[m_psm->GetSoluteIDInternal(pt,i)]; if (vPi > 0) { // evaluate nodal effective concentrations double c = m_psm->GetEffectiveSoluteConcentrationInternal(pt,i); zhat *= pow(c, vPi); } } return zhat; } //----------------------------------------------------------------------------- //! molar supply at material point double FEMembraneMassActionReversible::ReactionSupply(FEMaterialPoint& pt) { double zhatF = FwdReactionSupply(pt); double zhatR = RevReactionSupply(pt); return zhatF - zhatR; } //----------------------------------------------------------------------------- //! tangent of molar supply with strain at material point double FEMembraneMassActionReversible::Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) { // forward reaction double kF = m_pFwd->ReactionRate(pt); double dkFde = m_pFwd->Tangent_ReactionRate_Strain(pt); double zhatF = FwdReactionSupply(pt); double dzhatFde = 0; if (kF > 0) dzhatFde = dkFde*(zhatF/kF); // reverse reaction double kR = m_pRev->ReactionRate(pt); double dkRde = m_pRev->Tangent_ReactionRate_Strain(pt); double zhatR = RevReactionSupply(pt); double dzhatRde = 0; if (kR > 0) dzhatRde = dkRde*(zhatR/kR); return dzhatFde - dzhatRde; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective pressure at material point double FEMembraneMassActionReversible::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 pressure at material point double FEMembraneMassActionReversible::Tangent_ReactionSupply_Pi(FEMaterialPoint& pt) { return 0; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective pressure at material point double FEMembraneMassActionReversible::Tangent_ReactionSupply_Pe(FEMaterialPoint& pt) { return 0; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective concentration at material point double FEMembraneMassActionReversible::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; double c = m_psm->GetActualSoluteConcentration(pt, sol); if ((zhatF > 0) && (c > 0)) dzhatFdc = m_vR[sol]*zhatF/c; // reverse reaction double zhatR = RevReactionSupply(pt); double dzhatRdc = 0; if ((zhatR > 0) && (c > 0)) dzhatRdc = m_vP[sol]*zhatR/c; return dzhatFdc - dzhatRdc; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective concentration at material point double FEMembraneMassActionReversible::Tangent_ReactionSupply_Ci(FEMaterialPoint& pt, const int sol) { // forward reaction double zhatF = FwdReactionSupply(pt); double kF = m_pFwd->ReactionRate(pt); double dkFdci = m_pFwd->Tangent_ReactionRate_Ci(pt, sol); double dzhatFdc = 0; if (kF != 0) dzhatFdc = dkFdci/kF*zhatF; double ci = m_psm->GetEffectiveSoluteConcentrationInternal(pt, sol); int IDi = m_psm->GetSoluteIDInternal(pt, sol); if ((zhatF > 0) && (ci > 0)) dzhatFdc = m_vRi[IDi]*zhatF/ci; // reverse reaction double zhatR = RevReactionSupply(pt); double kR = m_pRev->ReactionRate(pt); double dkRdci = m_pRev->Tangent_ReactionRate_Ci(pt, sol); double dzhatRdc = 0; if (kR != 0) dzhatRdc = dkRdci/kR*zhatR; if ((zhatR > 0) && (ci > 0)) dzhatRdc += m_vPi[IDi]*zhatR/ci; return dzhatFdc - dzhatRdc; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective concentration at material point double FEMembraneMassActionReversible::Tangent_ReactionSupply_Ce(FEMaterialPoint& pt, const int sol) { // forward reaction double zhatF = FwdReactionSupply(pt); double kF = m_pFwd->ReactionRate(pt); double dkFdce = m_pFwd->Tangent_ReactionRate_Ce(pt, sol); double dzhatFdc = 0; if (kF != 0) dzhatFdc = dkFdce/kF*zhatF; double ce = m_psm->GetEffectiveSoluteConcentrationExternal(pt, sol); int IDe = m_psm->GetSoluteIDExternal(pt, sol); if ((zhatF > 0) && (ce > 0)) dzhatFdc = m_vRe[IDe]*zhatF/ce; // reverse reaction double zhatR = RevReactionSupply(pt); double kR = m_pRev->ReactionRate(pt); double dkRdce = m_pRev->Tangent_ReactionRate_Ce(pt, sol); double dzhatRdc = 0; if (kR != 0) dzhatRdc = dkRdce/kR*zhatR; if ((zhatR > 0) && (ce > 0)) dzhatRdc += m_vPe[IDe]*zhatR/ce; return dzhatFdc - dzhatRdc; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateSoluteAsSBM.h
.h
1,930
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 FEReactionRateSoluteAsSBM : public FEReactionRate { public: //! constructor FEReactionRateSoluteAsSBM(FEModel* pfem); //! 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; public: FEParamDouble m_k0; //!< reaction rate constant DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSoluteShellDomain.h
.h
4,319
115
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FEBioMech/FESSIShellDomain.h> #include "FEBiphasicSolute.h" #include "FEBiphasicSoluteDomain.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 FEBiphasicSoluteShellDomain : public FESSIShellDomain, public FEBiphasicSoluteDomain { public: //! constructor FEBiphasicSoluteShellDomain(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(FEShellElement& el, vector<double>& fe); //! element internal force vector (steady-state analyses) void ElementInternalForceSS(FEShellElement& el, vector<double>& fe); //! calculates the element solute-poroelastic stiffness matrix bool ElementBiphasicSoluteStiffness(FEShellElement& el, matrix& ke, bool bsymm); //! calculates the element solute-poroelastic stiffness matrix bool ElementBiphasicSoluteStiffnessSS(FEShellElement& 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_dof; int m_dofSX; int m_dofSY; int m_dofSZ; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPermRefTransIso.cpp
.cpp
6,682
172
/*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 "FEPermRefTransIso.h" #include <FECore/log.h> // define the material parameters BEGIN_FECORE_CLASS(FEPermRefTransIso, FEHydraulicPermeability) ADD_PARAMETER(m_perm0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "perm0")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_perm1T, FE_RANGE_GREATER_OR_EQUAL(0.0), "perm1T")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_perm1A, FE_RANGE_GREATER_OR_EQUAL(0.0), "perm1A")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_perm2T, FE_RANGE_GREATER_OR_EQUAL(0.0), "perm2T")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_perm2A, FE_RANGE_GREATER_OR_EQUAL(0.0), "perm2A")->setUnits(UNIT_PERMEABILITY); ADD_PARAMETER(m_M0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "M0"); ADD_PARAMETER(m_MT , FE_RANGE_GREATER_OR_EQUAL(0.0), "MT"); ADD_PARAMETER(m_MA , FE_RANGE_GREATER_OR_EQUAL(0.0), "MA"); ADD_PARAMETER(m_alpha0, FE_RANGE_GREATER_OR_EQUAL(0.0), "alpha0"); ADD_PARAMETER(m_alphaT, FE_RANGE_GREATER_OR_EQUAL(0.0), "alphaT"); ADD_PARAMETER(m_alphaA, FE_RANGE_GREATER_OR_EQUAL(0.0), "alphaA"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEPermRefTransIso::FEPermRefTransIso(FEModel* pfem) : FEHydraulicPermeability(pfem) { m_perm0 = 1; m_perm1T = m_perm1A = 0; m_perm2T = m_perm2A = 0; m_M0 = m_MT = m_MA = 0; m_alpha0 = m_alphaT = m_alphaA = 0; } //----------------------------------------------------------------------------- //! Permeability tensor. mat3ds FEPermRefTransIso::Permeability(FEMaterialPoint& mp) { vec3d V; // axial material directions in reference configuration mat3ds m; // axial texture tensor in current configuration FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // Identity mat3dd I(1); // deformation gradient mat3d &F = et.m_F; // left cauchy-green matrix mat3ds b = et.LeftCauchyGreen(); // relative volume double J = et.m_J; // referential solid volume fraction double phi0 = pt.m_phi0; double phisr = pt.m_phi0t; // check for potential error if (J <= phisr) feLogError("The perm-ref-trans-iso permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g.",J,phisr); // get the local coordinate systems mat3d Q = GetLocalCS(mp); // Copy the texture direction in the reference configuration to V V.x = Q[0][0]; V.y = Q[1][0]; V.z = Q[2][0]; m = dyad(F*V); // Evaluate texture tensor in the current configuration // --- strain-dependent permeability --- double f, k1T, k1A, k2T, k2A; double k0 = m_perm0*pow((J-phisr)/(1-phi0),m_alpha0)*exp(m_M0*(J*J-1.0)/2.0); // Transverse direction f = pow((J-phisr)/(1-phi0),m_alphaT)*exp(m_MT*(J*J-1.0)/2.0); k1T = m_perm1T/(J*J)*f; k2T = 0.5*m_perm2T/pow(J,4)*f; // Axial direction f = pow((J-phisr)/(1-phi0),m_alphaA)*exp(m_MA*(J*J-1.0)/2.0); k1A = m_perm1A/(J*J)*f; k2A = 0.5*m_perm2A/pow(J,4)*f; // Permeability mat3ds kt = k0*I + k1T*b + (k1A-k1T)*m + 2*k2T*b.sqr() + (m*b).sym()*(2.0*(k2A-k2T)); return kt; } //----------------------------------------------------------------------------- //! Tangent of permeability tens4dmm FEPermRefTransIso::Tangent_Permeability_Strain(FEMaterialPoint &mp) { vec3d V; // axial material directions in reference configuration mat3ds m; // axial texture tensor in current configuration FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint& pt = *mp.ExtractData<FEBiphasicMaterialPoint>(); // Identity mat3dd I(1); // deformation gradient mat3d &F = et.m_F; // left cauchy-green matrix mat3ds b = et.LeftCauchyGreen(); // relative volume double J = et.m_J; // referential solid volume fraction double phi0 = pt.m_phi0; double phisr = pt.m_phi0t; // check for potential error if (J <= phisr) feLogError("The perm-ref-trans-iso permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g.",J,phisr); // get the local coordinate systems mat3d Q = GetLocalCS(mp); // Copy the texture direction in the reference configuration to V V.x = Q[0][0]; V.y = Q[1][0]; V.z = Q[2][0]; m = dyad(F*V); // Evaluate texture tensor in the current configuration double f, k0, K0prime; mat3ds k0hat, k1hat, k2hat; k0 = m_perm0*pow((J-phisr)/(1-phi0),m_alpha0)*exp(m_M0*(J*J-1.0)/2.0); K0prime = (1+J*(m_alpha0/(J-phisr)+m_M0*J))*k0; k0hat = mat3dd(K0prime); tens4dmm K4 = dyad1mm(I,k0hat)-dyad4s(I)*(2*k0); // Transverse direction f = pow((J-phisr)/(1-phi0),m_alphaT)*exp(m_MT*(J*J-1.0)/2.0); double k1T = m_perm1T/(J*J)*f; double k2T = 0.5*m_perm2T/pow(J,4)*f; mat3ds k1hatT = mat3dd((J*J*m_MT+(J*(m_alphaT-1)+phi0)/(J-phisr))*k1T); mat3ds k2hatT = mat3dd((J*J*m_MT+(J*(m_alphaT-3)+3*phi0)/(J-phisr))*k2T); // Axial direction f = pow((J-phisr)/(1-phi0),m_alphaA)*exp(m_MA*(J*J-1.0)/2.0); double k1A = m_perm1A/(J*J)*f; double k2A = 0.5*m_perm2A/pow(J,4)*f; mat3ds k1hatA = mat3dd((J*J*m_MA+(J*(m_alphaA-1)+phi0)/(J-phisr))*k1A); mat3ds k2hatA = mat3dd((J*J*m_MA+(J*(m_alphaA-3)+3*phi0)/(J-phisr))*k2A); // Tangent K4 += dyad1mm(b.sqr(),k2hatT)*2 + dyad4s(b)*(4*k2T) + dyad4s(m,b)*(2*(k2A-k2T)) + dyad1mm(b,k1hatT) + dyad1mm(m,k1hatA-k1hatT) + dyad1mm((m*b).sym()*2.0,k2hatA-k2hatT); return K4; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSoluteDomain.h
.h
3,054
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/FEElasticDomain.h" #include "FEBiphasicSolute.h" //----------------------------------------------------------------------------- class FEModel; class FEGlobalVector; class FEBodyForce; class FESolver; //----------------------------------------------------------------------------- //! Abstract interface class for biphasic-solute 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 FEBiphasicSoluteDomain : public FEElasticDomain { public: FEBiphasicSoluteDomain(FEModel* pfem); virtual ~FEBiphasicSoluteDomain(){} // --- 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; protected: FEBiphasicSolute* m_pMat; int m_dofP; //!< pressure dof index int m_dofQ; //!< shell extra pressure dof index int m_dofC; //!< concentration dof index int m_dofD; //!< shell extra concentration dof index int m_dofVX; int m_dofVY; int m_dofVZ; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEActiveMomentumSupply.cpp
.cpp
1,707
40
/*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 "FEActiveMomentumSupply.h" //----------------------------------------------------------------------------- // Derivative of active momentum supply w.r.t. solute concentration at material point // Set this to zero by default because biphasic problems do not require it vec3d FEActiveMomentumSupply::Tangent_ActiveSupply_Concentration(FEMaterialPoint& pt, const int isol) { return vec3d(0,0,0); }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMembraneReactionRateVoltageGated.h
.h
2,868
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.*/ #pragma once #include "FEMembraneReaction.h" class FEBIOMIX_API FEMembraneReactionRateVoltageGated : public FEMembraneReactionRate { public: //! constructor FEMembraneReactionRateVoltageGated(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 { return 0; } //! 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) int m_lid; //!< local id of solute (zero-based) int m_z; //!< charge number of channel ion double m_a; //!< coefficient double m_b; //!< coefficient double m_c; //!< coefficient double m_d; //!< coefficient DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPressureStabilization.h
.h
2,297
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 <FECore/FESurfaceLoad.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! This pseudo-surface load is used to calculate the pressure stabilization //! time constant based on the properties of elements under that surface //! class FEBIOMIX_API FEPressureStabilization : public FESurfaceLoad { public: //! constructor FEPressureStabilization(FEModel* pfem); //! Set the surface to apply the load to void SetSurface(FESurface* ps) override; //! calculate pressure stiffness void StiffnessMatrix(FELinearSystem& LS) override {} //! calculate residual void LoadVector(FEGlobalVector& R) override {} //! initialize bool Init() override; //! activate void Activate() override; protected: double TimeConstant(FESurfaceElement& el, FESurface& s); protected: bool m_bstab; //!< flag for calculating stabilization constant DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMixtureNormalTraction.h
.h
2,422
69
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FESurfaceLoad.h> #include <FECore/FEModelParam.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! This boundary condition applies a mixture normal traction on a surface //! class FEBIOMIX_API FEMixtureNormalTraction : public FESurfaceLoad { public: //! constructor FEMixtureNormalTraction(FEModel* pfem); bool Init() override; //! Set the surface to apply the load to void SetSurface(FESurface* ps) override; void SetLinear(bool blinear) { m_blinear = blinear; } void SetEffective(bool beff) { m_beffective = beff; } //! calculate pressure stiffness void StiffnessMatrix(FELinearSystem& LS) override; //! calculate residual void LoadVector(FEGlobalVector& R) override; private: double Traction(FESurfaceMaterialPoint& mp); protected: FEParamDouble m_traction; //!< traction value bool m_blinear; //!< linear or not (true is non-follower, false is follower) bool m_bshellb; //!< flag for prescribing traction on shell bottom bool m_beffective; //!< effective or total normal traction DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMatchingOsmoticCoefficientBC.h
.h
2,350
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 <FECore/FEPrescribedBC.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 FEMatchingOsmoticCoefficientBC : public FEPrescribedSurface { public: //! constructor FEMatchingOsmoticCoefficientBC(FEModel* pfem); //! set the dilatation void Update() override; //! activate void Activate() override; //! serialization void Serialize(DumpStream& ar) override; public: void GetNodalValues(int nodelid, std::vector<double>& val) override; void CopyFrom(FEBoundaryCondition* pbc) 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/FEMultiphasicDomain.cpp
.cpp
1,755
45
/*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 "FEMultiphasicDomain.h" #include "FECore/FEModel.h" //----------------------------------------------------------------------------- FEMultiphasicDomain::FEMultiphasicDomain(FEModel* pfem) : FEElasticDomain(pfem) { m_pMat = 0; m_dofP = pfem->GetDOFIndex("p"); m_dofQ = pfem->GetDOFIndex("q"); m_dofC = pfem->GetDOFIndex("concentration", 0); m_dofD = pfem->GetDOFIndex("shell concentration", 0); m_breset = false; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicModule.cpp
.cpp
2,505
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) 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 "FEBiphasicModule.h" #include <FECore/DOFS.h> #include <FECore/FEModel.h> #include "FEBioMix.h" //============================================================================= FEBiphasicModule::FEBiphasicModule() {} void FEBiphasicModule::InitModel(FEModel* fem) { FESolidModule::InitModel(fem); // Allocate degrees of freedom DOFS& dofs = fem->GetDOFS(); int varP = dofs.AddVariable("fluid pressure"); dofs.SetDOFName(varP, 0, "p"); int varQ = dofs.AddVariable("shell fluid pressure"); dofs.SetDOFName(varQ, 0, "q"); } //============================================================================= FEBiphasicSoluteModule::FEBiphasicSoluteModule() {} void FEBiphasicSoluteModule::InitModel(FEModel* fem) { FEBiphasicModule::InitModel(fem); // Allocate degrees of freedom // (We start with zero concentration degrees of freedom) DOFS& dofs = fem->GetDOFS(); int varC = dofs.AddVariable("concentration", VAR_ARRAY); int varD = dofs.AddVariable("shell concentration", VAR_ARRAY); } //============================================================================= FEMultiphasicModule::FEMultiphasicModule() {} void FEMultiphasicModule::InitModel(FEModel* fem) { FEBiphasicSoluteModule::InitModel(fem); }
C++
3D
febiosoftware/FEBio
FEBioMix/FEPermRefTransIso.h
.h
2,759
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 "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 FEPermRefTransIso : public FEHydraulicPermeability { public: //! constructor FEPermRefTransIso(FEModel* pfem); //! permeability mat3ds Permeability(FEMaterialPoint& pt) override; //! Tangent of permeability tens4dmm Tangent_Permeability_Strain(FEMaterialPoint& mp) override; public: double m_perm0; //!< permeability for I term double m_perm1T; //!< transverse permeability for b term double m_perm1A; //!< axial permeability for b term double m_perm2T; //!< transverse permeability for b^2 term double m_perm2A; //!< axial permeability for b^2 term double m_M0; //!< nonlinear exponential coefficient for I term double m_MT; //!< nonlinear exponential coefficient for transverse direction double m_MA; //!< nonlinear exponential coefficient for axial direction double m_alpha0; //!< nonlinear power exponent for I term double m_alphaT; //!< nonlinear power exponent for transverse direction double m_alphaA; //!< nonlinear power exponent for axial direction // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEFluidFlux.cpp
.cpp
6,224
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 "FEFluidFlux.h" #include "FECore/FESolver.h" #include "FECore/FEModel.h" #include "FECore/FEAnalysis.h" #include "FEBioMix.h" #include "FEBiphasicAnalysis.h" //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FEFluidFlux, FESurfaceLoad) ADD_PARAMETER(m_flux , "flux" ); ADD_PARAMETER(m_blinear , "linear" ); ADD_PARAMETER(m_bshellb , "shell_bottom"); ADD_PARAMETER(m_bmixture, "mixture"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEFluidFlux::FEFluidFlux(FEModel* pfem) : FESurfaceLoad(pfem), m_dofP(pfem), m_dofU(pfem), m_dofV(pfem) { m_blinear = false; m_bmixture = false; m_bshellb = false; m_flux = 1.0; } //----------------------------------------------------------------------------- void FEFluidFlux::SetSurface(FESurface* ps) { FESurfaceLoad::SetSurface(ps); m_flux.SetItemList(ps->GetFacetSet()); } //----------------------------------------------------------------------------- bool FEFluidFlux::Init() { FEModel* fem = GetFEModel(); // get the degrees of freedom if (m_bshellb == false) { m_dofU.AddDof(fem->GetDOFIndex("x")); m_dofU.AddDof(fem->GetDOFIndex("y")); m_dofU.AddDof(fem->GetDOFIndex("z")); m_dofV.AddDof(fem->GetDOFIndex("vx")); m_dofV.AddDof(fem->GetDOFIndex("vy")); m_dofV.AddDof(fem->GetDOFIndex("vz")); m_dofP.AddDof(fem->GetDOFIndex("p")); } else { m_dofU.AddDof(fem->GetDOFIndex("sx")); m_dofU.AddDof(fem->GetDOFIndex("sy")); m_dofU.AddDof(fem->GetDOFIndex("sz")); m_dofV.AddDof(fem->GetDOFIndex("svx")); m_dofV.AddDof(fem->GetDOFIndex("svy")); m_dofV.AddDof(fem->GetDOFIndex("svz")); m_dofP.AddDof(fem->GetDOFIndex("q")); } return FESurfaceLoad::Init(); } //----------------------------------------------------------------------------- void FEFluidFlux::Serialize(DumpStream& ar) { FESurfaceLoad::Serialize(ar); if (ar.IsShallow() == false) { ar & m_dofU & m_dofV & m_dofP; } } //----------------------------------------------------------------------------- vec3d FEFluidFlux::SolidVelocity(FESurfaceMaterialPoint& pt) { FESurfaceElement& el = *pt.SurfaceElement(); int n = pt.m_index; vec3d vt[FEElement::MAX_NODES]; int neln = el.Nodes(); for (int i = 0; i<neln; ++i) { FENode& nd = m_psurf->GetMesh()->Node(el.m_node[i]); vt[i] = nd.get_vec3d(m_dofV[0], m_dofV[1], m_dofV[2]); } // shape functions at integration point n double* N = el.H(n); // solid velocity at integration point vec3d vr(0, 0, 0); for (int i = 0; i<neln; ++i) { vr += vt[i] * N[i]; } return vr; } //----------------------------------------------------------------------------- void FEFluidFlux::LoadVector(FEGlobalVector& R) { FEModel* fem = GetFEModel(); // only add the mixture term for transient analysis and when the m_bmixture flag is true bool bmixture = m_bmixture; if (fem->GetCurrentStep()->m_nanalysis == FEBiphasicAnalysis::STEADY_STATE) bmixture = false; // get time increment double dt = CurrentTimeIncrement(); // integrate over surface FEFluidFlux* flux = this; m_psurf->LoadVector(R, m_dofP, m_blinear, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, std::vector<double>& fa) { // fluid flux double wr = flux->m_flux(mp); if (flux->m_bshellb) wr = -wr; // surface normal vec3d dxt = mp.dxr ^ mp.dxs; // volumetric flow rate double f = dxt.norm()*wr; // add optional mixture term if (bmixture) { // solid velocity at integration point vec3d vr = flux->SolidVelocity(mp); f -= vr*dxt; } // put it all together double H_p = dof_a.shape; fa[0] = H_p * f * dt; }); } //----------------------------------------------------------------------------- void FEFluidFlux::StiffnessMatrix(FELinearSystem& LS) { FEModel& fem = *GetFEModel(); double dt = CurrentTimeIncrement(); FEFluidFlux* flux = this; bool btransient = (fem.GetCurrentStep()->m_nanalysis != FEBiphasicAnalysis::STEADY_STATE); if (!m_blinear || m_bmixture) { m_psurf->LoadStiffness(LS, m_dofP, m_dofU, [=](FESurfaceMaterialPoint& mp, const FESurfaceDofShape& dof_a, const FESurfaceDofShape& dof_b, matrix& Kab) { // fluid flux double wr = flux->m_flux(mp); if (m_bshellb) wr = -wr; // calculate surface normal vec3d dxt = mp.dxr ^ mp.dxs; // shape functions and derivatives at integration point double N_p = dof_a.shape; double N_u = dof_b.shape; double Gr_u = dof_b.shape_deriv_r; double Gs_u = dof_b.shape_deriv_s; // calculate stiffness component int i = dof_a.index; int j = dof_b.index; vec3d kab(0, 0, 0); if (flux->m_bmixture == false) { vec3d t1 = (dxt / dxt.norm())*wr; vec3d t2 = mp.dxs*Gr_u - mp.dxr*Gs_u; kab = (t1^t2)*dt*N_p; } else if (btransient) { kab = (dxt*N_u)*N_p; } Kab[0][0] += kab.x; Kab[0][1] += kab.y; Kab[0][2] += kab.z; }); } }
C++
3D
febiosoftware/FEBio
FEBioMix/FESolutesMaterialPoint.h
.h
4,548
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 <FECore/FEMaterialPoint.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Class for storing material point data for solute materials class FEBIOMIX_API FESolutesMaterialPoint : public FEMaterialPointData { public: //! Constructor FESolutesMaterialPoint(FEMaterialPointData* ppt); //! Create a shallow copy FEMaterialPointData* Copy(); //! serialize data void Serialize(DumpStream& ar); //! Initialize material point data void Init(); public: double Osmolarity() const; public: // solutes material data int m_nsol; //!< number of solutes std::vector<double> m_c; //!< effective solute concentration std::vector<vec3d> m_gradc; //!< spatial gradient of solute concentration std::vector<vec3d> m_j; //!< solute molar flux std::vector<double> m_ca; //!< actual solute concentration std::vector<double> m_crp; //!< referential actual solute concentration at previous time step double m_psi; //!< electric potential vec3d m_Ie; //!< current density double m_cF; //!< fixed charge density in current configuration int m_nsbm; //!< number of solid-bound molecules double m_rhor; //!< current referential mass density std::vector<double> m_sbmr; //!< referential mass concentration of solid-bound molecules std::vector<double> m_sbmrp; //!< m_sbmr at previoust time step std::vector<double> m_sbmrhat; //!< referential mass supply of solid-bound molecules std::vector<double> m_sbmrhatp; //!< referential mass supply of solid-bound molecules at previous time step std::vector<double> m_sbmrmin; //!< minimum value of m_sbmr std::vector<double> m_sbmrmax; //!< maximum value of m_sbmr std::vector<double> m_k; //!< solute partition coefficient std::vector<double> m_dkdJ; //!< 1st deriv of m_k with strain (J) std::vector<double> m_dkdJJ; //!< 2nd deriv of m_k with strain (J) std::vector< std::vector<double> > m_dkdc; //!< 1st deriv of m_k with effective concentration std::vector< std::vector<double> > m_dkdJc; //!< cross deriv of m_k with J and c std::vector< std::vector< std::vector<double> > > m_dkdcc; // 2nd deriv of m_k with c std::vector< std::vector<double> > m_dkdr; //!< 1st deriv of m_k with m_sbmr std::vector< std::vector<double> > m_dkdJr; //!< cross deriv of m_k with J and m_sbmr std::vector< std::vector< std::vector<double> > > m_dkdrc; //!< cross deriv of m_k with m_sbmr and c std::vector<int> m_cri; //!< optional integer data needed for chemical reactions std::vector<double> m_crd; //!< optional double data needed for chemical reactions double m_strain; //!< areal strain double m_pe; //!< effective fluid pressure on external side double m_pi; //!< effective fluid pressure on internal side std::vector<double> m_ce; //!< effective solute concentration on external side std::vector<double> m_ci; //!< effective solute concentration on internal side std::vector<int> m_ide; //!< solute IDs on external side std::vector<int> m_idi; //!< solute IDs on internal side std::vector<bool> m_bsb; //!< flag indicating that solute is solid-bound };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSoluteAnalysis.cpp
.cpp
1,706
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 "FEBiphasicSoluteAnalysis.h" BEGIN_FECORE_CLASS(FEBiphasicSoluteAnalysis, 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() FEBiphasicSoluteAnalysis::FEBiphasicSoluteAnalysis(FEModel* fem) : FEAnalysis(fem) { }
C++
3D
febiosoftware/FEBio
FEBioMix/FESBMPointSource.cpp
.cpp
12,782
444
/*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 "FESBMPointSource.h" #include "FEMultiphasic.h" #include "FESolute.h" #include <FECore/FEModel.h> #include <FECore/FESolidDomain.h> #include <FECore/FEElemElemList.h> #include <algorithm> #include <FEBioMech/FEElasticMaterialPoint.h> #include <iostream> #include <unordered_set> #include <unordered_map> #include <limits> #include <FECore/FEAnalysis.h> BEGIN_FECORE_CLASS(FESBMPointSource, FEBodyLoad) ADD_PARAMETER(m_sbmId, "sbm"); ADD_PARAMETER(m_rate, "rate"); ADD_PARAMETER(m_pos.x, "x"); ADD_PARAMETER(m_pos.y, "y"); ADD_PARAMETER(m_pos.z, "z"); ADD_PARAMETER(m_weighVolume, "weigh_volume"); END_FECORE_CLASS(); FESBMPointSource::FESBMPointSource(FEModel* fem) : FEBodyLoad(fem), m_search(&fem->GetMesh()) { //static bool bfirst = true; m_sbmId = -1; m_pos = vec3d(0, 0, 0); m_rate = 0.0; //m_reset = bfirst; //m_doReset = true; m_weighVolume = true; //bfirst = false; } vec3d FESBMPointSource::GetPosition() const { return m_pos; } void FESBMPointSource::SetPosition(const vec3d& pos) { m_pos = pos; } int FESBMPointSource::GetSBMID() const { return m_sbmId; } void FESBMPointSource::SetSBMID(int sbmID) { m_sbmId = sbmID; } double FESBMPointSource::GetRate() const { return m_rate; } void FESBMPointSource::SetRate(double rate) { m_rate = rate; } double FESBMPointSource::GetdC() const { return m_dC; } double FESBMPointSource::GetdCp() const { return m_dCp; } void FESBMPointSource::SetdC(double dC) { m_dC = dC; } void FESBMPointSource::SetRadius(double radius) { m_radius = radius; m_Vc = (4.0 / 3.0) * PI * pow(m_radius, 3.0); } void FESBMPointSource::SetAccumulateFlag(bool b) { m_accumulate = b; } //void FESBMPointSource::SetWeighVolume(bool b) //{ // m_weighVolume = b; //} //void FESBMPointSource::SetResetFlag(bool b) //{ // m_doReset = b; //} bool FESBMPointSource::Init() { if (m_sbmId == -1) return false; if (m_search.Init() == false) return false; m_el = dynamic_cast<FESolidElement*>(m_search.FindElement(m_pos, m_q)); return FEBodyLoad::Init(); } // allow species to accumulate at the point source void FESBMPointSource::Accumulate(double dc) { // find the element in which the point lies m_el = dynamic_cast<FESolidElement*>(m_search.FindElement(m_pos, m_q)); if (m_el == nullptr) return; // make sure this element is part of a multiphasic domain FEDomain* dom = dynamic_cast<FEDomain*>(m_el->GetMeshPartition()); FEMultiphasic* mat = dynamic_cast<FEMultiphasic*>(dom->GetMaterial()); if (mat == nullptr) return; // Make sure the material has the correct solute int sbmid = -1; int sbms = mat->SBMs(); for (int j = 0; j < sbms; ++j) { int sbmj = mat->GetSBM(j)->GetSBMID(); if (sbmj == m_sbmId) { sbmid = j; break; } } if (sbmid == -1) return; m_rate = dc + m_rate; m_accumulate = true; } void FESBMPointSource::Update() { //if (m_reset && m_doReset) ResetSBM(); if (m_accumulate) { m_dCp = m_dC; // find the element in which the point lies m_el = dynamic_cast<FESolidElement*>(m_search.FindElement(m_pos, m_q)); if (m_el == nullptr) return; // make sure this element is part of a multiphasic domain FEDomain* dom = dynamic_cast<FEDomain*>(m_el->GetMeshPartition()); FEMultiphasic* mat = dynamic_cast<FEMultiphasic*>(dom->GetMaterial()); if (mat == nullptr) return; // calculate the element volume FEMesh* mesh = dom->GetMesh(); double Ve = mesh->ElementVolume(*m_el); // we prescribe the element average to the integration points const int nint = m_el->GaussPoints(); // Make sure the material has the correct sbm int sbmid = -1; int sbms = mat->SBMs(); for (int j = 0; j < sbms; ++j) { int sbmj = mat->GetSBM(j)->GetSBMID(); if (sbmj == m_sbmId) { sbmid = j; break; } } if (sbmid == -1) return; double m_dt = mesh->GetFEModel()->GetCurrentStep()->m_dt; std::vector<FEMaterialPoint*> possible_ints; double total_elem = 0; FindIntInRadius(possible_ints, total_elem); double total_change = 0.0; // if the cell is not projecting on top of an integration point (i.e. too small) // then project it's concentration to the nodes via the shape functions //SL TODO: Currently assigns just to the current element. Should instead find the ~8 closest integration points // regardless of element. if (possible_ints.size() == 0) { FindNodesInRadius(possible_ints, total_elem); } if (possible_ints.size() == 0) { // set the concentration of all the integration points double H[FEElement::MAX_NODES]; m_el->shape_fnc(H, m_q[0], m_q[1], m_q[2]); for (int i = 0; i < nint; ++i) { double H[FEElement::MAX_NODES]; m_el->shape_fnc(H, m_q[0], m_q[1], m_q[2]); FEMaterialPoint& mp = *m_el->GetMaterialPoint(i); FESolutesMaterialPoint& pd = *(mp.ExtractData<FESolutesMaterialPoint>()); double new_r = H[i] * m_rate * nint / Ve + pd.m_sbmr[sbmid]; pd.m_sbmr[sbmid] = new_r; pd.m_sbmrp[sbmid] = pd.m_sbmr[sbmid]; total_change += m_rate / nint; } } // else evenly distribute it among the integration points that the cell is on top of. //SL TODO: currently may lead to a little bias when neighboring elements are smaller resulting in // higher density of integration points else { int nint_in = possible_ints.size(); for (auto iter = possible_ints.begin(); iter != possible_ints.end(); ++iter) { FEMaterialPoint& mp = **iter; FESolutesMaterialPoint& pd = *(mp.ExtractData<FESolutesMaterialPoint>()); // scale by H so that the total integral over each element is consistent. double H = double(nint) / double(nint_in); double new_r = H * m_rate / Ve + pd.m_sbmr[sbmid]; pd.m_sbmr[sbmid] = new_r; pd.m_sbmrp[sbmid] = pd.m_sbmr[sbmid]; total_change += m_rate / (nint_in); } } m_dC = -total_change / m_Vc; m_accumulate = false; // don't double count a point source } } void FESBMPointSource::FindIntInRadius(std::vector<FEMaterialPoint*> &possible_ints, double &total_elem) { // get element and set up buffers m_el = dynamic_cast<FESolidElement*>(m_search.FindElement(m_pos, m_q)); std::unordered_set<FESolidElement*> visited; std::set<FESolidElement*> next; //std::vector<FEMaterialPoint*> possible_ints; visited.reserve(1000); possible_ints.reserve(500); //we will need to check the current element first next.insert(m_el); // create the element adjacency list. FEDomain* dom = dynamic_cast<FEDomain*>(m_el->GetMeshPartition()); FEMultiphasic* mat = dynamic_cast<FEMultiphasic*>(dom->GetMaterial()); if (mat == nullptr) return; // calculate the element volume auto mesh = dom->GetMesh(); // create the element-element list FEElemElemList EEL; EEL.Create(mesh); //while there are still elements to evaluate while (next.size()) { // get the element to be evaluated FESolidElement* cur = *next.begin(); // remove the current element from the next buffer and add it to the visited buffer next.erase(next.begin()); visited.insert(cur); // get the current element bounds std::vector<vec3d> cur_element_bounds; // add integration points within the radius bool int_flag = false; for (int i = 0; i < cur->GaussPoints(); i++) { FEMaterialPoint* mp = cur->GetMaterialPoint(i); vec3d disp = mp->m_r0 - m_pos; if (disp.norm() <= m_radius) { possible_ints.push_back(mp); int_flag = true; } } if (int_flag) { total_elem++; } // Add neighboring element to the next buffer as long as they haven't been visited. // get the global ID of the current element int cur_id = cur->GetID()-1; // for each neighboring element for (int i = 0; i < EEL.NeighborSize(); i++) { if (EEL.Neighbor(cur_id, i)) { // if that element has not been visited yet add it to the next list if (!visited.count(dynamic_cast<FESolidElement*>(EEL.Neighbor(cur_id, i)))) { next.insert(dynamic_cast<FESolidElement*>(EEL.Neighbor(cur_id, i))); } } } } } void FESBMPointSource::FindNodesInRadius(std::vector<FEMaterialPoint*>& possible_ints, double& total_elem) { // get element and set up buffers m_el = dynamic_cast<FESolidElement*>(m_search.FindElement(m_pos, m_q)); std::unordered_set<FESolidElement*> visited; std::set<FESolidElement*> next; //std::vector<FEMaterialPoint*> possible_ints; visited.reserve(1000); std::vector<FENode*> possible_nodes; possible_nodes.reserve(500); //we will need to check the current element first next.insert(m_el); // create the element adjacency list. FEDomain* dom = dynamic_cast<FEDomain*>(m_el->GetMeshPartition()); FEMultiphasic* mat = dynamic_cast<FEMultiphasic*>(dom->GetMaterial()); if (mat == nullptr) return; // calculate the element volume auto mesh = dom->GetMesh(); // create the element-element list FEElemElemList EEL; EEL.Create(mesh); //while there are still elements to evaluate while (next.size()) { // get the element to be evaluated FESolidElement* cur = *next.begin(); // remove the current element from the next buffer and add it to the visited buffer next.erase(next.begin()); visited.insert(cur); // get the current element bounds std::vector<vec3d> cur_element_bounds; // add integration points within the radius bool int_flag = false; for (int i = 0; i < cur->Nodes(); i++) { FENode* mn = &(mesh->Node(cur->m_node[i])); vec3d disp = mn->m_rt - m_pos; FEMaterialPoint* closest; if (disp.norm() <= m_radius) { // find the closest mp in the element double min_d = std::numeric_limits<double>::max(); for (int j = 0; j < cur->GaussPoints(); j++) { double disp2 = (mn->m_rt - cur->GetMaterialPoint(j)->m_rt).norm(); if (disp2 < min_d) { min_d = disp2; closest = cur->GetMaterialPoint(j); } } possible_ints.push_back(closest); int_flag = true; } } if (int_flag) { total_elem++; } // Add neighboring element to the next buffer as long as they haven't been visited. // get the global ID of the current element int cur_id = cur->GetID() - 1; // for each neighboring element for (int i = 0; i < EEL.NeighborSize(); i++) { if (EEL.Neighbor(cur_id, i)) { // if that element has not been visited yet add it to the next list if (!visited.count(dynamic_cast<FESolidElement*>(EEL.Neighbor(cur_id, i)))) { next.insert(dynamic_cast<FESolidElement*>(EEL.Neighbor(cur_id, i))); } } } } } //void FESBMPointSource::ResetSBM() //{ // FEModel& fem = *GetFEModel(); // FEMesh& mesh = fem.GetMesh(); // // for (int i = 0; i < mesh.Domains(); ++i) // { // FEDomain& dom = mesh.Domain(i); // int NE = dom.Elements(); // // FEMultiphasic* mat = dynamic_cast<FEMultiphasic*>(dom.GetMaterial()); // if (mat) // { // // Make sure the material has the correct sbm // int sbmid = -1; // int sbms = mat->SBMs(); // for (int j = 0; j<sbms; ++j) // { // int sbmj = mat->GetSBM(j)->GetSBMID(); // if (sbmj == m_sbmId) // { // sbmid = j; // break; // } // } // // if (sbmid != -1) // { // for (int j = 0; j < NE; ++j) // { // FEElement& el = dom.ElementRef(j); // // // set the concentration of all the integration points // int nint = el.GaussPoints(); // for (int k = 0; k < nint; ++k) // { // FEMaterialPoint* mp = el.GetMaterialPoint(k); // FESolutesMaterialPoint& pd = *(mp->ExtractData<FESolutesMaterialPoint>()); // pd.m_sbmr[sbmid] = 0.0; // pd.m_sbmrp[sbmid] = 0.0; // } // } // } // } // } //}
C++
3D
febiosoftware/FEBio
FEBioMix/FEPermHolmesMow.cpp
.cpp
4,571
124
/*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 "FEPermHolmesMow.h" #include <FECore/log.h> // define the material parameters BEGIN_FECORE_CLASS(FEPermHolmesMow, FEHydraulicPermeability) ADD_PARAMETER(m_perm , FE_RANGE_GREATER_OR_EQUAL(0.0), "perm" )->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. FEPermHolmesMow::FEPermHolmesMow(FEModel* pfem) : FEHydraulicPermeability(pfem) { m_perm = 1; m_M = m_alpha = 0; } //----------------------------------------------------------------------------- bool FEPermHolmesMow::Init() { // make sure the ancestor implements the biphasic interface FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); if (pbm == nullptr) { feLogError("Parent material needs to be biphasic or multiphasic."); return false; } return FEHydraulicPermeability::Init(); } //----------------------------------------------------------------------------- //! Permeability tensor. mat3ds FEPermHolmesMow::Permeability(FEMaterialPoint& mp) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); // relative volume double J = et.m_J; // referential solid volume fraction also check if bfsi double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); // check for potential error if (J <= phi0) { FEElement* pe = mp.m_elem; int id = (pe ? pe->GetID() : -1); // NOTE: This function can be called from a parallel (omp) section // however, logging should be done in serial. #pragma omp critical feLogError("The Holmes-Mow permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g. (element %d)", J, phi0, id); } // --- strain-dependent isotropic permeability --- double perm = m_perm(mp); return mat3dd(perm*pow((J-phi0)/(1.0-phi0),m_alpha)*exp(m_M*(J*J-1.0)/2.0)); } //----------------------------------------------------------------------------- //! Tangent of permeability tens4dmm FEPermHolmesMow::Tangent_Permeability_Strain(FEMaterialPoint &mp) { FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& et = *mp.ExtractData<FEElasticMaterialPoint>(); // relative volume double J = et.m_J; // referential solid volume fraction double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); // check for potential error if (J <= phi0) { FEElement* pe = mp.m_elem; int id = (pe ? pe->GetID() : -1); // NOTE: This function can be called from a parallel (omp) section // however, logging should be done in serial. #pragma omp critical feLogError("The Holmes-Mow permeability calculation failed!\nThe volume ratio (J=%g) dropped below its theoretical minimum phi0=%g. (element %d)", J, phi0, id); } mat3dd I(1); // Identity double perm = m_perm(mp); double k0 = perm*pow((J-phi0)/(1.0-phi0),m_alpha)*exp(m_M*(J*J-1.0)/2.0); double K0prime = (J*J*m_M+(J*(m_alpha+1)-phi0)/(J-phi0))*k0; mat3ds k0hat = I*K0prime; return dyad1mm(I,k0hat)-dyad4s(I)*(2*k0); }
C++
3D
febiosoftware/FEBio
FEBioMix/FESlidingInterface3.h
.h
6,106
195
/*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 FESlidingSurface3 : public FEBiphasicContactSurface { public: //! constructor FESlidingSurface3(FEModel* pfem); //! destructor ~FESlidingSurface3(); //! initialization bool Init() override; //! 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(); // data serialization 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 GetContactTraction(int nface, vec3d& pt) override; void GetNodalContactPressure(int nface, double* pg) override; void GetNodalContactTraction(int nface, vec3d* tn) override; void EvaluateNodalContactPressures(); private: void GetContactPressure(int nface, double& pg); public: bool m_bporo; //!< set poro-mode bool m_bsolu; //!< set solute-mode vector<bool> m_poro; //!< surface element poro status vector<int> m_solu; //!< surface element solute id vector<vec3d> m_nn; //!< node normals vector<double> m_pn; //!< nodal contact pressures vec3d m_Ft; //!< total contact force (from equivalent nodal forces) protected: int m_dofC; }; //----------------------------------------------------------------------------- class FEBIOMIX_API FESlidingInterface3 : public FEContactInterface { public: //! constructor FESlidingInterface3(FEModel* pfem); //! destructor ~FESlidingInterface3(); //! initialization bool Init() override; //! interface activation void Activate() override; //! 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; 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(FESlidingSurface3& ss, FESlidingSurface3& ms, bool bupseg, bool bmove = false); //! calculate penalty factor void UpdateAutoPenalty(); void CalcAutoPenalty(FESlidingSurface3& s); void CalcAutoPressurePenalty(FESlidingSurface3& s); double AutoPressurePenalty(FESurfaceElement& el, FESlidingSurface3& s); void CalcAutoConcentrationPenalty(FESlidingSurface3& s); double AutoConcentrationPenalty(FESurfaceElement& el, FESlidingSurface3& s); public: FESlidingSurface3 m_ss; //!< primary surface FESlidingSurface3 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 double m_epsn; //!< normal penalty factor bool m_bautopen; //!< use autopenalty factor bool m_bupdtpen; //!< update penalty at each time step // biphasic-solute contact parameters 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 double m_ambc; //!< ambient concentration protected: int m_dofP; int m_dofC; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEFixedConcentration.h
.h
1,525
42
/*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 FEFixedConcentration : public FEFixedBC { public: FEFixedConcentration(FEModel* fem); bool Init() override; private: int m_dof; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateHuiskes.h
.h
2,606
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 "FEChemicalReaction.h" #include <FECore/FEMeshTopo.h> class FEBIOMIX_API FEReactionRateHuiskes : public FEReactionRate { public: //! constructor FEReactionRateHuiskes(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 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; public: FEParamDouble m_B; //!< mass supply coefficient FEParamDouble m_psi0; //!< specific strain energy at homeostasis double m_D; //!< characteristic sensor distance private: int m_comp; //!< component of solid mixture (if applicable) std::vector<std::vector<int>> m_EPL; //!< list of element proximity lists FEMeshTopo m_topo; //!< mesh topology; bool m_binit; //!< initialization flag double m_M; //!< molar mass of sbm int m_lsbm; //!< local sbm value DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESolventSupply.h
.h
2,294
61
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEMaterial.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Base class for solvent supply. //! These materials need to define the supply and tangent supply functions. //! class FEBIOMIX_API FESolventSupply : public FEMaterialProperty { public: FESolventSupply(FEModel* pfem) : FEMaterialProperty(pfem) {} virtual ~FESolventSupply(){} //! solvent supply virtual double Supply(FEMaterialPoint& pt) = 0; //! tangent of solvent supply with respect to strain virtual mat3ds Tangent_Supply_Strain(FEMaterialPoint& mp) = 0; //! tangent of solvent supply with respect to pressure virtual double Tangent_Supply_Pressure(FEMaterialPoint& mp) = 0; //! tangent of solvent supply with respect to concentration double Tangent_Supply_Concentration(FEMaterialPoint& mp, const int isol); //! initialization bool Init() override { return FEMaterialProperty::Init(); } FECORE_BASE_CLASS(FESolventSupply) };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPrescribedNodalFluidPressure.h
.h
1,737
49
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2020 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEPrescribedDOF.h> #include "febiomix_api.h" class FEBIOMIX_API FEPrescribedNodalFluidPressure : public FEPrescribedDOF { public: FEPrescribedNodalFluidPressure(FEModel* fem); bool Init() override; private: DECLARE_FECORE_CLASS(); }; class FEBIOMIX_API FEPrescribedShellFluidPressure : public FEPrescribedDOF { public: FEPrescribedShellFluidPressure(FEModel* fem); bool Init() override; private: DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicShellDomain.h
.h
5,246
139
/*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 <FECore/FEDofList.h> #include "FEMultiphasic.h" #include "FEMultiphasicDomain.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 FEMultiphasicShellDomain : public FESSIShellDomain, public FEMultiphasicDomain { public: //! constructor FEMultiphasicShellDomain(FEModel* pfem); //! Reset data void Reset() override; //! get the 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 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; //! calculates the membrane reaction stiffness matrix for this domain void MembraneReactionStiffnessMatrix(FELinearSystem& LS); //! 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, const FETimeInfo& tp); // update element shell material points if membrane reactions are present void UpdateShellMPData(int iel); //! Unpack element data (overridden from FEDomain) void UnpackMembraneLM(FEShellElement& el, vector<int>& lm); //! build connectivity for matrix profile void BuildMatrixProfile(FEGlobalMatrix& M) override; public: // internal work (overridden from FEElasticDomain) void InternalForces(FEGlobalVector& R) override; // internal work (steady-state case) void InternalForcesSS(FEGlobalVector& R) override; // external work of flux generated by membrane reactions void MembraneReactionFluxes(FEGlobalVector& R); public: //! element internal force vector void ElementInternalForce(FEShellElement& el, vector<double>& fe); //! element internal force vector (steady-state case) void ElementInternalForceSS(FEShellElement& el, vector<double>& fe); //! element external work of flux generated by membrane reactions void ElementMembraneReactionFlux(FEShellElement& el, vector<double>& fe); //! calculates the element multiphasic stiffness matrix bool ElementMultiphasicStiffness(FEShellElement& el, matrix& ke, bool bsymm); //! calculates the element multiphasic stiffness matrix bool ElementMultiphasicStiffnessSS(FEShellElement& el, matrix& ke, bool bsymm); //! calculates the element membrane flux stiffness matrix bool ElementMembraneFluxStiffness(FEShellElement& el, matrix& ke); 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_dofSU; FEDofList m_dofR; FEDofList m_dof; };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMassActionForwardEffective.h
.h
2,250
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, using effective concentrations class FEBIOMIX_API FEMassActionForwardEffective : public FEChemicalReaction { public: //! constructor FEMassActionForwardEffective(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/FEReactionRateRuberti.h
.h
2,378
63
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEChemicalReaction.h" #include <FECore/FEVec3dValuator.h> class FEBIOMIX_API FEReactionRateRuberti : public FEReactionRate { public: //! constructor FEReactionRateRuberti(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 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; public: FEParamDouble m_kd; //!< maximum sbm degradation rate FEParamDouble m_sig; //!< stretch standard deviation private: int m_comp; //!< component of solid mixture (if applicable) FEVec3dValuator* m_fiber; //!< fiber material double m_M; //!< molar mass of sbm int m_lsbm; //!< local sbm value DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicContactSurface.cpp
.cpp
6,042
193
/*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 "FEBiphasicContactSurface.h" #include "FEBiphasic.h" #include <FECore/FEModel.h> void FEBiphasicContactPoint::Serialize(DumpStream& ar) { FEContactMaterialPoint::Serialize(ar); ar & m_dg; ar & m_Lmd; ar & m_Lmt; ar & m_epsn; ar & m_epsp; ar & m_p1; ar & m_nu; ar & m_s1; ar & m_tr; ar & m_rs; ar & m_rsp; ar & m_bstick; ar & m_Lmp & m_pg & m_mueff & m_fls; } //----------------------------------------------------------------------------- FEBiphasicContactSurface::FEBiphasicContactSurface(FEModel* pfem) : FEContactSurface(pfem) { m_dofP = -1; } //----------------------------------------------------------------------------- FEBiphasicContactSurface::~FEBiphasicContactSurface() { } //----------------------------------------------------------------------------- bool FEBiphasicContactSurface::Init() { // I want to use the FEModel class for this, but don't know how DOFS& dofs = GetFEModel()->GetDOFS(); m_dofP = dofs.GetDOF("p"); return FEContactSurface::Init(); } //----------------------------------------------------------------------------- //! serialization void FEBiphasicContactSurface::Serialize(DumpStream& ar) { FEContactSurface::Serialize(ar); if (ar.IsShallow() == false) ar & m_dofP; } //----------------------------------------------------------------------------- vec3d FEBiphasicContactSurface::GetFluidForce() { assert(false); return vec3d(0,0,0); } //----------------------------------------------------------------------------- double FEBiphasicContactSurface::GetFluidLoadSupport() { int n, i; // initialize contact force double FLS = 0; double A = 0; // loop over all elements of the surface for (n=0; n<Elements(); ++n) { FESurfaceElement& el = Element(n); // evaluate the fluid force for that element for (i=0; i<el.GaussPoints(); ++i) { FEBiphasicContactPoint *cp = dynamic_cast<FEBiphasicContactPoint*>(el.GetMaterialPoint(i)); if (cp) { double w = el.GaussWeights()[i]; // get the base vectors vec3d g[2]; CoBaseVectors(el, i, g); // normal (magnitude = area) vec3d n = g[0] ^ g[1]; double da = n.norm(); FLS += cp->m_fls*w*da; } } } A = GetContactArea(); return (A > 0) ? FLS/A : 0; } //----------------------------------------------------------------------------- void FEBiphasicContactSurface::GetMuEffective(int nface, double& pg) { pg = 0; } //----------------------------------------------------------------------------- void FEBiphasicContactSurface::GetLocalFLS(int nface, double& pg) { pg = 0; } //----------------------------------------------------------------------------- void FEBiphasicContactSurface::UnpackLM(FEElement& el, vector<int>& lm) { int N = el.Nodes(); lm.assign(N*4, -1); // 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 if (m_dofP >= 0) lm[3*N+i] = id[m_dofP]; } } //----------------------------------------------------------------------------- // Evaluate the local fluid load support projected from the element to the surface Gauss points void FEBiphasicContactSurface::GetGPLocalFLS(int nface, double* pt, double pamb) { FESurfaceElement& el = Element(nface); FEElement* e = el.m_elem[0].pe; FESolidElement* se = dynamic_cast<FESolidElement*>(e); if (se) { mat3ds s; s.zero(); double p = 0; for (int i=0; i<se->GaussPoints(); ++i) { FEMaterialPoint* pt = se->GetMaterialPoint(i); FEElasticMaterialPoint* ep = pt->ExtractData<FEElasticMaterialPoint>(); FEBiphasicMaterialPoint* bp = pt->ExtractData<FEBiphasicMaterialPoint>(); if (ep) s += ep->m_s; if (bp) p += bp->m_p; } s /= se->GaussPoints(); p /= se->GaussPoints(); // account for ambient pressure p -= pamb; // evaluate FLS at integration points of that face for (int i=0; i<el.GaussPoints(); ++i) { double *H = el.H(i); pt[i] = 0; for (int j=0; j<el.Nodes(); ++j) { vec3d n = SurfaceNormal(el, j); double tn = n*(s*n); double fls = (tn != 0) ? -p/tn : 0; pt[i] += fls*H[j]; } } } else for (int i=0; i<el.Nodes(); ++i) pt[i] = 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEPrescribedConcentration.cpp
.cpp
2,006
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) 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 "FEPrescribedConcentration.h" #include <FECore/FEModel.h> #include <FECore/DOFS.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(FEPrescribedConcentration, FEBoundaryCondition) ADD_PARAMETER(m_dof, "dof", 0, "$(dof_list:concentration)"); ADD_PARAMETER(m_scale, "value")->setUnits(UNIT_CONCENTRATION)->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE); ADD_PARAMETER(m_brelative, "relative"); END_FECORE_CLASS(); FEPrescribedConcentration::FEPrescribedConcentration(FEModel* fem) : FEPrescribedDOF(fem) { }
C++
3D
febiosoftware/FEBio
FEBioMix/FEHydraulicPermeability.cpp
.cpp
1,709
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 "FEHydraulicPermeability.h" //----------------------------------------------------------------------------- // Derivative of permeability w.r.t. solute concentration at material point // Set this to zero by default because poroelasticity problems do not require it mat3ds FEHydraulicPermeability::Tangent_Permeability_Concentration(FEMaterialPoint& pt, const int isol) { return mat3ds(0,0,0,0,0,0); }
C++
3D
febiosoftware/FEBio
FEBioMix/FESlidingInterface2.h
.h
5,681
180
/*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 FESlidingSurface2 : public FEBiphasicContactSurface { public: //! constructor FESlidingSurface2(FEModel* pfem); //! initialization bool Init() override; // data serialization void Serialize(DumpStream& ar) override; //! evaluate net contact force vec3d GetContactForce() override; vec3d GetContactForceFromElementStress(); //! evaluate net contact area double GetContactArea() override; //! evaluate net fluid force vec3d GetFluidForce() override; vec3d GetFluidForceFromElementPressure(); //! evaluate the fluid load support double GetFluidLoadSupport() override; //! calculate the nodal normals void UpdateNodeNormals(); void SetPoroMode(bool bporo) { m_bporo = bporo; } //! create material point data FEMaterialPoint* CreateMaterialPoint() override; public: void GetContactTraction(int nface, vec3d& pt) override; void GetNodalContactPressure(int nface, double* pg) override; void GetNodalContactTraction(int nface, vec3d* pt) override; void EvaluateNodalContactPressures(); 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<double> m_pn; //!< nodal contact pressures vec3d m_Ft; //!< total contact force (from equivalent nodal forces) }; //----------------------------------------------------------------------------- class FEBIOMIX_API FESlidingInterface2 : public FEContactInterface { public: //! constructor FESlidingInterface2(FEModel* pfem); //! destructor ~FESlidingInterface2(); //! initialization bool Init() override; //! interface activation void Activate() override; //! 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(FESlidingSurface2& ss, FESlidingSurface2& ms, bool bupseg, bool bmove = false); //! calculate penalty factor void UpdateAutoPenalty(); void CalcAutoPenalty(FESlidingSurface2& s); void CalcAutoPressurePenalty(FESlidingSurface2& s); double AutoPressurePenalty(FESurfaceElement& el, FESlidingSurface2& s); public: FESlidingSurface2 m_ss; //!< primary surface FESlidingSurface2 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_bdupr; //!< dual projection flag for free-draining double m_epsn; //!< normal penalty factor bool m_bautopen; //!< use autopenalty factor bool m_bupdtpen; //!< update penalty at each time step // biphasic contact parameters double m_epsp; //!< flow rate penalty protected: int m_dofP; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEDiffConstOrtho.h
.h
2,437
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 "FEBiphasicSolute.h" #include <FECore/FEMesh.h> //----------------------------------------------------------------------------- // This class implements a material that has a constant orthotropic diffusivity class FEBIOMIX_API FEDiffConstOrtho : public FESoluteDiffusivity { public: //! constructor FEDiffConstOrtho(FEModel* pfem); //! free diffusivity double Free_Diffusivity(FEMaterialPoint& pt) override; //! Tangent of free 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[3]; //!< principal diffusivities // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateRuberti.cpp
.cpp
5,527
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.*/ #include "stdafx.h" #include "FEReactionRateRuberti.h" #include "FEBiphasic.h" #include "FEMultiphasic.h" #include "FESoluteInterface.h" #include <FEBioMech/FERemodelingElasticMaterial.h> #include <FEBioMech/FEElasticMixture.h> // Material parameters for the FEMultiphasic material BEGIN_FECORE_CLASS(FEReactionRateRuberti, FEReactionRate) ADD_PARAMETER(m_kd, "kd"); ADD_PARAMETER(m_sig, FE_RANGE_GREATER_OR_EQUAL(0.0), "sigma"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEReactionRateRuberti::FEReactionRateRuberti(FEModel* pfem) : FEReactionRate(pfem) { m_kd = 0; m_sig = 0; m_comp = -1; m_fiber = nullptr; m_M = 0; m_lsbm = -1; } //----------------------------------------------------------------------------- //! initialization bool FEReactionRateRuberti::Init() { FEMultiphasic* pbm = dynamic_cast<FEMultiphasic*>(GetAncestor()); if (pbm == nullptr) return true; // in case material is not multiphasic FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(GetAncestor()); FEChemicalReaction* pcm = dynamic_cast<FEChemicalReaction*>(m_pReact); int sbm = pcm->m_vRtmp[0]->m_speciesID; m_lsbm = pbm->FindLocalSBMID(sbm); m_M = pbm->SBMMolarMass(m_lsbm); 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; // get the fiber property (this remodeling rule only works with fibrous materials) m_fiber = dynamic_cast<FEVec3dValuator*>(psm->GetMaterial(m_comp)->GetProperty("fiber")); if (m_fiber == nullptr) return false; return true; } //----------------------------------------------------------------------------- //! reaction rate at material point double FEReactionRateRuberti::ReactionRate(FEMaterialPoint& pt) { FEMultiphasic* pbm = dynamic_cast<FEMultiphasic*>(GetAncestor()); FEBiphasicInterface* pbi = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(GetAncestor()); double phir = pbm->SolidReferentialVolumeFraction(pt); double c = psi->SBMConcentration(pt, m_lsbm); mat3d Q = pbm->GetLocalCS(pt); vec3d a0 = m_fiber->unitVector(pt); vec3d ar = Q * a0; FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double lam = (et.m_F*ar).norm(); double k = (lam > 1.0) ? m_kd(pt)*exp(-0.5*pow((lam-1)/m_sig(pt),2)) : m_kd(pt); return k; } //----------------------------------------------------------------------------- //! tangent of reaction rate with strain at material point mat3ds FEReactionRateRuberti::Tangent_ReactionRate_Strain(FEMaterialPoint& pt) { FEMultiphasic* pbm = dynamic_cast<FEMultiphasic*>(GetAncestor()); FEBiphasicInterface* pbi = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FESoluteInterface* psi = dynamic_cast<FESoluteInterface*>(GetAncestor()); double phir = pbm->SolidReferentialVolumeFraction(pt); double c = psi->SBMConcentration(pt, m_lsbm); mat3d Q = pbm->GetLocalCS(pt); vec3d a0 = m_fiber->unitVector(pt); vec3d ar = Q * a0; FEElasticMaterialPoint& et = *pt.ExtractData<FEElasticMaterialPoint>(); double lam = (et.m_F*ar).norm(); double kd = m_kd(pt); double sig = m_sig(pt); double k = (lam > 1.0) ? kd*exp(-0.5*pow(lam-1,2)/sig) : kd; double dkdlam = (lam > 1.0) ? -(lam-1)/sig*kd*exp(-0.5*pow((lam-1)/sig,2)) : 0; mat3ds dzhatde = dyad(et.m_F*ar)*(dkdlam/lam/et.m_J); return dzhatde; } //----------------------------------------------------------------------------- //! tangent of reaction rate with effective fluid pressure at material point double FEReactionRateRuberti::Tangent_ReactionRate_Pressure(FEMaterialPoint& pt) { return 0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESBMPointSource.h
.h
2,803
100
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEBodyLoad.h> #include <FECore/FEOctreeSearch.h> #include <unordered_map> #include "febiomix_api.h" class FESolidElement; class FEBIOMIX_API FESBMPointSource : public FEBodyLoad { public: FESBMPointSource(FEModel* fem); bool Init() override; void Update() override; void Accumulate(double dc); void SetPosition(const vec3d& pos); vec3d GetPosition() const; void SetSBMID(int id); int GetSBMID() const; void SetRate(double rate); void SetRadius(double radius); double GetRate() const; double GetdC() const; double GetdCp() const; void SetdC(double dC); void SetWeighVolume(bool b); void SetResetFlag(bool b); void SetAccumulateFlag(bool b); //std::vector<FEMaterialPoint*> FindIntInRadius(); void FindIntInRadius(std::vector<FEMaterialPoint*> &possible_ints, double &total_elem); //! return all the elements in the given radius void FindNodesInRadius(std::vector<FEMaterialPoint*>& possible_ints, double& total_elem); private: //void ResetSBM(); private: int m_sbmId; // The SBM ID that defins the cell's "concentration" vec3d m_pos; // the position (in reference coordinates) double m_rate; // density value at point source double m_radius; double m_Vc; bool m_reset; bool m_doReset; bool m_weighVolume; bool m_accumulate; // accumulate species flag for the update double m_dC = 0.0; // total change of a species double m_dCp = 0.0; private: FEOctreeSearch m_search; FESolidElement* m_el; double m_q[3]; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESolutePointSource.h
.h
2,757
101
/*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/FEBodyLoad.h> #include <FECore/FEOctreeSearch.h> #include <unordered_map> #include "febiomix_api.h" class FESolidElement; class FEBIOMIX_API FESolutePointSource : public FEBodyLoad { public: FESolutePointSource(FEModel* fem); bool Init() override; void Accumulate(double dc); void Update() override; void SetPosition(const vec3d& v); vec3d GetPosition() const; void SetSoluteID(int soluteID); int GetSoluteID() const; void SetRate(double rate); void SetRadius(double radius); double GetRate() const; double GetdC() const; double GetdCp() const; void SetdC(double dC); void SetdCp(double dCp); void SetAccumulateFlag(bool b); void SetAccumulateCAFlag(bool b); //! Evaluate force vector void LoadVector(FEGlobalVector& R) override; //! evaluate stiffness matrix void StiffnessMatrix(FELinearSystem& S) override; //! return all the elements in the given radius void FindNodesInRadius(std::vector<FEElement*>& possible_nodes, double& total_elem); vec3d ClampNatC(double r[3]); private: int m_soluteId; //!< solute ID double m_rate; //!< production rate vec3d m_pos; //!< position of source bool m_accumulate = false; //!< accumulate flag bool m_accumulate_ca; //! < accumulate actual concentration flag double m_radius; double m_Vc; double m_dC = 0.0; double m_dCp = 0.0; private: FEOctreeSearch m_search; FESolidElement* m_el; double m_q[3]; int m_dofC; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMixDomainFactory.cpp
.cpp
2,751
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.*/ #include "stdafx.h" #include "FEMixDomainFactory.h" #include "FEBiphasic.h" #include "FEBiphasicSolute.h" #include "FETriphasic.h" #include "FEMultiphasic.h" #include "FEBiphasicSolidDomain.h" #include "FEBiphasicSoluteDomain.h" #include "FETriphasicDomain.h" #include "FEMultiphasicDomain.h" #include <FECore/FEShellDomain.h> //----------------------------------------------------------------------------- FEDomain* FEMixDomainFactory::CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat) { FEModel* pfem = pmat->GetFEModel(); FE_Element_Class eclass = spec.eclass; FEDomain* pd = nullptr; if (eclass == FE_ELEM_SOLID) { const char* sztype = 0; if (dynamic_cast<FEBiphasic* >(pmat)) sztype = "biphasic-solid"; else if (dynamic_cast<FEBiphasicSolute*>(pmat)) sztype = "biphasic-solute-solid"; else if (dynamic_cast<FETriphasic* >(pmat)) sztype = "triphasic-solid"; else if (dynamic_cast<FEMultiphasic* >(pmat)) sztype = "multiphasic-solid"; if (sztype) pd = fecore_new<FESolidDomain>(sztype, pfem); } else if (eclass == FE_ELEM_SHELL) { const char* sztype = 0; if (dynamic_cast<FEBiphasic* >(pmat)) sztype = "biphasic-shell"; else if (dynamic_cast<FEBiphasicSolute*>(pmat)) sztype = "biphasic-solute-shell"; else if (dynamic_cast<FEMultiphasic* >(pmat)) sztype = "multiphasic-shell"; if (sztype) pd = fecore_new<FEShellDomain>(sztype, pfem); } if (pd) pd->SetMaterial(pmat); return pd; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMembraneReaction.h
.h
9,267
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.*/ #pragma once #include "FEReaction.h" #include "febiomix_api.h" #include "FESolute.h" //----------------------------------------------------------------------------- //! Base class for membrane reaction rates. class FEBIOMIX_API FEMembraneReactionRate : public FEMaterialProperty { public: //! constructor FEMembraneReactionRate(FEModel* pfem) : FEMaterialProperty(pfem), m_pReact(nullptr) {} //! reaction rate at material point virtual double ReactionRate(FEMaterialPoint& pt) = 0; //! tangent of reaction rate with area strain at material point virtual double 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; virtual double Tangent_ReactionRate_Pe(FEMaterialPoint& pt) = 0; virtual double Tangent_ReactionRate_Pi(FEMaterialPoint& pt) = 0; //! tangent of reaction rate with effective solute concentration at material point virtual double Tangent_ReactionRate_Concentration(FEMaterialPoint& pt, const int isol) = 0; virtual double Tangent_ReactionRate_Ce(FEMaterialPoint& pt, const int isol) = 0; virtual double Tangent_ReactionRate_Ci(FEMaterialPoint& pt, const int isol) = 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(FEMembraneReactionRate) }; //----------------------------------------------------------------------------- class FEBIOMIX_API FEInternalReactantSpeciesRef : public FEReactionSpeciesRef { public: FEInternalReactantSpeciesRef(FEModel* fem) : FEReactionSpeciesRef(fem) {} DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEInternalReactantSpeciesRef) }; class FEBIOMIX_API FEInternalProductSpeciesRef : public FEReactionSpeciesRef { public: FEInternalProductSpeciesRef(FEModel* fem) : FEReactionSpeciesRef(fem) {} DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEInternalProductSpeciesRef) }; class FEBIOMIX_API FEExternalReactantSpeciesRef : public FEReactionSpeciesRef { public: FEExternalReactantSpeciesRef(FEModel* fem) : FEReactionSpeciesRef(fem) {} DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEExternalReactantSpeciesRef) }; class FEBIOMIX_API FEExternalProductSpeciesRef : public FEReactionSpeciesRef { public: FEExternalProductSpeciesRef(FEModel* fem) : FEReactionSpeciesRef(fem) {} DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEExternalProductSpeciesRef) }; //----------------------------------------------------------------------------- //! Base class for membrane reactions. class FEBIOMIX_API FEMembraneReaction : public FEReaction { public: //! constructor FEMembraneReaction(FEModel* pfem); //! get solute (use only during initialization) FESoluteData* GetSolute(int nsol); //! initialization bool Init() override; public: //! set the forward reaction rate void SetForwardReactionRate(FEMembraneReactionRate* pfwd) { m_pFwd = pfwd; } //! set the reverse reaction rate void SetReverseReactionRate(FEMembraneReactionRate* 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 double Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) = 0; //! tangent of molar supply with effective pressure at material point virtual double Tangent_ReactionSupply_Pressure(FEMaterialPoint& pt) = 0; virtual double Tangent_ReactionSupply_Pe(FEMaterialPoint& pt) = 0; virtual double Tangent_ReactionSupply_Pi(FEMaterialPoint& pt) = 0; //! tangent of molar supply with effective concentration at material point virtual double Tangent_ReactionSupply_Concentration(FEMaterialPoint& pt, const int sol) = 0; virtual double Tangent_ReactionSupply_Ce(FEMaterialPoint& pt, const int sol) = 0; virtual double Tangent_ReactionSupply_Ci(FEMaterialPoint& pt, const int sol) = 0; public: //! Serialization void Serialize(DumpStream& ar) override; public: FEMembraneReactionRate* m_pFwd; //!< pointer to forward reaction rate FEMembraneReactionRate* m_pRev; //!< pointer to reverse reaction rate 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 vector<FEInternalReactantSpeciesRef*> m_vRitmp; //!< helper variable for reading in stoichiometric coefficients for internal reactants vector<FEInternalProductSpeciesRef*> m_vPitmp; //!< helper variable for reading in stoichiometric coefficients for internal products vector<FEExternalReactantSpeciesRef*> m_vRetmp; //!< helper variable for reading in stoichiometric coefficients for external reactants vector<FEExternalProductSpeciesRef*> m_vPetmp; //!< helper variable for reading in stoichiometric coefficients for external products intmap m_solR; //!< stoichiometric coefficients of solute reactants intmap m_solP; //!< stoichiometric coefficients of solute products intmap m_sbmR; //!< stoichiometric coefficients of solid-bound reactants intmap m_sbmP; //!< stoichiometric coefficients of solid-bound products intmap m_solRi; //!< stoichiometric coefficients of internal solute reactants intmap m_solPi; //!< stoichiometric coefficients of internal solute products intmap m_solRe; //!< stoichiometric coefficients of external solute reactants intmap m_solPe; //!< stoichiometric coefficients of external solute products public: int m_nsol; //!< number of solutes in the mixture double m_Vbar; //!< weighted molar volume of reactants and products bool m_Vovr; //!< override flag for m_Vbar 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 int m_NSOL; //!< number of solutes in the model vector<int> m_z; //!< charge number of all solutes vector<int> m_vRi; //!< stoichiometric coefficients of reactants vector<int> m_vPi; //!< stoichiometric coefficients of products vector<int> m_vi; //!< net stoichiometric coefficients of reactants and products vector<int> m_vRe; //!< stoichiometric coefficients of reactants vector<int> m_vPe; //!< stoichiometric coefficients of products vector<int> m_ve; //!< net stoichiometric coefficients of reactants and products DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEMembraneReaction) };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSolute.h
.h
5,488
150
/*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" #include "FESolutesMaterialPoint.h" #include "FESolute.h" #include "FEOsmoticCoefficient.h" #include "FESoluteInterface.h" #include <FECore/FEModelParam.h> //----------------------------------------------------------------------------- //! Base class for solute diffusion in biphasic materials. class FEBIOMIX_API FEBiphasicSolute : public FEMaterial, public FEBiphasicInterface, public FESoluteInterface_T<FESolutesMaterialPoint> { public: FEBiphasicSolute(FEModel* pfem); // returns a pointer to a new material point object FEMaterialPointData* CreateMaterialPointData() override; // Get the elastic component (overridden from FEMaterial) FEElasticMaterial* GetElasticMaterial() { return m_pSolid; } //! Get the solid FEElasticMaterial* GetSolid() { return m_pSolid; } //! Get the permeability FEHydraulicPermeability* GetPermeability() { return m_pPerm; } // solute interface public: // number of solutes int Solutes() override { return 1; } //! Get the solute FESolute* GetSolute(int i=0) override { return (i==0 ? (FESolute*)m_pSolute : 0); } double GetReferentialFixedChargeDensity(const FEMaterialPoint& mp) override; double GetFixedChargeDensity(const FEMaterialPoint& mp) override { const FESolutesMaterialPoint* spt = (mp.ExtractData<FESolutesMaterialPoint>()); return spt->m_cF; } //! Get the osmotic coefficient FEOsmoticCoefficient* GetOsmoticCoefficient() override { return m_pOsmC; } public: // overridden from FEBiphasicInterface //! Evaluate and return solid referential volume fraction double SolidReferentialVolumeFraction(FEMaterialPoint& mp) override { double phisr = m_phi0(mp); FEBiphasicMaterialPoint* pt = (mp.ExtractData<FEBiphasicMaterialPoint>()); pt->m_phi0 = pt->m_phi0t = phisr; return phisr; }; // Return solid referential volume fraction double GetReferentialSolidVolumeFraction(const FEMaterialPoint& mp) override { const FEBiphasicMaterialPoint* pt = (mp.ExtractData<FEBiphasicMaterialPoint>()); return pt->m_phi0t; } // Return actual fluid pressure double GetActualFluidPressure(const FEMaterialPoint& mp) override { const FEBiphasicMaterialPoint* pt = (mp.ExtractData<FEBiphasicMaterialPoint>()); return pt->m_pa; } public: bool Init() override; //! specialized material points void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) override; //! serialization void Serialize(DumpStream& ar) override; //! calculate stress at material point mat3ds Stress(FEMaterialPoint& pt); //! calculate tangent stiffness at material point tens4ds Tangent(FEMaterialPoint& pt); //! calculate fluid (solvent) flux vec3d FluidFlux(FEMaterialPoint& pt); //! calculate solute molar flux vec3d SoluteFlux(FEMaterialPoint& pt); //! actual fluid pressure (as opposed to effective pressure) double Pressure(FEMaterialPoint& pt); //! actual concentration (as opposed to effective concentration) double Concentration(FEMaterialPoint& pt); //! referential concentration (normalized to mixture volume in reference state) double ReferentialConcentration(FEMaterialPoint& pt); //! porosity double Porosity(FEMaterialPoint& pt); //! partition coefficient derivatives void PartitionCoefficientFunctions(FEMaterialPoint& mp, double& kappa, double& dkdJ, double& dkdc); //! fluid density double FluidDensity() { return m_rhoTw; } public: // material parameters double m_rhoTw; //!< true fluid density FEParamDouble m_phi0; //!< solid volume fraction in reference configuration public: double m_Mu; //!< solute molecular weight double m_rhoTu; //!< true solute density double m_Rgas; //!< universal gas constant double m_Tabs; //!< absolute temperature private: // material properties FEElasticMaterial* m_pSolid; //!< pointer to elastic solid material FEHydraulicPermeability* m_pPerm; //!< pointer to permeability material FEOsmoticCoefficient* m_pOsmC; //!< pointer to osmotic coefficient material FESolute* m_pSolute; //!< pointer to solute material DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMultiphasicFluidPressureLoad.h
.h
2,404
73
/*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/FESurfaceLoad.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- //! Prescribe the actual fluid pressure in a multiphasic mixture class FEBIOMIX_API FEMultiphasicFluidPressureLoad : public FESurfaceLoad { public: //! constructor FEMultiphasicFluidPressureLoad(FEModel* pfem); //! destructor ~FEMultiphasicFluidPressureLoad() {} //! calculate traction stiffness (there is none for this load) void StiffnessMatrix(FELinearSystem& LS) override {} //! calculate load vector (there is none for this load) 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; protected: int m_dofP; int m_Rgas; int m_Tabs; public: double m_p0; // prescribed actual fluid pressure DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEMixDomainFactory.h
.h
1,598
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.*/ #pragma once #include <FECore/FECoreKernel.h> #include "febiomix_api.h" //----------------------------------------------------------------------------- class FEBIOMIX_API FEMixDomainFactory : public FEDomainFactory { public: virtual FEDomain* CreateDomain(const FE_Element_Spec& spec, FEMesh* pm, FEMaterial* pmat); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEPermRefIso.h
.h
2,349
63
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEBiphasic.h" //----------------------------------------------------------------------------- // This class implements a poroelastic material that has a strain-dependent // permeability 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 FEPermRefIso : public FEHydraulicPermeability { public: //! constructor FEPermRefIso(FEModel* pfem); //! permeability mat3ds Permeability(FEMaterialPoint& pt) override; //! Tangent of permeability tens4dmm Tangent_Permeability_Strain(FEMaterialPoint& mp) override; //! data initialization and checking bool Validate() override; public: FEParamDouble m_perm0; //!< permeability for I term FEParamDouble m_perm1; //!< permeability for b term FEParamDouble m_perm2; //!< permeability for b^2 term double m_M; //!< nonlinear exponential coefficient double m_alpha; //!< nonlinear power exponent // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEDiffAlbroIso.cpp
.cpp
7,290
208
/*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 "FEDiffAlbroIso.h" #include <FECore/log.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEDiffAlbroIso, FESoluteDiffusivity) ADD_PARAMETER(m_diff0 , FE_RANGE_GREATER_OR_EQUAL(0.0), "free_diff")->setUnits(UNIT_DIFFUSIVITY)->setLongName("free diffusivity"); ADD_PARAMETER(m_cdinv , FE_RANGE_GREATER_OR_EQUAL(0.0), "cdinv" )->setUnits("L^3/n"); ADD_PARAMETER(m_alphad, FE_RANGE_GREATER_OR_EQUAL(0.0), "alphad" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEDiffAlbroIso::FEDiffAlbroIso(FEModel* pfem) : FESoluteDiffusivity(pfem) { m_diff0 = 1; m_cdinv = 0; m_alphad = 0; m_lsol = -1; } //----------------------------------------------------------------------------- //! Initialization. bool FEDiffAlbroIso::Init() { if (FESoluteDiffusivity::Init() == false) return false; // get the grandparent material which must be // a biphasic-solute/triphasic/multiphasic material FESolute* pSol = dynamic_cast<FESolute*> (GetParent()); m_lsol = pSol->GetSoluteLocalID(); if (m_lsol == -1) { feLogError("Invalid value for sol"); return false; } return true; } //----------------------------------------------------------------------------- //! Free diffusivity double FEDiffAlbroIso::Free_Diffusivity(FEMaterialPoint& mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); // solute concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); // diffusivity coefficient double d = m_diff0(mp)*exp(-m_cdinv(mp)*ca); return d; } //----------------------------------------------------------------------------- //! Tangent of free diffusivity with respect to concentration double FEDiffAlbroIso::Tangent_Free_Diffusivity_Concentration(FEMaterialPoint& mp, const int isol) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); // solute concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double c = psm->GetEffectiveSoluteConcentration(mp, m_lsol); double dkdc = psm->dkdc(mp, m_lsol, isol); double k = psm->GetPartitionCoefficient(mp, m_lsol); // diffusivity coefficient double d = m_diff0(mp)*exp(-m_cdinv(mp)*ca); // derivative of d w.r.t. actual concentration double dc = -m_cdinv(mp)*d; // tangent w.r.t. concentration if (isol == m_lsol) return dc*(k+dkdc*c); else return dc*dkdc*c; } //----------------------------------------------------------------------------- //! Diffusivity tensor. mat3ds FEDiffAlbroIso::Diffusivity(FEMaterialPoint& mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint* et = mp.ExtractData<FEElasticMaterialPoint>(); // relative volume double J = et->m_J; // solid volume fraction in reference configuration double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); // porosity in current configuration double phiw = 1 - phi0/J; // solute concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); // diffusivity coefficient double d = m_diff0(mp)*exp(-m_alphad(mp)*(1-phiw)/phiw - m_cdinv(mp)*ca); // diffusivity tensor mat3dd dt(d); return dt; } //----------------------------------------------------------------------------- //! Tangent of diffusivity with respect to strain tens4dmm FEDiffAlbroIso::Tangent_Diffusivity_Strain(FEMaterialPoint &mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint* et = mp.ExtractData<FEElasticMaterialPoint>(); // Identity mat3dd I(1); // relative volume double J = et->m_J; // solid volume fraction in reference configuration double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); // porosity in current configuration double phiw = 1 - phi0/J; // solute concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double c = psm->GetEffectiveSoluteConcentration(mp, m_lsol); double dkdJ = psm->dkdJ(mp, m_lsol); // diffusivity coefficient double d = m_diff0(mp)*exp(-m_alphad(mp)*(1-phiw)/phiw - m_cdinv(mp)*ca); // derivative of (J d) w.r.t. J double dJ = d*(1+J*(m_alphad(mp)*phi0/(J-phi0)/(J-phi0) - m_cdinv(mp)*c*dkdJ)); tens4dmm D4 = dyad1s(I)*dJ-dyad4s(I)*(2*d); return D4; } //----------------------------------------------------------------------------- //! Tangent of diffusivity with respect to concentration mat3ds FEDiffAlbroIso::Tangent_Diffusivity_Concentration(FEMaterialPoint &mp, const int isol) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint* et = mp.ExtractData<FEElasticMaterialPoint>(); // relative volume double J = et->m_J; // solid volume fraction in reference configuration double phi0 = pbm->GetReferentialSolidVolumeFraction(mp); // porosity in current configuration double phiw = 1 - phi0/J; // solute concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double c = psm->GetEffectiveSoluteConcentration(mp, m_lsol); double dkdc = psm->dkdc(mp, m_lsol, isol); double k = psm->GetPartitionCoefficient(mp, m_lsol); // diffusivity coefficient double d = m_diff0(mp)*exp(-m_alphad(mp)*(1-phiw)/phiw - m_cdinv(mp)*ca); // derivative of d w.r.t. actual concentration double dc = -m_cdinv(mp)*d; // tangent w.r.t. concentration if (isol == m_lsol) { return mat3dd(dc*(k+dkdc*c)); } else return mat3dd(dc*dkdc*c); }
C++
3D
febiosoftware/FEBio
FEBioMix/FEPrescribedConcentration.h
.h
1,500
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) 2020 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEPrescribedDOF.h> #include "febiomix_api.h" class FEBIOMIX_API FEPrescribedConcentration : public FEPrescribedDOF { public: FEPrescribedConcentration(FEModel* fem); DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEReactionRateExpSED.h
.h
2,029
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 "FEChemicalReaction.h" class FEBIOMIX_API FEReactionRateExpSED : public FEReactionRate { public: //! constructor FEReactionRateExpSED(FEModel* pfem); //! 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; public: FEParamDouble m_B; //!< mass supply coefficient FEParamDouble m_Psi0; //!< scaling strain energy density DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSoluteSolver.cpp
.cpp
19,049
647
/*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 "FEBiphasicSoluteSolver.h" #include "FEBiphasicSoluteDomain.h" #include "FEBiphasicDomain.h" #include <FEBioMech/FEElasticDomain.h> #include <FEBioMech/FEResidualVector.h> #include <FEBioMech/FESolidLinearSystem.h> #include <FECore/log.h> #include <FECore/FEModel.h> #include <FECore/FEModelLoad.h> #include <FECore/FEAnalysis.h> #include <FECore/FENodalLoad.h> #include <FECore/FESurfaceLoad.h> #include "FECore/sys.h" #include "FEBiphasicSoluteAnalysis.h" //----------------------------------------------------------------------------- FEBiphasicSoluteSolver::FEBiphasicSoluteSolver(FEModel* pfem) : FEBiphasicSolver(pfem), m_dofC(pfem), m_dofD(pfem) { m_Ctol = 0.01; m_msymm = REAL_UNSYMMETRIC; // assume non-symmetric stiffness matrix by default } //----------------------------------------------------------------------------- //! Allocates and initializes the data structures. // bool FEBiphasicSoluteSolver::Init() { // initialize base class if (FEBiphasicSolver::Init() == false) return false; int i; // get number of DOFS FEModel& fem = *GetFEModel(); 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 (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<MAX_CDOFS; ++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_dofD[j]); } FEMesh& mesh = fem.GetMesh(); gather(m_Ut, mesh, dofs); return true; } //----------------------------------------------------------------------------- //! Initialize equations bool FEBiphasicSoluteSolver::InitEquations() { // get number of DOFS FEModel& fem = *GetFEModel(); DOFS& fedofs = fem.GetDOFS(); int MAX_CDOFS = fedofs.GetVariableSize("concentration"); m_dofC.Clear(); for (int i=0; i<MAX_CDOFS; ++i) m_dofC.AddDof(fem.GetDOFIndex("concentration", i)); m_dofD.Clear(); for (int i = 0; i<MAX_CDOFS; ++i) m_dofD.AddDof(fem.GetDOFIndex("shell concentration", i)); AddSolutionVariable(&m_dofC, -1, "concentration", m_Ctol); AddSolutionVariable(&m_dofD, -1, "shell concentration", m_Ctol); // base class does most of the work FEBiphasicSolver::InitEquations(); // determined the nr of concentration equations FEMesh& mesh = fem.GetMesh(); for (int j=0; j<(int)m_nceq.size(); ++j) m_nceq[j] = 0; m_nceq.assign(MAX_CDOFS, 0); 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_dofD[j]] != -1) m_nceq[j]++; } } return true; } //----------------------------------------------------------------------------- //! Prepares the data for the first QN iteration. //! void FEBiphasicSoluteSolver::PrepStep() { for (int j=0; j<(int)m_nceq.size(); ++j) if (m_nceq[j]) zero(m_Ci[j]); // 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 ((m_dofC[0] > -1) && (dof == m_dofC[0])) adjust = true; else if ((m_dofD[0] > -1) && (dof == m_dofD[0])) adjust = true; if (adjust) { pl->SetDtScale(true); } } } FEBiphasicSolver::PrepStep(); } //----------------------------------------------------------------------------- //! Implements the BFGS algorithm to solve the nonlinear FE equations. bool FEBiphasicSoluteSolver::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 (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) { // 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 FEBiphasicSoluteSolver::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* psd = dynamic_cast<FEBiphasicSoluteDomain*>(&dom); if (psd) { if (fem.GetCurrentStep()->m_nanalysis == FEBiphasicSoluteAnalysis::STEADY_STATE) psd->InternalForcesSS(RHS); else psd->InternalForces(RHS); } else if (pbd) { if (fem.GetCurrentStep()->m_nanalysis == FEBiphasicSoluteAnalysis::STEADY_STATE) pbd->InternalForcesSS(RHS); else pbd->InternalForces(RHS); } else if (ped) ped->InternalForces(RHS); } // calculate contact forces if (fem.SurfacePairConstraints() > 0) { ContactForces(RHS); } // calculate linear constraint forces // note that these are the linear constraints // enforced using the augmented lagrangian NonLinearConstraintForces(RHS, tp); // add model loads int NML = fem.ModelLoads(); for (i=0; i<NML; ++i) { FEModelLoad& mli = *fem.ModelLoad(i); if (mli.IsActive()) { mli.LoadVector(RHS); } } // 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 FEBiphasicSoluteSolver::StiffnessMatrix() { FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // get the mesh FEMesh& mesh = fem.GetMesh(); // setup the linear system 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 == FEBiphasicSoluteAnalysis::STEADY_STATE) { for (int i=0; i<mesh.Domains(); ++i) { // Biphasic-solute analyses may also include biphasic and elastic domains FEBiphasicSoluteDomain* psdom = dynamic_cast<FEBiphasicSoluteDomain*>(&mesh.Domain(i)); FEBiphasicDomain* pbdom = dynamic_cast<FEBiphasicDomain*>(&mesh.Domain(i)); FEElasticDomain* pedom = dynamic_cast<FEElasticDomain*>(&mesh.Domain(i)); if (psdom) psdom->StiffnessMatrixSS(LS, bsymm); else if (pbdom) pbdom->StiffnessMatrixSS(LS, bsymm); else if (pedom) pedom->StiffnessMatrix(LS); } } else { for (int i = 0; i<mesh.Domains(); ++i) { // Biphasic-solute analyses may also include biphasic and elastic domains FEBiphasicSoluteDomain* psdom = dynamic_cast<FEBiphasicSoluteDomain*>(&mesh.Domain(i)); FEBiphasicDomain* pbdom = dynamic_cast<FEBiphasicDomain*>(&mesh.Domain(i)); FEElasticDomain* pedom = dynamic_cast<FEElasticDomain*>(&mesh.Domain(i)); if (psdom) psdom->StiffnessMatrix(LS, bsymm); else if (pbdom) pbdom->StiffnessMatrix(LS, bsymm); else if (pedom) pedom->StiffnessMatrix(LS); } } // calculate contact stiffness if (fem.SurfacePairConstraints() > 0) { ContactStiffness(LS); } // calculate stiffness matrices for surface loads int nml = fem.ModelLoads(); for (int i = 0; i<nml; ++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 FEBiphasicSoluteSolver::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_dofD[sol]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); ci[m++] = ui[nid]; assert(m <= (int) ci.size()); } } } //----------------------------------------------------------------------------- //! Update the model's kinematic data. This is overriden from FEBiphasicSolver so //! that solute data is updated void FEBiphasicSoluteSolver::UpdateKinematics(vector<double>& ui) { // first update all solid-mechanics kinematics FEBiphasicSolver::UpdateKinematics(ui); // update solute-poroelastic data UpdateSolute(ui); } //----------------------------------------------------------------------------- //! Updates the solute data void FEBiphasicSoluteSolver::UpdateSolute(vector<double>& ui) { 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 (int i=0; i<mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); // update nodal concentration for (int j=0; j<MAX_CDOFS; ++j) { int 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) ct = 0.0; node.set(m_dofC[j], ct); } } for (int j=0; j<MAX_DDOFS; ++j) { int n = node.m_ID[m_dofD[j]]; // Force the concentrations to remain positive if (n >= 0) { double ct = 0 + m_Ut[n] + m_Ui[n] + ui[n]; if (ct < 0) ct = 0.0; node.set(m_dofD[j], ct); } } } // update solute data for (int 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); } } //----------------------------------------------------------------------------- //! Save data to dump file void FEBiphasicSoluteSolver::Serialize(DumpStream& ar) { FEBiphasicSolver::Serialize(ar); if (ar.IsShallow()) return; ar & m_Ctol & m_nceq & m_dofC & m_dofD; ar & m_ci; ar & m_Ci; }
C++
3D
febiosoftware/FEBio
FEBioMix/FETriphasic.h
.h
5,309
147
/*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" #include "FESoluteInterface.h" //----------------------------------------------------------------------------- //! Base class for triphasic materials. class FEBIOMIX_API FETriphasic : public FEMaterial, public FESoluteInterface_T<FESolutesMaterialPoint> { public: FETriphasic(FEModel* pfem); // initialization bool Init() override; //! specialized material points void UpdateSpecializedMaterialPoints(FEMaterialPoint& mp, const FETimeInfo& tp) override; // serialization void Serialize(DumpStream& ar) override; // returns a pointer to a new material point object FEMaterialPointData* CreateMaterialPointData() override { return new FESolutesMaterialPoint(new FEBiphasicMaterialPoint(m_pSolid->CreateMaterialPointData())); } // Get the elastic component (overridden from FEMaterial) FEElasticMaterial* GetElasticMaterial() { return m_pSolid; } public: //! calculate stress at material point mat3ds Stress(FEMaterialPoint& pt); //! calculate tangent stiffness at material point tens4ds Tangent(FEMaterialPoint& pt); //! calculate fluid (solvent) flux vec3d FluidFlux(FEMaterialPoint& pt); //! calculate solute molar flux vec3d SoluteFlux(FEMaterialPoint& pt, const int ion); //! actual fluid pressure (as opposed to effective pressure) double Pressure(FEMaterialPoint& pt); //! actual concentration (as opposed to effective concentration) double Concentration(FEMaterialPoint& pt, const int ion); //! porosity double Porosity(FEMaterialPoint& pt); //! fixed charge density double FixedChargeDensity(FEMaterialPoint& pt); //! electric potential double ElectricPotential(FEMaterialPoint& pt, const bool eform=false); //! current density vec3d CurrentDensity(FEMaterialPoint& pt); //! partition coefficient double PartitionCoefficient(FEMaterialPoint& pt, const int sol); //! partition coefficient derivatives void PartitionCoefficientFunctions(FEMaterialPoint& mp, vector<double>& kappa, vector<double>& dkdJ, vector< vector<double> >& dkdc); //! fluid density double FluidDensity() { return m_rhoTw; } //! solute density double SoluteDensity(const int ion) { return m_pSolute[ion]->Density(); } //! solute molar mass double SoluteMolarMass(const int ion) { return m_pSolute[ion]->MolarMass(); } //! solute charge number int SoluteChargeNumber(const int ion) { return m_pSolute[ion]->ChargeNumber(); } //! Add a solute component void AddSolute(FESolute* ps); // solute interface public: int Solutes() override { return (int)m_pSolute.size(); } FESolute* GetSolute(int i) override { return m_pSolute[i]; } double GetReferentialFixedChargeDensity(const FEMaterialPoint& mp) override; FEOsmoticCoefficient* GetOsmoticCoefficient() override { return m_pOsmC; } double GetFixedChargeDensity(const FEMaterialPoint& mp) override { const FESolutesMaterialPoint* spt = (mp.ExtractData<FESolutesMaterialPoint>()); return spt->m_cF; } public: FEElasticMaterial* GetSolid() { return m_pSolid; } FEHydraulicPermeability* GetPermeability() { return m_pPerm; } public: // material parameters FEParamDouble m_phi0; //!< solid volume fraction in reference configuration double m_rhoTw; //!< true fluid density FEParamDouble m_cFr; //!< fixed charge density in reference configurations double m_penalty; //!< penalty for enforcing electroneutrality public: double m_Rgas; //!< universal gas constant double m_Tabs; //!< absolute temperature double m_Fc; //!< Faraday's constant public: // material properties FEElasticMaterial* m_pSolid; //!< pointer to elastic solid material FEHydraulicPermeability* m_pPerm; //!< pointer to permeability material FEOsmoticCoefficient* m_pOsmC; //!< pointer to osmotic coefficient material std::vector<FESolute*> m_pSolute; //!< pointer to solute materials DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESolubManning.h
.h
3,599
86
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <FECore/FEFunction1D.h> #include "FESolute.h" //----------------------------------------------------------------------------- // This class implements a material that has a solute solubility that follows // the Wells-Manning theory. The mobile ion-mobile ion correction from Wells // is provided by a loadcurve. //----------------------------------------------------------------------------- class FEBIOMIX_API FESolubManning : public FESoluteSolubility { public: //! constructor FESolubManning(FEModel* pfem); //! Initialization bool Init() override; //! solubility double Solubility(FEMaterialPoint& pt) override; //! Tangent of solubility with respect to strain double Tangent_Solubility_Strain(FEMaterialPoint& mp) override; //! Tangent of solubility with respect to concentration double Tangent_Solubility_Concentration(FEMaterialPoint& mp, const int isol) override; //! Cross derivative of solubility with respect to strain and concentration double Tangent_Solubility_Strain_Concentration(FEMaterialPoint& mp, const int isol) override; //! Second derivative of solubility with respect to strain double Tangent_Solubility_Strain_Strain(FEMaterialPoint& mp) override; //! Second derivative of solubility with respect to concentration double Tangent_Solubility_Concentration_Concentration(FEMaterialPoint& mp, const int isol, const int jsol) override; //! Manning response double Solubility_Manning(FEMaterialPoint& mp); double Tangent_Solubility_Strain_Manning(FEMaterialPoint& mp); double Tangent_Solubility_Concentration_Manning (FEMaterialPoint& mp, const int isol); //! Wells response double Solubility_Wells(FEMaterialPoint& mp); double Tangent_Solubility_Strain_Wells(FEMaterialPoint& mp); double Tangent_Solubility_Concentration_Wells(FEMaterialPoint& mp, const int isol); public: double m_ksi; //!< Manning parameter int m_sol; //!< global id of co-ion int m_lsol; //!< local id of co-ion bool m_bcoi; //!< true if this solute is the co-ion FEFunction1D* m_solub; //!< solubility from Wells correction // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/FESoluteInterface.cpp
.cpp
1,727
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) 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/FEMaterialPoint.h> #include "FESoluteInterface.h" #include "FESolute.h" //----------------------------------------------------------------------------- //! Returns the local solute index given the global ID int FESoluteInterface::FindLocalSoluteID(int nid) { int lsid = -1; for (int isol = 0; isol<Solutes(); ++isol) if (GetSolute(isol)->GetSoluteID() == nid) { lsid = isol; break; } return lsid; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicDomain.cpp
.cpp
1,729
47
/*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 "FEBiphasicDomain.h" #include "FECore/FEModel.h" //----------------------------------------------------------------------------- FEBiphasicDomain::FEBiphasicDomain(FEModel* pfem) : FEElasticDomain(pfem) { m_pMat = 0; if (pfem) { m_dofP = pfem->GetDOFIndex("p"); m_dofQ = pfem->GetDOFIndex("q"); m_dofVX = pfem->GetDOFIndex("vx"); m_dofVY = pfem->GetDOFIndex("vy"); m_dofVZ = pfem->GetDOFIndex("vz"); } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMassActionForward.cpp
.cpp
5,017
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.*/ #include "stdafx.h" #include "FEMassActionForward.h" #include "FESoluteInterface.h" #include "FEBiphasic.h" BEGIN_FECORE_CLASS(FEMassActionForward, FEChemicalReaction) END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMassActionForward::FEMassActionForward(FEModel* pfem) : FEChemicalReaction(pfem) { // set material properties ADD_PROPERTY(m_pFwd, "forward_rate", FEProperty::Optional); } //----------------------------------------------------------------------------- //! molar supply at material point double FEMassActionForward::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->GetActualSoluteConcentration(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 FEMassActionForward::Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) { const int nsol = m_nsol; const int nsbm = (int)m_v.size() - nsol; 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/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); dzhatde += I * (m_vR[isol] * dkdJ / k); } 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 FEMassActionForward::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 FEMassActionForward::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; 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); dzhatdc += m_vR[isol]*dkdc/k; if ((isol == sol) && (c > 0)) dzhatdc += m_vR[isol]/c; } dzhatdc *= zhat; return dzhatdc; }
C++
3D
febiosoftware/FEBio
FEBioMix/FERemodelingSolid.cpp
.cpp
5,985
174
/*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 "FERemodelingSolid.h" #include <FECore/log.h> #include <FEBioMech/FEElasticMixture.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FERemodelingSolid, FEElasticMaterial) ADD_PARAMETER(m_sbm , "sbm")->setEnums("$(sbms)"); ADD_PROPERTY (m_pMat, "solid"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- bool FERemodelingSolid::Init() { if (FEElasticMaterial::Init() == false) return false; // get the parent material which must be a multiphasic material m_pMP = GetAncestor()->ExtractProperty<FEMultiphasic>(); if (m_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 = m_pMP->FindLocalSBMID(m_sbm); if (m_lsbm == -1) { feLogError("Invalid value for sbm"); return false; } FEElasticMaterial* pem = m_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 FERemodelingSolid::Serialize(DumpStream& ar) { FEElasticMaterial::Serialize(ar); if (ar.IsShallow()) return; ar & m_lsbm; } //----------------------------------------------------------------------------- //! Create material point data FEMaterialPointData* FERemodelingSolid::CreateMaterialPointData() { return new FERemodelingMaterialPoint(new FEElasticMaterialPoint); } //----------------------------------------------------------------------------- //! update specialize material point data void FERemodelingSolid::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 FERemodelingSolid::StrainEnergy(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; double rho0 = m_pMP->SBMDensity(m_lsbm); double w = rhor/rho0; double sed = m_pMat->StrainEnergyDensity(mp)*w; return sed; } //----------------------------------------------------------------------------- mat3ds FERemodelingSolid::Stress(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; double rho0 = m_pMP->SBMDensity(m_lsbm); double w = rhor/rho0; mat3ds s = m_pMat->Stress(mp)*w; return s; } //----------------------------------------------------------------------------- tens4ds FERemodelingSolid::Tangent(FEMaterialPoint& mp) { FESolutesMaterialPoint& spt = *mp.ExtractData<FESolutesMaterialPoint>(); double rhor = spt.m_sbmr[m_lsbm]; double rho0 = m_pMP->SBMDensity(m_lsbm); double w = rhor/rho0; tens4ds c = m_pMat->Tangent(mp)*w; return c; } //----------------------------------------------------------------------------- //! evaluate referential mass density double FERemodelingSolid::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 FERemodelingSolid::Tangent_SE_Density(FEMaterialPoint& mp) { double rho0 = m_pMP->SBMDensity(m_lsbm); return m_pMat->StrainEnergyDensity(mp)/rho0; } //----------------------------------------------------------------------------- //! calculate tangent of stress with mass density mat3ds FERemodelingSolid::Tangent_Stress_Density(FEMaterialPoint& mp) { double rho0 = m_pMP->SBMDensity(m_lsbm); return m_pMat->Stress(mp)/rho0; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESolventSupplyStarling.h
.h
2,494
63
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEBiphasic.h" //----------------------------------------------------------------------------- // This class implements a material that has a solvent supply following // Starling's equation class FEBIOMIX_API FESolventSupplyStarling : public FESolventSupply { public: //! constructor FESolventSupplyStarling(FEModel* pfem); //! Solute supply double Supply(FEMaterialPoint& pt) override; //! Tangent of supply with respect to strain mat3ds Tangent_Supply_Strain(FEMaterialPoint& mp) override; //! Tangent of supply with respect to pressure double Tangent_Supply_Pressure(FEMaterialPoint& mp) override; //! Tangent of supply with respect to concentration double Tangent_Supply_Concentration(FEMaterialPoint& mp, const int isol); //! Initialization bool Init() override { return FESolventSupply::Init(); } public: FEParamDouble m_kp; //!< coefficient of pressure drop FEParamDouble m_pv; //!< prescribed (e.g., vascular) pressure vector<FEParamDouble> m_qc; //!< coefficients of concentration drops vector<FEParamDouble> m_cv; //!< prescribed (e.g., vascular) concentrations // declare parameter list DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FEBioMix/stdafx.h
.h
1,310
31
/*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 <stdlib.h>
Unknown
3D
febiosoftware/FEBio
FEBioMix/FEOsmCoefManning.cpp
.cpp
8,422
244
/*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 "FEOsmCoefManning.h" #include "FEMultiphasic.h" #include <FECore/log.h> #include <FECore/FECoreKernel.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FEOsmCoefManning, FEOsmoticCoefficient) ADD_PARAMETER(m_ksi , FE_RANGE_GREATER_OR_EQUAL(0.0), "ksi" ); ADD_PARAMETER (m_sol , "co_ion")->setEnums("$(solutes)"); ADD_PROPERTY(m_osmc, "osmc")->SetLongName("Wells osmotic coefficient"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FEOsmCoefManning::FEOsmCoefManning(FEModel* pfem) : FEOsmoticCoefficient(pfem) { m_ksi = 1; m_sol = -1; m_lsol = -1; m_osmc = nullptr; } //----------------------------------------------------------------------------- bool FEOsmCoefManning::Init() { // get the ancestor material which must be a multiphasic material FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); if (psm == nullptr) { feLogError("Ancestor material must have solutes"); return false; } // extract the local id of the solute from the global id // m_sol must be one-based m_lsol = psm->FindLocalSoluteID(m_sol); if (m_lsol == -1) { feLogError("Invalid value for sol"); return false; } if (m_osmc == nullptr) { feLogError("function for osmc not specified"); return false; } return FEOsmoticCoefficient::Init(); } //----------------------------------------------------------------------------- //! Osmotic coefficient double FEOsmCoefManning::OsmoticCoefficient(FEMaterialPoint& mp) { double phiPM = OsmoticCoefficient_Manning(mp); double phiMM = OsmoticCoefficient_Wells(mp); return phiPM + phiMM - 1; } //----------------------------------------------------------------------------- //! Tangent of osmotic coefficient with respect to strain double FEOsmCoefManning::Tangent_OsmoticCoefficient_Strain(FEMaterialPoint &mp) { double dphiPMdJ = Tangent_OsmoticCoefficient_Strain_Manning(mp); double dphiMMdJ = Tangent_OsmoticCoefficient_Strain_Wells(mp); return dphiPMdJ + dphiMMdJ; } //----------------------------------------------------------------------------- //! Tangent of osmotic coefficient with respect to concentration double FEOsmCoefManning::Tangent_OsmoticCoefficient_Concentration(FEMaterialPoint &mp, const int isol) { double dphiPMdc = Tangent_OsmoticCoefficient_Concentration_Manning(mp,isol); double dphiMMdc = Tangent_OsmoticCoefficient_Concentration_Wells(mp,isol); return dphiPMdc + dphiMMdc; } //----------------------------------------------------------------------------- //! Osmotic coefficient double FEOsmCoefManning::OsmoticCoefficient_Manning(FEMaterialPoint& mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); // evaluate X = FCD/co-ion actual concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double cF = fabs(psm->GetFixedChargeDensity(mp)); double X = 0; if (ca > 0) X = cF/ca; // --- Manning osmotic coefficient --- double osmcoef; if (m_ksi <= 1) osmcoef = 1 - 0.5*m_ksi*X/(X+2); else osmcoef = (0.5*X/m_ksi+2)/(X+2); assert(osmcoef>0); return osmcoef; } //----------------------------------------------------------------------------- //! Tangent of osmotic coefficient with respect to strain double FEOsmCoefManning::Tangent_OsmoticCoefficient_Strain_Manning(FEMaterialPoint &mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // evaluate X = FCD/co-ion actual concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double cF = fabs(psm->GetFixedChargeDensity(mp)); double kt = psm->GetPartitionCoefficient(mp, m_lsol); double dktdJ = psm->dkdJ(mp, m_lsol); double X = 0; if (ca > 0) X = cF/ca; // evaluate dX/dJ double J = pt.m_J; double phisr = pbm->GetReferentialSolidVolumeFraction(mp); double dXdJ = -(1./(J-phisr)+dktdJ/kt)*X; double dosmdX; if (m_ksi <= 1) dosmdX = -m_ksi/pow(X+2, 2); else dosmdX = (1-2*m_ksi)/m_ksi/pow(X+2, 2); return dosmdX*dXdJ; } //----------------------------------------------------------------------------- //! Tangent of osmotic coefficient with respect to concentration double FEOsmCoefManning::Tangent_OsmoticCoefficient_Concentration_Manning(FEMaterialPoint &mp, const int isol) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); // evaluate X = FCD/co-ion actual concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double cF = fabs(psm->GetFixedChargeDensity(mp)); double kta = psm->GetPartitionCoefficient(mp, m_lsol); double kt = psm->GetPartitionCoefficient(mp, isol); int zt = psm->GetSolute(isol)->ChargeNumber(); double X = 0; if (ca > 0) X = cF/ca; // evaluate dX/dc double dXdc = -zt*kt/ca; if (isol == m_lsol) dXdc -= kta*X/ca; double dosmdX; if (m_ksi <= 1) dosmdX = -m_ksi/pow(X+2, 2); else dosmdX = (1./m_ksi-2)/pow(X+2, 2); return dosmdX*dXdc; } //----------------------------------------------------------------------------- //! Osmotic coefficient double FEOsmCoefManning::OsmoticCoefficient_Wells(FEMaterialPoint& mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double osmc = m_osmc->value(ca); assert(osmc>0); return osmc; } //----------------------------------------------------------------------------- //! Tangent of osmotic coefficient with respect to strain double FEOsmCoefManning::Tangent_OsmoticCoefficient_Strain_Wells(FEMaterialPoint &mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double c = psm->GetEffectiveSoluteConcentration(mp, m_lsol); double dkdJ = psm->dkdJ(mp, m_lsol); double f = dkdJ*c; double dosmc = m_osmc->derive(ca); return dosmc*f; } //----------------------------------------------------------------------------- //! Tangent of osmotic coefficient with respect to concentration double FEOsmCoefManning::Tangent_OsmoticCoefficient_Concentration_Wells(FEMaterialPoint &mp, const int isol) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double c = psm->GetEffectiveSoluteConcentration(mp, m_lsol); double k = psm->GetPartitionCoefficient(mp, m_lsol); double dkdc = psm->dkdc(mp, m_lsol, isol); double f = dkdc*c; if (isol == m_lsol) f += k; double dosmc = m_osmc->derive(ca); return dosmc*f; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESlidingInterfaceBiphasicMixed.cpp
.cpp
102,626
2,720
/*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 "FESlidingInterfaceBiphasicMixed.h" #include "FEBiphasic.h" #include "FECore/FEAnalysis.h" #include "FECore/FENormalProjection.h" #include <FECore/FELinearSystem.h> #include "FECore/log.h" #include <FEBioMech/FEBioMech.h> #include "FEBioMix.h" #include <FECore/FEModel.h> //----------------------------------------------------------------------------- // Define sliding interface parameters BEGIN_FECORE_CLASS(FESlidingInterfaceBiphasicMixed, 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_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_bsymm , "symmetric_stiffness"); ADD_PARAMETER(m_srad , "search_radius" )->setUnits(UNIT_LENGTH);; ADD_PARAMETER(m_nsegup , "seg_up" ); ADD_PARAMETER(m_naugmin , "minaug" ); ADD_PARAMETER(m_naugmax , "maxaug" ); 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_bflips , "flip_primary" ); ADD_PARAMETER(m_bflipm , "flip_secondary" ); ADD_PARAMETER(m_bshellbs , "shell_bottom_primary" ); ADD_PARAMETER(m_bshellbm , "shell_bottom_secondary"); END_FECORE_CLASS(); //----------------------------------------------------------------------------- // FESlidingSurfaceBiphasic //----------------------------------------------------------------------------- FESlidingSurfaceBiphasicMixed::FESlidingSurfaceBiphasicMixed(FEModel* pfem) : FEBiphasicContactSurface(pfem) { m_bporo = false; } //----------------------------------------------------------------------------- //! create material point data FEMaterialPoint* FESlidingSurfaceBiphasicMixed::CreateMaterialPoint() { return new FEBiphasicContactPoint; } //----------------------------------------------------------------------------- bool FESlidingSurfaceBiphasicMixed::Init() { // get the displacement and fluid pressure variable indices. FEModel* fem = GetFEModel(); m_varU = fem->GetDOFS().GetVariableIndex(FEBioMech::GetVariableName(FEBioMech::DISPLACEMENT)); assert(m_varU >= 0); m_varP = fem->GetDOFS().GetVariableIndex(FEBioMix::GetVariableName(FEBioMix::FLUID_PRESSURE)); assert(m_varP >= 0); // initialize surface data first if (FEBiphasicContactSurface::Init() == false) return false; // allocate node normals and contact tractions m_nn.assign(Nodes(), vec3d(0,0,0)); m_tn.assign(Nodes(), vec3d(0,0,0)); m_pn.assign(Nodes(), 0); // determine biphasic status m_poro.resize(Elements(),false); for (int i=0; i<Elements(); ++i) { // get the surface element FESurfaceElement& se = Element(i); // 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()); // see if this is a poro-elastic element FEBiphasic* biph = dynamic_cast<FEBiphasic*> (pm); if (biph) { m_poro[i] = true; m_bporo = true; } } } return true; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::InitSlidingSurface() { for (int i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); int nint = el.GaussPoints(); for (int j=0; j<nint; ++j) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(j)); // Store current surface projection values as previous 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 FESlidingSurfaceBiphasicMixed::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 tractions by averaging values from surrounding //! faces. This function ensures that nodal contact tractions are always //! compressive, so that they can be used to detect free-draining status. void FESlidingSurfaceBiphasicMixed::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 tractions 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 FESlidingSurfaceBiphasicMixed::UpdateNodeNormals() { const int MN = FEElement::MAX_NODES; vec3d y[MN]; // zero nodal normals zero(m_nn); // loop over all elements for (int i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); int ne = el.Nodes(); // get the nodal coordinates for (int j=0; j<ne; ++j) y[j] = Node(el.m_lnode[j]).m_rt; // calculate the normals for (int j=0; j<ne; ++j) { int jp1 = (j+1)%ne; int jm1 = (j+ne-1)%ne; vec3d n = (y[jp1] - y[j]) ^ (y[jm1] - y[j]); m_nn[el.m_lnode[j]] += n; } } // normalize all vectors const int N = Nodes(); for (int i=0; i<N; ++i) m_nn[i].unit(); } //----------------------------------------------------------------------------- vec3d FESlidingSurfaceBiphasicMixed::GetContactForce() { return m_Ft; } //----------------------------------------------------------------------------- double FESlidingSurfaceBiphasicMixed::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 FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(i)); if (data.m_Ln > 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; } } } return a; } //----------------------------------------------------------------------------- vec3d FESlidingSurfaceBiphasicMixed::GetFluidForce() { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_d = dofs.GetVariableInterpolationOrder(m_varU); int degree_p = dofs.GetVariableInterpolationOrder(m_varP); const int MN = FEElement::MAX_NODES; double pn[MN]; // initialize contact force vec3d f(0,0,0); // loop over all elements of the surface for (int n=0; n<Elements(); ++n) { FESurfaceElement& el = Element(n); int nseln = el.Nodes(); // nodal pressures int npdof = el.ShapeFunctions(degree_p); for (int i=0; i<npdof; ++i) pn[i] = GetMesh()->Node(el.m_node[i]).get(m_dofP); // evaluate the fluid force for that element int nint = el.GaussPoints(); for (int 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 double p = el.eval(degree_p, pn, i); // contact force f += n*(w*p); } } return f; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::Serialize(DumpStream& ar) { FEBiphasicContactSurface::Serialize(ar); ar & m_bporo; ar & m_poro; ar & m_nn; ar & m_pn; ar & m_tn; ar & m_Ft; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::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) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_dg; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::GetContactPressure(int nface, double& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = 0; for (int k = 0; k < ni; ++k) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_Ln; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::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) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(k)); pt += data.m_tr; } pt /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::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) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(k)); if (!data.m_bstick) pt += data.m_s1; } pt /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::GetMuEffective(int nface, double& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = 0; for (int k = 0; k < ni; ++k) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_mueff; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::GetLocalFLS(int nface, double& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = 0; for (int k = 0; k < ni; ++k) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(k)); pg += data.m_fls; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::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) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(k)); gi[k] = data.m_dg; } el.project_to_nodes(gi, pg); } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::GetNodalContactPressure(int nface, double* pg) { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_p = dofs.GetVariableInterpolationOrder(m_varP); FESurfaceElement& el = Element(nface); int npdof = el.ShapeFunctions(degree_p); for (int k=0; k<npdof; ++k) pg[k] = m_pn[el.m_lnode[k]]; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::GetStickStatus(int nface, double& pg) { FESurfaceElement& el = Element(nface); int ni = el.GaussPoints(); pg = 0; for (int k = 0; k < ni; ++k) { FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(k)); if (data.m_bstick) pg += 1.0; } pg /= ni; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::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]]; } //----------------------------------------------------------------------------- void FESlidingSurfaceBiphasicMixed::UnpackLM(FEElement& el, vector<int>& lm) { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_d = dofs.GetVariableInterpolationOrder(m_varU); int degree_p = dofs.GetVariableInterpolationOrder(m_varP); // We should allocate the number of shapefunctions for each variable, // but for now, we allocate assuming the shape functions equals the nodes. // We can do this, because the nodes that don't have a pressure dof, // will have their id set to -1. int N = el.Nodes(); lm.assign(N * 4, -1); // 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 if (m_dofP >= 0) lm[3 * N + i] = id[m_dofP]; } } //----------------------------------------------------------------------------- // FESlidingInterfaceBiphasicMixed //----------------------------------------------------------------------------- FESlidingInterfaceBiphasicMixed::FESlidingInterfaceBiphasicMixed(FEModel* pfem) : FEContactInterface(pfem), m_ss(pfem), m_ms(pfem) { static int count = 1; SetID(count++); // initial values m_knmult = 0; m_atol = 0.1; m_epsn = 1; m_epsp = 1; m_btwo_pass = false; m_stol = 0.01; m_bsymm = true; m_srad = 1.0; m_gtol = 0; m_ptol = 0; m_nsegup = 0; m_bautopen = false; m_breloc = false; m_bsmaug = false; m_bsmfls = true; m_bupdtpen = false; m_mu = 0.0; m_phi = 0.0; m_naugmin = 0; m_naugmax = 10; m_bfreeze = false; m_bflipm = m_bflips = false; m_bshellbm = m_bshellbs = false; m_dofP = pfem->GetDOFIndex("p"); // set parents m_ss.SetContactInterface(this); m_ms.SetContactInterface(this); m_ss.SetSibling(&m_ms); m_ms.SetSibling(&m_ss); } //----------------------------------------------------------------------------- FESlidingInterfaceBiphasicMixed::~FESlidingInterfaceBiphasicMixed() { } //----------------------------------------------------------------------------- bool FESlidingInterfaceBiphasicMixed::Init() { // initialize surface data if (m_ss.Init() == false) return false; if (m_ms.Init() == false) return false; // Flip secondary and primary surfaces, if requested. // Note that we turn off those flags because otherwise we keep flipping, each time we get here (e.g. in optimization) // TODO: Of course, we shouldn't get here more than once. I think we also get through the FEModel::Reset, so I'll have // look into that. if (m_bflips) { m_ss.Invert(); m_bflips = false; } if (m_bflipm) { m_ms.Invert(); m_bflipm = false; } if (m_bshellbs) { m_ss.SetShellBottom(m_bshellbs); m_bshellbs = false; } if (m_bshellbm) { m_ms.SetShellBottom(m_bshellbm); m_bshellbm = false; } return true; } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::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_RU = fem.GetDOFIndex("Ru"); const int dof_RV = fem.GetDOFIndex("Rv"); const int dof_RW = fem.GetDOFIndex("Rw"); vector<int> lm(7*FEElement::MAX_NODES*2); int npass = (m_btwo_pass?2:1); for (int np=0; np<npass; ++np) { FESlidingSurfaceBiphasicMixed& 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) { FEBiphasicContactPoint& pt = static_cast<FEBiphasicContactPoint&>(*se.GetMaterialPoint(k)); FESurfaceElement* pe = pt.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[7*l ] = id[dof_X]; lm[7*l+1] = id[dof_Y]; lm[7*l+2] = id[dof_Z]; lm[7*l+3] = id[dof_P]; lm[7*l+4] = id[dof_RU]; lm[7*l+5] = id[dof_RV]; lm[7*l+6] = id[dof_RW]; } for (l=0; l<nmeln; ++l) { vector<int>& id = mesh.Node(mn[l]).m_ID; lm[7*(l+nseln) ] = id[dof_X]; lm[7*(l+nseln)+1] = id[dof_Y]; lm[7*(l+nseln)+2] = id[dof_Z]; lm[7*(l+nseln)+3] = id[dof_P]; lm[7*(l+nseln)+4] = id[dof_RU]; lm[7*(l+nseln)+5] = id[dof_RV]; lm[7*(l+nseln)+6] = id[dof_RW]; } K.build_add(lm); } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::UpdateAutoPenalty() { // calculate the penalty if (m_bautopen) { CalcAutoPenalty(m_ss); CalcAutoPenalty(m_ms); CalcAutoPressurePenalty(m_ss); CalcAutoPressurePenalty(m_ms); } } //----------------------------------------------------------------------------- //! This function is called during the initialization void FESlidingInterfaceBiphasicMixed::Activate() { // don't forget to call base member FEContactInterface::Activate(); UpdateAutoPenalty(); // update sliding interface data Update(); } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::CalcAutoPenalty(FESlidingSurfaceBiphasicMixed& 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) { FEBiphasicContactPoint& pt = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsn = eps; } } } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::CalcAutoPressurePenalty(FESlidingSurfaceBiphasicMixed& 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) { FEBiphasicContactPoint& pt = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(j)); pt.m_epsp = eps; } } } //----------------------------------------------------------------------------- double FESlidingInterfaceBiphasicMixed::AutoPressurePenalty(FESurfaceElement& el, FESlidingSurfaceBiphasicMixed& 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()); // see if this is a poro-elastic element FEBiphasic* biph = dynamic_cast<FEBiphasic*> (pm); if (biph == 0) return 0.0; // get a material point FEMaterialPoint& mp = *pe->GetMaterialPoint(0); FEElasticMaterialPoint& ept = *(mp.ExtractData<FEElasticMaterialPoint>()); // setup the material point ept.m_F = mat3dd(1.0); ept.m_J = 1; ept.m_s.zero(); // if this is a poroelastic element, then get the permeability tensor FEBiphasicMaterialPoint& pt = *(mp.ExtractData<FEBiphasicMaterialPoint>()); pt.m_p = 0; pt.m_w = vec3d(0,0,0); double K[3][3]; biph->Permeability(K, mp); double eps = n.x*(K[0][0]*n.x+K[0][1]*n.y+K[0][2]*n.z) +n.y*(K[1][0]*n.x+K[1][1]*n.y+K[1][2]*n.z) +n.z*(K[2][0]*n.x+K[2][1]*n.y+K[2][2]*n.z); // 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 FESlidingInterfaceBiphasicMixed::ProjectSurface(FESlidingSurfaceBiphasicMixed& ss, FESlidingSurfaceBiphasicMixed& ms, bool bupseg, bool bmove) { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_d = dofs.GetVariableInterpolationOrder(ss.m_varU); int degree_p = dofs.GetVariableInterpolationOrder(ss.m_varP); FEMesh& mesh = GetFEModel()->GetMesh(); // initialize projection data FENormalProjection np(ms); np.SetTolerance(m_stol); np.SetSearchRadius(m_srad); np.Init(); double psf = GetPenaltyScaleFactor(); // 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 #pragma omp parallel for 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(); double ps[FEElement::MAX_INTPOINTS]; // get the nodal pressures if (sporo) { int npd = el.ShapeFunctions(degree_p); for (int j=0; j<npd; ++j) ps[j] = mesh.Node(el.m_node[j]).get(m_dofP); } for (int j=0; j<nint; ++j) { // get the integration point data FEBiphasicContactPoint& pt = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(j)); // calculate the global position of the integration point vec3d r = ss.Local2Global(el, j); // get the pressure at the integration point double p1 = 0; if (sporo) p1 = el.eval(degree_p, ps, j); // calculate the normal at this integration point vec3d nu = ss.SurfaceNormal(el, j); // first see if the old intersected face is still good enough FESurfaceElement* pme = pt.m_pme; double rs[2] = {0,0}; 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; double Ln = pt.m_Lmd + eps*g; pt.m_gap = (g <= m_srad? g : 0); // calculate the pressure gap function bool mporo = ms.m_poro[pme->m_lid]; if ((Ln >= 0) && (g <= m_srad)) { // get the pressure at the projection point double p2 = 0; if (mporo) { double pm[FEElement::MAX_NODES]; int npdof = pme->ShapeFunctions(degree_p); for (int k=0; k<npdof; ++k) pm[k] = mesh.Node(pme->m_node[k]).get(m_dofP); p2 = pme->eval(degree_p, 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; } } else { pt.m_Lmd = 0; pt.m_pme = 0; pt.m_gap = 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; } } } 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; } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::Update() { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_p = dofs.GetVariableInterpolationOrder(m_ss.m_varP); static int naug = 0; static int biter = 0; FEModel& fem = *GetFEModel(); // 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)); 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 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; // update node normals m_ss.UpdateNodeNormals(); if (bporo) 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 dofs. // If the nodes are not in contact, they must be free // draining. Since all nodes have been previously marked to be // free-draining in MarkFreeDraining(), 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) { FESlidingSurfaceBiphasicMixed& ss = (np == 0? m_ss : m_ms); FESlidingSurfaceBiphasicMixed& ms = (np == 0? m_ms : m_ss); // loop over all the nodes of the primary surface for (int n=0; n<ss.Nodes(); ++n) { FENode& node = ss.Node(n); int id = node.m_ID[m_dofP]; if ((id < -1) && (ss.m_pn[n] > 0)) { // mark node as non-free-draining (= pos ID) node.m_ID[m_dofP] = -id-2; } } // loop over all nodes of the secondary surface // the secondary surface is trickier since we need // to look at the primary surface's projection if (ms.m_bporo) { FENormalProjection np(ss); np.SetTolerance(m_stol); np.SetSearchRadius(m_srad); np.Init(); for (int n=0; n<ms.Nodes(); ++n) { // get the node FENode& node = ms.Node(n); // project it onto the primary surface double rs[2] = {0,0}; FESurfaceElement* pse = np.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); 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]; int N = pse->ShapeFunctions(degree_p); for (int i=0; i<N; ++i) tn[i] = ss.m_pn[pse->m_lnode[i]]; // now evaluate the traction at the intersection point double tp = pse->eval(degree_p, tn, rs[0], rs[1]); // if tp > 0, mark node as non-free-draining. (= pos ID) int id = node.m_ID[m_dofP]; if ((id < -1) && (tp > 0)) { // mark as non free-draining node.m_ID[m_dofP] = -id-2; } } } } } } } //----------------------------------------------------------------------------- vec3d FESlidingInterfaceBiphasicMixed::SlipTangent(FESlidingSurfaceBiphasicMixed& ss, const int nel, const int nint, FESlidingSurfaceBiphasicMixed& 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 FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*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 FESlidingInterfaceBiphasicMixed::ContactTraction(FESlidingSurfaceBiphasicMixed& ss, const int nel, const int n, FESlidingSurfaceBiphasicMixed& ms, double& pn) { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_d = dofs.GetVariableInterpolationOrder(ss.m_varU); int degree_p = dofs.GetVariableInterpolationOrder(ss.m_varP); 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(); // get the mesh FEMesh& m = GetFEModel()->GetMesh(); // get the primary surface element FESurfaceElement& se = ss.Element(nel); // get the integration point data FEBiphasicContactPoint& data = static_cast<FEBiphasicContactPoint&>(*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 poro status of primary surface bool sporo = ss.m_poro[nel]; // 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 double fls = 0; if (m_bsmfls) { double lfls[FEElement::MAX_INTPOINTS]; ss.GetGPLocalFLS(nel, lfls); 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 : p/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_poro[pme->m_lid]; if (sporo && mporo) { double pm[FEElement::MAX_NODES]; int npdof = pme->ShapeFunctions(degree_p); for (int k=0; k<npdof; ++k) pm[k] = m.Node(pme->m_node[k]).get(m_dofP); double p2 = pme->eval(degree_p, pm, data.m_rs[0], data.m_rs[1]); data.m_pg = p - p2; } } 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 : p/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*(-pn) - s1*pn*data.m_mueff; // 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 : p/(-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 : p/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_poro[pme->m_lid]; 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; } } 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 : p/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*(-pn) - s1*pn*data.m_mueff; // 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 : p/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*(-pn) - s1*pn*data.m_mueff; // reset slip direction data.m_s1 = s1; data.m_bstick = false; } } } } return t; } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::LoadVector(FEGlobalVector& R, const FETimeInfo& tp) { // we will also calculate net contact forces, so zero them here 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 FESlidingSurfaceBiphasicMixed& ss = (np == 0 ? m_ss : m_ms); FESlidingSurfaceBiphasicMixed& ms = (np == 0 ? m_ms : m_ss); // assemble the load vector for this pass LoadVector(ss, ms, R, tp); } } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::LoadVector(FESlidingSurfaceBiphasicMixed& ss, FESlidingSurfaceBiphasicMixed& ms, FEGlobalVector& R, const FETimeInfo& tp) { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_d = dofs.GetVariableInterpolationOrder(ss.m_varU); int degree_p = dofs.GetVariableInterpolationOrder(ss.m_varP); const int MN = FEElement::MAX_NODES; vector<int> sLM, mLM, LM, en; vector<double> fe; double detJ[MN], w[MN], *Hs, Hm[MN], Hmp[MN]; double N[4*MN*2]; // need to multiply biphasic force entries by the timestep double dt = tp.timeIncrement; // loop over all primary surface elements for (int i=0; i<ss.Elements(); ++i) { // get the surface element FESurfaceElement& se = ss.Element(i); // flag indicating that primary element is poro bool sporo = ss.m_poro[i]; // 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 the integration point data FEBiphasicContactPoint& pt = static_cast<FEBiphasicContactPoint&>(*se.GetMaterialPoint(j)); // calculate contact pressure and account for stick double pn; vec3d t = ContactTraction(ss, i, j, ms, pn); // get the secondary element FESurfaceElement* pme = pt.m_pme; if (pme) { // get the secondary element FESurfaceElement& me = *pme; // get the secondary element poro status bool mporo = ms.m_poro[pme->m_lid]; // 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) { // get the pressure dofs for each element int nspdof = se.ShapeFunctions(degree_p); int nmpdof = me.ShapeFunctions(degree_p); int npdof = nspdof + nmpdof; // evaluate shape functions double* Hsp = se.H(degree_p, j); me.shape_fnc(degree_p, Hmp, pt.m_rs[0], pt.m_rs[1]); // calculate the flow rate double epsp = m_epsp*pt.m_epsp; double wn = pt.m_Lmp + epsp*pt.m_pg; // fill the LM LM.resize(npdof, -1); for (int k=0; k<nspdof; ++k) LM[k ] = sLM[3*nseln+k]; for (int k=0; k<nmpdof; ++k) LM[k + nspdof] = mLM[3*nmeln+k]; // fill the force array fe.resize(npdof); zero(fe); for (int k=0; k<nspdof; ++k) N[k ] = Hsp[k]; for (int k=0; k<nmpdof; ++k) N[k + nspdof] = -Hmp[k]; for (int k=0; k<npdof; ++k) fe[k] += dt*wn*N[k]*detJ[j]*w[j]; // build the en vector en.resize(npdof); for (int k = 0; k<nspdof; ++k) en[k ] = se.m_node[k]; for (int k = 0; k<nmpdof; ++k) en[k + nspdof] = me.m_node[k]; // assemble residual R.Assemble(en, LM, fe); } } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) { // 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 FESlidingSurfaceBiphasicMixed& ss = (np == 0 ? m_ss : m_ms); FESlidingSurfaceBiphasicMixed& ms = (np == 0 ? m_ms : m_ss); // assemble stiffness matrix for this pass StiffnessMatrix(ss, ms, LS, tp); } } //----------------------------------------------------------------------------- //! calculate contact stiffness void FESlidingInterfaceBiphasicMixed::StiffnessMatrix(FESlidingSurfaceBiphasicMixed& ss, FESlidingSurfaceBiphasicMixed& ms, FELinearSystem& LS, const FETimeInfo& tp) { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_d = dofs.GetVariableInterpolationOrder(ss.m_varU); int degree_p = dofs.GetVariableInterpolationOrder(ss.m_varP); // see how many reformations we've had to do so far int nref = GetSolver()->m_nref; const int MN = FEElement::MAX_NODES; double detJ[MN], w[MN], *Hs, Hm[MN], Hmp[MN]; double N[4*MN*2], H[4*MN*2]; vector<int> sLM, mLM, LM, en; FEElementMatrix ke; FEModel& fem = *GetFEModel(); double psf = GetPenaltyScaleFactor(); FEMesh& mesh = *ms.GetMesh(); // loop over all primary surface elements for (int i=0; i<ss.Elements(); ++i) { // get the next element FESurfaceElement& se = ss.Element(i); // primary element's poro status bool sporo = ss.m_poro[i]; // get nr of nodes, integration points, pressure dofs int nseln = se.Nodes(); int nint = se.GaussPoints(); int nspdof = se.ShapeFunctions(degree_p); // nodal pressures of primary element double pn[MN] = {0}; if (sporo) { for (int j=0; j<nspdof; ++j) pn[j] = ss.GetMesh()->Node(se.m_node[j]).get(m_dofP); } // copy the LM vector 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 for (int j=0; j<nint; ++j) { // get integration point data FEBiphasicContactPoint& pt = static_cast<FEBiphasicContactPoint&>(*se.GetMaterialPoint(j)); // calculate contact pressure and account for stick double pn; vec3d t = ContactTraction(ss, i, j, ms, pn); // get the secondary element FESurfaceElement* pme = pt.m_pme; if (pme) { // get secondary element FESurfaceElement& me = *pme; // get secondary element's poro status bool mporo = ms.m_poro[pme->m_lid]; // get the nr of secondary nodes int nmeln = me.Nodes(); // get secondary pressure dofs int nmpdof = me.ShapeFunctions(degree_p); // nodal pressures of secondary nodes double pm[MN] = {0}; for (int k=0; k<nmpdof; ++k) pm[k] = ms.GetMesh()->Node(me.m_node[k]).get(m_dofP); // copy the LM vector ms.UnpackLM(me, mLM); // calculate degrees of freedom int ndpn; // number of dofs per node int ndof; // number of dofs in stiffness matrix if (sporo && mporo) { // calculate degrees of freedom for biphasic-on-biphasic contact ndpn = 4; ndof = ndpn*(nseln+nmeln); // build the LM vector LM.resize(ndof); for (int k=0; k<nseln; ++k) { LM[4*k ] = sLM[3*k ]; // x-dof LM[4*k+1] = sLM[3*k+1]; // y-dof LM[4*k+2] = sLM[3*k+2]; // z-dof LM[4*k+3] = sLM[3*nseln+k]; // p-dof } for (int k=0; k<nmeln; ++k) { LM[4*(k+nseln) ] = mLM[3*k ]; // x-dof LM[4*(k+nseln)+1] = mLM[3*k+1]; // y-dof LM[4*(k+nseln)+2] = mLM[3*k+2]; // z-dof LM[4*(k+nseln)+3] = mLM[3*nmeln+k]; // p-dof } } else { // calculate degrees of freedom for biphasic-on-elastic or elastic-on-elastic contact ndpn = 3; ndof = ndpn*(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]; // primary shape functions Hs = se.H(j); // get primary pressure shape functions double* Hsp = se.H(degree_p, j); // secondary shape functions double r = pt.m_rs[0]; double s = pt.m_rs[1]; me.shape_fnc(Hm, r, s); // get secondary pressure shape functions me.shape_fnc(degree_p, Hmp, 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) { double dtn = eps; // 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* Gsr = se.Gr(j); double* Gss = 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]*Gsr[k] - gscovh[0]*Gss[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 --- // a. I-term //------------------------------------ for (int k=0; k<nseln; ++k) N[k ] = Hs[k]; for (int k=0; k<nmeln; ++k) N[k+nseln] = -Hm[k]; double tmp = dtn*detJ[j]*w[j]; for (int l=0; l<nseln+nmeln; ++l) { for (int k=0; k<nseln+nmeln; ++k) { ke[k*ndpn ][l*ndpn ] -= -tmp*N[k]*N[l]*I[0][0]; ke[k*ndpn ][l*ndpn+1] -= -tmp*N[k]*N[l]*I[0][1]; ke[k*ndpn ][l*ndpn+2] -= -tmp*N[k]*N[l]*I[0][2]; ke[k*ndpn+1][l*ndpn ] -= -tmp*N[k]*N[l]*I[1][0]; ke[k*ndpn+1][l*ndpn+1] -= -tmp*N[k]*N[l]*I[1][1]; ke[k*ndpn+1][l*ndpn+2] -= -tmp*N[k]*N[l]*I[1][2]; ke[k*ndpn+2][l*ndpn ] -= -tmp*N[k]*N[l]*I[2][0]; ke[k*ndpn+2][l*ndpn+1] -= -tmp*N[k]*N[l]*I[2][1]; ke[k*ndpn+2][l*ndpn+2] -= -tmp*N[k]*N[l]*I[2][2]; } } // b. A-term //------------------------------------- tmp = detJ[j]*w[j]; // non-symmetric for (int l=0; l<nseln; ++l) { for (int k=0; k<nseln+nmeln; ++k) { ke[k*ndpn ][l*ndpn ] -= tmp*N[k]*As[l][0][0]; ke[k*ndpn ][l*ndpn+1] -= tmp*N[k]*As[l][0][1]; ke[k*ndpn ][l*ndpn+2] -= tmp*N[k]*As[l][0][2]; ke[k*ndpn+1][l*ndpn ] -= tmp*N[k]*As[l][1][0]; ke[k*ndpn+1][l*ndpn+1] -= tmp*N[k]*As[l][1][1]; ke[k*ndpn+1][l*ndpn+2] -= tmp*N[k]*As[l][1][2]; ke[k*ndpn+2][l*ndpn ] -= tmp*N[k]*As[l][2][0]; ke[k*ndpn+2][l*ndpn+1] -= tmp*N[k]*As[l][2][1]; ke[k*ndpn+2][l*ndpn+2] -= tmp*N[k]*As[l][2][2]; } } // --- B 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; double tmp = dt*w[j]*detJ[j]; double epsp = m_epsp*pt.m_epsp*psf; double wn = pt.m_Lmp + epsp*pt.m_pg; // --- S O L I D - P R E S S U R E C O N T A C T --- // b. A-term //------------------------------------- for (int l=0; l<nseln; ++l) { vec3d Acn = Ac[l]*nu; for (int k=0; k<nseln+nmeln; ++k) { ke[4*k + 3][4*l ] -= tmp*wn*N[k]*Acn.x; ke[4*k + 3][4*l+1] -= tmp*wn*N[k]*Acn.y; ke[4*k + 3][4*l+2] -= tmp*wn*N[k]*Acn.z; } } // --- P R E S S U R E - P R E S S U R E C O N T A C T --- // calculate the N-vector for (int k=0; k<nseln; ++k) { N[ndpn*k ] = 0; N[ndpn*k+1] = 0; N[ndpn*k+2] = 0; N[ndpn*k+3] = Hs[k]; } for (int k=0; k<nmeln; ++k) { N[ndpn*(k+nseln) ] = 0; N[ndpn*(k+nseln)+1] = 0; N[ndpn*(k+nseln)+2] = 0; N[ndpn*(k+nseln)+3] = -Hm[k]; } for (int k=0; k<ndof; ++k) for (int l=0; l<ndof; ++l) ke[k][l] -= tmp*epsp*N[k]*N[l]; } // 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 Nh1 = 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 Sh1 = (mat3dd(1) - (s1 & s1))*hd; mat3d Sb1 = s1 & (Nb1*nu); // evaluate m, c, Mg, and R // evaluate L1 from Mg and R // NOTE: Mg has the 1/detJ included in its definition vec3d m = ((dgscov[0] ^ gscov[1]) + (gscov[0] ^ dgscov[1])); vec3d c = Sh1*Nh1*m*(1/detJ[j]); mat3d Mg = (mat3dd(1)*(nu * m) + (nu & m))*(1/detJ[j]); mat3d B = (c & (Nb1*nu)) - Sh1*Nh1; mat3d R = mat3dd(1)*(nu * dr) + (nu & dr); mat3d L1 = Sh1*((Nh1*Mg - mat3dd(1))*(-g) + R)*Nh1; // evaluate Mc and Ac and combine them into As // evaluate Fc from Ac_bar (Ab) // evaluate Jc as L1*Ac-Fc double* Gsr = se.Gr(j); double* Gss = se.Gs(j); mat3d Ac[MN], As[MN], Pc[MN], Jc[MN]; 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]); for (int k=0; k<nseln; ++k) { vec3d mc = gscnt[0]*Gsr[k] + gscnt[1]*Gss[k]; mat3d Mc = nu & mc; Ac[k] = (gscovh[1]*Gsr[k] - gscovh[0]*Gss[k])/detJ[j]; mat3d Ab = (dgscovh[1]*Gsr[k] - dgscovh[0]*Gss[k])/detJ[j]; vec3d hcp = (N1*mc + Ac[k]*nu)*pt.m_mueff*(-g); vec3d hcm = (N1*mc*m_mu - Ac[k]*nu*pt.m_mueff); As[k] = (Ac[k] + Mc*N1); mat3d Jc = (L1*Ac[k]) - Sh1*Nh1*Ab*(-g); Pc[k] = (s1 & hcm) + (c & hcp) - Jc*pt.m_mueff; } // evaluate mb and Mb // evaluate s1 dyad mb and combine as Pb double Gmr[MN], Gms[MN]; me.shape_deriv(Gmr, Gms, r, s); vec3d mb[MN]; mat3d Pb[MN]; for (int k=0; k<nmeln; ++k) { mb[k] = gmcnt[0]*Gmr[k] + gmcnt[1]*Gms[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]*Gmr[b]*Gsr[c] + a[0][1]*Gmr[b]*Gss[c] + a[1][0]*Gms[b]*Gsr[c] + a[1][1]*Gms[b]*Gss[c])*(-g); } } // define T, Ttb mat3d T = N1 + S1*pt.m_mueff; mat3d Ttb = Nt1 + Sb1*m_mu; // --- S O L I D - S O L I D C O N T A C T --- // a. NxN-term //------------------------------------ for (int k=0; k<nseln; ++k) N[k ] = Hs[k]; for (int k=0; k<nmeln; ++k) N[k+nseln] = -Hm[k]; double tmp = detJ[j]*w[j]; for (int l=0; l<nseln+nmeln; ++l) { for (int k=0; k<nseln+nmeln; ++k) { ke[k*ndpn ][l*ndpn ] -= -tmp*N[k]*N[l]*(eps*Ttb[0][0] + pt.m_mueff*tn*B[0][0]); ke[k*ndpn ][l*ndpn+1] -= -tmp*N[k]*N[l]*(eps*Ttb[0][1] + pt.m_mueff*tn*B[0][1]); ke[k*ndpn ][l*ndpn+2] -= -tmp*N[k]*N[l]*(eps*Ttb[0][2] + pt.m_mueff*tn*B[0][2]); ke[k*ndpn+1][l*ndpn ] -= -tmp*N[k]*N[l]*(eps*Ttb[1][0] + pt.m_mueff*tn*B[1][0]); ke[k*ndpn+1][l*ndpn+1] -= -tmp*N[k]*N[l]*(eps*Ttb[1][1] + pt.m_mueff*tn*B[1][1]); ke[k*ndpn+1][l*ndpn+2] -= -tmp*N[k]*N[l]*(eps*Ttb[1][2] + pt.m_mueff*tn*B[1][2]); ke[k*ndpn+2][l*ndpn ] -= -tmp*N[k]*N[l]*(eps*Ttb[2][0] + pt.m_mueff*tn*B[2][0]); ke[k*ndpn+2][l*ndpn+1] -= -tmp*N[k]*N[l]*(eps*Ttb[2][1] + pt.m_mueff*tn*B[2][1]); ke[k*ndpn+2][l*ndpn+2] -= -tmp*N[k]*N[l]*(eps*Ttb[2][2] + pt.m_mueff*tn*B[2][2]); } } // b. Na,Nb-term //------------------------------------- tmp = detJ[j]*w[j]; // non-symmetric for (int l=0; l<nseln; ++l) { for (int k=0; k<nseln+nmeln; ++k) { ke[k*ndpn ][l*ndpn ] -= -tmp*N[k]*(tn*(As[l][0][0] + Pc[l][0][0])); ke[k*ndpn ][l*ndpn+1] -= -tmp*N[k]*(tn*(As[l][0][1] + Pc[l][0][1])); ke[k*ndpn ][l*ndpn+2] -= -tmp*N[k]*(tn*(As[l][0][2] + Pc[l][0][2])); ke[k*ndpn+1][l*ndpn ] -= -tmp*N[k]*(tn*(As[l][1][0] + Pc[l][1][0])); ke[k*ndpn+1][l*ndpn+1] -= -tmp*N[k]*(tn*(As[l][1][1] + Pc[l][1][1])); ke[k*ndpn+1][l*ndpn+2] -= -tmp*N[k]*(tn*(As[l][1][2] + Pc[l][1][2])); ke[k*ndpn+2][l*ndpn ] -= -tmp*N[k]*(tn*(As[l][2][0] + Pc[l][2][0])); ke[k*ndpn+2][l*ndpn+1] -= -tmp*N[k]*(tn*(As[l][2][1] + Pc[l][2][1])); ke[k*ndpn+2][l*ndpn+2] -= -tmp*N[k]*(tn*(As[l][2][2] + Pc[l][2][2])); } } // c. Nc,Nd-term //--------------------------------------- tmp = detJ[j]*w[j]; // non-symmetric for (int k=0; k<nmeln; ++k) { for (int l=0; l<nseln+nmeln; ++l) { ke[(k+nseln)*ndpn ][l*ndpn ] -= tmp*N[l]*tn*Pb[k][0][0]; ke[(k+nseln)*ndpn ][l*ndpn+1] -= tmp*N[l]*tn*Pb[k][0][1]; ke[(k+nseln)*ndpn ][l*ndpn+2] -= tmp*N[l]*tn*Pb[k][0][2]; ke[(k+nseln)*ndpn+1][l*ndpn ] -= tmp*N[l]*tn*Pb[k][1][0]; ke[(k+nseln)*ndpn+1][l*ndpn+1] -= tmp*N[l]*tn*Pb[k][1][1]; ke[(k+nseln)*ndpn+1][l*ndpn+2] -= tmp*N[l]*tn*Pb[k][1][2]; ke[(k+nseln)*ndpn+2][l*ndpn ] -= tmp*N[l]*tn*Pb[k][2][0]; ke[(k+nseln)*ndpn+2][l*ndpn+1] -= tmp*N[l]*tn*Pb[k][2][1]; ke[(k+nseln)*ndpn+2][l*ndpn+2] -= tmp*N[l]*tn*Pb[k][2][2]; } } // c. Gbc-term //--------------------------------------- tmp = tn*detJ[j]*w[j]; for (int k=0; k<nmeln; ++k) { for (int l=0; l<nseln; ++l) { mat3d gT = T*(Gbc[k][l]*tmp); ke[(k+nseln)*ndpn ][l*ndpn ] -= gT[0][0]; ke[(k+nseln)*ndpn ][l*ndpn+1] -= gT[0][1]; ke[(k+nseln)*ndpn ][l*ndpn+2] -= gT[0][2]; ke[(k+nseln)*ndpn+1][l*ndpn ] -= gT[1][0]; ke[(k+nseln)*ndpn+1][l*ndpn+1] -= gT[1][1]; ke[(k+nseln)*ndpn+1][l*ndpn+2] -= gT[1][2]; ke[(k+nseln)*ndpn+2][l*ndpn ] -= gT[2][0]; ke[(k+nseln)*ndpn+2][l*ndpn+1] -= gT[2][1]; ke[(k+nseln)*ndpn+2][l*ndpn+2] -= gT[2][2]; } } // --- B 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; double dpr = 0, dps = 0; dpr = me.eval_deriv1(degree_p, pm, r, s); dps = me.eval_deriv2(degree_p, pm, r, s); vec3d q2 = gmcnt[0]*dpr + gmcnt[1]*dps; // evaluate gc vector<double> gc(nseln); for (int k=0; k<nseln; ++k) { gc[k] = (a[0][0]*dpr*Gsr[k] + a[0][1]*dpr*Gss[k] + a[1][0]*dps*Gsr[k] + a[1][1]*dps*Gss[k])*(-g); } tmp = dt*w[j]*detJ[j]; double epsp = m_epsp*pt.m_epsp*psf; // pressure shape functions double* Hsp = se.H(degree_p, j); me.shape_fnc(degree_p, Hmp, r, s); for (int i = 0; i < nseln + nmeln; ++i) H[i] = 0; for (int i = 0; i < nspdof; ++i) H[i ] = Hsp[i]; for (int i = 0; i < nmpdof; ++i) H[i + nseln] = Hmp[i]; // --- S O L I D - P R E S S U R E C O N T A C T --- // a. q-term //------------------------------------- for (int k=0; k<nseln+nmeln; ++k) for (int l=0; l<nseln+nmeln; ++l) { ke[4*k + 3][4*l ] += tmp*epsp*H[k]*N[l]*q2.x; ke[4*k + 3][4*l+1] += tmp*epsp*H[k]*N[l]*q2.y; ke[4*k + 3][4*l+2] += tmp*epsp*H[k]*N[l]*q2.z; } double wn = pt.m_Lmp + epsp*pt.m_pg; // b. A-term //------------------------------------- for (int l=0; l<nseln; ++l) { vec3d Acn = Ac[l]*nu; for (int k=0; k<nseln+nmeln; ++k) { ke[4*k + 3][4*l ] -= tmp*wn*H[k]*Acn.x; ke[4*k + 3][4*l+1] -= tmp*wn*H[k]*Acn.y; ke[4*k + 3][4*l+2] -= tmp*wn*H[k]*Acn.z; } } // c. s-term (Frictional term) //------------------------------------- vec3d q = s1*m_mu*(1.0 - m_phi); for (int l=0; l<nseln; ++l) { for (int k=0; k<nseln+nmeln; ++k) { ke[4*k ][4*l+3] -= tmp*H[k]*N[l]*q.x; ke[4*k + 1][4*l+3] -= tmp*H[k]*N[l]*q.y; ke[4*k + 2][4*l+3] -= tmp*H[k]*N[l]*q.z; } } // d. m-term //--------------------------------------- vec3d mbp[MN]; double Gpr[MN], Gps[MN]; me.shape_deriv(degree_p, Gpr, Gps, r, s); for (int k = 0; k < nmeln; ++k) mbp[k] = vec3d(0, 0, 0); for (int k = 0; k<nmpdof; ++k) { mbp[k] = gmcnt[0] * Gpr[k] + gmcnt[1] * Gps[k]; } for (int k=0; k<nmpdof; ++k) { for (int l=0; l<nseln+nmeln; ++l) { ke[4*(k+nseln) + 3][4*l ] += tmp*wn*N[l]*mbp[k].x; ke[4*(k+nseln) + 3][4*l+1] += tmp*wn*N[l]*mbp[k].y; ke[4*(k+nseln) + 3][4*l+2] += tmp*wn*N[l]*mbp[k].z; } } // e. gc-term //------------------------------------- for (int k=0; k<nseln+nmeln; ++k) for (int l=0; l<nseln; ++l) { ke[4*k + 3][4*l ] -= tmp*epsp*H[k]*gc[l]*nu.x; ke[4*k + 3][4*l+1] -= tmp*epsp*H[k]*gc[l]*nu.y; ke[4*k + 3][4*l+2] -= tmp*epsp*H[k]*gc[l]*nu.z; } // f. Gbc-term (CONVERT!) //--------------------------------------- /* for (int k=0; k<nmeln; ++k) { for (int l=0; l<nseln; ++l) { ke[4*(k+nseln) + 3][4*l ] -= tmp*wn*Gbc[k][l]*nu.x; ke[4*(k+nseln) + 3][4*l+1] -= tmp*wn*Gbc[k][l]*nu.y; ke[4*(k+nseln) + 3][4*l+2] -= tmp*wn*Gbc[k][l]*nu.z; } } */ // --- P R E S S U R E - P R E S S U R E C O N T A C T --- // calculate the N-vector for (int k = 0; k < ndof; ++k) N[k] = 0.0; for (int k=0; k<nspdof; ++k) { N[ndpn*k+3] = Hsp[k]; } for (int k=0; k<nmpdof; ++k) { N[ndpn*(k+nseln)+3] = -Hmp[k]; } for (int k=0; k<ndof; ++k) for (int l=0; l<ndof; ++l) ke[k][l] -= tmp*epsp*N[k]*N[l]; } // assemble the global stiffness ke.SetNodes(en); ke.SetIndices(LM); LS.Assemble(ke); } } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::UpdateContactPressures() { DOFS& dofs = GetFEModel()->GetDOFS(); int degree_d = dofs.GetVariableInterpolationOrder(m_ss.m_varU); int degree_p = dofs.GetVariableInterpolationOrder(m_ss.m_varP); int npass = (m_btwo_pass?2:1); const int MN = FEElement::MAX_NODES; const int MI = FEElement::MAX_INTPOINTS; double psf = GetPenaltyScaleFactor(); for (int np=0; np<npass; ++np) { FESlidingSurfaceBiphasicMixed& ss = (np == 0? m_ss : m_ms); FESlidingSurfaceBiphasicMixed& ms = (np == 0? m_ms : m_ss); // loop over all elements of the primary surface for (int n=0; n<ss.Elements(); ++n) { FESurfaceElement& el = ss.Element(n); int nint = el.GaussPoints(); // get the normal tractions at the integration points for (int i=0; i<nint; ++i) { // get integration point data FEBiphasicContactPoint& sd = static_cast<FEBiphasicContactPoint&>(*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) { // get secondary element data int mint = pme->GaussPoints(); double pi[MI]; vec3d ti[MI]; for (int j=0; j<mint; ++j) { FEBiphasicContactPoint& md = static_cast<FEBiphasicContactPoint&>(*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*pi[j] + md.m_s1*md.m_mueff*pi[j]); } } // project the data to the nodes double pn[MN]; vec3d tn[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(degree_p, 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 primary-secondary are opposite, so subtract sd.m_tr -= trac; } } } ss.EvaluateNodalContactPressures(); ss.EvaluateNodalContactTractions(); } } //----------------------------------------------------------------------------- bool FESlidingInterfaceBiphasicMixed::Augment(int naug, const FETimeInfo& tp) { // make sure we need to augment if (m_laugon != FECore::AUGLAG_METHOD) return true; int i; double Ln, Lp; bool bconv = true; double psf = GetPenaltyScaleFactor(); bool bporo = (m_ss.m_bporo && m_ms.m_bporo); 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; for (int i=0; i<NS; ++i) { FESurfaceElement& el = m_ss.Element(i); for (int j=0; j<el.GaussPoints(); ++j) { FEBiphasicContactPoint& ds = static_cast<FEBiphasicContactPoint&>(*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) { FEBiphasicContactPoint& dm = static_cast<FEBiphasicContactPoint&>(*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; double maxpg = 0; // update Lagrange multipliers double normL1 = 0, epsp; for (i=0; i<NS; ++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) { FEBiphasicContactPoint& ds = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(j)); // update Lagrange multipliers on primary surface double eps = m_epsn*ds.m_epsn*psf; if (ds.m_bstick) { // if stick, augment total traction if (m_bsmaug) { 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) { 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/ds.m_Lmd); if ( ds.m_Lmd < (1-m_phi)*ds.m_p1 ) { mueff = 0.0; } 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; 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; } ds.m_Lmp = Lp; } } } for (i=0; i<NM; ++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) { FEBiphasicContactPoint& dm = static_cast<FEBiphasicContactPoint&>(*el.GetMaterialPoint(j)); // update Lagrange multipliers on secondary surface double eps = m_epsn*dm.m_epsn*psf; if (dm.m_bstick) { // if stick, augment total traction if (m_bsmaug) { 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) { 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/dm.m_Lmd); if ( dm.m_Lmd < (1-m_phi)*dm.m_p1 ) { mueff = 0.0; } 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; 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; } dm.m_Lmp = Lp; } } } // 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; // calculate relative norms double lnorm = (normL1 != 0 ? fabs((normL1 - normL0) / normL1) : fabs(normL1 - normL0)); double pnorm = (normP != 0 ? (normDP/normP) : normDP); // check convergence if ((m_gtol > 0) && (maxgap > m_gtol)) bconv = false; if ((m_ptol > 0) && (bporo && maxpg > m_ptol)) bconv = false; if ((m_atol > 0) && (lnorm > m_atol)) bconv = false; if ((m_atol > 0) && (pnorm > 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"); } 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"); } ProjectSurface(m_ss, m_ms, true); if (m_btwo_pass) ProjectSurface(m_ms, m_ss, true); m_bfreeze = true; return bconv; } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::Serialize(DumpStream &ar) { // serialize contact data FEContactInterface::Serialize(ar); // serialize 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); } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::MarkFreeDraining() { // 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 (int np=0; np<2; ++np) { FESlidingSurfaceBiphasicMixed& 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 (int i=0; i<s.Nodes(); ++i) { FENode& node = s.Node(i); int id = node.m_ID[m_dofP]; if (id >= 0) { // mark node as free-draining node.m_ID[m_dofP] = -id-2; } } } } } //----------------------------------------------------------------------------- void FESlidingInterfaceBiphasicMixed::SetFreeDraining() { // Set the pressure to zero for the free-draining nodes for (int np=0; np<2; ++np) { FESlidingSurfaceBiphasicMixed& s = (np == 0? m_ss : m_ms); if (s.m_bporo) { // loop over all nodes for (int i=0; i<s.Nodes(); ++i) { FENode& node = s.Node(i); if (node.m_ID[m_dofP] < -1) { // set the fluid pressure to zero node.set(m_dofP, 0); } } } } }
C++
3D
febiosoftware/FEBio
FEBioMix/FEMembraneMassActionForward.cpp
.cpp
7,279
193
/*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 "FEMembraneMassActionForward.h" #include "FESoluteInterface.h" BEGIN_FECORE_CLASS(FEMembraneMassActionForward, FEMembraneReaction) END_FECORE_CLASS(); //----------------------------------------------------------------------------- FEMembraneMassActionForward::FEMembraneMassActionForward(FEModel* pfem) : FEMembraneReaction(pfem) { // set material properties ADD_PROPERTY(m_pFwd, "forward_rate", FEProperty::Optional); } //----------------------------------------------------------------------------- //! molar supply at material point double FEMembraneMassActionForward::ReactionSupply(FEMaterialPoint& pt) { // get reaction rate double kF = m_pFwd->ReactionRate(pt); // evaluate the reaction molar supply double zhat = kF; // start with contribution from membrane solutes const 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->SBMArealConcentration(pt, i); zhat *= pow(c, vR); } } // add contribution from internal and external solutes const int nse = (int) m_psm->SolutesExternal(pt); for (int i=0; i<nse; ++i) { int vRe = m_vRe[m_psm->GetSoluteIDExternal(pt,i)]; if (vRe > 0) { // evaluate nodal effective concentrations double c = m_psm->GetEffectiveSoluteConcentrationExternal(pt,i); zhat *= pow(c, vRe); } } const int nsi = (int) m_psm->SolutesInternal(pt); for (int i=0; i<nsi; ++i) { int vRi = m_vRi[m_vRi[m_psm->GetSoluteIDInternal(pt,i)]]; if (vRi > 0) { // evaluate nodal effective concentrations double c = m_psm->GetEffectiveSoluteConcentrationInternal(pt,i); zhat *= pow(c, vRi); } } return zhat; } //----------------------------------------------------------------------------- //! tangent of molar supply with strain at material point double FEMembraneMassActionForward::Tangent_ReactionSupply_Strain(FEMaterialPoint& pt) { double kF = m_pFwd->ReactionRate(pt); double dkFde = m_pFwd->Tangent_ReactionRate_Strain(pt); double zhat = ReactionSupply(pt); double dzhatde = 0; if (kF > 0) dzhatde = dkFde*(zhat/kF); return dzhatde; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective pressure at material point double FEMembraneMassActionForward::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 pressure at material point double FEMembraneMassActionForward::Tangent_ReactionSupply_Pi(FEMaterialPoint& pt) { double kF = m_pFwd->ReactionRate(pt); double dkFdp = m_pFwd->Tangent_ReactionRate_Pi(pt); double zhat = ReactionSupply(pt); double dzhatdp = 0; if (kF > 0) dzhatdp = dkFdp*zhat/kF; return dzhatdp; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective pressure at material point double FEMembraneMassActionForward::Tangent_ReactionSupply_Pe(FEMaterialPoint& pt) { double kF = m_pFwd->ReactionRate(pt); double dkFdp = m_pFwd->Tangent_ReactionRate_Pe(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 FEMembraneMassActionForward::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->GetActualSoluteConcentration(pt, sol); if ((zhat > 0) && (c > 0)) dzhatdc = m_vR[sol]/c*zhat; return dzhatdc; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective concentration at material point double FEMembraneMassActionForward::Tangent_ReactionSupply_Ci(FEMaterialPoint& pt, const int sol) { double zhat = ReactionSupply(pt); double kF = m_pFwd->ReactionRate(pt); double dkFdci = m_pFwd->Tangent_ReactionRate_Ci(pt, sol); double dzhatdc = 0; if (kF != 0) dzhatdc = dkFdci/kF*zhat; double ci = m_psm->GetEffectiveSoluteConcentrationInternal(pt, sol); int IDi = m_psm->GetSoluteIDInternal(pt, sol); if ((zhat > 0) && (ci > 0)) dzhatdc += m_vRi[IDi]/ci*zhat; return dzhatdc; } //----------------------------------------------------------------------------- //! tangent of molar supply with effective concentration at material point double FEMembraneMassActionForward::Tangent_ReactionSupply_Ce(FEMaterialPoint& pt, const int sol) { double zhat = ReactionSupply(pt); double kF = m_pFwd->ReactionRate(pt); double dkFdce = m_pFwd->Tangent_ReactionRate_Ce(pt, sol); double dzhatdc = 0; if (kF != 0) dzhatdc = dkFdce/kF*zhat; double ce = m_psm->GetEffectiveSoluteConcentrationExternal(pt, sol); int IDe = m_psm->GetSoluteIDExternal(pt, sol); if ((zhat > 0) && (ce > 0)) dzhatdc += m_vRe[IDe]/ce*zhat; return dzhatdc; }
C++
3D
febiosoftware/FEBio
FEBioMix/FEBiphasicSolver.cpp
.cpp
33,753
1,135
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEBiphasicSolver.h" #include "FEBiphasicDomain.h" #include <FEBioMech/FESlidingElasticInterface.h> #include "FESlidingInterface2.h" #include "FESlidingInterface3.h" #include "FESlidingInterfaceBiphasic.h" #include "FESlidingInterfaceBiphasicMixed.h" #include <FEBioMech/FEElasticDomain.h> #include <FEBioMech/FEPressureLoad.h> #include <FEBioMech/FEResidualVector.h> #include <FEBioMech/FESolidLinearSystem.h> #include <FEBioMech/FESSIShellDomain.h> #include <FEBioMech/FERigidConnector.h> #include <FECore/log.h> #include <FECore/sys.h> #include <FECore/FEModel.h> #include <FECore/FEModelLoad.h> #include <FECore/FENodalLoad.h> #include <FECore/FEAnalysis.h> #include <FECore/FEBoundaryCondition.h> #include <FECore/FENLConstraint.h> #include <FECore/FELinearConstraintManager.h> #include "FEBiphasicAnalysis.h" //----------------------------------------------------------------------------- // define the parameter list BEGIN_FECORE_CLASS(FEBiphasicSolver, 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_biphasicFormulation, "mixed_formulation"); END_PARAM_GROUP(); // obsolete parameters that used to be inherited from FESolidSolver2 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(); //----------------------------------------------------------------------------- FEBiphasicSolver::FEBiphasicSolver(FEModel* pfem) : FENewtonSolver(pfem), m_dofU(pfem), m_dofV(pfem), m_dofRQ(pfem), m_dofSU(pfem), m_dofSV(pfem), m_dofSA(pfem), m_dofP(pfem), m_dofSP(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; // only needed for biphasic-solute analyses 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); // set default formulation (full shape functions) m_biphasicFormulation = 0; m_solutionNorm.push_back(ConvergenceInfo()); // get pressure dof if (pfem) { m_dofP.AddDof(pfem->GetDOFIndex("p")); m_dofSP.AddDof(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"); } } //----------------------------------------------------------------------------- FEBiphasicSolver::~FEBiphasicSolver() {} //----------------------------------------------------------------------------- //! Allocates and initializes the data structures. // bool FEBiphasicSolver::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); // 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 = GetFEModel()->GetMesh(); gather(m_Ut, mesh, m_dofP[0]); gather(m_Ut, mesh, m_dofSP[0]); } return true; } //! Generate warnings if needed void FEBiphasicSolver::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; } } } } } //! Initialize equations bool FEBiphasicSolver::InitEquations() { // define the solution variables for the Newton solver // Do this before calling base class! // TODO: Maybe I can get default values from the domains? int pressureOrder = (m_biphasicFormulation == 1 ? 1 : -1); AddSolutionVariable(&m_dofU, -1, "displacement", m_Dtol); AddSolutionVariable(&m_dofSU, -1, "shell displacement", m_Dtol); AddSolutionVariable(&m_dofP, pressureOrder, "pressure", m_Ptol); AddSolutionVariable(&m_dofSP, pressureOrder, "shell fluid pressure", m_Ptol); // set the interpolation orders DOFS& dofs = GetFEModel()->GetDOFS(); int var_u = dofs.GetVariableIndex("displacement"); int var_p = dofs.GetVariableIndex("fluid pressure"); dofs.SetVariableInterpolationOrder(var_u, -1); dofs.SetVariableInterpolationOrder(var_p, pressureOrder); // First call the base class. // This will initialize all equation numbers, except the rigid body equation numbers if (FENewtonSolver::InitEquations2() == 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); } } // determined the nr of pressure and concentration equations m_ndeq = m_npeq = 0; FEMesh& mesh = fem.GetMesh(); 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 [0]] != -1) m_npeq++; if (n.m_ID[m_dofSP[0]] != -1) m_npeq++; } return true; } //----------------------------------------------------------------------------- //! Prepares the data for the first QN iteration. //! //! \todo There is some more stuff in the base method that //! I need to move to this method, but since it will //! change the order of some operations I need to make //! sure it won't break anything void FEBiphasicSolver::PrepStep() { zero(m_Pi); zero(m_Di); // for pressure 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()) { if ((pl->GetDOF() == m_dofP[0]) || (pl->GetDOF() == m_dofSP[0])) { 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. bool FEBiphasicSolver::Quasin() { // convergence norms double normR1; // residual norm double normE1; // energy norm double normD; // displacement norm double normd; // displacement increment norm double normRi = 0; // initial residual norm double normEi = 0; // initial energy norm double normEm = 0; // max energy norm double normDi = 0; // initial displacement norm // poro convergence norms data double normPi = 0; // initial pressure norm double normP; // current pressure norm double normp; // incremement pressure norm // prepare for the first iteration FEModel& fem = *GetFEModel(); 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; } // 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 ); 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; 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 FEBiphasicSolver::Residual(vector<double>& R) { // get the time information FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // zero nodal reaction forces zero(m_Fr); // setup global RHS vector zero(R); FEResidualVector RHS(fem, R, m_Fr); // zero rigid body reaction forces m_rigidSolver.Residual(); // calculate internal stress force InternalForces(RHS); // calculate nodal reaction forces for (int i = 0; i < m_neq; ++i) m_Fr[i] -= R[i]; // calculate external forces ExternalForces(RHS); // increase RHS counter m_nrhs++; return true; } //----------------------------------------------------------------------------- //! Calculates global stiffness matrix. bool FEBiphasicSolver::StiffnessMatrix() { FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // get the mesh FEMesh& mesh = fem.GetMesh(); // setup the linear system of equations 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 == FEBiphasicAnalysis::STEADY_STATE) { for (int i=0; i<mesh.Domains(); ++i) { // Biphasic analyses may include biphasic and elastic domains FEBiphasicDomain* pbdom = dynamic_cast<FEBiphasicDomain*>(&mesh.Domain(i)); if (pbdom) pbdom->StiffnessMatrixSS(LS, bsymm); else { FEElasticDomain* pedom = dynamic_cast<FEElasticDomain*>(&mesh.Domain(i)); if (pedom) pedom->StiffnessMatrix(LS); } } } else { for (int i=0; i<mesh.Domains(); ++i) { // Biphasic analyses may include biphasic and elastic domains FEBiphasicDomain* pbdom = dynamic_cast<FEBiphasicDomain*>(&mesh.Domain(i)); if (pbdom) pbdom->StiffnessMatrix(LS, bsymm); else { FEElasticDomain* pedom = dynamic_cast<FEElasticDomain*>(&mesh.Domain(i)); if (pedom) pedom->StiffnessMatrix(LS); } } } // calculate contact stiffness ContactStiffness(LS); // calculate stiffness matrices for surface loads int nml = fem.ModelLoads(); for (int i=0; i<nml; ++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; } //! Update the model's kinematic data. void FEBiphasicSolver::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(); { 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); } //----------------------------------------------------------------------------- //! Updates the poroelastic data void FEBiphasicSolver::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[0]]; if (n >= 0) node.set(m_dofP[0], 0 + m_Ut[n] + m_Ui[n] + ui[n]); n = node.m_ID[m_dofSP[0]]; if (n >= 0) node.set(m_dofSP[0], 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 current state of the model void FEBiphasicSolver::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(); } //! Update EAS void FEBiphasicSolver::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 FEBiphasicSolver::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); } } void FEBiphasicSolver::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(); FESlidingInterfaceBiphasic* psib = dynamic_cast<FESlidingInterfaceBiphasic*>(pci); if (psib) psib->MarkFreeDraining(); FESlidingInterfaceBiphasicMixed* psbm = dynamic_cast<FESlidingInterfaceBiphasicMixed*>(pci); if (psbm) psbm->MarkFreeDraining(); } // Update all contact interfaces // NOTE: note that we call the base class version here, not the overridden one!! 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(); 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 pressure) are fullfilled int nbcs = fem.BoundaryConditions(); for (int i = 0; i<nbcs; ++i) { FEBoundaryCondition& bc = *fem.BoundaryCondition(i); if (bc.IsActive()) bc.Repair(); } } //----------------------------------------------------------------------------- void FEBiphasicSolver::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 FEBiphasicSolver::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[0]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); pi[m++] = ui[nid]; assert(m <= (int) pi.size()); } nid = n.m_ID[m_dofSP[0]]; if (nid != -1) { nid = (nid < -1 ? -nid-2 : nid); pi[m++] = ui[nid]; assert(m <= (int) pi.size()); } } } //----------------------------------------------------------------------------- //! Save data to dump file void FEBiphasicSolver::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; ar& m_arcLength; ar& m_al_scale; 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_Ptol & m_ndeq & m_npeq; ar & m_nceq; ar & m_di & m_Di & m_pi & m_Pi; } //----------------------------------------------------------------------------- //! Internal forces void FEBiphasicSolver::InternalForces(FEGlobalVector& RHS) { // get the time information FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // get the mesh FEMesh& mesh = fem.GetMesh(); // calculate internal stress force if (fem.GetCurrentStep()->m_nanalysis == FEBiphasicAnalysis::STEADY_STATE) { for (int i=0; i<mesh.Domains(); ++i) { FEBiphasicDomain* pdom = dynamic_cast<FEBiphasicDomain*>(&mesh.Domain(i)); if (pdom) pdom->InternalForcesSS(RHS); else { FEElasticDomain& dom = dynamic_cast<FEElasticDomain&>(mesh.Domain(i)); dom.InternalForces(RHS); } } } else { for (int i=0; i<mesh.Domains(); ++i) { FEBiphasicDomain* pdom = dynamic_cast<FEBiphasicDomain*>(&mesh.Domain(i)); if (pdom) pdom->InternalForces(RHS); else { FEElasticDomain& dom = dynamic_cast<FEElasticDomain&>(mesh.Domain(i)); dom.InternalForces(RHS); } } } } //----------------------------------------------------------------------------- //! External forces void FEBiphasicSolver::ExternalForces(FEGlobalVector& RHS) { // get the time information FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // get the mesh FEMesh& mesh = fem.GetMesh(); // add model loads int NML = fem.ModelLoads(); for (int i=0; i<NML; ++i) { FEModelLoad& mli = *fem.ModelLoad(i); if (mli.IsActive()) mli.LoadVector(RHS); } // calculate contact forces ContactForces(RHS); // calculate nonlinear constraint forces // note that these are the linear constraints // enforced using the augmented lagrangian NonLinearConstraintForces(RHS, tp); // set the nodal reaction forces // TODO: Is this a good place to do this? for (int i=0; i<mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); node.set_load(m_dofU[0], 0); node.set_load(m_dofU[1], 0); node.set_load(m_dofU[2], 0); node.set_load(m_dofP[0], 0); int n; if ((n = node.m_ID[m_dofU[0]]) >= 0) node.set_load(m_dofU[0], -m_Fr[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]]) >= 0) node.set_load(m_dofU[1], -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]]) >= 0) node.set_load(m_dofU[2], -m_Fr[n]); if ((n = -node.m_ID[m_dofU[2]] - 2) >= 0) node.set_load(m_dofU[2], -m_Fr[n]); if ((n = node.m_ID[m_dofP[0]]) >= 0) node.set_load(m_dofP[0], -m_Fr[n]); if ((n = -node.m_ID[m_dofP[0]] - 2) >= 0) node.set_load(m_dofP[0], -m_Fr[n]); } } //! Calculates the contact forces void FEBiphasicSolver::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 FEBiphasicSolver::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 FEBiphasicSolver::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 FEBiphasicSolver::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/FESolubManning.cpp
.cpp
10,076
309
/*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 "FESolubManning.h" #include "FEMultiphasic.h" #include <FECore/log.h> //----------------------------------------------------------------------------- // define the material parameters BEGIN_FECORE_CLASS(FESolubManning, FESoluteSolubility) ADD_PARAMETER(m_ksi , FE_RANGE_GREATER_OR_EQUAL(0.0), "ksi" ); ADD_PARAMETER(m_sol , "co_ion")->setEnums("$(solutes)"); ADD_PROPERTY(m_solub, "solub" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FESolubManning::FESolubManning(FEModel* pfem) : FESoluteSolubility(pfem) { m_ksi = 1; m_sol = -1; m_lsol = -1; m_bcoi = false; m_solub = nullptr; } //----------------------------------------------------------------------------- bool FESolubManning::Init() { if (FESoluteSolubility::Init() == false) return false; // get the parent which must be a solute material FESolute* m_pSol = dynamic_cast<FESolute*>(GetParent()); // set m_bcoion flag if (m_pSol->GetSoluteID() == m_sol) m_bcoi = true; else m_bcoi = false; // get the ancestor material which must be a multiphasic material FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); if (psm == nullptr) { feLogError("Ancestor material must have solutes"); return false; } // extract the local id of the solute from the global id // m_sol must be zero-based m_lsol = psm->FindLocalSoluteID(m_sol); if (m_lsol == -1) { feLogError("Invalid value for sol"); return false; } if (m_solub == nullptr) { feLogError("Function for solub not assigned"); return false; } m_solub->Init(); return true; } //----------------------------------------------------------------------------- //! Solubility double FESolubManning::Solubility(FEMaterialPoint& mp) { double kPM = Solubility_Manning(mp); double kMM = Solubility_Wells(mp); return kPM*kMM; } //----------------------------------------------------------------------------- //! Tangent of solubility with respect to strain double FESolubManning::Tangent_Solubility_Strain(FEMaterialPoint &mp) { double kPM = Solubility_Manning(mp); double kMM = Solubility_Wells(mp); double dkPMdJ = Tangent_Solubility_Strain_Manning(mp); double dkMMdJ = Tangent_Solubility_Strain_Wells(mp); return dkPMdJ*kMM + kPM*dkMMdJ; } //----------------------------------------------------------------------------- //! Tangent of solubility with respect to strain double FESolubManning::Tangent_Solubility_Concentration(FEMaterialPoint& mp, const int isol) { double kPM = Solubility_Manning(mp); double kMM = Solubility_Wells(mp); double dkPMdc = Tangent_Solubility_Concentration_Manning(mp,isol); double dkMMdc = Tangent_Solubility_Concentration_Wells(mp,isol); return dkPMdc*kMM + kPM*dkMMdc; } //----------------------------------------------------------------------------- //! Cross derivative of solubility with respect to strain and concentration double FESolubManning::Tangent_Solubility_Strain_Concentration(FEMaterialPoint &mp, const int isol) { // assume 0 return 0; } //----------------------------------------------------------------------------- //! Second derivative of solubility with respect to strain double FESolubManning::Tangent_Solubility_Strain_Strain(FEMaterialPoint &mp) { // assume 0 return 0; } //----------------------------------------------------------------------------- //! Second derivative of solubility with respect to concentration double FESolubManning::Tangent_Solubility_Concentration_Concentration(FEMaterialPoint &mp, const int isol, const int jsol) { // assume 0 return 0; } //----------------------------------------------------------------------------- //! Solubility double FESolubManning::Solubility_Manning(FEMaterialPoint& mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); // evaluate X = FCD/co-ion actual concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double cF = psm->GetFixedChargeDensity(mp); double X = 0; if (ca > 0) X = cF/ca; // --- Manning activity coefficient --- double kh; if (m_ksi <= 1) kh = exp(0.5*m_ksi*X/(X+2)); else { double Y = X/m_ksi; if (m_bcoi) kh = exp(0.5*Y/(Y+2)); else kh = (X+1)/(Y+1)*exp(0.5*Y/(Y+2)); } assert(kh>0); return kh; } //----------------------------------------------------------------------------- //! Tangent of solubility with respect to strain double FESolubManning::Tangent_Solubility_Strain_Manning(FEMaterialPoint &mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); FEBiphasicInterface* pbm = dynamic_cast<FEBiphasicInterface*>(GetAncestor()); FEElasticMaterialPoint& pt = *mp.ExtractData<FEElasticMaterialPoint>(); // evaluate X = FCD/co-ion actual concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double cF = fabs(psm->GetFixedChargeDensity(mp)); double kt = psm->GetPartitionCoefficient(mp, m_lsol); double dktdJ = psm->dkdJ(mp, m_lsol); double X = 0; if (ca > 0) X = cF/ca; // evaluate dX/dJ double J = pt.m_J; double phisr = pbm->GetReferentialSolidVolumeFraction(mp); double dXdJ = -(1./(J-phisr)+dktdJ/kt)*X; // evaluate dkhdX double dkhdX = 0; if (m_ksi <= 1) dkhdX = m_ksi*exp(0.5*m_ksi*X/(X+2))/pow(X+2,2); else { double Y = X/m_ksi; double isk = 1./m_ksi; if (m_bcoi) dkhdX = isk*exp(0.5*Y/(Y+2))/pow(Y+2, 2); else dkhdX = exp(0.5*Y/(Y+2))*(Y*Y*(2-isk)+Y*(5-3*isk)+4-3*isk)/pow((Y+1)*(Y+2), 2); } // evaluate dkhdJ double dkhdJ = dkhdX*dXdJ; return dkhdJ; } //----------------------------------------------------------------------------- //! Tangent of solubility with respect to concentration double FESolubManning::Tangent_Solubility_Concentration_Manning(FEMaterialPoint &mp, const int isol) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); // evaluate X = FCD/co-ion actual concentration double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double cF = fabs(psm->GetFixedChargeDensity(mp)); double kta = psm->GetPartitionCoefficient(mp, m_lsol); double kt = psm->GetPartitionCoefficient(mp, isol); int zt = psm->GetSolute(isol)->ChargeNumber(); double X = 0; if (ca > 0) X = cF/ca; // evaluate dX/dc double dXdc = -zt*kt/ca; if (isol == m_lsol) dXdc -= kta*X/ca; // evaluate dkhdX double dkhdX = 0; if (m_ksi <= 1) dkhdX = m_ksi*exp(0.5*m_ksi*X/(X+2))/pow(X+2,2); else { double Y = X/m_ksi; double isk = 1./m_ksi; if (m_bcoi) dkhdX = isk*exp(0.5*Y/(Y+2))/pow(Y+2, 2); else dkhdX = exp(0.5*Y/(Y+2))*(Y*Y*(2-isk)+Y*(5-3*isk)+4-3*isk)/pow((Y+1)*(Y+2), 2); } // evaluate dkhdc double dkhdc = dkhdX*dXdc; return dkhdc; } //----------------------------------------------------------------------------- double FESolubManning::Solubility_Wells(FEMaterialPoint& mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double solub = m_solub->value(ca); assert(solub>0); return solub; } //----------------------------------------------------------------------------- double FESolubManning::Tangent_Solubility_Strain_Wells(FEMaterialPoint& mp) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double dsolub = m_solub->derive(ca); double c = psm->GetEffectiveSoluteConcentration(mp, m_lsol); double dkdJ = psm->dkdJ(mp, m_lsol); dsolub *= dkdJ * c; return dsolub; } //----------------------------------------------------------------------------- double FESolubManning::Tangent_Solubility_Concentration_Wells(FEMaterialPoint& mp, const int isol) { FESoluteInterface* psm = dynamic_cast<FESoluteInterface*>(GetAncestor()); double ca = psm->GetActualSoluteConcentration(mp, m_lsol); double c = psm->GetEffectiveSoluteConcentration(mp, m_lsol); double k = psm->GetPartitionCoefficient(mp, m_lsol); double dkdc = psm->dkdc(mp, m_lsol, isol); double f = dkdc*c; if (isol == m_lsol) f += k; double dsolub = m_solub->derive(ca); dsolub *= f; return dsolub; }
C++
3D
febiosoftware/FEBio
FEBioMix/FESupplyMichaelisMenten.cpp
.cpp
4,349
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 "FESupplyMichaelisMenten.h" #ifndef SQR #define SQR(x) ((x)*(x)) #endif // define the material parameters BEGIN_FECORE_CLASS(FESupplyMichaelisMenten, FESoluteSupply) ADD_PARAMETER(m_Vmax, FE_RANGE_GREATER_OR_EQUAL(0.0), "Vmax"); ADD_PARAMETER(m_Km , FE_RANGE_GREATER (0.0), "Km" ); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! Constructor. FESupplyMichaelisMenten::FESupplyMichaelisMenten(FEModel* pfem) : FESoluteSupply(pfem) { m_Vmax = m_Km = 0; } //----------------------------------------------------------------------------- //! Solute supply double FESupplyMichaelisMenten::Supply(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 crhat = -m_Vmax*cr/(m_Km+cr); return crhat; } //----------------------------------------------------------------------------- //! Tangent of solute supply with respect to strain double FESupplyMichaelisMenten::Tangent_Supply_Strain(FEMaterialPoint &mp) { return 0; } //----------------------------------------------------------------------------- //! Tangent of solute supply with respect to referential concentration double FESupplyMichaelisMenten::Tangent_Supply_Concentration(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 dcrhatdcr = -m_Vmax*m_Km/SQR(m_Km+cr); return dcrhatdcr; } //----------------------------------------------------------------------------- //! Receptor-ligand complex supply double FESupplyMichaelisMenten::ReceptorLigandSupply(FEMaterialPoint& mp) { return 0; } //----------------------------------------------------------------------------- //! Solute supply at steady state double FESupplyMichaelisMenten::SupplySS(FEMaterialPoint& mp) { return 0; } //----------------------------------------------------------------------------- //! Receptor-ligand concentration at steady-state double FESupplyMichaelisMenten::ReceptorLigandConcentrationSS(FEMaterialPoint& mp) { return 0; } //----------------------------------------------------------------------------- //! Referential solid supply (moles of solid/referential volume/time) double FESupplyMichaelisMenten::SolidSupply(FEMaterialPoint& mp) { return 0; } //----------------------------------------------------------------------------- //! Referential solid concentration (moles of solid/referential volume) //! at steady-state double FESupplyMichaelisMenten::SolidConcentrationSS(FEMaterialPoint& mp) { return 0; }
C++