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
FECore/FELogEnclosedVolume.cpp
.cpp
2,508
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.*/ #include "stdafx.h" #include "FELogEnclosedVolume.h" #include "FESurface.h" #include "FENode.h" BEGIN_FECORE_CLASS(FELogEnclosedVolume, FELogSurfaceData) END_FECORE_CLASS(); double FELogEnclosedVolume::value(FESurface& surface) { double vol = 0.0; int NE = surface.Elements(); for (int i = 0; i < NE; ++i) { FESurfaceElement& el = surface.Element(i); double* w = el.GaussWeights(); for (int n = 0; n < el.GaussPoints(); ++n) { vec3d xi = surface.Local2Global(el, n); vec3d g[2]; surface.CoBaseVectors(el, n, g); double DVj = xi * (g[0] ^ g[1]) / 3; vol += DVj * w[n]; } } return vol; } double FELogEnclosedVolumeChange::value(FESurface& surface) { double DV = 0.0; int NE = surface.Elements(); for (int i = 0; i < NE; ++i) { FESurfaceElement& el = surface.Element(i); double* w = el.GaussWeights(); for (int n = 0; n < el.GaussPoints(); ++n) { FEMaterialPoint& mp = *el.GetMaterialPoint(n); vec3d xi = surface.Local2Global(el, n); vec3d g[2]; surface.CoBaseVectors(el, n, g); vec3d Xi = surface.Local2Global0(el, n); vec3d G[2]; surface.CoBaseVectors0(el, n, G); double DVj = (xi * (g[0] ^ g[1]) - Xi * (G[0] ^ G[1])) / 3; DV += DVj * w[n]; } } return DV; }
C++
3D
febiosoftware/FEBio
FECore/FEMathController.cpp
.cpp
2,307
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 "FEMathController.h" #include "FEModel.h" BEGIN_FECORE_CLASS(FEMathController, FELoadController) ADD_PARAMETER(m_var, "var"); ADD_PARAMETER(m_math, "math"); END_FECORE_CLASS(); FEMathController::FEMathController(FEModel* fem) : FELoadController(fem) { } bool FEMathController::Init() { FEModel& fem = *GetFEModel(); m_val.AddVariable("t"); char sz[64] = { 0 }; for (int i = 0; i < (int)m_var.size(); ++i) { ParamString ps(m_var[i].c_str()); FEParamValue param = fem.GetParameterValue(ps); if (param.isValid() == false) return false; if (param.type() != FE_PARAM_DOUBLE) return false; m_param.push_back(param); snprintf(sz, sizeof(sz), "var_%d", i); m_val.AddVariable(sz); } if (m_val.Create(m_math) == false) return false; return FELoadController::Init(); } double FEMathController::GetValue(double time) { vector<double> p(1 + m_param.size()); p[0] = time; for (int i = 0; i < m_param.size(); ++i) p[1 + i] = m_param[i].value<double>(); return m_val.value_s(p); }
C++
3D
febiosoftware/FEBio
FECore/LinearSolver.cpp
.cpp
5,172
169
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "LinearSolver.h" //----------------------------------------------------------------------------- LinearSolver::LinearSolver(FEModel* fem) : FECoreBase(fem) { ResetStats(); } //----------------------------------------------------------------------------- LinearSolver::~LinearSolver() { Destroy(); } //----------------------------------------------------------------------------- // returns whether this is an iterative solver or not bool LinearSolver::IsIterative() const { return false; } //----------------------------------------------------------------------------- bool LinearSolver::PreProcess() { return true; } //----------------------------------------------------------------------------- void LinearSolver::SetPartitions(const vector<int>& part) { m_part = part; } //----------------------------------------------------------------------------- void LinearSolver::SetPartitions(int npart0, int npart1) { m_part.resize(2); m_part[0] = npart0; m_part[1] = npart1; } //----------------------------------------------------------------------------- // nr of partitions int LinearSolver::Partitions() const { return (int)m_part.size(); } //----------------------------------------------------------------------------- // get the size of a partition int LinearSolver::GetPartitionSize(int part) const { return m_part[part]; } //----------------------------------------------------------------------------- const LinearSolverStats& LinearSolver::GetStats() const { return m_stats; } double LinearSolver::ConditionNumber() { // returns an invalid value for the condition number return 0.0; } //----------------------------------------------------------------------------- void LinearSolver::ResetStats() { m_stats.backsolves = 0; m_stats.iterations = 0; } //----------------------------------------------------------------------------- void LinearSolver::UpdateStats(int iterations) { m_stats.backsolves++; m_stats.iterations += iterations; } //----------------------------------------------------------------------------- void LinearSolver::Destroy() { } //----------------------------------------------------------------------------- //! helper function for when this solver is used as a preconditioner bool LinearSolver::mult_vector(double* x, double* y) { return BackSolve(y, x); } //----------------------------------------------------------------------------- bool LinearSolver::SetSparseMatrix(SparseMatrix* pA) { assert(false); return false; } //----------------------------------------------------------------------------- //! convenience function for solving linear systems bool LinearSolver::Solve(vector<double>& x, vector<double>& y) { if (PreProcess() == false) return false; if (Factor() == false) return false; if (BackSolve(x, y) == false) return false; return true; } //----------------------------------------------------------------------------- IterativeLinearSolver::IterativeLinearSolver(FEModel* fem) : LinearSolver(fem) { } //! convenience function for solving linear systems with an iterative solver bool IterativeLinearSolver::Solve(SparseMatrix& A, std::vector<double>& x, std::vector<double>& b, LinearSolver* pc) { if (SetSparseMatrix(&A) == false) return false; SetLeftPreconditioner(pc); if (PreProcess() == false) return false; if (Factor() == false) return false; return BackSolve(x, b); } // returns whether this is an iterative solver or not bool IterativeLinearSolver::IsIterative() const { return true; } void IterativeLinearSolver::SetLeftPreconditioner(LinearSolver* pc) { assert(false); } void IterativeLinearSolver::SetRightPreconditioner(LinearSolver* pc) { assert(false); } // get the preconditioner LinearSolver* IterativeLinearSolver::GetLeftPreconditioner() { return nullptr; } LinearSolver* IterativeLinearSolver::GetRightPreconditioner() { return nullptr; }
C++
3D
febiosoftware/FEBio
FECore/FELogElementVolume.h
.h
1,615
43
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "ElementDataRecord.h" #include "FaceDataRecord.h" class FELogElementVolume : public FELogElemData { public: FELogElementVolume(FEModel* fem); double value(FEElement& el) override; }; class FELogFaceArea : public FELogFaceData { public: FELogFaceArea(FEModel* fem); double value(FESurfaceElement& el) override; };
Unknown
3D
febiosoftware/FEBio
FECore/FENodeElemList.h
.h
3,072
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_api.h" #include <vector> class FESurface; class FEMesh; class FEElement; class FEDomain; class DumpStream; //----------------------------------------------------------------------------- //! The FENodeElemList class is a utility class that determines for each node //! to which element it belongs. //! This class analyzes a mesh and finds for each node all elements that have //! this node class FECORE_API FENodeElemList { public: FENodeElemList(){} virtual ~FENodeElemList(){} //! build the node-element list for a surface void Create(const FESurface& s); //! build the node-selement list for a mesh void Create(FEMesh& mesh); //! build the node-element list for a domain void Create(FEDomain& dom); //! serialize data to/from dump file void Serialize(DumpStream& ar); //! Clear the list void Clear(); int MaxValence(); int Valence(int n) { return m_nval[n]; } FEElement** ElementList(int n) { return &m_eref[0] + m_pn[n]; } int* ElementIndexList(int n) { return &m_iref[0] + m_pn[n]; } int Size() { return (int) m_nval.size(); } protected: std::vector<int> m_nval; // nodal valences std::vector<FEElement*> m_eref; // element pointers std::vector<int> m_iref; // element indices std::vector<int> m_pn; // start index into the eref array }; //----------------------------------------------------------------------------- //! Like the FEElemElemList, but can create multiple levels class FENodeElemTree { public: FENodeElemTree() {} virtual ~FENodeElemTree() {} void Create(FESurface* ps, int k = 0); int Valence(int n) { return (int) m_nel[n].size(); } FEElement** ElementList(int n) { return &(m_nel[n][0]);} bool empty() { return m_nel.empty(); } protected: std::vector< std::vector<FEElement*> > m_nel; };
Unknown
3D
febiosoftware/FEBio
FECore/FESolver.cpp
.cpp
23,887
865
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FESolver.h" #include "FEModel.h" #include "FENodeReorder.h" #include "DumpStream.h" #include "FEDomain.h" #include "FESurfacePairConstraint.h" #include "FENLConstraint.h" #include "FELinearConstraintManager.h" #include "FENodalLoad.h" #include "LinearSolver.h" #include "log.h" BEGIN_FECORE_CLASS(FESolver, FECoreBase) BEGIN_PARAM_GROUP("linear system"); ADD_PARAMETER(m_msymm , "symmetric_stiffness", 0, "non-symmetric\0symmetric\0symmetric structure\0preferred\0")->setLongName("matrix format"); ADD_PARAMETER(m_eq_scheme, "equation_scheme", 0, "staggered\0block\0"); ADD_PARAMETER(m_eq_order , "equation_order", 0, "default\0reverse\0febio2\0"); ADD_PARAMETER(m_bwopt , "optimize_bw"); END_PARAM_GROUP(); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FESolver::FESolver(FEModel* fem) : FECoreBase(fem) { m_msymm = REAL_SYMMETRIC; // assume symmetric stiffness matrix m_niter = 0; m_nref = 0; m_baugment = false; m_naug = 0; m_neq = 0; m_bwopt = false; m_eq_scheme = EQUATION_SCHEME::STAGGERED; m_eq_order = EQUATION_ORDER::NORMAL_ORDER; } //----------------------------------------------------------------------------- FESolver::~FESolver() { } //----------------------------------------------------------------------------- void FESolver::SetEquationScheme(int scheme) { m_eq_scheme = scheme; } //----------------------------------------------------------------------------- //! set the linear system partitions void FESolver::SetPartitions(const vector<int>& part) { m_part = part; } //----------------------------------------------------------------------------- //! Get the size of a partition int FESolver::GetPartitionSize(int partition) { assert((partition >= 0) && (partition < (int)m_part.size())); if ((partition >= 0) && (partition < (int)m_part.size())) return m_part[partition]; else return 0; } //----------------------------------------------------------------------------- //! get the current stiffness matrix FEGlobalMatrix* FESolver::GetStiffnessMatrix() { return nullptr; } //----------------------------------------------------------------------------- //! get the current load vector std::vector<double> FESolver::GetLoadVector() { return std::vector<double>(); } //----------------------------------------------------------------------------- void FESolver::Clean() { } //----------------------------------------------------------------------------- void FESolver::Reset() { m_niter = 0; m_nref = 0; m_naug = 0; } //----------------------------------------------------------------------------- // get the linear solver LinearSolver* FESolver::GetLinearSolver() { return nullptr; } //----------------------------------------------------------------------------- //! get matrix type Matrix_Type FESolver::MatrixType() const { Matrix_Type mtype; switch (m_msymm) { case REAL_UNSYMMETRIC : mtype = REAL_UNSYMMETRIC; break; case REAL_SYMMETRIC : mtype = REAL_SYMMETRIC; break; case REAL_SYMM_STRUCTURE: mtype = REAL_SYMM_STRUCTURE; break; default: mtype = PreferredMatrixType(); const char* szfmt = ""; switch (mtype) { case REAL_UNSYMMETRIC: szfmt = "unsymmetric"; break; case REAL_SYMMETRIC : szfmt = "symmetric"; break; default: assert(false); } feLogInfo("Setting matrix format to: %s", szfmt); } return mtype; } // find the preferred matrix type: // symmetric unless any model component has its symmetric_stiffness parameter set to false Matrix_Type FESolver::PreferredMatrixType() const { FEModel& fem = *GetFEModel(); for (int i = 0; i < fem.ModelLoads(); ++i) { FEModelLoad* pl = fem.ModelLoad(i); if (pl->IsActive() && (pl->PreferredMatrixType() == REAL_UNSYMMETRIC)) { return REAL_UNSYMMETRIC; // no point in continuing } } for (int i = 0; i < fem.NonlinearConstraints(); ++i) { FENLConstraint* pc = fem.NonlinearConstraint(i); if (pc->IsActive()) { FEParam* p = pc->GetParameter("symmetric_stiffness"); if (p && (p->type() == FE_PARAM_BOOL) && !p->value<bool>()) { return REAL_UNSYMMETRIC; // no point in continuing } } } for (int i = 0; i < fem.SurfacePairConstraints(); ++i) { FESurfacePairConstraint* pc = fem.SurfacePairConstraint(i); if (pc->IsActive()) { FEParam* p = pc->GetParameter("symmetric_stiffness"); if (p && (p->type() == FE_PARAM_BOOL) && !p->value<bool>()) { return REAL_UNSYMMETRIC; // no point in continuing } } } return REAL_SYMMETRIC; } //----------------------------------------------------------------------------- // extract the (square) norm of a solution vector double FESolver::ExtractSolutionNorm(const vector<double>& v, const FEDofList& dofs) const { assert(v.size() == m_dofMap.size()); double norm = 0; for (int n = 0; n < dofs.Size(); ++n) { for (int i = 0; i < v.size(); ++i) { if (m_dofMap[i] == dofs[n]) norm += v[i] * v[i]; } } return norm; } //----------------------------------------------------------------------------- // return the solution vector std::vector<double> FESolver::GetSolutionVector() const { return std::vector<double>(); } //----------------------------------------------------------------------------- // see if the dofs in the dof list are active in this solver bool FESolver::HasActiveDofs(const FEDofList& dof) { assert(dof.IsEmpty() == false); if (dof.IsEmpty()) return true; assert(m_Var.size()); for (int i = 0; i < dof.Size(); ++i) { int dof_i = dof[i]; for (int i = 0; i < m_Var.size(); ++i) { FESolutionVariable& vi = m_Var[i]; if (vi.m_dofs->Contains(dof_i)) { return true; } } } return false; } //----------------------------------------------------------------------------- // get the active dof map (returns nr of functions) int FESolver::GetActiveDofMap(vector<int>& activeDofMap) { // get the dof map int neq = (int)m_dofMap.size(); if (m_dofMap.empty() || (m_dofMap.size() < neq)) return -1; // We need the partitions here, but for now we assume that // it is the first partition // The dof map indices point to the dofs as defined by the variables. // Since there could be more dofs than actually used in the linear system // we need to reindex this map. // First, find the min and max int imin = m_dofMap[0], imax = m_dofMap[0]; for (size_t i = 0; i < neq; ++i) { if (m_dofMap[i] > imax) imax = m_dofMap[i]; if (m_dofMap[i] < imin) imin = m_dofMap[i]; } // create the conversion table int nsize = imax - imin + 1; vector<int> LUT(nsize, -1); for (size_t i = 0; i < neq; ++i) { LUT[m_dofMap[i] - imin] = 1; } // count how many dofs are actually used int nfunc = 0; for (size_t i = 0; i < nsize; ++i) { if (LUT[i] != -1) LUT[i] = nfunc++; } // now, reindex the dof map // allocate dof map activeDofMap.resize(neq); for (size_t i = 0; i < neq; ++i) { activeDofMap[i] = LUT[m_dofMap[i] - imin]; } return nfunc; } //----------------------------------------------------------------------------- //! build the matrix profile void FESolver::BuildMatrixProfile(FEGlobalMatrix& G, bool breset) { FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); DOFS& fedofs = fem.GetDOFS(); int MAX_NDOFS = fedofs.GetTotalDOFS(); // when reset is true we build the entire matrix profile // (otherwise we only build the "dynamic" profile) if (breset) { // Add all elements to the profile // Loop over all active domains for (int nd = 0; nd<mesh.Domains(); ++nd) { FEDomain& d = mesh.Domain(nd); d.BuildMatrixProfile(G); } // linear constraints FELinearConstraintManager& LCM = fem.GetLinearConstraintManager(); LCM.BuildMatrixProfile(G); } else { // Do the "dynamic" profile. That is the part of the profile that always changes // This is mostly contact // do the nonlinear constraints int M = fem.NonlinearConstraints(); for (int m = 0; m<M; ++m) { FENLConstraint* pnlc = fem.NonlinearConstraint(m); if (pnlc->IsActive()) pnlc->BuildMatrixProfile(G); } // All following "elements" are nonstatic. That is, they can change // connectivity between calls to this function. All of these elements // are related to contact analysis (at this point). if (fem.SurfacePairConstraints() > 0) { // Add all contact interface elements for (int i = 0; i<fem.SurfacePairConstraints(); ++i) { FESurfacePairConstraint* pci = fem.SurfacePairConstraint(i); if (pci->IsActive()) pci->BuildMatrixProfile(G); } } } } //----------------------------------------------------------------------------- //! This function is called right before SolveStep and should be used to initialize //! time dependent information and other settings. bool FESolver::InitStep(double time) { FEModel& fem = *GetFEModel(); // evaluate load controllers values at current time fem.EvaluateLoadControllers(time); // evaluate data generators at current time fem.EvaluateDataGenerators(time); // evaluate load parameters fem.EvaluateLoadParameters(); // re-validate materials // This is necessary since the material parameters can have changed (e.g. via load curves) and thus // a new validation needs to be done to see if the material parameters are still valid. if (fem.ValidateMaterials() == false) return false; return true; } //----------------------------------------------------------------------------- //! This function initializes the equation system. //! It is assumed that all free dofs up until now have been given an ID >= 0 //! and the fixed or rigid dofs an ID < 0. //! After this operation the nodal ID array will contain the equation //! number assigned to the corresponding degree of freedom. To distinguish //! between free or unconstrained dofs and constrained ones the following rules //! apply to the ID array: //! //! / //! | >= 0 --> dof j of node i is a free dof //! ID[i][j] < == -1 --> dof j of node i is a fixed (no equation assigned too) //! | < -1 --> dof j of node i is constrained and has equation nr = -ID[i][j]-2 //! \ //! bool FESolver::InitEquations() { // get the mesh FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); // clear partitions m_part.clear(); // reorder the node numbers int NN = mesh.Nodes(); vector<int> P(NN); // see if we need to optimize the bandwidth if (m_bwopt) { FENodeReorder mod; mod.Apply(mesh, P); } else for (int i = 0; i < NN; ++i) P[i] = i; for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(P[i]); if (node.HasFlags(FENode::EXCLUDE)) for (int j = 0; j < (int)node.m_ID.size(); ++j) node.m_ID[j] = -1; } m_dofMap.clear(); // assign equations based on allocation scheme int neq = 0; if (m_eq_scheme == EQUATION_SCHEME::STAGGERED) { DOFS& dofs = fem.GetDOFS(); if (m_eq_order == EQUATION_ORDER::NORMAL_ORDER) { for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(P[i]); if (node.HasFlags(FENode::EXCLUDE) == false) { for (int nv = 0; nv < dofs.Variables(); ++nv) { int n = dofs.GetVariableSize(nv); for (int l = 0; l < n; ++l) { int nl = dofs.GetDOF(nv, l); if (node.is_active(nl)) { int bcj = node.get_bc(nl); if (bcj == DOF_OPEN ) { node.m_ID[nl] = neq++; m_dofMap.push_back(nl); } else if (bcj == DOF_FIXED ) { node.m_ID[nl] = -1; } else if (bcj == DOF_PRESCRIBED) { node.m_ID[nl] = -neq - 2; neq++; m_dofMap.push_back(nl); } else { assert(false); return false; } } else node.m_ID[nl] = -1; } } } } } else { int NN = mesh.Nodes(); for (int i = NN-1; i >= 0; --i) { FENode& node = mesh.Node(P[i]); if (node.HasFlags(FENode::EXCLUDE) == false) { int dofs = (int)node.m_ID.size(); for (int j = dofs - 1; j >= 0; --j) { if (node.is_active(j)) { int bcj = node.get_bc(j); if (bcj == DOF_OPEN ) { node.m_ID[j] = neq++; m_dofMap.push_back(j); } else if (bcj == DOF_FIXED ) { node.m_ID[j] = -1; } else if (bcj == DOF_PRESCRIBED) { node.m_ID[j] = -neq - 2; neq++; m_dofMap.push_back(j); } else { assert(false); return false; } } else node.m_ID[j] = -1; } } } } // assign partition m_part.push_back(neq); } else { // Assign equations numbers in blocks assert(m_eq_scheme == EQUATION_SCHEME::BLOCK); DOFS& dofs = fem.GetDOFS(); if (m_eq_order == EQUATION_ORDER::NORMAL_ORDER) { for (int nv = 0; nv < dofs.Variables(); ++nv) { int neq0 = neq; for (int i = 0; i < NN; ++i) { FENode& node = mesh.Node(P[i]); if (node.HasFlags(FENode::EXCLUDE) == false) { int n = dofs.GetVariableSize(nv); for (int l = 0; l < n; ++l) { int nl = dofs.GetDOF(nv, l); if (node.is_active(nl)) { int bcl = node.get_bc(nl); if (bcl == DOF_FIXED) { node.m_ID[nl] = -1; } else if (bcl == DOF_OPEN) { node.m_ID[nl] = neq++; m_dofMap.push_back(nl); } else if (bcl == DOF_PRESCRIBED) { node.m_ID[nl] = -neq - 2; neq++; m_dofMap.push_back(nl); } else { assert(false); return false; } } else node.m_ID[nl] = -1; } } } // assign partitions if (neq - neq0 > 0) m_part.push_back(neq - neq0); } } else if (m_eq_order == EQUATION_ORDER::REVERSE_ORDER) { int vars = dofs.Variables(); for (int nv = vars-1; nv >= 0; --nv) { for (int i = 0; i <NN; ++i) { FENode& node = mesh.Node(P[i]); if (node.HasFlags(FENode::EXCLUDE) == false) { int n = dofs.GetVariableSize(nv); for (int l = 0; l < n; ++l) { int nl = dofs.GetDOF(nv, l); if (node.is_active(nl)) { int bcl = node.get_bc(nl); if (bcl == DOF_FIXED ) { node.m_ID[nl] = -1; } else if (bcl == DOF_OPEN ) { node.m_ID[nl] = neq++; m_dofMap.push_back(nl); } else if (bcl == DOF_PRESCRIBED) { node.m_ID[nl] = -neq - 2; neq++; m_dofMap.push_back(nl); } else { assert(false); return false; } } else node.m_ID[nl] = -1; } } } // assign partitions if (nv == vars-1) m_part.push_back(neq); else m_part.push_back(neq - m_part[(vars-1) - nv - 1]); } } else { assert(m_eq_order == FEBIO2_ORDER); // Assign equations numbers in blocks for (int nv = 0; nv < dofs.Variables(); ++nv) { int n = dofs.GetVariableSize(nv); int neq0 = neq; for (int l = 0; l < n; ++l) { int nl = dofs.GetDOF(nv, l); for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); if (node.is_active(nl)) { int bcl = node.get_bc(nl); if (bcl == DOF_FIXED ) { node.m_ID[nl] = -1; } else if (bcl == DOF_OPEN ) { node.m_ID[nl] = neq++; m_dofMap.push_back(nl); } else if (bcl == DOF_PRESCRIBED) { node.m_ID[nl] = -neq - 2; neq++; m_dofMap.push_back(nl); } else { assert(false); return false; } } else node.m_ID[nl] = -1; } } // assign partitions if (neq - neq0 > 0) m_part.push_back(neq - neq0); } } } // store the number of equations m_neq = neq; assert(m_dofMap.size() == m_neq); // All initialization is done return true; } //----------------------------------------------------------------------------- bool FESolver::InitEquations2() { // get the mesh FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); // clear partitions m_part.clear(); // reorder the node numbers int NN = mesh.Nodes(); vector<int> P(NN); // see if we need to optimize the bandwidth if (m_bwopt) { FENodeReorder mod; mod.Apply(mesh, P); } else for (int i = 0; i < NN; ++i) P[i] = i; // reset all equation numbers // first, on all nodes for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(P[i]); if (node.HasFlags(FENode::EXCLUDE)) for (int j = 0; j < (int)node.m_ID.size(); ++j) node.m_ID[j] = -1; } // then, on all elements for (int i = 0; i < mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); for (int j = 0; j < dom.Elements(); ++j) { FEElement& el = dom.ElementRef(j); el.m_lm = -1; } } m_dofMap.clear(); // see if we need to deactivate some nodal dofs based on requested interpolation order for (int i = 0; i < mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); // get the interpolation orders for the different variables. for (int n = 0; n < m_Var.size(); ++n) { FESolutionVariable& var = m_Var[n]; FEDofList& dofs = *var.m_dofs; int P = var.m_order; // set unused dofs to -1 for (int j = 0; j < dom.Elements(); ++j) { FEElement& el = dom.ElementRef(j); int ne = el.Nodes(); int ne_p = el.ShapeFunctions(P); for (int n = ne_p; n < ne; ++n) { FENode& node = mesh.Node(el.m_node[n]); for (int k=0; k<dofs.Size(); ++k) node.set_bc(dofs[k], DOF_FIXED); } } } } // assign equations based on allocation scheme int neq = 0; if ((m_eq_scheme == EQUATION_SCHEME::STAGGERED) && (m_eq_order == EQUATION_ORDER::NORMAL_ORDER)) { for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(P[i]); if (node.HasFlags(FENode::EXCLUDE) == false) { int nvar = (int)m_Var.size(); for (int j = 0; j < nvar; ++j) { FESolutionVariable& var = m_Var[j]; FEDofList& dofs = *var.m_dofs; for (int k = 0; k < dofs.Size(); ++k) { int nk = dofs[k]; if (node.is_active(nk)) { int bck = node.get_bc(nk); if (bck == DOF_OPEN ) { node.m_ID[nk] = neq++; m_dofMap.push_back(nk); } else if (bck == DOF_FIXED ) { node.m_ID[nk] = -1; } else if (bck == DOF_PRESCRIBED) { node.m_ID[nk] = -neq - 2; neq++; m_dofMap.push_back(nk); } } } } } } // assign element dofs for (int i = 0; i < mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); for (int j = 0; j < dom.Elements(); ++j) { FEElement& el = dom.ElementRef(j); for (int n = 0; n < m_Var.size(); ++n) { FESolutionVariable& var = m_Var[n]; if (var.m_order == 0) { FEDofList& dofs = *var.m_dofs; assert(dofs.Size() == 1); assert(el.m_lm == -1); el.m_lm = neq++; m_dofMap.push_back(dofs[0]); } } } } // only one partition for this allocation scheme m_part.push_back(neq); } else if ((m_eq_scheme == EQUATION_SCHEME::BLOCK) && (m_eq_order == EQUATION_ORDER::NORMAL_ORDER)) { int neq0 = 0; int nvar = (int)m_Var.size(); for (int j = 0; j < nvar; ++j) { neq0 = neq; FESolutionVariable& var = m_Var[j]; FEDofList& dofs = *var.m_dofs; if (var.m_order != 0) { for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(P[i]); if (node.HasFlags(FENode::EXCLUDE) == false) { for (int k = 0; k < dofs.Size(); ++k) { int nk = dofs[k]; if (node.is_active(nk)) { int bck = node.get_bc(nk); if (bck == DOF_OPEN ) { node.m_ID[nk] = neq++; m_dofMap.push_back(nk); } else if (bck == DOF_FIXED ) { node.m_ID[nk] = -1; } else if (bck == DOF_PRESCRIBED) { node.m_ID[nk] = -neq - 2; neq++; m_dofMap.push_back(nk); } } } } } } else { assert(dofs.Size() == 1); // assign element dofs for (int i = 0; i < mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); for (int j = 0; j < dom.Elements(); ++j) { FEElement& el = dom.ElementRef(j); FEDofList& dofs = *var.m_dofs; assert(dofs.Size() == 1); assert(el.m_lm == -1); el.m_lm = neq++; m_dofMap.push_back(dofs[0]); } } } // add a partition int partitionSize = neq - neq0; if (partitionSize > 0) m_part.push_back(partitionSize); } } else assert(false); // store the number of equations m_neq = neq; assert(m_dofMap.size() == m_neq); // All initialization is done return true; } //----------------------------------------------------------------------------- //! add equations void FESolver::AddEquations(int neq, int partition) { m_neq += neq; m_part[partition] += neq; } //----------------------------------------------------------------------------- void FESolver::Serialize(DumpStream& ar) { FECoreBase::Serialize(ar); ar & m_nrhs & m_niter & m_nref & m_ntotref & m_naug; } //----------------------------------------------------------------------------- //! Update the state of the model void FESolver::Update(std::vector<double>& u) { assert(false); }; //----------------------------------------------------------------------------- // The augmentation is done after a time step converges and gives model components // an opportunity to modify the model's state. This will usually require that the time // step is solved again. bool FESolver::Augment() { FEModel& fem = *GetFEModel(); const FETimeInfo& tp = fem.GetTime(); // Assume we will pass (can't hurt to be optimistic) bool bconv = true; // Do contact augmentations for (int i = 0; i<fem.SurfacePairConstraints(); ++i) { FESurfacePairConstraint* pci = fem.SurfacePairConstraint(i); if (pci->IsActive()) bconv = (pci->Augment(m_naug, tp) && bconv); } // do nonlinear constraint augmentations for (int i = 0; i<fem.NonlinearConstraints(); ++i) { FENLConstraint* plc = fem.NonlinearConstraint(i); if (plc->IsActive()) bconv = plc->Augment(m_naug, tp) && bconv; } // do domain augmentations FEMesh& mesh = fem.GetMesh(); for (int i = 0; i<mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); bconv = dom.Augment(m_naug) && bconv; } fem.GetTime().augmentation++; return bconv; } //----------------------------------------------------------------------------- // return the node (mesh index) from an equation number FENodalDofInfo FESolver::GetDOFInfoFromEquation(int ieq) { FENodalDofInfo info; info.m_eq = ieq; info.m_node = -1; info.m_dof = -1; info.szdof = ""; FEModel& fem = *GetFEModel(); FEMesh& mesh = fem.GetMesh(); for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); vector<int>& id = node.m_ID; for (int j = 0; j < id.size(); ++j) { if (id[j] == ieq) { info.m_node = node.GetID(); info.m_dof = j; DOFS& Dofs = GetFEModel()->GetDOFS(); info.szdof = Dofs.GetDOFName(info.m_dof); if (info.szdof == nullptr) info.szdof = "???"; return info; } } } return info; }
C++
3D
febiosoftware/FEBio
FECore/FESurfaceToSurfaceMap.cpp
.cpp
3,823
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.*/ #include "stdafx.h" #include "FESurfaceToSurfaceMap.h" #include "FEMesh.h" #include "FESurface.h" #include <FECore/FEDomainMap.h> BEGIN_FECORE_CLASS(FESurfaceToSurfaceMap, FEElemDataGenerator) ADD_PROPERTY(m_func, "function"); ADD_PROPERTY(m_surf1, "bottom_surface", FEProperty::Reference); ADD_PROPERTY(m_surf2, "top_surface", FEProperty::Reference); END_FECORE_CLASS(); FESurfaceToSurfaceMap::FESurfaceToSurfaceMap(FEModel* fem) : FEElemDataGenerator(fem) { m_ccp1 = 0; m_ccp2 = 0; m_func = 0; m_surf1 = nullptr; m_surf2 = nullptr; m_binverted = false; } FESurfaceToSurfaceMap::~FESurfaceToSurfaceMap() { if (m_ccp1) delete m_ccp1; if (m_ccp2) delete m_ccp2; } bool FESurfaceToSurfaceMap::Init() { FEMesh& mesh = GetMesh(); if (m_func == 0) return false; if ((m_surf1 == nullptr) || (m_surf2 == nullptr)) return false; // we need to invert the second surface, otherwise the normal projections won't work if (m_binverted == false) { m_surf2->Invert(); m_binverted = true; } // initialize projections if (m_ccp1 == nullptr) { m_ccp1 = new FEClosestPointProjection(*m_surf1); m_ccp1->HandleSpecialCases(true); m_ccp1->AllowBoundaryProjections(true); if (m_ccp1->Init() == false) return false; } if (m_ccp2 == nullptr) { m_ccp2 = new FEClosestPointProjection(*m_surf2); m_ccp2->HandleSpecialCases(true); m_ccp2->AllowBoundaryProjections(true); if (m_ccp2->Init() == false) return false; } m_func->Init(); return FEMeshDataGenerator::Init(); } double FESurfaceToSurfaceMap::value(const vec3d& x) { vec3d r(x); // project x onto surface 1 vec3d q1(0,0,0), q2(0,0,0); vec2d r1, r2; FESurfaceElement* pe1 = m_ccp1->Project(r, q1, r1); if (pe1 == nullptr) { assert(false); return 0.0; } // project x onto surface 2 FESurfaceElement* pe2 = m_ccp2->Project(r, q2, r2); if (pe2 == nullptr) { assert(false); return 0.0; } double L1 = (x - q1).norm(); double L2 = (q2 - x).norm(); double D = L1 + L2; if (D == 0.0) D = 1.0; // find the fractional distance double w = L1 / D; // evaluate the function return m_func->value(w); } FEDataMap* FESurfaceToSurfaceMap::Generate() { FEElementSet* elset = GetElementSet(); if (elset == nullptr) return nullptr; FEDomainMap* map = new FEDomainMap(FEDataType::FE_DOUBLE, Storage_Fmt::FMT_NODE); map->Create(elset); FENodeList nodeList = elset->GetNodeList(); for (int i = 0; i < nodeList.Size(); ++i) { FENode* pn = nodeList.Node(i); double v = value(pn->m_r0); map->setValue(i, v); } return map; }
C++
3D
febiosoftware/FEBio
FECore/SchurComplement.cpp
.cpp
3,472
143
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "SchurComplement.h" SchurComplementA::SchurComplementA(LinearSolver* A, SparseMatrix* B, SparseMatrix* C, SparseMatrix* D) { m_print_level = 0; m_A = A; m_B = B; m_C = C; m_D = D; int n0 = m_B->Rows(); int n1 = m_B->Columns(); assert(n0 == m_C->Columns()); assert(n1 == m_C->Rows()); m_tmp1.resize(n0, 0.0); m_tmp2.resize(n0, 0.0); m_tmp3.resize(n1, 0.0); m_nrow = n1; m_ncol = n1; m_bnegate = false; } // negate schur complement void SchurComplementA::NegateSchur(bool b) { m_bnegate = b; } // set the print level void SchurComplementA::SetPrintLevel(int printLevel) { m_print_level = printLevel; } //! multiply with vector bool SchurComplementA::mult_vector(double* x, double* r) { m_B->mult_vector(x, &m_tmp1[0]); if (m_print_level != 0) printf("backsolving in SchurComplement\n"); if (m_A) { if (m_A->BackSolve(m_tmp2, m_tmp1) == false) return false; } else m_tmp2 = m_tmp1; m_C->mult_vector(&m_tmp2[0], r); if (m_D) { if (m_D->mult_vector(x, &m_tmp3[0]) == false) return false; size_t n = m_tmp3.size(); for (size_t i = 0; i<n; ++i) r[i] -= m_tmp3[i]; } if (m_bnegate) { size_t n = m_tmp3.size(); for (int i = 0; i < n; ++i) r[i] = -r[i]; } return true; } SchurComplementD::SchurComplementD(SparseMatrix* A, SparseMatrix* B, SparseMatrix* C, LinearSolver* D) { m_print_level = 0; m_A = A; m_B = B; m_C = C; m_D = D; int n0 = m_B->Rows(); int n1 = m_B->Columns(); assert(n0 == m_C->Columns()); assert(n1 == m_C->Rows()); m_tmp1.resize(n1, 0.0); m_tmp2.resize(n1, 0.0); m_tmp3.resize(n0, 0.0); m_nrow = n0; m_ncol = n0; } // set the print level void SchurComplementD::SetPrintLevel(int printLevel) { m_print_level = printLevel; } //! multiply with vector bool SchurComplementD::mult_vector(double* x, double* r) { m_C->mult_vector(x, &m_tmp1[0]); if (m_print_level != 0) printf("backsolving in SchurComplement\n"); if (m_D->BackSolve(m_tmp2, m_tmp1) == false) return false; m_B->mult_vector(&m_tmp2[0], r); if (m_A) { if (m_A->mult_vector(x, &m_tmp3[0]) == false) return false; size_t n = m_tmp3.size(); for (size_t i = 0; i<n; ++i) r[i] -= m_tmp3[i]; } return true; }
C++
3D
febiosoftware/FEBio
FECore/FENodalLoad.cpp
.cpp
5,992
228
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FENodalLoad.h" #include "FENodeSet.h" #include "DumpStream.h" #include "FENode.h" #include "FEMaterialPoint.h" //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FENodalLoad, FEModelLoad) ADD_PARAMETER(m_brelative, "relative"); // ADD_PROPERTY(m_nodeSet, "node_set", FEProperty::Reference); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FENodalLoad::FENodalLoad(FEModel* pfem) : FEModelLoad(pfem), m_dofs(pfem) { m_brelative = false; m_nodeSet = nullptr; } //----------------------------------------------------------------------------- void FENodalLoad::Serialize(DumpStream& ar) { FEModelComponent::Serialize(ar); if (ar.IsShallow()) return; ar & m_dofs & m_nodeSet; } //----------------------------------------------------------------------------- bool FENodalLoad::Init() { // Make sure we have a node set if (m_nodeSet == nullptr) return false; // Get the DOF list from the derived class m_dofs.Clear(); if (SetDofList(m_dofs) == false) return false; // make sure the dof list is not empty if (m_dofs.IsEmpty()) return false; // so far so good. return FEModelLoad::Init(); } //----------------------------------------------------------------------------- //! activation void FENodalLoad::Activate() { FEModelLoad::Activate(); if (m_brelative) { int nodes = m_nodeSet->Size(); int dofs = m_dofs.Size(); if ((dofs == 0) || (nodes == 0)) return; m_rval.resize(nodes, vector<double>(dofs, 0.0)); // get the current nodal loads for (int i = 0; i < nodes; ++i) { FENode& node = *m_nodeSet->Node(i); for (int j = 0; j < dofs; ++j) { m_rval[i][j] = -node.get_load(m_dofs[j]); } } } } //----------------------------------------------------------------------------- //! Get the DOF list const FEDofList& FENodalLoad::GetDOFList() const { return m_dofs; } //----------------------------------------------------------------------------- void FENodalLoad::SetNodeSet(FENodeSet* ns) { m_nodeSet = ns; } //----------------------------------------------------------------------------- //! get the nodeset FENodeSet* FENodalLoad::GetNodeSet() { return m_nodeSet; } //----------------------------------------------------------------------------- void FENodalLoad::LoadVector(FEGlobalVector& R) { FENodeSet& nset = *m_nodeSet; int dofs = m_dofs.Size(); vector<double> val(dofs, 0.0); int N = nset.Size(); for (int i = 0; i<N; ++i) { int nid = nset[i]; // get the nodal values GetNodalValues(i, val); // add relative values if (m_brelative) { for (int j = 0; j < dofs; ++j) val[j] += m_rval[i][j]; } // assemble into residual for (int j=0; j<dofs; ++j) R.Assemble(nid, m_dofs[j], val[j]); } } //----------------------------------------------------------------------------- void FENodalLoad::StiffnessMatrix(FELinearSystem& LS) { // Nothing to do here. } //----------------------------------------------------------------------------- BEGIN_FECORE_CLASS(FENodalDOFLoad, FENodalLoad) ADD_PARAMETER(m_dof, "dof", 0, "$(dof_list)"); ADD_PARAMETER(m_scale, "scale")->SetFlags(FE_PARAM_ADDLC | FE_PARAM_VOLATILE); END_FECORE_CLASS(); //----------------------------------------------------------------------------- FENodalDOFLoad::FENodalDOFLoad(FEModel* fem) : FENodalLoad(fem) { m_dof = -1; m_scale = 0.0; m_dtscale = false; } //----------------------------------------------------------------------------- void FENodalDOFLoad::SetDtScale(bool b) { m_dtscale = b; } //----------------------------------------------------------------------------- void FENodalDOFLoad::SetLoad(double s) { m_scale = s; } //----------------------------------------------------------------------------- bool FENodalDOFLoad::SetDofList(FEDofList& dofList) { return dofList.AddDof(m_dof); } //----------------------------------------------------------------------------- //! Return the current value of the nodal load void FENodalDOFLoad::GetNodalValues(int n, std::vector<double>& val) { assert(val.size() == 1); const FENodeSet& nset = *GetNodeSet(); int nid = nset[n]; const FENode& node = *nset.Node(n); FEMaterialPoint mp; mp.m_r0 = node.m_r0; mp.m_index = n; val[0] = m_scale(mp); if (m_dtscale) { double dt = GetTimeInfo().timeIncrement; val[0] *= dt; } } double FENodalDOFLoad::NodeValue(int n) { const FENodeSet& nset = *GetNodeSet(); int nid = nset[n]; const FENode& node = *nset.Node(n); FEMaterialPoint mp; mp.m_r0 = node.m_r0; mp.m_index = n; double val = m_scale(mp); if (m_dtscale) { double dt = GetTimeInfo().timeIncrement; val *= dt; } return val; }
C++
3D
febiosoftware/FEBio
FECore/FEElementTraits.cpp
.cpp
135,005
4,253
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEElementTraits.h" #include "FEElement.h" #include "FEException.h" #include "FESolidElementShape.h" #include "FESurfaceElementShape.h" using namespace std; #ifndef SQR #define SQR(x) ((x)*(x)) #endif FEElementTraits::FEElementTraits(int ni, int ne, FE_Element_Class c, FE_Element_Shape s, FE_Element_Type t) { m_neln = ne; m_nint = ni; m_faces = 0; m_spec.eclass = c; m_spec.eshape = s; m_spec.etype = t; m_H.resize(ni, ne); } //----------------------------------------------------------------------------- //! project mat3ds integration point data to nodes void FEElementTraits::project_to_nodes(mat3ds* si, mat3ds* so) const { double ai[FEElement::MAX_INTPOINTS]; double ao[FEElement::MAX_NODES]; for (int i = 0; i<3; ++i) { for (int j = i; j<3; ++j) { for (int n = 0; n<m_nint; ++n) ai[n] = si[n](i, j); project_to_nodes(ai, ao); for (int n = 0; n<m_neln; ++n) so[n](i, j) = ao[n]; } } } //----------------------------------------------------------------------------- //! project mat3d integration point data to nodes void FEElementTraits::project_to_nodes(mat3d* si, mat3d* so) const { double ai[FEElement::MAX_INTPOINTS]; double ao[FEElement::MAX_NODES]; for (int i = 0; i<3; ++i) { for (int j = 0; j<3; ++j) { for (int n = 0; n<m_nint; ++n) ai[n] = si[n](i, j); project_to_nodes(ai, ao); for (int n = 0; n<m_neln; ++n) so[n](i, j) = ao[n]; } } } //----------------------------------------------------------------------------- //! project vec3d integration point data to nodes void FEElementTraits::project_to_nodes(vec3d* si, vec3d* so) const { double ai[FEElement::MAX_INTPOINTS]; double ao[FEElement::MAX_NODES]; for (int n = 0; n<m_nint; ++n) ai[n] = si[n].x; project_to_nodes(ai, ao); for (int n = 0; n<m_neln; ++n) so[n].x = ao[n]; for (int n = 0; n<m_nint; ++n) ai[n] = si[n].y; project_to_nodes(ai, ao); for (int n = 0; n<m_neln; ++n) so[n].y = ao[n]; for (int n = 0; n<m_nint; ++n) ai[n] = si[n].z; project_to_nodes(ai, ao); for (int n = 0; n<m_neln; ++n) so[n].z = ao[n]; } //============================================================================= FESolidElementTraits::FESolidElementTraits(int ni, int ne, FE_Element_Shape eshape, FE_Element_Type etype) : FEElementTraits(ni, ne, FE_ELEM_SOLID, eshape, etype) { m_shape = nullptr; gr.resize(ni); gs.resize(ni); gt.resize(ni); gw.resize(ni); m_Gr.resize(ni, ne); m_Gs.resize(ni, ne); m_Gt.resize(ni, ne); Grr.resize(ni, ne); Gsr.resize(ni, ne); Gtr.resize(ni, ne); Grs.resize(ni, ne); Gss.resize(ni, ne); Gts.resize(ni, ne); Grt.resize(ni, ne); Gst.resize(ni, ne); Gtt.resize(ni, ne); // TODO: Move this to the individual classes? m_faces = 0; switch (eshape) { case ET_TET4: case ET_TET5: case ET_TET10: case ET_TET15: case ET_TET20: m_faces = 4; break; case ET_PENTA6: case ET_PENTA15: m_faces = 5; break; case ET_HEX8: case ET_HEX20: case ET_HEX27: m_faces = 6; break; case ET_PYRA5: case ET_PYRA13: m_faces = 5; break; default: assert(false); } } //----------------------------------------------------------------------------- int FESolidElementTraits::ShapeFunctions(int order) { FESolidElementShape* shape = m_shapeP[order]; return (shape ? shape->nodes(): 0); } //----------------------------------------------------------------------------- //! initialize element traits data void FESolidElementTraits::init() { assert(m_nint > 0); assert(m_neln > 0); const int NELN = FEElement::MAX_NODES; // get shape class m_shape = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(m_spec.eshape)); assert(m_shape && (m_shape->shape() == m_spec.eshape)); // calculate shape function values at gauss points double N[NELN]; for (int n=0; n<m_nint; ++n) { m_shape->shape_fnc(N, gr[n], gs[n], gt[n]); for (int i=0; i<m_neln; ++i) m_H[n][i] = N[i]; } // calculate local derivatives of shape functions at gauss points double Hr[NELN], Hs[NELN], Ht[NELN]; for (int n=0; n<m_nint; ++n) { m_shape->shape_deriv(Hr, Hs, Ht, gr[n], gs[n], gt[n]); for (int i=0; i<m_neln; ++i) { m_Gr[n][i] = Hr[i]; m_Gs[n][i] = Hs[i]; m_Gt[n][i] = Ht[i]; } } // calculate local second derivatives of shape functions at gauss points double Hrr[NELN], Hss[NELN], Htt[NELN], Hrs[NELN], Hst[NELN], Hrt[NELN]; for (int n=0; n<m_nint; ++n) { m_shape->shape_deriv2(Hrr, Hss, Htt, Hrs, Hst, Hrt, gr[n], gs[n], gt[n]); for (int i=0; i<m_neln; ++i) { Grr[n][i] = Hrr[i]; Grs[n][i] = Hrs[i]; Grt[n][i] = Hrt[i]; Gsr[n][i] = Hrs[i]; Gss[n][i] = Hss[i]; Gst[n][i] = Hst[i]; Gtr[n][i] = Hrt[i]; Gts[n][i] = Hst[i]; Gtt[n][i] = Htt[i]; } } // NOTE: Below, is a new interface for dealing with mixed element formulations. // This is still a work in progress. // Get the max interpolation order const int maxOrder = (int) m_shapeP.size() - 1; m_Hp.resize(maxOrder + 1); m_Gr_p.resize(maxOrder + 1); m_Gs_p.resize(maxOrder + 1); m_Gt_p.resize(maxOrder + 1); for (int i = 0; i <= maxOrder; ++i) { FESolidElementShape* shape = m_shapeP[i]; matrix& H = m_Hp[i]; matrix& Gr = m_Gr_p[i]; matrix& Gs = m_Gs_p[i]; matrix& Gt = m_Gt_p[i]; if (i == 0) { H.resize(m_nint, 1); Gr.resize(m_nint, 1); Gs.resize(m_nint, 1); Gt.resize(m_nint, 1); for (int n = 0; n < m_nint; ++n) { H[n][0] = 1.0; Gr[n][0] = Gs[n][0] = Gt[n][0] = 0.0; } } else if (m_shapeP[i]) { // get the nodes int neln = shape->nodes(); // shape function values H.resize(m_nint, neln); for (int n = 0; n<m_nint; ++n) { m_shapeP[i]->shape_fnc(N, gr[n], gs[n], gt[n]); for (int j = 0; j<neln; ++j) H[n][j] = N[j]; } // calculate local derivatives of shape functions at gauss points Gr.resize(m_nint, neln); Gs.resize(m_nint, neln); Gt.resize(m_nint, neln); for (int n = 0; n<m_nint; ++n) { shape->shape_deriv(Hr, Hs, Ht, gr[n], gs[n], gt[n]); for (int j = 0; j<neln; ++j) { Gr[n][j] = Hr[j]; Gs[n][j] = Hs[j]; Gt[n][j] = Ht[j]; } } } } } //! values of shape functions void FESolidElementTraits::shape_fnc(double* H, double r, double s, double t) { return m_shape->shape_fnc(H, r, s, t); } //! values of shape function derivatives void FESolidElementTraits::shape_deriv(double* Hr, double* Hs, double* Ht, double r, double s, double t) { return m_shape->shape_deriv(Hr, Hs, Ht, r, s, t); } //! values of shape function second derivatives void FESolidElementTraits::shape_deriv2(double* Hrr, double* Hss, double* Htt, double* Hrs, double* Hst, double* Hrt, double r, double s, double t) { return m_shape->shape_deriv2(Hrr, Hss, Htt, Hrs, Hst, Hrt, r, s, t); } //============================================================================= // F E H E X 8 //============================================================================= void FEHex8_::init() { // allocate shape classes m_shapeP.resize(2); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_HEX8)); // initialize base class FESolidElementTraits::init(); } //***************************************************************************** // H E X 8 G 8 //***************************************************************************** FEHex8G8::FEHex8G8() : FEHex8_(NINT, FE_HEX8G8) { // integration point coordinates const double a = 1.0 / sqrt(3.0); gr[0] = -a; gs[0] = -a; gt[0] = -a; gw[0] = 1; gr[1] = a; gs[1] = -a; gt[1] = -a; gw[1] = 1; gr[2] = a; gs[2] = a; gt[2] = -a; gw[2] = 1; gr[3] = -a; gs[3] = a; gt[3] = -a; gw[3] = 1; gr[4] = -a; gs[4] = -a; gt[4] = a; gw[4] = 1; gr[5] = a; gs[5] = -a; gt[5] = a; gw[5] = 1; gr[6] = a; gs[6] = a; gt[6] = a; gw[6] = 1; gr[7] = -a; gs[7] = a; gt[7] = a; gw[7] = 1; init(); m_Hi = m_H.inverse(); } //----------------------------------------------------------------------------- void FEHex8G8::project_to_nodes(double* ai, double* ao) const { for (int j=0; j<NELN; ++j) { ao[j] = 0; for (int k=0; k<NINT; ++k) { ao[j] += m_Hi[j][k]*ai[k]; } } } //***************************************************************************** // F E H E X R I //***************************************************************************** FEHex8RI::FEHex8RI(): FEHex8_(NINT, FE_HEX8RI) { // This is for a six point integration rule // integration point coordinates const double a = 8.0 / 6.0; gr[0] = -1; gs[0] = 0; gt[0] = 0; gw[0] = a; gr[1] = 1; gs[1] = 0; gt[1] = 0; gw[1] = a; gr[2] = 0; gs[2] =-1; gt[2] = 0; gw[2] = a; gr[3] = 0; gs[3] = 1; gt[3] = 0; gw[3] = a; gr[4] = 0; gs[4] = 0; gt[4] =-1; gw[4] = a; gr[5] = 0; gs[5] = 0; gt[5] = 1; gw[5] = a; init(); } //----------------------------------------------------------------------------- //! \todo implement this void FEHex8RI::project_to_nodes(double* ai, double* ao) const { } //***************************************************************************** // F E H E X G 1 //***************************************************************************** FEHex8G1::FEHex8G1() : FEHex8_(NINT, FE_HEX8G1) { // single gauss-point integration rule gr[0] = 0; gs[0] = 0; gt[0] = 0; gw[0] = 8.0; init(); } //----------------------------------------------------------------------------- void FEHex8G1::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[0]; ao[2] = ai[0]; ao[3] = ai[0]; ao[4] = ai[0]; ao[5] = ai[0]; ao[6] = ai[0]; ao[7] = ai[0]; } //============================================================================= // F E T E T 4 //============================================================================= //! initialize element traits data void FETet4_::init() { // allocate shape classes m_shapeP.resize(2); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TET4)); // initialize base class FESolidElementTraits::init(); } //============================================================================= // T E T 4 //============================================================================= FETet4G4::FETet4G4() : FETet4_(NINT, FE_TET4G4) { // gaussian integration for tetrahedral elements const double a = 0.58541020; const double b = 0.13819660; const double w = 1.0 / 24.0; gr[0] = b; gs[0] = b; gt[0] = b; gw[0] = w; gr[1] = a; gs[1] = b; gt[1] = b; gw[1] = w; gr[2] = b; gs[2] = a; gt[2] = b; gw[2] = w; gr[3] = b; gs[3] = b; gt[3] = a; gw[3] = w; init(); m_Hi = m_H.inverse(); } //----------------------------------------------------------------------------- void FETet4G4::project_to_nodes(double* ai, double* ao) const { for (int j=0; j<NELN; ++j) { ao[j] = 0; for (int k=0; k<NINT; ++k) { ao[j] += m_Hi[j][k]*ai[k]; } } } //============================================================================= // F E T E T 5 //============================================================================= //! initialize element traits data void FETet5_::init() { // allocate shape classes m_shapeP.resize(3); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TET4)); m_shapeP[2] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TET5)); // initialize base class FESolidElementTraits::init(); } //============================================================================= // T E T 5 G 4 //============================================================================= FETet5G4::FETet5G4() : FETet5_(NINT, FE_TET5G4) { // gaussian integration for tetrahedral elements const double a = 0.58541020; const double b = 0.13819660; const double w = 1.0 / 24.0; gr[0] = b; gs[0] = b; gt[0] = b; gw[0] = w; gr[1] = a; gs[1] = b; gt[1] = b; gw[1] = w; gr[2] = b; gs[2] = a; gt[2] = b; gw[2] = w; gr[3] = b; gs[3] = b; gt[3] = a; gw[3] = w; init(); } //----------------------------------------------------------------------------- void FETet5G4::project_to_nodes(double* ai, double* ao) const { // TODO: implement this assert(false); } //============================================================================= // F E G 1 T E T E L E M E N T //============================================================================= FETet4G1::FETet4G1() : FETet4_(NINT, FE_TET4G1) { // gaussian integration for tetrahedral elements const double a = 0.25; const double w = 1.0 / 6.0; gr[0] = a; gs[0] = a; gt[0] = a; gw[0] = w; init(); } //----------------------------------------------------------------------------- void FETet4G1::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[0]; ao[2] = ai[0]; ao[3] = ai[0]; } //============================================================================= // P E N T A 6 //============================================================================= void FEPenta6_::init() { // allocate shape classes m_shapeP.resize(2); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_PENTA6)); // initialize base class FESolidElementTraits::init(); } //============================================================================= // P E N T A 6 G 6 //============================================================================= FEPenta6G6::FEPenta6G6(): FEPenta6_(NINT, FE_PENTA6G6) { //gauss intergration points const double a = 1.0/6.0; const double b = 2.0/3.0; const double c = 1.0 / sqrt(3.0); const double w = 1.0 / 6.0; gr[0] = a; gs[0] = a; gt[0] = -c; gw[0] = w; gr[1] = b; gs[1] = a; gt[1] = -c; gw[1] = w; gr[2] = a; gs[2] = b; gt[2] = -c; gw[2] = w; gr[3] = a; gs[3] = a; gt[3] = c; gw[3] = w; gr[4] = b; gs[4] = a; gt[4] = c; gw[4] = w; gr[5] = a; gs[5] = b; gt[5] = c; gw[5] = w; init(); m_Hi = m_H.inverse(); } //----------------------------------------------------------------------------- void FEPenta6G6::project_to_nodes(double* ai, double* ao) const { for (int j=0; j<NELN; ++j) { ao[j] = 0; for (int k=0; k<NINT; ++k) { ao[j] += m_Hi[j][k]*ai[k]; } } } //============================================================================= // P E N T A 1 5 //============================================================================= //============================================================================= // F E P E N T A 1 5 G 8 //============================================================================= int FEPenta15G8::ni[NELN] = {}; FEPenta15G8::FEPenta15G8() : FEPenta15_(NINT, FE_PENTA15G8) { const double a = 1.0/3.0; const double b = 1.0/5.0; const double c = 3.0/5.0; const double d = sqrt(a); gr[0] = a; gs[0] = a; gt[0] = -d; gw[0] = -27.0/96.0; gr[1] = c; gs[1] = b; gt[1] = -d; gw[1] = 25.0/96.0; gr[2] = b; gs[2] = b; gt[2] = -d; gw[2] = 25.0/96.0; gr[3] = b; gs[3] = c; gt[3] = -d; gw[3] = 25.0/96.0; gr[4] = a; gs[4] = a; gt[4] = d; gw[4] = -27.0/96.0; gr[5] = c; gs[5] = b; gt[5] = d; gw[5] = 25.0/96.0; gr[6] = b; gs[6] = b; gt[6] = d; gw[6] = 25.0/96.0; gr[7] = b; gs[7] = c; gt[7] = d; gw[7] = 25.0/96.0; init(); m_MT.resize(NELN, NINT); for (int i=0; i<NINT; ++i) for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n); m_Hi.resize(NELN, NELN); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes //! Use least-squares extrapolation void FEPenta15G8::project_to_nodes(double* ai, double* ao) const { double v[NELN]; for (int n=0; n<NELN; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<NELN; ++j) { ao[j] = 0; for (int k=0; k<NELN; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //============================================================================= // F E P E N T A 1 5 G 2 1 //============================================================================= int FEPenta15G21::ni[NELN] = { 1, 2, 3, 4, 5, 6, 8, 9, 10, 15, 16, 17, 18, 19, 20 }; FEPenta15G21::FEPenta15G21() : FEPenta15_(NINT, FE_PENTA15G21) { const double w = 1.0/2.0; const double a = 0.774596669241483; const double w1 = 5.0 / 9.0; const double w2 = 8.0 / 9.0; gr[ 0] = 0.333333333333333; gs[ 0] = 0.333333333333333; gt[ 0] = -a; gw[ 0] = w*w1*0.225000000000000; gr[ 1] = 0.797426985353087; gs[ 1] = 0.101286507323456; gt[ 1] = -a; gw[ 1] = w*w1*0.125939180544827; gr[ 2] = 0.101286507323456; gs[ 2] = 0.797426985353087; gt[ 2] = -a; gw[ 2] = w*w1*0.125939180544827; gr[ 3] = 0.101286507323456; gs[ 3] = 0.101286507323456; gt[ 3] = -a; gw[ 3] = w*w1*0.125939180544827; gr[ 4] = 0.470142064105115; gs[ 4] = 0.470142064105115; gt[ 4] = -a; gw[ 4] = w*w1*0.132394152788506; gr[ 5] = 0.470142064105115; gs[ 5] = 0.059715871789770; gt[ 5] = -a; gw[ 5] = w*w1*0.132394152788506; gr[ 6] = 0.059715871789770; gs[ 6] = 0.470142064105115; gt[ 6] = -a; gw[ 6] = w*w1*0.132394152788506; gr[ 7] = 0.333333333333333; gs[ 7] = 0.333333333333333; gt[ 7] = 0; gw[ 7] = w*w2*0.225000000000000; gr[ 8] = 0.797426985353087; gs[ 8] = 0.101286507323456; gt[ 8] = 0; gw[ 8] = w*w2*0.125939180544827; gr[ 9] = 0.101286507323456; gs[ 9] = 0.797426985353087; gt[ 9] = 0; gw[ 9] = w*w2*0.125939180544827; gr[10] = 0.101286507323456; gs[10] = 0.101286507323456; gt[10] = 0; gw[10] = w*w2*0.125939180544827; gr[11] = 0.470142064105115; gs[11] = 0.470142064105115; gt[11] = 0; gw[11] = w*w2*0.132394152788506; gr[12] = 0.470142064105115; gs[12] = 0.059715871789770; gt[12] = 0; gw[12] = w*w2*0.132394152788506; gr[13] = 0.059715871789770; gs[13] = 0.470142064105115; gt[13] = 0; gw[13] = w*w2*0.132394152788506; gr[14] = 0.333333333333333; gs[14] = 0.333333333333333; gt[14] = a; gw[14] = w*w1*0.225000000000000; gr[15] = 0.797426985353087; gs[15] = 0.101286507323456; gt[15] = a; gw[15] = w*w1*0.125939180544827; gr[16] = 0.101286507323456; gs[16] = 0.797426985353087; gt[16] = a; gw[16] = w*w1*0.125939180544827; gr[17] = 0.101286507323456; gs[17] = 0.101286507323456; gt[17] = a; gw[17] = w*w1*0.125939180544827; gr[18] = 0.470142064105115; gs[18] = 0.470142064105115; gt[18] = a; gw[18] = w*w1*0.132394152788506; gr[19] = 0.470142064105115; gs[19] = 0.059715871789770; gt[19] = a; gw[19] = w*w1*0.132394152788506; gr[20] = 0.059715871789770; gs[20] = 0.470142064105115; gt[20] = a; gw[20] = w*w1*0.132394152788506; init(); m_MT.resize(NELN, NINT); for (int i=0; i<NINT; ++i) for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n); m_Hi.resize(NELN, NELN); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEPenta15G21::project_to_nodes(double* ai, double* ao) const { double v[NELN]; for (int n=0; n<NELN; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<NELN; ++j) { ao[j] = 0; for (int k=0; k<NELN; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //============================================================================= // T E T 1 0 //============================================================================= //! initialize element traits data void FETet10_::init() { // allocate shape classes m_shapeP.resize(3); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TET4)); m_shapeP[2] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TET10)); // initialize base class FESolidElementTraits::init(); } //============================================================================= // T E T 1 0 G 1 //============================================================================= FETet10G1::FETet10G1() : FETet10_(NINT, FE_TET10G1) { // gaussian integration for tetrahedral elements const double a = 0.25; const double w = 1.0 / 6.0; gr[0] = a; gs[0] = a; gt[0] = a; gw[0] = w; init(); } //----------------------------------------------------------------------------- void FETet10G1::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[0]; ao[2] = ai[0]; ao[3] = ai[0]; ao[4] = ai[0]; ao[5] = ai[0]; ao[6] = ai[0]; ao[7] = ai[0]; ao[8] = ai[0]; ao[9] = ai[0]; } //***************************************************************************** // F E T E T 1 0 E L E M E N T //***************************************************************************** // I think this assumes that the tetrahedron in natural space is essentially // a constant metric tet with the edge nodes at the center of the edges. FETet10G4::FETet10G4() : FETet10_(NINT, FE_TET10G4) { // integration point coordinates const double a = 0.58541020; const double b = 0.13819660; const double w = 0.25 / 6.0; gr[ 0] = a; gs[ 0] = b; gt[ 0] = b; gw[ 0] = w; gr[ 1] = b; gs[ 1] = a; gt[ 1] = b; gw[ 1] = w; gr[ 2] = b; gs[ 2] = b; gt[ 2] = a; gw[ 2] = w; gr[ 3] = b; gs[ 3] = b; gt[ 3] = b; gw[ 3] = w; init(); // setup the shape function matrix matrix A(4,4); for (int i=0; i<4; ++i) { double r = gr[i]; double s = gs[i]; double t = gt[i]; A[i][0] = 1 - r - s - t; A[i][1] = r; A[i][2] = s; A[i][3] = t; } // calculate inverse matrix Ai.resize(4, 4); Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETet10G4::project_to_nodes(double* ai, double* ao) const { ao[0] = Ai[0][0]*ai[0] + Ai[0][1]*ai[1] + Ai[0][2]*ai[2] + Ai[0][3]*ai[3]; ao[1] = Ai[1][0]*ai[0] + Ai[1][1]*ai[1] + Ai[1][2]*ai[2] + Ai[1][3]*ai[3]; ao[2] = Ai[2][0]*ai[0] + Ai[2][1]*ai[1] + Ai[2][2]*ai[2] + Ai[2][3]*ai[3]; ao[3] = Ai[3][0]*ai[0] + Ai[3][1]*ai[1] + Ai[3][2]*ai[2] + Ai[3][3]*ai[3]; ao[4] = 0.5*(ao[0] + ao[1]); ao[5] = 0.5*(ao[1] + ao[2]); ao[6] = 0.5*(ao[2] + ao[0]); ao[7] = 0.5*(ao[0] + ao[3]); ao[8] = 0.5*(ao[1] + ao[3]); ao[9] = 0.5*(ao[2] + ao[3]); } //============================================================================= // T E T 1 0 G 8 //============================================================================= // I think this assumes that the tetrahedron in natural space is essentially // a constant metric tet with the edge nodes at the center of the edges. FETet10G8::FETet10G8() : FETet10_(NINT, FE_TET10G8) { const double w = 1.0/6.0; gr[0] = 0.0158359099; gs[0] = 0.3280546970; gt[0] = 0.3280546970; gw[0] = 0.138527967*w; gr[1] = 0.3280546970; gs[1] = 0.0158359099; gt[1] = 0.3280546970; gw[1] = 0.138527967*w; gr[2] = 0.3280546970; gs[2] = 0.3280546970; gt[2] = 0.0158359099; gw[2] = 0.138527967*w; gr[3] = 0.3280546970; gs[3] = 0.3280546970; gt[3] = 0.3280546970; gw[3] = 0.138527967*w; gr[4] = 0.6791431780; gs[4] = 0.1069522740; gt[4] = 0.1069522740; gw[4] = 0.111472033*w; gr[5] = 0.1069522740; gs[5] = 0.6791431780; gt[5] = 0.1069522740; gw[5] = 0.111472033*w; gr[6] = 0.1069522740; gs[6] = 0.1069522740; gt[6] = 0.6791431780; gw[6] = 0.111472033*w; gr[7] = 0.1069522740; gs[7] = 0.1069522740; gt[7] = 0.1069522740; gw[7] = 0.111472033*w; init(); // setup the shape function matrix N.resize(8, 4); for (int i=0; i<8; ++i) { N[i][0] = 1.0 - gr[i] - gs[i] - gt[i]; N[i][1] = gr[i]; N[i][2] = gs[i]; N[i][3] = gt[i]; } matrix A(4, 4); A = N.transpose()*N; // calculate inverse matrix Ai.resize(4, 4); Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETet10G8::project_to_nodes(double* ai, double* ao) const { vector<double> b(4); for (int i=0; i<4; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += N[j][i]*ai[j]; } for (int i=0; i<4; ++i) { ao[i] = 0.0; for (int j=0; j<4; ++j) ao[i] += Ai[i][j]*b[j]; } ao[4] = 0.5*(ao[0] + ao[1]); ao[5] = 0.5*(ao[1] + ao[2]); ao[6] = 0.5*(ao[2] + ao[0]); ao[7] = 0.5*(ao[0] + ao[3]); ao[8] = 0.5*(ao[1] + ao[3]); ao[9] = 0.5*(ao[2] + ao[3]); } //============================================================================= // T E T 1 0 G 4 R I 1 //============================================================================= FETet10G4RI1::FETet10G4RI1() { m_pTRI = new FETet10G1; } //============================================================================= // T E T 1 0 G 8 R I 4 //============================================================================= FETet10G8RI4::FETet10G8RI4() { m_pTRI = new FETet10G4; } //============================================================================= // T E T 1 0 G L 1 1 //============================================================================= // I think this assumes that the tetrahedron in natural space is essentially // a constant metric tet with the edge nodes at the center of the edges. FETet10GL11::FETet10GL11() : FETet10_(NINT, FE_TET10GL11) { const double w = 1.0/6.0; const double a = w*1.0/60.0; const double b = w*4.0/60.0; gr[ 0] = 0.0; gs[ 0] = 0.0; gt[ 0] = 0.0; gw[ 0] = a; gr[ 1] = 1.0; gs[ 1] = 0.0; gt[ 1] = 0.0; gw[ 1] = a; gr[ 2] = 0.0; gs[ 2] = 1.0; gt[ 2] = 0.0; gw[ 2] = a; gr[ 3] = 0.0; gs[ 3] = 0.0; gt[ 3] = 1.0; gw[ 3] = a; gr[ 4] = 0.5; gs[ 4] = 0.0; gt[ 4] = 0.0; gw[ 4] = b; gr[ 5] = 0.5; gs[ 5] = 0.5; gt[ 5] = 0.0; gw[ 5] = b; gr[ 6] = 0.0; gs[ 6] = 0.5; gt[ 6] = 0.0; gw[ 6] = b; gr[ 7] = 0.0; gs[ 7] = 0.0; gt[ 7] = 0.5; gw[ 7] = b; gr[ 8] = 0.5; gs[ 8] = 0.0; gt[ 8] = 0.5; gw[ 8] = b; gr[ 9] = 0.0; gs[ 9] = 0.5; gt[ 9] = 0.5; gw[ 9] = b; gr[10] = 0.25; gs[10] = 0.25; gt[10] = 0.25; gw[10] = 32*a; init(); } //----------------------------------------------------------------------------- void FETet10GL11::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = ai[2]; ao[3] = ai[3]; ao[4] = ai[4]; ao[5] = ai[5]; ao[6] = ai[6]; ao[7] = ai[7]; ao[8] = ai[8]; ao[9] = ai[9]; } //============================================================================= // T E T 1 5 //============================================================================= //============================================================================= // T E T 1 5 G 4 //============================================================================= FETet15G4::FETet15G4() : FETet15_(NINT, FE_TET15G4) { // integration point coordinates const double a = 0.58541020; const double b = 0.13819660; const double w = 0.25 / 6.0; gr[ 0] = a; gs[ 0] = b; gt[ 0] = b; gw[ 0] = w; gr[ 1] = b; gs[ 1] = a; gt[ 1] = b; gw[ 1] = w; gr[ 2] = b; gs[ 2] = b; gt[ 2] = a; gw[ 2] = w; gr[ 3] = b; gs[ 3] = b; gt[ 3] = b; gw[ 3] = w; init(); // setup the shape function matrix matrix A(4,4); for (int i=0; i<4; ++i) { double r = gr[i]; double s = gs[i]; double t = gt[i]; A[i][0] = 1 - r - s - t; A[i][1] = r; A[i][2] = s; A[i][3] = t; } // calculate inverse matrix Ai.resize(4, 4); Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETet15G4::project_to_nodes(double* ai, double* ao) const { ao[0] = Ai[0][0]*ai[0] + Ai[0][1]*ai[1] + Ai[0][2]*ai[2] + Ai[0][3]*ai[3]; ao[1] = Ai[1][0]*ai[0] + Ai[1][1]*ai[1] + Ai[1][2]*ai[2] + Ai[1][3]*ai[3]; ao[2] = Ai[2][0]*ai[0] + Ai[2][1]*ai[1] + Ai[2][2]*ai[2] + Ai[2][3]*ai[3]; ao[3] = Ai[3][0]*ai[0] + Ai[3][1]*ai[1] + Ai[3][2]*ai[2] + Ai[3][3]*ai[3]; ao[4] = 0.5*(ao[0] + ao[1]); ao[5] = 0.5*(ao[1] + ao[2]); ao[6] = 0.5*(ao[2] + ao[0]); ao[7] = 0.5*(ao[0] + ao[3]); ao[8] = 0.5*(ao[1] + ao[3]); ao[9] = 0.5*(ao[2] + ao[3]); ao[10] = (ao[0] + ao[1] + ao[2])/3.0; ao[11] = (ao[0] + ao[1] + ao[3])/3.0; ao[12] = (ao[1] + ao[2] + ao[3])/3.0; ao[13] = (ao[0] + ao[2] + ao[3])/3.0; ao[14] = 0.25*(ao[0] + ao[1] + ao[2] + ao[3]); } //============================================================================= // T E T 1 5 G 8 //============================================================================= // I think this assumes that the tetrahedron in natural space is essentially // a constant metric tet with the edge nodes at the center of the edges. FETet15G8::FETet15G8() : FETet15_(NINT, FE_TET15G8) { const double w = 1.0/6.0; gr[0] = 0.0158359099; gs[0] = 0.3280546970; gt[0] = 0.3280546970; gw[0] = 0.138527967*w; gr[1] = 0.3280546970; gs[1] = 0.0158359099; gt[1] = 0.3280546970; gw[1] = 0.138527967*w; gr[2] = 0.3280546970; gs[2] = 0.3280546970; gt[2] = 0.0158359099; gw[2] = 0.138527967*w; gr[3] = 0.3280546970; gs[3] = 0.3280546970; gt[3] = 0.3280546970; gw[3] = 0.138527967*w; gr[4] = 0.6791431780; gs[4] = 0.1069522740; gt[4] = 0.1069522740; gw[4] = 0.111472033*w; gr[5] = 0.1069522740; gs[5] = 0.6791431780; gt[5] = 0.1069522740; gw[5] = 0.111472033*w; gr[6] = 0.1069522740; gs[6] = 0.1069522740; gt[6] = 0.6791431780; gw[6] = 0.111472033*w; gr[7] = 0.1069522740; gs[7] = 0.1069522740; gt[7] = 0.1069522740; gw[7] = 0.111472033*w; init(); // setup the shape function matrix N.resize(8, 4); for (int i=0; i<8; ++i) { N[i][0] = 1.0 - gr[i] - gs[i] - gt[i]; N[i][1] = gr[i]; N[i][2] = gs[i]; N[i][3] = gt[i]; } matrix A(4, 4); A = N.transpose()*N; // calculate inverse matrix Ai.resize(4, 4); Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETet15G8::project_to_nodes(double* ai, double* ao) const { vector<double> b(4); for (int i=0; i<4; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += N[j][i]*ai[j]; } for (int i=0; i<4; ++i) { ao[i] = 0.0; for (int j=0; j<4; ++j) ao[i] += Ai[i][j]*b[j]; } ao[4] = 0.5*(ao[0] + ao[1]); ao[5] = 0.5*(ao[1] + ao[2]); ao[6] = 0.5*(ao[2] + ao[0]); ao[7] = 0.5*(ao[0] + ao[3]); ao[8] = 0.5*(ao[1] + ao[3]); ao[9] = 0.5*(ao[2] + ao[3]); ao[10] = (ao[0] + ao[1] + ao[2])/3.0; ao[11] = (ao[0] + ao[1] + ao[3])/3.0; ao[12] = (ao[1] + ao[2] + ao[3])/3.0; ao[13] = (ao[0] + ao[2] + ao[3])/3.0; ao[14] = (ao[0] + ao[1] + ao[2] + ao[3])*0.25; } //============================================================================= // T E T 1 5 G 1 1 //============================================================================= FETet15G11::FETet15G11() : FETet15_(NINT, FE_TET15G11) { gr[0] = 0.25; gs[0] = 0.25; gt[0] = 0.25; gw[0] = -0.01315555556; gr[1] = 0.071428571428571; gs[1] = 0.071428571428571; gt[1] = 0.071428571428571; gw[1] = 0.007622222222; gr[2] = 0.785714285714286; gs[2] = 0.071428571428571; gt[2] = 0.071428571428571; gw[2] = 0.007622222222; gr[3] = 0.071428571428571; gs[3] = 0.785714285714286; gt[3] = 0.071428571428571; gw[3] = 0.007622222222; gr[4] = 0.071428571428571; gs[4] = 0.071428571428571; gt[4] = 0.785714285714286; gw[4] = 0.007622222222; gr[ 5] = 0.399403576166799; gs[ 5] = 0.100596423833201; gt[ 5] = 0.100596423833201; gw[ 5] = 0.024888888889; gr[ 6] = 0.100596423833201; gs[ 6] = 0.399403576166799; gt[ 6] = 0.100596423833201; gw[ 6] = 0.024888888889; gr[ 7] = 0.100596423833201; gs[ 7] = 0.100596423833201; gt[ 7] = 0.399403576166799; gw[ 7] = 0.024888888889; gr[ 8] = 0.399403576166799; gs[ 8] = 0.399403576166799; gt[ 8] = 0.100596423833201; gw[ 8] = 0.024888888889; gr[ 9] = 0.399403576166799; gs[ 9] = 0.100596423833201; gt[ 9] = 0.399403576166799; gw[ 9] = 0.024888888889; gr[10] = 0.100596423833201; gs[10] = 0.399403576166799; gt[10] = 0.399403576166799; gw[10] = 0.024888888889; init(); // setup the shape function matrix N.resize(11, 4); for (int i=0; i<11; ++i) { N[i][0] = 1.0 - gr[i] - gs[i] - gt[i]; N[i][1] = gr[i]; N[i][2] = gs[i]; N[i][3] = gt[i]; } matrix A(4, 4); A = N.transpose()*N; // calculate inverse matrix Ai.resize(4, 4); Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETet15G11::project_to_nodes(double* ai, double* ao) const { vector<double> b(4); for (int i=0; i<4; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += N[j][i]*ai[j]; } for (int i=0; i<4; ++i) { ao[i] = 0.0; for (int j=0; j<4; ++j) ao[i] += Ai[i][j]*b[j]; } ao[4] = 0.5*(ao[0] + ao[1]); ao[5] = 0.5*(ao[1] + ao[2]); ao[6] = 0.5*(ao[2] + ao[0]); ao[7] = 0.5*(ao[0] + ao[3]); ao[8] = 0.5*(ao[1] + ao[3]); ao[9] = 0.5*(ao[2] + ao[3]); ao[10] = (ao[0] + ao[1] + ao[2])/3.0; ao[11] = (ao[0] + ao[1] + ao[3])/3.0; ao[12] = (ao[1] + ao[2] + ao[3])/3.0; ao[13] = (ao[0] + ao[2] + ao[3])/3.0; ao[14] = (ao[0] + ao[1] + ao[2] + ao[3])*0.25; } //============================================================================= // T E T 1 5 G 1 5 //============================================================================= FETet15G15::FETet15G15() : FETet15_(NINT, FE_TET15G15) { gr[0] = 0.25; gs[0] = 0.25; gt[0] = 0.25; gw[0] = 0.030283678097089; gr[1] = 0.333333333333333; gs[1] = 0.333333333333333; gt[1] = 0.333333333333333; gw[1] = 0.006026785714286; gr[2] = 0.000000000000000; gs[2] = 0.333333333333333; gt[2] = 0.333333333333333; gw[2] = 0.006026785714286; gr[3] = 0.333333333333333; gs[3] = 0.000000000000000; gt[3] = 0.333333333333333; gw[3] = 0.006026785714286; gr[4] = 0.333333333333333; gs[4] = 0.333333333333333; gt[4] = 0.000000000000000; gw[4] = 0.006026785714286; gr[ 5] = 0.090909090909091; gs[ 5] = 0.090909090909091; gt[ 5] = 0.090909090909091; gw[ 5] = 0.011645249086029; gr[ 6] = 0.727272727272727; gs[ 6] = 0.090909090909091; gt[ 6] = 0.090909090909091; gw[ 6] = 0.011645249086029; gr[ 7] = 0.090909090909091; gs[ 7] = 0.727272727272727; gt[ 7] = 0.090909090909091; gw[ 7] = 0.011645249086029; gr[ 8] = 0.090909090909091; gs[ 8] = 0.090909090909091; gt[ 8] = 0.727272727272727; gw[ 8] = 0.011645249086029; gr[ 9] = 0.433449846426336; gs[ 9] = 0.066550153573664; gt[ 9] = 0.066550153573664; gw[ 9] = 0.010949141561386; gr[10] = 0.066550153573664; gs[10] = 0.433449846426336; gt[10] = 0.066550153573664; gw[10] = 0.010949141561386; gr[11] = 0.066550153573664; gs[11] = 0.066550153573664; gt[11] = 0.433449846426336; gw[11] = 0.010949141561386; gr[12] = 0.066550153573664; gs[12] = 0.433449846426336; gt[12] = 0.433449846426336; gw[12] = 0.010949141561386; gr[13] = 0.433449846426336; gs[13] = 0.066550153573664; gt[13] = 0.433449846426336; gw[13] = 0.010949141561386; gr[14] = 0.433449846426336; gs[14] = 0.433449846426336; gt[14] = 0.066550153573664; gw[14] = 0.010949141561386; init(); // setup the shape function matrix N.resize(NINT, 4); for (int i=0; i<NINT; ++i) { N[i][0] = 1.0 - gr[i] - gs[i] - gt[i]; N[i][1] = gr[i]; N[i][2] = gs[i]; N[i][3] = gt[i]; } matrix A(4, 4); A = N.transpose()*N; // calculate inverse matrix Ai.resize(4, 4); Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETet15G15::project_to_nodes(double* ai, double* ao) const { vector<double> b(4); for (int i=0; i<4; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += N[j][i]*ai[j]; } for (int i=0; i<4; ++i) { ao[i] = 0.0; for (int j=0; j<4; ++j) ao[i] += Ai[i][j]*b[j]; } ao[4] = 0.5*(ao[0] + ao[1]); ao[5] = 0.5*(ao[1] + ao[2]); ao[6] = 0.5*(ao[2] + ao[0]); ao[7] = 0.5*(ao[0] + ao[3]); ao[8] = 0.5*(ao[1] + ao[3]); ao[9] = 0.5*(ao[2] + ao[3]); ao[10] = (ao[0] + ao[1] + ao[2])/3.0; ao[11] = (ao[0] + ao[1] + ao[3])/3.0; ao[12] = (ao[1] + ao[2] + ao[3])/3.0; ao[13] = (ao[0] + ao[2] + ao[3])/3.0; ao[14] = (ao[0] + ao[1] + ao[2] + ao[3])*0.25; } //============================================================================= // T E T 1 5 G 1 5 R I 4 //============================================================================= FETet15G15RI4::FETet15G15RI4() { m_pTRI = new FETet15G4; } //============================================================================= // T E T 2 0 //============================================================================= //============================================================================= // T E T 2 0 G 1 5 //============================================================================= FETet20G15::FETet20G15() : FETet20_(NINT, FE_TET20G15) { gr[0] = 0.25; gs[0] = 0.25; gt[0] = 0.25; gw[0] = 0.030283678097089; gr[1] = 0.333333333333333; gs[1] = 0.333333333333333; gt[1] = 0.333333333333333; gw[1] = 0.006026785714286; gr[2] = 0.000000000000000; gs[2] = 0.333333333333333; gt[2] = 0.333333333333333; gw[2] = 0.006026785714286; gr[3] = 0.333333333333333; gs[3] = 0.000000000000000; gt[3] = 0.333333333333333; gw[3] = 0.006026785714286; gr[4] = 0.333333333333333; gs[4] = 0.333333333333333; gt[4] = 0.000000000000000; gw[4] = 0.006026785714286; gr[5] = 0.090909090909091; gs[5] = 0.090909090909091; gt[5] = 0.090909090909091; gw[5] = 0.011645249086029; gr[6] = 0.727272727272727; gs[6] = 0.090909090909091; gt[6] = 0.090909090909091; gw[6] = 0.011645249086029; gr[7] = 0.090909090909091; gs[7] = 0.727272727272727; gt[7] = 0.090909090909091; gw[7] = 0.011645249086029; gr[8] = 0.090909090909091; gs[8] = 0.090909090909091; gt[8] = 0.727272727272727; gw[8] = 0.011645249086029; gr[9] = 0.433449846426336; gs[9] = 0.066550153573664; gt[9] = 0.066550153573664; gw[9] = 0.010949141561386; gr[10] = 0.066550153573664; gs[10] = 0.433449846426336; gt[10] = 0.066550153573664; gw[10] = 0.010949141561386; gr[11] = 0.066550153573664; gs[11] = 0.066550153573664; gt[11] = 0.433449846426336; gw[11] = 0.010949141561386; gr[12] = 0.066550153573664; gs[12] = 0.433449846426336; gt[12] = 0.433449846426336; gw[12] = 0.010949141561386; gr[13] = 0.433449846426336; gs[13] = 0.066550153573664; gt[13] = 0.433449846426336; gw[13] = 0.010949141561386; gr[14] = 0.433449846426336; gs[14] = 0.433449846426336; gt[14] = 0.066550153573664; gw[14] = 0.010949141561386; init(); // setup the shape function matrix N.resize(15, 4); for (int i = 0; i<15; ++i) { N[i][0] = 1.0 - gr[i] - gs[i] - gt[i]; N[i][1] = gr[i]; N[i][2] = gs[i]; N[i][3] = gt[i]; } matrix A(4, 4); A = N.transpose()*N; // calculate inverse matrix Ai.resize(4, 4); Ai = A.inverse(); } void FETet20G15::project_to_nodes(double* ai, double* ao) const { vector<double> b(4); for (int i = 0; i<4; ++i) { b[i] = 0; for (int j = 0; j<NINT; ++j) b[i] += N[j][i] * ai[j]; } for (int i = 0; i<4; ++i) { ao[i] = 0.0; for (int j = 0; j<4; ++j) ao[i] += Ai[i][j] * b[j]; } const double w1 = 1.0 / 3.0; const double w2 = 2.0 / 3.0; ao[ 4] = ao[0] * w2 + ao[1] * w1; ao[ 5] = ao[0] * w1 + ao[1] * w2; ao[ 6] = ao[1] * w2 + ao[2] * w1; ao[ 7] = ao[1] * w1 + ao[2] * w2; ao[ 8] = ao[0] * w2 + ao[2] * w1; ao[ 9] = ao[0] * w1 + ao[2] * w2; ao[10] = ao[0] * w2 + ao[3] * w1; ao[11] = ao[0] * w1 + ao[3] * w2; ao[12] = ao[1] * w2 + ao[3] * w1; ao[13] = ao[1] * w1 + ao[3] * w2; ao[14] = ao[2] * w2 + ao[3] * w1; ao[15] = ao[2] * w1 + ao[3] * w2; ao[16] = (ao[0] + ao[1] + ao[3]) / 3.0; ao[17] = (ao[1] + ao[2] + ao[3]) / 3.0; ao[18] = (ao[2] + ao[0] + ao[3]) / 3.0; ao[19] = (ao[0] + ao[1] + ao[2]) / 3.0; } //============================================================================= // H E X 2 0 //============================================================================= int FEHex20_::Nodes(int order) { switch (order) { case 2: return 20; break; case 1: return 8; break; case 0: return 1; break; default: assert(false); return 20; } } void FEHex20_::init() { // allocate shape classes m_shapeP.resize(3); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_HEX8)); m_shapeP[2] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_HEX20)); // initialize base class FESolidElementTraits::init(); } //============================================================================= // H E X 2 0 G 8 //============================================================================= int FEHex20G8::ni[NELN] = {}; FEHex20G8::FEHex20G8() : FEHex20_(NINT, FE_HEX20G8) { // integration point coordinates const double a = 1.0 / sqrt(3.0); gr[0] = -a; gs[0] = -a; gt[0] = -a; gw[0] = 1; gr[1] = a; gs[1] = -a; gt[1] = -a; gw[1] = 1; gr[2] = a; gs[2] = a; gt[2] = -a; gw[2] = 1; gr[3] = -a; gs[3] = a; gt[3] = -a; gw[3] = 1; gr[4] = -a; gs[4] = -a; gt[4] = a; gw[4] = 1; gr[5] = a; gs[5] = -a; gt[5] = a; gw[5] = 1; gr[6] = a; gs[6] = a; gt[6] = a; gw[6] = 1; gr[7] = -a; gs[7] = a; gt[7] = a; gw[7] = 1; init(); MT.resize(NELN, NINT); for (int i=0; i<NINT; ++i) for (int n=0; n<NELN; ++n) MT(n,i) = m_H(i,n); Hi.resize(NELN, NELN); Hi = MT*MT.transpose(); Hi = Hi.inverse(); } //----------------------------------------------------------------------------- //! Use least-squares extrapolation void FEHex20G8::project_to_nodes(double* ai, double* ao) const { double v[NELN]; for (int n=0; n<NELN; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += MT(n,i)*ai[i]; } } for (int j=0; j<NELN; ++j) { ao[j] = 0; for (int k=0; k<NELN; ++k) { ao[j] += Hi[j][k]*v[k]; } } } //============================================================================= // H E X 2 0 G 2 7 //============================================================================= int FEHex20G27::ni[NELN] = { 0, 1, 2, 3, 5, 6, 7, 8, 9, 11, 15, 17, 18, 19, 20, 21, 23, 24, 25, 26 }; FEHex20G27::FEHex20G27() : FEHex20_(NINT, FE_HEX20G27) { // integration point coordinates const double a = 0.774596669241483; const double w1 = 5.0 / 9.0; const double w2 = 8.0 / 9.0; gr[ 0] = -a; gs[ 0] = -a; gt[ 0] = -a; gw[ 0] = w1*w1*w1; gr[ 1] = 0; gs[ 1] = -a; gt[ 1] = -a; gw[ 1] = w2*w1*w1; gr[ 2] = a; gs[ 2] = -a; gt[ 2] = -a; gw[ 2] = w1*w1*w1; gr[ 3] = -a; gs[ 3] = 0; gt[ 3] = -a; gw[ 3] = w1*w2*w1; gr[ 4] = 0; gs[ 4] = 0; gt[ 4] = -a; gw[ 4] = w2*w2*w1; gr[ 5] = a; gs[ 5] = 0; gt[ 5] = -a; gw[ 5] = w1*w2*w1; gr[ 6] = -a; gs[ 6] = a; gt[ 6] = -a; gw[ 6] = w1*w1*w1; gr[ 7] = 0; gs[ 7] = a; gt[ 7] = -a; gw[ 7] = w2*w1*w1; gr[ 8] = a; gs[ 8] = a; gt[ 8] = -a; gw[ 8] = w1*w1*w1; gr[ 9] = -a; gs[ 9] = -a; gt[ 9] = 0; gw[ 9] = w1*w1*w2; gr[10] = 0; gs[10] = -a; gt[10] = 0; gw[10] = w2*w1*w2; gr[11] = a; gs[11] = -a; gt[11] = 0; gw[11] = w1*w1*w2; gr[12] = -a; gs[12] = 0; gt[12] = 0; gw[12] = w1*w2*w2; gr[13] = 0; gs[13] = 0; gt[13] = 0; gw[13] = w2*w2*w2; gr[14] = a; gs[14] = 0; gt[14] = 0; gw[14] = w1*w2*w2; gr[15] = -a; gs[15] = a; gt[15] = 0; gw[15] = w1*w1*w2; gr[16] = 0; gs[16] = a; gt[16] = 0; gw[16] = w2*w1*w2; gr[17] = a; gs[17] = a; gt[17] = 0; gw[17] = w1*w1*w2; gr[18] = -a; gs[18] = -a; gt[18] = a; gw[18] = w1*w1*w1; gr[19] = 0; gs[19] = -a; gt[19] = a; gw[19] = w2*w1*w1; gr[20] = a; gs[20] = -a; gt[20] = a; gw[20] = w1*w1*w1; gr[21] = -a; gs[21] = 0; gt[21] = a; gw[21] = w1*w2*w1; gr[22] = 0; gs[22] = 0; gt[22] = a; gw[22] = w2*w2*w1; gr[23] = a; gs[23] = 0; gt[23] = a; gw[23] = w1*w2*w1; gr[24] = -a; gs[24] = a; gt[24] = a; gw[24] = w1*w1*w1; gr[25] = 0; gs[25] = a; gt[25] = a; gw[25] = w2*w1*w1; gr[26] = a; gs[26] = a; gt[26] = a; gw[26] = w1*w1*w1; init(); Hi.resize(NELN, NELN); for (int i=0; i<NELN; ++i) for (int n=0; n<NELN; ++n) Hi(i,n) = m_H(ni[i],n); Hi = Hi.inverse(); } //----------------------------------------------------------------------------- //! \todo implement this void FEHex20G27::project_to_nodes(double* ai, double* ao) const { for (int j=0; j<NELN; ++j) { ao[j] = 0; for (int k=0; k<NELN; ++k) { ao[j] += Hi[j][k]*ai[ni[k]]; } } } //============================================================================= // H E X 2 7 //============================================================================= void FEHex27_::init() { m_shapeP.resize(3); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_HEX8)); m_shapeP[2] = dynamic_cast<FESolidElementShape*>(FEElementLibrary::GetElementShapeClass(ET_HEX27)); // initialize base class FESolidElementTraits::init(); } //============================================================================= // H E X 2 7 G 2 7 //============================================================================= FEHex27G27::FEHex27G27() : FEHex27_(NINT, FE_HEX27G27) { // integration point coordinates const double a = 0.774596669241483; const double w1 = 5.0 / 9.0; const double w2 = 8.0 / 9.0; gr[ 0] = -a; gs[ 0] = -a; gt[ 0] = -a; gw[ 0] = w1*w1*w1; gr[ 1] = 0; gs[ 1] = -a; gt[ 1] = -a; gw[ 1] = w2*w1*w1; gr[ 2] = a; gs[ 2] = -a; gt[ 2] = -a; gw[ 2] = w1*w1*w1; gr[ 3] = -a; gs[ 3] = 0; gt[ 3] = -a; gw[ 3] = w1*w2*w1; gr[ 4] = 0; gs[ 4] = 0; gt[ 4] = -a; gw[ 4] = w2*w2*w1; gr[ 5] = a; gs[ 5] = 0; gt[ 5] = -a; gw[ 5] = w1*w2*w1; gr[ 6] = -a; gs[ 6] = a; gt[ 6] = -a; gw[ 6] = w1*w1*w1; gr[ 7] = 0; gs[ 7] = a; gt[ 7] = -a; gw[ 7] = w2*w1*w1; gr[ 8] = a; gs[ 8] = a; gt[ 8] = -a; gw[ 8] = w1*w1*w1; gr[ 9] = -a; gs[ 9] = -a; gt[ 9] = 0; gw[ 9] = w1*w1*w2; gr[10] = 0; gs[10] = -a; gt[10] = 0; gw[10] = w2*w1*w2; gr[11] = a; gs[11] = -a; gt[11] = 0; gw[11] = w1*w1*w2; gr[12] = -a; gs[12] = 0; gt[12] = 0; gw[12] = w1*w2*w2; gr[13] = 0; gs[13] = 0; gt[13] = 0; gw[13] = w2*w2*w2; gr[14] = a; gs[14] = 0; gt[14] = 0; gw[14] = w1*w2*w2; gr[15] = -a; gs[15] = a; gt[15] = 0; gw[15] = w1*w1*w2; gr[16] = 0; gs[16] = a; gt[16] = 0; gw[16] = w2*w1*w2; gr[17] = a; gs[17] = a; gt[17] = 0; gw[17] = w1*w1*w2; gr[18] = -a; gs[18] = -a; gt[18] = a; gw[18] = w1*w1*w1; gr[19] = 0; gs[19] = -a; gt[19] = a; gw[19] = w2*w1*w1; gr[20] = a; gs[20] = -a; gt[20] = a; gw[20] = w1*w1*w1; gr[21] = -a; gs[21] = 0; gt[21] = a; gw[21] = w1*w2*w1; gr[22] = 0; gs[22] = 0; gt[22] = a; gw[22] = w2*w2*w1; gr[23] = a; gs[23] = 0; gt[23] = a; gw[23] = w1*w2*w1; gr[24] = -a; gs[24] = a; gt[24] = a; gw[24] = w1*w1*w1; gr[25] = 0; gs[25] = a; gt[25] = a; gw[25] = w2*w1*w1; gr[26] = a; gs[26] = a; gt[26] = a; gw[26] = w1*w1*w1; init(); m_Hi = m_H.inverse(); } //----------------------------------------------------------------------------- //! \todo implement this void FEHex27G27::project_to_nodes(double* ai, double* ao) const { for (int j=0; j<NELN; ++j) { ao[j] = 0; for (int k=0; k<NINT; ++k) { ao[j] += m_Hi[j][k]*ai[k]; } } } //============================================================================= // P Y R A 5 //============================================================================= //============================================================================= // P Y R A 5 G 8 //============================================================================= FEPyra5G8::FEPyra5G8() : FEPyra5_(NINT, FE_PYRA5G8) { // integration point coordinates const double a = 1.0 / sqrt(3.0); gr[0] = -a; gs[0] = -a; gt[0] = -a; gw[0] = 1; gr[1] = a; gs[1] = -a; gt[1] = -a; gw[1] = 1; gr[2] = a; gs[2] = a; gt[2] = -a; gw[2] = 1; gr[3] = -a; gs[3] = a; gt[3] = -a; gw[3] = 1; gr[4] = -a; gs[4] = -a; gt[4] = a; gw[4] = 1; gr[5] = a; gs[5] = -a; gt[5] = a; gw[5] = 1; gr[6] = a; gs[6] = a; gt[6] = a; gw[6] = 1; gr[7] = -a; gs[7] = a; gt[7] = a; gw[7] = 1; init(); // we need Ai to project integration point data to the nodes matrix A(NELN, NELN); m_Ai.resize(NELN, NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } void FEPyra5G8::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i = 0; i<NELN; ++i) { b[i] = 0; for (int j = 0; j<NINT; ++j) b[i] += m_H[j][i] * ai[j]; } for (int i = 0; i<NELN; ++i) { ao[i] = 0; for (int j = 0; j<NELN; ++j) ao[i] += m_Ai[i][j] * b[j]; } } //============================================================================= // P Y R A 1 3 //============================================================================= //============================================================================= // P Y R A 1 3 G 8 //============================================================================= FEPyra13G8::FEPyra13G8() : FEPyra13_(NINT, FE_PYRA13G8) { // integration point coordinates const double a = 1.0 / sqrt(3.0); gr[0] = -a; gs[0] = -a; gt[0] = -a; gw[0] = 1; gr[1] = a; gs[1] = -a; gt[1] = -a; gw[1] = 1; gr[2] = a; gs[2] = a; gt[2] = -a; gw[2] = 1; gr[3] = -a; gs[3] = a; gt[3] = -a; gw[3] = 1; gr[4] = -a; gs[4] = -a; gt[4] = a; gw[4] = 1; gr[5] = a; gs[5] = -a; gt[5] = a; gw[5] = 1; gr[6] = a; gs[6] = a; gt[6] = a; gw[6] = 1; gr[7] = -a; gs[7] = a; gt[7] = a; gw[7] = 1; init(); // we need Ai to project integration point data to the nodes matrix A(NELN, NELN); m_Ai.resize(NELN, NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } void FEPyra13G8::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i = 0; i<NELN; ++i) { b[i] = 0; for (int j = 0; j<NINT; ++j) b[i] += m_H[j][i] * ai[j]; } for (int i = 0; i<NELN; ++i) { ao[i] = 0; for (int j = 0; j<NELN; ++j) ao[i] += m_Ai[i][j] * b[j]; } } //============================================================================= // // S U R F A C E E L E M E N T S // //============================================================================= FESurfaceElementTraits::FESurfaceElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et) : FEElementTraits(ni, ne, FE_ELEM_SURFACE, es, et) { gr.resize(ni); gs.resize(ni); gw.resize(ni); Gr.resize(ni, ne); Gs.resize(ni, ne); } //----------------------------------------------------------------------------- //! Initialize the surface element traits data variables. // void FESurfaceElementTraits::init() { assert(m_nint > 0); assert(m_neln > 0); // get shape class m_shape = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(m_spec.eshape)); assert(m_shape && (m_shape->shape() == m_spec.eshape)); // evaluate shape functions const int NE = FEElement::MAX_NODES; double N[NE]; for (int n=0; n<m_nint; ++n) { shape_fnc(N, gr[n], gs[n]); for (int i=0; i<m_neln; ++i) m_H[n][i] = N[i]; } // evaluate shape function derivatives double Nr[NE], Ns[NE]; for (int n=0; n<m_nint; ++n) { shape_deriv(Nr, Ns, gr[n], gs[n]); for (int i=0; i<m_neln; ++i) { Gr[n][i] = Nr[i]; Gs[n][i] = Ns[i]; } } // NOTE: Below, is a new interface for dealing with mixed element formulations. // This is still a work in progress. // Get the max interpolation order const int maxOrder = (int)m_shapeP.size() - 1; m_Hp.resize(maxOrder + 1); Gr_p.resize(maxOrder + 1); Gs_p.resize(maxOrder + 1); for (int i = 0; i <= maxOrder; ++i) { FESurfaceElementShape* shape = m_shapeP[i]; matrix& H = m_Hp[i]; matrix& Gr = Gr_p[i]; matrix& Gs = Gs_p[i]; if (i == 0) { H.resize(m_nint, 1); Gr.resize(m_nint, 1); Gs.resize(m_nint, 1); for (int n = 0; n < m_nint; ++n) { H[n][0] = 1.0; Gr[n][0] = Gs[n][0] = 0.0; } } else if (m_shapeP[i]) { // get the nodes int neln = shape->nodes(); // shape function values H.resize(m_nint, neln); for (int n = 0; n<m_nint; ++n) { m_shapeP[i]->shape_fnc(N, gr[n], gs[n]); for (int j = 0; j<neln; ++j) H[n][j] = N[j]; } // calculate local derivatives of shape functions at gauss points Gr.resize(m_nint, neln); Gs.resize(m_nint, neln); for (int n = 0; n<m_nint; ++n) { shape->shape_deriv(Nr, Ns, gr[n], gs[n]); for (int j = 0; j<neln; ++j) { Gr[n][j] = Nr[j]; Gs[n][j] = Ns[j]; } } } } } // shape functions at (r,s) void FESurfaceElementTraits::shape_fnc(double* H, double r, double s) { m_shape->shape_fnc(H, r, s); } // shape function derivatives at (r,s) void FESurfaceElementTraits::shape_deriv(double* Gr, double* Gs, double r, double s) { m_shape->shape_deriv(Gr, Gs, r, s); } // shape function derivatives at (r,s) void FESurfaceElementTraits::shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s) { m_shape->shape_deriv2(Grr, Gss, Grs, r, s); } // shape functions at (r,s) void FESurfaceElementTraits::shape_fnc(int order, double* H, double r, double s) { if (order == -1) m_shape->shape_fnc(H, r, s); else m_shapeP[order]->shape_fnc(H, r, s); } // shape function derivatives at (r,s) void FESurfaceElementTraits::shape_deriv(int order, double* Gr, double* Gs, double r, double s) { if (order == -1) shape_deriv(Gr, Gs, r, s); else m_shapeP[order]->shape_deriv(Gr, Gs, r, s); } //============================================================================= // F E Q U A D 4 //============================================================================= void FEQuad4_::init() { // allocate shape classes m_shapeP.resize(2); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_QUAD4)); // centroid coordinates cr = cs = 0; // initialize base class FESurfaceElementTraits::init(); } //============================================================================= // F E Q U A D G 4 //============================================================================= FEQuad4G4::FEQuad4G4() : FEQuad4_(NINT, FE_QUAD4G4) { const double a = 1.0 / sqrt(3.0); gr[0] = -a; gs[0] = -a; gw[0] = 1; gr[1] = a; gs[1] = -a; gw[1] = 1; gr[2] = a; gs[2] = a; gw[2] = 1; gr[3] = -a; gs[3] = a; gw[3] = 1; init(); m_Hi = m_H.inverse(); } //----------------------------------------------------------------------------- void FEQuad4G4::project_to_nodes(double* ai, double* ao) const { int ni = NINT; int ne = NELN; assert(ni == ne); for (int i=0; i<ne; ++i) { ao[i] = 0; for (int j=0; j<ni; ++j) ao[i] += m_Hi[i][j]*ai[j]; } } //============================================================================= // F E Q U A D G 16 //============================================================================= FEQuad4G16::FEQuad4G16() : FEQuad4_(NINT, FE_QUAD4G16) { const double a = 0.339981; const double b = 0.861136; const double wa = 0.652145; const double wb = 0.347855; gr[ 0] = -b; gs[ 0] = -b; gw[ 0] = wb * wb; gr[ 1] = -a; gs[ 1] = -b; gw[ 1] = wa * wb; gr[ 2] = a; gs[ 2] = -b; gw[ 2] = wa * wb; gr[ 3] = b; gs[ 3] = -b; gw[ 3] = wb * wb; gr[ 4] = -b; gs[ 4] = -a; gw[ 4] = wa * wb; gr[ 5] = -a; gs[ 5] = -a; gw[ 5] = wa * wa; gr[ 6] = a; gs[ 6] = -a; gw[ 6] = wa * wa; gr[ 7] = b; gs[ 7] = -a; gw[ 7] = wa * wb; gr[ 8] = -b; gs[ 8] = a; gw[ 8] = wa * wb; gr[ 9] = -a; gs[ 9] = a; gw[ 9] = wa * wa; gr[10] = a; gs[10] = a; gw[10] = wa * wa; gr[11] = b; gs[11] = a; gw[11] = wa * wb; gr[12] = -b; gs[12] = b; gw[12] = wb * wb; gr[13] = -a; gs[13] = b; gw[13] = wa * wb; gr[14] = a; gs[14] = b; gw[14] = wa * wb; gr[15] = b; gs[15] = b; gw[15] = wb * wb; init(); // we need Ai to project integration point data to the nodes matrix A(NELN, NELN); m_Ai.resize(NELN, NELN); A = m_H.transpose() * m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FEQuad4G16::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i = 0; i < NELN; ++i) { b[i] = 0; for (int j = 0; j < NINT; ++j) b[i] += m_H[j][i] * ai[j]; } for (int i = 0; i < NELN; ++i) { ao[i] = 0; for (int j = 0; j < NELN; ++j) ao[i] += m_Ai[i][j] * b[j]; } } //============================================================================= // F E Q U A D N I //============================================================================= FEQuad4NI::FEQuad4NI() : FEQuad4_(NINT, FE_QUAD4NI) { gr[0] = -1; gs[0] = -1; gw[0] = 1; gr[1] = 1; gs[1] = -1; gw[1] = 1; gr[2] = 1; gs[2] = 1; gw[2] = 1; gr[3] = -1; gs[3] = 1; gw[3] = 1; init(); } //----------------------------------------------------------------------------- void FEQuad4NI::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = ai[2]; ao[3] = ai[3]; } //============================================================================= // F E T R I //============================================================================= void FETri3_::init() { // allocate shape classes m_shapeP.resize(2); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TRI3)); // centroid coordinates cr = cs = 1.0/3.0; // initialize base class FESurfaceElementTraits::init(); } //============================================================================= // F E T R I G 1 //============================================================================= //----------------------------------------------------------------------------- FETri3G1::FETri3G1() : FETri3_(NINT, FE_TRI3G1) { const double a = 1.0/3.0; gr[0] = a; gs[0] = a; gw[0] = 0.5; init(); } //----------------------------------------------------------------------------- void FETri3G1::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[0]; ao[2] = ai[0]; } //============================================================================= // F E T R I G 3 //============================================================================= //----------------------------------------------------------------------------- FETri3G3::FETri3G3() : FETri3_(NINT, FE_TRI3G3) { const double a = 1.0 / 6.0; const double b = 2.0 / 3.0; gr[0] = a; gs[0] = a; gw[0] = a; gr[1] = b; gs[1] = a; gw[1] = a; gr[2] = a; gs[2] = b; gw[2] = a; init(); m_Hi = m_H.inverse(); } //----------------------------------------------------------------------------- void FETri3G3::project_to_nodes(double* ai, double* ao) const { assert(NINT == NELN); for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NINT; ++j) ao[i] += m_Hi[i][j]*ai[j]; } } //============================================================================= // F E T R I G 7 //============================================================================= //----------------------------------------------------------------------------- FETri3G7::FETri3G7() : FETri3_(NINT, FE_TRI3G7) { const double w = 1.0/2.0; gr[0] = 0.333333333333333; gs[0] = 0.333333333333333; gw[0] = w*0.225000000000000; gr[1] = 0.797426985353087; gs[1] = 0.101286507323456; gw[1] = w*0.125939180544827; gr[2] = 0.101286507323456; gs[2] = 0.797426985353087; gw[2] = w*0.125939180544827; gr[3] = 0.101286507323456; gs[3] = 0.101286507323456; gw[3] = w*0.125939180544827; gr[4] = 0.470142064105115; gs[4] = 0.470142064105115; gw[4] = w*0.132394152788506; gr[5] = 0.470142064105115; gs[5] = 0.059715871789770; gw[5] = w*0.132394152788506; gr[6] = 0.059715871789770; gs[6] = 0.470142064105115; gw[6] = w*0.132394152788506; init(); // we need Ai to project integration point data to the nodes matrix A(NELN,NELN); m_Ai.resize(NELN,NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETri3G7::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i=0; i<NELN; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += m_H[j][i]*ai[j]; } for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NELN; ++j) ao[i] += m_Ai[i][j]*b[j]; } } //============================================================================= // F E T R I N I //============================================================================= //----------------------------------------------------------------------------- FETri3NI::FETri3NI() : FETri3_(NINT, FE_TRI3NI) { const double a = 1.0 / 6.0; gr[0] = 0; gs[0] = 0; gw[0] = a; gr[1] = 1; gs[1] = 0; gw[1] = a; gr[2] = 0; gs[2] = 1; gw[2] = a; init(); } //----------------------------------------------------------------------------- void FETri3NI::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = ai[2]; } //============================================================================ // F E T R I 6 //============================================================================ void FETri6_::init() { // allocate shape classes m_shapeP.resize(3); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TRI3)); m_shapeP[2] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TRI6)); // centroid coordinates cr = cs = 1.0/3.0; // initialize base class FESurfaceElementTraits::init(); } //============================================================================= // F E T R I 6 G 3 //============================================================================= FETri6G3::FETri6G3() : FETri6_(NINT, FE_TRI6G3) { const double a = 1.0 / 6.0; const double b = 2.0 / 3.0; gr[0] = a; gs[0] = a; gw[0] = a; gr[1] = b; gs[1] = a; gw[1] = a; gr[2] = a; gs[2] = b; gw[2] = a; init(); } //----------------------------------------------------------------------------- void FETri6G3::project_to_nodes(double* ai, double* ao) const { matrix H(3, 3); for (int n=0; n<3; ++n) { H[n][0] = 1.0 - gr[n] - gs[n]; H[n][1] = gr[n]; H[n][2] = gs[n]; } H.inverse(); for (int i=0; i<3; ++i) { ao[i] = 0; for (int j=0; j<3; ++j) ao[i] += H[i][j]*ai[j]; } ao[3] = 0.5*(ao[0] + ao[1]); ao[4] = 0.5*(ao[1] + ao[2]); ao[5] = 0.5*(ao[2] + ao[0]); } //============================================================================= // F E T R I 6 G 4 //============================================================================= FETri6G4::FETri6G4() : FETri6_(NINT, FE_TRI6G4) { const double a = 1.0/3.0; const double b = 1.0/5.0; const double c = 3.0/5.0; gr[0] = a; gs[0] = a; gw[0] = -27.0/96.0; gr[1] = c; gs[1] = b; gw[1] = 25.0/96.0; gr[2] = b; gs[2] = b; gw[2] = 25.0/96.0; gr[3] = b; gs[3] = c; gw[3] = 25.0/96.0; init(); } //----------------------------------------------------------------------------- //! \todo implement this void FETri6G4::project_to_nodes(double* ai, double* ao) const { } //============================================================================= // F E T R I 6 G 7 //============================================================================= FETri6G7::FETri6G7() : FETri6_(NINT, FE_TRI6G7) { const double w = 1.0/2.0; gr[0] = 0.333333333333333; gs[0] = 0.333333333333333; gw[0] = w*0.225000000000000; gr[1] = 0.797426985353087; gs[1] = 0.101286507323456; gw[1] = w*0.125939180544827; gr[2] = 0.101286507323456; gs[2] = 0.797426985353087; gw[2] = w*0.125939180544827; gr[3] = 0.101286507323456; gs[3] = 0.101286507323456; gw[3] = w*0.125939180544827; gr[4] = 0.470142064105115; gs[4] = 0.470142064105115; gw[4] = w*0.132394152788506; gr[5] = 0.470142064105115; gs[5] = 0.059715871789770; gw[5] = w*0.132394152788506; gr[6] = 0.059715871789770; gs[6] = 0.470142064105115; gw[6] = w*0.132394152788506; init(); // we need Ai to project integration point data to the nodes matrix A(NELN,NELN); m_Ai.resize(NELN,NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETri6G7::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i=0; i<NELN; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += m_H[j][i]*ai[j]; } for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NELN; ++j) ao[i] += m_Ai[i][j]*b[j]; } } //============================================================================= // T R I 6 G L 7 //============================================================================= FETri6GL7::FETri6GL7() : FETri6_(NINT, FE_TRI6GL7) { const double a = 1.0/40.0; const double b = 1.0/15.0; gr[0] = 0.0; gs[0] = 0.0; gw[0] = a; gr[1] = 1.0; gs[1] = 0.0; gw[1] = a; gr[2] = 0.0; gs[2] = 1.0; gw[2] = a; gr[3] = 0.5; gs[3] = 0.0; gw[3] = b; gr[4] = 0.5; gs[4] = 0.5; gw[4] = b; gr[5] = 0.0; gs[5] = 0.5; gw[5] = b; gr[6] = 1.0/3.0; gs[6] = 1.0/3.0; gw[6] = 9.0*a; init(); } //----------------------------------------------------------------------------- void FETri6GL7::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = ai[2]; ao[3] = ai[3]; ao[4] = ai[4]; ao[5] = ai[5]; } //============================================================================= // F E T R I 6 N I //============================================================================= FETri6NI::FETri6NI() : FETri6_(NINT, FE_TRI6NI) { const double a = 0.0; const double b = 1.0/6.0; gr[0] = 0.0; gs[0] = 0.0; gw[0] = a; gr[1] = 1.0; gs[1] = 0.0; gw[1] = a; gr[2] = 0.0; gs[2] = 1.0; gw[2] = a; gr[3] = 0.5; gs[3] = 0.0; gw[3] = b; gr[4] = 0.5; gs[4] = 0.5; gw[4] = b; gr[5] = 0.0; gs[5] = 0.5; gw[5] = b; init(); } //----------------------------------------------------------------------------- void FETri6NI::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = ai[2]; ao[3] = ai[3]; ao[4] = ai[4]; ao[5] = ai[5]; } //============================================================================ // F E T R I 6 M //============================================================================ /* // parameter used in the tri6m (6-node triangle with modified shape functions) const double fetri6m_alpha = 0.2; //----------------------------------------------------------------------------- void FETri6m_::shape(double* H, double r, double s) { double r1 = 1.0 - r - s; double r2 = r; double r3 = s; double N[6]; N[0] = r1*(2.0*r1 - 1.0); N[1] = r2*(2.0*r2 - 1.0); N[2] = r3*(2.0*r3 - 1.0); N[3] = 4.0*r1*r2; N[4] = 4.0*r2*r3; N[5] = 4.0*r3*r1; const double a = fetri6m_alpha; const double b = 1.0 - 2.0*a; H[0] = N[0] + a*(N[3] + N[5]); H[1] = N[1] + a*(N[3] + N[4]); H[2] = N[2] + a*(N[4] + N[5]); H[3] = b*N[3]; H[4] = b*N[4]; H[5] = b*N[5]; } //----------------------------------------------------------------------------- void FETri6m_::shape_deriv(double* Hr, double* Hs, double r, double s) { double Nr[6], Ns[6]; Nr[0] = -3.0 + 4.0*r + 4.0*s; Nr[1] = 4.0*r - 1.0; Nr[2] = 0.0; Nr[3] = 4.0 - 8.0*r - 4.0*s; Nr[4] = 4.0*s; Nr[5] = -4.0*s; Ns[0] = -3.0 + 4.0*s + 4.0*r; Ns[1] = 0.0; Ns[2] = 4.0*s - 1.0; Ns[3] = -4.0*r; Ns[4] = 4.0*r; Ns[5] = 4.0 - 8.0*s - 4.0*r; const double a = fetri6m_alpha; const double b = 1.0 - 2.0*a; Hr[0] = Nr[0] + a*(Nr[3] + Nr[5]); Hr[1] = Nr[1] + a*(Nr[3] + Nr[4]); Hr[2] = Nr[2] + a*(Nr[4] + Nr[5]); Hr[3] = b*Nr[3]; Hr[4] = b*Nr[4]; Hr[5] = b*Nr[5]; Hs[0] = Ns[0] + a*(Ns[3] + Ns[5]); Hs[1] = Ns[1] + a*(Ns[3] + Ns[4]); Hs[2] = Ns[2] + a*(Ns[4] + Ns[5]); Hs[3] = b*Ns[3]; Hs[4] = b*Ns[4]; Hs[5] = b*Ns[5]; } //----------------------------------------------------------------------------- void FETri6m_::shape_deriv2(double* Hrr, double* Hrs, double* Hss, double r, double s) { double Nrr[6], Nrs[6], Nss[6]; Nrr[0] = 4.0; Nrs[0] = 4.0; Nss[0] = 4.0; Nrr[1] = 4.0; Nrs[1] = 0.0; Nss[1] = 0.0; Nrr[2] = 0.0; Nrs[2] = 0.0; Nss[2] = 4.0; Nrr[3] = -8.0; Nrs[3] = -4.0; Nss[3] = 0.0; Nrr[4] = 0.0; Nrs[4] = 4.0; Nss[4] = 0.0; Nrr[5] = 0.0; Nrs[5] = -4.0; Nss[5] = -8.0; const double a = fetri6m_alpha; const double b = 1.0 - 2.0*a; Hrr[0] = Nrr[0] + a*(Nrr[3] + Nrr[5]); Hrr[1] = Nrr[1] + a*(Nrr[3] + Nrr[4]); Hrr[2] = Nrr[2] + a*(Nrr[4] + Nrr[5]); Hrr[3] = b*Nrr[3]; Hrr[4] = b*Nrr[4]; Hrr[5] = b*Nrr[5]; Hrs[0] = Nrs[0] + a*(Nrs[3] + Nrs[5]); Hrs[1] = Nrs[1] + a*(Nrs[3] + Nrs[4]); Hrs[2] = Nrs[2] + a*(Nrs[4] + Nrs[5]); Hrs[3] = b*Nrs[3]; Hrs[4] = b*Nrs[4]; Hrs[5] = b*Nrs[5]; Hss[0] = Nss[0] + a*(Nss[3] + Nss[5]); Hss[1] = Nss[1] + a*(Nss[3] + Nss[4]); Hss[2] = Nss[2] + a*(Nss[4] + Nss[5]); Hss[3] = b*Nss[3]; Hss[4] = b*Nss[4]; Hss[5] = b*Nss[5]; } //============================================================================= // F E T R I 6 M G 7 //============================================================================= FETri6mG7::FETri6mG7() : FETri6m_(NINT, FE_TRI6MG7) { const double w = 1.0/2.0; gr[0] = 0.333333333333333; gs[0] = 0.333333333333333; gw[0] = w*0.225000000000000; gr[1] = 0.797426985353087; gs[1] = 0.101286507323456; gw[1] = w*0.125939180544827; gr[2] = 0.101286507323456; gs[2] = 0.797426985353087; gw[2] = w*0.125939180544827; gr[3] = 0.101286507323456; gs[3] = 0.101286507323456; gw[3] = w*0.125939180544827; gr[4] = 0.470142064105115; gs[4] = 0.470142064105115; gw[4] = w*0.132394152788506; gr[5] = 0.470142064105115; gs[5] = 0.059715871789770; gw[5] = w*0.132394152788506; gr[6] = 0.059715871789770; gs[6] = 0.470142064105115; gw[6] = w*0.132394152788506; init(); // we need Ai to project integration point data to the nodes matrix A(NELN,NELN); m_Ai.resize(NELN,NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETri6mG7::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i=0; i<NELN; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += m_H[j][i]*ai[j]; } for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NELN; ++j) ao[i] += m_Ai[i][j]*b[j]; } } */ //============================================================================= // F E T R I 7 G 3 //============================================================================= FETri7G3::FETri7G3() : FETri7_(NINT, FE_TRI7G3) { const double a = 1.0 / 6.0; const double b = 2.0 / 3.0; gr[0] = a; gs[0] = a; gw[0] = a; gr[1] = b; gs[1] = a; gw[1] = a; gr[2] = a; gs[2] = b; gw[2] = a; init(); } //----------------------------------------------------------------------------- void FETri7G3::project_to_nodes(double* ai, double* ao) const { matrix H(3, 3); for (int n=0; n<3; ++n) { H[n][0] = 1.0 - gr[n] - gs[n]; H[n][1] = gr[n]; H[n][2] = gs[n]; } H.inverse(); for (int i=0; i<3; ++i) { ao[i] = 0; for (int j=0; j<3; ++j) ao[i] += H[i][j]*ai[j]; } ao[3] = 0.5*(ao[0] + ao[1]); ao[4] = 0.5*(ao[1] + ao[2]); ao[5] = 0.5*(ao[2] + ao[0]); ao[6] = (ao[0]+ao[1]+ao[2])/3.0; } //============================================================================= // F E T R I 6 G 4 //============================================================================= FETri7G4::FETri7G4() : FETri7_(NINT, FE_TRI7G4) { const double a = 1.0/3.0; const double b = 1.0/5.0; const double c = 3.0/5.0; gr[0] = a; gs[0] = a; gw[0] = -27.0/96.0; gr[1] = c; gs[1] = b; gw[1] = 25.0/96.0; gr[2] = b; gs[2] = b; gw[2] = 25.0/96.0; gr[3] = b; gs[3] = c; gw[3] = 25.0/96.0; init(); } //----------------------------------------------------------------------------- //! \todo implement this void FETri7G4::project_to_nodes(double* ai, double* ao) const { } //============================================================================ // F E T R I 7 //============================================================================ void FETri7_::init() { // allocate shape classes m_shapeP.resize(3); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TRI3)); m_shapeP[2] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TRI7)); // centroid coordinates cr = cs = 1.0/3.0; // initialize base class FESurfaceElementTraits::init(); } //============================================================================= // F E T R I 7 G 7 //============================================================================= FETri7G7::FETri7G7() : FETri7_(NINT, FE_TRI7G7) { const double w = 1.0/2.0; gr[0] = 0.333333333333333; gs[0] = 0.333333333333333; gw[0] = w*0.225000000000000; gr[1] = 0.797426985353087; gs[1] = 0.101286507323456; gw[1] = w*0.125939180544827; gr[2] = 0.101286507323456; gs[2] = 0.797426985353087; gw[2] = w*0.125939180544827; gr[3] = 0.101286507323456; gs[3] = 0.101286507323456; gw[3] = w*0.125939180544827; gr[4] = 0.470142064105115; gs[4] = 0.470142064105115; gw[4] = w*0.132394152788506; gr[5] = 0.470142064105115; gs[5] = 0.059715871789770; gw[5] = w*0.132394152788506; gr[6] = 0.059715871789770; gs[6] = 0.470142064105115; gw[6] = w*0.132394152788506; init(); // we need Ai to project integration point data to the nodes matrix A(NELN,NELN); m_Ai.resize(NELN,NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETri7G7::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i=0; i<NELN; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += m_H[j][i]*ai[j]; } for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NELN; ++j) ao[i] += m_Ai[i][j]*b[j]; } } //============================================================================= // F E T R I 7 G L 7 //============================================================================= FETri7GL7::FETri7GL7() : FETri7_(NINT, FE_TRI7GL7) { const double a = 1.0/40.0; const double b = 1.0/15.0; gr[0] = 0.0; gs[0] = 0.0; gw[0] = a; gr[1] = 1.0; gs[1] = 0.0; gw[1] = a; gr[2] = 0.0; gs[2] = 1.0; gw[2] = a; gr[3] = 0.5; gs[3] = 0.0; gw[3] = b; gr[4] = 0.5; gs[4] = 0.5; gw[4] = b; gr[5] = 0.0; gs[5] = 0.5; gw[5] = b; gr[6] = 1.0/3.0; gs[6] = 1.0/3.0; gw[6] = 9.0*a; init(); } //----------------------------------------------------------------------------- void FETri7GL7::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = ai[2]; ao[3] = ai[3]; ao[4] = ai[4]; ao[5] = ai[5]; ao[6] = ai[6]; } //============================================================================ // F E T R I 1 0 //============================================================================ void FETri10_::init() { // allocate shape classes m_shapeP.resize(4); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TRI3)); m_shapeP[2] = 0; // this element cannot be used for quadratic interpolation! m_shapeP[3] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_TRI10)); // centroid coordinates cr = cs = 1.0/3.0; // initialize base class FESurfaceElementTraits::init(); } //============================================================================= // F E T R I 1 0 G 7 //============================================================================= FETri10G7::FETri10G7() : FETri10_(NINT, FE_TRI10G7) { const double w = 1.0 / 2.0; gr[0] = 0.333333333333333; gs[0] = 0.333333333333333; gw[0] = w*0.225000000000000; gr[1] = 0.797426985353087; gs[1] = 0.101286507323456; gw[1] = w*0.125939180544827; gr[2] = 0.101286507323456; gs[2] = 0.797426985353087; gw[2] = w*0.125939180544827; gr[3] = 0.101286507323456; gs[3] = 0.101286507323456; gw[3] = w*0.125939180544827; gr[4] = 0.470142064105115; gs[4] = 0.470142064105115; gw[4] = w*0.132394152788506; gr[5] = 0.470142064105115; gs[5] = 0.059715871789770; gw[5] = w*0.132394152788506; gr[6] = 0.059715871789770; gs[6] = 0.470142064105115; gw[6] = w*0.132394152788506; init(); // we need Ai to project integration point data to the nodes matrix A(NELN, NELN); m_Ai.resize(NELN, NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETri10G7::project_to_nodes(double* ai, double* ao) const { // TODO: Implement this } //============================================================================= // F E T R I 1 0 G 1 2 //============================================================================= FETri10G12::FETri10G12() : FETri10_(NINT, FE_TRI10G12) { gr[ 0] = 0.063089014; gs[ 0] = 0.873821971; gw[ 0] = 0.025422453; gr[ 1] = 0.873821971; gs[ 1] = 0.063089014; gw[ 1] = 0.025422453; gr[ 2] = 0.063089014; gs[ 2] = 0.063089014; gw[ 2] = 0.025422453; gr[ 3] = 0.249286745; gs[ 3] = 0.501426510; gw[ 3] = 0.058393138; gr[ 4] = 0.501426510; gs[ 4] = 0.249286745; gw[ 4] = 0.058393138; gr[ 5] = 0.249286745; gs[ 5] = 0.249286745; gw[ 5] = 0.058393138; gr[ 6] = 0.053145050; gs[ 6] = 0.636502499; gw[ 6] = 0.041425538; gr[ 7] = 0.636502499; gs[ 7] = 0.053145050; gw[ 7] = 0.041425538; gr[ 8] = 0.310352451; gs[ 8] = 0.636502499; gw[ 8] = 0.041425538; gr[ 9] = 0.636502499; gs[ 9] = 0.310352451; gw[ 9] = 0.041425538; gr[10] = 0.310352451; gs[10] = 0.053145050; gw[10] = 0.041425538; gr[11] = 0.053145050; gs[11] = 0.310352451; gw[11] = 0.041425538; init(); // we need Ai to project integration point data to the nodes matrix A(NELN, NELN); m_Ai.resize(NELN, NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FETri10G12::project_to_nodes(double* ai, double* ao) const { // TODO: Implement this } //============================================================================= // F E Q U A D 8 //============================================================================= void FEQuad8_::init() { // allocate shape classes m_shapeP.resize(3); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_QUAD4)); m_shapeP[2] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_QUAD8)); // centroid coordinates cr = cs = 0; // initialize base class FESurfaceElementTraits::init(); } //============================================================================= // F E Q U A D 8 G 9 //============================================================================= FEQuad8G9::FEQuad8G9() : FEQuad8_(NINT, FE_QUAD8G9) { // integration point coordinates const double a = sqrt(0.6); const double w1 = 25.0/81.0; const double w2 = 40.0/81.0; const double w3 = 64.0/81.0; gr[ 0] = -a; gs[ 0] = -a; gw[ 0] = w1; gr[ 1] = 0; gs[ 1] = -a; gw[ 1] = w2; gr[ 2] = a; gs[ 2] = -a; gw[ 2] = w1; gr[ 3] = -a; gs[ 3] = 0; gw[ 3] = w2; gr[ 4] = 0; gs[ 4] = 0; gw[ 4] = w3; gr[ 5] = a; gs[ 5] = 0; gw[ 5] = w2; gr[ 6] = -a; gs[ 6] = a; gw[ 6] = w1; gr[ 7] = 0; gs[ 7] = a; gw[ 7] = w2; gr[ 8] = a; gs[ 8] = a; gw[ 8] = w1; init(); // we need Ai to project integration point data to the nodes matrix A(NELN,NELN); m_Ai.resize(NELN,NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FEQuad8G9::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i=0; i<NELN; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += m_H[j][i]*ai[j]; } for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NELN; ++j) ao[i] += m_Ai[i][j]*b[j]; } } //============================================================================= // F E Q U A D 8 N I //============================================================================= FEQuad8NI::FEQuad8NI() : FEQuad8_(NINT, FE_QUAD8NI) { double w = 1./9.; gr[0] = -1; gs[0] = -1; gw[0] = w; gr[1] = 1; gs[1] = -1; gw[1] = w; gr[2] = 1; gs[2] = 1; gw[2] = w; gr[3] = -1; gs[3] = 1; gw[3] = w; gr[4] = 0; gs[4] = -1; gw[0] = 4*w; gr[5] = 1; gs[5] = 0; gw[1] = 4*w; gr[6] = 0; gs[6] = 1; gw[2] = 4*w; gr[7] = -1; gs[7] = 0; gw[3] = 4*w; init(); } //----------------------------------------------------------------------------- void FEQuad8NI::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = ai[2]; ao[3] = ai[3]; ao[4] = ai[4]; ao[5] = ai[5]; ao[6] = ai[6]; ao[7] = ai[7]; } //============================================================================= // F E Q U A D 9 //============================================================================= void FEQuad9_::init() { // allocate shape classes m_shapeP.resize(3); m_shapeP[0] = 0; m_shapeP[1] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_QUAD4)); m_shapeP[2] = dynamic_cast<FESurfaceElementShape*>(FEElementLibrary::GetElementShapeClass(ET_QUAD9)); // centroid coordinates cr = cs = 0; // initialize base class FESurfaceElementTraits::init(); } //============================================================================= // F E Q U A D 9 G 9 //============================================================================= FEQuad9G9::FEQuad9G9() : FEQuad9_(NINT, FE_QUAD9G9) { // integration point coordinates const double a = sqrt(0.6); const double w1 = 25.0/81.0; const double w2 = 40.0/81.0; const double w3 = 64.0/81.0; gr[ 0] = -a; gs[ 0] = -a; gw[ 0] = w1; gr[ 1] = 0; gs[ 1] = -a; gw[ 1] = w2; gr[ 2] = a; gs[ 2] = -a; gw[ 2] = w1; gr[ 3] = -a; gs[ 3] = 0; gw[ 3] = w2; gr[ 4] = 0; gs[ 4] = 0; gw[ 4] = w3; gr[ 5] = a; gs[ 5] = 0; gw[ 5] = w2; gr[ 6] = -a; gs[ 6] = a; gw[ 6] = w1; gr[ 7] = 0; gs[ 7] = a; gw[ 7] = w2; gr[ 8] = a; gs[ 8] = a; gw[ 8] = w1; init(); // we need Ai to project integration point data to the nodes matrix A(NELN,NELN); m_Ai.resize(NELN,NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FEQuad9G9::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i=0; i<NELN; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += m_H[j][i]*ai[j]; } for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NELN; ++j) ao[i] += m_Ai[i][j]*b[j]; } } //============================================================================= // F E Q U A D 9 N I //============================================================================= FEQuad9NI::FEQuad9NI() : FEQuad9_(NINT, FE_QUAD9NI) { double w = 1./9.; gr[0] = -1; gs[0] = -1; gw[0] = w; gr[1] = 1; gs[1] = -1; gw[1] = w; gr[2] = 1; gs[2] = 1; gw[2] = w; gr[3] = -1; gs[3] = 1; gw[3] = w; gr[4] = 0; gs[4] = -1; gw[0] = 4*w; gr[5] = 1; gs[5] = 0; gw[1] = 4*w; gr[6] = 0; gs[6] = 1; gw[2] = 4*w; gr[7] = -1; gs[7] = 0; gw[3] = 4*w; gr[8] = 0; gs[8] = 0; gw[3] = 16*w; init(); } //----------------------------------------------------------------------------- void FEQuad9NI::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = ai[2]; ao[3] = ai[3]; ao[4] = ai[4]; ao[5] = ai[5]; ao[6] = ai[6]; ao[7] = ai[7]; ao[8] = ai[8]; } //============================================================================= // // S H E L L E L E M E N T S // //============================================================================= FEShellElementTraits::FEShellElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et) : FEElementTraits(ni, ne, FE_ELEM_SHELL, es, et) { m_nvln = ne; gr.resize(ni); gs.resize(ni); gt.resize(ni); gw.resize(ni); Hr.resize(ni, ne); Hs.resize(ni, ne); m_faces = 1; } //----------------------------------------------------------------------------- //! initialize element traits data void FEShellElementTraits::init() { assert(m_nint > 0); assert(m_neln > 0); const int NELN = FEElement::MAX_NODES; // calculate shape function values at gauss points double N[NELN]; for (int n=0; n<m_nint; ++n) { shape_fnc(N, gr[n], gs[n]); for (int i=0; i<m_neln; ++i) m_H[n][i] = N[i]; } // calculate local derivatives of shape functions at gauss points double Nr[NELN], Ns[NELN]; for (int n=0; n<m_nint; ++n) { shape_deriv(Nr, Ns, gr[n], gs[n]); for (int i=0; i<m_neln; ++i) { Hr[n][i] = Nr[i]; Hs[n][i] = Ns[i]; } } } //! project mat3ds integration point data to nodes void FEShellElementTraits::project_to_nodes(mat3ds* si, mat3ds* so) const { double ai[FEElement::MAX_INTPOINTS]; double ao[FEElement::MAX_NODES]; for (int i = 0; i < 3; ++i) { for (int j = i; j < 3; ++j) { for (int n = 0; n < m_nint; ++n) ai[n] = si[n](i, j); project_to_nodes(ai, ao); for (int n = 0; n < m_nvln; ++n) so[n](i, j) = ao[n]; } } } //============================================================================= // F E S H E L L Q U A D 4 //============================================================================= //----------------------------------------------------------------------------- void FEShellQuad4_::shape_fnc(double* H, double r, double s) { H[0] = 0.25*(1-r)*(1-s); H[1] = 0.25*(1+r)*(1-s); H[2] = 0.25*(1+r)*(1+s); H[3] = 0.25*(1-r)*(1+s); } //----------------------------------------------------------------------------- //! values of shape function derivatives void FEShellQuad4_::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -0.25*(1-s); Hr[1] = 0.25*(1-s); Hr[2] = 0.25*(1+s); Hr[3] = -0.25*(1+s); Hs[0] = -0.25*(1-r); Hs[1] = -0.25*(1+r); Hs[2] = 0.25*(1+r); Hs[3] = 0.25*(1-r); } //***************************************************************************** // S H E L L Q U A D 4 G 4 //***************************************************************************** FEShellQuad4G4::FEShellQuad4G4() : FEShellQuad4_(NINT, FE_SHELL_QUAD4G4) { const double a = 1.0 / sqrt(3.0); gr[0] = -a; gs[0] = -a; gw[0] = 1; gr[1] = a; gs[1] = -a; gw[1] = 1; gr[2] = a; gs[2] = a; gw[2] = 1; gr[3] = -a; gs[3] = a; gw[3] = 1; init(); m_Hi = m_H.inverse(); } void FEShellQuad4G4::project_to_nodes(double* ai, double* ao) const { int ni = NINT; int ne = NELN; assert(ni == ne); for (int i = 0; i < ne; ++i) { ao[i] = 0; for (int j = 0; j < ni; ++j) ao[i] += m_Hi[i][j] * ai[j]; } } //***************************************************************************** // S H E L L Q U A D 4 G 8 //***************************************************************************** int FEShellQuad4G8::ni[NELN] = { 4, 5, 6, 7 }; FEShellQuad4G8::FEShellQuad4G8() : FEShellQuad4_(NINT, FE_SHELL_QUAD4G8) { m_nvln = 8; const double a = 1.0 / sqrt(3.0); const double w = 1.0; gr[ 0] = -a; gs[ 0] = -a; gt[ 0] = -a; gw[ 0] = w; gr[ 1] = a; gs[ 1] = -a; gt[ 1] = -a; gw[ 1] = w; gr[ 2] = a; gs[ 2] = a; gt[ 2] = -a; gw[ 2] = w; gr[ 3] = -a; gs[ 3] = a; gt[ 3] = -a; gw[ 3] = w; gr[ 4] = -a; gs[ 4] = -a; gt[ 4] = a; gw[ 4] = w; gr[ 5] = a; gs[ 5] = -a; gt[ 5] = a; gw[ 5] = w; gr[ 6] = a; gs[ 6] = a; gt[ 6] = a; gw[ 6] = w; gr[ 7] = -a; gs[ 7] = a; gt[ 7] = a; gw[ 7] = w; init(); m_MT.resize(m_nvln, NINT); for (int i=0; i<NINT; ++i) { for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n)*(1-gt[i])/2; for (int n=NELN; n<m_nvln; ++n) m_MT(n,i) = m_H(i,n-NELN)*(1+gt[i])/2; } m_Hi.resize(m_nvln, m_nvln); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEShellQuad4G8::project_to_nodes(double* ai, double* ao) const { std::vector<double> v(m_nvln); for (int n=0; n<m_nvln; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<m_nvln; ++j) { ao[j] = 0; for (int k=0; k<m_nvln; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //***************************************************************************** // S H E L L Q U A D 4 G 1 2 //***************************************************************************** int FEShellQuad4G12::ni[NELN] = { 8, 9, 10, 11 }; FEShellQuad4G12::FEShellQuad4G12() : FEShellQuad4_(NINT, FE_SHELL_QUAD4G12) { m_nvln = 8; const double a = 1.0 / sqrt(3.0); const double b = sqrt(3.0/5.0); const double w = 5.0 / 9.0; gr[ 0] = -a; gs[ 0] = -a; gt[ 0] = -b; gw[ 0] = w; gr[ 1] = a; gs[ 1] = -a; gt[ 1] = -b; gw[ 1] = w; gr[ 2] = a; gs[ 2] = a; gt[ 2] = -b; gw[ 2] = w; gr[ 3] = -a; gs[ 3] = a; gt[ 3] = -b; gw[ 3] = w; gr[ 4] = -a; gs[ 4] = -a; gt[ 4] = 0; gw[ 4] = 8.0/9.0; gr[ 5] = a; gs[ 5] = -a; gt[ 5] = 0; gw[ 5] = 8.0/9.0; gr[ 6] = a; gs[ 6] = a; gt[ 6] = 0; gw[ 6] = 8.0/9.0; gr[ 7] = -a; gs[ 7] = a; gt[ 7] = 0; gw[ 7] = 8.0/9.0; gr[ 8] = -a; gs[ 8] = -a; gt[ 8] = b; gw[ 8] = w; gr[ 9] = a; gs[ 9] = -a; gt[ 9] = b; gw[ 9] = w; gr[10] = a; gs[10] = a; gt[10] = b; gw[10] = w; gr[11] = -a; gs[11] = a; gt[11] = b; gw[11] = w; init(); m_MT.resize(m_nvln, NINT); for (int i=0; i<NINT; ++i) { for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n)*(1-gt[i])/2; for (int n=NELN; n<m_nvln; ++n) m_MT(n,i) = m_H(i,n-NELN)*(1+gt[i])/2; } m_Hi.resize(m_nvln, m_nvln); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEShellQuad4G12::project_to_nodes(double* ai, double* ao) const { std::vector<double> v(m_nvln); for (int n=0; n<m_nvln; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<m_nvln; ++j) { ao[j] = 0; for (int k=0; k<m_nvln; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //============================================================================= // F E S H E L L T R I 3 //============================================================================= //----------------------------------------------------------------------------- void FEShellTri3_::shape_fnc(double* H, double r, double s) { H[0] = 1-r-s; H[1] = r; H[2] = s; } //----------------------------------------------------------------------------- //! values of shape function derivatives void FEShellTri3_::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -1; Hr[1] = 1; Hr[2] = 0; Hs[0] = -1; Hs[1] = 0; Hs[2] = 1; } //***************************************************************************** // F E S H E L L T R I G 3 //***************************************************************************** //----------------------------------------------------------------------------- FEShellTri3G3::FEShellTri3G3() : FEShellTri3_(NINT, FE_SHELL_TRI3G3) { const double a = 1.0 / 6.0; const double b = 2.0 / 3.0; gr[0] = a; gs[0] = a; gw[0] = a; gr[1] = b; gs[1] = a; gw[1] = a; gr[2] = a; gs[2] = b; gw[2] = a; init(); m_Hi = m_H.inverse(); } //----------------------------------------------------------------------------- void FEShellTri3G3::project_to_nodes(double* ai, double* ao) const { assert(NINT == NELN); for (int i = 0; i < NELN; ++i) { ao[i] = 0; for (int j = 0; j < NINT; ++j) ao[i] += m_Hi[i][j] * ai[j]; } } //***************************************************************************** // S H E L L T R I 3 G 6 //***************************************************************************** int FEShellTri3G6::ni[NELN] = { 3, 4, 5 }; FEShellTri3G6::FEShellTri3G6() : FEShellTri3_(NINT, FE_SHELL_TRI3G6) { m_nvln = 6; //gauss intergration points const double a = 1.0/6.0; const double b = 2.0/3.0; const double c = 1.0 / sqrt(3.0); gr[0] = a; gs[0] = a; gt[0] = -c; gw[0] = a; gr[1] = b; gs[1] = a; gt[1] = -c; gw[1] = a; gr[2] = a; gs[2] = b; gt[2] = -c; gw[2] = a; gr[3] = a; gs[3] = a; gt[3] = c; gw[3] = a; gr[4] = b; gs[4] = a; gt[4] = c; gw[4] = a; gr[5] = a; gs[5] = b; gt[5] = c; gw[5] = a; init(); m_MT.resize(m_nvln, NINT); for (int i=0; i<NINT; ++i) { for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n)*(1-gt[i])/2; for (int n=NELN; n<m_nvln; ++n) m_MT(n,i) = m_H(i,n-NELN)*(1+gt[i])/2; } m_Hi.resize(m_nvln, m_nvln); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEShellTri3G6::project_to_nodes(double* ai, double* ao) const { std::vector<double> v(m_nvln); for (int n=0; n<m_nvln; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<m_nvln; ++j) { ao[j] = 0; for (int k=0; k<m_nvln; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //***************************************************************************** // S H E L L T R I 3 G 9 //***************************************************************************** int FEShellTri3G9::ni[NELN] = { 6, 7, 8 }; FEShellTri3G9::FEShellTri3G9() : FEShellTri3_(NINT, FE_SHELL_TRI3G9) { m_nvln = 6; const double a = 1.0 / 6.0; const double b = 2.0 / 3.0; const double w1 = 5.0 / 9.0; const double w2 = 8.0 / 9.0; gr[0] = a; gs[0] = a; gt[0] = -b; gw[0] = a*w1; gr[1] = b; gs[1] = a; gt[1] = -b; gw[1] = a*w1; gr[2] = a; gs[2] = b; gt[2] = -b; gw[2] = a*w1; gr[3] = a; gs[3] = a; gt[3] = 0; gw[3] = a*w2; gr[4] = b; gs[4] = a; gt[4] = 0; gw[4] = a*w2; gr[5] = a; gs[5] = b; gt[5] = 0; gw[5] = a*w2; gr[6] = a; gs[6] = a; gt[6] = b; gw[6] = a*w1; gr[7] = b; gs[7] = a; gt[7] = b; gw[7] = a*w1; gr[8] = a; gs[8] = b; gt[8] = b; gw[8] = a*w1; init(); m_MT.resize(m_nvln, NINT); for (int i=0; i<NINT; ++i) { for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n)*(1-gt[i])/2; for (int n=NELN; n<m_nvln; ++n) m_MT(n,i) = m_H(i,n-NELN)*(1+gt[i])/2; } m_Hi.resize(m_nvln, m_nvln); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEShellTri3G9::project_to_nodes(double* ai, double* ao) const { std::vector<double> v(m_nvln); for (int n=0; n<m_nvln; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<m_nvln; ++j) { ao[j] = 0; for (int k=0; k<m_nvln; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //============================================================================= // F E S H E L L Q U A D 8 //============================================================================= //----------------------------------------------------------------------------- void FEShellQuad8_::shape_fnc(double* H, double r, double s) { H[4] = 0.5*(1 - r*r)*(1 - s); H[5] = 0.5*(1 - s*s)*(1 + r); H[6] = 0.5*(1 - r*r)*(1 + s); H[7] = 0.5*(1 - s*s)*(1 - r); H[0] = 0.25*(1 - r)*(1 - s) - 0.5*(H[4] + H[7]); H[1] = 0.25*(1 + r)*(1 - s) - 0.5*(H[4] + H[5]); H[2] = 0.25*(1 + r)*(1 + s) - 0.5*(H[5] + H[6]); H[3] = 0.25*(1 - r)*(1 + s) - 0.5*(H[6] + H[7]); } //----------------------------------------------------------------------------- //! values of shape function derivatives void FEShellQuad8_::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[4] = -r*(1 - s); Hr[5] = 0.5*(1 - s*s); Hr[6] = -r*(1 + s); Hr[7] = -0.5*(1 - s*s); Hr[0] = -0.25*(1 - s) - 0.5*(Hr[4] + Hr[7]); Hr[1] = 0.25*(1 - s) - 0.5*(Hr[4] + Hr[5]); Hr[2] = 0.25*(1 + s) - 0.5*(Hr[5] + Hr[6]); Hr[3] = -0.25*(1 + s) - 0.5*(Hr[6] + Hr[7]); Hs[4] = -0.5*(1 - r*r); Hs[5] = -s*(1 + r); Hs[6] = 0.5*(1 - r*r); Hs[7] = -s*(1 - r); Hs[0] = -0.25*(1 - r) - 0.5*(Hs[4] + Hs[7]); Hs[1] = -0.25*(1 + r) - 0.5*(Hs[4] + Hs[5]); Hs[2] = 0.25*(1 + r) - 0.5*(Hs[5] + Hs[6]); Hs[3] = 0.25*(1 - r) - 0.5*(Hs[6] + Hs[7]); } //***************************************************************************** // S H E L L Q U A D 8 G 1 8 //***************************************************************************** int FEShellQuad8G18::ni[NELN] = { 9, 10, 11, 12, 14, 15, 16, 17 }; FEShellQuad8G18::FEShellQuad8G18() : FEShellQuad8_(NINT, FE_SHELL_QUAD8G18) { m_nvln = 16; // integration point coordinates const double a = 0.774596669241483; const double c = 0.577350269189626; const double w1 = 5.0 / 9.0; const double w2 = 8.0 / 9.0; gr[ 0] = -a; gs[ 0] = -a; gt[ 0] = -c; gw[ 0] = w1*w1; gr[ 1] = 0; gs[ 1] = -a; gt[ 1] = -c; gw[ 1] = w2*w1; gr[ 2] = a; gs[ 2] = -a; gt[ 2] = -c; gw[ 2] = w1*w1; gr[ 3] = -a; gs[ 3] = 0; gt[ 3] = -c; gw[ 3] = w1*w2; gr[ 4] = 0; gs[ 4] = 0; gt[ 4] = -c; gw[ 4] = w2*w2; gr[ 5] = a; gs[ 5] = 0; gt[ 5] = -c; gw[ 5] = w1*w2; gr[ 6] = -a; gs[ 6] = a; gt[ 6] = -c; gw[ 6] = w1*w1; gr[ 7] = 0; gs[ 7] = a; gt[ 7] = -c; gw[ 7] = w2*w1; gr[ 8] = a; gs[ 8] = a; gt[ 8] = -c; gw[ 8] = w1*w1; gr[ 9] = -a; gs[ 9] = -a; gt[ 9] = c; gw[ 9] = w1*w1; gr[10] = 0; gs[10] = -a; gt[10] = c; gw[10] = w2*w1; gr[11] = a; gs[11] = -a; gt[11] = c; gw[11] = w1*w1; gr[12] = -a; gs[12] = 0; gt[12] = c; gw[12] = w1*w2; gr[13] = 0; gs[13] = 0; gt[13] = c; gw[13] = w2*w2; gr[14] = a; gs[14] = 0; gt[14] = c; gw[14] = w1*w2; gr[15] = -a; gs[15] = a; gt[15] = c; gw[15] = w1*w1; gr[16] = 0; gs[16] = a; gt[16] = c; gw[16] = w2*w1; gr[17] = a; gs[17] = a; gt[17] = c; gw[17] = w1*w1; init(); m_MT.resize(m_nvln, NINT); for (int i=0; i<NINT; ++i) { for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n)*(1-gt[i])/2; for (int n=NELN; n<m_nvln; ++n) m_MT(n,i) = m_H(i,n-NELN)*(1+gt[i])/2; } m_Hi.resize(m_nvln, m_nvln); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEShellQuad8G18::project_to_nodes(double* ai, double* ao) const { std::vector<double> v(m_nvln); for (int n=0; n<m_nvln; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<m_nvln; ++j) { ao[j] = 0; for (int k=0; k<m_nvln; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //***************************************************************************** // S H E L L Q U A D 8 G 2 7 //***************************************************************************** int FEShellQuad8G27::ni[NELN] = { 18, 19, 20, 21, 23, 24, 25, 26 }; FEShellQuad8G27::FEShellQuad8G27() : FEShellQuad8_(NINT, FE_SHELL_QUAD8G27) { m_nvln = 16; // integration point coordinates const double a = 0.774596669241483; const double w1 = 5.0 / 9.0; const double w2 = 8.0 / 9.0; gr[ 0] = -a; gs[ 0] = -a; gt[ 0] = -a; gw[ 0] = w1*w1*w1; gr[ 1] = 0; gs[ 1] = -a; gt[ 1] = -a; gw[ 1] = w2*w1*w1; gr[ 2] = a; gs[ 2] = -a; gt[ 2] = -a; gw[ 2] = w1*w1*w1; gr[ 3] = -a; gs[ 3] = 0; gt[ 3] = -a; gw[ 3] = w1*w2*w1; gr[ 4] = 0; gs[ 4] = 0; gt[ 4] = -a; gw[ 4] = w2*w2*w1; gr[ 5] = a; gs[ 5] = 0; gt[ 5] = -a; gw[ 5] = w1*w2*w1; gr[ 6] = -a; gs[ 6] = a; gt[ 6] = -a; gw[ 6] = w1*w1*w1; gr[ 7] = 0; gs[ 7] = a; gt[ 7] = -a; gw[ 7] = w2*w1*w1; gr[ 8] = a; gs[ 8] = a; gt[ 8] = -a; gw[ 8] = w1*w1*w1; gr[ 9] = -a; gs[ 9] = -a; gt[ 9] = 0; gw[ 9] = w1*w1*w2; gr[10] = 0; gs[10] = -a; gt[10] = 0; gw[10] = w2*w1*w2; gr[11] = a; gs[11] = -a; gt[11] = 0; gw[11] = w1*w1*w2; gr[12] = -a; gs[12] = 0; gt[12] = 0; gw[12] = w1*w2*w2; gr[13] = 0; gs[13] = 0; gt[13] = 0; gw[13] = w2*w2*w2; gr[14] = a; gs[14] = 0; gt[14] = 0; gw[14] = w1*w2*w2; gr[15] = -a; gs[15] = a; gt[15] = 0; gw[15] = w1*w1*w2; gr[16] = 0; gs[16] = a; gt[16] = 0; gw[16] = w2*w1*w2; gr[17] = a; gs[17] = a; gt[17] = 0; gw[17] = w1*w1*w2; gr[18] = -a; gs[18] = -a; gt[18] = a; gw[18] = w1*w1*w1; gr[19] = 0; gs[19] = -a; gt[19] = a; gw[19] = w2*w1*w1; gr[20] = a; gs[20] = -a; gt[20] = a; gw[20] = w1*w1*w1; gr[21] = -a; gs[21] = 0; gt[21] = a; gw[21] = w1*w2*w1; gr[22] = 0; gs[22] = 0; gt[22] = a; gw[22] = w2*w2*w1; gr[23] = a; gs[23] = 0; gt[23] = a; gw[23] = w1*w2*w1; gr[24] = -a; gs[24] = a; gt[24] = a; gw[24] = w1*w1*w1; gr[25] = 0; gs[25] = a; gt[25] = a; gw[25] = w2*w1*w1; gr[26] = a; gs[26] = a; gt[26] = a; gw[26] = w1*w1*w1; init(); m_MT.resize(m_nvln, NINT); for (int i=0; i<NINT; ++i) { for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n)*(1-gt[i])/2; for (int n=NELN; n<m_nvln; ++n) m_MT(n,i) = m_H(i,n-NELN)*(1+gt[i])/2; } m_Hi.resize(m_nvln, m_nvln); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEShellQuad8G27::project_to_nodes(double* ai, double* ao) const { std::vector<double> v(m_nvln); for (int n=0; n<m_nvln; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<m_nvln; ++j) { ao[j] = 0; for (int k=0; k<m_nvln; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //============================================================================= // F E S H E L L T R I 6 //============================================================================= //----------------------------------------------------------------------------- void FEShellTri6_::shape_fnc(double* H, double r, double s) { double r1 = 1.0 - r - s; double r2 = r; double r3 = s; H[0] = r1*(2.0*r1 - 1.0); H[1] = r2*(2.0*r2 - 1.0); H[2] = r3*(2.0*r3 - 1.0); H[3] = 4.0*r1*r2; H[4] = 4.0*r2*r3; H[5] = 4.0*r3*r1; } //----------------------------------------------------------------------------- //! values of shape function derivatives void FEShellTri6_::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -3.0 + 4.0*r + 4.0*s; Hr[1] = 4.0*r - 1.0; Hr[2] = 0.0; Hr[3] = 4.0 - 8.0*r - 4.0*s; Hr[4] = 4.0*s; Hr[5] = -4.0*s; Hs[0] = -3.0 + 4.0*s + 4.0*r; Hs[1] = 0.0; Hs[2] = 4.0*s - 1.0; Hs[3] = -4.0*r; Hs[4] = 4.0*r; Hs[5] = 4.0 - 8.0*s - 4.0*r; } //***************************************************************************** // S H E L L T R I 6 G 1 4 //***************************************************************************** int FEShellTri6G14::ni[NELN] = { 8, 9, 10, 11, 12, 13 }; FEShellTri6G14::FEShellTri6G14() : FEShellTri6_(NINT, FE_SHELL_TRI6G14) { m_nvln = 12; const double a = 0.774596669241483; const double c = 0.577350269189626; const double w = 1.0/2.0; gr[ 0] = 0.333333333333333; gs[ 0] = 0.333333333333333; gt[ 0] = -c; gw[ 0] = w*0.225000000000000; gr[ 1] = 0.797426985353087; gs[ 1] = 0.101286507323456; gt[ 1] = -c; gw[ 1] = w*0.125939180544827; gr[ 2] = 0.101286507323456; gs[ 2] = 0.797426985353087; gt[ 2] = -c; gw[ 2] = w*0.125939180544827; gr[ 3] = 0.101286507323456; gs[ 3] = 0.101286507323456; gt[ 3] = -c; gw[ 3] = w*0.125939180544827; gr[ 4] = 0.470142064105115; gs[ 4] = 0.470142064105115; gt[ 4] = -c; gw[ 4] = w*0.132394152788506; gr[ 5] = 0.470142064105115; gs[ 5] = 0.059715871789770; gt[ 5] = -c; gw[ 5] = w*0.132394152788506; gr[ 6] = 0.059715871789770; gs[ 6] = 0.470142064105115; gt[ 6] = -c; gw[ 6] = w*0.132394152788506; gr[ 7] = 0.333333333333333; gs[ 7] = 0.333333333333333; gt[ 7] = c; gw[ 7] = w*0.225000000000000; gr[ 8] = 0.797426985353087; gs[ 8] = 0.101286507323456; gt[ 8] = c; gw[ 8] = w*0.125939180544827; gr[ 9] = 0.101286507323456; gs[ 9] = 0.797426985353087; gt[ 9] = c; gw[ 9] = w*0.125939180544827; gr[10] = 0.101286507323456; gs[10] = 0.101286507323456; gt[10] = c; gw[10] = w*0.125939180544827; gr[11] = 0.470142064105115; gs[11] = 0.470142064105115; gt[11] = c; gw[11] = w*0.132394152788506; gr[12] = 0.470142064105115; gs[12] = 0.059715871789770; gt[12] = c; gw[12] = w*0.132394152788506; gr[13] = 0.059715871789770; gs[13] = 0.470142064105115; gt[13] = c; gw[13] = w*0.132394152788506; init(); m_MT.resize(m_nvln, NINT); for (int i=0; i<NINT; ++i) { for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n)*(1-gt[i])/2; for (int n=NELN; n<m_nvln; ++n) m_MT(n,i) = m_H(i,n-NELN)*(1+gt[i])/2; } m_Hi.resize(m_nvln, m_nvln); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEShellTri6G14::project_to_nodes(double* ai, double* ao) const { std::vector<double> v(m_nvln); for (int n=0; n<m_nvln; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<m_nvln; ++j) { ao[j] = 0; for (int k=0; k<m_nvln; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //***************************************************************************** // S H E L L T R I 6 G 2 1 //***************************************************************************** int FEShellTri6G21::ni[NELN] = { 15, 16, 17, 18, 19, 20 }; FEShellTri6G21::FEShellTri6G21() : FEShellTri6_(NINT, FE_SHELL_TRI6G21) { m_nvln = 12; const double a = 0.774596669241483; const double w = 1.0/2.0; const double w1 = 5.0 / 9.0; const double w2 = 8.0 / 9.0; gr[ 0] = 0.333333333333333; gs[ 0] = 0.333333333333333; gt[ 0] = -a; gw[ 0] = w*w1*0.225000000000000; gr[ 1] = 0.797426985353087; gs[ 1] = 0.101286507323456; gt[ 1] = -a; gw[ 1] = w*w1*0.125939180544827; gr[ 2] = 0.101286507323456; gs[ 2] = 0.797426985353087; gt[ 2] = -a; gw[ 2] = w*w1*0.125939180544827; gr[ 3] = 0.101286507323456; gs[ 3] = 0.101286507323456; gt[ 3] = -a; gw[ 3] = w*w1*0.125939180544827; gr[ 4] = 0.470142064105115; gs[ 4] = 0.470142064105115; gt[ 4] = -a; gw[ 4] = w*w1*0.132394152788506; gr[ 5] = 0.470142064105115; gs[ 5] = 0.059715871789770; gt[ 5] = -a; gw[ 5] = w*w1*0.132394152788506; gr[ 6] = 0.059715871789770; gs[ 6] = 0.470142064105115; gt[ 6] = -a; gw[ 6] = w*w1*0.132394152788506; gr[ 7] = 0.333333333333333; gs[ 7] = 0.333333333333333; gt[ 7] = 0; gw[ 7] = w*w2*0.225000000000000; gr[ 8] = 0.797426985353087; gs[ 8] = 0.101286507323456; gt[ 8] = 0; gw[ 8] = w*w2*0.125939180544827; gr[ 9] = 0.101286507323456; gs[ 9] = 0.797426985353087; gt[ 9] = 0; gw[ 9] = w*w2*0.125939180544827; gr[10] = 0.101286507323456; gs[10] = 0.101286507323456; gt[10] = 0; gw[10] = w*w2*0.125939180544827; gr[11] = 0.470142064105115; gs[11] = 0.470142064105115; gt[11] = 0; gw[11] = w*w2*0.132394152788506; gr[12] = 0.470142064105115; gs[12] = 0.059715871789770; gt[12] = 0; gw[12] = w*w2*0.132394152788506; gr[13] = 0.059715871789770; gs[13] = 0.470142064105115; gt[13] = 0; gw[13] = w*w2*0.132394152788506; gr[14] = 0.333333333333333; gs[14] = 0.333333333333333; gt[14] = a; gw[14] = w*w1*0.225000000000000; gr[15] = 0.797426985353087; gs[15] = 0.101286507323456; gt[15] = a; gw[15] = w*w1*0.125939180544827; gr[16] = 0.101286507323456; gs[16] = 0.797426985353087; gt[16] = a; gw[16] = w*w1*0.125939180544827; gr[17] = 0.101286507323456; gs[17] = 0.101286507323456; gt[17] = a; gw[17] = w*w1*0.125939180544827; gr[18] = 0.470142064105115; gs[18] = 0.470142064105115; gt[18] = a; gw[18] = w*w1*0.132394152788506; gr[19] = 0.470142064105115; gs[19] = 0.059715871789770; gt[19] = a; gw[19] = w*w1*0.132394152788506; gr[20] = 0.059715871789770; gs[20] = 0.470142064105115; gt[20] = a; gw[20] = w*w1*0.132394152788506; init(); m_MT.resize(m_nvln, NINT); for (int i=0; i<NINT; ++i) { for (int n=0; n<NELN; ++n) m_MT(n,i) = m_H(i,n)*(1-gt[i])/2; for (int n=NELN; n<m_nvln; ++n) m_MT(n,i) = m_H(i,n-NELN)*(1+gt[i])/2; } m_Hi.resize(m_nvln, m_nvln); m_Hi = m_MT*m_MT.transpose(); m_Hi = m_Hi.inverse(); } //----------------------------------------------------------------------------- //! project to nodes void FEShellTri6G21::project_to_nodes(double* ai, double* ao) const { std::vector<double> v(m_nvln); for (int n=0; n<m_nvln; ++n) { v[n] = 0; for (int i=0; i<NINT; ++i) { v[n] += m_MT(n,i)*ai[i]; } } for (int j=0; j<m_nvln; ++j) { ao[j] = 0; for (int k=0; k<m_nvln; ++k) { ao[j] += m_Hi[j][k]*v[k]; } } } //============================================================================= // F E T R U S S E L E M E N T //============================================================================= FETrussElementTraits::FETrussElementTraits() : FEElementTraits(NINT, NELN, FE_ELEM_TRUSS, ET_TRUSS2, FE_TRUSS) { gr.resize(NINT, 0); gw.resize(NINT, 0); init(); } void FETrussElementTraits::init() { const double a = 1.0 / sqrt(3.0); gr[0] = -a; gr[1] = a; gw[0] = gw[1] = 1; assert(m_nint > 0); assert(m_neln > 0); // evaluate shape functions const int NE = FEElement::MAX_NODES; double N[NE]; for (int n = 0; n < m_nint; ++n) { shape(N, gr[n]); for (int i = 0; i < m_neln; ++i) m_H[n][i] = N[i]; } } void FETrussElementTraits::shape(double* H, double r) { H[0] = 0.5 * (1.0 - r); H[1] = 0.5 * (1.0 + r); } //============================================================================= // // 2 D E L E M E N T S // //============================================================================= FE2DElementTraits::FE2DElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et) : FEElementTraits(ni, ne, FE_ELEM_2D, es, et) { gr.resize(ni); gs.resize(ni); gw.resize(ni); Gr.resize(ni, ne); Gs.resize(ni, ne); Grr.resize(ni, ne); Gsr.resize(ni, ne); Grs.resize(ni, ne); Gss.resize(ni, ne); } //----------------------------------------------------------------------------- //! Initialize the 2D element traits data variables. // void FE2DElementTraits::init() { assert(m_nint > 0); assert(m_neln > 0); // evaluate shape functions const int NE = FEElement::MAX_NODES; double N[NE]; for (int n=0; n<m_nint; ++n) { shape(N, gr[n], gs[n]); for (int i=0; i<m_neln; ++i) m_H[n][i] = N[i]; } // evaluate shape function derivatives double Nr[NE], Ns[NE]; for (int n=0; n<m_nint; ++n) { shape_deriv(Nr, Ns, gr[n], gs[n]); for (int i=0; i<m_neln; ++i) { Gr[n][i] = Nr[i]; Gs[n][i] = Ns[i]; } } } //============================================================================= // F E 2 D T R I //============================================================================= //----------------------------------------------------------------------------- void FE2DTri3_::shape(double* H, double r, double s) { H[0] = 1.0 - r - s; H[1] = r; H[2] = s; } //----------------------------------------------------------------------------- void FE2DTri3_::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -1; Hs[0] = -1; Hr[1] = 1; Hs[1] = 0; Hr[2] = 0; Hs[2] = 1; } //----------------------------------------------------------------------------- void FE2DTri3_::shape_deriv2(double* Hrr, double* Hrs, double* Hss, double r, double s) { Hrr[0] = 0; Hrs[0] = 0; Hss[0] = 0; Hrr[1] = 0; Hrs[1] = 0; Hss[1] = 0; Hrr[2] = 0; Hrs[2] = 0; Hss[2] = 0; } //============================================================================= // F E 2 D T R I G 1 //============================================================================= //----------------------------------------------------------------------------- FE2DTri3G1::FE2DTri3G1() : FE2DTri3_(NINT, FE2D_TRI3G1) { const double a = 1.0/3.0; gr[0] = a; gs[0] = a; gw[0] = 0.5; init(); } //----------------------------------------------------------------------------- void FE2DTri3G1::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[0]; ao[2] = ai[0]; } //============================================================================ // F E 2 D T R I 6 //============================================================================ //----------------------------------------------------------------------------- void FE2DTri6_::shape(double* H, double r, double s) { double r1 = 1.0 - r - s; double r2 = r; double r3 = s; H[0] = r1*(2.0*r1 - 1.0); H[1] = r2*(2.0*r2 - 1.0); H[2] = r3*(2.0*r3 - 1.0); H[3] = 4.0*r1*r2; H[4] = 4.0*r2*r3; H[5] = 4.0*r3*r1; } //----------------------------------------------------------------------------- void FE2DTri6_::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -3.0 + 4.0*r + 4.0*s; Hr[1] = 4.0*r - 1.0; Hr[2] = 0.0; Hr[3] = 4.0 - 8.0*r - 4.0*s; Hr[4] = 4.0*s; Hr[5] = -4.0*s; Hs[0] = -3.0 + 4.0*s + 4.0*r; Hs[1] = 0.0; Hs[2] = 4.0*s - 1.0; Hs[3] = -4.0*r; Hs[4] = 4.0*r; Hs[5] = 4.0 - 8.0*s - 4.0*r; } //----------------------------------------------------------------------------- void FE2DTri6_::shape_deriv2(double* Hrr, double* Hrs, double* Hss, double r, double s) { Hrr[0] = 4.0; Hrs[0] = 4.0; Hss[0] = 4.0; Hrr[1] = 4.0; Hrs[1] = 0.0; Hss[1] = 0.0; Hrr[2] = 0.0; Hrs[2] = 0.0; Hss[2] = 4.0; Hrr[3] = -8.0; Hrs[3] = -4.0; Hss[3] = 0.0; Hrr[4] = 0.0; Hrs[4] = 4.0; Hss[4] = 0.0; Hrr[5] = 0.0; Hrs[5] = -4.0; Hss[5] = -8.0; } //============================================================================= // F E 2 D T R I 6 G 3 //============================================================================= FE2DTri6G3::FE2DTri6G3() : FE2DTri6_(NINT, FE2D_TRI6G3) { const double a = 1.0 / 6.0; const double b = 2.0 / 3.0; gr[0] = a; gs[0] = a; gw[0] = a; gr[1] = b; gs[1] = a; gw[1] = a; gr[2] = a; gs[2] = b; gw[2] = a; init(); } //----------------------------------------------------------------------------- void FE2DTri6G3::project_to_nodes(double* ai, double* ao) const { matrix H(3, 3); for (int n=0; n<3; ++n) { H[n][0] = 1.0 - gr[n] - gs[n]; H[n][1] = gr[n]; H[n][2] = gs[n]; } H.inverse(); for (int i=0; i<3; ++i) { ao[i] = 0; for (int j=0; j<3; ++j) ao[i] += H[i][j]*ai[j]; } ao[3] = 0.5*(ao[0] + ao[1]); ao[4] = 0.5*(ao[1] + ao[2]); ao[5] = 0.5*(ao[2] + ao[0]); } //============================================================================= // F E 2 D Q U A D 4 //============================================================================= //----------------------------------------------------------------------------- void FE2DQuad4_::shape(double* H, double r, double s) { H[0] = 0.25*(1-r)*(1-s); H[1] = 0.25*(1+r)*(1-s); H[2] = 0.25*(1+r)*(1+s); H[3] = 0.25*(1-r)*(1+s); } //----------------------------------------------------------------------------- void FE2DQuad4_::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -0.25*(1-s); Hs[0] = -0.25*(1-r); Hr[1] = 0.25*(1-s); Hs[1] = -0.25*(1+r); Hr[2] = 0.25*(1+s); Hs[2] = 0.25*(1+r); Hr[3] = -0.25*(1+s); Hs[3] = 0.25*(1-r); } //----------------------------------------------------------------------------- void FE2DQuad4_::shape_deriv2(double* Hrr, double* Hrs, double* Hss, double r, double s) { Hrr[0] = 0; Hrs[0] = 0.25; Hss[0] = 0; Hrr[1] = 0; Hrs[1] = -0.25; Hss[1] = 0; Hrr[2] = 0; Hrs[2] = 0.25; Hss[2] = 0; Hrr[3] = 0; Hrs[3] = -0.25; Hss[3] = 0; } //============================================================================= // F E 2 D Q U A D G 4 //============================================================================= FE2DQuad4G4::FE2DQuad4G4() : FE2DQuad4_(NINT, FE2D_QUAD4G4) { const double a = 1.0 / sqrt(3.0); gr[0] = -a; gs[0] = -a; gw[0] = 1; gr[1] = a; gs[1] = -a; gw[1] = 1; gr[2] = a; gs[2] = a; gw[2] = 1; gr[3] = -a; gs[3] = a; gw[3] = 1; init(); m_Hi = m_H.inverse(); } //----------------------------------------------------------------------------- void FE2DQuad4G4::project_to_nodes(double* ai, double* ao) const { int ni = NINT; int ne = NELN; assert(ni == ne); for (int i=0; i<ne; ++i) { ao[i] = 0; for (int j=0; j<ni; ++j) ao[i] += m_Hi[i][j]*ai[j]; } } //============================================================================= // F E 2 D Q U A D 8 //============================================================================= //----------------------------------------------------------------------------- // shape function at (r,s) void FE2DQuad8_::shape(double* H, double r, double s) { H[4] = 0.5*(1 - r*r)*(1 - s); H[5] = 0.5*(1 - s*s)*(1 + r); H[6] = 0.5*(1 - r*r)*(1 + s); H[7] = 0.5*(1 - s*s)*(1 - r); H[0] = 0.25*(1 - r)*(1 - s) - 0.5*(H[4] + H[7]); H[1] = 0.25*(1 + r)*(1 - s) - 0.5*(H[4] + H[5]); H[2] = 0.25*(1 + r)*(1 + s) - 0.5*(H[5] + H[6]); H[3] = 0.25*(1 - r)*(1 + s) - 0.5*(H[6] + H[7]); } //----------------------------------------------------------------------------- // shape function derivatives at (r,s) void FE2DQuad8_::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[4] = -r*(1 - s); Hr[5] = 0.5*(1 - s*s); Hr[6] = -r*(1 + s); Hr[7] = -0.5*(1 - s*s); Hr[0] = -0.25*(1 - s) - 0.5*(Hr[4] + Hr[7]); Hr[1] = 0.25*(1 - s) - 0.5*(Hr[4] + Hr[5]); Hr[2] = 0.25*(1 + s) - 0.5*(Hr[5] + Hr[6]); Hr[3] = -0.25*(1 + s) - 0.5*(Hr[6] + Hr[7]); Hs[4] = -0.5*(1 - r*r); Hs[5] = -s*(1 + r); Hs[6] = 0.5*(1 - r*r); Hs[7] = -s*(1 - r); Hs[0] = -0.25*(1 - r) - 0.5*(Hs[4] + Hs[7]); Hs[1] = -0.25*(1 + r) - 0.5*(Hs[4] + Hs[5]); Hs[2] = 0.25*(1 + r) - 0.5*(Hs[5] + Hs[6]); Hs[3] = 0.25*(1 - r) - 0.5*(Hs[6] + Hs[7]); } //----------------------------------------------------------------------------- //! shape function derivatives at (r,s) void FE2DQuad8_::shape_deriv2(double* Hrr, double* Hrs, double* Hss, double r, double s) { Hrr[4] = -(1 - s); Hrr[5] = 0.0; Hrr[6] = -(1 + s); Hrr[7] = 0.0; Hrs[4] = r; Hrs[5] = -s; Hrs[6] = -r; Hrs[7] = s; Hss[4] = 0.0; Hss[5] = -(1 + r); Hss[6] = 0.0; Hss[7] = -(1 - r); Hrr[0] = - 0.5*(Hrr[4] + Hrr[7]); Hrr[1] = - 0.5*(Hrr[4] + Hrr[5]); Hrr[2] = - 0.5*(Hrr[5] + Hrr[6]); Hrr[3] = - 0.5*(Hrr[6] + Hrr[7]); Hrs[0] = 0.25 - 0.5*(Hrs[4] + Hrs[7]); Hrs[1] = -0.25 - 0.5*(Hrs[4] + Hrs[5]); Hrs[2] = 0.25 - 0.5*(Hrs[5] + Hrs[6]); Hrs[3] = -0.25 - 0.5*(Hrs[6] + Hrs[7]); Hss[0] = - 0.5*(Hss[4] + Hss[7]); Hss[1] = - 0.5*(Hss[4] + Hss[5]); Hss[2] = - 0.5*(Hss[5] + Hss[6]); Hss[3] = - 0.5*(Hss[6] + Hss[7]); } //============================================================================= // F E 2 D Q U A D 8 G 9 //============================================================================= FE2DQuad8G9::FE2DQuad8G9() : FE2DQuad8_(NINT, FE2D_QUAD8G9) { // integration point coordinates const double a = sqrt(0.6); const double w1 = 25.0/81.0; const double w2 = 40.0/81.0; const double w3 = 64.0/81.0; gr[ 0] = -a; gs[ 0] = -a; gw[ 0] = w1; gr[ 1] = 0; gs[ 1] = -a; gw[ 1] = w2; gr[ 2] = a; gs[ 2] = -a; gw[ 2] = w1; gr[ 3] = -a; gs[ 3] = 0; gw[ 3] = w2; gr[ 4] = 0; gs[ 4] = 0; gw[ 4] = w3; gr[ 5] = a; gs[ 5] = 0; gw[ 5] = w2; gr[ 6] = -a; gs[ 6] = a; gw[ 6] = w1; gr[ 7] = 0; gs[ 7] = a; gw[ 7] = w2; gr[ 8] = a; gs[ 8] = a; gw[ 8] = w1; init(); // we need Ai to project integration point data to the nodes matrix A(NELN,NELN); m_Ai.resize(NELN,NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FE2DQuad8G9::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i=0; i<NELN; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += m_H[j][i]*ai[j]; } for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NELN; ++j) ao[i] += m_Ai[i][j]*b[j]; } } //============================================================================= // F E 2 D Q U A D 9 //============================================================================= //----------------------------------------------------------------------------- // shape function at (r,s) void FE2DQuad9_::shape(double* H, double r, double s) { double R[3] = {0.5*r*(r-1.0), 0.5*r*(r+1.0), 1.0 - r*r}; double S[3] = {0.5*s*(s-1.0), 0.5*s*(s+1.0), 1.0 - s*s}; H[0] = R[0]*S[0]; H[1] = R[1]*S[0]; H[2] = R[1]*S[1]; H[3] = R[0]*S[1]; H[4] = R[2]*S[0]; H[5] = R[1]*S[2]; H[6] = R[2]*S[1]; H[7] = R[0]*S[2]; H[8] = R[2]*S[2]; } //----------------------------------------------------------------------------- // shape function derivatives at (r,s) void FE2DQuad9_::shape_deriv(double* Hr, double* Hs, double r, double s) { double R[3] = {0.5*r*(r-1.0), 0.5*r*(r+1.0), 1.0 - r*r}; double S[3] = {0.5*s*(s-1.0), 0.5*s*(s+1.0), 1.0 - s*s}; double DR[3] = {r-0.5, r+0.5, -2.0*r}; double DS[3] = {s-0.5, s+0.5, -2.0*s}; Hr[0] = DR[0]*S[0]; Hr[1] = DR[1]*S[0]; Hr[2] = DR[1]*S[1]; Hr[3] = DR[0]*S[1]; Hr[4] = DR[2]*S[0]; Hr[5] = DR[1]*S[2]; Hr[6] = DR[2]*S[1]; Hr[7] = DR[0]*S[2]; Hr[8] = DR[2]*S[2]; Hs[0] = R[0]*DS[0]; Hs[1] = R[1]*DS[0]; Hs[2] = R[1]*DS[1]; Hs[3] = R[0]*DS[1]; Hs[4] = R[2]*DS[0]; Hs[5] = R[1]*DS[2]; Hs[6] = R[2]*DS[1]; Hs[7] = R[0]*DS[2]; Hs[8] = R[2]*DS[2]; } //----------------------------------------------------------------------------- //! shape function derivatives at (r,s) void FE2DQuad9_::shape_deriv2(double* Grr, double* Grs, double* Gss, double r, double s) { double R[3] = {0.5*r*(r-1.0), 0.5*r*(r+1.0), 1.0 - r*r}; double S[3] = {0.5*s*(s-1.0), 0.5*s*(s+1.0), 1.0 - s*s}; double DR[3] = {r-0.5, r+0.5, -2.0*r}; double DS[3] = {s-0.5, s+0.5, -2.0*s}; double DDR[3] = {1.0, 1.0, -2.0}; double DDS[3] = {1.0, 1.0, -2.0}; Grr[0] = DDR[0]*S[0]; Grs[0] = DR[0]*DS[0]; Gss[0] = R[0]*DDS[0]; Grr[1] = DDR[1]*S[0]; Grs[1] = DR[1]*DS[0]; Gss[1] = R[1]*DDS[0]; Grr[2] = DDR[1]*S[1]; Grs[2] = DR[1]*DS[1]; Gss[2] = R[1]*DDS[1]; Grr[3] = DDR[0]*S[1]; Grs[3] = DR[0]*DS[1]; Gss[3] = R[0]*DDS[1]; Grr[4] = DDR[2]*S[0]; Grs[4] = DR[2]*DS[0]; Gss[4] = R[2]*DDS[0]; Grr[5] = DDR[1]*S[2]; Grs[5] = DR[1]*DS[2]; Gss[5] = R[1]*DDS[2]; Grr[6] = DDR[2]*S[1]; Grs[6] = DR[2]*DS[1]; Gss[6] = R[2]*DDS[1]; Grr[7] = DDR[0]*S[2]; Grs[7] = DR[0]*DS[2]; Gss[7] = R[0]*DDS[2]; Grr[8] = DDR[2]*S[2]; Grs[8] = DR[2]*DS[2]; Gss[8] = R[2]*DDS[2]; } //============================================================================= // F E 2 D Q U A D 9 G 9 //============================================================================= FE2DQuad9G9::FE2DQuad9G9() : FE2DQuad9_(NINT, FE2D_QUAD9G9) { // integration point coordinates const double a = sqrt(0.6); const double w1 = 25.0/81.0; const double w2 = 40.0/81.0; const double w3 = 64.0/81.0; gr[ 0] = -a; gs[ 0] = -a; gw[ 0] = w1; gr[ 1] = 0; gs[ 1] = -a; gw[ 1] = w2; gr[ 2] = a; gs[ 2] = -a; gw[ 2] = w1; gr[ 3] = -a; gs[ 3] = 0; gw[ 3] = w2; gr[ 4] = 0; gs[ 4] = 0; gw[ 4] = w3; gr[ 5] = a; gs[ 5] = 0; gw[ 5] = w2; gr[ 6] = -a; gs[ 6] = a; gw[ 6] = w1; gr[ 7] = 0; gs[ 7] = a; gw[ 7] = w2; gr[ 8] = a; gs[ 8] = a; gw[ 8] = w1; init(); // we need Ai to project integration point data to the nodes matrix A(NELN,NELN); m_Ai.resize(NELN,NELN); A = m_H.transpose()*m_H; m_Ai = A.inverse(); } //----------------------------------------------------------------------------- void FE2DQuad9G9::project_to_nodes(double* ai, double* ao) const { vector<double> b(NELN); for (int i=0; i<NELN; ++i) { b[i] = 0; for (int j=0; j<NINT; ++j) b[i] += m_H[j][i]*ai[j]; } for (int i=0; i<NELN; ++i) { ao[i] = 0; for (int j=0; j<NELN; ++j) ao[i] += m_Ai[i][j]*b[j]; } } //============================================================================= // // L I N E E L E M E N T S // //============================================================================= FELineElementTraits::FELineElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et) : FEElementTraits(ni, ne, FE_ELEM_EDGE, es, et) { gr.resize(ni); gw.resize(ni); Gr.resize(ni, ne); Grr.resize(ni, ne); } //----------------------------------------------------------------------------- void FELineElementTraits::init() { assert(m_nint > 0); assert(m_neln > 0); // evaluate shape functions const int NE = FEElement::MAX_NODES; double N[NE]; for (int n=0; n<m_nint; ++n) { shape(N, gr[n]); for (int i=0; i<m_neln; ++i) m_H[n][i] = N[i]; } // evaluate shape function derivatives double Nr[NE]; for (int n=0; n<m_nint; ++n) { shape_deriv(Nr, gr[n]); for (int i=0; i<m_neln; ++i) { Gr[n][i] = Nr[i]; } } } //============================================================================= // FELine2_ //============================================================================= //----------------------------------------------------------------------------- void FELine2_::shape(double* H, double r) { H[0] = 0.5*(1.0 - r); H[1] = 0.5*(1.0 + r); } //----------------------------------------------------------------------------- void FELine2_::shape_deriv(double* Hr, double r) { Hr[0] = -0.5; Hr[1] = 0.5; } //----------------------------------------------------------------------------- void FELine2_::shape_deriv2(double* Hrr, double r) { Hrr[0] = 0; Hrr[1] = 0; } //============================================================================= // FELine2G1 //============================================================================= //----------------------------------------------------------------------------- FELine2G1::FELine2G1() : FELine2_(NINT, FE_LINE2G1) { gr[0] = 0.0; gw[0] = 2.0; init(); } //----------------------------------------------------------------------------- void FELine2G1::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[0]; } //============================================================================= // FELine2NI //============================================================================= //----------------------------------------------------------------------------- FELine2NI::FELine2NI() : FELine2_(NINT, FE_LINE2NI) { gr[0] = -1; gr[1] = 1; gw[0] = gw[1] = 1.0; init(); } //----------------------------------------------------------------------------- void FELine2NI::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[1]; } //============================================================================= // // B E A M E L E M E N T S // //============================================================================= FEBeamElementTraits::FEBeamElementTraits(int ni, int ne, FE_Element_Shape es, FE_Element_Type et) : FEElementTraits(ni, ne, FE_ELEM_EDGE, es, et) { gr.resize(ni); gw.resize(ni); Gr.resize(ni, ne); Grr.resize(ni, ne); } //----------------------------------------------------------------------------- void FEBeamElementTraits::init() { assert(m_nint > 0); assert(m_neln > 0); // evaluate shape functions const int NE = FEElement::MAX_NODES; double N[NE]; for (int n = 0; n < m_nint; ++n) { shape(N, gr[n]); for (int i = 0; i < m_neln; ++i) m_H[n][i] = N[i]; } // evaluate shape function derivatives double Nr[NE]; for (int n = 0; n < m_nint; ++n) { shape_deriv(Nr, gr[n]); for (int i = 0; i < m_neln; ++i) { Gr[n][i] = Nr[i]; } } } //============================================================================= // FEBeam2_ //============================================================================= //----------------------------------------------------------------------------- void FEBeam2_::shape(double* H, double r) { H[0] = 0.5 * (1.0 - r); H[1] = 0.5 * (1.0 + r); } //----------------------------------------------------------------------------- void FEBeam2_::shape_deriv(double* Hr, double r) { Hr[0] = -0.5; Hr[1] = 0.5; } //----------------------------------------------------------------------------- void FEBeam2_::shape_deriv2(double* Hrr, double r) { Hrr[0] = 0; Hrr[1] = 0; } //============================================================================= // FEBeam2G1 //============================================================================= //----------------------------------------------------------------------------- FEBeam2G1::FEBeam2G1() : FEBeam2_(NINT, FE_BEAM2G1) { gr[0] = 0.0; gw[0] = 2.0; init(); } //----------------------------------------------------------------------------- void FEBeam2G1::project_to_nodes(double* ai, double* ao) const { ao[0] = ai[0]; ao[1] = ai[0]; } //============================================================================= // FEBeam2G2 //============================================================================= //----------------------------------------------------------------------------- FEBeam2G2::FEBeam2G2() : FEBeam2_(NINT, FE_BEAM2G2) { const double a = 1.0 / sqrt(3.0); gr[0] = -a; gw[0] = 1.0; gr[1] = a; gw[1] = 1.0; init(); } //----------------------------------------------------------------------------- void FEBeam2G2::project_to_nodes(double* ai, double* ao) const { // TODO: implement better! ao[0] = ai[0]; ao[1] = ai[1]; } //============================================================================= // FEBeam3_ //============================================================================= //----------------------------------------------------------------------------- void FEBeam3_::shape(double* H, double r) { H[0] = 0.5 * r * (r - 1.0); H[1] = 0.5 * r * (r + 1.0); H[2] = 1.0 - r*r; } //----------------------------------------------------------------------------- void FEBeam3_::shape_deriv(double* Hr, double r) { Hr[0] = 0.5 * (2.0*r - 1.0); Hr[1] = 0.5 * (2.0*r + 1.0); Hr[2] = -2.0*r; } //----------------------------------------------------------------------------- void FEBeam3_::shape_deriv2(double* Hrr, double r) { Hrr[0] = 1.0; Hrr[1] = 1.0; Hrr[2] = -2.0; } //============================================================================= // FEBeam3G2 //============================================================================= //----------------------------------------------------------------------------- FEBeam3G2::FEBeam3G2() : FEBeam3_(NINT, FE_BEAM3G2) { const double a = 1.0/sqrt(3.0); gr[0] = -a; gw[0] = 1.0; gr[1] = a; gw[1] = 1.0; init(); } //----------------------------------------------------------------------------- void FEBeam3G2::project_to_nodes(double* ai, double* ao) const { // TODO: implement this better assert(false); ao[0] = ai[0]; ao[1] = ai[1]; ao[2] = 0.5*(ai[0] + ai[1]); }
C++
3D
febiosoftware/FEBio
FECore/mat6d.h
.h
4,704
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 //----------------------------------------------------------------------------- // Class describing a symmetric 6x6 matrix. // Only the upper triangular matrix is stored in column major order // / 0 1 3 6 10 15 \ // | 2 4 7 11 16 | // | 5 8 12 17 | // A = | 9 13 18 | // | 14 19 | // \ 20 / class mat6ds { public: enum { NNZ = 21 }; public: mat6ds() {} //! operators mat6ds& operator *= (double g); public: // access operators double& operator () (int i, int j); const double& operator () (int i, int j) const; public: //! initialize to zero void zero(); private: double d[NNZ]; }; //----------------------------------------------------------------------------- // Class describing a 6x6 matrix class mat6d { public: //! default constructor mat6d() {} //! operators mat6d& operator *= (double g); public: // access operator double* operator [] (int i) { return d[i]; } public: //! initialize to zero void zero(); private: double d[6][6]; //!< matrix data }; //----------------------------------------------------------------------------- inline double& mat6ds::operator()(int i, int j) { const int n[] = {0, 1, 3, 6, 10, 15}; return (i<=j? d[n[j]+i] : d[n[i]+j]); } //----------------------------------------------------------------------------- inline const double& mat6ds::operator()(int i, int j) const { const int n[] = {0, 1, 3, 6, 10, 15}; return (i<=j? d[n[j]+i] : d[n[i]+j]); } //----------------------------------------------------------------------------- inline mat6ds& mat6ds::operator *= (double g) { d[ 0] *= g; d[ 1] *= g; d[ 2] *= g; d[ 3] *= g; d[ 4] *= g; d[ 5] *= g; d[ 6] *= g; d[ 7] *= g; d[ 8] *= g; d[ 9] *= g; d[10] *= g; d[11] *= g; d[12] *= g; d[13] *= g; d[14] *= g; d[15] *= g; d[16] *= g; d[17] *= g; d[18] *= g; d[19] *= g; d[20] *= g; return *this; } //----------------------------------------------------------------------------- inline void mat6ds::zero() { d[ 0] = d[ 1] = d[ 2] = d[ 3] = d[ 4] = d[ 5] = 0.0; d[ 6] = d[ 7] = d[ 8] = d[ 9] = d[10] = 0.0; d[11] = d[12] = d[13] = d[14] = 0.0; d[15] = d[16] = d[17] = 0.0; d[18] = d[19] = 0.0; d[20] = 0.0; } //----------------------------------------------------------------------------- inline void mat6d::zero() { d[0][0] = d[0][1] = d[0][2] = d[0][3] = d[0][4] = d[0][5] = 0.0; d[1][0] = d[1][1] = d[1][2] = d[1][3] = d[1][4] = d[1][5] = 0.0; d[2][0] = d[2][1] = d[2][2] = d[2][3] = d[2][4] = d[2][5] = 0.0; d[3][0] = d[3][1] = d[3][2] = d[3][3] = d[3][4] = d[3][5] = 0.0; d[4][0] = d[4][1] = d[4][2] = d[4][3] = d[4][4] = d[4][5] = 0.0; d[5][0] = d[5][1] = d[5][2] = d[5][3] = d[5][4] = d[5][5] = 0.0; } //----------------------------------------------------------------------------- mat6d& mat6d::operator *= (double g) { d[0][0] *= g; d[0][1] *= g; d[0][2] *= g; d[0][3] *= g; d[0][4] *= g; d[0][5] *= g; d[1][0] *= g; d[1][1] *= g; d[1][2] *= g; d[1][3] *= g; d[1][4] *= g; d[1][5] *= g; d[2][0] *= g; d[2][1] *= g; d[2][2] *= g; d[2][3] *= g; d[2][4] *= g; d[2][5] *= g; d[3][0] *= g; d[3][1] *= g; d[3][2] *= g; d[3][3] *= g; d[3][4] *= g; d[3][5] *= g; d[4][0] *= g; d[4][1] *= g; d[4][2] *= g; d[4][3] *= g; d[4][4] *= g; d[4][5] *= g; d[5][0] *= g; d[5][1] *= g; d[5][2] *= g; d[5][3] *= g; d[5][4] *= g; d[5][5] *= g; return *this; }
Unknown
3D
febiosoftware/FEBio
FECore/MItem.cpp
.cpp
36,836
1,302
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "MItem.h" #include "MMatrix.h" #include "MEvaluate.h" #include "MMath.h" using namespace std; #ifndef PI #define PI 3.141592653589793 #endif //----------------------------------------------------------------------------- // Some special constants MITEM MPi (new MNamedCt(PI , "pi")); MITEM ME (new MNamedCt(exp(1.0), "e" )); MITEM MINF(new MNamedCt(1e308 , "_inf_")); //----------------------------------------------------------------------------- MItem* MFuncND::copy() const { return new MFuncND(m_pf, m_name, GetSequence()); } //----------------------------------------------------------------------------- MSequence::MSequence(const MSequence& s) : MItem(MSEQUENCE) { int N = s.size(); for (int i=0; i<N; ++i) add(s[i]->copy()); } //----------------------------------------------------------------------------- MSequence::~MSequence() { int M = size(); for (int i=0; i<M; ++i) delete m_item[i]; m_item.clear(); } //----------------------------------------------------------------------------- void MSequence::remove(int i) { delete m_item[i]; m_item.erase(m_item.begin()+i); } //----------------------------------------------------------------------------- void MSequence::replace(int i, MItem* pi) { delete m_item[i]; m_item[i] = pi; } //----------------------------------------------------------------------------- MSequence& MSequence::operator = (MSequence& s) { int M = size(); for (int i=0; i<M; ++i) delete m_item[i]; m_item.clear(); int N = s.size(); for (int i=0; i<N; ++i) add(s[i]->copy()); return (*this); } //----------------------------------------------------------------------------- MITEM Fraction(double n, double d) { double s = (n*d<0?-1:1); n = fabs(n); d = fabs(d); if ((n - floor(n) == 0) && (d - floor(d) == 0)) { if (d != 0.0) { if (n==0) return 0.0; double f = n/d; if (f - floor(f) == 0) { MITEM c(f); if (s<0) return -c; else return c; } double c = (double) gcf((long) n, (long) d); n /= c; d /= c; } } /* else if (d - floor(d) == 0.0) { double v = n / d; return v; } */ if (d == 1.0) return (s*n); MITEM r = new MFraction(n, d); if (s<0) return -r; else return r; } //============================================================================= // N E G A T I O N ( - ) //============================================================================= //----------------------------------------------------------------------------- MITEM operator - (const MITEM& l) { // get the Item pointer const MItem* pi = l.ItemPtr(); // remove unnecessary negative signs int n = 0; while (is_neg(pi)) { pi = mneg(pi)->Item(); n = (n+1)%2; } // -(a-b) = b-a if (is_sub(pi)) { const MItem* pl = msub(pi)->LeftItem (); const MItem* pr = msub(pi)->RightItem(); if (!is_neg(pl) && !is_neg(pr)) { MITEM a = pl->copy(); MITEM b = pr->copy(); return (b - a); } } // remove negative from zero if (is_zero(pi)) return 0.0; // return the negative of a copy of pi MItem* pret = pi->copy(); if (n==0) pret = new MNeg(pret); return pret; } //----------------------------------------------------------------------------- //============================================================================= // A D D I T I O N ( + ) //============================================================================= //----------------------------------------------------------------------------- MITEM operator + (const MITEM& l, const MITEM& r) { if (is_matrix(l) || is_matrix(r)) { if (is_matrix(l) && is_matrix(r)) { const MMatrix& A = *mmatrix(l); const MMatrix& B = *mmatrix(r); return A+B; } // else throw InvalidOperation(); } if (isConst(l)) return (r + l.value()); if (isConst(r)) return (l + r.value()); if (is_neg (r)) return (l - (-r)); // a+(-b) = a - b if (is_neg (l)) return (r - (-l)); // ((-a)+b) = b - a if (is_frac(l) && is_frac(r)) { FRACTION a = mfrac(l)->fraction(); FRACTION b = mfrac(r)->fraction(); return Fraction(a + b); } return new MAdd(l.copy(), r.copy()); } //----------------------------------------------------------------------------- MITEM operator + (const MITEM& l, double r) { if (is_matrix(l)) throw InvalidOperation(); if (r==0) return l; if (isConst(l)) return (l.value() + r); if (is_neg (l)) return (r - l.Item()); if (is_frac (l)) { FRACTION a = mfrac(l)->fraction(); return Fraction(a + r); } return new MAdd(l.copy(), r); } //----------------------------------------------------------------------------- MITEM operator + (double l, const MITEM& r) { if (is_matrix(r)) throw InvalidOperation(); if (l==0) return r; if (isConst(r)) return (l + r.value()); if (is_neg (r)) return (l - r.Item()); if (is_frac (r)) { FRACTION a = mfrac(r)->fraction(); return Fraction(a + l); } return new MAdd(r.copy(), l); } //============================================================================= // S U B T R A C T I O N ( - ) //============================================================================= //----------------------------------------------------------------------------- MITEM operator - (const MITEM& l, const MITEM& r) { if (is_matrix(l) || is_matrix(r)) { if (is_matrix(l) && is_matrix(r)) { const MMatrix& A = *mmatrix(l); const MMatrix& B = *mmatrix(r); return A-B; } // else throw InvalidOperation(); } if (isConst(l)) return (l.value() - r); if (isConst(r)) return (l - r.value()); if (is_neg(l) && is_neg(r)) return (-r)-(-l); // (-a)-(-b) = b - a; if (is_neg(r)) return (l+(-r)); if (is_neg(l)) return -((-l)+r); if (is_frac(l) && is_frac(r)) { FRACTION a = mfrac(l)->fraction(); FRACTION b = mfrac(r)->fraction(); return Fraction(a - b); } return new MSub(l.copy(), r.copy()); } //----------------------------------------------------------------------------- MITEM operator - (double l, const MITEM& r) { if (is_matrix(r)) throw InvalidOperation(); if (l==0) return -r; if (isConst(r)) return (l - r.value()); if (is_neg (r)) return (-r) + l; if (is_frac (r)) { FRACTION a = mfrac(r)->fraction(); return Fraction(l - a); } return new MSub(l, r.copy()); } //----------------------------------------------------------------------------- MITEM operator - (const MITEM& l, double r) { if (is_matrix(l)) throw InvalidOperation(); if (r == 0) return l; if (isConst(l)) return (l.value() - r); if (is_neg (l)) return -((-l) + r); if (is_frac (l)) { FRACTION a = mfrac(l)->fraction(); return Fraction(a - r); } else return new MSub(l.copy(), r); } //============================================================================= // M U L T I P L I C A T I O N ( * ) //============================================================================= //----------------------------------------------------------------------------- MITEM operator * (const MITEM& l, const MITEM& r) { if (is_matrix(l) && ::is_scalar(r)) { const MMatrix& A = *mmatrix(l); return A*r; } if (is_matrix(r) && ::is_scalar(l)) { const MMatrix& A = *mmatrix(r); return A*l; } if (isConst(l)) return (l.value() * r); if (isConst(r)) return (r.value() * l); if (is_neg(l) && is_neg(r)) return ((-l)*(-r)); if (is_neg(l)) return -((-l)*r); if (is_neg(r)) return -(l*(-r)); if (is_frac(l) && is_frac(r)) { FRACTION a = mfrac(l)->fraction(); FRACTION b = mfrac(r)->fraction(); return Fraction(a*b); } if (is_frac(l)) { FRACTION a = mfrac(l)->fraction(); return (a.n*r)/a.d; } if (is_frac(r)) { FRACTION a = mfrac(r)->fraction(); return (a.n*l)/a.d; } if (is_div(l) && (is_matrix(r) == false)) { MITEM l1 = l.Left(); MITEM l2 = l.Right(); return (l1*r)/l2; } if (is_div(r) && (is_matrix(r) == false)) { MITEM r1 = r.Left(); MITEM r2 = r.Right(); return (l*r1)/r2; } if (is_matrix(l) && is_matrix(r)) { const MMatrix& A = *mmatrix(l); const MMatrix& B = *mmatrix(r); return A*B; } return new MMul(l.copy(), r.copy()); } //----------------------------------------------------------------------------- MITEM operator * (double l, const MITEM& r) { if (l == 0.0) return 0.0; if (l == 1.0) return r; if (isConst(r)) return l*r.value(); if (is_neg (r)) return -(l * (-r)); if (is_frac (r)) { FRACTION a = mfrac(r)->fraction(); return Fraction(l*a); } if (is_div(r)) { MITEM fl = r.Left (); MITEM fr = r.Right(); return (l*fl)/fr; } return new MMul(l, r.copy()); } //============================================================================= // D I V I S I O N ( / ) //============================================================================= MITEM operator / (const MITEM& l, const MITEM& r) { if (r == 0.0) throw DivisionByZero(); if (r == 1.0) return l; if (is_matrix(r)) throw InvalidOperation(); if (is_matrix(l)) { const MMatrix& A = *mmatrix(l); return A/r; } if (isConst(l)) return (l.value() / r); if (isConst(r)) return (l / r.value()); if (is_neg (l)) return -((-l)/r); if (is_neg (r)) return -(l/(-r)); if (is_frac(l) && is_frac(r)) { FRACTION a = mfrac(l)->fraction(); FRACTION b = mfrac(r)->fraction(); return Fraction(a/b); } if (is_div(r)) { MITEM r1 = r.Left(); MITEM r2 = r.Right(); return (l*r2)/r1; } if (is_div(l)) { MITEM l1 = l.Left(); MITEM l2 = l.Right(); return (l1/(l2*r)); } //------------------------------------------------------ return new MDiv(l.copy(), r.copy()); } //----------------------------------------------------------------------------- MITEM operator / (double l, const MITEM& r) { if (is_matrix(r)) throw InvalidOperation(); if ((l==0.0) && (r!=0.0)) return 0.0; if (isConst(r)) return Fraction(l, r.value()); if (is_neg (r)) return -(l/(-r)); if (is_frac (r)) { FRACTION a = mfrac(r)->fraction(); return Fraction(l/a); } if (is_div(r)) { MITEM a = r.Left(); MITEM b = r.Right(); return (l*b)/a; } return new MDiv(l, r.copy()); } //----------------------------------------------------------------------------- MITEM operator / (const MITEM& l, double r) { if (r == 1.0) return l; if (isConst(l)) return Fraction(l.value(), r); if (is_neg (l)) return -((-l)/r); if (is_frac (l)) { FRACTION a = mfrac(l)->fraction(); return Fraction(a/r); } if (is_div(l)) { MITEM a = l.Left(); MITEM b = l.Right(); return (a/(r*b)); } return new MDiv(l.copy(), r); } //============================================================================= // P O W E R ( ^ ) //============================================================================= //----------------------------------------------------------------------------- MITEM operator ^ (const MITEM& l, const MITEM& r) { if (is_matrix(l) || is_matrix(r)) throw InvalidOperation(); if (isConst(r)) return (l ^ r.value()); if (is_neg(r)) { MITEM mr = -r; if (isConst(mr)) return 1/ (l^mr); } if (is_fnc1d(l, "sqrt")) { MITEM a = l.Item(); return (a^(r / 2)); } return new MPow(l.copy(), r.copy()); } //----------------------------------------------------------------------------- MITEM operator ^ (const MITEM& l, double r) { if (is_matrix(l)) throw InvalidOperation(); if (r==1) return l; if (r==0) return 1.0; if (l==1.0) return 1.0; if (isConst(l) && is_int(r)) return pow(l.value(), r); if (is_neg(l) && is_int(r)) { int n = (int) r; if (n%2==0) return (-l)^r; else return -((-l)^r); } if (is_frac(l) && is_int(r)) { FRACTION a = mfrac(l)->fraction(); return Fraction(pow(a.n,r), pow(a.d,r)); } if (is_pow(l)) { MITEM v = l.Left(); MITEM p = l.Right(); return (v^(r*p)); } if (is_mul(l)) { MITEM l1 = l.Left (); MITEM r1 = l.Right(); return ((l1^r)*(r1^r)); } if (is_div(l)) { MITEM l1 = l.Left (); MITEM r1 = l.Right(); return ((l1^r)/(r1^r)); } if (is_fnc1d(l, "sqrt")) { MITEM a = l.Item(); return (a^(Fraction(r, 2))); } return new MPow(l.copy(), r); } //============================================================================= // F U N C T I O N S //============================================================================= //----------------------------------------------------------------------------- // Absolute value MITEM Abs(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); if (is_neg(a)) return Abs(-a); // remove redundant abs const MItem* pi = a.ItemPtr(); while (is_neg(pi) || is_abs(pi)) { pi = munary(pi)->Item(); } if (isConst(pi)) return fabs(mnumber(pi)->value()); if (is_named(pi)) return pi->copy(); // This assumes that all named constants are positive! return new MFunc1D(fabs, "abs", pi->copy()); } //----------------------------------------------------------------------------- // return the sign of the expression MITEM Sgn(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); if (isConst(a)) return 1.0; // this assumes that all constants are positive if (is_neg(a)) return -Sgn(-a); if (is_pow(a)) { const MItem *pr = mpow(a)->RightItem(); if (isConst(pr) && is_int(mnumber(pr)->value())) { MITEM l = a.Left(); int n = (int) mnumber(pr)->value(); if (n%2 == 0) return 1.0; else return Sgn(l); } } return new MFunc1D(sgn, "sgn", a.copy()); } //----------------------------------------------------------------------------- // This function sees if a is a multiple of pi where the multiplier is a fraction // of integers. bool pi_multiple(const MITEM& a, int& num, int& den) { if (a==0.0) { num = 0; den = 1; return true; } if (is_pi(a)) { num = den = 1; return true; } else if (is_mul(a)) { const MItem* pl = mmul(a)->LeftItem(); const MItem* pr = mmul(a)->RightItem(); if (is_pi(pl) && is_int(pr)) { num = (int)mconst(pr)->value(); den = 1; return true; } if (is_pi(pr) && is_int(pl)) { num = (int)mconst(pl)->value(); den = 1; return true; } } else if (is_div(a)) { const MItem* pl = mdiv(a)->LeftItem(); const MItem* pr = mdiv(a)->RightItem(); if (is_pi(pl)&&is_int(pr)) { num = 1; den = (int)mconst(pr)->value(); return true; } if (is_mul(pl)&&is_int(pr)) { den = (int)mconst(pr)->value(); const MItem* pl1 = mmul(pl)->LeftItem(); const MItem* pl2 = mmul(pl)->RightItem(); if (is_pi(pl1) && (is_int(pl2))) { num = (int)mconst(pl2)->value(); return true; } if (is_pi(pl2) && (is_int(pl1))) { num = (int)mconst(pl1)->value(); return true; } } } return false; } //----------------------------------------------------------------------------- MITEM Sin(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); // sin(-x) = -sin(x) if (is_neg(a)) return -Sin(-a); // check for multiples of pi int num, den; if (pi_multiple(a, num, den)) { if (num == 0) return 0.0; if (den == 1) return 0.0; if ((num == 1) && (den == 2)) return 1.0; if ((num == 1) && (den == 3)) return Sqrt(MITEM(3.0))/2.0; if ((num == 1) && (den == 4)) return Sqrt(MITEM(2.0))/2.0; if ((num == 1) && (den == 6)) return 1.0 / MITEM(2.0); if ((num == 1) && (den == 12)) return Sqrt(MITEM(2.0))/4*(Sqrt(MITEM(3.0)) - 1.0); if ((num == 5) && (den == 12)) return Sqrt(MITEM(2.0))/4*(Sqrt(MITEM(3.0)) + 1.0); if ((num == 7) && (den == 12)) return Sqrt(MITEM(2.0))/4*(Sqrt(MITEM(3.0)) + 1.0); if ((num == 2) && (den == 3 )) return Sqrt(MITEM(3.0))/2; if ((num == 3) && (den == 4 )) return Sqrt(MITEM(2.0))/2; if ((num == 5) && (den == 6 )) return 1.0 / MITEM(2.0); if ((num == 11) && (den == 12)) return Sqrt(MITEM(2.0))/4*(Sqrt(MITEM(3.0)) - 1.0); } return new MFunc1D(sin, "sin", a.copy()); } //----------------------------------------------------------------------------- MITEM Cos(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); // cos(-x) = cos(x) if (is_neg(a)) return Cos(-a); // check for multiples of pi int num, den; if (pi_multiple(a, num, den)) { if (num == 0) return 1.0; if (den == 1) return (num%2==0?1.0:-1.0); if ((num == 1) && (den == 2)) return 0.0; if ((num == 1) && (den == 3)) return 1.0 / MITEM(2.0); if ((num == 1) && (den == 4)) return Sqrt(MITEM(2.0))/2.0; if ((num == 1) && (den == 6)) return Sqrt(MITEM(3.0))/2.0; if ((num == 1) && (den == 12)) return Sqrt(MITEM(2.0))/4*(Sqrt(MITEM(3.0)) + 1.0); if ((num == 5) && (den == 12)) return Sqrt(MITEM(2.0))/4*(Sqrt(MITEM(3.0)) - 1.0); if ((num == 7) && (den == 12)) return -Sqrt(MITEM(2.0))/4*(Sqrt(MITEM(3.0)) - 1.0); if ((num == 2) && (den == 3 )) return -1.0 / MITEM(2.0); if ((num == 3) && (den == 4 )) return -Sqrt(MITEM(2.0))/2; if ((num == 5) && (den == 6 )) return -Sqrt(MITEM(3.0))/2; if ((num == 11) && (den == 12)) return -Sqrt(MITEM(2.0))/4*(Sqrt(MITEM(3.0)) + 1.0); } return new MFunc1D(cos, "cos", a.copy()); } //----------------------------------------------------------------------------- MITEM Sec(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); // sec(-x) = sec(x) if (is_neg(a)) return Sec(-a); // check for multiples of pi int num, den; if (pi_multiple(a, num, den)) { if (num == 0) return 1.0; if (den == 1) return (num%2==0?1.0:-1.0); // if ((num == 1) && (den == 2)) return INFINITY; if ((num == 1) && (den == 3)) return 2.0; if ((num == 1) && (den == 4)) return Sqrt(MITEM(2.0)); if ((num == 1) && (den == 6)) return 2.0*Sqrt(MITEM(3.0))/3.0; if ((num == 1) && (den == 12)) return Sqrt(MITEM(2.0))*(Sqrt(MITEM(3.0)) - 1.0); if ((num == 5) && (den == 12)) return Sqrt(MITEM(2.0))*(Sqrt(MITEM(3.0)) + 1.0); if ((num == 7) && (den == 12)) return -Sqrt(MITEM(2.0))*(Sqrt(MITEM(3.0)) + 1.0); if ((num == 2) && (den == 3 )) return -2.0; if ((num == 3) && (den == 4 )) return -Sqrt(MITEM(2.0)); if ((num == 5) && (den == 6 )) return -(2.0*Sqrt(MITEM(3.0))/3); if ((num == 11) && (den == 12)) return -Sqrt(MITEM(2.0))*(Sqrt(MITEM(3.0)) - 1.0); } return new MFunc1D(sec, "sec", a.copy()); } //----------------------------------------------------------------------------- MITEM Csc(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); // csc(-x) = -csc(x) if (is_neg(a)) return -Csc(-a); // check for multiples of pi int num, den; if (pi_multiple(a, num, den)) { // if (num == 0) return INFINITY; // if (den == 1) return INFINITY; if ((num == 1) && (den == 2)) return 1.0; if ((num == 1) && (den == 3)) return 2.0*Sqrt(MITEM(3.0))/3.0; if ((num == 1) && (den == 4)) return Sqrt(MITEM(2.0)); if ((num == 1) && (den == 6)) return 2.0; if ((num == 1) && (den == 12)) return Sqrt(MITEM(2.0))*(Sqrt(MITEM(3.0)) + 1.0); if ((num == 5) && (den == 12)) return Sqrt(MITEM(2.0))*(Sqrt(MITEM(3.0)) - 1.0); if ((num == 7) && (den == 12)) return Sqrt(MITEM(2.0))*(Sqrt(MITEM(3.0)) - 1.0); if ((num == 2) && (den == 3 )) return 2.0*Sqrt(MITEM(3.0))/3.0; if ((num == 3) && (den == 4 )) return Sqrt(MITEM(2.0)); if ((num == 5) && (den == 6 )) return 2.0; if ((num == 11) && (den == 12)) return Sqrt(MITEM(2.0))*(Sqrt(MITEM(3.0)) + 1.0); } return new MFunc1D(csc, "csc", a.copy()); } //----------------------------------------------------------------------------- MITEM Tan(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); // tan(-x) = -tan(x) if (is_neg(a)) return -Tan(-a); // check for multiples of pi int num, den; if (pi_multiple(a, num, den)) { if (num == 0) return 0.0; if (den == 1) return 0.0; // if ((num == 1) && (den == 2)) +/- return INFINITY; if ((num == 1) && (den == 3)) return Sqrt(MITEM(3.0)); if ((num == 1) && (den == 4)) return 1.0; if ((num == 1) && (den == 6)) return Sqrt(MITEM(3.0))/3.0; if ((num == 1) && (den == 12)) return MITEM(2.0) - Sqrt(MITEM(3.0)); if ((num == 5) && (den == 12)) return MITEM(2.0) + Sqrt(MITEM(3.0)); if ((num == 7) && (den == 12)) return -(MITEM(2.0) + Sqrt(MITEM(3.0))); if ((num == 2) && (den == 3 )) return -Sqrt(MITEM(3.0)); if ((num == 3) && (den == 4 )) return -1.0; if ((num == 5) && (den == 6 )) return -Sqrt(MITEM(3.0))/3.0; if ((num == 11) && (den == 12)) return -(MITEM(2.0) - Sqrt(MITEM(3.0))); } return new MFunc1D(tan, "tan", a.copy()); } //----------------------------------------------------------------------------- MITEM Cot(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); // cot(-x) = -cot(x) if (is_neg(a)) return -Cot(-a); // check for multiples of pi int num, den; if (pi_multiple(a, num, den)) { // if (num == 0) return +/- INFINITY; // if (den == 1) return +/- INFINITY; if ((num == 1) && (den == 2)) return 0.0; if ((num == 1) && (den == 3)) return Sqrt(MITEM(3.0))/3.0; if ((num == 1) && (den == 4)) return 1.0; if ((num == 1) && (den == 6)) return Sqrt(MITEM(3.0)); if ((num == 1) && (den == 12)) return MITEM(2.0) + Sqrt(MITEM(3.0)); if ((num == 5) && (den == 12)) return MITEM(2.0) - Sqrt(MITEM(3.0)); if ((num == 7) && (den == 12)) return -(MITEM(2.0) - Sqrt(MITEM(3.0))); if ((num == 2) && (den == 3 )) return -Sqrt(MITEM(3.0))/3.0; if ((num == 3) && (den == 4 )) return -1.0; if ((num == 5) && (den == 6 )) return -Sqrt(MITEM(3.0)); if ((num == 11) && (den == 12)) return -(MITEM(2.0) + Sqrt(MITEM(3.0))); } return new MFunc1D(cot, "cot", a.copy()); } //----------------------------------------------------------------------------- MITEM Atan(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); if (is_neg(a)) return -Atan(-a); if (a == 0.0) return 0.0; if (a == 1.0) return MPi/4.0; return new MFunc1D(atan, "atan", a.copy()); } //----------------------------------------------------------------------------- MITEM Cosh(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); if (l == 0) return 1.0; if (is_neg(l)) return Cosh(-l); return new MFunc1D(cosh, "cosh", l.copy()); } //----------------------------------------------------------------------------- MITEM Sinh(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); if (l == 0) return 0.0; if (is_neg(l)) return -Sinh(-l); return new MFunc1D(sinh, "sinh", l.copy()); } //----------------------------------------------------------------------------- MITEM Exp(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); return ME^a; } //----------------------------------------------------------------------------- // Natural logarithm (base e) MITEM Log(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); if (a==0.0) return -MINF; if (a==1.0) return 0.0; if (is_named(a)) { string sz = mnamed(a)->Name(); if (sz.compare("e") == 0) return 1.0; } if (is_pow(a)) { const MItem* pl = mpow(a)->LeftItem(); const MItem* pr = mpow(a)->RightItem(); if (is_named(pl)) { string sz = mnamed(pl)->Name(); if (sz.compare("e") == 0) { return pr->copy(); } } } return new MFunc1D(log, "ln", a.copy()); } //----------------------------------------------------------------------------- // base 10 log MITEM Log10(const MITEM& a) { if (is_matrix(a)) throw InvalidOperation(); if (isConst(a)) { double w = a.value(); if (w > 0) { double p = log10(w); double pi = (double) ((int) p); if (pi == p) return p; } } return new MFunc1D(log10, "log", a.copy()); } //----------------------------------------------------------------------------- MITEM Sqrt(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); if (l == 1.0) return 1.0; if (is_pow(l)) { MITEM a = l.Left(); MITEM b = l.Right(); return a^(b/2); } if (isConst(l)) { double a = l.value(); double f = sqrt(a); if (is_int(f)) return f; return new MFunc1D(sqrt, "sqrt", l.copy()); } if (is_var(l) || is_named(l)) { return new MFunc1D(sqrt, "sqrt", l.copy()); } return l ^ Fraction(1,2); } //----------------------------------------------------------------------------- MITEM Erf(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); if (l == 0.0) return 0.0; return new MFunc1D(erf, "erf", l.copy()); } //----------------------------------------------------------------------------- MITEM Erfc(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); if (l == 0.0) return 1.0; return new MFunc1D(erfc, "erfc", l.copy()); } //----------------------------------------------------------------------------- MITEM Tn(int n, const MITEM& r) { if (is_matrix(r)) throw InvalidOperation(); if (n >= 0) { if (n == 0) return MITEM(1.0); if (n == 1) return r; return MEvaluate(MExpand(2*r*Tn(n-1,r) - Tn(n-2,r))); } else return new MFunc2D(chebyshev, "Tn", new MConstant((double)n), r.copy()); } //----------------------------------------------------------------------------- MITEM Tn(const MITEM& l, const MITEM& r) { if (is_matrix(l) || is_matrix(r)) throw InvalidOperation(); if (is_int(l) && (l.value() >= 0.0)) return Tn((int) l.value(), r); return new MFunc2D(chebyshev, "Tn", l.copy(), r.copy()); } //----------------------------------------------------------------------------- #ifdef WIN32 MITEM J0(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); if (l == 0.0) return 1.0; return new MFunc1D(_j0, "J0", l.copy()); } #endif //----------------------------------------------------------------------------- #ifdef WIN32 MITEM J1(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); if (l == 0.0) return 0.0; return new MFunc1D(_j1, "J1", l.copy()); } #endif //----------------------------------------------------------------------------- #ifdef WIN32 MITEM Jn(int n, const MITEM& r) { if (is_matrix(r)) throw InvalidOperation(); if (n >= 0) { if (r == 0.0) return ((n == 0)?1.0:0.0); } return new MFunc2D(jn, "Jn", new MConstant((double)n), r.copy()); } #endif //----------------------------------------------------------------------------- #ifdef WIN32 MITEM Jn(const MITEM& l, const MITEM& r) { if (is_matrix(l) || is_matrix(r)) throw InvalidOperation(); if (is_int(l)) return Jn((int)l.value(), r); return new MFunc2D(jn, "Jn", l.copy(), r.copy()); } #endif //----------------------------------------------------------------------------- #ifdef WIN32 MITEM Y0(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); return new MFunc1D(_y0, "Y0", l.copy()); } #endif //----------------------------------------------------------------------------- #ifdef WIN32 MITEM Y1(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); return new MFunc1D(_y1, "Y1", l.copy()); } #endif //----------------------------------------------------------------------------- #ifdef WIN32 MITEM Yn(int n, const MITEM& r) { if (is_matrix(r)) throw InvalidOperation(); return new MFunc2D(yn, "Yn", new MConstant((double)n), r.copy()); } #endif //----------------------------------------------------------------------------- #ifdef WIN32 MITEM Yn(const MITEM& l, const MITEM& r) { if (is_matrix(l) || is_matrix(r)) throw InvalidOperation(); if (is_int(l)) return Yn((int)l.value(), r); return new MFunc2D(yn, "Yn", l.copy(), r.copy()); } #endif //----------------------------------------------------------------------------- MITEM Fac(const MITEM& l) { if (is_matrix(l)) throw InvalidOperation(); if (is_int(l) && (l.value() >= 0)) return fac(l.value()); return new MFunc1D(fac, "fac", l.copy()); } //----------------------------------------------------------------------------- MITEM Binomial(const MITEM& l, const MITEM& r) { if (is_matrix(l) || is_matrix(r)) throw InvalidOperation(); if (is_rconst(l.ItemPtr()) && is_rconst(r.ItemPtr())) return binomial(l.value(), r.value()); return new MFunc2D(binomial, "binomial", l.copy(), r.copy()); } //----------------------------------------------------------------------------- MITEM Identity(const MITEM& n) { if (is_int(n)) { int m = (int) n.value(); if (m <= 0) throw InvalidOperation(); return matrix_identity(m); } else throw InvalidOperation(); } //----------------------------------------------------------------------------- MITEM Float(const MITEM& a) { if (is_rconst(a.ItemPtr())) { if (is_number(a.ItemPtr())) return a.value(); if (is_neg(a)) return -Float(-a); if (is_add(a)) return Float(a.Left()).value() + Float(a.Right()).value(); if (is_sub(a)) return Float(a.Left()).value() - Float(a.Right()).value(); if (is_mul(a)) return Float(a.Left()).value() * Float(a.Right()).value(); if (is_div(a)) return Float(a.Left()).value() / Float(a.Right()).value(); if (is_pow(a)) { if (is_neg(mpow(a)->RightItem())) return pow(Float(a.Left()).value(), -(Float(-(a.Right())).value())); else return pow(Float(a.Left()).value(), Float(a.Right()).value()); } if (is_func1d(a)) { FUNCPTR pf = mfnc1d(a)->funcptr(); MITEM v(mfnc1d(a)->Item()->copy()); return pf(Float(v).value()); } return a.value(); } return a; } //----------------------------------------------------------------------------- bool is_equal(const MItem* pl, const MItem* pr) { if ((pl == 0)&&(pr == 0)) return true; if ((pl == 0)||(pr == 0)) return false; Item_Type t = pl->Type(); if (t != pr->Type()) return false; switch (t) { case MCONST: case MFRAC: case MNAMED: return (mnumber(pl)->value() == mnumber(pr)->value()); case MVAR: { const string& vl = mvar(pl)->Name(); const string& vr = mvar(pr)->Name(); return (vl.compare(vr) == 0); } case MNEG: { const MItem* pa = munary(pl)->Item(); const MItem* pb = munary(pr)->Item(); return is_equal(pa, pb); } case MADD: { const MItem* pl1 = mbinary(pl)->LeftItem(), *pr1 = mbinary(pl)->RightItem(); const MItem* pl2 = mbinary(pr)->LeftItem(), *pr2 = mbinary(pr)->RightItem(); // TODO: since this only looks one level deep, this may not always return the correct answer return ((is_equal(pl1, pl2) && is_equal(pr1, pr2)) || (is_equal(pl1, pr2) && is_equal(pr1, pl2))); } case MMUL: { MITEM l(pl->copy()); MITEM r(pr->copy()); MProduct a(l), b(r); return (a==b); } case MSUB: case MDIV: case MPOW: { const MItem* pl1 = mbinary(pl)->LeftItem(), *pr1 = mbinary(pl)->RightItem(); const MItem* pl2 = mbinary(pr)->LeftItem(), *pr2 = mbinary(pr)->RightItem(); return (is_equal(pl1, pl2) && is_equal(pr1, pr2)); } case MF1D: { if (mfnc1d(pl)->funcptr() == mfnc1d(pr)->funcptr()) { const MItem* pa = munary(pl)->Item(); const MItem* pb = munary(pr)->Item(); return is_equal(pa, pb); } else return false; } case MSFNC: { const string& vl = msfncnd(pl)->Name(); const string& vr = msfncnd(pr)->Name(); if (vl.compare(vr) != 0) return false; const MItem* pa = msfncnd(pl)->Value(); const MItem* pb = msfncnd(pr)->Value(); return is_equal(pa, pb); } } return false; } //----------------------------------------------------------------------------- // See if the expression is constant. That is, there are no variables in // this expression. bool is_rconst(const MItem* pi) { if (is_var(pi)) return false; if (isConst(pi) || is_named(pi) || is_frac(pi)) return true; if (is_unary(pi)) return is_rconst(munary(pi)->Item()); if (is_binary(pi)) { const MItem* pl = mbinary(pi)->LeftItem (); const MItem* pr = mbinary(pi)->RightItem(); return (is_rconst(pl) && is_rconst(pr)); } if (is_nary(pi)) { const MNary* pn = mnary(pi); int n = pn->Params(); for (int i=0; i<n; ++i) if (is_rconst(pn->Param(i)) == false) return false; return true; } if (is_matrix(pi)) { const MMatrix& A = *mmatrix(pi); for (int i=0; i<A.rows(); ++i) for (int j=0; j<A.columns(); ++j) { MItem* pij = A[i][j]; if (is_rconst(pij) == false) return false; } return true; } assert(false); return false; } //----------------------------------------------------------------------------- // See if the expression is dependent on the variable x bool is_dependent(const MItem* pi, const MVariable& x) { if (is_var(pi)) return (mvar(pi)->Name().compare(x.Name()) == 0); if (isConst(pi) || is_named(pi) || is_frac(pi)) return false; if (is_unary(pi)) return is_dependent(munary(pi)->Item(), x); if (is_binary(pi)) { const MItem* pl = mbinary(pi)->LeftItem (); const MItem* pr = mbinary(pi)->RightItem(); return (is_dependent(pl, x) || is_dependent(pr, x)); } if (is_nary(pi)) { const MNary* pn = mnary(pi); int n = pn->Params(); bool b = false; for (int i=0; i<n; ++i) b = (b || is_dependent(pn->Param(i), x)); return b; } if (is_matrix(pi)) { const MMatrix& m = *mmatrix(pi); int nr = m.rows(); int nc = m.columns(); for (int i=0; i<nr; ++i) for (int j=0; j<nc; ++j) { const MItem* mij = m(i,j); if (is_dependent(mij, x)) return true; } return false; } assert(false); return false; } //----------------------------------------------------------------------------- // See if the expression contains the expression px bool is_dependent(const MItem* pi, const MItem* px) { if (is_equal(pi, px)) return true; if (is_unary(pi)) return is_dependent(munary(pi)->Item(), px); if (is_binary(pi)) { const MItem* pl = mbinary(pi)->LeftItem (); const MItem* pr = mbinary(pi)->RightItem(); return (is_dependent(pl, px) || is_dependent(pr, px)); } if (is_nary(pi)) { const MNary* pn = mnary(pi); int n = pn->Params(); bool b = false; for (int i=0; i<n; ++i) b = (b || is_dependent(pn->Param(i), px)); return b; } if (is_matrix(pi)) { const MMatrix& m = *mmatrix(pi); int nr = m.rows(); int nc = m.columns(); for (int i=0; i<nr; ++i) for (int j=0; j<nc; ++j) { const MItem* mij = m(i,j); if (is_dependent(mij, px)) return true; } return false; } return false; } //----------------------------------------------------------------------------- // see if the item is the named constant pi bool is_pi(const MItem* pi) { if (is_named(pi)) { const string& sz = mnamed(pi)->Name(); if (sz.compare("pi") == 0) return true; } return false; } //----------------------------------------------------------------------------- // see if the expression is a scalar expression (e.g. does not contain matrices) bool is_scalar(const MItem* pi) { if (is_number(pi)) return true; if (is_unary(pi)) return ::is_scalar(munary(pi)->Item()); if (is_binary(pi)) { const MItem* pl = mbinary(pi)->LeftItem (); const MItem* pr = mbinary(pi)->RightItem(); return (::is_scalar(pl) && ::is_scalar(pr)); } if (is_nary(pi)) { const MNary* pn = mnary(pi); int n = pn->Params(); bool b = true; for (int i=0; i<n; ++i) b = (b && ::is_scalar(pn->Param(i))); return b; } return false; } //----------------------------------------------------------------------------- // Calculate the number of operations for the expression. int op_count(const MItem* pi) { int n = 0; if (is_unary(pi)) n = op_count(munary(pi)->Item()) + 1; else if (is_binary(pi)) { int n1 = op_count(mbinary(pi)->LeftItem()); int n2 = op_count(mbinary(pi)->RightItem()); n = n1 + n2 + 1; } else if (is_nary(pi)) { n = 1; const MNary* pn = mnary(pi); int N = pn->Params(); for (int i=0; i<N; ++i) n += op_count(pn->Param(i)); } return n; } //----------------------------------------------------------------------------- const char* read_format(const MItem* pe, const char* sz) { switch (sz[0]) { case '+': { const MBinary* pb = mbinary(pe); if (pe->Type() != MADD) return nullptr; sz = read_format(pb->LeftItem(), sz+1); read_format(pb->RightItem(), sz); } break; } return 0; } //----------------------------------------------------------------------------- bool is_format(const MItem* pe, const char* sz) { return (read_format(pe, sz) != 0); }
C++
3D
febiosoftware/FEBio
FECore/FEAugLagLinearConstraint.h
.h
4,495
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 <FECore/vector.h> #include <FECore/matrix.h> #include <FECore/FESurfaceConstraint.h> #include <FECore/FENodeSetConstraint.h> #include <FECore/FECoreClass.h> #include "fecore_api.h" #include <list> class FENode; //----------------------------------------------------------------------------- //! linear constraint enforced using augmented lagrangian class FECORE_API FEAugLagLinearConstraintDOF : public FECoreClass { public: FEAugLagLinearConstraintDOF(FEModel* fem); FENode& Node(); int NodeIndex(); public: int m_nodeid; // the ID of the node to which this dof belongs to int m_bc; // the degree of freedom double m_val; // coefficient value DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEAugLagLinearConstraintDOF); }; class FECORE_API FEAugLagLinearConstraint : public FECoreClass { public: typedef std::vector<FEAugLagLinearConstraintDOF*>::iterator Iterator; public: //! constructor FEAugLagLinearConstraint(FEModel* fem) : FECoreClass(fem) { m_lam = 0; } //! serialize data to archive void Serialize(DumpStream& ar) override; void ClearDOFs(); void AddDOF(int node, int bc, double val); public: std::vector<FEAugLagLinearConstraintDOF*> m_dof; //!< list of participating dofs double m_lam; //!< lagrange multiplier DECLARE_FECORE_CLASS(); FECORE_BASE_CLASS(FEAugLagLinearConstraint); }; //----------------------------------------------------------------------------- //! This class manages a group of linear constraints class FECORE_API FELinearConstraintSet : public FENLConstraint { public: //! constructor FELinearConstraintSet(FEModel* pfem); //! add a linear constraint to the list void add(FEAugLagLinearConstraint* plc) { m_LC.push_back(plc); } public: //! add the linear constraint contributions to the residual void LoadVector(FEGlobalVector& R, const FETimeInfo& tp) override; //! add the linear constraint contributions to the stiffness matrix void StiffnessMatrix(FELinearSystem& LS, const FETimeInfo& tp) override; //! do the augmentation bool Augment(int naug, const FETimeInfo& tp) override; //! build connectivity for matrix profile void BuildMatrixProfile(FEGlobalMatrix& M) override; //! serialization void Serialize(DumpStream& ar) override; //! initialize bool Init() override; // allocate equations int InitEquations(int neq) override; void Update(const std::vector<double>& Ui, const std::vector<double>& ui) override; void UpdateIncrements(std::vector<double>& Ui, const std::vector<double>& ui) override; void PrepStep() override; protected: //! calculate the constraint value double constraint(FEAugLagLinearConstraint& LC); public: std::vector<FEAugLagLinearConstraint*> m_LC; //!< list of linear constraints public: int m_laugon; //!< contact enforcement method double m_tol; //!< augmentation tolerance double m_eps; //!< penalty factor double m_rhs; //!< right-hand-side of linear constraint equation int m_naugmax; //!< max nr of augmentations int m_naugmin; //!< min nf of augmentations int m_nID; //!< ID of manager protected: vector<int> m_EQ; vector<double> m_Lm, m_Lmp; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FECore/PointCurve.cpp
.cpp
22,675
837
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "PointCurve.h" #include "BSpline.h" #include "AkimaSpline.h" #include <assert.h> #include <algorithm> #ifndef min #define min(a,b) ((a)<(b)?(a):(b)) #endif size_t binarySearch(const std::vector<vec2d>& points, double x) { size_t N = points.size(); size_t low = 0; size_t high = N - 1; // Repeat until the pointers low and high meet each other while (low <= high) { size_t mid = low + (high - low) / 2; if (points[mid].x() <= x) low = mid + 1; else high = mid - 1; } return low; } class PointCurve::Imp { public: int fnc; //!< interpolation function int ext; //!< extend mode std::vector<vec2d> points; std::vector<vec2d> dpts; // derivative points for C2SMOOTH option BSpline* spline; //!< B-spline BSpline* sderiv; //!< B-spline for 1st derivative AkimaSpline* akima; //!< Akima spline }; //----------------------------------------------------------------------------- PointCurve::PointCurve() : im(new PointCurve::Imp) { im->fnc = LINEAR; im->ext = CONSTANT; im->spline = nullptr; im->sderiv = nullptr; im->akima = nullptr; } //----------------------------------------------------------------------------- PointCurve::PointCurve(const PointCurve& pc) : im(new PointCurve::Imp) { im->fnc = pc.im->fnc; im->ext = pc.im->ext; im->points = pc.im->points; im->spline = nullptr; im->sderiv = nullptr; im->akima = nullptr; Update(); } //----------------------------------------------------------------------------- void PointCurve::operator = (const PointCurve& pc) { im->fnc = pc.im->fnc; im->ext = pc.im->ext; im->points = pc.im->points; if (im->spline) delete im->spline; if (im->sderiv) delete im->spline; if (im->akima) delete im->akima; Update(); } //----------------------------------------------------------------------------- PointCurve::~PointCurve() { if (im->spline) delete im->spline; if (im->sderiv) delete im->sderiv; if (im->akima) delete im->akima; } //----------------------------------------------------------------------------- //! adds a point to the point curve int PointCurve::Add(double x, double y) { // find the place to insert the data point int n = 0; int nsize = Points(); while ((n < nsize) && (im->points[n].x() < x)) ++n; // insert loadpoint im->points.insert(im->points.begin() + n, vec2d(x, y)); return n; } //----------------------------------------------------------------------------- int PointCurve::Add(const vec2d& p) { return Add(p.x(), p.y()); } //----------------------------------------------------------------------------- //! Clears the loadcurve data void PointCurve::Clear() { im->points.clear(); if (im->spline) delete im->spline; im->spline = nullptr; if (im->sderiv) delete im->sderiv; im->sderiv = nullptr; if (im->akima) delete im->akima; im->akima = nullptr; } //----------------------------------------------------------------------------- //! return nr of points int PointCurve::Points() const { return (int) im->points.size(); } //----------------------------------------------------------------------------- // Sets the time and data value of point i // This function assumes that the load curve data has already been created // void PointCurve::SetPoint(int i, double x, double y) { vec2d& pt = im->points[i]; pt.x() = x; pt.y() = y; } //----------------------------------------------------------------------------- void PointCurve::SetPoint(int i, const vec2d& p) { im->points[i] = p; } //----------------------------------------------------------------------------- void PointCurve::SetPoints(const std::vector<vec2d>& points) { im->points = points; } //----------------------------------------------------------------------------- //! return all points std::vector<vec2d> PointCurve::GetPoints() const { return im->points; } //----------------------------------------------------------------------------- //! Set the type of interpolation void PointCurve::SetInterpolator(int fnc) { im->fnc = fnc; } //----------------------------------------------------------------------------- //! return current interpolator int PointCurve::GetInterpolator() const { return im->fnc; } //----------------------------------------------------------------------------- //! Set the extend mode void PointCurve::SetExtendMode(int mode) { im->ext = mode; } //----------------------------------------------------------------------------- //! Get the extend mode int PointCurve::GetExtendMode() const { return im->ext; } //----------------------------------------------------------------------------- //! get a point vec2d PointCurve::Point(int i) const { return im->points[i]; } //----------------------------------------------------------------------------- void PointCurve::Delete(int n) { if ((n >= 0) && (n < Points()) && (Points() > 2)) { im->points.erase(im->points.begin() + n); } } //----------------------------------------------------------------------------- void PointCurve::Delete(const std::vector<int>& indexList) { std::vector<int> tmp; int N = (int)indexList.size(); for (int i = 0; i < N; ++i) { int n = indexList[i]; if ((n >= 0) && (n < Points())) tmp.push_back(n); } std::sort(tmp.begin(), tmp.end()); for (int i = 0; i < N; ++i) { int n = tmp[i]; im->points.erase(im->points.begin() + n); for (int j = i + 1; j < N; ++j) tmp[j]--; } } //----------------------------------------------------------------------------- void PointCurve::Scale(double s) { for (int i = 0; i < Points(); ++i) { im->points[i].y() *= s; } } //----------------------------------------------------------------------------- // FUNCTION : LoadCurve::Value // Returns the load curve's value at time t. // When the time value is outside the time range, the return value // is that of the closest data value. // // TODO: maybe I should extrapolate the out-of-domain return values, // in stead of clamping them. I think that is what NIKE does. Or even // better let the user determine the out-of-range behaviour. Options could // be zero, clamp to range, linear extrapolation, ... // inline double lerp(double t, double t0, double f0, double t1, double f1) { return f0 + (f1 - f0) * (t - t0) / (t1 - t0); } inline double qerp(double t, double t0, double f0, double t1, double f1, double t2, double f2) { double q0 = ((t2 - t) * (t1 - t)) / ((t2 - t0) * (t1 - t0)); double q1 = ((t2 - t) * (t - t0)) / ((t2 - t1) * (t1 - t0)); double q2 = ((t - t1) * (t - t0)) / ((t2 - t1) * (t2 - t0)); return f0 * q0 + f1 * q1 + f2 * q2; } double PointCurve::value(double time) const { std::vector<vec2d>& points = im->points; int nsize = Points(); if (nsize == 0) return 0; if (nsize == 1) return points[0].y(); int N = nsize - 1; if (time == points[0].x()) return points[0].y(); if (time == points[N].x()) return points[N].y(); double tmax = points[N].x(); double tmin = points[0].x(); if (time < tmin) return ExtendValue(time); if (time > tmax) return ExtendValue(time); if (im->fnc == LINEAR) { size_t n = binarySearch(points, time); double t0 = points[n - 1].x(); double t1 = points[n].x(); double f0 = points[n - 1].y(); double f1 = points[n].y(); return lerp(time, t0, f0, t1, f1); } else if (im->fnc == STEP) { size_t n = binarySearch(points, time); return points[n].y(); } else if (im->fnc == SMOOTH_STEP) { size_t n = binarySearch(points, time); double t0 = points[n - 1].x(); double t1 = points[n].x(); double f0 = points[n - 1].y(); double f1 = points[n].y(); double w = (time - t0) / (t1 - t0); double w2 = w * w; double w3 = w * w2; return f0 + (f1 - f0)*w3*(10.0 - 15.0*w + 6.0*w2); } else if ((im->fnc == CSPLINE) || (im->fnc == CPOINTS) || (im->fnc == APPROX)) { if (time > tmax) return im->spline->eval(tmax); else if (time < tmin) return im->spline->eval(tmin); else return im->spline->eval(time); } else if ((im->fnc == SMOOTH) || (im->fnc == C2SMOOTH)) { if (nsize == 2) { double t0 = points[0].x(); double t1 = points[1].x(); double f0 = points[0].y(); double f1 = points[1].y(); return lerp(time, t0, f0, t1, f1); } else if (nsize == 3) { double t0 = points[0].x(); double t1 = points[1].x(); double t2 = points[2].x(); double f0 = points[0].y(); double f1 = points[1].y(); double f2 = points[2].y(); return qerp(time, t0, f0, t1, f1, t2, f2); } else { size_t n = binarySearch(points, time); if (n == 1) { double t0 = points[0].x(); double t1 = points[1].x(); double t2 = points[2].x(); double f0 = points[0].y(); double f1 = points[1].y(); double f2 = points[2].y(); return qerp(time, t0, f0, t1, f1, t2, f2); } else if (n == nsize - 1) { double t0 = points[n - 2].x(); double t1 = points[n - 1].x(); double t2 = points[n].x(); double f0 = points[n - 2].y(); double f1 = points[n - 1].y(); double f2 = points[n].y(); return qerp(time, t0, f0, t1, f1, t2, f2); } else { double t0 = points[n - 2].x(); double t1 = points[n - 1].x(); double t2 = points[n].x(); double t3 = points[n + 1].x(); double f0 = points[n - 2].y(); double f1 = points[n - 1].y(); double f2 = points[n].y(); double f3 = points[n + 1].y(); double q1 = qerp(time, t0, f0, t1, f1, t2, f2); double q2 = qerp(time, t1, f1, t2, f2, t3, f3); return lerp(time, t1, q1, t2, q2); } } } return 0; } //----------------------------------------------------------------------------- //! This function determines the value of the point curve outside of its domain //! double PointCurve::ExtendValue(double t) const { int nsize = Points(); int N = nsize - 1; std::vector<vec2d>& points = im->points; if (nsize == 0) return 0; if (nsize == 1) return points[0].y(); double Dt = (points[N].x() - points[0].x()); double dt = 0.001 * Dt; if (dt == 0) return points[0].y(); switch (im->ext) { case CONSTANT: if (t < points[0].x()) return points[0].y(); if (t > points[N].x()) return points[N].y(); break; case EXTRAPOLATE: switch (im->fnc) { case STEP: case SMOOTH_STEP: { if (t < points[0].x()) return points[0].y(); if (t > points[N].x()) return points[N].y(); } break; case LINEAR: { if (t < points[0].x()) return lerp(t, points[0].x(), points[0].y(), points[1].x(), points[1].y()); else return lerp(t, points[N - 1].x(), points[N - 1].y(), points[N].x(), points[N].y()); } break; case SMOOTH: case CSPLINE: case CPOINTS: case APPROX: case C2SMOOTH: { if (t < points[0].x()) return lerp(t, points[0].x(), points[0].y(), points[0].x() + dt, value(points[0].x() + dt)); else return lerp(t, points[N].x() - dt, value(points[N].x() - dt), points[N].x(), points[N].y()); } return 0; } break; case REPEAT: { if (t < points[0].x()) while (t < points[0].x()) t += Dt; else while (t > points[N].x()) t -= Dt; return value(t); } break; case REPEAT_OFFSET: { int n = 0; if (t < points[0].x()) while (t < points[0].x()) { t += Dt; --n; } else while (t > points[N].x()) { t -= Dt; ++n; } double off = n * (points[N].y() - points[0].y()); return value(t) + off; } break; } return 0; } //----------------------------------------------------------------------------- // This function finds the index of the first load point // for which the time is greater than t. // It returns -1 if t is larger than the last time value // int PointCurve::FindPoint(double t, double& tval, int startIndex) { switch (im->ext) { case REPEAT: case REPEAT_OFFSET: { double toff = 0.0; while (1) { double ti = 0; for (int i = 0; i < Points(); ++i) { ti = im->points[i].x() + toff; if (ti > t) { tval = ti; return i; } } toff = ti; } } break; default: if (startIndex < 0) startIndex = 0; if (startIndex >= Points()) return -1; for (int i = startIndex; i < Points(); ++i) { double ti = im->points[i].x(); if (ti > t) { tval = ti; return i; } } } return -1; } //----------------------------------------------------------------------------- bool PointCurve::HasPoint(double t) const { const double tmax = im->points[Points() - 1].x(); const double eps = 1e-7 * tmax; for (int i = 0; i < Points(); ++i) if (fabs(im->points[i].x() - t) < eps) return true; return false; } //----------------------------------------------------------------------------- double PointCurve::derive(double time) const { int N = (int)im->points.size(); if (N <= 1) return 0; double tmax = im->points[N - 1].x(); double tmin = im->points[0].x(); double Dt = im->points[N - 1].x() - im->points[0].x(); double dt = Dt * 1e-9; double D = 0; if (time >= tmax) { // use backward difference double t2 = time - 2 * dt; double t1 = time - dt; double t0 = time; double v2 = value(t2); double v1 = value(t1); double v0 = value(t0); return (v2 - 4 * v1 + 3 * v0) / (2 * dt); } else if (time < tmin) { // use forward difference double t0 = time; double t1 = time + dt; double t2 = time + 2 * dt; double v0 = value(t0); double v1 = value(t1); double v2 = value(t2); return (-v2 + 4 * v1 - 3 * v0) / (2 * dt); } if ((im->fnc == CSPLINE) || (im->fnc == CPOINTS) || (im->fnc == APPROX)) { return im->spline->eval_deriv(time); } else if (im->fnc == C2SMOOTH) { if (N == 3) { double t0 = im->dpts[0].x(); double t1 = im->dpts[1].x(); double t2 = im->dpts[2].x(); double f0 = im->dpts[0].y(); double f1 = im->dpts[1].y(); double f2 = im->dpts[2].y(); return qerp(time, t0, f0, t1, f1, t2, f2); } else { size_t n = binarySearch(im->dpts, time); if (n == 1) { double t0 = im->dpts[0].x(); double t1 = im->dpts[1].x(); double t2 = im->dpts[2].x(); double f0 = im->dpts[0].y(); double f1 = im->dpts[1].y(); double f2 = im->dpts[2].y(); return qerp(time, t0, f0, t1, f1, t2, f2); } else if (n == N - 1) { double t0 = im->dpts[n - 2].x(); double t1 = im->dpts[n - 1].x(); double t2 = im->dpts[n].x(); double f0 = im->dpts[n - 2].y(); double f1 = im->dpts[n - 1].y(); double f2 = im->dpts[n].y(); return qerp(time, t0, f0, t1, f1, t2, f2); } else { double t0 = im->dpts[n - 2].x(); double t1 = im->dpts[n - 1].x(); double t2 = im->dpts[n].x(); double t3 = im->dpts[n + 1].x(); double f0 = im->dpts[n - 2].y(); double f1 = im->dpts[n - 1].y(); double f2 = im->dpts[n].y(); double f3 = im->dpts[n + 1].y(); double q1 = qerp(time, t0, f0, t1, f1, t2, f2); double q2 = qerp(time, t1, f1, t2, f2, t3, f3); return lerp(time, t1, q1, t2, q2); } } } else { // use central difference double t0 = time - dt; double t1 = time + dt; double v1 = value(t1); double v0 = value(t0); return (v1 - v0) / (2 * dt); } } //----------------------------------------------------------------------------- double PointCurve::deriv2(double time) const { int N = (int)im->points.size(); if (N <= 1) return 0; double tmax = im->points[N - 1].x(); double tmin = im->points[0].x(); double Dt = im->points[N - 1].x() - im->points[0].x(); double dt = Dt * 1e-3; if (time > tmax) { // use backward difference double t2 = time - 2 * dt; double t1 = time - dt; double t0 = time; double v2 = value(t2); double v1 = value(t1); double v0 = value(t0); return (v2 - 2 * v1 + v0) / (dt * dt); } else if (time < tmin) { // use forward difference double t0 = time; double t1 = time + dt; double t2 = time + 2 * dt; double v0 = value(t0); double v1 = value(t1); double v2 = value(t2); return (v2 - 2 * v1 + v0) / (dt * dt); } if ((im->fnc == CSPLINE) || (im->fnc == CPOINTS) || (im->fnc == APPROX)) { return im->spline->eval_deriv2(time); } else { // use central difference double t0 = time - dt; double t1 = time; double t2 = time + dt; double v0 = value(t0); double v1 = value(t1); double v2 = value(t2); return (v2 - 2 * v1 + v0) / (dt * dt); } } double PointCurve::integrate(double a, double b) const { if (a == b) return 0; // Swap a and b if a is greater than b // negate the answer at the end. int neg = 1; if (a > b) { double temp = a; a = b; b = temp; neg = -1; } double integral = 0.0; // if both points are outside the bounds of the load curve // just do a single trapezoid // TODO: add cases for repeat and repeat offset curves std::vector<vec2d>& points = im->points; if (a > points[Points() - 1].x() || b < points[0].x()) { integral = (b - a) * (value(a) + value(b)) / 2; } else { // Find index of first point larger than a int start = -1; for (int index = 0; index < Points(); index++) { if (points[index].x() > a) { start = index; break; } } // Do trapezoid rule from a to next point integral += (points[start].x() - value(a)) * ((points[start].y() + value(a)) / 2); // Loop over points between a and b and do trapezoid rule for each interval int index; for (index = start; index < Points() - 1; index++) { // Stop before overshooting b if (points[index + 1].x() >= b) break; integral += (points[index + 1].x() - points[index].x()) * ((points[index + 1].y() + points[index].y()) * 0.5); } //Do trapezoid rule from most recent point to b integral += (value(b) - points[index].x()) * ((value(b) + points[index].y()) * 0.5); } return integral * neg; } bool PointCurve::Update() { bool bvalid = true; if ((im->fnc > SMOOTH) && (im->fnc != SMOOTH_STEP)) { const int N = Points(); switch (im->fnc) { case CSPLINE: { // initialize B-spline if (im->spline) delete im->spline; im->spline = new BSpline(); int korder = min(N, 4); if (!im->spline->init_interpolation(korder, im->points)) bvalid = false; } break; case CPOINTS: { // initialize B-spline if (im->spline) delete im->spline; im->spline = new BSpline(); int korder = min(N, 4); if (!im->spline->init(korder, im->points)) bvalid = false; } break; case APPROX: { // initialize B-spline if (im->spline) delete im->spline; im->spline = new BSpline(); int korder = min(N / 2 + 1, 4); if (!im->spline->init_approximation(korder, N / 2 + 1, im->points)) bvalid = false; } break; case C2SMOOTH: { if (N < 3) { bvalid = false; break; } // evaluate control points of spline derivative using finite difference scheme (non-uniform) std::vector<vec2d>& dpts = im->dpts; dpts = im->points; double d01, d10, d11, d20,d21, d02, d12; // forward difference at first point d10 = dpts[1].x() - dpts[0].x(); d20 = dpts[2].x() - dpts[0].x(); d21 = dpts[2].x() - dpts[1].x(); dpts[0].y() = (im->points[0].y()*(pow(d10,2)-pow(d20,2)) + im->points[1].y()*pow(d20,2) - im->points[2].y()*pow(d10,2))/(d10*d20*d21); // backward difference at last point int n = N-1; d02 = dpts[n].x() - dpts[n-2].x(); d01 = dpts[n].x() - dpts[n-1].x(); d12 = dpts[n-1].x() - dpts[n-2].x(); dpts[n].y() = (im->points[n].y()*(pow(d02,2)-pow(d01,2)) - im->points[n-1].y()*pow(d02,2) + im->points[n-2].y()*pow(d01,2))/(d01*d02*d12); // central difference at intermediate points for (int i=1; i<n; ++i) { d10 = dpts[i+1].x() - dpts[i].x(); d01 = dpts[i].x() - dpts[i-1].x(); d11 = dpts[i+1].x() - dpts[i-1].x(); dpts[i].y() = (im->points[i].y()*(pow(d10,2)-pow(d01,2)) - im->points[i-1].y()*pow(d10,2) + im->points[i+1].y()*pow(d01,2))/(d01*d10*d11); } } break; default: bvalid = false; assert(false); } if (bvalid == false) { if (im->spline) delete im->spline; im->spline = nullptr; if (im->akima) delete im->akima; im->akima = nullptr; } } return bvalid; }
C++
3D
febiosoftware/FEBio
FECore/DumpFile.cpp
.cpp
2,456
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.*/ #include "stdafx.h" #include "DumpFile.h" DumpFile::DumpFile(FEModel& fem) : DumpStream(fem) { m_fp = 0; m_size = 0; } DumpFile::~DumpFile() { Close(); } bool DumpFile::Open(const char* szfile) { m_fp = fopen(szfile, "rb"); if (m_fp == 0) return false; DumpStream::Open(false, false); return true; } bool DumpFile::Create(const char* szfile) { m_fp = fopen(szfile, "wb"); if (m_fp == 0) return false; DumpStream::Open(true, false); return true; } bool DumpFile::Append(const char* szfile) { m_fp = fopen(szfile, "a+b"); if (m_fp == 0) return false; DumpStream::Open(true, false); return true; } void DumpFile::Close() { if (m_fp) fclose(m_fp); m_fp = 0; } //! write buffer to archive size_t DumpFile::write(const void* pd, size_t size, size_t count) { assert(IsSaving()); size_t elemsWritten = fwrite(pd, size, count, m_fp); m_size += size * elemsWritten; return size * elemsWritten; } //! read buffer from archive size_t DumpFile::read(void* pd, size_t size, size_t count) { assert(IsLoading()); size_t elemsRead = fread(pd, size, count, m_fp); return size * elemsRead; } bool DumpFile::EndOfStream() const { return (feof(m_fp) != 0); }
C++
3D
febiosoftware/FEBio
FECore/FETimeInfo.h
.h
1,934
57
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "fecore_api.h" class DumpStream; //----------------------------------------------------------------------------- class FECORE_API FETimeInfo { public: FETimeInfo(); FETimeInfo(double time, double tinc); void Serialize(DumpStream& ar); public: double currentTime; //!< current time value double timeIncrement; //!< current time step (difference between this time and previous one) int timeStep; //!< current time step int currentIteration; //!< iteration number int augmentation; //!< augmentation // HHT time integration parameters double alpha; double beta; double gamma; double alphaf; double alpham; };
Unknown
3D
febiosoftware/FEBio
FECore/FEDomain.h
.h
3,361
96
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEMeshPartition.h" #include "FEMat3dValuator.h" // forward declaration of material class class FEMaterial; // Base class for solid and shell parts. Domains can also have materials assigned. class FECORE_API FEDomain : public FEMeshPartition { public: FEDomain(int nclass, FEModel* fem); //! get the material of this domain virtual FEMaterial* GetMaterial() { return 0; } // assign a material to this domain virtual void SetMaterial(FEMaterial* pm); //! set the material ID of all elements void SetMatID(int mid); //! Allocate material point data for the elements //! This is called after elements get read in from the input file. //! And must be called before material point data can be accessed. //! \todo Perhaps I can make this part of the "creation" routine void CreateMaterialPointData(); // serialization void Serialize(DumpStream& ar) override; //! augmentation // NOTE: This is here so that the FESolver can do the augmentations // for the 3-field hex/shell domains. virtual bool Augment(int naug) { return true; } // create function virtual bool Create(int elements, FE_Element_Spec espec) = 0; public: //! Get the list of dofs on this domain virtual const FEDofList& GetDOFList() const = 0; //! Unpack the LM data for an element of this domain virtual void UnpackLM(FEElement& el, vector<int>& lm); //! build the matrix profile virtual void BuildMatrixProfile(FEGlobalMatrix& M); //! Activate the domain virtual void Activate(); //! Gives domains a chance to update any data that depends on the displacement increments. //! This function is called during the line search as well. The finalFlag //! indicates whether it is safe to commit the updates. virtual void IncrementalUpdate(std::vector<double>& ui, bool finalFlag); protected: // helper function for activating dof lists void Activate(const FEDofList& dof); // helper function for unpacking element dofs void UnpackLM(FEElement& el, const FEDofList& dof, vector<int>& lm); protected: FEMat3dValuator* m_matAxis; // initial material axis };
Unknown
3D
febiosoftware/FEBio
FECore/stdafx.h
.h
1,532
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) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 <stdio.h> #include <stdlib.h> #ifdef WIN32 #include "targetver.h" #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #endif // TODO: reference additional headers your program requires here
Unknown
3D
febiosoftware/FEBio
FECore/FEException.h
.h
5,011
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.*/ #pragma once #include "fecore_api.h" #include <string> class FEElement; class FECORE_API FEException { public: enum { Error = 0, Warning = 1 }; public: // level = 0, error // level = 1, warning FEException(const char* msg = nullptr, int level = 0); virtual ~FEException(); const char* what(); void what(const char* msg, ...); int level() const; private: std::string m_what; int m_level; }; class FECORE_API NegativeJacobian : public FEException { public: NegativeJacobian(int iel, int ng, double vol, FEElement* pe = 0); int m_iel; // element where the jacobian was negative int m_ng; // integration point double m_vol; // volume FEElement* m_pel; // pointer to element static bool DoOutput(); static void clearFlag(); static bool IsThrown(); static int Count(); static void ResetCount(); public: static bool m_bthrown; static int m_maxout; // max nr of negative jacobians reported (< 0 for unlimited, 0 = off, > 0 sets limit) static int m_count; }; class FECORE_API ZeroDiagonal : public FEException { private: struct EQUATION { int node; // node int dof; // degree of node }; public: ZeroDiagonal(int node, int dof); }; class FECORE_API EnergyDiverging : public FEException { public: EnergyDiverging() : FEException("Problem diverging uncontrollably.") {} }; class FECORE_API MaxStiffnessReformations : public FEException { public: MaxStiffnessReformations() : FEException("Max nr of reformations reached.") {} }; class FECORE_API ZeroLinestepSize : public FEException { public: ZeroLinestepSize() : FEException("Zero line step size.") {} }; class FECORE_API ForceConversion : public FEException { public: ForceConversion() : FEException("User forced conversion.\nSolution might not be stable.", FEException::Warning) {} }; class FECORE_API IterationFailure : public FEException { public: IterationFailure() : FEException("User forced iteration failure.", FEException::Warning) {} }; class FECORE_API MaxResidualError : public FEException { public: MaxResidualError() : FEException("Maximum residual exceeded.", FEException::Warning) {} }; struct FECORE_API FENodalDofInfo; class FECORE_API NANInResidualDetected : public FEException { public: NANInResidualDetected() : FEException("NAN detected") {} NANInResidualDetected(const FENodalDofInfo& ndi); }; class FECORE_API NANInSolutionDetected : public FEException { public: NANInSolutionDetected() : FEException("NAN detected") {} NANInSolutionDetected(const FENodalDofInfo& ndi); }; class FECORE_API FatalError : public FEException{ public: FatalError() : FEException("Fatal error") {} }; class FECORE_API DoRunningRestart : public FEException { public: DoRunningRestart() : FEException("Running restart requested", FEException::Warning) {} }; class FECORE_API FEMultiScaleException : public FEException { public: FEMultiScaleException(int eid, int gpt); }; class FECORE_API LinearSolverFailed : public FEException { public: LinearSolverFailed() : FEException("Linear solver failed to find solution. Aborting run.") {} }; class FECORE_API FactorizationError : public FEException{ public: FactorizationError() : FEException("Fatal error in factorization of stiffness matrix. Aborting run.") {} }; class FECORE_API NegativeJacobianDetected : public FEException { public: NegativeJacobianDetected() { int n = NegativeJacobian::Count(); if (n > 1) what("%d negative jacobians detected.", n); else what("Negative jacobian detected."); NegativeJacobian::ResetCount(); } }; class FECORE_API ConcentrationChangeDetected : public FEException { public: ConcentrationChangeDetected() : FEException("Concentration change detected") {} ConcentrationChangeDetected(const FENodalDofInfo& ndi); };
Unknown
3D
febiosoftware/FEBio
FECore/FESegmentSet.cpp
.cpp
3,011
104
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FESegmentSet.h" #include "DumpStream.h" #include "FEMesh.h" //----------------------------------------------------------------------------- void FESegmentSet::SEGMENT::Serialize(DumpStream& ar) { ar & node; ar & ntype; } //----------------------------------------------------------------------------- FESegmentSet::FESegmentSet(FEModel* fem) : FEItemList(fem, FEItemList::FE_ELEMENT_SET) { } //----------------------------------------------------------------------------- void FESegmentSet::Create(int n) { m_Seg.resize(n); } //----------------------------------------------------------------------------- FESegmentSet::SEGMENT& FESegmentSet::Segment(int i) { return m_Seg[i]; } //----------------------------------------------------------------------------- const FESegmentSet::SEGMENT& FESegmentSet::Segment(int i) const { return m_Seg[i]; } //----------------------------------------------------------------------------- void FESegmentSet::Serialize(DumpStream& ar) { FEItemList::Serialize(ar); if (ar.IsShallow()) return; ar & m_Seg; } void FESegmentSet::SaveClass(DumpStream& ar, FESegmentSet* p) { } FESegmentSet* FESegmentSet::LoadClass(DumpStream& ar, FESegmentSet* p) { p = new FESegmentSet(&ar.GetFEModel()); return p; } //----------------------------------------------------------------------------- FENodeList FESegmentSet::GetNodeList() const { FEMesh* mesh = GetMesh(); FENodeList set(mesh); vector<int> tag(mesh->Nodes(), 0); for (int i = 0; i < Segments(); ++i) { const SEGMENT& el = m_Seg[i]; int ne = el.ntype; for (int j = 0; j < ne; ++j) { if (tag[el.node[j]] == 0) { set.Add(el.node[j]); tag[el.node[j]] = 1; } } } return set; }
C++
3D
febiosoftware/FEBio
FECore/DataStore.h
.h
1,734
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 "DataRecord.h" #include "fecore_api.h" //----------------------------------------------------------------------------- class FECORE_API DataStore { public: DataStore(); virtual ~DataStore(); void Clear(); void Write(); void AddRecord(DataRecord* prec); int Size() { return (int) m_data.size(); } DataRecord* GetDataRecord(int i) { return m_data[i]; } protected: std::vector<DataRecord*> m_data; //!< the data records };
Unknown
3D
febiosoftware/FEBio
FECore/FETransform.cpp
.cpp
2,170
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.*/ #include "stdafx.h" #include "FETransform.h" Transform::Transform() { Reset(); } void Transform::Reset() { m_scl = vec3d(1, 1, 1); m_pos = vec3d(0, 0, 0); m_rot = quatd(0, 0, 0, 1); m_roti = quatd(0, 0, 0, 1); } void Transform::SetPosition(const vec3d& t) { m_pos = t; } void Transform::SetScale(double sx, double sy, double sz) { m_scl.x = sx; m_scl.y = sy; m_scl.z = sz; } void Transform::SetRotation(const quatd& q) { m_rot = q; m_roti = m_rot.Inverse(); } void Transform::SetRotation(const vec3d& r) { m_rot = quatd(r*DEG2RAD); m_roti = m_rot.Inverse(); } void Transform::SetRotation(double X, double Y, double Z) { X *= DEG2RAD; Y *= DEG2RAD; Z *= DEG2RAD; m_rot.SetEuler(X, Y, Z); m_roti = m_rot.Inverse(); } vec3d Transform::Apply(const vec3d& r) const { vec3d p(m_scl.x * r.x, m_scl.y * r.y, m_scl.z * r.z); m_rot.RotateVector(p); p += m_pos; return p; }
C++
3D
febiosoftware/FEBio
FECore/FESurface.cpp
.cpp
69,887
2,657
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FESurface.h" #include "FEMesh.h" #include "FESolidDomain.h" #include "FEElemElemList.h" #include "DumpStream.h" #include "matrix.h" #include <FECore/log.h> #include "FEModelParam.h" #include "FEMesh.h" //----------------------------------------------------------------------------- FESurface::FESurface(FEModel* fem) : FEMeshPartition(FE_DOMAIN_SURFACE, fem) { m_surf = 0; m_bitfc = false; m_alpha = 1; m_bshellb = false; } //----------------------------------------------------------------------------- FESurface::~FESurface() { } //----------------------------------------------------------------------------- void FESurface::Create(int nsize, int elemType) { m_el.resize(nsize); for (int i = 0; i < nsize; ++i) { FESurfaceElement& el = m_el[i]; el.SetLocalID(i); el.SetMeshPartition(this); el.m_elem[0].Reset(); el.m_elem[1].Reset(); } if (elemType != -1) { for (int i = 0; i < nsize; ++i) m_el[i].SetType(elemType); CreateMaterialPointData(); } } //----------------------------------------------------------------------------- void FESurface::Create(const FEFacetSet& set) { if (m_surf == 0) m_surf = const_cast<FEFacetSet*>(&set); assert(m_surf == &set); FEMesh& m = *GetMesh(); // count nr of faces int faces = set.Faces(); // allocate storage for faces Create(faces); // read faces for (int i = 0; i<faces; ++i) { FESurfaceElement& el = Element(i); const FEFacetSet::FACET& fi = set.Face(i); if (fi.ntype == 4) el.SetType(FE_QUAD4G4); else if (fi.ntype == 3) el.SetType(FE_TRI3G1); else if (fi.ntype == 6) el.SetType(FE_TRI6G3); else if (fi.ntype == 7) el.SetType(FE_TRI7G4); else if (fi.ntype == 8) el.SetType(FE_QUAD8G9); else if (fi.ntype == 9) el.SetType(FE_QUAD9G9); else if (fi.ntype == 10) el.SetType(FE_TRI10G7); else assert(false); int N = el.Nodes(); assert(N == fi.ntype); for (int j = 0; j<N; ++j) el.m_node[j] = fi.node[j]; } // copy the name SetName(set.GetName()); // allocate surface material points CreateMaterialPointData(); } //----------------------------------------------------------------------------- void FESurface::CreateMaterialPointData() { for (int i = 0; i < Elements(); ++i) { FESurfaceElement& el = m_el[i]; int nint = el.GaussPoints(); el.ClearData(); for (int n = 0; n < nint; ++n) { FESurfaceMaterialPoint* pt = dynamic_cast<FESurfaceMaterialPoint*>(CreateMaterialPoint()); assert(pt); el.SetMaterialPointData(pt, n); } } } //----------------------------------------------------------------------------- // extract the nodes from this surface FENodeList FESurface::GetNodeList() { FEMesh* pm = GetMesh(); FENodeList nset(pm); vector<int> tag(pm->Nodes(), 0); for (int i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); int ne = el.Nodes(); for (int j=0; j<ne; ++j) { if (tag[el.m_node[j]] == 0) { nset.Add(el.m_node[j]); tag[el.m_node[j]] = 1; } } } return nset; } //----------------------------------------------------------------------------- //! Get the list of (local) node indices of the boundary nodes void FESurface::GetBoundaryFlags(std::vector<bool>& boundary) const { FEElemElemList EEL; EEL.Create(this); boundary.assign(Nodes(), false); for (int i = 0; i < Elements(); ++i) { const FESurfaceElement& el = Element(i); for (int j = 0; j < el.facet_edges(); ++j) { FEElement* nel = EEL.Neighbor(i, j); if (nel == nullptr) { int en[3] = { -1,-1,-1 }; el.facet_edge(j, en); boundary[en[0]] = true; boundary[en[1]] = true; if (en[2] > -1) boundary[en[2]] = true; } } } } //----------------------------------------------------------------------------- // Create material point data for this surface FEMaterialPoint* FESurface::CreateMaterialPoint() { return new FESurfaceMaterialPoint; } //----------------------------------------------------------------------------- // update surface data void FESurface::Update(const FETimeInfo& tp) { ForEachSurfaceElement([=](FESurfaceElement& el) { int nint = el.GaussPoints(); int neln = el.Nodes(); vec3d rt[FEElement::MAX_NODES]; NodalCoordinates(el, rt); for (int n = 0; n < nint; ++n) { FESurfaceMaterialPoint& mp = static_cast<FESurfaceMaterialPoint&>(*el.GetMaterialPoint(n)); double* Gr = el.Gr(n); double* Gs = el.Gs(n); double* H = el.H(n); mp.m_rt = vec3d(0,0,0); mp.dxr = vec3d(0, 0, 0); mp.dxs = vec3d(0, 0, 0); for (int i = 0; i < neln; ++i) { mp.m_rt += rt[i] * H[i]; mp.dxr += rt[i] * Gr[i]; mp.dxs += rt[i] * Gs[i]; } } }); } //----------------------------------------------------------------------------- void FESurface::InitSurface() { // get the mesh to which this surface belongs FEMesh& mesh = *GetMesh(); // This array is used to keep tags on each node vector<int> tag; tag.assign(mesh.Nodes(), -1); // let's find all nodes the surface needs int nn = 0; int ne = Elements(); for (int i = 0; i<ne; ++i) { FESurfaceElement& el = Element(i); el.m_lid = i; for (int j = 0; j<el.Nodes(); ++j) { // get the global node number int m = el.m_node[j]; // create a local node number if (tag[m] == -1) tag[m] = nn++; // set the local node number el.m_lnode[j] = tag[m]; } } // allocate node index table m_Node.resize(nn); // fill the node index table for (int i = 0; i<mesh.Nodes(); ++i) { if (tag[i] >= 0) { m_Node[tag[i]] = i; } } } //----------------------------------------------------------------------------- //! Initialize surface node data structure //! Note that it is assumed that the element array is already created //! and initialized. bool FESurface::Init() { // make sure that there is a surface defined if (Elements() == 0) return false; // initialize the surface data InitSurface(); // NOTE: Make sure the mesh has its node-element list initialized // otherwise the omp loop below might crash due to race condition. GetMesh()->NodeElementList(); // see if we can find all elements that the faces belong to int invalidFacets = 0; int ne = Elements(); #pragma omp parallel for reduction(+:invalidFacets) for (int i=0; i<ne; ++i) { FESurfaceElement& el = Element(i); if (m_bitfc && (el.m_elem[0].pe == nullptr)) FindElements(el); else if (el.m_elem[0].pe == nullptr) el.m_elem[0] = FindElement(el); //to make sure else if (m_bitfc && (el.m_elem[1].pe == nullptr)) FindElements(el); if (el.m_elem[0].pe == nullptr) { invalidFacets++; } } if (invalidFacets > 0) { std::string surfName = GetName(); if (surfName.empty()) surfName = "(unknown)"; feLogWarning("The surface \"%s\" has %d invalid facets. \nThe model may not run correctly.", surfName.c_str(), invalidFacets); } vec3d re[FEElement::MAX_NODES]; // initialize material points of surface elements for (int i = 0; i < Elements(); ++i) { FESurfaceElement& el = m_el[i]; NodalCoordinates(el, re); int nint = el.GaussPoints(); int neln = el.Nodes(); for (int n = 0; n < nint; ++n) { FESurfaceMaterialPoint* pt = dynamic_cast<FESurfaceMaterialPoint*>(el.GetMaterialPoint(n)); if (pt == nullptr) return false; // initialize some material point data double* H = el.H(n); vec3d rn(0, 0, 0); for (int j = 0; j < neln; ++j) { rn += re[j]*H[j]; } pt->m_r0 = rn; pt->m_rt = pt->m_rp = rn; // calculate initial surface tangents double* Gr = el.Gr(n); double* Gs = el.Gs(n); vec3d dxr(0, 0, 0), dxs(0, 0, 0); for (int i = 0; i < neln; ++i) { dxr += re[i] * Gr[i]; dxs += re[i] * Gs[i]; } pt->dxr = dxr; pt->dxs = dxs; // initialize the other material point data pt->Init(); } } // allocate node normals and evaluate them in initial configuration m_nn.assign(Nodes(), vec3d(0,0,0)); UpdateNodeNormals(); return true; } //----------------------------------------------------------------------------- //! Find the element that a face belongs to // TODO: I should be able to speed this up FESurfaceElement::ELEMENT_REF FESurface::FindElement(FESurfaceElement& el) { // get the mesh to which this surface belongs FEMesh& mesh = *GetMesh(); FENodeElemList& NEL = mesh.NodeElementList(); FESurfaceElement::ELEMENT_REF ref; int node = el.m_node[0]; int nval = NEL.Valence(node); FEElement** ppe = NEL.ElementList(node); for (int i=0; i<nval; ++i) { FEElement* pe = ppe[i]; int nfaces = pe->Faces(); int nf[FEElement::MAX_NODES], nn; for (int j=0; j<nfaces; ++j) { nn = pe->GetFace(j, nf); if (nn == el.Nodes()) { int orient = 0; switch (nn) { case 3: orient = el.HasNodes(nf, 3); break; case 4: orient = el.HasNodes(nf, 4); break; case 6: orient = el.HasNodes(nf, 3); break; case 7: orient = el.HasNodes(nf, 3); break; case 8: orient = el.HasNodes(nf, 4); break; case 9: orient = el.HasNodes(nf, 4); break; default: assert(false); } if (orient != 0) { ref.pe = pe; ref.face = j; ref.orient = orient; return ref; } } } } return ref; } void FESurface::ForEachSurfaceElement(std::function<void(FESurfaceElement& el)> f) { for (size_t i = 0; i < m_el.size(); ++i) f(m_el[i]); } void FESurface::FindElements(FESurfaceElement& el) { // get the mesh to which this surface belongs FEMesh& mesh = *GetMesh(); FENodeElemList& NEL = mesh.NodeElementList(); vector<int>& sf = el.m_node; int node = el.m_node[0]; int nval = NEL.Valence(node); FEElement** ppe = NEL.ElementList(node); for (int i = 0; i < nval; ++i) { FEElement& sel = *ppe[i]; if (sel.isActive()) { // check all faces of this solid element int orient = 0; int nfaces = sel.Faces(); for (int j = 0; j < nfaces; ++j) { int nf[FEElement::MAX_NODES]; vec3d g[3]; int nn = sel.GetFace(j, nf); if (nn == el.Nodes()) { switch (nn) { case 3: orient = el.HasNodes(nf, 3); break; case 4: orient = el.HasNodes(nf, 4); break; case 6: orient = el.HasNodes(nf, 3); break; case 7: orient = el.HasNodes(nf, 3); break; case 8: orient = el.HasNodes(nf, 4); break; case 9: orient = el.HasNodes(nf, 4); break; default: assert(false); } } if (orient != 0) { if (el.m_elem[0].pe == nullptr) { el.m_elem[0].pe = &sel; el.m_elem[0].face = j; el.m_elem[0].orient = orient; } else if (el.m_elem[0].pe != &sel) { el.m_elem[1].pe = &sel; el.m_elem[1].face = j; el.m_elem[1].orient = orient; } } } } } } //----------------------------------------------------------------------------- //! unpack an LM vector from a dof list void FESurface::UnpackLM(const FESurfaceElement& el, const FEDofList& dofList, vector<int>& lm) { int dofPerNode = dofList.Size(); int neln = el.Nodes(); int ndof = neln*dofPerNode; lm.assign(ndof, -1); for (int j = 0; j < neln; ++j) { FENode& node = Node(el.m_lnode[j]); for (int k = 0; k < dofPerNode; ++k) { if (dofList[k] >= 0) lm[dofPerNode*j + k] = node.m_ID[dofList[k]]; } } } //----------------------------------------------------------------------------- // project onto a triangular face vec3d project2tri(vec3d* y, vec3d x, double& r, double& s) { // calculate base vectors vec3d e1 = y[1] - y[0]; vec3d e2 = y[2] - y[0]; // calculate plane normal vec3d n = e1^e2; n.unit(); // project x onto the plane vec3d q = x - n*((x-y[0])*n); // set up metric tensor double G[2][2]; G[0][0] = e1*e1; G[0][1] = G[1][0] = e1*e2; G[1][1] = e2*e2; // invert metric tensor double D = G[0][0]*G[1][1] - G[0][1]*G[1][0]; double Gi[2][2]; Gi[0][0] = G[1][1]/D; Gi[1][1] = G[0][0]/D; Gi[0][1] = Gi[1][0] = -G[0][1]/D; // calculate dual base vectors vec3d E1 = e1*Gi[0][0] + e2*Gi[0][1]; vec3d E2 = e1*Gi[1][0] + e2*Gi[1][1]; // now we can calculate r and s vec3d t = q - y[0]; r = t*E1; s = t*E2; return q; } //----------------------------------------------------------------------------- // project onto a quadrilateral surface. bool project2quad(vec3d* y, vec3d x, double& r, double& s, vec3d& q) { double R[2], u[2], D; double gr[4] = {-1, +1, +1, -1}; double gs[4] = {-1, -1, +1, +1}; double H[4], Hr[4], Hs[4], Hrs[4]; int i, j; int NMAX = 50, n=0; // evaulate scalar products double xy[4] = {x*y[0], x*y[1], x*y[2], x*y[3]}; double yy[4][4]; yy[0][0] = y[0]*y[0]; yy[1][1] = y[1]*y[1]; yy[2][2] = y[2]*y[2]; yy[3][3] = y[3]*y[3]; yy[0][1] = yy[1][0] = y[0]*y[1]; yy[0][2] = yy[2][0] = y[0]*y[2]; yy[0][3] = yy[3][0] = y[0]*y[3]; yy[1][2] = yy[2][1] = y[1]*y[2]; yy[1][3] = yy[3][1] = y[1]*y[3]; yy[2][3] = yy[3][2] = y[2]*y[3]; // loop until converged bool bconv = false; double normu; do { // evaluate shape functions and shape function derivatives. for (i=0; i<4; ++i) { H[i] = 0.25*(1+gr[i]*r)*(1+gs[i]*s); Hr[i] = 0.25*gr[i]*( 1 + gs[i]*s ); Hs[i] = 0.25*gs[i]*( 1 + gr[i]*r ); Hrs[i] = 0.25*gr[i]*gs[i]; } // set up the system of equations R[0] = R[1] = 0; double A[2][2] = {0}; for (i=0; i<4; ++i) { R[0] -= (xy[i])*Hr[i]; R[1] -= (xy[i])*Hs[i]; A[0][1] += (xy[i])*Hrs[i]; A[1][0] += (xy[i])*Hrs[i]; for (j=0; j<4; ++j) { double yij = yy[i][j]; R[0] -= -H[j]*Hr[i]*(yij); R[1] -= -H[j]*Hs[i]*(yij); A[0][0] -= (yij)*(Hr[i]*Hr[j]); A[1][1] -= (yij)*(Hs[i]*Hs[j]); A[0][1] -= (yij)*(Hr[i]*Hs[j]+Hrs[i]*H[j]); A[1][0] -= (yij)*(Hs[i]*Hr[j]+Hrs[i]*H[j]); } } // determinant of A D = A[0][0]*A[1][1] - A[0][1]*A[1][0]; // solve for u = A^(-1)*R u[0] = (A[1][1]*R[0] - A[0][1]*R[1])/D; u[1] = (A[0][0]*R[1] - A[1][0]*R[0])/D; // calculate displacement norm normu = u[0]*u[0]+u[1]*u[1]; // check for convergence bconv = ((normu < 1e-10)); if (!bconv && (n <= NMAX)) { // Don't update if converged otherwise the point q // does not correspond with the current values for (r,s) r += u[0]; s += u[1]; ++n; } else break; } while (1); // evaluate q q = y[0]*H[0] + y[1]*H[1] + y[2]*H[2] + y[3]*H[3]; return bconv; } //----------------------------------------------------------------------------- // project to general surface element. bool project2surf(FESurfaceElement& el, vec3d* y, vec3d x, double& r, double& s, vec3d& q) { double Q[2], u[2], D; const int NE = FEElement::MAX_NODES; double H[NE], Hr[NE], Hs[NE], Hrr[NE], Hss[NE], Hrs[NE]; int i, j; int NMAX = 50, n=0; // get number of nodes int ne = el.Nodes(); // evaulate scalar products double xy[NE]; double yy[NE][NE]; for (i=0; i<ne; ++i) { xy[i] = x*y[i]; yy[i][i] = y[i]*y[i]; for (j=i+1; j<ne; ++j) { yy[i][j] = yy[j][i] = y[i]*y[j]; } } // loop until converged bool bconv = false; double normu; do { // evaluate shape functions and shape function derivatives. el.shape_fnc(H, r, s); el.shape_deriv(Hr, Hs, r, s); el.shape_deriv2(Hrr, Hrs, Hss, r, s); // set up the system of equations Q[0] = Q[1] = 0; double A[2][2] = {0}; for (i=0; i<ne; ++i) { Q[0] -= (xy[i])*Hr[i]; Q[1] -= (xy[i])*Hs[i]; A[0][0] += (xy[i])*Hrr[i]; A[0][1] += (xy[i])*Hrs[i]; A[1][0] += (xy[i])*Hrs[i]; A[1][1] += (xy[i])*Hss[i]; for (j=0; j<ne; ++j) { double yij = yy[i][j]; Q[0] -= -H[j]*Hr[i]*(yij); Q[1] -= -H[j]*Hs[i]*(yij); A[0][0] -= (yij)*(H[i]*Hrr[j] + Hr[i]*Hr[j]); A[1][1] -= (yij)*(H[i]*Hss[j] + Hs[i]*Hs[j]); A[0][1] -= (yij)*(Hrs[i]*H[j] + Hr[i]*Hs[j]); A[1][0] -= (yij)*(Hrs[i]*H[j] + Hs[i]*Hr[j]); } } // determinant of A D = A[0][0]*A[1][1] - A[0][1]*A[1][0]; // solve for u = A^(-1)*R u[0] = (A[1][1]*Q[0] - A[0][1]*Q[1])/D; u[1] = (A[0][0]*Q[1] - A[1][0]*Q[0])/D; // calculate displacement norm normu = u[0]*u[0]+u[1]*u[1]; // check for convergence bconv = ((normu < 1e-10)); if (!bconv && (n <= NMAX)) { // Don't update if converged otherwise the point q // does not correspond with the current values for (r,s) r += u[0]; s += u[1]; ++n; } else break; } while (1); // evaluate q q = vec3d(0,0,0); for (int i=0; i<ne; ++i) q += y[i]*H[i]; return bconv; } //----------------------------------------------------------------------------- vec3d FESurface::Position(FESurfaceElement& el, double r, double s) { // get the mesh to which this surface belongs FEMesh& mesh = *m_pMesh; // number of element nodes int ne = el.Nodes(); // get the elements nodal positions vec3d y[FEElement::MAX_NODES]; if (!m_bshellb) for (int i = 0; i<ne; ++i) y[i] = mesh.Node(el.m_node[i]).m_rt; else for (int i = 0; i<ne; ++i) y[i] = mesh.Node(el.m_node[i]).st(); double H[FEElement::MAX_NODES]; el.shape_fnc(H, r, s); vec3d q(0,0,0); for (int i=0; i<ne; ++i) { q += y[i]*H[i]; } return q; } //----------------------------------------------------------------------------- //! This function calculates the position of integration point n vec3d FESurface::Position(FESurfaceElement &el, int n) { // get the mesh to which this surface belongs FEMesh& mesh = *m_pMesh; // number of element nodes int ne = el.Nodes(); // get the elements nodal positions vec3d y[FEElement::MAX_NODES]; if (!m_bshellb) for (int i = 0; i<ne; ++i) y[i] = mesh.Node(el.m_node[i]).m_rt; else for (int i = 0; i<ne; ++i) y[i] = mesh.Node(el.m_node[i]).st(); double* H = el.H(n); vec3d q(0,0,0); for (int i=0; i<ne; ++i) { q += y[i]*H[i]; } return q; } //----------------------------------------------------------------------------- void FESurface::NodalCoordinates(FESurfaceElement& el, vec3d* re) { int ne = el.Nodes(); if (!m_bshellb) for (int i = 0; i < ne; ++i) re[i] = Node(el.m_lnode[i]).m_rt; else for (int i = 0; i < ne; ++i) re[i] = Node(el.m_lnode[i]).st(); } //----------------------------------------------------------------------------- void FESurface::PreviousNodalCoordinates(FESurfaceElement& el, vec3d* re) { int ne = el.Nodes(); if (!m_bshellb) for (int i = 0; i < ne; ++i) re[i] = Node(el.m_lnode[i]).m_rp; else for (int i = 0; i < ne; ++i) re[i] = Node(el.m_lnode[i]).sp(); } //----------------------------------------------------------------------------- //! detect face normal relative to element: //! return +1 if face points away from element, -1 if face points into element, 0 if invalid solution found double FESurface::FacePointing(FESurfaceElement& se, FEElement& el) { FEMesh& mesh = *GetMesh(); // get point on surface element vec3d sp = Position(se, 0,0); // get surface normal at that point; vec3d sn = SurfaceNormal(se, 0,0); // check if element attached to this surface element is solid or shell FESolidElement* sel = dynamic_cast<FESolidElement*>(&el); FEShellElement* shl = dynamic_cast<FEShellElement*>(&el); // get centroid of element el vec3d c(0,0,0); if (sel) { for (int i=0; i<sel->Nodes(); ++i) { FENode& node = mesh.Node(sel->m_node[i]); c += node.m_rt; } c /= sel->Nodes(); } else if (shl) { for (int i=0; i<sel->Nodes(); ++i) { FENode& node = mesh.Node(sel->m_node[i]); c += node.m_rt; c += node.st(); } c /= (2*sel->Nodes()); } else return 0; // project vector from centroid to surface point onto surface normal double d = (sp - c)*sn; if (d > 0) return 1.0; else if (d < 0) return -1.0; else return 0.0; } //----------------------------------------------------------------------------- //! This function calculates the projection of x on the surface element el. //! It does this by finding the solution of the nonlinear equation (x-y)*y,[a]=0, //! where the comma denotes differentation and a ranges from 1 to 2. //! The system is solved using the Newton-Raphson method. //! The surface element may be either a quad or a triangular element. vec3d FESurface::ProjectToSurface(FESurfaceElement& el, vec3d x, double& r, double& s) { // get the mesh to which this surface belongs FEMesh& mesh = *m_pMesh; // number of element nodes int ne = el.Nodes(); // get the elements nodal positions vec3d y[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<ne; ++i) y[i] = mesh.Node(el.m_node[i]).m_rt; else for (int i=0; i<ne; ++i) y[i] = mesh.Node(el.m_node[i]).st(); // calculate normal projection of x onto element vec3d q; switch (ne) { case 3: q = project2tri(y, x, r, s); break; case 4: // see if we get lucky if (project2quad(y, x, r, s, q) == false) { // the direct projection failed, so we'll try it more incrementally vec3d x0 = (y[0]+y[1]+y[2]+y[3])*0.25; r = s = 0; bool b = project2quad(y, x0, r, s, q); assert(b); double w = 0.5; int l = 1, N = 0, NMAX = 20; do { vec3d xi = x0*(1.0 - w) + x*w; b = project2quad(y, xi, r, s, q); if (b) { --l; if (l == 0) { x0 = xi; w = 1.0; } else w *= 2.0; } else { ++l; w *= 0.5; } ++N; } while ((l >= 0) && (N<=NMAX) && (w>0.1)); } break; case 6: case 7: case 8: case 9: if (project2surf(el, y, x, r, s, q)==false) { // assert(false); } break; default: assert(false); } return q; } //----------------------------------------------------------------------------- //! This function calculates the area of a surface element double FESurface::FaceArea(FESurfaceElement& el) { // get the mesh to which this surface belongs FEMesh& mesh = *m_pMesh; // get the number of nodes int nint = el.GaussPoints(); int neln = el.Nodes(); // get the initial nodes vec3d r0[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<neln; ++i) r0[i] = mesh.Node(el.m_node[i]).m_r0; else for (int i=0; i<neln; ++i) r0[i] = mesh.Node(el.m_node[i]).s0(); // get the integration weights double* w = el.GaussWeights(); double *Gr, *Gs; vec3d dxr, dxs; double detJ; double area = 0; int n, k; for (n=0; n<nint; ++n) { Gr = el.Gr(n); Gs = el.Gs(n); // calculate jacobian dxr = dxs = vec3d(0,0,0); for (k=0; k<neln; ++k) { dxr.x += Gr[k]*r0[k].x; dxr.y += Gr[k]*r0[k].y; dxr.z += Gr[k]*r0[k].z; dxs.x += Gs[k]*r0[k].x; dxs.y += Gs[k]*r0[k].y; dxs.z += Gs[k]*r0[k].z; } detJ = (dxr ^ dxs).norm(); area += w[n]*detJ; } return area; } //----------------------------------------------------------------------------- //! This function calculates the area of a surface element double FESurface::CurrentFaceArea(FESurfaceElement& el) { // get the mesh to which this surface belongs FEMesh& mesh = *m_pMesh; // get the number of nodes int nint = el.GaussPoints(); int neln = el.Nodes(); // get the initial nodes vec3d rt[FEElement::MAX_NODES]; if (!m_bshellb) for (int i = 0; i < neln; ++i) rt[i] = mesh.Node(el.m_node[i]).m_rt; else for (int i = 0; i < neln; ++i) rt[i] = mesh.Node(el.m_node[i]).st(); // get the integration weights double* w = el.GaussWeights(); double* Gr, * Gs; vec3d dxr, dxs; double detJ; double area = 0; int n, k; for (n = 0; n < nint; ++n) { Gr = el.Gr(n); Gs = el.Gs(n); // calculate jacobian dxr = dxs = vec3d(0, 0, 0); for (k = 0; k < neln; ++k) { dxr.x += Gr[k] * rt[k].x; dxr.y += Gr[k] * rt[k].y; dxr.z += Gr[k] * rt[k].z; dxs.x += Gs[k] * rt[k].x; dxs.y += Gs[k] * rt[k].y; dxs.z += Gs[k] * rt[k].z; } detJ = (dxr ^ dxs).norm(); area += w[n] * detJ; } return area; } //----------------------------------------------------------------------------- //! Calculate the max element size. double FESurface::MaxElementSize() { FEMesh& mesh = *m_pMesh; double h2 = 0.0; int NS = Elements(); for (int m=0; m<NS; ++m) { FESurfaceElement& e = Element(m); int n = e.Nodes(); for (int i=0; i<n; ++i) for (int j=i+1; j<n; ++j) { vec3d& a = mesh.Node(e.m_node[i]).m_rt; vec3d& b = mesh.Node(e.m_node[j]).m_rt; double L2 = (b - a)*(b - a); if (L2 > h2) h2 = L2; } } return sqrt(h2); } //----------------------------------------------------------------------------- //! Calculates the metric tensor at the point with surface coordinates (r,s) //! \todo Perhaps I should place this function in the element class. mat2d FESurface::Metric0(FESurfaceElement& el, double r, double s) { // nr of element nodes int neln = el.Nodes(); // element nodes vec3d r0[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<neln; ++i) r0[i] = m_pMesh->Node(el.m_node[i]).m_r0; else for (int i=0; i<neln; ++i) r0[i] = m_pMesh->Node(el.m_node[i]).s0(); // shape function derivatives double Hr[FEElement::MAX_NODES], Hs[FEElement::MAX_NODES]; // get the shape function values at this node el.shape_deriv(Hr, Hs, r, s); // get the tangent vectors vec3d t1(0,0,0); vec3d t2(0,0,0); for (int k=0; k<neln; ++k) { t1 += r0[k]*Hr[k]; t2 += r0[k]*Hs[k]; } // calculate metric tensor return mat2d(t1*t1, t1*t2, t2*t1, t2*t2); } //----------------------------------------------------------------------------- //! Calculates the metric tensor at the point with surface coordinates (r,s) //! \todo Perhaps I should place this function in the element class. mat2d FESurface::Metric(FESurfaceElement& el, double r, double s) { // nr of element nodes int neln = el.Nodes(); // element nodes vec3d rt[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<neln; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).m_rt; else for (int i=0; i<neln; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).st(); // shape function derivatives double Hr[FEElement::MAX_NODES], Hs[FEElement::MAX_NODES]; // get the shape function values at this node el.shape_deriv(Hr, Hs, r, s); // get the tangent vectors vec3d t1(0,0,0); vec3d t2(0,0,0); for (int k=0; k<neln; ++k) { t1 += rt[k]*Hr[k]; t2 += rt[k]*Hs[k]; } // calculate metric tensor return mat2d(t1*t1, t1*t2, t2*t1, t2*t2); } //----------------------------------------------------------------------------- //! Calculates the metric tensor at an integration point //! \todo Perhaps I should place this function in the element class. mat2d FESurface::Metric(const FESurfaceElement& el, int n) const { // nr of element nodes int neln = el.Nodes(); // element nodes vec3d rt[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<neln; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).m_rt; else for (int i=0; i<neln; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).st(); // get the shape function derivatives at this integration point double* Hr = el.Gr(n); double* Hs = el.Gs(n); // get the tangent vectors vec3d t1(0,0,0); vec3d t2(0,0,0); for (int k=0; k<neln; ++k) { t1 += rt[k]*Hr[k]; t2 += rt[k]*Hs[k]; } // calculate metric tensor return mat2d(t1*t1, t1*t2, t2*t1, t2*t2); } //----------------------------------------------------------------------------- //! Calculates the metric tensor at an integration point at previous time //! \todo Perhaps I should place this function in the element class. mat2d FESurface::MetricP(FESurfaceElement& el, int n) { // nr of element nodes int neln = el.Nodes(); // element nodes vec3d rp[FEElement::MAX_NODES]; for (int i=0; i<neln; ++i) rp[i] = m_pMesh->Node(el.m_node[i]).m_rp; // get the shape function derivatives at this integration point double* Hr = el.Gr(n); double* Hs = el.Gs(n); // get the tangent vectors vec3d t1(0,0,0); vec3d t2(0,0,0); for (int k=0; k<neln; ++k) { t1 += rp[k]*Hr[k]; t2 += rp[k]*Hs[k]; } // calculate metric tensor return mat2d(t1*t1, t1*t2, t2*t1, t2*t2); } //----------------------------------------------------------------------------- //! This function calculates the global location of an integration point in its reference configuration //! vec3d FESurface::Local2Global0(FESurfaceElement &el, int n) { FEMesh& m = *m_pMesh; // get the shape functions at this integration point double* H = el.H(n); // calculate the location vec3d r(0); int ne = el.Nodes(); if (!m_bshellb) for (int i=0; i<ne; ++i) r += m.Node(el.m_node[i]).m_r0*H[i]; else for (int i=0; i<ne; ++i) r += m.Node(el.m_node[i]).s0()*H[i]; return r; } //----------------------------------------------------------------------------- //! Given an element an the natural coordinates of a point in this element, this //! function returns the global position vector. vec3d FESurface::Local2Global(FESurfaceElement &el, double r, double s) { // get the mesh FEMesh& mesh = *m_pMesh; // get the coordinates of the element nodes int ne = el.Nodes(); vec3d y[FEElement::MAX_NODES]; if (!m_bshellb) for (int l=0; l<ne; ++l) y[l] = mesh.Node(el.m_node[l]).m_rt; else for (int l=0; l<ne; ++l) y[l] = mesh.Node(el.m_node[l]).st(); // calculate the element position return el.eval(y, r, s); } //----------------------------------------------------------------------------- //! This function calculates the global location of an integration point //! vec3d FESurface::Local2Global(FESurfaceElement &el, int n) { FEMesh& m = *m_pMesh; // get the shape functions at this integration point double* H = el.H(n); // calculate the location vec3d r(0); int ne = el.Nodes(); if (!m_bshellb) for (int i=0; i<ne; ++i) r += m.Node(el.m_node[i]).m_rt*H[i]; else for (int i=0; i<ne; ++i) r += m.Node(el.m_node[i]).st()*H[i]; return r; } //----------------------------------------------------------------------------- //! Given an element an the natural coordinates of a point in this element, this //! function returns the global position vector at the previous time. vec3d FESurface::Local2GlobalP(FESurfaceElement &el, double r, double s) { // get the mesh FEMesh& mesh = *m_pMesh; // get the coordinates of the element nodes int ne = el.Nodes(); vec3d y[FEElement::MAX_NODES]; for (int l=0; l<ne; ++l) y[l] = mesh.Node(el.m_node[l]).m_rp; // calculate the element position return el.eval(y, r, s); } //----------------------------------------------------------------------------- //! This function calculates the global location of an integration point //! vec3d FESurface::Local2GlobalP(FESurfaceElement &el, int n) { FEMesh& m = *m_pMesh; // get the shape functions at this integration point double* H = el.H(n); // calculate the location vec3d r; int ne = el.Nodes(); for (int i=0; i<ne; ++i) r += m.Node(el.m_node[i]).m_rp*H[i]; return r; } //----------------------------------------------------------------------------- //! This function calculates the normal of a surface element at integration //! point n vec3d FESurface::SurfaceNormal(const FESurfaceElement &el, int n) const { FEMesh& m = *m_pMesh; // get the shape function derivatives at this integration point double* Hr = el.Gr(n); double* Hs = el.Gs(n); // get the coordinates of the element nodes int ne = el.Nodes(); vec3d y[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<ne; ++i) y[i] = m.Node(el.m_node[i]).m_rt; else for (int i=0; i<ne; ++i) y[i] = m.Node(el.m_node[i]).st(); // calculate the tangents vec3d xr, xs; for (int i=0; i<ne; ++i) { xr += y[i]*Hr[i]; xs += y[i]*Hs[i]; } // calculate the normal vec3d np = xr ^ xs; np.unit(); if (m_bshellb) np = -np; return np; } //----------------------------------------------------------------------------- //! This function calculates the normal of a surface element at the natural //! coordinates (r,s) vec3d FESurface::SurfaceNormal(FESurfaceElement &el, double r, double s) const { int l; FEMesh& mesh = *m_pMesh; // get the coordinates of the element nodes int ne = el.Nodes(); vec3d y[FEElement::MAX_NODES]; if (!m_bshellb) for (l=0; l<ne; ++l) y[l] = mesh.Node(el.m_node[l]).m_rt; else for (l=0; l<ne; ++l) y[l] = mesh.Node(el.m_node[l]).st(); // set up shape functions and derivatives double Hr[FEElement::MAX_NODES], Hs[FEElement::MAX_NODES]; el.shape_deriv(Hr, Hs, r, s); // calculate the element tangents vec3d xr(0,0,0), xs; for (l=0; l<ne; ++l) { xr += y[l]*Hr[l]; xs += y[l]*Hs[l]; } // calculate the normal vec3d np = xr ^ xs; np.unit(); if (m_bshellb) np = -np; return np; } //----------------------------------------------------------------------------- //! 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 FESurface::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(); } //----------------------------------------------------------------------------- //! This function checks whether the point with natural coordinates (r,s) is //! inside the element, within a tolerance of tol. bool FESurface::IsInsideElement(FESurfaceElement& el, double r, double s, double tol) { int ne = el.Nodes(); switch (ne) { case 4: case 8: case 9: { // check quads if ((r >= -1-tol) && (r <= 1+tol) && (s >= -1-tol) && (s <= 1+tol)) return true; else return false; } break; case 3: case 6: case 7: { // check triangles if ((r >= -tol) && (s >= -tol) && (r+s <= 1+tol)) return true; else return false; } break; } assert(false); return false; } //----------------------------------------------------------------------------- //! This function calculates the covariant base vectors of a surface element //! at an integration point void FESurface::CoBaseVectors(FESurfaceElement& el, double r, double s, vec3d t[2]) { FEMesh& m = *m_pMesh; // get the nr of nodes int n = el.Nodes(); // get the shape function derivatives double Hr[FEElement::MAX_NODES], Hs[FEElement::MAX_NODES]; el.shape_deriv(Hr, Hs, r, s); t[0] = t[1] = vec3d(0,0,0); if (!m_bshellb) { for (int i=0; i<n; ++i) { t[0] += m.Node(el.m_node[i]).m_rt*Hr[i]; t[1] += m.Node(el.m_node[i]).m_rt*Hs[i]; } } else { for (int i=0; i<n; ++i) { t[0] -= m.Node(el.m_node[i]).st()*Hr[i]; t[1] -= m.Node(el.m_node[i]).st()*Hs[i]; } } } //----------------------------------------------------------------------------- //! This function calculates the covariant base vectors of a surface element //! at an integration point void FESurface::CoBaseVectors(const FESurfaceElement& el, int j, vec3d t[2]) const { FEMesh& m = *m_pMesh; // get the nr of nodes int n = el.Nodes(); // get the shape function derivatives double* Hr = el.Gr(j); double* Hs = el.Gs(j); t[0] = t[1] = vec3d(0,0,0); if (!m_bshellb) { for (int i=0; i<n; ++i) { t[0] += m.Node(el.m_node[i]).m_rt*Hr[i]; t[1] += m.Node(el.m_node[i]).m_rt*Hs[i]; } } else { for (int i=0; i<n; ++i) { t[0] -= m.Node(el.m_node[i]).st()*Hr[i]; t[1] -= m.Node(el.m_node[i]).st()*Hs[i]; } } } //----------------------------------------------------------------------------- //! This function calculates the covariant base vectors of a surface element //! at an integration point at previous time step void FESurface::CoBaseVectorsP(FESurfaceElement& el, int j, vec3d t[2]) { FEMesh& m = *m_pMesh; // get the nr of nodes int n = el.Nodes(); // get the shape function derivatives double* Hr = el.Gr(j); double* Hs = el.Gs(j); t[0] = t[1] = vec3d(0,0,0); for (int i=0; i<n; ++i) { t[0] += m.Node(el.m_node[i]).m_rp*Hr[i]; t[1] += m.Node(el.m_node[i]).m_rp*Hs[i]; } } //----------------------------------------------------------------------------- //! This function calculates the covariant base vectors of a surface element //! at an integration point in the reference configuration void FESurface::CoBaseVectors0(const FESurfaceElement& el, int j, vec3d t[2]) const { FEMesh& m = *m_pMesh; // get the nr of nodes int n = el.Nodes(); // get the shape function derivatives double* Hr = el.Gr(j); double* Hs = el.Gs(j); t[0] = t[1] = vec3d(0,0,0); if (!m_bshellb) { for (int i=0; i<n; ++i) { t[0] += m.Node(el.m_node[i]).m_r0*Hr[i]; t[1] += m.Node(el.m_node[i]).m_r0*Hs[i]; } } else { for (int i=0; i<n; ++i) { t[0] -= m.Node(el.m_node[i]).s0()*Hr[i]; t[1] -= m.Node(el.m_node[i]).s0()*Hs[i]; } } } //----------------------------------------------------------------------------- //! This function calculates the covariant base vectors of a surface element //! at the natural coordinates (r,s) void FESurface::CoBaseVectors0(FESurfaceElement &el, double r, double s, vec3d t[2]) { int i; const int MN = FEElement::MAX_NODES; vec3d y[MN]; double H0[MN], H1[MN]; int n = el.Nodes(); if (!m_bshellb) for (i=0; i<n; ++i) y[i] = m_pMesh->Node(el.m_node[i]).m_r0; else for (i=0; i<n; ++i) y[i] = m_pMesh->Node(el.m_node[i]).s0(); el.shape_deriv(H0, H1, r, s); t[0] = t[1] = vec3d(0,0,0); for (i=0; i<n; ++i) { t[0] += y[i]*H0[i]; t[1] += y[i]*H1[i]; } } //----------------------------------------------------------------------------- void FESurface::ContraBaseVectors(const FESurfaceElement& el, int j, vec3d t[2]) const { vec3d e[2]; CoBaseVectors(el, j, e); mat2d M = Metric(el, j); mat2d Mi = M.inverse(); t[0] = e[0]*Mi[0][0] + e[1]*Mi[0][1]; t[1] = e[0]*Mi[1][0] + e[1]*Mi[1][1]; } //----------------------------------------------------------------------------- void FESurface::ContraBaseVectorsP(FESurfaceElement& el, int j, vec3d t[2]) { vec3d e[2]; CoBaseVectorsP(el, j, e); mat2d M = MetricP(el, j); mat2d Mi = M.inverse(); t[0] = e[0]*Mi[0][0] + e[1]*Mi[0][1]; t[1] = e[0]*Mi[1][0] + e[1]*Mi[1][1]; } //----------------------------------------------------------------------------- void FESurface::ContraBaseVectors(FESurfaceElement& el, double r, double s, vec3d t[2]) { vec3d e[2]; CoBaseVectors(el, r, s, e); mat2d M = Metric(el, r, s); mat2d Mi = M.inverse(); t[0] = e[0]*Mi[0][0] + e[1]*Mi[0][1]; t[1] = e[0]*Mi[1][0] + e[1]*Mi[1][1]; } //----------------------------------------------------------------------------- void FESurface::ContraBaseVectors0(FESurfaceElement& el, double r, double s, vec3d t[2]) { vec3d e[2]; CoBaseVectors0(el, r, s, e); mat2d M = Metric0(el, r, s); mat2d Mi = M.inverse(); t[0] = e[0]*Mi[0][0] + e[1]*Mi[0][1]; t[1] = e[0]*Mi[1][0] + e[1]*Mi[1][1]; } //----------------------------------------------------------------------------- double FESurface::jac0(FESurfaceElement &el, int n) { const int nseln = el.Nodes(); vec3d r0[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<nseln; ++i) r0[i] = GetMesh()->Node(el.m_node[i]).m_r0; else for (int i=0; i<nseln; ++i) r0[i] = GetMesh()->Node(el.m_node[i]).s0(); double* Gr = el.Gr(n); double* Gs = el.Gs(n); vec3d dxr(0,0,0), dxs(0,0,0); for (int k=0; k<nseln; ++k) { dxr.x += Gr[k]*r0[k].x; dxr.y += Gr[k]*r0[k].y; dxr.z += Gr[k]*r0[k].z; dxs.x += Gs[k]*r0[k].x; dxs.y += Gs[k]*r0[k].y; dxs.z += Gs[k]*r0[k].z; } return (dxr ^ dxs).norm(); } //----------------------------------------------------------------------------- double FESurface::jac0(const FESurfaceElement &el, int n, vec3d& nu) { const int nseln = el.Nodes(); vec3d r0[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<nseln; ++i) r0[i] = GetMesh()->Node(el.m_node[i]).m_r0; else for (int i=0; i<nseln; ++i) r0[i] = GetMesh()->Node(el.m_node[i]).s0(); double* Gr = el.Gr(n); double* Gs = el.Gs(n); vec3d dxr(0,0,0), dxs(0,0,0); for (int k=0; k<nseln; ++k) { dxr.x += Gr[k]*r0[k].x; dxr.y += Gr[k]*r0[k].y; dxr.z += Gr[k]*r0[k].z; dxs.x += Gs[k]*r0[k].x; dxs.y += Gs[k]*r0[k].y; dxs.z += Gs[k]*r0[k].z; } nu = dxr ^ dxs; return nu.unit(); } //----------------------------------------------------------------------------- // This function calculates the intersection of a ray with a triangle // and returns true if the ray intersects the triangle. // bool IntersectTri(vec3d* y, vec3d r, vec3d n, double rs[2], double& g, double eps) { vec3d e[2], E[2]; mat2d G; // create base vectors on triangle e[0] = y[1]-y[0]; e[1] = y[2]-y[0]; // create triangle normal vec3d m = e[0]^e[1]; m.unit(); double d = n*m; // if (d != 0) // normals should be pointing opposite to each other for valid contact if (d < 0) { // distance from r to plane of triangle g = m*(y[0] - r)/d; // intersection point with plane of triangle vec3d q = r + n*g; // next, we decompose q into its components // in the triangle basis // we need to create the dual basis // first, we calculate the metric tensor G[0][0] = e[0]*e[0]; G[0][1] = e[0]*e[1]; G[1][0] = e[1]*e[0]; G[1][1] = e[1]*e[1]; // and its inverse mat2d Gi = G.inverse(); // build dual basis E[0] = e[0]*Gi[0][0] + e[1]*Gi[0][1]; E[1] = e[0]*Gi[1][0] + e[1]*Gi[1][1]; // get the components rs[0] = E[0]*(q - y[0]); rs[1] = E[1]*(q - y[0]); // see if the intersection point is inside the triangle if ((rs[0] >= -eps) && (rs[1] >= -eps) && (rs[0]+rs[1] <= 1+eps)) return true; } return false; } //----------------------------------------------------------------------------- //! This function calculates the intersection of a ray with a quad //! and returns true if the ray intersected. //! bool IntersectQuad(vec3d* y, vec3d r, vec3d n, double rs[2], double& g, double eps, bool checkNormal = true) { // first we're going to see if the ray intersects the two subtriangles vec3d x1[3], x2[3]; x1[0] = y[0]; x2[0] = y[2]; x1[1] = y[1]; x2[1] = y[3]; x1[2] = y[3]; x2[2] = y[1]; bool b = false; double rp = 0, sp = 0; if (IntersectTri(x1, r, n, rs, g, eps)) { // we've intersected the first triangle b = true; rp = -1.0 + 2.0*rs[0]; sp = -1.0 + 2.0*rs[1]; } else if (IntersectTri(x2, r, n, rs, g, eps)) { // we've intersected the second triangle b = true; rp = 1.0 - 2.0*rs[0]; sp = 1.0 - 2.0*rs[1]; } // if one of the triangels was intersected, // we calculate a more accurate projection if (b) { mat3d A; vec3d dx; vec3d F, F1, F2, F3; double H[4], H1[4], H2[4]; double l1 = rp; double l2 = sp; double l3 = g; int nn = 0; int maxn = 5; do { // shape functions of quad H[0] = 0.25*(1 - l1)*(1 - l2); H[1] = 0.25*(1 + l1)*(1 - l2); H[2] = 0.25*(1 + l1)*(1 + l2); H[3] = 0.25*(1 - l1)*(1 + l2); // shape function derivatives H1[0] = -0.25*(1 - l2); H2[0] = -0.25*(1 - l1); H1[1] = 0.25*(1 - l2); H2[1] = -0.25*(1 + l1); H1[2] = 0.25*(1 + l2); H2[2] = 0.25*(1 + l1); H1[3] = -0.25*(1 + l2); H2[3] = 0.25*(1 - l1); // calculate residual F = r + n*l3 - y[0]*H[0] - y[1]*H[1] - y[2]*H[2] - y[3]*H[3]; // residual derivatives F1 = - y[0]*H1[0] - y[1]*H1[1] - y[2]*H1[2] - y[3]*H1[3]; F2 = - y[0]*H2[0] - y[1]*H2[1] - y[2]*H2[2] - y[3]*H2[3]; F3 = n; // set up the tangent matrix A[0][0] = F1.x; A[0][1] = F2.x; A[0][2] = F3.x; A[1][0] = F1.y; A[1][1] = F2.y; A[1][2] = F3.y; A[2][0] = F1.z; A[2][1] = F2.z; A[2][2] = F3.z; // calculate solution increment mat3d Ai = A.inverse(); dx = -(Ai*F); // update solution l1 += dx.x; l2 += dx.y; l3 += dx.z; ++nn; } while ((dx.norm() > 1e-7) && (nn < maxn)); if (nn == maxn) return false; // store results rs[0] = l1; rs[1] = l2; g = l3; if (checkNormal) { vec3d nu2 = F1 ^ F2; nu2.unit(); double cosq = n * nu2; if (cosq > 0) return false; } // see if the point is inside the quad if ((rs[0] >= -1-eps) && (rs[0] <= 1+eps) && (rs[1] >= -1-eps) && (rs[1] <= 1+eps)) return true; } return false; } //----------------------------------------------------------------------------- //! This function calculates the intersection of a ray with a quad //! and returns true if the ray intersected. //! bool IntersectQuad8(vec3d* y, vec3d r, vec3d n, double rs[2], double& g, double eps) { mat3d A; vec3d dx; vec3d F, F1, F2, F3; double H[8], H1[8], H2[8]; double l1 = 0; double l2 = 0; double l3 = 0; int nn = 0; int maxn = 10; do { // shape functions of quad H[4] = 0.5*(1 - l1*l1)*(1 - l2); H[5] = 0.5*(1 - l2*l2)*(1 + l1); H[6] = 0.5*(1 - l1*l1)*(1 + l2); H[7] = 0.5*(1 - l2*l2)*(1 - l1); H[0] = 0.25*(1 - l1)*(1 - l2) - 0.5*(H[4] + H[7]); H[1] = 0.25*(1 + l1)*(1 - l2) - 0.5*(H[4] + H[5]); H[2] = 0.25*(1 + l1)*(1 + l2) - 0.5*(H[5] + H[6]); H[3] = 0.25*(1 - l1)*(1 + l2) - 0.5*(H[6] + H[7]); // shape function derivatives H1[4] = -l1*(1 - l2); H1[5] = 0.5*(1 - l2*l2); H1[6] = -l1*(1 + l2); H1[7] = -0.5*(1 - l2*l2); H1[0] = -0.25*(1 - l2) - 0.5*(H1[4] + H1[7]); H1[1] = 0.25*(1 - l2) - 0.5*(H1[4] + H1[5]); H1[2] = 0.25*(1 + l2) - 0.5*(H1[5] + H1[6]); H1[3] = -0.25*(1 + l2) - 0.5*(H1[6] + H1[7]); H2[4] = -0.5*(1 - l1*l1); H2[5] = -l2*(1 + l1); H2[6] = 0.5*(1 - l1*l1); H2[7] = -l2*(1 - l1); H2[0] = -0.25*(1 - l1) - 0.5*(H2[4] + H2[7]); H2[1] = -0.25*(1 + l1) - 0.5*(H2[4] + H2[5]); H2[2] = 0.25*(1 + l1) - 0.5*(H2[5] + H2[6]); H2[3] = 0.25*(1 - l1) - 0.5*(H2[6] + H2[7]); // calculate residual F = r + n*l3 - y[0]*H[0] - y[1]*H[1] - y[2]*H[2] - y[3]*H[3] - y[4]*H[4] - y[5]*H[5] - y[6]*H[6] - y[7]*H[7]; // residual derivatives F1 = - y[0]*H1[0] - y[1]*H1[1] - y[2]*H1[2] - y[3]*H1[3] - y[4]*H1[4] - y[5]*H1[5] - y[6]*H1[6] - y[7]*H1[7]; F2 = - y[0]*H2[0] - y[1]*H2[1] - y[2]*H2[2] - y[3]*H2[3] - y[4]*H2[4] - y[5]*H2[5] - y[6]*H2[6] - y[7]*H2[7]; F3 = n; // set up the tangent matrix A[0][0] = F1.x; A[0][1] = F2.x; A[0][2] = F3.x; A[1][0] = F1.y; A[1][1] = F2.y; A[1][2] = F3.y; A[2][0] = F1.z; A[2][1] = F2.z; A[2][2] = F3.z; // calculate solution increment mat3d Ai = A.inverse(); dx = -(Ai*F); // update solution l1 += dx.x; l2 += dx.y; l3 += dx.z; ++nn; } while ((dx.norm() > 1e-7) && (nn < maxn)); if (nn == maxn) return false; // store results rs[0] = l1; rs[1] = l2; g = l3; vec3d nu2 = F1 ^ F2; nu2.unit(); double cosq = n*nu2; if (cosq > 0) return false; // see if the point is inside the quad if ((rs[0] >= -1-eps) && (rs[0] <= 1+eps) && (rs[1] >= -1-eps) && (rs[1] <= 1+eps)) return true; return false; } //----------------------------------------------------------------------------- //! This function calculates the intersection of a ray with a quad //! and returns true if the ray intersected. //! bool IntersectQuad9(vec3d* y, vec3d r, vec3d n, double rs[2], double& g, double eps) { mat3d A; vec3d dx; vec3d F, F1, F2, F3; double H[9], H1[9], H2[9]; double l1 = 0; double l2 = 0; double l3 = 0; int nn = 0; int maxn = 10; do { // shape functions of quad double R[3] = {0.5*l1*(l1-1.0), 0.5*l1*(l1+1.0), 1.0 - l1*l1}; double S[3] = {0.5*l2*(l2-1.0), 0.5*l2*(l2+1.0), 1.0 - l2*l2}; double DR[3] = {l1-0.5, l1+0.5, -2.0*l1}; double DS[3] = {l2-0.5, l2+0.5, -2.0*l2}; H[0] = R[0]*S[0]; H[1] = R[1]*S[0]; H[2] = R[1]*S[1]; H[3] = R[0]*S[1]; H[4] = R[2]*S[0]; H[5] = R[1]*S[2]; H[6] = R[2]*S[1]; H[7] = R[0]*S[2]; H[8] = R[2]*S[2]; // shape function derivatives H1[0] = DR[0]*S[0]; H1[1] = DR[1]*S[0]; H1[2] = DR[1]*S[1]; H1[3] = DR[0]*S[1]; H1[4] = DR[2]*S[0]; H1[5] = DR[1]*S[2]; H1[6] = DR[2]*S[1]; H1[7] = DR[0]*S[2]; H1[8] = DR[2]*S[2]; H2[0] = R[0]*DS[0]; H2[1] = R[1]*DS[0]; H2[2] = R[1]*DS[1]; H2[3] = R[0]*DS[1]; H2[4] = R[2]*DS[0]; H2[5] = R[1]*DS[2]; H2[6] = R[2]*DS[1]; H2[7] = R[0]*DS[2]; H2[8] = R[2]*DS[2]; // calculate residual F = r + n*l3 - y[0]*H[0] - y[1]*H[1] - y[2]*H[2] - y[3]*H[3] - y[4]*H[4] - y[5]*H[5] - y[6]*H[6] - y[7]*H[7] - y[8]*H[8]; // residual derivatives F1 = - y[0]*H1[0] - y[1]*H1[1] - y[2]*H1[2] - y[3]*H1[3] - y[4]*H1[4] - y[5]*H1[5] - y[6]*H1[6] - y[7]*H1[7] - y[8]*H1[8]; F2 = - y[0]*H2[0] - y[1]*H2[1] - y[2]*H2[2] - y[3]*H2[3] - y[4]*H2[4] - y[5]*H2[5] - y[6]*H2[6] - y[7]*H2[7] - y[8]*H2[8]; F3 = n; // set up the tangent matrix A[0][0] = F1.x; A[0][1] = F2.x; A[0][2] = F3.x; A[1][0] = F1.y; A[1][1] = F2.y; A[1][2] = F3.y; A[2][0] = F1.z; A[2][1] = F2.z; A[2][2] = F3.z; // calculate solution increment mat3d Ai = A.inverse(); dx = -(Ai*F); // update solution l1 += dx.x; l2 += dx.y; l3 += dx.z; ++nn; } while ((dx.norm() > 1e-7) && (nn < maxn)); if (nn == maxn) return false; // store results rs[0] = l1; rs[1] = l2; g = l3; vec3d nu2 = F1 ^ F2; nu2.unit(); double cosq = n*nu2; if (cosq > 0) return false; // see if the point is inside the quad if ((rs[0] >= -1-eps) && (rs[0] <= 1+eps) && (rs[1] >= -1-eps) && (rs[1] <= 1+eps)) return true; return false; } //----------------------------------------------------------------------------- //! This function calculates the intersection of a ray with a 6-node triangle //! and returns true if the ray intersected. //! bool IntersectTri6(vec3d* y, vec3d r, vec3d n, double rs[2], double& g, double eps) { // first we're going to see if the ray intersects the four subtriangles vec3d x1[3], x2[3], x3[3], x4[3]; x1[0] = y[0]; x2[0] = y[3]; x3[0] = y[5]; x4[0] = y[4]; x1[1] = y[3]; x2[1] = y[1]; x3[1] = y[4]; x4[1] = y[5]; x1[2] = y[5]; x2[2] = y[4]; x3[2] = y[2]; x4[2] = y[3]; bool b = false; double rp = 0, sp = 0; if (IntersectTri(x1, r, n, rs, g, eps)) { // we've intersected the first triangle b = true; rp = rs[0]/2.0; sp = rs[1]/2.0; } else if (IntersectTri(x2, r, n, rs, g, eps)) { // we've intersected the second triangle b = true; rp = 0.5 + rs[0]/2.0; sp = rs[1]/2.0; } else if (IntersectTri(x3, r, n, rs, g, eps)) { // we've intersected the third triangle b = true; rp = rs[0]/2.0; sp = 0.5 + rs[1]/2.0; } else if (IntersectTri(x4, r, n, rs, g, eps)) { // we've intersected the fourth triangle b = true; rp = 0.5 - rs[0]/2.0; sp = 0.5 - rs[1]/2.0; } // if one of the triangels was intersected, // we calculate a more accurate projection if (b) { mat3d A; vec3d dx; vec3d F, F1, F2, F3; double H[6], H1[6], H2[6]; double l0; double l1 = rp; double l2 = sp; double l3 = g; int nn = 0; int maxn = 10; do { l0 = 1 - l1 - l2; // shape functions of quad H[0] = l0*(2.0*l0 - 1.0); H[1] = l1*(2.0*l1 - 1.0); H[2] = l2*(2.0*l2 - 1.0); H[3] = 4.0*l0*l1; H[4] = 4.0*l1*l2; H[5] = 4.0*l2*l0; // shape function derivatives H1[0] = -3.0 + 4.0*l1 + 4.0*l2; H1[1] = 4.0*l1 - 1.0; H1[2] = 0.0; H1[3] = 4.0 - 8.0*l1 - 4.0*l2; H1[4] = 4.0*l2; H1[5] = -4.0*l2; H2[0] = -3.0 + 4.0*l2 + 4.0*l1; H2[1] = 0.0; H2[2] = 4.0*l2 - 1.0; H2[3] = -4.0*l1; H2[4] = 4.0*l1; H2[5] = 4.0 - 8.0*l2 - 4.0*l1; // calculate residual F = r + n*l3 - y[0]*H[0] - y[1]*H[1] - y[2]*H[2] - y[3]*H[3] - y[4]*H[4] - y[5]*H[5]; // residual derivatives F1 = - y[0]*H1[0] - y[1]*H1[1] - y[2]*H1[2] - y[3]*H1[3] - y[4]*H1[4] - y[5]*H1[5]; F2 = - y[0]*H2[0] - y[1]*H2[1] - y[2]*H2[2] - y[3]*H2[3] - y[4]*H2[4] - y[5]*H2[5]; F3 = n; // set up the tangent matrix A[0][0] = F1.x; A[0][1] = F2.x; A[0][2] = F3.x; A[1][0] = F1.y; A[1][1] = F2.y; A[1][2] = F3.y; A[2][0] = F1.z; A[2][1] = F2.z; A[2][2] = F3.z; // calculate solution increment mat3d Ai = A.inverse(); dx = -(Ai*F); // update solution l1 += dx.x; l2 += dx.y; l3 += dx.z; ++nn; } while ((dx.norm() > 1e-7) && (nn < maxn)); if (nn == maxn) return false; // store results rs[0] = l1; rs[1] = l2; g = l3; vec3d nu2 = F1 ^ F2; nu2.unit(); double cosq = n*nu2; if (cosq > 0) return false; // see if the point is inside the quad if ((rs[0] >= -eps) && (rs[1] >= -eps) && (rs[0]+rs[1] <= 1+eps)) return true; } return false; } //----------------------------------------------------------------------------- //! This function calculates the intersection of a ray with a 6-node triangle //! and returns true if the ray intersected. //! bool IntersectTri7(vec3d* y, vec3d r, vec3d n, double rs[2], double& g, double eps) { // first we're going to see if the ray intersects the four subtriangles vec3d x1[3], x2[3], x3[3], x4[3]; x1[0] = y[0]; x2[0] = y[3]; x3[0] = y[5]; x4[0] = y[4]; x1[1] = y[3]; x2[1] = y[1]; x3[1] = y[4]; x4[1] = y[5]; x1[2] = y[5]; x2[2] = y[4]; x3[2] = y[2]; x4[2] = y[3]; bool b = false; double rp = 0, sp = 0; if (IntersectTri(x1, r, n, rs, g, eps)) { // we've intersected the first triangle b = true; rp = rs[0]/2.0; sp = rs[1]/2.0; } else if (IntersectTri(x2, r, n, rs, g, eps)) { // we've intersected the second triangle b = true; rp = 0.5 + rs[0]/2.0; sp = rs[1]/2.0; } else if (IntersectTri(x3, r, n, rs, g, eps)) { // we've intersected the third triangle b = true; rp = rs[0]/2.0; sp = 0.5 + rs[1]/2.0; } else if (IntersectTri(x4, r, n, rs, g, eps)) { // we've intersected the fourth triangle b = true; rp = 0.5 - rs[0]/2.0; sp = 0.5 - rs[1]/2.0; } // if one of the triangels was intersected, // we calculate a more accurate projection if (b) { mat3d A; vec3d dx; vec3d F, F1, F2, F3; double H[7], H1[7], H2[7]; double l0; double l1 = rp; double l2 = sp; double l3 = g; int nn = 0; int maxn = 5; do { l0 = 1 - l1 - l2; H[6] = 27.0*l0*l1*l2; H[0] = l0*(2.0*l0 - 1.0) + H[6]/9.0; H[1] = l1*(2.0*l1 - 1.0) + H[6]/9.0; H[2] = l2*(2.0*l2 - 1.0) + H[6]/9.0; H[3] = 4.0*l0*l1 - 4.0*H[6]/9.0; H[4] = 4.0*l1*l2 - 4.0*H[6]/9.0; H[5] = 4.0*l2*l0 - 4.0*H[6]/9.0; // shape function derivatives H1[6] = 27.0*l2*(1.0 - 2.0*l1 - l2); H1[0] = -3.0 + 4.0*l1 + 4.0*l2 + H1[6]/9.0; H1[1] = 4.0*l1 - 1.0 + H1[6]/9.0; H1[2] = 0.0 + H1[6]/9.0; H1[3] = 4.0 - 8.0*l1 - 4.0*l2 - 4.0*H1[6]/9.0; H1[4] = 4.0*l2 - 4.0*H1[6]/9.0; H1[5] = -4.0*l2 - 4.0*H1[6]/9.0; H2[6] = 27.0*l1*(1.0 - l1 - 2.0*l2); H2[0] = -3.0 + 4.0*l2 + 4.0*l1 + H2[6]/9.0; H2[1] = 0.0 + H2[6]/9.0; H2[2] = 4.0*l2 - 1.0 + H2[6]/9.0; H2[3] = -4.0*l1 - 4.0*H2[6]/9.0; H2[4] = 4.0*l1 - 4.0*H2[6]/9.0; H2[5] = 4.0 - 8.0*l2 - 4.0*l1 - 4.0*H2[6]/9.0; // calculate residual F = r + n*l3 - y[0]*H[0] - y[1]*H[1] - y[2]*H[2] - y[3]*H[3] - y[4]*H[4] - y[5]*H[5] - y[6]*H[6]; // residual derivatives F1 = - y[0]*H1[0] - y[1]*H1[1] - y[2]*H1[2] - y[3]*H1[3] - y[4]*H1[4] - y[5]*H1[5] - y[6]*H1[6]; F2 = - y[0]*H2[0] - y[1]*H2[1] - y[2]*H2[2] - y[3]*H2[3] - y[4]*H2[4] - y[5]*H2[5] - y[6]*H2[6]; F3 = n; // set up the tangent matrix A[0][0] = F1.x; A[0][1] = F2.x; A[0][2] = F3.x; A[1][0] = F1.y; A[1][1] = F2.y; A[1][2] = F3.y; A[2][0] = F1.z; A[2][1] = F2.z; A[2][2] = F3.z; // calculate solution increment mat3d Ai = A.inverse(); dx = -(Ai*F); // update solution l1 += dx.x; l2 += dx.y; l3 += dx.z; ++nn; } while ((dx.norm() > 1e-7) && (nn < maxn)); if (nn == maxn) return false; // store results rs[0] = l1; rs[1] = l2; g = l3; vec3d nu2 = F1 ^ F2; nu2.unit(); double cosq = n*nu2; if (cosq > 0) return false; // see if the point is inside the quad if ((rs[0] >= -eps) && (rs[1] >= -eps) && (rs[0]+rs[1] <= 1+eps)) return true; } return false; } //----------------------------------------------------------------------------- void FESurface::Invert() { ForEachSurfaceElement([](FESurfaceElement& el) { int tmp; switch (el.Shape()) { case ET_TRI3 : tmp = el.m_node[1]; el.m_node[1] = el.m_node[2]; el.m_node[2] = tmp; break; case ET_QUAD4: tmp = el.m_node[1]; el.m_node[1] = el.m_node[3]; el.m_node[3] = tmp; break; case ET_QUAD8: case ET_QUAD9: tmp = el.m_node[1]; el.m_node[1] = el.m_node[3]; el.m_node[3] = tmp; tmp = el.m_node[4]; el.m_node[4] = el.m_node[7]; el.m_node[7] = tmp; tmp = el.m_node[5]; el.m_node[5] = el.m_node[6]; el.m_node[6] = tmp; break; case ET_TRI6: case ET_TRI7: tmp = el.m_node[1]; el.m_node[1] = el.m_node[2]; el.m_node[2] = tmp; tmp = el.m_node[3]; el.m_node[3] = el.m_node[5]; el.m_node[5] = tmp; break; default: assert(false); } }); } //----------------------------------------------------------------------------- //! This function calculates the intersection of a ray with a surface element. //! It simply calls the correct intersection function based on the type //! of element. //! bool FESurface::Intersect(FESurfaceElement& el, vec3d r, vec3d n, double rs[2], double& g, double eps, bool checkNormal) { int N = el.Nodes(); // get the element nodes FEMesh& mesh = *m_pMesh; vec3d y[FEElement::MAX_NODES]; if (!m_bshellb) for (int i=0; i<N; ++i) y[i] = mesh.Node(el.m_node[i]).m_rt; else for (int i=0; i<N; ++i) y[i] = mesh.Node(el.m_node[i]).st(); // call the correct intersection function switch (N) { case 3: return IntersectTri (y, r, n, rs, g, eps); break; case 4: return IntersectQuad (y, r, n, rs, g, eps, checkNormal); break; case 6: return IntersectTri6 (y, r, n, rs, g, eps); break; case 7: return IntersectTri7 (y, r, n, rs, g, eps); break; case 8: return IntersectQuad8(y, r, n, rs, g, eps); break; case 9: return IntersectQuad9(y, r, n, rs, g, eps); break; default: assert(false); } // if we get here, the ray did not intersect the element return false; } //----------------------------------------------------------------------------- void FESurface::Serialize(DumpStream &ar) { FEMeshPartition::Serialize(ar); if (ar.IsShallow() == false) { ar & m_surf; ar & m_bitfc; ar & m_alpha; ar & m_bshellb; ar & m_el; // reallocate integration point data on loading if (ar.IsSaving() == false) { for (int i = 0; i < Elements(); ++i) { FESurfaceElement& el = Element(i); el.SetMeshPartition(this); int nint = el.GaussPoints(); for (int n = 0; n < nint; ++n) { FESurfaceMaterialPoint* pt = dynamic_cast<FESurfaceMaterialPoint*>(CreateMaterialPoint()); assert(pt); el.SetMaterialPointData(pt, n); } } } } if ((ar.IsShallow() == false) && (ar.IsSaving() == false)) { // see if we can find all elements that the faces belong to int ne = Elements(); for (int i = 0; i<ne; ++i) { FESurfaceElement& el = Element(i); if (m_bitfc && (el.m_elem[0].pe == nullptr)) FindElements(el); else if (el.m_elem[0].pe == nullptr) el.m_elem[0] = FindElement(el); //to make sure else if (m_bitfc && (el.m_elem[1].pe == nullptr)) FindElements(el); assert(el.m_elem[0].pe != nullptr); } } // serialize material point data for (int i = 0; i < Elements(); ++i) { FESurfaceElement& el = Element(i); int nint = el.GaussPoints(); for (int n = 0; n < nint; ++n) { FESurfaceMaterialPoint* pt = dynamic_cast<FESurfaceMaterialPoint*>(el.GetMaterialPoint(n)); assert(pt); pt->Serialize(ar); } } } //----------------------------------------------------------------------------- void FESurface::GetNodalCoordinates(FESurfaceElement& el, vec3d* rt) { FEMesh& mesh = *GetMesh(); int neln = el.Nodes(); if (!m_bshellb) for (int j = 0; j < neln; ++j) rt[j] = mesh.Node(el.m_node[j]).m_rt; else for (int j = 0; j < neln; ++j) rt[j] = mesh.Node(el.m_node[j]).st(); } //----------------------------------------------------------------------------- void FESurface::GetReferenceNodalCoordinates(FESurfaceElement& el, vec3d* r0) { FEMesh& mesh = *GetMesh(); int neln = el.Nodes(); if (!m_bshellb) for (int j = 0; j < neln; ++j) r0[j] = mesh.Node(el.m_node[j]).m_r0; else for (int j = 0; j < neln; ++j) r0[j] = mesh.Node(el.m_node[j]).s0(); } //----------------------------------------------------------------------------- // Get current coordinates at intermediate configuration void FESurface::GetNodalCoordinates(FESurfaceElement& el, double alpha, vec3d* rt) { int neln = el.Nodes(); for (int j = 0; j<neln; ++j) { FENode& node = Node(el.m_lnode[j]); rt[j] = node.m_rt*alpha + node.m_rp*(1.0 - alpha); if (m_bshellb) rt[j] -= node.m_dt*alpha + node.m_dp*(1.0 - alpha); } } //----------------------------------------------------------------------------- // Evaluate field variables double FESurface::Evaluate(FESurfaceMaterialPoint& mp, int dof) { double v[FEElement::MAX_NODES]; FESurfaceElement& el = *mp.SurfaceElement(); int neln = el.Nodes(); for (int j = 0; j < neln; ++j) v[j] = Node(el.m_lnode[j]).get(dof); double s = el.eval(v, mp.m_index); return s; } //----------------------------------------------------------------------------- // Evaluate field variables double FESurface::Evaluate(int nface, int dof) { double v = 0; FESurfaceElement& el = Element(nface); int neln = el.Nodes(); for (int j = 0; j < neln; ++j) v += Node(el.m_lnode[j]).get(dof); return v/neln; } //----------------------------------------------------------------------------- void FESurface::LoadVector(FEGlobalVector& R, const FEDofList& dofList, bool breference, FESurfaceVectorIntegrand f) { int dofPerNode = dofList.Size(); int order = (dofPerNode == 1 ? dofList.InterpolationOrder(0) : -1); int NE = Elements(); #pragma omp parallel for shared(R, dofList, f) for (int i = 0; i < NE; ++i) { vector<double> fe; vector<int> lm; vec3d re[FEElement::MAX_NODES]; std::vector<double> G(dofPerNode, 0.0); // get the next element FESurfaceElement& el = Element(i); // init the element vector int neln = el.ShapeFunctions(order); int ndof = dofPerNode * neln; fe.assign(ndof, 0.0); // get the nodal coordinates if (breference) GetReferenceNodalCoordinates(el, re); else GetNodalCoordinates(el, re); // calculate element vector FESurfaceDofShape dof_a; double* w = el.GaussWeights(); int nint = el.GaussPoints(); for (int n = 0; n < nint; ++n) { FESurfaceMaterialPoint& pt = static_cast<FESurfaceMaterialPoint&>(*el.GetMaterialPoint(n)); // kinematics at integration points pt.dxr = el.eval_deriv1(re, n); pt.dxs = el.eval_deriv2(re, n); pt.m_shape = el.H(n); double* H = el.H(order, n); double* Hr = el.Gr(order, n); double* Hs = el.Gr(order, n); // put it all together for (int j = 0; j<neln; ++j) { // shape function and derivatives dof_a.index = j; dof_a.shape = H[j]; dof_a.shape_deriv_r = Hr[j]; dof_a.shape_deriv_s = Hs[j]; // evaluate the integrand f(pt, dof_a, G); for (int k = 0; k < dofPerNode; ++k) { fe[dofPerNode * j + k] += G[k] * w[n]; } } } // get the corresponding LM vector UnpackLM(el, dofList, lm); // Assemble into global vector R.Assemble(el.m_node, lm, fe); } } //----------------------------------------------------------------------------- void FESurface::LoadStiffness(FELinearSystem& LS, const FEDofList& dofList_a, const FEDofList& dofList_b, FESurfaceMatrixIntegrand f) { FEElementMatrix ke; int dofPerNode_a = dofList_a.Size(); int dofPerNode_b = dofList_b.Size(); int order_a = (dofPerNode_a == 1 ? dofList_a.InterpolationOrder(0) : -1); int order_b = (dofPerNode_b == 1 ? dofList_b.InterpolationOrder(0) : -1); vec3d rt[FEElement::MAX_NODES]; matrix kab(dofPerNode_a, dofPerNode_b); FESurfaceDofShape dof_a, dof_b; int NE = Elements(); for (int m = 0; m<NE; ++m) { // get the surface element FESurfaceElement& el = Element(m); ke.SetNodes(el.m_node); // shape functions int neln = el.Nodes(); int nn_a = el.ShapeFunctions(dofPerNode_a); int nn_b = el.ShapeFunctions(dofPerNode_b); // get the element stiffness matrix int ndof_a = dofPerNode_a * nn_a; int ndof_b = dofPerNode_b * nn_b; ke.resize(ndof_a, ndof_b); // calculate element stiffness int nint = el.GaussPoints(); // gauss weights double* w = el.GaussWeights(); // nodal coordinates GetNodalCoordinates(el, rt); // repeat over integration points ke.zero(); for (int n = 0; n<nint; ++n) { FESurfaceMaterialPoint& pt = static_cast<FESurfaceMaterialPoint&>(*el.GetMaterialPoint(n)); double* Gr = el.Gr(n); double* Gs = el.Gs(n); // tangents at integration point pt.dxr = vec3d(0, 0, 0); pt.dxs = vec3d(0, 0, 0); for (int i = 0; i<neln; ++i) { pt.dxr += rt[i] * Gr[i]; pt.dxs += rt[i] * Gs[i]; } // calculate stiffness component for (int i = 0; i < nn_a; ++i) { // shape function values dof_a.index = i; dof_a.shape = el.H(order_a, n)[i]; dof_a.shape_deriv_r = el.Gr(order_a, n)[i]; dof_a.shape_deriv_s = el.Gs(order_a, n)[i]; for (int j = 0; j < nn_b; ++j) { // shape function values dof_b.index = j; dof_b.shape = el.H(order_b, n)[j]; dof_b.shape_deriv_r = el.Gr(order_b, n)[j]; dof_b.shape_deriv_s = el.Gs(order_b, n)[j]; // evaluate integrand kab.zero(); f(pt, dof_a, dof_b, kab); // add it to the local element matrix ke.adds(dofPerNode_a * i, dofPerNode_b * j, kab, w[n]); } } } // get the element's LM vector std::vector<int>& lma = ke.RowIndices(); std::vector<int>& lmb = ke.ColumnsIndices(); UnpackLM(el, dofList_a, lma); UnpackLM(el, dofList_b, lmb); // assemble element matrix in global stiffness matrix LS.Assemble(ke); } } //----------------------------------------------------------------------------- // project FEParamDouble pd to nodes and store nodal values in vector<double> d void FESurface::ProjectToNodes(FEParamDouble& pd, std::vector<double>& d) { d.assign(Nodes(), 0.0); std::vector<int> nd(Nodes(),0); for (int i=0; i<Elements(); ++i) { FESurfaceElement& el = Element(i); double ei[FEElement::MAX_INTPOINTS]; for (int j=0; j<el.GaussPoints(); ++j) { FEMaterialPoint* pt = el.GetMaterialPoint(j); ei[j] = pd(*pt); } double en[FEElement::MAX_NODES]; el.project_to_nodes(ei, en); for (int j=0; j<el.Nodes(); ++j) { d[el.m_lnode[j]] += en[j]; ++nd[el.m_lnode[j]]; } } // evaluate average for (int i=0; i<Nodes(); ++i) if (nd[i]) d[i] /= nd[i]; } FECORE_API double CalculateSurfaceVolume(FESurface& s) { // get the mesh FEMesh& mesh = *s.GetMesh(); // loop over all elements double vol = 0.0; int NE = s.Elements(); vec3d x[FEElement::MAX_NODES]; for (int i = 0; i < NE; ++i) { // get the next element FESurfaceElement& el = s.Element(i); // get the nodal coordinates int neln = el.Nodes(); for (int j = 0; j < neln; ++j) x[j] = mesh.Node(el.m_node[j]).m_rt; // loop over integration points double* w = el.GaussWeights(); int nint = el.GaussPoints(); for (int n = 0; n < nint; ++n) { // evaluate the position vector at this point vec3d r = el.eval(x, n); // calculate the tangent vectors double* Gr = el.Gr(n); double* Gs = el.Gs(n); vec3d dxr(0, 0, 0), dxs(0, 0, 0); for (int j = 0; j < neln; ++j) { dxr += x[j] * Gr[j]; dxs += x[j] * Gs[j]; } // update volume vol += w[n] * (r * (dxr ^ dxs)); } } return vol / 3.0; }
C++
3D
febiosoftware/FEBio
FECore/FENodeReorder.cpp
.cpp
8,339
311
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FENodeReorder.h" #include "FEMesh.h" #include <stack> using namespace std; //----------------------------------------------------------------------------- FENodeReorder::FENodeReorder() { } FENodeReorder::~FENodeReorder() { } //----------------------------------------------------------------------------- //! This function applies the node-reordering algorithm to a particular mesh. //! The new node number is stored in P. To be precise, P stores for each new //! node the old node that corresponds to this node. void FENodeReorder::Apply(FEMesh& mesh, vector<int>& P) { int i, j, n, l, m; int* pn; // get the nr of nodes int N = mesh.Nodes(); // initialize the permutation vector // Set all entries to -1 to indicate that // no node has been given a new number yet. vector<int> Q; Q.assign(N, -1); // create the node-node list // this list stores for each node of the mesh // a list of nodes that are adjacent to it. FENodeNodeList NL; NL.Create(mesh); // sort the nodelist in order of increasing degree NL.Sort(); // Levelstructures are used to group all nodes // in levels FELevelStructure Lv, Lu, Ls, L; // this swap variable will tell you if // the node numbering needs to be reversed at the end bool bswap; // The mesh may comprise of several disconnected // components. We therefor have to apply the algorithm // several times until all components are processed. int neq = 0, neq0; while (true) { // To identify an unprocessed component we try to // find an unprocessed node (nv). An unprocessed // node will have Q[i]<0. We also require this node // to be of minimal degree. int valmin = 0x7fffffff; // initialize the min valence to a ridiculously large value int nv = -1, nu; int nval; for (i=0; i<N; ++i) { nval = NL.Valence(i); if ((Q[i] < 0) && (nval < valmin)) { valmin = nval; nv = i; } } // if we havn't found an unprocessed node, we can stop if (nv == -1) break; // store the starting equation number // we need this in case we need to reverse the // node ordering neq0 = neq; // we now will find the pseudo-diameter of the node graph (i.e. NodeNodeList), // which identifies to nodes at the end of the diameter, // namely nv, and nu. We will require the level structure for // nu to be of minimal width, which is stored in wmin int wmin = 0x7fffffff; // Let's find the pseudo-diameter // if we found one bok will be true bool bok; do { // let's be optimistic bok = true; // create a level structure rooted at nv Lv.Create(NL, nv); // sort the last level in order of increasing degree l = Lv.Depth() - 1; Lv.SortLevels(l, l); // get the list of nodes at the last level of Lv n = Lv.Valence(l); pn = Lv.NodeList(l); // loop over all the nodes for (i=0; i<n; ++i) { // get a possible candidate for nu nu = pn[i]; // create a level structure rooted at u Ls.Create(NL, nu); // make sure that the depth of Ls is not // greater than that of Lv if (Ls.Depth() > Lv.Depth()) { // Oh, oh, the depth of Ls is greater than // that of nv, so replace nv with nu and try // again. nv = nu; wmin = 0x7fffffff; // reset the min width bok = false; break; } else { // store the level stucture with minimal width if (Ls.Width() < wmin) { Lu = Ls; // store the level structure wmin = Ls.Width(); // store the minimum width } } } } while (!bok); // we have found the pseudo-diamter u,v // Next, merge the level structures into one // This new level structure will usually have a width // that is smaller than either Lv or Lu. // make sure we start with the node of lowest degree if (NL.Valence(nu) < NL.Valence(nv)) { // swap u and v nu ^= nv; nv ^= nu; nu ^= nv; L.Merge(Lu, Lv, bswap); } else { L.Merge(Lv, Lu, bswap); bswap = !bswap; } // sort all levels of L in order of increasing degree L.SortLevels(0, L.Depth()-1); // get the width of L. This width is the largest width // of any level of L int lmax = L.Width(); // the following stack and vectors will assist us in // renumbering the nodes. stack<int> NQ; vector<int> Vi(0, lmax); vector<int> Vip1(0, lmax); // Using the level structure L we can now go ahead and define // the new node numbering. The basic idea is to loop over all // levels and assign the node numbers level by level. In each // level the numbers adjacent to the lowest number node in the same // level gets numbered first. Then the nodes adjacent to the lowest // numbered nodes in the previous level gets numbered next. int nw; Q[nv] = neq++; Vi.push_back(nv); for (l=0; l<L.Depth(); ++l) { // assign numbers to level l // The Vi array stores the nodes of level l that have been // numbered in order of increasing node number. // We loop over all these nodes and assign a // node number to unnumbered adjacent nodes until // all nodes of level l have been numbered for(i=0; i<(int) Vi.size(); ++i) { nw = Vi[i]; // loop over all unassigned nodes adjacent to nw n = NL.Valence(nw); pn = NL.NodeList(nw); for (j=0; j<n; ++j) { m = pn[j]; if ((L.NodeLevel(m) == l) && (Q[m] < 0)) { Q[m] = neq++; Vi.push_back(m); } } // If we are about to terminate the loop make sure // that all nodes of level l have been assigned // a new node number if (i==(Vi.size() - 1)) { // check to see if all nodes in level l are numbered n = L.Valence(l); pn = L.NodeList(l); for (j=0; j<n; ++j) { m = pn[j]; if (Q[m] < 0) { // Aha, we found an unnumbered node in this level // so place in the array an continue the loop over i Vi.push_back(m); Q[m] = neq++; break; } } } } // If this is not the last level, we go ahead and number // all nodes in level l+1 that are adjacent to numbered nodes // of level l if (l<L.Depth()-1) { Vip1.clear(); // assign numbers to the next level for (i=0; i<(int) Vi.size(); ++i) { nw = Vi[i]; n = NL.Valence(nw); pn = NL.NodeList(nw); for (j=0; j<n; ++j) { m = pn[j]; if ((L.NodeLevel(m) == l+1) && (Q[m] < 0)) { Q[m] = neq++; Vip1.push_back(m); } } } // copy the numbered nodes of level l+1 into Vi Vi = Vip1; } } // we have assigned new node numbers // see if we need to invert the numbering if (bswap) { for (i=0; i<N; ++i) { if (Q[i] >= neq0) Q[i] = neq - 1 - Q[i] + neq0; } } } // The Q array stores for each old node its new node number // but we actually need the inverse permutation. That is, for // each new node, the old node number that is associated with it. // This array is stored in P. P.resize(N); for (i=0; i<N; ++i) { P[Q[i]] = i; } }
C++
3D
febiosoftware/FEBio
FECore/mat2d.h
.h
3,583
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 "vec2d.h" class mat2d { public: // constructors mat2d(){} mat2d(double a00, double a01, double a10, double a11) { d[0][0] = a00; d[0][1] = a01; d[1][0] = a10; d[1][1] = a11; } // access operators double& operator () (int i, int j) { return d[i][j]; } double operator () (int i, int j) const { return d[i][j]; } double* operator [] (int i) { return d[i]; } public: // arithmetic operations mat2d operator + (const mat2d& m) { return mat2d(d[0][0]+m.d[0][0], d[0][1]+m.d[0][1], d[1][0]+m.d[1][0], d[1][1]+m.d[1][1]); } mat2d operator - (const mat2d& m) { return mat2d(d[0][0]-m.d[0][0], d[0][1]-m.d[0][1], d[1][0]-m.d[1][0], d[1][1]-m.d[1][1]); } mat2d operator * (double g) { return mat2d(d[0][0]*g, d[0][1]*g, d[1][0]*g, d[1][1]*g); } mat2d operator / (double g) { return mat2d(d[0][0]/g, d[0][1]/g, d[1][0]/g, d[1][1]/g); } mat2d& operator += (const mat2d& m) { d[0][0] += m.d[0][0]; d[0][1] += m.d[0][1]; d[1][0] += m.d[1][0]; d[1][1] += m.d[1][1]; return *this; } mat2d& operator -= (const mat2d& m) { d[0][0] -= m.d[0][0]; d[0][1] -= m.d[0][1]; d[1][0] -= m.d[1][0]; d[1][1] -= m.d[1][1]; return *this; } mat2d& operator *= (double g) { d[0][0] *= g; d[0][1] *= g; d[1][0] *= g; d[1][1] *= g; return *this; } mat2d& operator /= (double g) { d[0][0] /= g; d[0][1] /= g; d[1][0] /= g; d[1][1] /= g; return *this; } mat2d operator * (const mat2d& m) { return mat2d( d[0][0]*m.d[0][0]+d[0][1]*m.d[1][0], d[0][0]*m.d[0][1]+d[0][1]*m.d[1][1], d[1][0]*m.d[0][0]+d[1][1]*m.d[1][0], d[1][0]*m.d[0][1]+d[1][1]*m.d[1][1]); } public: // matrix operations mat2d inverse() const { double Di = 1/(d[0][0]*d[1][1] - d[0][1]*d[1][0]); return mat2d(d[1][1]*Di, -d[0][1]*Di, -d[1][0]*Di, d[0][0]*Di); } mat2d transpose() const { return mat2d(d[0][0], d[1][0], d[0][1], d[1][1]); } void zero() { d[0][0] = d[0][1] = d[1][0] = d[1][1] = 0.0; } void identity() { d[0][0] = d[1][1] = 1.0; d[0][1] = d[1][0] = 0.0; } protected: double d[2][2]; }; // matrix-vector operations inline vec2d operator * (mat2d& m, vec2d& a) { return vec2d(m[0][0]*a[0]+m[0][1]*a[1], m[1][0]*a[0]+m[1][1]*a[1]); } // dyadic product inline mat2d dyad(vec2d& a, vec2d& b) { return mat2d(a.r[0]*b.r[0], a.r[0]*b.r[1], a.r[1]*b.r[0], a.r[1]*b.r[1]); }
Unknown
3D
febiosoftware/FEBio
FECore/MSimplify.cpp
.cpp
6,628
289
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "MMath.h" #include "MEvaluate.h" using namespace std; //----------------------------------------------------------------------------- // Simplify an expression MITEM MSimplify(const MITEM& i) { MITEM e = MEvaluate(i); switch (e.Type()) { case MFRAC: { FRACTION f = mfrac(i)->fraction(); if (f.d == 1.0) return f.n; } break; case MNEG: return -MExpand(e.Item()); case MMUL: { MITEM l = e.Left(); MITEM r = e.Right(); if (is_add(r)) { MITEM a = r.Left(); MITEM b = r.Right(); return MExpand(l*a) + MExpand(l*b); } if (is_sub(r)) { MITEM a = r.Left(); MITEM b = r.Right(); return MExpand(l*a) - MExpand(l*b); } if (is_add(l)) { MITEM a = l.Left(); MITEM b = l.Right(); return MExpand(r*a) + MExpand(r*b); } if (is_sub(l)) { MITEM a = l.Left(); MITEM b = l.Right(); return MExpand(r*a) - MExpand(r*b); } MITEM Ml = MExpand(l); MITEM Mr = MExpand(r); // if ((l != Ml) || (r != Mr)) return Ml*Mr; if ((l != Ml) || (r != Mr)) return MExpand(Ml*Mr); // it looks like this could create an infinite loop } break; case MDIV: { MITEM l = e.Left(); MITEM r = e.Right(); if (is_add(l)) { MITEM a = l.Left(); MITEM b = l.Right(); return MExpand(a/r) + MExpand(b/r); } if (is_sub(l)) { MITEM a = l.Left(); MITEM b = l.Right(); return MExpand(a/r) - MExpand(b/r); } MITEM Ml = MExpand(l); MITEM Mr = MExpand(r); if ((l != Ml) || (r != Mr)) return MExpand(Ml/Mr); else return Ml/Mr; } break; case MADD: { MITEM l = e.Left(); MITEM r = e.Right(); return MExpand(l) + MExpand(r); } break; case MSUB: { MITEM l = e.Left(); MITEM r = e.Right(); return MExpand(l) - MExpand(r); } break; case MPOW: { MITEM l = e.Left(); MITEM r = e.Right(); if (is_int(r) && is_add(l)) { MITEM a = l.Left(); MITEM b = l.Right(); int n = (int) r.value(); if (n == 0) return 1.0; MITEM s(0.0); for (int i=0; i<=n; ++i) { double C = binomial(n,i); s = s + C*MExpand(a^(n-i))*MExpand(b^i); } return s; } if (is_int(r) && is_sub(l)) { MITEM a = l.Left(); MITEM b = l.Right(); int n = (int) r.value(); if (n == 0) return 1.0; MITEM s(0.0); for (int i=0; i<=n; ++i) { double C = binomial(n,i); MITEM t = C*MExpand(a^(n-i))*MExpand(b^i); if (i%2 == 0) s = s + t; else s = s - t; } return s; } if (is_add(r)) { MITEM a = r.Left(); MITEM b = r.Right(); return ((l^a)*(l^b)); } MITEM le = MExpand(l); MITEM re = MExpand(r); return le^re; } break; case MF1D: { const string& f = mfnc1d(e)->Name(); if (f.compare("cos") == 0) { MITEM p = e.Param(); if (p.Type() == MADD) { MITEM a = p.Left(); MITEM b = p.Right(); return MExpand(Cos(a)*Cos(b) - Sin(a)*Sin(b)); } if (p.Type() == MSUB) { MITEM a = p.Left(); MITEM b = p.Right(); return MExpand(Cos(a)*Cos(b) + Sin(a)*Sin(b)); } } if (f.compare("sin") == 0) { MITEM p = e.Param(); if (p.Type() == MADD) { MITEM a = p.Left(); MITEM b = p.Right(); return MExpand(Sin(a)*Cos(b) + Cos(a)*Sin(b)); } if (p.Type() == MSUB) { MITEM a = p.Left(); MITEM b = p.Right(); return MExpand(Sin(a)*Cos(b) - Cos(a)*Sin(b)); } } if (f.compare("tan") == 0) { MITEM p = e.Param(); if (p.Type() == MADD) { MITEM a = p.Left(); MITEM b = p.Right(); return MExpand((Tan(a)+Tan(b))/(1.0 - Tan(a)*Tan(b))); } if (p.Type() == MSUB) { MITEM a = p.Left(); MITEM b = p.Right(); return MExpand((Tan(a)-Tan(b))/(1.0 + Tan(a)*Tan(b))); } } /* if (f.compare("ln") == 0) { MITEM p = e.Param(); if (is_mul(p)) { MITEM a = MExpand(p.Left()); MITEM b = MExpand(p.Right()); return MExpand(Log(a)+Log(b)); } if (is_div(p)) { MITEM a = MExpand(p.Left()); MITEM b = MExpand(p.Right()); return MExpand(Log(a)-Log(b)); } if (is_pow(p)) { MITEM a = MExpand(p.Left()); MITEM b = MExpand(p.Right()); return MExpand(b*Log(a)); } } */ const MFunc1D* pf = mfnc1d(e); MITEM v = MExpand(e.Param()); return new MFunc1D(pf->funcptr(), pf->Name(), v.copy()); } break; case MSFNC: { MITEM f(msfncnd(i)->Value()->copy()); return MExpand(f); } break; case MEQUATION: { MITEM l = e.Left(); MITEM r = e.Right(); MITEM Ml = MExpand(l); MITEM Mr = MExpand(r); return new MEquation(Ml.copy(), Mr.copy()); } break; case MSEQUENCE: { const MSequence& q = *msequence(i); MSequence* ps = new MSequence(); for (int i=0; i<q.size(); ++i) { MITEM qi = q[i]->copy(); MITEM vi = MExpand(qi); ps->add(vi.copy()); } return ps; } break; case MMATRIX: { const MMatrix& m = *mmatrix(e); int ncol = m.columns(); int nrow = m.rows(); MMatrix* pdm = new MMatrix; pdm->Create(nrow, ncol); for (int i=0; i<nrow; ++i) for (int j=0; j<ncol; ++j) { MITEM mij(m.Item(i,j)->copy()); MITEM aij = MExpand(mij); (*pdm)[i][j] = aij.copy(); } return MITEM(pdm); } break; } return e; }
C++
3D
febiosoftware/FEBio
FECore/FENode.h
.h
5,650
167
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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_api.h" #include "DOFS.h" #include "vec3d.h" #include <vector> class DumpStream; //----------------------------------------------------------------------------- //! This class defines a finite element node //! It stores nodal positions and nodal equations numbers and more. //! //! The m_ID array will store the equation number for the corresponding //! degree of freedom. Its values can be (a) non-negative (0 or higher) which //! gives the equation number in the linear system of equations, (b) -1 if the //! dof is fixed, and (c) < -1 if the dof corresponds to a prescribed dof. In //! that case the corresponding equation number is given by -ID-2. class FECORE_API FENode { public: // Node status flags enum Status { EXCLUDE = 0x01, // exclude node from analysis SHELL = 0x02, // this node belongs to a shell RIGID_CLAMP = 0x04, // this node should be clamped to a rigid body (only applies to shell nodes) HANGING = 0x08 // This is a hanging node }; public: //! default constructor FENode(); //! copy constructor FENode(const FENode& n); //! assignment operator FENode& operator = (const FENode& n); //! Set the number of DOFS void SetDOFS(int n); //! Get the nodal ID int GetID() const { return m_nID; } //! Set the node ID void SetID(int n) { m_nID = n; } //! see if status flags are set bool HasFlags(unsigned int flags) const { return ((m_nstate & flags) != 0); } //! set all the status flags void SetAllFlags(unsigned int flags) { m_nstate = flags; } //! get the status falgs unsigned int Flags() const { return m_nstate; } //! Add flags void SetFlags(unsigned int flags) { m_nstate |= flags; } //! Remove flags void UnsetFlags(unsigned int flags) { m_nstate &= ~flags; } // Serialize void Serialize(DumpStream& ar); //! Update nodal values, which copies the current values to the previous array void UpdateValues(); protected: int m_nID; //!< nodal ID public: // geometry data vec3d m_r0; //!< initial position vec3d m_rt; //!< current position vec3d m_ra; //!< used by rigid solver vec3d m_at; //!< nodal acceleration vec3d m_rp; //!< position of node at previous time step vec3d m_vp; //!< previous velocity vec3d m_ap; //!< previous acceleration vec3d m_d0; //!< initial director vec3d m_dt; //!< current director vec3d m_dp; //!< director at previous time step public: // rigid body data unsigned int m_nstate; //!< node state flags int m_rid; //!< rigid body number public: // get/set functions for current value array double& get(int n) { return m_val_t[n]; } double get(int n) const { return m_val_t[n]; } void set(int n, double v) { m_val_t[n] = v; } void add(int n, double v) { m_val_t[n] += v; } void sub(int n, double v) { m_val_t[n] -= v; } vec3d get_vec3d(int i, int j, int k) const { return vec3d(m_val_t[i], m_val_t[j], m_val_t[k]); } void set_vec3d(int i, int j, int k, const vec3d& v) { m_val_t[i] = v.x; m_val_t[j] = v.y; m_val_t[k] = v.z; } // get functions for previous value array // to set these values, call UpdateValues which copies the current values double get_prev(int n) const { return m_val_p[n]; } vec3d get_vec3d_prev(int i, int j, int k) const { return vec3d(m_val_p[i], m_val_p[j], m_val_p[k]); } double get_load(int n) const { return m_Fr[n]; } vec3d get_load3(int i, int j, int k) const { return vec3d(m_Fr[i], m_Fr[j], m_Fr[k]); } void set_load(int n, double v) { m_Fr[n] = v; } public: // dof functions void set_bc(int ndof, int bcflag) { m_BC[ndof] = ((m_BC[ndof] & 0xF0) | bcflag); } void set_active (int ndof) { m_BC[ndof] |= 0x10; } void set_inactive(int ndof) { m_BC[ndof] &= 0x0F; } int get_bc(int ndof) const { return (m_BC[ndof] & 0x0F); } bool is_active(int ndof) const { return ((m_BC[ndof] & 0xF0) != 0); } int dofs() const { return (int) m_ID.size(); } public: // return position of shell back-node vec3d s0() const { return m_r0 - m_d0; } vec3d st() const { return m_rt - m_dt; } vec3d sp() const { return m_rp - m_dp; } private: std::vector<int> m_BC; //!< boundary condition array std::vector<double> m_val_t; //!< current nodal DOF values std::vector<double> m_val_p; //!< previous nodal DOF values std::vector<double> m_Fr; //!< equivalent nodal forces public: std::vector<int> m_ID; //!< nodal equation numbers };
Unknown
3D
febiosoftware/FEBio
FECore/FENodeSetConstraint.h
.h
1,602
43
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FENLConstraint.h" class FENodeSet; // Base class for nonlinear constraints that are defined using a node set. class FECORE_API FENodeSetConstraint : public FENLConstraint { public: FENodeSetConstraint(FEModel* fem); // return the surface virtual FENodeSet* GetNodeSet() { return 0; } };
Unknown
3D
febiosoftware/FEBio
FECore/FESurfaceConstraint.h
.h
1,883
50
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FENLConstraint.h" class FESurface; // Base class for nonlinear constraints that are defined using a surface. class FECORE_API FESurfaceConstraint : public FENLConstraint { FECORE_BASE_CLASS(FESurfaceConstraint) public: FESurfaceConstraint(FEModel* fem); // return the surface virtual FESurface* GetSurface() { return 0; } // we need an integration rule for all surfaces. // By default, this was always assumed to be a nodal integration rule // but this is not always desired, so derived classes can override this virtual bool UseNodalIntegration() { return true; }; };
Unknown
3D
febiosoftware/FEBio
FECore/FESurfaceToSurfaceVectorMap.cpp
.cpp
6,649
270
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FESurfaceToSurfaceVectorMap.h" #include "FEMesh.h" #include "FESurface.h" #include "FEDomainMap.h" #include "FECoreKernel.h" #include "LinearSolver.h" #include "FEGlobalMatrix.h" #include "FELinearSystem.h" #include "FESolidDomain.h" #include "FEModel.h" #include "log.h" BEGIN_FECORE_CLASS(FESurfaceToSurfaceVectorMap, FEElemDataGenerator) ADD_PROPERTY(m_surf[0], "surface1", FEProperty::Reference); ADD_PROPERTY(m_surf[1], "surface2", FEProperty::Reference); ADD_PARAMETER(m_normal, "normal"); ADD_PARAMETER(m_cross, "cross"); ADD_PARAMETER(m_inAngle, "in_angle"); ADD_PARAMETER(m_outAngle, "out_angle"); ADD_PARAMETER(m_smoothIters, "smooth_iters"); END_FECORE_CLASS(); FESurfaceToSurfaceVectorMap::FESurfaceToSurfaceVectorMap(FEModel* fem) : FEElemDataGenerator(fem) { m_surf[0] = nullptr; m_surf[1] = nullptr; m_normal = vec3d(0, 0, 1); m_cross = false; m_inAngle = 0; m_outAngle = 0; } FESurfaceToSurfaceVectorMap::~FESurfaceToSurfaceVectorMap() { } bool FESurfaceToSurfaceVectorMap::Init() { if ((m_surf[0] == nullptr) || (m_surf[1] == nullptr)) return false; return FEMeshDataGenerator::Init(); } FEDataMap* FESurfaceToSurfaceVectorMap::Generate() { FEElementSet* elset = GetElementSet(); if (elset == nullptr) return nullptr; FEMesh& mesh = GetMesh(); int NN = mesh.Nodes(); vector<int> bn_mesh(NN, 0); vector<double> val_mesh(NN, 0.0); for (int i = 0; i < 2; ++i) { FESurface* surf = m_surf[i]; double v = (double)i; for (int n = 0; n < surf->Nodes(); n++) { int nid = surf->NodeIndex(n); assert((nid >= 0) && (nid < NN)); val_mesh[nid] = v; bn_mesh[nid] = 1; } } FENodeList nodeList = elset->GetNodeList(); int nn = nodeList.Size(); vector<int> bn(nn, 0); vector<double> val(nn, 0.0); for (int i = 0; i < nn; ++i) { int globalIndex = nodeList[i]; bn[i] = bn_mesh[globalIndex]; val[i] = val_mesh[globalIndex]; } // count equations int neq = 0; for (int i = 0; i < nn; ++i) { if (bn[i] == 0) { bn[i] = neq++; } else { bn[i] = -neq-2; neq++; } } // solve Laplace equation FECoreKernel& fecore = FECoreKernel::GetInstance(); LinearSolver* ls = fecore.CreateDefaultLinearSolver(GetFEModel()); if (ls == nullptr) return nullptr; SparseMatrix* A = ls->CreateSparseMatrix(Matrix_Type::REAL_SYMMETRIC); if (A == nullptr) return nullptr; FEGlobalMatrix K(A); FEModel dummy; std::vector<double> b(neq, 0); FELinearSystem LS(&dummy, K, b, val, true); // build matrix profile K.build_begin(neq); for (int i = 0; i < elset->Elements(); ++i) { FEElement& el = elset->Element(i); int ne = el.Nodes(); std::vector<int> lm(ne, -1); for (int k=0; k<ne; ++k) { int l = nodeList.GlobalToLocalID(el.m_node[k]); lm[k] = bn[l]; } K.build_add(lm); } K.build_end(); A->Zero(); // fill matrix and RHS FEElementMatrix ke; vector<int> lm; FEDomainList& domList = elset->GetDomainList(); for (int ndom = 0; ndom < domList.size(); ++ndom) { FESolidDomain& dom = dynamic_cast<FESolidDomain&>(*domList.GetDomain(ndom)); for (int m = 0; m < dom.Elements(); ++m) { // get the element FESolidElement& el = dom.Element(m); int neln = el.Nodes(); // get the element stiffness matrix ke.resize(neln, neln); lm.resize(neln); vector<vec3d> gradN(neln); // calculate stiffness int nint = el.GaussPoints(); // gauss weights double* w = el.GaussWeights(); // nodal coordinates vec3d rt[FEElement::MAX_NODES]; for (int j = 0; j < neln; ++j) rt[j] = mesh.Node(el.m_node[j]).m_rt; // repeat over integration points ke.zero(); for (int n = 0; n < nint; ++n) { double Jt = dom.ShapeGradient0(el, n, gradN.data()); // calculate stiffness component for (int i = 0; i < neln; ++i) { for (int j = 0; j < neln; ++j) ke[i][j] += (gradN[i] * gradN[j]) * w[n] * Jt; } } // get the element's LM vector for (int j = 0; j < el.Nodes(); ++j) { int m = nodeList.GlobalToLocalID(el.m_node[j]); lm[j] = bn[m]; } // assemble element matrix in global stiffness matrix ke.SetIndices(lm); LS.Assemble(ke); } } // solve linear system std::vector<double> x(neq, 0); ls->PreProcess(); ls->Factor(); ls->BackSolve(x, b); for (int i = 0; i < nn; ++i) { int m = bn[i]; if (m >= 0) val[i] = x[m]; } vec3d N = m_normal; N.unit(); FEDomainMap* map = new FEDomainMap(FEDataType::FE_VEC3D, Storage_Fmt::FMT_ITEM); map->Create(elset); for (int i=0; i<elset->Elements(); ++i) { FESolidElement& el = dynamic_cast<FESolidElement&>(elset->Element(i)); FESolidDomain& dom = dynamic_cast<FESolidDomain&>(*el.GetMeshPartition()); int ne = el.Nodes(); double vn[FEElement::MAX_NODES]; for (int j = 0; j < ne; ++j) { int m = nodeList.GlobalToLocalID(el.m_node[j]); vn[j] = val[m]; } // calculate average gradient vec3d grad(0,0,0); for (int j = 0; j < el.GaussPoints(); ++j) { grad += dom.gradient(el, vn, j); } grad.Normalize(); if (m_cross) { vec3d b = grad ^ N; b.unit(); grad = b; } // do plane rotations if (m_outAngle != 0) { vec3d a = grad ^ N; quatd q(m_outAngle * PI / 180.0, a); q.RotateVector(grad); } if (m_inAngle != 0) { quatd q(m_inAngle * PI / 180.0, N); q.RotateVector(grad); } map->setValue(i, grad); } return map; }
C++
3D
febiosoftware/FEBio
FECore/FENode.cpp
.cpp
3,357
137
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FENode.h" #include "DumpStream.h" //============================================================================= // FENode //----------------------------------------------------------------------------- FENode::FENode() { // set the default state m_nstate = 0; // rigid body data m_rid = -1; // default ID m_nID = -1; } //----------------------------------------------------------------------------- void FENode::SetDOFS(int n) { // initialize dof stuff m_ID.assign(n, -1); m_BC.assign(n, 0); m_val_t.assign(n, 0.0); m_val_p.assign(n, 0.0); m_Fr.assign(n, 0.0); } //----------------------------------------------------------------------------- FENode::FENode(const FENode& n) { m_r0 = n.m_r0; m_rt = n.m_rt; m_at = n.m_at; m_rp = n.m_rp; m_vp = n.m_vp; m_ap = n.m_ap; m_d0 = n.m_d0; m_dt = n.m_dt; m_dp = n.m_dp; m_nID = n.m_nID; m_rid = n.m_rid; m_nstate = n.m_nstate; m_ID = n.m_ID; m_BC = n.m_BC; m_val_t = n.m_val_t; m_val_p = n.m_val_p; m_Fr = n.m_Fr; } //----------------------------------------------------------------------------- FENode& FENode::operator = (const FENode& n) { m_r0 = n.m_r0; m_rt = n.m_rt; m_at = n.m_at; m_rp = n.m_rp; m_vp = n.m_vp; m_ap = n.m_ap; m_d0 = n.m_d0; m_dt = n.m_dt; m_dp = n.m_dp; m_nID = n.m_nID; m_rid = n.m_rid; m_nstate = n.m_nstate; m_ID = n.m_ID; m_BC = n.m_BC; m_val_t = n.m_val_t; m_val_p = n.m_val_p; m_Fr = n.m_Fr; return (*this); } //----------------------------------------------------------------------------- // Serialize void FENode::Serialize(DumpStream& ar) { ar & m_rt & m_at; ar & m_rp & m_vp & m_ap; ar & m_Fr; ar & m_val_t & m_val_p; ar & m_dt & m_dp; if (ar.IsShallow() == false) { ar & m_nID; ar & m_nstate; ar & m_ID; ar & m_BC; ar & m_r0; ar & m_ra; ar & m_rid; ar & m_d0; } } //----------------------------------------------------------------------------- //! Update nodal values, which copies the current values to the previous array void FENode::UpdateValues() { m_val_p = m_val_t; }
C++
3D
febiosoftware/FEBio
FECore/FEElemElemList.cpp
.cpp
6,822
268
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEElemElemList.h" #include "FENodeElemList.h" #include "FESolidDomain.h" #include "FESurface.h" #include "FEMesh.h" //----------------------------------------------------------------------------- FEElemElemList::FEElemElemList(void) { m_pmesh = nullptr; } //----------------------------------------------------------------------------- FEElemElemList::~FEElemElemList(void) { } bool FEElemElemList::IsValid() const { return (m_pmesh != nullptr); } void FEElemElemList::Clear() { m_pmesh = nullptr; m_ref.clear(); m_pel.clear(); m_peli.clear(); } //----------------------------------------------------------------------------- void FEElemElemList::Init() { FEMesh& m = *m_pmesh; // allocate storage int NE = m.Elements(); m_ref.resize(NE); // count nr of neighbors int NN = 0, n = 0; for (int i=0; i<m.Domains(); ++i) { FEDomain& dom = m.Domain(i); for (int j=0; j<dom.Elements(); ++j, ++n) { FEElement& el = dom.ElementRef(j); int nf = el.Faces(); m_ref[n] = NN; NN += nf; } } m_pel.resize(NN); m_peli.resize(NN); // TODO: do this for shells as well (if we have to) } //----------------------------------------------------------------------------- bool FEElemElemList::Create(FEMesh* pmesh) { // store a pointer to the mesh m_pmesh = pmesh; FEMesh& m = *m_pmesh; // initialize data structures Init(); // create the node element list FENodeElemList& NEL = pmesh->NodeElementList(); // loop over all solid elements first int en0[FEElement::MAX_NODES], en1[FEElement::MAX_NODES], n0, n1, M = 0; int nf0, nf1; for (int nd=0; nd<m.Domains(); ++nd) { FEDomain& dom = m.Domain(nd); for (int i=0; i<dom.Elements(); ++i) { FEElement& el = dom.ElementRef(i); // get the number of neighbors nf0 = el.Faces(); // loop over all neighbors for (int j=0; j<nf0; ++j, ++M) { // get the face nodes n0 = el.GetFace(j, en0); // find the neighbor element m_pel[M] = 0; m_peli[M] = -1; // loop over all possible candidates int nval = NEL.Valence(en0[0]); FEElement** pne = NEL.ElementList(en0[0]); int* pnei = NEL.ElementIndexList(en0[0]); for (int k=0; k<nval; ++k) { // make sure we don't compare the current element if (pne[k] != &el) { // get the number of faces nf1 = pne[k]->Faces(); // see if any of these faces match en0 for (int l=0; l<nf1; ++l) { n1 = pne[k]->GetFace(l, en1); // make sure the faces have the same nr of nodes if (n1 == n0) { // check triangles if ((n0 == 3) || (n0 == 6) || (n0 ==7)) { if (((en0[0] == en1[0]) || (en0[0] == en1[1]) || (en0[0] == en1[2])) && ((en0[1] == en1[0]) || (en0[1] == en1[1]) || (en0[1] == en1[2])) && ((en0[2] == en1[0]) || (en0[2] == en1[1]) || (en0[2] == en1[2]))) { // found it! m_pel[M] = pne[k]; m_peli[M] = pnei[k]; break; } } // check quads else if ((n0 == 4) || (n0 == 8) || (n0 == 9)) { if (((en0[0] == en1[0]) || (en0[0] == en1[1]) || (en0[0] == en1[2]) || (en0[0] == en1[3])) && ((en0[1] == en1[0]) || (en0[1] == en1[1]) || (en0[1] == en1[2]) || (en0[1] == en1[3])) && ((en0[2] == en1[0]) || (en0[2] == en1[1]) || (en0[2] == en1[2]) || (en0[2] == en1[3])) && ((en0[3] == en1[0]) || (en0[3] == en1[1]) || (en0[3] == en1[2]) || (en0[3] == en1[3]))) { // found it! m_pel[M] = pne[k]; m_peli[M] = pnei[k]; break; } } } if (m_pel[M] != 0) break; } } } } } } // TODO: do the same for shells return true; } //----------------------------------------------------------------------------- //! Find the element neighbors for a surface. In this case, the elements are //! surface elements (i.e. FESurfaceElement). bool FEElemElemList::Create(const FESurface* psurf) { // allocate storage int NE = psurf->Elements(); m_ref.resize(NE); // count nr of neighbors int NN = 0; m_ref[0] = 0; for (int j=0; j<NE; ++j) { const FESurfaceElement& el = psurf->Element(j); int nf = el.facet_edges(); if (j != NE-1) m_ref[j+1] = m_ref[j] + nf; NN += nf; } m_pel.resize(NN); // create the node element list FENodeElemList NEL; NEL.Create(*psurf); // loop over all facets int en0[3], en1[3], M = 0; int nf0, nf1; for (int i=0; i<NE; ++i) { const FESurfaceElement& el = psurf->Element(i); // get the number of neighbors nf0 = el.facet_edges(); // loop over all neighbors for (int j=0; j<nf0; ++j, ++M) { // get the edge nodes el.facet_edge(j, en0); // find the neighbor element m_pel[M] = 0; // loop over all possible candidates int nval = NEL.Valence(en0[0]); FEElement** pne = NEL.ElementList(en0[0]); for (int k=0; k<nval; ++k) { // make sure we don't compare the current element if (pne[k] != &el) { // get the number of edges FESurfaceElement& me = dynamic_cast<FESurfaceElement&>(*pne[k]); nf1 = me.facet_edges(); // see if any of these edges match en0 for (int l=0; l<nf1; ++l) { me.facet_edge(l, en1); if (((en0[0] == en1[0]) || (en0[0] == en1[1])) && ((en0[1] == en1[0]) || (en0[1] == en1[1]))) { // found it! m_pel[M] = pne[k]; break; } } if (m_pel[M] != 0) break; } } } } return true; }
C++
3D
febiosoftware/FEBio
FECore/JFNKMatrix.cpp
.cpp
4,412
190
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "JFNKMatrix.h" #include "FENewtonSolver.h" #include "FEModel.h" #include "FEDomain.h" JFNKMatrix::JFNKMatrix(FENewtonSolver* pns, SparseMatrix* K) : m_pns(pns), m_K(K) { m_nrow = m_ncol = pns->m_neq; m_nsize = 0; m_bauto_eps = false; m_eps = 1e-6; m_policy = ZERO_PRESCRIBED_DOFS; // TODO: For contact problems we'll need some mechanism to change the array size m_v.resize(m_nrow); m_R.resize(m_nrow); // figure out the free and prescribed equation numbers m_freeDofs.clear(); m_prescribedDofs.clear(); FEModel* fem = m_pns->GetFEModel(); FEMesh& mesh = fem->GetMesh(); for (int i = 0; i < mesh.Nodes(); ++i) { FENode& node = mesh.Node(i); for (int j = 0; j < node.m_ID.size(); ++j) { int id = node.m_ID[j]; if (id >= 0) m_freeDofs.push_back(id); if (id < -1) m_prescribedDofs.push_back(-id - 2); } } // Add element dofs for (int i = 0; i < mesh.Domains(); ++i) { FEDomain& dom = mesh.Domain(i); int NEL = dom.Elements(); for (int j = 0; j < NEL; ++j) { FEElement& elj = dom.ElementRef(j); if (elj.m_lm >= 0) m_freeDofs.push_back(elj.m_lm); } } // make sure it all matches assert(m_freeDofs.size() + m_prescribedDofs.size() == m_pns->m_neq); } //! set matrix policy void JFNKMatrix::SetPolicy(MultiplyPolicy p) { m_policy = p; } //! Set the forward difference epsilon void JFNKMatrix::SetEpsilon(double eps) { m_eps = eps; } //! Create a sparse matrix from a sparse-matrix profile void JFNKMatrix::Create(SparseMatrixProfile& MP) { m_K->Create(MP); m_nrow = m_K->Rows(); m_ncol = m_K->Columns(); m_nsize = m_K->NonZeroes(); } void JFNKMatrix::SetReferenceResidual(std::vector<double>& R0) { m_R0 = R0; } bool JFNKMatrix::mult_vector(double* x, double* r) { int neq = (int)m_pns->m_ui.size(); if (m_policy == ZERO_PRESCRIBED_DOFS) { for (int i = 0; i < m_freeDofs.size(); ++i) { int id = m_freeDofs[i]; m_v[id] = x[id]; } for (int i = 0; i < m_prescribedDofs.size(); ++i) { int id = m_prescribedDofs[i]; m_v[id] = 0.0; } } else { for (int i = 0; i < m_freeDofs.size(); ++i) { int id = m_freeDofs[i]; m_v[id] = 0.0; } for (int i = 0; i < m_prescribedDofs.size(); ++i) { int id = m_prescribedDofs[i]; m_v[id] = x[id]; } } double eps = m_eps; if (m_bauto_eps) { vector<double> u; m_pns->GetSolutionVector(u); assert(neq == Rows()); double norm_v = l2_norm(m_v); eps = 0.0; if (norm_v != 0.0) { for (int i = 0; i < neq; ++i) eps += fabs(u[i]); eps *= m_eps / (neq*norm_v); } eps += m_eps; } // multiply by eps for (int i = 0; i < neq; ++i) m_v[i] *= eps; m_pns->Update2(m_v); if (m_pns->Residual(m_R) == false) return false; for (int i = 0; i < m_freeDofs.size(); ++i) { int id = m_freeDofs[i]; r[id] = (m_R0[id] - m_R[id]) / eps; } if (m_policy == ZERO_PRESCRIBED_DOFS) { for (int i = 0; i < m_prescribedDofs.size(); ++i) { int id = m_prescribedDofs[i]; r[id] = x[id]; } } else { for (int i = 0; i < m_prescribedDofs.size(); ++i) { int id = m_prescribedDofs[i]; r[id] = 0.0; } } return true; }
C++
3D
febiosoftware/FEBio
FECore/FELinearSystem.cpp
.cpp
3,755
137
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FELinearSystem.h" #include "FELinearConstraintManager.h" #include "FEModel.h" //----------------------------------------------------------------------------- FELinearSystem::FELinearSystem(FEModel* fem, FEGlobalMatrix& K, vector<double>& F, vector<double>& u, bool bsymm) : m_K(K), m_F(F), m_u(u), m_fem(fem) { m_bsymm = bsymm; } //----------------------------------------------------------------------------- FELinearSystem::~FELinearSystem() { } //----------------------------------------------------------------------------- // get symmetry flag bool FELinearSystem::IsSymmetric() const { return m_bsymm; } //! assemble global stiffness matrix void FELinearSystem::Assemble(const FEElementMatrix& ke) { if ((ke.rows() == 0) || (ke.columns() == 0)) return; // assemble into the global stiffness m_K.Assemble(ke); // check the prescribed contributions SparseMatrix& K = m_K; int N = ke.rows(); int neq = m_K.Rows(); // loop over columns const vector<int>& lmi = ke.RowIndices(); const vector<int>& lmj = ke.ColumnsIndices(); for (int j = 0; j<N; ++j) { int J = -lmj[j] - 2; if ((J >= 0) && (J<neq)) { // dof j is a prescribed degree of freedom // loop over rows for (int i = 0; i<N; ++i) { int I = lmi[i]; if (I >= 0) { // dof i is not a prescribed degree of freedom #pragma omp atomic m_F[I] -= ke[i][j] * m_u[J]; } } // set the diagonal element of K to 1 K.set(J, J, 1); } } if (m_fem) { FELinearConstraintManager& LCM = m_fem->GetLinearConstraintManager(); if (LCM.LinearConstraints()) { const vector<int>& en = ke.Nodes(); #pragma omp critical (LC_assemble) LCM.AssembleStiffness(m_K, m_F, m_u, en, lmi, lmj, ke); } } } //----------------------------------------------------------------------------- void FELinearSystem::AssembleRHS(vector<int>& lm, matrix& ke, vector<double>& U) { int ne = (int)lm.size(); for (int j = 0; j<ne; ++j) { if (lm[j] >= 0) { double q = 0; for (int k = 0; k<ne; ++k) { if (lm[k] >= 0) q += ke[j][k] * U[lm[k]]; else if (-lm[k] - 2 >= 0) q += ke[j][k] * U[-lm[k] - 2]; } m_F[lm[j]] += q; } } } //----------------------------------------------------------------------------- void FELinearSystem::AssembleRHS(vector<int>& lm, vector<double>& fe) { const int n = (int)lm.size(); for (int i = 0; i<n; ++i) { int nid = lm[i]; if (nid >= 0) { m_F[nid] += fe[i]; } } }
C++
3D
febiosoftware/FEBio
FECore/SkylineSolver.cpp
.cpp
2,894
80
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "SkylineSolver.h" //----------------------------------------------------------------------------- void colsol_factor(int N, double* values, int* pointers); void colsol_solve(int N, double* values, int* pointers, double* R); //----------------------------------------------------------------------------- SkylineSolver::SkylineSolver(FEModel* fem) : LinearSolver(fem), m_pA(0) { } //----------------------------------------------------------------------------- //! Create a sparse matrix SparseMatrix* SkylineSolver::CreateSparseMatrix(Matrix_Type ntype) { return (m_pA = (ntype == REAL_SYMMETRIC? new SkylineMatrix() : 0)); } //----------------------------------------------------------------------------- bool SkylineSolver::PreProcess() { // We don't need to do any preprocessing for this solver return LinearSolver::PreProcess(); } //----------------------------------------------------------------------------- bool SkylineSolver::Factor() { colsol_factor(m_pA->Rows(), m_pA->values(), m_pA->pointers()); return true; } //----------------------------------------------------------------------------- bool SkylineSolver::BackSolve(double* x, double* b) { // we need to make a copy of R since colsol overwrites the right hand side vector // with the solution int neq = m_pA->Rows(); for (int i=0; i<neq; ++i) x[i] = b[i]; colsol_solve(m_pA->Rows(), m_pA->values(), m_pA->pointers(), x); return true; } //----------------------------------------------------------------------------- void SkylineSolver::Destroy() { // Nothing to destroy LinearSolver::Destroy(); }
C++
3D
febiosoftware/FEBio
FECore/FEModelLoad.cpp
.cpp
2,415
77
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEModelLoad.h" #include "FESolver.h" //----------------------------------------------------------------------------- FEModelLoad::FEModelLoad(FEModel* pfem) : FEStepComponent(pfem), m_dof(pfem) { } //----------------------------------------------------------------------------- const FEDofList& FEModelLoad::GetDofList() const { return m_dof; } //----------------------------------------------------------------------------- void FEModelLoad::Serialize(DumpStream& ar) { FEStepComponent::Serialize(ar); ar & m_dof; } void FEModelLoad::PrepStep() { } Matrix_Type FEModelLoad::PreferredMatrixType() { FEParam* p = GetParameter("symmetric_stiffness"); if (p && (p->type() == FE_PARAM_BOOL) && !p->value<bool>()) { return REAL_UNSYMMETRIC; } return REAL_SYMMETRIC; } //----------------------------------------------------------------------------- void FEModelLoad::LoadVector(FEGlobalVector& R) { // base class does nothing } //----------------------------------------------------------------------------- void FEModelLoad::StiffnessMatrix(FELinearSystem& LS) { // base class does nothing. }
C++
3D
febiosoftware/FEBio
FECore/FESurfacePair.h
.h
2,035
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_api.h" #include <string> //----------------------------------------------------------------------------- class FEMesh; class FEFacetSet; class DumpStream; //----------------------------------------------------------------------------- class FECORE_API FESurfacePair { public: FESurfacePair(FEMesh* pm); void SetName(const std::string& name); const std::string& GetName() const; FEFacetSet* GetPrimarySurface(); void SetPrimarySurface(FEFacetSet* pf); FEFacetSet* GetSecondarySurface(); void SetSecondarySurface(FEFacetSet* pf); void Serialize(DumpStream& ar); private: std::string m_name; FEFacetSet* m_surface1; // the primary surface FEFacetSet* m_surface2; // the secondary surface FEMesh* m_mesh; };
Unknown
3D
febiosoftware/FEBio
FECore/FELinearSystem.h
.h
2,978
75
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEGlobalMatrix.h" #include "matrix.h" #include <vector> class FEModel; //----------------------------------------------------------------------------- // Experimental class to see if all the assembly operations can be moved to a class // and out of the solver class. class FECORE_API FELinearSystem { public: // Constructor // Takes a FEGlobalMatrix class K that will store the actual stiffness matrix // and a vector F which contains the assembled contribution of the prescribed // degrees of freedom. The F vector must be added to the "force" vector. The u // vector contains the nodal values of the prescribed degrees of freedom. FELinearSystem(FEModel* fem, FEGlobalMatrix& K, std::vector<double>& F, std::vector<double>& u, bool bsymm); // virtual destructor virtual ~FELinearSystem(); // get symmetry flag bool IsSymmetric() const; public: // Assembly routine // This assembles the element stiffness matrix ke into the global matrix. // The contributions of prescribed degrees of freedom will be stored in m_F virtual void Assemble(const FEElementMatrix& ke); // This assembles a matrix to the RHS by pre-multiplying the matrix with the // prescribed value array U and then adding it to F void AssembleRHS(std::vector<int>& lm, matrix& ke, std::vector<double>& U); // This assembles a vetor to the RHS void AssembleRHS(std::vector<int>& lm, std::vector<double>& fe); protected: bool m_bsymm; //!< symmetry flag FEModel* m_fem; FEGlobalMatrix& m_K; //!< The global stiffness matrix std::vector<double>& m_F; //!< Contributions from prescribed degrees of freedom std::vector<double>& m_u; //!< the array with prescribed values };
Unknown
3D
febiosoftware/FEBio
FECore/SkylineMatrix.h
.h
2,523
79
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "SparseMatrix.h" #include "fecore_api.h" //============================================================================= //! Implements a sparse matrix using the skyline storage //! This class implements a symmetric sparse matrix where only the values //! below the skyline are stored. class FECORE_API SkylineMatrix : public SparseMatrix { public: SkylineMatrix(); virtual ~SkylineMatrix(); public: // from SparseMatrix void Zero() override; void Clear() override; void Create(SparseMatrixProfile& mp) override; void Assemble(const matrix& ke, const std::vector<int>& lm) override; //! assemble a matrix into the sparse matrix void Assemble(const matrix& ke, const std::vector<int>& lmi, const std::vector<int>& lmj) override; void add(int i, int j, double v) override; void set(int i, int j, double v) override; // NOTE: This is not implemented yet! bool check(int i, int j) override; double get(int i, int j) override; double diag(int i) override; double* values() { return m_pd; } int* pointers() { return m_ppointers; } protected: void Create(double* pv, int* pp, int N); protected: double* m_pd; //!< matrix values int* m_ppointers; //!< arrays of indices to diagonal elements };
Unknown
3D
febiosoftware/FEBio
FECore/FEBeamDomain.h
.h
1,705
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) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEDomain.h" //----------------------------------------------------------------------------- //! Abstract base class for beam domains class FECORE_API FEBeamDomain : public FEDomain { FECORE_SUPER_CLASS(FEBEAMDOMAIN_ID) FECORE_BASE_CLASS(FEBeamDomain) // get the element type (TODO: Move to FEDomain class?) int GetElementType() { return ElementRef(0).Type(); }; public: FEBeamDomain(FEModel* pm); };
Unknown
3D
febiosoftware/FEBio
FECore/FEShellDomain.h
.h
4,815
146
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEDomain.h" #include "FEShellElement.h" //----------------------------------------------------------------------------- //! Abstract base class for shell element domains class FECORE_API FEShellDomain : public FEDomain { FECORE_SUPER_CLASS(FESHELLDOMAIN_ID) FECORE_BASE_CLASS(FEShellDomain) public: //! constructor FEShellDomain(FEModel* fem); //! Update element data prior to solving time step void PreSolveUpdate(const FETimeInfo& timeInfo); //! Reset element data void Reset(); // get a shell element virtual FEShellElement& Element(int i) = 0; // get the element type (TODO: Move to FEDomain class?) int GetElementType() { return ElementRef(0).Type(); }; public: // evaluate volume of element in reference frame virtual double Volume(FEShellElement& el) { return 0.0; } // evaluate volume of element in current frame virtual double CurrentVolume(FEShellElement& el) { return 0.0; } // Initialize shell data (Called from FEMesh::InitShells) virtual bool InitShells(); virtual void AssignDefaultShellThickness() {} public: //! get the current nodal coordinates void GetCurrentNodalCoordinates(const FEShellElement& el, vec3d* rt, const bool back = false); void GetCurrentNodalCoordinates(const FEShellElement& el, vec3d* rt, double alpha, const bool back = false); //! get the reference nodal coordinates void GetReferenceNodalCoordinates(const FEShellElement& el, vec3d* r0, const bool back = false); //! get the nodal coordinates at previous state void GetPreviousNodalCoordinates(const FEShellElement& el, vec3d* rp, const bool back = false); public: void ForEachShellElement(std::function<void(FEShellElement& el)> f); DECLARE_FECORE_CLASS(); }; //----------------------------------------------------------------------------- // Old director-based shell formulation class FECORE_API FEShellDomainOld : public FEShellDomain { public: FEShellDomainOld(FEModel* fem); //! create storage for elements bool Create(int nsize, FE_Element_Spec espec) override; public: //! return nr of elements int Elements() const override { return (int)m_Elem.size(); } //! element access FEShellElement& Element(int n) override { return m_Elem[n]; } FEElement& ElementRef(int n) override { return m_Elem[n]; } const FEElement& ElementRef(int n) const override { return m_Elem[n]; } FEShellElementOld& ShellElement(int i) { return m_Elem[i]; } double Volume(FEShellElement& el) override; bool InitShells() override; protected: vector<FEShellElementOld> m_Elem; //!< array of elements }; //----------------------------------------------------------------------------- // New shell formulation class FECORE_API FEShellDomainNew : public FEShellDomain { public: FEShellDomainNew(FEModel* fem); //! create storage for elements bool Create(int nsize, FE_Element_Spec espec) override; public: //! return nr of elements int Elements() const override { return (int)m_Elem.size(); } //! element access FEShellElement& Element(int n) override { return m_Elem[n]; } FEElement& ElementRef(int n) override { return m_Elem[n]; } const FEElement& ElementRef(int n) const override { return m_Elem[n]; } FEShellElementNew& ShellElement(int i) { return m_Elem[i]; } double Volume(FEShellElement& el) override; double DefaultShellThickness() const { return m_h0; } void AssignDefaultShellThickness() override; protected: double m_h0; protected: vector<FEShellElementNew> m_Elem; //!< array of elements DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FECore/tens4dmm.hpp
.hpp
115,486
909
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 // NOTE: This file is automatically included from tens4d.h // Users should not include this file manually! inline tens4dmm::tens4dmm(const double g) { d[ 0] = d[ 1] = d[ 2] = d[ 3] = d[ 4] = d[ 5] = d[ 6] = d[ 7] = d[ 8] = d[ 9] = d[10] = d[11] = d[12] = d[13] = d[14] = d[15] = d[16] = d[17] = d[18] = d[19] = d[20] = d[21] = d[22] = d[23] = d[24] = d[25] = d[26] = d[27] = d[28] = d[29] = d[30] = d[31] = d[32] = d[33] = d[34] = d[35] = g; } inline tens4dmm::tens4dmm(const tens4ds t) { d[ 0] = t.d[ 0]; d[ 6] = t.d[ 1]; d[12] = t.d[ 3]; d[18] = t.d[ 6]; d[24] = t.d[10]; d[30] = t.d[15]; d[ 1] = t.d[ 1]; d[ 7] = t.d[ 2]; d[13] = t.d[ 4]; d[19] = t.d[ 7]; d[25] = t.d[11]; d[31] = t.d[16]; d[ 2] = t.d[ 3]; d[ 8] = t.d[ 4]; d[14] = t.d[ 5]; d[20] = t.d[ 8]; d[26] = t.d[12]; d[32] = t.d[17]; d[ 3] = t.d[ 6]; d[ 9] = t.d[ 7]; d[15] = t.d[ 8]; d[21] = t.d[ 9]; d[27] = t.d[13]; d[33] = t.d[18]; d[ 4] = t.d[10]; d[10] = t.d[11]; d[16] = t.d[12]; d[22] = t.d[13]; d[28] = t.d[14]; d[34] = t.d[19]; d[ 5] = t.d[15]; d[11] = t.d[16]; d[17] = t.d[17]; d[23] = t.d[18]; d[29] = t.d[19]; d[35] = t.d[20]; } inline tens4dmm::tens4dmm(double m[6][6]) { d[ 0]=m[0][0]; d[ 6]=m[0][1]; d[12]=m[0][2]; d[18]=m[0][3]; d[24]=m[0][4]; d[30]=m[0][5]; d[ 1]=m[1][0]; d[ 7]=m[1][1]; d[13]=m[1][2]; d[19]=m[1][3]; d[25]=m[1][4]; d[31]=m[1][5]; d[ 2]=m[2][0]; d[ 8]=m[2][1]; d[14]=m[2][2]; d[20]=m[2][3]; d[26]=m[2][4]; d[32]=m[2][5]; d[ 3]=m[3][0]; d[ 9]=m[3][1]; d[15]=m[3][2]; d[21]=m[3][3]; d[27]=m[3][4]; d[33]=m[3][5]; d[ 4]=m[4][0]; d[10]=m[4][1]; d[16]=m[4][2]; d[22]=m[4][3]; d[28]=m[4][4]; d[34]=m[4][5]; d[ 5]=m[5][0]; d[11]=m[5][1]; d[17]=m[5][2]; d[23]=m[5][3]; d[29]=m[5][4]; d[35]=m[5][5]; } inline double& tens4dmm::operator () (int i, int j, int k, int l) { const int m[3][3] = {{0,3,5},{3,1,4},{5,4,2}}; tens4dmm& T = (*this); return T(m[i][j], m[k][l]); } inline double tens4dmm::operator () (int i, int j, int k, int l) const { const int m[3][3] = {{0,3,5},{3,1,4},{5,4,2}}; const tens4dmm& T = (*this); return T(m[i][j], m[k][l]); } inline double& tens4dmm::operator () (int i, int j) { const int m[6] = {0, 6, 12, 18, 24, 30}; return d[m[j]+i]; } inline double tens4dmm::operator () (int i, int j) const { const int m[6] = {0, 6, 12, 18, 24, 30}; return d[m[j]+i]; } //----------------------------------------------------------------------------- // operator + inline tens4dmm tens4dmm::operator + (const tens4dmm& t) const { tens4dmm s; // for (int i=0; i<NNZ; i++) // s.d[i] = d[i] + t.d[i]; s.d[ 0] = d[ 0] + t.d[ 0]; s.d[12] = d[12] + t.d[12]; s.d[24] = d[24] + t.d[24]; s.d[ 1] = d[ 1] + t.d[ 1]; s.d[13] = d[13] + t.d[13]; s.d[25] = d[25] + t.d[25]; s.d[ 2] = d[ 2] + t.d[ 2]; s.d[14] = d[14] + t.d[14]; s.d[26] = d[26] + t.d[26]; s.d[ 3] = d[ 3] + t.d[ 3]; s.d[15] = d[15] + t.d[15]; s.d[27] = d[27] + t.d[27]; s.d[ 4] = d[ 4] + t.d[ 4]; s.d[16] = d[16] + t.d[16]; s.d[28] = d[28] + t.d[28]; s.d[ 5] = d[ 5] + t.d[ 5]; s.d[17] = d[17] + t.d[17]; s.d[29] = d[29] + t.d[29]; s.d[ 6] = d[ 6] + t.d[ 6]; s.d[18] = d[18] + t.d[18]; s.d[30] = d[30] + t.d[30]; s.d[ 7] = d[ 7] + t.d[ 7]; s.d[19] = d[19] + t.d[19]; s.d[31] = d[31] + t.d[31]; s.d[ 8] = d[ 8] + t.d[ 8]; s.d[20] = d[20] + t.d[20]; s.d[32] = d[32] + t.d[32]; s.d[ 9] = d[ 9] + t.d[ 9]; s.d[21] = d[21] + t.d[21]; s.d[33] = d[33] + t.d[33]; s.d[10] = d[10] + t.d[10]; s.d[22] = d[22] + t.d[22]; s.d[34] = d[34] + t.d[34]; s.d[11] = d[11] + t.d[11]; s.d[23] = d[23] + t.d[23]; s.d[35] = d[35] + t.d[35]; return s; } //----------------------------------------------------------------------------- // operator - inline tens4dmm tens4dmm::operator - (const tens4dmm& t) const { tens4dmm s; // for (int i=0; i<NNZ; i++) // s.d[i] = d[i] - t.d[i]; s.d[ 0] = d[ 0] - t.d[ 0]; s.d[12] = d[12] - t.d[12]; s.d[24] = d[24] - t.d[24]; s.d[ 1] = d[ 1] - t.d[ 1]; s.d[13] = d[13] - t.d[13]; s.d[25] = d[25] - t.d[25]; s.d[ 2] = d[ 2] - t.d[ 2]; s.d[14] = d[14] - t.d[14]; s.d[26] = d[26] - t.d[26]; s.d[ 3] = d[ 3] - t.d[ 3]; s.d[15] = d[15] - t.d[15]; s.d[27] = d[27] - t.d[27]; s.d[ 4] = d[ 4] - t.d[ 4]; s.d[16] = d[16] - t.d[16]; s.d[28] = d[28] - t.d[28]; s.d[ 5] = d[ 5] - t.d[ 5]; s.d[17] = d[17] - t.d[17]; s.d[29] = d[29] - t.d[29]; s.d[ 6] = d[ 6] - t.d[ 6]; s.d[18] = d[18] - t.d[18]; s.d[30] = d[30] - t.d[30]; s.d[ 7] = d[ 7] - t.d[ 7]; s.d[19] = d[19] - t.d[19]; s.d[31] = d[31] - t.d[31]; s.d[ 8] = d[ 8] - t.d[ 8]; s.d[20] = d[20] - t.d[20]; s.d[32] = d[32] - t.d[32]; s.d[ 9] = d[ 9] - t.d[ 9]; s.d[21] = d[21] - t.d[21]; s.d[33] = d[33] - t.d[33]; s.d[10] = d[10] - t.d[10]; s.d[22] = d[22] - t.d[22]; s.d[34] = d[34] - t.d[34]; s.d[11] = d[11] - t.d[11]; s.d[23] = d[23] - t.d[23]; s.d[35] = d[35] - t.d[35]; return s; } //----------------------------------------------------------------------------- // operator + tens4ds inline tens4dmm tens4dmm::operator + (const tens4ds& t) const { tens4dmm s; s.d[ 0] = d[ 0] + t.d[ 0]; s.d[12] = d[12] + t.d[ 3]; s.d[24] = d[24] + t.d[10]; s.d[ 1] = d[ 1] + t.d[ 1]; s.d[13] = d[13] + t.d[ 4]; s.d[25] = d[25] + t.d[11]; s.d[ 2] = d[ 2] + t.d[ 3]; s.d[14] = d[14] + t.d[ 5]; s.d[26] = d[26] + t.d[12]; s.d[ 3] = d[ 3] + t.d[ 6]; s.d[15] = d[15] + t.d[ 8]; s.d[27] = d[27] + t.d[13]; s.d[ 4] = d[ 4] + t.d[10]; s.d[16] = d[16] + t.d[12]; s.d[28] = d[28] + t.d[14]; s.d[ 5] = d[ 5] + t.d[15]; s.d[17] = d[17] + t.d[17]; s.d[29] = d[29] + t.d[19]; s.d[ 6] = d[ 6] + t.d[ 1]; s.d[18] = d[18] + t.d[ 6]; s.d[30] = d[30] + t.d[15]; s.d[ 7] = d[ 7] + t.d[ 2]; s.d[19] = d[19] + t.d[ 7]; s.d[31] = d[31] + t.d[16]; s.d[ 8] = d[ 8] + t.d[ 4]; s.d[20] = d[20] + t.d[ 8]; s.d[32] = d[32] + t.d[17]; s.d[ 9] = d[ 9] + t.d[ 7]; s.d[21] = d[21] + t.d[ 9]; s.d[33] = d[33] + t.d[18]; s.d[10] = d[10] + t.d[11]; s.d[22] = d[22] + t.d[13]; s.d[34] = d[34] + t.d[19]; s.d[11] = d[11] + t.d[16]; s.d[23] = d[23] + t.d[18]; s.d[35] = d[35] + t.d[20]; return s; } //----------------------------------------------------------------------------- // operator - tens4ds inline tens4dmm tens4dmm::operator - (const tens4ds& t) const { tens4dmm s; s.d[ 0] = d[ 0] - t.d[ 0]; s.d[12] = d[12] - t.d[ 3]; s.d[24] = d[24] - t.d[10]; s.d[ 1] = d[ 1] - t.d[ 1]; s.d[13] = d[13] - t.d[ 4]; s.d[25] = d[25] - t.d[11]; s.d[ 2] = d[ 2] - t.d[ 3]; s.d[14] = d[14] - t.d[ 5]; s.d[26] = d[26] - t.d[12]; s.d[ 3] = d[ 3] - t.d[ 6]; s.d[15] = d[15] - t.d[ 8]; s.d[27] = d[27] - t.d[13]; s.d[ 4] = d[ 4] - t.d[10]; s.d[16] = d[16] - t.d[12]; s.d[28] = d[28] - t.d[14]; s.d[ 5] = d[ 5] - t.d[15]; s.d[17] = d[17] - t.d[17]; s.d[29] = d[29] - t.d[19]; s.d[ 6] = d[ 6] - t.d[ 1]; s.d[18] = d[18] - t.d[ 6]; s.d[30] = d[30] - t.d[15]; s.d[ 7] = d[ 7] - t.d[ 2]; s.d[19] = d[19] - t.d[ 7]; s.d[31] = d[31] - t.d[16]; s.d[ 8] = d[ 8] - t.d[ 4]; s.d[20] = d[20] - t.d[ 8]; s.d[32] = d[32] - t.d[17]; s.d[ 9] = d[ 9] - t.d[ 7]; s.d[21] = d[21] - t.d[ 9]; s.d[33] = d[33] - t.d[18]; s.d[10] = d[10] - t.d[11]; s.d[22] = d[22] - t.d[13]; s.d[34] = d[34] - t.d[19]; s.d[11] = d[11] - t.d[16]; s.d[23] = d[23] - t.d[18]; s.d[35] = d[35] - t.d[20]; return s; } //----------------------------------------------------------------------------- // operator * inline tens4dmm tens4dmm::operator * (double g) const { tens4dmm s; // for (int i=0; i<NNZ; i++) // s.d[i] = g*d[i]; s.d[ 0] = g*d[ 0]; s.d[12] = g*d[12]; s.d[24] = g*d[24]; s.d[ 1] = g*d[ 1]; s.d[13] = g*d[13]; s.d[25] = g*d[25]; s.d[ 2] = g*d[ 2]; s.d[14] = g*d[14]; s.d[26] = g*d[26]; s.d[ 3] = g*d[ 3]; s.d[15] = g*d[15]; s.d[27] = g*d[27]; s.d[ 4] = g*d[ 4]; s.d[16] = g*d[16]; s.d[28] = g*d[28]; s.d[ 5] = g*d[ 5]; s.d[17] = g*d[17]; s.d[29] = g*d[29]; s.d[ 6] = g*d[ 6]; s.d[18] = g*d[18]; s.d[30] = g*d[30]; s.d[ 7] = g*d[ 7]; s.d[19] = g*d[19]; s.d[31] = g*d[31]; s.d[ 8] = g*d[ 8]; s.d[20] = g*d[20]; s.d[32] = g*d[32]; s.d[ 9] = g*d[ 9]; s.d[21] = g*d[21]; s.d[33] = g*d[33]; s.d[10] = g*d[10]; s.d[22] = g*d[22]; s.d[34] = g*d[34]; s.d[11] = g*d[11]; s.d[23] = g*d[23]; s.d[35] = g*d[35]; return s; } //----------------------------------------------------------------------------- // operator / inline tens4dmm tens4dmm::operator / (double g) const { tens4dmm s; // for (int i=0; i<NNZ; i++) // s.d[i] = d[i]/g; s.d[ 0] = d[ 0]/g; s.d[12] = d[12]/g; s.d[24] = d[24]/g; s.d[ 1] = d[ 1]/g; s.d[13] = d[13]/g; s.d[25] = d[25]/g; s.d[ 2] = d[ 2]/g; s.d[14] = d[14]/g; s.d[26] = d[26]/g; s.d[ 3] = d[ 3]/g; s.d[15] = d[15]/g; s.d[27] = d[27]/g; s.d[ 4] = d[ 4]/g; s.d[16] = d[16]/g; s.d[28] = d[28]/g; s.d[ 5] = d[ 5]/g; s.d[17] = d[17]/g; s.d[29] = d[29]/g; s.d[ 6] = d[ 6]/g; s.d[18] = d[18]/g; s.d[30] = d[30]/g; s.d[ 7] = d[ 7]/g; s.d[19] = d[19]/g; s.d[31] = d[31]/g; s.d[ 8] = d[ 8]/g; s.d[20] = d[20]/g; s.d[32] = d[32]/g; s.d[ 9] = d[ 9]/g; s.d[21] = d[21]/g; s.d[33] = d[33]/g; s.d[10] = d[10]/g; s.d[22] = d[22]/g; s.d[34] = d[34]/g; s.d[11] = d[11]/g; s.d[23] = d[23]/g; s.d[35] = d[35]/g; return s; } //----------------------------------------------------------------------------- // assignment operator += inline tens4dmm& tens4dmm::operator += (const tens4dmm& t) { // for (int i=0; i<NNZ; i++) // d[i] += t.d[i]; d[ 0] += t.d[ 0]; d[12] += t.d[12]; d[24] += t.d[24]; d[ 1] += t.d[ 1]; d[13] += t.d[13]; d[25] += t.d[25]; d[ 2] += t.d[ 2]; d[14] += t.d[14]; d[26] += t.d[26]; d[ 3] += t.d[ 3]; d[15] += t.d[15]; d[27] += t.d[27]; d[ 4] += t.d[ 4]; d[16] += t.d[16]; d[28] += t.d[28]; d[ 5] += t.d[ 5]; d[17] += t.d[17]; d[29] += t.d[29]; d[ 6] += t.d[ 6]; d[18] += t.d[18]; d[30] += t.d[30]; d[ 7] += t.d[ 7]; d[19] += t.d[19]; d[31] += t.d[31]; d[ 8] += t.d[ 8]; d[20] += t.d[20]; d[32] += t.d[32]; d[ 9] += t.d[ 9]; d[21] += t.d[21]; d[33] += t.d[33]; d[10] += t.d[10]; d[22] += t.d[22]; d[34] += t.d[34]; d[11] += t.d[11]; d[23] += t.d[23]; d[35] += t.d[35]; return (*this); } //----------------------------------------------------------------------------- // assignment operator -= inline tens4dmm& tens4dmm::operator -= (const tens4dmm& t) { // for (int i=0; i<NNZ; i++) // d[i] -= t.d[i]; d[ 0] -= t.d[ 0]; d[12] -= t.d[12]; d[24] -= t.d[24]; d[ 1] -= t.d[ 1]; d[13] -= t.d[13]; d[25] -= t.d[25]; d[ 2] -= t.d[ 2]; d[14] -= t.d[14]; d[26] -= t.d[26]; d[ 3] -= t.d[ 3]; d[15] -= t.d[15]; d[27] -= t.d[27]; d[ 4] -= t.d[ 4]; d[16] -= t.d[16]; d[28] -= t.d[28]; d[ 5] -= t.d[ 5]; d[17] -= t.d[17]; d[29] -= t.d[29]; d[ 6] -= t.d[ 6]; d[18] -= t.d[18]; d[30] -= t.d[30]; d[ 7] -= t.d[ 7]; d[19] -= t.d[19]; d[31] -= t.d[31]; d[ 8] -= t.d[ 8]; d[20] -= t.d[20]; d[32] -= t.d[32]; d[ 9] -= t.d[ 9]; d[21] -= t.d[21]; d[33] -= t.d[33]; d[10] -= t.d[10]; d[22] -= t.d[22]; d[34] -= t.d[34]; d[11] -= t.d[11]; d[23] -= t.d[23]; d[35] -= t.d[35]; return (*this); } //----------------------------------------------------------------------------- // assignment operator += tens4ds inline tens4dmm& tens4dmm::operator += (const tens4ds& t) { d[ 0] += t.d[ 0]; d[12] += t.d[ 3]; d[24] += t.d[10]; d[ 1] += t.d[ 1]; d[13] += t.d[ 4]; d[25] += t.d[11]; d[ 2] += t.d[ 3]; d[14] += t.d[ 5]; d[26] += t.d[12]; d[ 3] += t.d[ 6]; d[15] += t.d[ 8]; d[27] += t.d[13]; d[ 4] += t.d[10]; d[16] += t.d[12]; d[28] += t.d[14]; d[ 5] += t.d[15]; d[17] += t.d[17]; d[29] += t.d[19]; d[ 6] += t.d[ 1]; d[18] += t.d[ 6]; d[30] += t.d[15]; d[ 7] += t.d[ 2]; d[19] += t.d[ 7]; d[31] += t.d[16]; d[ 8] += t.d[ 4]; d[20] += t.d[ 8]; d[32] += t.d[17]; d[ 9] += t.d[ 7]; d[21] += t.d[ 9]; d[33] += t.d[18]; d[10] += t.d[11]; d[22] += t.d[13]; d[34] += t.d[19]; d[11] += t.d[16]; d[23] += t.d[18]; d[35] += t.d[20]; return (*this); } //----------------------------------------------------------------------------- // assignment operator -= tens4ds inline tens4dmm& tens4dmm::operator -= (const tens4ds& t) { d[ 0] -= t.d[ 0]; d[12] -= t.d[ 3]; d[24] -= t.d[10]; d[ 1] -= t.d[ 1]; d[13] -= t.d[ 4]; d[25] -= t.d[11]; d[ 2] -= t.d[ 3]; d[14] -= t.d[ 5]; d[26] -= t.d[12]; d[ 3] -= t.d[ 6]; d[15] -= t.d[ 8]; d[27] -= t.d[13]; d[ 4] -= t.d[10]; d[16] -= t.d[12]; d[28] -= t.d[14]; d[ 5] -= t.d[15]; d[17] -= t.d[17]; d[29] -= t.d[19]; d[ 6] -= t.d[ 1]; d[18] -= t.d[ 6]; d[30] -= t.d[15]; d[ 7] -= t.d[ 2]; d[19] -= t.d[ 7]; d[31] -= t.d[16]; d[ 8] -= t.d[ 4]; d[20] -= t.d[ 8]; d[32] -= t.d[17]; d[ 9] -= t.d[ 7]; d[21] -= t.d[ 9]; d[33] -= t.d[18]; d[10] -= t.d[11]; d[22] -= t.d[13]; d[34] -= t.d[19]; d[11] -= t.d[16]; d[23] -= t.d[18]; d[35] -= t.d[20]; return (*this); } //----------------------------------------------------------------------------- // assignment operator *= inline tens4dmm& tens4dmm::operator *= (double g) { // for (int i=0; i<NNZ; i++) // d[i] *= g; d[ 0] *= g; d[12] *= g; d[24] *= g; d[ 1] *= g; d[13] *= g; d[25] *= g; d[ 2] *= g; d[14] *= g; d[26] *= g; d[ 3] *= g; d[15] *= g; d[27] *= g; d[ 4] *= g; d[16] *= g; d[28] *= g; d[ 5] *= g; d[17] *= g; d[29] *= g; d[ 6] *= g; d[18] *= g; d[30] *= g; d[ 7] *= g; d[19] *= g; d[31] *= g; d[ 8] *= g; d[20] *= g; d[32] *= g; d[ 9] *= g; d[21] *= g; d[33] *= g; d[10] *= g; d[22] *= g; d[34] *= g; d[11] *= g; d[23] *= g; d[35] *= g; return (*this); } //----------------------------------------------------------------------------- // assignment operator /= inline tens4dmm& tens4dmm::operator /= (double g) { // for (int i=0; i<NNZ; i++) // d[i] /= g; d[ 0] /= g; d[12] /= g; d[24] /= g; d[ 1] /= g; d[13] /= g; d[25] /= g; d[ 2] /= g; d[14] /= g; d[26] /= g; d[ 3] /= g; d[15] /= g; d[27] /= g; d[ 4] /= g; d[16] /= g; d[28] /= g; d[ 5] /= g; d[17] /= g; d[29] /= g; d[ 6] /= g; d[18] /= g; d[30] /= g; d[ 7] /= g; d[19] /= g; d[31] /= g; d[ 8] /= g; d[20] /= g; d[32] /= g; d[ 9] /= g; d[21] /= g; d[33] /= g; d[10] /= g; d[22] /= g; d[34] /= g; d[11] /= g; d[23] /= g; d[35] /= g; return (*this); } //----------------------------------------------------------------------------- // unary operator - inline tens4dmm tens4dmm::operator - () const { tens4dmm s; s.d[ 0] = -d[ 0]; s.d[12] = -d[12]; s.d[24] = -d[24]; s.d[ 1] = -d[ 1]; s.d[13] = -d[13]; s.d[25] = -d[25]; s.d[ 2] = -d[ 2]; s.d[14] = -d[14]; s.d[26] = -d[26]; s.d[ 3] = -d[ 3]; s.d[15] = -d[15]; s.d[27] = -d[27]; s.d[ 4] = -d[ 4]; s.d[16] = -d[16]; s.d[28] = -d[28]; s.d[ 5] = -d[ 5]; s.d[17] = -d[17]; s.d[29] = -d[29]; s.d[ 6] = -d[ 6]; s.d[18] = -d[18]; s.d[30] = -d[30]; s.d[ 7] = -d[ 7]; s.d[19] = -d[19]; s.d[31] = -d[31]; s.d[ 8] = -d[ 8]; s.d[20] = -d[20]; s.d[32] = -d[32]; s.d[ 9] = -d[ 9]; s.d[21] = -d[21]; s.d[33] = -d[33]; s.d[10] = -d[10]; s.d[22] = -d[22]; s.d[34] = -d[34]; s.d[11] = -d[11]; s.d[23] = -d[23]; s.d[35] = -d[35]; return s; } //----------------------------------------------------------------------------- // operator * mat3ds inline tens4dmm tens4dmm::operator * (const mat3ds& m) const { tens4dmm t = *this; tens4dmm s; for (int i=0; i<3; ++i) for (int j=0; j<3; ++j) for (int k=0; k<3; ++k) for (int n=0; n<3; ++n) { s(i,j,k,n) = t(i,j,k,0)*m(0,n) + t(i,j,k,1)*m(1,n) + t(i,j,k,2)*m(2,n); } return s; } //----------------------------------------------------------------------------- // operator * mat3d inline tens4dmm tens4dmm::operator * (const mat3d& m) const { tens4dmm t = *this; tens4dmm s; for (int i=0; i<3; ++i) for (int j=0; j<3; ++j) for (int k=0; k<3; ++k) for (int n=0; n<3; ++n) { s(i,j,k,n) = t(i,j,k,0)*m(0,n) + t(i,j,k,1)*m(1,n) + t(i,j,k,2)*m(2,n); } return s; } //----------------------------------------------------------------------------- // vdotTdotv_jk = a_i T_ijkl b_l inline mat3d vdotTdotv(const vec3d& a, const tens4dmm& T, const vec3d& b) { return mat3d(a.x*b.x*T.d[0] + a.y*b.x*T.d[3] + a.z*b.x*T.d[5] + a.x*b.y*T.d[18] + a.y*b.y*T.d[21] + a.z*b.y*T.d[23] + a.x*b.z*T.d[30] + a.y*b.z*T.d[33] + a.z*b.z*T.d[35], a.x*b.y*T.d[6] + a.y*b.y*T.d[9] + a.z*b.y*T.d[11] + a.x*b.x*T.d[18] + a.y*b.x*T.d[21] + a.z*b.x*T.d[23] + a.x*b.z*T.d[24] + a.y*b.z*T.d[27] + a.z*b.z*T.d[29], a.x*b.z*T.d[12] + a.y*b.z*T.d[15] + a.z*b.z*T.d[17] + a.x*b.y*T.d[24] + a.y*b.y*T.d[27] + a.z*b.y*T.d[29] + a.x*b.x*T.d[30] + a.y*b.x*T.d[33] + a.z*b.x*T.d[35], a.y*b.x*T.d[1] + a.x*b.x*T.d[3] + a.z*b.x*T.d[4] + a.y*b.y*T.d[19] + a.x*b.y*T.d[21] + a.z*b.y*T.d[22] + a.y*b.z*T.d[31] + a.x*b.z*T.d[33] + a.z*b.z*T.d[34], a.y*b.y*T.d[7] + a.x*b.y*T.d[9] + a.z*b.y*T.d[10] + a.y*b.x*T.d[19] + a.x*b.x*T.d[21] + a.z*b.x*T.d[22] + a.y*b.z*T.d[25] + a.x*b.z*T.d[27] + a.z*b.z*T.d[28], a.y*b.z*T.d[13] + a.x*b.z*T.d[15] + a.z*b.z*T.d[16] + a.y*b.y*T.d[25] + a.x*b.y*T.d[27] + a.z*b.y*T.d[28] + a.y*b.x*T.d[31] + a.x*b.x*T.d[33] + a.z*b.x*T.d[34], a.z*b.x*T.d[2] + a.y*b.x*T.d[4] + a.x*b.x*T.d[5] + a.z*b.y*T.d[20] + a.y*b.y*T.d[22] + a.x*b.y*T.d[23] + a.z*b.z*T.d[32] + a.y*b.z*T.d[34] + a.x*b.z*T.d[35], a.z*b.y*T.d[8] + a.y*b.y*T.d[10] + a.x*b.y*T.d[11] + a.z*b.x*T.d[20] + a.y*b.x*T.d[22] + a.x*b.x*T.d[23] + a.z*b.z*T.d[26] + a.y*b.z*T.d[28] + a.x*b.z*T.d[29], a.z*b.z*T.d[14] + a.y*b.z*T.d[16] + a.x*b.z*T.d[17] + a.z*b.y*T.d[26] + a.y*b.y*T.d[28] + a.x*b.y*T.d[29] + a.z*b.x*T.d[32] + a.y*b.x*T.d[34] + a.x*b.x*T.d[35]); } //----------------------------------------------------------------------------- // double contraction of general 4th-order tensor with a general 2nd-order tensor // Aij = Dijkl Mkl inline mat3ds tens4dmm::dot(const mat3ds &m) const { mat3ds a; a.xx() = d[0]*m.xx() + d[18]*m.xy() + d[30]*m.xz() + d[6]*m.yy() + d[24]*m.yz() + d[12]*m.zz(); a.yy() = d[1]*m.xx() + d[19]*m.xy() + d[31]*m.xz() + d[7]*m.yy() + d[25]*m.yz() + d[13]*m.zz(); a.zz() = d[2]*m.xx() + d[20]*m.xy() + d[32]*m.xz() + d[8]*m.yy() + d[26]*m.yz() + d[14]*m.zz(); a.xy() = d[3]*m.xx() + d[21]*m.xy() + d[33]*m.xz() + d[9]*m.yy() + d[27]*m.yz() + d[15]*m.zz(); a.yz() = d[4]*m.xx() + d[22]*m.xy() + d[34]*m.xz() + d[10]*m.yy() + d[28]*m.yz() + d[16]*m.zz(); a.xz() = d[5]*m.xx() + d[23]*m.xy() + d[35]*m.xz() + d[11]*m.yy() + d[29]*m.yz() + d[17]*m.zz(); return a; } //----------------------------------------------------------------------------- // double contraction of mm 4th-order tensor with a symmetric 4th-order tensor // Aijmn = Bijkl Tklmn inline tens4dmm tens4dmm::ddot(const tens4ds& t) const { tens4dmm b = *this; tens4dmm a; for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { for (int m=0; m<3; ++m) { for (int n=0; n<3; ++n) { a(i,j,m,n) = 0; for (int k=0; k<3; ++k) { for (int l=0; l<3; ++l) { a(i,j,m,n) += b(i,j,k,l)*t(k,l,m,n); } } } } } } return a; } //----------------------------------------------------------------------------- // double contraction of mm 4th-order tensor with a mm 4th-order tensor // Aijmn = Bijkl Tklmn inline tens4dmm tens4dmm::ddot(const tens4dmm& t) const { tens4dmm b = *this; tens4dmm a; for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { for (int m=0; m<3; ++m) { for (int n=0; n<3; ++n) { a(i,j,m,n) = 0; for (int k=0; k<3; ++k) { for (int l=0; l<3; ++l) { a(i,j,m,n) += b(i,j,k,l)*t(k,l,m,n); } } } } } } return a; } //----------------------------------------------------------------------------- // trace // C.tr() = I:C:I inline double tens4dmm::tr() const { return (d[0]+d[1]+d[2]+d[6]+d[7]+d[8]+d[12]+d[13]+d[14]); } //----------------------------------------------------------------------------- // intialize to zero inline void tens4dmm::zero() { d[ 0] = d[ 1] = d[ 2] = d[ 3] = d[ 4] = d[ 5] = d[ 6] = d[ 7] = d[ 8] = d[ 9] = d[10] = d[11] = d[12] = d[13] = d[14] = d[15] = d[16] = d[17] = d[18] = d[19] = d[20] = d[21] = d[22] = d[23] = d[24] = d[25] = d[26] = d[27] = d[28] = d[29] = d[30] = d[31] = d[32] = d[33] = d[34] = d[35] = 0; } //----------------------------------------------------------------------------- // extract 6x6 matrix inline void tens4dmm::extract(double D[6][6]) { D[0][0] = d[0]; D[0][1] = d[ 6]; D[0][2] = d[12]; D[0][3] = d[18]; D[0][4] = d[24]; D[0][5] = d[30]; D[1][0] = d[1]; D[1][1] = d[ 7]; D[1][2] = d[13]; D[1][3] = d[19]; D[1][4] = d[25]; D[1][5] = d[31]; D[2][0] = d[2]; D[2][1] = d[ 8]; D[2][2] = d[14]; D[2][3] = d[20]; D[2][4] = d[26]; D[2][5] = d[32]; D[3][0] = d[3]; D[3][1] = d[ 9]; D[3][2] = d[15]; D[3][3] = d[21]; D[3][4] = d[27]; D[3][5] = d[33]; D[4][0] = d[4]; D[4][1] = d[10]; D[4][2] = d[16]; D[4][3] = d[22]; D[4][4] = d[28]; D[4][5] = d[34]; D[5][0] = d[5]; D[5][1] = d[11]; D[5][2] = d[17]; D[5][3] = d[23]; D[5][4] = d[29]; D[5][5] = d[35]; } //----------------------------------------------------------------------------- // compute the super symmetric (major and minor symmetric) component of the tensor // Sijkl = (1/8)*(Cijkl + Cjikl + Cijlk + Cjilk + Cklij + Clkij + Cklji + Clkji) inline tens4ds tens4dmm::supersymm() const { tens4ds s; s.d[ 0] = d[0]; s.d[ 1] = (d[1]+d[6])/2; s.d[ 2] = d[7]; s.d[ 3] = (d[2]+d[12])/2; s.d[ 4] = (d[8]+d[13])/2; s.d[ 5] = d[14]; s.d[ 6] = (d[3]+d[18])/2; s.d[ 7] = (d[9]+d[19])/2; s.d[ 8] = (d[15]+d[20])/2; s.d[ 9] = d[21]; s.d[10] = (d[4]+d[24])/2; s.d[11] = (d[10]+d[25])/2; s.d[12] = (d[16]+d[26])/2; s.d[13] = (d[22]+d[27])/2; s.d[14] = d[28]; s.d[15] = (d[5]+d[30])/2; s.d[16] = (d[11]+d[31])/2; s.d[17] = (d[17]+d[32])/2; s.d[18] = (d[23]+d[33])/2; s.d[19] = (d[29]+d[34])/2; s.d[20] = d[35]; return s; } //----------------------------------------------------------------------------- // compute the major transpose of the tensor // Sijkl -> Sklij inline tens4dmm tens4dmm::transpose() const { tens4dmm s; s.d[ 0] = d[ 0]; s.d[ 2] = d[12]; s.d[ 4] = d[24]; s.d[ 6] = d[ 1]; s.d[ 8] = d[13]; s.d[10] = d[25]; s.d[12] = d[ 2]; s.d[14] = d[14]; s.d[16] = d[26]; s.d[18] = d[ 3]; s.d[20] = d[15]; s.d[22] = d[27]; s.d[24] = d[ 4]; s.d[26] = d[16]; s.d[28] = d[28]; s.d[30] = d[ 5]; s.d[32] = d[17]; s.d[34] = d[29]; s.d[ 1] = d[ 6]; s.d[ 3] = d[18]; s.d[ 5] = d[30]; s.d[ 7] = d[ 7]; s.d[ 9] = d[19]; s.d[11] = d[31]; s.d[13] = d[ 8]; s.d[15] = d[20]; s.d[17] = d[32]; s.d[19] = d[ 9]; s.d[21] = d[21]; s.d[23] = d[33]; s.d[25] = d[10]; s.d[27] = d[22]; s.d[29] = d[34]; s.d[31] = d[11]; s.d[33] = d[23]; s.d[35] = d[35]; return s; } //----------------------------------------------------------------------------- // (a dyad1 b)_ijkl = a_ij b_kl inline tens4dmm dyad1mm(const mat3ds& a, const mat3ds& b) { tens4dmm c; c.d[ 0] = a.xx()*b.xx(); c.d[12] = a.xx()*b.zz(); c.d[24] = a.xx()*b.yz(); c.d[ 1] = a.yy()*b.xx(); c.d[13] = a.yy()*b.zz(); c.d[25] = a.yy()*b.yz(); c.d[ 2] = a.zz()*b.xx(); c.d[14] = a.zz()*b.zz(); c.d[26] = a.zz()*b.yz(); c.d[ 3] = a.xy()*b.xx(); c.d[15] = a.xy()*b.zz(); c.d[27] = a.xy()*b.yz(); c.d[ 4] = a.yz()*b.xx(); c.d[16] = a.yz()*b.zz(); c.d[28] = a.yz()*b.yz(); c.d[ 5] = a.xz()*b.xx(); c.d[17] = a.xz()*b.zz(); c.d[29] = a.xz()*b.yz(); c.d[ 6] = a.xx()*b.yy(); c.d[18] = a.xx()*b.xy(); c.d[30] = a.xx()*b.xz(); c.d[ 7] = a.yy()*b.yy(); c.d[19] = a.yy()*b.xy(); c.d[31] = a.yy()*b.xz(); c.d[ 8] = a.zz()*b.yy(); c.d[20] = a.zz()*b.xy(); c.d[32] = a.zz()*b.xz(); c.d[ 9] = a.xy()*b.yy(); c.d[21] = a.xy()*b.xy(); c.d[33] = a.xy()*b.xz(); c.d[10] = a.yz()*b.yy(); c.d[22] = a.yz()*b.xy(); c.d[34] = a.yz()*b.xz(); c.d[11] = a.xz()*b.yy(); c.d[23] = a.xz()*b.xy(); c.d[35] = a.xz()*b.xz(); return c; } //----------------------------------------------------------------------------- // (a dyad2 b)_ijkl = a_ik b_jl inline tens4dmm dyad2mm(const mat3ds& a, const mat3ds& b) { tens4dmm c; c.d[ 0] = a.xx()*b.xx(); c.d[12] = a.xz()*b.xz(); c.d[24] = a.xy()*b.xz(); c.d[ 1] = a.xy()*b.xy(); c.d[13] = a.yz()*b.yz(); c.d[25] = a.yy()*b.yz(); c.d[ 2] = a.xz()*b.xz(); c.d[14] = a.zz()*b.zz(); c.d[26] = a.yz()*b.zz(); c.d[ 3] = a.xx()*b.xy(); c.d[15] = a.xz()*b.yz(); c.d[27] = a.xy()*b.yz(); c.d[ 4] = a.xy()*b.xz(); c.d[16] = a.yz()*b.zz(); c.d[28] = a.yy()*b.zz(); c.d[ 5] = a.xx()*b.xz(); c.d[17] = a.xz()*b.zz(); c.d[29] = a.xy()*b.zz(); c.d[ 6] = a.xy()*b.xy(); c.d[18] = a.xx()*b.xy(); c.d[30] = a.xx()*b.xz(); c.d[ 7] = a.yy()*b.yy(); c.d[19] = a.xy()*b.yy(); c.d[31] = a.xy()*b.yz(); c.d[ 8] = a.yz()*b.yz(); c.d[20] = a.xz()*b.yz(); c.d[32] = a.xz()*b.zz(); c.d[ 9] = a.xy()*b.yy(); c.d[21] = a.xx()*b.yy(); c.d[33] = a.xx()*b.yz(); c.d[10] = a.yy()*b.yz(); c.d[22] = a.xy()*b.yz(); c.d[34] = a.xy()*b.zz(); c.d[11] = a.xy()*b.yz(); c.d[23] = a.xx()*b.yz(); c.d[35] = a.xx()*b.zz(); return c; } //----------------------------------------------------------------------------- // (a dyad3 b)_ijkl = a_il b_jk inline tens4dmm dyad3mm(const mat3ds& a, const mat3ds& b) { tens4dmm c; c.d[ 0] = a.xx()*b.xx(); c.d[12] = a.xz()*b.xz(); c.d[24] = a.xz()*b.xy(); c.d[ 1] = a.xy()*b.xy(); c.d[13] = a.yz()*b.yz(); c.d[25] = a.yz()*b.yy(); c.d[ 2] = a.xz()*b.xz(); c.d[14] = a.zz()*b.zz(); c.d[26] = a.zz()*b.yz(); c.d[ 3] = a.xx()*b.xy(); c.d[15] = a.xz()*b.yz(); c.d[27] = a.xz()*b.yy(); c.d[ 4] = a.xy()*b.xz(); c.d[16] = a.yz()*b.zz(); c.d[28] = a.yz()*b.yz(); c.d[ 5] = a.xx()*b.xz(); c.d[17] = a.xz()*b.zz(); c.d[29] = a.xz()*b.yz(); c.d[ 6] = a.xy()*b.xy(); c.d[18] = a.xy()*b.xx(); c.d[30] = a.xz()*b.xx(); c.d[ 7] = a.yy()*b.yy(); c.d[19] = a.yy()*b.xy(); c.d[31] = a.yz()*b.xy(); c.d[ 8] = a.yz()*b.yz(); c.d[20] = a.yz()*b.xz(); c.d[32] = a.zz()*b.xz(); c.d[ 9] = a.xy()*b.yy(); c.d[21] = a.xy()*b.xy(); c.d[33] = a.xz()*b.xy(); c.d[10] = a.yy()*b.yz(); c.d[22] = a.yy()*b.xz(); c.d[34] = a.yz()*b.xz(); c.d[11] = a.xy()*b.yz(); c.d[23] = a.xy()*b.xz(); c.d[35] = a.xz()*b.xz(); return c; } //----------------------------------------------------------------------------- // (a dyad4 b)_ijkl = 0.5(a_ik b_jl + a_il b_jk) inline tens4dmm dyad4mm(const mat3ds& a, const mat3ds& b) { return (dyad2mm(a,b) + dyad3mm(a,b))/2; } //----------------------------------------------------------------------------- // (a dyad4 b)_ijkl = 0.5(a_ik b_jl + a_il b_jk) inline tens4dmm dyad4mm(const mat3d& a, const mat3d& b) { tens4dmm c; c.d[ 0] = 2*a(0,0)*b(0,0); c.d[ 1] = 2*a(1,0)*b(1,0); c.d[ 2] = 2*a(2,0)*b(2,0); c.d[ 3] = a(1,0)*b(0,0) + a(0,0)*b(1,0); c.d[ 4] = a(2,0)*b(1,0) + a(1,0)*b(2,0); c.d[ 5] = a(2,0)*b(0,0) + a(0,0)*b(2,0); c.d[ 6] = 2*a(0,1)*b(0,1); c.d[ 7] = 2*a(1,1)*b(1,1); c.d[ 8] = 2*a(2,1)*b(2,1); c.d[ 9] = a(1,1)*b(0,1) + a(0,1)*b(1,1); c.d[10] = a(2,1)*b(1,1) + a(1,1)*b(2,1); c.d[11] = a(2,1)*b(0,1) + a(0,1)*b(2,1); c.d[12] = 2*a(0,2)*b(0,2); c.d[13] = 2*a(1,2)*b(1,2); c.d[14] = 2*a(2,2)*b(2,2); c.d[15] = a(1,2)*b(0,2) + a(0,2)*b(1,2); c.d[16] = a(2,2)*b(1,2) + a(1,2)*b(2,2); c.d[17] = a(2,2)*b(0,2) + a(0,2)*b(2,2); c.d[18] = a(0,1)*b(0,0) + a(0,0)*b(0,1); c.d[19] = a(1,1)*b(1,0) + a(1,0)*b(1,1); c.d[20] = a(2,1)*b(2,0) + a(2,0)*b(2,1); c.d[21] = (a(1,1)*b(0,0) + a(1,0)*b(0,1) + a(0,1)*b(1,0) + a(0,0)*b(1,1))/2.; c.d[22] = (a(2,1)*b(1,0) + a(2,0)*b(1,1) + a(1,1)*b(2,0) + a(1,0)*b(2,1))/2.; c.d[23] = (a(2,1)*b(0,0) + a(2,0)*b(0,1) + a(0,1)*b(2,0) + a(0,0)*b(2,1))/2.; c.d[24] = a(0,2)*b(0,1) + a(0,1)*b(0,2); c.d[25] = a(1,2)*b(1,1) + a(1,1)*b(1,2); c.d[26] = a(2,2)*b(2,1) + a(2,1)*b(2,2); c.d[27] = (a(1,2)*b(0,1) + a(1,1)*b(0,2) + a(0,2)*b(1,1) + a(0,1)*b(1,2))/2.; c.d[28] = (a(2,2)*b(1,1) + a(2,1)*b(1,2) + a(1,2)*b(2,1) + a(1,1)*b(2,2))/2.; c.d[29] = (a(2,2)*b(0,1) + a(2,1)*b(0,2) + a(0,2)*b(2,1) + a(0,1)*b(2,2))/2.; c.d[30] = a(0,2)*b(0,0) + a(0,0)*b(0,2); c.d[31] = a(1,2)*b(1,0) + a(1,0)*b(1,2); c.d[32] = a(2,2)*b(2,0) + a(2,0)*b(2,2); c.d[33] = (a(1,2)*b(0,0) + a(1,0)*b(0,2) + a(0,2)*b(1,0) + a(0,0)*b(1,2))/2.; c.d[34] = (a(2,2)*b(1,0) + a(2,0)*b(1,2) + a(1,2)*b(2,0) + a(1,0)*b(2,2))/2.; c.d[35] = (a(2,2)*b(0,0) + a(2,0)*b(0,2) + a(0,2)*b(2,0) + a(0,0)*b(2,2))/2.; return c/2; } //----------------------------------------------------------------------------- // (a ddot b)_ijkl = a_ijmn b_mnkl inline tens4dmm ddot(const tens4dmm& a, const tens4dmm& b) { tens4dmm c; c.d[ 0] = a.d[0]*b.d[0] + a.d[6]*b.d[1] + a.d[12]*b.d[2] + a.d[18]*b.d[3] + a.d[24]*b.d[4] + a.d[30]*b.d[5]; c.d[ 1] = a.d[1]*b.d[0] + a.d[7]*b.d[1] + a.d[13]*b.d[2] + a.d[19]*b.d[3] + a.d[25]*b.d[4] + a.d[31]*b.d[5]; c.d[ 2] = a.d[2]*b.d[0] + a.d[8]*b.d[1] + a.d[14]*b.d[2] + a.d[20]*b.d[3] + a.d[26]*b.d[4] + a.d[32]*b.d[5]; c.d[ 3] = a.d[3]*b.d[0] + a.d[9]*b.d[1] + a.d[15]*b.d[2] + a.d[21]*b.d[3] + a.d[27]*b.d[4] + a.d[33]*b.d[5]; c.d[ 4] = a.d[4]*b.d[0] + a.d[10]*b.d[1] + a.d[16]*b.d[2] + a.d[22]*b.d[3] + a.d[28]*b.d[4] + a.d[34]*b.d[5]; c.d[ 5] = a.d[5]*b.d[0] + a.d[11]*b.d[1] + a.d[17]*b.d[2] + a.d[23]*b.d[3] + a.d[29]*b.d[4] + a.d[35]*b.d[5]; c.d[ 6] = a.d[24]*b.d[10] + a.d[30]*b.d[11] + a.d[0]*b.d[6] + a.d[6]*b.d[7] + a.d[12]*b.d[8] + a.d[18]*b.d[9]; c.d[ 7] = a.d[25]*b.d[10] + a.d[31]*b.d[11] + a.d[1]*b.d[6] + a.d[7]*b.d[7] + a.d[13]*b.d[8] + a.d[19]*b.d[9]; c.d[ 8] = a.d[26]*b.d[10] + a.d[32]*b.d[11] + a.d[2]*b.d[6] + a.d[8]*b.d[7] + a.d[14]*b.d[8] + a.d[20]*b.d[9]; c.d[ 9] = a.d[27]*b.d[10] + a.d[33]*b.d[11] + a.d[3]*b.d[6] + a.d[9]*b.d[7] + a.d[15]*b.d[8] + a.d[21]*b.d[9]; c.d[10] = a.d[28]*b.d[10] + a.d[34]*b.d[11] + a.d[4]*b.d[6] + a.d[10]*b.d[7] + a.d[16]*b.d[8] + a.d[22]*b.d[9]; c.d[11] = a.d[29]*b.d[10] + a.d[35]*b.d[11] + a.d[5]*b.d[6] + a.d[11]*b.d[7] + a.d[17]*b.d[8] + a.d[23]*b.d[9]; c.d[12] = a.d[0]*b.d[12] + a.d[6]*b.d[13] + a.d[12]*b.d[14] + a.d[18]*b.d[15] + a.d[24]*b.d[16] + a.d[30]*b.d[17]; c.d[13] = a.d[1]*b.d[12] + a.d[7]*b.d[13] + a.d[13]*b.d[14] + a.d[19]*b.d[15] + a.d[25]*b.d[16] + a.d[31]*b.d[17]; c.d[14] = a.d[2]*b.d[12] + a.d[8]*b.d[13] + a.d[14]*b.d[14] + a.d[20]*b.d[15] + a.d[26]*b.d[16] + a.d[32]*b.d[17]; c.d[15] = a.d[3]*b.d[12] + a.d[9]*b.d[13] + a.d[15]*b.d[14] + a.d[21]*b.d[15] + a.d[27]*b.d[16] + a.d[33]*b.d[17]; c.d[16] = a.d[4]*b.d[12] + a.d[10]*b.d[13] + a.d[16]*b.d[14] + a.d[22]*b.d[15] + a.d[28]*b.d[16] + a.d[34]*b.d[17]; c.d[17] = a.d[5]*b.d[12] + a.d[11]*b.d[13] + a.d[17]*b.d[14] + a.d[23]*b.d[15] + a.d[29]*b.d[16] + a.d[35]*b.d[17]; c.d[18] = a.d[0]*b.d[18] + a.d[6]*b.d[19] + a.d[12]*b.d[20] + a.d[18]*b.d[21] + a.d[24]*b.d[22] + a.d[30]*b.d[23]; c.d[19] = a.d[1]*b.d[18] + a.d[7]*b.d[19] + a.d[13]*b.d[20] + a.d[19]*b.d[21] + a.d[25]*b.d[22] + a.d[31]*b.d[23]; c.d[20] = a.d[2]*b.d[18] + a.d[8]*b.d[19] + a.d[14]*b.d[20] + a.d[20]*b.d[21] + a.d[26]*b.d[22] + a.d[32]*b.d[23]; c.d[21] = a.d[3]*b.d[18] + a.d[9]*b.d[19] + a.d[15]*b.d[20] + a.d[21]*b.d[21] + a.d[27]*b.d[22] + a.d[33]*b.d[23]; c.d[22] = a.d[4]*b.d[18] + a.d[10]*b.d[19] + a.d[16]*b.d[20] + a.d[22]*b.d[21] + a.d[28]*b.d[22] + a.d[34]*b.d[23]; c.d[23] = a.d[5]*b.d[18] + a.d[11]*b.d[19] + a.d[17]*b.d[20] + a.d[23]*b.d[21] + a.d[29]*b.d[22] + a.d[35]*b.d[23]; c.d[24] = a.d[0]*b.d[24] + a.d[6]*b.d[25] + a.d[12]*b.d[26] + a.d[18]*b.d[27] + a.d[24]*b.d[28] + a.d[30]*b.d[29]; c.d[25] = a.d[1]*b.d[24] + a.d[7]*b.d[25] + a.d[13]*b.d[26] + a.d[19]*b.d[27] + a.d[25]*b.d[28] + a.d[31]*b.d[29]; c.d[26] = a.d[2]*b.d[24] + a.d[8]*b.d[25] + a.d[14]*b.d[26] + a.d[20]*b.d[27] + a.d[26]*b.d[28] + a.d[32]*b.d[29]; c.d[27] = a.d[3]*b.d[24] + a.d[9]*b.d[25] + a.d[15]*b.d[26] + a.d[21]*b.d[27] + a.d[27]*b.d[28] + a.d[33]*b.d[29]; c.d[28] = a.d[4]*b.d[24] + a.d[10]*b.d[25] + a.d[16]*b.d[26] + a.d[22]*b.d[27] + a.d[28]*b.d[28] + a.d[34]*b.d[29]; c.d[29] = a.d[5]*b.d[24] + a.d[11]*b.d[25] + a.d[17]*b.d[26] + a.d[23]*b.d[27] + a.d[29]*b.d[28] + a.d[35]*b.d[29]; c.d[30] = a.d[0]*b.d[30] + a.d[6]*b.d[31] + a.d[12]*b.d[32] + a.d[18]*b.d[33] + a.d[24]*b.d[34] + a.d[30]*b.d[35]; c.d[31] = a.d[1]*b.d[30] + a.d[7]*b.d[31] + a.d[13]*b.d[32] + a.d[19]*b.d[33] + a.d[25]*b.d[34] + a.d[31]*b.d[35]; c.d[32] = a.d[2]*b.d[30] + a.d[8]*b.d[31] + a.d[14]*b.d[32] + a.d[20]*b.d[33] + a.d[26]*b.d[34] + a.d[32]*b.d[35]; c.d[33] = a.d[3]*b.d[30] + a.d[9]*b.d[31] + a.d[15]*b.d[32] + a.d[21]*b.d[33] + a.d[27]*b.d[34] + a.d[33]*b.d[35]; c.d[34] = a.d[4]*b.d[30] + a.d[10]*b.d[31] + a.d[16]*b.d[32] + a.d[22]*b.d[33] + a.d[28]*b.d[34] + a.d[34]*b.d[35]; c.d[35] = a.d[5]*b.d[30] + a.d[11]*b.d[31] + a.d[17]*b.d[32] + a.d[23]*b.d[33] + a.d[29]*b.d[34] + a.d[35]*b.d[35]; return c; } //----------------------------------------------------------------------------- // (a ddot b)_ijkl = a_ijmn b_mnkl where b is super-symmetric inline tens4dmm ddot(const tens4dmm& a, const tens4ds& b) { tens4dmm c; c.d[ 0] = a.d[0]*b.d[0] + a.d[6]*b.d[1] + a.d[12]*b.d[3] + a.d[18]*b.d[6] + a.d[24]*b.d[10] + a.d[30]*b.d[15]; c.d[ 1] = a.d[1]*b.d[0] + a.d[7]*b.d[1] + a.d[13]*b.d[3] + a.d[19]*b.d[6] + a.d[25]*b.d[10] + a.d[31]*b.d[15]; c.d[ 2] = a.d[2]*b.d[0] + a.d[8]*b.d[1] + a.d[14]*b.d[3] + a.d[20]*b.d[6] + a.d[26]*b.d[10] + a.d[32]*b.d[15]; c.d[ 3] = a.d[3]*b.d[0] + a.d[9]*b.d[1] + a.d[15]*b.d[3] + a.d[21]*b.d[6] + a.d[27]*b.d[10] + a.d[33]*b.d[15]; c.d[ 4] = a.d[4]*b.d[0] + a.d[10]*b.d[1] + a.d[16]*b.d[3] + a.d[22]*b.d[6] + a.d[28]*b.d[10] + a.d[34]*b.d[15]; c.d[ 5] = a.d[5]*b.d[0] + a.d[11]*b.d[1] + a.d[17]*b.d[3] + a.d[23]*b.d[6] + a.d[29]*b.d[10] + a.d[35]*b.d[15]; c.d[ 6] = a.d[0]*b.d[1] + a.d[6]*b.d[2] + a.d[12]*b.d[4] + a.d[18]*b.d[7] + a.d[24]*b.d[11] + a.d[30]*b.d[16]; c.d[ 7] = a.d[1]*b.d[1] + a.d[7]*b.d[2] + a.d[13]*b.d[4] + a.d[19]*b.d[7] + a.d[25]*b.d[11] + a.d[31]*b.d[16]; c.d[ 8] = a.d[2]*b.d[1] + a.d[8]*b.d[2] + a.d[14]*b.d[4] + a.d[20]*b.d[7] + a.d[26]*b.d[11] + a.d[32]*b.d[16]; c.d[ 9] = a.d[3]*b.d[1] + a.d[9]*b.d[2] + a.d[15]*b.d[4] + a.d[21]*b.d[7] + a.d[27]*b.d[11] + a.d[33]*b.d[16]; c.d[10] = a.d[4]*b.d[1] + a.d[10]*b.d[2] + a.d[16]*b.d[4] + a.d[22]*b.d[7] + a.d[28]*b.d[11] + a.d[34]*b.d[16]; c.d[11] = a.d[5]*b.d[1] + a.d[11]*b.d[2] + a.d[17]*b.d[4] + a.d[23]*b.d[7] + a.d[29]*b.d[11] + a.d[35]*b.d[16]; c.d[12] = a.d[0]*b.d[3] + a.d[6]*b.d[4] + a.d[12]*b.d[5] + a.d[18]*b.d[8] + a.d[24]*b.d[12] + a.d[30]*b.d[17]; c.d[13] = a.d[1]*b.d[3] + a.d[7]*b.d[4] + a.d[13]*b.d[5] + a.d[19]*b.d[8] + a.d[25]*b.d[12] + a.d[31]*b.d[17]; c.d[14] = a.d[2]*b.d[3] + a.d[8]*b.d[4] + a.d[14]*b.d[5] + a.d[20]*b.d[8] + a.d[26]*b.d[12] + a.d[32]*b.d[17]; c.d[15] = a.d[3]*b.d[3] + a.d[9]*b.d[4] + a.d[15]*b.d[5] + a.d[21]*b.d[8] + a.d[27]*b.d[12] + a.d[33]*b.d[17]; c.d[16] = a.d[4]*b.d[3] + a.d[10]*b.d[4] + a.d[16]*b.d[5] + a.d[22]*b.d[8] + a.d[28]*b.d[12] + a.d[34]*b.d[17]; c.d[17] = a.d[5]*b.d[3] + a.d[11]*b.d[4] + a.d[17]*b.d[5] + a.d[23]*b.d[8] + a.d[29]*b.d[12] + a.d[35]*b.d[17]; c.d[18] = a.d[0]*b.d[6] + a.d[6]*b.d[7] + a.d[12]*b.d[8] + a.d[18]*b.d[9] + a.d[24]*b.d[13] + a.d[30]*b.d[18]; c.d[19] = a.d[1]*b.d[6] + a.d[7]*b.d[7] + a.d[13]*b.d[8] + a.d[19]*b.d[9] + a.d[25]*b.d[13] + a.d[31]*b.d[18]; c.d[20] = a.d[2]*b.d[6] + a.d[8]*b.d[7] + a.d[14]*b.d[8] + a.d[20]*b.d[9] + a.d[26]*b.d[13] + a.d[32]*b.d[18]; c.d[21] = a.d[3]*b.d[6] + a.d[9]*b.d[7] + a.d[15]*b.d[8] + a.d[21]*b.d[9] + a.d[27]*b.d[13] + a.d[33]*b.d[18]; c.d[22] = a.d[4]*b.d[6] + a.d[10]*b.d[7] + a.d[16]*b.d[8] + a.d[22]*b.d[9] + a.d[28]*b.d[13] + a.d[34]*b.d[18]; c.d[23] = a.d[5]*b.d[6] + a.d[11]*b.d[7] + a.d[17]*b.d[8] + a.d[23]*b.d[9] + a.d[29]*b.d[13] + a.d[35]*b.d[18]; c.d[24] = a.d[0]*b.d[10] + a.d[6]*b.d[11] + a.d[12]*b.d[12] + a.d[18]*b.d[13] + a.d[24]*b.d[14] + a.d[30]*b.d[19]; c.d[25] = a.d[1]*b.d[10] + a.d[7]*b.d[11] + a.d[13]*b.d[12] + a.d[19]*b.d[13] + a.d[25]*b.d[14] + a.d[31]*b.d[19]; c.d[26] = a.d[2]*b.d[10] + a.d[8]*b.d[11] + a.d[14]*b.d[12] + a.d[20]*b.d[13] + a.d[26]*b.d[14] + a.d[32]*b.d[19]; c.d[27] = a.d[3]*b.d[10] + a.d[9]*b.d[11] + a.d[15]*b.d[12] + a.d[21]*b.d[13] + a.d[27]*b.d[14] + a.d[33]*b.d[19]; c.d[28] = a.d[4]*b.d[10] + a.d[10]*b.d[11] + a.d[16]*b.d[12] + a.d[22]*b.d[13] + a.d[28]*b.d[14] + a.d[34]*b.d[19]; c.d[29] = a.d[5]*b.d[10] + a.d[11]*b.d[11] + a.d[17]*b.d[12] + a.d[23]*b.d[13] + a.d[29]*b.d[14] + a.d[35]*b.d[19]; c.d[30] = a.d[0]*b.d[15] + a.d[6]*b.d[16] + a.d[12]*b.d[17] + a.d[18]*b.d[18] + a.d[24]*b.d[19] + a.d[30]*b.d[20]; c.d[31] = a.d[1]*b.d[15] + a.d[7]*b.d[16] + a.d[13]*b.d[17] + a.d[19]*b.d[18] + a.d[25]*b.d[19] + a.d[31]*b.d[20]; c.d[32] = a.d[2]*b.d[15] + a.d[8]*b.d[16] + a.d[14]*b.d[17] + a.d[20]*b.d[18] + a.d[26]*b.d[19] + a.d[32]*b.d[20]; c.d[33] = a.d[3]*b.d[15] + a.d[9]*b.d[16] + a.d[15]*b.d[17] + a.d[21]*b.d[18] + a.d[27]*b.d[19] + a.d[33]*b.d[20]; c.d[34] = a.d[4]*b.d[15] + a.d[10]*b.d[16] + a.d[16]*b.d[17] + a.d[22]*b.d[18] + a.d[28]*b.d[19] + a.d[34]*b.d[20]; c.d[35] = a.d[5]*b.d[15] + a.d[11]*b.d[16] + a.d[17]*b.d[17] + a.d[23]*b.d[18] + a.d[29]*b.d[19] + a.d[35]*b.d[20]; return c; } //----------------------------------------------------------------------------- // inverse inline tens4dmm tens4dmm::inverse() const { matrix c(6,6); // populate c c(0,0) = d[ 0]; c(0,1) = d[ 6]; c(0,2) = d[12]; c(0,3) = d[18]; c(0,4) = d[24]; c(0,5) = d[30]; c(1,0) = d[ 1]; c(1,1) = d[ 7]; c(1,2) = d[13]; c(1,3) = d[19]; c(1,4) = d[25]; c(1,5) = d[31]; c(2,0) = d[ 2]; c(2,1) = d[ 8]; c(2,2) = d[14]; c(2,3) = d[20]; c(2,4) = d[26]; c(2,5) = d[32]; c(3,0) = d[ 3]; c(3,1) = d[ 9]; c(3,2) = d[15]; c(3,3) = d[21]; c(3,4) = d[27]; c(3,5) = d[33]; c(4,0) = d[ 4]; c(4,1) = d[10]; c(4,2) = d[16]; c(4,3) = d[22]; c(4,4) = d[28]; c(4,5) = d[34]; c(5,0) = d[ 5]; c(5,1) = d[11]; c(5,2) = d[17]; c(5,3) = d[23]; c(5,4) = d[29]; c(5,5) = d[35]; // invert c matrix s = c.inverse(); // return inverse tens4dmm S; S.d[ 0] = s(0,0); S.d[ 6] = s(0,1); S.d[12] = s(0,2); S.d[18] = s(0,3); S.d[24] = s(0,4); S.d[30] = s(0,5); S.d[ 1] = s(1,0); S.d[ 7] = s(1,1); S.d[13] = s(1,2); S.d[19] = s(1,3); S.d[25] = s(1,4); S.d[31] = s(1,5); S.d[ 2] = s(2,0); S.d[ 8] = s(2,1); S.d[14] = s(2,2); S.d[20] = s(2,3); S.d[26] = s(2,4); S.d[32] = s(2,5); S.d[ 3] = s(3,0); S.d[ 9] = s(3,1); S.d[15] = s(3,2); S.d[21] = s(3,3); S.d[27] = s(3,4); S.d[33] = s(3,5); S.d[ 4] = s(4,0); S.d[10] = s(4,1); S.d[16] = s(4,2); S.d[22] = s(4,3); S.d[28] = s(4,4); S.d[34] = s(4,5); S.d[ 5] = s(5,0); S.d[11] = s(5,1); S.d[17] = s(5,2); S.d[23] = s(5,3); S.d[29] = s(5,4); S.d[35] = s(5,5); return S; } //----------------------------------------------------------------------------- // evaluate push/pull operation // c_ijpq = F_ik F_jl C_klmn F_pm F_qn inline tens4dmm tens4dmm::pp(const mat3d& F) { tens4dmm c; c.d[0] = d[0]*pow(F(0,0),4) + 2*d[3]*pow(F(0,0),3)*F(0,1) + 2*d[18]*pow(F(0,0),3)*F(0,1) + d[1]*pow(F(0,0),2)*pow(F(0,1),2) + d[6]*pow(F(0,0),2)*pow(F(0,1),2) + 4*d[21]*pow(F(0,0),2)*pow(F(0,1),2) + 2*d[9]*F(0,0)*pow(F(0,1),3) + 2*d[19]*F(0,0)*pow(F(0,1),3) + d[7]*pow(F(0,1),4) + 2*d[5]*pow(F(0,0),3)*F(0,2) + 2*d[30]*pow(F(0,0),3)*F(0,2) + 2*d[4]*pow(F(0,0),2)*F(0,1)*F(0,2) + 4*d[23]*pow(F(0,0),2)*F(0,1)*F(0,2) + 2*d[24]*pow(F(0,0),2)*F(0,1)*F(0,2) + 4*d[33]*pow(F(0,0),2)*F(0,1)*F(0,2) + 2*d[11]*F(0,0)*pow(F(0,1),2)*F(0,2) + 4*d[22]*F(0,0)*pow(F(0,1),2)*F(0,2) + 4*d[27]*F(0,0)*pow(F(0,1),2)*F(0,2) + 2*d[31]*F(0,0)*pow(F(0,1),2)*F(0,2) + 2*d[10]*pow(F(0,1),3)*F(0,2) + 2*d[25]*pow(F(0,1),3)*F(0,2) + d[2]*pow(F(0,0),2)*pow(F(0,2),2) + d[12]*pow(F(0,0),2)*pow(F(0,2),2) + 4*d[35]*pow(F(0,0),2)*pow(F(0,2),2) + 2*d[15]*F(0,0)*F(0,1)*pow(F(0,2),2) + 2*d[20]*F(0,0)*F(0,1)*pow(F(0,2),2) + 4*d[29]*F(0,0)*F(0,1)*pow(F(0,2),2) + 4*d[34]*F(0,0)*F(0,1)*pow(F(0,2),2) + d[8]*pow(F(0,1),2)*pow(F(0,2),2) + d[13]*pow(F(0,1),2)*pow(F(0,2),2) + 4*d[28]*pow(F(0,1),2)*pow(F(0,2),2) + 2*d[17]*F(0,0)*pow(F(0,2),3) + 2*d[32]*F(0,0)*pow(F(0,2),3) + 2*d[16]*F(0,1)*pow(F(0,2),3) + 2*d[26]*F(0,1)*pow(F(0,2),3) + d[14]*pow(F(0,2),4); c.d[1] = d[0]*pow(F(0,0),2)*pow(F(1,0),2) + 2*d[18]*F(0,0)*F(0,1)*pow(F(1,0),2) + d[6]*pow(F(0,1),2)*pow(F(1,0),2) + 2*d[30]*F(0,0)*F(0,2)*pow(F(1,0),2) + 2*d[24]*F(0,1)*F(0,2)*pow(F(1,0),2) + d[12]*pow(F(0,2),2)*pow(F(1,0),2) + 2*d[3]*pow(F(0,0),2)*F(1,0)*F(1,1) + 4*d[21]*F(0,0)*F(0,1)*F(1,0)*F(1,1) + 2*d[9]*pow(F(0,1),2)*F(1,0)*F(1,1) + 4*d[33]*F(0,0)*F(0,2)*F(1,0)*F(1,1) + 4*d[27]*F(0,1)*F(0,2)*F(1,0)*F(1,1) + 2*d[15]*pow(F(0,2),2)*F(1,0)*F(1,1) + d[1]*pow(F(0,0),2)*pow(F(1,1),2) + 2*d[19]*F(0,0)*F(0,1)*pow(F(1,1),2) + d[7]*pow(F(0,1),2)*pow(F(1,1),2) + 2*d[31]*F(0,0)*F(0,2)*pow(F(1,1),2) + 2*d[25]*F(0,1)*F(0,2)*pow(F(1,1),2) + d[13]*pow(F(0,2),2)*pow(F(1,1),2) + 2*d[5]*pow(F(0,0),2)*F(1,0)*F(1,2) + 4*d[23]*F(0,0)*F(0,1)*F(1,0)*F(1,2) + 2*d[11]*pow(F(0,1),2)*F(1,0)*F(1,2) + 4*d[35]*F(0,0)*F(0,2)*F(1,0)*F(1,2) + 4*d[29]*F(0,1)*F(0,2)*F(1,0)*F(1,2) + 2*d[17]*pow(F(0,2),2)*F(1,0)*F(1,2) + 2*d[4]*pow(F(0,0),2)*F(1,1)*F(1,2) + 4*d[22]*F(0,0)*F(0,1)*F(1,1)*F(1,2) + 2*d[10]*pow(F(0,1),2)*F(1,1)*F(1,2) + 4*d[34]*F(0,0)*F(0,2)*F(1,1)*F(1,2) + 4*d[28]*F(0,1)*F(0,2)*F(1,1)*F(1,2) + 2*d[16]*pow(F(0,2),2)*F(1,1)*F(1,2) + d[2]*pow(F(0,0),2)*pow(F(1,2),2) + 2*d[20]*F(0,0)*F(0,1)*pow(F(1,2),2) + d[8]*pow(F(0,1),2)*pow(F(1,2),2) + 2*d[32]*F(0,0)*F(0,2)*pow(F(1,2),2) + 2*d[26]*F(0,1)*F(0,2)*pow(F(1,2),2) + d[14]*pow(F(0,2),2)*pow(F(1,2),2); c.d[2] = d[0]*pow(F(0,0),2)*pow(F(2,0),2) + 2*d[18]*F(0,0)*F(0,1)*pow(F(2,0),2) + d[6]*pow(F(0,1),2)*pow(F(2,0),2) + 2*d[30]*F(0,0)*F(0,2)*pow(F(2,0),2) + 2*d[24]*F(0,1)*F(0,2)*pow(F(2,0),2) + d[12]*pow(F(0,2),2)*pow(F(2,0),2) + 2*d[3]*pow(F(0,0),2)*F(2,0)*F(2,1) + 4*d[21]*F(0,0)*F(0,1)*F(2,0)*F(2,1) + 2*d[9]*pow(F(0,1),2)*F(2,0)*F(2,1) + 4*d[33]*F(0,0)*F(0,2)*F(2,0)*F(2,1) + 4*d[27]*F(0,1)*F(0,2)*F(2,0)*F(2,1) + 2*d[15]*pow(F(0,2),2)*F(2,0)*F(2,1) + d[1]*pow(F(0,0),2)*pow(F(2,1),2) + 2*d[19]*F(0,0)*F(0,1)*pow(F(2,1),2) + d[7]*pow(F(0,1),2)*pow(F(2,1),2) + 2*d[31]*F(0,0)*F(0,2)*pow(F(2,1),2) + 2*d[25]*F(0,1)*F(0,2)*pow(F(2,1),2) + d[13]*pow(F(0,2),2)*pow(F(2,1),2) + 2*d[5]*pow(F(0,0),2)*F(2,0)*F(2,2) + 4*d[23]*F(0,0)*F(0,1)*F(2,0)*F(2,2) + 2*d[11]*pow(F(0,1),2)*F(2,0)*F(2,2) + 4*d[35]*F(0,0)*F(0,2)*F(2,0)*F(2,2) + 4*d[29]*F(0,1)*F(0,2)*F(2,0)*F(2,2) + 2*d[17]*pow(F(0,2),2)*F(2,0)*F(2,2) + 2*d[4]*pow(F(0,0),2)*F(2,1)*F(2,2) + 4*d[22]*F(0,0)*F(0,1)*F(2,1)*F(2,2) + 2*d[10]*pow(F(0,1),2)*F(2,1)*F(2,2) + 4*d[34]*F(0,0)*F(0,2)*F(2,1)*F(2,2) + 4*d[28]*F(0,1)*F(0,2)*F(2,1)*F(2,2) + 2*d[16]*pow(F(0,2),2)*F(2,1)*F(2,2) + d[2]*pow(F(0,0),2)*pow(F(2,2),2) + 2*d[20]*F(0,0)*F(0,1)*pow(F(2,2),2) + d[8]*pow(F(0,1),2)*pow(F(2,2),2) + 2*d[32]*F(0,0)*F(0,2)*pow(F(2,2),2) + 2*d[26]*F(0,1)*F(0,2)*pow(F(2,2),2) + d[14]*pow(F(0,2),2)*pow(F(2,2),2); c.d[3] = d[0]*pow(F(0,0),3)*F(1,0) + 2*d[18]*pow(F(0,0),2)*F(0,1)*F(1,0) + d[6]*F(0,0)*pow(F(0,1),2)*F(1,0) + 2*d[21]*F(0,0)*pow(F(0,1),2)*F(1,0) + d[9]*pow(F(0,1),3)*F(1,0) + d[5]*pow(F(0,0),2)*F(0,2)*F(1,0) + 2*d[30]*pow(F(0,0),2)*F(0,2)*F(1,0) + 2*d[23]*F(0,0)*F(0,1)*F(0,2)*F(1,0) + 2*d[24]*F(0,0)*F(0,1)*F(0,2)*F(1,0) + 2*d[33]*F(0,0)*F(0,1)*F(0,2)*F(1,0) + d[11]*pow(F(0,1),2)*F(0,2)*F(1,0) + 2*d[27]*pow(F(0,1),2)*F(0,2)*F(1,0) + d[12]*F(0,0)*pow(F(0,2),2)*F(1,0) + 2*d[35]*F(0,0)*pow(F(0,2),2)*F(1,0) + d[15]*F(0,1)*pow(F(0,2),2)*F(1,0) + 2*d[29]*F(0,1)*pow(F(0,2),2)*F(1,0) + d[17]*pow(F(0,2),3)*F(1,0) + d[1]*pow(F(0,0),2)*F(0,1)*F(1,1) + 2*d[21]*pow(F(0,0),2)*F(0,1)*F(1,1) + d[9]*F(0,0)*pow(F(0,1),2)*F(1,1) + 2*d[19]*F(0,0)*pow(F(0,1),2)*F(1,1) + d[7]*pow(F(0,1),3)*F(1,1) + d[4]*pow(F(0,0),2)*F(0,2)*F(1,1) + 2*d[33]*pow(F(0,0),2)*F(0,2)*F(1,1) + 2*d[22]*F(0,0)*F(0,1)*F(0,2)*F(1,1) + 2*d[27]*F(0,0)*F(0,1)*F(0,2)*F(1,1) + 2*d[31]*F(0,0)*F(0,1)*F(0,2)*F(1,1) + d[10]*pow(F(0,1),2)*F(0,2)*F(1,1) + 2*d[25]*pow(F(0,1),2)*F(0,2)*F(1,1) + d[15]*F(0,0)*pow(F(0,2),2)*F(1,1) + 2*d[34]*F(0,0)*pow(F(0,2),2)*F(1,1) + d[13]*F(0,1)*pow(F(0,2),2)*F(1,1) + 2*d[28]*F(0,1)*pow(F(0,2),2)*F(1,1) + d[16]*pow(F(0,2),3)*F(1,1) + d[3]*pow(F(0,0),2)*(F(0,1)*F(1,0) + F(0,0)*F(1,1)) + d[5]*pow(F(0,0),3)*F(1,2) + d[4]*pow(F(0,0),2)*F(0,1)*F(1,2) + 2*d[23]*pow(F(0,0),2)*F(0,1)*F(1,2) + d[11]*F(0,0)*pow(F(0,1),2)*F(1,2) + 2*d[22]*F(0,0)*pow(F(0,1),2)*F(1,2) + d[10]*pow(F(0,1),3)*F(1,2) + d[2]*pow(F(0,0),2)*F(0,2)*F(1,2) + 2*d[35]*pow(F(0,0),2)*F(0,2)*F(1,2) + 2*d[20]*F(0,0)*F(0,1)*F(0,2)*F(1,2) + 2*d[29]*F(0,0)*F(0,1)*F(0,2)*F(1,2) + 2*d[34]*F(0,0)*F(0,1)*F(0,2)*F(1,2) + d[8]*pow(F(0,1),2)*F(0,2)*F(1,2) + 2*d[28]*pow(F(0,1),2)*F(0,2)*F(1,2) + d[17]*F(0,0)*pow(F(0,2),2)*F(1,2) + 2*d[32]*F(0,0)*pow(F(0,2),2)*F(1,2) + d[16]*F(0,1)*pow(F(0,2),2)*F(1,2) + 2*d[26]*F(0,1)*pow(F(0,2),2)*F(1,2) + d[14]*pow(F(0,2),3)*F(1,2); c.d[4] = d[0]*pow(F(0,0),2)*F(1,0)*F(2,0) + 2*d[18]*F(0,0)*F(0,1)*F(1,0)*F(2,0) + d[6]*pow(F(0,1),2)*F(1,0)*F(2,0) + 2*d[30]*F(0,0)*F(0,2)*F(1,0)*F(2,0) + 2*d[24]*F(0,1)*F(0,2)*F(1,0)*F(2,0) + d[12]*pow(F(0,2),2)*F(1,0)*F(2,0) + d[3]*pow(F(0,0),2)*F(1,1)*F(2,0) + 2*d[21]*F(0,0)*F(0,1)*F(1,1)*F(2,0) + d[9]*pow(F(0,1),2)*F(1,1)*F(2,0) + 2*d[33]*F(0,0)*F(0,2)*F(1,1)*F(2,0) + 2*d[27]*F(0,1)*F(0,2)*F(1,1)*F(2,0) + d[15]*pow(F(0,2),2)*F(1,1)*F(2,0) + d[5]*pow(F(0,0),2)*F(1,2)*F(2,0) + 2*d[23]*F(0,0)*F(0,1)*F(1,2)*F(2,0) + d[11]*pow(F(0,1),2)*F(1,2)*F(2,0) + 2*d[35]*F(0,0)*F(0,2)*F(1,2)*F(2,0) + 2*d[29]*F(0,1)*F(0,2)*F(1,2)*F(2,0) + d[17]*pow(F(0,2),2)*F(1,2)*F(2,0) + d[3]*pow(F(0,0),2)*F(1,0)*F(2,1) + 2*d[21]*F(0,0)*F(0,1)*F(1,0)*F(2,1) + d[9]*pow(F(0,1),2)*F(1,0)*F(2,1) + 2*d[33]*F(0,0)*F(0,2)*F(1,0)*F(2,1) + 2*d[27]*F(0,1)*F(0,2)*F(1,0)*F(2,1) + d[15]*pow(F(0,2),2)*F(1,0)*F(2,1) + d[1]*pow(F(0,0),2)*F(1,1)*F(2,1) + 2*d[19]*F(0,0)*F(0,1)*F(1,1)*F(2,1) + d[7]*pow(F(0,1),2)*F(1,1)*F(2,1) + 2*d[31]*F(0,0)*F(0,2)*F(1,1)*F(2,1) + 2*d[25]*F(0,1)*F(0,2)*F(1,1)*F(2,1) + d[13]*pow(F(0,2),2)*F(1,1)*F(2,1) + d[4]*pow(F(0,0),2)*F(1,2)*F(2,1) + 2*d[22]*F(0,0)*F(0,1)*F(1,2)*F(2,1) + d[10]*pow(F(0,1),2)*F(1,2)*F(2,1) + 2*d[34]*F(0,0)*F(0,2)*F(1,2)*F(2,1) + 2*d[28]*F(0,1)*F(0,2)*F(1,2)*F(2,1) + d[16]*pow(F(0,2),2)*F(1,2)*F(2,1) + d[5]*pow(F(0,0),2)*F(1,0)*F(2,2) + 2*d[23]*F(0,0)*F(0,1)*F(1,0)*F(2,2) + d[11]*pow(F(0,1),2)*F(1,0)*F(2,2) + 2*d[35]*F(0,0)*F(0,2)*F(1,0)*F(2,2) + 2*d[29]*F(0,1)*F(0,2)*F(1,0)*F(2,2) + d[17]*pow(F(0,2),2)*F(1,0)*F(2,2) + d[4]*pow(F(0,0),2)*F(1,1)*F(2,2) + 2*d[22]*F(0,0)*F(0,1)*F(1,1)*F(2,2) + d[10]*pow(F(0,1),2)*F(1,1)*F(2,2) + 2*d[34]*F(0,0)*F(0,2)*F(1,1)*F(2,2) + 2*d[28]*F(0,1)*F(0,2)*F(1,1)*F(2,2) + d[16]*pow(F(0,2),2)*F(1,1)*F(2,2) + d[2]*pow(F(0,0),2)*F(1,2)*F(2,2) + 2*d[20]*F(0,0)*F(0,1)*F(1,2)*F(2,2) + d[8]*pow(F(0,1),2)*F(1,2)*F(2,2) + 2*d[32]*F(0,0)*F(0,2)*F(1,2)*F(2,2) + 2*d[26]*F(0,1)*F(0,2)*F(1,2)*F(2,2) + d[14]*pow(F(0,2),2)*F(1,2)*F(2,2); c.d[5] = d[0]*pow(F(0,0),3)*F(2,0) + 2*d[18]*pow(F(0,0),2)*F(0,1)*F(2,0) + d[6]*F(0,0)*pow(F(0,1),2)*F(2,0) + 2*d[21]*F(0,0)*pow(F(0,1),2)*F(2,0) + d[9]*pow(F(0,1),3)*F(2,0) + d[5]*pow(F(0,0),2)*F(0,2)*F(2,0) + 2*d[30]*pow(F(0,0),2)*F(0,2)*F(2,0) + 2*d[23]*F(0,0)*F(0,1)*F(0,2)*F(2,0) + 2*d[24]*F(0,0)*F(0,1)*F(0,2)*F(2,0) + 2*d[33]*F(0,0)*F(0,1)*F(0,2)*F(2,0) + d[11]*pow(F(0,1),2)*F(0,2)*F(2,0) + 2*d[27]*pow(F(0,1),2)*F(0,2)*F(2,0) + d[12]*F(0,0)*pow(F(0,2),2)*F(2,0) + 2*d[35]*F(0,0)*pow(F(0,2),2)*F(2,0) + d[15]*F(0,1)*pow(F(0,2),2)*F(2,0) + 2*d[29]*F(0,1)*pow(F(0,2),2)*F(2,0) + d[17]*pow(F(0,2),3)*F(2,0) + d[1]*pow(F(0,0),2)*F(0,1)*F(2,1) + 2*d[21]*pow(F(0,0),2)*F(0,1)*F(2,1) + d[9]*F(0,0)*pow(F(0,1),2)*F(2,1) + 2*d[19]*F(0,0)*pow(F(0,1),2)*F(2,1) + d[7]*pow(F(0,1),3)*F(2,1) + d[4]*pow(F(0,0),2)*F(0,2)*F(2,1) + 2*d[33]*pow(F(0,0),2)*F(0,2)*F(2,1) + 2*d[22]*F(0,0)*F(0,1)*F(0,2)*F(2,1) + 2*d[27]*F(0,0)*F(0,1)*F(0,2)*F(2,1) + 2*d[31]*F(0,0)*F(0,1)*F(0,2)*F(2,1) + d[10]*pow(F(0,1),2)*F(0,2)*F(2,1) + 2*d[25]*pow(F(0,1),2)*F(0,2)*F(2,1) + d[15]*F(0,0)*pow(F(0,2),2)*F(2,1) + 2*d[34]*F(0,0)*pow(F(0,2),2)*F(2,1) + d[13]*F(0,1)*pow(F(0,2),2)*F(2,1) + 2*d[28]*F(0,1)*pow(F(0,2),2)*F(2,1) + d[16]*pow(F(0,2),3)*F(2,1) + d[3]*pow(F(0,0),2)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + d[5]*pow(F(0,0),3)*F(2,2) + d[4]*pow(F(0,0),2)*F(0,1)*F(2,2) + 2*d[23]*pow(F(0,0),2)*F(0,1)*F(2,2) + d[11]*F(0,0)*pow(F(0,1),2)*F(2,2) + 2*d[22]*F(0,0)*pow(F(0,1),2)*F(2,2) + d[10]*pow(F(0,1),3)*F(2,2) + d[2]*pow(F(0,0),2)*F(0,2)*F(2,2) + 2*d[35]*pow(F(0,0),2)*F(0,2)*F(2,2) + 2*d[20]*F(0,0)*F(0,1)*F(0,2)*F(2,2) + 2*d[29]*F(0,0)*F(0,1)*F(0,2)*F(2,2) + 2*d[34]*F(0,0)*F(0,1)*F(0,2)*F(2,2) + d[8]*pow(F(0,1),2)*F(0,2)*F(2,2) + 2*d[28]*pow(F(0,1),2)*F(0,2)*F(2,2) + d[17]*F(0,0)*pow(F(0,2),2)*F(2,2) + 2*d[32]*F(0,0)*pow(F(0,2),2)*F(2,2) + d[16]*F(0,1)*pow(F(0,2),2)*F(2,2) + 2*d[26]*F(0,1)*pow(F(0,2),2)*F(2,2) + d[14]*pow(F(0,2),3)*F(2,2); c.d[6] = d[0]*pow(F(0,0),2)*pow(F(1,0),2) + 2*d[3]*F(0,0)*F(0,1)*pow(F(1,0),2) + d[1]*pow(F(0,1),2)*pow(F(1,0),2) + 2*d[5]*F(0,0)*F(0,2)*pow(F(1,0),2) + 2*d[4]*F(0,1)*F(0,2)*pow(F(1,0),2) + d[2]*pow(F(0,2),2)*pow(F(1,0),2) + 2*d[18]*pow(F(0,0),2)*F(1,0)*F(1,1) + 4*d[21]*F(0,0)*F(0,1)*F(1,0)*F(1,1) + 2*d[19]*pow(F(0,1),2)*F(1,0)*F(1,1) + 4*d[23]*F(0,0)*F(0,2)*F(1,0)*F(1,1) + 4*d[22]*F(0,1)*F(0,2)*F(1,0)*F(1,1) + 2*d[20]*pow(F(0,2),2)*F(1,0)*F(1,1) + d[6]*pow(F(0,0),2)*pow(F(1,1),2) + 2*d[9]*F(0,0)*F(0,1)*pow(F(1,1),2) + d[7]*pow(F(0,1),2)*pow(F(1,1),2) + 2*d[11]*F(0,0)*F(0,2)*pow(F(1,1),2) + 2*d[10]*F(0,1)*F(0,2)*pow(F(1,1),2) + d[8]*pow(F(0,2),2)*pow(F(1,1),2) + 2*d[30]*pow(F(0,0),2)*F(1,0)*F(1,2) + 4*d[33]*F(0,0)*F(0,1)*F(1,0)*F(1,2) + 2*d[31]*pow(F(0,1),2)*F(1,0)*F(1,2) + 4*d[35]*F(0,0)*F(0,2)*F(1,0)*F(1,2) + 4*d[34]*F(0,1)*F(0,2)*F(1,0)*F(1,2) + 2*d[32]*pow(F(0,2),2)*F(1,0)*F(1,2) + 2*d[24]*pow(F(0,0),2)*F(1,1)*F(1,2) + 4*d[27]*F(0,0)*F(0,1)*F(1,1)*F(1,2) + 2*d[25]*pow(F(0,1),2)*F(1,1)*F(1,2) + 4*d[29]*F(0,0)*F(0,2)*F(1,1)*F(1,2) + 4*d[28]*F(0,1)*F(0,2)*F(1,1)*F(1,2) + 2*d[26]*pow(F(0,2),2)*F(1,1)*F(1,2) + d[12]*pow(F(0,0),2)*pow(F(1,2),2) + 2*d[15]*F(0,0)*F(0,1)*pow(F(1,2),2) + d[13]*pow(F(0,1),2)*pow(F(1,2),2) + 2*d[17]*F(0,0)*F(0,2)*pow(F(1,2),2) + 2*d[16]*F(0,1)*F(0,2)*pow(F(1,2),2) + d[14]*pow(F(0,2),2)*pow(F(1,2),2); c.d[7] = d[0]*pow(F(1,0),4) + 2*d[3]*pow(F(1,0),3)*F(1,1) + 2*d[18]*pow(F(1,0),3)*F(1,1) + d[1]*pow(F(1,0),2)*pow(F(1,1),2) + d[6]*pow(F(1,0),2)*pow(F(1,1),2) + 4*d[21]*pow(F(1,0),2)*pow(F(1,1),2) + 2*d[9]*F(1,0)*pow(F(1,1),3) + 2*d[19]*F(1,0)*pow(F(1,1),3) + d[7]*pow(F(1,1),4) + 2*d[5]*pow(F(1,0),3)*F(1,2) + 2*d[30]*pow(F(1,0),3)*F(1,2) + 2*d[4]*pow(F(1,0),2)*F(1,1)*F(1,2) + 4*d[23]*pow(F(1,0),2)*F(1,1)*F(1,2) + 2*d[24]*pow(F(1,0),2)*F(1,1)*F(1,2) + 4*d[33]*pow(F(1,0),2)*F(1,1)*F(1,2) + 2*d[11]*F(1,0)*pow(F(1,1),2)*F(1,2) + 4*d[22]*F(1,0)*pow(F(1,1),2)*F(1,2) + 4*d[27]*F(1,0)*pow(F(1,1),2)*F(1,2) + 2*d[31]*F(1,0)*pow(F(1,1),2)*F(1,2) + 2*d[10]*pow(F(1,1),3)*F(1,2) + 2*d[25]*pow(F(1,1),3)*F(1,2) + d[2]*pow(F(1,0),2)*pow(F(1,2),2) + d[12]*pow(F(1,0),2)*pow(F(1,2),2) + 4*d[35]*pow(F(1,0),2)*pow(F(1,2),2) + 2*d[15]*F(1,0)*F(1,1)*pow(F(1,2),2) + 2*d[20]*F(1,0)*F(1,1)*pow(F(1,2),2) + 4*d[29]*F(1,0)*F(1,1)*pow(F(1,2),2) + 4*d[34]*F(1,0)*F(1,1)*pow(F(1,2),2) + d[8]*pow(F(1,1),2)*pow(F(1,2),2) + d[13]*pow(F(1,1),2)*pow(F(1,2),2) + 4*d[28]*pow(F(1,1),2)*pow(F(1,2),2) + 2*d[17]*F(1,0)*pow(F(1,2),3) + 2*d[32]*F(1,0)*pow(F(1,2),3) + 2*d[16]*F(1,1)*pow(F(1,2),3) + 2*d[26]*F(1,1)*pow(F(1,2),3) + d[14]*pow(F(1,2),4); c.d[8] = d[0]*pow(F(1,0),2)*pow(F(2,0),2) + 2*d[18]*F(1,0)*F(1,1)*pow(F(2,0),2) + d[6]*pow(F(1,1),2)*pow(F(2,0),2) + 2*d[30]*F(1,0)*F(1,2)*pow(F(2,0),2) + 2*d[24]*F(1,1)*F(1,2)*pow(F(2,0),2) + d[12]*pow(F(1,2),2)*pow(F(2,0),2) + 2*d[3]*pow(F(1,0),2)*F(2,0)*F(2,1) + 4*d[21]*F(1,0)*F(1,1)*F(2,0)*F(2,1) + 2*d[9]*pow(F(1,1),2)*F(2,0)*F(2,1) + 4*d[33]*F(1,0)*F(1,2)*F(2,0)*F(2,1) + 4*d[27]*F(1,1)*F(1,2)*F(2,0)*F(2,1) + 2*d[15]*pow(F(1,2),2)*F(2,0)*F(2,1) + d[1]*pow(F(1,0),2)*pow(F(2,1),2) + 2*d[19]*F(1,0)*F(1,1)*pow(F(2,1),2) + d[7]*pow(F(1,1),2)*pow(F(2,1),2) + 2*d[31]*F(1,0)*F(1,2)*pow(F(2,1),2) + 2*d[25]*F(1,1)*F(1,2)*pow(F(2,1),2) + d[13]*pow(F(1,2),2)*pow(F(2,1),2) + 2*d[5]*pow(F(1,0),2)*F(2,0)*F(2,2) + 4*d[23]*F(1,0)*F(1,1)*F(2,0)*F(2,2) + 2*d[11]*pow(F(1,1),2)*F(2,0)*F(2,2) + 4*d[35]*F(1,0)*F(1,2)*F(2,0)*F(2,2) + 4*d[29]*F(1,1)*F(1,2)*F(2,0)*F(2,2) + 2*d[17]*pow(F(1,2),2)*F(2,0)*F(2,2) + 2*d[4]*pow(F(1,0),2)*F(2,1)*F(2,2) + 4*d[22]*F(1,0)*F(1,1)*F(2,1)*F(2,2) + 2*d[10]*pow(F(1,1),2)*F(2,1)*F(2,2) + 4*d[34]*F(1,0)*F(1,2)*F(2,1)*F(2,2) + 4*d[28]*F(1,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[16]*pow(F(1,2),2)*F(2,1)*F(2,2) + d[2]*pow(F(1,0),2)*pow(F(2,2),2) + 2*d[20]*F(1,0)*F(1,1)*pow(F(2,2),2) + d[8]*pow(F(1,1),2)*pow(F(2,2),2) + 2*d[32]*F(1,0)*F(1,2)*pow(F(2,2),2) + 2*d[26]*F(1,1)*F(1,2)*pow(F(2,2),2) + d[14]*pow(F(1,2),2)*pow(F(2,2),2); c.d[9] = d[0]*F(0,0)*pow(F(1,0),3) + d[5]*F(0,2)*pow(F(1,0),3) + 2*d[18]*F(0,0)*pow(F(1,0),2)*F(1,1) + d[1]*F(0,1)*pow(F(1,0),2)*F(1,1) + 2*d[21]*F(0,1)*pow(F(1,0),2)*F(1,1) + d[4]*F(0,2)*pow(F(1,0),2)*F(1,1) + 2*d[23]*F(0,2)*pow(F(1,0),2)*F(1,1) + d[6]*F(0,0)*F(1,0)*pow(F(1,1),2) + 2*d[21]*F(0,0)*F(1,0)*pow(F(1,1),2) + d[9]*F(0,1)*F(1,0)*pow(F(1,1),2) + 2*d[19]*F(0,1)*F(1,0)*pow(F(1,1),2) + d[11]*F(0,2)*F(1,0)*pow(F(1,1),2) + 2*d[22]*F(0,2)*F(1,0)*pow(F(1,1),2) + d[9]*F(0,0)*pow(F(1,1),3) + d[7]*F(0,1)*pow(F(1,1),3) + d[10]*F(0,2)*pow(F(1,1),3) + d[3]*pow(F(1,0),2)*(F(0,1)*F(1,0) + F(0,0)*F(1,1)) + d[5]*F(0,0)*pow(F(1,0),2)*F(1,2) + 2*d[30]*F(0,0)*pow(F(1,0),2)*F(1,2) + d[4]*F(0,1)*pow(F(1,0),2)*F(1,2) + 2*d[33]*F(0,1)*pow(F(1,0),2)*F(1,2) + d[2]*F(0,2)*pow(F(1,0),2)*F(1,2) + 2*d[35]*F(0,2)*pow(F(1,0),2)*F(1,2) + 2*d[23]*F(0,0)*F(1,0)*F(1,1)*F(1,2) + 2*d[24]*F(0,0)*F(1,0)*F(1,1)*F(1,2) + 2*d[33]*F(0,0)*F(1,0)*F(1,1)*F(1,2) + 2*d[22]*F(0,1)*F(1,0)*F(1,1)*F(1,2) + 2*d[27]*F(0,1)*F(1,0)*F(1,1)*F(1,2) + 2*d[31]*F(0,1)*F(1,0)*F(1,1)*F(1,2) + 2*d[20]*F(0,2)*F(1,0)*F(1,1)*F(1,2) + 2*d[29]*F(0,2)*F(1,0)*F(1,1)*F(1,2) + 2*d[34]*F(0,2)*F(1,0)*F(1,1)*F(1,2) + d[11]*F(0,0)*pow(F(1,1),2)*F(1,2) + 2*d[27]*F(0,0)*pow(F(1,1),2)*F(1,2) + d[10]*F(0,1)*pow(F(1,1),2)*F(1,2) + 2*d[25]*F(0,1)*pow(F(1,1),2)*F(1,2) + d[8]*F(0,2)*pow(F(1,1),2)*F(1,2) + 2*d[28]*F(0,2)*pow(F(1,1),2)*F(1,2) + d[12]*F(0,0)*F(1,0)*pow(F(1,2),2) + 2*d[35]*F(0,0)*F(1,0)*pow(F(1,2),2) + d[15]*F(0,1)*F(1,0)*pow(F(1,2),2) + 2*d[34]*F(0,1)*F(1,0)*pow(F(1,2),2) + d[17]*F(0,2)*F(1,0)*pow(F(1,2),2) + 2*d[32]*F(0,2)*F(1,0)*pow(F(1,2),2) + d[15]*F(0,0)*F(1,1)*pow(F(1,2),2) + 2*d[29]*F(0,0)*F(1,1)*pow(F(1,2),2) + d[13]*F(0,1)*F(1,1)*pow(F(1,2),2) + 2*d[28]*F(0,1)*F(1,1)*pow(F(1,2),2) + d[16]*F(0,2)*F(1,1)*pow(F(1,2),2) + 2*d[26]*F(0,2)*F(1,1)*pow(F(1,2),2) + d[17]*F(0,0)*pow(F(1,2),3) + d[16]*F(0,1)*pow(F(1,2),3) + d[14]*F(0,2)*pow(F(1,2),3); c.d[10] = d[0]*pow(F(1,0),3)*F(2,0) + 2*d[18]*pow(F(1,0),2)*F(1,1)*F(2,0) + d[6]*F(1,0)*pow(F(1,1),2)*F(2,0) + 2*d[21]*F(1,0)*pow(F(1,1),2)*F(2,0) + d[9]*pow(F(1,1),3)*F(2,0) + d[5]*pow(F(1,0),2)*F(1,2)*F(2,0) + 2*d[30]*pow(F(1,0),2)*F(1,2)*F(2,0) + 2*d[23]*F(1,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[24]*F(1,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[33]*F(1,0)*F(1,1)*F(1,2)*F(2,0) + d[11]*pow(F(1,1),2)*F(1,2)*F(2,0) + 2*d[27]*pow(F(1,1),2)*F(1,2)*F(2,0) + d[12]*F(1,0)*pow(F(1,2),2)*F(2,0) + 2*d[35]*F(1,0)*pow(F(1,2),2)*F(2,0) + d[15]*F(1,1)*pow(F(1,2),2)*F(2,0) + 2*d[29]*F(1,1)*pow(F(1,2),2)*F(2,0) + d[17]*pow(F(1,2),3)*F(2,0) + d[1]*pow(F(1,0),2)*F(1,1)*F(2,1) + 2*d[21]*pow(F(1,0),2)*F(1,1)*F(2,1) + d[9]*F(1,0)*pow(F(1,1),2)*F(2,1) + 2*d[19]*F(1,0)*pow(F(1,1),2)*F(2,1) + d[7]*pow(F(1,1),3)*F(2,1) + d[4]*pow(F(1,0),2)*F(1,2)*F(2,1) + 2*d[33]*pow(F(1,0),2)*F(1,2)*F(2,1) + 2*d[22]*F(1,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[27]*F(1,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[31]*F(1,0)*F(1,1)*F(1,2)*F(2,1) + d[10]*pow(F(1,1),2)*F(1,2)*F(2,1) + 2*d[25]*pow(F(1,1),2)*F(1,2)*F(2,1) + d[15]*F(1,0)*pow(F(1,2),2)*F(2,1) + 2*d[34]*F(1,0)*pow(F(1,2),2)*F(2,1) + d[13]*F(1,1)*pow(F(1,2),2)*F(2,1) + 2*d[28]*F(1,1)*pow(F(1,2),2)*F(2,1) + d[16]*pow(F(1,2),3)*F(2,1) + d[3]*pow(F(1,0),2)*(F(1,1)*F(2,0) + F(1,0)*F(2,1)) + d[5]*pow(F(1,0),3)*F(2,2) + d[4]*pow(F(1,0),2)*F(1,1)*F(2,2) + 2*d[23]*pow(F(1,0),2)*F(1,1)*F(2,2) + d[11]*F(1,0)*pow(F(1,1),2)*F(2,2) + 2*d[22]*F(1,0)*pow(F(1,1),2)*F(2,2) + d[10]*pow(F(1,1),3)*F(2,2) + d[2]*pow(F(1,0),2)*F(1,2)*F(2,2) + 2*d[35]*pow(F(1,0),2)*F(1,2)*F(2,2) + 2*d[20]*F(1,0)*F(1,1)*F(1,2)*F(2,2) + 2*d[29]*F(1,0)*F(1,1)*F(1,2)*F(2,2) + 2*d[34]*F(1,0)*F(1,1)*F(1,2)*F(2,2) + d[8]*pow(F(1,1),2)*F(1,2)*F(2,2) + 2*d[28]*pow(F(1,1),2)*F(1,2)*F(2,2) + d[17]*F(1,0)*pow(F(1,2),2)*F(2,2) + 2*d[32]*F(1,0)*pow(F(1,2),2)*F(2,2) + d[16]*F(1,1)*pow(F(1,2),2)*F(2,2) + 2*d[26]*F(1,1)*pow(F(1,2),2)*F(2,2) + d[14]*pow(F(1,2),3)*F(2,2); c.d[11] = d[0]*F(0,0)*pow(F(1,0),2)*F(2,0) + d[5]*F(0,2)*pow(F(1,0),2)*F(2,0) + 2*d[18]*F(0,0)*F(1,0)*F(1,1)*F(2,0) + 2*d[21]*F(0,1)*F(1,0)*F(1,1)*F(2,0) + 2*d[23]*F(0,2)*F(1,0)*F(1,1)*F(2,0) + d[6]*F(0,0)*pow(F(1,1),2)*F(2,0) + d[9]*F(0,1)*pow(F(1,1),2)*F(2,0) + d[11]*F(0,2)*pow(F(1,1),2)*F(2,0) + 2*d[30]*F(0,0)*F(1,0)*F(1,2)*F(2,0) + 2*d[33]*F(0,1)*F(1,0)*F(1,2)*F(2,0) + 2*d[35]*F(0,2)*F(1,0)*F(1,2)*F(2,0) + 2*d[24]*F(0,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[27]*F(0,1)*F(1,1)*F(1,2)*F(2,0) + 2*d[29]*F(0,2)*F(1,1)*F(1,2)*F(2,0) + d[12]*F(0,0)*pow(F(1,2),2)*F(2,0) + d[15]*F(0,1)*pow(F(1,2),2)*F(2,0) + d[17]*F(0,2)*pow(F(1,2),2)*F(2,0) + d[1]*F(0,1)*pow(F(1,0),2)*F(2,1) + d[4]*F(0,2)*pow(F(1,0),2)*F(2,1) + 2*d[21]*F(0,0)*F(1,0)*F(1,1)*F(2,1) + 2*d[19]*F(0,1)*F(1,0)*F(1,1)*F(2,1) + 2*d[22]*F(0,2)*F(1,0)*F(1,1)*F(2,1) + d[9]*F(0,0)*pow(F(1,1),2)*F(2,1) + d[7]*F(0,1)*pow(F(1,1),2)*F(2,1) + d[10]*F(0,2)*pow(F(1,1),2)*F(2,1) + 2*d[33]*F(0,0)*F(1,0)*F(1,2)*F(2,1) + 2*d[31]*F(0,1)*F(1,0)*F(1,2)*F(2,1) + 2*d[34]*F(0,2)*F(1,0)*F(1,2)*F(2,1) + 2*d[27]*F(0,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[25]*F(0,1)*F(1,1)*F(1,2)*F(2,1) + 2*d[28]*F(0,2)*F(1,1)*F(1,2)*F(2,1) + d[15]*F(0,0)*pow(F(1,2),2)*F(2,1) + d[13]*F(0,1)*pow(F(1,2),2)*F(2,1) + d[16]*F(0,2)*pow(F(1,2),2)*F(2,1) + d[3]*pow(F(1,0),2)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + d[5]*F(0,0)*pow(F(1,0),2)*F(2,2) + d[4]*F(0,1)*pow(F(1,0),2)*F(2,2) + d[2]*F(0,2)*pow(F(1,0),2)*F(2,2) + 2*d[23]*F(0,0)*F(1,0)*F(1,1)*F(2,2) + 2*d[22]*F(0,1)*F(1,0)*F(1,1)*F(2,2) + 2*d[20]*F(0,2)*F(1,0)*F(1,1)*F(2,2) + d[11]*F(0,0)*pow(F(1,1),2)*F(2,2) + d[10]*F(0,1)*pow(F(1,1),2)*F(2,2) + d[8]*F(0,2)*pow(F(1,1),2)*F(2,2) + 2*d[35]*F(0,0)*F(1,0)*F(1,2)*F(2,2) + 2*d[34]*F(0,1)*F(1,0)*F(1,2)*F(2,2) + 2*d[32]*F(0,2)*F(1,0)*F(1,2)*F(2,2) + 2*d[29]*F(0,0)*F(1,1)*F(1,2)*F(2,2) + 2*d[28]*F(0,1)*F(1,1)*F(1,2)*F(2,2) + 2*d[26]*F(0,2)*F(1,1)*F(1,2)*F(2,2) + d[17]*F(0,0)*pow(F(1,2),2)*F(2,2) + d[16]*F(0,1)*pow(F(1,2),2)*F(2,2) + d[14]*F(0,2)*pow(F(1,2),2)*F(2,2); c.d[12] = d[0]*pow(F(0,0),2)*pow(F(2,0),2) + 2*d[3]*F(0,0)*F(0,1)*pow(F(2,0),2) + d[1]*pow(F(0,1),2)*pow(F(2,0),2) + 2*d[5]*F(0,0)*F(0,2)*pow(F(2,0),2) + 2*d[4]*F(0,1)*F(0,2)*pow(F(2,0),2) + d[2]*pow(F(0,2),2)*pow(F(2,0),2) + 2*d[18]*pow(F(0,0),2)*F(2,0)*F(2,1) + 4*d[21]*F(0,0)*F(0,1)*F(2,0)*F(2,1) + 2*d[19]*pow(F(0,1),2)*F(2,0)*F(2,1) + 4*d[23]*F(0,0)*F(0,2)*F(2,0)*F(2,1) + 4*d[22]*F(0,1)*F(0,2)*F(2,0)*F(2,1) + 2*d[20]*pow(F(0,2),2)*F(2,0)*F(2,1) + d[6]*pow(F(0,0),2)*pow(F(2,1),2) + 2*d[9]*F(0,0)*F(0,1)*pow(F(2,1),2) + d[7]*pow(F(0,1),2)*pow(F(2,1),2) + 2*d[11]*F(0,0)*F(0,2)*pow(F(2,1),2) + 2*d[10]*F(0,1)*F(0,2)*pow(F(2,1),2) + d[8]*pow(F(0,2),2)*pow(F(2,1),2) + 2*d[30]*pow(F(0,0),2)*F(2,0)*F(2,2) + 4*d[33]*F(0,0)*F(0,1)*F(2,0)*F(2,2) + 2*d[31]*pow(F(0,1),2)*F(2,0)*F(2,2) + 4*d[35]*F(0,0)*F(0,2)*F(2,0)*F(2,2) + 4*d[34]*F(0,1)*F(0,2)*F(2,0)*F(2,2) + 2*d[32]*pow(F(0,2),2)*F(2,0)*F(2,2) + 2*d[24]*pow(F(0,0),2)*F(2,1)*F(2,2) + 4*d[27]*F(0,0)*F(0,1)*F(2,1)*F(2,2) + 2*d[25]*pow(F(0,1),2)*F(2,1)*F(2,2) + 4*d[29]*F(0,0)*F(0,2)*F(2,1)*F(2,2) + 4*d[28]*F(0,1)*F(0,2)*F(2,1)*F(2,2) + 2*d[26]*pow(F(0,2),2)*F(2,1)*F(2,2) + d[12]*pow(F(0,0),2)*pow(F(2,2),2) + 2*d[15]*F(0,0)*F(0,1)*pow(F(2,2),2) + d[13]*pow(F(0,1),2)*pow(F(2,2),2) + 2*d[17]*F(0,0)*F(0,2)*pow(F(2,2),2) + 2*d[16]*F(0,1)*F(0,2)*pow(F(2,2),2) + d[14]*pow(F(0,2),2)*pow(F(2,2),2); c.d[13] = d[0]*pow(F(1,0),2)*pow(F(2,0),2) + 2*d[3]*F(1,0)*F(1,1)*pow(F(2,0),2) + d[1]*pow(F(1,1),2)*pow(F(2,0),2) + 2*d[5]*F(1,0)*F(1,2)*pow(F(2,0),2) + 2*d[4]*F(1,1)*F(1,2)*pow(F(2,0),2) + d[2]*pow(F(1,2),2)*pow(F(2,0),2) + 2*d[18]*pow(F(1,0),2)*F(2,0)*F(2,1) + 4*d[21]*F(1,0)*F(1,1)*F(2,0)*F(2,1) + 2*d[19]*pow(F(1,1),2)*F(2,0)*F(2,1) + 4*d[23]*F(1,0)*F(1,2)*F(2,0)*F(2,1) + 4*d[22]*F(1,1)*F(1,2)*F(2,0)*F(2,1) + 2*d[20]*pow(F(1,2),2)*F(2,0)*F(2,1) + d[6]*pow(F(1,0),2)*pow(F(2,1),2) + 2*d[9]*F(1,0)*F(1,1)*pow(F(2,1),2) + d[7]*pow(F(1,1),2)*pow(F(2,1),2) + 2*d[11]*F(1,0)*F(1,2)*pow(F(2,1),2) + 2*d[10]*F(1,1)*F(1,2)*pow(F(2,1),2) + d[8]*pow(F(1,2),2)*pow(F(2,1),2) + 2*d[30]*pow(F(1,0),2)*F(2,0)*F(2,2) + 4*d[33]*F(1,0)*F(1,1)*F(2,0)*F(2,2) + 2*d[31]*pow(F(1,1),2)*F(2,0)*F(2,2) + 4*d[35]*F(1,0)*F(1,2)*F(2,0)*F(2,2) + 4*d[34]*F(1,1)*F(1,2)*F(2,0)*F(2,2) + 2*d[32]*pow(F(1,2),2)*F(2,0)*F(2,2) + 2*d[24]*pow(F(1,0),2)*F(2,1)*F(2,2) + 4*d[27]*F(1,0)*F(1,1)*F(2,1)*F(2,2) + 2*d[25]*pow(F(1,1),2)*F(2,1)*F(2,2) + 4*d[29]*F(1,0)*F(1,2)*F(2,1)*F(2,2) + 4*d[28]*F(1,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[26]*pow(F(1,2),2)*F(2,1)*F(2,2) + d[12]*pow(F(1,0),2)*pow(F(2,2),2) + 2*d[15]*F(1,0)*F(1,1)*pow(F(2,2),2) + d[13]*pow(F(1,1),2)*pow(F(2,2),2) + 2*d[17]*F(1,0)*F(1,2)*pow(F(2,2),2) + 2*d[16]*F(1,1)*F(1,2)*pow(F(2,2),2) + d[14]*pow(F(1,2),2)*pow(F(2,2),2); c.d[14] = d[0]*pow(F(2,0),4) + 2*d[3]*pow(F(2,0),3)*F(2,1) + 2*d[18]*pow(F(2,0),3)*F(2,1) + d[1]*pow(F(2,0),2)*pow(F(2,1),2) + d[6]*pow(F(2,0),2)*pow(F(2,1),2) + 4*d[21]*pow(F(2,0),2)*pow(F(2,1),2) + 2*d[9]*F(2,0)*pow(F(2,1),3) + 2*d[19]*F(2,0)*pow(F(2,1),3) + d[7]*pow(F(2,1),4) + 2*d[5]*pow(F(2,0),3)*F(2,2) + 2*d[30]*pow(F(2,0),3)*F(2,2) + 2*d[4]*pow(F(2,0),2)*F(2,1)*F(2,2) + 4*d[23]*pow(F(2,0),2)*F(2,1)*F(2,2) + 2*d[24]*pow(F(2,0),2)*F(2,1)*F(2,2) + 4*d[33]*pow(F(2,0),2)*F(2,1)*F(2,2) + 2*d[11]*F(2,0)*pow(F(2,1),2)*F(2,2) + 4*d[22]*F(2,0)*pow(F(2,1),2)*F(2,2) + 4*d[27]*F(2,0)*pow(F(2,1),2)*F(2,2) + 2*d[31]*F(2,0)*pow(F(2,1),2)*F(2,2) + 2*d[10]*pow(F(2,1),3)*F(2,2) + 2*d[25]*pow(F(2,1),3)*F(2,2) + d[2]*pow(F(2,0),2)*pow(F(2,2),2) + d[12]*pow(F(2,0),2)*pow(F(2,2),2) + 4*d[35]*pow(F(2,0),2)*pow(F(2,2),2) + 2*d[15]*F(2,0)*F(2,1)*pow(F(2,2),2) + 2*d[20]*F(2,0)*F(2,1)*pow(F(2,2),2) + 4*d[29]*F(2,0)*F(2,1)*pow(F(2,2),2) + 4*d[34]*F(2,0)*F(2,1)*pow(F(2,2),2) + d[8]*pow(F(2,1),2)*pow(F(2,2),2) + d[13]*pow(F(2,1),2)*pow(F(2,2),2) + 4*d[28]*pow(F(2,1),2)*pow(F(2,2),2) + 2*d[17]*F(2,0)*pow(F(2,2),3) + 2*d[32]*F(2,0)*pow(F(2,2),3) + 2*d[16]*F(2,1)*pow(F(2,2),3) + 2*d[26]*F(2,1)*pow(F(2,2),3) + d[14]*pow(F(2,2),4); c.d[15] = d[0]*F(0,0)*F(1,0)*pow(F(2,0),2) + d[5]*F(0,2)*F(1,0)*pow(F(2,0),2) + d[1]*F(0,1)*F(1,1)*pow(F(2,0),2) + d[4]*F(0,2)*F(1,1)*pow(F(2,0),2) + d[3]*(F(0,1)*F(1,0) + F(0,0)*F(1,1))*pow(F(2,0),2) + d[5]*F(0,0)*F(1,2)*pow(F(2,0),2) + d[4]*F(0,1)*F(1,2)*pow(F(2,0),2) + d[2]*F(0,2)*F(1,2)*pow(F(2,0),2) + 2*d[18]*F(0,0)*F(1,0)*F(2,0)*F(2,1) + 2*d[21]*F(0,1)*F(1,0)*F(2,0)*F(2,1) + 2*d[23]*F(0,2)*F(1,0)*F(2,0)*F(2,1) + 2*d[21]*F(0,0)*F(1,1)*F(2,0)*F(2,1) + 2*d[19]*F(0,1)*F(1,1)*F(2,0)*F(2,1) + 2*d[22]*F(0,2)*F(1,1)*F(2,0)*F(2,1) + 2*d[23]*F(0,0)*F(1,2)*F(2,0)*F(2,1) + 2*d[22]*F(0,1)*F(1,2)*F(2,0)*F(2,1) + 2*d[20]*F(0,2)*F(1,2)*F(2,0)*F(2,1) + d[6]*F(0,0)*F(1,0)*pow(F(2,1),2) + d[9]*F(0,1)*F(1,0)*pow(F(2,1),2) + d[11]*F(0,2)*F(1,0)*pow(F(2,1),2) + d[9]*F(0,0)*F(1,1)*pow(F(2,1),2) + d[7]*F(0,1)*F(1,1)*pow(F(2,1),2) + d[10]*F(0,2)*F(1,1)*pow(F(2,1),2) + d[11]*F(0,0)*F(1,2)*pow(F(2,1),2) + d[10]*F(0,1)*F(1,2)*pow(F(2,1),2) + d[8]*F(0,2)*F(1,2)*pow(F(2,1),2) + 2*d[30]*F(0,0)*F(1,0)*F(2,0)*F(2,2) + 2*d[33]*F(0,1)*F(1,0)*F(2,0)*F(2,2) + 2*d[35]*F(0,2)*F(1,0)*F(2,0)*F(2,2) + 2*d[33]*F(0,0)*F(1,1)*F(2,0)*F(2,2) + 2*d[31]*F(0,1)*F(1,1)*F(2,0)*F(2,2) + 2*d[34]*F(0,2)*F(1,1)*F(2,0)*F(2,2) + 2*d[35]*F(0,0)*F(1,2)*F(2,0)*F(2,2) + 2*d[34]*F(0,1)*F(1,2)*F(2,0)*F(2,2) + 2*d[32]*F(0,2)*F(1,2)*F(2,0)*F(2,2) + 2*d[24]*F(0,0)*F(1,0)*F(2,1)*F(2,2) + 2*d[27]*F(0,1)*F(1,0)*F(2,1)*F(2,2) + 2*d[29]*F(0,2)*F(1,0)*F(2,1)*F(2,2) + 2*d[27]*F(0,0)*F(1,1)*F(2,1)*F(2,2) + 2*d[25]*F(0,1)*F(1,1)*F(2,1)*F(2,2) + 2*d[28]*F(0,2)*F(1,1)*F(2,1)*F(2,2) + 2*d[29]*F(0,0)*F(1,2)*F(2,1)*F(2,2) + 2*d[28]*F(0,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[26]*F(0,2)*F(1,2)*F(2,1)*F(2,2) + d[12]*F(0,0)*F(1,0)*pow(F(2,2),2) + d[15]*F(0,1)*F(1,0)*pow(F(2,2),2) + d[17]*F(0,2)*F(1,0)*pow(F(2,2),2) + d[15]*F(0,0)*F(1,1)*pow(F(2,2),2) + d[13]*F(0,1)*F(1,1)*pow(F(2,2),2) + d[16]*F(0,2)*F(1,1)*pow(F(2,2),2) + d[17]*F(0,0)*F(1,2)*pow(F(2,2),2) + d[16]*F(0,1)*F(1,2)*pow(F(2,2),2) + d[14]*F(0,2)*F(1,2)*pow(F(2,2),2); c.d[16] = d[0]*F(1,0)*pow(F(2,0),3) + d[5]*F(1,2)*pow(F(2,0),3) + 2*d[18]*F(1,0)*pow(F(2,0),2)*F(2,1) + d[1]*F(1,1)*pow(F(2,0),2)*F(2,1) + 2*d[21]*F(1,1)*pow(F(2,0),2)*F(2,1) + d[4]*F(1,2)*pow(F(2,0),2)*F(2,1) + 2*d[23]*F(1,2)*pow(F(2,0),2)*F(2,1) + d[6]*F(1,0)*F(2,0)*pow(F(2,1),2) + 2*d[21]*F(1,0)*F(2,0)*pow(F(2,1),2) + d[9]*F(1,1)*F(2,0)*pow(F(2,1),2) + 2*d[19]*F(1,1)*F(2,0)*pow(F(2,1),2) + d[11]*F(1,2)*F(2,0)*pow(F(2,1),2) + 2*d[22]*F(1,2)*F(2,0)*pow(F(2,1),2) + d[9]*F(1,0)*pow(F(2,1),3) + d[7]*F(1,1)*pow(F(2,1),3) + d[10]*F(1,2)*pow(F(2,1),3) + d[3]*pow(F(2,0),2)*(F(1,1)*F(2,0) + F(1,0)*F(2,1)) + d[5]*F(1,0)*pow(F(2,0),2)*F(2,2) + 2*d[30]*F(1,0)*pow(F(2,0),2)*F(2,2) + d[4]*F(1,1)*pow(F(2,0),2)*F(2,2) + 2*d[33]*F(1,1)*pow(F(2,0),2)*F(2,2) + d[2]*F(1,2)*pow(F(2,0),2)*F(2,2) + 2*d[35]*F(1,2)*pow(F(2,0),2)*F(2,2) + 2*d[23]*F(1,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[24]*F(1,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[33]*F(1,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[22]*F(1,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[27]*F(1,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[31]*F(1,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[20]*F(1,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[29]*F(1,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[34]*F(1,2)*F(2,0)*F(2,1)*F(2,2) + d[11]*F(1,0)*pow(F(2,1),2)*F(2,2) + 2*d[27]*F(1,0)*pow(F(2,1),2)*F(2,2) + d[10]*F(1,1)*pow(F(2,1),2)*F(2,2) + 2*d[25]*F(1,1)*pow(F(2,1),2)*F(2,2) + d[8]*F(1,2)*pow(F(2,1),2)*F(2,2) + 2*d[28]*F(1,2)*pow(F(2,1),2)*F(2,2) + d[12]*F(1,0)*F(2,0)*pow(F(2,2),2) + 2*d[35]*F(1,0)*F(2,0)*pow(F(2,2),2) + d[15]*F(1,1)*F(2,0)*pow(F(2,2),2) + 2*d[34]*F(1,1)*F(2,0)*pow(F(2,2),2) + d[17]*F(1,2)*F(2,0)*pow(F(2,2),2) + 2*d[32]*F(1,2)*F(2,0)*pow(F(2,2),2) + d[15]*F(1,0)*F(2,1)*pow(F(2,2),2) + 2*d[29]*F(1,0)*F(2,1)*pow(F(2,2),2) + d[13]*F(1,1)*F(2,1)*pow(F(2,2),2) + 2*d[28]*F(1,1)*F(2,1)*pow(F(2,2),2) + d[16]*F(1,2)*F(2,1)*pow(F(2,2),2) + 2*d[26]*F(1,2)*F(2,1)*pow(F(2,2),2) + d[17]*F(1,0)*pow(F(2,2),3) + d[16]*F(1,1)*pow(F(2,2),3) + d[14]*F(1,2)*pow(F(2,2),3); c.d[17] = d[0]*F(0,0)*pow(F(2,0),3) + d[5]*F(0,2)*pow(F(2,0),3) + 2*d[18]*F(0,0)*pow(F(2,0),2)*F(2,1) + d[1]*F(0,1)*pow(F(2,0),2)*F(2,1) + 2*d[21]*F(0,1)*pow(F(2,0),2)*F(2,1) + d[4]*F(0,2)*pow(F(2,0),2)*F(2,1) + 2*d[23]*F(0,2)*pow(F(2,0),2)*F(2,1) + d[6]*F(0,0)*F(2,0)*pow(F(2,1),2) + 2*d[21]*F(0,0)*F(2,0)*pow(F(2,1),2) + d[9]*F(0,1)*F(2,0)*pow(F(2,1),2) + 2*d[19]*F(0,1)*F(2,0)*pow(F(2,1),2) + d[11]*F(0,2)*F(2,0)*pow(F(2,1),2) + 2*d[22]*F(0,2)*F(2,0)*pow(F(2,1),2) + d[9]*F(0,0)*pow(F(2,1),3) + d[7]*F(0,1)*pow(F(2,1),3) + d[10]*F(0,2)*pow(F(2,1),3) + d[3]*pow(F(2,0),2)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + d[5]*F(0,0)*pow(F(2,0),2)*F(2,2) + 2*d[30]*F(0,0)*pow(F(2,0),2)*F(2,2) + d[4]*F(0,1)*pow(F(2,0),2)*F(2,2) + 2*d[33]*F(0,1)*pow(F(2,0),2)*F(2,2) + d[2]*F(0,2)*pow(F(2,0),2)*F(2,2) + 2*d[35]*F(0,2)*pow(F(2,0),2)*F(2,2) + 2*d[23]*F(0,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[24]*F(0,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[33]*F(0,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[22]*F(0,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[27]*F(0,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[31]*F(0,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[20]*F(0,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[29]*F(0,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[34]*F(0,2)*F(2,0)*F(2,1)*F(2,2) + d[11]*F(0,0)*pow(F(2,1),2)*F(2,2) + 2*d[27]*F(0,0)*pow(F(2,1),2)*F(2,2) + d[10]*F(0,1)*pow(F(2,1),2)*F(2,2) + 2*d[25]*F(0,1)*pow(F(2,1),2)*F(2,2) + d[8]*F(0,2)*pow(F(2,1),2)*F(2,2) + 2*d[28]*F(0,2)*pow(F(2,1),2)*F(2,2) + d[12]*F(0,0)*F(2,0)*pow(F(2,2),2) + 2*d[35]*F(0,0)*F(2,0)*pow(F(2,2),2) + d[15]*F(0,1)*F(2,0)*pow(F(2,2),2) + 2*d[34]*F(0,1)*F(2,0)*pow(F(2,2),2) + d[17]*F(0,2)*F(2,0)*pow(F(2,2),2) + 2*d[32]*F(0,2)*F(2,0)*pow(F(2,2),2) + d[15]*F(0,0)*F(2,1)*pow(F(2,2),2) + 2*d[29]*F(0,0)*F(2,1)*pow(F(2,2),2) + d[13]*F(0,1)*F(2,1)*pow(F(2,2),2) + 2*d[28]*F(0,1)*F(2,1)*pow(F(2,2),2) + d[16]*F(0,2)*F(2,1)*pow(F(2,2),2) + 2*d[26]*F(0,2)*F(2,1)*pow(F(2,2),2) + d[17]*F(0,0)*pow(F(2,2),3) + d[16]*F(0,1)*pow(F(2,2),3) + d[14]*F(0,2)*pow(F(2,2),3); c.d[18] = d[0]*pow(F(0,0),3)*F(1,0) + 2*d[3]*pow(F(0,0),2)*F(0,1)*F(1,0) + d[18]*pow(F(0,0),2)*F(0,1)*F(1,0) + d[1]*F(0,0)*pow(F(0,1),2)*F(1,0) + 2*d[21]*F(0,0)*pow(F(0,1),2)*F(1,0) + d[19]*pow(F(0,1),3)*F(1,0) + 2*d[5]*pow(F(0,0),2)*F(0,2)*F(1,0) + d[30]*pow(F(0,0),2)*F(0,2)*F(1,0) + 2*d[4]*F(0,0)*F(0,1)*F(0,2)*F(1,0) + 2*d[23]*F(0,0)*F(0,1)*F(0,2)*F(1,0) + 2*d[33]*F(0,0)*F(0,1)*F(0,2)*F(1,0) + 2*d[22]*pow(F(0,1),2)*F(0,2)*F(1,0) + d[31]*pow(F(0,1),2)*F(0,2)*F(1,0) + d[2]*F(0,0)*pow(F(0,2),2)*F(1,0) + 2*d[35]*F(0,0)*pow(F(0,2),2)*F(1,0) + d[20]*F(0,1)*pow(F(0,2),2)*F(1,0) + 2*d[34]*F(0,1)*pow(F(0,2),2)*F(1,0) + d[32]*pow(F(0,2),3)*F(1,0) + d[18]*pow(F(0,0),3)*F(1,1) + d[6]*pow(F(0,0),2)*F(0,1)*F(1,1) + 2*d[21]*pow(F(0,0),2)*F(0,1)*F(1,1) + 2*d[9]*F(0,0)*pow(F(0,1),2)*F(1,1) + d[19]*F(0,0)*pow(F(0,1),2)*F(1,1) + d[7]*pow(F(0,1),3)*F(1,1) + 2*d[23]*pow(F(0,0),2)*F(0,2)*F(1,1) + d[24]*pow(F(0,0),2)*F(0,2)*F(1,1) + 2*d[11]*F(0,0)*F(0,1)*F(0,2)*F(1,1) + 2*d[22]*F(0,0)*F(0,1)*F(0,2)*F(1,1) + 2*d[27]*F(0,0)*F(0,1)*F(0,2)*F(1,1) + 2*d[10]*pow(F(0,1),2)*F(0,2)*F(1,1) + d[25]*pow(F(0,1),2)*F(0,2)*F(1,1) + d[20]*F(0,0)*pow(F(0,2),2)*F(1,1) + 2*d[29]*F(0,0)*pow(F(0,2),2)*F(1,1) + d[8]*F(0,1)*pow(F(0,2),2)*F(1,1) + 2*d[28]*F(0,1)*pow(F(0,2),2)*F(1,1) + d[26]*pow(F(0,2),3)*F(1,1) + d[30]*pow(F(0,0),3)*F(1,2) + d[24]*pow(F(0,0),2)*F(0,1)*F(1,2) + 2*d[33]*pow(F(0,0),2)*F(0,1)*F(1,2) + 2*d[27]*F(0,0)*pow(F(0,1),2)*F(1,2) + d[31]*F(0,0)*pow(F(0,1),2)*F(1,2) + d[25]*pow(F(0,1),3)*F(1,2) + d[12]*pow(F(0,0),2)*F(0,2)*F(1,2) + 2*d[35]*pow(F(0,0),2)*F(0,2)*F(1,2) + 2*d[15]*F(0,0)*F(0,1)*F(0,2)*F(1,2) + 2*d[29]*F(0,0)*F(0,1)*F(0,2)*F(1,2) + 2*d[34]*F(0,0)*F(0,1)*F(0,2)*F(1,2) + d[13]*pow(F(0,1),2)*F(0,2)*F(1,2) + 2*d[28]*pow(F(0,1),2)*F(0,2)*F(1,2) + 2*d[17]*F(0,0)*pow(F(0,2),2)*F(1,2) + d[32]*F(0,0)*pow(F(0,2),2)*F(1,2) + 2*d[16]*F(0,1)*pow(F(0,2),2)*F(1,2) + d[26]*F(0,1)*pow(F(0,2),2)*F(1,2) + d[14]*pow(F(0,2),3)*F(1,2); c.d[19] = d[0]*F(0,0)*pow(F(1,0),3) + d[30]*F(0,2)*pow(F(1,0),3) + 2*d[3]*F(0,0)*pow(F(1,0),2)*F(1,1) + d[6]*F(0,1)*pow(F(1,0),2)*F(1,1) + 2*d[21]*F(0,1)*pow(F(1,0),2)*F(1,1) + d[24]*F(0,2)*pow(F(1,0),2)*F(1,1) + 2*d[33]*F(0,2)*pow(F(1,0),2)*F(1,1) + d[1]*F(0,0)*F(1,0)*pow(F(1,1),2) + 2*d[21]*F(0,0)*F(1,0)*pow(F(1,1),2) + 2*d[9]*F(0,1)*F(1,0)*pow(F(1,1),2) + d[19]*F(0,1)*F(1,0)*pow(F(1,1),2) + 2*d[27]*F(0,2)*F(1,0)*pow(F(1,1),2) + d[31]*F(0,2)*F(1,0)*pow(F(1,1),2) + d[19]*F(0,0)*pow(F(1,1),3) + d[7]*F(0,1)*pow(F(1,1),3) + d[25]*F(0,2)*pow(F(1,1),3) + d[18]*pow(F(1,0),2)*(F(0,1)*F(1,0) + F(0,0)*F(1,1)) + 2*d[5]*F(0,0)*pow(F(1,0),2)*F(1,2) + d[30]*F(0,0)*pow(F(1,0),2)*F(1,2) + 2*d[23]*F(0,1)*pow(F(1,0),2)*F(1,2) + d[24]*F(0,1)*pow(F(1,0),2)*F(1,2) + d[12]*F(0,2)*pow(F(1,0),2)*F(1,2) + 2*d[35]*F(0,2)*pow(F(1,0),2)*F(1,2) + 2*d[4]*F(0,0)*F(1,0)*F(1,1)*F(1,2) + 2*d[23]*F(0,0)*F(1,0)*F(1,1)*F(1,2) + 2*d[33]*F(0,0)*F(1,0)*F(1,1)*F(1,2) + 2*d[11]*F(0,1)*F(1,0)*F(1,1)*F(1,2) + 2*d[22]*F(0,1)*F(1,0)*F(1,1)*F(1,2) + 2*d[27]*F(0,1)*F(1,0)*F(1,1)*F(1,2) + 2*d[15]*F(0,2)*F(1,0)*F(1,1)*F(1,2) + 2*d[29]*F(0,2)*F(1,0)*F(1,1)*F(1,2) + 2*d[34]*F(0,2)*F(1,0)*F(1,1)*F(1,2) + 2*d[22]*F(0,0)*pow(F(1,1),2)*F(1,2) + d[31]*F(0,0)*pow(F(1,1),2)*F(1,2) + 2*d[10]*F(0,1)*pow(F(1,1),2)*F(1,2) + d[25]*F(0,1)*pow(F(1,1),2)*F(1,2) + d[13]*F(0,2)*pow(F(1,1),2)*F(1,2) + 2*d[28]*F(0,2)*pow(F(1,1),2)*F(1,2) + d[2]*F(0,0)*F(1,0)*pow(F(1,2),2) + 2*d[35]*F(0,0)*F(1,0)*pow(F(1,2),2) + d[20]*F(0,1)*F(1,0)*pow(F(1,2),2) + 2*d[29]*F(0,1)*F(1,0)*pow(F(1,2),2) + 2*d[17]*F(0,2)*F(1,0)*pow(F(1,2),2) + d[32]*F(0,2)*F(1,0)*pow(F(1,2),2) + d[20]*F(0,0)*F(1,1)*pow(F(1,2),2) + 2*d[34]*F(0,0)*F(1,1)*pow(F(1,2),2) + d[8]*F(0,1)*F(1,1)*pow(F(1,2),2) + 2*d[28]*F(0,1)*F(1,1)*pow(F(1,2),2) + 2*d[16]*F(0,2)*F(1,1)*pow(F(1,2),2) + d[26]*F(0,2)*F(1,1)*pow(F(1,2),2) + d[32]*F(0,0)*pow(F(1,2),3) + d[26]*F(0,1)*pow(F(1,2),3) + d[14]*F(0,2)*pow(F(1,2),3); c.d[20] = d[0]*F(0,0)*F(1,0)*pow(F(2,0),2) + d[30]*F(0,2)*F(1,0)*pow(F(2,0),2) + d[6]*F(0,1)*F(1,1)*pow(F(2,0),2) + d[24]*F(0,2)*F(1,1)*pow(F(2,0),2) + d[18]*(F(0,1)*F(1,0) + F(0,0)*F(1,1))*pow(F(2,0),2) + d[30]*F(0,0)*F(1,2)*pow(F(2,0),2) + d[24]*F(0,1)*F(1,2)*pow(F(2,0),2) + d[12]*F(0,2)*F(1,2)*pow(F(2,0),2) + 2*d[3]*F(0,0)*F(1,0)*F(2,0)*F(2,1) + 2*d[21]*F(0,1)*F(1,0)*F(2,0)*F(2,1) + 2*d[33]*F(0,2)*F(1,0)*F(2,0)*F(2,1) + 2*d[21]*F(0,0)*F(1,1)*F(2,0)*F(2,1) + 2*d[9]*F(0,1)*F(1,1)*F(2,0)*F(2,1) + 2*d[27]*F(0,2)*F(1,1)*F(2,0)*F(2,1) + 2*d[33]*F(0,0)*F(1,2)*F(2,0)*F(2,1) + 2*d[27]*F(0,1)*F(1,2)*F(2,0)*F(2,1) + 2*d[15]*F(0,2)*F(1,2)*F(2,0)*F(2,1) + d[1]*F(0,0)*F(1,0)*pow(F(2,1),2) + d[19]*F(0,1)*F(1,0)*pow(F(2,1),2) + d[31]*F(0,2)*F(1,0)*pow(F(2,1),2) + d[19]*F(0,0)*F(1,1)*pow(F(2,1),2) + d[7]*F(0,1)*F(1,1)*pow(F(2,1),2) + d[25]*F(0,2)*F(1,1)*pow(F(2,1),2) + d[31]*F(0,0)*F(1,2)*pow(F(2,1),2) + d[25]*F(0,1)*F(1,2)*pow(F(2,1),2) + d[13]*F(0,2)*F(1,2)*pow(F(2,1),2) + 2*d[5]*F(0,0)*F(1,0)*F(2,0)*F(2,2) + 2*d[23]*F(0,1)*F(1,0)*F(2,0)*F(2,2) + 2*d[35]*F(0,2)*F(1,0)*F(2,0)*F(2,2) + 2*d[23]*F(0,0)*F(1,1)*F(2,0)*F(2,2) + 2*d[11]*F(0,1)*F(1,1)*F(2,0)*F(2,2) + 2*d[29]*F(0,2)*F(1,1)*F(2,0)*F(2,2) + 2*d[35]*F(0,0)*F(1,2)*F(2,0)*F(2,2) + 2*d[29]*F(0,1)*F(1,2)*F(2,0)*F(2,2) + 2*d[17]*F(0,2)*F(1,2)*F(2,0)*F(2,2) + 2*d[4]*F(0,0)*F(1,0)*F(2,1)*F(2,2) + 2*d[22]*F(0,1)*F(1,0)*F(2,1)*F(2,2) + 2*d[34]*F(0,2)*F(1,0)*F(2,1)*F(2,2) + 2*d[22]*F(0,0)*F(1,1)*F(2,1)*F(2,2) + 2*d[10]*F(0,1)*F(1,1)*F(2,1)*F(2,2) + 2*d[28]*F(0,2)*F(1,1)*F(2,1)*F(2,2) + 2*d[34]*F(0,0)*F(1,2)*F(2,1)*F(2,2) + 2*d[28]*F(0,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[16]*F(0,2)*F(1,2)*F(2,1)*F(2,2) + d[2]*F(0,0)*F(1,0)*pow(F(2,2),2) + d[20]*F(0,1)*F(1,0)*pow(F(2,2),2) + d[32]*F(0,2)*F(1,0)*pow(F(2,2),2) + d[20]*F(0,0)*F(1,1)*pow(F(2,2),2) + d[8]*F(0,1)*F(1,1)*pow(F(2,2),2) + d[26]*F(0,2)*F(1,1)*pow(F(2,2),2) + d[32]*F(0,0)*F(1,2)*pow(F(2,2),2) + d[26]*F(0,1)*F(1,2)*pow(F(2,2),2) + d[14]*F(0,2)*F(1,2)*pow(F(2,2),2); c.d[21] = d[0]*pow(F(0,0),2)*pow(F(1,0),2) + d[18]*F(0,0)*F(0,1)*pow(F(1,0),2) + d[21]*pow(F(0,1),2)*pow(F(1,0),2) + d[5]*F(0,0)*F(0,2)*pow(F(1,0),2) + d[30]*F(0,0)*F(0,2)*pow(F(1,0),2) + d[23]*F(0,1)*F(0,2)*pow(F(1,0),2) + d[33]*F(0,1)*F(0,2)*pow(F(1,0),2) + d[35]*pow(F(0,2),2)*pow(F(1,0),2) + d[18]*pow(F(0,0),2)*F(1,0)*F(1,1) + d[1]*F(0,0)*F(0,1)*F(1,0)*F(1,1) + d[6]*F(0,0)*F(0,1)*F(1,0)*F(1,1) + 2*d[21]*F(0,0)*F(0,1)*F(1,0)*F(1,1) + d[9]*pow(F(0,1),2)*F(1,0)*F(1,1) + d[19]*pow(F(0,1),2)*F(1,0)*F(1,1) + d[4]*F(0,0)*F(0,2)*F(1,0)*F(1,1) + d[23]*F(0,0)*F(0,2)*F(1,0)*F(1,1) + d[24]*F(0,0)*F(0,2)*F(1,0)*F(1,1) + d[33]*F(0,0)*F(0,2)*F(1,0)*F(1,1) + d[11]*F(0,1)*F(0,2)*F(1,0)*F(1,1) + d[22]*F(0,1)*F(0,2)*F(1,0)*F(1,1) + d[27]*F(0,1)*F(0,2)*F(1,0)*F(1,1) + d[31]*F(0,1)*F(0,2)*F(1,0)*F(1,1) + d[29]*pow(F(0,2),2)*F(1,0)*F(1,1) + d[34]*pow(F(0,2),2)*F(1,0)*F(1,1) + d[21]*pow(F(0,0),2)*pow(F(1,1),2) + d[9]*F(0,0)*F(0,1)*pow(F(1,1),2) + d[19]*F(0,0)*F(0,1)*pow(F(1,1),2) + d[7]*pow(F(0,1),2)*pow(F(1,1),2) + d[22]*F(0,0)*F(0,2)*pow(F(1,1),2) + d[27]*F(0,0)*F(0,2)*pow(F(1,1),2) + d[10]*F(0,1)*F(0,2)*pow(F(1,1),2) + d[25]*F(0,1)*F(0,2)*pow(F(1,1),2) + d[28]*pow(F(0,2),2)*pow(F(1,1),2) + d[3]*F(0,0)*F(1,0)*(F(0,1)*F(1,0) + F(0,0)*F(1,1)) + d[5]*pow(F(0,0),2)*F(1,0)*F(1,2) + d[30]*pow(F(0,0),2)*F(1,0)*F(1,2) + d[4]*F(0,0)*F(0,1)*F(1,0)*F(1,2) + d[23]*F(0,0)*F(0,1)*F(1,0)*F(1,2) + d[24]*F(0,0)*F(0,1)*F(1,0)*F(1,2) + d[33]*F(0,0)*F(0,1)*F(1,0)*F(1,2) + d[22]*pow(F(0,1),2)*F(1,0)*F(1,2) + d[27]*pow(F(0,1),2)*F(1,0)*F(1,2) + d[2]*F(0,0)*F(0,2)*F(1,0)*F(1,2) + d[12]*F(0,0)*F(0,2)*F(1,0)*F(1,2) + 2*d[35]*F(0,0)*F(0,2)*F(1,0)*F(1,2) + d[15]*F(0,1)*F(0,2)*F(1,0)*F(1,2) + d[20]*F(0,1)*F(0,2)*F(1,0)*F(1,2) + d[29]*F(0,1)*F(0,2)*F(1,0)*F(1,2) + d[34]*F(0,1)*F(0,2)*F(1,0)*F(1,2) + d[17]*pow(F(0,2),2)*F(1,0)*F(1,2) + d[32]*pow(F(0,2),2)*F(1,0)*F(1,2) + d[23]*pow(F(0,0),2)*F(1,1)*F(1,2) + d[33]*pow(F(0,0),2)*F(1,1)*F(1,2) + d[11]*F(0,0)*F(0,1)*F(1,1)*F(1,2) + d[22]*F(0,0)*F(0,1)*F(1,1)*F(1,2) + d[27]*F(0,0)*F(0,1)*F(1,1)*F(1,2) + d[31]*F(0,0)*F(0,1)*F(1,1)*F(1,2) + d[10]*pow(F(0,1),2)*F(1,1)*F(1,2) + d[25]*pow(F(0,1),2)*F(1,1)*F(1,2) + d[15]*F(0,0)*F(0,2)*F(1,1)*F(1,2) + d[20]*F(0,0)*F(0,2)*F(1,1)*F(1,2) + d[29]*F(0,0)*F(0,2)*F(1,1)*F(1,2) + d[34]*F(0,0)*F(0,2)*F(1,1)*F(1,2) + d[8]*F(0,1)*F(0,2)*F(1,1)*F(1,2) + d[13]*F(0,1)*F(0,2)*F(1,1)*F(1,2) + 2*d[28]*F(0,1)*F(0,2)*F(1,1)*F(1,2) + d[16]*pow(F(0,2),2)*F(1,1)*F(1,2) + d[26]*pow(F(0,2),2)*F(1,1)*F(1,2) + d[35]*pow(F(0,0),2)*pow(F(1,2),2) + d[29]*F(0,0)*F(0,1)*pow(F(1,2),2) + d[34]*F(0,0)*F(0,1)*pow(F(1,2),2) + d[28]*pow(F(0,1),2)*pow(F(1,2),2) + d[17]*F(0,0)*F(0,2)*pow(F(1,2),2) + d[32]*F(0,0)*F(0,2)*pow(F(1,2),2) + d[16]*F(0,1)*F(0,2)*pow(F(1,2),2) + d[26]*F(0,1)*F(0,2)*pow(F(1,2),2) + d[14]*pow(F(0,2),2)*pow(F(1,2),2); c.d[22] = d[0]*F(0,0)*pow(F(1,0),2)*F(2,0) + d[30]*F(0,2)*pow(F(1,0),2)*F(2,0) + d[3]*F(0,0)*F(1,0)*F(1,1)*F(2,0) + d[6]*F(0,1)*F(1,0)*F(1,1)*F(2,0) + d[21]*F(0,1)*F(1,0)*F(1,1)*F(2,0) + d[24]*F(0,2)*F(1,0)*F(1,1)*F(2,0) + d[33]*F(0,2)*F(1,0)*F(1,1)*F(2,0) + d[21]*F(0,0)*pow(F(1,1),2)*F(2,0) + d[9]*F(0,1)*pow(F(1,1),2)*F(2,0) + d[27]*F(0,2)*pow(F(1,1),2)*F(2,0) + d[18]*F(1,0)*(F(0,1)*F(1,0) + F(0,0)*F(1,1))*F(2,0) + d[5]*F(0,0)*F(1,0)*F(1,2)*F(2,0) + d[30]*F(0,0)*F(1,0)*F(1,2)*F(2,0) + d[23]*F(0,1)*F(1,0)*F(1,2)*F(2,0) + d[24]*F(0,1)*F(1,0)*F(1,2)*F(2,0) + d[12]*F(0,2)*F(1,0)*F(1,2)*F(2,0) + d[35]*F(0,2)*F(1,0)*F(1,2)*F(2,0) + d[23]*F(0,0)*F(1,1)*F(1,2)*F(2,0) + d[33]*F(0,0)*F(1,1)*F(1,2)*F(2,0) + d[11]*F(0,1)*F(1,1)*F(1,2)*F(2,0) + d[27]*F(0,1)*F(1,1)*F(1,2)*F(2,0) + d[15]*F(0,2)*F(1,1)*F(1,2)*F(2,0) + d[29]*F(0,2)*F(1,1)*F(1,2)*F(2,0) + d[35]*F(0,0)*pow(F(1,2),2)*F(2,0) + d[29]*F(0,1)*pow(F(1,2),2)*F(2,0) + d[17]*F(0,2)*pow(F(1,2),2)*F(2,0) + d[3]*F(0,0)*pow(F(1,0),2)*F(2,1) + d[21]*F(0,1)*pow(F(1,0),2)*F(2,1) + d[33]*F(0,2)*pow(F(1,0),2)*F(2,1) + d[1]*F(0,0)*F(1,0)*F(1,1)*F(2,1) + d[21]*F(0,0)*F(1,0)*F(1,1)*F(2,1) + d[9]*F(0,1)*F(1,0)*F(1,1)*F(2,1) + d[19]*F(0,1)*F(1,0)*F(1,1)*F(2,1) + d[27]*F(0,2)*F(1,0)*F(1,1)*F(2,1) + d[31]*F(0,2)*F(1,0)*F(1,1)*F(2,1) + d[19]*F(0,0)*pow(F(1,1),2)*F(2,1) + d[7]*F(0,1)*pow(F(1,1),2)*F(2,1) + d[25]*F(0,2)*pow(F(1,1),2)*F(2,1) + d[4]*F(0,0)*F(1,0)*F(1,2)*F(2,1) + d[33]*F(0,0)*F(1,0)*F(1,2)*F(2,1) + d[22]*F(0,1)*F(1,0)*F(1,2)*F(2,1) + d[27]*F(0,1)*F(1,0)*F(1,2)*F(2,1) + d[15]*F(0,2)*F(1,0)*F(1,2)*F(2,1) + d[34]*F(0,2)*F(1,0)*F(1,2)*F(2,1) + d[22]*F(0,0)*F(1,1)*F(1,2)*F(2,1) + d[31]*F(0,0)*F(1,1)*F(1,2)*F(2,1) + d[10]*F(0,1)*F(1,1)*F(1,2)*F(2,1) + d[25]*F(0,1)*F(1,1)*F(1,2)*F(2,1) + d[13]*F(0,2)*F(1,1)*F(1,2)*F(2,1) + d[28]*F(0,2)*F(1,1)*F(1,2)*F(2,1) + d[34]*F(0,0)*pow(F(1,2),2)*F(2,1) + d[28]*F(0,1)*pow(F(1,2),2)*F(2,1) + d[16]*F(0,2)*pow(F(1,2),2)*F(2,1) + d[5]*F(0,0)*pow(F(1,0),2)*F(2,2) + d[23]*F(0,1)*pow(F(1,0),2)*F(2,2) + d[35]*F(0,2)*pow(F(1,0),2)*F(2,2) + d[4]*F(0,0)*F(1,0)*F(1,1)*F(2,2) + d[23]*F(0,0)*F(1,0)*F(1,1)*F(2,2) + d[11]*F(0,1)*F(1,0)*F(1,1)*F(2,2) + d[22]*F(0,1)*F(1,0)*F(1,1)*F(2,2) + d[29]*F(0,2)*F(1,0)*F(1,1)*F(2,2) + d[34]*F(0,2)*F(1,0)*F(1,1)*F(2,2) + d[22]*F(0,0)*pow(F(1,1),2)*F(2,2) + d[10]*F(0,1)*pow(F(1,1),2)*F(2,2) + d[28]*F(0,2)*pow(F(1,1),2)*F(2,2) + d[2]*F(0,0)*F(1,0)*F(1,2)*F(2,2) + d[35]*F(0,0)*F(1,0)*F(1,2)*F(2,2) + d[20]*F(0,1)*F(1,0)*F(1,2)*F(2,2) + d[29]*F(0,1)*F(1,0)*F(1,2)*F(2,2) + d[17]*F(0,2)*F(1,0)*F(1,2)*F(2,2) + d[32]*F(0,2)*F(1,0)*F(1,2)*F(2,2) + d[20]*F(0,0)*F(1,1)*F(1,2)*F(2,2) + d[34]*F(0,0)*F(1,1)*F(1,2)*F(2,2) + d[8]*F(0,1)*F(1,1)*F(1,2)*F(2,2) + d[28]*F(0,1)*F(1,1)*F(1,2)*F(2,2) + d[16]*F(0,2)*F(1,1)*F(1,2)*F(2,2) + d[26]*F(0,2)*F(1,1)*F(1,2)*F(2,2) + d[32]*F(0,0)*pow(F(1,2),2)*F(2,2) + d[26]*F(0,1)*pow(F(1,2),2)*F(2,2) + d[14]*F(0,2)*pow(F(1,2),2)*F(2,2); c.d[23] = d[0]*pow(F(0,0),2)*F(1,0)*F(2,0) + d[18]*F(0,0)*F(0,1)*F(1,0)*F(2,0) + d[21]*pow(F(0,1),2)*F(1,0)*F(2,0) + d[5]*F(0,0)*F(0,2)*F(1,0)*F(2,0) + d[30]*F(0,0)*F(0,2)*F(1,0)*F(2,0) + d[23]*F(0,1)*F(0,2)*F(1,0)*F(2,0) + d[33]*F(0,1)*F(0,2)*F(1,0)*F(2,0) + d[35]*pow(F(0,2),2)*F(1,0)*F(2,0) + d[18]*pow(F(0,0),2)*F(1,1)*F(2,0) + d[6]*F(0,0)*F(0,1)*F(1,1)*F(2,0) + d[21]*F(0,0)*F(0,1)*F(1,1)*F(2,0) + d[9]*pow(F(0,1),2)*F(1,1)*F(2,0) + d[23]*F(0,0)*F(0,2)*F(1,1)*F(2,0) + d[24]*F(0,0)*F(0,2)*F(1,1)*F(2,0) + d[11]*F(0,1)*F(0,2)*F(1,1)*F(2,0) + d[27]*F(0,1)*F(0,2)*F(1,1)*F(2,0) + d[29]*pow(F(0,2),2)*F(1,1)*F(2,0) + d[30]*pow(F(0,0),2)*F(1,2)*F(2,0) + d[24]*F(0,0)*F(0,1)*F(1,2)*F(2,0) + d[33]*F(0,0)*F(0,1)*F(1,2)*F(2,0) + d[27]*pow(F(0,1),2)*F(1,2)*F(2,0) + d[12]*F(0,0)*F(0,2)*F(1,2)*F(2,0) + d[35]*F(0,0)*F(0,2)*F(1,2)*F(2,0) + d[15]*F(0,1)*F(0,2)*F(1,2)*F(2,0) + d[29]*F(0,1)*F(0,2)*F(1,2)*F(2,0) + d[17]*pow(F(0,2),2)*F(1,2)*F(2,0) + d[1]*F(0,0)*F(0,1)*F(1,0)*F(2,1) + d[21]*F(0,0)*F(0,1)*F(1,0)*F(2,1) + d[19]*pow(F(0,1),2)*F(1,0)*F(2,1) + d[4]*F(0,0)*F(0,2)*F(1,0)*F(2,1) + d[33]*F(0,0)*F(0,2)*F(1,0)*F(2,1) + d[22]*F(0,1)*F(0,2)*F(1,0)*F(2,1) + d[31]*F(0,1)*F(0,2)*F(1,0)*F(2,1) + d[34]*pow(F(0,2),2)*F(1,0)*F(2,1) + d[21]*pow(F(0,0),2)*F(1,1)*F(2,1) + d[9]*F(0,0)*F(0,1)*F(1,1)*F(2,1) + d[19]*F(0,0)*F(0,1)*F(1,1)*F(2,1) + d[7]*pow(F(0,1),2)*F(1,1)*F(2,1) + d[22]*F(0,0)*F(0,2)*F(1,1)*F(2,1) + d[27]*F(0,0)*F(0,2)*F(1,1)*F(2,1) + d[10]*F(0,1)*F(0,2)*F(1,1)*F(2,1) + d[25]*F(0,1)*F(0,2)*F(1,1)*F(2,1) + d[28]*pow(F(0,2),2)*F(1,1)*F(2,1) + d[33]*pow(F(0,0),2)*F(1,2)*F(2,1) + d[27]*F(0,0)*F(0,1)*F(1,2)*F(2,1) + d[31]*F(0,0)*F(0,1)*F(1,2)*F(2,1) + d[25]*pow(F(0,1),2)*F(1,2)*F(2,1) + d[15]*F(0,0)*F(0,2)*F(1,2)*F(2,1) + d[34]*F(0,0)*F(0,2)*F(1,2)*F(2,1) + d[13]*F(0,1)*F(0,2)*F(1,2)*F(2,1) + d[28]*F(0,1)*F(0,2)*F(1,2)*F(2,1) + d[16]*pow(F(0,2),2)*F(1,2)*F(2,1) + d[3]*F(0,0)*F(1,0)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + d[5]*pow(F(0,0),2)*F(1,0)*F(2,2) + d[4]*F(0,0)*F(0,1)*F(1,0)*F(2,2) + d[23]*F(0,0)*F(0,1)*F(1,0)*F(2,2) + d[22]*pow(F(0,1),2)*F(1,0)*F(2,2) + d[2]*F(0,0)*F(0,2)*F(1,0)*F(2,2) + d[35]*F(0,0)*F(0,2)*F(1,0)*F(2,2) + d[20]*F(0,1)*F(0,2)*F(1,0)*F(2,2) + d[34]*F(0,1)*F(0,2)*F(1,0)*F(2,2) + d[32]*pow(F(0,2),2)*F(1,0)*F(2,2) + d[23]*pow(F(0,0),2)*F(1,1)*F(2,2) + d[11]*F(0,0)*F(0,1)*F(1,1)*F(2,2) + d[22]*F(0,0)*F(0,1)*F(1,1)*F(2,2) + d[10]*pow(F(0,1),2)*F(1,1)*F(2,2) + d[20]*F(0,0)*F(0,2)*F(1,1)*F(2,2) + d[29]*F(0,0)*F(0,2)*F(1,1)*F(2,2) + d[8]*F(0,1)*F(0,2)*F(1,1)*F(2,2) + d[28]*F(0,1)*F(0,2)*F(1,1)*F(2,2) + d[26]*pow(F(0,2),2)*F(1,1)*F(2,2) + d[35]*pow(F(0,0),2)*F(1,2)*F(2,2) + d[29]*F(0,0)*F(0,1)*F(1,2)*F(2,2) + d[34]*F(0,0)*F(0,1)*F(1,2)*F(2,2) + d[28]*pow(F(0,1),2)*F(1,2)*F(2,2) + d[17]*F(0,0)*F(0,2)*F(1,2)*F(2,2) + d[32]*F(0,0)*F(0,2)*F(1,2)*F(2,2) + d[16]*F(0,1)*F(0,2)*F(1,2)*F(2,2) + d[26]*F(0,1)*F(0,2)*F(1,2)*F(2,2) + d[14]*pow(F(0,2),2)*F(1,2)*F(2,2); c.d[24] = d[0]*pow(F(0,0),2)*F(1,0)*F(2,0) + 2*d[3]*F(0,0)*F(0,1)*F(1,0)*F(2,0) + d[1]*pow(F(0,1),2)*F(1,0)*F(2,0) + 2*d[5]*F(0,0)*F(0,2)*F(1,0)*F(2,0) + 2*d[4]*F(0,1)*F(0,2)*F(1,0)*F(2,0) + d[2]*pow(F(0,2),2)*F(1,0)*F(2,0) + d[18]*pow(F(0,0),2)*F(1,1)*F(2,0) + 2*d[21]*F(0,0)*F(0,1)*F(1,1)*F(2,0) + d[19]*pow(F(0,1),2)*F(1,1)*F(2,0) + 2*d[23]*F(0,0)*F(0,2)*F(1,1)*F(2,0) + 2*d[22]*F(0,1)*F(0,2)*F(1,1)*F(2,0) + d[20]*pow(F(0,2),2)*F(1,1)*F(2,0) + d[30]*pow(F(0,0),2)*F(1,2)*F(2,0) + 2*d[33]*F(0,0)*F(0,1)*F(1,2)*F(2,0) + d[31]*pow(F(0,1),2)*F(1,2)*F(2,0) + 2*d[35]*F(0,0)*F(0,2)*F(1,2)*F(2,0) + 2*d[34]*F(0,1)*F(0,2)*F(1,2)*F(2,0) + d[32]*pow(F(0,2),2)*F(1,2)*F(2,0) + d[18]*pow(F(0,0),2)*F(1,0)*F(2,1) + 2*d[21]*F(0,0)*F(0,1)*F(1,0)*F(2,1) + d[19]*pow(F(0,1),2)*F(1,0)*F(2,1) + 2*d[23]*F(0,0)*F(0,2)*F(1,0)*F(2,1) + 2*d[22]*F(0,1)*F(0,2)*F(1,0)*F(2,1) + d[20]*pow(F(0,2),2)*F(1,0)*F(2,1) + d[6]*pow(F(0,0),2)*F(1,1)*F(2,1) + 2*d[9]*F(0,0)*F(0,1)*F(1,1)*F(2,1) + d[7]*pow(F(0,1),2)*F(1,1)*F(2,1) + 2*d[11]*F(0,0)*F(0,2)*F(1,1)*F(2,1) + 2*d[10]*F(0,1)*F(0,2)*F(1,1)*F(2,1) + d[8]*pow(F(0,2),2)*F(1,1)*F(2,1) + d[24]*pow(F(0,0),2)*F(1,2)*F(2,1) + 2*d[27]*F(0,0)*F(0,1)*F(1,2)*F(2,1) + d[25]*pow(F(0,1),2)*F(1,2)*F(2,1) + 2*d[29]*F(0,0)*F(0,2)*F(1,2)*F(2,1) + 2*d[28]*F(0,1)*F(0,2)*F(1,2)*F(2,1) + d[26]*pow(F(0,2),2)*F(1,2)*F(2,1) + d[30]*pow(F(0,0),2)*F(1,0)*F(2,2) + 2*d[33]*F(0,0)*F(0,1)*F(1,0)*F(2,2) + d[31]*pow(F(0,1),2)*F(1,0)*F(2,2) + 2*d[35]*F(0,0)*F(0,2)*F(1,0)*F(2,2) + 2*d[34]*F(0,1)*F(0,2)*F(1,0)*F(2,2) + d[32]*pow(F(0,2),2)*F(1,0)*F(2,2) + d[24]*pow(F(0,0),2)*F(1,1)*F(2,2) + 2*d[27]*F(0,0)*F(0,1)*F(1,1)*F(2,2) + d[25]*pow(F(0,1),2)*F(1,1)*F(2,2) + 2*d[29]*F(0,0)*F(0,2)*F(1,1)*F(2,2) + 2*d[28]*F(0,1)*F(0,2)*F(1,1)*F(2,2) + d[26]*pow(F(0,2),2)*F(1,1)*F(2,2) + d[12]*pow(F(0,0),2)*F(1,2)*F(2,2) + 2*d[15]*F(0,0)*F(0,1)*F(1,2)*F(2,2) + d[13]*pow(F(0,1),2)*F(1,2)*F(2,2) + 2*d[17]*F(0,0)*F(0,2)*F(1,2)*F(2,2) + 2*d[16]*F(0,1)*F(0,2)*F(1,2)*F(2,2) + d[14]*pow(F(0,2),2)*F(1,2)*F(2,2); c.d[25] = d[0]*pow(F(1,0),3)*F(2,0) + 2*d[3]*pow(F(1,0),2)*F(1,1)*F(2,0) + d[18]*pow(F(1,0),2)*F(1,1)*F(2,0) + d[1]*F(1,0)*pow(F(1,1),2)*F(2,0) + 2*d[21]*F(1,0)*pow(F(1,1),2)*F(2,0) + d[19]*pow(F(1,1),3)*F(2,0) + 2*d[5]*pow(F(1,0),2)*F(1,2)*F(2,0) + d[30]*pow(F(1,0),2)*F(1,2)*F(2,0) + 2*d[4]*F(1,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[23]*F(1,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[33]*F(1,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[22]*pow(F(1,1),2)*F(1,2)*F(2,0) + d[31]*pow(F(1,1),2)*F(1,2)*F(2,0) + d[2]*F(1,0)*pow(F(1,2),2)*F(2,0) + 2*d[35]*F(1,0)*pow(F(1,2),2)*F(2,0) + d[20]*F(1,1)*pow(F(1,2),2)*F(2,0) + 2*d[34]*F(1,1)*pow(F(1,2),2)*F(2,0) + d[32]*pow(F(1,2),3)*F(2,0) + d[18]*pow(F(1,0),3)*F(2,1) + d[6]*pow(F(1,0),2)*F(1,1)*F(2,1) + 2*d[21]*pow(F(1,0),2)*F(1,1)*F(2,1) + 2*d[9]*F(1,0)*pow(F(1,1),2)*F(2,1) + d[19]*F(1,0)*pow(F(1,1),2)*F(2,1) + d[7]*pow(F(1,1),3)*F(2,1) + 2*d[23]*pow(F(1,0),2)*F(1,2)*F(2,1) + d[24]*pow(F(1,0),2)*F(1,2)*F(2,1) + 2*d[11]*F(1,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[22]*F(1,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[27]*F(1,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[10]*pow(F(1,1),2)*F(1,2)*F(2,1) + d[25]*pow(F(1,1),2)*F(1,2)*F(2,1) + d[20]*F(1,0)*pow(F(1,2),2)*F(2,1) + 2*d[29]*F(1,0)*pow(F(1,2),2)*F(2,1) + d[8]*F(1,1)*pow(F(1,2),2)*F(2,1) + 2*d[28]*F(1,1)*pow(F(1,2),2)*F(2,1) + d[26]*pow(F(1,2),3)*F(2,1) + d[30]*pow(F(1,0),3)*F(2,2) + d[24]*pow(F(1,0),2)*F(1,1)*F(2,2) + 2*d[33]*pow(F(1,0),2)*F(1,1)*F(2,2) + 2*d[27]*F(1,0)*pow(F(1,1),2)*F(2,2) + d[31]*F(1,0)*pow(F(1,1),2)*F(2,2) + d[25]*pow(F(1,1),3)*F(2,2) + d[12]*pow(F(1,0),2)*F(1,2)*F(2,2) + 2*d[35]*pow(F(1,0),2)*F(1,2)*F(2,2) + 2*d[15]*F(1,0)*F(1,1)*F(1,2)*F(2,2) + 2*d[29]*F(1,0)*F(1,1)*F(1,2)*F(2,2) + 2*d[34]*F(1,0)*F(1,1)*F(1,2)*F(2,2) + d[13]*pow(F(1,1),2)*F(1,2)*F(2,2) + 2*d[28]*pow(F(1,1),2)*F(1,2)*F(2,2) + 2*d[17]*F(1,0)*pow(F(1,2),2)*F(2,2) + d[32]*F(1,0)*pow(F(1,2),2)*F(2,2) + 2*d[16]*F(1,1)*pow(F(1,2),2)*F(2,2) + d[26]*F(1,1)*pow(F(1,2),2)*F(2,2) + d[14]*pow(F(1,2),3)*F(2,2); c.d[26] = d[0]*F(1,0)*pow(F(2,0),3) + d[30]*F(1,2)*pow(F(2,0),3) + 2*d[3]*F(1,0)*pow(F(2,0),2)*F(2,1) + d[6]*F(1,1)*pow(F(2,0),2)*F(2,1) + 2*d[21]*F(1,1)*pow(F(2,0),2)*F(2,1) + d[24]*F(1,2)*pow(F(2,0),2)*F(2,1) + 2*d[33]*F(1,2)*pow(F(2,0),2)*F(2,1) + d[1]*F(1,0)*F(2,0)*pow(F(2,1),2) + 2*d[21]*F(1,0)*F(2,0)*pow(F(2,1),2) + 2*d[9]*F(1,1)*F(2,0)*pow(F(2,1),2) + d[19]*F(1,1)*F(2,0)*pow(F(2,1),2) + 2*d[27]*F(1,2)*F(2,0)*pow(F(2,1),2) + d[31]*F(1,2)*F(2,0)*pow(F(2,1),2) + d[19]*F(1,0)*pow(F(2,1),3) + d[7]*F(1,1)*pow(F(2,1),3) + d[25]*F(1,2)*pow(F(2,1),3) + d[18]*pow(F(2,0),2)*(F(1,1)*F(2,0) + F(1,0)*F(2,1)) + 2*d[5]*F(1,0)*pow(F(2,0),2)*F(2,2) + d[30]*F(1,0)*pow(F(2,0),2)*F(2,2) + 2*d[23]*F(1,1)*pow(F(2,0),2)*F(2,2) + d[24]*F(1,1)*pow(F(2,0),2)*F(2,2) + d[12]*F(1,2)*pow(F(2,0),2)*F(2,2) + 2*d[35]*F(1,2)*pow(F(2,0),2)*F(2,2) + 2*d[4]*F(1,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[23]*F(1,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[33]*F(1,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[11]*F(1,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[22]*F(1,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[27]*F(1,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[15]*F(1,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[29]*F(1,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[34]*F(1,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[22]*F(1,0)*pow(F(2,1),2)*F(2,2) + d[31]*F(1,0)*pow(F(2,1),2)*F(2,2) + 2*d[10]*F(1,1)*pow(F(2,1),2)*F(2,2) + d[25]*F(1,1)*pow(F(2,1),2)*F(2,2) + d[13]*F(1,2)*pow(F(2,1),2)*F(2,2) + 2*d[28]*F(1,2)*pow(F(2,1),2)*F(2,2) + d[2]*F(1,0)*F(2,0)*pow(F(2,2),2) + 2*d[35]*F(1,0)*F(2,0)*pow(F(2,2),2) + d[20]*F(1,1)*F(2,0)*pow(F(2,2),2) + 2*d[29]*F(1,1)*F(2,0)*pow(F(2,2),2) + 2*d[17]*F(1,2)*F(2,0)*pow(F(2,2),2) + d[32]*F(1,2)*F(2,0)*pow(F(2,2),2) + d[20]*F(1,0)*F(2,1)*pow(F(2,2),2) + 2*d[34]*F(1,0)*F(2,1)*pow(F(2,2),2) + d[8]*F(1,1)*F(2,1)*pow(F(2,2),2) + 2*d[28]*F(1,1)*F(2,1)*pow(F(2,2),2) + 2*d[16]*F(1,2)*F(2,1)*pow(F(2,2),2) + d[26]*F(1,2)*F(2,1)*pow(F(2,2),2) + d[32]*F(1,0)*pow(F(2,2),3) + d[26]*F(1,1)*pow(F(2,2),3) + d[14]*F(1,2)*pow(F(2,2),3); c.d[27] = d[0]*F(0,0)*pow(F(1,0),2)*F(2,0) + d[5]*F(0,2)*pow(F(1,0),2)*F(2,0) + d[18]*F(0,0)*F(1,0)*F(1,1)*F(2,0) + d[1]*F(0,1)*F(1,0)*F(1,1)*F(2,0) + d[21]*F(0,1)*F(1,0)*F(1,1)*F(2,0) + d[4]*F(0,2)*F(1,0)*F(1,1)*F(2,0) + d[23]*F(0,2)*F(1,0)*F(1,1)*F(2,0) + d[21]*F(0,0)*pow(F(1,1),2)*F(2,0) + d[19]*F(0,1)*pow(F(1,1),2)*F(2,0) + d[22]*F(0,2)*pow(F(1,1),2)*F(2,0) + d[3]*F(1,0)*(F(0,1)*F(1,0) + F(0,0)*F(1,1))*F(2,0) + d[5]*F(0,0)*F(1,0)*F(1,2)*F(2,0) + d[30]*F(0,0)*F(1,0)*F(1,2)*F(2,0) + d[4]*F(0,1)*F(1,0)*F(1,2)*F(2,0) + d[33]*F(0,1)*F(1,0)*F(1,2)*F(2,0) + d[2]*F(0,2)*F(1,0)*F(1,2)*F(2,0) + d[35]*F(0,2)*F(1,0)*F(1,2)*F(2,0) + d[23]*F(0,0)*F(1,1)*F(1,2)*F(2,0) + d[33]*F(0,0)*F(1,1)*F(1,2)*F(2,0) + d[22]*F(0,1)*F(1,1)*F(1,2)*F(2,0) + d[31]*F(0,1)*F(1,1)*F(1,2)*F(2,0) + d[20]*F(0,2)*F(1,1)*F(1,2)*F(2,0) + d[34]*F(0,2)*F(1,1)*F(1,2)*F(2,0) + d[35]*F(0,0)*pow(F(1,2),2)*F(2,0) + d[34]*F(0,1)*pow(F(1,2),2)*F(2,0) + d[32]*F(0,2)*pow(F(1,2),2)*F(2,0) + d[18]*F(0,0)*pow(F(1,0),2)*F(2,1) + d[21]*F(0,1)*pow(F(1,0),2)*F(2,1) + d[23]*F(0,2)*pow(F(1,0),2)*F(2,1) + d[6]*F(0,0)*F(1,0)*F(1,1)*F(2,1) + d[21]*F(0,0)*F(1,0)*F(1,1)*F(2,1) + d[9]*F(0,1)*F(1,0)*F(1,1)*F(2,1) + d[19]*F(0,1)*F(1,0)*F(1,1)*F(2,1) + d[11]*F(0,2)*F(1,0)*F(1,1)*F(2,1) + d[22]*F(0,2)*F(1,0)*F(1,1)*F(2,1) + d[9]*F(0,0)*pow(F(1,1),2)*F(2,1) + d[7]*F(0,1)*pow(F(1,1),2)*F(2,1) + d[10]*F(0,2)*pow(F(1,1),2)*F(2,1) + d[23]*F(0,0)*F(1,0)*F(1,2)*F(2,1) + d[24]*F(0,0)*F(1,0)*F(1,2)*F(2,1) + d[22]*F(0,1)*F(1,0)*F(1,2)*F(2,1) + d[27]*F(0,1)*F(1,0)*F(1,2)*F(2,1) + d[20]*F(0,2)*F(1,0)*F(1,2)*F(2,1) + d[29]*F(0,2)*F(1,0)*F(1,2)*F(2,1) + d[11]*F(0,0)*F(1,1)*F(1,2)*F(2,1) + d[27]*F(0,0)*F(1,1)*F(1,2)*F(2,1) + d[10]*F(0,1)*F(1,1)*F(1,2)*F(2,1) + d[25]*F(0,1)*F(1,1)*F(1,2)*F(2,1) + d[8]*F(0,2)*F(1,1)*F(1,2)*F(2,1) + d[28]*F(0,2)*F(1,1)*F(1,2)*F(2,1) + d[29]*F(0,0)*pow(F(1,2),2)*F(2,1) + d[28]*F(0,1)*pow(F(1,2),2)*F(2,1) + d[26]*F(0,2)*pow(F(1,2),2)*F(2,1) + d[30]*F(0,0)*pow(F(1,0),2)*F(2,2) + d[33]*F(0,1)*pow(F(1,0),2)*F(2,2) + d[35]*F(0,2)*pow(F(1,0),2)*F(2,2) + d[24]*F(0,0)*F(1,0)*F(1,1)*F(2,2) + d[33]*F(0,0)*F(1,0)*F(1,1)*F(2,2) + d[27]*F(0,1)*F(1,0)*F(1,1)*F(2,2) + d[31]*F(0,1)*F(1,0)*F(1,1)*F(2,2) + d[29]*F(0,2)*F(1,0)*F(1,1)*F(2,2) + d[34]*F(0,2)*F(1,0)*F(1,1)*F(2,2) + d[27]*F(0,0)*pow(F(1,1),2)*F(2,2) + d[25]*F(0,1)*pow(F(1,1),2)*F(2,2) + d[28]*F(0,2)*pow(F(1,1),2)*F(2,2) + d[12]*F(0,0)*F(1,0)*F(1,2)*F(2,2) + d[35]*F(0,0)*F(1,0)*F(1,2)*F(2,2) + d[15]*F(0,1)*F(1,0)*F(1,2)*F(2,2) + d[34]*F(0,1)*F(1,0)*F(1,2)*F(2,2) + d[17]*F(0,2)*F(1,0)*F(1,2)*F(2,2) + d[32]*F(0,2)*F(1,0)*F(1,2)*F(2,2) + d[15]*F(0,0)*F(1,1)*F(1,2)*F(2,2) + d[29]*F(0,0)*F(1,1)*F(1,2)*F(2,2) + d[13]*F(0,1)*F(1,1)*F(1,2)*F(2,2) + d[28]*F(0,1)*F(1,1)*F(1,2)*F(2,2) + d[16]*F(0,2)*F(1,1)*F(1,2)*F(2,2) + d[26]*F(0,2)*F(1,1)*F(1,2)*F(2,2) + d[17]*F(0,0)*pow(F(1,2),2)*F(2,2) + d[16]*F(0,1)*pow(F(1,2),2)*F(2,2) + d[14]*F(0,2)*pow(F(1,2),2)*F(2,2); c.d[28] = d[0]*pow(F(1,0),2)*pow(F(2,0),2) + d[18]*F(1,0)*F(1,1)*pow(F(2,0),2) + d[21]*pow(F(1,1),2)*pow(F(2,0),2) + d[5]*F(1,0)*F(1,2)*pow(F(2,0),2) + d[30]*F(1,0)*F(1,2)*pow(F(2,0),2) + d[23]*F(1,1)*F(1,2)*pow(F(2,0),2) + d[33]*F(1,1)*F(1,2)*pow(F(2,0),2) + d[35]*pow(F(1,2),2)*pow(F(2,0),2) + d[18]*pow(F(1,0),2)*F(2,0)*F(2,1) + d[1]*F(1,0)*F(1,1)*F(2,0)*F(2,1) + d[6]*F(1,0)*F(1,1)*F(2,0)*F(2,1) + 2*d[21]*F(1,0)*F(1,1)*F(2,0)*F(2,1) + d[9]*pow(F(1,1),2)*F(2,0)*F(2,1) + d[19]*pow(F(1,1),2)*F(2,0)*F(2,1) + d[4]*F(1,0)*F(1,2)*F(2,0)*F(2,1) + d[23]*F(1,0)*F(1,2)*F(2,0)*F(2,1) + d[24]*F(1,0)*F(1,2)*F(2,0)*F(2,1) + d[33]*F(1,0)*F(1,2)*F(2,0)*F(2,1) + d[11]*F(1,1)*F(1,2)*F(2,0)*F(2,1) + d[22]*F(1,1)*F(1,2)*F(2,0)*F(2,1) + d[27]*F(1,1)*F(1,2)*F(2,0)*F(2,1) + d[31]*F(1,1)*F(1,2)*F(2,0)*F(2,1) + d[29]*pow(F(1,2),2)*F(2,0)*F(2,1) + d[34]*pow(F(1,2),2)*F(2,0)*F(2,1) + d[21]*pow(F(1,0),2)*pow(F(2,1),2) + d[9]*F(1,0)*F(1,1)*pow(F(2,1),2) + d[19]*F(1,0)*F(1,1)*pow(F(2,1),2) + d[7]*pow(F(1,1),2)*pow(F(2,1),2) + d[22]*F(1,0)*F(1,2)*pow(F(2,1),2) + d[27]*F(1,0)*F(1,2)*pow(F(2,1),2) + d[10]*F(1,1)*F(1,2)*pow(F(2,1),2) + d[25]*F(1,1)*F(1,2)*pow(F(2,1),2) + d[28]*pow(F(1,2),2)*pow(F(2,1),2) + d[3]*F(1,0)*F(2,0)*(F(1,1)*F(2,0) + F(1,0)*F(2,1)) + d[5]*pow(F(1,0),2)*F(2,0)*F(2,2) + d[30]*pow(F(1,0),2)*F(2,0)*F(2,2) + d[4]*F(1,0)*F(1,1)*F(2,0)*F(2,2) + d[23]*F(1,0)*F(1,1)*F(2,0)*F(2,2) + d[24]*F(1,0)*F(1,1)*F(2,0)*F(2,2) + d[33]*F(1,0)*F(1,1)*F(2,0)*F(2,2) + d[22]*pow(F(1,1),2)*F(2,0)*F(2,2) + d[27]*pow(F(1,1),2)*F(2,0)*F(2,2) + d[2]*F(1,0)*F(1,2)*F(2,0)*F(2,2) + d[12]*F(1,0)*F(1,2)*F(2,0)*F(2,2) + 2*d[35]*F(1,0)*F(1,2)*F(2,0)*F(2,2) + d[15]*F(1,1)*F(1,2)*F(2,0)*F(2,2) + d[20]*F(1,1)*F(1,2)*F(2,0)*F(2,2) + d[29]*F(1,1)*F(1,2)*F(2,0)*F(2,2) + d[34]*F(1,1)*F(1,2)*F(2,0)*F(2,2) + d[17]*pow(F(1,2),2)*F(2,0)*F(2,2) + d[32]*pow(F(1,2),2)*F(2,0)*F(2,2) + d[23]*pow(F(1,0),2)*F(2,1)*F(2,2) + d[33]*pow(F(1,0),2)*F(2,1)*F(2,2) + d[11]*F(1,0)*F(1,1)*F(2,1)*F(2,2) + d[22]*F(1,0)*F(1,1)*F(2,1)*F(2,2) + d[27]*F(1,0)*F(1,1)*F(2,1)*F(2,2) + d[31]*F(1,0)*F(1,1)*F(2,1)*F(2,2) + d[10]*pow(F(1,1),2)*F(2,1)*F(2,2) + d[25]*pow(F(1,1),2)*F(2,1)*F(2,2) + d[15]*F(1,0)*F(1,2)*F(2,1)*F(2,2) + d[20]*F(1,0)*F(1,2)*F(2,1)*F(2,2) + d[29]*F(1,0)*F(1,2)*F(2,1)*F(2,2) + d[34]*F(1,0)*F(1,2)*F(2,1)*F(2,2) + d[8]*F(1,1)*F(1,2)*F(2,1)*F(2,2) + d[13]*F(1,1)*F(1,2)*F(2,1)*F(2,2) + 2*d[28]*F(1,1)*F(1,2)*F(2,1)*F(2,2) + d[16]*pow(F(1,2),2)*F(2,1)*F(2,2) + d[26]*pow(F(1,2),2)*F(2,1)*F(2,2) + d[35]*pow(F(1,0),2)*pow(F(2,2),2) + d[29]*F(1,0)*F(1,1)*pow(F(2,2),2) + d[34]*F(1,0)*F(1,1)*pow(F(2,2),2) + d[28]*pow(F(1,1),2)*pow(F(2,2),2) + d[17]*F(1,0)*F(1,2)*pow(F(2,2),2) + d[32]*F(1,0)*F(1,2)*pow(F(2,2),2) + d[16]*F(1,1)*F(1,2)*pow(F(2,2),2) + d[26]*F(1,1)*F(1,2)*pow(F(2,2),2) + d[14]*pow(F(1,2),2)*pow(F(2,2),2); c.d[29] = d[0]*F(0,0)*F(1,0)*pow(F(2,0),2) + d[5]*F(0,2)*F(1,0)*pow(F(2,0),2) + d[18]*F(0,0)*F(1,1)*pow(F(2,0),2) + d[21]*F(0,1)*F(1,1)*pow(F(2,0),2) + d[23]*F(0,2)*F(1,1)*pow(F(2,0),2) + d[30]*F(0,0)*F(1,2)*pow(F(2,0),2) + d[33]*F(0,1)*F(1,2)*pow(F(2,0),2) + d[35]*F(0,2)*F(1,2)*pow(F(2,0),2) + d[18]*F(0,0)*F(1,0)*F(2,0)*F(2,1) + d[1]*F(0,1)*F(1,0)*F(2,0)*F(2,1) + d[21]*F(0,1)*F(1,0)*F(2,0)*F(2,1) + d[4]*F(0,2)*F(1,0)*F(2,0)*F(2,1) + d[23]*F(0,2)*F(1,0)*F(2,0)*F(2,1) + d[6]*F(0,0)*F(1,1)*F(2,0)*F(2,1) + d[21]*F(0,0)*F(1,1)*F(2,0)*F(2,1) + d[9]*F(0,1)*F(1,1)*F(2,0)*F(2,1) + d[19]*F(0,1)*F(1,1)*F(2,0)*F(2,1) + d[11]*F(0,2)*F(1,1)*F(2,0)*F(2,1) + d[22]*F(0,2)*F(1,1)*F(2,0)*F(2,1) + d[24]*F(0,0)*F(1,2)*F(2,0)*F(2,1) + d[33]*F(0,0)*F(1,2)*F(2,0)*F(2,1) + d[27]*F(0,1)*F(1,2)*F(2,0)*F(2,1) + d[31]*F(0,1)*F(1,2)*F(2,0)*F(2,1) + d[29]*F(0,2)*F(1,2)*F(2,0)*F(2,1) + d[34]*F(0,2)*F(1,2)*F(2,0)*F(2,1) + d[21]*F(0,0)*F(1,0)*pow(F(2,1),2) + d[19]*F(0,1)*F(1,0)*pow(F(2,1),2) + d[22]*F(0,2)*F(1,0)*pow(F(2,1),2) + d[9]*F(0,0)*F(1,1)*pow(F(2,1),2) + d[7]*F(0,1)*F(1,1)*pow(F(2,1),2) + d[10]*F(0,2)*F(1,1)*pow(F(2,1),2) + d[27]*F(0,0)*F(1,2)*pow(F(2,1),2) + d[25]*F(0,1)*F(1,2)*pow(F(2,1),2) + d[28]*F(0,2)*F(1,2)*pow(F(2,1),2) + d[3]*F(1,0)*F(2,0)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + d[5]*F(0,0)*F(1,0)*F(2,0)*F(2,2) + d[30]*F(0,0)*F(1,0)*F(2,0)*F(2,2) + d[4]*F(0,1)*F(1,0)*F(2,0)*F(2,2) + d[33]*F(0,1)*F(1,0)*F(2,0)*F(2,2) + d[2]*F(0,2)*F(1,0)*F(2,0)*F(2,2) + d[35]*F(0,2)*F(1,0)*F(2,0)*F(2,2) + d[23]*F(0,0)*F(1,1)*F(2,0)*F(2,2) + d[24]*F(0,0)*F(1,1)*F(2,0)*F(2,2) + d[22]*F(0,1)*F(1,1)*F(2,0)*F(2,2) + d[27]*F(0,1)*F(1,1)*F(2,0)*F(2,2) + d[20]*F(0,2)*F(1,1)*F(2,0)*F(2,2) + d[29]*F(0,2)*F(1,1)*F(2,0)*F(2,2) + d[12]*F(0,0)*F(1,2)*F(2,0)*F(2,2) + d[35]*F(0,0)*F(1,2)*F(2,0)*F(2,2) + d[15]*F(0,1)*F(1,2)*F(2,0)*F(2,2) + d[34]*F(0,1)*F(1,2)*F(2,0)*F(2,2) + d[17]*F(0,2)*F(1,2)*F(2,0)*F(2,2) + d[32]*F(0,2)*F(1,2)*F(2,0)*F(2,2) + d[23]*F(0,0)*F(1,0)*F(2,1)*F(2,2) + d[33]*F(0,0)*F(1,0)*F(2,1)*F(2,2) + d[22]*F(0,1)*F(1,0)*F(2,1)*F(2,2) + d[31]*F(0,1)*F(1,0)*F(2,1)*F(2,2) + d[20]*F(0,2)*F(1,0)*F(2,1)*F(2,2) + d[34]*F(0,2)*F(1,0)*F(2,1)*F(2,2) + d[11]*F(0,0)*F(1,1)*F(2,1)*F(2,2) + d[27]*F(0,0)*F(1,1)*F(2,1)*F(2,2) + d[10]*F(0,1)*F(1,1)*F(2,1)*F(2,2) + d[25]*F(0,1)*F(1,1)*F(2,1)*F(2,2) + d[8]*F(0,2)*F(1,1)*F(2,1)*F(2,2) + d[28]*F(0,2)*F(1,1)*F(2,1)*F(2,2) + d[15]*F(0,0)*F(1,2)*F(2,1)*F(2,2) + d[29]*F(0,0)*F(1,2)*F(2,1)*F(2,2) + d[13]*F(0,1)*F(1,2)*F(2,1)*F(2,2) + d[28]*F(0,1)*F(1,2)*F(2,1)*F(2,2) + d[16]*F(0,2)*F(1,2)*F(2,1)*F(2,2) + d[26]*F(0,2)*F(1,2)*F(2,1)*F(2,2) + d[35]*F(0,0)*F(1,0)*pow(F(2,2),2) + d[34]*F(0,1)*F(1,0)*pow(F(2,2),2) + d[32]*F(0,2)*F(1,0)*pow(F(2,2),2) + d[29]*F(0,0)*F(1,1)*pow(F(2,2),2) + d[28]*F(0,1)*F(1,1)*pow(F(2,2),2) + d[26]*F(0,2)*F(1,1)*pow(F(2,2),2) + d[17]*F(0,0)*F(1,2)*pow(F(2,2),2) + d[16]*F(0,1)*F(1,2)*pow(F(2,2),2) + d[14]*F(0,2)*F(1,2)*pow(F(2,2),2); c.d[30] = d[0]*pow(F(0,0),3)*F(2,0) + 2*d[3]*pow(F(0,0),2)*F(0,1)*F(2,0) + d[18]*pow(F(0,0),2)*F(0,1)*F(2,0) + d[1]*F(0,0)*pow(F(0,1),2)*F(2,0) + 2*d[21]*F(0,0)*pow(F(0,1),2)*F(2,0) + d[19]*pow(F(0,1),3)*F(2,0) + 2*d[5]*pow(F(0,0),2)*F(0,2)*F(2,0) + d[30]*pow(F(0,0),2)*F(0,2)*F(2,0) + 2*d[4]*F(0,0)*F(0,1)*F(0,2)*F(2,0) + 2*d[23]*F(0,0)*F(0,1)*F(0,2)*F(2,0) + 2*d[33]*F(0,0)*F(0,1)*F(0,2)*F(2,0) + 2*d[22]*pow(F(0,1),2)*F(0,2)*F(2,0) + d[31]*pow(F(0,1),2)*F(0,2)*F(2,0) + d[2]*F(0,0)*pow(F(0,2),2)*F(2,0) + 2*d[35]*F(0,0)*pow(F(0,2),2)*F(2,0) + d[20]*F(0,1)*pow(F(0,2),2)*F(2,0) + 2*d[34]*F(0,1)*pow(F(0,2),2)*F(2,0) + d[32]*pow(F(0,2),3)*F(2,0) + d[18]*pow(F(0,0),3)*F(2,1) + d[6]*pow(F(0,0),2)*F(0,1)*F(2,1) + 2*d[21]*pow(F(0,0),2)*F(0,1)*F(2,1) + 2*d[9]*F(0,0)*pow(F(0,1),2)*F(2,1) + d[19]*F(0,0)*pow(F(0,1),2)*F(2,1) + d[7]*pow(F(0,1),3)*F(2,1) + 2*d[23]*pow(F(0,0),2)*F(0,2)*F(2,1) + d[24]*pow(F(0,0),2)*F(0,2)*F(2,1) + 2*d[11]*F(0,0)*F(0,1)*F(0,2)*F(2,1) + 2*d[22]*F(0,0)*F(0,1)*F(0,2)*F(2,1) + 2*d[27]*F(0,0)*F(0,1)*F(0,2)*F(2,1) + 2*d[10]*pow(F(0,1),2)*F(0,2)*F(2,1) + d[25]*pow(F(0,1),2)*F(0,2)*F(2,1) + d[20]*F(0,0)*pow(F(0,2),2)*F(2,1) + 2*d[29]*F(0,0)*pow(F(0,2),2)*F(2,1) + d[8]*F(0,1)*pow(F(0,2),2)*F(2,1) + 2*d[28]*F(0,1)*pow(F(0,2),2)*F(2,1) + d[26]*pow(F(0,2),3)*F(2,1) + d[30]*pow(F(0,0),3)*F(2,2) + d[24]*pow(F(0,0),2)*F(0,1)*F(2,2) + 2*d[33]*pow(F(0,0),2)*F(0,1)*F(2,2) + 2*d[27]*F(0,0)*pow(F(0,1),2)*F(2,2) + d[31]*F(0,0)*pow(F(0,1),2)*F(2,2) + d[25]*pow(F(0,1),3)*F(2,2) + d[12]*pow(F(0,0),2)*F(0,2)*F(2,2) + 2*d[35]*pow(F(0,0),2)*F(0,2)*F(2,2) + 2*d[15]*F(0,0)*F(0,1)*F(0,2)*F(2,2) + 2*d[29]*F(0,0)*F(0,1)*F(0,2)*F(2,2) + 2*d[34]*F(0,0)*F(0,1)*F(0,2)*F(2,2) + d[13]*pow(F(0,1),2)*F(0,2)*F(2,2) + 2*d[28]*pow(F(0,1),2)*F(0,2)*F(2,2) + 2*d[17]*F(0,0)*pow(F(0,2),2)*F(2,2) + d[32]*F(0,0)*pow(F(0,2),2)*F(2,2) + 2*d[16]*F(0,1)*pow(F(0,2),2)*F(2,2) + d[26]*F(0,1)*pow(F(0,2),2)*F(2,2) + d[14]*pow(F(0,2),3)*F(2,2); c.d[31] = d[0]*F(0,0)*pow(F(1,0),2)*F(2,0) + d[30]*F(0,2)*pow(F(1,0),2)*F(2,0) + 2*d[3]*F(0,0)*F(1,0)*F(1,1)*F(2,0) + 2*d[21]*F(0,1)*F(1,0)*F(1,1)*F(2,0) + 2*d[33]*F(0,2)*F(1,0)*F(1,1)*F(2,0) + d[1]*F(0,0)*pow(F(1,1),2)*F(2,0) + d[19]*F(0,1)*pow(F(1,1),2)*F(2,0) + d[31]*F(0,2)*pow(F(1,1),2)*F(2,0) + 2*d[5]*F(0,0)*F(1,0)*F(1,2)*F(2,0) + 2*d[23]*F(0,1)*F(1,0)*F(1,2)*F(2,0) + 2*d[35]*F(0,2)*F(1,0)*F(1,2)*F(2,0) + 2*d[4]*F(0,0)*F(1,1)*F(1,2)*F(2,0) + 2*d[22]*F(0,1)*F(1,1)*F(1,2)*F(2,0) + 2*d[34]*F(0,2)*F(1,1)*F(1,2)*F(2,0) + d[2]*F(0,0)*pow(F(1,2),2)*F(2,0) + d[20]*F(0,1)*pow(F(1,2),2)*F(2,0) + d[32]*F(0,2)*pow(F(1,2),2)*F(2,0) + d[6]*F(0,1)*pow(F(1,0),2)*F(2,1) + d[24]*F(0,2)*pow(F(1,0),2)*F(2,1) + 2*d[21]*F(0,0)*F(1,0)*F(1,1)*F(2,1) + 2*d[9]*F(0,1)*F(1,0)*F(1,1)*F(2,1) + 2*d[27]*F(0,2)*F(1,0)*F(1,1)*F(2,1) + d[19]*F(0,0)*pow(F(1,1),2)*F(2,1) + d[7]*F(0,1)*pow(F(1,1),2)*F(2,1) + d[25]*F(0,2)*pow(F(1,1),2)*F(2,1) + 2*d[23]*F(0,0)*F(1,0)*F(1,2)*F(2,1) + 2*d[11]*F(0,1)*F(1,0)*F(1,2)*F(2,1) + 2*d[29]*F(0,2)*F(1,0)*F(1,2)*F(2,1) + 2*d[22]*F(0,0)*F(1,1)*F(1,2)*F(2,1) + 2*d[10]*F(0,1)*F(1,1)*F(1,2)*F(2,1) + 2*d[28]*F(0,2)*F(1,1)*F(1,2)*F(2,1) + d[20]*F(0,0)*pow(F(1,2),2)*F(2,1) + d[8]*F(0,1)*pow(F(1,2),2)*F(2,1) + d[26]*F(0,2)*pow(F(1,2),2)*F(2,1) + d[18]*pow(F(1,0),2)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + d[30]*F(0,0)*pow(F(1,0),2)*F(2,2) + d[24]*F(0,1)*pow(F(1,0),2)*F(2,2) + d[12]*F(0,2)*pow(F(1,0),2)*F(2,2) + 2*d[33]*F(0,0)*F(1,0)*F(1,1)*F(2,2) + 2*d[27]*F(0,1)*F(1,0)*F(1,1)*F(2,2) + 2*d[15]*F(0,2)*F(1,0)*F(1,1)*F(2,2) + d[31]*F(0,0)*pow(F(1,1),2)*F(2,2) + d[25]*F(0,1)*pow(F(1,1),2)*F(2,2) + d[13]*F(0,2)*pow(F(1,1),2)*F(2,2) + 2*d[35]*F(0,0)*F(1,0)*F(1,2)*F(2,2) + 2*d[29]*F(0,1)*F(1,0)*F(1,2)*F(2,2) + 2*d[17]*F(0,2)*F(1,0)*F(1,2)*F(2,2) + 2*d[34]*F(0,0)*F(1,1)*F(1,2)*F(2,2) + 2*d[28]*F(0,1)*F(1,1)*F(1,2)*F(2,2) + 2*d[16]*F(0,2)*F(1,1)*F(1,2)*F(2,2) + d[32]*F(0,0)*pow(F(1,2),2)*F(2,2) + d[26]*F(0,1)*pow(F(1,2),2)*F(2,2) + d[14]*F(0,2)*pow(F(1,2),2)*F(2,2); c.d[32] = d[0]*F(0,0)*pow(F(2,0),3) + d[30]*F(0,2)*pow(F(2,0),3) + 2*d[3]*F(0,0)*pow(F(2,0),2)*F(2,1) + d[6]*F(0,1)*pow(F(2,0),2)*F(2,1) + 2*d[21]*F(0,1)*pow(F(2,0),2)*F(2,1) + d[24]*F(0,2)*pow(F(2,0),2)*F(2,1) + 2*d[33]*F(0,2)*pow(F(2,0),2)*F(2,1) + d[1]*F(0,0)*F(2,0)*pow(F(2,1),2) + 2*d[21]*F(0,0)*F(2,0)*pow(F(2,1),2) + 2*d[9]*F(0,1)*F(2,0)*pow(F(2,1),2) + d[19]*F(0,1)*F(2,0)*pow(F(2,1),2) + 2*d[27]*F(0,2)*F(2,0)*pow(F(2,1),2) + d[31]*F(0,2)*F(2,0)*pow(F(2,1),2) + d[19]*F(0,0)*pow(F(2,1),3) + d[7]*F(0,1)*pow(F(2,1),3) + d[25]*F(0,2)*pow(F(2,1),3) + d[18]*pow(F(2,0),2)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + 2*d[5]*F(0,0)*pow(F(2,0),2)*F(2,2) + d[30]*F(0,0)*pow(F(2,0),2)*F(2,2) + 2*d[23]*F(0,1)*pow(F(2,0),2)*F(2,2) + d[24]*F(0,1)*pow(F(2,0),2)*F(2,2) + d[12]*F(0,2)*pow(F(2,0),2)*F(2,2) + 2*d[35]*F(0,2)*pow(F(2,0),2)*F(2,2) + 2*d[4]*F(0,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[23]*F(0,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[33]*F(0,0)*F(2,0)*F(2,1)*F(2,2) + 2*d[11]*F(0,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[22]*F(0,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[27]*F(0,1)*F(2,0)*F(2,1)*F(2,2) + 2*d[15]*F(0,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[29]*F(0,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[34]*F(0,2)*F(2,0)*F(2,1)*F(2,2) + 2*d[22]*F(0,0)*pow(F(2,1),2)*F(2,2) + d[31]*F(0,0)*pow(F(2,1),2)*F(2,2) + 2*d[10]*F(0,1)*pow(F(2,1),2)*F(2,2) + d[25]*F(0,1)*pow(F(2,1),2)*F(2,2) + d[13]*F(0,2)*pow(F(2,1),2)*F(2,2) + 2*d[28]*F(0,2)*pow(F(2,1),2)*F(2,2) + d[2]*F(0,0)*F(2,0)*pow(F(2,2),2) + 2*d[35]*F(0,0)*F(2,0)*pow(F(2,2),2) + d[20]*F(0,1)*F(2,0)*pow(F(2,2),2) + 2*d[29]*F(0,1)*F(2,0)*pow(F(2,2),2) + 2*d[17]*F(0,2)*F(2,0)*pow(F(2,2),2) + d[32]*F(0,2)*F(2,0)*pow(F(2,2),2) + d[20]*F(0,0)*F(2,1)*pow(F(2,2),2) + 2*d[34]*F(0,0)*F(2,1)*pow(F(2,2),2) + d[8]*F(0,1)*F(2,1)*pow(F(2,2),2) + 2*d[28]*F(0,1)*F(2,1)*pow(F(2,2),2) + 2*d[16]*F(0,2)*F(2,1)*pow(F(2,2),2) + d[26]*F(0,2)*F(2,1)*pow(F(2,2),2) + d[32]*F(0,0)*pow(F(2,2),3) + d[26]*F(0,1)*pow(F(2,2),3) + d[14]*F(0,2)*pow(F(2,2),3); c.d[33] = d[0]*pow(F(0,0),2)*F(1,0)*F(2,0) + d[18]*F(0,0)*F(0,1)*F(1,0)*F(2,0) + d[21]*pow(F(0,1),2)*F(1,0)*F(2,0) + d[5]*F(0,0)*F(0,2)*F(1,0)*F(2,0) + d[30]*F(0,0)*F(0,2)*F(1,0)*F(2,0) + d[23]*F(0,1)*F(0,2)*F(1,0)*F(2,0) + d[33]*F(0,1)*F(0,2)*F(1,0)*F(2,0) + d[35]*pow(F(0,2),2)*F(1,0)*F(2,0) + d[1]*F(0,0)*F(0,1)*F(1,1)*F(2,0) + d[21]*F(0,0)*F(0,1)*F(1,1)*F(2,0) + d[19]*pow(F(0,1),2)*F(1,1)*F(2,0) + d[4]*F(0,0)*F(0,2)*F(1,1)*F(2,0) + d[33]*F(0,0)*F(0,2)*F(1,1)*F(2,0) + d[22]*F(0,1)*F(0,2)*F(1,1)*F(2,0) + d[31]*F(0,1)*F(0,2)*F(1,1)*F(2,0) + d[34]*pow(F(0,2),2)*F(1,1)*F(2,0) + d[3]*F(0,0)*(F(0,1)*F(1,0) + F(0,0)*F(1,1))*F(2,0) + d[5]*pow(F(0,0),2)*F(1,2)*F(2,0) + d[4]*F(0,0)*F(0,1)*F(1,2)*F(2,0) + d[23]*F(0,0)*F(0,1)*F(1,2)*F(2,0) + d[22]*pow(F(0,1),2)*F(1,2)*F(2,0) + d[2]*F(0,0)*F(0,2)*F(1,2)*F(2,0) + d[35]*F(0,0)*F(0,2)*F(1,2)*F(2,0) + d[20]*F(0,1)*F(0,2)*F(1,2)*F(2,0) + d[34]*F(0,1)*F(0,2)*F(1,2)*F(2,0) + d[32]*pow(F(0,2),2)*F(1,2)*F(2,0) + d[18]*pow(F(0,0),2)*F(1,0)*F(2,1) + d[6]*F(0,0)*F(0,1)*F(1,0)*F(2,1) + d[21]*F(0,0)*F(0,1)*F(1,0)*F(2,1) + d[9]*pow(F(0,1),2)*F(1,0)*F(2,1) + d[23]*F(0,0)*F(0,2)*F(1,0)*F(2,1) + d[24]*F(0,0)*F(0,2)*F(1,0)*F(2,1) + d[11]*F(0,1)*F(0,2)*F(1,0)*F(2,1) + d[27]*F(0,1)*F(0,2)*F(1,0)*F(2,1) + d[29]*pow(F(0,2),2)*F(1,0)*F(2,1) + d[21]*pow(F(0,0),2)*F(1,1)*F(2,1) + d[9]*F(0,0)*F(0,1)*F(1,1)*F(2,1) + d[19]*F(0,0)*F(0,1)*F(1,1)*F(2,1) + d[7]*pow(F(0,1),2)*F(1,1)*F(2,1) + d[22]*F(0,0)*F(0,2)*F(1,1)*F(2,1) + d[27]*F(0,0)*F(0,2)*F(1,1)*F(2,1) + d[10]*F(0,1)*F(0,2)*F(1,1)*F(2,1) + d[25]*F(0,1)*F(0,2)*F(1,1)*F(2,1) + d[28]*pow(F(0,2),2)*F(1,1)*F(2,1) + d[23]*pow(F(0,0),2)*F(1,2)*F(2,1) + d[11]*F(0,0)*F(0,1)*F(1,2)*F(2,1) + d[22]*F(0,0)*F(0,1)*F(1,2)*F(2,1) + d[10]*pow(F(0,1),2)*F(1,2)*F(2,1) + d[20]*F(0,0)*F(0,2)*F(1,2)*F(2,1) + d[29]*F(0,0)*F(0,2)*F(1,2)*F(2,1) + d[8]*F(0,1)*F(0,2)*F(1,2)*F(2,1) + d[28]*F(0,1)*F(0,2)*F(1,2)*F(2,1) + d[26]*pow(F(0,2),2)*F(1,2)*F(2,1) + d[30]*pow(F(0,0),2)*F(1,0)*F(2,2) + d[24]*F(0,0)*F(0,1)*F(1,0)*F(2,2) + d[33]*F(0,0)*F(0,1)*F(1,0)*F(2,2) + d[27]*pow(F(0,1),2)*F(1,0)*F(2,2) + d[12]*F(0,0)*F(0,2)*F(1,0)*F(2,2) + d[35]*F(0,0)*F(0,2)*F(1,0)*F(2,2) + d[15]*F(0,1)*F(0,2)*F(1,0)*F(2,2) + d[29]*F(0,1)*F(0,2)*F(1,0)*F(2,2) + d[17]*pow(F(0,2),2)*F(1,0)*F(2,2) + d[33]*pow(F(0,0),2)*F(1,1)*F(2,2) + d[27]*F(0,0)*F(0,1)*F(1,1)*F(2,2) + d[31]*F(0,0)*F(0,1)*F(1,1)*F(2,2) + d[25]*pow(F(0,1),2)*F(1,1)*F(2,2) + d[15]*F(0,0)*F(0,2)*F(1,1)*F(2,2) + d[34]*F(0,0)*F(0,2)*F(1,1)*F(2,2) + d[13]*F(0,1)*F(0,2)*F(1,1)*F(2,2) + d[28]*F(0,1)*F(0,2)*F(1,1)*F(2,2) + d[16]*pow(F(0,2),2)*F(1,1)*F(2,2) + d[35]*pow(F(0,0),2)*F(1,2)*F(2,2) + d[29]*F(0,0)*F(0,1)*F(1,2)*F(2,2) + d[34]*F(0,0)*F(0,1)*F(1,2)*F(2,2) + d[28]*pow(F(0,1),2)*F(1,2)*F(2,2) + d[17]*F(0,0)*F(0,2)*F(1,2)*F(2,2) + d[32]*F(0,0)*F(0,2)*F(1,2)*F(2,2) + d[16]*F(0,1)*F(0,2)*F(1,2)*F(2,2) + d[26]*F(0,1)*F(0,2)*F(1,2)*F(2,2) + d[14]*pow(F(0,2),2)*F(1,2)*F(2,2); c.d[34] = d[0]*F(0,0)*F(1,0)*pow(F(2,0),2) + d[30]*F(0,2)*F(1,0)*pow(F(2,0),2) + d[3]*F(0,0)*F(1,1)*pow(F(2,0),2) + d[21]*F(0,1)*F(1,1)*pow(F(2,0),2) + d[33]*F(0,2)*F(1,1)*pow(F(2,0),2) + d[5]*F(0,0)*F(1,2)*pow(F(2,0),2) + d[23]*F(0,1)*F(1,2)*pow(F(2,0),2) + d[35]*F(0,2)*F(1,2)*pow(F(2,0),2) + d[3]*F(0,0)*F(1,0)*F(2,0)*F(2,1) + d[6]*F(0,1)*F(1,0)*F(2,0)*F(2,1) + d[21]*F(0,1)*F(1,0)*F(2,0)*F(2,1) + d[24]*F(0,2)*F(1,0)*F(2,0)*F(2,1) + d[33]*F(0,2)*F(1,0)*F(2,0)*F(2,1) + d[1]*F(0,0)*F(1,1)*F(2,0)*F(2,1) + d[21]*F(0,0)*F(1,1)*F(2,0)*F(2,1) + d[9]*F(0,1)*F(1,1)*F(2,0)*F(2,1) + d[19]*F(0,1)*F(1,1)*F(2,0)*F(2,1) + d[27]*F(0,2)*F(1,1)*F(2,0)*F(2,1) + d[31]*F(0,2)*F(1,1)*F(2,0)*F(2,1) + d[4]*F(0,0)*F(1,2)*F(2,0)*F(2,1) + d[23]*F(0,0)*F(1,2)*F(2,0)*F(2,1) + d[11]*F(0,1)*F(1,2)*F(2,0)*F(2,1) + d[22]*F(0,1)*F(1,2)*F(2,0)*F(2,1) + d[29]*F(0,2)*F(1,2)*F(2,0)*F(2,1) + d[34]*F(0,2)*F(1,2)*F(2,0)*F(2,1) + d[21]*F(0,0)*F(1,0)*pow(F(2,1),2) + d[9]*F(0,1)*F(1,0)*pow(F(2,1),2) + d[27]*F(0,2)*F(1,0)*pow(F(2,1),2) + d[19]*F(0,0)*F(1,1)*pow(F(2,1),2) + d[7]*F(0,1)*F(1,1)*pow(F(2,1),2) + d[25]*F(0,2)*F(1,1)*pow(F(2,1),2) + d[22]*F(0,0)*F(1,2)*pow(F(2,1),2) + d[10]*F(0,1)*F(1,2)*pow(F(2,1),2) + d[28]*F(0,2)*F(1,2)*pow(F(2,1),2) + d[18]*F(1,0)*F(2,0)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + d[5]*F(0,0)*F(1,0)*F(2,0)*F(2,2) + d[30]*F(0,0)*F(1,0)*F(2,0)*F(2,2) + d[23]*F(0,1)*F(1,0)*F(2,0)*F(2,2) + d[24]*F(0,1)*F(1,0)*F(2,0)*F(2,2) + d[12]*F(0,2)*F(1,0)*F(2,0)*F(2,2) + d[35]*F(0,2)*F(1,0)*F(2,0)*F(2,2) + d[4]*F(0,0)*F(1,1)*F(2,0)*F(2,2) + d[33]*F(0,0)*F(1,1)*F(2,0)*F(2,2) + d[22]*F(0,1)*F(1,1)*F(2,0)*F(2,2) + d[27]*F(0,1)*F(1,1)*F(2,0)*F(2,2) + d[15]*F(0,2)*F(1,1)*F(2,0)*F(2,2) + d[34]*F(0,2)*F(1,1)*F(2,0)*F(2,2) + d[2]*F(0,0)*F(1,2)*F(2,0)*F(2,2) + d[35]*F(0,0)*F(1,2)*F(2,0)*F(2,2) + d[20]*F(0,1)*F(1,2)*F(2,0)*F(2,2) + d[29]*F(0,1)*F(1,2)*F(2,0)*F(2,2) + d[17]*F(0,2)*F(1,2)*F(2,0)*F(2,2) + d[32]*F(0,2)*F(1,2)*F(2,0)*F(2,2) + d[23]*F(0,0)*F(1,0)*F(2,1)*F(2,2) + d[33]*F(0,0)*F(1,0)*F(2,1)*F(2,2) + d[11]*F(0,1)*F(1,0)*F(2,1)*F(2,2) + d[27]*F(0,1)*F(1,0)*F(2,1)*F(2,2) + d[15]*F(0,2)*F(1,0)*F(2,1)*F(2,2) + d[29]*F(0,2)*F(1,0)*F(2,1)*F(2,2) + d[22]*F(0,0)*F(1,1)*F(2,1)*F(2,2) + d[31]*F(0,0)*F(1,1)*F(2,1)*F(2,2) + d[10]*F(0,1)*F(1,1)*F(2,1)*F(2,2) + d[25]*F(0,1)*F(1,1)*F(2,1)*F(2,2) + d[13]*F(0,2)*F(1,1)*F(2,1)*F(2,2) + d[28]*F(0,2)*F(1,1)*F(2,1)*F(2,2) + d[20]*F(0,0)*F(1,2)*F(2,1)*F(2,2) + d[34]*F(0,0)*F(1,2)*F(2,1)*F(2,2) + d[8]*F(0,1)*F(1,2)*F(2,1)*F(2,2) + d[28]*F(0,1)*F(1,2)*F(2,1)*F(2,2) + d[16]*F(0,2)*F(1,2)*F(2,1)*F(2,2) + d[26]*F(0,2)*F(1,2)*F(2,1)*F(2,2) + d[35]*F(0,0)*F(1,0)*pow(F(2,2),2) + d[29]*F(0,1)*F(1,0)*pow(F(2,2),2) + d[17]*F(0,2)*F(1,0)*pow(F(2,2),2) + d[34]*F(0,0)*F(1,1)*pow(F(2,2),2) + d[28]*F(0,1)*F(1,1)*pow(F(2,2),2) + d[16]*F(0,2)*F(1,1)*pow(F(2,2),2) + d[32]*F(0,0)*F(1,2)*pow(F(2,2),2) + d[26]*F(0,1)*F(1,2)*pow(F(2,2),2) + d[14]*F(0,2)*F(1,2)*pow(F(2,2),2); c.d[35] = d[0]*pow(F(0,0),2)*pow(F(2,0),2) + d[18]*F(0,0)*F(0,1)*pow(F(2,0),2) + d[21]*pow(F(0,1),2)*pow(F(2,0),2) + d[5]*F(0,0)*F(0,2)*pow(F(2,0),2) + d[30]*F(0,0)*F(0,2)*pow(F(2,0),2) + d[23]*F(0,1)*F(0,2)*pow(F(2,0),2) + d[33]*F(0,1)*F(0,2)*pow(F(2,0),2) + d[35]*pow(F(0,2),2)*pow(F(2,0),2) + d[18]*pow(F(0,0),2)*F(2,0)*F(2,1) + d[1]*F(0,0)*F(0,1)*F(2,0)*F(2,1) + d[6]*F(0,0)*F(0,1)*F(2,0)*F(2,1) + 2*d[21]*F(0,0)*F(0,1)*F(2,0)*F(2,1) + d[9]*pow(F(0,1),2)*F(2,0)*F(2,1) + d[19]*pow(F(0,1),2)*F(2,0)*F(2,1) + d[4]*F(0,0)*F(0,2)*F(2,0)*F(2,1) + d[23]*F(0,0)*F(0,2)*F(2,0)*F(2,1) + d[24]*F(0,0)*F(0,2)*F(2,0)*F(2,1) + d[33]*F(0,0)*F(0,2)*F(2,0)*F(2,1) + d[11]*F(0,1)*F(0,2)*F(2,0)*F(2,1) + d[22]*F(0,1)*F(0,2)*F(2,0)*F(2,1) + d[27]*F(0,1)*F(0,2)*F(2,0)*F(2,1) + d[31]*F(0,1)*F(0,2)*F(2,0)*F(2,1) + d[29]*pow(F(0,2),2)*F(2,0)*F(2,1) + d[34]*pow(F(0,2),2)*F(2,0)*F(2,1) + d[21]*pow(F(0,0),2)*pow(F(2,1),2) + d[9]*F(0,0)*F(0,1)*pow(F(2,1),2) + d[19]*F(0,0)*F(0,1)*pow(F(2,1),2) + d[7]*pow(F(0,1),2)*pow(F(2,1),2) + d[22]*F(0,0)*F(0,2)*pow(F(2,1),2) + d[27]*F(0,0)*F(0,2)*pow(F(2,1),2) + d[10]*F(0,1)*F(0,2)*pow(F(2,1),2) + d[25]*F(0,1)*F(0,2)*pow(F(2,1),2) + d[28]*pow(F(0,2),2)*pow(F(2,1),2) + d[3]*F(0,0)*F(2,0)*(F(0,1)*F(2,0) + F(0,0)*F(2,1)) + d[5]*pow(F(0,0),2)*F(2,0)*F(2,2) + d[30]*pow(F(0,0),2)*F(2,0)*F(2,2) + d[4]*F(0,0)*F(0,1)*F(2,0)*F(2,2) + d[23]*F(0,0)*F(0,1)*F(2,0)*F(2,2) + d[24]*F(0,0)*F(0,1)*F(2,0)*F(2,2) + d[33]*F(0,0)*F(0,1)*F(2,0)*F(2,2) + d[22]*pow(F(0,1),2)*F(2,0)*F(2,2) + d[27]*pow(F(0,1),2)*F(2,0)*F(2,2) + d[2]*F(0,0)*F(0,2)*F(2,0)*F(2,2) + d[12]*F(0,0)*F(0,2)*F(2,0)*F(2,2) + 2*d[35]*F(0,0)*F(0,2)*F(2,0)*F(2,2) + d[15]*F(0,1)*F(0,2)*F(2,0)*F(2,2) + d[20]*F(0,1)*F(0,2)*F(2,0)*F(2,2) + d[29]*F(0,1)*F(0,2)*F(2,0)*F(2,2) + d[34]*F(0,1)*F(0,2)*F(2,0)*F(2,2) + d[17]*pow(F(0,2),2)*F(2,0)*F(2,2) + d[32]*pow(F(0,2),2)*F(2,0)*F(2,2) + d[23]*pow(F(0,0),2)*F(2,1)*F(2,2) + d[33]*pow(F(0,0),2)*F(2,1)*F(2,2) + d[11]*F(0,0)*F(0,1)*F(2,1)*F(2,2) + d[22]*F(0,0)*F(0,1)*F(2,1)*F(2,2) + d[27]*F(0,0)*F(0,1)*F(2,1)*F(2,2) + d[31]*F(0,0)*F(0,1)*F(2,1)*F(2,2) + d[10]*pow(F(0,1),2)*F(2,1)*F(2,2) + d[25]*pow(F(0,1),2)*F(2,1)*F(2,2) + d[15]*F(0,0)*F(0,2)*F(2,1)*F(2,2) + d[20]*F(0,0)*F(0,2)*F(2,1)*F(2,2) + d[29]*F(0,0)*F(0,2)*F(2,1)*F(2,2) + d[34]*F(0,0)*F(0,2)*F(2,1)*F(2,2) + d[8]*F(0,1)*F(0,2)*F(2,1)*F(2,2) + d[13]*F(0,1)*F(0,2)*F(2,1)*F(2,2) + 2*d[28]*F(0,1)*F(0,2)*F(2,1)*F(2,2) + d[16]*pow(F(0,2),2)*F(2,1)*F(2,2) + d[26]*pow(F(0,2),2)*F(2,1)*F(2,2) + d[35]*pow(F(0,0),2)*pow(F(2,2),2) + d[29]*F(0,0)*F(0,1)*pow(F(2,2),2) + d[34]*F(0,0)*F(0,1)*pow(F(2,2),2) + d[28]*pow(F(0,1),2)*pow(F(2,2),2) + d[17]*F(0,0)*F(0,2)*pow(F(2,2),2) + d[32]*F(0,0)*F(0,2)*pow(F(2,2),2) + d[16]*F(0,1)*F(0,2)*pow(F(2,2),2) + d[26]*F(0,1)*F(0,2)*pow(F(2,2),2) + d[14]*pow(F(0,2),2)*pow(F(2,2),2); return c; }
Unknown
3D
febiosoftware/FEBio
FECore/FEDiscreteDomain.h
.h
2,205
62
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEDomain.h" //----------------------------------------------------------------------------- //! domain for discrete elements class FECORE_API FEDiscreteDomain : public FEDomain { FECORE_SUPER_CLASS(FEDISCRETEDOMAIN_ID) FECORE_BASE_CLASS(FEDiscreteDomain) public: FEDiscreteDomain(FEModel* fem) : FEDomain(FE_DOMAIN_DISCRETE, fem) {} bool Create(int nsize, FE_Element_Spec espec) override; int Elements() const override { return (int) m_Elem.size(); } FEElement& ElementRef(int n) override { return m_Elem[n]; } const FEElement& ElementRef(int n) const override { return m_Elem[n]; } FEDiscreteElement& Element(int n) { return m_Elem[n]; } bool Init() override; void Reset() override; //! copy data from another domain (overridden from FEDomain) void CopyFrom(FEMeshPartition* pd) override; public: void AddElement(int eid, int n[2]); protected: vector<FEDiscreteElement> m_Elem; };
Unknown
3D
febiosoftware/FEBio
FECore/FEMeshTopo.h
.h
3,256
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.*/ #pragma once #include "FEEdgeList.h" #include "FEFaceList.h" #include "vec3d.h" class FEMesh; class FEElement; class FESurface; //----------------------------------------------------------------------------- //! This is a helper class for looping over elements, faces (internal and external), //! and edges of a FEMesh. class FECORE_API FEMeshTopo { class MeshTopoImp; public: FEMeshTopo(); ~FEMeshTopo(); // Create the FEMeshTopo from a mesh bool Create(FEMesh* mesh); // get the mesh FEMesh* GetMesh(); // return number of elements int Elements(); // return an element FEElement* Element(int i); // get the element index (into global element array) from an element ID int GetElementIndexFromID(int elemId); // return the number of faces in the mesh int Faces(); // return a face const FEFaceList::FACE& Face(int i); // return the number of surface faces int SurfaceFaces() const; // return the number of surface faces const FEFaceList::FACE& SurfaceFace(int i) const; // return the element-face list const std::vector<int>& ElementFaceList(int nelem); // return the number of edges in the mesh int Edges(); // return an edge const FEEdgeList::EDGE& Edge(int i); // return the face-edge list const std::vector<int>& FaceEdgeList(int nface); // return the element-edge list const std::vector<int>& ElementEdgeList(int nelem); // return the list of face indices of a surface std::vector<int> FaceIndexList(FESurface& s); // return the list of face indices of a surface std::vector<int> SurfaceFaceIndexList(FESurface& s); // return the element neighbor list std::vector<FEElement*> ElementNeighborList(int i); // return the element neighbor index list std::vector<int> ElementNeighborIndexList(int i); // find neighboring elements that fall within given proximity d std::vector<int> ElementProximityList(int i, double d, bool excludeSelf = true, bool matchMaterial = true); private: MeshTopoImp* imp; };
Unknown
3D
febiosoftware/FEBio
FECore/DataRecord.h
.h
3,509
114
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <stdio.h> #include <string> #include <vector> #include <stdexcept> #include "FECoreBase.h" #include "FELogData.h" #include "fecore_api.h" //----------------------------------------------------------------------------- // forward declaration class FEModel; class DumpStream; class FEItemList; //----------------------------------------------------------------------------- enum FEDataRecordType { FE_DATA_NODE = 0x01, FE_DATA_FACE, FE_DATA_ELEM, FE_DATA_RB, FE_DATA_NLC, FE_DATA_SURFACE, FE_DATA_DOMAIN, FE_DATA_MODEL }; //----------------------------------------------------------------------------- // Exception thrown when parsing fails class FECORE_API UnknownDataField : public std::runtime_error { public: UnknownDataField(const char* sz); }; //----------------------------------------------------------------------------- class FECORE_API DataRecord : public FECoreBase { FECORE_SUPER_CLASS(FEDATARECORD_ID) FECORE_BASE_CLASS(DataRecord) public: enum {MAX_DELIM=16, MAX_STRING=1024}; public: DataRecord(FEModel* pfem, int ntype); virtual ~DataRecord(); bool SetFileName(const char* szfile); bool Write(); void SetItemList(const std::vector<int>& items); virtual void SetItemList(FEItemList* itemList, const std::vector<int>& selection); void SetName(const char* sz); void SetDelim(const char* sz); void SetFormat(const char* sz); void SetComments(bool b) { m_bcomm = b; } public: virtual bool Initialize(); virtual double Evaluate(int item, int ndata) = 0; virtual void SelectAllItems() = 0; virtual void Serialize(DumpStream& ar); virtual void SetData(const char* sz) = 0; virtual int Size() const = 0; private: std::string printToString(int i); std::string printToFormatString(int i); public: int m_nid; //!< ID of data record std::vector<int> m_item; //!< item list int m_type; //!< type of data record protected: bool m_bcomm; //!< export comments or not char m_szname[MAX_STRING]; //!< name of expression char m_szdelim[MAX_DELIM]; //!< data delimitor char m_szdata[MAX_STRING]; //!< data expression char m_szfmt[MAX_STRING]; //!< max format string protected: char m_szfile[MAX_STRING]; //!< file name of data record FILE* m_fp; };
Unknown
3D
febiosoftware/FEBio
FECore/EigenSolver.cpp
.cpp
1,451
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 "EigenSolver.h" #include "fecore_enum.h" EigenSolver::EigenSolver(FEModel* fem) : FECoreBase(fem) { } bool EigenSolver::Init() { return true; }
C++
3D
febiosoftware/FEBio
FECore/CompactMatrix.h
.h
2,942
99
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "SparseMatrix.h" #include "CSRMatrix.h" //============================================================================= //! This class stores a sparse matrix in Harwell-Boeing format. //! This is the base class for the symmetric and unsymmetric classes class FECORE_API CompactMatrix : public SparseMatrix { public: //! constructor CompactMatrix( int offset ); //! destructor virtual ~CompactMatrix(); //! zero matrix elements void Zero() override; //! Clear void Clear() override; public: //! Pointer to matrix values double* Values () override { return m_pd; } //! Pointer to matrix indices int* Indices() override { return m_pindices; } //! pointer to matrix row pointers int* Pointers() override { return m_ppointers; } //! return the index offset (is 0 or 1) int Offset() const override { return m_offset; } public: //! Create the matrix void alloc(int nr, int nc, int nz, double* pv, int *pi, int* pp, bool bdel = true); //! is the matrix symmetric or not virtual bool isSymmetric() = 0; //! is this a row-based format or not virtual bool isRowBased() = 0; public: //! Calculate the infinity norm virtual double infNorm() const = 0; //! calculate the one norm virtual double oneNorm() const = 0; //! calculate bandwidth of matrix int bandWidth(); //! count the actual nr. of nonzeroes size_t actualNonZeroes(); protected: double* m_pd; //!< matrix values int* m_pindices; //!< indices int* m_ppointers; //!< pointers int m_offset; //!< adjust array indices for fortran arrays bool m_bdel; //!< delete data arrays in destructor protected: std::vector<int> P; };
Unknown
3D
febiosoftware/FEBio
FECore/FEElementShape.cpp
.cpp
1,468
36
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEElementShape.h" FEElementShape::FEElementShape(FE_Element_Shape eshape, int nodes) : m_shape(eshape), m_nodes(nodes) { } FEElementShape::~FEElementShape() { }
C++
3D
febiosoftware/FEBio
FECore/eig3.cpp
.cpp
6,914
291
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 <math.h> #ifdef MAX #undef MAX #endif #define MAX(a, b) ((a)>(b)?(a):(b)) #define n 3 static double hypot2(double x, double y) { return sqrt(x*x+y*y); } // Symmetric Householder reduction to tridiagonal form. static void tred2(double V[n][n], double d[n], double e[n]) { // This is derived from the Algol procedures tred2 by // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding // Fortran subroutine in EISPACK. for (int j = 0; j < n; j++) { d[j] = V[n-1][j]; } // Householder reduction to tridiagonal form. for (int i = n-1; i > 0; i--) { // Scale to avoid under/overflow. double scale = 0.0; double h = 0.0; for (int k = 0; k < i; k++) { scale = scale + fabs(d[k]); } if (scale == 0.0) { e[i] = d[i-1]; for (int j = 0; j < i; j++) { d[j] = V[i-1][j]; V[i][j] = 0.0; V[j][i] = 0.0; } } else { // Generate Householder vector. for (int k = 0; k < i; k++) { d[k] /= scale; h += d[k] * d[k]; } double f = d[i-1]; double g = sqrt(h); if (f > 0) { g = -g; } e[i] = scale * g; h = h - f * g; d[i-1] = f - g; for (int j = 0; j < i; j++) { e[j] = 0.0; } // Apply similarity transformation to remaining columns. for (int j = 0; j < i; j++) { f = d[j]; V[j][i] = f; g = e[j] + V[j][j] * f; for (int k = j+1; k <= i-1; k++) { g += V[k][j] * d[k]; e[k] += V[k][j] * f; } e[j] = g; } f = 0.0; for (int j = 0; j < i; j++) { e[j] /= h; f += e[j] * d[j]; } double hh = f / (h + h); for (int j = 0; j < i; j++) { e[j] -= hh * d[j]; } for (int j = 0; j < i; j++) { f = d[j]; g = e[j]; for (int k = j; k <= i-1; k++) { V[k][j] -= (f * e[k] + g * d[k]); } d[j] = V[i-1][j]; V[i][j] = 0.0; } } d[i] = h; } // Accumulate transformations. for (int i = 0; i < n-1; i++) { V[n-1][i] = V[i][i]; V[i][i] = 1.0; double h = d[i+1]; if (h != 0.0) { for (int k = 0; k <= i; k++) { d[k] = V[k][i+1] / h; } for (int j = 0; j <= i; j++) { double g = 0.0; for (int k = 0; k <= i; k++) { g += V[k][i+1] * V[k][j]; } for (int k = 0; k <= i; k++) { V[k][j] -= g * d[k]; } } } for (int k = 0; k <= i; k++) { V[k][i+1] = 0.0; } } for (int j = 0; j < n; j++) { d[j] = V[n-1][j]; V[n-1][j] = 0.0; } V[n-1][n-1] = 1.0; e[0] = 0.0; } // Symmetric tridiagonal QL algorithm. static void tql2(double V[n][n], double d[n], double e[n]) { // This is derived from the Algol procedures tql2, by // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding // Fortran subroutine in EISPACK. for (int i = 1; i < n; i++) { e[i-1] = e[i]; } e[n-1] = 0.0; double f = 0.0; double tst1 = 0.0; double eps = pow(2.0,-52.0); for (int l = 0; l < n; l++) { // Find small subdiagonal element tst1 = MAX(tst1,fabs(d[l]) + fabs(e[l])); int m = l; while (m < n) { if (fabs(e[m]) <= eps*tst1) { break; } m++; } // If m == l, d[l] is an eigenvalue, // otherwise, iterate. if (m > l) { int iter = 0; do { iter = iter + 1; // (Could check iteration count here.) // Compute implicit shift double g = d[l]; double p = (d[l+1] - g) / (2.0 * e[l]); double r = hypot2(p,1.0); if (p < 0) { r = -r; } d[l] = e[l] / (p + r); d[l+1] = e[l] * (p + r); double dl1 = d[l+1]; double h = g - d[l]; for (int i = l+2; i < n; i++) { d[i] -= h; } f = f + h; // Implicit QL transformation. p = d[m]; double c = 1.0; double c2 = c; double c3 = c; double el1 = e[l+1]; double s = 0.0; double s2 = 0.0; for (int i = m-1; i >= l; i--) { c3 = c2; c2 = c; s2 = s; g = c * e[i]; h = c * p; r = hypot2(p,e[i]); e[i+1] = s * r; s = e[i] / r; c = p / r; p = c * d[i] - s * g; d[i+1] = h + s * (c * g + s * d[i]); // Accumulate transformation. for (int k = 0; k < n; k++) { h = V[k][i+1]; V[k][i+1] = s * V[k][i] + c * h; V[k][i] = c * V[k][i] - s * h; } } p = -s * s2 * c3 * el1 * e[l] / dl1; e[l] = s * p; d[l] = c * p; // Check for convergence. } while (fabs(e[l]) > eps*tst1); } d[l] = d[l] + f; e[l] = 0.0; } // Sort eigenvalues and corresponding vectors. for (int i = 0; i < n-1; i++) { int k = i; double p = d[i]; for (int j = i+1; j < n; j++) { if (d[j] < p) { k = j; p = d[j]; } } if (k != i) { d[k] = d[i]; d[i] = p; for (int j = 0; j < n; j++) { p = V[j][i]; V[j][i] = V[j][k]; V[j][k] = p; } } } } void eigen_decomposition(double A[n][n], double V[n][n], double d[n]) { double e[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { V[i][j] = A[i][j]; } } tred2(V, d, e); tql2(V, d, e); }
C++
3D
febiosoftware/FEBio
FECore/FESurfaceMap.cpp
.cpp
9,463
358
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FESurfaceMap.h" #include "FESurface.h" #include "DumpStream.h" #include "FEMesh.h" //----------------------------------------------------------------------------- FESurfaceMap::FESurfaceMap() : FEDataMap(FE_SURFACE_MAP) { m_maxFaceNodes = 0; m_format = FMT_MULT; } //----------------------------------------------------------------------------- FESurfaceMap::FESurfaceMap(FEDataType dataType) : FEDataMap(FE_SURFACE_MAP, dataType) { m_maxFaceNodes = 0; m_format = FMT_MULT; } //----------------------------------------------------------------------------- FESurfaceMap::FESurfaceMap(const FESurfaceMap& map) : FEDataMap(map) { m_maxFaceNodes = map.m_maxFaceNodes; m_format = map.m_format; } //----------------------------------------------------------------------------- FESurfaceMap& FESurfaceMap::operator = (const FESurfaceMap& map) { FEDataArray::operator=(map); m_name = map.m_name; m_maxFaceNodes = map.m_maxFaceNodes; return *this; } //----------------------------------------------------------------------------- // return the item list associated with this map FEItemList* FESurfaceMap::GetItemList() { return const_cast<FEFacetSet*>(m_surf); } //----------------------------------------------------------------------------- int FESurfaceMap::StorageFormat() const { return m_format; } //----------------------------------------------------------------------------- bool FESurfaceMap::Create(const FEFacetSet* ps, double val, Storage_Fmt fmt) { m_surf = ps; m_format = fmt; if (fmt == FMT_MULT) { int NF = ps->Faces(); m_maxFaceNodes = 0; for (int i = 0; i < NF; ++i) { const FEFacetSet::FACET& f = ps->Face(i); // TODO: currently, the number of nodes matches the type, but not sure if this will remain the case. if (f.ntype > m_maxFaceNodes) m_maxFaceNodes = f.ntype; } return resize(NF*m_maxFaceNodes, val); } else if (fmt == FMT_NODE) { FENodeList nodeList = ps->GetNodeList(); int NN = nodeList.Size(); m_maxFaceNodes = 1; return resize(NN, val); } else return false; } //----------------------------------------------------------------------------- void FESurfaceMap::setValue(int n, double v) { int index = n*m_maxFaceNodes; for (int i=0; i<m_maxFaceNodes; ++i) set<double>(index+i, v); } //----------------------------------------------------------------------------- void FESurfaceMap::setValue(int n, const vec2d& v) { int index = n*m_maxFaceNodes; for (int i = 0; i<m_maxFaceNodes; ++i) set<vec2d>(index + i, v); } //----------------------------------------------------------------------------- void FESurfaceMap::setValue(int n, const vec3d& v) { int index = n*m_maxFaceNodes; for (int i = 0; i<m_maxFaceNodes; ++i) set<vec3d>(index + i, v); } //----------------------------------------------------------------------------- void FESurfaceMap::setValue(int n, const mat3d& v) { int index = n*m_maxFaceNodes; for (int i = 0; i<m_maxFaceNodes; ++i) set<mat3d>(index + i, v); } //----------------------------------------------------------------------------- void FESurfaceMap::setValue(int n, const mat3ds& v) { int index = n * m_maxFaceNodes; for (int i = 0; i < m_maxFaceNodes; ++i) set<mat3ds>(index + i, v); } //----------------------------------------------------------------------------- void FESurfaceMap::fillValue(double v) { set<double>(v); } //----------------------------------------------------------------------------- void FESurfaceMap::fillValue(const vec2d& v) { set<vec2d>(v); } //----------------------------------------------------------------------------- void FESurfaceMap::fillValue(const vec3d& v) { set<vec3d>(v); } //----------------------------------------------------------------------------- void FESurfaceMap::fillValue(const mat3d& v) { set<mat3d>(v); } //----------------------------------------------------------------------------- void FESurfaceMap::fillValue(const mat3ds& v) { set<mat3ds>(v); } //----------------------------------------------------------------------------- void FESurfaceMap::Serialize(DumpStream& ar) { FEDataMap::Serialize(ar); if (ar.IsShallow()) return; ar & m_maxFaceNodes & m_format; if (ar.IsSaving()) { FEFacetSet* fs = const_cast<FEFacetSet*>(m_surf); ar << fs; } else { FEFacetSet* fs = nullptr; ar >> fs; m_surf = fs; } } //----------------------------------------------------------------------------- double FESurfaceMap::value(const FEMaterialPoint& pt) { double v = 0.0; switch (m_format) { case FMT_NODE: { if (pt.m_elem) { // get the element this material point is in FESurfaceElement* pe = dynamic_cast<FESurfaceElement*>(pt.m_elem); assert(pe); // make sure this element belongs to this domain // TODO: Can't check this if map was created through FEFacetSet // assert(pe->GetMeshPartition() == m_dom); if (pt.m_index < 0x10000) { // integration point // get shape functions double* H = pe->H(pt.m_index); int ne = pe->Nodes(); for (int i = 0; i < ne; ++i) { double vi = value<double>(pe->m_lnode[i], 0); v += vi * H[i]; } } else { // element node int n = pt.m_index - 0x10000; v = value<double>(pe->m_lnode[n], 0); } return v; } else { // assume material point is a node return value<double>(pt.m_index, 0); } } break; case FMT_MULT: { // get the element this material point is in FESurfaceElement* pe = dynamic_cast<FESurfaceElement*>(pt.m_elem); assert(pe); // make sure this element belongs to this domain // TODO: Can't check this if map was created through FEFacetSet // assert(pe->GetMeshPartition() == m_dom); // get its local ID int lid = pe->GetLocalID(); // get shape functions if (pt.m_index < 0x10000) { double* H = pe->H(pt.m_index); int ne = pe->Nodes(); for (int i = 0; i < ne; ++i) { double vi = value<double>(lid, i); v += vi * H[i]; } } else { // element node int n = pt.m_index - 0x10000; v = value<double>(lid, n); } } break; } return v; } //----------------------------------------------------------------------------- vec3d FESurfaceMap::valueVec3d(const FEMaterialPoint& pt) { // get the element this material point is in FESurfaceElement* pe = dynamic_cast<FESurfaceElement*>(pt.m_elem); assert(pe); // make sure this element belongs to this domain // TODO: Can't check this if map was created through FEFacetSet // assert(pe->GetMeshPartition() == m_dom); // get its local ID int lid = pe->GetLocalID(); // get shape functions double* H = pe->H(pt.m_index); vec3d v(0,0,0); int ne = pe->Nodes(); for (int i = 0; i < ne; ++i) { vec3d vi = value<vec3d>(lid, i); v += vi*H[i]; } return v; } //----------------------------------------------------------------------------- mat3d FESurfaceMap::valueMat3d(const FEMaterialPoint& pt) { // get the element this material point is in FESurfaceElement* pe = dynamic_cast<FESurfaceElement*>(pt.m_elem); assert(pe); // make sure this element belongs to this domain // TODO: Can't check this if map was created through FEFacetSet // assert(pe->GetMeshPartition() == m_dom); // get its local ID int lid = pe->GetLocalID(); // get shape functions double* H = pe->H(pt.m_index); mat3d v; v.zero(); int ne = pe->Nodes(); for (int i = 0; i < ne; ++i) { mat3d vi = value<mat3d>(lid, i); v += vi*H[i]; } return v; } //----------------------------------------------------------------------------- mat3ds FESurfaceMap::valueMat3ds(const FEMaterialPoint& pt) { // get the element this material point is in FESurfaceElement* pe = dynamic_cast<FESurfaceElement*>(pt.m_elem); assert(pe); // make sure this element belongs to this domain // TODO: Can't check this if map was created through FEFacetSet // assert(pe->GetMeshPartition() == m_dom); // get its local ID int lid = pe->GetLocalID(); // get shape functions double* H = pe->H(pt.m_index); mat3ds v; v.zero(); int ne = pe->Nodes(); for (int i = 0; i < ne; ++i) { mat3ds vi = value<mat3ds>(lid, i); v += vi * H[i]; } return v; }
C++
3D
febiosoftware/FEBio
FECore/FEVec3dValuator.cpp
.cpp
1,399
36
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEVec3dValuator.h" FEVec3dValuator::FEVec3dValuator(FEModel* fem) : FEValuator(fem) { };
C++
3D
febiosoftware/FEBio
FECore/MObjBuilder.cpp
.cpp
25,878
1,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.*/ #include "stdafx.h" #include "MObjBuilder.h" #include "MMath.h" #include "MEvaluate.h" #include "MFunctions.h" #include "assert.h" #include <map> #include <string> #include <math.h> using namespace std; map<string, FUNCPTR> FNC; // 1-D functions map<string, FUNC2PTR> FNC2; // 2-D functions map<string, FUNCNPTR> FNCN; // N-D functions map<string, FUNCMATPTR> FMAT; // Matrix functions map<string, double> CNT; // predefined constants void init_function_lists() { // 1-parameter functions FNC["cos" ] = cos; FNC["sin" ] = sin; FNC["tan" ] = tan; FNC["csc" ] = csc; FNC["sec" ] = sec; FNC["cot" ] = cot; FNC["acos" ] = acos; FNC["asin" ] = asin; FNC["atan" ] = atan; FNC["cosh" ] = cosh; FNC["sinh" ] = sinh; FNC["tanh" ] = tanh; FNC["acosh"] = acosh; FNC["ln" ] = log; FNC["log" ] = log10; FNC["exp" ] = exp; FNC["sqrt" ] = sqrt; FNC["abs" ] = fabs; FNC["sgn" ] = sgn; FNC["H" ] = heaviside; FNC["step" ] = unit_step; #ifdef WIN32 FNC["J0" ] = _j0; FNC["J1" ] = _j1; FNC["Y0" ] = _y0; FNC["Y1" ] = _y1; #endif FNC["sinc" ] = sinc; FNC["fl" ] = fl; FNC["fac" ] = fac; FNC["erf" ] = erf; FNC["erfc" ] = erfc; FNC["tgamma"] = tgamma; // 2-parameter functions #ifdef WIN32 FNC2["Jn" ] = jn; FNC2["Yn" ] = yn; #endif FNC2["atan2"] = atan2; FNC2["pow" ] = pow; FNC2["mod" ] = fmod; FNC2["Tn"] = chebyshev; FNC2["binomial"] = binomial; // n-parameter functions FNCN["max"] = fmax; FNCN["min"] = fmin; FNCN["avg"] = avg; // Matrix functions FMAT["transpose"] = matrix_transpose; FMAT["trace" ] = matrix_trace; FMAT["det" ] = matrix_determinant; FMAT["inverse" ] = matrix_inverse; // predefined constants CNT["pi" ] = 3.1415926535897932385; // "pi" CNT["e" ] = 2.7182818284590452354; // exp(1) CNT["gamma"] = 0.57721566490153286061; // Euler-Mascheroni constant CNT["_inf_"] = 1e308; // "infinity" } //----------------------------------------------------------------------------- bool MObjBuilder::Add1DFunction(const std::string& name, double (*f)(double)) { if (FNC.find(name) != FNC.end()) return false; FNC[name] = f; return true; } //----------------------------------------------------------------------------- MObjBuilder::MObjBuilder() { static bool bfirst = true; if (bfirst) init_function_lists(); bfirst = false; m_autoVars = true; } //----------------------------------------------------------------------------- char* find_next(char* sz) { char* ch = sz; int l = 0; while (*ch) { if (*ch == '(') l++; else if (*ch == ')') l--; else if ((*ch == ',') && (l==0)) return ch; ++ch; } return 0; } //----------------------------------------------------------------------------- bool string_replace(string& s, const std::string& in, const std::string& out) { size_t n = s.find(in); if (n != string::npos) { s.replace(n, in.size(), out); return true; } else return false; } //----------------------------------------------------------------------------- // process string substitutions // Math expressions can be defined with string literals, which will be substituted // in the last statement. // e.g. // s = a + b; 2*s // will be replaced by: s*(a+b) std::string MObjBuilder::processStrings(const std::string& ex) { // remove white space string tmp; for (size_t i = 0; i < ex.size(); ++i) { char c = ex[i]; if (isspace(c) == 0) tmp.push_back(c); } // keep track of string subs std::map<string, string> subs; // build string sub list size_t lp = 0; size_t l1 = tmp.find(';', lp); while (l1 != std::string::npos) { size_t equalSign = tmp.find('=', lp); string leftVal = tmp.substr(lp, equalSign - lp); string rightVal = tmp.substr(equalSign + 1, l1 - equalSign - 1); subs[leftVal] = rightVal; lp = l1 + 1; l1 = tmp.find(';', lp); } string out = tmp.substr(lp); bool b = true; while (b) { std::map<string, string>::iterator it = subs.begin(); b = false; for (; it != subs.end(); ++it) { string rep = "(" + it->second + ")"; bool ret = string_replace(out, it->first, rep); if (ret) b = true; } } return out; } //----------------------------------------------------------------------------- bool MObjBuilder::Create(MSimpleExpression* mo, const std::string& expression, bool beval) { // process the strins for string substitutions std::string ex = processStrings(expression); // make a copy of the original string char szcopy[512] = { 0 }; strcpy(szcopy, ex.c_str()); m_szexpr = m_szorg = szcopy; // keep pointer to object being constructed m_po = mo; // let's build a simple expression try { MITEM i = create(); if (beval) i = MEvaluate(i); mo->SetExpression(i); } catch (MathError e) { fprintf(stderr, "Error evaluating math expression: %s (position %d)\n", e.GetErrorStr(), e.GetPosition()); return false; } catch (...) { fprintf(stderr, "Error evaluating math expression: (unknown)\n"); return false; } return true; } //----------------------------------------------------------------------------- // Convert a string to a math object MathObject* MObjBuilder::Create(const std::string& ex, bool beval) { // make a copy of the original string char szcopy[512] = {0}; strcpy(szcopy, ex.c_str()); m_szexpr = m_szorg = szcopy; m_po = 0; // let's build a simple expression MSimpleExpression* pe = new MSimpleExpression; m_po = pe; MITEM i = create(); if (beval) i = MEvaluate(i); pe->SetExpression(i); return m_po; } //----------------------------------------------------------------------------- MItem* MObjBuilder::sequence() { MSequence* ps = new MSequence; do { MItem* pi = create(); ps->add(pi); } while (curr_tok == COMMA); return ps; } //----------------------------------------------------------------------------- MItem* MObjBuilder::create() { MItem* pi = expr(); for (;;) { switch(curr_tok) { case EQUAL: pi = new MEquation(pi, expr()); break; case EQUALITY: pi = new MEquality(pi, expr()); break; /* case COMMA: { MSequence* pe = dynamic_cast<MSequence*>(pi); if (pe == 0) { pe = new MSequence; pe->add(pi); } pe->add(expr()); pi = pe; } break; */ default: return pi; } } } //----------------------------------------------------------------------------- MItem* MObjBuilder::create_sequence() { MItem* pi = expr(); for (;;) { switch(curr_tok) { case EQUAL: pi = new MEquation(pi, expr()); break; case COMMA: { MSequence* pe = dynamic_cast<MSequence*>(pi); if (pe == 0) { pe = new MSequence; pe->add(pi); } pe->add(expr()); pi = pe; } break; default: return pi; } } } //----------------------------------------------------------------------------- MItem* MObjBuilder::expr() { MItem* pi = term(); for (;;) { switch(curr_tok) { case PLUS: pi = new MAdd(pi, term()); break; case MINUS: pi = new MSub(pi, term()); break; default: return pi; } } } //----------------------------------------------------------------------------- MItem* MObjBuilder::term() { MItem* pi = power(); for (;;) switch(curr_tok) { case MUL: pi = new MMul(pi, power()); break; case DIV: pi = new MDiv(pi, power()); break; case CONTRACT: { MMatrix* pl = mmatrix(pi); if (pl == 0) throw MathError(Position(), "invalid left term"); MMatrix* pr = mmatrix(power()); if (pr == 0) throw MathError(Position(), "invalid right term"); pi = new MFuncMat2(matrix_contract, "contract", pl, pr); } break; default: return pi; } } //----------------------------------------------------------------------------- MItem* MObjBuilder::power() { MItem* pi = prim(); for (;;) switch(curr_tok) { case POW: pi = new MPow(pi, prim()); break; default: return pi; } } //----------------------------------------------------------------------------- MItem* MObjBuilder::prim() { MItem* pi = 0; get_token(); switch (curr_tok) { case NUMBER: { pi = new MConstant(number_value); get_token(); } break; case NAME: { string s(string_value); get_token(); // if the next token is a left bracket, let's assume it's a function if (curr_tok == LP) { pi = func(); if (pi == 0) throw MathError(Position(), "Unknown function"); } else { pi = var(); if (is_matrix(pi)) { // we might be extracting the component of a matrix if (curr_tok == LB) { MSequence* pe = dynamic_cast<MSequence*>(sequence()); read_token(RB); if (pe == 0) { delete pe; throw MathError(Position(), "comma expected"); } MSequence& e = *pe; if (e.size() != 2) throw MathError(Position(), "syntax error"); const MConstant* pc0 = mconst(e[0]); if ((pc0 == 0) || (is_int(pc0->value()) == false)) throw MathError(Position(), "syntax error"); const MConstant* pc1 = mconst(e[1]); if ((pc1 == 0) || (is_int(pc1->value()) == false)) throw MathError(Position(), "syntax error"); int i = (int)(pc0->value()); int j = (int)(pc1->value()); const MMatrix& m = *mmatrix(pi); int nr = m.rows(); int nc = m.columns(); if ((i<0)||(i>=nr)) throw MathError(Position(), "invalid matrix component"); if ((j<0)||(j>=nc)) throw MathError(Position(), "invalid matrix component"); pi = (m[i][j]->copy()); delete pe; } } } } break; case MINUS: { pi = new MNeg(power()); } break; case LP: { pi = create(); read_token(RP); // eat ')' } break; case LC: { pi = sequence(); if (pi == 0) { throw MathError(Position(), "comma expected"); } read_token(RC); } break; case LB: { MSequence* pe = dynamic_cast<MSequence*>(sequence()); if (pe == 0) { delete pe; throw MathError(Position(), "comma expected"); } MSequence& e = *pe; read_token(RB); if (is_matrix(e[0])) { int nrow = e.size(); int ncol = mmatrix(e[0])->columns(); int N = e.size(); for (int i=0; i<N; ++i) { const MMatrix* pm = mmatrix(e[i]); if (pm == 0) throw MathError(Position(), "invalid matrix definition"); if (pm->columns() != ncol) throw MathError(Position(), "invalid matrix definition"); if (pm->rows() != 1) throw MathError(Position(), "invalid matrix definition"); } MMatrix* pm = new MMatrix(); pm->Create(nrow, ncol); for (int i=0; i<nrow; ++i) for (int j=0; j<ncol; ++j) { const MMatrix* pk = mmatrix(e[i]); (*pm)[i][j] = (*pk)[0][j]->copy(); } pi = pm; } else { MMatrix* pm = new MMatrix(); int ncol = e.size(); pm->Create(1, ncol); for (int i=0; i<ncol; ++i) (*pm)[0][i] = e[i]->copy(); pi = pm; } delete pe; } break; case AB: { pi = new MFunc1D(fabs, "abs", create()); if (curr_tok != AB) throw MathError(Position(), "'|' expected"); get_token(); // eat '|' } break; default: throw MathError(Position(), "Token expected"); } assert(pi); // look for post-operators do { if (curr_tok == FACT) { pi = new MFunc1D(fac, "fac", pi); get_token(); // eat '!' } else if (curr_tok == TRANS) { pi = new MFuncMat(matrix_transpose, "transpose", pi); get_token(); // eat ''' } else break; } while (true); return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::var() { string s(string_value); MItem* pi = 0; // see if it is a predefined variable map<string, double>::iterator pc = CNT.find(s); if (pc != CNT.end()) { pi = new MNamedCt(pc->second, pc->first); } else { // see if it is a user variable MVariable* pvar = m_po->FindVariable(s); if (pvar == 0) { if (m_autoVars == false) throw MathError(Position(), "Unknown variable"); // create a new variable pvar = new MVariable(s); m_po->AddVariable(pvar); } pi = new MVarRef(pvar); } return pi; } //----------------------------------------------------------------------------- // parse a function MItem* MObjBuilder::func() { MItem* pi = 0; pi = fncnd(); if (pi == 0) pi = fnc1d(); if (pi == 0) pi = fnc2d(); if (pi == 0) pi = fmat(); if (pi == 0) pi = fsym(); return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::fnc1d() { MItem* pi = 0; string s(string_value); map<string, FUNCPTR>::iterator pf = FNC.find(s); if (pf != FNC.end()) { FUNCPTR fnc = pf->second; if (curr_tok != LP) throw MathError(Position(), "'(' expected"); pi = new MFunc1D(fnc, pf->first, create()); if (curr_tok != RP) throw MathError(Position(), "')' expected"); get_token(); } return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::fnc2d() { MItem* pi = 0; string s(string_value); map<string, FUNC2PTR>::iterator pf = FNC2.find(s); if (pf != FNC2.end()) { FUNC2PTR fnc = pf->second; MItem *p1, *p2; p1 = create(); if (curr_tok != COMMA) throw MathError(Position(), "',' expected"); p2 = create(); pi = new MFunc2D(fnc, pf->first, p1, p2); if (curr_tok != RP) throw MathError(Position(), "')' expected"); get_token(); } return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::fncnd() { MItem* pi = 0; string s(string_value); map<string, FUNCNPTR>::iterator pf = FNCN.find(s); if (pf != FNCN.end()) { FUNCNPTR fnc = pf->second; MSequence pl; do { pl.add(create()); } while (curr_tok == COMMA); if (curr_tok != RP) throw MathError(Position(), "')' expected"); get_token(); pi = new MFuncND(fnc, pf->first, pl); } return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::fmat() { MItem* pi = 0; string s(string_value); map<string, FUNCMATPTR>::iterator pf = FMAT.find(s); if (pf != FMAT.end()) { FUNCMATPTR fnc = pf->second; if (curr_tok != LP) throw MathError(Position(), "'(' expected"); pi = new MFuncMat(fnc, pf->first, create()); if (curr_tok != RP) throw MathError(Position(), "')' expected"); get_token(); } return pi; } //----------------------------------------------------------------------------- // Read a symbolic function. MItem* MObjBuilder::fsym() { string s(string_value); if (s.compare("derive" ) == 0) return derive (); else if (s.compare("replace" ) == 0) return replace (); else if (s.compare("taylor" ) == 0) return taylor (); else if (s.compare("integrate") == 0) return integrate(); else if (s.compare("expand" ) == 0) return expand (); else if (s.compare("simplify" ) == 0) return simplify (); else if (s.compare("solve" ) == 0) return solve (); else if (s.compare("collect" ) == 0) return collect (); else if (s.compare("identity" ) == 0) return identity (); else if (s.compare("mdiag" ) == 0) return mdiag (); return 0; } //----------------------------------------------------------------------------- MObjBuilder::Token_value MObjBuilder::get_token() { // remove leading whitespace while ((*m_szexpr==' ') || (*m_szexpr=='\t')) m_szexpr++; // get the first character char ch = *m_szexpr++; switch(ch) { case 0: return curr_tok = END; case '^': case '*': case '/': case '+': case '-': case '(': case ')': case '[': case ']': case '{': case '}': case '%': case ',': case '|': case '!': case '\'': case ':': return curr_tok = Token_value(ch); case '=': if (*m_szexpr=='=') { m_szexpr++; return curr_tok = EQUALITY; } else return curr_tok = EQUAL; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': m_szexpr--; number_value = get_number(); return curr_tok = NUMBER; case '$': { if (*m_szexpr != '{') throw MathError(Position(), "'{' expected"); m_szexpr++; int n = 0; string_value[0] = 0; while ((*m_szexpr) && (*m_szexpr != '}')) string_value[n++] = *m_szexpr++; string_value[n] = 0; if (*m_szexpr != '}') throw MathError(Position(), "'}' expected"); m_szexpr++; } return curr_tok = NAME; default: if (isalpha(ch)||(ch=='_')) { m_szexpr--; get_name(string_value); return curr_tok = NAME; } throw MathError(Position(), "Bad token"); return curr_tok=PRINT; } } double MObjBuilder::get_number() { const char* ch = m_szexpr; // read first digits while (isdigit(*ch)) ch++; if (*ch == '.') { // read more digits after decimal point ch++; while (isdigit(*ch)) ch++; } // see if we're using exp notation if ((*ch == 'E') || (*ch == 'e')) { ch++; if ((*ch == '-') || (*ch == '+')) ch++; // read digits while (isdigit(*ch)) ch++; } double val = atof(m_szexpr); m_szexpr = ch; return val; } void MObjBuilder::get_name(char* str) { int n = 0; bool binside = false; while (isalnum(*m_szexpr) || (*m_szexpr == '_') || (*m_szexpr == '.') || (*m_szexpr == '{') || ((*m_szexpr == '}')&&binside) || binside) { if (*m_szexpr == '{') binside = true; if (*m_szexpr == '}') binside = false; str[n++] = *m_szexpr++; } str[n] = 0; } //----------------------------------------------------------------------------- // Check's to see if the current token is void MObjBuilder::read_token(MObjBuilder::Token_value n, bool bnext) { switch (n) { case COMMA : if (curr_tok != COMMA ) throw MathError(Position(), "',' expected"); break; case NAME : if (curr_tok != NAME ) throw MathError(Position(), "syntax error"); break; case NUMBER: if (curr_tok != NUMBER) throw MathError(Position(), "syntax error"); break; case RP : if (curr_tok != RP ) throw MathError(Position(), "')' expected"); break; case LC : if (curr_tok != LC ) throw MathError(Position(), "'{' expected"); break; case RC : if (curr_tok != RC ) throw MathError(Position(), "'}' expected"); break; case RB : if (curr_tok != RB ) throw MathError(Position(), "']' expected"); break; } if (bnext) get_token(); } //----------------------------------------------------------------------------- // Read a variable name; assuming the current token is indeed a variable MVariable* MObjBuilder::read_var(bool badd) { // read the name token read_token(NAME); // get the variable MVariable* pv = m_po->FindVariable(string_value); if (pv == 0) { if (badd) { pv = new MVariable(string_value); m_po->AddVariable(pv); } else throw MathError(Position(), "unknown variable"); } return pv; } //----------------------------------------------------------------------------- // Read an integer number int MObjBuilder::read_int() { read_token(NUMBER); double f = number_value; if (f - floor(f) != 0) throw MathError(Position(), "integer expected"); return (int) f; } //----------------------------------------------------------------------------- // Read a double number double MObjBuilder::read_double() { read_token(NUMBER); return number_value; } //----------------------------------------------------------------------------- // read a mathematical expression MItem* MObjBuilder::read_math() { return create(); } //----------------------------------------------------------------------------- MItem* MObjBuilder::derive() { // read the argument MITEM e = read_math(); // read the comma read_token(COMMA, false); // find the variable MITEM v = read_math(); MItem* pi = 0; if (is_sequence(v)) { // read the parentheses read_token(RP); // calculate derivatives const MSequence& s = *msequence(v); pi = MDerive(e, s).copy(); } else { // make sure v is a variable if (is_var(v) == false) throw MathError(Position(), "This is not a variable"); const MVariable& x = *(mvar(v)->GetVariable()); // read optional arguments if (curr_tok == COMMA) { // skip the comma get_token(); if (curr_tok == NUMBER) { // read the number int n = read_int(); // make sure it is at least one if (n <= 0) throw MathError(Position(), "integer must be at least one"); read_token(RP); pi = MDerive(e, x, n).copy(); } else MathError(Position(), "number unexpected"); } else { read_token(RP); pi = MDerive(e, x).copy(); } } // return the result return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::replace() { // read the expression MITEM e = read_math(); // read the comma read_token(COMMA, false); // read the expression to replace MITEM x = read_math(); if (is_sequence(x)) { const MSequence& v = *msequence(x); // read the comma read_token(COMMA); // read the left curly bracket read_token(LC, false); // read the list of new variables const MSequence& s = *msequence(sequence()); // read the right curly bracket read_token(RC); // read the right parenthesis read_token(RP); // calculate the new expression MItem* pi = MReplace(e, v, s).copy(); // clean-up delete &s; // done return pi; } else { // read comma if (curr_tok == COMMA) { // read the second expression MITEM s = read_math(); // read the right parenthesis read_token(RP); // call replace function return MReplace(e, x, s).copy(); } else { read_token(RP); return MReplace(e,x).copy(); } } } //----------------------------------------------------------------------------- MItem* MObjBuilder::taylor() { // read the expression MITEM e = read_math(); // read comma read_token(COMMA); // read the variable name MVariable* pv = read_var(); // read comma read_token(COMMA); // read the point at which to expand the expression double z = read_double(); // read comma read_token(COMMA); // read the number of terms in taylor expansion int n = read_int(); if (n < 0) throw MathError(Position(), "integer must be larger than zero"); // read the right parenthesis read_token(RP); return MTaylor(e, *pv, z, n).copy(); } //----------------------------------------------------------------------------- MItem* MObjBuilder::integrate() { // read the expression MITEM e = read_math(); // read comma read_token(COMMA); // read the variable MVariable* pv = read_var(true); MItem* pi = 0; if (curr_tok == COMMA) { // if a comma is there we calculate the definite integral MITEM a = read_math(); read_token(COMMA, false); MITEM b = create(); read_token(RP); pi = MIntegral(e, *pv, a, b).copy(); } else { // else we calculate the indefinite integral read_token(RP); pi = MIntegral(e, *pv).copy(); } return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::expand() { // read the expression MITEM e = read_math(); MItem* pi = 0; if (curr_tok == COMMA) { MITEM s = read_math(); read_token(RP); pi = MExpand(e, s).copy(); } else { read_token(RP); pi = MExpand(e).copy(); } return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::simplify() { // read the expression MITEM e = read_math(); read_token(RP); MItem* pi = MExpand(e).copy(); return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::solve() { // read the argument MITEM e = read_math(); // read the comma read_token(COMMA, false); // find the variable MITEM v = read_math(); read_token(RP); MItem* pi = MSolve(e, v).copy(); // return the result return pi; } //----------------------------------------------------------------------------- MItem* MObjBuilder::collect() { // read the expression MITEM e = read_math(); read_token(COMMA, false); MITEM a = read_math(); read_token(RP); return MCollect(e, a).copy(); } //----------------------------------------------------------------------------- MItem* MObjBuilder::identity() { // read the expression MITEM e = read_math(); read_token(RP); if (is_int(e)) { return matrix_identity((int)e.value()); } else throw MathError(Position(), "constant expected"); return 0; } //----------------------------------------------------------------------------- MItem* MObjBuilder::mdiag() { // read the expression MSequence* pe = dynamic_cast<MSequence*>(sequence()); read_token(RP); MSequence& e = *pe; int n = pe->size(); MMatrix* pm = new MMatrix(); pm->Create(n, n); for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) { if (i == j) { const MItem* pi = e[i]; (*pm)[i][j] = pi->copy(); } else { (*pm)[i][j] = new MConstant(0.0); } } delete pe; return pm; }
C++
3D
febiosoftware/FEBio
FECore/FEDiscreteDomain.cpp
.cpp
2,789
87
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEDiscreteDomain.h" #include "FEMesh.h" #include "FEMaterial.h" //----------------------------------------------------------------------------- bool FEDiscreteDomain::Create(int nelems, FE_Element_Spec espec) { m_Elem.resize(nelems); for (int i = 0; i < nelems; ++i) { FEDiscreteElement& el = m_Elem[i]; el.SetLocalID(i); el.SetMeshPartition(this); } if (espec.etype != FE_ELEM_INVALID_TYPE) for (int i=0; i<nelems; ++i) m_Elem[i].SetType(espec.etype); return true; } //----------------------------------------------------------------------------- void FEDiscreteDomain::Reset() { for (auto& el : m_Elem) el.setActive(); } //----------------------------------------------------------------------------- bool FEDiscreteDomain::Init() { if (FEDomain::Init() == false) return false; FEMaterial* pmat = GetMaterial(); if (pmat) SetMatID(pmat->GetID() - 1); return true; } //----------------------------------------------------------------------------- void FEDiscreteDomain::CopyFrom(FEMeshPartition* pd) { FEDomain::CopyFrom(pd); FEDiscreteDomain* psd = dynamic_cast<FEDiscreteDomain*>(pd); m_Elem = psd->m_Elem; ForEachElement([=](FEElement& el) { el.SetMeshPartition(this); }); } //----------------------------------------------------------------------------- void FEDiscreteDomain::AddElement(int eid, int n[2]) { FEDiscreteElement el; el.SetType(FE_DISCRETE); el.m_node[0] = n[0]; el.m_node[1] = n[1]; el.SetID(eid); m_Elem.push_back(el); }
C++
3D
febiosoftware/FEBio
FECore/FEModule.h
.h
2,290
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) 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_api.h" #include <vector> class FEModel; class FECoreKernel; // The FEModule class defines the physics variables for a particular module class FECORE_API FEModule { class Impl; public: enum Status { EXPERIMENTAL, RELEASED }; public: FEModule(); FEModule(const char* szname, const char* szdescription = nullptr); virtual ~FEModule(); // this function must be overridden by derived classes virtual void InitModel(FEModel* fem); void AddDependency(FEModule& mod); void ClearDependencies(); std::vector<int> GetDependencies() const; int GetModuleID() const; void SetAllocID(int id); int GetAllocID() const; const char* GetName() const; const char* GetDescription() const; int GetStatus() const; bool HasDependent(int modId) const; protected: void SetStatus(FEModule::Status status); private: void SetID(int newId); void SetName(const char* szname); void SetDescription(const char* szdesc); public: Impl* im; friend class FECoreKernel; };
Unknown
3D
febiosoftware/FEBio
FECore/FENewtonSolver.h
.h
8,747
272
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FESolver.h" #include "FENewtonStrategy.h" #include "FETimeInfo.h" #include "FELineSearch.h" //----------------------------------------------------------------------------- // forward declarations class FEModel; class FEGlobalMatrix; class FELinearSystem; //----------------------------------------------------------------------------- enum QN_STRATEGY { QN_BFGS, QN_BROYDEN, QN_JFNK }; //----------------------------------------------------------------------------- struct ConvergenceInfo { int nvar; // corresponding solution variable double tol; // convergence tolerance double norm0; // initial norm double normi; // current incremental norm double norm; // current total norm double maxnorm; // the max norm ConvergenceInfo() { nvar = -1; tol = 0.0; norm0 = 0.0; normi = 0.0; norm = 0.0; maxnorm = 0.0; } bool IsConverged() const { return (tol > 0 ? normi <= (tol*tol)*norm : true); } }; //----------------------------------------------------------------------------- //! This class defines the base class for Newton-type solvers. //! The class implements the basic logic behind a newton-solver but defers some //! of the logic, especially relating to the update of the stiffness matrix to //! the FENewtonStrategy class. //! \todo there is some common functionality with the FELinearSolver. Perhaps //! I can make the FELinearSolver a base class? //! \todo Perhaps I can introduce a base class for linear search algorithms //! so that the line search strategy can be customized as well. class FECORE_API FENewtonSolver : public FESolver { public: //! constructor FENewtonSolver(FEModel* pfem); //! destrcutor ~FENewtonSolver(); //! Set the default solution strategy void SetDefaultStrategy(QN_STRATEGY qn); //! Check the zero diagonal void CheckZeroDiagonal(bool bcheck, double ztol = 0.0); public: // overloaded from FESolver //! Initialization bool Init() override; //! return number of equations int NumberOfEquations() const { return m_neq; } //! Clean up void Clean() override; //! serialization void Serialize(DumpStream& ar) override; //! Solve an analysis step bool SolveStep() override; //! rewind solver void Rewind() override; //! prep the solver for the QN updates virtual void PrepStep(); public: // Quasi-Newton methods //! call this at the start of the quasi-newton loop bool QNInit(); //! Do a qn update bool QNUpdate(); //! solve the equations using QN method (returns line search size) double QNSolve(); //! Force a stiffness reformation during next update void QNForceReform(bool b); // return line search FELineSearch* GetLineSearch(); public: //! return the stiffness matrix FEGlobalMatrix* GetStiffnessMatrix() override; //! reform the stiffness matrix bool ReformStiffness(); //! recalculates the shape of the stiffness matrix bool CreateStiffness(bool breset); //! get the RHS std::vector<double> GetLoadVector() override; //! Get the total solution vector (for current Newton iteration) virtual void GetSolutionVector(std::vector<double>& U); //! Get the total solution vector std::vector<double> GetSolutionVector() const override; public: //! do augmentations bool DoAugmentations(); //! solve the equations void SolveEquations(std::vector<double>& u, std::vector<double>& R); //! do a line search double DoLineSearch(); public: //! Set the solution strategy void SetSolutionStrategy(FENewtonStrategy* pstrategy); //! solve the linear system of equations void SolveLinearSystem(vector<double>& x, vector<double>& R); //! Do a Quasi-Newton step //! This is called from SolveStep. virtual bool Quasin(); //! calculates the global stiffness matrix (needs to be overwritten by derived classes) virtual bool StiffnessMatrix(); //! this is the new method for building the stiffness matrix virtual bool StiffnessMatrix(FELinearSystem& LS); //! calculates the global residual vector (needs to be overwritten by derived classes) virtual bool Residual(vector<double>& R) = 0; //! Check convergence. Derived classes that don't override Quasin, should implement this //! niter = iteration number //! ui = search direction //! ls = line search factor virtual bool CheckConvergence(int niter, const vector<double>& ui, double ls); //! return the linear solver LinearSolver* GetLinearSolver() override; //! Add a solution variable from a doflist void AddSolutionVariable(FEDofList* dofs, int order, const char* szname, double tol); //! Update the state of the model void Update(std::vector<double>& u) override; //! TODO: This is a helper function to get around an issue with the current implementation // regarding prescribed displacements. The purpose of this Update2 function is to update // all degrees of freedom, including prescribed ones. This is currently only used by the JFNKMatrix class. // and overridden in FESolidSolver2. virtual void Update2(const vector<double>& ui); //! Update the model virtual void UpdateModel(); public: ConvergenceInfo GetResidualConvergence() { return m_residuNorm; } ConvergenceInfo GetEnergyConvergence() { return m_energyNorm; } ConvergenceInfo GetSolutionConvergence(int n) { return m_solutionNorm[n]; } protected: bool AllocateLinearSystem(); public: // line search options FELineSearch* m_lineSearch; // solver parameters int m_maxref; //!< max nr of reformations per time step int m_force_partition; //!< Force a partition of the global matrix (e.g. for testing with BIPN solver) double m_Rtol; //!< residual convergence norm double m_Etol; //!< energy convergence norm double m_Rmin; //!< min residual value double m_Rmax; //!< max residual value // solution strategy FENewtonStrategy* m_qnstrategy; //!< class handling the specific stiffness update logic bool m_breformtimestep; //!< reform at start of time step bool m_breformAugment; //!< reform after each (failed) augmentations bool m_bforceReform; //!< forces a reform in QNInit bool m_bdivreform; //!< reform when diverging bool m_bdoreforms; //!< do reformations // counters int m_nref; //!< nr of stiffness retormations // Error handling bool m_bzero_diagonal; //!< check for zero diagonals double m_zero_tol; //!< tolerance for zero diagonal // linear solver data LinearSolver* m_plinsolve; //!< the linear solver FEGlobalMatrix* m_pK; //!< global stiffness matrix bool m_breshape; //!< Matrix reshape flag bool m_persistMatrix;//!< Don't delete stiffness matrix until necessary (if true, K is deleted at end of time step) // data used by Quasin vector<double> m_R0; //!< residual at iteration i-1 vector<double> m_R1; //!< residual at iteration i vector<double> m_ui; //!< solution increment vector vector<double> m_Ut; //!< total solution vector vector<double> m_Ui; //!< total solution increments of current time step vector<double> m_up; //!< solution increment of previous iteration vector<double> m_Fd; //!< residual correction due to prescribed degrees of freedom private: double m_ls; //!< line search factor calculated in last call to QNSolve protected: ConvergenceInfo m_residuNorm; // residual convergence info ConvergenceInfo m_energyNorm; // energy convergence info vector<ConvergenceInfo> m_solutionNorm; // converge info for solution variables DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FECore/FENodeSetConstraint.cpp
.cpp
1,412
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.*/ #include "stdafx.h" #include "FENodeSetConstraint.h" FENodeSetConstraint::FENodeSetConstraint(FEModel* fem) : FENLConstraint(fem) { }
C++
3D
febiosoftware/FEBio
FECore/tens6ds.hpp
.hpp
1,840
49
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once // NOTE: This file is automatically included from tens6d.h // Users should not include this file manually! // access operator inline double tens6ds::operator() (int i, int j, int k, int l, int m, int n) { // lookup table convering triplets to a row/column index const int LUT[3][3][3] = { {{0,1,2},{1,3,4},{2,4,5}}, {{1,3,4},{3,6,7},{4,7,8}}, {{2,4,5},{4,7,8},{5,8,9}}}; // index to start of columns const int M[10] = {0,1,3,6,10,15,21,28,37,46}; int I = LUT[i][j][k]; int J = LUT[l][m][n]; return (I <= J ? d[M[J]+I] : d[M[I]+J]); }
Unknown
3D
febiosoftware/FEBio
FECore/FESolver.h
.h
6,452
214
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECoreBase.h" #include "Timer.h" #include "matrix.h" #include "vector.h" #include "FEDofList.h" #include "FETimeInfo.h" //----------------------------------------------------------------------------- // Scheme for assigning equation numbers // STAGGERED: | a0, b0, a1, b1, ..., an, bn | // BLOCK : | a0, a1, ..., an, b0, b1, ..., bn | enum EQUATION_SCHEME { STAGGERED, BLOCK }; //----------------------------------------------------------------------------- enum EQUATION_ORDER { NORMAL_ORDER, REVERSE_ORDER, FEBIO2_ORDER }; //----------------------------------------------------------------------------- // Solution variable class FESolutionVariable { public: FESolutionVariable(const char* szname, FEDofList* dofs = nullptr, int order = 2) { m_szname = szname; m_dofs = dofs; m_order = order; } public: FEDofList* m_dofs; // the dof list int m_order; // the order of interpolation (0 = constant, 1 = linear, 2 = default) const char* m_szname; // name of solution variable }; //----------------------------------------------------------------------------- // structure identifying nodal dof info struct FECORE_API FENodalDofInfo { int m_eq = -1; // equation number int m_node = -1; // 0-based index into mesh! int m_dof = -1; // index into nodal m_ID array const char* szdof = nullptr; }; //----------------------------------------------------------------------------- class FEModel; class FEGlobalMatrix; class LinearSolver; class FEGlobalVector; //----------------------------------------------------------------------------- //! This is the base class for all FE solvers. //! A class derived from FESolver implements a solver for a specific type //! of physics problem. It takes the FEModel in its constructor and implements //! the SolveStep function to solve the FE problem. class FECORE_API FESolver : public FECoreBase { FECORE_SUPER_CLASS(FESOLVER_ID) FECORE_BASE_CLASS(FESolver) public: //! constructor FESolver(FEModel* fem); //! destructor virtual ~FESolver(); public: //! Data serialization void Serialize(DumpStream& ar) override; //! This is called by FEAnalaysis::Deactivate virtual void Clean(); //! rewind the solver (This is called when the time step fails and needs to retry) virtual void Rewind() {} //! called during model reset virtual void Reset(); // Initialize linear equation system virtual bool InitEquations(); // New equation initialization procedure // TODO: work in progress virtual bool InitEquations2(); //! add equations void AddEquations(int neq, int partition = 0); //! initialize the step (This is called before SolveStep) virtual bool InitStep(double time); //! Solve an analysis step virtual bool SolveStep() = 0; //! Update the state of the model virtual void Update(std::vector<double>& u); //! Do the augmentations virtual bool Augment(); //! Calculates concentrated nodal loads // virtual void NodalLoads(FEGlobalVector& R, const FETimeInfo& tp); public: //! Set the equation allocation scheme void SetEquationScheme(int scheme); //! set the linear system partitions void SetPartitions(const vector<int>& part); //! Get the size of a partition int GetPartitionSize(int partition); //! get the current stiffness matrix virtual FEGlobalMatrix* GetStiffnessMatrix(); //! get the current load vector virtual std::vector<double> GetLoadVector(); // get the linear solver virtual LinearSolver* GetLinearSolver(); //! get matrix type Matrix_Type MatrixType() const; //! build the matrix profile virtual void BuildMatrixProfile(FEGlobalMatrix& G, bool breset); // see if the dofs in the dof list are active in this solver bool HasActiveDofs(const FEDofList& dof); // get the active dof map (returns nr of functions) int GetActiveDofMap(vector<int>& dofMap); // return the node (mesh index) from an equation number FENodalDofInfo GetDOFInfoFromEquation(int ieq); public: // extract the (square) norm of a solution vector double ExtractSolutionNorm(const vector<double>& v, const FEDofList& dofs) const; // return the solution vector virtual std::vector<double> GetSolutionVector() const; protected: virtual Matrix_Type PreferredMatrixType() const; public: //TODO Move these parameters elsewhere bool m_bwopt; //!< bandwidth optimization flag int m_msymm; //!< matrix symmetry flag for linear solver allocation int m_eq_scheme; //!< equation number scheme (used in InitEquations) int m_eq_order; //!< normal or reverse ordering int m_neq; //!< number of equations std::vector<int> m_part; //!< partitions of linear system std::vector<int> m_dofMap; //!< array stores for each equation the corresponding dof index // counters int m_nrhs; //!< nr of right hand side evalutations int m_niter; //!< nr of quasi-newton iterations int m_nref; //!< nr of stiffness retormations int m_ntotref; //!< nr of total stiffness reformations // augmentation int m_naug; //!< nr of augmentations bool m_baugment; //!< do augmentations flag protected: // list of solution variables vector<FESolutionVariable> m_Var; DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FECore/FEProperty.cpp
.cpp
3,656
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 "FEProperty.h" #include "FECoreBase.h" #include "DumpStream.h" #include "FECoreKernel.h" //----------------------------------------------------------------------------- FEProperty::FEProperty(SUPER_CLASS_ID superClassID) : m_szname(nullptr), m_className(nullptr), m_szlongname(nullptr), m_szdefaultType(nullptr), m_flags(0), m_superClassID(superClassID) {} //----------------------------------------------------------------------------- FEProperty::~FEProperty(){} //----------------------------------------------------------------------------- //! Set the name of the property. //! Note that the name is not copied so it must point to a static string. FEProperty& FEProperty::SetName(const char* sz) { m_szname = sz; return *this; } //----------------------------------------------------------------------------- //! Return the name of this property const char* FEProperty::GetName() const { return m_szname; } //----------------------------------------------------------------------------- FEProperty& FEProperty::SetLongName(const char* sz) { m_szlongname = sz; return *this; } //----------------------------------------------------------------------------- const char* FEProperty::GetLongName() const { return m_szlongname; } //----------------------------------------------------------------------------- const char* FEProperty::GetDefaultType() const { return m_szdefaultType; } //----------------------------------------------------------------------------- FEProperty& FEProperty::SetDefaultType(const char* szdefType) { m_szdefaultType = szdefType; return *this; } //----------------------------------------------------------------------------- void FEProperty::Write(DumpStream& ar, FECoreBase* pc) { int nflag = (pc == 0 ? 0 : 1); ar << nflag; if (nflag) { int ntype = (int) pc->GetSuperClassID(); ar << pc->GetTypeStr(); ar << ntype; pc->Serialize(ar); } } //----------------------------------------------------------------------------- FECoreBase* FEProperty::Read(DumpStream& ar) { int nflag = 0; FECoreBase* pm = 0; ar >> nflag; if (nflag) { char sz[256]; int ntype = FEINVALID_ID; ar >> sz; ar >> ntype; pm = fecore_new<FECoreBase>(ntype, sz, &ar.GetFEModel()); pm->SetParent(GetParent()); pm->Serialize(ar); // TODO: Do I really need to do this here? //pm->Init(); } return pm; }
C++
3D
febiosoftware/FEBio
FECore/FELogEnclosedVolume.h
.h
1,720
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 #include "SurfaceDataRecord.h" class FECORE_API FELogEnclosedVolume : public FELogSurfaceData { public: FELogEnclosedVolume(FEModel* fem) : FELogSurfaceData(fem) {} double value(FESurface& surface) override; DECLARE_FECORE_CLASS(); }; class FELogEnclosedVolumeChange : public FELogSurfaceData { public: FELogEnclosedVolumeChange(FEModel* fem) : FELogSurfaceData(fem) {} double value(FESurface& surface) override; };
Unknown
3D
febiosoftware/FEBio
FECore/FEParamValidator.cpp
.cpp
5,089
163
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEParamValidator.h" #include "FEParam.h" #include "FECoreKernel.h" #include "DumpStream.h" #include "FEModelParam.h" //----------------------------------------------------------------------------- bool is_inside_range_int(int ival, int rng, int imin, int imax) { switch (rng) { case FE_GREATER : return (ival > imin); break; case FE_GREATER_OR_EQUAL: return (ival >= imin); break; case FE_LESS : return (ival < imin); break; case FE_LESS_OR_EQUAL : return (ival <= imin); break; case FE_OPEN : return ((ival > imin) && (ival < imax)); break; case FE_CLOSED : return ((ival >= imin) && (ival <= imax)); break; case FE_LEFT_OPEN : return ((ival > imin) && (ival <= imax)); break; case FE_RIGHT_OPEN : return ((ival >= imin) && (ival < imax)); break; case FE_NOT_EQUAL : return (ival != imin); break; } return false; } //----------------------------------------------------------------------------- bool is_inside_range_double(double val, int rng, double dmin, double dmax) { switch (rng) { case FE_GREATER : return (val > dmin); break; case FE_GREATER_OR_EQUAL: return (val >= dmin); break; case FE_LESS : return (val < dmin); break; case FE_LESS_OR_EQUAL : return (val <= dmin); break; case FE_OPEN : return ((val > dmin) && (val < dmax)); break; case FE_CLOSED : return ((val >= dmin) && (val <= dmax)); break; case FE_LEFT_OPEN : return ((val > dmin) && (val <= dmax)); break; case FE_RIGHT_OPEN : return ((val >= dmin) && (val < dmax)); break; case FE_NOT_EQUAL : return (val != dmin); break; } return false; } //----------------------------------------------------------------------------- bool FEIntValidator::is_valid(const FEParam& p) const { if (p.type() != FE_PARAM_INT) return false; bool bvalid = true; int val = 0; if (p.dim() == 1) { val = p.value<int>(); bvalid = is_inside_range_int(val, m_rng, m_nmin, m_nmax); } else { for (int i = 0; i<p.dim(); ++i) { val = p.value<int>(i); bvalid = is_inside_range_int(val, m_rng, m_nmin, m_nmax); if (bvalid == false) break; } } return bvalid; } //----------------------------------------------------------------------------- void FEIntValidator::Serialize(DumpStream& ar) { if (ar.IsShallow()) return; ar & m_rng; ar & m_nmin & m_nmax; } //----------------------------------------------------------------------------- bool FEDoubleValidator::is_valid(const FEParam& p) const { if (p.type() != FE_PARAM_DOUBLE) return false; bool bvalid; double val = 0; if (p.dim() == 1) { val = p.value<double>(); bvalid = is_inside_range_double(val, m_rng, m_fmin, m_fmax); } else { for (int i = 0; i<p.dim(); ++i) { val = p.value<double>(i); bvalid = is_inside_range_double(val, m_rng, m_fmin, m_fmax); if (bvalid == false) break; } } return bvalid; } //----------------------------------------------------------------------------- void FEDoubleValidator::Serialize(DumpStream& ar) { if (ar.IsShallow()) return; ar & m_rng; ar & m_fmin & m_fmax; } //----------------------------------------------------------------------------- bool FEParamDoubleValidator::is_valid(const FEParam& p) const { if (p.type() != FE_PARAM_DOUBLE_MAPPED) return false; const FEParamDouble& d = p.value<FEParamDouble>(); // This only works for const values double val = 0.0; bool bvalid = true; if (d.isConst()) { val = d.constValue(); bvalid = is_inside_range_double(val, m_rng, m_fmin, m_fmax); } return bvalid; } //----------------------------------------------------------------------------- void FEParamDoubleValidator::Serialize(DumpStream& ar) { if (ar.IsShallow()) return; ar & m_rng; ar & m_fmin & m_fmax; }
C++
3D
febiosoftware/FEBio
FECore/NodeDataRecord.h
.h
2,274
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 "FECoreBase.h" #include "DataRecord.h" #include "FELogNodeData.h" class FENodeSet; class FENode; //----------------------------------------------------------------------------- //! This class records nodal data //! \todo should I create a different class for each data record? Like for the plot file? class FECORE_API NodeDataRecord : public DataRecord { public: NodeDataRecord(FEModel* pfem); double Evaluate(int item, int ndata) override; void SetData(const char* sz) override; void SelectAllItems() override; int Size() const override; void SetItemList(FEItemList* items, const std::vector<int>& selection) override; private: vector<FELogNodeData*> m_Data; }; //----------------------------------------------------------------------------- // Special class for outputting nodal variables class FECORE_API FENodeVarData : public FELogNodeData { public: FENodeVarData(FEModel* pfem, int ndof); double value(const FENode& node) override; private: int m_ndof; };
Unknown
3D
febiosoftware/FEBio
FECore/FESurfaceElement.cpp
.cpp
4,894
202
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FESurfaceElement.h" #include "DumpStream.h" //================================================================================================= // FESurfaceElement //================================================================================================= //----------------------------------------------------------------------------- FESurfaceElement::FESurfaceElement() { m_lid = -1; } FESurfaceElement::FESurfaceElement(const FESurfaceElement& el) : FEElement(el) { // set the traits of the element if (el.m_pT) SetTraits(el.m_pT); // copy base class data m_mat = el.m_mat; m_nID = el.m_nID; m_lid = el.m_lid; m_node = el.m_node; m_lnode = el.m_lnode; m_lm = el.m_lm; m_val = el.m_val; m_status = el.m_status; // copy surface element data m_lid = el.m_lid; m_elem[0] = el.m_elem[0]; m_elem[1] = el.m_elem[1]; } FESurfaceElement& FESurfaceElement::operator = (const FESurfaceElement& el) { // make sure the element type is the same if (m_pT == 0) SetTraits(el.m_pT); else assert(m_pT == el.m_pT); // copy base class data m_mat = el.m_mat; m_nID = el.m_nID; m_lid = el.m_lid; m_node = el.m_node; m_lnode = el.m_lnode; m_lm = el.m_lm; m_val = el.m_val; // copy surface element data m_lid = el.m_lid; m_elem[0] = el.m_elem[0]; m_elem[1] = el.m_elem[1]; return (*this); } void FESurfaceElement::SetTraits(FEElementTraits* pt) { m_pT = pt; m_node.resize(Nodes()); m_lnode.resize(Nodes()); m_State.Create(GaussPoints()); } int FESurfaceElement::facet_edges() const { int nn = Nodes(), nf = 0; switch (nn) { case 3: case 6: case 7: nf = 3; break; case 4: case 8: case 9: nf = 4; break; default: assert(false); } return nf; } void FESurfaceElement::facet_edge(int j, int* en) const { int nn = Nodes(); switch (nn) { case 3: en[0] = m_lnode[j]; en[1] = m_lnode[(j + 1) % 3]; break; case 6: case 7: en[0] = m_lnode[j]; en[1] = m_lnode[j + 3]; en[2] = m_lnode[(j + 1) % 3]; break; case 4: en[0] = m_lnode[j]; en[1] = m_lnode[(j + 1) % 4]; break; case 8: case 9: en[0] = m_lnode[j]; en[1] = m_lnode[j + 4]; en[2] = m_lnode[(j + 1) % 4]; break; } } //----------------------------------------------------------------------------- // see if this element has the list of nodes n. Return 0 if not or order is invalid, 1 if same order // and -1 if opposite order int FESurfaceElement::HasNodes(int* n, const int ns) const { int l = Nodes(); if (l < ns) return 0; // find start index int m0 = -1; for (int i = 0; i < ns; ++i) { if (m_node[0] == n[i]) { m0 = i; break; } } if (m0 == -1) return 0; // check positive order int order = 1; for (int i = 1; i < ns; ++i) { int m = (i + m0) % ns; if (m_node[i] != n[m]) { order = 0; break; } } if (order == 0) { // check negative order order = -1; for (int i = 1; i < ns; ++i) { int m = (m0 + ns - i) % ns; assert((m >= 0) && (m < ns)); if (m_node[i] != n[m]) { order = 0; break; } } } return order; } double* FESurfaceElement::Gr(int order, int n) const { return (order >= 0 ? ((FESurfaceElementTraits*)(m_pT))->Gr_p[order][n] : ((FESurfaceElementTraits*)(m_pT))->Gr[n]); } // shape function derivative to r double* FESurfaceElement::Gs(int order, int n) const { return (order >= 0 ? ((FESurfaceElementTraits*)(m_pT))->Gs_p[order][n] : ((FESurfaceElementTraits*)(m_pT))->Gs[n]); } // shape function derivative to s void FESurfaceElement::Serialize(DumpStream& ar) { FEElement::Serialize(ar); if (ar.IsShallow()) return; ar & m_lid; // TODO: Serialize m_elem }
C++
3D
febiosoftware/FEBio
FECore/FETransform.h
.h
5,816
192
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "vec3d.h" #include "quatd.h" //----------------------------------------------------------------------------- //! Class that defines an affine transformation (scale, rotate, translate). //! This currently applies the transformation as follows: //! 1. scale : the scale is applied in the local coordinate system //! 2. rotate: rotation from local to global coordinates //! 3. translate: translate to a global position //! class Transform { public: FECORE_API Transform(); //! Reset the transform FECORE_API void Reset(); //! set the scale factors FECORE_API void SetScale(double sx, double sy, double sz); //! set the scale of the object void SetScale(const vec3d& s) { m_scl = s; } //! get scale of the object const vec3d& GetScale() const { return m_scl; } //! set the position (or translation) FECORE_API void SetPosition(const vec3d& t); //! get position of object const vec3d& GetPosition() const { return m_pos; } //! set the rotation quaternion FECORE_API void SetRotation(const quatd& q); //! set the rotation vector (uses degrees) FECORE_API void SetRotation(const vec3d& r); //! set rotation via Euler angles Tait-Bryan (Z,Y,X) convention (in degrees) FECORE_API void SetRotation(double X, double Y, double Z); //! get orientation const quatd& GetRotation() const { return m_rot; } //! get inverse of rotation quatd GetRotationInverse() const { return m_roti; } //! apply transformation FECORE_API vec3d Apply(const vec3d& r) const; //! translate the transform void Translate(const vec3d& dr); //! scale an object void Scale(double s, vec3d r, vec3d rc); //! rotate around the center rc void Rotate(quatd q, vec3d rc); //! Rotate angle w around an axis defined by the position vectors a, b. void Rotate(const vec3d& a, const vec3d& b, double w); //! comparison bool operator == (const Transform& T) const; public: //! convert from local to global coordinates vec3d LocalToGlobal(const vec3d& r) const; //! convert from global to local coordinates vec3d GlobalToLocal(const vec3d& r) const; //! get a normal-like vector from global to local vec3d LocalToGlobalNormal(const vec3d& n) const; //! get a normal-like vector from global to local vec3d GlobalToLocalNormal(const vec3d& n) const; private: vec3d m_scl; //! scale factors vec3d m_pos; //! translation (global space) quatd m_rot; //! rotation quatd m_roti; //! inverse rotation }; inline bool Transform::operator == (const Transform& T) const { return ((m_pos == T.m_pos) && (m_scl == T.m_scl) && (m_rot == T.m_rot)); } inline void Transform::Translate(const vec3d& dr) { m_pos += dr; } //! convert from local to global coordinates inline vec3d Transform::LocalToGlobal(const vec3d& r) const { return m_pos + m_rot * vec3d(r.x * m_scl.x, r.y * m_scl.y, r.z * m_scl.z); } //! convert from global to local coordinates inline vec3d Transform::GlobalToLocal(const vec3d& r) const { vec3d p = m_roti * (r - m_pos); return vec3d(p.x / m_scl.x, p.y / m_scl.y, p.z / m_scl.z); } //! get a normal-like vector from global to local inline vec3d Transform::LocalToGlobalNormal(const vec3d& n) const { // NOTE: scaling is turned off because this is used in the generation of material axes. // If I use scaling the axes may no longer be orthogonal. Maybe I should create another // function for this since this is now inconsistent with the reverse operation. // return m_rot*vec3d(n.x / m_scl.x, n.y / m_scl.y, n.z / m_scl.z); return m_rot * vec3d(n.x, n.y, n.z); } //! get a normal-like vector from global to local inline vec3d Transform::GlobalToLocalNormal(const vec3d& n) const { vec3d m = m_roti * n; m.x /= m_scl.x; m.y /= m_scl.y; m.z /= m_scl.z; m.Normalize(); return m; } //! scale inline void Transform::Scale(double s, vec3d r, vec3d rc) { vec3d r0 = GlobalToLocal(rc); double a = s - 1; m_roti.RotateVector(r); r.Normalize(); r.x = 1 + a * fabs(r.x); r.y = 1 + a * fabs(r.y); r.z = 1 + a * fabs(r.z); m_scl.x *= r.x; m_scl.y *= r.y; m_scl.z *= r.z; m_pos -= LocalToGlobal(r0) - rc; } //! rotate around the center rc inline void Transform::Rotate(quatd q, vec3d rc) { m_rot = q * m_rot; m_roti = m_rot.Inverse(); m_rot.MakeUnit(); m_roti.MakeUnit(); m_pos = rc + q * (m_pos - rc); } //! Rotate angle w around an axis defined by the position vectors a, b. inline void Transform::Rotate(const vec3d& a, const vec3d& b, double w) { double wr = PI * w / 180.0; vec3d n = (b - a); n.Normalize(); quatd q(wr, n); Rotate(q, a); }
Unknown
3D
febiosoftware/FEBio
FECore/LUSolver.cpp
.cpp
3,919
161
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "LUSolver.h" #include <math.h> //----------------------------------------------------------------------------- LUSolver::LUSolver(FEModel* fem) : LinearSolver(fem), m_pA(nullptr) { } //----------------------------------------------------------------------------- //! Create a sparse matrix SparseMatrix* LUSolver::CreateSparseMatrix(Matrix_Type ntype) { return (m_pA = new FECore::DenseMatrix()); } //----------------------------------------------------------------------------- void LUSolver::SetMatrix(FECore::DenseMatrix* pA) { m_pA = pA; } //----------------------------------------------------------------------------- bool LUSolver::PreProcess() { // We don't need to do any preprocessing for this solver return LinearSolver::PreProcess(); } //----------------------------------------------------------------------------- bool LUSolver::Factor() { FECore::DenseMatrix& a = *m_pA; const double TINY = 1.0e-20; int i, imax, j, k; double big, dum, sum, temp; int n = a.Rows(); // create index vector indx.resize(n); vector<double> vv(n); for (i=0; i<n; ++i) { big = 0; for (j=0; j<n; ++j) if ((temp=fabs(a(i,j))) > big) big = temp; if (big == 0) return false; // singular matrix vv[i] = 1.0 / big; } for (j=0; j<n; ++j) { for (i=0; i<j; ++i) { sum = a(i,j); for (k=0; k<i; ++k) sum -= a(i,k)*a(k,j); a(i,j) = sum; } big = 0; imax = j; for (i=j;i<n;++i) { sum = a(i,j); for (k=0; k<j; ++k) sum -= a(i,k)*a(k,j); a(i,j) = sum; if ((dum=vv[i]*fabs(sum))>=big) { big = dum; imax = i; } } if (j != imax) { for (k=0; k<n; ++k) { dum = a(imax,k); a(imax,k) = a(j,k); a(j,k) = dum; } vv[imax] = vv[j]; } indx[j] = imax; if (a(j,j) == 0) a(j,j) = TINY; if (j != n-1) { dum = 1.0/a(j,j); for (i=j+1;i<n; ++i) a(i,j) *= dum; } } return true; } //----------------------------------------------------------------------------- bool LUSolver::BackSolve(double* x, double* b) { FECore::DenseMatrix& a = *m_pA; int n = a.Rows(); for (int i=0; i<n; i++) x[i] = b[i]; int ii=0; for (int i=0; i<n; ++i) { int ip = indx[i]; double sum = x[ip]; x[ip] = x[i]; if (ii != 0) for (int j=ii-1;j<i;++j) sum -= a(i,j)*x[j]; else if (sum != 0) ii = i+1; x[i] = sum; } for (int i=n-1; i>=0; --i) { double sum = x[i]; for (int j=i+1; j<n; ++j) sum -= a(i,j)*x[j]; x[i] = sum/a(i,i); } return false; } //----------------------------------------------------------------------------- void LUSolver::Destroy() { // nothing to destroy LinearSolver::Destroy(); }
C++
3D
febiosoftware/FEBio
FECore/FEPeriodicLinearConstraint.h
.h
2,078
62
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEStepComponent.h" #include <FECore/FENodeList.h> #include <FECore/FENodeSet.h> #include "fecore_api.h" class FECORE_API FEPeriodicLinearConstraint : public FEStepComponent { struct NodeSetPair { FENodeList primary; FENodeList secondary; }; public: FEPeriodicLinearConstraint(FEModel* fem); ~FEPeriodicLinearConstraint(); void AddNodeSetPair(const FENodeList& ms, const FENodeList& ss, bool push_back = true); void SetReferenceNode(int node) { m_refNode = node; } void ExcludeNodes(const FENodeSet& ps) { m_exclude = ps; } public: // generate the linear constraints bool GenerateConstraints(FEModel* fem); private: std::vector<NodeSetPair> m_set; // list of node set pairs FENodeSet m_exclude; // nodes to exclude int m_refNode; // reference node };
Unknown
3D
febiosoftware/FEBio
FECore/FESurfaceElementShape.h
.h
5,886
164
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEElementShape.h" //============================================================================= // Base class for defining element shape classes for (3D) solid elements class FESurfaceElementShape : public FEElementShape { public: FESurfaceElementShape(FE_Element_Shape shape, int nodes) : FEElementShape(shape, nodes) {} //! values of shape functions virtual void shape_fnc(double* H, double r, double s) = 0; //! values of shape function derivatives virtual void shape_deriv(double* Hr, double* Hs, double r, double s) = 0; //! values of shape function second derivatives virtual void shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) = 0; }; //============================================================================= // Class for QUAD4 elements class FEQuad4 : public FESurfaceElementShape { public: FEQuad4() : FESurfaceElementShape(ET_QUAD4, 4) {} //! values of shape functions void shape_fnc(double* H, double r, double s) override; //! values of shape function derivatives void shape_deriv(double* Hr, double* Hs, double r, double s) override; //! values of shape function second derivatives void shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) override; }; //============================================================================= // Class for QUAD8 elements class FEQuad8 : public FESurfaceElementShape { public: FEQuad8() : FESurfaceElementShape(ET_QUAD8, 8) {} //! values of shape functions void shape_fnc(double* H, double r, double s) override; //! values of shape function derivatives void shape_deriv(double* Hr, double* Hs, double r, double s) override; //! values of shape function second derivatives void shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) override; }; //============================================================================= // Class for QUAD9 elements class FEQuad9 : public FESurfaceElementShape { public: FEQuad9() : FESurfaceElementShape(ET_QUAD9, 9) {} //! values of shape functions void shape_fnc(double* H, double r, double s) override; //! values of shape function derivatives void shape_deriv(double* Hr, double* Hs, double r, double s) override; //! values of shape function second derivatives void shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) override; }; //============================================================================= // Class for TRI3 elements class FETri3 : public FESurfaceElementShape { public: FETri3() : FESurfaceElementShape(ET_TRI3, 4) {} //! values of shape functions void shape_fnc(double* H, double r, double s) override; //! values of shape function derivatives void shape_deriv(double* Hr, double* Hs, double r, double s) override; //! values of shape function second derivatives void shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) override; }; //============================================================================= // Class for TRI6 elements class FETri6 : public FESurfaceElementShape { public: FETri6() : FESurfaceElementShape(ET_TRI6, 6) {} //! values of shape functions void shape_fnc(double* H, double r, double s) override; //! values of shape function derivatives void shape_deriv(double* Hr, double* Hs, double r, double s) override; //! values of shape function second derivatives void shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) override; }; //============================================================================= // Class for TRI7 elements class FETri7 : public FESurfaceElementShape { public: FETri7() : FESurfaceElementShape(ET_TRI7, 7) {} //! values of shape functions void shape_fnc(double* H, double r, double s) override; //! values of shape function derivatives void shape_deriv(double* Hr, double* Hs, double r, double s) override; //! values of shape function second derivatives void shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) override; }; //============================================================================= // Class for TRI10 elements class FETri10 : public FESurfaceElementShape { public: FETri10() : FESurfaceElementShape(ET_TRI10, 10) {} //! values of shape functions void shape_fnc(double* H, double r, double s) override; //! values of shape function derivatives void shape_deriv(double* Hr, double* Hs, double r, double s) override; //! values of shape function second derivatives void shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) override; };
Unknown
3D
febiosoftware/FEBio
FECore/FEDiscreteSet.h
.h
2,165
70
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "fecore_api.h" #include <vector> #include <string> //----------------------------------------------------------------------------- // Forward declarations class FEMesh; class DumpStream; //----------------------------------------------------------------------------- //! Defines a discrete element set (i.e. node-pairs) class FECORE_API FEDiscreteSet { public: struct NodePair { int n0, n1; void Serialize(DumpStream& ar); }; public: FEDiscreteSet(FEMesh* pm); void create(int n); int size() const { return (int)m_pair.size(); } void add(int n0, int n1); void SetName(const std::string& name); const std::string& GetName() const; const NodePair& Element(int i) const { return m_pair[i]; } void Serialize(DumpStream& ar); private: FEMesh* m_pmesh; std::vector<NodePair> m_pair; //!< list of discrete elements std::string m_name; };
Unknown
3D
febiosoftware/FEBio
FECore/FEPrescribedBC.cpp
.cpp
9,165
371
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEPrescribedBC.h" #include "FESurface.h" #include "FENode.h" //============================================================================= BEGIN_FECORE_CLASS(FEPrescribedNodeSet, FENodalBC) ADD_PARAMETER(m_brelative, "relative"); END_FECORE_CLASS(); FEPrescribedNodeSet::FEPrescribedNodeSet(FEModel* fem) : FENodalBC(fem) { m_brelative = false; } //----------------------------------------------------------------------------- // set the relative flag void FEPrescribedNodeSet::SetRelativeFlag(bool br) { m_brelative = br; } void FEPrescribedNodeSet::Activate() { FENodalBC::Activate(); FENodeSet& nodeSet = *GetNodeSet(); int N = nodeSet.Size(); int dofs = m_dof.Size(); if (m_brelative) m_rval.assign(N * dofs, 0.0); for (int i = 0; i < N; ++i) { // get the node FENode& node = *nodeSet.Node(i); // set the dofs to prescribed for (size_t j = 0; j < dofs; ++j) { node.set_bc(m_dof[j], DOF_PRESCRIBED); if (m_brelative) { m_rval[i * dofs + j] = node.get(m_dof[j]); } } } } //----------------------------------------------------------------------------- void FEPrescribedNodeSet::Deactivate() { FEBoundaryCondition::Deactivate(); FENodeSet& nodeSet = *GetNodeSet(); int N = nodeSet.Size(); int dofs = m_dof.Size(); for (int i = 0; i < N; ++i) { // get the node FENode& node = *nodeSet.Node(i); // set the dof to open for (int j = 0; j < dofs; ++j) { node.set_bc(m_dof[j], DOF_OPEN); } } } //----------------------------------------------------------------------------- // This function is called when the solver needs to know the // prescribed dof values. The brel flag indicates wheter the total // value is needed or the value with respect to the current nodal dof value void FEPrescribedNodeSet::PrepStep(std::vector<double>& ui, bool brel) { FENodeSet& nodeSet = *GetNodeSet(); int N = nodeSet.Size(); int dofs = m_dof.Size(); vector<double> val(dofs, 0.0); for (int i = 0; i < N; ++i) { // get the node FENode& node = *nodeSet.Node(i); // get the values GetNodalValues(i, val); assert(val.size() == dofs); for (size_t j = 0; j < dofs; ++j) { double uj = val[j]; if (m_brelative) { uj += m_rval[i * dofs + j]; } int I = -node.m_ID[m_dof[j]] - 2; if (I >= 0) ui[I] = (brel ? uj - node.get(m_dof[j]) : uj); } } } //----------------------------------------------------------------------------- // serialization void FEPrescribedNodeSet::Serialize(DumpStream& ar) { FENodalBC::Serialize(ar); ar & m_rval; } //----------------------------------------------------------------------------- // This is called during nodal update and should be used to enforce the // nodal degrees of freedoms void FEPrescribedNodeSet::Update() { FENodeSet& nodeSet = *GetNodeSet(); int N = nodeSet.Size(); int dofs = m_dof.Size(); std::vector<double> val(dofs, 0.0); for (int i = 0; i < N; ++i) { // get the node FENode& node = *nodeSet.Node(i); // get the values GetNodalValues(i, val); assert(val.size() == dofs); for (size_t j = 0; j < dofs; ++j) { double uj = val[j]; if (m_brelative) { uj += m_rval[i * dofs + j]; } node.set(m_dof[j], uj); } } } //----------------------------------------------------------------------------- // This is called during contact update and should be used to enforce the // nodal degrees of freedoms void FEPrescribedNodeSet::Repair() { FENodeSet& nodeSet = *GetNodeSet(); int N = nodeSet.Size(); int dofs = m_dof.Size(); std::vector<double> val(dofs, 0.0); for (int i = 0; i < N; ++i) { // get the node FENode& node = *nodeSet.Node(i); // get the values GetNodalValues(i, val); assert(val.size() == dofs); for (size_t j = 0; j < dofs; ++j) { if (node.m_ID[m_dof[j]] >= 0) { node.m_ID[m_dof[j]] = -node.m_ID[m_dof[j]] - 2; double uj = val[j]; if (m_brelative) { uj += m_rval[i * dofs + j]; } node.set(m_dof[j], uj); } } } } //============================================================================= BEGIN_FECORE_CLASS(FEPrescribedSurface, FESurfaceBC) END_FECORE_CLASS(); FEPrescribedSurface::FEPrescribedSurface(FEModel* fem) : FESurfaceBC(fem) { m_brelative = false; } void FEPrescribedSurface::Activate() { FESurfaceBC::Activate(); FESurface* surface = GetSurface(); if (surface == nullptr) return; m_nodeList = surface->GetNodeList(); int N = m_nodeList.Size(); int dofs = m_dof.Size(); if (m_brelative) m_rval.assign(N * dofs, 0.0); for (int i = 0; i < N; ++i) { // get the node FENode& node = *m_nodeList.Node(i); // set the dofs to prescribed for (size_t j = 0; j < dofs; ++j) { node.set_bc(m_dof[j], DOF_PRESCRIBED); if (m_brelative) { m_rval[i * dofs + j] = node.get(m_dof[j]); } } } } //----------------------------------------------------------------------------- void FEPrescribedSurface::Deactivate() { FEBoundaryCondition::Deactivate(); int N = m_nodeList.Size(); int dofs = m_dof.Size(); for (int i = 0; i < N; ++i) { // get the node FENode& node = *m_nodeList.Node(i); // set the dof to open for (int j = 0; j < dofs; ++j) { node.set_bc(m_dof[j], DOF_OPEN); } } } //----------------------------------------------------------------------------- // This function is called when the solver needs to know the // prescribed dof values. The brel flag indicates wheter the total // value is needed or the value with respect to the current nodal dof value void FEPrescribedSurface::PrepStep(std::vector<double>& ui, bool brel) { int N = m_nodeList.Size(); int dofs = m_dof.Size(); vector<double> val(dofs, 0.0); for (int i = 0; i < N; ++i) { // get the node FENode& node = *m_nodeList.Node(i); // get the values GetNodalValues(i, val); assert(val.size() == dofs); for (size_t j = 0; j < dofs; ++j) { double uj = val[j]; if (m_brelative) { uj += m_rval[i * dofs + j]; } int I = -node.m_ID[m_dof[j]] - 2; if (I >= 0) ui[I] = (brel ? uj - node.get(m_dof[j]) : uj); } } } //----------------------------------------------------------------------------- // set the relative flag void FEPrescribedSurface::SetRelativeFlag(bool br) { m_brelative = br; } //----------------------------------------------------------------------------- // serialization void FEPrescribedSurface::Serialize(DumpStream& ar) { FEBoundaryCondition::Serialize(ar); ar & m_rval; if (ar.IsShallow() == false) ar & m_nodeList; } //----------------------------------------------------------------------------- // This is called during nodal update and should be used to enforce the // nodal degrees of freedoms void FEPrescribedSurface::Update() { int N = m_nodeList.Size(); int dofs = m_dof.Size(); std::vector<double> val(dofs, 0.0); for (int i = 0; i < N; ++i) { // get the node FENode& node = *m_nodeList.Node(i); // get the values GetNodalValues(i, val); assert(val.size() == dofs); for (size_t j = 0; j < dofs; ++j) { double uj = val[j]; if (m_brelative) { uj += m_rval[i * dofs + j]; } node.set(m_dof[j], uj); } } } //----------------------------------------------------------------------------- // This is called during contact update and should be used to enforce the // nodal degrees of freedoms void FEPrescribedSurface::Repair() { int N = m_nodeList.Size(); int dofs = m_dof.Size(); std::vector<double> val(dofs, 0.0); for (int i = 0; i < N; ++i) { // get the node FENode& node = *m_nodeList.Node(i); // get the values GetNodalValues(i, val); assert(val.size() == dofs); for (size_t j = 0; j < dofs; ++j) { if (node.m_ID[m_dof[j]] >= 0) { node.m_ID[m_dof[j]] = -node.m_ID[m_dof[j]] - 2; double uj = val[j]; if (m_brelative) { uj += m_rval[i * dofs + j]; } node.set(m_dof[j], uj); } } } }
C++
3D
febiosoftware/FEBio
FECore/FESurfaceElementShape.cpp
.cpp
14,049
403
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FESurfaceElementShape.h" //============================================================================= // Q U A D 4 //============================================================================= //----------------------------------------------------------------------------- void FEQuad4::shape_fnc(double* H, double r, double s) { H[0] = 0.25*(1 - r)*(1 - s); H[1] = 0.25*(1 + r)*(1 - s); H[2] = 0.25*(1 + r)*(1 + s); H[3] = 0.25*(1 - r)*(1 + s); } //----------------------------------------------------------------------------- void FEQuad4::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -0.25*(1 - s); Hs[0] = -0.25*(1 - r); Hr[1] = 0.25*(1 - s); Hs[1] = -0.25*(1 + r); Hr[2] = 0.25*(1 + s); Hs[2] = 0.25*(1 + r); Hr[3] = -0.25*(1 + s); Hs[3] = 0.25*(1 - r); } //----------------------------------------------------------------------------- void FEQuad4::shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) { Hrr[0] = 0; Hrs[0] = 0.25; Hss[0] = 0; Hrr[1] = 0; Hrs[1] = -0.25; Hss[1] = 0; Hrr[2] = 0; Hrs[2] = 0.25; Hss[2] = 0; Hrr[3] = 0; Hrs[3] = -0.25; Hss[3] = 0; } //============================================================================= // Q U A D 8 //============================================================================= //----------------------------------------------------------------------------- // shape function at (r,s) void FEQuad8::shape_fnc(double* H, double r, double s) { H[4] = 0.5*(1 - r*r)*(1 - s); H[5] = 0.5*(1 - s*s)*(1 + r); H[6] = 0.5*(1 - r*r)*(1 + s); H[7] = 0.5*(1 - s*s)*(1 - r); H[0] = 0.25*(1 - r)*(1 - s) - 0.5*(H[4] + H[7]); H[1] = 0.25*(1 + r)*(1 - s) - 0.5*(H[4] + H[5]); H[2] = 0.25*(1 + r)*(1 + s) - 0.5*(H[5] + H[6]); H[3] = 0.25*(1 - r)*(1 + s) - 0.5*(H[6] + H[7]); } //----------------------------------------------------------------------------- // shape function derivatives at (r,s) void FEQuad8::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[4] = -r*(1 - s); Hr[5] = 0.5*(1 - s*s); Hr[6] = -r*(1 + s); Hr[7] = -0.5*(1 - s*s); Hr[0] = -0.25*(1 - s) - 0.5*(Hr[4] + Hr[7]); Hr[1] = 0.25*(1 - s) - 0.5*(Hr[4] + Hr[5]); Hr[2] = 0.25*(1 + s) - 0.5*(Hr[5] + Hr[6]); Hr[3] = -0.25*(1 + s) - 0.5*(Hr[6] + Hr[7]); Hs[4] = -0.5*(1 - r*r); Hs[5] = -s*(1 + r); Hs[6] = 0.5*(1 - r*r); Hs[7] = -s*(1 - r); Hs[0] = -0.25*(1 - r) - 0.5*(Hs[4] + Hs[7]); Hs[1] = -0.25*(1 + r) - 0.5*(Hs[4] + Hs[5]); Hs[2] = 0.25*(1 + r) - 0.5*(Hs[5] + Hs[6]); Hs[3] = 0.25*(1 - r) - 0.5*(Hs[6] + Hs[7]); } //----------------------------------------------------------------------------- //! shape function derivatives at (r,s) //! \todo implement this void FEQuad8::shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) { Hrr[4] = -(1 - s); Hrr[5] = 0.0; Hrr[6] = -(1 + s); Hrr[7] = 0.0; Hrs[4] = r; Hrs[5] = -s; Hrs[6] = -r; Hrs[7] = s; Hss[4] = 0.0; Hss[5] = -(1 + r); Hss[6] = 0.0; Hss[7] = -(1 - r); Hrr[0] = -0.5*(Hrr[4] + Hrr[7]); Hrr[1] = -0.5*(Hrr[4] + Hrr[5]); Hrr[2] = -0.5*(Hrr[5] + Hrr[6]); Hrr[3] = -0.5*(Hrr[6] + Hrr[7]); Hrs[0] = 0.25 - 0.5*(Hrs[4] + Hrs[7]); Hrs[1] = -0.25 - 0.5*(Hrs[4] + Hrs[5]); Hrs[2] = 0.25 - 0.5*(Hrs[5] + Hrs[6]); Hrs[3] = -0.25 - 0.5*(Hrs[6] + Hrs[7]); Hss[0] = -0.5*(Hss[4] + Hss[7]); Hss[1] = -0.5*(Hss[4] + Hss[5]); Hss[2] = -0.5*(Hss[5] + Hss[6]); Hss[3] = -0.5*(Hss[6] + Hss[7]); } //============================================================================= // Q U A D 9 //============================================================================= //----------------------------------------------------------------------------- // shape function at (r,s) void FEQuad9::shape_fnc(double* H, double r, double s) { double R[3] = { 0.5*r*(r - 1.0), 0.5*r*(r + 1.0), 1.0 - r*r }; double S[3] = { 0.5*s*(s - 1.0), 0.5*s*(s + 1.0), 1.0 - s*s }; H[0] = R[0] * S[0]; H[1] = R[1] * S[0]; H[2] = R[1] * S[1]; H[3] = R[0] * S[1]; H[4] = R[2] * S[0]; H[5] = R[1] * S[2]; H[6] = R[2] * S[1]; H[7] = R[0] * S[2]; H[8] = R[2] * S[2]; } //----------------------------------------------------------------------------- // shape function derivatives at (r,s) void FEQuad9::shape_deriv(double* Hr, double* Hs, double r, double s) { double R[3] = { 0.5*r*(r - 1.0), 0.5*r*(r + 1.0), 1.0 - r*r }; double S[3] = { 0.5*s*(s - 1.0), 0.5*s*(s + 1.0), 1.0 - s*s }; double DR[3] = { r - 0.5, r + 0.5, -2.0*r }; double DS[3] = { s - 0.5, s + 0.5, -2.0*s }; Hr[0] = DR[0] * S[0]; Hr[1] = DR[1] * S[0]; Hr[2] = DR[1] * S[1]; Hr[3] = DR[0] * S[1]; Hr[4] = DR[2] * S[0]; Hr[5] = DR[1] * S[2]; Hr[6] = DR[2] * S[1]; Hr[7] = DR[0] * S[2]; Hr[8] = DR[2] * S[2]; Hs[0] = R[0] * DS[0]; Hs[1] = R[1] * DS[0]; Hs[2] = R[1] * DS[1]; Hs[3] = R[0] * DS[1]; Hs[4] = R[2] * DS[0]; Hs[5] = R[1] * DS[2]; Hs[6] = R[2] * DS[1]; Hs[7] = R[0] * DS[2]; Hs[8] = R[2] * DS[2]; } //----------------------------------------------------------------------------- //! shape function derivatives at (r,s) void FEQuad9::shape_deriv2(double* Grr, double* Gss, double* Grs, double r, double s) { double R[3] = { 0.5*r*(r - 1.0), 0.5*r*(r + 1.0), 1.0 - r*r }; double S[3] = { 0.5*s*(s - 1.0), 0.5*s*(s + 1.0), 1.0 - s*s }; double DR[3] = { r - 0.5, r + 0.5, -2.0*r }; double DS[3] = { s - 0.5, s + 0.5, -2.0*s }; double DDR[3] = { 1.0, 1.0, -2.0 }; double DDS[3] = { 1.0, 1.0, -2.0 }; Grr[0] = DDR[0] * S[0]; Grs[0] = DR[0] * DS[0]; Gss[0] = R[0] * DDS[0]; Grr[1] = DDR[1] * S[0]; Grs[1] = DR[1] * DS[0]; Gss[1] = R[1] * DDS[0]; Grr[2] = DDR[1] * S[1]; Grs[2] = DR[1] * DS[1]; Gss[2] = R[1] * DDS[1]; Grr[3] = DDR[0] * S[1]; Grs[3] = DR[0] * DS[1]; Gss[3] = R[0] * DDS[1]; Grr[4] = DDR[2] * S[0]; Grs[4] = DR[2] * DS[0]; Gss[4] = R[2] * DDS[0]; Grr[5] = DDR[1] * S[2]; Grs[5] = DR[1] * DS[2]; Gss[5] = R[1] * DDS[2]; Grr[6] = DDR[2] * S[1]; Grs[6] = DR[2] * DS[1]; Gss[6] = R[2] * DDS[1]; Grr[7] = DDR[0] * S[2]; Grs[7] = DR[0] * DS[2]; Gss[7] = R[0] * DDS[2]; Grr[8] = DDR[2] * S[2]; Grs[8] = DR[2] * DS[2]; Gss[8] = R[2] * DDS[2]; } //============================================================================= // T R I 3 //============================================================================= //----------------------------------------------------------------------------- void FETri3::shape_fnc(double* H, double r, double s) { H[0] = 1.0 - r - s; H[1] = r; H[2] = s; } //----------------------------------------------------------------------------- void FETri3::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -1; Hs[0] = -1; Hr[1] = 1; Hs[1] = 0; Hr[2] = 0; Hs[2] = 1; } //----------------------------------------------------------------------------- void FETri3::shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) { Hrr[0] = 0; Hrs[0] = 0; Hss[0] = 0; Hrr[1] = 0; Hrs[1] = 0; Hss[1] = 0; Hrr[2] = 0; Hrs[2] = 0; Hss[2] = 0; } //============================================================================= // T R I 6 //============================================================================= //----------------------------------------------------------------------------- void FETri6::shape_fnc(double* H, double r, double s) { double r1 = 1.0 - r - s; double r2 = r; double r3 = s; H[0] = r1*(2.0*r1 - 1.0); H[1] = r2*(2.0*r2 - 1.0); H[2] = r3*(2.0*r3 - 1.0); H[3] = 4.0*r1*r2; H[4] = 4.0*r2*r3; H[5] = 4.0*r3*r1; } //----------------------------------------------------------------------------- void FETri6::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[0] = -3.0 + 4.0*r + 4.0*s; Hr[1] = 4.0*r - 1.0; Hr[2] = 0.0; Hr[3] = 4.0 - 8.0*r - 4.0*s; Hr[4] = 4.0*s; Hr[5] = -4.0*s; Hs[0] = -3.0 + 4.0*s + 4.0*r; Hs[1] = 0.0; Hs[2] = 4.0*s - 1.0; Hs[3] = -4.0*r; Hs[4] = 4.0*r; Hs[5] = 4.0 - 8.0*s - 4.0*r; } //----------------------------------------------------------------------------- void FETri6::shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) { Hrr[0] = 4.0; Hrs[0] = 4.0; Hss[0] = 4.0; Hrr[1] = 4.0; Hrs[1] = 0.0; Hss[1] = 0.0; Hrr[2] = 0.0; Hrs[2] = 0.0; Hss[2] = 4.0; Hrr[3] = -8.0; Hrs[3] = -4.0; Hss[3] = 0.0; Hrr[4] = 0.0; Hrs[4] = 4.0; Hss[4] = 0.0; Hrr[5] = 0.0; Hrs[5] = -4.0; Hss[5] = -8.0; } //============================================================================= // T R I 7 //============================================================================= //----------------------------------------------------------------------------- void FETri7::shape_fnc(double* H, double r, double s) { double r1 = 1.0 - r - s; double r2 = r; double r3 = s; H[6] = 27.0*r1*r2*r3; H[0] = r1*(2.0*r1 - 1.0) + H[6] / 9.0; H[1] = r2*(2.0*r2 - 1.0) + H[6] / 9.0; H[2] = r3*(2.0*r3 - 1.0) + H[6] / 9.0; H[3] = 4.0*r1*r2 - 4.0*H[6] / 9.0; H[4] = 4.0*r2*r3 - 4.0*H[6] / 9.0; H[5] = 4.0*r3*r1 - 4.0*H[6] / 9.0; } //----------------------------------------------------------------------------- void FETri7::shape_deriv(double* Hr, double* Hs, double r, double s) { Hr[6] = 27.0*s*(1.0 - 2.0*r - s); Hr[0] = -3.0 + 4.0*r + 4.0*s + Hr[6] / 9.0; Hr[1] = 4.0*r - 1.0 + Hr[6] / 9.0; Hr[2] = 0.0 + Hr[6] / 9.0; Hr[3] = 4.0 - 8.0*r - 4.0*s - 4.0*Hr[6] / 9.0; Hr[4] = 4.0*s - 4.0*Hr[6] / 9.0; Hr[5] = -4.0*s - 4.0*Hr[6] / 9.0; Hs[6] = 27.0*r*(1.0 - r - 2.0*s); Hs[0] = -3.0 + 4.0*s + 4.0*r + Hs[6] / 9.0; Hs[1] = 0.0 + Hs[6] / 9.0; Hs[2] = 4.0*s - 1.0 + Hs[6] / 9.0; Hs[3] = -4.0*r - 4.0*Hs[6] / 9.0; Hs[4] = 4.0*r - 4.0*Hs[6] / 9.0; Hs[5] = 4.0 - 8.0*s - 4.0*r - 4.0*Hs[6] / 9.0; } //----------------------------------------------------------------------------- void FETri7::shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) { Hrr[6] = -54.0*s; Hss[6] = -54.0*r; Hrs[6] = 27.0*(1.0 - 2.0*r - 2.0*s); Hrr[0] = 4.0 + Hrr[6] / 9.0; Hrs[0] = 4.0 + Hrs[6] / 9.0; Hss[0] = 4.0 + Hss[6] / 9.0; Hrr[1] = 4.0 + Hrr[6] / 9.0; Hrs[1] = 0.0 + Hrs[6] / 9.0; Hss[1] = 0.0 + Hss[6] / 9.0; Hrr[2] = 0.0 + Hrr[6] / 9.0; Hrs[2] = 0.0 + Hrs[6] / 9.0; Hss[2] = 4.0 + Hss[6] / 9.0; Hrr[3] = -8.0 - 4.0*Hrr[6] / 9.0; Hrs[3] = -4.0 - 4.0*Hrs[6] / 9.0; Hss[3] = 0.0 - 4.0*Hss[6] / 9.0; Hrr[4] = 0.0 - 4.0*Hrr[6] / 9.0; Hrs[4] = 4.0 - 4.0*Hrs[6] / 9.0; Hss[4] = 0.0 - 4.0*Hss[6] / 9.0; Hrr[5] = 0.0 - 4.0*Hrr[6] / 9.0; Hrs[5] = -4.0 - 4.0*Hrs[6] / 9.0; Hss[5] = -8.0 - 4.0*Hss[6] / 9.0; } //============================================================================= // T R I 10 //============================================================================= //----------------------------------------------------------------------------- void FETri10::shape_fnc(double* H, double r, double s) { double L1 = 1.0 - r - s; double L2 = r; double L3 = s; H[0] = 0.5*(3 * L1 - 1)*(3 * L1 - 2)*L1; H[1] = 0.5*(3 * L2 - 1)*(3 * L2 - 2)*L2; H[2] = 0.5*(3 * L3 - 1)*(3 * L3 - 2)*L3; H[3] = 4.5*(3 * L1 - 1)*L1*L2; H[4] = 4.5*(3 * L2 - 1)*L1*L2; H[5] = 4.5*(3 * L2 - 1)*L2*L3; H[6] = 4.5*(3 * L3 - 1)*L2*L3; H[7] = 4.5*(3 * L1 - 1)*L1*L3; H[8] = 4.5*(3 * L3 - 1)*L1*L3; H[9] = 27.*L1*L2*L3; } //----------------------------------------------------------------------------- void FETri10::shape_deriv(double* Hr, double* Hs, double r, double s) { double L1 = 1.0 - r - s; double L2 = r; double L3 = s; Hr[0] = -3. / 2.*(3 * L1 - 2)*L1 - 3. / 2.*(3 * L1 - 1)*L1 - 0.5*(3 * L1 - 1)*(3 * L1 - 2); Hr[1] = 3. / 2.*(3 * L2 - 2)*L2 + 3. / 2.*(3 * L2 - 1)*L2 + 0.5*(3 * L2 - 1)*(3 * L2 - 2); Hr[2] = 0.0; Hr[3] = -27. / 2.*L1*L2 - 9. / 2.*(3 * L1 - 1)*L2 + 9. / 2.*(3 * L1 - 1)*L1; Hr[4] = 27. / 2.*L1*L2 - 9. / 2.*(3 * L2 - 1)*L2 + 9. / 2.*(3 * L2 - 1)*L1; Hr[5] = 27. / 2.*L2*L3 + 9. / 2.*(3 * L2 - 1)*L3; Hr[6] = 9. / 2.*(3 * L3 - 1)*L3; Hr[7] = -27. / 2.*L1*L3 - 9. / 2.*(3 * L1 - 1)*L3; Hr[8] = -9. / 2.*(3 * L3 - 1)*L3; Hr[9] = -27.*L2*L3 + 27.*L1*L3; Hs[0] = -3. / 2.*(3 * L1 - 2)*L1 - 3. / 2.*(3 * L1 - 1)*L1 - 0.5*(3 * L1 - 1)*(3 * L1 - 2); Hs[1] = 0.0; Hs[2] = 3. / 2.*(3 * L3 - 2)*L3 + 3. / 2.*(3 * L3 - 1)*L3 + 0.5*(3 * L3 - 1)*(3 * L3 - 2); Hs[3] = -27. / 2.*L1*L2 - 9. / 2.*(3 * L1 - 1)*L2; Hs[4] = -9. / 2.*(3 * L2 - 1)*L2; Hs[5] = 9. / 2.*(3 * L2 - 1)*L2; Hs[6] = 27. / 2.*L2*L3 + 9. / 2.*(3 * L3 - 1)*L2; Hs[7] = -27. / 2.*L1*L3 - 9. / 2.*(3 * L1 - 1)*L3 + 9. / 2.*(3 * L1 - 1)*L1; Hs[8] = 27. / 2.*L1*L3 - 9. / 2.*(3 * L3 - 1)*L3 + 9. / 2.*(3 * L3 - 1)*L1; Hs[9] = -27.*L2*L3 + 27.*L1*L2; } //----------------------------------------------------------------------------- void FETri10::shape_deriv2(double* Hrr, double* Hss, double* Hrs, double r, double s) { // TODO: Implement this }
C++
3D
febiosoftware/FEBio
FECore/NodeDataRecord.cpp
.cpp
3,804
112
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "NodeDataRecord.h" #include "FEAnalysis.h" #include "FECoreKernel.h" #include "FEModel.h" //----------------------------------------------------------------------------- NodeDataRecord::NodeDataRecord(FEModel* pfem) : DataRecord(pfem, FE_DATA_NODE) {} //----------------------------------------------------------------------------- int NodeDataRecord::Size() const { return (int)m_Data.size(); } //----------------------------------------------------------------------------- void NodeDataRecord::SetData(const char* szexpr) { char szcopy[MAX_STRING] = {0}; strcpy(szcopy, szexpr); char* sz = szcopy, *ch; m_Data.clear(); strcpy(m_szdata, szexpr); FEModel* fem = GetFEModel(); do { ch = strchr(sz, ';'); if (ch) *ch++ = 0; FELogNodeData* pdata = fecore_new<FELogNodeData>(sz, fem); if (pdata) m_Data.push_back(pdata); else { // see if this refers to a DOF of the model int ndof = fem->GetDOFIndex(sz); if (ndof >= 0) { // Add an output for a nodal variable pdata = new FENodeVarData(fem, ndof); m_Data.push_back(pdata); } else throw UnknownDataField(sz); } sz = ch; } while (ch); } //----------------------------------------------------------------------------- double NodeDataRecord::Evaluate(int item, int ndata) { FEMesh& mesh = GetFEModel()->GetMesh(); int nnode = item - 1; assert((nnode>=0)&&(nnode<mesh.Nodes())); if ((nnode < 0) || (nnode >= mesh.Nodes())) return 0; FENode& node = mesh.Node(nnode); return m_Data[ndata]->value(node); } //----------------------------------------------------------------------------- void NodeDataRecord::SelectAllItems() { int n = GetFEModel()->GetMesh().Nodes(); m_item.resize(n); for (int i=0; i<n; ++i) m_item[i] = i+1; } //----------------------------------------------------------------------------- void NodeDataRecord::SetItemList(FEItemList* items, const std::vector<int>& selection) { // TODO: We don't support using a selection of a node set yet. assert(selection.empty()); FENodeSet* pns = dynamic_cast<FENodeSet*>(items); assert(pns); int n = pns->Size(); m_item.resize(n); for (int i = 0; i < n; ++i) m_item[i] = (*pns)[i] + 1; } //----------------------------------------------------------------------------- FENodeVarData::FENodeVarData(FEModel* pfem, int ndof) : FELogNodeData(pfem), m_ndof(ndof) {} //----------------------------------------------------------------------------- double FENodeVarData::value(const FENode& node) { return node.get(m_ndof); }
C++
3D
febiosoftware/FEBio
FECore/SkylineMatrix.cpp
.cpp
4,973
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 "SkylineMatrix.h" using namespace std; //============================================================================= // SkylineMatrix //============================================================================= //----------------------------------------------------------------------------- SkylineMatrix::SkylineMatrix() { m_ppointers = 0; m_pd = 0; } //----------------------------------------------------------------------------- SkylineMatrix::~SkylineMatrix() { Clear(); } //----------------------------------------------------------------------------- void SkylineMatrix::Zero() { memset(m_pd, 0, m_nsize*sizeof(double)); } //----------------------------------------------------------------------------- void SkylineMatrix::Clear() { if (m_pd ) delete [] m_pd ; m_pd = 0; if (m_ppointers) delete [] m_ppointers; m_ppointers = 0; SparseMatrix::Clear(); } //----------------------------------------------------------------------------- //! \todo Can I get rid of this function? void SkylineMatrix::Create(double* pv, int* pp, int N) { delete [] m_pd ; m_pd = pv; delete [] m_ppointers; m_ppointers = pp; m_nrow = m_ncol = N; m_nsize = pp[N]; } //----------------------------------------------------------------------------- void SkylineMatrix::Create(SparseMatrixProfile& mp) { int neq = mp.Rows(); int* pointers = new int[neq + 1]; pointers[0] = 0; for (int i=1; i<=neq; ++i) { SparseMatrixProfile::ColumnProfile& a = mp.Column(i-1); int n = i - a[0].start; pointers[i] = pointers[i-1] + n; } // allocate stiffness matrix double* values = new double[pointers[neq]]; if (values==0) { double falloc = (double) sizeof(double) * (double) (pointers[neq]); } // create the matrix Create(values, pointers, neq); } //----------------------------------------------------------------------------- //! This function assembles the local stiffness matrix //! into the global stiffness matrix which is in skyline format //! void SkylineMatrix::Assemble(const matrix& ke, const vector<int>& LM) { int i, j, I, J; const int N = ke.rows(); double* pv = values(); int* pi = pointers(); for (i=0; i<N; ++i) { I = LM[i]; if (I>=0) { for (j=0; j<N; ++j) { J = LM[j]; // only add values to upper-diagonal part of stiffness matrix if (J>=I) { #pragma omp atomic pv[ pi[J] + J - I] += ke[i][j]; } } } } } //----------------------------------------------------------------------------- void SkylineMatrix::Assemble(const matrix& ke, const vector<int>& LMi, const vector<int>& LMj) { int i, j, I, J; const int N = ke.rows(); const int M = ke.columns(); double* pv = values(); int* pi = pointers(); for (i=0; i<N; ++i) { I = LMi[i]; if (I>=0) { for (j=0; j<M; ++j) { J = LMj[j]; // only add values to upper-diagonal part of stiffness matrix if (J>=I) { #pragma omp atomic pv[ pi[J] + J - I] += ke[i][j]; } } } } } bool SkylineMatrix::check(int i, int j) { assert(false); return true; } void SkylineMatrix::add(int i, int j, double v) { // only add to the upper triangular part if (j >= i) { #pragma omp atomic m_pd[m_ppointers[j] + j - i] += v; } } void SkylineMatrix::set(int i, int j, double v) { // only add to the upper triangular part if (j >= i) { #pragma omp critical (SKY_set) m_pd[m_ppointers[j] + j - i] = v; } } double SkylineMatrix::get(int i, int j) { if (i>j) { i^= j; j ^= i; i ^= j; } int l = m_ppointers[j+1] - m_ppointers[j]; if (j-i < l) return m_pd[ m_ppointers[j] + j-i]; return 0; } double SkylineMatrix::diag(int i) { return m_pd[ m_ppointers[i] ]; }
C++
3D
febiosoftware/FEBio
FECore/FEElementList.cpp
.cpp
1,974
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.*/ #include "stdafx.h" #include "FEElementList.h" #include "FEMesh.h" #include "FEDomain.h" FEElement& FEElementList::iterator::operator*() { return m_pmesh->Domain(m_ndom).ElementRef(m_nel); } FEElement* FEElementList::iterator::operator->() { return &m_pmesh->Domain(m_ndom).ElementRef(m_nel); } FECORE_API FEElementList::iterator::operator FEElement* () { return &m_pmesh->Domain(m_ndom).ElementRef(m_nel); } void FEElementList::iterator::operator ++ () { if (m_pmesh && (m_ndom >= 0) && (m_nel >= 0)) { m_nel++; if (m_nel >= m_pmesh->Domain(m_ndom).Elements()) { m_ndom++; m_nel = 0; if (m_ndom >= m_pmesh->Domains()) { m_ndom = -1; m_nel = -1; } } } }
C++
3D
febiosoftware/FEBio
FECore/FENLConstraint.cpp
.cpp
1,641
43
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FENLConstraint.h" //----------------------------------------------------------------------------- FENLConstraint::FENLConstraint(FEModel* pfem) : FEStepComponent(pfem) { static int ncount = 1; SetID(ncount++); } //----------------------------------------------------------------------------- FENLConstraint::~FENLConstraint() { }
C++
3D
febiosoftware/FEBio
FECore/FENodeList.cpp
.cpp
2,612
106
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FENodeList.h" #include "FEMesh.h" #include "DumpStream.h" FENodeList::FENodeList(FEMesh* mesh) : m_mesh(mesh) { } FENodeList::FENodeList(const FENodeList& nodeList) { m_mesh = nodeList.m_mesh; m_nodes = nodeList.m_nodes; } FENodeList& FENodeList::operator = (const FENodeList& nodeList) { m_mesh = nodeList.m_mesh; m_nodes = nodeList.m_nodes; return *this; } void FENodeList::Add(int n) { assert(m_mesh); assert((n >= 0) && (n < m_mesh->Nodes())); m_nodes.push_back(n); } void FENodeList::Add(const std::vector<int>& nodeList) { assert(m_mesh); m_nodes.insert(m_nodes.end(), nodeList.begin(), nodeList.end()); } void FENodeList::Add(const FENodeList& nodeList) { assert(m_mesh == nodeList.m_mesh); Add(nodeList.m_nodes); } void FENodeList::Clear() { m_nodes.clear(); } FENode* FENodeList::Node(int i) { assert(m_mesh); return &m_mesh->Node(m_nodes[i]); } const FENode* FENodeList::Node(int i) const { assert(m_mesh); return &m_mesh->Node(m_nodes[i]); } int FENodeList::Size() const { return (int)m_nodes.size(); } void FENodeList::Serialize(DumpStream& ar) { if (ar.IsShallow() == false) ar & m_mesh; ar & m_nodes; } int FENodeList::GlobalToLocalID(int globalId) const { for (int i = 0; i < m_nodes.size(); ++i) { if (m_nodes[i] == globalId) return i; } return -1; }
C++
3D
febiosoftware/FEBio
FECore/matrix.cpp
.cpp
17,635
690
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "matrix.h" #include <assert.h> #include <math.h> #include <memory> using namespace std; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// //----------------------------------------------------------------------------- // These functions are defined in colsol.cpp void lubksb(double**a, int n, int *indx, double b[]); void ludcmp(double**a, int n, int* indx); //----------------------------------------------------------------------------- // These functions are defined in svd.cpp void svbksb(matrix& u, vector<double>& w, matrix& v, vector<double>& b, vector<double>& x); void svdcmp(matrix& a, vector<double>& w, matrix& v); //----------------------------------------------------------------------------- vector<double> operator / (vector<double>& b, matrix& m) { int n = (int)b.size(); vector<double> x(b); vector<int> indx(n); matrix a(m); ludcmp(a, n, &indx[0]); lubksb(a, n, &indx[0], &x[0]); return x; } vector<double> operator * (matrix& m, vector<double>& b) { int i, j; int NR = m.rows(); int NC = m.columns(); assert(NC == b.size()); vector<double> r(NR); for (i=0; i<NR; ++i) { r[i] = 0.0; for (j=0; j<NC; ++j) r[i] += m[i][j]*b[j]; } return r; } //----------------------------------------------------------------------------- void matrix::alloc(int nr, int nc) { m_nr = nr; m_nc = nc; m_nsize = nr*nc; m_pd = new double [m_nsize]; m_pr = new double*[nr]; for (int i=0; i<nr; i++) m_pr[i] = m_pd + i*nc; } //----------------------------------------------------------------------------- //! Constructor for matrix class. matrix::matrix(int nr, int nc) { alloc(nr, nc); } //----------------------------------------------------------------------------- //! matrix destructor void matrix::clear() { if (m_pr) delete [] m_pr; if (m_pd) delete [] m_pd; m_pd = 0; m_pr = 0; m_nr = m_nc = 0; } //----------------------------------------------------------------------------- //! Copy constructor for matrix class. matrix::matrix(const matrix& m) { alloc(m.m_nr, m.m_nc); for (int i=0; i<m_nsize; ++i) m_pd[i] = m.m_pd[i]; } //----------------------------------------------------------------------------- //! constructor matrix::matrix(const mat3d& m) { alloc(3, 3); m_pr[0][0] = m[0][0]; m_pr[0][1] = m[0][1]; m_pr[0][2] = m[0][2]; m_pr[1][0] = m[1][0]; m_pr[1][1] = m[1][1]; m_pr[1][2] = m[1][2]; m_pr[2][0] = m[2][0]; m_pr[2][1] = m[2][1]; m_pr[2][2] = m[2][2]; } //----------------------------------------------------------------------------- //! assignment operator matrix& matrix::operator = (const mat3d& m) { resize(3, 3); m_pr[0][0] = m[0][0]; m_pr[0][1] = m[0][1]; m_pr[0][2] = m[0][2]; m_pr[1][0] = m[1][0]; m_pr[1][1] = m[1][1]; m_pr[1][2] = m[1][2]; m_pr[2][0] = m[2][0]; m_pr[2][1] = m[2][1]; m_pr[2][2] = m[2][2]; return *this; } //----------------------------------------------------------------------------- matrix& matrix::operator = (const matrix& m) { if ((m.m_nr != m_nr) || (m.m_nc != m_nc)) { clear(); alloc(m.m_nr, m.m_nc); } for (int i=0; i<m_nsize; ++i) m_pd[i] = m.m_pd[i]; return (*this); } //----------------------------------------------------------------------------- void matrix::resize(int nr, int nc) { if ((nr != m_nr) || (nc != m_nc)) { clear(); alloc(nr, nc); } } //----------------------------------------------------------------------------- matrix matrix::operator * (double a) const { matrix m(m_nr, m_nc); int n = m_nr*m_nc; for (int i = 0; i < n; ++i) m.m_pd[i] = m_pd[i] * a; return m; } //----------------------------------------------------------------------------- matrix matrix::operator * (const matrix& m) const { assert(m_nc == m.m_nr); matrix a(m_nr, m.m_nc); // NOTE: commented this out since this can be called for small matrices. // TODO: make a separate function that implements a parallel version. (e.g. pmult) // #pragma omp parallel for shared(a) for (int i = 0; i < m_nr; ++i) { double* pa = a.m_pr[i]; for (int j = 0; j < m.m_nc; ++j) pa[j] = 0.0; for (int k = 0; k < m_nc; ++k) { const double pik = m_pr[i][k]; const double* pm = m.m_pr[k]; for (int j = 0; j < m.m_nc; ++j) { pa[j] += pik * pm[j]; } } } return a; } //----------------------------------------------------------------------------- void matrix::add(int i, int j, const matrix& m) { int mr = m.rows(); int mc = m.columns(); for (int r = 0; r < mr; ++r) for (int c = 0; c < mc; ++c) m_pr[i + r][j + c] += m[r][c]; } //----------------------------------------------------------------------------- void matrix::add(int i, int j, const vec3d& a) { m_pr[i ][j] += a.x; m_pr[i+1][j] += a.y; m_pr[i+2][j] += a.z; } //----------------------------------------------------------------------------- void matrix::adds(int i, int j, const matrix& m, double s) { int mr = m.rows(); int mc = m.columns(); for (int r = 0; r < mr; ++r) for (int c = 0; c < mc; ++c) m_pr[i + r][j + c] += m[r][c]*s; } //----------------------------------------------------------------------------- void matrix::adds(const matrix& m, double s) { const int mr = m.rows(); const int mc = m.columns(); for (int r = 0; r < mr; ++r) for (int c = 0; c < mc; ++c) m_pr[r][c] += m[r][c] * s; } //----------------------------------------------------------------------------- // Calculate the LU decomposition of this matrix. Note that this will modify // the matrix. This is used for repeated solves of a linear system. Use // lusolve for solving after lufactor. void matrix::lufactor(vector<int>& indx) { // make sure this is a square matrix assert(m_nr == m_nc); // do a LU decomposition int n = m_nr; indx.resize(n); ludcmp(*(this), n, &indx[0]); } //----------------------------------------------------------------------------- // Solve the linear system Ax=b, where A has been factored using lufactor. // The indx array is the same one that was returned from lufactor void matrix::lusolve(vector<double>& b, vector<int>& indx) { // make sure this is a square matrix assert(m_nr == m_nc); lubksb(*(this), m_nr, &indx[0], &b[0]); } //----------------------------------------------------------------------------- matrix matrix::inverse() { // make sure this is a square matrix assert(m_nr == m_nc); // make a copy of this matrix // since we don't want to change it matrix a(*this); // do a LU decomposition int n = m_nr; vector<int> indx(n); ludcmp(a, n, &indx[0]); // allocate the inverse matrix matrix ai(n, n); // do a backsubstituation on the columns of a vector<double> b; b.assign(n, 0); for (int j=0; j<n; ++j) { b[j] = 1; lubksb(a, n, &indx[0], &b[0]); for (int i=0; i<n; ++i) { ai[i][j] = b[i]; b[i] = 0; } } return ai; } //----------------------------------------------------------------------------- // Matrix using singular value decomposition matrix matrix::svd_inverse() { matrix U(*this); matrix V(m_nr, m_nc); vector<double> w(m_nc); // calculate the decomposition svdcmp(U, w, V); matrix Ai(m_nc, m_nr); // inverse for (int i=0; i<m_nc; ++i) for (int j=0; j<m_nr; ++j) { double s = 0.0; for (int k=0;k<m_nc; ++k) { if (w[k] > 0.0) { s += (V[i][k]*U[j][k])/w[k]; } } Ai[i][j] = s; } return Ai; } //----------------------------------------------------------------------------- matrix matrix::transpose() const { int i, j; matrix At(m_nc, m_nr); for (i=0; i<m_nr; ++i) for (j=0; j<m_nc; ++j) At[j][i] = m_pr[i][j]; return At; } //----------------------------------------------------------------------------- matrix& matrix::operator += (const matrix& m) { assert((m_nr == m.m_nr ) && (m_nc == m.m_nc)); for (int i=0; i<m_nsize; ++i) m_pd[i] += m.m_pd[i]; return (*this); } //----------------------------------------------------------------------------- matrix& matrix::operator -= (const matrix& m) { assert((m_nr == m.m_nr ) && (m_nc == m.m_nc)); for (int i=0; i<m_nsize; ++i) m_pd[i] -= m.m_pd[i]; return (*this); } //----------------------------------------------------------------------------- matrix matrix::operator * (const vec3d& v) const { assert(m_nc == 3); matrix A(m_nr, 1); const matrix& T = *this; for (int i = 0; i < m_nr; ++i) { A[i][0] = T[i][0]*v.x + T[i][1] * v.y + T[i][2] * v.z; } return A; } //----------------------------------------------------------------------------- // calculate outer product of a vector to produce a matrix matrix outer_product(vector<double>& a) { int n = (int) a.size(); matrix m(n,n); for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) m[i][j] = a[i]*a[j]; } return m; } //----------------------------------------------------------------------------- // Calculates the infinity norm. That is, the max of the absolute row sum. double matrix::inf_norm() { matrix& self = (*this); double m = 0; for (int j=0; j<m_nr; ++j) { double s = 0; for (int i=0; i<m_nc; ++i) s += fabs(self[j][i]); if (s > m) m = s; } return m; } //----------------------------------------------------------------------------- void matrix::get(int i, int j, int rows, int cols, matrix& A) const { // make sure we create a valid matrix if ((rows <= 0) || (cols <= 0)) return; // initialize the matrix A.resize(rows, cols); A.zero(); // make sure the bounds are within this matrix if ((i >= m_nr) || (j >= m_nc)) return; if ((i + rows <= 0) || (j + cols <= 0)) return; // set range int r0 = 0; int r1 = rows - 1; int c0 = 0; int c1 = cols - 1; if (i < 0) r0 -= i; if (j < 0) c0 -= j; if (i + rows > m_nr) r1 -= rows + i - m_nr; if (j + cols > m_nc) c1 -= cols + j - m_nc; for (int r=r0; r<=r1; ++r) for (int c=c0; c<=c1; ++c) A[r][c] = (*this)(i+r, j+c); } //----------------------------------------------------------------------------- // fill a matrix void matrix::fill(int i, int j, int rows, int cols, double val) { if ((i >= m_nr) || (j >= m_nc)) return; if ((i + rows <= 0) || (j + cols <= 0)) return; int r0 = 0; int r1 = rows - 1; int c0 = 0; int c1 = cols - 1; if (i < 0) r0 -= i; if (j < 0) c0 -= j; if (i + rows > m_nr) r1 -= rows + i - m_nr; if (j + cols > m_nc) c1 -= cols + j - m_nc; for (int r = r0; r<=r1; ++r) for (int c = c0; c<=c1; ++c) (*this)(i + r, j + c) = val; } //----------------------------------------------------------------------------- // solve the linear system Ax=b void matrix::solve(vector<double>& x, const vector<double>& b) { matrix A(*this); vector<int> index; A.lufactor(index); x = b; A.lusolve(x, index); } //----------------------------------------------------------------------------- matrix matrix::operator + (const matrix& m) const { matrix s(*this); for (int i=0; i<m_nr; ++i) for (int j=0; j<m_nc; ++j) s(i,j) += m(i,j); return s; } //----------------------------------------------------------------------------- matrix matrix::operator - (const matrix& m) const { matrix s(*this); for (int i = 0; i<m_nr; ++i) for (int j = 0; j<m_nc; ++j) s(i, j) -= m(i, j); return s; } //----------------------------------------------------------------------------- void matrix::mult(vector<double>& x, vector<double>& y) { for (int i = 0; i < m_nr; ++i) { double* di = m_pd + i * m_nc; y[i] = 0.0; for (int j = 0; j < m_nc; ++j) y[i] += di[j] * x[j]; } } // Here y = this*m*x. This is useful if this*m is a very large matrix, // but is then immediately multiplied by a vector, brining its size down // to m_nr x 1. In this unique circumstance, the memory requrements can be // drastically lower. void matrix::mult(const matrix& m, std::vector<double>& x, std::vector<double>& y) { assert(m_nc == m.m_nr); assert(m.m_nc == x.size()); y.assign(m_nr, 0.0); int nx = (int)x.size(); vector<double> tmp(m_nc, 0.0); #pragma omp parallel shared(tmp) { #pragma omp for for (int i = 0; i < m_nc; ++i) { for (int k = 0; k < nx; ++k) tmp[i] += m.m_pr[i][k] * x[k]; } #pragma omp for for (int i = 0; i < m_nr; ++i) { for (int k = 0; k < m_nc; ++k) y[i] += m_pr[i][k] * tmp[k]; } } } //----------------------------------------------------------------------------- void matrix::mult_transpose(vector<double>& x, vector<double>& y) { for (int i = 0; i < m_nc; ++i) y[i] = 0.0; for (int i = 0; i < m_nr; ++i) { double* di = m_pd + i * m_nc; for (int j = 0; j < m_nc; ++j) y[j] += di[j] * x[i]; } } //----------------------------------------------------------------------------- void matrix::mult_transpose_self(matrix& AAt) { matrix& A = *this; int N = m_nc; int R = m_nr; for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) { double& aij = AAt[i][j]; aij = 0.0; for (int k = 0; k < R; ++k) aij += A[k][i] * A[k][j]; } } //----------------------------------------------------------------------------- bool matrix::lsq_solve(vector<double>& x, vector<double>& b) { if ((int)x.size() != m_nc) return false; if ((int)b.size() != m_nr) return false; vector<double> y(m_nc); mult_transpose(b, y); matrix AA(m_nc, m_nc); mult_transpose_self(AA); AA.solve(x, y); return true; } #define ROTATE(a, i, j, k, l) g=a[i][j]; h=a[k][l];a[i][j]=g-s*(h+g*tau); a[k][l] = h + s*(g - h*tau); //----------------------------------------------------------------------------- bool matrix::eigen_vectors(matrix& Eigen, vector<double>& eigen_values) { matrix& A = *this; int N = m_nc; int R = m_nr; const int NMAX = 50; double sm, tresh, g, h, t, c, tau, s, th; const double eps = 0;//1.0e-15; int k; //initialize Eigen to identity for (int i = 0; i < R; i++) { for (int j = 0; j < N; j++) Eigen[i][j] = 0; Eigen[i][i] = 1; } vector<double> b; b.reserve(R); vector<double> z; z.reserve(R); // initialize b and eigen_values to the diagonal of A for (int i = 0; i < R; i++) { b.push_back(A[i][i]); eigen_values.push_back(A[i][i]); z.push_back(0); } // loop int n, nrot = 0; for (n = 0; n < NMAX; ++n) { // sum off-diagonal elements sm = 0; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) sm += fabs(A[i][j]); } if (sm <= eps) { break; } // set the treshold if (n < 3) tresh = 0.2 * sm / (R * R); else tresh = 0.0; // loop over off-diagonal elements for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { g = 100.0 * fabs(A[i][j]); // after four sweeps, skip the rotation if the off-diagonal element is small if ((n > 3) && ((fabs(eigen_values[i]) + g) == fabs(eigen_values[i])) && ((fabs(eigen_values[j]) + g) == fabs(eigen_values[j]))) { A[i][j] = 0.0; } else if (fabs(A[i][j]) > tresh) { h = eigen_values[j] - eigen_values[i]; if ((fabs(h) + g) == fabs(h)) t = A[i][j] / h; else { th = 0.5 * h / A[i][j]; t = 1.0 / (fabs(th) + sqrt(1 + th * th)); if (th < 0.0) t = -t; } c = 1.0 / sqrt(1.0 + t * t); s = t * c; tau = s / (1.0 + c); h = t * A[i][j]; z[i] -= h; z[j] += h; eigen_values[i] -= h; eigen_values[j] += h; A[i][j] = 0; for (k = 0; k <= i - 1; ++k) { ROTATE(A, k, i, k, j) } for (k = i + 1; k <= j - 1; ++k) { ROTATE(A, i, k, k, j) } for (k = j + 1; k < N; ++k) { ROTATE(A, i, k, j, k) } for (k = 0; k < N; ++k) { ROTATE(Eigen, k, i, k, j) } ++nrot; } } }//end of for loop //Update eigen_values with the sum. Reinitialize z. for (int i = 0; i < R; ++i) { b[i] += z[i]; eigen_values[i] = b[i]; z[i] = 0.0; } } // we sure we converged assert(n < NMAX); return true; } matrix covariance(const matrix& a) { int n = a.rows(); int d = a.columns(); // calculate mean row vector vector<double> mu(d, 0.0); for (int i = 0; i < n; ++i) { for (int j = 0; j < d; ++j) mu[j] += a[i][j]; } for (int i = 0; i < d; ++i) mu[i] /= n; // normalization factor // NOTE: it is n - 1, to be consistent with MatLab! double R = (n == 1 ? 1.0 : n - 1); // calculate covariance matrix matrix c(d, d); c.zero(); for (int i = 0; i < d; ++i) for (int j = 0; j < d; ++j) { double cij = 0.0; for (int k = 0; k < n; ++k) { cij += (a[k][i] - mu[i]) * (a[k][j] - mu[j]); } cij /= R; c[i][j] = cij; } return c; }
C++
3D
febiosoftware/FEBio
FECore/DOFS.h
.h
6,572
206
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include <vector> #include <string> #include "fecore_api.h" class DumpStream; //----------------------------------------------------------------------------- // Degree of freedom types #define DOF_OPEN 0 // the dof is open and will be given an equation number #define DOF_FIXED 1 // the dof is fixed and will not be given an equation number #define DOF_PRESCRIBED 2 // the dof is prescribed. It will be given a negative equation number (equation = - index - 2) //----------------------------------------------------------------------------- // Types of variables #define VAR_SCALAR 0 // scalar variable #define VAR_VEC2 1 // 2D vector #define VAR_VEC3 2 // 3D vector #define VAR_ARRAY 3 // a variable array of scalars //----------------------------------------------------------------------------- //! Class that manages the variables and degrees of freedoms. class FECORE_API DOFS { // Class representing an individual degree of freedom class DOF_ITEM { public: enum { MAX_DOF_NAME = 8 }; public: DOF_ITEM(); DOF_ITEM(const char* sz); ~DOF_ITEM(); DOF_ITEM(const DOF_ITEM& d); void operator = (const DOF_ITEM& d); void SetName(const char* szdof); void Serialize(DumpStream& ar); public: char sz[MAX_DOF_NAME]; //!< symbol of variable int ndof; //!< index of degree of freedom int nvar; //!< variable associated with this dof }; public: // A Variable is a logical grouping of degrees of freedoms. // (e.g. a displacement variable in 3D has 3 dofs.) // The order variable is the interpolation order that should be // assumed for this variable. By default, it is set to -1, which // should be interpreted as the interpolation order implied by the // nodes of the element type. class Var { public: Var(); Var(const Var& v); void operator = (const Var& v); void Serialize(DumpStream& ar); public: int m_ntype; // type of variable int m_order; // interpolation order std::string m_name; // variable name std::vector<DOF_ITEM> m_dof; // list of dofs for this variable }; public: // constructors DOFS(); DOFS(const DOFS& dofs); DOFS& operator = (const DOFS& dofs); //! destructor ~DOFS(); //! Reset dofs void Reset(); public: //! Add a (empty) variable //! returns the new variable's index (or -1 if the variable already exists) int AddVariable(const char* szname, int ntype = VAR_SCALAR); //! Get number of variables int Variables() const; //! Get the index of a variable (returns -1 if the variable does not exist) int GetVariableIndex(const char* szname); //! Get the variable name std::string GetVariableName(int n) const; // Add a degree of freedom // Can only be used on array variables. // returns >= 0 on success and -1 on failure (e.g. if the dof is already defined) int AddDOF(const char* szvar, const char* sz); // Add a degree of freedom // Can only be used on array variables. // returns >= 0 on success and -1 on failure (e.g. if the dof is already defined) int AddDOF(int nvar, const char* sz); //! return a dof index from the dof symbol //! this function returns -1 if the symbol is not recognized int GetDOF(const char* szdof, const char* varName = nullptr); //! return a list of dofs for a variable void GetDOFList(const char* varName, std::vector<int>& dofs); //! return a list of dofs for a variable void GetDOFList(int nvar, std::vector<int>& dofs); //! return a list of dofs from comma seperated list dof symbols bool ParseDOFString(const char* sz, std::vector<int>& dofs, const char* varName = nullptr); //! return a dof index from a variable //! this function returns -1 if the symbol is not recognized int GetDOF(const char* szvar, int n); //! return the index into the variable's dof list int GetIndex(const char* varName, const char* szdof); //! return a dof index from a variable index //! this function returns -1 if the symbol is not recognized int GetDOF(int nvar, int n); //! return the size of a variable //! (returns -1 if the variable is not defined) int GetVariableSize(const char* sz); //! return the size of a variable //! (returns -1 if the variable is not defined) int GetVariableSize(int nvar); //! return the type of a variable int GetVariableType(int nvar); //! return the total number of degrees of freedom int GetTotalDOFS() const; //! Set the name of a DOF void SetDOFName(const char* szvar, int n, const char* szname); void SetDOFName(int nvar, int n, const char* szname); //! Get a dof name const char* GetDOFName(int nvar, int n); const char* GetDOFName(int ndof); //! serialization void Serialize(DumpStream& ar); //! set the interpolation order for a variable void SetVariableInterpolationOrder(int nvar, int order); // return the interpolation order of a variable int GetVariableInterpolationOrder(int nvar); // Find the variable from a dof int FindVariableFromDOF(int ndof); // return the interpolation order for a degree of freedom int GetDOFInterpolationOrder(int ndof); private: void Update(); Var* GetVariable(const char* szvar); DOF_ITEM* GetDOFPtr(const char* szdof); private: std::vector<Var> m_var; //!< array of variables int m_maxdofs; //!< total number of nodal DOFS (i.e. size of FENode::m_val array) };
Unknown
3D
febiosoftware/FEBio
FECore/FEOctreeSearch.cpp
.cpp
9,149
305
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEOctreeSearch.h" #include "FEMesh.h" #include "FEElementList.h" #include "FESolidDomain.h" //----------------------------------------------------------------------------- FEOctreeSearch::Block::Block(FEMesh* mesh, int level) { m_parent = nullptr; m_mesh = mesh; m_level = level; } //----------------------------------------------------------------------------- FEOctreeSearch::Block::Block(FEOctreeSearch::Block* parent, int level) { m_parent = parent; m_mesh = parent->m_mesh; m_level = level; } //----------------------------------------------------------------------------- FEOctreeSearch::Block::~Block() { Clear(); } //----------------------------------------------------------------------------- void FEOctreeSearch::Block::Clear() { for (size_t i = 0; i < m_children.size(); ++i) delete m_children[i]; m_children.clear(); } //----------------------------------------------------------------------------- // Create the eight children of an octree node and find their contents void FEOctreeSearch::Block::CreateChildren(const int max_level, const int max_elem) { vec3d dc = (m_cmax - m_cmin) / 2; for (int i = 0; i <= 1; ++i) { for (int j = 0; j <= 1; ++j) { for (int k = 0; k <= 1; ++k) { Block* node = new Block(this, m_level + 1); // evaluate bounding box by subdividing parent node box node->m_cmin = vec3d(m_cmin.x + i*dc.x, m_cmin.y + j*dc.y, m_cmin.z + k*dc.z); node->m_cmax = vec3d(m_cmax.x - (1 - i)*dc.x, m_cmax.y - (1 - j)*dc.y, m_cmax.z - (1 - k)*dc.z); // find all elements in this child node node->FillBlock(); if (node->m_selist.size()) { // use recursion to create children of this node // as long as node contains too many elements // and max octree levels not exceeded if ((node->m_level < max_level) && (node->m_selist.size() > max_elem)) node->CreateChildren(max_level, max_elem); } // store this node m_children.push_back(node); } } } } //----------------------------------------------------------------------------- // Find all elements that fall inside a block void FEOctreeSearch::Block::FillBlock() { // Loop over all elements in the parent node for (int i = 0; i<(int)m_parent->m_selist.size(); ++i) { FEElement* pe = m_parent->m_selist[i]; if (ElementIntersectsNode(pe)) { // add this surface element to the current node m_selist.push_back(pe); } } } //----------------------------------------------------------------------------- // Determine whether a surface element intersects a node bool FEOctreeSearch::Block::ElementIntersectsNode(FEElement* pel) { // Extract FE node coordinates from element // and determine bounding box of element FEMesh& mesh = *m_mesh; FEElement& el = *pel; int N = el.Nodes(); vector<vec3d> fenode(N); fenode[0] = mesh.Node(el.m_node[0]).m_r0; vec3d fmin = fenode[0]; vec3d fmax = fenode[0]; for (int i = 1; i<N; ++i) { fenode[i] = mesh.Node(el.m_node[i]).m_r0; if (fenode[i].x < fmin.x) fmin.x = fenode[i].x; if (fenode[i].x > fmax.x) fmax.x = fenode[i].x; if (fenode[i].y < fmin.y) fmin.y = fenode[i].y; if (fenode[i].y > fmax.y) fmax.y = fenode[i].y; if (fenode[i].z < fmin.z) fmin.z = fenode[i].z; if (fenode[i].z > fmax.z) fmax.z = fenode[i].z; } // Check if bounding boxes of OT node and surface element overlap if ((fmax.x < m_cmin.x) || (fmin.x > m_cmax.x)) return false; if ((fmax.y < m_cmin.y) || (fmin.y > m_cmax.y)) return false; if ((fmax.z < m_cmin.z) || (fmin.z > m_cmax.z)) return false; // At this point we find that bounding boxes overlap. // Technically that does not prove that the surface element is // inside the octree node, but any additional check would be // more expensive. return true; } //----------------------------------------------------------------------------- bool FEOctreeSearch::Block::IsInside(const vec3d& r) const { if ((r.x < m_cmin.x) || (r.x > m_cmax.x)) return false; if ((r.y < m_cmin.y) || (r.y > m_cmax.y)) return false; if ((r.z < m_cmin.z) || (r.z > m_cmax.z)) return false; return true; } //----------------------------------------------------------------------------- FEElement* FEOctreeSearch::Block::FindElement(const vec3d& y, double r[3]) { if (IsInside(y)) { if (m_children.empty() == false) { for (int i = 0; i < m_children.size(); ++i) { FEElement* pe = m_children[i]->FindElement(y, r); if (pe) return pe; } } else { vec3d x[FEElement::MAX_NODES]; int NE = (int)m_selist.size(); for (int i = 0; i<NE; ++i) { // get the next element FESolidElement& e = *((FESolidElement*)m_selist[i]); // get the element nodal coordinates int neln = e.Nodes(); for (int j = 0; j<neln; ++j) x[j] = m_mesh->Node(e.m_node[j]).m_r0; // first, as a quick check, we see if y lies in the bounding box defined by x FEBoundingBox box(x[0]); for (int j = 1; j<neln; ++j) box.add(x[j]); // inflate a little for round-off double dr = box.radius()*1e-6; box.inflate(dr, dr, dr); if (box.IsInside(y)) { FESolidDomain* dom = dynamic_cast<FESolidDomain*>(e.GetMeshPartition()); // If the point y lies inside the box, we apply a Newton method to find // the isoparametric coordinates r if (dom->ProjectToReferenceElement(e, y, r)) return &e; } } } } return nullptr; } ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// FEOctreeSearch::FEOctreeSearch(FEMesh* mesh) { m_root = nullptr; m_mesh = mesh; m_dom = nullptr; m_max_level = 6; m_max_elem = 9; } FEOctreeSearch::FEOctreeSearch(FEDomain* domain) { m_root = nullptr; m_mesh = domain->GetMesh(); m_dom = domain; m_max_level = 6; m_max_elem = 9; } //----------------------------------------------------------------------------- FEOctreeSearch::~FEOctreeSearch() { } //----------------------------------------------------------------------------- bool FEOctreeSearch::Init(double inflate) { if (m_mesh == nullptr) return false; // Set up the root node in the octree if (m_root) delete m_root; m_root = new Block(m_mesh, 0); Block& root = *m_root; // Create the list of all elements in the root node int nel = 0; if (m_dom == nullptr) { FEElementList EL(*m_mesh); nel = m_mesh->Elements(); for (FEElementList::iterator it = EL.begin(); it != EL.end(); ++it) root.m_selist.push_back(it); } else { nel = m_dom->Elements(); for (int i = 0; i < nel; ++i) { root.m_selist.push_back(&m_dom->ElementRef(i)); } } // Find the bounding box of the mesh vec3d r0 = (m_mesh->Node(0)).m_r0; root.m_cmin = r0; root.m_cmax = r0; for (int i = 1; i<m_mesh->Nodes(); ++i) { vec3d r = (m_mesh->Node(i)).m_r0; if (r.x < root.m_cmin.x) root.m_cmin.x = r.x; if (r.x > root.m_cmax.x) root.m_cmax.x = r.x; if (r.y < root.m_cmin.y) root.m_cmin.y = r.y; if (r.y > root.m_cmax.y) root.m_cmax.y = r.y; if (r.z < root.m_cmin.z) root.m_cmin.z = r.z; if (r.z > root.m_cmax.z) root.m_cmax.z = r.z; } // expand bounding box by search tolerance stol double d = (root.m_cmax - root.m_cmin).norm()*inflate; root.m_cmin -= vec3d(d, d, d); root.m_cmax += vec3d(d, d, d); // figure out the levels int level = (int) (log((double)nel) / log(8.0)); if (level < 1) level = 1; if (level > m_max_level) level = m_max_level - 1; // Recursively create children of this root if (root.m_selist.size()) { if ((root.m_level < m_max_level) && (root.m_selist.size() > m_max_elem)) root.CreateChildren(level, m_max_elem); } return true; } //----------------------------------------------------------------------------- FEElement* FEOctreeSearch::FindElement(const vec3d& x, double r[3]) { return m_root->FindElement(x, r); }
C++
3D
febiosoftware/FEBio
FECore/MItem.h
.h
27,941
696
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "MFunctions.h" #include "MTypes.h" #include <vector> #include <assert.h> #include <string> #include <string.h> //----------------------------------------------------------------------------- // This exception will get thrown when an invalid operation is performed. class InvalidOperation {}; class DivisionByZero {}; //----------------------------------------------------------------------------- // The following classes define the componenents of a mathematical expression enum Item_Type { MCONST, MFRAC, MNAMED, MVAR, MBOOL, MMATRIX, MNEG, MADD, MSUB, MMUL, MDIV, MPOW, MEQUATION, MEQUALITY, MF1D, MF2D, MFND, MFMAT, MFMAT2, MSFNC, MINTEGRAL, MSEQUENCE }; //----------------------------------------------------------------------------- // stores the value of a variable class MVariable { public: MVariable(const std::string& s, double initVal = 0.0) : m_v(initVal), m_name(s), m_index(-1) {} MVariable(const MVariable& v) : m_v(0), m_name(v.m_name), m_index(-1) {} void operator = (const MVariable& v) { m_name = v.m_name; m_index = v.m_index; } double value() const { return m_v; } void value(double v) { m_v = v; } const std::string& Name() const { return m_name; } void setIndex(int n) { m_index = n; } int index() const { return m_index; } protected: double m_v; int m_index; std::string m_name; }; //----------------------------------------------------------------------------- // base class for Math items // a math item can be a constant, a variable, a matrix, an operator or a function class MItem { public: MItem(Item_Type ntype) : m_ntype(ntype) {} virtual ~MItem(){} // return the item's type Item_Type Type() const { return m_ntype; } // create a copy of this item virtual MItem* copy() const = 0; protected: Item_Type m_ntype; }; //----------------------------------------------------------------------------- // base class for numbers. // numbers can be either constant or variables. class MNumber : public MItem { public: MNumber(Item_Type ntype) : MItem(ntype){} // return the float value for this number virtual double value() const = 0; }; //----------------------------------------------------------------------------- // defines a constant number class MConstant : public MNumber { public: MConstant(double x) : MNumber(MCONST), m_v(x) { assert(m_v>=0); } void value(double v) { m_v = v; } public: double value() const override { return m_v; } MItem* copy() const override { return new MConstant(m_v); } private: double m_v; }; //----------------------------------------------------------------------------- // defines a constant fraction class MFraction : public MNumber { public: MFraction(double a, double b) : MNumber(MFRAC), m_v(a,b) {} MFraction(const FRACTION& a) : MNumber(MFRAC), m_v(a) {} FRACTION fraction() const { return m_v; } public: double value() const override { return m_v.n / m_v.d; } MItem* copy() const override { return new MFraction(m_v); } private: FRACTION m_v; }; //----------------------------------------------------------------------------- // defines a named constant number class MNamedCt : public MNumber { public: MNamedCt(double x, const std::string& sz) : MNumber(MNAMED), m_v(x), m_name(sz) {} const std::string& Name() const { return m_name; } public: double value() const override { return m_v; } MItem* copy() const override { return new MNamedCt(m_v, m_name); } private: double m_v; std::string m_name; }; //----------------------------------------------------------------------------- // defines a reference to a variable class MVarRef : public MNumber { public: MVarRef(const MVariable* pv) : MNumber(MVAR), m_pv(pv) {} const MVariable* GetVariable() const { return m_pv; } const std::string& Name() const { return m_pv->Name(); } int index() const { return m_pv->index(); } void SetVariable(const MVariable* v) { m_pv = v; } public: double value() const override { return m_pv->value(); } MItem* copy() const override { return new MVarRef(m_pv); } private: const MVariable* m_pv; }; //----------------------------------------------------------------------------- // Item for representing boolean values class MBoolean : public MItem { public: MBoolean(bool b) : MItem(MBOOL), m_b(b) {} MItem* copy() const override { return new MBoolean(m_b); } bool value() { return m_b; } private: bool m_b; }; //----------------------------------------------------------------------------- // base class for unary operations class MUnary : public MItem { public: MUnary(MItem* pi, Item_Type ntype) : MItem(ntype), m_pi(pi) {} ~MUnary() { delete m_pi; } MItem* Item() { return m_pi; } const MItem* Item() const { return m_pi; } protected: MItem* m_pi; }; //----------------------------------------------------------------------------- // base class for binary operations class MBinary : public MItem { public: MBinary(MItem* pl, MItem* pr, Item_Type ntype) : MItem(ntype), m_pleft(pl), m_pright(pr) {} ~MBinary() { delete m_pleft; delete m_pright; } MItem* LeftItem() { return m_pleft; } MItem* RightItem() { return m_pright; } const MItem* LeftItem() const { return m_pleft; } const MItem* RightItem() const { return m_pright; } protected: MItem *m_pleft, *m_pright; }; //----------------------------------------------------------------------------- // a list of items class MSequence : public MItem { public: MSequence() : MItem(MSEQUENCE){} MSequence(const MSequence& s); ~MSequence(); MSequence* copy() const override { return new MSequence(*this); } MSequence& operator = (MSequence& s); MItem* operator [] (int i) { return m_item[i]; } const MItem* operator [] (int i) const { return m_item[i]; } int size() const { return (int) m_item.size(); } void add(MItem* pi) { m_item.push_back(pi); } void replace(int i, MItem* pi); void remove(int i); protected: std::vector<MItem*> m_item; }; //----------------------------------------------------------------------------- // base class for N-ary operators and functions class MNary : public MItem { public: MNary(const MSequence& s, Item_Type ntype) : MItem(ntype), m_s(s) {} ~MNary() {} int Params() const { return (int) m_s.size(); } MItem* Param(int n) { return m_s[n]; } const MItem* Param(int n) const { return m_s[n]; } MSequence& GetSequence() { return m_s; } const MSequence& GetSequence() const { return m_s; } protected: MSequence m_s; }; //----------------------------------------------------------------------------- // defines a negative operation class MNeg : public MUnary { public: MNeg(MItem* pi) : MUnary(pi, MNEG) {} MItem* copy() const override { return new MNeg(m_pi->copy()); } }; //----------------------------------------------------------------------------- // addition operator class MAdd : public MBinary { public: MAdd(MItem* pl, MItem* pr) : MBinary(pl, pr, MADD){} MAdd(MItem* pl, double r) : MBinary(pl, new MConstant(r), MADD){} MItem* copy() const override { return new MAdd(m_pleft->copy(), m_pright->copy()); } }; //----------------------------------------------------------------------------- // subtraction operator class MSub : public MBinary { public: MSub(MItem* pl, MItem* pr) : MBinary(pl, pr, MSUB){} MSub(double l, MItem* pr) : MBinary(new MConstant(l), pr, MSUB){} MSub(MItem* pl, double r) : MBinary(pl, new MConstant(r), MSUB){} MItem* copy() const override { return new MSub(m_pleft->copy(), m_pright->copy()); } }; //----------------------------------------------------------------------------- // multiplication operator class MMul : public MBinary { public: MMul(MItem* pl, MItem* pr) : MBinary(pl, pr, MMUL){} MMul(double l, MItem* pr) : MBinary(new MConstant(l), pr, MMUL){} MItem* copy() const override { return new MMul(m_pleft->copy(), m_pright->copy()); } }; //----------------------------------------------------------------------------- // division operator class MDiv : public MBinary { public: MDiv(MItem* pl, MItem* pr) : MBinary(pl, pr, MDIV){} MDiv(double l, MItem* pr) : MBinary(new MConstant(l), pr, MDIV){} MDiv(MItem* pl, double r) : MBinary(pl, new MConstant(r), MDIV){} MDiv(double l, double r) : MBinary(new MConstant(l), new MConstant(r), MDIV){} MItem* copy() const override { return new MDiv(m_pleft->copy(), m_pright->copy()); } }; //----------------------------------------------------------------------------- // power operator class MPow : public MBinary { public: MPow(MItem* pl, MItem* pr) : MBinary(pl, pr, MPOW){} MPow(MItem* pl, double r) : MBinary(pl, new MConstant(r), MPOW){} MItem* copy() const override { return new MPow(m_pleft->copy(), m_pright->copy()); } }; //----------------------------------------------------------------------------- // equal-than operator class MEquation : public MBinary { public: MEquation(MItem* pl, MItem* pr) : MBinary(pl, pr, MEQUATION){} MItem* copy() const override { return new MEquation(m_pleft->copy(), m_pright->copy()); } }; //----------------------------------------------------------------------------- // equality test class MEquality : public MBinary { public: MEquality(MItem* pl, MItem* pr) : MBinary(pl, pr, MEQUALITY){} MItem* copy() const override { return new MEquality(m_pleft->copy(), m_pright->copy()); } }; //----------------------------------------------------------------------------- // function of one variable class MFunc1D : public MUnary { public: MFunc1D(FUNCPTR pf, const std::string& s, MItem* pi) : MUnary(pi, MF1D), m_name(s), m_pf(pf) {} MItem* copy() const override { return new MFunc1D(m_pf, m_name, m_pi->copy()); } const std::string& Name() const { return m_name; } FUNCPTR funcptr() const { return m_pf; } protected: std::string m_name; FUNCPTR m_pf; }; //----------------------------------------------------------------------------- // function of two variables class MFunc2D : public MBinary { public: MFunc2D(FUNC2PTR pf, const std::string& s, MItem* p1, MItem* p2) : MBinary(p1, p2, MF2D), m_name(s), m_pf(pf) {} MItem* copy() const override { return new MFunc2D(m_pf, m_name, m_pleft->copy(), m_pright->copy()); } const std::string& Name() const { return m_name; } FUNC2PTR funcptr() const { return m_pf; } protected: std::string m_name; FUNC2PTR m_pf; }; //----------------------------------------------------------------------------- // function of N variables class MFuncND : public MNary { public: MFuncND(FUNCNPTR pf, const std::string& s, const MSequence& l) : MNary(l, MFND), m_name(s), m_pf(pf) {} MItem* copy() const override; const std::string& Name() const { return m_name; } FUNCNPTR funcptr() const { return m_pf; } protected: std::string m_name; FUNCNPTR m_pf; }; //----------------------------------------------------------------------------- // class for a symbolic function definition of N variables class MSFuncND : public MNary { public: MSFuncND(const std::string& s, MItem* pv, const MSequence* ps) : MNary(*ps, MSFNC), m_name(s), m_pval(pv) {} ~MSFuncND(){ delete m_pval; } MItem* copy() const override { return new MSFuncND(m_name, m_pval->copy(), &GetSequence()); } const MItem* Value() const { return m_pval; } const std::string& Name() const { return m_name; } private: std::string m_name; MItem* m_pval; //!< result of function evaluation }; //----------------------------------------------------------------------------- // Symbolic operator class MSymOp : public MItem { public: MSymOp(Item_Type ntype) : MItem(ntype) {} }; //----------------------------------------------------------------------------- class MOpIntegral : public MSymOp { public: MOpIntegral(MItem* pf, MVarRef* px) : MSymOp(MINTEGRAL), m_pf(pf), m_px(px){} ~MOpIntegral() { delete m_pf; delete m_px; } MItem* copy() const override { return new MOpIntegral(m_pf->copy(), dynamic_cast<MVarRef*>(m_px->copy())); } MItem* Item() { return m_pf; } MVarRef* Var() { return m_px; } protected: MItem* m_pf; MVarRef* m_px; }; //----------------------------------------------------------------------------- inline const MNumber* mnumber (const MItem* pi) { return static_cast<const MNumber* >(pi); } inline const MConstant* mconst (const MItem* pi) { return static_cast<const MConstant*>(pi); } inline const MFraction* mfrac (const MItem* pi) { return static_cast<const MFraction*>(pi); } inline const MNamedCt* mnamed (const MItem* pi) { return static_cast<const MNamedCt *>(pi); } inline const MVarRef* mvar (const MItem* pi) { return static_cast<const MVarRef *>(pi); } inline const MBoolean* mboolean (const MItem* pi) { return static_cast<const MBoolean* >(pi); } inline const MNeg* mneg (const MItem* pi) { return static_cast<const MNeg *>(pi); } inline const MAdd* madd (const MItem* pi) { return static_cast<const MAdd *>(pi); } inline const MSub* msub (const MItem* pi) { return static_cast<const MSub *>(pi); } inline const MMul* mmul (const MItem* pi) { return static_cast<const MMul *>(pi); } inline const MDiv* mdiv (const MItem* pi) { return static_cast<const MDiv *>(pi); } inline const MPow* mpow (const MItem* pi) { return static_cast<const MPow *>(pi); } inline const MUnary* munary (const MItem* pi) { return static_cast<const MUnary *>(pi); } inline const MBinary* mbinary (const MItem* pi) { return static_cast<const MBinary *>(pi); } inline const MNary* mnary (const MItem* pi) { return static_cast<const MNary *>(pi); } inline const MFunc1D* mfnc1d (const MItem* pi) { return static_cast<const MFunc1D *>(pi); } inline const MFunc2D* mfnc2d (const MItem* pi) { return static_cast<const MFunc2D *>(pi); } inline const MFuncND* mfncnd (const MItem* pi) { return static_cast<const MFuncND *>(pi); } inline const MSFuncND* msfncnd (const MItem* pi) { return static_cast<const MSFuncND *>(pi); } inline const MSequence* msequence(const MItem* pi) { return static_cast<const MSequence*>(pi); } inline const MEquation* mequation(const MItem* pi) { return static_cast<const MEquation*>(pi); } inline const MEquality* mequality(const MItem* pi) { return static_cast<const MEquality*>(pi); } //----------------------------------------------------------------------------- // This class is defined so that we can do arithmetic with the math classes // without worrying about making copies and garbage collection. Each MITEM // stores its own expression. This will probably cause a proliferation of // copying, so perhaps I can come up with a better memory managment model. // (e.g. like auto_ptr, where owner- ship of an pointer can be passed along) class MITEM { public: MITEM() { m_pi = 0; } ~MITEM() { delete m_pi; } //~MITEM() { } MITEM(MItem* pi) { m_pi = pi; } // Note that the item is not copied in this constructor MITEM(const MItem* pi) { m_pi = pi->copy(); } MITEM(const MITEM& it) { m_pi = (it.m_pi?it.m_pi->copy():0); } MITEM(const MVariable& v) { m_pi = new MVarRef(&v); } MITEM(double g) { m_pi = new MConstant(fabs(g)); if (g < 0) m_pi = new MNeg(m_pi); } MITEM(FRACTION& g) { m_pi = new MFraction(fabs(g.n), fabs(g.d)); if (g < 0) m_pi = new MNeg(m_pi); } void operator = (const MITEM& it) { delete m_pi; m_pi = it.m_pi->copy(); } void operator = (MItem* pi) { delete m_pi; m_pi = pi; } MItem* ItemPtr() { return m_pi; } const MItem* ItemPtr() const { return m_pi; } MItem* copy() const { return m_pi->copy(); } MITEM Left () const { return (static_cast<MBinary*>(m_pi))->LeftItem()->copy(); } MITEM Right() const { return (static_cast<MBinary*>(m_pi))->RightItem()->copy(); } MITEM Item() const { return (static_cast<MUnary*>(m_pi))->Item()->copy(); } MITEM Param() const { return (static_cast<MFunc1D*>(m_pi))->Item()->copy(); } Item_Type Type() const { return m_pi->Type(); } double value() const { return (Type()==MNEG? -mnumber(mneg(m_pi)->Item())->value() : mnumber(m_pi)->value()); } private: MItem* m_pi; }; //----------------------------------------------------------------------------- inline const MNumber* mnumber (const MITEM& i) { return static_cast<const MNumber *>(i.ItemPtr()); } inline const MConstant* mconst (const MITEM& i) { return static_cast<const MConstant*>(i.ItemPtr()); } inline const MFraction* mfrac (const MITEM& i) { return static_cast<const MFraction*>(i.ItemPtr()); } inline const MNamedCt* mnamed (const MITEM& i) { return static_cast<const MNamedCt *>(i.ItemPtr()); } inline const MVarRef* mvar (const MITEM& i) { return static_cast<const MVarRef *>(i.ItemPtr()); } inline const MBoolean* mboolean (const MITEM& i) { return static_cast<const MBoolean* >(i.ItemPtr()); } inline const MNeg* mneg (const MITEM& i) { return static_cast<const MNeg *>(i.ItemPtr()); } inline const MAdd* madd (const MITEM& i) { return static_cast<const MAdd *>(i.ItemPtr()); } inline const MSub* msub (const MITEM& i) { return static_cast<const MSub *>(i.ItemPtr()); } inline const MMul* mmul (const MITEM& i) { return static_cast<const MMul *>(i.ItemPtr()); } inline const MDiv* mdiv (const MITEM& i) { return static_cast<const MDiv *>(i.ItemPtr()); } inline const MPow* mpow (const MITEM& i) { return static_cast<const MPow *>(i.ItemPtr()); } inline const MUnary* munary (const MITEM& i) { return static_cast<const MUnary *>(i.ItemPtr()); } inline const MBinary* mbinary (const MITEM& i) { return static_cast<const MBinary *>(i.ItemPtr()); } inline const MNary* mnary (const MITEM& i) { return static_cast<const MNary *>(i.ItemPtr()); } inline const MFunc1D* mfnc1d (const MITEM& i) { return static_cast<const MFunc1D *>(i.ItemPtr()); } inline const MFunc2D* mfnc2d (const MITEM& i) { return static_cast<const MFunc2D *>(i.ItemPtr()); } inline const MSFuncND* msfncnd (const MITEM& i) { return static_cast<const MSFuncND *>(i.ItemPtr()); } inline const MSequence* msequence(const MITEM& i) { return static_cast<const MSequence*>(i.ItemPtr()); } inline const MEquation* mequation(const MITEM& i) { return static_cast<const MEquation*>(i.ItemPtr()); } inline const MEquality* mequality(const MITEM& i) { return static_cast<const MEquality*>(i.ItemPtr()); } //----------------------------------------------------------------------------- // Some helper functions to determine the type of an MItem inline bool is_number(const MItem* pi) { return (dynamic_cast<const MNumber *>(pi) != 0); } inline bool is_unary (const MItem* pi) { return (dynamic_cast<const MUnary *>(pi) != 0); } inline bool is_binary(const MItem* pi) { return (dynamic_cast<const MBinary *>(pi) != 0); } inline bool is_nary (const MItem* pi) { return (dynamic_cast<const MNary *>(pi) != 0); } inline bool isConst (const MItem* pi) { return (pi->Type() == MCONST ); } inline bool is_frac (const MItem* pi) { return (pi->Type() == MFRAC ); } inline bool is_named (const MItem* pi) { return (pi->Type() == MNAMED ); } inline bool is_var (const MItem* pi) { return (pi->Type() == MVAR ); } inline bool is_boolean (const MItem* pi) { return (pi->Type() == MBOOL ); } inline bool is_neg (const MItem* pi) { return (pi->Type() == MNEG ); } inline bool is_add (const MItem* pi) { return (pi->Type() == MADD ); } inline bool is_sub (const MItem* pi) { return (pi->Type() == MSUB ); } inline bool is_mul (const MItem* pi) { return (pi->Type() == MMUL ); } inline bool is_div (const MItem* pi) { return (pi->Type() == MDIV ); } inline bool is_pow (const MItem* pi) { return (pi->Type() == MPOW ); } inline bool is_equation(const MItem* pi) { return (pi->Type() == MEQUATION); } inline bool is_equality(const MItem* pi) { return (pi->Type() == MEQUALITY); } inline bool is_func1d (const MItem* pi) { return (pi->Type() == MF1D ); } inline bool is_matrix (const MItem* pi) { return (pi->Type() == MMATRIX ); } inline bool is_sfunc (const MItem* pi) { return (pi->Type() == MSFNC ); } inline bool isConst (const MITEM& i) { return (i.Type() == MCONST ); } inline bool is_frac (const MITEM& i) { return (i.Type() == MFRAC ); } inline bool is_named (const MITEM& i) { return (i.Type() == MNAMED ); } inline bool is_var (const MITEM& i) { return (i.Type() == MVAR ); } inline bool is_boolean (const MITEM& i) { return (i.Type() == MBOOL ); } inline bool is_neg (const MITEM& i) { return (i.Type() == MNEG ); } inline bool is_add (const MITEM& i) { return (i.Type() == MADD ); } inline bool is_sub (const MITEM& i) { return (i.Type() == MSUB ); } inline bool is_mul (const MITEM& i) { return (i.Type() == MMUL ); } inline bool is_div (const MITEM& i) { return (i.Type() == MDIV ); } inline bool is_pow (const MITEM& i) { return (i.Type() == MPOW ); } inline bool is_equation(const MITEM& i) { return (i.Type() == MEQUATION); } inline bool is_equality(const MITEM& i) { return (i.Type() == MEQUALITY); } inline bool is_func1d (const MITEM& i) { return (i.Type() == MF1D ); } inline bool is_matrix (const MITEM& i) { return (i.Type() == MMATRIX ); } inline bool is_sequence(const MITEM& i) { return (i.Type() == MSEQUENCE); } inline bool is_sfunc (const MITEM& i) { return (i.Type() == MSFNC ); } inline bool is_number(const MITEM& i) { return is_number(i.ItemPtr()); } inline bool is_func(const MItem* pi) { Item_Type t = pi->Type(); return ((t==MF1D) || (t==MF2D) || (t==MFND)); } inline bool is_int (double r) { return (r - floor(r) == 0.0); } inline bool is_abs (const MItem* pi) { return (is_func1d(pi) && (mfnc1d(pi)->Name().compare("abs") == 0)); } inline bool is_func(const MITEM& i) { return is_func(i.ItemPtr()); } inline bool is_abs (const MITEM& i) { return is_abs (i.ItemPtr()); } inline bool is_int(const MItem* pi) { return isConst(pi) && is_int(mnumber(pi)->value()); } inline bool is_int (const MITEM& i) { return is_int(i.ItemPtr()); } inline bool is_fnc1d(const MITEM& i, const char* sz) { return (is_func1d(i) && (strcmp(mfnc1d(i)->Name().c_str(), sz) == 0)); } bool is_rconst(const MItem* pi); // is recursive constant bool is_dependent(const MItem* pi, const MVariable& x); // is i dependent on x bool is_dependent(const MItem* pi, const MItem* px); // is i dependent on x bool is_scalar(const MItem* pi); // is the expression scalar inline bool is_rconst(const MITEM& i) { return is_rconst(i.ItemPtr()); } bool is_pi(const MItem* pi); // is pi the constant pi? inline bool is_pi(const MITEM& i) { return is_pi(i.ItemPtr()); } inline bool is_zero(const MItem* pi) { if (isConst(pi)) return (mconst(pi)->value() == 0.0); else return false; } inline bool is_scalar(const MITEM& m) { return ::is_scalar(m.ItemPtr()); } //----------------------------------------------------------------------------- // Algebraic operators for MITEM's MITEM operator - (const MITEM& l); MITEM operator + (const MITEM& l, const MITEM& r); MITEM operator + (const MITEM& l, double r); MITEM operator + (double l, const MITEM& r); MITEM operator - (const MITEM& l, const MITEM& r); MITEM operator - (double l, const MITEM& r); MITEM operator - (const MITEM& l, double r); MITEM operator * (const MITEM& l, const MITEM& r); MITEM operator * (double l, const MITEM& r); MITEM operator / (const MITEM& l, const MITEM& r); MITEM operator / (double l, const MITEM& r); MITEM operator / (const MITEM& l, double r); MITEM operator ^ (const MITEM& l, const MITEM& r); MITEM operator ^ (const MITEM& l, double r); //----------------------------------------------------------------------------- // Fractions MITEM Fraction(double n, double d); inline MITEM Fraction(FRACTION f) { return Fraction(f.n, f.d); } //----------------------------------------------------------------------------- // Symbolic math functions MITEM Abs(const MITEM& l); MITEM Sgn(const MITEM& l); MITEM Sin(const MITEM& l); MITEM Cos(const MITEM& l); MITEM Tan(const MITEM& l); MITEM Cot(const MITEM& l); MITEM Sec(const MITEM& l); MITEM Csc(const MITEM& l); MITEM Atan(const MITEM& l); MITEM Cosh(const MITEM& l); MITEM Sinh(const MITEM& l); MITEM Exp(const MITEM& l); MITEM Log(const MITEM& l); MITEM Log10(const MITEM& l); MITEM Float(const MITEM& l); MITEM Sqrt(const MITEM& l); MITEM Erf(const MITEM& l); MITEM Erfc(const MITEM& l); // Chebyshev polynomials MITEM Tn(int n, MITEM& r); MITEM Tn(const MITEM& l, const MITEM& r); // Bessel functions (1st kind) #ifdef WIN32 MITEM J0(const MITEM& l); MITEM J1(const MITEM& l); MITEM Jn(int n, const MITEM& r); MITEM Jn(const MITEM& l, const MITEM& r); #endif // Bessel functions (2e kind) #ifdef WIN32 MITEM Y0(const MITEM& l); MITEM Y1(const MITEM& l); MITEM Yn(int n, const MITEM& r); MITEM Yn(const MITEM& l, const MITEM& r); #endif // Miscellaneous functions MITEM Fac(const MITEM& l); MITEM Binomial(const MITEM& l, const MITEM& r); MITEM Identity(const MITEM& n); //----------------------------------------------------------------------------- // check equality of two items inline bool operator == (const MITEM& l, const std::string& r) { if (is_var(l)) { const std::string& s = mvar(l)->Name(); return (s.compare(r) == 0); } else return false; } inline bool operator == (const MITEM& l, const MVariable& x) { if (is_var(l)) { const std::string& s = mvar(l)->Name(); return (s.compare(x.Name()) == 0); } else return false; } inline bool operator == (const MITEM& l, double r) { if (isConst(l)) return (mnumber(l)->value() == r); else return false; } inline bool operator != (const MITEM& l, double r) { return !(l==r); } inline bool is_dependent(const MITEM& l, const MVariable& x) { return is_dependent(l.ItemPtr(), x); } inline bool is_dependent(const MITEM& l, const MITEM& x) { return is_dependent(l.ItemPtr(), x.ItemPtr()); } bool is_equal(const MItem* pl, const MItem* pr); inline bool is_equal(const MItem* pl, const MVariable& x) { if (is_var(pl)) { const std::string& s = mvar(pl)->Name(); return (s.compare(x.Name()) == 0); } else return false; } inline bool operator == (const MITEM& l, const MITEM& r) { return is_equal(l.ItemPtr(), r.ItemPtr()); } inline bool operator != (const MITEM& l, const MITEM& r) { return (is_equal(l.ItemPtr(), r.ItemPtr()) == false); } //----------------------------------------------------------------------------- // functions for calculating and comparing heuristics int op_count(MItem* pi); inline int op_count(MITEM& i) { return op_count(i.ItemPtr()); } //----------------------------------------------------------------------------- bool is_format(MItem* pe, const char* sz); inline bool is_format(MITEM& e, const char* sz) { return is_format(e.ItemPtr(), sz); }
Unknown
3D
febiosoftware/FEBio
FECore/FEPIDController.h
.h
2,118
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 "FELoadController.h" #include "MathObject.h" class FEPIDController : public FELoadController { public: FEPIDController(FEModel* fem); bool Init() override; double GetParameterValue() const { return m_paramVal; } double GetError() const { return m_error; } void Serialize(DumpStream& ar) override; protected: double GetValue(double time) override; private: std::string m_paramName; // the parameter to target double m_trg; // the target value double m_Kp; double m_Kd; double m_Ki; FEParamValue m_param; //!< parameter that is tracked double m_paramVal; //!< current parameter value double m_error; //!< current error double m_prev; //!< error at previous time step double m_prevTime; //!< previous time step double m_int; //!< integral value DECLARE_FECORE_CLASS(); };
Unknown
3D
febiosoftware/FEBio
FECore/FSPath.cpp
.cpp
2,029
84
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include <regex> #include <string> #include "FSPath.h" bool FSPath::isAbsolute(const char* path) { #ifdef WIN32 return std::regex_search(path, std::regex("^([A-Z]|[a-z])\\:[\\\\\\/]")); #else return std::regex_search(path, std::regex("^\\/")); #endif } bool FSPath::isPath(const char* path) { return std::regex_search(path, std::regex("\\/|\\\\")); } void FSPath::filePath(char* filename, char* path) { std::string name(filename); int index = name.find_last_of("/\\"); if(index == std::string::npos) { strcpy(path,""); return; } #ifdef WIN32 char sep = '\\'; #else char sep = '/'; #endif snprintf(path, name.length(), "%s%c", name.substr(0,index).c_str(), sep); }
C++
3D
febiosoftware/FEBio
FECore/FENodalBC.cpp
.cpp
1,898
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.*/ #include "stdafx.h" #include "FENodalBC.h" //================================================================== FENodalBC::FENodalBC(FEModel* fem) : FEBoundaryCondition(fem) { m_nodeSet = nullptr; } //----------------------------------------------------------------------------- void FENodalBC::SetNodeSet(FENodeSet* nodeSet) { m_nodeSet = nodeSet; } //----------------------------------------------------------------------------- FENodeSet* FENodalBC::GetNodeSet() { return m_nodeSet; } void FENodalBC::Serialize(DumpStream& ar) { FEBoundaryCondition::Serialize(ar); if (ar.IsShallow()) return; ar & m_nodeSet; }
C++
3D
febiosoftware/FEBio
FECore/JFNKMatrix.h
.h
3,834
111
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "SparseMatrix.h" class FENewtonSolver; //----------------------------------------------------------------------------- // This is a class that just mimics a sparse matrix. // It is only used by the JFNK strategy. // The only function it implements is the mult_vector. class FECORE_API JFNKMatrix : public SparseMatrix { public: enum MultiplyPolicy { ZERO_FREE_DOFS, ZERO_PRESCRIBED_DOFS }; public: JFNKMatrix(FENewtonSolver* pns, SparseMatrix* K = 0); //! override multiply with vector (Does not use sparse matrix m_K) bool mult_vector(double* x, double* r) override; //! set the reference residual void SetReferenceResidual(std::vector<double>& R0); //! set matrix policy void SetPolicy(MultiplyPolicy p); //! set the forward difference epsilon void SetEpsilon(double eps); public: // these functions use the actual sparse matrix m_K //! set all matrix elements to zero void Zero() override { m_K->Zero(); } //! Create a sparse matrix from a sparse-matrix profile void Create(SparseMatrixProfile& MP) override; //! assemble a matrix into the sparse matrix void Assemble(const matrix& ke, const std::vector<int>& lm) override { m_K->Assemble(ke, lm); } //! assemble a matrix into the sparse matrix void Assemble(const matrix& ke, const std::vector<int>& lmi, const std::vector<int>& lmj) override { m_K->Assemble(ke, lmi, lmj); } //! check if an entry was allocated bool check(int i, int j) override { return m_K->check(i, j); } //! set entry to value void set(int i, int j, double v) override { m_K->set(i, j, v); } //! add value to entry void add(int i, int j, double v) override { m_K->add(i, j, v); } //! retrieve value double get(int i, int j) override { return m_K->get(i, j); } //! get the diagonal value double diag(int i) override { return m_K->diag(i); } //! release memory for storing data void Clear() override { m_K->Clear(); } // interface to compact matrices double* Values() override { return m_K->Values(); } int* Indices() override { return m_K->Indices(); } int* Pointers() override { return m_K->Pointers(); } int Offset() const override { return m_K->Offset(); } private: bool m_bauto_eps; // calculate epsilon automatically double m_eps; // forward difference epsilon SparseMatrix* m_K; // the actual sparse matrix (This is only used as a preconditioner and can be null) FENewtonSolver* m_pns; std::vector<double> m_v, m_R; std::vector<double> m_R0; std::vector<int> m_freeDofs, m_prescribedDofs; MultiplyPolicy m_policy; };
Unknown
3D
febiosoftware/FEBio
FECore/FEBox.cpp
.cpp
2,340
91
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEBox.h" #include "FEMesh.h" #include "FEMeshPartition.h" FEBox::FEBox() { } FEBox::FEBox(const vec3d& r0, const vec3d& r1) : m_r0(r0), m_r1(r1) { } FEBox::FEBox(const FEMesh& mesh) { m_r0 = m_r1 = vec3d(0,0,0); int N = mesh.Nodes(); if (N > 0) { m_r0 = m_r1 = mesh.Node(0).m_rt; for (int i=1; i<N; ++i) { const FENode& ni = mesh.Node(i); add(ni.m_rt); } } } FEBox::FEBox(const FEMeshPartition& dom) { m_r0 = m_r1 = vec3d(0,0,0); int N = dom.Nodes(); if (N > 0) { m_r0 = m_r1 = dom.Node(0).m_rt; for (int i=1; i<N; ++i) { const FENode& ni = dom.Node(i); add(ni.m_rt); } } } double FEBox::maxsize() { double dx = fabs(width()); double dy = fabs(height()); double dz = fabs(depth()); double D = dx; if (dy > D) D = dy; if (dz > D) D = dz; return D; } void FEBox::add(const vec3d& r) { if (r.x < m_r0.x) m_r0.x = r.x; if (r.x > m_r1.x) m_r1.x = r.x; if (r.y < m_r0.y) m_r0.y = r.y; if (r.y > m_r1.y) m_r1.y = r.y; if (r.z < m_r0.z) m_r0.z = r.z; if (r.z > m_r1.z) m_r1.z = r.z; }
C++
3D
febiosoftware/FEBio
FECore/FEValuator.h
.h
1,715
51
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FECoreBase.h" class FEMaterialPoint; class FEModelParam; // Base class for evaluating model parameters class FECORE_API FEValuator : public FECoreBase { public: FEValuator(FEModel* fem); virtual ~FEValuator(); void SetModelParam(FEModelParam* p); FEModelParam* GetModelParam(); void Serialize(DumpStream& ar) override; private: FEModelParam* m_param; //!< the model param that is using this valuator };
Unknown
3D
febiosoftware/FEBio
FECore/Integrate.h
.h
3,210
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 "matrix.h" #include <functional> //----------------------------------------------------------------------------- // The purpose of this file is to explore mechanisms for evaluating the integrals // that commonly appear in FE formulations. The goal is that this would simplify // the implementation of new FE features. //----------------------------------------------------------------------------- class FESolidDomain; class FESolidElement; class FEMaterialPoint; class FELinearSystem; class FESolver; class FEGlobalVector; //----------------------------------------------------------------------------- // Integrator function for BDB forms // where B is the shape function gradients FECORE_API void IntegrateBDB(FESolidDomain& dom, FESolidElement& el, double D, matrix& ke); FECORE_API void IntegrateBDB(FESolidDomain& dom, FESolidElement& el, const mat3ds& D, matrix& ke); FECORE_API void IntegrateBDB(FESolidDomain& dom, FESolidElement& el, std::function<mat3ds (const FEMaterialPoint& mp)> f, matrix& ke); //----------------------------------------------------------------------------- // Integrator function for NCN forms // where N are the shape functions FECORE_API void IntegrateNCN(FESolidDomain& dom, FESolidElement& el, double C, matrix& ke); //----------------------------------------------------------------------------- // Generic integrator class for solid domains // Requires that the domain implements the GetElementDofs function. FECORE_API void AssembleSolidDomain(FESolidDomain& dom, FELinearSystem& ls, std::function<void(FESolidElement& el, matrix& ke)> elementIntegrand); FECORE_API void AssembleSolidDomain(FESolidDomain& dom, FEGlobalVector& R, std::function<void(FESolidElement& el, std::vector<double>& fe)> elementIntegrand); FECORE_API void IntegrateSolidDomain(FESolidDomain& dom, FELinearSystem& ls, std::function<void(FEMaterialPoint& mp, matrix& ke)> elementIntegrand);
Unknown
3D
febiosoftware/FEBio
FECore/SparseMatrix.cpp
.cpp
1,730
56
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "SparseMatrix.h" #include <memory.h> using namespace std; //----------------------------------------------------------------------------- SparseMatrix::SparseMatrix() { m_nrow = m_ncol = 0; m_nsize = 0; } SparseMatrix::~SparseMatrix() { } void SparseMatrix::Clear() { m_nrow = m_ncol = 0; m_nsize = 0; } //! scale matrix void SparseMatrix::scale(const vector<double>& L, const vector<double>& R) { assert(false); }
C++
3D
febiosoftware/FEBio
FECore/log.cpp
.cpp
1,661
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 "log.h" #include "FEModel.h" #include <stdarg.h> void write_log(FEModel* fem, int ntag, const char* szmsg, ...) { assert(fem); if (fem->LogBlocked()) return; // get a pointer to the argument list va_list args; // make the message char sztxt[2048] = { 0 }; va_start(args, szmsg); vsnprintf(sztxt, sizeof(sztxt), szmsg, args); va_end(args); fem->Log(ntag, sztxt); }
C++
3D
febiosoftware/FEBio
FECore/MTypes.cpp
.cpp
2,138
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.*/ #include "stdafx.h" #include "MTypes.h" #include <math.h> //----------------------------------------------------------------------------- // Calculates the greatest common factor of two integers long gcf(long a, long b) { if ((a==0) || (b==0)) return 1; if (a<0) a = -a; if (b<0) b = -b; if (a > b) { a ^= b; b ^= a; a ^= b; } long q, r; do { q = b/a; r = b%a; if (r > 0) { b = (b-r)/q; a = r; } } while (r>0); return a; } //----------------------------------------------------------------------------- // reduces the fraction to it simplest form void FRACTION::normalize() { double s = (n*d<0?-1:1); n = fabs(n); d = fabs(d); if (d != 0) { long in = (long ) n; long id = (long ) d; if ((n==(double) in) && (d == (double) id)) { double c = (double) gcf(in, id); n /= c; d /= c; } } if (s<0) n = -n; }
C++
3D
febiosoftware/FEBio
FECore/FEModifiedNewtonStrategy.cpp
.cpp
2,346
63
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FEModifiedNewtonStrategy.h" #include "FESolver.h" #include "FEException.h" #include "FENewtonSolver.h" //----------------------------------------------------------------------------- FEModifiedNewtonStrategy::FEModifiedNewtonStrategy(FEModel* fem) : FENewtonStrategy(fem) { m_plinsolve = nullptr; m_maxups = 0; } //----------------------------------------------------------------------------- bool FEModifiedNewtonStrategy::Init() { if (m_pns == nullptr) return false; m_plinsolve = m_pns->GetLinearSolver(); return true; } //----------------------------------------------------------------------------- bool FEModifiedNewtonStrategy::Update(double s, vector<double>& ui, vector<double>& R0, vector<double>& R1) { // nothing to do here. return true; } //----------------------------------------------------------------------------- void FEModifiedNewtonStrategy::SolveEquations(vector<double>& x, vector<double>& b) { // perform a backsubstitution if (m_plinsolve->BackSolve(x, b) == false) { throw LinearSolverFailed(); } }
C++
3D
febiosoftware/FEBio
FECore/FEMeshTopo.cpp
.cpp
9,663
419
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEMeshTopo.h" #include "FEElementList.h" #include "FEMesh.h" #include "FEDomain.h" #include "FEElemElemList.h" #include "FESurface.h" #include <stack> class FEMeshTopo::MeshTopoImp { public: MeshTopoImp() { m_minId = -1; m_mesh = nullptr; } public: FEMesh* m_mesh; // the mesh FEEdgeList m_edgeList; // the edge list FEElementEdgeList m_EEL; // the element-edge list FEFaceList m_faceList; // the face list (all faces) FEElementFaceList m_EFL; // the element-face list FEElemElemList m_ENL; // the element neighbor list FEFaceList m_surface; // only surface facets FEElementFaceList m_ESL; // element-surface facet list FEFaceEdgeList m_FEL; // face-edge list std::vector<FEElement*> m_elem; // element list std::vector<int> m_lut; int m_minId; }; FEMeshTopo::FEMeshTopo() : imp(new FEMeshTopo::MeshTopoImp) { } FEMeshTopo::~FEMeshTopo() { delete imp; } // get the mesh FEMesh* FEMeshTopo::GetMesh() { return imp->m_mesh; } bool FEMeshTopo::Create(FEMesh* mesh) { imp->m_mesh = mesh; FEElementList elemList(*mesh); // create a vector of all elements int NEL = mesh->Elements(); imp->m_elem.resize(NEL); NEL = 0; for (int i = 0; i < mesh->Domains(); ++i) { FEDomain& dom = mesh->Domain(i); int nel = dom.Elements(); for (int j = 0; j < nel; ++j) { imp->m_elem[NEL++] = &dom.ElementRef(j); } } // build the index lookup table FEElementIterator it(mesh); imp->m_minId = -1; int minId = -1, maxId = -1; for (; it.isValid(); ++it) { int nid = (*it).GetID(); assert(nid != -1); if (minId == -1) { minId = nid; maxId = nid; } else { if (nid < minId) minId = nid; if (nid > maxId) maxId = nid; } } int lutSize = maxId - minId + 1; imp->m_lut.assign(lutSize, -1); imp->m_minId = minId; int n = 0; for (it.reset(); it.isValid(); ++it, ++n) { int nid = (*it).GetID() - minId; imp->m_lut[nid] = n; } // create the element neighbor list if (imp->m_ENL.Create(mesh) == false) return false; // create a face list if (imp->m_faceList.Create(*mesh, imp->m_ENL) == false) return false; // extract the surface facets imp->m_surface = imp->m_faceList.GetSurface(); // create the element-face list if (imp->m_EFL.Create(elemList, imp->m_faceList) == false) return false; // create the element-surface facet list if (imp->m_ESL.Create(elemList, imp->m_surface) == false) return false; imp->m_surface.BuildNeighbors(); // create the edge list (from the face list) if (imp->m_edgeList.Create(mesh) == false) return false; // create the element-edge list if (imp->m_EEL.Create(elemList, imp->m_edgeList) == false) return false; // create the face-edge list if (imp->m_FEL.Create(imp->m_faceList, imp->m_edgeList) == false) return false; return true; } // return elements int FEMeshTopo::Elements() { return (int)imp->m_elem.size(); } // return an element FEElement* FEMeshTopo::Element(int i) { if (i < 0) return nullptr; else return imp->m_elem[i]; } int FEMeshTopo::GetElementIndexFromID(int elemId) { int eid = elemId - imp->m_minId; if ((eid < 0) || (eid >= imp->m_lut.size())) { assert(false); return -1; } int lid = imp->m_lut[eid]; assert(lid != -1); return lid; } int FEMeshTopo::Faces() { return imp->m_faceList.Faces(); } // return the number of surface faces int FEMeshTopo::SurfaceFaces() const { return imp->m_surface.Faces(); } // return a face const FEFaceList::FACE& FEMeshTopo::Face(int i) { return imp->m_faceList[i]; } // return a surface facet const FEFaceList::FACE& FEMeshTopo::SurfaceFace(int i) const { return imp->m_surface[i]; } // return the element-face list const std::vector<int>& FEMeshTopo::ElementFaceList(int nelem) { return imp->m_EFL.FaceList(nelem); } // return the number of edges in the mesh int FEMeshTopo::Edges() { return imp->m_edgeList.Edges(); } // return a edge const FEEdgeList::EDGE& FEMeshTopo::Edge(int i) { return imp->m_edgeList[i]; } // return the face-edge list const std::vector<int>& FEMeshTopo::FaceEdgeList(int nface) { return imp->m_FEL.EdgeList(nface); } // return the element-edge list const std::vector<int>& FEMeshTopo::ElementEdgeList(int nelem) { return imp->m_EEL.EdgeList(nelem); } // return the list of face indices of a surface std::vector<int> FEMeshTopo::FaceIndexList(FESurface& s) { FENodeFaceList NFL; NFL.Create(imp->m_faceList); int NF = s.Elements(); std::vector<int> fil(NF, -1); for (int i = 0; i < NF; ++i) { FESurfaceElement& el = s.Element(i); int nval = NFL.Faces(el.m_node[0]); const std::vector<int>& nfl = NFL.FaceList(el.m_node[0]); for (int j = 0; j < nval; ++j) { const FEFaceList::FACE& face = imp->m_faceList[nfl[j]]; if (face.IsEqual(&el.m_node[0])) { fil[i] = nfl[j]; break; } } assert(fil[i] != -1); } return fil; } // return the list of face indices of a surface std::vector<int> FEMeshTopo::SurfaceFaceIndexList(FESurface& s) { FENodeFaceList NFL; NFL.Create(imp->m_surface); int NF = s.Elements(); std::vector<int> fil(NF, -1); for (int i = 0; i < NF; ++i) { FESurfaceElement& el = s.Element(i); int nval = NFL.Faces(el.m_node[0]); const std::vector<int>& nfl = NFL.FaceList(el.m_node[0]); for (int j = 0; j < nval; ++j) { const FEFaceList::FACE& face = imp->m_surface[nfl[j]]; if (face.IsEqual(&el.m_node[0])) { fil[i] = nfl[j]; break; } } assert(fil[i] != -1); } return fil; } // return the element neighbor list std::vector<FEElement*> FEMeshTopo::ElementNeighborList(int n) { FEElement* el = Element(n); int nbrs = 0; switch (el->Shape()) { case ET_HEX8: case ET_HEX20: case ET_HEX27: nbrs = 6; break; case ET_TET4: case ET_TET5: case ET_TET10: case ET_TET15: case ET_TET20: nbrs = 4; break; case ET_PENTA6: case ET_PENTA15: case ET_PYRA5: case ET_PYRA13: nbrs = 5; break; default: assert(false); } vector<FEElement*> elemList; for (int i = 0; i < nbrs; ++i) { elemList.push_back(imp->m_ENL.Neighbor(n, i)); } return elemList; } // return the element neighbor list std::vector<int> FEMeshTopo::ElementNeighborIndexList(int n) { FEElement* el = Element(n); int nbrs = 0; switch (el->Shape()) { case ET_HEX8: case ET_HEX20: case ET_HEX27: nbrs = 6; break; case ET_TET4: case ET_TET5: case ET_TET10: case ET_TET15: case ET_TET20: nbrs = 4; break; case ET_PENTA6: case ET_PENTA15: case ET_PYRA5: case ET_PYRA13: nbrs = 5; break; default: assert(false); } vector<int> elemList; for (int i = 0; i < nbrs; ++i) { elemList.push_back(imp->m_ENL.NeighborIndex(n, i)); } return elemList; } // evaluate centroid of element as average position of integration points vec3d ElementCentroid(FEElement& el) { int nint = el.GaussPoints(); vec3d c(0,0,0); for (int n=0; n<nint; ++n) { FEMaterialPoint* pt = el.GetMaterialPoint(n); c += pt->m_rt; } c /= nint; return c; } // find neighboring elements that fall within given proximity d std::vector<int> FEMeshTopo::ElementProximityList(int i, double d, bool excludeSelf, bool matchMaterial) { std::vector<int> EPL; // element proximity list std::vector<bool> vst; // list of visited elements int NE = Elements(); vst.assign(NE, false); // exclude element i itself from the list, if requested if (!excludeSelf) { EPL.push_back(i); } FEElement& el_i = *Element(i); // get centroid of element i vec3d x = ElementCentroid(el_i); std::stack<int> stack; stack.push(i); vst[i] = true; while (!stack.empty()) { int n = stack.top(); stack.pop(); std::vector<int> ENIL = ElementNeighborIndexList(n); // search each neighbor to see if it falls within given proximity d for (int j = 0; j < ENIL.size(); ++j) { int k = ENIL[j]; if ((k != -1) && !vst[k]) { FEElement& el_k = *Element(k); vec3d xk = ElementCentroid(el_k); double dk = (x - xk).Length(); if (dk <= d) { if (!matchMaterial || (el_k.GetMatID() == el_i.GetMatID())) { EPL.push_back(k); stack.push(k); } } vst[k] = true; } } } return EPL; }
C++
3D
febiosoftware/FEBio
FECore/FECallBack.h
.h
1,964
50
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEModelComponent.h" //----------------------------------------------------------------------------- // Forward declaration of the FEModel class. class FEModel; //----------------------------------------------------------------------------- // This class implements a mechanism for defining callbacks from within plugins. class FECORE_API FECallBack : public FEModelComponent { FECORE_SUPER_CLASS(FECALLBACK_ID) FECORE_BASE_CLASS(FECallBack) public: // constructor requires the WHEN parameter (defined in FEModel.h) FECallBack(FEModel* pfem, int when); // Override this function in the derived class. virtual bool Execute(FEModel& fem, int nwhen) = 0; };
Unknown
3D
febiosoftware/FEBio
FECore/ClassDescriptor.h
.h
2,656
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 <string> #include <vector> #include "fecore_api.h" class FECORE_API FEClassDescriptor { public: class Variable { public: Variable(const std::string& name) : m_name(name) {} virtual ~Variable() {} virtual size_t Count() const = 0; public: std::string m_name; }; class SimpleVariable : public Variable { public: SimpleVariable(const std::string& name, const std::string& value) : Variable(name), m_val(value) {} size_t Count() const override { return 1; } public: std::string m_val; }; class ClassVariable : public Variable { public: ClassVariable(const std::string& name, const std::string& type) : Variable(name), m_type(type) {} size_t Count() const override { return m_var.size(); } void AddVariable(Variable* v) { m_var.push_back(v); } Variable* GetVariable(int i) { return m_var[i]; } const Variable* GetVariable(int i) const { return m_var[i]; } public: std::vector<Variable*> m_var; std::string m_type; }; public: FEClassDescriptor(const std::string& classType) : m_var("root", classType) {} void AddVariable(Variable* v) { m_var.AddVariable(v); } ClassVariable* Root() { return &m_var; } const ClassVariable* Root() const { return &m_var; } SimpleVariable* FindParameter(const char* szparam); const std::string& ClassType() const { return m_var.m_type; } public: ClassVariable m_var; };
Unknown
3D
febiosoftware/FEBio
FECore/FESurfaceLoad.cpp
.cpp
2,118
77
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FESurfaceLoad.h" #include "FEMesh.h" #include "DumpStream.h" #include "FEModel.h" FESurfaceLoad::FESurfaceLoad(FEModel* pfem) : FEModelLoad(pfem) { m_psurf = 0; } FESurfaceLoad::~FESurfaceLoad(void) { } //! Set the surface to apply the load to void FESurfaceLoad::SetSurface(FESurface* ps) { m_psurf = ps; } bool FESurfaceLoad::Init() { if (m_psurf == 0) return false; if (m_psurf->Init() == false) return false; return FEModelLoad::Init(); } void FESurfaceLoad::Serialize(DumpStream& ar) { FEModelLoad::Serialize(ar); if (ar.IsShallow()) return; ar & m_psurf; // the mesh manages surfaces for surface loads if (m_psurf && ar.IsLoading()) { FEMesh* pm = m_psurf->GetMesh(); pm->AddSurface(m_psurf); } } void FESurfaceLoad::ForceMeshUpdate() { GetFEModel()->SetMeshUpdateFlag(true); }
C++
3D
febiosoftware/FEBio
FECore/table.h
.h
2,568
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 <vector> // template class for storing 2D data template <typename T> class table { public: // constructors table() : m_rows(0), m_cols(0) {} table(int nrows, int ncols) : m_rows(0), m_cols(0) { resize(nrows, ncols); } table(const table& t) { m_data = t.m_data; m_rows = t.m_rows; m_cols = t.m_cols; } // assignment operator table& operator = (const table& t) { m_data = t.m_data; m_rows = t.m_rows; m_cols = t.m_cols; return (*this); } // resize table void resize(int nrows, int ncols, T def = T(0)) { std::vector<T> tmp(m_data); m_data.assign(nrows*ncols, def); int nr = (nrows < m_rows ? nrows : m_rows); int nc = (ncols < m_cols ? ncols : m_cols); for (int i=0; i<nr; ++i) { for (int j=0; j<nc; ++j) m_data[i*ncols + j] = tmp[i*m_cols + j]; } m_rows = nrows; m_cols = ncols; } // assign a value to the entire table void set(const T& v) { if (m_data.empty() == false) m_data.assign(m_rows*m_cols, v); } // get sizes int rows() const { return m_rows; } int columns() const { return m_cols; } // access operator const T& operator () (int i, int j) const { return m_data[i*m_cols + j]; } T& operator () (int i, int j) { return m_data[i*m_cols + j]; } private: std::vector<T> m_data; int m_rows, m_cols; };
Unknown
3D
febiosoftware/FEBio
FECore/FECube.cpp
.cpp
3,545
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.*/ #include "stdafx.h" #include "FECube.h" #include "FESurface.h" #include "FEModel.h" FECube::FECube() : m_mesh(0) { } FECube::~FECube() { for (int i = 0; i<6; ++i) { delete m_surf[i]; m_surf[i] = 0; } } // Get a surface FESurface* FECube::GetSurface(int i) { return m_surf[i]; } // get the node set of the corner nodes const FENodeSet& FECube::GetCornerNodes() const { return *m_corners; } // get the node set of boundary nodes const FENodeSet& FECube::GetBoundaryNodes() const { return *m_boundary; } // get the mesh of this cube FEMesh* FECube::GetMesh() { return m_mesh; } bool FECube::Build(FEModel* fem) { // make sure we have a mesh m_mesh = &fem->GetMesh(); FEMesh& m = *m_mesh; int NN = m.Nodes(); // first, get the outside surface FESurface* boundary = m.ElementBoundarySurface(); // get the boundary node set m_boundary = new FENodeSet(fem); m_boundary->Add(boundary->GetNodeList()); // Next, split it up in 6 surfaces // We divide the surface by comparing normals to the 6 surface normals of a cube vec3d fn[6] = { { 1, 0, 0 }, { -1, 0, 0 }, { 0, 1, 0 }, { 0, -1, 0 }, { 0, 0, 1 }, { 0, 0, -1 } }; for (int n = 0; n<6; ++n) { // create the surface m_surf[n] = fecore_alloc(FESurface, m_mesh->GetFEModel()); // get the normal for this face vec3d N = fn[n]; int faces = 0; for (int i = 0; i<boundary->Elements(); ++i) { FESurfaceElement& face = boundary->Element(i); vec3d Ni = boundary->SurfaceNormal(face, 0, 0); if (Ni*N > 0.9999) faces++; } m_surf[n]->Create(faces); faces = 0; for (int i = 0; i<boundary->Elements(); ++i) { FESurfaceElement& face = boundary->Element(i); vec3d Ni = boundary->SurfaceNormal(face, 0, 0); if (Ni*N > 0.9999) { FESurfaceElement& newFace = m_surf[n]->Element(faces++); newFace = face; } } m_surf[n]->Init(); } // we also need to find the 8 corner nodes vector<int> tag(NN, 0); for (int n = 0; n<6; ++n) { FESurface& sn = *m_surf[n]; FENodeList ns = sn.GetNodeList(); for (int i = 0; i<ns.Size(); ++i) tag[ns[i]]++; } m_corners = new FENodeSet(fem); for (int i = 0; i<NN; ++i) if (tag[i] == 3) m_corners->Add(i); assert(m_corners->Size() == 8); // don't forget to cleanup delete boundary; return true; }
C++
3D
febiosoftware/FEBio
FECore/FEShellDomain.cpp
.cpp
9,075
323
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 "FEShellDomain.h" #include "FEMesh.h" #include "FEMaterial.h" BEGIN_FECORE_CLASS(FEShellDomain, FEDomain) ADD_PROPERTY(m_matAxis, "mat_axis", FEProperty::Optional); END_FECORE_CLASS(); //----------------------------------------------------------------------------- //! constructor FEShellDomain::FEShellDomain(FEModel* fem) : FEDomain(FE_DOMAIN_SHELL, fem) { } //----------------------------------------------------------------------------- void FEShellDomain::PreSolveUpdate(const FETimeInfo& timeInfo) { ForEachMaterialPoint([&](FEMaterialPoint& mp) { mp.Update(timeInfo); }); } //----------------------------------------------------------------------------- void FEShellDomain::Reset() { ForEachShellElement([](FEShellElement& el) { int ni = el.GaussPoints(); for (int j = 0; j<ni; ++j) el.GetMaterialPoint(j)->Init(); int ne = el.Nodes(); for (int j = 0; j<ne; ++j) el.m_ht[j] = el.m_h0[j]; }); } //----------------------------------------------------------------------------- bool FEShellDomain::InitShells() { ForEachShellElement([](FEShellElement& el) { int n = el.Nodes(); for (int j = 0; j<n; ++j) el.m_ht[j] = el.m_h0[j]; }); return true; } //----------------------------------------------------------------------------- //! get the current nodal coordinates void FEShellDomain::GetCurrentNodalCoordinates(const FEShellElement& el, vec3d* rt, const bool back) { int neln = el.Nodes(); if (!back) for (int i = 0; i<neln; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).m_rt; else for (int i = 0; i<neln; ++i) rt[i] = m_pMesh->Node(el.m_node[i]).st(); } //----------------------------------------------------------------------------- //! get the current nodal coordinates void FEShellDomain::GetCurrentNodalCoordinates(const FEShellElement& el, vec3d* rt, double alpha, const bool back) { int neln = el.Nodes(); if (!back) { for (int i = 0; i<neln; ++i) { FENode& nd = m_pMesh->Node(el.m_node[i]); rt[i] = nd.m_rt*alpha + nd.m_rp*(1 - alpha); } } else { for (int i = 0; i<neln; ++i) { FENode& nd = m_pMesh->Node(el.m_node[i]); rt[i] = nd.st()*alpha + nd.sp()*(1 - alpha); } } } //----------------------------------------------------------------------------- //! get the reference nodal coordinates void FEShellDomain::GetReferenceNodalCoordinates(const FEShellElement& el, vec3d* r0, const bool back) { int neln = el.Nodes(); if (!back) for (int i = 0; i<neln; ++i) r0[i] = m_pMesh->Node(el.m_node[i]).m_r0; else for (int i = 0; i<neln; ++i) r0[i] = m_pMesh->Node(el.m_node[i]).s0(); } //----------------------------------------------------------------------------- //! get the previous nodal coordinates void FEShellDomain::GetPreviousNodalCoordinates(const FEShellElement& el, vec3d* rp, const bool back) { int neln = el.Nodes(); if (!back) for (int i = 0; i<neln; ++i) rp[i] = m_pMesh->Node(el.m_node[i]).m_rp; else for (int i = 0; i<neln; ++i) rp[i] = m_pMesh->Node(el.m_node[i]).sp(); } //----------------------------------------------------------------------------- void FEShellDomain::ForEachShellElement(std::function<void(FEShellElement& el)> f) { int NE = Elements(); for (int i = 0; i < NE; ++i) f(Element(i)); } //================================================================================================= FEShellDomainOld::FEShellDomainOld(FEModel* fem) : FEShellDomain(fem) { } //----------------------------------------------------------------------------- bool FEShellDomainOld::Create(int nelems, FE_Element_Spec espec) { m_Elem.resize(nelems); for (int i = 0; i < nelems; ++i) { FEShellElementOld& el = m_Elem[i]; el.SetLocalID(i); el.SetMeshPartition(this); } if (espec.etype != FE_ELEM_INVALID_TYPE) for (int i=0; i<nelems; ++i) m_Elem[i].SetType(espec.etype); return true; } //----------------------------------------------------------------------------- double FEShellDomainOld::Volume(FEShellElement& se) { FEShellElementOld& el = static_cast<FEShellElementOld&>(se); int neln = el.Nodes(); // initial nodal coordinates and directors vec3d r0[FEElement::MAX_NODES], D0[FEElement::MAX_NODES]; for (int i = 0; i<neln; ++i) { r0[i] = Node(el.m_lnode[i]).m_r0; D0[i] = el.m_D0[i]; } int nint = el.GaussPoints(); double *w = el.GaussWeights(); double V = 0; vec3d g[3]; for (int n = 0; n<nint; ++n) { // jacobian matrix double eta = el.gt(n); double* Mr = el.Hr(n); double* Ms = el.Hs(n); double* M = el.H(n); // evaluate covariant basis vectors g[0] = g[1] = g[2] = vec3d(0, 0, 0); for (int i = 0; i<neln; ++i) { g[0] += (r0[i] + D0[i] * eta / 2)*Mr[i]; g[1] += (r0[i] + D0[i] * eta / 2)*Ms[i]; g[2] += D0[i] * (M[i] / 2); } mat3d J = mat3d(g[0].x, g[1].x, g[2].x, g[0].y, g[1].y, g[2].y, g[0].z, g[1].z, g[2].z); // calculate the determinant double detJ0 = J.det(); V += detJ0*w[n]; } return V; } //----------------------------------------------------------------------------- //! Calculate all shell normals (i.e. the shell directors). //! And find shell nodes bool FEShellDomainOld::InitShells() { if (!FEShellDomain::InitShells()) return false; FEMesh& mesh = *GetMesh(); for (int i = 0; i<Elements(); ++i) { FEShellElementOld& el = ShellElement(i); int ne = el.Nodes(); for (int j = 0; j<ne; ++j) { vec3d d0 = mesh.Node(el.m_node[j]).m_d0; d0.unit(); el.m_D0[j] = d0 * el.m_h0[j]; } } return true; } //================================================================================================= BEGIN_FECORE_CLASS(FEShellDomainNew, FEShellDomain) ADD_PARAMETER(m_h0, "shell_thickness"); END_FECORE_CLASS(); FEShellDomainNew::FEShellDomainNew(FEModel* fem) : FEShellDomain(fem) { m_h0 = 0.0; } //----------------------------------------------------------------------------- bool FEShellDomainNew::Create(int nelems, FE_Element_Spec espec) { m_Elem.resize(nelems); for (int i = 0; i < nelems; ++i) { FEShellElementNew& el = m_Elem[i]; el.SetLocalID(i); el.SetMeshPartition(this); } if (espec.etype != FE_ELEM_INVALID_TYPE) for (int i = 0; i<nelems; ++i) m_Elem[i].SetType(espec.etype); return true; } //----------------------------------------------------------------------------- void FEShellDomainNew::AssignDefaultShellThickness() { double h0 = DefaultShellThickness(); if (h0 <= 0.0) return; for (int j = 0; j < Elements(); ++j) { FEShellElement& el = Element(j); int ne = el.Nodes(); for (int n = 0; n < ne; ++n) el.m_ht[n] = el.m_h0[n] = h0; } } //----------------------------------------------------------------------------- double FEShellDomainNew::Volume(FEShellElement& se) { FEShellElementNew& el = static_cast<FEShellElementNew&>(se); int neln = el.Nodes(); // initial nodal coordinates and directors vec3d r0[FEElement::MAX_NODES], D0[FEElement::MAX_NODES]; for (int i = 0; i<neln; ++i) { r0[i] = Node(el.m_lnode[i]).m_r0; D0[i] = Node(el.m_lnode[i]).m_d0; } int nint = el.GaussPoints(); double *w = el.GaussWeights(); double V = 0; vec3d g[3]; for (int n = 0; n<nint; ++n) { // jacobian matrix double eta = el.gt(n); double* Mr = el.Hr(n); double* Ms = el.Hs(n); double* M = el.H(n); // evaluate covariant basis vectors g[0] = g[1] = g[2] = vec3d(0, 0, 0); for (int i = 0; i<neln; ++i) { g[0] += (r0[i] + D0[i] * eta / 2)*Mr[i]; g[1] += (r0[i] + D0[i] * eta / 2)*Ms[i]; g[2] += D0[i] * (M[i] / 2); } mat3d J = mat3d(g[0].x, g[1].x, g[2].x, g[0].y, g[1].y, g[2].y, g[0].z, g[1].z, g[2].z); // calculate the determinant double detJ0 = J.det(); V += detJ0*w[n]; } return V; }
C++
3D
febiosoftware/FEBio
FECore/FENodeDataMap.h
.h
2,419
72
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once #include "FEDataMap.h" class FENodeSet; class FECORE_API FENodeDataMap : public FEDataMap { public: FENodeDataMap(); FENodeDataMap(FEDataType dataType); void Create(const FENodeSet* nodeSet, double val = 0.0); const FENodeSet* GetNodeSet() const; // return the item list associated with this map FEItemList* GetItemList() override; void Serialize(DumpStream& ar) override; public: void setValue(int n, double v) override; void setValue(int n, const vec2d& v) override; void setValue(int n, const vec3d& v) override; void setValue(int n, const mat3d& v) override; void setValue(int n, const mat3ds& v) override; double getValue(int n) const; void fillValue(double v) override; void fillValue(const vec2d& v) override; void fillValue(const vec3d& v) override; void fillValue(const mat3d& v) override; void fillValue(const mat3ds& v) override; double value(const FEMaterialPoint& mp) override; vec3d valueVec3d(const FEMaterialPoint& mp) override; mat3d valueMat3d(const FEMaterialPoint& mp) override; mat3ds valueMat3ds(const FEMaterialPoint& mp) override; private: const FENodeSet* m_nodeSet; };
Unknown
3D
febiosoftware/FEBio
FECore/tens4d.hpp
.hpp
91,019
1,449
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #pragma once // NOTE: This file is automatically included from tens4d.h // Users should not include this file manually! inline tens4d::tens4d(const double g) { d[ 0] = d[ 1] = d[ 2] = d[ 3] = d[ 4] = d[ 5] = d[ 6] = d[ 7] = d[ 8] = g; d[ 9] = d[10] = d[11] = d[12] = d[13] = d[14] = d[15] = d[16] = d[17] = g; d[18] = d[19] = d[20] = d[21] = d[22] = d[23] = d[24] = d[25] = d[26] = g; d[27] = d[28] = d[29] = d[30] = d[31] = d[32] = d[33] = d[34] = d[35] = g; d[36] = d[37] = d[38] = d[39] = d[40] = d[41] = d[42] = d[43] = d[44] = g; d[45] = d[46] = d[47] = d[48] = d[49] = d[50] = d[51] = d[52] = d[53] = g; d[54] = d[55] = d[56] = d[57] = d[58] = d[59] = d[60] = d[61] = d[62] = g; d[63] = d[64] = d[65] = d[66] = d[67] = d[68] = d[69] = d[70] = d[71] = g; d[72] = d[73] = d[74] = d[75] = d[76] = d[77] = d[78] = d[79] = d[80] = g; } inline tens4d::tens4d(const tens4ds t) { d[ 0]=t.d[ 0]; d[ 9]=t.d[ 1]; d[18]=t.d[ 3]; d[27]=t.d[ 6]; d[36]=t.d[10]; d[45]=t.d[15]; d[54]=t.d[ 6]; d[63]=t.d[10]; d[72]=t.d[15]; d[ 1]=t.d[ 1]; d[10]=t.d[ 2]; d[19]=t.d[ 4]; d[28]=t.d[ 7]; d[37]=t.d[11]; d[46]=t.d[16]; d[55]=t.d[ 7]; d[64]=t.d[11]; d[73]=t.d[16]; d[ 2]=t.d[ 3]; d[11]=t.d[ 4]; d[20]=t.d[ 5]; d[29]=t.d[ 8]; d[38]=t.d[12]; d[47]=t.d[17]; d[56]=t.d[ 8]; d[65]=t.d[12]; d[74]=t.d[17]; d[ 3]=t.d[ 6]; d[12]=t.d[ 7]; d[21]=t.d[ 8]; d[30]=t.d[ 9]; d[39]=t.d[13]; d[48]=t.d[18]; d[57]=t.d[ 9]; d[66]=t.d[13]; d[75]=t.d[18]; d[ 4]=t.d[10]; d[13]=t.d[11]; d[22]=t.d[12]; d[31]=t.d[13]; d[40]=t.d[14]; d[49]=t.d[19]; d[58]=t.d[13]; d[67]=t.d[14]; d[76]=t.d[19]; d[ 5]=t.d[15]; d[14]=t.d[16]; d[23]=t.d[17]; d[32]=t.d[18]; d[41]=t.d[19]; d[50]=t.d[20]; d[59]=t.d[18]; d[68]=t.d[19]; d[77]=t.d[20]; d[ 6]=t.d[ 6]; d[15]=t.d[ 7]; d[24]=t.d[ 8]; d[33]=t.d[ 9]; d[42]=t.d[13]; d[51]=t.d[18]; d[60]=t.d[ 9]; d[69]=t.d[13]; d[78]=t.d[18]; d[ 7]=t.d[10]; d[16]=t.d[11]; d[25]=t.d[12]; d[34]=t.d[13]; d[43]=t.d[14]; d[52]=t.d[19]; d[61]=t.d[13]; d[70]=t.d[14]; d[79]=t.d[19]; d[ 8]=t.d[15]; d[17]=t.d[16]; d[26]=t.d[17]; d[35]=t.d[18]; d[44]=t.d[19]; d[53]=t.d[20]; d[62]=t.d[18]; d[71]=t.d[19]; d[80]=t.d[20]; } inline tens4d::tens4d(const tens4dmm t) { d[ 0]=t.d[ 0]; d[ 9]=t.d[ 6]; d[18]=t.d[12]; d[27]=t.d[18]; d[36]=t.d[24]; d[45]=t.d[30]; d[54]=t.d[18]; d[63]=t.d[24]; d[72]=t.d[30]; d[ 1]=t.d[ 1]; d[10]=t.d[ 7]; d[19]=t.d[13]; d[28]=t.d[19]; d[37]=t.d[25]; d[46]=t.d[31]; d[55]=t.d[19]; d[64]=t.d[25]; d[73]=t.d[31]; d[ 2]=t.d[ 2]; d[11]=t.d[ 8]; d[20]=t.d[14]; d[29]=t.d[20]; d[38]=t.d[26]; d[47]=t.d[32]; d[56]=t.d[20]; d[65]=t.d[26]; d[74]=t.d[32]; d[ 3]=t.d[ 3]; d[12]=t.d[ 9]; d[21]=t.d[15]; d[30]=t.d[21]; d[39]=t.d[27]; d[48]=t.d[33]; d[57]=t.d[21]; d[66]=t.d[27]; d[75]=t.d[33]; d[ 4]=t.d[ 4]; d[13]=t.d[10]; d[22]=t.d[16]; d[31]=t.d[22]; d[40]=t.d[28]; d[49]=t.d[34]; d[58]=t.d[22]; d[67]=t.d[28]; d[76]=t.d[34]; d[ 5]=t.d[ 5]; d[14]=t.d[11]; d[23]=t.d[17]; d[32]=t.d[23]; d[41]=t.d[29]; d[50]=t.d[35]; d[59]=t.d[23]; d[68]=t.d[29]; d[77]=t.d[35]; d[ 6]=t.d[ 3]; d[15]=t.d[ 9]; d[24]=t.d[15]; d[33]=t.d[21]; d[42]=t.d[27]; d[51]=t.d[33]; d[60]=t.d[21]; d[69]=t.d[27]; d[78]=t.d[33]; d[ 7]=t.d[ 4]; d[16]=t.d[10]; d[25]=t.d[16]; d[34]=t.d[22]; d[43]=t.d[28]; d[52]=t.d[34]; d[61]=t.d[22]; d[70]=t.d[28]; d[79]=t.d[34]; d[ 8]=t.d[ 5]; d[17]=t.d[11]; d[26]=t.d[17]; d[35]=t.d[23]; d[44]=t.d[29]; d[53]=t.d[35]; d[62]=t.d[23]; d[71]=t.d[29]; d[80]=t.d[35]; } inline tens4d::tens4d(double m[9][9]) { d[ 0]=m[0][0]; d[ 9]=m[0][1]; d[18]=m[0][2]; d[27]=m[0][3]; d[36]=m[0][4]; d[45]=m[0][5]; d[54]=m[0][6]; d[63]=m[0][7]; d[72]=m[0][8]; d[ 1]=m[1][0]; d[10]=m[1][1]; d[19]=m[1][2]; d[28]=m[1][3]; d[37]=m[1][4]; d[46]=m[1][5]; d[55]=m[1][6]; d[64]=m[1][7]; d[73]=m[1][8]; d[ 2]=m[2][0]; d[11]=m[2][1]; d[20]=m[2][2]; d[29]=m[2][3]; d[38]=m[2][4]; d[47]=m[2][5]; d[56]=m[2][6]; d[65]=m[2][7]; d[74]=m[2][8]; d[ 3]=m[3][0]; d[12]=m[3][1]; d[21]=m[3][2]; d[30]=m[3][3]; d[39]=m[3][4]; d[48]=m[3][5]; d[57]=m[3][6]; d[66]=m[3][7]; d[75]=m[3][8]; d[ 4]=m[4][0]; d[13]=m[4][1]; d[22]=m[4][2]; d[31]=m[4][3]; d[40]=m[4][4]; d[49]=m[4][5]; d[58]=m[4][6]; d[67]=m[4][7]; d[76]=m[4][8]; d[ 5]=m[5][0]; d[14]=m[5][1]; d[23]=m[5][2]; d[32]=m[5][3]; d[41]=m[5][4]; d[50]=m[5][5]; d[59]=m[5][6]; d[68]=m[5][7]; d[77]=m[5][8]; d[ 6]=m[6][0]; d[15]=m[6][1]; d[24]=m[6][2]; d[33]=m[6][3]; d[42]=m[6][4]; d[51]=m[6][5]; d[60]=m[6][6]; d[69]=m[6][7]; d[78]=m[6][8]; d[ 7]=m[7][0]; d[16]=m[7][1]; d[25]=m[7][2]; d[34]=m[7][3]; d[43]=m[7][4]; d[52]=m[7][5]; d[61]=m[7][6]; d[70]=m[7][7]; d[79]=m[7][8]; d[ 8]=m[8][0]; d[17]=m[8][1]; d[26]=m[8][2]; d[35]=m[8][3]; d[44]=m[8][4]; d[53]=m[8][5]; d[62]=m[8][6]; d[71]=m[8][7]; d[80]=m[8][8]; } inline double& tens4d::operator () (int i, int j, int k, int l) { const int m[3][3] = {{0,3,8},{6,1,4},{5,7,2}}; tens4d& T = (*this); return T(m[i][j], m[k][l]); } inline double tens4d::operator () (int i, int j, int k, int l) const { const int m[3][3] = {{0,3,8},{6,1,4},{5,7,2}}; const tens4d& T = (*this); return T(m[i][j], m[k][l]); } inline double& tens4d::operator () (int i, int j) { const int m[9] = {0, 9, 18, 27, 36, 45, 54, 63, 72}; return d[m[j]+i]; } inline double tens4d::operator () (int i, int j) const { const int m[9] = {0, 9, 18, 27, 36, 45, 54, 63, 72}; return d[m[j]+i]; } //----------------------------------------------------------------------------- // operator + inline tens4d tens4d::operator + (const tens4d& t) const { tens4d s; // for (int i=0; i<NNZ; i++) // s.d[i] = d[i] + t.d[i]; s.d[ 0] = d[ 0] + t.d[ 0]; s.d[27] = d[27] + t.d[27]; s.d[54] = d[54] + t.d[54]; s.d[ 1] = d[ 1] + t.d[ 1]; s.d[28] = d[28] + t.d[28]; s.d[55] = d[55] + t.d[55]; s.d[ 2] = d[ 2] + t.d[ 2]; s.d[29] = d[29] + t.d[29]; s.d[56] = d[56] + t.d[56]; s.d[ 3] = d[ 3] + t.d[ 3]; s.d[30] = d[30] + t.d[30]; s.d[57] = d[57] + t.d[57]; s.d[ 4] = d[ 4] + t.d[ 4]; s.d[31] = d[31] + t.d[31]; s.d[58] = d[58] + t.d[58]; s.d[ 5] = d[ 5] + t.d[ 5]; s.d[32] = d[32] + t.d[32]; s.d[59] = d[59] + t.d[59]; s.d[ 6] = d[ 6] + t.d[ 6]; s.d[33] = d[33] + t.d[33]; s.d[60] = d[60] + t.d[60]; s.d[ 7] = d[ 7] + t.d[ 7]; s.d[34] = d[34] + t.d[34]; s.d[61] = d[61] + t.d[61]; s.d[ 8] = d[ 8] + t.d[ 8]; s.d[35] = d[35] + t.d[35]; s.d[62] = d[62] + t.d[62]; s.d[ 9] = d[ 9] + t.d[ 9]; s.d[36] = d[36] + t.d[36]; s.d[63] = d[63] + t.d[63]; s.d[10] = d[10] + t.d[10]; s.d[37] = d[37] + t.d[37]; s.d[64] = d[64] + t.d[64]; s.d[11] = d[11] + t.d[11]; s.d[38] = d[38] + t.d[38]; s.d[65] = d[65] + t.d[65]; s.d[12] = d[12] + t.d[12]; s.d[39] = d[39] + t.d[39]; s.d[66] = d[66] + t.d[66]; s.d[13] = d[13] + t.d[13]; s.d[40] = d[40] + t.d[40]; s.d[67] = d[67] + t.d[67]; s.d[14] = d[14] + t.d[14]; s.d[41] = d[41] + t.d[41]; s.d[68] = d[68] + t.d[68]; s.d[15] = d[15] + t.d[15]; s.d[42] = d[42] + t.d[42]; s.d[69] = d[69] + t.d[69]; s.d[16] = d[16] + t.d[16]; s.d[43] = d[43] + t.d[43]; s.d[70] = d[70] + t.d[70]; s.d[17] = d[17] + t.d[17]; s.d[44] = d[44] + t.d[44]; s.d[71] = d[71] + t.d[71]; s.d[18] = d[18] + t.d[18]; s.d[45] = d[45] + t.d[45]; s.d[72] = d[72] + t.d[72]; s.d[19] = d[19] + t.d[19]; s.d[46] = d[46] + t.d[46]; s.d[73] = d[73] + t.d[73]; s.d[20] = d[20] + t.d[20]; s.d[47] = d[47] + t.d[47]; s.d[74] = d[74] + t.d[74]; s.d[21] = d[21] + t.d[21]; s.d[48] = d[48] + t.d[48]; s.d[75] = d[75] + t.d[75]; s.d[22] = d[22] + t.d[22]; s.d[49] = d[49] + t.d[49]; s.d[76] = d[76] + t.d[76]; s.d[23] = d[23] + t.d[23]; s.d[50] = d[50] + t.d[50]; s.d[77] = d[77] + t.d[77]; s.d[24] = d[24] + t.d[24]; s.d[51] = d[51] + t.d[51]; s.d[78] = d[78] + t.d[78]; s.d[25] = d[25] + t.d[25]; s.d[52] = d[52] + t.d[52]; s.d[79] = d[79] + t.d[79]; s.d[26] = d[26] + t.d[26]; s.d[53] = d[53] + t.d[53]; s.d[80] = d[80] + t.d[80]; return s; } //----------------------------------------------------------------------------- // operator - inline tens4d tens4d::operator - (const tens4d& t) const { tens4d s; // for (int i=0; i<NNZ; i++) // s.d[i] = d[i] - t.d[i]; s.d[ 0] = d[ 0] - t.d[ 0]; s.d[27] = d[27] - t.d[27]; s.d[54] = d[54] - t.d[54]; s.d[ 1] = d[ 1] - t.d[ 1]; s.d[28] = d[28] - t.d[28]; s.d[55] = d[55] - t.d[55]; s.d[ 2] = d[ 2] - t.d[ 2]; s.d[29] = d[29] - t.d[29]; s.d[56] = d[56] - t.d[56]; s.d[ 3] = d[ 3] - t.d[ 3]; s.d[30] = d[30] - t.d[30]; s.d[57] = d[57] - t.d[57]; s.d[ 4] = d[ 4] - t.d[ 4]; s.d[31] = d[31] - t.d[31]; s.d[58] = d[58] - t.d[58]; s.d[ 5] = d[ 5] - t.d[ 5]; s.d[32] = d[32] - t.d[32]; s.d[59] = d[59] - t.d[59]; s.d[ 6] = d[ 6] - t.d[ 6]; s.d[33] = d[33] - t.d[33]; s.d[60] = d[60] - t.d[60]; s.d[ 7] = d[ 7] - t.d[ 7]; s.d[34] = d[34] - t.d[34]; s.d[61] = d[61] - t.d[61]; s.d[ 8] = d[ 8] - t.d[ 8]; s.d[35] = d[35] - t.d[35]; s.d[62] = d[62] - t.d[62]; s.d[ 9] = d[ 9] - t.d[ 9]; s.d[36] = d[36] - t.d[36]; s.d[63] = d[63] - t.d[63]; s.d[10] = d[10] - t.d[10]; s.d[37] = d[37] - t.d[37]; s.d[64] = d[64] - t.d[64]; s.d[11] = d[11] - t.d[11]; s.d[38] = d[38] - t.d[38]; s.d[65] = d[65] - t.d[65]; s.d[12] = d[12] - t.d[12]; s.d[39] = d[39] - t.d[39]; s.d[66] = d[66] - t.d[66]; s.d[13] = d[13] - t.d[13]; s.d[40] = d[40] - t.d[40]; s.d[67] = d[67] - t.d[67]; s.d[14] = d[14] - t.d[14]; s.d[41] = d[41] - t.d[41]; s.d[68] = d[68] - t.d[68]; s.d[15] = d[15] - t.d[15]; s.d[42] = d[42] - t.d[42]; s.d[69] = d[69] - t.d[69]; s.d[16] = d[16] - t.d[16]; s.d[43] = d[43] - t.d[43]; s.d[70] = d[70] - t.d[70]; s.d[17] = d[17] - t.d[17]; s.d[44] = d[44] - t.d[44]; s.d[71] = d[71] - t.d[71]; s.d[18] = d[18] - t.d[18]; s.d[45] = d[45] - t.d[45]; s.d[72] = d[72] - t.d[72]; s.d[19] = d[19] - t.d[19]; s.d[46] = d[46] - t.d[46]; s.d[73] = d[73] - t.d[73]; s.d[20] = d[20] - t.d[20]; s.d[47] = d[47] - t.d[47]; s.d[74] = d[74] - t.d[74]; s.d[21] = d[21] - t.d[21]; s.d[48] = d[48] - t.d[48]; s.d[75] = d[75] - t.d[75]; s.d[22] = d[22] - t.d[22]; s.d[49] = d[49] - t.d[49]; s.d[76] = d[76] - t.d[76]; s.d[23] = d[23] - t.d[23]; s.d[50] = d[50] - t.d[50]; s.d[77] = d[77] - t.d[77]; s.d[24] = d[24] - t.d[24]; s.d[51] = d[51] - t.d[51]; s.d[78] = d[78] - t.d[78]; s.d[25] = d[25] - t.d[25]; s.d[52] = d[52] - t.d[52]; s.d[79] = d[79] - t.d[79]; s.d[26] = d[26] - t.d[26]; s.d[53] = d[53] - t.d[53]; s.d[80] = d[80] - t.d[80]; return s; } //----------------------------------------------------------------------------- // operator + tens4ds inline tens4d tens4d::operator + (const tens4ds& t) const { tens4d s; s.d[ 0] = d[ 0] + t.d[ 0]; s.d[27] = d[27] + t.d[ 6]; s.d[54] = d[54] + t.d[ 6]; s.d[ 1] = d[ 1] + t.d[ 1]; s.d[28] = d[28] + t.d[ 7]; s.d[55] = d[55] + t.d[ 7]; s.d[ 2] = d[ 2] + t.d[ 3]; s.d[29] = d[29] + t.d[ 8]; s.d[56] = d[56] + t.d[ 8]; s.d[ 3] = d[ 3] + t.d[ 6]; s.d[30] = d[30] + t.d[ 9]; s.d[57] = d[57] + t.d[ 9]; s.d[ 4] = d[ 4] + t.d[10]; s.d[31] = d[31] + t.d[13]; s.d[58] = d[58] + t.d[13]; s.d[ 5] = d[ 5] + t.d[15]; s.d[32] = d[32] + t.d[18]; s.d[59] = d[59] + t.d[18]; s.d[ 6] = d[ 6] + t.d[ 6]; s.d[33] = d[33] + t.d[ 9]; s.d[60] = d[60] + t.d[9]; s.d[ 7] = d[ 7] + t.d[10]; s.d[34] = d[34] + t.d[13]; s.d[61] = d[61] + t.d[13]; s.d[ 8] = d[ 8] + t.d[15]; s.d[35] = d[35] + t.d[18]; s.d[62] = d[62] + t.d[18]; s.d[ 9] = d[ 9] + t.d[ 1]; s.d[36] = d[36] + t.d[10]; s.d[63] = d[63] + t.d[10]; s.d[10] = d[10] + t.d[ 2]; s.d[37] = d[37] + t.d[11]; s.d[64] = d[64] + t.d[11]; s.d[11] = d[11] + t.d[ 4]; s.d[38] = d[38] + t.d[12]; s.d[65] = d[65] + t.d[12]; s.d[12] = d[12] + t.d[ 7]; s.d[39] = d[39] + t.d[13]; s.d[66] = d[66] + t.d[13]; s.d[13] = d[13] + t.d[11]; s.d[40] = d[40] + t.d[14]; s.d[67] = d[67] + t.d[14]; s.d[14] = d[14] + t.d[16]; s.d[41] = d[41] + t.d[19]; s.d[68] = d[68] + t.d[19]; s.d[15] = d[15] + t.d[ 7]; s.d[42] = d[42] + t.d[13]; s.d[69] = d[69] + t.d[13]; s.d[16] = d[16] + t.d[11]; s.d[43] = d[43] + t.d[14]; s.d[70] = d[70] + t.d[14]; s.d[17] = d[17] + t.d[16]; s.d[44] = d[44] + t.d[19]; s.d[71] = d[71] + t.d[19]; s.d[18] = d[18] + t.d[ 3]; s.d[45] = d[45] + t.d[15]; s.d[72] = d[72] + t.d[15]; s.d[19] = d[19] + t.d[ 4]; s.d[46] = d[46] + t.d[16]; s.d[73] = d[73] + t.d[16]; s.d[20] = d[20] + t.d[ 5]; s.d[47] = d[47] + t.d[17]; s.d[74] = d[74] + t.d[17]; s.d[21] = d[21] + t.d[ 8]; s.d[48] = d[48] + t.d[18]; s.d[75] = d[75] + t.d[18]; s.d[22] = d[22] + t.d[12]; s.d[49] = d[49] + t.d[19]; s.d[76] = d[76] + t.d[19]; s.d[23] = d[23] + t.d[17]; s.d[50] = d[50] + t.d[20]; s.d[77] = d[77] + t.d[20]; s.d[24] = d[24] + t.d[ 8]; s.d[51] = d[51] + t.d[18]; s.d[78] = d[78] + t.d[18]; s.d[25] = d[25] + t.d[12]; s.d[52] = d[52] + t.d[19]; s.d[79] = d[79] + t.d[19]; s.d[26] = d[26] + t.d[17]; s.d[53] = d[53] + t.d[20]; s.d[80] = d[80] + t.d[20]; return s; } //----------------------------------------------------------------------------- // operator - tens4ds inline tens4d tens4d::operator - (const tens4ds& t) const { tens4d s; s.d[ 0] = d[ 0] - t.d[ 0]; s.d[27] = d[27] - t.d[ 6]; s.d[54] = d[54] - t.d[ 6]; s.d[ 1] = d[ 1] - t.d[ 1]; s.d[28] = d[28] - t.d[ 7]; s.d[55] = d[55] - t.d[ 7]; s.d[ 2] = d[ 2] - t.d[ 3]; s.d[29] = d[29] - t.d[ 8]; s.d[56] = d[56] - t.d[ 8]; s.d[ 3] = d[ 3] - t.d[ 6]; s.d[30] = d[30] - t.d[ 9]; s.d[57] = d[57] - t.d[ 9]; s.d[ 4] = d[ 4] - t.d[10]; s.d[31] = d[31] - t.d[13]; s.d[58] = d[58] - t.d[13]; s.d[ 5] = d[ 5] - t.d[15]; s.d[32] = d[32] - t.d[18]; s.d[59] = d[59] - t.d[18]; s.d[ 6] = d[ 6] - t.d[ 6]; s.d[33] = d[33] - t.d[ 9]; s.d[60] = d[60] - t.d[9]; s.d[ 7] = d[ 7] - t.d[10]; s.d[34] = d[34] - t.d[13]; s.d[61] = d[61] - t.d[13]; s.d[ 8] = d[ 8] - t.d[15]; s.d[35] = d[35] - t.d[18]; s.d[62] = d[62] - t.d[18]; s.d[ 9] = d[ 9] - t.d[ 1]; s.d[36] = d[36] - t.d[10]; s.d[63] = d[63] - t.d[10]; s.d[10] = d[10] - t.d[ 2]; s.d[37] = d[37] - t.d[11]; s.d[64] = d[64] - t.d[11]; s.d[11] = d[11] - t.d[ 4]; s.d[38] = d[38] - t.d[12]; s.d[65] = d[65] - t.d[12]; s.d[12] = d[12] - t.d[ 7]; s.d[39] = d[39] - t.d[13]; s.d[66] = d[66] - t.d[13]; s.d[13] = d[13] - t.d[11]; s.d[40] = d[40] - t.d[14]; s.d[67] = d[67] - t.d[14]; s.d[14] = d[14] - t.d[16]; s.d[41] = d[41] - t.d[19]; s.d[68] = d[68] - t.d[19]; s.d[15] = d[15] - t.d[ 7]; s.d[42] = d[42] - t.d[13]; s.d[69] = d[69] - t.d[13]; s.d[16] = d[16] - t.d[11]; s.d[43] = d[43] - t.d[14]; s.d[70] = d[70] - t.d[14]; s.d[17] = d[17] - t.d[16]; s.d[44] = d[44] - t.d[19]; s.d[71] = d[71] - t.d[19]; s.d[18] = d[18] - t.d[ 3]; s.d[45] = d[45] - t.d[15]; s.d[72] = d[72] - t.d[15]; s.d[19] = d[19] - t.d[ 4]; s.d[46] = d[46] - t.d[16]; s.d[73] = d[73] - t.d[16]; s.d[20] = d[20] - t.d[ 5]; s.d[47] = d[47] - t.d[17]; s.d[74] = d[74] - t.d[17]; s.d[21] = d[21] - t.d[ 8]; s.d[48] = d[48] - t.d[18]; s.d[75] = d[75] - t.d[18]; s.d[22] = d[22] - t.d[12]; s.d[49] = d[49] - t.d[19]; s.d[76] = d[76] - t.d[19]; s.d[23] = d[23] - t.d[17]; s.d[50] = d[50] - t.d[20]; s.d[77] = d[77] - t.d[20]; s.d[24] = d[24] - t.d[ 8]; s.d[51] = d[51] - t.d[18]; s.d[78] = d[78] - t.d[18]; s.d[25] = d[25] - t.d[12]; s.d[52] = d[52] - t.d[19]; s.d[79] = d[79] - t.d[19]; s.d[26] = d[26] - t.d[17]; s.d[53] = d[53] - t.d[20]; s.d[80] = d[80] - t.d[20]; return s; } //----------------------------------------------------------------------------- // operator * inline tens4d tens4d::operator * (double g) const { tens4d s; // for (int i=0; i<NNZ; i++) // s.d[i] = g*d[i]; s.d[ 0] = g*d[ 0]; s.d[27] = g*d[27]; s.d[54] = g*d[54]; s.d[ 1] = g*d[ 1]; s.d[28] = g*d[28]; s.d[55] = g*d[55]; s.d[ 2] = g*d[ 2]; s.d[29] = g*d[29]; s.d[56] = g*d[56]; s.d[ 3] = g*d[ 3]; s.d[30] = g*d[30]; s.d[57] = g*d[57]; s.d[ 4] = g*d[ 4]; s.d[31] = g*d[31]; s.d[58] = g*d[58]; s.d[ 5] = g*d[ 5]; s.d[32] = g*d[32]; s.d[59] = g*d[59]; s.d[ 6] = g*d[ 6]; s.d[33] = g*d[33]; s.d[60] = g*d[60]; s.d[ 7] = g*d[ 7]; s.d[34] = g*d[34]; s.d[61] = g*d[61]; s.d[ 8] = g*d[ 8]; s.d[35] = g*d[35]; s.d[62] = g*d[62]; s.d[ 9] = g*d[ 9]; s.d[36] = g*d[36]; s.d[63] = g*d[63]; s.d[10] = g*d[10]; s.d[37] = g*d[37]; s.d[64] = g*d[64]; s.d[11] = g*d[11]; s.d[38] = g*d[38]; s.d[65] = g*d[65]; s.d[12] = g*d[12]; s.d[39] = g*d[39]; s.d[66] = g*d[66]; s.d[13] = g*d[13]; s.d[40] = g*d[40]; s.d[67] = g*d[67]; s.d[14] = g*d[14]; s.d[41] = g*d[41]; s.d[68] = g*d[68]; s.d[15] = g*d[15]; s.d[42] = g*d[42]; s.d[69] = g*d[69]; s.d[16] = g*d[16]; s.d[43] = g*d[43]; s.d[70] = g*d[70]; s.d[17] = g*d[17]; s.d[44] = g*d[44]; s.d[71] = g*d[71]; s.d[18] = g*d[18]; s.d[45] = g*d[45]; s.d[72] = g*d[72]; s.d[19] = g*d[19]; s.d[46] = g*d[46]; s.d[73] = g*d[73]; s.d[20] = g*d[20]; s.d[47] = g*d[47]; s.d[74] = g*d[74]; s.d[21] = g*d[21]; s.d[48] = g*d[48]; s.d[75] = g*d[75]; s.d[22] = g*d[22]; s.d[49] = g*d[49]; s.d[76] = g*d[76]; s.d[23] = g*d[23]; s.d[50] = g*d[50]; s.d[77] = g*d[77]; s.d[24] = g*d[24]; s.d[51] = g*d[51]; s.d[78] = g*d[78]; s.d[25] = g*d[25]; s.d[52] = g*d[52]; s.d[79] = g*d[79]; s.d[26] = g*d[26]; s.d[53] = g*d[53]; s.d[80] = g*d[80]; return s; } //----------------------------------------------------------------------------- // operator / inline tens4d tens4d::operator / (double g) const { tens4d s; // for (int i=0; i<NNZ; i++) // s.d[i] = d[i]/g; s.d[ 0] = d[ 0]/g; s.d[27] = d[27]/g; s.d[54] = d[54]/g; s.d[ 1] = d[ 1]/g; s.d[28] = d[28]/g; s.d[55] = d[55]/g; s.d[ 2] = d[ 2]/g; s.d[29] = d[29]/g; s.d[56] = d[56]/g; s.d[ 3] = d[ 3]/g; s.d[30] = d[30]/g; s.d[57] = d[57]/g; s.d[ 4] = d[ 4]/g; s.d[31] = d[31]/g; s.d[58] = d[58]/g; s.d[ 5] = d[ 5]/g; s.d[32] = d[32]/g; s.d[59] = d[59]/g; s.d[ 6] = d[ 6]/g; s.d[33] = d[33]/g; s.d[60] = d[60]/g; s.d[ 7] = d[ 7]/g; s.d[34] = d[34]/g; s.d[61] = d[61]/g; s.d[ 8] = d[ 8]/g; s.d[35] = d[35]/g; s.d[62] = d[62]/g; s.d[ 9] = d[ 9]/g; s.d[36] = d[36]/g; s.d[63] = d[63]/g; s.d[10] = d[10]/g; s.d[37] = d[37]/g; s.d[64] = d[64]/g; s.d[11] = d[11]/g; s.d[38] = d[38]/g; s.d[65] = d[65]/g; s.d[12] = d[12]/g; s.d[39] = d[39]/g; s.d[66] = d[66]/g; s.d[13] = d[13]/g; s.d[40] = d[40]/g; s.d[67] = d[67]/g; s.d[14] = d[14]/g; s.d[41] = d[41]/g; s.d[68] = d[68]/g; s.d[15] = d[15]/g; s.d[42] = d[42]/g; s.d[69] = d[69]/g; s.d[16] = d[16]/g; s.d[43] = d[43]/g; s.d[70] = d[70]/g; s.d[17] = d[17]/g; s.d[44] = d[44]/g; s.d[71] = d[71]/g; s.d[18] = d[18]/g; s.d[45] = d[45]/g; s.d[72] = d[72]/g; s.d[19] = d[19]/g; s.d[46] = d[46]/g; s.d[73] = d[73]/g; s.d[20] = d[20]/g; s.d[47] = d[47]/g; s.d[74] = d[74]/g; s.d[21] = d[21]/g; s.d[48] = d[48]/g; s.d[75] = d[75]/g; s.d[22] = d[22]/g; s.d[49] = d[49]/g; s.d[76] = d[76]/g; s.d[23] = d[23]/g; s.d[50] = d[50]/g; s.d[77] = d[77]/g; s.d[24] = d[24]/g; s.d[51] = d[51]/g; s.d[78] = d[78]/g; s.d[25] = d[25]/g; s.d[52] = d[52]/g; s.d[79] = d[79]/g; s.d[26] = d[26]/g; s.d[53] = d[53]/g; s.d[80] = d[80]/g; return s; } //----------------------------------------------------------------------------- // assignment operator += inline tens4d& tens4d::operator += (const tens4d& t) { // for (int i=0; i<NNZ; i++) // d[i] += t.d[i]; d[ 0] += t.d[ 0]; d[27] += t.d[27]; d[54] += t.d[54]; d[ 1] += t.d[ 1]; d[28] += t.d[28]; d[55] += t.d[55]; d[ 2] += t.d[ 2]; d[29] += t.d[29]; d[56] += t.d[56]; d[ 3] += t.d[ 3]; d[30] += t.d[30]; d[57] += t.d[57]; d[ 4] += t.d[ 4]; d[31] += t.d[31]; d[58] += t.d[58]; d[ 5] += t.d[ 5]; d[32] += t.d[32]; d[59] += t.d[59]; d[ 6] += t.d[ 6]; d[33] += t.d[33]; d[60] += t.d[60]; d[ 7] += t.d[ 7]; d[34] += t.d[34]; d[61] += t.d[61]; d[ 8] += t.d[ 8]; d[35] += t.d[35]; d[62] += t.d[62]; d[ 9] += t.d[ 9]; d[36] += t.d[36]; d[63] += t.d[63]; d[10] += t.d[10]; d[37] += t.d[37]; d[64] += t.d[64]; d[11] += t.d[11]; d[38] += t.d[38]; d[65] += t.d[65]; d[12] += t.d[12]; d[39] += t.d[39]; d[66] += t.d[66]; d[13] += t.d[13]; d[40] += t.d[40]; d[67] += t.d[67]; d[14] += t.d[14]; d[41] += t.d[41]; d[68] += t.d[68]; d[15] += t.d[15]; d[42] += t.d[42]; d[69] += t.d[69]; d[16] += t.d[16]; d[43] += t.d[43]; d[70] += t.d[70]; d[17] += t.d[17]; d[44] += t.d[44]; d[71] += t.d[71]; d[18] += t.d[18]; d[45] += t.d[45]; d[72] += t.d[72]; d[19] += t.d[19]; d[46] += t.d[46]; d[73] += t.d[73]; d[20] += t.d[20]; d[47] += t.d[47]; d[74] += t.d[74]; d[21] += t.d[21]; d[48] += t.d[48]; d[75] += t.d[75]; d[22] += t.d[22]; d[49] += t.d[49]; d[76] += t.d[76]; d[23] += t.d[23]; d[50] += t.d[50]; d[77] += t.d[77]; d[24] += t.d[24]; d[51] += t.d[51]; d[78] += t.d[78]; d[25] += t.d[25]; d[52] += t.d[52]; d[79] += t.d[79]; d[26] += t.d[26]; d[53] += t.d[53]; d[80] += t.d[80]; return (*this); } //----------------------------------------------------------------------------- // assignment operator -= inline tens4d& tens4d::operator -= (const tens4d& t) { // for (int i=0; i<NNZ; i++) // d[i] -= t.d[i]; d[ 0] -= t.d[ 0]; d[27] -= t.d[27]; d[54] -= t.d[54]; d[ 1] -= t.d[ 1]; d[28] -= t.d[28]; d[55] -= t.d[55]; d[ 2] -= t.d[ 2]; d[29] -= t.d[29]; d[56] -= t.d[56]; d[ 3] -= t.d[ 3]; d[30] -= t.d[30]; d[57] -= t.d[57]; d[ 4] -= t.d[ 4]; d[31] -= t.d[31]; d[58] -= t.d[58]; d[ 5] -= t.d[ 5]; d[32] -= t.d[32]; d[59] -= t.d[59]; d[ 6] -= t.d[ 6]; d[33] -= t.d[33]; d[60] -= t.d[60]; d[ 7] -= t.d[ 7]; d[34] -= t.d[34]; d[61] -= t.d[61]; d[ 8] -= t.d[ 8]; d[35] -= t.d[35]; d[62] -= t.d[62]; d[ 9] -= t.d[ 9]; d[36] -= t.d[36]; d[63] -= t.d[63]; d[10] -= t.d[10]; d[37] -= t.d[37]; d[64] -= t.d[64]; d[11] -= t.d[11]; d[38] -= t.d[38]; d[65] -= t.d[65]; d[12] -= t.d[12]; d[39] -= t.d[39]; d[66] -= t.d[66]; d[13] -= t.d[13]; d[40] -= t.d[40]; d[67] -= t.d[67]; d[14] -= t.d[14]; d[41] -= t.d[41]; d[68] -= t.d[68]; d[15] -= t.d[15]; d[42] -= t.d[42]; d[69] -= t.d[69]; d[16] -= t.d[16]; d[43] -= t.d[43]; d[70] -= t.d[70]; d[17] -= t.d[17]; d[44] -= t.d[44]; d[71] -= t.d[71]; d[18] -= t.d[18]; d[45] -= t.d[45]; d[72] -= t.d[72]; d[19] -= t.d[19]; d[46] -= t.d[46]; d[73] -= t.d[73]; d[20] -= t.d[20]; d[47] -= t.d[47]; d[74] -= t.d[74]; d[21] -= t.d[21]; d[48] -= t.d[48]; d[75] -= t.d[75]; d[22] -= t.d[22]; d[49] -= t.d[49]; d[76] -= t.d[76]; d[23] -= t.d[23]; d[50] -= t.d[50]; d[77] -= t.d[77]; d[24] -= t.d[24]; d[51] -= t.d[51]; d[78] -= t.d[78]; d[25] -= t.d[25]; d[52] -= t.d[52]; d[79] -= t.d[79]; d[26] -= t.d[26]; d[53] -= t.d[53]; d[80] -= t.d[80]; return (*this); } //----------------------------------------------------------------------------- // assignment operator += tens4ds inline tens4d& tens4d::operator += (const tens4ds& t) { d[ 0] += t.d[ 0]; d[27] += t.d[ 6]; d[54] += t.d[ 6]; d[ 1] += t.d[ 1]; d[28] += t.d[ 7]; d[55] += t.d[ 7]; d[ 2] += t.d[ 3]; d[29] += t.d[ 8]; d[56] += t.d[ 8]; d[ 3] += t.d[ 6]; d[30] += t.d[ 9]; d[57] += t.d[ 9]; d[ 4] += t.d[10]; d[31] += t.d[13]; d[58] += t.d[13]; d[ 5] += t.d[15]; d[32] += t.d[18]; d[59] += t.d[18]; d[ 6] += t.d[ 6]; d[33] += t.d[ 9]; d[60] += t.d[ 9]; d[ 7] += t.d[10]; d[34] += t.d[13]; d[61] += t.d[13]; d[ 8] += t.d[15]; d[35] += t.d[18]; d[62] += t.d[18]; d[ 9] += t.d[ 1]; d[36] += t.d[10]; d[63] += t.d[10]; d[10] += t.d[ 2]; d[37] += t.d[11]; d[64] += t.d[11]; d[11] += t.d[ 4]; d[38] += t.d[12]; d[65] += t.d[12]; d[12] += t.d[ 7]; d[39] += t.d[13]; d[66] += t.d[13]; d[13] += t.d[11]; d[40] += t.d[14]; d[67] += t.d[14]; d[14] += t.d[16]; d[41] += t.d[19]; d[68] += t.d[19]; d[15] += t.d[ 7]; d[42] += t.d[13]; d[69] += t.d[13]; d[16] += t.d[11]; d[43] += t.d[14]; d[70] += t.d[14]; d[17] += t.d[16]; d[44] += t.d[19]; d[71] += t.d[19]; d[18] += t.d[ 3]; d[45] += t.d[15]; d[72] += t.d[15]; d[19] += t.d[ 4]; d[46] += t.d[16]; d[73] += t.d[16]; d[20] += t.d[ 5]; d[47] += t.d[17]; d[74] += t.d[17]; d[21] += t.d[ 8]; d[48] += t.d[18]; d[75] += t.d[18]; d[22] += t.d[12]; d[49] += t.d[19]; d[76] += t.d[19]; d[23] += t.d[17]; d[50] += t.d[20]; d[77] += t.d[20]; d[24] += t.d[ 8]; d[51] += t.d[18]; d[78] += t.d[18]; d[25] += t.d[12]; d[52] += t.d[19]; d[79] += t.d[19]; d[26] += t.d[17]; d[53] += t.d[20]; d[80] += t.d[20]; return (*this); } //----------------------------------------------------------------------------- // assignment operator -= tens4ds inline tens4d& tens4d::operator -= (const tens4ds& t) { d[ 0] -= t.d[ 0]; d[27] -= t.d[ 6]; d[54] -= t.d[ 6]; d[ 1] -= t.d[ 1]; d[28] -= t.d[ 7]; d[55] -= t.d[ 7]; d[ 2] -= t.d[ 3]; d[29] -= t.d[ 8]; d[56] -= t.d[ 8]; d[ 3] -= t.d[ 6]; d[30] -= t.d[ 9]; d[57] -= t.d[ 9]; d[ 4] -= t.d[10]; d[31] -= t.d[13]; d[58] -= t.d[13]; d[ 5] -= t.d[15]; d[32] -= t.d[18]; d[59] -= t.d[18]; d[ 6] -= t.d[ 6]; d[33] -= t.d[ 9]; d[60] -= t.d[ 9]; d[ 7] -= t.d[10]; d[34] -= t.d[13]; d[61] -= t.d[13]; d[ 8] -= t.d[15]; d[35] -= t.d[18]; d[62] -= t.d[18]; d[ 9] -= t.d[ 1]; d[36] -= t.d[10]; d[63] -= t.d[10]; d[10] -= t.d[ 2]; d[37] -= t.d[11]; d[64] -= t.d[11]; d[11] -= t.d[ 4]; d[38] -= t.d[12]; d[65] -= t.d[12]; d[12] -= t.d[ 7]; d[39] -= t.d[13]; d[66] -= t.d[13]; d[13] -= t.d[11]; d[40] -= t.d[14]; d[67] -= t.d[14]; d[14] -= t.d[16]; d[41] -= t.d[19]; d[68] -= t.d[19]; d[15] -= t.d[ 7]; d[42] -= t.d[13]; d[69] -= t.d[13]; d[16] -= t.d[11]; d[43] -= t.d[14]; d[70] -= t.d[14]; d[17] -= t.d[16]; d[44] -= t.d[19]; d[71] -= t.d[19]; d[18] -= t.d[ 3]; d[45] -= t.d[15]; d[72] -= t.d[15]; d[19] -= t.d[ 4]; d[46] -= t.d[16]; d[73] -= t.d[16]; d[20] -= t.d[ 5]; d[47] -= t.d[17]; d[74] -= t.d[17]; d[21] -= t.d[ 8]; d[48] -= t.d[18]; d[75] -= t.d[18]; d[22] -= t.d[12]; d[49] -= t.d[19]; d[76] -= t.d[19]; d[23] -= t.d[17]; d[50] -= t.d[20]; d[77] -= t.d[20]; d[24] -= t.d[ 8]; d[51] -= t.d[18]; d[78] -= t.d[18]; d[25] -= t.d[12]; d[52] -= t.d[19]; d[79] -= t.d[19]; d[26] -= t.d[17]; d[53] -= t.d[20]; d[80] -= t.d[20]; return (*this); } //----------------------------------------------------------------------------- // assignment operator *= inline tens4d& tens4d::operator *= (double g) { // for (int i=0; i<NNZ; i++) // d[i] *= g; d[ 0] *= g; d[27] *= g; d[54] *= g; d[ 1] *= g; d[28] *= g; d[55] *= g; d[ 2] *= g; d[29] *= g; d[56] *= g; d[ 3] *= g; d[30] *= g; d[57] *= g; d[ 4] *= g; d[31] *= g; d[58] *= g; d[ 5] *= g; d[32] *= g; d[59] *= g; d[ 6] *= g; d[33] *= g; d[60] *= g; d[ 7] *= g; d[34] *= g; d[61] *= g; d[ 8] *= g; d[35] *= g; d[62] *= g; d[ 9] *= g; d[36] *= g; d[63] *= g; d[10] *= g; d[37] *= g; d[64] *= g; d[11] *= g; d[38] *= g; d[65] *= g; d[12] *= g; d[39] *= g; d[66] *= g; d[13] *= g; d[40] *= g; d[67] *= g; d[14] *= g; d[41] *= g; d[68] *= g; d[15] *= g; d[42] *= g; d[69] *= g; d[16] *= g; d[43] *= g; d[70] *= g; d[17] *= g; d[44] *= g; d[71] *= g; d[18] *= g; d[45] *= g; d[72] *= g; d[19] *= g; d[46] *= g; d[73] *= g; d[20] *= g; d[47] *= g; d[74] *= g; d[21] *= g; d[48] *= g; d[75] *= g; d[22] *= g; d[49] *= g; d[76] *= g; d[23] *= g; d[50] *= g; d[77] *= g; d[24] *= g; d[51] *= g; d[78] *= g; d[25] *= g; d[52] *= g; d[79] *= g; d[26] *= g; d[53] *= g; d[80] *= g; return (*this); } //----------------------------------------------------------------------------- // assignment operator /= inline tens4d& tens4d::operator /= (double g) { // for (int i=0; i<NNZ; i++) // d[i] /= g; d[ 0] /= g; d[27] /= g; d[54] /= g; d[ 1] /= g; d[28] /= g; d[55] /= g; d[ 2] /= g; d[29] /= g; d[56] /= g; d[ 3] /= g; d[30] /= g; d[57] /= g; d[ 4] /= g; d[31] /= g; d[58] /= g; d[ 5] /= g; d[32] /= g; d[59] /= g; d[ 6] /= g; d[33] /= g; d[60] /= g; d[ 7] /= g; d[34] /= g; d[61] /= g; d[ 8] /= g; d[35] /= g; d[62] /= g; d[ 9] /= g; d[36] /= g; d[63] /= g; d[10] /= g; d[37] /= g; d[64] /= g; d[11] /= g; d[38] /= g; d[65] /= g; d[12] /= g; d[39] /= g; d[66] /= g; d[13] /= g; d[40] /= g; d[67] /= g; d[14] /= g; d[41] /= g; d[68] /= g; d[15] /= g; d[42] /= g; d[69] /= g; d[16] /= g; d[43] /= g; d[70] /= g; d[17] /= g; d[44] /= g; d[71] /= g; d[18] /= g; d[45] /= g; d[72] /= g; d[19] /= g; d[46] /= g; d[73] /= g; d[20] /= g; d[47] /= g; d[74] /= g; d[21] /= g; d[48] /= g; d[75] /= g; d[22] /= g; d[49] /= g; d[76] /= g; d[23] /= g; d[50] /= g; d[77] /= g; d[24] /= g; d[51] /= g; d[78] /= g; d[25] /= g; d[52] /= g; d[79] /= g; d[26] /= g; d[53] /= g; d[80] /= g; return (*this); } //----------------------------------------------------------------------------- // unary operator - inline tens4d tens4d::operator - () const { tens4d s; s.d[ 0] = -d[ 0]; s.d[27] = -d[27]; s.d[54] = -d[54]; s.d[ 1] = -d[ 1]; s.d[28] = -d[28]; s.d[55] = -d[55]; s.d[ 2] = -d[ 2]; s.d[29] = -d[29]; s.d[56] = -d[56]; s.d[ 3] = -d[ 3]; s.d[30] = -d[30]; s.d[57] = -d[57]; s.d[ 4] = -d[ 4]; s.d[31] = -d[31]; s.d[58] = -d[58]; s.d[ 5] = -d[ 5]; s.d[32] = -d[32]; s.d[59] = -d[59]; s.d[ 6] = -d[ 6]; s.d[33] = -d[33]; s.d[60] = -d[60]; s.d[ 7] = -d[ 7]; s.d[34] = -d[34]; s.d[61] = -d[61]; s.d[ 8] = -d[ 8]; s.d[35] = -d[35]; s.d[62] = -d[62]; s.d[ 9] = -d[ 9]; s.d[36] = -d[36]; s.d[63] = -d[63]; s.d[10] = -d[10]; s.d[37] = -d[37]; s.d[64] = -d[64]; s.d[11] = -d[11]; s.d[38] = -d[38]; s.d[65] = -d[65]; s.d[12] = -d[12]; s.d[39] = -d[39]; s.d[66] = -d[66]; s.d[13] = -d[13]; s.d[40] = -d[40]; s.d[67] = -d[67]; s.d[14] = -d[14]; s.d[41] = -d[41]; s.d[68] = -d[68]; s.d[15] = -d[15]; s.d[42] = -d[42]; s.d[69] = -d[69]; s.d[16] = -d[16]; s.d[43] = -d[43]; s.d[70] = -d[70]; s.d[17] = -d[17]; s.d[44] = -d[44]; s.d[71] = -d[71]; s.d[18] = -d[18]; s.d[45] = -d[45]; s.d[72] = -d[72]; s.d[19] = -d[19]; s.d[46] = -d[46]; s.d[73] = -d[73]; s.d[20] = -d[20]; s.d[47] = -d[47]; s.d[74] = -d[74]; s.d[21] = -d[21]; s.d[48] = -d[48]; s.d[75] = -d[75]; s.d[22] = -d[22]; s.d[49] = -d[49]; s.d[76] = -d[76]; s.d[23] = -d[23]; s.d[50] = -d[50]; s.d[77] = -d[77]; s.d[24] = -d[24]; s.d[51] = -d[51]; s.d[78] = -d[78]; s.d[25] = -d[25]; s.d[52] = -d[52]; s.d[79] = -d[79]; s.d[26] = -d[26]; s.d[53] = -d[53]; s.d[80] = -d[80]; return s; } //----------------------------------------------------------------------------- // double contraction of general 4th-order tensor with a general 2nd-order tensor // Aij = Dijkl Mkl inline mat3d tens4d::dot(const mat3d &m) const { mat3d a; a(0,0) = d[0]*m(0,0) + d[27]*m(0,1) + d[72]*m(0,2) + d[54]*m(1,0) + d[ 9]*m(1,1) + d[36]*m(1,2) + d[45]*m(2,0) + d[63]*m(2,1) + d[18]*m(2,2); a(0,1) = d[1]*m(0,0) + d[28]*m(0,1) + d[73]*m(0,2) + d[55]*m(1,0) + d[10]*m(1,1) + d[37]*m(1,2) + d[46]*m(2,0) + d[64]*m(2,1) + d[19]*m(2,2); a(0,2) = d[2]*m(0,0) + d[29]*m(0,1) + d[74]*m(0,2) + d[56]*m(1,0) + d[11]*m(1,1) + d[38]*m(1,2) + d[47]*m(2,0) + d[65]*m(2,1) + d[20]*m(2,2); a(1,0) = d[3]*m(0,0) + d[30]*m(0,1) + d[75]*m(0,2) + d[57]*m(1,0) + d[12]*m(1,1) + d[39]*m(1,2) + d[48]*m(2,0) + d[66]*m(2,1) + d[21]*m(2,2); a(1,1) = d[4]*m(0,0) + d[31]*m(0,1) + d[76]*m(0,2) + d[58]*m(1,0) + d[13]*m(1,1) + d[40]*m(1,2) + d[49]*m(2,0) + d[67]*m(2,1) + d[22]*m(2,2); a(1,2) = d[5]*m(0,0) + d[32]*m(0,1) + d[77]*m(0,2) + d[59]*m(1,0) + d[14]*m(1,1) + d[41]*m(1,2) + d[50]*m(2,0) + d[68]*m(2,1) + d[23]*m(2,2); a(2,0) = d[6]*m(0,0) + d[33]*m(0,1) + d[78]*m(0,2) + d[60]*m(1,0) + d[15]*m(1,1) + d[42]*m(1,2) + d[51]*m(2,0) + d[69]*m(2,1) + d[24]*m(2,2); a(2,1) = d[7]*m(0,0) + d[34]*m(0,1) + d[79]*m(0,2) + d[61]*m(1,0) + d[16]*m(1,1) + d[43]*m(1,2) + d[52]*m(2,0) + d[70]*m(2,1) + d[25]*m(2,2); a(2,2) = d[8]*m(0,0) + d[35]*m(0,1) + d[80]*m(0,2) + d[62]*m(1,0) + d[17]*m(1,1) + d[44]*m(1,2) + d[53]*m(2,0) + d[71]*m(2,1) + d[26]*m(2,2); return a; } // single dot product with 2nd order tensor inline tens4d tens4d::sdot(const mat3d& m) const { tens4d s; s.d[ 0] = d[0]*m(0,0) + d[27]*m(1,0) + d[72]*m(2,0); s.d[ 1] = d[1]*m(0,0) + d[28]*m(1,0) + d[73]*m(2,0); s.d[ 2] = d[2]*m(0,0) + d[29]*m(1,0) + d[74]*m(2,0); s.d[ 3] = d[3]*m(0,0) + d[30]*m(1,0) + d[75]*m(2,0); s.d[ 4] = d[4]*m(0,0) + d[31]*m(1,0) + d[76]*m(2,0); s.d[ 5] = d[5]*m(0,0) + d[32]*m(1,0) + d[77]*m(2,0); s.d[ 6] = d[6]*m(0,0) + d[33]*m(1,0) + d[78]*m(2,0); s.d[ 7] = d[7]*m(0,0) + d[34]*m(1,0) + d[79]*m(2,0); s.d[ 8] = d[8]*m(0,0) + d[35]*m(1,0) + d[80]*m(2,0); s.d[ 9] = d[54]*m(0,1) + d[ 9]*m(1,1) + d[36]*m(2,1); s.d[10] = d[55]*m(0,1) + d[10]*m(1,1) + d[37]*m(2,1); s.d[11] = d[56]*m(0,1) + d[11]*m(1,1) + d[38]*m(2,1); s.d[12] = d[57]*m(0,1) + d[12]*m(1,1) + d[39]*m(2,1); s.d[13] = d[58]*m(0,1) + d[13]*m(1,1) + d[40]*m(2,1); s.d[14] = d[59]*m(0,1) + d[14]*m(1,1) + d[41]*m(2,1); s.d[15] = d[60]*m(0,1) + d[15]*m(1,1) + d[42]*m(2,1); s.d[16] = d[61]*m(0,1) + d[16]*m(1,1) + d[43]*m(2,1); s.d[17] = d[62]*m(0,1) + d[17]*m(1,1) + d[44]*m(2,1); s.d[18] = d[45]*m(0,2) + d[63]*m(1,2) + d[18]*m(2,2); s.d[19] = d[46]*m(0,2) + d[64]*m(1,2) + d[19]*m(2,2); s.d[20] = d[47]*m(0,2) + d[65]*m(1,2) + d[20]*m(2,2); s.d[21] = d[48]*m(0,2) + d[66]*m(1,2) + d[21]*m(2,2); s.d[22] = d[49]*m(0,2) + d[67]*m(1,2) + d[22]*m(2,2); s.d[23] = d[50]*m(0,2) + d[68]*m(1,2) + d[23]*m(2,2); s.d[24] = d[51]*m(0,2) + d[69]*m(1,2) + d[24]*m(2,2); s.d[25] = d[52]*m(0,2) + d[70]*m(1,2) + d[25]*m(2,2); s.d[26] = d[53]*m(0,2) + d[71]*m(1,2) + d[26]*m(2,2); s.d[27] = d[0]*m(0,1) + d[27]*m(1,1) + d[72]*m(2,1); s.d[28] = d[1]*m(0,1) + d[28]*m(1,1) + d[73]*m(2,1); s.d[29] = d[2]*m(0,1) + d[29]*m(1,1) + d[74]*m(2,1); s.d[30] = d[3]*m(0,1) + d[30]*m(1,1) + d[75]*m(2,1); s.d[31] = d[4]*m(0,1) + d[31]*m(1,1) + d[76]*m(2,1); s.d[32] = d[5]*m(0,1) + d[32]*m(1,1) + d[77]*m(2,1); s.d[33] = d[6]*m(0,1) + d[33]*m(1,1) + d[78]*m(2,1); s.d[34] = d[7]*m(0,1) + d[34]*m(1,1) + d[79]*m(2,1); s.d[35] = d[8]*m(0,1) + d[35]*m(1,1) + d[80]*m(2,1); s.d[36] = d[54]*m(0,2) + d[ 9]*m(1,2) + d[36]*m(2,2); s.d[37] = d[55]*m(0,2) + d[10]*m(1,2) + d[37]*m(2,2); s.d[38] = d[56]*m(0,2) + d[11]*m(1,2) + d[38]*m(2,2); s.d[39] = d[57]*m(0,2) + d[12]*m(1,2) + d[39]*m(2,2); s.d[40] = d[58]*m(0,2) + d[13]*m(1,2) + d[40]*m(2,2); s.d[41] = d[59]*m(0,2) + d[14]*m(1,2) + d[41]*m(2,2); s.d[42] = d[60]*m(0,2) + d[15]*m(1,2) + d[42]*m(2,2); s.d[43] = d[61]*m(0,2) + d[16]*m(1,2) + d[43]*m(2,2); s.d[44] = d[62]*m(0,2) + d[17]*m(1,2) + d[44]*m(2,2); s.d[45] = d[45]*m(0,0) + d[63]*m(1,0) + d[18]*m(2,0); s.d[46] = d[46]*m(0,0) + d[64]*m(1,0) + d[19]*m(2,0); s.d[47] = d[47]*m(0,0) + d[65]*m(1,0) + d[20]*m(2,0); s.d[48] = d[48]*m(0,0) + d[66]*m(1,0) + d[21]*m(2,0); s.d[49] = d[49]*m(0,0) + d[67]*m(1,0) + d[22]*m(2,0); s.d[50] = d[50]*m(0,0) + d[68]*m(1,0) + d[23]*m(2,0); s.d[51] = d[51]*m(0,0) + d[69]*m(1,0) + d[24]*m(2,0); s.d[52] = d[52]*m(0,0) + d[70]*m(1,0) + d[25]*m(2,0); s.d[53] = d[53]*m(0,0) + d[71]*m(1,0) + d[26]*m(2,0); s.d[54] = d[54]*m(0,0) + d[ 9]*m(1,0) + d[36]*m(2,0); s.d[55] = d[55]*m(0,0) + d[10]*m(1,0) + d[37]*m(2,0); s.d[56] = d[56]*m(0,0) + d[11]*m(1,0) + d[38]*m(2,0); s.d[57] = d[57]*m(0,0) + d[12]*m(1,0) + d[39]*m(2,0); s.d[58] = d[58]*m(0,0) + d[13]*m(1,0) + d[40]*m(2,0); s.d[59] = d[59]*m(0,0) + d[14]*m(1,0) + d[41]*m(2,0); s.d[60] = d[60]*m(0,0) + d[15]*m(1,0) + d[42]*m(2,0); s.d[61] = d[61]*m(0,0) + d[16]*m(1,0) + d[43]*m(2,0); s.d[62] = d[62]*m(0,0) + d[17]*m(1,0) + d[44]*m(2,0); s.d[63] = d[45]*m(0,1) + d[63]*m(1,1) + d[18]*m(2,1); s.d[64] = d[46]*m(0,1) + d[64]*m(1,1) + d[19]*m(2,1); s.d[65] = d[47]*m(0,1) + d[65]*m(1,1) + d[20]*m(2,1); s.d[66] = d[48]*m(0,1) + d[66]*m(1,1) + d[21]*m(2,1); s.d[67] = d[49]*m(0,1) + d[67]*m(1,1) + d[22]*m(2,1); s.d[68] = d[50]*m(0,1) + d[68]*m(1,1) + d[23]*m(2,1); s.d[69] = d[51]*m(0,1) + d[69]*m(1,1) + d[24]*m(2,1); s.d[70] = d[52]*m(0,1) + d[70]*m(1,1) + d[25]*m(2,1); s.d[71] = d[53]*m(0,1) + d[71]*m(1,1) + d[26]*m(2,1); s.d[72] = d[0]*m(0,2) + d[27]*m(1,2) + d[72]*m(2,2); s.d[73] = d[1]*m(0,2) + d[28]*m(1,2) + d[73]*m(2,2); s.d[74] = d[2]*m(0,2) + d[29]*m(1,2) + d[74]*m(2,2); s.d[75] = d[3]*m(0,2) + d[30]*m(1,2) + d[75]*m(2,2); s.d[76] = d[4]*m(0,2) + d[31]*m(1,2) + d[76]*m(2,2); s.d[77] = d[5]*m(0,2) + d[32]*m(1,2) + d[77]*m(2,2); s.d[78] = d[6]*m(0,2) + d[33]*m(1,2) + d[78]*m(2,2); s.d[79] = d[7]*m(0,2) + d[34]*m(1,2) + d[79]*m(2,2); s.d[80] = d[8]*m(0,2) + d[35]*m(1,2) + d[80]*m(2,2); return s; } //----------------------------------------------------------------------------- // trace // C.tr() = I:C:I inline double tens4d::tr() const { return (d[0]+d[1]+d[2]+d[9]+d[10]+d[11]+d[18]+d[19]+d[20]); } //----------------------------------------------------------------------------- // intialize to zero inline void tens4d::zero() { d[ 0] = d[ 1] = d[ 2] = d[ 3] = d[ 4] = d[ 5] = d[ 6] = d[ 7] = d[ 8] = 0; d[ 9] = d[10] = d[11] = d[12] = d[13] = d[14] = d[15] = d[16] = d[17] = 0; d[18] = d[19] = d[20] = d[21] = d[22] = d[23] = d[24] = d[25] = d[26] = 0; d[27] = d[28] = d[29] = d[30] = d[31] = d[32] = d[33] = d[34] = d[35] = 0; d[36] = d[37] = d[38] = d[39] = d[40] = d[41] = d[42] = d[43] = d[44] = 0; d[45] = d[46] = d[47] = d[48] = d[49] = d[50] = d[51] = d[52] = d[53] = 0; d[54] = d[55] = d[56] = d[57] = d[58] = d[59] = d[60] = d[61] = d[62] = 0; d[63] = d[64] = d[65] = d[66] = d[67] = d[68] = d[69] = d[70] = d[71] = 0; d[72] = d[73] = d[74] = d[75] = d[76] = d[77] = d[78] = d[79] = d[80] = 0; } //----------------------------------------------------------------------------- // extract 9x9 matrix inline void tens4d::extract(double D[9][9]) { D[0][0] = d[ 0]; D[0][3] = d[27]; D[0][6] = d[54]; D[1][0] = d[ 1]; D[1][3] = d[28]; D[1][6] = d[55]; D[2][0] = d[ 2]; D[2][3] = d[29]; D[2][6] = d[56]; D[3][0] = d[ 3]; D[3][3] = d[30]; D[3][6] = d[57]; D[4][0] = d[ 4]; D[4][3] = d[31]; D[4][6] = d[58]; D[5][0] = d[ 5]; D[5][3] = d[32]; D[5][6] = d[59]; D[6][0] = d[ 6]; D[6][3] = d[33]; D[6][6] = d[60]; D[7][0] = d[ 7]; D[7][3] = d[34]; D[7][6] = d[61]; D[8][0] = d[ 8]; D[8][3] = d[35]; D[8][6] = d[62]; D[0][1] = d[ 9]; D[0][4] = d[36]; D[0][7] = d[63]; D[1][1] = d[10]; D[1][4] = d[37]; D[1][7] = d[64]; D[2][1] = d[11]; D[2][4] = d[38]; D[2][7] = d[65]; D[3][1] = d[12]; D[3][4] = d[39]; D[3][7] = d[66]; D[4][1] = d[13]; D[4][4] = d[40]; D[4][7] = d[67]; D[5][1] = d[14]; D[5][4] = d[41]; D[5][7] = d[68]; D[6][1] = d[15]; D[6][4] = d[42]; D[6][7] = d[69]; D[7][1] = d[16]; D[7][4] = d[43]; D[7][7] = d[70]; D[8][1] = d[17]; D[8][4] = d[44]; D[8][7] = d[71]; D[0][2] = d[18]; D[0][5] = d[45]; D[0][8] = d[72]; D[1][2] = d[19]; D[1][5] = d[46]; D[1][8] = d[73]; D[2][2] = d[20]; D[2][5] = d[47]; D[2][8] = d[74]; D[3][2] = d[21]; D[3][5] = d[48]; D[3][8] = d[75]; D[4][2] = d[22]; D[4][5] = d[49]; D[4][8] = d[76]; D[5][2] = d[23]; D[5][5] = d[50]; D[5][8] = d[77]; D[6][2] = d[24]; D[6][5] = d[51]; D[6][8] = d[78]; D[7][2] = d[25]; D[7][5] = d[52]; D[7][8] = d[79]; D[8][2] = d[26]; D[8][5] = d[53]; D[8][8] = d[80]; } //----------------------------------------------------------------------------- // compute the super symmetric (major and minor symmetric) component of the tensor // Sijkl = (1/8)*(Cijkl + Cjikl + Cijlk + Cjilk + Cklij + Clkij + Cklji + Clkji) inline tens4ds tens4d::supersymm() const { tens4ds s; s.d[ 0] = d[0]; s.d[ 1] = (d[9]+d[1])/2; s.d[ 2] = d[10]; s.d[ 3] = (d[18]+d[2])/2; s.d[ 4] = (d[19]+d[11])/2; s.d[ 5] = d[20]; s.d[ 6] = (d[3] + d[6] + d[27] + d[54])/4; s.d[ 7] = (d[12] + d[15] + d[28] + d[55])/4; s.d[ 8] = (d[21] + d[24] + d[29] + d[56])/4; s.d[ 9] = (d[30] + d[33] + d[57] + d[60])/4; s.d[10] = (d[4] + d[7] + d[36] + d[63])/4; s.d[11] = (d[13] + d[16] + d[37] + d[64])/4; s.d[12] = (d[22] + d[25] + d[38] + d[65])/4; s.d[13] = (d[31] + d[34] + d[39] + d[42] + d[58] + d[61] + d[66] + d[69])/8; s.d[14] = (d[40] + d[43] + d[67] + d[70])/4; s.d[15] = (d[5] + d[8] + d[45] + d[72])/4; s.d[16] = (d[14] + d[17] + d[46] + d[73])/4; s.d[17] = (d[23] + d[26] + d[47] + d[74])/4; s.d[18] = (d[32] + d[35] + d[48] + d[51] + d[59] + d[62] + d[75] + d[78])/8; s.d[19] = (d[41] + d[44] + d[49] + d[52] + d[68] + d[71] + d[76] + d[79])/8; s.d[20] = (d[50] + d[53] + d[77] + d[80])/4; return s; } //----------------------------------------------------------------------------- // compute the major transpose of the tensor // Sijkl -> Sklij inline tens4d tens4d::transpose() const { tens4d s; s.d[ 0] = d[ 0]; s.d[ 6] = d[54]; s.d[ 5] = d[45]; s.d[27] = d[ 3]; s.d[33] = d[57]; s.d[32] = d[48]; s.d[72] = d[ 8]; s.d[78] = d[62]; s.d[77] = d[53]; s.d[54] = d[ 6]; s.d[60] = d[60]; s.d[59] = d[51]; s.d[ 9] = d[ 1]; s.d[15] = d[55]; s.d[14] = d[46]; s.d[36] = d[ 4]; s.d[42] = d[58]; s.d[41] = d[49]; s.d[45] = d[ 5]; s.d[51] = d[59]; s.d[50] = d[50]; s.d[63] = d[ 7]; s.d[69] = d[61]; s.d[68] = d[52]; s.d[18] = d[ 2]; s.d[24] = d[56]; s.d[23] = d[47]; s.d[ 3] = d[27]; s.d[ 1] = d[ 9]; s.d[ 7] = d[63]; s.d[30] = d[30]; s.d[28] = d[12]; s.d[34] = d[66]; s.d[75] = d[35]; s.d[73] = d[17]; s.d[79] = d[71]; s.d[57] = d[33]; s.d[55] = d[15]; s.d[61] = d[69]; s.d[12] = d[28]; s.d[10] = d[10]; s.d[16] = d[64]; s.d[39] = d[31]; s.d[37] = d[13]; s.d[43] = d[67]; s.d[48] = d[32]; s.d[46] = d[14]; s.d[52] = d[68]; s.d[66] = d[34]; s.d[64] = d[16]; s.d[70] = d[70]; s.d[21] = d[29]; s.d[19] = d[11]; s.d[25] = d[65]; s.d[ 8] = d[72]; s.d[ 4] = d[36]; s.d[ 2] = d[18]; s.d[35] = d[75]; s.d[31] = d[39]; s.d[29] = d[21]; s.d[80] = d[80]; s.d[76] = d[44]; s.d[74] = d[26]; s.d[62] = d[78]; s.d[58] = d[42]; s.d[56] = d[24]; s.d[17] = d[73]; s.d[13] = d[37]; s.d[11] = d[19]; s.d[44] = d[76]; s.d[40] = d[40]; s.d[38] = d[22]; s.d[53] = d[77]; s.d[49] = d[41]; s.d[47] = d[23]; s.d[71] = d[79]; s.d[67] = d[43]; s.d[65] = d[25]; s.d[26] = d[74]; s.d[22] = d[38]; s.d[20] = d[20]; return s; } //----------------------------------------------------------------------------- // compute the left transpose of the tensor // Sijkl -> Sjikl inline tens4d tens4d::left_transpose() const { tens4d s; s.d[ 0] = d[ 0]; s.d[ 6] = d[ 3]; s.d[ 5] = d[ 8]; s.d[27] = d[27]; s.d[33] = d[30]; s.d[32] = d[35]; s.d[72] = d[72]; s.d[78] = d[75]; s.d[77] = d[80]; s.d[54] = d[54]; s.d[60] = d[57]; s.d[59] = d[62]; s.d[ 9] = d[ 9]; s.d[15] = d[12]; s.d[14] = d[17]; s.d[36] = d[36]; s.d[42] = d[39]; s.d[41] = d[44]; s.d[45] = d[45]; s.d[51] = d[48]; s.d[50] = d[53]; s.d[63] = d[63]; s.d[69] = d[66]; s.d[68] = d[71]; s.d[18] = d[18]; s.d[24] = d[21]; s.d[23] = d[26]; s.d[ 3] = d[ 6]; s.d[ 1] = d[ 1]; s.d[ 7] = d[ 4]; s.d[30] = d[33]; s.d[28] = d[28]; s.d[34] = d[31]; s.d[75] = d[78]; s.d[73] = d[73]; s.d[79] = d[76]; s.d[57] = d[60]; s.d[55] = d[55]; s.d[61] = d[58]; s.d[12] = d[15]; s.d[10] = d[10]; s.d[16] = d[13]; s.d[39] = d[42]; s.d[37] = d[37]; s.d[43] = d[40]; s.d[48] = d[51]; s.d[46] = d[46]; s.d[52] = d[49]; s.d[66] = d[69]; s.d[64] = d[64]; s.d[70] = d[67]; s.d[21] = d[24]; s.d[19] = d[19]; s.d[25] = d[22]; s.d[ 8] = d[ 5]; s.d[ 4] = d[ 7]; s.d[ 2] = d[ 2]; s.d[35] = d[32]; s.d[31] = d[34]; s.d[29] = d[29]; s.d[80] = d[77]; s.d[76] = d[79]; s.d[74] = d[74]; s.d[62] = d[59]; s.d[58] = d[61]; s.d[56] = d[56]; s.d[17] = d[14]; s.d[13] = d[16]; s.d[11] = d[11]; s.d[44] = d[41]; s.d[40] = d[43]; s.d[38] = d[38]; s.d[53] = d[50]; s.d[49] = d[52]; s.d[47] = d[47]; s.d[71] = d[68]; s.d[67] = d[70]; s.d[65] = d[65]; s.d[26] = d[23]; s.d[22] = d[25]; s.d[20] = d[20]; return s; } //----------------------------------------------------------------------------- // compute the right transpose of the tensor // Sijkl -> Sijlk inline tens4d tens4d::right_transpose() const { tens4d s; s.d[ 0] = d[ 0]; s.d[ 6] = d[ 6]; s.d[ 5] = d[ 5]; s.d[27] = d[54]; s.d[33] = d[60]; s.d[32] = d[59]; s.d[72] = d[45]; s.d[78] = d[51]; s.d[77] = d[50]; s.d[54] = d[27]; s.d[60] = d[33]; s.d[59] = d[32]; s.d[ 9] = d[ 9]; s.d[15] = d[15]; s.d[14] = d[14]; s.d[36] = d[63]; s.d[42] = d[69]; s.d[41] = d[68]; s.d[45] = d[72]; s.d[51] = d[78]; s.d[50] = d[77]; s.d[63] = d[36]; s.d[69] = d[42]; s.d[68] = d[41]; s.d[18] = d[18]; s.d[24] = d[24]; s.d[23] = d[23]; s.d[ 3] = d[ 3]; s.d[ 1] = d[ 1]; s.d[ 7] = d[ 7]; s.d[30] = d[57]; s.d[28] = d[55]; s.d[34] = d[61]; s.d[75] = d[48]; s.d[73] = d[46]; s.d[79] = d[52]; s.d[57] = d[30]; s.d[55] = d[28]; s.d[61] = d[34]; s.d[12] = d[12]; s.d[10] = d[10]; s.d[16] = d[16]; s.d[39] = d[66]; s.d[37] = d[64]; s.d[43] = d[70]; s.d[48] = d[75]; s.d[46] = d[73]; s.d[52] = d[79]; s.d[66] = d[39]; s.d[64] = d[37]; s.d[70] = d[43]; s.d[21] = d[21]; s.d[19] = d[19]; s.d[25] = d[25]; s.d[ 8] = d[ 8]; s.d[ 4] = d[ 4]; s.d[ 2] = d[ 2]; s.d[35] = d[62]; s.d[31] = d[58]; s.d[29] = d[56]; s.d[80] = d[53]; s.d[76] = d[49]; s.d[74] = d[47]; s.d[62] = d[35]; s.d[58] = d[31]; s.d[56] = d[29]; s.d[17] = d[17]; s.d[13] = d[13]; s.d[11] = d[11]; s.d[44] = d[71]; s.d[40] = d[67]; s.d[38] = d[65]; s.d[53] = d[80]; s.d[49] = d[76]; s.d[47] = d[74]; s.d[71] = d[44]; s.d[67] = d[40]; s.d[65] = d[38]; s.d[26] = d[26]; s.d[22] = d[22]; s.d[20] = d[20]; return s; } //----------------------------------------------------------------------------- // (a dyad1 b)_ijkl = a_ij b_kl inline tens4d dyad1(const mat3d& a, const mat3d& b) { tens4d c; c.d[ 0] = a(0,0)*b(0,0); c.d[27] = a(0,0)*b(0,1); c.d[72] = a(0,0)*b(0,2); c.d[54] = a(0,0)*b(1,0); c.d[ 9] = a(0,0)*b(1,1); c.d[36] = a(0,0)*b(1,2); c.d[45] = a(0,0)*b(2,0); c.d[63] = a(0,0)*b(2,1); c.d[18] = a(0,0)*b(2,2); c.d[ 3] = a(0,1)*b(0,0); c.d[30] = a(0,1)*b(0,1); c.d[75] = a(0,1)*b(0,2); c.d[57] = a(0,1)*b(1,0); c.d[12] = a(0,1)*b(1,1); c.d[39] = a(0,1)*b(1,2); c.d[48] = a(0,1)*b(2,0); c.d[66] = a(0,1)*b(2,1); c.d[21] = a(0,1)*b(2,2); c.d[ 8] = a(0,2)*b(0,0); c.d[35] = a(0,2)*b(0,1); c.d[80] = a(0,2)*b(0,2); c.d[62] = a(0,2)*b(1,0); c.d[17] = a(0,2)*b(1,1); c.d[44] = a(0,2)*b(1,2); c.d[53] = a(0,2)*b(2,0); c.d[71] = a(0,2)*b(2,1); c.d[26] = a(0,2)*b(2,2); c.d[6] = a(1,0)*b(0,0); c.d[33] = a(1,0)*b(0,1); c.d[78] = a(1,0)*b(0,2); c.d[60] = a(1,0)*b(1,0); c.d[15] = a(1,0)*b(1,1); c.d[42] = a(1,0)*b(1,2); c.d[51] = a(1,0)*b(2,0); c.d[69] = a(1,0)*b(2,1); c.d[24] = a(1,0)*b(2,2); c.d[ 1] = a(1,1)*b(0,0); c.d[28] = a(1,1)*b(0,1); c.d[73] = a(1,1)*b(0,2); c.d[55] = a(1,1)*b(1,0); c.d[10] = a(1,1)*b(1,1); c.d[37] = a(1,1)*b(1,2); c.d[46] = a(1,1)*b(2,0); c.d[64] = a(1,1)*b(2,1); c.d[19] = a(1,1)*b(2,2); c.d[ 4] = a(1,2)*b(0,0); c.d[31] = a(1,2)*b(0,1); c.d[76] = a(1,2)*b(0,2); c.d[58] = a(1,2)*b(1,0); c.d[13] = a(1,2)*b(1,1); c.d[40] = a(1,2)*b(1,2); c.d[49] = a(1,2)*b(2,0); c.d[67] = a(1,2)*b(2,1); c.d[22] = a(1,2)*b(2,2); c.d[ 5] = a(2,0)*b(0,0); c.d[32] = a(2,0)*b(0,1); c.d[77] = a(2,0)*b(0,2); c.d[59] = a(2,0)*b(1,0); c.d[14] = a(2,0)*b(1,1); c.d[41] = a(2,0)*b(1,2); c.d[50] = a(2,0)*b(2,0); c.d[68] = a(2,0)*b(2,1); c.d[23] = a(2,0)*b(2,2); c.d[ 7] = a(2,1)*b(0,0); c.d[34] = a(2,1)*b(0,1); c.d[79] = a(2,1)*b(0,2); c.d[61] = a(2,1)*b(1,0); c.d[16] = a(2,1)*b(1,1); c.d[43] = a(2,1)*b(1,2); c.d[52] = a(2,1)*b(2,0); c.d[70] = a(2,1)*b(2,1); c.d[25] = a(2,1)*b(2,2); c.d[ 2] = a(2,2)*b(0,0); c.d[29] = a(2,2)*b(0,1); c.d[74] = a(2,2)*b(0,2); c.d[56] = a(2,2)*b(1,0); c.d[11] = a(2,2)*b(1,1); c.d[38] = a(2,2)*b(1,2); c.d[47] = a(2,2)*b(2,0); c.d[65] = a(2,2)*b(2,1); c.d[20] = a(2,2)*b(2,2); return c; } //----------------------------------------------------------------------------- // (a dyad2 b)_ijkl = a_ik b_jl inline tens4d dyad2(const mat3d& a, const mat3d& b) { tens4d c; c.d[ 0] = a(0,0)*b(0,0); c.d[27] = a(0,0)*b(0,1); c.d[72] = a(0,0)*b(0,2); c.d[54] = a(0,1)*b(0,0); c.d[ 9] = a(0,1)*b(0,1); c.d[36] = a(0,1)*b(0,2); c.d[45] = a(0,2)*b(0,0); c.d[63] = a(0,2)*b(0,1); c.d[18] = a(0,2)*b(0,2); c.d[ 3] = a(0,0)*b(1,0); c.d[30] = a(0,0)*b(1,1); c.d[75] = a(0,0)*b(1,2); c.d[57] = a(0,1)*b(1,0); c.d[12] = a(0,1)*b(1,1); c.d[39] = a(0,1)*b(1,2); c.d[48] = a(0,2)*b(1,0); c.d[66] = a(0,2)*b(1,1); c.d[21] = a(0,2)*b(1,2); c.d[ 8] = a(0,0)*b(2,0); c.d[35] = a(0,0)*b(2,1); c.d[80] = a(0,0)*b(2,2); c.d[62] = a(0,1)*b(2,0); c.d[17] = a(0,1)*b(2,1); c.d[44] = a(0,1)*b(2,2); c.d[53] = a(0,2)*b(2,0); c.d[71] = a(0,2)*b(2,1); c.d[26] = a(0,2)*b(2,2); c.d[ 6] = a(1,0)*b(0,0); c.d[33] = a(1,0)*b(0,1); c.d[78] = a(1,0)*b(0,2); c.d[60] = a(1,1)*b(0,0); c.d[15] = a(1,1)*b(0,1); c.d[42] = a(1,1)*b(0,2); c.d[51] = a(1,2)*b(0,0); c.d[69] = a(1,2)*b(0,1); c.d[24] = a(1,2)*b(0,2); c.d[ 1] = a(1,0)*b(1,0); c.d[28] = a(1,0)*b(1,1); c.d[73] = a(1,0)*b(1,2); c.d[55] = a(1,1)*b(1,0); c.d[10] = a(1,1)*b(1,1); c.d[37] = a(1,1)*b(1,2); c.d[46] = a(1,2)*b(1,0); c.d[64] = a(1,2)*b(1,1); c.d[19] = a(1,2)*b(1,2); c.d[ 4] = a(1,0)*b(2,0); c.d[31] = a(1,0)*b(2,1); c.d[76] = a(1,0)*b(2,2); c.d[58] = a(1,1)*b(2,0); c.d[13] = a(1,1)*b(2,1); c.d[40] = a(1,1)*b(2,2); c.d[49] = a(1,2)*b(2,0); c.d[67] = a(1,2)*b(2,1); c.d[22] = a(1,2)*b(2,2); c.d[ 5] = a(2,0)*b(0,0); c.d[32] = a(2,0)*b(0,1); c.d[77] = a(2,0)*b(0,2); c.d[59] = a(2,1)*b(0,0); c.d[14] = a(2,1)*b(0,1); c.d[41] = a(2,1)*b(0,2); c.d[50] = a(2,2)*b(0,0); c.d[68] = a(2,2)*b(0,1); c.d[23] = a(2,2)*b(0,2); c.d[ 7] = a(2,0)*b(1,0); c.d[34] = a(2,0)*b(1,1); c.d[79] = a(2,0)*b(1,2); c.d[61] = a(2,1)*b(1,0); c.d[16] = a(2,1)*b(1,1); c.d[43] = a(2,1)*b(1,2); c.d[52] = a(2,2)*b(1,0); c.d[70] = a(2,2)*b(1,1); c.d[25] = a(2,2)*b(1,2); c.d[ 2] = a(2,0)*b(2,0); c.d[29] = a(2,0)*b(2,1); c.d[74] = a(2,0)*b(2,2); c.d[56] = a(2,1)*b(2,0); c.d[11] = a(2,1)*b(2,1); c.d[38] = a(2,1)*b(2,2); c.d[47] = a(2,2)*b(2,0); c.d[65] = a(2,2)*b(2,1); c.d[20] = a(2,2)*b(2,2); return c; } //----------------------------------------------------------------------------- // (a dyad3 b)_ijkl = a_il b_jk inline tens4d dyad3(const mat3d& a, const mat3d& b) { tens4d c; c.d[ 0] = a(0,0)*b(0,0); c.d[27] = a(0,1)*b(0,0); c.d[72] = a(0,2)*b(0,0); c.d[54] = a(0,0)*b(0,1); c.d[ 9] = a(0,1)*b(0,1); c.d[36] = a(0,2)*b(0,1); c.d[45] = a(0,0)*b(0,2); c.d[63] = a(0,1)*b(0,2); c.d[18] = a(0,2)*b(0,2); c.d[ 3] = a(0,0)*b(1,0); c.d[30] = a(0,1)*b(1,0); c.d[75] = a(0,2)*b(1,0); c.d[57] = a(0,0)*b(1,1); c.d[12] = a(0,1)*b(1,1); c.d[39] = a(0,2)*b(1,1); c.d[48] = a(0,0)*b(1,2); c.d[66] = a(0,1)*b(1,2); c.d[21] = a(0,2)*b(1,2); c.d[ 8] = a(0,0)*b(2,0); c.d[35] = a(0,1)*b(2,0); c.d[80] = a(0,2)*b(2,0); c.d[62] = a(0,0)*b(2,1); c.d[17] = a(0,1)*b(2,1); c.d[44] = a(0,2)*b(2,1); c.d[53] = a(0,0)*b(2,2); c.d[71] = a(0,1)*b(2,2); c.d[26] = a(0,2)*b(2,2); c.d[ 6] = a(1,0)*b(0,0); c.d[33] = a(1,1)*b(0,0); c.d[78] = a(1,2)*b(0,0); c.d[60] = a(1,0)*b(0,1); c.d[15] = a(1,1)*b(0,1); c.d[42] = a(1,2)*b(0,1); c.d[51] = a(1,0)*b(0,2); c.d[69] = a(1,1)*b(0,2); c.d[24] = a(1,2)*b(0,2); c.d[ 1] = a(1,0)*b(1,0); c.d[28] = a(1,1)*b(1,0); c.d[73] = a(1,2)*b(1,0); c.d[55] = a(1,0)*b(1,1); c.d[10] = a(1,1)*b(1,1); c.d[37] = a(1,2)*b(1,1); c.d[46] = a(1,0)*b(1,2); c.d[64] = a(1,1)*b(1,2); c.d[19] = a(1,2)*b(1,2); c.d[ 4] = a(1,0)*b(2,0); c.d[31] = a(1,1)*b(2,0); c.d[76] = a(1,2)*b(2,0); c.d[58] = a(1,0)*b(2,1); c.d[13] = a(1,1)*b(2,1); c.d[40] = a(1,2)*b(2,1); c.d[49] = a(1,0)*b(2,2); c.d[67] = a(1,1)*b(2,2); c.d[22] = a(1,2)*b(2,2); c.d[ 5] = a(2,0)*b(0,0); c.d[32] = a(2,1)*b(0,0); c.d[77] = a(2,2)*b(0,0); c.d[59] = a(2,0)*b(0,1); c.d[14] = a(2,1)*b(0,1); c.d[41] = a(2,2)*b(0,1); c.d[50] = a(2,0)*b(0,2); c.d[68] = a(2,1)*b(0,2); c.d[23] = a(2,2)*b(0,2); c.d[ 7] = a(2,0)*b(1,0); c.d[34] = a(2,1)*b(1,0); c.d[79] = a(2,2)*b(1,0); c.d[61] = a(2,0)*b(1,1); c.d[16] = a(2,1)*b(1,1); c.d[43] = a(2,2)*b(1,1); c.d[52] = a(2,0)*b(1,2); c.d[70] = a(2,1)*b(1,2); c.d[25] = a(2,2)*b(1,2); c.d[ 2] = a(2,0)*b(2,0); c.d[29] = a(2,1)*b(2,0); c.d[74] = a(2,2)*b(2,0); c.d[56] = a(2,0)*b(2,1); c.d[11] = a(2,1)*b(2,1); c.d[38] = a(2,2)*b(2,1); c.d[47] = a(2,0)*b(2,2); c.d[65] = a(2,1)*b(2,2); c.d[20] = a(2,2)*b(2,2); return c; } //----------------------------------------------------------------------------- // (a ddot b)_ijkl = a_ijmn b_mnkl inline tens4d ddot(const tens4d& a, const tens4d& b) { tens4d c; c.d[0] = a.d[0]*b.d[0] + a.d[9]*b.d[1] + a.d[18]*b.d[2] + a.d[27]*b.d[3] + a.d[36]*b.d[4] + a.d[45]*b.d[5] + a.d[54]*b.d[6] + a.d[63]*b.d[7] + a.d[72]*b.d[8]; c.d[1] = a.d[0]*b.d[9] + a.d[9]*b.d[10] + a.d[18]*b.d[11] + a.d[27]*b.d[12] + a.d[36]*b.d[13] + a.d[45]*b.d[14] + a.d[54]*b.d[15] + a.d[63]*b.d[16] + a.d[72]*b.d[17]; c.d[2] = a.d[0]*b.d[18] + a.d[9]*b.d[19] + a.d[18]*b.d[20] + a.d[27]*b.d[21] + a.d[36]*b.d[22] + a.d[45]*b.d[23] + a.d[54]*b.d[24] + a.d[63]*b.d[25] + a.d[72]*b.d[26]; c.d[3] = a.d[0]*b.d[27] + a.d[9]*b.d[28] + a.d[18]*b.d[29] + a.d[27]*b.d[30] + a.d[36]*b.d[31] + a.d[45]*b.d[32] + a.d[54]*b.d[33] + a.d[63]*b.d[34] + a.d[72]*b.d[35]; c.d[4] = a.d[0]*b.d[36] + a.d[9]*b.d[37] + a.d[18]*b.d[38] + a.d[27]*b.d[39] + a.d[36]*b.d[40] + a.d[45]*b.d[41] + a.d[54]*b.d[42] + a.d[63]*b.d[43] + a.d[72]*b.d[44]; c.d[5] = a.d[0]*b.d[45] + a.d[9]*b.d[46] + a.d[18]*b.d[47] + a.d[27]*b.d[48] + a.d[36]*b.d[49] + a.d[45]*b.d[50] + a.d[54]*b.d[51] + a.d[63]*b.d[52] + a.d[72]*b.d[53]; c.d[6] = a.d[0]*b.d[54] + a.d[9]*b.d[55] + a.d[18]*b.d[56] + a.d[27]*b.d[57] + a.d[36]*b.d[58] + a.d[45]*b.d[59] + a.d[54]*b.d[60] + a.d[63]*b.d[61] + a.d[72]*b.d[62]; c.d[7] = a.d[0]*b.d[63] + a.d[9]*b.d[64] + a.d[18]*b.d[65] + a.d[27]*b.d[66] + a.d[36]*b.d[67] + a.d[45]*b.d[68] + a.d[54]*b.d[69] + a.d[63]*b.d[70] + a.d[72]*b.d[71]; c.d[8] = a.d[0]*b.d[72] + a.d[9]*b.d[73] + a.d[18]*b.d[74] + a.d[27]*b.d[75] + a.d[36]*b.d[76] + a.d[45]*b.d[77] + a.d[54]*b.d[78] + a.d[63]*b.d[79] + a.d[72]*b.d[80]; c.d[9] = a.d[1]*b.d[0] + a.d[10]*b.d[1] + a.d[19]*b.d[2] + a.d[28]*b.d[3] + a.d[37]*b.d[4] + a.d[46]*b.d[5] + a.d[55]*b.d[6] + a.d[64]*b.d[7] + a.d[73]*b.d[8]; c.d[10] = a.d[1]*b.d[9] + a.d[10]*b.d[10] + a.d[19]*b.d[11] + a.d[28]*b.d[12] + a.d[37]*b.d[13] + a.d[46]*b.d[14] + a.d[55]*b.d[15] + a.d[64]*b.d[16] + a.d[73]*b.d[17]; c.d[11] = a.d[1]*b.d[18] + a.d[10]*b.d[19] + a.d[19]*b.d[20] + a.d[28]*b.d[21] + a.d[37]*b.d[22] + a.d[46]*b.d[23] + a.d[55]*b.d[24] + a.d[64]*b.d[25] + a.d[73]*b.d[26]; c.d[12] = a.d[1]*b.d[27] + a.d[10]*b.d[28] + a.d[19]*b.d[29] + a.d[28]*b.d[30] + a.d[37]*b.d[31] + a.d[46]*b.d[32] + a.d[55]*b.d[33] + a.d[64]*b.d[34] + a.d[73]*b.d[35]; c.d[13] = a.d[1]*b.d[36] + a.d[10]*b.d[37] + a.d[19]*b.d[38] + a.d[28]*b.d[39] + a.d[37]*b.d[40] + a.d[46]*b.d[41] + a.d[55]*b.d[42] + a.d[64]*b.d[43] + a.d[73]*b.d[44]; c.d[14] = a.d[1]*b.d[45] + a.d[10]*b.d[46] + a.d[19]*b.d[47] + a.d[28]*b.d[48] + a.d[37]*b.d[49] + a.d[46]*b.d[50] + a.d[55]*b.d[51] + a.d[64]*b.d[52] + a.d[73]*b.d[53]; c.d[15] = a.d[1]*b.d[54] + a.d[10]*b.d[55] + a.d[19]*b.d[56] + a.d[28]*b.d[57] + a.d[37]*b.d[58] + a.d[46]*b.d[59] + a.d[55]*b.d[60] + a.d[64]*b.d[61] + a.d[73]*b.d[62]; c.d[16] = a.d[1]*b.d[63] + a.d[10]*b.d[64] + a.d[19]*b.d[65] + a.d[28]*b.d[66] + a.d[37]*b.d[67] + a.d[46]*b.d[68] + a.d[55]*b.d[69] + a.d[64]*b.d[70] + a.d[73]*b.d[71]; c.d[17] = a.d[1]*b.d[72] + a.d[10]*b.d[73] + a.d[19]*b.d[74] + a.d[28]*b.d[75] + a.d[37]*b.d[76] + a.d[46]*b.d[77] + a.d[55]*b.d[78] + a.d[64]*b.d[79] + a.d[73]*b.d[80]; c.d[18] = a.d[2]*b.d[0] + a.d[11]*b.d[1] + a.d[20]*b.d[2] + a.d[29]*b.d[3] + a.d[38]*b.d[4] + a.d[47]*b.d[5] + a.d[56]*b.d[6] + a.d[65]*b.d[7] + a.d[74]*b.d[8]; c.d[19] = a.d[2]*b.d[9] + a.d[11]*b.d[10] + a.d[20]*b.d[11] + a.d[29]*b.d[12] + a.d[38]*b.d[13] + a.d[47]*b.d[14] + a.d[56]*b.d[15] + a.d[65]*b.d[16] + a.d[74]*b.d[17]; c.d[20] = a.d[2]*b.d[18] + a.d[11]*b.d[19] + a.d[20]*b.d[20] + a.d[29]*b.d[21] + a.d[38]*b.d[22] + a.d[47]*b.d[23] + a.d[56]*b.d[24] + a.d[65]*b.d[25] + a.d[74]*b.d[26]; c.d[21] = a.d[2]*b.d[27] + a.d[11]*b.d[28] + a.d[20]*b.d[29] + a.d[29]*b.d[30] + a.d[38]*b.d[31] + a.d[47]*b.d[32] + a.d[56]*b.d[33] + a.d[65]*b.d[34] + a.d[74]*b.d[35]; c.d[22] = a.d[2]*b.d[36] + a.d[11]*b.d[37] + a.d[20]*b.d[38] + a.d[29]*b.d[39] + a.d[38]*b.d[40] + a.d[47]*b.d[41] + a.d[56]*b.d[42] + a.d[65]*b.d[43] + a.d[74]*b.d[44]; c.d[23] = a.d[2]*b.d[45] + a.d[11]*b.d[46] + a.d[20]*b.d[47] + a.d[29]*b.d[48] + a.d[38]*b.d[49] + a.d[47]*b.d[50] + a.d[56]*b.d[51] + a.d[65]*b.d[52] + a.d[74]*b.d[53]; c.d[24] = a.d[2]*b.d[54] + a.d[11]*b.d[55] + a.d[20]*b.d[56] + a.d[29]*b.d[57] + a.d[38]*b.d[58] + a.d[47]*b.d[59] + a.d[56]*b.d[60] + a.d[65]*b.d[61] + a.d[74]*b.d[62]; c.d[25] = a.d[2]*b.d[63] + a.d[11]*b.d[64] + a.d[20]*b.d[65] + a.d[29]*b.d[66] + a.d[38]*b.d[67] + a.d[47]*b.d[68] + a.d[56]*b.d[69] + a.d[65]*b.d[70] + a.d[74]*b.d[71]; c.d[26] = a.d[2]*b.d[72] + a.d[11]*b.d[73] + a.d[20]*b.d[74] + a.d[29]*b.d[75] + a.d[38]*b.d[76] + a.d[47]*b.d[77] + a.d[56]*b.d[78] + a.d[65]*b.d[79] + a.d[74]*b.d[80]; c.d[27] = a.d[3]*b.d[0] + a.d[12]*b.d[1] + a.d[21]*b.d[2] + a.d[30]*b.d[3] + a.d[39]*b.d[4] + a.d[48]*b.d[5] + a.d[57]*b.d[6] + a.d[66]*b.d[7] + a.d[75]*b.d[8]; c.d[28] = a.d[3]*b.d[9] + a.d[12]*b.d[10] + a.d[21]*b.d[11] + a.d[30]*b.d[12] + a.d[39]*b.d[13] + a.d[48]*b.d[14] + a.d[57]*b.d[15] + a.d[66]*b.d[16] + a.d[75]*b.d[17]; c.d[29] = a.d[3]*b.d[18] + a.d[12]*b.d[19] + a.d[21]*b.d[20] + a.d[30]*b.d[21] + a.d[39]*b.d[22] + a.d[48]*b.d[23] + a.d[57]*b.d[24] + a.d[66]*b.d[25] + a.d[75]*b.d[26]; c.d[30] = a.d[3]*b.d[27] + a.d[12]*b.d[28] + a.d[21]*b.d[29] + a.d[30]*b.d[30] + a.d[39]*b.d[31] + a.d[48]*b.d[32] + a.d[57]*b.d[33] + a.d[66]*b.d[34] + a.d[75]*b.d[35]; c.d[31] = a.d[3]*b.d[36] + a.d[12]*b.d[37] + a.d[21]*b.d[38] + a.d[30]*b.d[39] + a.d[39]*b.d[40] + a.d[48]*b.d[41] + a.d[57]*b.d[42] + a.d[66]*b.d[43] + a.d[75]*b.d[44]; c.d[32] = a.d[3]*b.d[45] + a.d[12]*b.d[46] + a.d[21]*b.d[47] + a.d[30]*b.d[48] + a.d[39]*b.d[49] + a.d[48]*b.d[50] + a.d[57]*b.d[51] + a.d[66]*b.d[52] + a.d[75]*b.d[53]; c.d[33] = a.d[3]*b.d[54] + a.d[12]*b.d[55] + a.d[21]*b.d[56] + a.d[30]*b.d[57] + a.d[39]*b.d[58] + a.d[48]*b.d[59] + a.d[57]*b.d[60] + a.d[66]*b.d[61] + a.d[75]*b.d[62]; c.d[34] = a.d[3]*b.d[63] + a.d[12]*b.d[64] + a.d[21]*b.d[65] + a.d[30]*b.d[66] + a.d[39]*b.d[67] + a.d[48]*b.d[68] + a.d[57]*b.d[69] + a.d[66]*b.d[70] + a.d[75]*b.d[71]; c.d[35] = a.d[3]*b.d[72] + a.d[12]*b.d[73] + a.d[21]*b.d[74] + a.d[30]*b.d[75] + a.d[39]*b.d[76] + a.d[48]*b.d[77] + a.d[57]*b.d[78] + a.d[66]*b.d[79] + a.d[75]*b.d[80]; c.d[36] = a.d[4]*b.d[0] + a.d[13]*b.d[1] + a.d[22]*b.d[2] + a.d[31]*b.d[3] + a.d[40]*b.d[4] + a.d[49]*b.d[5] + a.d[58]*b.d[6] + a.d[67]*b.d[7] + a.d[76]*b.d[8]; c.d[37] = a.d[4]*b.d[9] + a.d[13]*b.d[10] + a.d[22]*b.d[11] + a.d[31]*b.d[12] + a.d[40]*b.d[13] + a.d[49]*b.d[14] + a.d[58]*b.d[15] + a.d[67]*b.d[16] + a.d[76]*b.d[17]; c.d[38] = a.d[4]*b.d[18] + a.d[13]*b.d[19] + a.d[22]*b.d[20] + a.d[31]*b.d[21] + a.d[40]*b.d[22] + a.d[49]*b.d[23] + a.d[58]*b.d[24] + a.d[67]*b.d[25] + a.d[76]*b.d[26]; c.d[39] = a.d[4]*b.d[27] + a.d[13]*b.d[28] + a.d[22]*b.d[29] + a.d[31]*b.d[30] + a.d[40]*b.d[31] + a.d[49]*b.d[32] + a.d[58]*b.d[33] + a.d[67]*b.d[34] + a.d[76]*b.d[35]; c.d[40] = a.d[4]*b.d[36] + a.d[13]*b.d[37] + a.d[22]*b.d[38] + a.d[31]*b.d[39] + a.d[40]*b.d[40] + a.d[49]*b.d[41] + a.d[58]*b.d[42] + a.d[67]*b.d[43] + a.d[76]*b.d[44]; c.d[41] = a.d[4]*b.d[45] + a.d[13]*b.d[46] + a.d[22]*b.d[47] + a.d[31]*b.d[48] + a.d[40]*b.d[49] + a.d[49]*b.d[50] + a.d[58]*b.d[51] + a.d[67]*b.d[52] + a.d[76]*b.d[53]; c.d[42] = a.d[4]*b.d[54] + a.d[13]*b.d[55] + a.d[22]*b.d[56] + a.d[31]*b.d[57] + a.d[40]*b.d[58] + a.d[49]*b.d[59] + a.d[58]*b.d[60] + a.d[67]*b.d[61] + a.d[76]*b.d[62]; c.d[43] = a.d[4]*b.d[63] + a.d[13]*b.d[64] + a.d[22]*b.d[65] + a.d[31]*b.d[66] + a.d[40]*b.d[67] + a.d[49]*b.d[68] + a.d[58]*b.d[69] + a.d[67]*b.d[70] + a.d[76]*b.d[71]; c.d[44] = a.d[4]*b.d[72] + a.d[13]*b.d[73] + a.d[22]*b.d[74] + a.d[31]*b.d[75] + a.d[40]*b.d[76] + a.d[49]*b.d[77] + a.d[58]*b.d[78] + a.d[67]*b.d[79] + a.d[76]*b.d[80]; c.d[45] = a.d[5]*b.d[0] + a.d[14]*b.d[1] + a.d[23]*b.d[2] + a.d[32]*b.d[3] + a.d[41]*b.d[4] + a.d[50]*b.d[5] + a.d[59]*b.d[6] + a.d[68]*b.d[7] + a.d[77]*b.d[8]; c.d[46] = a.d[5]*b.d[9] + a.d[14]*b.d[10] + a.d[23]*b.d[11] + a.d[32]*b.d[12] + a.d[41]*b.d[13] + a.d[50]*b.d[14] + a.d[59]*b.d[15] + a.d[68]*b.d[16] + a.d[77]*b.d[17]; c.d[47] = a.d[5]*b.d[18] + a.d[14]*b.d[19] + a.d[23]*b.d[20] + a.d[32]*b.d[21] + a.d[41]*b.d[22] + a.d[50]*b.d[23] + a.d[59]*b.d[24] + a.d[68]*b.d[25] + a.d[77]*b.d[26]; c.d[48] = a.d[5]*b.d[27] + a.d[14]*b.d[28] + a.d[23]*b.d[29] + a.d[32]*b.d[30] + a.d[41]*b.d[31] + a.d[50]*b.d[32] + a.d[59]*b.d[33] + a.d[68]*b.d[34] + a.d[77]*b.d[35]; c.d[49] = a.d[5]*b.d[36] + a.d[14]*b.d[37] + a.d[23]*b.d[38] + a.d[32]*b.d[39] + a.d[41]*b.d[40] + a.d[50]*b.d[41] + a.d[59]*b.d[42] + a.d[68]*b.d[43] + a.d[77]*b.d[44]; c.d[50] = a.d[5]*b.d[45] + a.d[14]*b.d[46] + a.d[23]*b.d[47] + a.d[32]*b.d[48] + a.d[41]*b.d[49] + a.d[50]*b.d[50] + a.d[59]*b.d[51] + a.d[68]*b.d[52] + a.d[77]*b.d[53]; c.d[51] = a.d[5]*b.d[54] + a.d[14]*b.d[55] + a.d[23]*b.d[56] + a.d[32]*b.d[57] + a.d[41]*b.d[58] + a.d[50]*b.d[59] + a.d[59]*b.d[60] + a.d[68]*b.d[61] + a.d[77]*b.d[62]; c.d[52] = a.d[5]*b.d[63] + a.d[14]*b.d[64] + a.d[23]*b.d[65] + a.d[32]*b.d[66] + a.d[41]*b.d[67] + a.d[50]*b.d[68] + a.d[59]*b.d[69] + a.d[68]*b.d[70] + a.d[77]*b.d[71]; c.d[53] = a.d[5]*b.d[72] + a.d[14]*b.d[73] + a.d[23]*b.d[74] + a.d[32]*b.d[75] + a.d[41]*b.d[76] + a.d[50]*b.d[77] + a.d[59]*b.d[78] + a.d[68]*b.d[79] + a.d[77]*b.d[80]; c.d[54] = a.d[6]*b.d[0] + a.d[15]*b.d[1] + a.d[24]*b.d[2] + a.d[33]*b.d[3] + a.d[42]*b.d[4] + a.d[51]*b.d[5] + a.d[60]*b.d[6] + a.d[69]*b.d[7] + a.d[78]*b.d[8]; c.d[55] = a.d[6]*b.d[9] + a.d[15]*b.d[10] + a.d[24]*b.d[11] + a.d[33]*b.d[12] + a.d[42]*b.d[13] + a.d[51]*b.d[14] + a.d[60]*b.d[15] + a.d[69]*b.d[16] + a.d[78]*b.d[17]; c.d[56] = a.d[6]*b.d[18] + a.d[15]*b.d[19] + a.d[24]*b.d[20] + a.d[33]*b.d[21] + a.d[42]*b.d[22] + a.d[51]*b.d[23] + a.d[60]*b.d[24] + a.d[69]*b.d[25] + a.d[78]*b.d[26]; c.d[57] = a.d[6]*b.d[27] + a.d[15]*b.d[28] + a.d[24]*b.d[29] + a.d[33]*b.d[30] + a.d[42]*b.d[31] + a.d[51]*b.d[32] + a.d[60]*b.d[33] + a.d[69]*b.d[34] + a.d[78]*b.d[35]; c.d[58] = a.d[6]*b.d[36] + a.d[15]*b.d[37] + a.d[24]*b.d[38] + a.d[33]*b.d[39] + a.d[42]*b.d[40] + a.d[51]*b.d[41] + a.d[60]*b.d[42] + a.d[69]*b.d[43] + a.d[78]*b.d[44]; c.d[59] = a.d[6]*b.d[45] + a.d[15]*b.d[46] + a.d[24]*b.d[47] + a.d[33]*b.d[48] + a.d[42]*b.d[49] + a.d[51]*b.d[50] + a.d[60]*b.d[51] + a.d[69]*b.d[52] + a.d[78]*b.d[53]; c.d[60] = a.d[6]*b.d[54] + a.d[15]*b.d[55] + a.d[24]*b.d[56] + a.d[33]*b.d[57] + a.d[42]*b.d[58] + a.d[51]*b.d[59] + a.d[60]*b.d[60] + a.d[69]*b.d[61] + a.d[78]*b.d[62]; c.d[61] = a.d[6]*b.d[63] + a.d[15]*b.d[64] + a.d[24]*b.d[65] + a.d[33]*b.d[66] + a.d[42]*b.d[67] + a.d[51]*b.d[68] + a.d[60]*b.d[69] + a.d[69]*b.d[70] + a.d[78]*b.d[71]; c.d[62] = a.d[6]*b.d[72] + a.d[15]*b.d[73] + a.d[24]*b.d[74] + a.d[33]*b.d[75] + a.d[42]*b.d[76] + a.d[51]*b.d[77] + a.d[60]*b.d[78] + a.d[69]*b.d[79] + a.d[78]*b.d[80]; c.d[63] = a.d[7]*b.d[0] + a.d[16]*b.d[1] + a.d[25]*b.d[2] + a.d[34]*b.d[3] + a.d[43]*b.d[4] + a.d[52]*b.d[5] + a.d[61]*b.d[6] + a.d[70]*b.d[7] + a.d[79]*b.d[8]; c.d[64] = a.d[7]*b.d[9] + a.d[16]*b.d[10] + a.d[25]*b.d[11] + a.d[34]*b.d[12] + a.d[43]*b.d[13] + a.d[52]*b.d[14] + a.d[61]*b.d[15] + a.d[70]*b.d[16] + a.d[79]*b.d[17]; c.d[65] = a.d[7]*b.d[18] + a.d[16]*b.d[19] + a.d[25]*b.d[20] + a.d[34]*b.d[21] + a.d[43]*b.d[22] + a.d[52]*b.d[23] + a.d[61]*b.d[24] + a.d[70]*b.d[25] + a.d[79]*b.d[26]; c.d[66] = a.d[7]*b.d[27] + a.d[16]*b.d[28] + a.d[25]*b.d[29] + a.d[34]*b.d[30] + a.d[43]*b.d[31] + a.d[52]*b.d[32] + a.d[61]*b.d[33] + a.d[70]*b.d[34] + a.d[79]*b.d[35]; c.d[67] = a.d[7]*b.d[36] + a.d[16]*b.d[37] + a.d[25]*b.d[38] + a.d[34]*b.d[39] + a.d[43]*b.d[40] + a.d[52]*b.d[41] + a.d[61]*b.d[42] + a.d[70]*b.d[43] + a.d[79]*b.d[44]; c.d[68] = a.d[7]*b.d[45] + a.d[16]*b.d[46] + a.d[25]*b.d[47] + a.d[34]*b.d[48] + a.d[43]*b.d[49] + a.d[52]*b.d[50] + a.d[61]*b.d[51] + a.d[70]*b.d[52] + a.d[79]*b.d[53]; c.d[69] = a.d[7]*b.d[54] + a.d[16]*b.d[55] + a.d[25]*b.d[56] + a.d[34]*b.d[57] + a.d[43]*b.d[58] + a.d[52]*b.d[59] + a.d[61]*b.d[60] + a.d[70]*b.d[61] + a.d[79]*b.d[62]; c.d[70] = a.d[7]*b.d[63] + a.d[16]*b.d[64] + a.d[25]*b.d[65] + a.d[34]*b.d[66] + a.d[43]*b.d[67] + a.d[52]*b.d[68] + a.d[61]*b.d[69] + a.d[70]*b.d[70] + a.d[79]*b.d[71]; c.d[71] = a.d[7]*b.d[72] + a.d[16]*b.d[73] + a.d[25]*b.d[74] + a.d[34]*b.d[75] + a.d[43]*b.d[76] + a.d[52]*b.d[77] + a.d[61]*b.d[78] + a.d[70]*b.d[79] + a.d[79]*b.d[80]; c.d[72] = a.d[8]*b.d[0] + a.d[17]*b.d[1] + a.d[26]*b.d[2] + a.d[35]*b.d[3] + a.d[44]*b.d[4] + a.d[53]*b.d[5] + a.d[62]*b.d[6] + a.d[71]*b.d[7] + a.d[80]*b.d[8]; c.d[73] = a.d[8]*b.d[9] + a.d[17]*b.d[10] + a.d[26]*b.d[11] + a.d[35]*b.d[12] + a.d[44]*b.d[13] + a.d[53]*b.d[14] + a.d[62]*b.d[15] + a.d[71]*b.d[16] + a.d[80]*b.d[17]; c.d[74] = a.d[8]*b.d[18] + a.d[17]*b.d[19] + a.d[26]*b.d[20] + a.d[35]*b.d[21] + a.d[44]*b.d[22] + a.d[53]*b.d[23] + a.d[62]*b.d[24] + a.d[71]*b.d[25] + a.d[80]*b.d[26]; c.d[75] = a.d[8]*b.d[27] + a.d[17]*b.d[28] + a.d[26]*b.d[29] + a.d[35]*b.d[30] + a.d[44]*b.d[31] + a.d[53]*b.d[32] + a.d[62]*b.d[33] + a.d[71]*b.d[34] + a.d[80]*b.d[35]; c.d[76] = a.d[8]*b.d[36] + a.d[17]*b.d[37] + a.d[26]*b.d[38] + a.d[35]*b.d[39] + a.d[44]*b.d[40] + a.d[53]*b.d[41] + a.d[62]*b.d[42] + a.d[71]*b.d[43] + a.d[80]*b.d[44]; c.d[77] = a.d[8]*b.d[45] + a.d[17]*b.d[46] + a.d[26]*b.d[47] + a.d[35]*b.d[48] + a.d[44]*b.d[49] + a.d[53]*b.d[50] + a.d[62]*b.d[51] + a.d[71]*b.d[52] + a.d[80]*b.d[53]; c.d[78] = a.d[8]*b.d[54] + a.d[17]*b.d[55] + a.d[26]*b.d[56] + a.d[35]*b.d[57] + a.d[44]*b.d[58] + a.d[53]*b.d[59] + a.d[62]*b.d[60] + a.d[71]*b.d[61] + a.d[80]*b.d[62]; c.d[79] = a.d[8]*b.d[63] + a.d[17]*b.d[64] + a.d[26]*b.d[65] + a.d[35]*b.d[66] + a.d[44]*b.d[67] + a.d[53]*b.d[68] + a.d[62]*b.d[69] + a.d[71]*b.d[70] + a.d[80]*b.d[71]; c.d[80] = a.d[8]*b.d[72] + a.d[17]*b.d[73] + a.d[26]*b.d[74] + a.d[35]*b.d[75] + a.d[44]*b.d[76] + a.d[53]*b.d[77] + a.d[62]*b.d[78] + a.d[71]*b.d[79] + a.d[80]*b.d[80]; return c; } //----------------------------------------------------------------------------- // (a ddot b)_ijkl = a_ijmn b_mnkl where b is super-symmetric inline tens4d ddot(const tens4d& a, const tens4ds& b) { tens4d c; c.d[0] = a.d[0]*b.d[0] + a.d[9]*b.d[1] + a.d[18]*b.d[3] + a.d[27]*b.d[6] + a.d[54]*b.d[6] + a.d[36]*b.d[10] + a.d[63]*b.d[10] + a.d[45]*b.d[15] + a.d[72]*b.d[15]; c.d[1] = a.d[0]*b.d[1] + a.d[9]*b.d[2] + a.d[18]*b.d[4] + a.d[27]*b.d[7] + a.d[54]*b.d[7] + a.d[36]*b.d[11] + a.d[63]*b.d[11] + a.d[45]*b.d[16] + a.d[72]*b.d[16]; c.d[2] = a.d[0]*b.d[3] + a.d[9]*b.d[4] + a.d[18]*b.d[5] + a.d[27]*b.d[8] + a.d[54]*b.d[8] + a.d[36]*b.d[12] + a.d[63]*b.d[12] + a.d[45]*b.d[17] + a.d[72]*b.d[17]; c.d[3] = a.d[0]*b.d[6] + a.d[9]*b.d[7] + a.d[18]*b.d[8] + a.d[27]*b.d[9] + a.d[54]*b.d[9] + a.d[36]*b.d[13] + a.d[63]*b.d[13] + a.d[45]*b.d[18] + a.d[72]*b.d[18]; c.d[4] = a.d[0]*b.d[10] + a.d[9]*b.d[11] + a.d[18]*b.d[12] + a.d[27]*b.d[13] + a.d[54]*b.d[13] + a.d[36]*b.d[14] + a.d[63]*b.d[14] + a.d[45]*b.d[19] + a.d[72]*b.d[19]; c.d[5] = a.d[0]*b.d[15] + a.d[9]*b.d[16] + a.d[18]*b.d[17] + a.d[27]*b.d[18] + a.d[54]*b.d[18] + a.d[36]*b.d[19] + a.d[63]*b.d[19] + a.d[45]*b.d[20] + a.d[72]*b.d[20]; c.d[6] = a.d[0]*b.d[6] + a.d[9]*b.d[7] + a.d[18]*b.d[8] + a.d[27]*b.d[9] + a.d[54]*b.d[9] + a.d[36]*b.d[13] + a.d[63]*b.d[13] + a.d[45]*b.d[18] + a.d[72]*b.d[18]; c.d[7] = a.d[0]*b.d[10] + a.d[9]*b.d[11] + a.d[18]*b.d[12] + a.d[27]*b.d[13] + a.d[54]*b.d[13] + a.d[36]*b.d[14] + a.d[63]*b.d[14] + a.d[45]*b.d[19] + a.d[72]*b.d[19]; c.d[8] = a.d[0]*b.d[15] + a.d[9]*b.d[16] + a.d[18]*b.d[17] + a.d[27]*b.d[18] + a.d[54]*b.d[18] + a.d[36]*b.d[19] + a.d[63]*b.d[19] + a.d[45]*b.d[20] + a.d[72]*b.d[20]; c.d[9] = a.d[1]*b.d[0] + a.d[10]*b.d[1] + a.d[19]*b.d[3] + a.d[28]*b.d[6] + a.d[55]*b.d[6] + a.d[37]*b.d[10] + a.d[64]*b.d[10] + a.d[46]*b.d[15] + a.d[73]*b.d[15]; c.d[10] = a.d[1]*b.d[1] + a.d[10]*b.d[2] + a.d[19]*b.d[4] + a.d[28]*b.d[7] + a.d[55]*b.d[7] + a.d[37]*b.d[11] + a.d[64]*b.d[11] + a.d[46]*b.d[16] + a.d[73]*b.d[16]; c.d[11] = a.d[1]*b.d[3] + a.d[10]*b.d[4] + a.d[19]*b.d[5] + a.d[28]*b.d[8] + a.d[55]*b.d[8] + a.d[37]*b.d[12] + a.d[64]*b.d[12] + a.d[46]*b.d[17] + a.d[73]*b.d[17]; c.d[12] = a.d[1]*b.d[6] + a.d[10]*b.d[7] + a.d[19]*b.d[8] + a.d[28]*b.d[9] + a.d[55]*b.d[9] + a.d[37]*b.d[13] + a.d[64]*b.d[13] + a.d[46]*b.d[18] + a.d[73]*b.d[18]; c.d[13] = a.d[1]*b.d[10] + a.d[10]*b.d[11] + a.d[19]*b.d[12] + a.d[28]*b.d[13] + a.d[55]*b.d[13] + a.d[37]*b.d[14] + a.d[64]*b.d[14] + a.d[46]*b.d[19] + a.d[73]*b.d[19]; c.d[14] = a.d[1]*b.d[15] + a.d[10]*b.d[16] + a.d[19]*b.d[17] + a.d[28]*b.d[18] + a.d[55]*b.d[18] + a.d[37]*b.d[19] + a.d[64]*b.d[19] + a.d[46]*b.d[20] + a.d[73]*b.d[20]; c.d[15] = a.d[1]*b.d[6] + a.d[10]*b.d[7] + a.d[19]*b.d[8] + a.d[28]*b.d[9] + a.d[55]*b.d[9] + a.d[37]*b.d[13] + a.d[64]*b.d[13] + a.d[46]*b.d[18] + a.d[73]*b.d[18]; c.d[16] = a.d[1]*b.d[10] + a.d[10]*b.d[11] + a.d[19]*b.d[12] + a.d[28]*b.d[13] + a.d[55]*b.d[13] + a.d[37]*b.d[14] + a.d[64]*b.d[14] + a.d[46]*b.d[19] + a.d[73]*b.d[19]; c.d[17] = a.d[1]*b.d[15] + a.d[10]*b.d[16] + a.d[19]*b.d[17] + a.d[28]*b.d[18] + a.d[55]*b.d[18] + a.d[37]*b.d[19] + a.d[64]*b.d[19] + a.d[46]*b.d[20] + a.d[73]*b.d[20]; c.d[18] = a.d[2]*b.d[0] + a.d[11]*b.d[1] + a.d[20]*b.d[3] + a.d[29]*b.d[6] + a.d[56]*b.d[6] + a.d[38]*b.d[10] + a.d[65]*b.d[10] + a.d[47]*b.d[15] + a.d[74]*b.d[15]; c.d[19] = a.d[2]*b.d[1] + a.d[11]*b.d[2] + a.d[20]*b.d[4] + a.d[29]*b.d[7] + a.d[56]*b.d[7] + a.d[38]*b.d[11] + a.d[65]*b.d[11] + a.d[47]*b.d[16] + a.d[74]*b.d[16]; c.d[20] = a.d[2]*b.d[3] + a.d[11]*b.d[4] + a.d[20]*b.d[5] + a.d[29]*b.d[8] + a.d[56]*b.d[8] + a.d[38]*b.d[12] + a.d[65]*b.d[12] + a.d[47]*b.d[17] + a.d[74]*b.d[17]; c.d[21] = a.d[2]*b.d[6] + a.d[11]*b.d[7] + a.d[20]*b.d[8] + a.d[29]*b.d[9] + a.d[56]*b.d[9] + a.d[38]*b.d[13] + a.d[65]*b.d[13] + a.d[47]*b.d[18] + a.d[74]*b.d[18]; c.d[22] = a.d[2]*b.d[10] + a.d[11]*b.d[11] + a.d[20]*b.d[12] + a.d[29]*b.d[13] + a.d[56]*b.d[13] + a.d[38]*b.d[14] + a.d[65]*b.d[14] + a.d[47]*b.d[19] + a.d[74]*b.d[19]; c.d[23] = a.d[2]*b.d[15] + a.d[11]*b.d[16] + a.d[20]*b.d[17] + a.d[29]*b.d[18] + a.d[56]*b.d[18] + a.d[38]*b.d[19] + a.d[65]*b.d[19] + a.d[47]*b.d[20] + a.d[74]*b.d[20]; c.d[24] = a.d[2]*b.d[6] + a.d[11]*b.d[7] + a.d[20]*b.d[8] + a.d[29]*b.d[9] + a.d[56]*b.d[9] + a.d[38]*b.d[13] + a.d[65]*b.d[13] + a.d[47]*b.d[18] + a.d[74]*b.d[18]; c.d[25] = a.d[2]*b.d[10] + a.d[11]*b.d[11] + a.d[20]*b.d[12] + a.d[29]*b.d[13] + a.d[56]*b.d[13] + a.d[38]*b.d[14] + a.d[65]*b.d[14] + a.d[47]*b.d[19] + a.d[74]*b.d[19]; c.d[26] = a.d[2]*b.d[15] + a.d[11]*b.d[16] + a.d[20]*b.d[17] + a.d[29]*b.d[18] + a.d[56]*b.d[18] + a.d[38]*b.d[19] + a.d[65]*b.d[19] + a.d[47]*b.d[20] + a.d[74]*b.d[20]; c.d[27] = a.d[3]*b.d[0] + a.d[12]*b.d[1] + a.d[21]*b.d[3] + a.d[30]*b.d[6] + a.d[57]*b.d[6] + a.d[39]*b.d[10] + a.d[66]*b.d[10] + a.d[48]*b.d[15] + a.d[75]*b.d[15]; c.d[28] = a.d[3]*b.d[1] + a.d[12]*b.d[2] + a.d[21]*b.d[4] + a.d[30]*b.d[7] + a.d[57]*b.d[7] + a.d[39]*b.d[11] + a.d[66]*b.d[11] + a.d[48]*b.d[16] + a.d[75]*b.d[16]; c.d[29] = a.d[3]*b.d[3] + a.d[12]*b.d[4] + a.d[21]*b.d[5] + a.d[30]*b.d[8] + a.d[57]*b.d[8] + a.d[39]*b.d[12] + a.d[66]*b.d[12] + a.d[48]*b.d[17] + a.d[75]*b.d[17]; c.d[30] = a.d[3]*b.d[6] + a.d[12]*b.d[7] + a.d[21]*b.d[8] + a.d[30]*b.d[9] + a.d[57]*b.d[9] + a.d[39]*b.d[13] + a.d[66]*b.d[13] + a.d[48]*b.d[18] + a.d[75]*b.d[18]; c.d[31] = a.d[3]*b.d[10] + a.d[12]*b.d[11] + a.d[21]*b.d[12] + a.d[30]*b.d[13] + a.d[57]*b.d[13] + a.d[39]*b.d[14] + a.d[66]*b.d[14] + a.d[48]*b.d[19] + a.d[75]*b.d[19]; c.d[32] = a.d[3]*b.d[15] + a.d[12]*b.d[16] + a.d[21]*b.d[17] + a.d[30]*b.d[18] + a.d[57]*b.d[18] + a.d[39]*b.d[19] + a.d[66]*b.d[19] + a.d[48]*b.d[20] + a.d[75]*b.d[20]; c.d[33] = a.d[3]*b.d[6] + a.d[12]*b.d[7] + a.d[21]*b.d[8] + a.d[30]*b.d[9] + a.d[57]*b.d[9] + a.d[39]*b.d[13] + a.d[66]*b.d[13] + a.d[48]*b.d[18] + a.d[75]*b.d[18]; c.d[34] = a.d[3]*b.d[10] + a.d[12]*b.d[11] + a.d[21]*b.d[12] + a.d[30]*b.d[13] + a.d[57]*b.d[13] + a.d[39]*b.d[14] + a.d[66]*b.d[14] + a.d[48]*b.d[19] + a.d[75]*b.d[19]; c.d[35] = a.d[3]*b.d[15] + a.d[12]*b.d[16] + a.d[21]*b.d[17] + a.d[30]*b.d[18] + a.d[57]*b.d[18] + a.d[39]*b.d[19] + a.d[66]*b.d[19] + a.d[48]*b.d[20] + a.d[75]*b.d[20]; c.d[36] = a.d[4]*b.d[0] + a.d[13]*b.d[1] + a.d[22]*b.d[3] + a.d[31]*b.d[6] + a.d[58]*b.d[6] + a.d[40]*b.d[10] + a.d[67]*b.d[10] + a.d[49]*b.d[15] + a.d[76]*b.d[15]; c.d[37] = a.d[4]*b.d[1] + a.d[13]*b.d[2] + a.d[22]*b.d[4] + a.d[31]*b.d[7] + a.d[58]*b.d[7] + a.d[40]*b.d[11] + a.d[67]*b.d[11] + a.d[49]*b.d[16] + a.d[76]*b.d[16]; c.d[38] = a.d[4]*b.d[3] + a.d[13]*b.d[4] + a.d[22]*b.d[5] + a.d[31]*b.d[8] + a.d[58]*b.d[8] + a.d[40]*b.d[12] + a.d[67]*b.d[12] + a.d[49]*b.d[17] + a.d[76]*b.d[17]; c.d[39] = a.d[4]*b.d[6] + a.d[13]*b.d[7] + a.d[22]*b.d[8] + a.d[31]*b.d[9] + a.d[58]*b.d[9] + a.d[40]*b.d[13] + a.d[67]*b.d[13] + a.d[49]*b.d[18] + a.d[76]*b.d[18]; c.d[40] = a.d[4]*b.d[10] + a.d[13]*b.d[11] + a.d[22]*b.d[12] + a.d[31]*b.d[13] + a.d[58]*b.d[13] + a.d[40]*b.d[14] + a.d[67]*b.d[14] + a.d[49]*b.d[19] + a.d[76]*b.d[19]; c.d[41] = a.d[4]*b.d[15] + a.d[13]*b.d[16] + a.d[22]*b.d[17] + a.d[31]*b.d[18] + a.d[58]*b.d[18] + a.d[40]*b.d[19] + a.d[67]*b.d[19] + a.d[49]*b.d[20] + a.d[76]*b.d[20]; c.d[42] = a.d[4]*b.d[6] + a.d[13]*b.d[7] + a.d[22]*b.d[8] + a.d[31]*b.d[9] + a.d[58]*b.d[9] + a.d[40]*b.d[13] + a.d[67]*b.d[13] + a.d[49]*b.d[18] + a.d[76]*b.d[18]; c.d[43] = a.d[4]*b.d[10] + a.d[13]*b.d[11] + a.d[22]*b.d[12] + a.d[31]*b.d[13] + a.d[58]*b.d[13] + a.d[40]*b.d[14] + a.d[67]*b.d[14] + a.d[49]*b.d[19] + a.d[76]*b.d[19]; c.d[44] = a.d[4]*b.d[15] + a.d[13]*b.d[16] + a.d[22]*b.d[17] + a.d[31]*b.d[18] + a.d[58]*b.d[18] + a.d[40]*b.d[19] + a.d[67]*b.d[19] + a.d[49]*b.d[20] + a.d[76]*b.d[20]; c.d[45] = a.d[5]*b.d[0] + a.d[14]*b.d[1] + a.d[23]*b.d[3] + a.d[32]*b.d[6] + a.d[59]*b.d[6] + a.d[41]*b.d[10] + a.d[68]*b.d[10] + a.d[50]*b.d[15] + a.d[77]*b.d[15]; c.d[46] = a.d[5]*b.d[1] + a.d[14]*b.d[2] + a.d[23]*b.d[4] + a.d[32]*b.d[7] + a.d[59]*b.d[7] + a.d[41]*b.d[11] + a.d[68]*b.d[11] + a.d[50]*b.d[16] + a.d[77]*b.d[16]; c.d[47] = a.d[5]*b.d[3] + a.d[14]*b.d[4] + a.d[23]*b.d[5] + a.d[32]*b.d[8] + a.d[59]*b.d[8] + a.d[41]*b.d[12] + a.d[68]*b.d[12] + a.d[50]*b.d[17] + a.d[77]*b.d[17]; c.d[48] = a.d[5]*b.d[6] + a.d[14]*b.d[7] + a.d[23]*b.d[8] + a.d[32]*b.d[9] + a.d[59]*b.d[9] + a.d[41]*b.d[13] + a.d[68]*b.d[13] + a.d[50]*b.d[18] + a.d[77]*b.d[18]; c.d[49] = a.d[5]*b.d[10] + a.d[14]*b.d[11] + a.d[23]*b.d[12] + a.d[32]*b.d[13] + a.d[59]*b.d[13] + a.d[41]*b.d[14] + a.d[68]*b.d[14] + a.d[50]*b.d[19] + a.d[77]*b.d[19]; c.d[50] = a.d[5]*b.d[15] + a.d[14]*b.d[16] + a.d[23]*b.d[17] + a.d[32]*b.d[18] + a.d[59]*b.d[18] + a.d[41]*b.d[19] + a.d[68]*b.d[19] + a.d[50]*b.d[20] + a.d[77]*b.d[20]; c.d[51] = a.d[5]*b.d[6] + a.d[14]*b.d[7] + a.d[23]*b.d[8] + a.d[32]*b.d[9] + a.d[59]*b.d[9] + a.d[41]*b.d[13] + a.d[68]*b.d[13] + a.d[50]*b.d[18] + a.d[77]*b.d[18]; c.d[52] = a.d[5]*b.d[10] + a.d[14]*b.d[11] + a.d[23]*b.d[12] + a.d[32]*b.d[13] + a.d[59]*b.d[13] + a.d[41]*b.d[14] + a.d[68]*b.d[14] + a.d[50]*b.d[19] + a.d[77]*b.d[19]; c.d[53] = a.d[5]*b.d[15] + a.d[14]*b.d[16] + a.d[23]*b.d[17] + a.d[32]*b.d[18] + a.d[59]*b.d[18] + a.d[41]*b.d[19] + a.d[68]*b.d[19] + a.d[50]*b.d[20] + a.d[77]*b.d[20]; c.d[54] = a.d[6]*b.d[0] + a.d[15]*b.d[1] + a.d[24]*b.d[3] + a.d[33]*b.d[6] + a.d[60]*b.d[6] + a.d[42]*b.d[10] + a.d[69]*b.d[10] + a.d[51]*b.d[15] + a.d[78]*b.d[15]; c.d[55] = a.d[6]*b.d[1] + a.d[15]*b.d[2] + a.d[24]*b.d[4] + a.d[33]*b.d[7] + a.d[60]*b.d[7] + a.d[42]*b.d[11] + a.d[69]*b.d[11] + a.d[51]*b.d[16] + a.d[78]*b.d[16]; c.d[56] = a.d[6]*b.d[3] + a.d[15]*b.d[4] + a.d[24]*b.d[5] + a.d[33]*b.d[8] + a.d[60]*b.d[8] + a.d[42]*b.d[12] + a.d[69]*b.d[12] + a.d[51]*b.d[17] + a.d[78]*b.d[17]; c.d[57] = a.d[6]*b.d[6] + a.d[15]*b.d[7] + a.d[24]*b.d[8] + a.d[33]*b.d[9] + a.d[60]*b.d[9] + a.d[42]*b.d[13] + a.d[69]*b.d[13] + a.d[51]*b.d[18] + a.d[78]*b.d[18]; c.d[58] = a.d[6]*b.d[10] + a.d[15]*b.d[11] + a.d[24]*b.d[12] + a.d[33]*b.d[13] + a.d[60]*b.d[13] + a.d[42]*b.d[14] + a.d[69]*b.d[14] + a.d[51]*b.d[19] + a.d[78]*b.d[19]; c.d[59] = a.d[6]*b.d[15] + a.d[15]*b.d[16] + a.d[24]*b.d[17] + a.d[33]*b.d[18] + a.d[60]*b.d[18] + a.d[42]*b.d[19] + a.d[69]*b.d[19] + a.d[51]*b.d[20] + a.d[78]*b.d[20]; c.d[60] = a.d[6]*b.d[6] + a.d[15]*b.d[7] + a.d[24]*b.d[8] + a.d[33]*b.d[9] + a.d[60]*b.d[9] + a.d[42]*b.d[13] + a.d[69]*b.d[13] + a.d[51]*b.d[18] + a.d[78]*b.d[18]; c.d[61] = a.d[6]*b.d[10] + a.d[15]*b.d[11] + a.d[24]*b.d[12] + a.d[33]*b.d[13] + a.d[60]*b.d[13] + a.d[42]*b.d[14] + a.d[69]*b.d[14] + a.d[51]*b.d[19] + a.d[78]*b.d[19]; c.d[62] = a.d[6]*b.d[15] + a.d[15]*b.d[16] + a.d[24]*b.d[17] + a.d[33]*b.d[18] + a.d[60]*b.d[18] + a.d[42]*b.d[19] + a.d[69]*b.d[19] + a.d[51]*b.d[20] + a.d[78]*b.d[20]; c.d[63] = a.d[7]*b.d[0] + a.d[16]*b.d[1] + a.d[25]*b.d[3] + a.d[34]*b.d[6] + a.d[61]*b.d[6] + a.d[43]*b.d[10] + a.d[70]*b.d[10] + a.d[52]*b.d[15] + a.d[79]*b.d[15]; c.d[64] = a.d[7]*b.d[1] + a.d[16]*b.d[2] + a.d[25]*b.d[4] + a.d[34]*b.d[7] + a.d[61]*b.d[7] + a.d[43]*b.d[11] + a.d[70]*b.d[11] + a.d[52]*b.d[16] + a.d[79]*b.d[16]; c.d[65] = a.d[7]*b.d[3] + a.d[16]*b.d[4] + a.d[25]*b.d[5] + a.d[34]*b.d[8] + a.d[61]*b.d[8] + a.d[43]*b.d[12] + a.d[70]*b.d[12] + a.d[52]*b.d[17] + a.d[79]*b.d[17]; c.d[66] = a.d[7]*b.d[6] + a.d[16]*b.d[7] + a.d[25]*b.d[8] + a.d[34]*b.d[9] + a.d[61]*b.d[9] + a.d[43]*b.d[13] + a.d[70]*b.d[13] + a.d[52]*b.d[18] + a.d[79]*b.d[18]; c.d[67] = a.d[7]*b.d[10] + a.d[16]*b.d[11] + a.d[25]*b.d[12] + a.d[34]*b.d[13] + a.d[61]*b.d[13] + a.d[43]*b.d[14] + a.d[70]*b.d[14] + a.d[52]*b.d[19] + a.d[79]*b.d[19]; c.d[68] = a.d[7]*b.d[15] + a.d[16]*b.d[16] + a.d[25]*b.d[17] + a.d[34]*b.d[18] + a.d[61]*b.d[18] + a.d[43]*b.d[19] + a.d[70]*b.d[19] + a.d[52]*b.d[20] + a.d[79]*b.d[20]; c.d[69] = a.d[7]*b.d[6] + a.d[16]*b.d[7] + a.d[25]*b.d[8] + a.d[34]*b.d[9] + a.d[61]*b.d[9] + a.d[43]*b.d[13] + a.d[70]*b.d[13] + a.d[52]*b.d[18] + a.d[79]*b.d[18]; c.d[70] = a.d[7]*b.d[10] + a.d[16]*b.d[11] + a.d[25]*b.d[12] + a.d[34]*b.d[13] + a.d[61]*b.d[13] + a.d[43]*b.d[14] + a.d[70]*b.d[14] + a.d[52]*b.d[19] + a.d[79]*b.d[19]; c.d[71] = a.d[7]*b.d[15] + a.d[16]*b.d[16] + a.d[25]*b.d[17] + a.d[34]*b.d[18] + a.d[61]*b.d[18] + a.d[43]*b.d[19] + a.d[70]*b.d[19] + a.d[52]*b.d[20] + a.d[79]*b.d[20]; c.d[72] = a.d[8]*b.d[0] + a.d[17]*b.d[1] + a.d[26]*b.d[3] + a.d[35]*b.d[6] + a.d[62]*b.d[6] + a.d[44]*b.d[10] + a.d[71]*b.d[10] + a.d[53]*b.d[15] + a.d[80]*b.d[15]; c.d[73] = a.d[8]*b.d[1] + a.d[17]*b.d[2] + a.d[26]*b.d[4] + a.d[35]*b.d[7] + a.d[62]*b.d[7] + a.d[44]*b.d[11] + a.d[71]*b.d[11] + a.d[53]*b.d[16] + a.d[80]*b.d[16]; c.d[74] = a.d[8]*b.d[3] + a.d[17]*b.d[4] + a.d[26]*b.d[5] + a.d[35]*b.d[8] + a.d[62]*b.d[8] + a.d[44]*b.d[12] + a.d[71]*b.d[12] + a.d[53]*b.d[17] + a.d[80]*b.d[17]; c.d[75] = a.d[8]*b.d[6] + a.d[17]*b.d[7] + a.d[26]*b.d[8] + a.d[35]*b.d[9] + a.d[62]*b.d[9] + a.d[44]*b.d[13] + a.d[71]*b.d[13] + a.d[53]*b.d[18] + a.d[80]*b.d[18]; c.d[76] = a.d[8]*b.d[10] + a.d[17]*b.d[11] + a.d[26]*b.d[12] + a.d[35]*b.d[13] + a.d[62]*b.d[13] + a.d[44]*b.d[14] + a.d[71]*b.d[14] + a.d[53]*b.d[19] + a.d[80]*b.d[19]; c.d[77] = a.d[8]*b.d[15] + a.d[17]*b.d[16] + a.d[26]*b.d[17] + a.d[35]*b.d[18] + a.d[62]*b.d[18] + a.d[44]*b.d[19] + a.d[71]*b.d[19] + a.d[53]*b.d[20] + a.d[80]*b.d[20]; c.d[78] = a.d[8]*b.d[6] + a.d[17]*b.d[7] + a.d[26]*b.d[8] + a.d[35]*b.d[9] + a.d[62]*b.d[9] + a.d[44]*b.d[13] + a.d[71]*b.d[13] + a.d[53]*b.d[18] + a.d[80]*b.d[18]; c.d[79] = a.d[8]*b.d[10] + a.d[17]*b.d[11] + a.d[26]*b.d[12] + a.d[35]*b.d[13] + a.d[62]*b.d[13] + a.d[44]*b.d[14] + a.d[71]*b.d[14] + a.d[53]*b.d[19] + a.d[80]*b.d[19]; c.d[80] = a.d[8]*b.d[15] + a.d[17]*b.d[16] + a.d[26]*b.d[17] + a.d[35]*b.d[18] + a.d[62]*b.d[18] + a.d[44]*b.d[19] + a.d[71]*b.d[19] + a.d[53]*b.d[20] + a.d[80]*b.d[20]; return c; } //----------------------------------------------------------------------------- // vdotTdotv_jk = a_i T_ijkl b_l inline mat3d vdotTdotv(const vec3d& a, const tens4d& T, const vec3d& b) { return mat3d(a.x*b.x*T.d[0] + a.z*b.x*T.d[5] + a.y*b.x*T.d[6] + a.x*b.y*T.d[27] + a.z*b.y*T.d[32] + a.y*b.y*T.d[33] + a.x*b.z*T.d[72] + a.z*b.z*T.d[77] + a.y*b.z*T.d[78], a.y*b.x*T.d[1] + a.x*b.x*T.d[3] + a.z*b.x*T.d[7] + a.y*b.y*T.d[28] + a.x*b.y*T.d[30] + a.z*b.y*T.d[34] + a.y*b.z*T.d[73] + a.x*b.z*T.d[75] + a.z*b.z*T.d[79], a.z*b.x*T.d[2] + a.y*b.x*T.d[4] + a.x*b.x*T.d[8] + a.z*b.y*T.d[29] + a.y*b.y*T.d[31] + a.x*b.y*T.d[35] + a.z*b.z*T.d[74] + a.y*b.z*T.d[76] + a.x*b.z*T.d[80], a.x*b.y*T.d[9] + a.z*b.y*T.d[14] + a.y*b.y*T.d[15] + a.x*b.z*T.d[36] + a.z*b.z*T.d[41] + a.y*b.z*T.d[42] + a.x*b.x*T.d[54] + a.z*b.x*T.d[59] + a.y*b.x*T.d[60], a.y*b.y*T.d[10] + a.x*b.y*T.d[12] + a.z*b.y*T.d[16] + a.y*b.z*T.d[37] + a.x*b.z*T.d[39] + a.z*b.z*T.d[43] + a.y*b.x*T.d[55] + a.x*b.x*T.d[57] + a.z*b.x*T.d[61], a.z*b.y*T.d[11] + a.y*b.y*T.d[13] + a.x*b.y*T.d[17] + a.z*b.z*T.d[38] + a.y*b.z*T.d[40] + a.x*b.z*T.d[44] + a.z*b.x*T.d[56] + a.y*b.x*T.d[58] + a.x*b.x*T.d[62], a.x*b.z*T.d[18] + a.z*b.z*T.d[23] + a.y*b.z*T.d[24] + a.x*b.x*T.d[45] + a.z*b.x*T.d[50] + a.y*b.x*T.d[51] + a.x*b.y*T.d[63] + a.z*b.y*T.d[68] + a.y*b.y*T.d[69], a.y*b.z*T.d[19] + a.x*b.z*T.d[21] + a.z*b.z*T.d[25] + a.y*b.x*T.d[46] + a.x*b.x*T.d[48] + a.z*b.x*T.d[52] + a.y*b.y*T.d[64] + a.x*b.y*T.d[66] + a.z*b.y*T.d[70], a.z*b.z*T.d[20] + a.y*b.z*T.d[22] + a.x*b.z*T.d[26] + a.z*b.x*T.d[47] + a.y*b.x*T.d[49] + a.x*b.x*T.d[53] + a.z*b.y*T.d[65] + a.y*b.y*T.d[67] + a.x*b.y*T.d[71]); } //----------------------------------------------------------------------------- // inverse inline tens4d tens4d::inverse() const { matrix c(9,9); // populate c c(0,0) = d[ 0]; c(0,1) = d[ 9]; c(0,2) = d[18]; c(0,3) = d[27]; c(0,4) = d[36]; c(0,5) = d[45]; c(0,6) = d[54]; c(0,7) = d[63]; c(0,8) = d[72]; c(1,0) = d[ 1]; c(1,1) = d[10]; c(1,2) = d[19]; c(1,3) = d[28]; c(1,4) = d[37]; c(1,5) = d[46]; c(1,6) = d[55]; c(1,7) = d[64]; c(1,8) = d[73]; c(2,0) = d[ 2]; c(2,1) = d[11]; c(2,2) = d[20]; c(2,3) = d[29]; c(2,4) = d[38]; c(2,5) = d[47]; c(2,6) = d[56]; c(2,7) = d[65]; c(2,8) = d[74]; c(3,0) = d[ 3]; c(3,1) = d[12]; c(3,2) = d[21]; c(3,3) = d[30]; c(3,4) = d[39]; c(3,5) = d[48]; c(3,6) = d[57]; c(3,7) = d[66]; c(3,8) = d[75]; c(4,0) = d[ 4]; c(4,1) = d[13]; c(4,2) = d[22]; c(4,3) = d[31]; c(4,4) = d[40]; c(4,5) = d[49]; c(4,6) = d[58]; c(4,7) = d[67]; c(4,8) = d[76]; c(5,0) = d[ 5]; c(5,1) = d[14]; c(5,2) = d[23]; c(5,3) = d[32]; c(5,4) = d[41]; c(5,5) = d[50]; c(5,6) = d[59]; c(5,7) = d[68]; c(5,8) = d[77]; c(6,0) = d[ 6]; c(6,1) = d[15]; c(6,2) = d[24]; c(6,3) = d[33]; c(6,4) = d[42]; c(6,5) = d[51]; c(6,6) = d[60]; c(6,7) = d[69]; c(6,8) = d[78]; c(7,0) = d[ 7]; c(7,1) = d[16]; c(7,2) = d[25]; c(7,3) = d[34]; c(7,4) = d[43]; c(7,5) = d[52]; c(7,6) = d[61]; c(7,7) = d[70]; c(7,8) = d[79]; c(8,0) = d[ 8]; c(8,1) = d[17]; c(8,2) = d[26]; c(8,3) = d[35]; c(8,4) = d[44]; c(8,5) = d[53]; c(8,6) = d[62]; c(8,7) = d[71]; c(8,8) = d[80]; // invert c matrix s = c.inverse(); // return inverse tens4d S; S.d[ 0] = s(0,0); S.d[ 9] = s(0,1); S.d[18] = s(0,2); S.d[27] = s(0,3); S.d[36] = s(0,4); S.d[45] = s(0,5); S.d[54] = s(0,6); S.d[63] = s(0,7); S.d[72] = s(0,8); S.d[ 1] = s(1,0); S.d[10] = s(1,1); S.d[19] = s(1,2); S.d[28] = s(1,3); S.d[37] = s(1,4); S.d[46] = s(1,5); S.d[55] = s(1,6); S.d[64] = s(1,7); S.d[73] = s(1,8); S.d[ 2] = s(2,0); S.d[11] = s(2,1); S.d[20] = s(2,2); S.d[29] = s(2,3); S.d[38] = s(2,4); S.d[47] = s(2,5); S.d[56] = s(2,6); S.d[65] = s(2,7); S.d[74] = s(2,8); S.d[ 3] = s(3,0); S.d[12] = s(3,1); S.d[21] = s(3,2); S.d[30] = s(3,3); S.d[39] = s(3,4); S.d[48] = s(3,5); S.d[57] = s(3,6); S.d[66] = s(3,7); S.d[75] = s(3,8); S.d[ 4] = s(4,0); S.d[13] = s(4,1); S.d[22] = s(4,2); S.d[31] = s(4,3); S.d[40] = s(4,4); S.d[49] = s(4,5); S.d[58] = s(4,6); S.d[67] = s(4,7); S.d[76] = s(4,8); S.d[ 5] = s(5,0); S.d[14] = s(5,1); S.d[23] = s(5,2); S.d[32] = s(5,3); S.d[41] = s(5,4); S.d[50] = s(5,5); S.d[59] = s(5,6); S.d[68] = s(5,7); S.d[77] = s(5,8); S.d[ 6] = s(6,0); S.d[15] = s(6,1); S.d[24] = s(6,2); S.d[33] = s(6,3); S.d[42] = s(6,4); S.d[51] = s(6,5); S.d[60] = s(6,6); S.d[69] = s(6,7); S.d[78] = s(6,8); S.d[ 7] = s(7,0); S.d[16] = s(7,1); S.d[25] = s(7,2); S.d[34] = s(7,3); S.d[43] = s(7,4); S.d[52] = s(7,5); S.d[61] = s(7,6); S.d[70] = s(7,7); S.d[79] = s(7,8); S.d[ 8] = s(8,0); S.d[17] = s(8,1); S.d[26] = s(8,2); S.d[35] = s(8,3); S.d[44] = s(8,4); S.d[53] = s(8,5); S.d[62] = s(8,6); S.d[71] = s(8,7); S.d[80] = s(8,8); return S; }
Unknown
3D
febiosoftware/FEBio
FECore/FELogDomainVolume.cpp
.cpp
1,970
60
/*This file is part of the FEBio source code and is licensed under the MIT license listed below. See Copyright-FEBio.txt for details. Copyright (c) 2021 University of Utah, The Trustees of Columbia University in the City of New York, and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ #include "stdafx.h" #include "FELogDomainVolume.h" #include "FESolidDomain.h" #include "FEShellDomain.h" double FELogDomainVolume::value(FEDomain& dom) { double vol = 0.0; int NE = dom.Elements(); FESolidDomain* solidDomain = dynamic_cast<FESolidDomain*>(&dom); if (solidDomain) { for (int i = 0; i < NE; ++i) { FESolidElement& el = solidDomain->Element(i); double Ve = solidDomain->CurrentVolume(el); vol += Ve; } } FEShellDomain* shellDomain = dynamic_cast<FEShellDomain*>(&dom); if (shellDomain) { for (int i = 0; i < NE; ++i) { FEShellElement& el = shellDomain->Element(i); double Ve = shellDomain->CurrentVolume(el); vol += Ve; } } return vol; }
C++